Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hw/xbox/nv2a/nv2a_regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@
#define NV_PGRAPH_TEXCTL0_0 0x000019CC
# define NV_PGRAPH_TEXCTL0_0_COLORKEYMODE 0x03
# define NV_PGRAPH_TEXCTL0_0_ALPHAKILLEN (1 << 2)
# define NV_PGRAPH_TEXCTL0_0_MAX_ANISOTROPY 0x30
# define NV_PGRAPH_TEXCTL0_0_MAX_LOD_CLAMP 0x0003FFC0
# define NV_PGRAPH_TEXCTL0_0_MIN_LOD_CLAMP 0x3FFC0000
# define NV_PGRAPH_TEXCTL0_0_ENABLE (1 << 30)
Expand Down
14 changes: 11 additions & 3 deletions hw/xbox/nv2a/pgraph/gl/texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ static void apply_texture_parameters(TextureBinding *binding,
unsigned int filter,
unsigned int address,
bool is_bordered,
uint32_t border_color)
uint32_t border_color,
uint32_t max_anisotropy)
{
unsigned int min_filter = GET_MASK(filter, NV_PGRAPH_TEXFILTER0_MIN);
unsigned int mag_filter = GET_MASK(filter, NV_PGRAPH_TEXFILTER0_MAG);
Expand Down Expand Up @@ -181,6 +182,8 @@ static void apply_texture_parameters(TextureBinding *binding,
needs_border_color = needs_border_color || binding->addrp == NV_PGRAPH_TEXADDRESS0_ADDRU_BORDER;
}

glTexParameterf(binding->gl_target, GL_TEXTURE_MAX_ANISOTROPY, max_anisotropy);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically GL_TEXTURE_MAX_ANISOTROPY is not GL 4.0 core--it comes from the ARB_texture_filter_anisotropic extension.

The original extension was EXT_texture_filter_anisotropic and used the GL_TEXTURE_MAX_ANISOTROY_EXT token, which have identical numeric values.

Though it is ubiquitous, it would be good practice to confirm GL_EXT_texture_filter_anisotropic extension is present (See pgraph_gl_init) before using it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done; added a struct to track extension use similar to VK enabled features.


if (!is_bordered && needs_border_color) {
if (!binding->border_color_set || binding->border_color != border_color) {
/* FIXME: Color channels might be wrong order */
Expand Down Expand Up @@ -219,6 +222,9 @@ void pgraph_gl_bind_textures(NV2AState *d)
uint32_t filter = pgraph_reg_r(pg, NV_PGRAPH_TEXFILTER0 + i*4);
uint32_t address = pgraph_reg_r(pg, NV_PGRAPH_TEXADDRESS0 + i*4);
uint32_t border_color = pgraph_reg_r(pg, NV_PGRAPH_BORDERCOLOR0 + i*4);
uint32_t max_anisotropy =
1 << (GET_MASK(pgraph_reg_r(pg, NV_PGRAPH_TEXCTL0_0 + i*4),
NV_PGRAPH_TEXCTL0_0_MAX_ANISOTROPY));

/* Check for unsupported features */
if (filter & NV_PGRAPH_TEXFILTER0_ASIGNED) NV2A_UNIMPLEMENTED("NV_PGRAPH_TEXFILTER0_ASIGNED");
Expand Down Expand Up @@ -268,7 +274,8 @@ void pgraph_gl_bind_textures(NV2AState *d)
filter,
address,
state.border,
border_color);
border_color,
max_anisotropy);
continue;
}
}
Expand Down Expand Up @@ -378,7 +385,8 @@ void pgraph_gl_bind_textures(NV2AState *d)
filter,
address,
state.border,
border_color);
border_color,
max_anisotropy);

if (r->texture_binding[i]) {
if (r->texture_binding[i]->gl_target != binding->gl_target) {
Expand Down
1 change: 1 addition & 0 deletions hw/xbox/nv2a/pgraph/vk/instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ static bool create_logical_device(PGRAPHState *pg, Error **errp)
F(occlusionQueryPrecise, true),
F(fillModeNonSolid, true),
F(wideLines, false),
F(samplerAnisotropy, false),
#undef F
// clang-format on
};
Expand Down
1 change: 1 addition & 0 deletions hw/xbox/nv2a/pgraph/vk/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ typedef struct TextureKey {
uint32_t filter;
uint32_t address;
uint32_t border_color;
uint32_t max_anisotropy;
} TextureKey;

typedef struct TextureBinding {
Expand Down
12 changes: 9 additions & 3 deletions hw/xbox/nv2a/pgraph/vk/texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,9 @@ static void create_texture(PGRAPHState *pg, int texture_idx)
pgraph_reg_r(pg, NV_PGRAPH_BORDERCOLOR0 + texture_idx * 4);
bool is_indexed = (state.color_format ==
NV097_SET_TEXTURE_FORMAT_COLOR_SZ_I8_A8R8G8B8);
uint32_t max_anisotropy =
1 << (GET_MASK(pgraph_reg_r(pg, NV_PGRAPH_TEXCTL0_0 + texture_idx*4),
NV_PGRAPH_TEXCTL0_0_MAX_ANISOTROPY));

TextureKey key;
memset(&key, 0, sizeof(key));
Expand All @@ -1120,6 +1123,7 @@ static void create_texture(PGRAPHState *pg, int texture_idx)
key.filter = filter;
key.address = address;
key.border_color = border_color_pack32;
key.max_anisotropy = max_anisotropy;

bool possibly_dirty = false;
bool possibly_dirty_checked = false;
Expand Down Expand Up @@ -1343,6 +1347,8 @@ static void create_texture(PGRAPHState *pg, int texture_idx)
} else if (lod_bias < -r->device_props.limits.maxSamplerLodBias) {
lod_bias = -r->device_props.limits.maxSamplerLodBias;
}
uint32_t sampler_max_anisotropy =
MIN(r->device_props.limits.maxSamplerAnisotropy, max_anisotropy);

VkSamplerCreateInfo sampler_create_info = {
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
Expand All @@ -1354,9 +1360,9 @@ static void create_texture(PGRAPHState *pg, int texture_idx)
GET_MASK(address, NV_PGRAPH_TEXADDRESS0_ADDRV)),
.addressModeW = (state.dimensionality > 2) ? lookup_texture_address_mode(
GET_MASK(address, NV_PGRAPH_TEXADDRESS0_ADDRP)) : 0,
.anisotropyEnable = VK_FALSE,
// .anisotropyEnable = VK_TRUE,
// .maxAnisotropy = properties.limits.maxSamplerAnisotropy,
.anisotropyEnable = r->enabled_physical_device_features.wideLines &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a copy paste error. We need to check for samplerAnisotropy feature, not wideLines here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stupid mistake/autosuggest fail, done.

sampler_max_anisotropy > 1,
.maxAnisotropy = sampler_max_anisotropy,
.borderColor = vk_border_color,
.compareEnable = VK_FALSE,
.compareOp = VK_COMPARE_OP_ALWAYS,
Expand Down
Loading