浏览代码

Vulkan: Some work on bindings

Panagiotis Christopoulos Charitos 9 年之前
父节点
当前提交
ed6df81eee

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

@@ -173,7 +173,6 @@ const U MAX_BINDINGS_PER_DESCRIPTOR_SET =
 
 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_PER_POOL = 1024; ///< An anoying limit for Vulkan.
 
 /// Compute max number of mipmaps for a 2D texture.
 inline U computeMaxMipmapCount2d(U w, U h, U minSizeOfLastMip = 1)

+ 11 - 0
src/anki/gr/vulkan/CommandBufferImpl.h

@@ -140,6 +140,14 @@ public:
 
 	void bindShaderProgram(ShaderProgramPtr& prog);
 
+	void bindUniformBuffer(U32 set, U32 binding, BufferPtr& buff, PtrSize offset, PtrSize range)
+	{
+		commandCommon();
+		U realBinding = MAX_TEXTURE_BINDINGS + binding;
+		m_dsetState[set].bindUniformBuffer(realBinding, buff.get(), offset, range);
+		m_dsetDirty.set(set);
+	}
+
 private:
 	StackAllocator<U8> m_alloc;
 
@@ -157,6 +165,9 @@ private:
 
 	PipelineStateTracker m_state;
 
+	Array<DescriptorSetState, MAX_DESCRIPTOR_SETS> m_dsetState;
+	BitSet<MAX_DESCRIPTOR_SETS, U8> m_dsetDirty = {false};
+
 	/// @name cleanup_references
 	/// @{
 	List<FramebufferPtr> m_fbList;

+ 2 - 0
src/anki/gr/vulkan/CommandBufferImpl.inl.h

@@ -454,6 +454,8 @@ inline void CommandBufferImpl::drawcallCommon()
 		ANKI_CMD(vkCmdBindPipeline(m_handle, VK_PIPELINE_BIND_POINT_GRAPHICS, ppline.getHandle()), ANY_OTHER_COMMAND);
 	}
 
+	// Bind dsets
+
 	ANKI_TRACE_INC_COUNTER(GR_DRAWCALLS, 1);
 }
 

+ 7 - 9
src/anki/gr/vulkan/DescriptorSet.h

@@ -107,7 +107,7 @@ public:
 		m_layout = layout;
 	}
 
-	void bindTexture(U binding, TexturePtr& tex, DepthStencilAspectBit aspect, VkImageLayout layout)
+	void bindTexture(U binding, Texture* tex, DepthStencilAspectBit aspect, VkImageLayout layout)
 	{
 		m_bindings[binding].m_type = DescriptorType::TEXTURE;
 		m_bindings[binding].m_uuids[0] = m_bindings[binding].m_uuids[1] = tex->getUuid();
@@ -119,7 +119,7 @@ public:
 	}
 
 	void bindTextureAndSampler(
-		U binding, TexturePtr& tex, SamplerPtr& sampler, DepthStencilAspectBit aspect, VkImageLayout layout)
+		U binding, Texture* tex, SamplerPtr& sampler, DepthStencilAspectBit aspect, VkImageLayout layout)
 	{
 		m_bindings[binding].m_type = DescriptorType::TEXTURE;
 		m_bindings[binding].m_uuids[0] = tex->getUuid();
@@ -131,7 +131,7 @@ public:
 		m_bindings[binding].m_tex.m_layout = layout;
 	}
 
-	void bindUniformBuffer(U binding, BufferPtr& buff, PtrSize offset, PtrSize range)
+	void bindUniformBuffer(U binding, Buffer* buff, PtrSize offset, PtrSize range)
 	{
 		m_bindings[binding].m_type = DescriptorType::UNIFORM_BUFFER;
 		m_bindings[binding].m_uuids[0] = m_bindings[binding].m_uuids[1] = buff->getUuid();
@@ -141,7 +141,7 @@ public:
 		m_bindings[binding].m_buff.m_range = range;
 	}
 
-	void bindStorageBuffer(U binding, BufferPtr& buff, PtrSize offset, PtrSize range)
+	void bindStorageBuffer(U binding, Buffer* buff, PtrSize offset, PtrSize range)
 	{
 		m_bindings[binding].m_type = DescriptorType::STORAGE_BUFFER;
 		m_bindings[binding].m_uuids[0] = m_bindings[binding].m_uuids[1] = buff->getUuid();
@@ -151,15 +151,13 @@ public:
 		m_bindings[binding].m_buff.m_range = range;
 	}
 
