Skip to content

Conversation

abaire
Copy link
Contributor

@abaire abaire commented Sep 19, 2025

Implements handling of anisotropic filter level from SET_TEXTURE_CONTROL0.

Fixes #2444 (in conjunction with PR #2435 for STEAL)
Fixes #2385 (for whatever isn't already fixed by PR #2435)

Tests: https://github.com/abaire/nxdk_pgraph_tests/blob/4dc2b8f16749d0d9b9bd9e8c90b649944f96a662/src/tests/texture_anisotropy_tests.h#L10

HW results: https://abaire.github.io/nxdk_pgraph_tests_golden_results/results/Texture_anisotropy/index.html

PR results: https://abaire.github.io/xemu-dev_pgraph_test_results/fix_2444_respect_anisotropic_filter_level/index.html - Please note that there was a bleedover error in the test suite when I first ran the suite that tainted the diff for the Texture_perspective_enable result. If you manually compare the Source and xemu Golden images they are now identical.

@abaire abaire marked this pull request as ready for review September 22, 2025 16:16
.anisotropyEnable = VK_FALSE,
// .anisotropyEnable = VK_TRUE,
// .maxAnisotropy = properties.limits.maxSamplerAnisotropy,
.anisotropyEnable = max_anisotropy > 1,
Copy link
Member

Choose a reason for hiding this comment

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

Before this can be VK_TRUE, the samplerAnisotropy device feature will need to be enabled. Then check that it is actually enabled via r->enabled_physical_device_features.samplerAnisotropy.

See here:

F(wideLines, false),

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? I don't have a way to actually test.

Should we sort those desired features alphabetically? I can imagine it'll become hard to tell what has been requested at a glance as the list gets longer.

Copy link
Member

@mborgerson mborgerson Sep 24, 2025

Choose a reason for hiding this comment

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

sort those desired features alphabetically?

Probably yes

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.

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 xbox_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.

  • xbox_ prefix is inconsistent with other fields
  • Will need to be added to texture key for caching. See below at line 1127

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.

Is the plan for the nearby FIXME to pull the sampler out of the texture binding?

Copy link
Member

@mborgerson mborgerson Sep 24, 2025

Choose a reason for hiding this comment

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

Is the plan for the nearby FIXME to pull the sampler out of the texture binding?

They need not be coupled, but it's also not a high priority. Keeping them together simplifies lookup/expiration at the cost of inflated sampler counts.

uint32_t xbox_max_anisotropy =
1 << (GET_MASK(pgraph_reg_r(pg, NV_PGRAPH_TEXCTL0_0 + texture_idx*4),
NV_PGRAPH_TEXCTL0_0_MAX_ANISOTROPY));
uint32_t 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.

Simplify with MIN

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, also moved closer to where it's actually used.

Implements handling of anisotropic filter level from SET_TEXTURE_CONTROL0.
@abaire abaire force-pushed the fix_2444_respect_anisotropic_filter_level branch from d2ab8e4 to cce8e3a Compare September 23, 2025 23:29
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.

.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.

F(occlusionQueryPrecise, true),
F(samplerAnisotropy, false),
F(shaderClipDistance, true),
F(shaderTessellationAndGeometryPointSize, true),

Choose a reason for hiding this comment

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

These changes seem unrelated to the actual work. Consider moving this to a separate pull request, or elaborate why it should be in 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.

These changes are related to the PR; samplerAnisotropy was added as part of emulating the max anisotropy field.

As confirmed previously in this code review, these are intended to be kept alphabetized to make it easier to determine what features are and are not being requested. In my opinion the overhead of yet another PR for a tiny additional cleanup is not justified.

@mborgerson mborgerson merged commit 518208e into xemu-project:master Sep 25, 2025
21 checks passed
@mborgerson
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wreckless: The Yakuza Missions Mipmap Issues Mipmapping Issues (missing emulation of LOD bias and anisotropic filtering)
3 participants