Skip to content

Commit

Permalink
Apply nearest filter for pixel-mapped draws
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Jan 11, 2024
1 parent 944b3c5 commit 341fe04
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions GPU/Common/TextureCacheCommon.cpp
Expand Up @@ -284,6 +284,9 @@ SamplerCacheKey TextureCacheCommon::GetSamplingParams(int maxLevel, const TexCac
break;
}
}
if (gstate_c.pixelMapped) {
forceFiltering = TEX_FILTER_FORCE_NEAREST;
}

switch (forceFiltering) {
case TEX_FILTER_AUTO:
Expand Down
5 changes: 4 additions & 1 deletion GPU/D3D11/DrawEngineD3D11.cpp
Expand Up @@ -408,8 +408,11 @@ void DrawEngineD3D11::DoFlush() {
if (result.action == SW_CLEAR && everUsedEqualDepth_ && gstate.isClearModeDepthMask() && result.depth > 0.0f && result.depth < 1.0f)
result.action = SW_NOT_READY;

if (textureNeedsApply)
if (textureNeedsApply) {
gstate_c.pixelMapped = result.pixelMapped;
textureCache_->ApplyTexture();
gstate_c.pixelMapped = false;
}

// Need to ApplyDrawState after ApplyTexture because depal can launch a render pass and that wrecks the state.
ApplyDrawState(prim);
Expand Down
5 changes: 4 additions & 1 deletion GPU/Directx9/DrawEngineDX9.cpp
Expand Up @@ -365,8 +365,11 @@ void DrawEngineDX9::DoFlush() {
if (result.action == SW_CLEAR && everUsedEqualDepth_ && gstate.isClearModeDepthMask() && result.depth > 0.0f && result.depth < 1.0f)
result.action = SW_NOT_READY;

if (textureNeedsApply)
if (textureNeedsApply) {
gstate_c.pixelMapped = result.pixelMapped;
textureCache_->ApplyTexture();
gstate_c.pixelMapped = false;
}

ApplyDrawState(prim);

Expand Down
5 changes: 4 additions & 1 deletion GPU/GLES/DrawEngineGLES.cpp
Expand Up @@ -393,8 +393,11 @@ void DrawEngineGLES::DoFlush() {
if (result.action == SW_CLEAR && everUsedEqualDepth_ && gstate.isClearModeDepthMask() && result.depth > 0.0f && result.depth < 1.0f)
result.action = SW_NOT_READY;

if (textureNeedsApply)
if (textureNeedsApply) {
gstate_c.pixelMapped = result.pixelMapped;
textureCache_->ApplyTexture();
gstate_c.pixelMapped = false;
}

// Need to ApplyDrawState after ApplyTexture because depal can launch a render pass and that wrecks the state.
ApplyDrawState(prim);
Expand Down
3 changes: 3 additions & 0 deletions GPU/GPUState.h
Expand Up @@ -689,6 +689,9 @@ struct GPUStateCache {
// We detect this case and go into a special drawing mode.
bool blueToAlpha;

// U/V is 1:1 to pixels. Can influence texture sampling.
bool pixelMapped;

// TODO: These should be accessed from the current VFB object directly.
u32 curRTWidth;
u32 curRTHeight;
Expand Down
2 changes: 2 additions & 0 deletions GPU/Vulkan/DrawEngineVulkan.cpp
Expand Up @@ -440,7 +440,9 @@ void DrawEngineVulkan::DoFlush() {
// to use a "pre-clear" render pass, for high efficiency on tilers.
if (result.action == SW_DRAW_PRIMITIVES) {
if (textureNeedsApply) {
gstate_c.pixelMapped = result.pixelMapped;
textureCache_->ApplyTexture();
gstate_c.pixelMapped = false;
textureCache_->GetVulkanHandles(imageView, sampler);
if (imageView == VK_NULL_HANDLE)
imageView = (VkImageView)draw_->GetNativeObject(gstate_c.textureIsArray ? Draw::NativeObject::NULL_IMAGEVIEW_ARRAY : Draw::NativeObject::NULL_IMAGEVIEW);
Expand Down
1 change: 1 addition & 0 deletions GPU/Vulkan/TextureCacheVulkan.cpp
Expand Up @@ -136,6 +136,7 @@ VkSampler SamplerCache::GetOrCreateSampler(const SamplerCacheKey &key) {
samp.magFilter = key.magFilt ? VK_FILTER_LINEAR : VK_FILTER_NEAREST;
samp.minFilter = key.minFilt ? VK_FILTER_LINEAR : VK_FILTER_NEAREST;
samp.mipmapMode = key.mipFilt ? VK_SAMPLER_MIPMAP_MODE_LINEAR : VK_SAMPLER_MIPMAP_MODE_NEAREST;

if (key.aniso) {
// Docs say the min of this value and the supported max are used.
samp.maxAnisotropy = 1 << g_Config.iAnisotropyLevel;
Expand Down

0 comments on commit 341fe04

Please sign in to comment.