Increase precision of GetDepthScaleFactors to match ToScaledDepthFromIntegerScale

This commit is contained in:
Henrik Rydgård 2023-02-11 11:24:02 +01:00
parent 1c2e45453b
commit 116b3ba8cc
2 changed files with 10 additions and 4 deletions

View file

@ -573,8 +573,14 @@ DepthScaleFactors GetDepthScaleFactors(u32 useFlags) {
}
const double depthSliceFactor = DepthSliceFactor(useFlags);
if (useFlags & GPU_SCALE_DEPTH_FROM_24BIT_TO_16BIT) {
const double offset = 0.5 * (depthSliceFactor - 1.0) / depthSliceFactor;
const double scale = 16777215.0;
return DepthScaleFactors(offset, scale);
} else {
const double offset = 0.5f * (depthSliceFactor - 1.0f) * (1.0f / depthSliceFactor);
return DepthScaleFactors(offset, (float)(depthSliceFactor * 65535.0));
}
}
void ConvertViewportAndScissor(bool useBufferedRendering, float renderWidth, float renderHeight, int bufferWidth, int bufferHeight, ViewportAndScissor &out) {

View file

@ -810,7 +810,7 @@ static bool TestDepthMath() {
GPU_USE_DEPTH_CLAMP | GPU_USE_ACCURATE_DEPTH,
GPU_USE_DEPTH_CLAMP | GPU_USE_ACCURATE_DEPTH | GPU_SCALE_DEPTH_FROM_24BIT_TO_16BIT, // Here, GPU_SCALE_DEPTH_FROM_24BIT_TO_16BIT should take precedence over USE_DEPTH_CLAMP.
};
static const float expectedScale[] = { 65535.0f, 262140.0f, 16776960.0f, 65535.0f, 16776960.0f, };
static const float expectedScale[] = { 65535.0f, 262140.0f, 16777215.0f, 65535.0f, 16777215.0f, };
static const float expectedOffset[] = { 0.0f, 0.375f, 0.498047f, 0.0f, 0.498047f, };
EXPECT_REL_EQ_FLOAT(100000.0f, 100001.0f, 0.00001f);
@ -822,7 +822,7 @@ static bool TestDepthMath() {
EXPECT_EQ_FLOAT(factors.ScaleU16(), expectedScale[j]);
EXPECT_REL_EQ_FLOAT(factors.Offset(), expectedOffset[j], 0.00001f);
EXPECT_EQ_FLOAT(factors.ScaleU16(), DepthSliceFactor(useFlags) * 65535.0f);
EXPECT_REL_EQ_FLOAT(factors.ScaleU16(), DepthSliceFactor(useFlags) * 65535.0f, 0.0001f);
for (int i = 0; i < ARRAY_SIZE(testValues); i++) {
float testValue = testValues[i] * 65535.0f;