Browse Source

Add debug marker support

Panagiotis Christopoulos Charitos 8 years ago
parent
commit
1cee9741f7

+ 1 - 0
src/anki/core/Config.cpp

@@ -77,6 +77,7 @@ Config::Config()
 	newOption("fullscreenDesktopResolution", false);
 	newOption("fullscreenDesktopResolution", false);
 	newOption("debugContext", false);
 	newOption("debugContext", false);
 	newOption("vsync", false);
 	newOption("vsync", false);
+	newOption("debugMarkers", false);
 
 
 	// Core
 	// Core
 	newOption("core.uniformPerFrameMemorySize", 1024 * 1024 * 16);
 	newOption("core.uniformPerFrameMemorySize", 1024 * 1024 * 16);

+ 38 - 0
src/anki/gr/Common.h

@@ -176,6 +176,44 @@ const U MAX_BINDINGS_PER_DESCRIPTOR_SET = MAX_TEXTURE_BINDINGS + MAX_UNIFORM_BUF
 const U MAX_FRAMES_IN_FLIGHT = 3; ///< Triple buffering.
 const U MAX_FRAMES_IN_FLIGHT = 3; ///< Triple buffering.
 const U MAX_DESCRIPTOR_SETS = 2; ///< Groups that can be bound at the same time.
 const U MAX_DESCRIPTOR_SETS = 2; ///< Groups that can be bound at the same time.
 
 
