|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
#include "SHpch.h"
|
|
|
|
|
#include "SHParticleSubSustem.h"
|
|
|
|
|
#include "SHParticleSubSystem.h"
|
|
|
|
|
#include "Graphics/Pipeline/SHPipelineLayoutParams.h"
|
|
|
|
|
#include "Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h"
|
|
|
|
|
#include "Graphics/Devices/SHVkLogicalDevice.h"
|
|
|
|
@ -110,8 +110,8 @@ namespace SHADE
|
|
|
|
|
offsets[DYOFF_INDEX_EMITTER] = i * emitterStructAligned;
|
|
|
|
|
offsets[DYOFF_INDEX_PARTICLE_INPUT] = inputOffset;
|
|
|
|
|
offsets[DYOFF_INDEX_PARTICLE_OUTPUT] = outputOffset;
|
|
|
|
|
offsets[DYOFF_INDEX_INDICES_DATA] = i * sizeofIndirectCmd;
|
|
|
|
|
offsets[DYOFF_INDEX_DRAW_DATA] = i * sizeofUint * comp.maxParticles;
|
|
|
|
|
offsets[DYOFF_INDEX_INDICES_DATA] = i * sizeofUint * comp.maxParticles;
|
|
|
|
|
offsets[DYOFF_INDEX_DRAW_DATA] = i * sizeofIndirectCmd;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -134,6 +134,13 @@ namespace SHADE
|
|
|
|
|
{
|
|
|
|
|
auto const& mappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::PARTICLE_RENEDERING);
|
|
|
|
|
|
|
|
|
|
uint32_t instanceCountOffset = sizeof (vk::DrawIndirectCommand) * frameIndex + offsetof(vk::DrawIndirectCommand, instanceCount);
|
|
|
|
|
uint32_t ZERO = 0;
|
|
|
|
|
|
|
|
|
|
// reset instance count to 0
|
|
|
|
|
comp.drawCallData->WriteToMemory (&ZERO, sizeof(uint32_t), 0, instanceCountOffset);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// bind the descriptor sets required for emitting particles
|
|
|
|
|
cmdBuffer->BindDescriptorSet(comp.particleDescriptorSet, SH_PIPELINE_TYPE::COMPUTE, mappings.at(SHPredefinedDescriptorTypes::PARTICLES), comp.dynamicOffsets[frameIndex]);
|
|
|
|
|
|
|
|
|
@ -141,6 +148,11 @@ namespace SHADE
|
|
|
|
|
cmdBuffer->ComputeDispatch((comp.maxParticles / EMITTER_WORKGROUP_SIZE) + 1, 1, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SHParticleSubSystem::RenderComponent(Handle<SHVkCommandBuffer> cmdBuffer, SHParticleEmitterComponent& comp, uint32_t frameIndex) noexcept
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SHParticleSubSystem::Init(Handle<SHVkLogicalDevice> device, Handle<SHVkDescriptorPool> inDescPool, Handle<SHVkRenderpass> compatibleRenderpass, Handle<SHSubpass> subpass, Handle<SHVkShaderModule> VS, Handle<SHVkShaderModule> FS, Handle<SHVkShaderModule> emitCS, Handle<SHVkShaderModule> defaultUpdateCS) noexcept
|
|
|
|
|
{
|
|
|
|
|
descPool = inDescPool;
|
|
|
|
@ -191,11 +203,14 @@ namespace SHADE
|
|
|
|
|
// Get offset into GPU emitter data (for updating)
|
|
|
|
|
uint32_t emitterDataOffset = frameIndex * sizeof (SHParticleEmitterComponent::GPUEmitterStruct);
|
|
|
|
|
|
|
|
|
|
//! Barriers to make sure emitting shader is done completely before update is run.
|
|
|
|
|
//! Every emitter will have its own barrier.
|
|
|
|
|
// Barriers to make sure emitting shader is done completely before update is run.
|
|
|
|
|
// Every emitter will have its own barrier.
|
|
|
|
|
std::vector<vk::BufferMemoryBarrier> preUpdateBarriers{};
|
|
|
|
|
preUpdateBarriers.resize(emitters.size());
|
|
|
|
|
|
|
|
|
|
// If we wanted to be VERY safe, a barrier would be good here to make sure output particles have finish reading input particles in
|
|
|
|
|
// the update compute. HOWEVER since a NUM_FRAME_BUFFERS frames would have passed by then, we will not insert 1 here.
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
|
/* BEGIN EMITTING PARTICES */
|
|
|
|
|
/*-----------------------------------------------------------------------*/
|
|
|
|
@ -280,6 +295,10 @@ namespace SHADE
|
|
|
|
|
auto& emitters = SHComponentManager::GetDense<SHParticleEmitterComponent>();
|
|
|
|
|
|
|
|
|
|
// TODO: Issue barrier for output particle data. Semaphore should also be issued outside in SHGraphicsSystem
|
|
|
|
|
for (auto& emitter : emitters)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SHParticleSubSystem::Exit(void) noexcept
|
|
|
|
|