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

Remove MaterialResource and ShaderProgramResource

Panagiotis Christopoulos Charitos 5 лет назад
Родитель
Сommit
64a26adbf9

+ 0 - 2
src/anki/Resource.h

@@ -10,7 +10,6 @@
 #include <anki/resource/AnimationResource.h>
 #include <anki/resource/ScriptResource.h>
 #include <anki/resource/MeshResource.h>
-#include <anki/resource/MaterialResource.h>
 #include <anki/resource/MaterialResource2.h>
 #include <anki/resource/TextureAtlasResource.h>
 #include <anki/resource/TextureResource.h>
@@ -18,7 +17,6 @@
 #include <anki/resource/SkeletonResource.h>
 #include <anki/resource/DummyResource.h>
 #include <anki/resource/ModelResource.h>
-#include <anki/resource/ShaderProgramResource.h>
 #include <anki/resource/ShaderProgramResource2.h>
 #include <anki/resource/CollisionResource.h>
 

+ 0 - 1
src/anki/renderer/Drawer.cpp

@@ -5,7 +5,6 @@
 
 #include <anki/renderer/Drawer.h>
 #include <anki/renderer/RenderQueue.h>
-#include <anki/resource/MaterialResource.h>
 #include <anki/resource/TextureResource.h>
 #include <anki/renderer/Renderer.h>
 #include <anki/util/Tracer.h>

+ 0 - 1
src/anki/renderer/LightShading.h

@@ -7,7 +7,6 @@
 
 #include <anki/renderer/RendererObject.h>
 #include <anki/resource/TextureResource.h>
