From 12356d7342c1ed120cf4ed788f7f8239843aa174 Mon Sep 17 00:00:00 2001 From: Joshua Ashton Date: Mon, 1 Jun 2020 13:32:54 +0100 Subject: [PATCH] [dxso] Bias FETCH4 half-texel offset to avoid grid effect --- src/dxso/dxso_compiler.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/dxso/dxso_compiler.cpp b/src/dxso/dxso_compiler.cpp index a7f20ccb578..92d0d7d3d3c 100644 --- a/src/dxso/dxso_compiler.cpp +++ b/src/dxso/dxso_compiler.cpp @@ -3110,7 +3110,12 @@ void DxsoCompiler::emitControlFlowGenericLoop( textureSize.type = { DxsoScalarType::Float32, samplerInfo.dimensions }; textureSize.id = m_module.opConvertStoF(getVectorTypeId(textureSize.type), textureSize.id); - textureSize.id = m_module.opFDiv(getVectorTypeId(textureSize.type), m_module.constfReplicant(1.0f, samplerInfo.dimensions), textureSize.id); + // HACK: Bias fetch4 half-texel offset to avoid a "grid" effect. + // Technically we should only do that for non-powers of two + // as only then does the imprecision need to be biased + // towards infinity -- but that's not really worth doing... + float numerator = 1.0f - 1.0f / 256.0f; + textureSize.id = m_module.opFDiv(getVectorTypeId(textureSize.type), m_module.constfReplicant(numerator, samplerInfo.dimensions), textureSize.id); // coord => same dimensions as texture size (no cube here !) const std::array naturalIndices = { 0, 1, 2, 3 };