Skip to content

Commit dcce545

Browse files
committed
nv2a: Handle anisotropic filter setting
Implements handling of anisotropic filter level from SET_TEXTURE_CONTROL0.
1 parent 59626b1 commit dcce545

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

hw/xbox/nv2a/nv2a_regs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@
539539
#define NV_PGRAPH_TEXCTL0_0 0x000019CC
540540
# define NV_PGRAPH_TEXCTL0_0_COLORKEYMODE 0x03
541541
# define NV_PGRAPH_TEXCTL0_0_ALPHAKILLEN (1 << 2)
542+
# define NV_PGRAPH_TEXCTL0_0_MAX_ANISOTROPY 0x30
542543
# define NV_PGRAPH_TEXCTL0_0_MAX_LOD_CLAMP 0x0003FFC0
543544
# define NV_PGRAPH_TEXCTL0_0_MIN_LOD_CLAMP 0x3FFC0000
544545
# define NV_PGRAPH_TEXCTL0_0_ENABLE (1 << 30)

hw/xbox/nv2a/pgraph/gl/texture.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ static void apply_texture_parameters(TextureBinding *binding,
113113
unsigned int filter,
114114
unsigned int address,
115115
bool is_bordered,
116-
uint32_t border_color)
116+
uint32_t border_color,
117+
uint32_t max_anisotropy)
117118
{
118119
unsigned int min_filter = GET_MASK(filter, NV_PGRAPH_TEXFILTER0_MIN);
119120
unsigned int mag_filter = GET_MASK(filter, NV_PGRAPH_TEXFILTER0_MAG);
@@ -181,6 +182,8 @@ static void apply_texture_parameters(TextureBinding *binding,
181182
needs_border_color = needs_border_color || binding->addrp == NV_PGRAPH_TEXADDRESS0_ADDRU_BORDER;
182183
}
183184

185+
glTexParameterf(binding->gl_target, GL_TEXTURE_MAX_ANISOTROPY, max_anisotropy);
186+
184187
if (!is_bordered && needs_border_color) {
185188
if (!binding->border_color_set || binding->border_color != border_color) {
186189
/* FIXME: Color channels might be wrong order */
@@ -219,6 +222,9 @@ void pgraph_gl_bind_textures(NV2AState *d)
219222
uint32_t filter = pgraph_reg_r(pg, NV_PGRAPH_TEXFILTER0 + i*4);
220223
uint32_t address = pgraph_reg_r(pg, NV_PGRAPH_TEXADDRESS0 + i*4);
221224
uint32_t border_color = pgraph_reg_r(pg, NV_PGRAPH_BORDERCOLOR0 + i*4);
225+
uint32_t max_anisotropy =
226+
1 << (GET_MASK(pgraph_reg_r(pg, NV_PGRAPH_TEXCTL0_0 + i*4),
227+
NV_PGRAPH_TEXCTL0_0_MAX_ANISOTROPY));
222228

223229
/* Check for unsupported features */
224230
if (filter & NV_PGRAPH_TEXFILTER0_ASIGNED) NV2A_UNIMPLEMENTED("NV_PGRAPH_TEXFILTER0_ASIGNED");
@@ -268,7 +274,8 @@ void pgraph_gl_bind_textures(NV2AState *d)
268274
filter,
269275
address,
270276
state.border,
271-
border_color);
277+
border_color,
278+
max_anisotropy);
272279
continue;
273280
}
274281
}
@@ -378,7 +385,8 @@ void pgraph_gl_bind_textures(NV2AState *d)
378385
filter,
379386
address,
380387
state.border,
381-
border_color);
388+
border_color,
389+
max_anisotropy);
382390

383391
if (r->texture_binding[i]) {
384392
if (r->texture_binding[i]->gl_target != binding->gl_target) {

hw/xbox/nv2a/pgraph/vk/texture.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,13 @@ static void create_texture(PGRAPHState *pg, int texture_idx)
11011101
pgraph_reg_r(pg, NV_PGRAPH_BORDERCOLOR0 + texture_idx * 4);
11021102
bool is_indexed = (state.color_format ==
11031103
NV097_SET_TEXTURE_FORMAT_COLOR_SZ_I8_A8R8G8B8);
1104+
uint32_t xbox_max_anisotropy =
1105+
1 << (GET_MASK(pgraph_reg_r(pg, NV_PGRAPH_TEXCTL0_0 + texture_idx*4),
1106+
NV_PGRAPH_TEXCTL0_0_MAX_ANISOTROPY));
1107+
uint32_t max_anisotropy =
1108+
xbox_max_anisotropy <= r->device_props.limits.maxSamplerAnisotropy ?
1109+
xbox_max_anisotropy :
1110+
r->device_props.limits.maxSamplerAnisotropy;
11041111

11051112
TextureKey key;
11061113
memset(&key, 0, sizeof(key));
@@ -1354,9 +1361,8 @@ static void create_texture(PGRAPHState *pg, int texture_idx)
13541361
GET_MASK(address, NV_PGRAPH_TEXADDRESS0_ADDRV)),
13551362
.addressModeW = (state.dimensionality > 2) ? lookup_texture_address_mode(
13561363
GET_MASK(address, NV_PGRAPH_TEXADDRESS0_ADDRP)) : 0,
1357-
.anisotropyEnable = VK_FALSE,
1358-
// .anisotropyEnable = VK_TRUE,
1359-
// .maxAnisotropy = properties.limits.maxSamplerAnisotropy,
1364+
.anisotropyEnable = max_anisotropy > 1,
1365+
.maxAnisotropy = max_anisotropy,
13601366
.borderColor = vk_border_color,
13611367
.compareEnable = VK_FALSE,
13621368
.compareOp = VK_COMPARE_OP_ALWAYS,

0 commit comments

Comments
 (0)