Browse Source

Add debug drawing support back. Fix validation errors

Panagiotis Christopoulos Charitos 2 years ago
parent
commit
273a69e9dd

+ 2 - 0
AnKi/Gr/Vulkan/CommandBufferImpl.cpp

@@ -60,6 +60,8 @@ Error CommandBufferImpl::init(const CommandBufferInitInfo& init)
 		state.init(m_pool);
 	}
 
+	m_state.setVrsCapable(getGrManagerImpl().getDeviceCapabilities().m_vrs);
+
 	return Error::kNone;
 }
 

+ 1 - 1
AnKi/Gr/Vulkan/Pipeline.cpp

@@ -383,7 +383,7 @@ const VkGraphicsPipelineCreateInfo& PipelineStateTracker::updatePipelineCreateIn
 		 VK_DYNAMIC_STATE_STENCIL_REFERENCE, VK_DYNAMIC_STATE_LINE_WIDTH, VK_DYNAMIC_STATE_DEPTH_BIAS,
 		 VK_DYNAMIC_STATE_FRAGMENT_SHADING_RATE_KHR}};
 
-	dynCi.dynamicStateCount = kDyn.getSize();
+	dynCi.dynamicStateCount = (m_vrsCapable) ? kDyn.getSize() : (kDyn.getSize() - 1);
 	dynCi.pDynamicStates = &kDyn[0];
 	ci.pDynamicState = &dynCi;
 

+ 17 - 22
AnKi/Gr/Vulkan/Pipeline.h

@@ -393,6 +393,11 @@ public:
 		m_pipelineStatisticsEnabled = enable;
 	}
 
+	void setVrsCapable(Bool capable)
+	{
+		m_vrsCapable = capable;
+	}
+
 	/// Flush state
 	void flush(U64& pipelineHash, Bool& stateDirty)
 	{
@@ -427,30 +432,19 @@ private:
 	class DirtyBits
 	{
 	public:
-		Bool m_prog : 1;
-		Bool m_rpass : 1;
-		Bool m_inputAssembler : 1;
-		Bool m_rasterizer : 1;
-		Bool m_depth : 1;
-		Bool m_stencil : 1;
-		Bool m_color : 1;
+		Bool m_prog : 1 = true;
+		Bool m_rpass : 1 = true;
+		Bool m_inputAssembler : 1 = true;
+		Bool m_rasterizer : 1 = true;
+		Bool m_depth : 1 = true;
+		Bool m_stencil : 1 = true;
+		Bool m_color : 1 = true;
 
 		// Vertex
 		BitSet<kMaxVertexAttributes, U8> m_attribs = {true};
 		BitSet<kMaxVertexAttributes, U8> m_vertBindings = {true};
 
 		BitSet<kMaxColorRenderTargets, U8> m_colAttachments = {true};
-
-		DirtyBits()
-			: m_prog(true)
-			, m_rpass(true)
-			, m_inputAssembler(true)
-			, m_rasterizer(true)
-			, m_depth(true)
-			, m_stencil(true)
-			, m_color(true)
-		{
-		}
 	} m_dirty;
 
 	class SetBits
@@ -465,9 +459,9 @@ private:
 	BitSet<kMaxColorRenderTargets, U8> m_shaderColorAttachmentWritemask = {false};
 
 	// Renderpass info
-	Bool m_fbDepth = false;
-	Bool m_fbStencil = false;
-	Bool m_defaultFb = false;
+	Bool m_fbDepth : 1 = false;
+	Bool m_fbStencil : 1 = false;
+	Bool m_defaultFb : 1 = false;
 	BitSet<kMaxColorRenderTargets, U8> m_fbColorAttachmentMask = {false};
 
 	class Hashes
@@ -512,7 +506,8 @@ private:
 		VkPipelineRasterizationStateRasterizationOrderAMD m_rasterOrder;
 	} m_ci;
 
-	Bool m_pipelineStatisticsEnabled = false;
+	Bool m_pipelineStatisticsEnabled : 1 = false;
+	Bool m_vrsCapable : 1 = false;
 
 	Bool updateHashes();
 	void updateSuperHash();

+ 118 - 48
AnKi/Renderer/Dbg.cpp

@@ -43,6 +43,14 @@ Error Dbg::init()
 	m_fbDescr.m_depthStencilAttachment.m_aspect = DepthStencilAspectBit::kDepth;
 	m_fbDescr.bake();
 
+	ResourceManager& rsrcManager = *getExternalSubsystems().m_resourceManager;
+	ANKI_CHECK(m_drawer.init(&rsrcManager, getExternalSubsystems().m_grManager));
+	ANKI_CHECK(rsrcManager.loadResource("EngineAssets/GiProbe.ankitex", m_giProbeImage));
+	ANKI_CHECK(rsrcManager.loadResource("EngineAssets/LightBulb.ankitex", m_pointLightImage));
+	ANKI_CHECK(rsrcManager.loadResource("EngineAssets/SpotLight.ankitex", m_spotLightImage));
+	ANKI_CHECK(rsrcManager.loadResource("EngineAssets/GreenDecal.ankitex", m_decalImage));
+	ANKI_CHECK(rsrcManager.loadResource("EngineAssets/Mirror.ankitex", m_reflectionImage));
+
 	return Error::kNone;
 }
 
@@ -56,25 +64,12 @@ void Dbg::run(RenderPassWorkContext& rgraphCtx, const RenderingContext& ctx)
 	cmdb->setViewport(0, 0, m_r->getInternalResolution().x(), m_r->getInternalResolution().y());
 	cmdb->setDepthWrite(false);
 
-	cmdb->bindSampler(0, 0, m_r->getSamplers().m_nearestNearestClamp);
+	cmdb->bindSampler(0, 1, m_r->getSamplers().m_nearestNearestClamp);
 
-	rgraphCtx.bindTexture(0, 1, m_r->getGBuffer().getDepthRt(), TextureSubresourceInfo(DepthStencilAspectBit::kDepth));
+	rgraphCtx.bindTexture(0, 2, m_r->getGBuffer().getDepthRt(), TextureSubresourceInfo(DepthStencilAspectBit::kDepth));
 
 	cmdb->setBlendFactors(0, BlendFactor::kSrcAlpha, BlendFactor::kOneMinusSrcAlpha);
