!B (Wavicle) (CE-21275) Release GPUParticle runtimes and ComputePSOs on every level...
[CRYENGINE.git] / Code / CryEngine / RenderDll / XRenderD3D9 / Gpu / Particles / GpuParticleManager.h
blob8cafad80dabb7eb8a9c103c1f98b361273680ad6
1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
3 #pragma once
5 #include <CryRenderer/IGpuParticles.h>
6 #include "GpuParticleFeatureFactory.h"
7 #include "Gpu/GpuBitonicSort.h"
8 #include "GpuParticleComponentRuntime.h"
9 #include <map>
11 namespace gpu_pfx2
14 class CGpuInterfaceFactory;
16 // interface of GPU particle system
17 class CManager : public IManager
19 public:
20 struct SRuntimeRef
22 SRuntimeRef() : m_pComponentRuntime(0), m_firstChild(0), m_numChildren(0) {}
23 SRuntimeRef(IParticleComponentRuntime* pComponentRuntime)
24 : m_pComponentRuntime((CParticleComponentRuntime*)pComponentRuntime)
25 , m_firstChild(0)
26 , m_numChildren(0)
30 CParticleComponentRuntime* m_pComponentRuntime;
31 size_t m_firstChild;
32 size_t m_numChildren;
35 CManager();
37 virtual void BeginFrame() override {}
39 virtual IParticleComponentRuntime* CreateParticleContainer(const SComponentParams& params, TConstArray<IParticleFeature*> features) override;
41 virtual IParticleFeature* CreateParticleFeature(EGpuFeatureType) override;
43 // this needs to be called from the render thread when the renderer
44 // releases resources to release references to ComputePSOs
45 void ReleaseResources() override;
47 virtual void RenderThreadUpdate(CRenderView* pRenderView) override;
48 virtual void RenderThreadPreUpdate(CRenderView* pRenderView) override;
49 virtual void RenderThreadPostUpdate(CRenderView* pRenderView) override;
51 // gets initialized the first time it is called and will allocate buffers
52 // (so make sure its only called from the render thread)
53 gpu::CBitonicSort* GetBitonicSort(CGraphicsPipeline* pGraphicsPipeline);
55 private:
56 std::vector<_smart_ptr<CParticleComponentRuntime>>& GetWriteRuntimes()
58 return m_particleComponentRuntimes[0];
60 std::vector<_smart_ptr<CParticleComponentRuntime>>& GetReadRuntimes()
62 return m_particleComponentRuntimes[1];
65 void Initialize();
67 // in here, gpu resources might be freed
68 void ProcessResources();
70 // this keeps a reference to runtimes so we can control the lifetime and
71 // release resources on the render thread if refcount = 1
72 std::vector<_smart_ptr<CParticleComponentRuntime>> m_particleComponentRuntimes[2];
73 std::vector<_smart_ptr<CFeature>> m_particleFeatureGpuInterfaces;
74 std::vector<_smart_ptr<CFeature>> m_particleFeatureGpuInterfacesInitialization;
76 gpu::CStructuredResource<uint, gpu::BufferFlagsReadWriteReadback> m_counter;
77 gpu::CStructuredResource<uint, gpu::BufferFlagsReadWriteReadback> m_scratch;
78 gpu::CStructuredResource<SReadbackData, gpu::BufferFlagsReadWriteReadback> m_readback;
80 #if (CRY_RENDERER_DIRECT3D >= 111)
81 std::unique_ptr<CClearRegionPass> m_clearRegionPass;
82 #endif
84 int m_numRuntimesReadback;
86 CryCriticalSection m_cs;
88 std::unique_ptr<gpu::CBitonicSort> m_pBitonicSort;
89 CGpuInterfaceFactory m_gpuInterfaceFactory;