From e44e961e14c33f79c716e22979a1d4c1d0c249a0 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Wed, 1 Mar 2023 10:06:09 +0800 Subject: [PATCH] Particles WIP --- .../Particles/SHParticleEmitterComponent.cpp | 1 + .../Particles/SHParticleSubSystem.cpp | 29 +++++++++++++++---- .../MiddleEnd/Particles/SHParticleSubSystem.h | 3 +- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Particles/SHParticleEmitterComponent.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Particles/SHParticleEmitterComponent.cpp index e991e8e1..12690ece 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Particles/SHParticleEmitterComponent.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Particles/SHParticleEmitterComponent.cpp @@ -1,3 +1,4 @@ +#include "SHpch.h" #include "SHParticleEmitterComponent.h" namespace SHADE diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Particles/SHParticleSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Particles/SHParticleSubSystem.cpp index e1d33753..7c3d9c74 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Particles/SHParticleSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Particles/SHParticleSubSystem.cpp @@ -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 cmdBuffer, SHParticleEmitterComponent& comp, uint32_t frameIndex) noexcept + { + + } + void SHParticleSubSystem::Init(Handle device, Handle inDescPool, Handle compatibleRenderpass, Handle subpass, Handle VS, Handle FS, Handle emitCS, Handle 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 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(); // TODO: Issue barrier for output particle data. Semaphore should also be issued outside in SHGraphicsSystem + for (auto& emitter : emitters) + { + + } } void SHParticleSubSystem::Exit(void) noexcept diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Particles/SHParticleSubSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Particles/SHParticleSubSystem.h index 61bd9af4..ed697a59 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Particles/SHParticleSubSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Particles/SHParticleSubSystem.h @@ -78,7 +78,8 @@ namespace SHADE void InitializeComponent (SHParticleEmitterComponent& comp) noexcept; void EmitComponent (Handle cmdBuffer, SHParticleEmitterComponent& comp, uint32_t frameIndex) noexcept; - void UpdateCompoennt (Handle cmdBuffer, SHParticleEmitterComponent& comp, uint32_t frameIndex) noexcept; + void UpdateCompoennt(Handle cmdBuffer, SHParticleEmitterComponent& comp, uint32_t frameIndex) noexcept; + void RenderComponent(Handle cmdBuffer, SHParticleEmitterComponent& comp, uint32_t frameIndex) noexcept; public: void Init(Handle device, Handle inDescPool, Handle compatibleRenderpass, Handle subpass, Handle VS, Handle FS, Handle emitCS, Handle defaultUpdateCS) noexcept;