PixelShaderGen: Clamp texture layer when using manual texture sampling with stereoscopic 3D

Otherwise, texelFetch() will use an out-of-bounds layer for game textures (that have 1 layer; EFB copies have 2 layers in stereoscopic 3D mode), which is undefined behavior (often resulting in a black image). The fast texture sampling path uses texture(), which always clamps (see https://www.khronos.org/opengl/wiki/Array_Texture#Access_in_shaders), so it was unaffected by this difference.
This commit is contained in:
Pokechu22
2022-12-27 13:45:13 -08:00
parent 1f1474f8ac
commit f3df3a7727
3 changed files with 18 additions and 5 deletions

View File

@ -274,15 +274,25 @@ struct VideoConfig final
return backend_info.bSupportsGPUTextureDecoding && bEnableGPUTextureDecoding;
}
bool UseVertexRounding() const { return bVertexRounding && iEFBScale != 1; }
bool ManualTextureSamplingWithHiResTextures() const
bool ManualTextureSamplingWithCustomTextureSizes() const
{
// Hi-res textures (including hi-res EFB copies, but not native-resolution EFB copies at higher
// internal resolutions) breaks the wrapping logic used by manual texture sampling.
// If manual texture sampling is disabled, we don't need to do anything.
if (bFastTextureSampling)
return false;
// Hi-res textures break the wrapping logic used by manual texture sampling, as a texture's
// size won't match the size the game sets.
if (bHiresTextures)
return true;
// Hi-res EFB copies (but not native-resolution EFB copies at higher internal resolutions)
// also result in different texture sizes that need special handling.
if (iEFBScale != 1 && bCopyEFBScaled)
return true;
return bHiresTextures;
// Stereoscopic 3D changes the number of layers some textures have (EFB copies have 2 layers,
// while game textures still have 1), meaning bounds checks need to be added.
if (stereo_mode != StereoMode::Off)
return true;
// Otherwise, manual texture sampling can use the sizes games specify directly.
return false;
}
bool UsingUberShaders() const;
u32 GetShaderCompilerThreads() const;