+const U MAX_GR_OBJECT_NAME_LENGTH = 15;
+
+/// The base of all init infos for GR.
+class GrBaseInitInfo
+{
+public:
+	/// @name The name of the object.
+	GrBaseInitInfo(CString name)
+	{
+		ANKI_ASSERT(name.getLength() > 0 && name.getLength() <= MAX_GR_OBJECT_NAME_LENGTH);
+		memcpy(&m_name[0], &name[0], name.getLength() + 1);
+	}
+
+	GrBaseInitInfo()
+	{
+		m_name[0] = '\0';
+	}
+
+	GrBaseInitInfo(const GrBaseInitInfo& b)
+	{
+		m_name = b.m_name;
+	}
+
+	GrBaseInitInfo& operator=(const GrBaseInitInfo& b)
+	{
+		m_name = b.m_name;
+		return *this;
+	}
+
+	CString getName() const
+	{
+		return (m_name[0] != '\0') ? CString(&m_name[0]) : CString();
+	}
+
+private:
+	Array<char, MAX_GR_OBJECT_NAME_LENGTH + 1> m_name;
+};
+
 /// Compute max number of mipmaps for a 2D texture.
 /// Compute max number of mipmaps for a 2D texture.
 inline U computeMaxMipmapCount2d(U w, U h, U minSizeOfLastMip = 1)
 inline U computeMaxMipmapCount2d(U w, U h, U minSizeOfLastMip = 1)
 {
 {

+ 13 - 2
src/anki/gr/Framebuffer.h

@@ -33,16 +33,25 @@ public:
 
 
 /// Framebuffer initializer. If you require the default framebuffer then set m_colorAttachmentCount to 1 and don't set a
 /// Framebuffer initializer. If you require the default framebuffer then set m_colorAttachmentCount to 1 and don't set a
 /// color texture.
 /// color texture.
-class FramebufferInitInfo
+class FramebufferInitInfo : public GrBaseInitInfo
 {
 {
 public:
 public:
 	Array<FramebufferAttachmentInfo, MAX_COLOR_ATTACHMENTS> m_colorAttachments;
 	Array<FramebufferAttachmentInfo, MAX_COLOR_ATTACHMENTS> m_colorAttachments;
 	U32 m_colorAttachmentCount = 0;
 	U32 m_colorAttachmentCount = 0;
 	FramebufferAttachmentInfo m_depthStencilAttachment;
 	FramebufferAttachmentInfo m_depthStencilAttachment;
 
 
-	FramebufferInitInfo() = default;
+	FramebufferInitInfo()
+		: GrBaseInitInfo()
+	{
+	}
+
+	FramebufferInitInfo(CString name)
+		: GrBaseInitInfo(name)
+	{
+	}
 
 
 	FramebufferInitInfo(const FramebufferInitInfo& b)
 	FramebufferInitInfo(const FramebufferInitInfo& b)
+		: GrBaseInitInfo(b)
 	{
 	{
 		operator=(b);
 		operator=(b);
 	}
 	}
@@ -51,6 +60,8 @@ public:
 
 
 	FramebufferInitInfo& operator=(const FramebufferInitInfo& b)
 	FramebufferInitInfo& operator=(const FramebufferInitInfo& b)
 	{
 	{
+		GrBaseInitInfo::operator=(b);
+
 		for(U i = 0; i < b.m_colorAttachmentCount; i++)
 		for(U i = 0; i < b.m_colorAttachmentCount; i++)
 		{
 		{
 			m_colorAttachments[i] = b.m_colorAttachments[i];
 			m_colorAttachments[i] = b.m_colorAttachments[i];

+ 19 - 0
src/anki/gr/gl/CommandBuffer.cpp

@@ -868,6 +868,25 @@ void CommandBuffer::beginRenderPass(FramebufferPtr fb)
 
 
 void CommandBuffer::endRenderPass()
 void CommandBuffer::endRenderPass()
 {
 {
+	class Command final : public GlCommand
+	{
+	public:
+		FramebufferImpl* m_fb;
+
+		Command(FramebufferImpl* fb)
+			: m_fb(fb)
+		{
+			ANKI_ASSERT(fb);
+		}
+
+		Error operator()(GlState&)
+		{
+			m_fb->endRenderPass();
+			return ErrorCode::NONE;
+		}
+	};
+
+	m_impl->pushBackNewCommand<Command>(m_impl->m_state.m_fb);
 	m_impl->m_state.endRenderPass();
 	m_impl->m_state.endRenderPass();
 }
 }
 
 

+ 13 - 0
src/anki/gr/gl/FramebufferImpl.cpp

@@ -153,6 +153,11 @@ void FramebufferImpl::attachTextureInternal(
 
 
 void FramebufferImpl::bind(const GlState& state)
 void FramebufferImpl::bind(const GlState& state)
 {
 {
+	if(m_in.getName() && getManager().getImplementation().debugMarkersEnabled())
+	{
+		glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, m_glName, 0, &m_in.getName()[0]);
+	}
+
 	if(m_bindDefault)
 	if(m_bindDefault)
 	{
 	{
 		glBindFramebuffer(GL_FRAMEBUFFER, 0);
 		glBindFramebuffer(GL_FRAMEBUFFER, 0);
@@ -259,4 +264,12 @@ void FramebufferImpl::bind(const GlState& state)
 	}
 	}
 }
 }
 
 
+void FramebufferImpl::endRenderPass() const
+{
+	if(m_in.getName() && getManager().getImplementation().debugMarkersEnabled())
+	{
+		glPopDebugGroup();
+	}
+}
+
 } // end namespace anki
 } // end namespace anki

+ 2 - 0
src/anki/gr/gl/FramebufferImpl.h

@@ -35,6 +35,8 @@ public:
 	/// Bind it to the state. Call it in rendering thread
 	/// Bind it to the state. Call it in rendering thread
 	void bind(const GlState& state);
 	void bind(const GlState& state);
 
 
+	void endRenderPass() const;
+
 	U getColorBufferCount() const
 	U getColorBufferCount() const
 	{
 	{
 		return m_in.m_colorAttachmentCount;
 		return m_in.m_colorAttachmentCount;

+ 5 - 0
src/anki/gr/gl/GlObject.h

@@ -72,6 +72,11 @@ public:
 		return *m_manager;
 		return *m_manager;
 	}
 	}
 
 
+	const GrManager& getManager() const
+	{
+		return *m_manager;
+	}
+
 protected:
 protected:
 	GrManager* m_manager = nullptr;
 	GrManager* m_manager = nullptr;
 	GLuint m_glName = 0; ///< OpenGL name
 	GLuint m_glName = 0; ///< OpenGL name

+ 3 - 0
src/anki/gr/gl/GrManagerImpl.cpp

@@ -7,6 +7,7 @@
 #include <anki/gr/GrManager.h>
 #include <anki/gr/GrManager.h>
 #include <anki/gr/gl/RenderingThread.h>
 #include <anki/gr/gl/RenderingThread.h>
 #include <anki/gr/gl/GlState.h>
 #include <anki/gr/gl/GlState.h>
+#include <anki/core/Config.h>
 
 
 namespace anki
 namespace anki
 {
 {
@@ -36,6 +37,8 @@ GrAllocator<U8> GrManagerImpl::getAllocator() const
 
 
 Error GrManagerImpl::init(GrManagerInitInfo& init)
 Error GrManagerImpl::init(GrManagerInitInfo& init)
 {
 {
+	m_debugMarkers = init.m_config->getNumber("debugMarkers");
+
 	// Init the backend of the backend
 	// Init the backend of the backend
 	ANKI_CHECK(createBackend(init));
 	ANKI_CHECK(createBackend(init));
 
 

+ 6 - 0
src/anki/gr/gl/GrManagerImpl.h

@@ -62,11 +62,17 @@ public:
 
 
 	void pinContextToCurrentThread(Bool pin);
 	void pinContextToCurrentThread(Bool pin);
 
 
+	Bool debugMarkersEnabled() const
+	{
+		return m_debugMarkers;
+	}
+
 private:
 private:
 	GrManager* m_manager;
 	GrManager* m_manager;
 	GlState* m_state = nullptr;
 	GlState* m_state = nullptr;
 	RenderingThread* m_thread = nullptr;
 	RenderingThread* m_thread = nullptr;
 	WindowingBackend* m_backend = nullptr; ///< The backend of the backend.
 	WindowingBackend* m_backend = nullptr; ///< The backend of the backend.
+	Bool m_debugMarkers = false;
 
 
 	ANKI_USE_RESULT Error createBackend(GrManagerInitInfo& init);
 	ANKI_USE_RESULT Error createBackend(GrManagerInitInfo& init);
 	void destroyBackend();
 	void destroyBackend();

+ 2 - 2
src/anki/renderer/Bloom.cpp

@@ -35,7 +35,7 @@ Error BloomExposure::init(const ConfigSet& config)
 		SamplingFilter::LINEAR));
 		SamplingFilter::LINEAR));
 
 
 	// Create FBs
 	// Create FBs
-	FramebufferInitInfo fbInit;
+	FramebufferInitInfo fbInit("bloomex");
 	fbInit.m_colorAttachmentCount = 1;
 	fbInit.m_colorAttachmentCount = 1;
 	fbInit.m_colorAttachments[0].m_texture = m_rt;
 	fbInit.m_colorAttachments[0].m_texture = m_rt;
 	fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE;
 	fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE;
@@ -106,7 +106,7 @@ Error BloomUpscale::init(const ConfigSet& config)
 		SamplingFilter::LINEAR));
 		SamplingFilter::LINEAR));
 
 
 	// Create FBs
 	// Create FBs
-	FramebufferInitInfo fbInit;
+	FramebufferInitInfo fbInit("bloomup");
 	fbInit.m_colorAttachmentCount = 1;
 	fbInit.m_colorAttachmentCount = 1;
 	fbInit.m_colorAttachments[0].m_texture = m_rt;
 	fbInit.m_colorAttachments[0].m_texture = m_rt;
 	fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE;
 	fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE;

+ 2 - 2
src/anki/renderer/DepthDownscale.cpp

@@ -28,7 +28,7 @@ Error HalfDepth::init(const ConfigSet&)
 		SamplingFilter::LINEAR));
 		SamplingFilter::LINEAR));
 
 
 	// Create FB
 	// Create FB
