]> git.nega.tv - josh/narcissus/commitdiff
shark: Fix out-of-bounds writes in bin clear
authorJosh Simmons <josh@nega.tv>
Mon, 10 Jun 2024 06:38:29 +0000 (08:38 +0200)
committerJosh Simmons <josh@nega.tv>
Mon, 10 Jun 2024 07:42:58 +0000 (09:42 +0200)
title/shark-shaders/shaders/compute_bindings.h
title/shark-shaders/shaders/primitive_2d_bin_clear.comp.glsl
title/shark/src/main.rs
title/shark/src/pipelines/mod.rs

index f8cb41ec82df5088d273b25b63dd753578e1543b..88498ed74446c80b76087a7b2bb290900fe9e9a8 100644 (file)
@@ -36,6 +36,7 @@ layout(buffer_reference, std430, buffer_reference_align = 4) writeonly buffer Ti
 struct ComputeUniforms {
     uvec2 screen_resolution;
     uvec2 atlas_resolution;
+    uvec2 tile_resolution;
 
     uint num_primitives;
     uint num_primitives_32;
index d9e138b44758dea8aa9c95e1ce2dc77917b1ebc9..5707be1ef694d5469b991bb1fcd7d308398eaf77 100644 (file)
 layout (local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
 
 void main() {
-    uniforms.tiles.values[gl_GlobalInvocationID.x * TILE_STRIDE + TILE_BITMAP_RANGE_OFFSET + 0] = 0xffffffff;
-    uniforms.tiles.values[gl_GlobalInvocationID.x * TILE_STRIDE + TILE_BITMAP_RANGE_OFFSET + 1] = 0;
+    if (gl_GlobalInvocationID.x >= uniforms.tile_resolution.x * uniforms.tile_resolution.y) {
+        return;
+    }
+
+    const uint index = gl_GlobalInvocationID.x * TILE_STRIDE + TILE_BITMAP_RANGE_OFFSET;
+
+    uniforms.tiles.values[index + 0] = 0xffffffff;
+    uniforms.tiles.values[index + 1] = 0;
 }
index 6e8aeb6a24c443ec9b08c8dd67e1841b6e5faab1..2830aa247fb1172a3cf74baccd42b0a5fd7edfcc 100644 (file)
@@ -1471,6 +1471,8 @@ impl<'gpu> DrawState<'gpu> {
                         num_primitives,
                         num_primitives_32,
                         num_primitives_1024,
+                        tile_resolution_x: self.tile_resolution_x,
+                        tile_resolution_y: self.tile_resolution_y,
                         tile_stride: self.tile_resolution_x,
                         glyphs_buffer: gpu.get_buffer_address(glyph_buffer.to_arg()),
                         glyph_instances_buffer: gpu
index 3f38de7534eec08247caeaf5fc813c8ae811ce95..4464b1aaa0cf2ee9a30c502d45bb8cea9814c1f3 100644 (file)
@@ -13,13 +13,16 @@ pub const TILE_STRIDE: u32 = TILE_BITMAP_WORDS_L0 + TILE_BITMAP_WORDS_L1 + 2;
 pub struct PrimitiveUniforms {
     pub screen_resolution_x: u32,
     pub screen_resolution_y: u32,
+
     pub atlas_resolution_x: u32,
     pub atlas_resolution_y: u32,
 
+    pub tile_resolution_x: u32,
+    pub tile_resolution_y: u32,
+
     pub num_primitives: u32,
     pub num_primitives_32: u32,
     pub num_primitives_1024: u32,
-
     pub tile_stride: u32,
 
     pub glyphs_buffer: u64,