Browse Source

Add bone transforms in the material

Panagiotis Christopoulos Charitos 5 years ago
parent
commit
b84c22392c

+ 4 - 4
src/anki/gr/vulkan/DescriptorSet.cpp

@@ -955,9 +955,9 @@ Error DescriptorSetFactory::newDescriptorSetLayout(const DescriptorSetLayoutInit
 
 	if(init.m_bindings.getSize() > 0)
 	{
-		memcpy(&bindings[0], &init.m_bindings[0], init.m_bindings.getSizeInBytes());
-		std::sort(&bindings[0],
-			&bindings[0] + bindingCount,
+		memcpy(bindings.getBegin(), init.m_bindings.getBegin(), init.m_bindings.getSizeInBytes());
+		std::sort(bindings.getBegin(),
+			bindings.getBegin() + bindingCount,
 			[](const DescriptorBinding& a, const DescriptorBinding& b) { return a.m_binding < b.m_binding; });
 
 		hash = computeHash(&bindings[0], init.m_bindings.getSizeInBytes());
@@ -1018,7 +1018,7 @@ Error DescriptorSetFactory::newDescriptorSetLayout(const DescriptorSetLayoutInit
 		if(cache == nullptr)
 		{
 			cache = m_alloc.newInstance<DSLayoutCacheEntry>(this);
-			ANKI_CHECK(cache->init(&bindings[0], bindingCount, hash));
+			ANKI_CHECK(cache->init(bindings.getBegin(), bindingCount, hash));
 
 			m_caches.resize(m_alloc, m_caches.getSize() + 1);
 			m_caches[m_caches.getSize() - 1] = cache;

+ 24 - 0
src/anki/resource/MaterialResource2.cpp

@@ -369,6 +369,30 @@ Error MaterialResource2::parseMutators(XmlElement mutatorsEl)
 		}
 
 		++builtinMutatorCount;
+
+		// Find the binding of the transforms
+		const ShaderProgramBinary& binary = m_prog->getBinary();
+		for(const ShaderProgramBinaryBlock& block : binary.m_storageBlocks)
+		{
+			if(block.m_name.getBegin() == CString("u_ankiBoneTransforms"))
+			{
+				if(block.m_set != m_descriptorSetIdx)
+				{
+					ANKI_RESOURCE_LOGE("The set of u_ankiBoneTransforms should be %u", m_descriptorSetIdx);
+					return Error::USER_DATA;
+				}
+
+				m_boneTrfsBinding = block.m_binding;
+				break;
+			}
+		}
+
+		if(m_boneTrfsBinding == MAX_U32)
+		{
+			ANKI_RESOURCE_LOGE("The program is using the %s mutator but u_ankiBoneTransforms was not found",
+				BUILTIN_MUTATOR_NAMES[BuiltinMutatorId2::BONES].cstr());
+			return Error::NONE;
+		}
 	}
 
 	m_builtinMutators[BuiltinMutatorId2::VELOCITY] =

+ 8 - 1
src/anki/resource/MaterialResource2.h

@@ -319,9 +319,15 @@ public:
 
 	U32 getDescriptorSetIndex() const
 	{
+		ANKI_ASSERT(m_descriptorSetIdx != MAX_U8);
 		return m_descriptorSetIdx;
 	}
 
+	U32 getBoneTransformsBinding() const
+	{
+		return m_boneTrfsBinding;
+	}
+
 	const MaterialVariant2& getOrCreateVariant(const RenderingKey& key) const;
 
 private:
@@ -339,8 +345,9 @@ private:
 	Bool m_shadow = true;
 	Bool m_forwardShading = false;
 	U8 m_lodCount = 1;
-	U8 m_descriptorSetIdx = 0; ///< The material set.
+	U8 m_descriptorSetIdx = MAX_U8; ///< The material set.
 	U32 m_uboIdx = MAX_U32; ///< The b_ankiMaterial UBO inside the binary.
+	U32 m_boneTrfsBinding = MAX_U32;
 
 	/// Matrix of variants.
 	mutable Array5d<MaterialVariant2, U(Pass::COUNT), MAX_LOD_COUNT, MAX_INSTANCE_GROUPS, 2, 2> m_variantMatrix;