-	FramebufferInitInfo fbInit;
+	FramebufferInitInfo fbInit("halfdepth");
 	fbInit.m_depthStencilAttachment.m_texture = m_depthRt;
 	fbInit.m_depthStencilAttachment.m_texture = m_depthRt;
 	fbInit.m_depthStencilAttachment.m_loadOperation = AttachmentLoadOperation::DONT_CARE;
 	fbInit.m_depthStencilAttachment.m_loadOperation = AttachmentLoadOperation::DONT_CARE;
 	fbInit.m_depthStencilAttachment.m_aspect = DepthStencilAspectBit::DEPTH;
 	fbInit.m_depthStencilAttachment.m_aspect = DepthStencilAspectBit::DEPTH;
@@ -91,7 +91,7 @@ Error QuarterDepth::init(const ConfigSet&)
 		TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE | TextureUsageBit::SAMPLED_FRAGMENT,
 		TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE | TextureUsageBit::SAMPLED_FRAGMENT,
 		SamplingFilter::LINEAR));
 		SamplingFilter::LINEAR));
 
 
-	FramebufferInitInfo fbInit;
+	FramebufferInitInfo fbInit("quarterdepth");
 	fbInit.m_colorAttachments[0].m_texture = m_depthRt;
 	fbInit.m_colorAttachments[0].m_texture = m_depthRt;
 	fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE;
 	fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE;
 	fbInit.m_colorAttachmentCount = 1;
 	fbInit.m_colorAttachmentCount = 1;

+ 1 - 1
src/anki/renderer/DownscaleBlur.cpp

@@ -41,7 +41,7 @@ Error DownscaleBlur::initSubpass(U idx, const UVec2& inputTexSize)
 		SamplingFilter::LINEAR));
 		SamplingFilter::LINEAR));
 
 
 	// FB
 	// FB
