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
|
|
@ -1,7 +1,7 @@
|
|||
import { getWorkgroupCounts } from '../../utils/graphics/get-workgroup-counts';
|
||||
import random from '../../utils/graphics/random.wgsl';
|
||||
import { smartCompile } from '../../utils/graphics/smart-compile';
|
||||
import { CommonState } from '../common-state/common-state';
|
||||
import { AGENT_SIZE_IN_BYTES } from './agent-generation/agent';
|
||||
import agentSchme from './agent-generation/agent-schema.wgsl';
|
||||
import { AgentSettings } from './agent-settings';
|
||||
import shader from './agent.wgsl';
|
||||
|
|
@ -10,7 +10,7 @@ import { vec2 } from 'gl-matrix';
|
|||
|
||||
export class AgentPipeline {
|
||||
private static readonly WORKGROUP_SIZE = 64;
|
||||
private static readonly UNIFORM_COUNT = 16;
|
||||
private static readonly UNIFORM_COUNT = 17;
|
||||
|
||||
private readonly bindGroupLayout: GPUBindGroupLayout;
|
||||
private readonly pipeline: GPUComputePipeline;
|
||||
|
|
@ -19,6 +19,8 @@ export class AgentPipeline {
|
|||
private previousTrailMapIn?: GPUTextureView;
|
||||
private previousTrailMapOut?: GPUTextureView;
|
||||
|
||||
private agentCount = 0;
|
||||
|
||||
public constructor(
|
||||
private readonly device: GPUDevice,
|
||||
private readonly commonState: CommonState,
|
||||
|
|
@ -57,13 +59,16 @@ export class AgentPipeline {
|
|||
turnWhenLost,
|
||||
individualTrailWeight,
|
||||
deinfectionProbability,
|
||||
agentCount,
|
||||
}: AgentSettings & {
|
||||
evenGenerationAggression: number;
|
||||
oddGenerationAggression: number;
|
||||
nextGenerationId: number;
|
||||
center: vec2;
|
||||
radius: number;
|
||||
agentCount: number;
|
||||
}) {
|
||||
this.agentCount = agentCount;
|
||||
this.device.queue.writeBuffer(
|
||||
this.uniforms,
|
||||
0,
|
||||
|
|
@ -82,6 +87,7 @@ export class AgentPipeline {
|
|||
turnWhenLost,
|
||||
individualTrailWeight,
|
||||
deinfectionProbability,
|
||||
agentCount,
|
||||
])
|
||||
);
|
||||
}
|
||||
|
|
@ -98,9 +104,7 @@ export class AgentPipeline {
|
|||
this.commonState.execute(passEncoder);
|
||||
passEncoder.setBindGroup(1, this.bindGroup);
|
||||
passEncoder.dispatchWorkgroups(
|
||||
Math.ceil(
|
||||
this.agentsBuffer.size / AGENT_SIZE_IN_BYTES / AgentPipeline.WORKGROUP_SIZE
|
||||
)
|
||||
...getWorkgroupCounts(this.device, this.agentCount, AgentPipeline.WORKGROUP_SIZE)
|
||||
);
|
||||
passEncoder.end();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue