Browse Source

Add the skeletons of various GPU particle classes

Panagiotis Christopoulos Charitos 6 years ago
parent
commit
29bcd520d3

+ 19 - 0
shaders/GpuParticles.glslp

@@ -0,0 +1,19 @@
+// Copyright (C) 2009-2019, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+// This shader does a particle simulation
+
+#pragma anki input const UVec3 WORKGROUP_SIZE
+
+#pragma anki start comp
+
+layout(local_size_x = WORKGROUP_SIZE.x, local_size_y = WORKGROUP_SIZE.y, local_size_z = WORKGROUP_SIZE.z) in;
+
+void main()
+{
+	// TODO
+}
+
+#pragma anki end

+ 1 - 0
src/anki/Renderer.h

@@ -31,5 +31,6 @@
 #include <anki/renderer/Bloom.h>
 #include <anki/renderer/Bloom.h>
 #include <anki/renderer/VolumetricLightingAccumulation.h>
 #include <anki/renderer/VolumetricLightingAccumulation.h>
 #include <anki/renderer/GlobalIllumination.h>
 #include <anki/renderer/GlobalIllumination.h>
+#include <anki/renderer/GenericCompute.h>
 
 
 /// @defgroup renderer Renderering system
 /// @defgroup renderer Renderering system

+ 2 - 0
src/anki/Scene.h

@@ -9,6 +9,7 @@
 #include <anki/scene/ModelNode.h>
 #include <anki/scene/ModelNode.h>
 #include <anki/scene/StaticGeometryNode.h>
 #include <anki/scene/StaticGeometryNode.h>
 #include <anki/scene/ParticleEmitterNode.h>
 #include <anki/scene/ParticleEmitterNode.h>
+#include <anki/scene/GpuParticleEmitterNode.h>
 #include <anki/scene/CameraNode.h>
 #include <anki/scene/CameraNode.h>
 #include <anki/scene/LightNode.h>
 #include <anki/scene/LightNode.h>
 #include <anki/scene/StaticCollisionNode.h>
 #include <anki/scene/StaticCollisionNode.h>
@@ -40,6 +41,7 @@
 #include <anki/scene/components/TriggerComponent.h>
 #include <anki/scene/components/TriggerComponent.h>
 #include <anki/scene/components/FogDensityComponent.h>
 #include <anki/scene/components/FogDensityComponent.h>
 #include <anki/scene/components/GlobalIlluminationProbeComponent.h>
 #include <anki/scene/components/GlobalIlluminationProbeComponent.h>
+#include <anki/scene/components/GenericGpuComputeJobComponent.h>
 
 
 #include <anki/scene/events/EventManager.h>
 #include <anki/scene/events/EventManager.h>
 #include <anki/scene/events/Event.h>
 #include <anki/scene/events/Event.h>

+ 24 - 6
src/anki/renderer/DepthDownscale.cpp

@@ -31,9 +31,14 @@ Error DepthDownscale::initInternal(const ConfigSet&)
 	ANKI_R_LOGI("Initializing HiZ. Mip count %u, last mip size %ux%u", m_mipCount, lastMipWidth, lastMipHeight);
 	ANKI_R_LOGI("Initializing HiZ. Mip count %u, last mip size %ux%u", m_mipCount, lastMipWidth, lastMipHeight);
 
 
 	// Create RT descr
 	// Create RT descr
-	m_hizRtDescr = m_r->create2DRenderTargetDescription(width, height, Format::R32_SFLOAT, "HiZ");
-	m_hizRtDescr.m_mipmapCount = m_mipCount;
-	m_hizRtDescr.bake();
+	TextureInitInfo texInit = m_r->create2DRenderTargetInitInfo(width,
+		height,
+		Format::R32_SFLOAT,
+		TextureUsageBit::SAMPLED_FRAGMENT | TextureUsageBit::SAMPLED_COMPUTE | TextureUsageBit::IMAGE_COMPUTE_WRITE,
+		"HiZ");
+	texInit.m_mipmapCount = m_mipCount;
+	texInit.m_initialUsage = TextureUsageBit::SAMPLED_FRAGMENT;
+	m_hizTex = m_r->createAndClearRenderTarget(texInit);
 
 
 	// Progs
 	// Progs
 	ANKI_CHECK(getResourceManager().loadResource("shaders/DepthDownscale.glslp", m_prog));
 	ANKI_CHECK(getResourceManager().loadResource("shaders/DepthDownscale.glslp", m_prog));
