Browse Source

Vulkan: Minor work

Panagiotis Christopoulos Charitos 9 years ago
parent
commit
48c4830b97

+ 2 - 3
src/anki/gr/vulkan/Pipeline.cpp

@@ -187,8 +187,7 @@ const VkGraphicsPipelineCreateInfo& PipelineStateTracker::updatePipelineCreateIn
 	ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
 
 	// Prog
-	ci.pStages = &m_state.m_prog->m_impl->m_shaderCreateInfos[0];
-	ci.stageCount = m_state.m_prog->m_impl->m_shaderCreateInfoCount;
+	ci.pStages = m_state.m_prog->m_impl->getShaderCreateInfos(ci.stageCount);
 
 	// Vert
 	if(!!m_shaderAttributeMask)
@@ -347,7 +346,7 @@ const VkGraphicsPipelineCreateInfo& PipelineStateTracker::updatePipelineCreateIn
 	ci.pDynamicState = &dynCi;
 
 	// The rest
-	ci.layout = m_state.m_prog->m_impl->m_pplineLayout.getHandle();
+	ci.layout = m_state.m_prog->m_impl->getPipelineLayout().getHandle();
 	ci.renderPass = m_rpass;
 	ci.subpass = 0;
 

+ 2 - 2
src/anki/gr/vulkan/Pipeline.h

@@ -331,8 +331,8 @@ public:
 		if(prog != m_state.m_prog)
 		{
 			const ShaderProgramImpl& impl = *prog->m_impl;
-			m_shaderColorAttachmentWritemask = impl.m_colorAttachmentWritemask;
-			m_shaderAttributeMask = impl.m_attributeMask;
+			m_shaderColorAttachmentWritemask = impl.getReflectionInfo().m_colorAttachmentWritemask;
+			m_shaderAttributeMask = impl.getReflectionInfo().m_attributeMask;
 			m_dirty.m_prog = true;
 		}
 	}

+ 5 - 5
src/anki/gr/vulkan/ShaderProgramImpl.cpp