-
-	// Set the context
-	RenderQueueDrawContext dctx;
-	dctx.m_viewMatrix = ctx.m_renderQueue->m_viewMatrix;
-	dctx.m_viewProjectionMatrix = ctx.m_renderQueue->m_viewProjectionMatrix;
-	dctx.m_projectionMatrix = ctx.m_renderQueue->m_projectionMatrix;
-	dctx.m_cameraTransform = ctx.m_renderQueue->m_cameraTransform;
-	dctx.m_rebarStagingPool = m_r->getExternalSubsystems().m_rebarStagingPool;
-	dctx.m_framePool = ctx.m_tempPool;
-	dctx.m_commandBuffer = cmdb;
-	dctx.m_sampler = m_r->getSamplers().m_trilinearRepeatAniso;
-	dctx.m_key = RenderingKey(RenderingTechnique::kForward, 0, false, false);
-	dctx.m_debugDraw = true;
-	dctx.m_debugDrawFlags = m_debugDrawFlags;
+	cmdb->setDepthCompareOperation((m_depthTestOn) ? CompareOperation::kLess : CompareOperation::kAlways);
 
 	// Draw renderables
 	const U32 threadId = rgraphCtx.m_currentSecondLevelCommandBufferIndex;
@@ -83,51 +78,100 @@ void Dbg::run(RenderPassWorkContext& rgraphCtx, const RenderingContext& ctx)
 	U32 start, end;
 	splitThreadedProblem(threadId, threadCount, problemSize, start, end);
 
-	// TODO
-#if 0
+	RebarStagingGpuMemoryPool& rebar = *getExternalSubsystems().m_rebarStagingPool;
+
+	// Renderables
 	for(U32 i = start; i < end; ++i)
 	{
 		const RenderableQueueElement& el = ctx.m_renderQueue->m_renderables[i];
-		Array<void*, 1> a = {const_cast<void*>(el.m_userData)};
-		el.m_callback(dctx, a);
+
+		const Vec3 tsl = (el.m_aabbMin + el.m_aabbMax) / 2.0f;
+		constexpr F32 kMargin = 0.1f;
+		const Vec3 scale = (el.m_aabbMax - el.m_aabbMin + kMargin) / 2.0f;
+
+		// Set non uniform scale. Add a margin to avoid flickering
+		Mat3 nonUniScale = Mat3::getZero();
+
+		nonUniScale(0, 0) = scale.x();
+		nonUniScale(1, 1) = scale.y();
+		nonUniScale(2, 2) = scale.z();
+
+		const Mat4 mvp = ctx.m_matrices.m_viewProjection * Mat4(tsl.xyz1(), Mat3::getIdentity() * nonUniScale, 1.0f);
+
+		m_drawer.drawCube(mvp, Vec4(1.0f, 0.0f, 1.0f, 1.0f), 2.0f, m_ditheredDepthTestOn, 2.0f, rebar, cmdb);
 	}
 
-	// Draw forward shaded
+	// Forward shaded renderables
 	if(threadId == 0)
 	{
 		for(const RenderableQueueElement& el : ctx.m_renderQueue->m_forwardShadingRenderables)
 		{
-			Array<void*, 1> a = {const_cast<void*>(el.m_userData)};
-			el.m_callback(dctx, a);
+			const Vec3 tsl = (el.m_aabbMin + el.m_aabbMax) / 2.0f;
+			constexpr F32 kMargin = 0.1f;
+			const Vec3 scale = (el.m_aabbMax - el.m_aabbMin + kMargin) / 2.0f;
+
+			// Set non uniform scale. Add a margin to avoid flickering
+			Mat3 nonUniScale = Mat3::getZero();
+
+			nonUniScale(0, 0) = scale.x();
+			nonUniScale(1, 1) = scale.y();
+			nonUniScale(2, 2) = scale.z();
+
+			const Mat4 mvp =
+				ctx.m_matrices.m_viewProjection * Mat4(tsl.xyz1(), Mat3::getIdentity() * nonUniScale, 1.0f);
+
+			m_drawer.drawCube(mvp, Vec4(1.0f, 0.0f, 1.0f, 1.0f), 2.0f, m_ditheredDepthTestOn, 2.0f, rebar, cmdb);
 		}
 	}
-#endif
 
-	// Draw probes
+	// GI probes
 	if(threadId == 0)
 	{
 		for(const GlobalIlluminationProbeQueueElement& el : ctx.m_renderQueue->m_giProbes)
 		{
-			Array<void*, 1> a = {const_cast<void*>(el.m_debugDrawCallbackUserData)};
-			el.m_debugDrawCallback(dctx, a);
+			const Vec3 tsl = (el.m_aabbMax + el.m_aabbMin) / 2.0f;
+			const Vec3 scale = (tsl - el.m_aabbMin);
+
+			// Set non uniform scale.
+			Mat3 rot = Mat3::getIdentity();
+			rot(0, 0) *= scale.x();
+			rot(1, 1) *= scale.y();
+			rot(2, 2) *= scale.z();
+
+			const Mat4 mvp = ctx.m_matrices.m_viewProjection * Mat4(tsl.xyz1(), rot, 1.0f);
+
+			m_drawer.drawCubes(ConstWeakArray<Mat4>(&mvp, 1), Vec4(0.729f, 0.635f, 0.196f, 1.0f), 1.0f,
+							   m_ditheredDepthTestOn, 2.0f, rebar, cmdb);
+
+			m_drawer.drawBillboardTextures(ctx.m_matrices.m_projection, ctx.m_matrices.m_view,
+										   ConstWeakArray<Vec3>(&tsl, 1), Vec4(1.0f), m_ditheredDepthTestOn,
+										   m_giProbeImage->getTextureView(), m_r->getSamplers().m_trilinearRepeatAniso,
+										   Vec2(0.75f), rebar, cmdb);
 		}
 	}
 
