1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
5 #include <CryRenderer/IGpuParticles.h>
6 #include "GpuParticleFeatureFactory.h"
7 #include "Gpu/GpuBitonicSort.h"
8 #include "GpuParticleComponentRuntime.h"
14 class CGpuInterfaceFactory
;
16 // interface of GPU particle system
17 class CManager
: public IManager
22 SRuntimeRef() : m_pComponentRuntime(0), m_firstChild(0), m_numChildren(0) {}
23 SRuntimeRef(IParticleComponentRuntime
* pComponentRuntime
)
24 : m_pComponentRuntime((CParticleComponentRuntime
*)pComponentRuntime
)
30 CParticleComponentRuntime
* m_pComponentRuntime
;
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
);
56 std::vector
<_smart_ptr
<CParticleComponentRuntime
>>& GetWriteRuntimes()
58 return m_particleComponentRuntimes
[0];
60 std::vector
<_smart_ptr
<CParticleComponentRuntime
>>& GetReadRuntimes()
62 return m_particleComponentRuntimes
[1];
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
;
84 int m_numRuntimesReadback
;
86 CryCriticalSection m_cs
;
88 std::unique_ptr
<gpu::CBitonicSort
> m_pBitonicSort
;
89 CGpuInterfaceFactory m_gpuInterfaceFactory
;