From c04b62dcc9b41c51709a672fd008fe00001bea13 Mon Sep 17 00:00:00 2001 From: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Wed, 20 Nov 2024 11:44:24 +0000 Subject: [PATCH] [Fix] Fixes handling uf (u/i)sampler2DArray shader translation for WebGPU (#7120) Co-authored-by: Martin Valigursky --- src/platform/graphics/bind-group-format.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/platform/graphics/bind-group-format.js b/src/platform/graphics/bind-group-format.js index 49b26f22c7f..1dd187e4cb8 100644 --- a/src/platform/graphics/bind-group-format.js +++ b/src/platform/graphics/bind-group-format.js @@ -359,19 +359,17 @@ class BindGroupFormat { let textureType = textureDimensionInfo[format.textureDimension]; Debug.assert(textureType, 'Unsupported texture type', format.textureDimension); + const isArray = textureType === 'texture2DArray'; + + const sampleTypePrefix = format.sampleType === SAMPLETYPE_UINT ? 'u' : (format.sampleType === SAMPLETYPE_INT ? 'i' : ''); + textureType = `${sampleTypePrefix}${textureType}`; // handle texture2DArray by renaming the texture object and defining a replacement macro let namePostfix = ''; let extraCode = ''; - if (textureType === 'texture2DArray') { + if (isArray) { namePostfix = '_texture'; - extraCode = `#define ${format.name} sampler2DArray(${format.name}${namePostfix}, ${format.name}_sampler)\n`; - } - - if (format.sampleType === SAMPLETYPE_INT) { - textureType = `i${textureType}`; - } else if (format.sampleType === SAMPLETYPE_UINT) { - textureType = `u${textureType}`; + extraCode = `#define ${format.name} ${sampleTypePrefix}sampler2DArray(${format.name}${namePostfix}, ${format.name}_sampler)\n`; } code += `layout(set = ${bindGroup}, binding = ${format.slot}) uniform ${textureType} ${format.name}${namePostfix};\n`;