Skip to content

Commit 7d50cf9

Browse files
Fix tile mapping and dispatch dimensions
1 parent d8a57f8 commit 7d50cf9

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

src/ImageSharp.Drawing.WebGPU/Shaders/PreparedCompositeFineComputeShader.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,19 +200,21 @@ fn positive_mod(value: i32, divisor: i32) -> i32 {
200200
201201
@compute @workgroup_size(8, 8, 1)
202202
fn cs_main(@builtin(global_invocation_id) global_id: vec3<u32>) {
203-
let tile_index = global_id.z;
203+
let tile_x = global_id.z;
204+
let tile_y = global_id.y / 16u;
205+
let tile_index = tile_y * dispatch_config.tile_count_x + tile_x;
204206
if (tile_index >= dispatch_config.tile_count) {
205207
return;
206208
}
207209
208-
if (global_id.x >= 16u || global_id.y >= 16u) {
210+
let pixel_x = global_id.x;
211+
let pixel_y = global_id.y % 16u;
212+
if (pixel_x >= 16u || pixel_y >= 16u) {
209213
return;
210214
}
211215
212-
let tile_x = tile_index % dispatch_config.tile_count_x;
213-
let tile_y = tile_index / dispatch_config.tile_count_x;
214-
let dest_x = (tile_x * 16u) + global_id.x;
215-
let dest_y = (tile_y * 16u) + global_id.y;
216+
let dest_x = (tile_x * 16u) + pixel_x;
217+
let dest_y = (tile_y * 16u) + pixel_y;
216218
217219
if (dest_x >= dispatch_config.target_width || dest_y >= dispatch_config.target_height) {
218220
return;

src/ImageSharp.Drawing.WebGPU/WebGPUDrawingBackend.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,8 +1108,8 @@ bool LayoutFactory(WebGPU api, Device* device, out BindGroupLayout* layout, out
11081108
flushContext.Api.ComputePassEncoderDispatchWorkgroups(
11091109
passEncoder,
11101110
DivideRoundUp(CompositeTileWidth, CompositeComputeWorkgroupSize),
1111-
DivideRoundUp(CompositeTileHeight, CompositeComputeWorkgroupSize),
1112-
(uint)tileCount);
1111+
DivideRoundUp(CompositeTileHeight, CompositeComputeWorkgroupSize) * (uint)tileCountY,
1112+
(uint)tileCountX);
11131113
}
11141114
finally
11151115
{

0 commit comments

Comments
 (0)