Graphics Reference
In-Depth Information
thread group size. For example, if we choose the maximum size thread group of [1024,1,1],
we would round our estimated number of particles up to the next multiple of 1024.
But what happens when the additional threads from rounding up try to read from
the consume buffer and no particle data is available? Trying to consume more data than
is present produces an undefined behavior, so we must ensure that this does not hap-
pen. We can manage this by copying the element count to a constant buffer with the
CopyStructureCount method, and then masking off the particle processing code with a
conditional statement to ensure that the appropriate number of elements is processed. The
threading setup is shown in Listing 12.8, along with the required resource declarations.
struct Particle
{
float3 position;
float3 velocity;
float time;
};
AppendStructuredBuffer<Particle> NewSimulationState : register( u0 );
ConsumeStructuredBuffer<Particle> CurrentSimulationState : register( u1 );
cbuffer SimulationParameters
{
float4 TimeFactors;
float4 EmitterLocation;
float4 ConsumerLocation;
};
cbuffer ParticleCount
{
uint4 NumParticles;
};
[numthreads( 512, 1, 1)]
void CSMAIN( uint3 DispatchThreadID : SV_DispatchThneadID )
{
// Check for if this thread should run or not.
uint myID = DispatchThreadID.x
+ DispatchThreadID.y * 512
+ DispatchThreadID.z * 512 * 512;
if ( myID < NumParticles.x )
{
// Perform update process here...
}
}
Listing 12.8. The threading setup used to update all of the particles in the system.
Search WWH ::




Custom Search