more clean up
This commit is contained in:
parent
15e99380b5
commit
ea0304356f
11 changed files with 710 additions and 0 deletions
34
src/pipelines/agents/agent-dispatch.ts
Normal file
34
src/pipelines/agents/agent-dispatch.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
export const AGENT_WORKGROUP_SIZE = 64;
|
||||
export const AGENT_MAX_DISPATCH_WORKGROUPS_PER_DIMENSION = 65_535;
|
||||
export const AGENT_MAX_DISPATCHABLE_COUNT = 0xffffffff;
|
||||
|
||||
export const getAgentDispatchWorkgroups = (agentCount: number): [number, number] => {
|
||||
if (!Number.isFinite(agentCount) || agentCount <= 0) {
|
||||
throw new Error('Agent count must be a positive finite number');
|
||||
}
|
||||
|
||||
const workgroupCount = Math.ceil(agentCount / AGENT_WORKGROUP_SIZE);
|
||||
if (workgroupCount <= AGENT_MAX_DISPATCH_WORKGROUPS_PER_DIMENSION) {
|
||||
return [workgroupCount, 1];
|
||||
}
|
||||
|
||||
const workgroupX = Math.min(
|
||||
Math.ceil(Math.sqrt(workgroupCount)),
|
||||
AGENT_MAX_DISPATCH_WORKGROUPS_PER_DIMENSION
|
||||
);
|
||||
const workgroupY = Math.ceil(workgroupCount / workgroupX);
|
||||
|
||||
if (workgroupY > AGENT_MAX_DISPATCH_WORKGROUPS_PER_DIMENSION) {
|
||||
throw new Error('Agent count exceeds dispatchable workgroup range');
|
||||
}
|
||||
|
||||
return [workgroupX, workgroupY];
|
||||
};
|
||||
|
||||
export const dispatchAgentWorkgroups = (
|
||||
passEncoder: GPUComputePassEncoder,
|
||||
agentCount: number
|
||||
): void => {
|
||||
const [workgroupX, workgroupY] = getAgentDispatchWorkgroups(agentCount);
|
||||
passEncoder.dispatchWorkgroups(workgroupX, workgroupY);
|
||||
};
|
||||
Loading…
Reference in a new issue