-	FramebufferInitInfo fbInit;
+	FramebufferInitInfo fbInit("downblur");
 	fbInit.m_colorAttachmentCount = 1;
 	fbInit.m_colorAttachmentCount = 1;
 	fbInit.m_colorAttachments[0].m_texture = pass.m_rt;
 	fbInit.m_colorAttachments[0].m_texture = pass.m_rt;
 	fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE;
 	fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE;

+ 1 - 1
src/anki/renderer/Fs.cpp

@@ -45,7 +45,7 @@ Error Fs::initInternal(const ConfigSet&)
 		TextureUsageBit::SAMPLED_FRAGMENT | TextureUsageBit::FRAMEBUFFER_ATTACHMENT_READ_WRITE,
 		TextureUsageBit::SAMPLED_FRAGMENT | TextureUsageBit::FRAMEBUFFER_ATTACHMENT_READ_WRITE,
 		SamplingFilter::LINEAR));
 		SamplingFilter::LINEAR));
 
 
-	FramebufferInitInfo fbInit;
+	FramebufferInitInfo fbInit("forward");
 	fbInit.m_colorAttachmentCount = 1;
 	fbInit.m_colorAttachmentCount = 1;
 	fbInit.m_colorAttachments[0].m_texture = m_rt;
 	fbInit.m_colorAttachments[0].m_texture = m_rt;
 	fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::CLEAR;
 	fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::CLEAR;

+ 1 - 1
src/anki/renderer/FsUpscale.cpp

@@ -54,7 +54,7 @@ Error FsUpscale::initInternal(const ConfigSet& config)
 	m_r->createDrawQuadShaderProgram(m_frag->getGrShader(), m_prog);
 	m_r->createDrawQuadShaderProgram(m_frag->getGrShader(), m_prog);
 
 
 	// Create FB
 	// Create FB
-	FramebufferInitInfo fbInit;
+	FramebufferInitInfo fbInit("fwdupscale");
 	fbInit.m_colorAttachmentCount = 1;
 	fbInit.m_colorAttachmentCount = 1;
 	fbInit.m_colorAttachments[0].m_texture = m_r->getIs().getRt();
 	fbInit.m_colorAttachments[0].m_texture = m_r->getIs().getRt();
 	fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::LOAD;
 	fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::LOAD;

+ 1 - 1
src/anki/renderer/Is.cpp

@@ -129,7 +129,7 @@ Error Is::initInternal(const ConfigSet& config)
 		TextureUsageBit::SAMPLED_FRAGMENT | TextureUsageBit::FRAMEBUFFER_ATTACHMENT_READ_WRITE,
 		TextureUsageBit::SAMPLED_FRAGMENT | TextureUsageBit::FRAMEBUFFER_ATTACHMENT_READ_WRITE,
 		SamplingFilter::LINEAR));
 		SamplingFilter::LINEAR));
 
 
-	FramebufferInitInfo fbInit;
+	FramebufferInitInfo fbInit("lightp");
 	fbInit.m_colorAttachmentCount = 1;
 	fbInit.m_colorAttachmentCount = 1;
 	fbInit.m_colorAttachments[0].m_texture = m_rt;
 	fbInit.m_colorAttachments[0].m_texture = m_rt;
 	fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE;
 	fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE;

+ 1 - 1
src/anki/renderer/Ms.cpp

@@ -52,7 +52,7 @@ Error Ms::createRt()
 	loadop = AttachmentLoadOperation::CLEAR;
 	loadop = AttachmentLoadOperation::CLEAR;
 #endif
 #endif
 
 
-	FramebufferInitInfo fbInit;
+	FramebufferInitInfo fbInit("gbuffer");
 	fbInit.m_colorAttachmentCount = MS_COLOR_ATTACHMENT_COUNT;
 	fbInit.m_colorAttachmentCount = MS_COLOR_ATTACHMENT_COUNT;
 	fbInit.m_colorAttachments[0].m_texture = m_rt0;
 	fbInit.m_colorAttachments[0].m_texture = m_rt0;
 	fbInit.m_colorAttachments[0].m_loadOperation = loadop;
 	fbInit.m_colorAttachments[0].m_loadOperation = loadop;

+ 1 - 1
src/anki/renderer/Pps.cpp

@@ -47,7 +47,7 @@ Error Pps::initInternal(const ConfigSet& config)
 			TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE | TextureUsageBit::SAMPLED_FRAGMENT,
 			TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE | TextureUsageBit::SAMPLED_FRAGMENT,
 			SamplingFilter::LINEAR));
 			SamplingFilter::LINEAR));
 
 
-		FramebufferInitInfo fbInit;
+		FramebufferInitInfo fbInit("pps");
 		fbInit.m_colorAttachmentCount = 1;
 		fbInit.m_colorAttachmentCount = 1;
 		fbInit.m_colorAttachments[0].m_texture = m_rt;
 		fbInit.m_colorAttachments[0].m_texture = m_rt;
 		fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE;
 		fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE;

+ 1 - 1
src/anki/renderer/Sm.cpp

@@ -71,7 +71,7 @@ Error Sm::initInternal(const ConfigSet& config)
 	// Init 2D layers
 	// Init 2D layers
 	m_spots.create(getAllocator(), config.getNumber("sm.maxLights"));
 	m_spots.create(getAllocator(), config.getNumber("sm.maxLights"));
 
 
-	FramebufferInitInfo fbInit;
+	FramebufferInitInfo fbInit("shadows");
 	fbInit.m_depthStencilAttachment.m_texture = m_spotTexArray;
 	fbInit.m_depthStencilAttachment.m_texture = m_spotTexArray;
 	fbInit.m_depthStencilAttachment.m_loadOperation = AttachmentLoadOperation::CLEAR;
 	fbInit.m_depthStencilAttachment.m_loadOperation = AttachmentLoadOperation::CLEAR;
 	fbInit.m_depthStencilAttachment.m_clearValue.m_depthStencil.m_depth = 1.0;
 	fbInit.m_depthStencilAttachment.m_clearValue.m_depthStencil.m_depth = 1.0;

+ 2 - 2
src/anki/renderer/Ssao.cpp

@@ -39,7 +39,7 @@ Error SsaoMain::init(const ConfigSet& config)
 		SamplingFilter::LINEAR));
 		SamplingFilter::LINEAR));
 
 
 	// FB
 	// FB
-	FramebufferInitInfo fbInit;
+	FramebufferInitInfo fbInit("ssaomain");
 	fbInit.m_colorAttachmentCount = 1;
 	fbInit.m_colorAttachmentCount = 1;
 	fbInit.m_colorAttachments[0].m_texture = m_rt;
 	fbInit.m_colorAttachments[0].m_texture = m_rt;
 	fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE;
 	fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE;
@@ -128,7 +128,7 @@ Error SsaoHBlur::init(const ConfigSet& config)
 		SamplingFilter::LINEAR));
 		SamplingFilter::LINEAR));
 
 
 	// FB
 	// FB
-	FramebufferInitInfo fbInit;
+	FramebufferInitInfo fbInit("ssaoblur");
 	fbInit.m_colorAttachmentCount = 1;
 	fbInit.m_colorAttachmentCount = 1;
 	fbInit.m_colorAttachments[0].m_texture = m_rt;
 	fbInit.m_colorAttachments[0].m_texture = m_rt;
 	fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE;
 	fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE;

+ 1 - 1
src/anki/renderer/Taa.cpp

@@ -41,7 +41,7 @@ Error Taa::initInternal(const ConfigSet& config)
 			TextureUsageBit::SAMPLED_FRAGMENT | TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE,
 			TextureUsageBit::SAMPLED_FRAGMENT | TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE,
 			SamplingFilter::LINEAR));
 			SamplingFilter::LINEAR));
 
 
-		FramebufferInitInfo fbInit;
+		FramebufferInitInfo fbInit("taa");
 		fbInit.m_colorAttachmentCount = 1;
 		fbInit.m_colorAttachmentCount = 1;
 		fbInit.m_colorAttachments[0].m_texture = m_rts[i];
 		fbInit.m_colorAttachments[0].m_texture = m_rts[i];
 		fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE;
 		fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE;

+ 1 - 1
src/anki/renderer/Volumetric.cpp

@@ -139,7 +139,7 @@ Error VolumetricHBlur::init(const ConfigSet& config)
 		SamplingFilter::LINEAR));
 		SamplingFilter::LINEAR));
 
 
 	// Create FBs
 	// Create FBs
-	FramebufferInitInfo fbInit;
+	FramebufferInitInfo fbInit("volumetric");
 	fbInit.m_colorAttachmentCount = 1;
 	fbInit.m_colorAttachmentCount = 1;
 	fbInit.m_colorAttachments[0].m_texture = m_rt;
 	fbInit.m_colorAttachments[0].m_texture = m_rt;
 	fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE;
 	fbInit.m_colorAttachments[0].m_loadOperation = AttachmentLoadOperation::DONT_CARE;