-#include <anki/resource/ShaderProgramResource.h>
 
 namespace anki
 {

+ 0 - 1
src/anki/renderer/RendererObject.h

@@ -9,7 +9,6 @@
 #include <anki/util/StdTypes.h>
 #include <anki/Gr.h>
 #include <anki/resource/ResourceManager.h>
-#include <anki/resource/ShaderProgramResource.h>
 #include <anki/resource/ShaderProgramResource2.h>
 #include <anki/core/StagingGpuMemoryManager.h>
 

+ 0 - 1
src/anki/renderer/TraditionalDeferredShading.cpp

@@ -6,7 +6,6 @@
 #include <anki/renderer/TraditionalDeferredShading.h>
 #include <anki/renderer/RenderQueue.h>
 #include <anki/resource/ResourceManager.h>
-#include <anki/resource/ShaderProgramResource.h>
 #include <anki/resource/MeshResource.h>
 #include <shaders/glsl_cpp_common/TraditionalDeferredShading.h>
 

+ 0 - 4
src/anki/resource/InstantiationMacros.h

@@ -9,8 +9,6 @@ ANKI_INSTANTIATE_RESOURCE(AnimationResource, AnimationResourcePtr)
 ANKI_INSTANSIATE_RESOURCE_DELIMITER()
 ANKI_INSTANTIATE_RESOURCE(TextureResource, TextureResourcePtr)
 ANKI_INSTANSIATE_RESOURCE_DELIMITER()
-ANKI_INSTANTIATE_RESOURCE(MaterialResource, MaterialResourcePtr)
-ANKI_INSTANSIATE_RESOURCE_DELIMITER()
 ANKI_INSTANTIATE_RESOURCE(MeshResource, MeshResourcePtr)
 ANKI_INSTANSIATE_RESOURCE_DELIMITER()
 ANKI_INSTANTIATE_RESOURCE(SkeletonResource, SkeletonResourcePtr)
@@ -29,8 +27,6 @@ ANKI_INSTANTIATE_RESOURCE(GenericResource, GenericResourcePtr)
 ANKI_INSTANSIATE_RESOURCE_DELIMITER()
 ANKI_INSTANTIATE_RESOURCE(TextureAtlasResource, TextureAtlasResourcePtr)
 ANKI_INSTANSIATE_RESOURCE_DELIMITER()
-ANKI_INSTANTIATE_RESOURCE(ShaderProgramResource, ShaderProgramResourcePtr)
-ANKI_INSTANSIATE_RESOURCE_DELIMITER()
 ANKI_INSTANTIATE_RESOURCE(ShaderProgramResource2, ShaderProgramResource2Ptr)
 ANKI_INSTANSIATE_RESOURCE_DELIMITER()
 ANKI_INSTANTIATE_RESOURCE(MaterialResource2, MaterialResource2Ptr)

+ 0 - 606
src/anki/resource/MaterialResource.cpp

@@ -1,606 +0,0 @@
-// Copyright (C) 2009-2020, Panagiotis Christopoulos Charitos and contributors.
-// All rights reserved.
-// Code licensed under the BSD License.
-// http://www.anki3d.org/LICENSE
-
-#include <anki/resource/MaterialResource.h>
-#include <anki/resource/ResourceManager.h>
-#include <anki/util/Xml.h>
-
-namespace anki
-{
-
-struct BuiltinVarInfo
-{
-	const char* m_name;
-	ShaderVariableDataType m_type;
-	Bool m_instanced;
-};
-
-static const Array<BuiltinVarInfo, U(BuiltinMaterialVariableId::COUNT) - 1> BUILTIN_INFOS = {
-	{{"MODEL_VIEW_PROJECTION_MATRIX", ShaderVariableDataType::MAT4, true},
-		{"MODEL_VIEW_MATRIX", ShaderVariableDataType::MAT4, true},
-		{"MODEL_MATRIX", ShaderVariableDataType::MAT4, true},
-		{"VIEW_PROJECTION_MATRIX", ShaderVariableDataType::MAT4, false},
-		{"VIEW_MATRIX", ShaderVariableDataType::MAT4, false},
-		{"NORMAL_MATRIX", ShaderVariableDataType::MAT3, true},
-		{"ROTATION_MATRIX", ShaderVariableDataType::MAT3, true},
-		{"CAMERA_ROTATION_MATRIX", ShaderVariableDataType::MAT3, false},
-		{"CAMERA_POSITION", ShaderVariableDataType::VEC3, false},
-		{"PREVIOUS_MODEL_VIEW_PROJECTION_MATRIX", ShaderVariableDataType::MAT4, true},
-		{"GLOBAL_SAMPLER", ShaderVariableDataType::SAMPLER, false}}};
-
-MaterialVariable::MaterialVariable()
-{
-	m_mat4 = Mat4::getZero();
-}
-
-MaterialVariable::~MaterialVariable()
-{
-}
-
-MaterialResource::MaterialResource(ResourceManager* manager)
-	: ResourceObject(manager)
-{
-}
-
-MaterialResource::~MaterialResource()
-{
-	m_vars.destroy(getAllocator());
-	m_constValues.destroy(getAllocator());
-	m_mutations.destroy(getAllocator());
-}
-
-Error MaterialResource::load(const ResourceFilename& filename, Bool async)
-{
-	XmlDocument doc;
-	XmlElement el;
-	Bool present = false;
-	ANKI_CHECK(openFileParseXml(filename, doc));
-
-	// <material>
-	XmlElement rootEl;
-	ANKI_CHECK(doc.getChildElement("material", rootEl));
-
-	// shaderProgram
-	CString fname;
-	ANKI_CHECK(rootEl.getAttributeText("shaderProgram", fname));
-	ANKI_CHECK(getManager().loadResource(fname, m_prog, async));
-	m_descriptorSetIdx = U8(m_prog->getDescriptorSetIndex());
-
-	// shadow
-	ANKI_CHECK(rootEl.getAttributeNumberOptional("shadow", m_shadow, present));
-	m_shadow = m_shadow != 0;
-
-	// forwardShading
-	ANKI_CHECK(rootEl.getAttributeNumberOptional("forwardShading", m_forwardShading, present));
-	m_forwardShading = m_forwardShading != 0;
-
-	// <mutators>
-	XmlElement mutatorsEl;
-	ANKI_CHECK(rootEl.getChildElementOptional("mutators", mutatorsEl));
-	if(mutatorsEl)
-	{
-		ANKI_CHECK(parseMutators(mutatorsEl));
-	}
-
-	// <inputs>
-	ANKI_CHECK(rootEl.getChildElementOptional("inputs", el));
-	if(el)
-	{
-		ANKI_CHECK(parseInputs(el, async));
-	}
-
-	return Error::NONE;
-}
-
-Error MaterialResource::parseMutators(XmlElement mutatorsEl)
-{
-	XmlElement mutatorEl;
-	ANKI_CHECK(mutatorsEl.getChildElement("mutator", mutatorEl));
-
-	U32 mutatorCount = 0;
-	ANKI_CHECK(mutatorEl.getSiblingElementsCount(mutatorCount));
-	++mutatorCount;
-	ANKI_ASSERT(mutatorCount > 0);
-	m_mutations.create(getAllocator(), mutatorCount);
-	mutatorCount = 0;
-
-	do
-	{
-		ShaderProgramResourceMutation& mutation = m_mutations[mutatorCount];
-
-		// name
-		CString mutatorName;
-		ANKI_CHECK(mutatorEl.getAttributeText("name", mutatorName));
-		if(mutatorName.isEmpty())
-		{
-			ANKI_RESOURCE_LOGE("Mutator name is empty");
-			return Error::USER_DATA;
-		}
-
-		if(mutatorName == "INSTANCE_COUNT" || mutatorName == "PASS" || mutatorName == "LOD" || mutatorName == "BONES"
-			|| mutatorName == "VELOCITY")
-		{
-			ANKI_RESOURCE_LOGE("Cannot list builtin mutator \"%s\"", &mutatorName[0]);
-			return Error::USER_DATA;
-		}
-
-		// value
-		ANKI_CHECK(mutatorEl.getAttributeNumber("value", mutation.m_value));
-
-		// Find mutator
-		mutation.m_mutator = m_prog->tryFindMutator(mutatorName);
-
-		if(!mutation.m_mutator)
-		{
-			ANKI_RESOURCE_LOGE("Mutator not found in program %s", &mutatorName[0]);
-			return Error::USER_DATA;
-		}
-
-		if(!mutation.m_mutator->valueExists(mutation.m_value))
-		{
-			ANKI_RESOURCE_LOGE("Value %d is not part of the mutator %s", mutation.m_value, &mutatorName[0]);
-			return Error::USER_DATA;
-		}
-
-		// Advance
-		++mutatorCount;
-		ANKI_CHECK(mutatorEl.getNextSiblingElement("mutator", mutatorEl));
-	} while(mutatorEl);
-
-	// Find the builtin mutators
-	U builtinMutatorCount = 0;
-
-	m_instanceMutator = m_prog->getInstancingMutator();
-	if(m_instanceMutator)
-	{
-		if(m_instanceMutator->getName() != "INSTANCE_COUNT")
-		{
-			ANKI_RESOURCE_LOGE("If program is instanced then the instance mutator should be the INSTANCE_COUNT");
-			return Error::USER_DATA;
-		}
-
-		if(m_instanceMutator->getValues().getSize() != MAX_INSTANCE_GROUPS)
-		{
-			ANKI_RESOURCE_LOGE("Mutator INSTANCE_COUNT should have %u values in the program", MAX_INSTANCE_GROUPS);
-			return Error::USER_DATA;
-		}
-
-		for(U32 i = 0; i < MAX_INSTANCE_GROUPS; ++i)
-		{
-			if(m_instanceMutator->getValues()[i] != (1 << i))
-			{
-				ANKI_RESOURCE_LOGE("Values of the INSTANCE_COUNT mutator in the program are not the expected");
-				return Error::USER_DATA;
-			}
-		}
-
-		++builtinMutatorCount;
-	}
-
-	m_passMutator = m_prog->tryFindMutator("PASS");
-	if(m_passMutator)
-	{
-		if(m_passMutator->getValues().getSize() != U32(Pass::COUNT))
-		{
-			ANKI_RESOURCE_LOGE("Mutator PASS should have %u values in the program", U32(Pass::COUNT));
-			return Error::USER_DATA;
-		}
-
-		for(U32 i = 0; i < U(Pass::COUNT); ++i)
-		{
-			if(m_passMutator->getValues()[i] != I(i))
-			{
-				ANKI_RESOURCE_LOGE("Values of the PASS mutator in the program are not the expected");
-				return Error::USER_DATA;
-			}
-		}
-
-		++builtinMutatorCount;
-	}
-
-	if(!m_forwardShading && !m_passMutator)
-	{
-		ANKI_RESOURCE_LOGE("PASS mutator is required");
-		return Error::USER_DATA;
-	}
-
-	m_lodMutator = m_prog->tryFindMutator("LOD");
-	if(m_lodMutator)
-	{
-		if(m_lodMutator->getValues().getSize() > MAX_LOD_COUNT)
-		{
-			ANKI_RESOURCE_LOGE("Mutator LOD should have at least %u values in the program", U32(MAX_LOD_COUNT));
-			return Error::USER_DATA;
-		}
-
-		for(U32 i = 0; i < m_lodMutator->getValues().getSize(); ++i)
-		{
-			if(m_lodMutator->getValues()[i] != I(i))
-			{
-				ANKI_RESOURCE_LOGE("Values of the LOD mutator in the program are not the expected");
-				return Error::USER_DATA;
-			}
-		}
-
-		m_lodCount = U8(m_lodMutator->getValues().getSize());
-		++builtinMutatorCount;
-	}
-
-	m_bonesMutator = m_prog->tryFindMutator("BONES");
-	if(m_bonesMutator)
-	{
-		if(m_bonesMutator->getValues().getSize() != 2)
-		{
-			ANKI_RESOURCE_LOGE("Mutator BONES should have 2 values in the program");
-			return Error::USER_DATA;
-		}
-
-		for(U32 i = 0; i < m_bonesMutator->getValues().getSize(); ++i)
-		{
-			if(m_bonesMutator->getValues()[i] != I(i))
-			{
-				ANKI_RESOURCE_LOGE("Values of the BONES mutator in the program are not the expected");
-				return Error::USER_DATA;
-			}
-		}
-
-		++builtinMutatorCount;
-	}
-
-	m_velocityMutator = m_prog->tryFindMutator("VELOCITY");
-	if(m_velocityMutator)
-	{
-		if(m_velocityMutator->getValues().getSize() != 2)
-		{
-			ANKI_RESOURCE_LOGE("Mutator VELOCITY should have 2 values in the program");
-			return Error::USER_DATA;
-		}
-
-		for(U32 i = 0; i < m_velocityMutator->getValues().getSize(); ++i)
-		{
-			if(m_velocityMutator->getValues()[i] != I(i))
-			{
-				ANKI_RESOURCE_LOGE("Values of the VELOCITY mutator in the program are not the expected");
-				return Error::USER_DATA;
-			}
-		}
-
-		++builtinMutatorCount;
-	}
-
-	if(m_mutations.getSize() + builtinMutatorCount != m_prog->getMutators().getSize())
-	{
-		ANKI_RESOURCE_LOGE("Some mutatators are unacounted for");
-		return Error::USER_DATA;
-	}
-
-	return Error::NONE;
-}
-
-Error MaterialResource::parseInputs(XmlElement inputsEl, Bool async)
-{
-	// Iterate the program's variables and get counts
-	U32 constInputCount = 0;
-	U32 nonConstInputCount = 0;
-	for(const ShaderProgramResourceInputVariable& in : m_prog->getInputVariables())
-	{
-		if(!in.acceptAllMutations(m_mutations))
-		{
-			// Will not be used by this material at all
-			continue;
-		}
-
-		if(in.isConstant())
-		{
-			++constInputCount;
-		}
-		else
-		{
-			++nonConstInputCount;
-		}
-	}
-
-	m_vars.create(getAllocator(), nonConstInputCount);
-	m_constValues.create(getAllocator(), constInputCount);
-
-	// Connect the input variables
-	XmlElement inputEl;
-	ANKI_CHECK(inputsEl.getChildElementOptional("input", inputEl));
-	while(inputEl)
-	{
-		// Get var name
-		CString varName;
-		ANKI_CHECK(inputEl.getAttributeText("shaderInput", varName));
-
-		// Try find var
-		const ShaderProgramResourceInputVariable* foundVar = m_prog->tryFindInputVariable(varName);
-		if(foundVar == nullptr)
-		{
-			ANKI_RESOURCE_LOGE("Variable \"%s\" not found", &varName[0]);
-			return Error::USER_DATA;
-		}
-
-		if(!foundVar->acceptAllMutations(m_mutations))
-		{
-			ANKI_RESOURCE_LOGE("Variable \"%s\" is not needed by the material's mutations", varName.cstr());
-			return Error::USER_DATA;
-		}
-
-		// Process var
-		if(foundVar->isConstant())
-		{
-			// Const
-
-			ShaderProgramResourceConstantValue& constVal = m_constValues[--constInputCount];
-			constVal.m_variable = foundVar;
-
-			switch(foundVar->getShaderVariableDataType())
-			{
-			case ShaderVariableDataType::INT:
-				ANKI_CHECK(inputEl.getAttributeNumber("value", constVal.m_int));
-				break;
-			case ShaderVariableDataType::IVEC2:
-				ANKI_CHECK(inputEl.getAttributeNumbers("value", constVal.m_ivec2));
-				break;
-			case ShaderVariableDataType::IVEC3:
-				ANKI_CHECK(inputEl.getAttributeNumbers("value", constVal.m_ivec3));
-				break;
-			case ShaderVariableDataType::IVEC4:
-				ANKI_CHECK(inputEl.getAttributeNumbers("value", constVal.m_ivec4));
-				break;
-			case ShaderVariableDataType::UINT:
-				ANKI_CHECK(inputEl.getAttributeNumber("value", constVal.m_uint));
-				break;
-			case ShaderVariableDataType::UVEC2:
-				ANKI_CHECK(inputEl.getAttributeNumbers("value", constVal.m_uvec2));
-				break;
-			case ShaderVariableDataType::UVEC3:
-				ANKI_CHECK(inputEl.getAttributeNumbers("value", constVal.m_uvec3));
-				break;
-			case ShaderVariableDataType::UVEC4:
-				ANKI_CHECK(inputEl.getAttributeNumbers("value", constVal.m_uvec4));
-				break;
-			case ShaderVariableDataType::FLOAT:
-				ANKI_CHECK(inputEl.getAttributeNumber("value", constVal.m_float));
-				break;
-			case ShaderVariableDataType::VEC2:
-				ANKI_CHECK(inputEl.getAttributeNumbers("value", constVal.m_vec2));
-				break;
-			case ShaderVariableDataType::VEC3:
-				ANKI_CHECK(inputEl.getAttributeNumbers("value", constVal.m_vec3));
-				break;
-			case ShaderVariableDataType::VEC4:
-				ANKI_CHECK(inputEl.getAttributeNumbers("value", constVal.m_vec4));
-				break;
-			default:
-				ANKI_ASSERT(0);
-				break;
-			}
-		}
-		else
-		{
-			// Builtin or not
-
-			Bool builtinPresent = false;
-			CString builtinStr;
-			ANKI_CHECK(inputEl.getAttributeTextOptional("builtin", builtinStr, builtinPresent));
-			if(builtinPresent)
-			{
-				// Builtin
-
-				U i;
-				for(i = 0; i < BUILTIN_INFOS.getSize(); ++i)
-				{
-					if(builtinStr == BUILTIN_INFOS[i].m_name)
-					{
-						break;
-					}
-				}
-
-				if(i == BUILTIN_INFOS.getSize())
-				{
-					ANKI_RESOURCE_LOGE("Incorrect builtin variable: %s", &builtinStr[0]);
-					return Error::USER_DATA;
-				}
-
-				if(BUILTIN_INFOS[i].m_type != foundVar->getShaderVariableDataType())
-				{
-					ANKI_RESOURCE_LOGE(
-						"The type of the builtin variable in the shader program is not the correct one: %s",
-						&builtinStr[0]);
-					return Error::USER_DATA;
-				}
-
-				if(foundVar->isInstanced() && !BUILTIN_INFOS[i].m_instanced)
-				{
-					ANKI_RESOURCE_LOGE("Builtin variable %s cannot be instanced", BUILTIN_INFOS[i].m_name);
-					return Error::USER_DATA;
-				}
-
-				MaterialVariable& mtlVar = m_vars[--nonConstInputCount];
-				mtlVar.m_input = foundVar;
-				mtlVar.m_builtin = BuiltinMaterialVariableId(i + 1);
-			}
-			else
-			{
-				// Not built-in
-
-				if(foundVar->isInstanced())
-				{
-					ANKI_RESOURCE_LOGE("Only some builtin variables can be instanced: %s", &foundVar->getName()[0]);
-					return Error::USER_DATA;
-				}
-
-				MaterialVariable& mtlVar = m_vars[--nonConstInputCount];
-				mtlVar.m_input = foundVar;
-
-				switch(foundVar->getShaderVariableDataType())
-				{
-				case ShaderVariableDataType::INT:
-					ANKI_CHECK(inputEl.getAttributeNumber("value", mtlVar.m_int));
-					break;
-				case ShaderVariableDataType::IVEC2:
-					ANKI_CHECK(inputEl.getAttributeNumbers("value", mtlVar.m_ivec2));
-					break;
-				case ShaderVariableDataType::IVEC3:
-					ANKI_CHECK(inputEl.getAttributeNumbers("value", mtlVar.m_ivec3));
-					break;
-				case ShaderVariableDataType::IVEC4:
-					ANKI_CHECK(inputEl.getAttributeNumbers("value", mtlVar.m_ivec4));
-					break;
-				case ShaderVariableDataType::UINT:
-					ANKI_CHECK(inputEl.getAttributeNumber("value", mtlVar.m_uint));
-					break;
-				case ShaderVariableDataType::UVEC2:
-					ANKI_CHECK(inputEl.getAttributeNumbers("value", mtlVar.m_uvec2));
-					break;
-				case ShaderVariableDataType::UVEC3:
-					ANKI_CHECK(inputEl.getAttributeNumbers("value", mtlVar.m_uvec3));
-					break;
-				case ShaderVariableDataType::UVEC4:
-					ANKI_CHECK(inputEl.getAttributeNumbers("value", mtlVar.m_uvec4));
-					break;
-				case ShaderVariableDataType::FLOAT:
-					ANKI_CHECK(inputEl.getAttributeNumber("value", mtlVar.m_float));
-					break;
-				case ShaderVariableDataType::VEC2:
-					ANKI_CHECK(inputEl.getAttributeNumbers("value", mtlVar.m_vec2));
-					break;
-				case ShaderVariableDataType::VEC3:
-					ANKI_CHECK(inputEl.getAttributeNumbers("value", mtlVar.m_vec3));
-					break;
-				case ShaderVariableDataType::VEC4:
-					ANKI_CHECK(inputEl.getAttributeNumbers("value", mtlVar.m_vec4));
-					break;
-				case ShaderVariableDataType::MAT3:
-					ANKI_CHECK(inputEl.getAttributeNumbers("value", mtlVar.m_mat3));
-					break;
-				case ShaderVariableDataType::MAT4:
-					ANKI_CHECK(inputEl.getAttributeNumbers("value", mtlVar.m_mat4));
-					break;
-				case ShaderVariableDataType::TEXTURE_2D:
-				case ShaderVariableDataType::TEXTURE_2D_ARRAY:
-				case ShaderVariableDataType::TEXTURE_3D:
-				case ShaderVariableDataType::TEXTURE_CUBE:
-				{
-					CString texfname;
-					ANKI_CHECK(inputEl.getAttributeText("value", texfname));
-					ANKI_CHECK(getManager().loadResource(texfname, mtlVar.m_tex, async));
-					break;
-				}
-
-				default:
-					ANKI_ASSERT(0);
-					break;
-				}
-			}
-		}
-
-		// Advance
-		ANKI_CHECK(inputEl.getNextSiblingElement("input", inputEl));
-	}
-
-	if(nonConstInputCount != 0)
-	{
-		ANKI_RESOURCE_LOGE("Forgot to list %u shader program inputs in this material", nonConstInputCount);
-		return Error::USER_DATA;
-	}
-
-	if(constInputCount != 0)
-	{
-		ANKI_RESOURCE_LOGE("Forgot to list %u constant shader program variables in this material", constInputCount);
-		return Error::USER_DATA;
-	}
-
-	return Error::NONE;
-}
-
-const MaterialVariant& MaterialResource::getOrCreateVariant(const RenderingKey& key_) const
-{
-	RenderingKey key = key_;
-	key.setLod(min<U32>(m_lodCount - 1, key.getLod()));
-
-	if(!isInstanced())
-	{
-		ANKI_ASSERT(key.getInstanceCount() == 1);
-	}
-
-	ANKI_ASSERT(!key.isSkinned() || m_bonesMutator);
-	ANKI_ASSERT(!key.hasVelocity() || m_velocityMutator);
-
-	key.setInstanceCount(1 << getInstanceGroupIdx(key.getInstanceCount()));
-
-	MaterialVariant& variant = m_variantMatrix[key.getPass()][key.getLod()][getInstanceGroupIdx(key.getInstanceCount())]
-											  [key.isSkinned()][key.hasVelocity()];
-	LockGuard<SpinLock> lock(m_variantMatrixMtx);
-
-	if(variant.m_variant == nullptr)
-	{
-		const U32 mutatorCount = m_mutations.getSize() + ((m_instanceMutator) ? 1 : 0) + ((m_passMutator) ? 1 : 0)
-								 + ((m_lodMutator) ? 1 : 0) + ((m_bonesMutator) ? 1 : 0)
-								 + ((m_velocityMutator) ? 1 : 0);
-
-		DynamicArrayAuto<ShaderProgramResourceMutation> mutations(getTempAllocator());
-		mutations.create(mutatorCount);
-		U32 count = m_mutations.getSize();
-		if(m_mutations.getSize())
-		{
-			memcpy(&mutations[0], &m_mutations[0], m_mutations.getSize() * sizeof(m_mutations[0]));
-		}
-
-		if(m_instanceMutator)
-		{
-			mutations[count].m_mutator = m_instanceMutator;
-			mutations[count].m_value = key.getInstanceCount();
-			++count;
-		}
-
-		if(m_passMutator)
-		{
-			mutations[count].m_mutator = m_passMutator;
-			mutations[count].m_value = I32(key.getPass());
-			++count;
-		}
-
-		if(m_lodMutator)
-		{
-			mutations[count].m_mutator = m_lodMutator;
-			mutations[count].m_value = I32(key.getLod());
-			++count;
-		}
-
-		if(m_bonesMutator)
-		{
-			mutations[count].m_mutator = m_bonesMutator;
-			mutations[count].m_value = key.isSkinned() != 0;
-			++count;
-		}
-
-		if(m_velocityMutator)
-		{
-			mutations[count].m_mutator = m_velocityMutator;
-			mutations[count].m_value = key.hasVelocity() != 0;
-			++count;
-		}
-
-		m_prog->getOrCreateVariant(
-			ConstWeakArray<ShaderProgramResourceMutation>(mutations.getSize() ? &mutations[0] : nullptr, count),
-			ConstWeakArray<ShaderProgramResourceConstantValue>(
-				(m_constValues.getSize()) ? &m_constValues[0] : nullptr, m_constValues.getSize()),
-			variant.m_variant);
-	}
-
-	return variant;
-}
-
-U32 MaterialResource::getInstanceGroupIdx(U32 instanceCount)
-{
-	ANKI_ASSERT(instanceCount > 0);
-	instanceCount = nextPowerOfTwo(instanceCount);
-	ANKI_ASSERT(instanceCount <= MAX_INSTANCES);
-	return U32(std::log2(F32(instanceCount)));
-}
-
-} // end namespace anki

+ 0 - 295
src/anki/resource/MaterialResource.h

@@ -1,295 +0,0 @@
-// Copyright (C) 2009-2020, Panagiotis Christopoulos Charitos and contributors.
-// All rights reserved.
-// Code licensed under the BSD License.
-// http://www.anki3d.org/LICENSE
-
-#pragma once
-
-#include <anki/resource/ResourceObject.h>
-#include <anki/resource/ShaderProgramResource.h>
-#include <anki/resource/TextureResource.h>
-#include <anki/resource/RenderingKey.h>
-#include <anki/Math.h>
-#include <anki/util/Visitor.h>
-#include <anki/util/NonCopyable.h>
-
-namespace anki
-{
-
-// Forward
-class XmlElement;
-class MaterialResource;
-template<typename T>
-class MaterialVariableTemplate;
-class MaterialVariable;
-class MaterialVariant;
-
-/// @addtogroup resource
-/// @{
-
-/// The ID of a buildin material variable
-enum class BuiltinMaterialVariableId : U8
-{
-	NONE = 0,
-	MODEL_VIEW_PROJECTION_MATRIX,
-	MODEL_VIEW_MATRIX,
-	MODEL_MATRIX,
-	VIEW_PROJECTION_MATRIX,
-	VIEW_MATRIX,
-	NORMAL_MATRIX,
-	ROTATION_MATRIX,
-	CAMERA_ROTATION_MATRIX,
-	CAMERA_POSITION,
-	PREVIOUS_MODEL_VIEW_PROJECTION_MATRIX,
-	GLOBAL_SAMPLER,
-	COUNT
-};
-
-/// Holds the shader variables. Its a container for shader program variables that share the same name
-class MaterialVariable : public NonCopyable
-{
-	friend class MaterialResource;
-	friend class MaterialVariant;
-
-public:
-	MaterialVariable();
-
-	~MaterialVariable();
-
-	/// Get the builtin info.
-	BuiltinMaterialVariableId getBuiltin() const
-	{
-		return m_builtin;
-	}
-
-	const ShaderProgramResourceInputVariable& getShaderProgramResourceInputVariable() const
-	{
-		ANKI_ASSERT(m_input);
-		return *m_input;
-	}
-
-	template<typename T>
-	const T& getValue() const;
-
-protected:
-	const ShaderProgramResourceInputVariable* m_input = nullptr;
-
-	union
-	{
-		I32 m_int;
-		IVec2 m_ivec2;
-		IVec3 m_ivec3;
-		IVec4 m_ivec4;
-		U32 m_uint;
-		UVec2 m_uvec2;
-		UVec3 m_uvec3;
-		UVec4 m_uvec4;
-		F32 m_float;
-		Vec2 m_vec2;
-		Vec3 m_vec3;
-		Vec4 m_vec4;
-		Mat3 m_mat3;
-		Mat4 m_mat4;
-	};
-
-	TextureResourcePtr m_tex;
-
-	BuiltinMaterialVariableId m_builtin = BuiltinMaterialVariableId::NONE;
-};
-
-// Specialize the MaterialVariable::getValue
-#define ANKI_SPECIALIZE_GET_VALUE(t_, var_, shaderType_) \
-	template<> \
-	inline const t_& MaterialVariable::getValue<t_>() const \
-	{ \
-		ANKI_ASSERT(m_input); \
-		ANKI_ASSERT(m_input->getShaderVariableDataType() == ShaderVariableDataType::shaderType_); \
-		ANKI_ASSERT(m_builtin == BuiltinMaterialVariableId::NONE); \
-		return var_; \
-	}
-
-ANKI_SPECIALIZE_GET_VALUE(I32, m_int, INT)
-ANKI_SPECIALIZE_GET_VALUE(IVec2, m_ivec2, IVEC2)
-ANKI_SPECIALIZE_GET_VALUE(IVec3, m_ivec3, IVEC3)
-ANKI_SPECIALIZE_GET_VALUE(IVec4, m_ivec4, IVEC4)
-ANKI_SPECIALIZE_GET_VALUE(U32, m_uint, UINT)
-ANKI_SPECIALIZE_GET_VALUE(UVec2, m_uvec2, UVEC2)
-ANKI_SPECIALIZE_GET_VALUE(UVec3, m_uvec3, UVEC3)
-ANKI_SPECIALIZE_GET_VALUE(UVec4, m_uvec4, UVEC4)
-ANKI_SPECIALIZE_GET_VALUE(F32, m_float, FLOAT)
-ANKI_SPECIALIZE_GET_VALUE(Vec2, m_vec2, VEC2)
-ANKI_SPECIALIZE_GET_VALUE(Vec3, m_vec3, VEC3)
-ANKI_SPECIALIZE_GET_VALUE(Vec4, m_vec4, VEC4)
-ANKI_SPECIALIZE_GET_VALUE(Mat3, m_mat3, MAT3)
-ANKI_SPECIALIZE_GET_VALUE(Mat4, m_mat4, MAT4)
-
-template<>
-inline const TextureResourcePtr& MaterialVariable::getValue() const
-{
-	ANKI_ASSERT(m_input);
-	ANKI_ASSERT(m_input->getShaderVariableDataType() >= ShaderVariableDataType::TEXTURE_FIRST
-				&& m_input->getShaderVariableDataType() <= ShaderVariableDataType::TEXTURE_LAST);
-	ANKI_ASSERT(m_builtin == BuiltinMaterialVariableId::NONE);
-	return m_tex;
-}
-
-#undef ANKI_SPECIALIZE_GET_VALUE
-
-/// Material variant.
-class MaterialVariant : public NonCopyable
-{
-	friend class MaterialResource;
-	friend class MaterialVariable;
-
-public:
-	MaterialVariant()
-	{
-	}
-
-	~MaterialVariant()
-	{
-	}
-
-	const ShaderProgramResourceVariant& getShaderProgramResourceVariant() const
-	{
-		ANKI_ASSERT(m_variant);
-		return *m_variant;
-	}
-
-	/// Return true of the the variable is active.
-	Bool variableActive(const MaterialVariable& var) const
-	{
-		ANKI_ASSERT(var.m_input);
-		return m_variant->variableActive(*var.m_input);
-	}
-
-	const ShaderProgramPtr& getShaderProgram() const
-	{
-		return m_variant->getProgram();
-	}
-
-	U32 getUniformBlockSize() const
-	{
-		return m_variant->getUniformBlockSize();
-	}
-
-	U32 getBindingCount() const
-	{
-		return m_variant->getBindingCount();
-	}
-
-private:
-	const ShaderProgramResourceVariant* m_variant = nullptr;
-};
-
-/// Material resource.
-///
-/// Material XML file format:
-/// @code
-/// <material
-///		[shadow="0 | 1"]
-///		[forwardShading="0 | 1"]
-///		<shaderProgram="path"/>
-///
-///		[<mutators>
-///			<mutator name="str" value="value"/>
-///		</mutators>]
-///
-///		[<inputs>
-///			<input
-///				shaderInput="name to shaderProg input"
-///				[value="values"] (1)
-///				[builtin="name"]/> (2)
-///		</inputs>]
-/// </material>
-/// @endcode
-/// (1): For non-builtins.
-/// (2): For builtins.
-class MaterialResource : public ResourceObject
-{
-	friend class MaterialVariable;
-	friend class MaterialVariant;
-
-public:
-	MaterialResource(ResourceManager* manager);
-
-	~MaterialResource();
-
-	/// Load a material file
-	ANKI_USE_RESULT Error load(const ResourceFilename& filename, Bool async);
-
-	U32 getLodCount() const
-	{
-		return m_lodCount;
-	}
-
-	Bool castsShadow() const
-	{
-		return m_shadow;
-	}
-
-	Bool hasTessellation() const
-	{
-		return m_prog->hasTessellation();
-	}
-
-	Bool isForwardShading() const
-	{
-		return m_forwardShading;
-	}
-
-	Bool isInstanced() const
-	{
-		return m_prog->isInstanced();
-	}
-
-	const MaterialVariant& getOrCreateVariant(const RenderingKey& key) const;
-
-	const DynamicArray<MaterialVariable>& getVariables() const
-	{
-		return m_vars;
-	}
-
-	ShaderProgramResourcePtr getShaderProgramResource() const
-	{
-		return m_prog;
-	}
-
-	U32 getDescriptorSetIndex() const
-	{
-		return m_descriptorSetIdx;
-	}
-
-private:
-	ShaderProgramResourcePtr m_prog;
-
-	Bool m_shadow = true;
-	Bool m_forwardShading = false;
-	U8 m_lodCount = 1;
-	U8 m_descriptorSetIdx = 0; ///< Cache the value from the m_prog;
-
-	const ShaderProgramResourceMutator* m_lodMutator = nullptr;
-	const ShaderProgramResourceMutator* m_passMutator = nullptr;
-	const ShaderProgramResourceMutator* m_instanceMutator = nullptr;
-	const ShaderProgramResourceMutator* m_bonesMutator = nullptr;
-	const ShaderProgramResourceMutator* m_velocityMutator = nullptr;
-
-	DynamicArray<ShaderProgramResourceMutation> m_mutations;
-
-	/// Matrix of variants.
-	mutable Array5d<MaterialVariant, U(Pass::COUNT), MAX_LOD_COUNT, MAX_INSTANCE_GROUPS, 2, 2> m_variantMatrix;
-	mutable SpinLock m_variantMatrixMtx;
-
-	DynamicArray<MaterialVariable> m_vars; ///< Non-const vars.
-	DynamicArray<ShaderProgramResourceConstantValue> m_constValues;
-
-	static U32 getInstanceGroupIdx(U32 instanceCount);
-
-	/// Parse whatever is inside the <inputs> tag.
-	ANKI_USE_RESULT Error parseInputs(XmlElement inputsEl, Bool async);
-
-	ANKI_USE_RESULT Error parseMutators(XmlElement mutatorsEl);
-};
-/// @}
-
-} // end namespace anki

+ 0 - 2
src/anki/resource/ResourceManager.cpp

@@ -10,7 +10,6 @@
 #include <anki/core/ConfigSet.h>
 #include <anki/gr/ShaderCompiler.h>
 
-#include <anki/resource/MaterialResource.h>
 #include <anki/resource/MaterialResource2.h>
 #include <anki/resource/MeshResource.h>
 #include <anki/resource/ModelResource.h>
@@ -20,7 +19,6 @@
 #include <anki/resource/TextureResource.h>
 #include <anki/resource/GenericResource.h>
 #include <anki/resource/TextureAtlasResource.h>
-#include <anki/resource/ShaderProgramResource.h>
 #include <anki/resource/ShaderProgramResource2.h>
 #include <anki/resource/CollisionResource.h>
 

+ 0 - 621
src/anki/resource/ShaderProgramResource.cpp

@@ -1,621 +0,0 @@
-// Copyright (C) 2009-2020, Panagiotis Christopoulos Charitos and contributors.
-// All rights reserved.
-// Code licensed under the BSD License.
-// http://www.anki3d.org/LICENSE
-
-#include <anki/resource/ShaderProgramResource.h>
-#include <anki/resource/ResourceManager.h>
-#include <anki/util/Filesystem.h>
-#include <tinyexpr.h>
-
-namespace anki
-{
-
-Bool ShaderProgramResourceInputVariable::evalPreproc(ConstWeakArray<te_variable> vars) const
-{
-	ANKI_ASSERT(vars.getSize() == m_program->getMutators().getSize());
-
-	int err;
-	te_expr* n = te_compile(m_preprocExpr.cstr(), &vars[0], vars.getSize(), &err);
-
-	if(!n)
-	{
-		ANKI_RESOURCE_LOGF("Error evaluating expression: %s", m_preprocExpr.cstr());
-	}
-
-	F64 evalOut = te_eval(n);
-	if(evalOut != 0.0 && evalOut != 1.0)
-	{
-		ANKI_RESOURCE_LOGF("Wrong result of the expression: %s", m_preprocExpr.cstr());
-	}
-
-	te_free(n);
-	return evalOut != 0.0;
-}
-
-Bool ShaderProgramResourceInputVariable::recusiveSpin(U32 crntMissingMutatorIdx,
-	WeakArray<const ShaderProgramResourceMutator*> missingMutators,
-	WeakArray<te_variable> vars,
-	WeakArray<F64> varValues,
-	U32 varIdxOffset) const
-{
-	for(ShaderProgramResourceMutatorValue val : missingMutators[crntMissingMutatorIdx]->getValues())
-	{
-		const U32 valIdx = varIdxOffset + crntMissingMutatorIdx;
-		varValues[valIdx] = val;
-		vars[valIdx] = {missingMutators[crntMissingMutatorIdx]->getName().cstr(), &varValues[valIdx], 0, 0};
-
-		if(crntMissingMutatorIdx == missingMutators.getSize() - 1)
-		{
-			// Last missing mutator will eval
-			const Bool accepted = evalPreproc(vars);
-			if(accepted)
-			{
-				return true;
-			}
-		}
-		else
-		{
-			return recusiveSpin(crntMissingMutatorIdx + 1, missingMutators, vars, varValues, varIdxOffset);
-		}
-	}
-
-	return false;
-}
-
-Bool ShaderProgramResourceInputVariable::acceptAllMutations(
-	ConstWeakArray<ShaderProgramResourceMutation> mutations) const
-{
-	if(mutations.getSize() == 0 || !m_preprocExpr)
-	{
-		// Early exit
-		return true;
-	}
-
-	static const U MAX_MUTATORS = 64;
-
-	Array<const ShaderProgramResourceMutator*, MAX_MUTATORS> missingMutators;
-	U32 missingMutatorCount = 0;
-
-	Array<te_variable, MAX_MUTATORS> vars;
-	Array<F64, MAX_MUTATORS> varValues;
-	U32 varCount = 0;
-
-	// - Find the mutators that don't appear in "mutations"
-	// - Fill the vars with the known mutators
-	for(const ShaderProgramResourceMutator& mutator : m_program->getMutators())
-	{
-		const ShaderProgramResourceMutation* foundMutation = nullptr;
-		for(const ShaderProgramResourceMutation& mutation : mutations)
-		{
-			if(mutation.m_mutator == &mutator)
-			{
-				// Found the mutator
-				foundMutation = &mutation;
-				break;
-			}
-			else
-			{
-				ANKI_ASSERT(mutation.m_mutator->getName() != mutator.getName());
-			}
-		}
-
-		if(foundMutation)
-		{
-			// Take the value from the mutation
-			varValues[varCount] = foundMutation->m_value;
-			vars[varCount] = {mutator.getName().cstr(), &varValues[varCount], 0, 0};
-			++varCount;
-		}
-		else
-		{
-			missingMutators[missingMutatorCount++] = &mutator;
-		}
-	}
-	ANKI_ASSERT(missingMutatorCount == m_program->getMutators().getSize() - varCount);
-
-	// Eval the expression
-	if(missingMutatorCount == 0)
-	{
-		ANKI_ASSERT(varCount == m_program->getMutators().getSize());
-		return evalPreproc(ConstWeakArray<te_variable>(&vars[0], varCount));
-	}
-	else
-	{
-		// Spin
-		return recusiveSpin(0,
-			WeakArray<const ShaderProgramResourceMutator*>(&missingMutators[0], missingMutatorCount),
-			WeakArray<te_variable>(&vars[0], m_program->getMutators().getSize()),
-			WeakArray<F64>(&varValues[0], m_program->getMutators().getSize()),
-			varCount);
-	}
-
-	ANKI_ASSERT(0 && "Shouldn't reach that");
-	return false;
-}
-
-ShaderProgramResource::ShaderProgramResource(ResourceManager* manager)
-	: ResourceObject(manager)
-{
-}
-
-ShaderProgramResource::~ShaderProgramResource()
-{
-	auto alloc = getAllocator();
-
-	while(!m_variants.isEmpty())
-	{
-		auto it = m_variants.getBegin();
-		ShaderProgramResourceVariant* variant = *it;
-		m_variants.erase(getAllocator(), it);
-
-		variant->m_blockInfos.destroy(alloc);
-		variant->m_bindings.destroy(alloc);
-		alloc.deleteInstance(variant);
-	}
-
-	for(Input& var : m_inputVars)
-	{
-		var.m_name.destroy(alloc);
-		var.m_preprocExpr.destroy(alloc);
-	}
-	m_inputVars.destroy(alloc);
-
-	for(ShaderProgramResourceMutator& m : m_mutators)
-	{
-		m.m_name.destroy(alloc);
-		m.m_values.destroy(alloc);
-	}
-	m_mutators.destroy(alloc);
-
-	m_source.destroy(alloc);
-}
-
-Error ShaderProgramResource::load(const ResourceFilename& filename, Bool async)
-{
-	// Preprocess
-	ShaderProgramPreprocessor pp(filename, &getManager().getFilesystem(), getTempAllocator());
-	ANKI_CHECK(pp.parse());
-
-	// Create the source
-	m_source.create(getAllocator(), pp.getSource());
-
-	// Create the mutators
-	U32 instancedMutatorIdx = MAX_U32;
-	if(pp.getMutators().getSize())
-	{
-		m_mutators.create(getAllocator(), pp.getMutators().getSize());
-
-		for(U32 i = 0; i < m_mutators.getSize(); ++i)
-		{
-			Mutator& out = m_mutators[i];
-			const ShaderProgramPreprocessorMutator& in = pp.getMutators()[i];
-
-			out.m_name.create(getAllocator(), in.getName());
-			out.m_values.create(getAllocator(), in.getValues().getSize());
-			for(U32 j = 0; j < out.m_values.getSize(); ++j)
-			{
-				out.m_values[j] = in.getValues()[j];
-			}
-
-			if(in.isInstanced())
-			{
-				instancedMutatorIdx = i;
-			}
-		}
-	}
-
-	// Create the inputs
-	if(pp.getInputs().getSize())
-	{
-		m_inputVars.create(getAllocator(), pp.getInputs().getSize());
-
-		for(U32 i = 0; i < m_inputVars.getSize(); ++i)
-		{
-			Input& out = m_inputVars[i];
-			const ShaderProgramPreprocessorInput& in = pp.getInputs()[i];
-
-			out.m_program = this;
-			out.m_name.create(getAllocator(), in.getName());
-			if(in.getPreprocessorCondition())
-			{
-				out.m_preprocExpr.create(getAllocator(), in.getPreprocessorCondition());
-			}
-			out.m_idx = i;
-			out.m_dataType = in.getDataType();
-			out.m_const = in.isConstant();
-			out.m_instanced = in.isInstanced();
-		}
-	}
-
-	// Set some other vars
-	m_descriptorSet = U8(pp.getDescritproSet());
-	m_shaderStages = pp.getShaderTypes();
-	if(instancedMutatorIdx != MAX_U32)
-	{
-		m_instancingMutator = &m_mutators[instancedMutatorIdx];
-	}
-
-	return Error::NONE;
-}
-
-U64 ShaderProgramResource::computeVariantHash(ConstWeakArray<ShaderProgramResourceMutation> mutations,
-	ConstWeakArray<ShaderProgramResourceConstantValue> constants) const
-{
-	U hash = 1;
-
-	if(mutations.getSize())
-	{
-		hash = computeHash(&mutations[0], sizeof(mutations[0]) * mutations.getSize());
-	}
-
-	if(constants.getSize())
-	{
-		hash = appendHash(&constants[0], sizeof(constants[0]) * constants.getSize(), hash);
-	}
-
-	return hash;
-}
-
-void ShaderProgramResource::getOrCreateVariant(ConstWeakArray<ShaderProgramResourceMutation> mutation,
-	ConstWeakArray<ShaderProgramResourceConstantValue> constants,
-	const ShaderProgramResourceVariant*& variant) const
-{
-	// Sanity checks
-	ANKI_ASSERT(mutation.getSize() == m_mutators.getSize());
-	ANKI_ASSERT(mutation.getSize() <= 128 && "Wrong assumption");
-	BitSet<128> mutatorPresent = {false};
-	for(const ShaderProgramResourceMutation& m : mutation)
-	{
-		(void)m;
-		ANKI_ASSERT(m.m_mutator);
-		ANKI_ASSERT(m.m_mutator->valueExists(m.m_value));
-
-		ANKI_ASSERT(&m_mutators[0] <= m.m_mutator);
-		const U idx = m.m_mutator - &m_mutators[0];
-		ANKI_ASSERT(idx < m_mutators.getSize());
-		ANKI_ASSERT(!mutatorPresent.get(idx) && "Appeared 2 times in 'mutation'");
-		mutatorPresent.set(idx);
-
-#if ANKI_EXTRA_CHECKS
-		if(m_instancingMutator == m.m_mutator)
-		{
-			ANKI_ASSERT(m.m_value > 0 && "Instancing value can't be negative");
-		}
-#endif
-	}
-
-	// Compute hash
-	U64 hash = computeVariantHash(mutation, constants);
-
-	LockGuard<Mutex> lock(m_mtx);
-
-	auto it = m_variants.find(hash);
-	if(it != m_variants.getEnd())
-	{
-		variant = *it;
-	}
-	else
-	{
-		// Create one
-		ShaderProgramResourceVariant* v = getAllocator().newInstance<ShaderProgramResourceVariant>();
-		initVariant(mutation, constants, *v);
-
-		m_variants.emplace(getAllocator(), hash, v);
-		variant = v;
-	}
-}
-
-void ShaderProgramResource::initVariant(ConstWeakArray<ShaderProgramResourceMutation> mutations,
-	ConstWeakArray<ShaderProgramResourceConstantValue> constants,
-	ShaderProgramResourceVariant& variant) const
-{
-	variant.m_activeInputVars.unsetAll();
-	variant.m_blockInfos.create(getAllocator(), m_inputVars.getSize());
-	variant.m_bindings.create(getAllocator(), m_inputVars.getSize(), -1);
-
-	// Get instance count, one mutation has it
-	U32 instanceCount = 1;
-	if(m_instancingMutator)
-	{
-		for(const ShaderProgramResourceMutation& m : mutations)
-		{
-			if(m.m_mutator == m_instancingMutator)
-			{
-				ANKI_ASSERT(m.m_value > 0);
-				instanceCount = m.m_value;
-				break;
-			}
-		}
-	}
-
-	// - Compute the block info for each var
-	// - Activate vars
-	// - Compute varius strings
-	StringListAuto headerSrc(getTempAllocator());
-	U binding = 0;
-
-	for(const Input& in : m_inputVars)
-	{
-		if(!in.acceptAllMutations(mutations))
-		{
-			continue;
-		}
-
-		variant.m_activeInputVars.set(in.m_idx);
-
-		// Init block info
-		if(in.inBlock())
-		{
-			ShaderVariableBlockInfo& blockInfo = variant.m_blockInfos[in.m_idx];
-
-			// std140 rules
-			blockInfo.m_offset = I16(variant.m_uniBlockSize);
-			blockInfo.m_arraySize = (in.m_instanced) ? I16(instanceCount) : 1;
-
-			if(in.m_dataType == ShaderVariableDataType::FLOAT || in.m_dataType == ShaderVariableDataType::INT
-				|| in.m_dataType == ShaderVariableDataType::UINT)
-			{
-				blockInfo.m_arrayStride = sizeof(Vec4);
-
-				if(blockInfo.m_arraySize == 1)
-				{
-					// No need to align the in.m_offset
-					variant.m_uniBlockSize += sizeof(F32);
-				}
-				else
-				{
-					alignRoundUp(sizeof(Vec4), blockInfo.m_offset);
-					variant.m_uniBlockSize += sizeof(Vec4) * blockInfo.m_arraySize;
-				}
-			}
-			else if(in.m_dataType == ShaderVariableDataType::VEC2 || in.m_dataType == ShaderVariableDataType::IVEC2
-					|| in.m_dataType == ShaderVariableDataType::UVEC2)
-			{
-				blockInfo.m_arrayStride = sizeof(Vec4);
-
-				if(blockInfo.m_arraySize == 1)
-				{
-					alignRoundUp(sizeof(Vec2), blockInfo.m_offset);
-					variant.m_uniBlockSize = blockInfo.m_offset + sizeof(Vec2);
-				}
-				else
-				{
-					alignRoundUp(sizeof(Vec4), blockInfo.m_offset);
-					variant.m_uniBlockSize = blockInfo.m_offset + sizeof(Vec4) * blockInfo.m_arraySize;
-				}
-			}
-			else if(in.m_dataType == ShaderVariableDataType::VEC3 || in.m_dataType == ShaderVariableDataType::IVEC3
-					|| in.m_dataType == ShaderVariableDataType::UVEC3)
-			{
-				alignRoundUp(sizeof(Vec4), blockInfo.m_offset);
-				blockInfo.m_arrayStride = sizeof(Vec4);
-
-				if(blockInfo.m_arraySize == 1)
-				{
-					variant.m_uniBlockSize = blockInfo.m_offset + sizeof(Vec3);
-				}
-				else
-				{
-					variant.m_uniBlockSize = blockInfo.m_offset + sizeof(Vec4) * blockInfo.m_arraySize;
-				}
-			}
-			else if(in.m_dataType == ShaderVariableDataType::VEC4 || in.m_dataType == ShaderVariableDataType::IVEC4
-					|| in.m_dataType == ShaderVariableDataType::UVEC4)
-			{
-				blockInfo.m_arrayStride = sizeof(Vec4);
-				alignRoundUp(sizeof(Vec4), blockInfo.m_offset);
-				variant.m_uniBlockSize = blockInfo.m_offset + sizeof(Vec4) * blockInfo.m_arraySize;
-			}
-			else if(in.m_dataType == ShaderVariableDataType::MAT3)
-			{
-				alignRoundUp(sizeof(Vec4), blockInfo.m_offset);
-				blockInfo.m_arrayStride = sizeof(Vec4) * 3;
-				variant.m_uniBlockSize = blockInfo.m_offset + sizeof(Vec4) * 3 * blockInfo.m_arraySize;
-				blockInfo.m_matrixStride = sizeof(Vec4);
-			}
-			else if(in.m_dataType == ShaderVariableDataType::MAT4)
-			{
-				alignRoundUp(sizeof(Vec4), blockInfo.m_offset);
-				blockInfo.m_arrayStride = sizeof(Mat4);
-				variant.m_uniBlockSize = blockInfo.m_offset + sizeof(Mat4) * blockInfo.m_arraySize;
-				blockInfo.m_matrixStride = sizeof(Vec4);
-			}
-			else
-			{
-				ANKI_ASSERT(0);
-			}
-		} // if(in.inBlock())
-
-		if(in.m_const)
-		{
-			// Find the const value
-			const ShaderProgramResourceConstantValue* constVal = nullptr;
-			for(const ShaderProgramResourceConstantValue& c : constants)
-			{
-				if(c.m_variable == &in)
-				{
-					constVal = &c;
-					break;
-				}
-			}
-
-			ANKI_ASSERT(constVal);
-
-			switch(in.m_dataType)
-			{
-			case ShaderVariableDataType::INT:
-				headerSrc.pushBackSprintf("#define %s_CONSTVAL %d\n", &in.m_name[0], constVal->m_int);
-				break;
-			case ShaderVariableDataType::IVEC2:
-				headerSrc.pushBackSprintf(
-					"#define %s_CONSTVAL %d, %d\n", &in.m_name[0], constVal->m_ivec2.x(), constVal->m_ivec2.y());
-				break;
-			case ShaderVariableDataType::IVEC3:
-				headerSrc.pushBackSprintf("#define %s_CONSTVAL %d, %d, %d\n",
-					&in.m_name[0],
-					constVal->m_ivec3.x(),
-					constVal->m_ivec3.y(),
-					constVal->m_ivec3.z());
-				break;
-			case ShaderVariableDataType::IVEC4:
-				headerSrc.pushBackSprintf("#define %s_CONSTVAL %d, %d, %d, %d\n",
-					&in.m_name[0],
-					constVal->m_ivec4.x(),
-					constVal->m_ivec4.y(),
-					constVal->m_ivec4.z(),
-					constVal->m_ivec4.w());
-				break;
-			case ShaderVariableDataType::UINT:
-				headerSrc.pushBackSprintf("#define %s_CONSTVAL %u\n", &in.m_name[0], constVal->m_uint);
-				break;
-			case ShaderVariableDataType::UVEC2:
-				headerSrc.pushBackSprintf(
-					"#define %s_CONSTVAL %u, %u\n", &in.m_name[0], constVal->m_uvec2.x(), constVal->m_uvec2.y());
-				break;
-			case ShaderVariableDataType::UVEC3:
-				headerSrc.pushBackSprintf("#define %s_CONSTVAL %u, %u, %u\n",
-					&in.m_name[0],
-					constVal->m_uvec3.x(),
-					constVal->m_uvec3.y(),
-					constVal->m_uvec3.z());
-				break;
-			case ShaderVariableDataType::UVEC4:
-				headerSrc.pushBackSprintf("#define %s_CONSTVAL %u, %u, %u, %u\n",
-					&in.m_name[0],
-					constVal->m_uvec4.x(),
-					constVal->m_uvec4.y(),
-					constVal->m_uvec4.z(),
-					constVal->m_uvec4.w());
-				break;
-			case ShaderVariableDataType::FLOAT:
-				headerSrc.pushBackSprintf("#define %s_CONSTVAL %f\n", &in.m_name[0], constVal->m_float);
-				break;
-			case ShaderVariableDataType::VEC2:
-				headerSrc.pushBackSprintf(
-					"#define %s_CONSTVAL %f, %f\n", &in.m_name[0], constVal->m_vec2.x(), constVal->m_vec2.y());
-				break;
-			case ShaderVariableDataType::VEC3:
-				headerSrc.pushBackSprintf("#define %s_CONSTVAL %f, %f, %f\n",
-					&in.m_name[0],
-					constVal->m_vec3.x(),
-					constVal->m_vec3.y(),
-					constVal->m_vec3.z());
-				break;
-			case ShaderVariableDataType::VEC4:
-				headerSrc.pushBackSprintf("#define %s_CONSTVAL %f, %f, %f, %f\n",
-					&in.m_name[0],
-					constVal->m_vec4.x(),
-					constVal->m_vec4.y(),
-					constVal->m_vec4.z(),
-					constVal->m_vec4.w());
-				break;
-			default:
-				ANKI_ASSERT(0);
-			}
-		}
-
-		if(in.isTexture() || in.isSampler())
-		{
-			headerSrc.pushBackSprintf("#if USE_PUSH_CONSTANTS\n"
-									  "#define %s_BINDING %u\n"
-									  "#else\n"
-									  "#define %s_BINDING %u\n"
-									  "#endif\n",
-				in.m_name.cstr(),
-				binding,
-				in.m_name.cstr(),
-				binding + 1);
-			variant.m_bindings[in.m_idx] = I16(binding);
-			++binding;
-		}
-	}
-
-	// Check if we can use push constants
-	variant.m_usesPushConstants =
-		instanceCount == 1
-		&& variant.m_uniBlockSize <= getManager().getGrManager().getDeviceCapabilities().m_pushConstantsSize;
-
-	// If there is a UBO then it takes the 0 binding. Shift the bindings of textures.
-	if(!variant.m_usesPushConstants)
-	{
-		for(I16& binding : variant.m_bindings)
-		{
-			if(binding >= 0)
-			{
-				++binding;
-			}
-		}
-	}
-
-	// Compute the binding count
-	variant.m_bindingCount = U8((!variant.m_usesPushConstants) + binding);
-
-	// Write the source header
-	StringListAuto shaderHeaderSrc(getTempAllocator());
-	shaderHeaderSrc.pushBackSprintf("#define USE_PUSH_CONSTANTS %d\n#define BINDING_COUNT %u\n",
-		I(variant.m_usesPushConstants),
-		U(variant.m_bindingCount));
-
-	for(const ShaderProgramResourceMutation& m : mutations)
-	{
-		shaderHeaderSrc.pushBackSprintf("#define %s %d\n", &m.m_mutator->getName()[0], m.m_value);
-	}
-
-	if(!headerSrc.isEmpty())
-	{
-		StringAuto str(getTempAllocator());
-		headerSrc.join("", str);
-		shaderHeaderSrc.pushBack(str.toCString());
-	}
-
-	StringAuto shaderHeader(getTempAllocator());
-	shaderHeaderSrc.join("", shaderHeader);
-
-	// Create the program name
-	StringAuto progName(getTempAllocator());
-	getFilepathFilename(getFilename(), progName);
-	char* cprogName = const_cast<char*>(progName.cstr());
-	if(progName.getLength() > MAX_GR_OBJECT_NAME_LENGTH)
-	{
-		cprogName[MAX_GR_OBJECT_NAME_LENGTH] = '\0';
-	}
-
-	// Create the shaders and the program
-	ShaderProgramInitInfo progInf(cprogName);
-	for(ShaderType i = ShaderType::FIRST; i < ShaderType::COUNT; ++i)
-	{
-		if(!(m_shaderStages & ShaderTypeBit(1 << U(i))))
-		{
-			continue;
-		}
-
-		StringAuto src(getTempAllocator());
-		src.append(shaderHeader);
-		src.append(m_source);
-
-		// Compile
-		DynamicArrayAuto<U8> bin(getTempAllocator());
-
-		ShaderCompilerOptions compileOptions;
-		compileOptions.setFromGrManager(getManager().getGrManager());
-		compileOptions.m_shaderType = i;
-
-		const Error err = getManager().getShaderCompiler().compile(
-			src.toCString(), nullptr, compileOptions, bin, getManager().getDumpShaderSource());
-		if(err)
-		{
-			ANKI_RESOURCE_LOGF("Shader compilation failed");
-		}
-
-		ShaderInitInfo inf(cprogName);
-		inf.m_shaderType = i;
-		inf.m_binary = ConstWeakArray<U8>(&bin[0], bin.getSize());
-
-		progInf.m_shaders[i] = getManager().getGrManager().newShader(inf);
-	}
-
-	variant.m_prog = getManager().getGrManager().newShaderProgram(progInf);
-}
-
-} // end namespace anki

+ 0 - 464
src/anki/resource/ShaderProgramResource.h

@@ -1,464 +0,0 @@
-// Copyright (C) 2009-2020, Panagiotis Christopoulos Charitos and contributors.
-// All rights reserved.
-// Code licensed under the BSD License.
-// http://www.anki3d.org/LICENSE
-
-#pragma once
-
-#include <anki/resource/ResourceObject.h>
-#include <anki/resource/ShaderProgramPreProcessor.h>
-#include <anki/Gr.h>
-#include <anki/util/BitSet.h>
-
-// Forward
-struct te_variable;
-
-namespace anki
-{
-
-/// @addtogroup resource
-/// @{
-
-using ShaderProgramResourceMutatorValue = ShaderProgramPreprocessorMutator::ValueType;
-
-/// The means to mutate a shader program.
-class ShaderProgramResourceMutator : public NonCopyable
-{
-	friend class ShaderProgramResource;
-
-public:
-	CString getName() const
-	{
-		ANKI_ASSERT(m_name);
-		return m_name.toCString();
-	}
-
-	const DynamicArray<ShaderProgramResourceMutatorValue>& getValues() const
-	{
-		ANKI_ASSERT(m_values.getSize() > 0);
-		return m_values;
-	}
-
-	Bool valueExists(ShaderProgramResourceMutatorValue v) const
-	{
-		for(ShaderProgramResourceMutatorValue val : m_values)
-		{
-			if(v == val)
-			{
-				return true;
-			}
-		}
-		return false;
-	}
-
-private:
-	String m_name;
-	DynamicArray<ShaderProgramResourceMutatorValue> m_values;
-};
-
-class ShaderProgramResourceMutation
-{
-public:
-	const ShaderProgramResourceMutator* m_mutator;
-	ShaderProgramResourceMutatorValue m_value;
-	U8 _padding[sizeof(void*) - sizeof(ShaderProgramResourceMutatorValue)];
-
-	ShaderProgramResourceMutation()
-	{
-		zeroMemory(*this);
-	}
-};
-
-static_assert(sizeof(ShaderProgramResourceMutation) == sizeof(void*) * 2, "Need it to be packed");
-
-/// A wrapper over the uniforms of a shader or constants.
-class ShaderProgramResourceInputVariable : public NonCopyable
-{
-	friend class ShaderProgramResourceVariant;
-	friend class ShaderProgramResource;
-
-public:
-	CString getName() const
-	{
-		return m_name.toCString();
-	}
-
-	ShaderVariableDataType getShaderVariableDataType() const
-	{
-		ANKI_ASSERT(m_dataType);
-		return m_dataType;
-	}
-
-	Bool isInstanced() const
-	{
-		return m_instanced;
-	}
-
-	Bool isConstant() const
-	{
-		return m_const;
-	}
-
-	/// Pass a subset of the mutators and check if this input variable is active for this subset. If the mutators are
-	/// not present in mutations and they are part of the expression then they are not taken into account
-	Bool acceptAllMutations(ConstWeakArray<ShaderProgramResourceMutation> mutations) const;
-
-private:
-	ShaderProgramResource* m_program = nullptr;
-	String m_name;
-	String m_preprocExpr;
-	U32 m_idx;
-	ShaderVariableDataType m_dataType = ShaderVariableDataType::NONE;
-	Bool m_const = false;
-	Bool m_instanced = false;
-
-	Bool isTexture() const
-	{
-		return m_dataType >= ShaderVariableDataType::TEXTURE_FIRST
-			   && m_dataType <= ShaderVariableDataType::TEXTURE_LAST;
-	}
-
-	Bool isSampler() const
-	{
-		return m_dataType == ShaderVariableDataType::SAMPLER;
-	}
-
-	Bool inBlock() const
-	{
-		return !m_const && !isTexture() && !isSampler();
-	}
-
-	Bool evalPreproc(ConstWeakArray<te_variable> vars) const;
-
-	Bool recusiveSpin(U32 crntMissingMutatorIdx,
-		WeakArray<const ShaderProgramResourceMutator*> missingMutators,
-		WeakArray<te_variable> vars,
-		WeakArray<F64> varValues,
-		U32 varIdxOffset) const;
-};
-
-/// Shader program resource variant.
-class ShaderProgramResourceVariant
-{
-	friend class ShaderProgramResource;
-
-public:
-	ShaderProgramResourceVariant()
-	{
-	}
-
-	~ShaderProgramResourceVariant()
-	{
-	}
-
-	/// Return true of the the variable is active.
-	Bool variableActive(const ShaderProgramResourceInputVariable& var) const
-	{
-		return m_activeInputVars.get(var.m_idx);
-	}
-
-	U32 getUniformBlockSize() const
-	{
-		return m_uniBlockSize;
-	}
-
-	Bool usePushConstants() const
-	{
-		return m_usesPushConstants;
-	}
-
-	const ShaderVariableBlockInfo& getVariableBlockInfo(const ShaderProgramResourceInputVariable& var) const
-	{
-		ANKI_ASSERT(!var.isTexture() && !var.isSampler() && variableActive(var));
-		return m_blockInfos[var.m_idx];
-	}
-
-	template<typename T>
-	void writeShaderBlockMemory(const ShaderProgramResourceInputVariable& var,
-		const T* elements,
-		U32 elementsCount,
-		void* buffBegin,
-		const void* buffEnd) const
-	{
-		ANKI_ASSERT(getShaderVariableTypeFromTypename<T>() == var.m_dataType);
-		const ShaderVariableBlockInfo& blockInfo = m_blockInfos[var.m_idx];
-		anki::writeShaderBlockMemory(var.m_dataType, blockInfo, elements, elementsCount, buffBegin, buffEnd);
-	}
-
-	const ShaderProgramPtr& getProgram() const
-	{
-		return m_prog;
-	}
-
-	U32 getBinding(const ShaderProgramResourceInputVariable& var) const
-	{
-		ANKI_ASSERT(m_bindings[var.m_idx] >= 0);
-		return U32(m_bindings[var.m_idx]);
-	}
-
-	U32 getBindingCount() const
-	{
-		return m_bindingCount;
-	}
-
-private:
-	ShaderProgramPtr m_prog;
-
-	BitSet<128, U64> m_activeInputVars = {false};
-	DynamicArray<ShaderVariableBlockInfo> m_blockInfos;
-	DynamicArray<I16> m_bindings;
-	U32 m_uniBlockSize = 0;
-	U8 m_bindingCount = 0;
-	Bool m_usesPushConstants = false;
-};
-
-/// The value of a constant.
-class ShaderProgramResourceConstantValue
-{
-public:
-	union
-	{
-		I32 m_int;
-		IVec2 m_ivec2;
-		IVec3 m_ivec3;
-		IVec4 m_ivec4;
-
-		U32 m_uint;
-		UVec2 m_uvec2;
-		UVec3 m_uvec3;
-		UVec4 m_uvec4;
-
-		F32 m_float;
-		Vec2 m_vec2;
-		Vec3 m_vec3;
-		Vec4 m_vec4;
-	};
-
-	const ShaderProgramResourceInputVariable* m_variable;
-	U8 _padding[sizeof(Vec4) - sizeof(void*)];
-
-	ShaderProgramResourceConstantValue()
-	{
-		zeroMemory(*this);
-	}
-};
-
-static_assert(sizeof(ShaderProgramResourceConstantValue) == sizeof(Vec4) * 2, "Need it to be packed");
-
-/// Shader program resource. It loads special AnKi programs.
-class ShaderProgramResource : public ResourceObject
-{
-public:
-	ShaderProgramResource(ResourceManager* manager);
-
-	~ShaderProgramResource();
-
-	/// Load the resource.
-	ANKI_USE_RESULT Error load(const ResourceFilename& filename, Bool async);
-
-	/// Get the array of input variables.
-	const DynamicArray<ShaderProgramResourceInputVariable>& getInputVariables() const
-	{
-		return m_inputVars;
-	}
-
-	/// Try to find an input variable.
-	const ShaderProgramResourceInputVariable* tryFindInputVariable(CString name) const
-	{
-		for(const ShaderProgramResourceInputVariable& m : m_inputVars)
-		{
-			if(m.getName() == name)
-			{
-				return &m;
-			}
-		}
-		return nullptr;
-	}
-
-	/// Get the array of mutators.
-	const DynamicArray<ShaderProgramResourceMutator>& getMutators() const
-	{
-		return m_mutators;
-	}
-
-	/// Try to find a mutator.
-	const ShaderProgramResourceMutator* tryFindMutator(CString name) const
-	{
-		for(const ShaderProgramResourceMutator& m : m_mutators)
-		{
-			if(m.getName() == name)
-			{
-				return &m;
-			}
-		}
-		return nullptr;
-	}
-
-	/// Get or create a graphics shader program variant.
-	/// @note It's thread-safe.
-	void getOrCreateVariant(ConstWeakArray<ShaderProgramResourceMutation> mutation,
-		ConstWeakArray<ShaderProgramResourceConstantValue> constants,
-		const ShaderProgramResourceVariant*& variant) const;
-
-	/// Get or create a graphics shader program variant.
-	/// @note It's thread-safe.
-	void getOrCreateVariant(ConstWeakArray<ShaderProgramResourceConstantValue> constants,
-		const ShaderProgramResourceVariant*& variant) const
-	{
-		getOrCreateVariant(ConstWeakArray<ShaderProgramResourceMutation>(), constants, variant);
-	}
-
-	/// Get or create a graphics shader program variant.
-	/// @note It's thread-safe.
-	void getOrCreateVariant(
-		ConstWeakArray<ShaderProgramResourceMutation> mutations, const ShaderProgramResourceVariant*& variant) const
-	{
-		getOrCreateVariant(mutations, ConstWeakArray<ShaderProgramResourceConstantValue>(), variant);
-	}
-
-	/// Get or create a graphics shader program variant.
-	/// @note It's thread-safe.
-	void getOrCreateVariant(const ShaderProgramResourceVariant*& variant) const
-	{
-		getOrCreateVariant(ConstWeakArray<ShaderProgramResourceMutation>(),
-			ConstWeakArray<ShaderProgramResourceConstantValue>(),
-			variant);
-	}
-
-	/// Has tessellation shaders.
-	Bool hasTessellation() const
-	{
-		return !!(m_shaderStages & ShaderTypeBit::TESSELLATION_EVALUATION);
-	}
-
-	/// Return true if it's instanced.
-	Bool isInstanced() const
-	{
-		return m_instancingMutator != nullptr;
-	}
-
-	/// Get the mutator that controls the instancing.
-	const ShaderProgramResourceMutator* getInstancingMutator() const
-	{
-		return m_instancingMutator;
-	}
-
-	/// The value of attribute "index" in <descriptorSet> tag.
-	U32 getDescriptorSetIndex() const
-	{
-		return m_descriptorSet;
-	}
-
-private:
-	using Mutator = ShaderProgramResourceMutator;
-	using Input = ShaderProgramResourceInputVariable;
-
-	DynamicArray<Input> m_inputVars;
-	DynamicArray<Mutator> m_mutators;
-
-	String m_source;
-
-	mutable HashMap<U64, ShaderProgramResourceVariant*> m_variants;
-	mutable Mutex m_mtx;
-
-	U8 m_descriptorSet = 0;
-	ShaderTypeBit m_shaderStages = ShaderTypeBit::NONE;
-	const Mutator* m_instancingMutator = nullptr;
-
-	U64 computeVariantHash(ConstWeakArray<ShaderProgramResourceMutation> mutations,
-		ConstWeakArray<ShaderProgramResourceConstantValue> constants) const;
-
-	void initVariant(ConstWeakArray<ShaderProgramResourceMutation> mutations,
-		ConstWeakArray<ShaderProgramResourceConstantValue> constants,
-		ShaderProgramResourceVariant& variant) const;
-};
-
-/// Smart initializer of multiple ShaderProgramResourceConstantValue.
-template<U32 count>
-class ShaderProgramResourceConstantValueInitList
-{
-public:
-	ShaderProgramResourceConstantValueInitList(ShaderProgramResourcePtr ptr)
-		: m_ptr(ptr)
-	{
-	}
-
-	~ShaderProgramResourceConstantValueInitList()
-	{
-		ANKI_ASSERT((m_count == count || m_count == 0) && "Forgot to set something");
-	}
-
-	template<typename T>
-	ShaderProgramResourceConstantValueInitList& add(CString name, const T& t)
-	{
-		const ShaderProgramResourceInputVariable* in = m_ptr->tryFindInputVariable(name);
-		ANKI_ASSERT(in);
-		ANKI_ASSERT(in->isConstant());
-		ANKI_ASSERT(in->getShaderVariableDataType() == getShaderVariableTypeFromTypename<T>());
-		m_constantValues[m_count].m_variable = in;
-		memcpy(&m_constantValues[m_count].m_int, &t, sizeof(T));
-		++m_count;
-		return *this;
-	}
-
-	ConstWeakArray<ShaderProgramResourceConstantValue> get() const
-	{
-		ANKI_ASSERT(m_count == count);
-		return ConstWeakArray<ShaderProgramResourceConstantValue>(&m_constantValues[0], m_count);
-	}
-
-	ShaderProgramResourceConstantValue& operator[](U32 idx)
-	{
-		return m_constantValues[idx];
-	}
-
-private:
-	ShaderProgramResourcePtr m_ptr;
-	U32 m_count = 0;
-	Array<ShaderProgramResourceConstantValue, count> m_constantValues;
-};
-
-/// Smart initializer of multiple ShaderProgramResourceMutation.
-template<U32 count>
-class ShaderProgramResourceMutationInitList
-{
-public:
-	ShaderProgramResourceMutationInitList(ShaderProgramResourcePtr ptr)
-		: m_ptr(ptr)
-	{
-	}
-
-	~ShaderProgramResourceMutationInitList()
-	{
-		ANKI_ASSERT((m_count == count || m_count == 0) && "Forgot to set something");
-	}
-
-	ShaderProgramResourceMutationInitList& add(CString name, ShaderProgramResourceMutatorValue t)
-	{
-		const ShaderProgramResourceMutator* m = m_ptr->tryFindMutator(name);
-		ANKI_ASSERT(m);
-		m_mutations[m_count].m_mutator = m;
-		m_mutations[m_count].m_value = t;
-		++m_count;
-		return *this;
-	}
-
-	ConstWeakArray<ShaderProgramResourceMutation> get() const
-	{
-		ANKI_ASSERT(m_count == count);
-		return ConstWeakArray<ShaderProgramResourceMutation>(&m_mutations[0], m_count);
-	}
-
-	ShaderProgramResourceMutation& operator[](U32 idx)
-	{
-		return m_mutations[idx];
-	}
-
-private:
-	ShaderProgramResourcePtr m_ptr;
-	U32 m_count = 0;
-	Array<ShaderProgramResourceMutation, count> m_mutations;
-};
-/// @}
-
-} // end namespace anki

+ 1 - 1
src/anki/scene/DebugDrawer.h

@@ -9,8 +9,8 @@
 #include <anki/Math.h>
 #include <anki/Gr.h>
 #include <anki/physics/PhysicsDrawer.h>
+#include <anki/resource/ShaderProgramResource2.h>
 #include <anki/util/Array.h>
-#include <anki/resource/ShaderProgramResource.h>
 
 namespace anki
 {