-	// Draw lights
+	// Lights
 	if(threadId == 0)
 	{
-		U32 count = ctx.m_renderQueue->m_pointLights.getSize();
-		while(count--)
+		for(const PointLightQueueElement& el : ctx.m_renderQueue->m_pointLights)
 		{
-			const PointLightQueueElement& el = ctx.m_renderQueue->m_pointLights[count];
-			Array<void*, 1> a = {const_cast<void*>(el.m_debugDrawCallbackUserData)};
-			el.m_debugDrawCallback(dctx, a);
+			Vec3 color = el.m_diffuseColor.xyz();
+			color /= max(max(color.x(), color.y()), color.z());
+
+			m_drawer.drawBillboardTexture(ctx.m_matrices.m_projection, ctx.m_matrices.m_view, el.m_worldPosition,
+										  color.xyz1(), m_ditheredDepthTestOn, m_pointLightImage->getTextureView(),
+										  m_r->getSamplers().m_trilinearRepeatAniso, Vec2(0.75f), rebar, cmdb);
 		}
 
 		for(const SpotLightQueueElement& el : ctx.m_renderQueue->m_spotLights)
 		{
-			Array<void*, 1> a = {const_cast<void*>(el.m_debugDrawCallbackUserData)};
-			el.m_debugDrawCallback(dctx, a);
+			Vec3 color = el.m_diffuseColor.xyz();
+			color /= max(max(color.x(), color.y()), color.z());
+
+			m_drawer.drawBillboardTexture(ctx.m_matrices.m_projection, ctx.m_matrices.m_view,
+										  el.m_worldTransform.getTranslationPart().xyz(), color.xyz1(),
+										  m_ditheredDepthTestOn, m_spotLightImage->getTextureView(),
+										  m_r->getSamplers().m_trilinearRepeatAniso, Vec2(0.75f), rebar, cmdb);
 		}
 	}
 
@@ -136,8 +180,25 @@ void Dbg::run(RenderPassWorkContext& rgraphCtx, const RenderingContext& ctx)
 	{
 		for(const DecalQueueElement& el : ctx.m_renderQueue->m_decals)
 		{
-			Array<void*, 1> a = {const_cast<void*>(el.m_debugDrawCallbackUserData)};
-			el.m_debugDrawCallback(dctx, a);
+			const Mat3 rot = el.m_obbRotation;
+			const Vec4 tsl = el.m_obbCenter.xyz1();
+			const Vec3 scale = el.m_obbExtend;
+
+			Mat3 nonUniScale = Mat3::getZero();
+			nonUniScale(0, 0) = scale.x();
+			nonUniScale(1, 1) = scale.y();
+			nonUniScale(2, 2) = scale.z();
+
+			const Mat4 mvp = ctx.m_matrices.m_viewProjection * Mat4(tsl, rot * nonUniScale, 1.0f);
+
+			m_drawer.drawCubes(ConstWeakArray<Mat4>(&mvp, 1), Vec4(0.0f, 1.0f, 0.0f, 1.0f), 1.0f, m_ditheredDepthTestOn,
+							   2.0f, rebar, cmdb);
+
+			const Vec3 pos = el.m_obbCenter;
+			m_drawer.drawBillboardTextures(ctx.m_matrices.m_projection, ctx.m_matrices.m_view,
+										   ConstWeakArray<Vec3>(&pos, 1), Vec4(1.0f), m_ditheredDepthTestOn,
+										   m_decalImage->getTextureView(), m_r->getSamplers().m_trilinearRepeatAniso,
+										   Vec2(0.75f), rebar, cmdb);
 		}
 	}
 
@@ -146,20 +207,29 @@ void Dbg::run(RenderPassWorkContext& rgraphCtx, const RenderingContext& ctx)
 	{
 		for(const ReflectionProbeQueueElement& el : ctx.m_renderQueue->m_reflectionProbes)
 		{
-			Array<void*, 1> a = {const_cast<void*>(el.m_debugDrawCallbackUserData)};
-			el.m_debugDrawCallback(dctx, a);
-		}
-	}
+			const Vec3 tsl = el.m_worldPosition;
+			const Vec3 scale = (el.m_aabbMax - el.m_aabbMin);
 
-	// GI probes
-	if(threadId == 0)
-	{
-		for(const GlobalIlluminationProbeQueueElement& el : ctx.m_renderQueue->m_giProbes)
-		{
-			Array<void*, 1> a = {const_cast<void*>(el.m_debugDrawCallbackUserData)};
-			el.m_debugDrawCallback(dctx, a);
+			// Set non uniform scale.
+			Mat3 rot = Mat3::getIdentity();
+			rot(0, 0) *= scale.x();
+			rot(1, 1) *= scale.y();
+			rot(2, 2) *= scale.z();
+
+			const Mat4 mvp = ctx.m_matrices.m_viewProjection * Mat4(tsl.xyz1(), rot, 1.0f);
+
+			m_drawer.drawCubes(ConstWeakArray<Mat4>(&mvp, 1), Vec4(0.0f, 0.0f, 1.0f, 1.0f), 1.0f, m_ditheredDepthTestOn,
+							   2.0f, rebar, cmdb);
+
+			m_drawer.drawBillboardTextures(ctx.m_matrices.m_projection, ctx.m_matrices.m_view,
+										   ConstWeakArray<Vec3>(&el.m_worldPosition, 1), Vec4(1.0f),
+										   m_ditheredDepthTestOn, m_reflectionImage->getTextureView(),
+										   m_r->getSamplers().m_trilinearRepeatAniso, Vec2(0.75f), rebar, cmdb);
 		}
 	}
+
+	// Restore state
+	cmdb->setDepthCompareOperation(CompareOperation::kLess);
 }
 
 void Dbg::populateRenderGraph(RenderingContext& ctx)

+ 18 - 7
AnKi/Renderer/Dbg.h

@@ -6,6 +6,7 @@
 #pragma once
 
 #include <AnKi/Renderer/RendererObject.h>
+#include <AnKi/Renderer/DebugDrawer.h>
 #include <AnKi/Gr.h>
 #include <AnKi/Util/Enum.h>
 #include <AnKi/Renderer/RenderQueue.h>
