diff --git a/piet-gpu/shader/binning.comp b/piet-gpu/shader/binning.comp index 17acc76..6812fb6 100644 --- a/piet-gpu/shader/binning.comp +++ b/piet-gpu/shader/binning.comp @@ -78,16 +78,18 @@ void main() { // trying to keep divergence low. // Right now, it's just a bbox, but we'll get finer with // segments. - x0 = clamp(x0, 0, N_TILE_X); - x1 = clamp(x1, x0, N_TILE_X); - y0 = clamp(y0, 0, N_TILE_Y); - y1 = clamp(y1, y0, N_TILE_Y); + uint width_in_bins = (conf.width_in_tiles + N_TILE_X - 1)/N_TILE_X; + uint height_in_bins = (conf.height_in_tiles + N_TILE_Y - 1)/N_TILE_Y; + x0 = clamp(x0, 0, int(width_in_bins)); + x1 = clamp(x1, x0, int(width_in_bins)); + y0 = clamp(y0, 0, int(height_in_bins)); + y1 = clamp(y1, y0, int(height_in_bins)); if (x0 == x1) y1 = y0; int x = x0, y = y0; uint my_slice = gl_LocalInvocationID.x / 32; uint my_mask = 1 << (gl_LocalInvocationID.x & 31); while (y < y1) { - atomicOr(bitmaps[my_slice][y * N_TILE_X + x], my_mask); + atomicOr(bitmaps[my_slice][y * width_in_bins + x], my_mask); x++; if (x == x1) { x = x0; @@ -128,7 +130,7 @@ void main() { x = x0; y = y0; while (y < y1) { - uint bin_ix = y * N_TILE_X + x; + uint bin_ix = y * width_in_bins + x; uint out_mask = bitmaps[my_slice][bin_ix]; if ((out_mask & my_mask) != 0) { uint idx = bitCount(out_mask & (my_mask - 1)); diff --git a/piet-gpu/shader/binning.spv b/piet-gpu/shader/binning.spv index d92b919..7974dac 100644 Binary files a/piet-gpu/shader/binning.spv and b/piet-gpu/shader/binning.spv differ diff --git a/piet-gpu/shader/coarse.comp b/piet-gpu/shader/coarse.comp index c739f91..112a57d 100644 --- a/piet-gpu/shader/coarse.comp +++ b/piet-gpu/shader/coarse.comp @@ -71,7 +71,8 @@ void main() { // Could use either linear or 2d layouts for both dispatch and // invocations within the workgroup. We'll use variables to abstract. - uint bin_ix = N_TILE_X * gl_WorkGroupID.y + gl_WorkGroupID.x; + uint width_in_bins = (conf.width_in_tiles + N_TILE_X - 1)/N_TILE_X; + uint bin_ix = width_in_bins * gl_WorkGroupID.y + gl_WorkGroupID.x; uint partition_ix = 0; uint n_partitions = (conf.n_elements + N_TILE - 1) / N_TILE; uint th_ix = gl_LocalInvocationID.x; diff --git a/piet-gpu/shader/coarse.spv b/piet-gpu/shader/coarse.spv index 0b3e125..8991094 100644 Binary files a/piet-gpu/shader/coarse.spv and b/piet-gpu/shader/coarse.spv differ