@@ -79,6 +84,22 @@ Error DepthDownscale::init(const ConfigSet& cfg)
 	return err;
 	return err;
 }
 }
 
 
+void DepthDownscale::importRenderTargets(RenderingContext& ctx)
+{
+	RenderGraphDescription& rgraph = ctx.m_renderGraphDescr;
+
+	// Import RT
+	if(m_hizTexImportedOnce)
+	{
+		m_runCtx.m_hizRt = rgraph.importRenderTarget(m_hizTex);
+	}
+	else
+	{
+		m_runCtx.m_hizRt = rgraph.importRenderTarget(m_hizTex, TextureUsageBit::SAMPLED_FRAGMENT);
+		m_hizTexImportedOnce = true;
+	}
+}
+
 void DepthDownscale::populateRenderGraph(RenderingContext& ctx)
 void DepthDownscale::populateRenderGraph(RenderingContext& ctx)
 {
 {
 	RenderGraphDescription& rgraph = ctx.m_renderGraphDescr;
 	RenderGraphDescription& rgraph = ctx.m_renderGraphDescr;
@@ -86,9 +107,6 @@ void DepthDownscale::populateRenderGraph(RenderingContext& ctx)
 
 
 	static const Array<CString, 5> passNames = {{"HiZ #0", "HiZ #1", "HiZ #2", "HiZ #3", "HiZ #4"}};
 	static const Array<CString, 5> passNames = {{"HiZ #0", "HiZ #1", "HiZ #2", "HiZ #3", "HiZ #4"}};
 
 
-	// Create render targets
-	m_runCtx.m_hizRt = rgraph.newRenderTarget(m_hizRtDescr);
-
 	// Every pass can do MIPS_WRITTEN_PER_PASS mips
 	// Every pass can do MIPS_WRITTEN_PER_PASS mips
 	for(U i = 0; i < m_mipCount; i += MIPS_WRITTEN_PER_PASS)
 	for(U i = 0; i < m_mipCount; i += MIPS_WRITTEN_PER_PASS)
 	{
 	{

+ 5 - 4
src/anki/renderer/DepthDownscale.h

@@ -12,9 +12,6 @@
 namespace anki
 namespace anki
 {
 {
 
 
-// Forward
-class DepthDownscale;
-
 /// @addtogroup renderer
 /// @addtogroup renderer
 /// @{
 /// @{
 
 
@@ -31,6 +28,9 @@ anki_internal:
 
 
 	ANKI_USE_RESULT Error init(const ConfigSet& cfg);
 	ANKI_USE_RESULT Error init(const ConfigSet& cfg);
 
 
+	/// Import render targets
+	void importRenderTargets(RenderingContext& ctx);
+
 	/// Populate the rendergraph.
 	/// Populate the rendergraph.
 	void populateRenderGraph(RenderingContext& ctx);
 	void populateRenderGraph(RenderingContext& ctx);
 
 
@@ -56,7 +56,8 @@ anki_internal:
 private:
 private:
 	static const U32 MIPS_WRITTEN_PER_PASS = 2;
 	static const U32 MIPS_WRITTEN_PER_PASS = 2;
 
 
-	RenderTargetDescription m_hizRtDescr;
+	TexturePtr m_hizTex;
+	Bool m_hizTexImportedOnce = false;
 	ShaderProgramResourcePtr m_prog;
 	ShaderProgramResourcePtr m_prog;
 	ShaderProgramPtr m_grProg;
 	ShaderProgramPtr m_grProg;
 	U32 m_mipCount = 0;
 	U32 m_mipCount = 0;

+ 52 - 0
src/anki/renderer/GenericCompute.cpp

@@ -0,0 +1,52 @@
+// Copyright (C) 2009-2019, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#include <anki/renderer/GenericCompute.h>
+#include <anki/renderer/Renderer.h>
+#include <anki/renderer/DepthDownscale.h>
+#include <anki/renderer/RenderQueue.h>
+
+namespace anki
+{
+
+GenericCompute::~GenericCompute()
+{
+}
+
+void GenericCompute::populateRenderGraph(RenderingContext& ctx)
+{
+	if(ctx.m_renderQueue->m_genericGpuComputeJobs.getSize() == 0)
+	{
+		return;
+	}
+
+	m_runCtx.m_ctx = &ctx;
+
+	ComputeRenderPassDescription& pass = ctx.m_renderGraphDescr.newComputeRenderPass("Generic compute");
+
+	pass.setWork(
+		[](RenderPassWorkContext& rgraphCtx) {
+			GenericCompute* const self = static_cast<GenericCompute*>(rgraphCtx.m_userData);
+			self->run(rgraphCtx);
+		},
+		this,
+		0);
+}
+
+void GenericCompute::run(RenderPassWorkContext& rgraphCtx)
+{
+	ANKI_ASSERT(m_runCtx.m_ctx->m_renderQueue->m_genericGpuComputeJobs.getSize() > 0);
+
+	// Bind some state
+	rgraphCtx.bindTexture(0, 0, m_r->getDepthDownscale().getHiZRt(), TextureSubresourceInfo());
+
+	for(const GenericGpuComputeJobQueueElement& element : m_runCtx.m_ctx->m_renderQueue->m_genericGpuComputeJobs)
+	{
+		ANKI_ASSERT(element.m_callback);
+		element.m_callback(element.m_userData);
+	}
+}
+
+} // end namespace anki

+ 47 - 0
src/anki/renderer/GenericCompute.h

@@ -0,0 +1,47 @@
+// Copyright (C) 2009-2019, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#pragma once
+
+#include <anki/renderer/RendererObject.h>
+
+namespace anki
+{
+
+/// @addtogroup renderer
+/// @{
+
+/// Executes various compute jobs required by the render queue. It's guaranteed to run before light shading and nothing
+/// more. It can access the previous frame's depth buffer.
+class GenericCompute : public RendererObject
+{
+anki_internal:
+	GenericCompute(Renderer* r)
+		: RendererObject(r)
+	{
+	}
+
+	~GenericCompute();
+
+	ANKI_USE_RESULT Error init(const ConfigSet& cfg)
+	{
+		return Error::NONE;
+	}
+
+	/// Populate the rendergraph.
+	void populateRenderGraph(RenderingContext& ctx);
+
+private:
+	class
+	{
+	public:
+		const RenderingContext* m_ctx = nullptr;
+	} m_runCtx;
+
+	void run(RenderPassWorkContext& rgraphCtx);
+};
+/// @}
+
+} // end namespace anki

+ 19 - 0
src/anki/renderer/RenderQueue.h

@@ -66,6 +66,24 @@ public:
 static_assert(
 static_assert(
 	std::is_trivially_destructible<RenderableQueueElement>::value == true, "Should be trivially destructible");
 	std::is_trivially_destructible<RenderableQueueElement>::value == true, "Should be trivially destructible");
 
 
+/// Callback for GenericGpuComputeJobQueueElement.
+using GenericGpuComputeJobQueueElementCallback = void (*)(const void* userData);
+
+/// It has enough info to execute generic compute on the GPU.
+class GenericGpuComputeJobQueueElement final
+{
+public:
+	GenericGpuComputeJobQueueElementCallback m_callback;
+	const void* m_userData;
+
+	GenericGpuComputeJobQueueElement()
+	{
+	}
+};
+
+static_assert(std::is_trivially_destructible<GenericGpuComputeJobQueueElement>::value == true,
+	"Should be trivially destructible");
+
 /// Point light render queue element.
 /// Point light render queue element.
 class PointLightQueueElement final
 class PointLightQueueElement final
 {
 {
@@ -319,6 +337,7 @@ public:
 	WeakArray<DecalQueueElement> m_decals;
 	WeakArray<DecalQueueElement> m_decals;
 	WeakArray<FogDensityQueueElement> m_fogDensityVolumes;
 	WeakArray<FogDensityQueueElement> m_fogDensityVolumes;
 	WeakArray<UiQueueElement> m_uis;
 	WeakArray<UiQueueElement> m_uis;
+	WeakArray<GenericGpuComputeJobQueueElement> m_genericGpuComputeJobs;
 
 
 	/// Applies only if the RenderQueue holds shadow casters. It's the max timesamp of all shadow casters
 	/// Applies only if the RenderQueue holds shadow casters. It's the max timesamp of all shadow casters
 	Timestamp m_shadowRenderablesLastUpdateTimestamp = 0;
 	Timestamp m_shadowRenderablesLastUpdateTimestamp = 0;

+ 1 - 0
src/anki/renderer/Renderer.cpp

@@ -294,6 +294,7 @@ Error Renderer::populateRenderGraph(RenderingContext& ctx)
 	// Import RTs first
 	// Import RTs first
 	m_downscale->importRenderTargets(ctx);
 	m_downscale->importRenderTargets(ctx);
 	m_tonemapping->importRenderTargets(ctx);
 	m_tonemapping->importRenderTargets(ctx);
+	m_depth->importRenderTargets(ctx);
 
 
 	// Populate render graph. WARNING Watch the order
 	// Populate render graph. WARNING Watch the order
 	m_shadowMapping->populateRenderGraph(ctx);
 	m_shadowMapping->populateRenderGraph(ctx);

+ 1 - 0
src/anki/resource/ParticleEmitterResource.h

@@ -7,6 +7,7 @@
 
 
 #include <anki/resource/ResourceObject.h>
 #include <anki/resource/ResourceObject.h>
 #include <anki/resource/RenderingKey.h>
 #include <anki/resource/RenderingKey.h>
+#include <anki/resource/MaterialResource.h>
 #include <anki/Math.h>
 #include <anki/Math.h>
 #include <anki/Gr.h>
 #include <anki/Gr.h>
 
 

+ 11 - 0
src/anki/scene/GpuParticleEmitterNode.cpp

@@ -0,0 +1,11 @@
+// Copyright (C) 2009-2019, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#include <anki/scene/GpuParticleEmitterNode.h>
+
+namespace anki
+{
+
+} // end namespace anki

+ 34 - 0
src/anki/scene/GpuParticleEmitterNode.h

@@ -0,0 +1,34 @@
+// Copyright (C) 2009-2019, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#pragma once
+
+#include <anki/scene/SceneNode.h>
+#include <anki/resource/ParticleEmitterResource.h>
+#include <anki/renderer/RenderQueue.h>
+#include <anki/collision/Obb.h>
+#include <anki/physics/Forward.h>
+
+namespace anki
+{
+
+/// @addtogroup scene
+/// @{
+
+/// The particle emitter scene node. This scene node emitts
+class GpuParticleEmitterNode : public SceneNode
+{
+public:
+	GpuParticleEmitterNode(SceneGraph* scene, CString name);
+
+	~GpuParticleEmitterNode();
+
+	ANKI_USE_RESULT Error init(const CString& filename);
+
+	ANKI_USE_RESULT Error frameUpdate(Second prevUpdateTime, Second crntTime) override;
+};
+/// @}
+
+} // end namespace anki

+ 0 - 2
src/anki/scene/ParticleEmitterNode.h

@@ -14,8 +14,6 @@
 namespace anki
 namespace anki
 {
 {
 
 
-class ParticleEmitterNode;
-
 /// @addtogroup scene
 /// @addtogroup scene
 /// @{
 /// @{
 
 

+ 51 - 0
src/anki/scene/components/GenericGpuComputeJobComponent.h

@@ -0,0 +1,51 @@
+// Copyright (C) 2009-2019, Panagiotis Christopoulos Charitos and contributors.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#pragma once
+
+#include <anki/scene/components/SceneComponent.h>
+
+namespace anki
+{
+
+/// @addtogroup scene
+/// @{
+
+/// Holds some info for GPU compute jobs.
+class GenericGpuComputeJobComponent : public SceneComponent
+{
+public:
+	static const SceneComponentType CLASS_TYPE = SceneComponentType::GENERIC_GPU_COMPUTE_JOB_COMPONENT;
+
+	GenericGpuComputeJobComponent()
+		: SceneComponent(CLASS_TYPE)
+	{
+	}
+
+	~GenericGpuComputeJobComponent()
+	{
+	}
+
+	void setCallback(GenericGpuComputeJobQueueElementCallback callback, const void* userData)
+	{
+		ANKI_ASSERT(callback && userData);
+		m_callback = callback;
+		m_userData = userData;
+	}
+
+	void setupGenericGpuComputeJobQueueElement(GenericGpuComputeJobQueueElement& el)
+	{
+		ANKI_ASSERT(m_callback && m_userData);
+		el.m_callback = m_callback;
+		el.m_userData = m_userData;
+	}
+
+private:
+	GenericGpuComputeJobQueueElementCallback m_callback = nullptr;
+	const void* m_userData = nullptr;
+};
+/// @}
+
+} // end namespace anki

+ 1 - 0
src/anki/scene/components/SceneComponent.h

@@ -35,6 +35,7 @@ enum class SceneComponentType : U16
 	JOINT,
 	JOINT,
 	TRIGGER,
 	TRIGGER,
 	FOG_DENSITY,
 	FOG_DENSITY,
+	GENERIC_GPU_COMPUTE_JOB_COMPONENT,
 	PLAYER_CONTROLLER,
 	PLAYER_CONTROLLER,
 
 
 	COUNT,
 	COUNT,