@@ -35,38 +36,48 @@ public:
 
 	Bool getDepthTestEnabled() const
 	{
-		return m_debugDrawFlags.get(RenderQueueDebugDrawFlag::kDepthTestOn);
+		return m_depthTestOn;
 	}
 
 	void setDepthTestEnabled(Bool enable)
 	{
-		m_debugDrawFlags.set(RenderQueueDebugDrawFlag::kDepthTestOn, enable);
+		m_depthTestOn = enable;
 	}
 
 	void switchDepthTestEnabled()
 	{
-		m_debugDrawFlags.flip(RenderQueueDebugDrawFlag::kDepthTestOn);
+		m_depthTestOn = !m_depthTestOn;
 	}
 
 	Bool getDitheredDepthTestEnabled() const
 	{
-		return m_debugDrawFlags.get(RenderQueueDebugDrawFlag::kDitheredDepthTestOn);
+		return m_ditheredDepthTestOn;
 	}
 
 	void setDitheredDepthTestEnabled(Bool enable)
 	{
-		m_debugDrawFlags.set(RenderQueueDebugDrawFlag::kDitheredDepthTestOn, enable);
+		m_ditheredDepthTestOn = enable;
 	}
 
 	void switchDitheredDepthTestEnabled()
 	{
-		m_debugDrawFlags.flip(RenderQueueDebugDrawFlag::kDitheredDepthTestOn);
+		m_ditheredDepthTestOn = !m_ditheredDepthTestOn;
 	}
 
 private:
 	RenderTargetDescription m_rtDescr;
 	FramebufferDescription m_fbDescr;