@@ -103,17 +103,17 @@ Error ShaderProgramImpl::init(const Array<ShaderPtr, U(ShaderType::COUNT)>& shad
 	const Bool graphicsProg = !!(shaderMask & ShaderTypeBit::VERTEX);
 	if(graphicsProg)
 	{
-		m_attributeMask = shaders[ShaderType::VERTEX]->m_impl->m_attributeMask;
-		m_colorAttachmentWritemask = shaders[ShaderType::FRAGMENT]->m_impl->m_colorAttachmentWritemask;
+		m_refl.m_attributeMask = shaders[ShaderType::VERTEX]->m_impl->m_attributeMask;
+		m_refl.m_colorAttachmentWritemask = shaders[ShaderType::FRAGMENT]->m_impl->m_colorAttachmentWritemask;
 
-		const U attachmentCount = m_colorAttachmentWritemask.getEnabledBitCount();
+		const U attachmentCount = m_refl.m_colorAttachmentWritemask.getEnabledBitCount();
 		for(U i = 0; i < attachmentCount; ++i)
 		{
-			ANKI_ASSERT(m_colorAttachmentWritemask.get(i) && "Should write to all attachments");
+			ANKI_ASSERT(m_refl.m_colorAttachmentWritemask.get(i) && "Should write to all attachments");
 		}
 	}
 
-	// Cache some values
+	// Init the create infos
 	//
 	if(graphicsProg)
 	{

+ 44 - 8
src/anki/gr/vulkan/ShaderProgramImpl.h

@@ -17,26 +17,62 @@ class PipelineFactory;
 /// @addtogroup vulkan
 /// @{
 
+class ShaderProgramReflectionInfo
+{
+public:
+	BitSet<MAX_COLOR_ATTACHMENTS, U8> m_colorAttachmentWritemask = {false};
+	BitSet<MAX_VERTEX_ATTRIBUTES, U8> m_attributeMask = {false};
+};
+
 /// Shader program implementation.
 class ShaderProgramImpl : public VulkanObject
 {
 public:
+	ShaderProgramImpl(GrManager* manager);
+	~ShaderProgramImpl();
+
+	Error init(const Array<ShaderPtr, U(ShaderType::COUNT)>& shaders);
+
+	Bool isGraphics() const
+	{
+		return m_pplineFactory != nullptr;
+	}
+
+	const VkPipelineShaderStageCreateInfo* getShaderCreateInfos(U32& count) const
+	{
+		ANKI_ASSERT(isGraphics());
+		count = m_shaderCreateInfoCount;
+		return &m_shaderCreateInfos[0];
+	}
+
+	const PipelineLayout& getPipelineLayout() const
+	{
+		return m_pplineLayout;
+	}
+
+	const ShaderProgramReflectionInfo& getReflectionInfo() const
+	{
+		return m_refl;
+	}
+
+	PipelineFactory& getPipelineFactory()
+	{
+		ANKI_ASSERT(m_pplineFactory);
+		return *m_pplineFactory;
+	}
+
+private:
 	Array<ShaderPtr, U(ShaderType::COUNT)> m_shaders;
 
 	Array<VkPipelineShaderStageCreateInfo, U(ShaderType::COUNT) - 1> m_shaderCreateInfos;
 	U32 m_shaderCreateInfoCount = 0;
-	PipelineLayout m_pplineLayout;
 
+	PipelineLayout m_pplineLayout;
 	Array<DescriptorSetLayout, MAX_DESCRIPTOR_SETS> m_descriptorSetLayouts;
-	BitSet<MAX_COLOR_ATTACHMENTS, U8> m_colorAttachmentWritemask = {false};
-	BitSet<MAX_VERTEX_ATTRIBUTES, U8> m_attributeMask = {false};
 
-	PipelineFactory* m_pplineFactory = nullptr; ///< Only for graphics programs.
-
-	ShaderProgramImpl(GrManager* manager);
-	~ShaderProgramImpl();
+	ShaderProgramReflectionInfo m_refl;
 
-	Error init(const Array<ShaderPtr, U(ShaderType::COUNT)>& shaders);
+	PipelineFactory* m_pplineFactory = nullptr; ///< Only for graphics programs.
 };
 /// @}
 

+ 49 - 4
tests/util/HashMap.cpp

@@ -151,9 +151,11 @@ ANKI_TEST(Util, HashMap)
 
 	// Bench it
 	{
-		HashMap<int, int, Hasher, Compare> akMap;
-		std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, HeapAllocator<std::pair<int, int>>> stdMap(
-			10, std::hash<int>(), std::equal_to<int>(), alloc);
+		using AkMap = HashMap<int, int, Hasher, Compare>;
+		AkMap akMap;
+		using StlMap =
+			std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, HeapAllocator<std::pair<int, int>>>;
+		StlMap stdMap(10, std::hash<int>(), std::equal_to<int>(), alloc);
 
 		std::unordered_map<int, int> tmpMap;
 
@@ -161,7 +163,7 @@ ANKI_TEST(Util, HashMap)
 		I64 count = 0;
 
 		// Create a huge set
-		const U COUNT = 1024 * 100;
+		const U COUNT = 1024 * 1024;
 		DynamicArrayAuto<int> vals(alloc);
 		vals.create(COUNT);
 
@@ -219,6 +221,49 @@ ANKI_TEST(Util, HashMap)
 
 		printf("Find bench: STL %f AnKi %f | %f%%\n", stlTime, akTime, stlTime / akTime * 100.0);
 
+		// Create a random set for deletion out of vals
+		tmpMap.clear();
+		const U DEL_COUNT = COUNT / 2;
+		DynamicArrayAuto<AkMap::Iterator> delValsAk(alloc);
+		delValsAk.create(DEL_COUNT);
+
+		DynamicArrayAuto<StlMap::iterator> delValsStl(alloc);
+		delValsStl.create(DEL_COUNT);
+
+		for(U i = 0; i < DEL_COUNT; ++i)
+		{
+			// Put unique keys
+			int v;
+			do
+			{
+				v = vals[rand() % COUNT];
+			} while(tmpMap.find(v) != tmpMap.end());
+			tmpMap[v] = 1;
+
+			delValsAk[i] = akMap.find(v);
+			delValsStl[i] = stdMap.find(v);
+		}
+
+		// Random delete AnKi
+		timer.start();
+		for(U i = 0; i < DEL_COUNT; ++i)
+		{
+			akMap.erase(alloc, delValsAk[i]);
+		}
+		timer.stop();
+		akTime = timer.getElapsedTime();
+
+		// Random delete STL
+		timer.start();
+		for(U i = 0; i < DEL_COUNT; ++i)
+		{
+			stdMap.erase(delValsStl[i]);
+		}
+		timer.stop();
+		stlTime = timer.getElapsedTime();
+
+		printf("Deleting bench: STL %f AnKi %f | %f%%\n", stlTime, akTime, stlTime / akTime * 100.0);
+
 		akMap.destroy(alloc);
 	}
 }