refactor: update workgroup size in compute shader and dispatch logic

Modified the workgroup size in the state-update compute shader from 1 to 64 for improved parallel processing. Adjusted the dispatch logic in StateUpdatePass to calculate the correct number of workgroups based on the new size, enhancing performance during state updates. Removed unnecessary terrain parameter upload in TerritoryRenderer to streamline resource management.
This commit is contained in:
scamiv
2026-01-16 22:03:48 +01:00
parent 2714454cd7
commit 8d08f72c13
3 changed files with 4 additions and 5 deletions
@@ -316,9 +316,6 @@ export class TerritoryRenderer {
// Upload palette if needed
this.resources.uploadPalette();
// Upload terrain params if needed (theme changed)
this.resources.uploadTerrainParams();
// Upload defense posts if needed (tracks if it was dirty before upload)
const wasDefensePostsDirty = (this.resources as any)
.needsDefensePostsUpload;
@@ -101,7 +101,9 @@ export class StateUpdatePass implements ComputePass {
const pass = encoder.beginComputePass();
pass.setPipeline(this.pipeline);
pass.setBindGroup(0, this.bindGroup);
pass.dispatchWorkgroups(numUpdates);
// Dispatch with workgroup_size(64), so divide by 64 and round up
const workgroupCount = Math.ceil(numUpdates / 64);
pass.dispatchWorkgroups(workgroupCount);
pass.end();
}
@@ -6,7 +6,7 @@ struct Update {
@group(0) @binding(0) var<storage, read> updates: array<Update>;
@group(0) @binding(1) var stateTex: texture_storage_2d<r32uint, write>;
@compute @workgroup_size(1)
@compute @workgroup_size(64)
fn main(@builtin(global_invocation_id) globalId: vec3<u32>) {
let idx = globalId.x;
if (idx >= arrayLength(&updates)) {