From 990c238277c99f36fe142a255b47e1f21da30335 Mon Sep 17 00:00:00 2001 From: Greggman Date: Tue, 19 Nov 2024 13:54:55 -0800 Subject: [PATCH] Fix makeRandomDepthComparisonTexelGenerator (#4048) This bug broke all textureXXCompare tests with unencodable depth formats. --- .../execution/expression/call/builtin/texture_utils.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/webgpu/shader/execution/expression/call/builtin/texture_utils.ts b/src/webgpu/shader/execution/expression/call/builtin/texture_utils.ts index 846e0caa5b72..bae7620882c9 100644 --- a/src/webgpu/shader/execution/expression/call/builtin/texture_utils.ts +++ b/src/webgpu/shader/execution/expression/call/builtin/texture_utils.ts @@ -1195,7 +1195,8 @@ export function makeRandomDepthComparisonTexelGenerator( }, comparison: GPUCompareFunction ) { - const rep = kTexelRepresentationInfo[info.format as EncodableTextureFormat]; + const format = isUnencodableDepthFormat(info.format) ? 'depth32float' : info.format; + const rep = kTexelRepresentationInfo[format as EncodableTextureFormat]; const size = reifyExtent3D(info.size); const comparisonIsEqualOrNotEqual = comparison === 'equal' || comparison === 'not-equal'; @@ -1207,7 +1208,7 @@ export function makeRandomDepthComparisonTexelGenerator( // The problem with comparing equal is other than 0.0 and 1.0, no other // values are guaranteed to be equal. const fixedValues = [0, 0.6, 1, 1]; - const format = comparisonIsEqualOrNotEqual + const encode = comparisonIsEqualOrNotEqual ? (norm: number) => fixedValues[(norm * (fixedValues.length - 1)) | 0] : (norm: number) => norm; @@ -1225,7 +1226,7 @@ export function makeRandomDepthComparisonTexelGenerator( size.depthOrArrayLayers ); const normalized = clamp(rnd / 0xffffffff, { min: 0, max: 1 }); - texel[component] = format(normalized); + texel[component] = encode(normalized); } return quantize(texel, rep); };