-	BitSet<U(RenderQueueDebugDrawFlag::kCount), U32> m_debugDrawFlags = {false};
+
+	DebugDrawer2 m_drawer;
+
+	ImageResourcePtr m_giProbeImage;
+	ImageResourcePtr m_pointLightImage;
+	ImageResourcePtr m_spotLightImage;
+	ImageResourcePtr m_decalImage;
+	ImageResourcePtr m_reflectionImage;
+
+	Bool m_depthTestOn : 1 = false;
+	Bool m_ditheredDepthTestOn : 1 = false;
 
 	class
 	{

+ 15 - 22
AnKi/Scene/DebugDrawer.cpp → AnKi/Renderer/DebugDrawer.cpp

@@ -3,13 +3,12 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
-#include <AnKi/Scene/DebugDrawer.h>
+#include <AnKi/Renderer/DebugDrawer.h>
 #include <AnKi/Resource/ResourceManager.h>
 #include <AnKi/Renderer/RenderQueue.h>
 #include <AnKi/Core/GpuMemoryPools.h>
 #include <AnKi/Physics/PhysicsWorld.h>
 #include <AnKi/Gr/Buffer.h>
-#include <AnKi/Collision.h>
 
 namespace anki {
 
@@ -142,8 +141,7 @@ void DebugDrawer2::drawCubes(ConstWeakArray<Mat4> mvps, const Vec4& color, F32 l
 {
 	// Set the uniforms
 	RebarGpuMemoryToken unisToken;
-	Mat4* pmvps =
-		static_cast<Mat4*>(stagingGpuAllocator.allocateFrame(sizeof(Mat4) * mvps.getSize() + sizeof(Vec4), unisToken));
+	Mat4* pmvps = static_cast<Mat4*>(stagingGpuAllocator.allocateFrame(sizeof(Mat4) * mvps.getSize(), unisToken));
 
 	if(cubeSideSize == 2.0f)
 	{
@@ -154,23 +152,21 @@ void DebugDrawer2::drawCubes(ConstWeakArray<Mat4> mvps, const Vec4& color, F32 l
 		ANKI_ASSERT(!"TODO");
 	}
 
-	Vec4* pcolor = reinterpret_cast<Vec4*>(pmvps + mvps.getSize());
-	*pcolor = color;
-
 	// Setup state
 	ShaderProgramResourceVariantInitInfo variantInitInfo(m_prog);
 	variantInitInfo.addMutation("COLOR_TEXTURE", 0);
 	variantInitInfo.addMutation("DITHERED_DEPTH_TEST", U32(ditherFailedDepth != 0));
-	variantInitInfo.addConstant("kInstanceCount", mvps.getSize());
 	const ShaderProgramResourceVariant* variant;
 	m_prog->getOrCreateVariant(variantInitInfo, variant);
 	cmdb->bindShaderProgram(variant->getProgram());
 
+	cmdb->setPushConstants(&color, sizeof(color));
+
 	cmdb->setVertexAttribute(0, 0, Format::kR32G32B32_Sfloat, 0);
 	cmdb->bindVertexBuffer(0, m_cubePositionsBuffer, 0, sizeof(Vec3));
 	cmdb->bindIndexBuffer(m_cubeIndicesBuffer, 0, IndexType::kU16);
 
-	cmdb->bindUniformBuffer(1, 0, stagingGpuAllocator.getBuffer(), unisToken.m_offset, unisToken.m_range);
+	cmdb->bindStorageBuffer(0, 0, stagingGpuAllocator.getBuffer(), unisToken.m_offset, unisToken.m_range);
 
 	cmdb->setLineWidth(lineSize);
 	constexpr U kIndexCount = 12 * 2;
@@ -192,26 +188,23 @@ void DebugDrawer2::drawLines(ConstWeakArray<Mat4> mvps, const Vec4& color, F32 l
 
 	// Set the uniforms
 	RebarGpuMemoryToken unisToken;
-	Mat4* pmvps =
-		static_cast<Mat4*>(stagingGpuAllocator.allocateFrame(sizeof(Mat4) * mvps.getSize() + sizeof(Vec4), unisToken));
-
+	Mat4* pmvps = static_cast<Mat4*>(stagingGpuAllocator.allocateFrame(sizeof(Mat4) * mvps.getSize(), unisToken));
 	memcpy(pmvps, &mvps[0], mvps.getSizeInBytes());
-	Vec4* pcolor = reinterpret_cast<Vec4*>(pmvps + mvps.getSize());
-	*pcolor = color;
 
 	// Setup state
 	ShaderProgramResourceVariantInitInfo variantInitInfo(m_prog);
 	variantInitInfo.addMutation("COLOR_TEXTURE", 0);
 	variantInitInfo.addMutation("DITHERED_DEPTH_TEST", U32(ditherFailedDepth != 0));
-	variantInitInfo.addConstant("kInstanceCount", mvps.getSize());
 	const ShaderProgramResourceVariant* variant;
 	m_prog->getOrCreateVariant(variantInitInfo, variant);
 	cmdb->bindShaderProgram(variant->getProgram());
 
+	cmdb->setPushConstants(&color, sizeof(color));
+
 	cmdb->setVertexAttribute(0, 0, Format::kR32G32B32_Sfloat, 0);
 	cmdb->bindVertexBuffer(0, stagingGpuAllocator.getBuffer(), vertsToken.m_offset, sizeof(Vec3));
 
-	cmdb->bindUniformBuffer(1, 0, stagingGpuAllocator.getBuffer(), unisToken.m_offset, unisToken.m_range);
+	cmdb->bindStorageBuffer(0, 0, stagingGpuAllocator.getBuffer(), unisToken.m_offset, unisToken.m_range);
 
 	cmdb->setLineWidth(lineSize);
 	cmdb->drawArrays(PrimitiveTopology::kLines, linePositions.getSize(), mvps.getSize());
@@ -240,8 +233,7 @@ void DebugDrawer2::drawBillboardTextures(const Mat4& projMat, const Mat3x4& view
 
 	// Set the uniforms
 	RebarGpuMemoryToken unisToken;
-	Mat4* pmvps = static_cast<Mat4*>(
-		stagingGpuAllocator.allocateFrame(sizeof(Mat4) * positions.getSize() + sizeof(Vec4), unisToken));
+	Mat4* pmvps = static_cast<Mat4*>(stagingGpuAllocator.allocateFrame(sizeof(Mat4) * positions.getSize(), unisToken));
 
 	const Mat4 camTrf = Mat4(viewMat, Vec4(0.0f, 0.0f, 0.0f, 1.0f)).getInverse();
 	const Vec3 zAxis = camTrf.getZAxis().xyz().getNormalized();
@@ -268,19 +260,20 @@ void DebugDrawer2::drawBillboardTextures(const Mat4& projMat, const Mat3x4& view
 	ShaderProgramResourceVariantInitInfo variantInitInfo(m_prog);
 	variantInitInfo.addMutation("COLOR_TEXTURE", 1);
 	variantInitInfo.addMutation("DITHERED_DEPTH_TEST", U32(ditherFailedDepth != 0));
-	variantInitInfo.addConstant("kInstanceCount", positions.getSize());
 	const ShaderProgramResourceVariant* variant;
 	m_prog->getOrCreateVariant(variantInitInfo, variant);
 	cmdb->bindShaderProgram(variant->getProgram());
 
+	cmdb->setPushConstants(&color, sizeof(color));
+
 	cmdb->setVertexAttribute(0, 0, Format::kR32G32B32_Sfloat, 0);
 	cmdb->setVertexAttribute(1, 1, Format::kR32G32_Sfloat, 0);
 	cmdb->bindVertexBuffer(0, stagingGpuAllocator.getBuffer(), positionsToken.m_offset, sizeof(Vec3));
 	cmdb->bindVertexBuffer(1, stagingGpuAllocator.getBuffer(), uvsToken.m_offset, sizeof(Vec2));
 
-	cmdb->bindUniformBuffer(1, 0, stagingGpuAllocator.getBuffer(), unisToken.m_offset, unisToken.m_range);
-	cmdb->bindSampler(1, 1, sampler);
-	cmdb->bindTexture(1, 2, tex);
+	cmdb->bindStorageBuffer(0, 0, stagingGpuAllocator.getBuffer(), unisToken.m_offset, unisToken.m_range);
+	cmdb->bindSampler(0, 3, sampler);
+	cmdb->bindTexture(0, 4, tex);
 
 	cmdb->drawArrays(PrimitiveTopology::kTriangleStrip, 4, positions.getSize());
 }

+ 1 - 2
AnKi/Scene/DebugDrawer.h → AnKi/Renderer/DebugDrawer.h

@@ -5,7 +5,7 @@
 
 #pragma once
 
-#include <AnKi/Scene/Common.h>
+#include <AnKi/Renderer/Common.h>
 #include <AnKi/Math.h>
 #include <AnKi/Gr.h>
 #include <AnKi/Physics/PhysicsDrawer.h>
@@ -15,7 +15,6 @@
 namespace anki {
 
 // Forward
-class RenderQueueDrawContext;
 class RebarStagingGpuMemoryPool;
 class RebarGpuMemoryToken;
 

+ 3 - 38
AnKi/Renderer/RenderQueue.h

@@ -26,30 +26,6 @@ public:
 	Mat4 m_previousViewProjectionMatrix;
 };
 
-/// Some options that can be used as hints in debug drawcalls.
-enum class RenderQueueDebugDrawFlag : U32
-{
-	kDepthTestOn,
-	kDitheredDepthTestOn,
-	kCount
-};
-
-/// Context that contains variables for drawing and will be passed to RenderQueueDrawCallback.
-class RenderQueueDrawContext final : public RenderingMatrices
-{
-public:
-	RenderingKey m_key;
-	CommandBufferPtr m_commandBuffer;
-	SamplerPtr m_sampler; ///< A trilinear sampler with anisotropy.
-	RebarStagingGpuMemoryPool* m_rebarStagingPool ANKI_DEBUG_CODE(= nullptr);
-	StackMemoryPool* m_framePool = nullptr;
-	Bool m_debugDraw; ///< If true the drawcall should be drawing some kind of debug mesh.
-	BitSet<U(RenderQueueDebugDrawFlag::kCount), U32> m_debugDrawFlags = {false};
-};
-
-/// Draw callback for drawing.
-using RenderQueueDrawCallback = void (*)(RenderQueueDrawContext& ctx, ConstWeakArray<void*> userData);
-
 /// Render queue element that contains info on items that populate the G-buffer or the forward shading buffer etc.
 class RenderableQueueElement final
 {
@@ -77,6 +53,9 @@ public:
 
 	F32 m_distanceFromCamera; ///< Don't set this. Visibility will.
 
+	Vec3 m_aabbMin;
+	Vec3 m_aabbMax;
+
 	Bool m_indexed;
 	PrimitiveTopology m_primitiveTopology;
 
@@ -136,8 +115,6 @@ public:
 	F32 m_radius;
 	Vec3 m_diffuseColor;
 	Array<RenderQueue*, 6> m_shadowRenderQueues;
-	RenderQueueDrawCallback m_debugDrawCallback;
-	const void* m_debugDrawCallbackUserData;
 
 	Array<Vec2, 6> m_shadowAtlasTileOffsets; ///< Renderer internal.
 	F32 m_shadowAtlasTileSize; ///< Renderer internal.
@@ -167,8 +144,6 @@ public:
 	Vec3 m_diffuseColor;
 	Array<Vec3, 4> m_edgePoints;
 	RenderQueue* m_shadowRenderQueue;
-	RenderQueueDrawCallback m_debugDrawCallback;
-	const void* m_debugDrawCallbackUserData;
 
 	U8 m_shadowLayer; ///< Renderer internal.
 
@@ -189,8 +164,6 @@ class DirectionalLightQueueElement final
 public:
 	Array<Mat4, kMaxShadowCascades> m_textureMatrices;
 	Array<RenderQueue*, kMaxShadowCascades> m_shadowRenderQueues;
-	RenderQueueDrawCallback m_drawCallback;
-	const void* m_drawCallbackUserData;
 	U64 m_uuid; ///< Zero means that there is no dir light
 	Vec3 m_diffuseColor;
 	Vec3 m_direction;
@@ -226,8 +199,6 @@ public:
 	U64 m_uuid;
 	ReflectionProbeQueueElementFeedbackCallback m_feedbackCallback;
 	void* m_feedbackCallbackUserData;
-	RenderQueueDrawCallback m_debugDrawCallback;
-	const void* m_debugDrawCallbackUserData;
 	Array<RenderQueue*, 6> m_renderQueues;
 	Vec3 m_worldPosition;
 	Vec3 m_aabbMin;
@@ -251,8 +222,6 @@ public:
 	U64 m_uuid;
 	GlobalIlluminationProbeQueueElementFeedbackCallback m_feedbackCallback;
 	void* m_feedbackCallbackUserData;
-	RenderQueueDrawCallback m_debugDrawCallback;
-	const void* m_debugDrawCallbackUserData;
 	Array<RenderQueue*, 6> m_renderQueues;
 	Vec3 m_aabbMin;
 	Vec3 m_aabbMax;
@@ -285,8 +254,6 @@ class LensFlareQueueElement final
 public:
 	/// Totaly unsafe but we can't have a smart ptr in here since there will be no deletion.
 	const TextureView* m_textureView;
-	const void* m_userData;
-	RenderQueueDrawCallback m_drawCallback;
 	Vec3 m_worldPosition;
 	Vec2 m_firstFlareSize;
 	Vec4 m_colorMultiplier;
@@ -301,8 +268,6 @@ static_assert(std::is_trivially_destructible<LensFlareQueueElement>::value == tr
 class DecalQueueElement final
 {
 public:
-	RenderQueueDrawCallback m_debugDrawCallback;
-	const void* m_debugDrawCallbackUserData;
 	U32 m_diffuseBindlessTextureIndex;
 	U32 m_roughnessMetalnessBindlessTextureIndex;
 	F32 m_diffuseBlendFactor;

+ 0 - 2
AnKi/Scene/Components/DecalComponent.h

@@ -67,8 +67,6 @@ public:
 		el.m_obbCenter = m_obb.getCenter().xyz();
 		el.m_obbExtend = m_obb.getExtend().xyz();
 		el.m_obbRotation = m_obb.getRotation().getRotationPart();
-		el.m_debugDrawCallback = nullptr;
-		el.m_debugDrawCallbackUserData = this;
 	}
 
 private:

+ 0 - 2
AnKi/Scene/Components/GlobalIlluminationProbeComponent.h

@@ -87,8 +87,6 @@ public:
 		el.m_uuid = m_uuid;
 		el.m_feedbackCallback = giProbeQueueElementFeedbackCallback;
 		el.m_feedbackCallbackUserData = this;
-		el.m_debugDrawCallback = nullptr;
-		el.m_debugDrawCallbackUserData = this;
 		el.m_renderQueues = {};
 		el.m_aabbMin = -m_halfSize + m_worldPos;
 		el.m_aabbMax = m_halfSize + m_worldPos;

+ 0 - 2
AnKi/Scene/Components/LensFlareComponent.h

@@ -73,8 +73,6 @@ public:
 		el.m_firstFlareSize = m_firstFlareSize;
 		el.m_colorMultiplier = m_colorMul;
 		el.m_textureView = m_image->getTextureView().get();
-		el.m_userData = this;
-		el.m_drawCallback = nullptr;
 	}
 
 private:

+ 0 - 2
AnKi/Scene/Components/LightComponent.cpp

@@ -181,8 +181,6 @@ void LightComponent::setupDirectionalLightQueueElement(const Frustum& primaryFru
 
 	const U32 shadowCascadeCount = cascadeFrustums.getSize();
 
-	el.m_drawCallback = nullptr;
-	el.m_drawCallbackUserData = this;
 	el.m_uuid = m_uuid;
 	el.m_diffuseColor = m_diffColor.xyz();
 	el.m_direction = -m_worldTransform.getRotation().getZAxis().xyz();

+ 0 - 4
AnKi/Scene/Components/LightComponent.h

@@ -135,8 +135,6 @@ public:
 		el.m_worldPosition = m_worldTransform.getOrigin().xyz();
 		el.m_radius = m_point.m_radius;
 		el.m_diffuseColor = m_diffColor.xyz();
-		el.m_debugDrawCallback = nullptr;
-		el.m_debugDrawCallbackUserData = this;
 		el.m_shadowLayer = kMaxU8;
 	}
 
@@ -151,8 +149,6 @@ public:
 		el.m_innerAngle = m_spot.m_innerAngle;
 		el.m_diffuseColor = m_diffColor.xyz();
 		el.m_edgePoints = m_spot.m_edgePointsWspace;
-		el.m_debugDrawCallback = nullptr;
-		el.m_debugDrawCallbackUserData = this;
 		el.m_shadowLayer = kMaxU8;
 	}
 

+ 3 - 0
AnKi/Scene/Components/ModelComponent.cpp

@@ -277,6 +277,9 @@ void ModelComponent::setupRenderableQueueElements(U32 lod, RenderingTechnique te
 		queueElem.m_indexed = true;
 		queueElem.m_primitiveTopology = PrimitiveTopology::kTriangles;
 
+		queueElem.m_aabbMin = m_spatial.getAabbWorldSpace().getMin().xyz();
+		queueElem.m_aabbMax = m_spatial.getAabbWorldSpace().getMax().xyz();
+
 		queueElem.computeMergeKey();
 
 		++renderableCount;

+ 2 - 0
AnKi/Scene/Components/ParticleEmitterComponent.cpp

@@ -464,6 +464,8 @@ void ParticleEmitterComponent::setupRenderableQueueElements(RenderingTechnique t
 	el->m_firstVertex = 0;
 	el->m_indexed = false;
 	el->m_primitiveTopology = PrimitiveTopology::kTriangles;
+	el->m_aabbMin = m_spatial.getAabbWorldSpace().getMin().xyz();
+	el->m_aabbMax = m_spatial.getAabbWorldSpace().getMax().xyz();
 
 	outRenderables.setArray(el, 1);
 }

+ 0 - 1
AnKi/Scene/Components/ParticleEmitterComponent.h

@@ -14,7 +14,6 @@
 namespace anki {
 
 // Forward
-class RenderQueueDrawContext;
 class RenderableQueueElement;
 
 /// @addtogroup scene

+ 0 - 2
AnKi/Scene/Components/ReflectionProbeComponent.h

@@ -58,8 +58,6 @@ public:
 		el.m_aabbMin = -m_halfSize + m_worldPos;
 		el.m_aabbMax = m_halfSize + m_worldPos;
 		el.m_textureArrayIndex = kMaxU32;
-		el.m_debugDrawCallback = nullptr;
-		el.m_debugDrawCallbackUserData = this;
 	}
 
 private:

+ 0 - 3
AnKi/Scene/SceneGraph.cpp

@@ -67,9 +67,6 @@ Error SceneGraph::init(const SceneGraphInitInfo& initInfo)
 	camc->setPerspective(0.1f, 1000.0f, toRad(60.0f), (1080.0f / 1920.0f) * toRad(60.0f));
 	m_mainCam = m_defaultMainCam;
 
-	// Other
-	ANKI_CHECK(m_debugDrawer.init(m_subsystems.m_resourceManager, m_subsystems.m_grManager));
-
 	return Error::kNone;
 }
 

+ 0 - 8
AnKi/Scene/SceneGraph.h

@@ -7,7 +7,6 @@
 
 #include <AnKi/Scene/Common.h>
 #include <AnKi/Scene/SceneNode.h>
-#include <AnKi/Scene/DebugDrawer.h>
 #include <AnKi/Math.h>
 #include <AnKi/Util/HashMap.h>
 #include <AnKi/Core/App.h>
@@ -170,11 +169,6 @@ public:
 		return *m_octree;
 	}
 
-	const DebugDrawer2& getDebugDrawer() const
-	{
-		return m_debugDrawer;
-	}
-
 private:
 	class UpdateSceneNodesCtx;
 
@@ -206,8 +200,6 @@ private:
 
 	SceneGraphStats m_stats;
 
-	DebugDrawer2 m_debugDrawer;
-
 	/// Put a node in the appropriate containers
 	Error registerNode(SceneNode* node);
 	void unregisterNode(SceneNode* node);

+ 2 - 2
AnKi/Shaders/DownscaleBlur.hlsl

@@ -23,7 +23,7 @@ struct Uniforms
 [[vk::push_constant]] ConstantBuffer<Uniforms> g_uniforms;
 
 #if defined(ANKI_COMPUTE_SHADER)
-[[vk::binding(3)]] RWTexture2D<RVec3> g_outUav;
+[[vk::binding(3)]] RWTexture2D<RVec4> g_outUav;
 #endif
 
 #if defined(ANKI_COMPUTE_SHADER)
@@ -58,7 +58,7 @@ RVec3 main([[vk::location(0)]] Vec2 uv : TEXCOORD) : SV_TARGET0
 	}
 
 #if defined(ANKI_COMPUTE_SHADER)
-	g_outUav[svDispatchThreadId.xy] = output;
+	g_outUav[svDispatchThreadId.xy] = RVec4(output, 1.0);
 #else
 	return output;
 #endif

+ 2 - 2
AnKi/Shaders/IndirectDiffuse.hlsl

@@ -36,7 +36,7 @@ ANKI_SPECIALIZATION_CONSTANT_U32(kSampleCount, 0u);
 [[vk::binding(10)]] Texture2D g_historyLengthTex;
 
 #if defined(ANKI_COMPUTE_SHADER)
-[[vk::binding(11)]] RWTexture2D<RVec3> g_outUav;
+[[vk::binding(11)]] RWTexture2D<RVec4> g_outUav;
 #endif
 
 [[vk::push_constant]] ConstantBuffer<IndirectDiffuseUniforms> g_uniforms;
@@ -230,7 +230,7 @@ RVec3 main([[vk::location(0)]] Vec2 uv : TEXCOORD, Vec4 svPosition : SV_POSITION
 
 	// Store color
 #if defined(ANKI_COMPUTE_SHADER)
-	g_outUav[svDispatchThreadId.xy] = outColor;
+	g_outUav[svDispatchThreadId.xy] = RVec4(outColor, 0.0f);
 #else
 	return outColor;
 #endif

+ 4 - 4
AnKi/Shaders/IndirectDiffuseDenoise.hlsl

@@ -18,7 +18,7 @@
 
 #if defined(ANKI_COMPUTE_SHADER)
 #	define THREAD_GROUP_SIZE_SQRT 8
-[[vk::binding(3)]] RWTexture2D<RVec3> g_outUav;
+[[vk::binding(3)]] RWTexture2D<RVec4> g_outUav;
 #endif
 
 [[vk::push_constant]] ConstantBuffer<IndirectDiffuseDenoiseUniforms> g_uniforms;
@@ -52,10 +52,10 @@ RVec3 main([[vk::location(0)]] Vec2 uv : TEXCOORD) : SV_TARGET0
 	if(depthCenter == 1.0)
 	{
 #if defined(ANKI_COMPUTE_SHADER)
-		g_outUav[svDispatchThreadId.xy] = RVec3(0.0, 0.0, 0.0);
+		g_outUav[svDispatchThreadId.xy] = 0.0f;
 		return;
 #else
-		return RVec3(0.0, 0.0, 0.0);
+		return 0.0f;
 #endif
 	}
 
@@ -85,7 +85,7 @@ RVec3 main([[vk::location(0)]] Vec2 uv : TEXCOORD) : SV_TARGET0
 	color /= weight;
 
 #if defined(ANKI_COMPUTE_SHADER)
-	g_outUav[svDispatchThreadId.xy] = color;
+	g_outUav[svDispatchThreadId.xy] = RVec4(color, 0.0f);
 #else
 	return color;
 #endif

+ 42 - 30
AnKi/Shaders/SceneDebug.ankiprog

@@ -3,68 +3,80 @@
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 
+#pragma anki hlsl
+
 #pragma anki mutator COLOR_TEXTURE 0 1
 #pragma anki mutator DITHERED_DEPTH_TEST 0 1
 
-#include <AnKi/Shaders/Common.glsl>
-
-ANKI_SPECIALIZATION_CONSTANT_U32(kInstanceCount, 0u);
+#include <AnKi/Shaders/Common.hlsl>
 
-layout(set = 1, binding = 0, row_major) uniform u0_
+struct Uniforms
 {
-	Mat4 u_mvp[kInstanceCount];
-	Vec4 u_color;
+	Vec4 m_color;
 };
 
-#pragma anki start vert
+[[vk::push_constant]] ConstantBuffer<Uniforms> g_uniforms;
 
-layout(location = 0) in Vec3 in_position;
+[[vk::binding(0)]] StructuredBuffer<Mat4> g_mvps;
+
+struct VertIn
+{
+	[[vk::location(0)]] Vec3 m_position : POSITION;
 #if COLOR_TEXTURE == 1
-layout(location = 1) in Vec2 in_uv;
-layout(location = 0) out Vec2 out_uv;
+	[[vk::location(1)]] Vec2 m_uv : TEXCOORD;
 #endif
+	U32 m_svInstanceId : SV_INSTANCEID;
+};
 
-out gl_PerVertex
+struct VertOut
 {
-	Vec4 gl_Position;
+	Vec4 m_svPosition : SV_POSITION;
+	Vec2 m_uv : TEXCOORD;
 };
 
-void main()
+#pragma anki start vert
+
+VertOut main(VertIn input)
 {
+	VertOut output;
+
 #if COLOR_TEXTURE == 1
-	out_uv = in_uv;
+	output.m_uv = input.m_uv;
 #endif
-	gl_Position = u_mvp[gl_InstanceIndex] * Vec4(in_position, 1.0);
+	output.m_svPosition = mul(g_mvps[input.m_svInstanceId], Vec4(input.m_position, 1.0));
+
+	return output;
 }
 #pragma anki end
 
 #pragma anki start frag
-#include <AnKi/Shaders/ImportanceSampling.glsl>
+#include <AnKi/Shaders/ImportanceSampling.hlsl>
 
 #if COLOR_TEXTURE == 1
-layout(location = 0) in Vec2 in_uv;
-layout(set = 1, binding = 1) uniform sampler u_trilinearRepeatSampler;
-layout(set = 1, binding = 2) uniform texture2D u_tex;
+[[vk::binding(3)]] SamplerState g_trilinearRepeatSampler;
+[[vk::binding(4)]] Texture2D g_tex;
 #endif
 
 // NOTE: Don't eliminate the binding because it confuses the descriptor set creation
 #if DITHERED_DEPTH_TEST == 1
-layout(set = 0, binding = 0) uniform sampler u_nearestAnyClampSampler;
-layout(set = 0, binding = 1) uniform texture2D u_depthRt;
+[[vk::binding(1)]] SamplerState g_nearestAnyClampSampler;
+[[vk::binding(2)]] Texture2D g_depthRt;
 #endif
 
-layout(location = 0) out Vec4 out_color;
-
-void main()
+Vec4 main(VertOut input) : SV_TARGET0
 {
+	ANKI_MAYBE_UNUSED(input);
+
 	// Check if we should skip the frag
 #if DITHERED_DEPTH_TEST == 1
-	const UVec2 random = rand3DPCG16(UVec3(UVec2(gl_FragCoord.xy), 1)).xy;
+	const UVec2 random = rand3DPCG16(UVec3(UVec2(input.m_svPosition.xy), 1)).xy;
 	const Vec2 noise = Vec2(random) / 65536.0;
 	const F32 factor = noise.x * noise.y;
-	const Vec2 uv = gl_FragCoord.xy / Vec2(textureSize(u_depthRt, 0));
-	const F32 depthRef = textureLod(u_depthRt, u_nearestAnyClampSampler, uv, 0.0).r;
-	const Bool depthTestFailed = gl_FragCoord.z >= depthRef;
+	Vec2 texSize;
+	g_depthRt.GetDimensions(texSize.x, texSize.y);
+	const Vec2 uv = input.m_svPosition.xy / texSize;
+	const F32 depthRef = g_depthRt.SampleLevel(g_nearestAnyClampSampler, uv, 0.0).r;
+	const Bool depthTestFailed = input.m_svPosition.z >= depthRef;
 	if(depthTestFailed && factor < 0.5)
 	{
 		discard;
@@ -73,9 +85,9 @@ void main()
 
 	// Write the color
 #if COLOR_TEXTURE == 1
-	out_color = texture(u_tex, u_trilinearRepeatSampler, in_uv) * u_color;
+	return g_tex.Sample(g_trilinearRepeatSampler, input.m_uv) * g_uniforms.m_color;
 #else
-	out_color = u_color;
+	return g_uniforms.m_color;
 #endif
 }
 #pragma anki end

BIN
ThirdParty/Bin/Windows64/dxc.exe


BIN
ThirdParty/Bin/Windows64/dxcompiler.dll