updated simulation chain

This commit is contained in:
Turanszki Janos
2017-10-31 20:39:05 +00:00
parent 87442b0fcb
commit 04ab25c78b
13 changed files with 36 additions and 83 deletions
+2
View File
@@ -824,6 +824,8 @@ void EditorComponent::Load()
decalWnd->SetDecal(nullptr);
envProbeWnd->SetProbe(nullptr);
materialWnd->SetMaterial(nullptr);
emitterWnd->SetObject(nullptr);
forceFieldWnd->SetForceField(nullptr);
});
GetGUI().AddWidget(clearButton);
+2 -2
View File
@@ -235,6 +235,7 @@ void EmitterWindow::SetObject(Object* obj)
{
GetEmitter()->DEBUG = false;
}
debugCheckBox->SetCheck(false);
object = obj;
@@ -310,8 +311,7 @@ void EmitterWindow::UpdateData()
auto data = emitter->GetDebugData();
stringstream ss("");
ss << "Alive Particle Count [CURRENT] = " << data.aliveCount_CURRENT << endl;
ss << "Alive Particle Count [NEW] = " << data.aliveCount_NEW << endl;
ss << "Alive Particle Count = " << data.aliveCount << endl;
ss << "Dead Particle Count = " << data.deadCount << endl;
ss << "GPU Emit count = " << data.realEmitCount << endl;
debugDataLabel->SetText(ss.str());
+1 -2
View File
@@ -19,9 +19,8 @@ struct Particle
struct ParticleCounters
{
uint aliveCount_CURRENT;
uint aliveCount;
uint deadCount;
uint aliveCount_NEW;
uint realEmitCount;
};
@@ -121,10 +121,6 @@
<FxCompile Include="downsampleDepthBuffer4xPS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
</FxCompile>
<FxCompile Include="emittedparticle_drawargsCS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.0</ShaderModel>
</FxCompile>
<FxCompile Include="emittedparticle_emitCS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.0</ShaderModel>
@@ -133,10 +129,6 @@
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.0</ShaderModel>
</FxCompile>
<FxCompile Include="emittedparticle_simulateargsCS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.0</ShaderModel>
</FxCompile>
<FxCompile Include="emittedparticle_simulateCS.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Compute</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">5.0</ShaderModel>
@@ -612,15 +612,9 @@
<FxCompile Include="emittedparticle_emitCS.hlsl">
<Filter>CS</Filter>
</FxCompile>
<FxCompile Include="emittedparticle_drawargsCS.hlsl">
<Filter>CS</Filter>
</FxCompile>
<FxCompile Include="emittedparticle_kickoffUpdateCS.hlsl">
<Filter>CS</Filter>
</FxCompile>
<FxCompile Include="emittedparticle_simulateargsCS.hlsl">
<Filter>CS</Filter>
</FxCompile>
<FxCompile Include="emittedparticle_simulateCS.hlsl">
<Filter>CS</Filter>
</FxCompile>
@@ -1,16 +0,0 @@
#include "globals.hlsli"
#include "ShaderInterop_EmittedParticle.h"
RWSTRUCTUREDBUFFER(counterBuffer, ParticleCounters, 4);
RWRAWBUFFER(indirectDrawBuffer, 5); // indirectdrawinstanced args
[numthreads(1, 1, 1)]
void main(uint3 DTid : SV_DispatchThreadID)
{
// Fill Draw arguments for drawing:
// VertexCountPerInstance;
// InstanceCount;
// StartVertexLocation;
// StartInstanceLocation;
indirectDrawBuffer.Store4(24, uint4(counterBuffer[0].aliveCount_NEW * 6, 1, 0, 0));
}
+4 -4
View File
@@ -2,7 +2,7 @@
#include "ShaderInterop_EmittedParticle.h"
RWSTRUCTUREDBUFFER(particleBuffer, Particle, 0);
RWSTRUCTUREDBUFFER(aliveBuffer_OLD, uint, 1);
RWSTRUCTUREDBUFFER(aliveBuffer_CURRENT, uint, 1);
RWSTRUCTUREDBUFFER(aliveBuffer_NEW, uint, 2);
RWSTRUCTUREDBUFFER(deadBuffer, uint, 3);
RWSTRUCTUREDBUFFER(counterBuffer, ParticleCounters, 4);
@@ -99,8 +99,8 @@ void main(uint3 DTid : SV_DispatchThreadID)
particleBuffer[newParticleIndex] = particle;
// and add index to the alive list (push):
uint aliveCount_OLD;
InterlockedAdd(counterBuffer[0].aliveCount_CURRENT, 1, aliveCount_OLD);
aliveBuffer_OLD[aliveCount_OLD] = newParticleIndex;
uint aliveCount;
InterlockedAdd(counterBuffer[0].aliveCount, 1, aliveCount);
aliveBuffer_CURRENT[aliveCount] = newParticleIndex;
}
}
@@ -2,24 +2,31 @@
#include "ShaderInterop_EmittedParticle.h"
RWSTRUCTUREDBUFFER(counterBuffer, ParticleCounters, 4);
RWRAWBUFFER(indirectDispatchBuffer, 5); // indirect kickoff args
RWRAWBUFFER(indirectBuffers, 5);
[numthreads(1, 1, 1)]
void main(uint3 DTid : SV_DispatchThreadID)
{
// Load dead particle count:
uint deadCount = counterBuffer[0].deadCount;
// Load alive particle count from draw argument buffer (which contains alive particle count * 6):
uint aliveCount_NEW = indirectBuffers.Load(24) / 6;
// we can not emit more than there are free slots in the dead list:
uint realEmitCount = min(deadCount, xEmitCount);
// Fill dispatch argument buffer for simulation:
indirectDispatchBuffer.Store3(0, uint3(ceil((float)realEmitCount / (float)THREADCOUNT_EMIT), 1, 1));
// Fill dispatch argument buffer for emitting (ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ):
indirectBuffers.Store3(0, uint3(ceil((float)realEmitCount / (float)THREADCOUNT_EMIT), 1, 1));
// Fill dispatch argument buffer for simulation (ThreadGroupCountX, ThreadGroupCountY, ThreadGroupCountZ):
indirectBuffers.Store3(12, uint3(ceil((float)(aliveCount_NEW + realEmitCount) / (float)THREADCOUNT_SIMULATION), 1, 1));
// Reset the draw argument buffer to defaults (VertexCountPerInstance, InstanceCount, StartVertexLocation, StartInstanceLocation):
indirectBuffers.Store4(24, uint4(0, 1, 0, 0));
// copy new alivelistcount to current alivelistcount:
counterBuffer[0].aliveCount_CURRENT = counterBuffer[0].aliveCount_NEW;
// also reset the new alive list count:
counterBuffer[0].aliveCount_NEW = 0;
counterBuffer[0].aliveCount = aliveCount_NEW;
// and write real emit count:
counterBuffer[0].realEmitCount = realEmitCount;
+6 -5
View File
@@ -2,10 +2,11 @@
#include "ShaderInterop_EmittedParticle.h"
RWSTRUCTUREDBUFFER(particleBuffer, Particle, 0);
RWSTRUCTUREDBUFFER(aliveBuffer_OLD, uint, 1);
RWSTRUCTUREDBUFFER(aliveBuffer_CURRENT, uint, 1);
RWSTRUCTUREDBUFFER(aliveBuffer_NEW, uint, 2);
RWSTRUCTUREDBUFFER(deadBuffer, uint, 3);
RWSTRUCTUREDBUFFER(counterBuffer, ParticleCounters, 4);
RWRAWBUFFER(indirectBuffers, 5);
#define NUM_LDS_FORCEFIELDS 32
struct LDS_ForceField
@@ -26,7 +27,7 @@ void main(uint3 DTid : SV_DispatchThreadID, uint Gid : SV_GroupIndex)
// Read alive particle count and store in LDS:
if (Gid == 0)
{
aliveParticleCount = counterBuffer[0].aliveCount_CURRENT;
aliveParticleCount = counterBuffer[0].aliveCount;
}
// Load the forcefields into LDS:
@@ -49,7 +50,7 @@ void main(uint3 DTid : SV_DispatchThreadID, uint Gid : SV_GroupIndex)
{
const float dt = g_xFrame_DeltaTime;
uint particleIndex = aliveBuffer_OLD[DTid.x];
uint particleIndex = aliveBuffer_CURRENT[DTid.x];
Particle particle = particleBuffer[particleIndex];
if (particle.life > 0)
@@ -91,8 +92,8 @@ void main(uint3 DTid : SV_DispatchThreadID, uint Gid : SV_GroupIndex)
// add to new alive list:
uint newAliveIndex;
InterlockedAdd(counterBuffer[0].aliveCount_NEW, 1, newAliveIndex);
aliveBuffer_NEW[newAliveIndex] = particleIndex;
indirectBuffers.InterlockedAdd(24, 6, newAliveIndex); // write the draw argument buffer, which should contain particle count * 6
aliveBuffer_NEW[newAliveIndex / 6] = particleIndex; // draw arg buffer contains particle count * 6, so just divide to retrieve correct index
}
else
{
@@ -1,12 +0,0 @@
#include "globals.hlsli"
#include "ShaderInterop_EmittedParticle.h"
RWSTRUCTUREDBUFFER(counterBuffer, ParticleCounters, 4);
RWRAWBUFFER(indirectDispatchBuffer, 5); // indirect simulation args
[numthreads(1, 1, 1)]
void main( uint3 DTid : SV_DispatchThreadID )
{
// Fill dispatch argument buffer for simulation:
indirectDispatchBuffer.Store3(12, uint3(ceil((float)counterBuffer[0].aliveCount_CURRENT / (float)THREADCOUNT_SIMULATION), 1, 1));
}
+2 -16
View File
@@ -14,7 +14,7 @@ using namespace wiGraphicsTypes;
VertexShader *wiEmittedParticle::vertexShader = nullptr;
PixelShader *wiEmittedParticle::pixelShader = nullptr, *wiEmittedParticle::simplestPS = nullptr;
ComputeShader *wiEmittedParticle::kickoffUpdateCS, *wiEmittedParticle::emitCS = nullptr, *wiEmittedParticle::simulateargsCS = nullptr, *wiEmittedParticle::drawargsCS = nullptr, *wiEmittedParticle::simulateCS = nullptr;
ComputeShader *wiEmittedParticle::kickoffUpdateCS, *wiEmittedParticle::emitCS = nullptr, *wiEmittedParticle::simulateCS = nullptr;
BlendState *wiEmittedParticle::blendStateAlpha = nullptr,*wiEmittedParticle::blendStateAdd = nullptr;
RasterizerState *wiEmittedParticle::rasterizerState = nullptr,*wiEmittedParticle::wireFrameRS = nullptr;
DepthStencilState *wiEmittedParticle::depthStencilState = nullptr;
@@ -189,9 +189,8 @@ void wiEmittedParticle::CreateSelfBuffers()
ParticleCounters counters;
counters.aliveCount_CURRENT = 0;
counters.aliveCount = 0;
counters.deadCount = MAX_PARTICLES;
counters.aliveCount_NEW = 0;
counters.realEmitCount = 0;
data.pSysMem = &counters;
@@ -308,18 +307,10 @@ void wiEmittedParticle::UpdateRenderData(GRAPHICSTHREAD threadID)
device->BindCS(emitCS, threadID);
device->DispatchIndirect(indirectBuffers, 0, threadID);
// kick off simulation based on CURRENT alivelist count
device->BindCS(simulateargsCS, threadID);
device->Dispatch(1, 1, 1, threadID);
// update CURRENT alive list, write NEW alive list
device->BindCS(simulateCS, threadID);
device->DispatchIndirect(indirectBuffers, sizeof(wiGraphicsTypes::IndirectDispatchArgs), threadID);
// update the draw arguments
device->BindCS(drawargsCS, threadID);
device->Dispatch(1, 1, 1, threadID);
device->BindCS(nullptr, threadID);
device->UnBindUnorderedAccessResources(0, ARRAYSIZE(uavs), threadID);
@@ -398,8 +389,6 @@ void wiEmittedParticle::LoadShaders()
kickoffUpdateCS = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "emittedparticle_kickoffUpdateCS.cso", wiResourceManager::COMPUTESHADER));
emitCS = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "emittedparticle_emitCS.cso", wiResourceManager::COMPUTESHADER));
simulateargsCS = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "emittedparticle_simulateargsCS.cso", wiResourceManager::COMPUTESHADER));
drawargsCS = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "emittedparticle_drawargsCS.cso", wiResourceManager::COMPUTESHADER));
simulateCS = static_cast<ComputeShader*>(wiResourceManager::GetShaderManager()->add(wiRenderer::SHADERPATH + "emittedparticle_simulateCS.cso", wiResourceManager::COMPUTESHADER));
@@ -508,10 +497,7 @@ void wiEmittedParticle::CleanUpStatic()
SAFE_DELETE(pixelShader);
SAFE_DELETE(simplestPS);
SAFE_DELETE(emitCS);
SAFE_DELETE(simulateargsCS);
SAFE_DELETE(drawargsCS);
SAFE_DELETE(simulateCS);
//SAFE_DELETE(constantBuffer);
SAFE_DELETE(blendStateAlpha);
SAFE_DELETE(blendStateAdd);
SAFE_DELETE(rasterizerState);
+4 -4
View File
@@ -28,10 +28,10 @@ private:
wiGraphicsTypes::GPUBuffer* constantBuffer;
void CreateSelfBuffers();
static wiGraphicsTypes::ComputeShader *kickoffUpdateCS, *emitCS, *simulateargsCS, *drawargsCS, *simulateCS;
static wiGraphicsTypes::VertexShader *vertexShader;
static wiGraphicsTypes::PixelShader *pixelShader,*simplestPS;
static wiGraphicsTypes::BlendState *blendStateAlpha,*blendStateAdd;
static wiGraphicsTypes::ComputeShader *kickoffUpdateCS, *emitCS, *simulateCS;
static wiGraphicsTypes::VertexShader *vertexShader;
static wiGraphicsTypes::PixelShader *pixelShader,*simplestPS;
static wiGraphicsTypes::BlendState *blendStateAlpha,*blendStateAdd;
static wiGraphicsTypes::RasterizerState *rasterizerState,*wireFrameRS;
static wiGraphicsTypes::DepthStencilState *depthStencilState;
+1 -1
View File
@@ -9,7 +9,7 @@ namespace wiVersion
// minor features, major updates
const int minor = 13;
// minor bug fixes, alterations, refactors, updates
const int revision = 71;
const int revision = 72;
long GetVersion()