-	void bindImage(U binding, TexturePtr& tex, U32 level)
+	void bindImage(U binding, Texture* tex, U32 level)
 	{
 		m_bindings[binding].m_type = DescriptorType::IMAGE;
 		m_bindings[binding].m_uuids[0] = m_bindings[binding].m_uuids[1] = tex->getUuid();
 
-		m_bindings[binding].m_tex.m_tex = tex->m_impl.get();
-		m_bindings[binding].m_tex.m_sampler = nullptr;
-		m_bindings[binding].m_tex.m_aspect = DepthStencilAspectBit::NONE;
-		m_bindings[binding].m_tex.m_layout = VK_IMAGE_LAYOUT_GENERAL;
+		m_bindings[binding].m_image.m_tex = tex->m_impl.get();
+		m_bindings[binding].m_image.m_level = level;
 	}
 
 private:

+ 3 - 0
src/anki/gr/vulkan/ShaderImpl.cpp

@@ -327,6 +327,9 @@ void ShaderImpl::doReflection(const std::vector<unsigned int>& spirv)
 			const U32 set = spvc.get_decoration(id, spv::Decoration::DecorationDescriptorSet);
 			const U32 binding = spvc.get_decoration(id, spv::Decoration::DecorationBinding);
 
+			m_descriptorSetMask.set(set);
+			m_activeBindingMask[set].set(set);
+
 			// Check that there are no other descriptors with the same binding
 			for(U i = 0; i < counts[set]; ++i)
 			{

+ 2 - 0
src/anki/gr/vulkan/ShaderImpl.h

@@ -27,6 +27,8 @@ public:
 	Array<DynamicArray<DescriptorBinding>, MAX_DESCRIPTOR_SETS> m_bindings;
 	BitSet<MAX_COLOR_ATTACHMENTS, U8> m_colorAttachmentWritemask = {false};
 	BitSet<MAX_VERTEX_ATTRIBUTES, U8> m_attributeMask = {false};
+	BitSet<MAX_DESCRIPTOR_SETS, U8> m_descriptorSetMask = {false};
+	Array<BitSet<MAX_BINDINGS_PER_DESCRIPTOR_SET, U8>, MAX_DESCRIPTOR_SETS> m_activeBindingMask = {{{false}, {false}}};
 
 	ShaderImpl(GrManager* manager)
 		: VulkanObject(manager)

+ 3 - 0
src/anki/gr/vulkan/ShaderProgramImpl.cpp

@@ -49,6 +49,9 @@ Error ShaderProgramImpl::init(const Array<ShaderPtr, U(ShaderType::COUNT)>& shad
 
 			const ShaderImpl& simpl = *shaders[stype]->m_impl;
 
+			m_refl.m_descriptorSetMask |= simpl.m_descriptorSetMask;
+			m_refl.m_activeBindingMask[set] |= simpl.m_activeBindingMask[set];
+
 			for(U i = 0; i < simpl.m_bindings[set].getSize(); ++i)
 			{
 				Bool bindingFound = false;

+ 2 - 0
src/anki/gr/vulkan/ShaderProgramImpl.h

@@ -22,6 +22,8 @@ class ShaderProgramReflectionInfo
 public:
 	BitSet<MAX_COLOR_ATTACHMENTS, U8> m_colorAttachmentWritemask = {false};
 	BitSet<MAX_VERTEX_ATTRIBUTES, U8> m_attributeMask = {false};
+	BitSet<MAX_DESCRIPTOR_SETS, U8> m_descriptorSetMask = {false};
+	Array<BitSet<MAX_BINDINGS_PER_DESCRIPTOR_SET, U8>, MAX_DESCRIPTOR_SETS> m_activeBindingMask = {{{false}, {false}}};
 };
 
 /// Shader program implementation.

+ 30 - 0
src/anki/util/BitSet.h

@@ -46,6 +46,16 @@ public:
 		return out;
 	}
 
+	/// Bitwise or between this and @a b sets.
+	BitSet& operator|=(const BitSet& b)
+	{
+		for(U i = 0; i < CHUNK_COUNT; ++i)
+		{
+			m_chunks[i] |= b.m_chunks[i];
+		}
+		return *this;
+	}
+
 	/// Bitwise and between this and @a b sets.
 	BitSet operator&(const BitSet& b) const
 	{
@@ -57,6 +67,16 @@ public:
 		return out;
 	}
 
+	/// Bitwise and between this and @a b sets.
+	BitSet& operator&=(const BitSet& b)
+	{
+		for(U i = 0; i < CHUNK_COUNT; ++i)
+		{
+			m_chunks[i] &= b.m_chunks[i];
+		}
+		return *this;
+	}
+
 	/// Bitwise xor between this and @a b sets.
 	BitSet operator^(const BitSet& b) const
 	{
@@ -68,6 +88,16 @@ public:
 		return out;
 	}
 
+	/// Bitwise xor between this and @a b sets.
+	BitSet& operator^=(const BitSet& b)
+	{
+		for(U i = 0; i < CHUNK_COUNT; ++i)
+		{
+			m_chunks[i] ^= b.m_chunks[i];
+		}
+		return *this;
+	}
+
 	Bool operator==(const BitSet& b) const
 	{
 		return memcmp(&m_chunks[0], &b.m_chunks[0], sizeof(m_chunks)) == 0;