Skip to content

Commit

Permalink
WebGPURenderer: Prevent out of bounds textureLoad access in WGSL (#…
Browse files Browse the repository at this point in the history
…29470)

Co-authored-by: aardgoose <[email protected]>
  • Loading branch information
aardgoose and aardgoose authored Sep 23, 2024
1 parent cd1d4a5 commit 7b9a543
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/renderers/webgpu/nodes/WGSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ fn tsl_repeatWrapping( uv : vec2<f32>, dimension : vec2<u32> ) -> vec2<u32> {
biquadraticTexture: new CodeNode( `
fn tsl_biquadraticTexture( map : texture_2d<f32>, 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;
Expand All @@ -105,10 +106,10 @@ fn tsl_biquadraticTexture( map : texture_2d<f32>, 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 );
Expand Down

0 comments on commit 7b9a543

Please sign in to comment.