From 7b9a543a488cd842c41d9cee4fd4a826082475f2 Mon Sep 17 00:00:00 2001 From: aardgoose Date: Mon, 23 Sep 2024 19:33:58 +0100 Subject: [PATCH] WebGPURenderer: Prevent out of bounds `textureLoad` access in WGSL (#29470) Co-authored-by: aardgoose --- src/renderers/webgpu/nodes/WGSLNodeBuilder.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js index 90d969f6e0f2ba..a8594e6efe4773 100644 --- a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +++ b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js @@ -94,7 +94,8 @@ fn tsl_repeatWrapping( uv : vec2, dimension : vec2 ) -> vec2 { biquadraticTexture: new CodeNode( ` fn tsl_biquadraticTexture( map : texture_2d, coord : vec2f, level : i32 ) -> vec4f { - let res = vec2f( textureDimensions( map, level ) ); + let iRes = vec2i( textureDimensions( map, level ) ); + let res = vec2f( iRes ); let uvScaled = coord * res; let uvWrapping = ( ( uvScaled % res ) + res ) % res; @@ -105,10 +106,10 @@ fn tsl_biquadraticTexture( map : texture_2d, coord : vec2f, level : i32 ) - let iuv = floor( uv ); let f = fract( uv ); - let rg1 = textureLoad( map, vec2i( iuv + vec2( 0.5, 0.5 ) ), level ); - let rg2 = textureLoad( map, vec2i( iuv + vec2( 1.5, 0.5 ) ), level ); - let rg3 = textureLoad( map, vec2i( iuv + vec2( 0.5, 1.5 ) ), level ); - let rg4 = textureLoad( map, vec2i( iuv + vec2( 1.5, 1.5 ) ), level ); + let rg1 = textureLoad( map, vec2i( iuv + vec2( 0.5, 0.5 ) ) % iRes, level ); + let rg2 = textureLoad( map, vec2i( iuv + vec2( 1.5, 0.5 ) ) % iRes, level ); + let rg3 = textureLoad( map, vec2i( iuv + vec2( 0.5, 1.5 ) ) % iRes, level ); + let rg4 = textureLoad( map, vec2i( iuv + vec2( 1.5, 1.5 ) ) % iRes, level ); return mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );