From f30a8ee2a8e0317d11d70c348bdd9c7cd15844c8 Mon Sep 17 00:00:00 2001 From: gm-matthew <108370479+gm-matthew@users.noreply.github.com> Date: Tue, 4 Jun 2024 16:40:36 +0100 Subject: [PATCH] Minor shader optimization If the mipmap level is 0.0, we only need to run texBiLinear() for the highest quality texture mipmap Adds around 10-20% more performance in Daytona 2 --- Src/Graphics/New3D/R3DShaderCommon.h | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Src/Graphics/New3D/R3DShaderCommon.h b/Src/Graphics/New3D/R3DShaderCommon.h index df12c1b..df392ea 100644 --- a/Src/Graphics/New3D/R3DShaderCommon.h +++ b/Src/Graphics/New3D/R3DShaderCommon.h @@ -249,15 +249,22 @@ vec4 textureR3D(usampler2D texSampler, ivec2 wrapMode, ivec2 texSize, ivec2 texP int iLevel = int(fLevel); ivec2 texPos0 = GetTexturePosition(iLevel,texPos); - ivec2 texPos1 = GetTexturePosition(iLevel+1,texPos); - ivec2 texSize0 = GetTextureSize(iLevel, texSize); - ivec2 texSize1 = GetTextureSize(iLevel+1, texSize); - vec4 texLevel0 = texBiLinear(texSampler, wrapMode, vec2(texSize0), texPos0, texCoord); - vec4 texLevel1 = texBiLinear(texSampler, wrapMode, vec2(texSize1), texPos1, texCoord); + if (fLevel > 0) + { + ivec2 texPos1 = GetTexturePosition(iLevel+1,texPos); + ivec2 texSize1 = GetTextureSize(iLevel+1, texSize); - return mix(texLevel0, texLevel1, fract(fLevel)); // linear blend between our mipmap levels + vec4 texLevel0 = texBiLinear(texSampler, wrapMode, vec2(texSize0), texPos0, texCoord); + vec4 texLevel1 = texBiLinear(texSampler, wrapMode, vec2(texSize1), texPos1, texCoord); + + return mix(texLevel0, texLevel1, fract(fLevel)); // linear blend between our mipmap levels + } + else + { + return texBiLinear(texSampler, wrapMode, vec2(texSize0), texPos0, texCoord); + } } vec4 GetTextureValue()