Allow more agents & dynamic setting of agent count
This commit is contained in:
parent
0f5dd1f820
commit
09e672442b
12 changed files with 144 additions and 49 deletions
28
src/utils/graphics/get-workgroup-counts.ts
Normal file
28
src/utils/graphics/get-workgroup-counts.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
export const getWorkgroupCounts = (
|
||||
device: GPUDevice,
|
||||
invocationCount: number,
|
||||
workgroupSize: number
|
||||
): [number, number, number] => {
|
||||
const workgroupCount = Math.ceil(invocationCount / workgroupSize);
|
||||
|
||||
const workgroupCountX = Math.min(
|
||||
device.limits.maxComputeWorkgroupsPerDimension,
|
||||
workgroupCount
|
||||
);
|
||||
|
||||
const workgroupCountY = Math.min(
|
||||
device.limits.maxComputeWorkgroupsPerDimension,
|
||||
Math.ceil(workgroupCount / workgroupCountX)
|
||||
);
|
||||
|
||||
const workgroupCountZ = Math.min(
|
||||
device.limits.maxComputeWorkgroupsPerDimension,
|
||||
Math.ceil(workgroupCount / workgroupCountX / workgroupCountY)
|
||||
);
|
||||
|
||||
if (workgroupCountX * workgroupCountY * workgroupCountZ < workgroupCount) {
|
||||
throw new Error('Cannot have this many invocations');
|
||||
}
|
||||
|
||||
return [workgroupCountX, workgroupCountY, workgroupCountZ];
|
||||
};
|
||||
|
|
@ -22,10 +22,7 @@ export const initializeGpu = async (): Promise<GPUDevice> => {
|
|||
requiredLimits: {
|
||||
maxBufferSize: adapter.limits.maxBufferSize,
|
||||
maxStorageBufferBindingSize: adapter.limits.maxStorageBufferBindingSize,
|
||||
maxComputeInvocationsPerWorkgroup: adapter.limits.maxComputeInvocationsPerWorkgroup,
|
||||
maxComputeWorkgroupSizeX: adapter.limits.maxComputeWorkgroupSizeX,
|
||||
maxComputeWorkgroupSizeY: adapter.limits.maxComputeWorkgroupSizeY,
|
||||
maxComputeWorkgroupSizeZ: adapter.limits.maxComputeWorkgroupSizeZ,
|
||||
maxComputeWorkgroupsPerDimension: adapter.limits.maxComputeWorkgroupsPerDimension,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue