Просмотр исходного кода

Vulkan: Fix a bug. Reset the state tracker after pushing secondary command buffers

Panagiotis Christopoulos Charitos 8 лет назад
Родитель
Сommit
aeaf9077d3

+ 6 - 0
src/anki/gr/vulkan/CommandBufferImpl.cpp

@@ -227,6 +227,12 @@ void CommandBufferImpl::endRenderPass()
 
 	m_activeFb.reset(nullptr);
 	m_state.endRenderPass();
+
+	// After pushing second level command buffers the state is undefined. Reset the tracker
+	if(m_subpassContents == VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS)
+	{
+		m_state.reset();
+	}
 }
 
 void CommandBufferImpl::endRecording()

+ 15 - 0
src/anki/gr/vulkan/Pipeline.cpp

@@ -10,6 +10,21 @@
 namespace anki
 {
 
+void PipelineStateTracker::reset()
+{
+	m_state.reset();
+	m_hashes = {};
+	m_dirty = {};
+	m_set = {};
+	m_shaderAttributeMask.unsetAll();
+	m_shaderColorAttachmentWritemask.unsetAll();
+	m_fbDepth = false;
+	m_fbStencil = false;
+	m_defaultFb = false;
+	m_fbColorAttachmentMask.unsetAll();
+	m_rpass = VK_NULL_HANDLE;
+}
+
 Bool PipelineStateTracker::updateHashes()
 {
 	Bool stateDirty = false;

+ 33 - 21
src/anki/gr/vulkan/Pipeline.h

@@ -134,6 +134,21 @@ class PipelineInfoState : public NonCopyable
 {
 public:
 	PipelineInfoState()
+	{
+		reset();
+	}
+
+	ShaderProgramPtr m_prog;
+	PPVertexStateInfo m_vertex;
+	PPInputAssemblerStateInfo m_inputAssembler;
+	PPTessellationStateInfo m_tessellation;
+	PPViewportStateInfo m_viewport;
+	PPRasterizerStateInfo m_rasterizer;
+	PPDepthStateInfo m_depth;
+	PPStencilStateInfo m_stencil;
+	PPColorStateInfo m_color;
+
+	void reset()
 	{
 		// Do a special construction. The state will be hashed and the padding may contain garbage. With this trick
 		// zero the padding
@@ -153,16 +168,6 @@ public:
 
 #undef ANKI_CONSTRUCT_AND_ZERO_PADDING
 	}
-
-	ShaderProgramPtr m_prog;
-	PPVertexStateInfo m_vertex;
-	PPInputAssemblerStateInfo m_inputAssembler;
-	PPTessellationStateInfo m_tessellation;
-	PPViewportStateInfo m_viewport;
-	PPRasterizerStateInfo m_rasterizer;
-	PPDepthStateInfo m_depth;
-	PPStencilStateInfo m_stencil;
-	PPColorStateInfo m_color;
 };
 
 /// Track changes in the static state.
@@ -409,23 +414,30 @@ public:
 	/// Populate the internal pipeline create info structure.
 	const VkGraphicsPipelineCreateInfo& updatePipelineCreateInfo();
 
+	void reset();
+
 private:
 	PipelineInfoState m_state;
 
 	class Hashes
 	{
 	public:
-		U64 m_prog = 0;
-		Array<U64, MAX_VERTEX_ATTRIBUTES> m_vertexAttribs = {};
-		U64 m_ia = 0;
-		U64 m_raster = 0;
-		U64 m_depth = 0;
-		U64 m_stencil = 0;
-		U64 m_color = 0;
-		Array<U64, MAX_COLOR_ATTACHMENTS> m_colAttachments = {};
-
-		U64 m_superHash = 0;
-		U64 m_lastSuperHash = 0;
+		U64 m_prog;
+		Array<U64, MAX_VERTEX_ATTRIBUTES> m_vertexAttribs;
+		U64 m_ia;
+		U64 m_raster;
+		U64 m_depth;
+		U64 m_stencil;
+		U64 m_color;
+		Array<U64, MAX_COLOR_ATTACHMENTS> m_colAttachments;
+
+		U64 m_superHash;
+		U64 m_lastSuperHash;
+
+		Hashes()
+		{
+			zeroMemory(*this);
+		}
 	} m_hashes;
 
 	class DirtyBits