Browse Source

Move GBufferPost to the new format

Panagiotis Christopoulos Charitos 5 years ago
parent
commit
dba732147c

+ 1 - 1
shaders/Bloom.ankiprog

@@ -3,7 +3,7 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-ANKI_SPECIALIZATION_CONSTANT_IVEC2(FB_SIZE, 0, IVec2(1));
+ANKI_SPECIALIZATION_CONSTANT_UVEC2(FB_SIZE, 0, UVec2(1));
 const UVec2 WORKGROUP_SIZE = UVec2(16, 16);
 const UVec2 WORKGROUP_SIZE = UVec2(16, 16);
 
 
 #pragma anki start comp
 #pragma anki start comp

+ 2 - 2
shaders/BloomUpscale.ankiprog

@@ -3,8 +3,8 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-ANKI_SPECIALIZATION_CONSTANT_IVEC2(FB_SIZE, 0, IVec2(1));
-ANKI_SPECIALIZATION_CONSTANT_IVEC2(INPUT_TEX_SIZE, 2, IVec2(1));
+ANKI_SPECIALIZATION_CONSTANT_UVEC2(FB_SIZE, 0, UVec2(1));
+ANKI_SPECIALIZATION_CONSTANT_UVEC2(INPUT_TEX_SIZE, 2, UVec2(1));
 const UVec2 WORKGROUP_SIZE = UVec2(16u, 16u);
 const UVec2 WORKGROUP_SIZE = UVec2(16u, 16u);
 
 
 #pragma anki start comp
 #pragma anki start comp

+ 3 - 3
shaders/FinalComposite.ankiprog

@@ -7,9 +7,9 @@
 #pragma anki mutator BLOOM_ENABLED 0 1
 #pragma anki mutator BLOOM_ENABLED 0 1
 #pragma anki mutator DBG_ENABLED 0 1
 #pragma anki mutator DBG_ENABLED 0 1
 
 
-ANKI_SPECIALIZATION_CONSTANT_I32(LUT_SIZE, 0, 1);
-ANKI_SPECIALIZATION_CONSTANT_IVEC2(FB_SIZE, 1, IVec2(1, 1));
-ANKI_SPECIALIZATION_CONSTANT_I32(MOTION_BLUR_SAMPLES, 3, 1);
+ANKI_SPECIALIZATION_CONSTANT_U32(LUT_SIZE, 0, 1);
+ANKI_SPECIALIZATION_CONSTANT_UVEC2(FB_SIZE, 1, UVec2(1, 1));
+ANKI_SPECIALIZATION_CONSTANT_U32(MOTION_BLUR_SAMPLES, 3, 1);
 
 
 #pragma anki start vert
 #pragma anki start vert
 #include <shaders/QuadVert.glsl>
 #include <shaders/QuadVert.glsl>

+ 2 - 3
shaders/GBufferPost.glslp → shaders/GBufferPost.ankiprog

@@ -3,9 +3,8 @@
 // Code licensed under the BSD License.
 // Code licensed under the BSD License.
 // http://www.anki3d.org/LICENSE
 // http://www.anki3d.org/LICENSE
 
 
-#pragma anki input const U32 CLUSTER_COUNT_X
-#pragma anki input const U32 CLUSTER_COUNT_Y
-#pragma anki input const U32 CLUSTER_COUNT_Z
+ANKI_SPECIALIZATION_CONSTANT_U32(CLUSTER_COUNT_X, 0, 1);
+ANKI_SPECIALIZATION_CONSTANT_U32(CLUSTER_COUNT_Y, 1, 1);
 
 
 #pragma anki start vert
 #pragma anki start vert
 #include <shaders/Common.glsl>
 #include <shaders/Common.glsl>

+ 7 - 0
src/anki/gr/Shader.h

@@ -23,6 +23,7 @@ public:
 	{
 	{
 		F32 m_float;
 		F32 m_float;
 		I32 m_int;
 		I32 m_int;
+		U32 m_uint;
 	};
 	};
 
 
 	U32 m_constantId = MAX_U32;
 	U32 m_constantId = MAX_U32;
@@ -46,6 +47,12 @@ public:
 	{
 	{
 	}
 	}
 
 
+	explicit ShaderSpecializationConstValue(U32 i)
+		: m_int(i)
+		, m_dataType(ShaderVariableDataType::UINT)
+	{
+	}
+
 	ShaderSpecializationConstValue(const ShaderSpecializationConstValue&) = default;
 	ShaderSpecializationConstValue(const ShaderSpecializationConstValue&) = default;
 
 
 	ShaderSpecializationConstValue& operator=(const ShaderSpecializationConstValue&) = default;
 	ShaderSpecializationConstValue& operator=(const ShaderSpecializationConstValue&) = default;

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

@@ -85,8 +85,8 @@ Error ShaderImpl::init(const ShaderInitInfo& inf)
 
 
 		m_specConstInfo.mapEntryCount = constCount;
 		m_specConstInfo.mapEntryCount = constCount;
 		m_specConstInfo.pMapEntries = getAllocator().newArray<VkSpecializationMapEntry>(constCount);
 		m_specConstInfo.pMapEntries = getAllocator().newArray<VkSpecializationMapEntry>(constCount);
-		m_specConstInfo.dataSize = constCount * sizeof(I32);
-		m_specConstInfo.pData = getAllocator().newArray<I32>(constCount);
+		m_specConstInfo.dataSize = constCount * sizeof(U32);
+		m_specConstInfo.pData = getAllocator().newArray<U32>(constCount);
 
 
 		U32 count = 0;
 		U32 count = 0;
 		for(const spirv_cross::SpecializationConstant& sconst : specConstIds.m_vec)
 		for(const spirv_cross::SpecializationConstant& sconst : specConstIds.m_vec)
@@ -94,8 +94,8 @@ Error ShaderImpl::init(const ShaderInitInfo& inf)
 			// Set the entry
 			// Set the entry
 			VkSpecializationMapEntry& entry = const_cast<VkSpecializationMapEntry&>(m_specConstInfo.pMapEntries[count]);
 			VkSpecializationMapEntry& entry = const_cast<VkSpecializationMapEntry&>(m_specConstInfo.pMapEntries[count]);
 			entry.constantID = sconst.constant_id;
 			entry.constantID = sconst.constant_id;
-			entry.offset = count * sizeof(I32);
-			entry.size = sizeof(I32);
+			entry.offset = count * sizeof(U32);
+			entry.size = sizeof(U32);
 
 
 			// Find the value
 			// Find the value
 			const ShaderSpecializationConstValue* val = nullptr;
 			const ShaderSpecializationConstValue* val = nullptr;
@@ -112,7 +112,7 @@ Error ShaderImpl::init(const ShaderInitInfo& inf)
 			// Copy the data
 			// Copy the data
 			U8* data = static_cast<U8*>(const_cast<void*>(m_specConstInfo.pData));
 			U8* data = static_cast<U8*>(const_cast<void*>(m_specConstInfo.pData));
 			data += entry.offset;
 			data += entry.offset;
-			*reinterpret_cast<I32*>(data) = val->m_int;
+			*reinterpret_cast<U32*>(data) = val->m_uint;
 
 
 			++count;
 			++count;
 		}
 		}

+ 3 - 3
src/anki/renderer/Bloom.cpp

@@ -39,7 +39,7 @@ Error Bloom::initExposure(const ConfigSet& config)
 	ANKI_CHECK(getResourceManager().loadResource("shaders/Bloom.ankiprog", m_exposure.m_prog));
 	ANKI_CHECK(getResourceManager().loadResource("shaders/Bloom.ankiprog", m_exposure.m_prog));
 
 
 	ShaderProgramResourceVariantInitInfo2 variantInitInfo(m_exposure.m_prog);
 	ShaderProgramResourceVariantInitInfo2 variantInitInfo(m_exposure.m_prog);
-	variantInitInfo.addConstant("FB_SIZE", IVec2(m_exposure.m_width, m_exposure.m_height));
+	variantInitInfo.addConstant("FB_SIZE", UVec2(m_exposure.m_width, m_exposure.m_height));
 
 
 	const ShaderProgramResourceVariant2* variant;
 	const ShaderProgramResourceVariant2* variant;
 	m_exposure.m_prog->getOrCreateVariant(variantInitInfo, variant);
 	m_exposure.m_prog->getOrCreateVariant(variantInitInfo, variant);
@@ -65,8 +65,8 @@ Error Bloom::initUpscale(const ConfigSet& config)
 	ANKI_CHECK(getResourceManager().loadResource("shaders/BloomUpscale.ankiprog", m_upscale.m_prog));
 	ANKI_CHECK(getResourceManager().loadResource("shaders/BloomUpscale.ankiprog", m_upscale.m_prog));
 
 
 	ShaderProgramResourceVariantInitInfo2 variantInitInfo(m_upscale.m_prog);
 	ShaderProgramResourceVariantInitInfo2 variantInitInfo(m_upscale.m_prog);
-	variantInitInfo.addConstant("FB_SIZE", IVec2(m_upscale.m_width, m_upscale.m_height));
-	variantInitInfo.addConstant("INPUT_TEX_SIZE", IVec2(m_exposure.m_width, m_exposure.m_height));
+	variantInitInfo.addConstant("FB_SIZE", UVec2(m_upscale.m_width, m_upscale.m_height));
+	variantInitInfo.addConstant("INPUT_TEX_SIZE", UVec2(m_exposure.m_width, m_exposure.m_height));
 
 
 	const ShaderProgramResourceVariant2* variant;
 	const ShaderProgramResourceVariant2* variant;
 	m_upscale.m_prog->getOrCreateVariant(variantInitInfo, variant);
 	m_upscale.m_prog->getOrCreateVariant(variantInitInfo, variant);

+ 4 - 4
src/anki/renderer/FinalComposite.cpp

@@ -49,10 +49,10 @@ Error FinalComposite::initInternal(const ConfigSet& config)
 	variantInitInfo.addMutation("BLUE_NOISE", 1);
 	variantInitInfo.addMutation("BLUE_NOISE", 1);
 	variantInitInfo.addMutation("BLOOM_ENABLED", 1);
 	variantInitInfo.addMutation("BLOOM_ENABLED", 1);
 	variantInitInfo.addMutation("DBG_ENABLED", 0);
 	variantInitInfo.addMutation("DBG_ENABLED", 0);
-	variantInitInfo.addConstant("LUT_SIZE", I32(LUT_SIZE));
-	variantInitInfo.addConstant("LUT_SIZE", I32(LUT_SIZE));
-	variantInitInfo.addConstant("FB_SIZE", IVec2(m_r->getWidth(), m_r->getHeight()));
-	variantInitInfo.addConstant("MOTION_BLUR_SAMPLES", I32(config.getNumberU32("r_motionBlurSamples")));
+	variantInitInfo.addConstant("LUT_SIZE", U32(LUT_SIZE));
+	variantInitInfo.addConstant("LUT_SIZE", U32(LUT_SIZE));
+	variantInitInfo.addConstant("FB_SIZE", UVec2(m_r->getWidth(), m_r->getHeight()));
+	variantInitInfo.addConstant("MOTION_BLUR_SAMPLES", config.getNumberU32("r_motionBlurSamples"));
 
 
 	const ShaderProgramResourceVariant2* variant;
 	const ShaderProgramResourceVariant2* variant;
 	m_prog->getOrCreateVariant(variantInitInfo, variant);
 	m_prog->getOrCreateVariant(variantInitInfo, variant);

+ 7 - 8
src/anki/renderer/GBufferPost.cpp

@@ -18,7 +18,7 @@ GBufferPost::~GBufferPost()
 
 
 Error GBufferPost::init(const ConfigSet& cfg)
 Error GBufferPost::init(const ConfigSet& cfg)
 {
 {
-	Error err = initInternal(cfg);
+	const Error err = initInternal(cfg);
 	if(err)
 	if(err)
 	{
 	{
 		ANKI_R_LOGE("Failed to initialize GBufferPost pass");
 		ANKI_R_LOGE("Failed to initialize GBufferPost pass");
@@ -31,15 +31,14 @@ Error GBufferPost::initInternal(const ConfigSet& cfg)
 	ANKI_R_LOGI("Initializing GBufferPost pass");
 	ANKI_R_LOGI("Initializing GBufferPost pass");
 
 
 	// Load shaders
 	// Load shaders
-	ANKI_CHECK(getResourceManager().loadResource("shaders/GBufferPost.glslp", m_prog));
+	ANKI_CHECK(getResourceManager().loadResource("shaders/GBufferPost.ankiprog", m_prog));
 
 
-	ShaderProgramResourceConstantValueInitList<3> consts(m_prog);
-	consts.add("CLUSTER_COUNT_X", cfg.getNumberU32("r_clusterSizeX"));
-	consts.add("CLUSTER_COUNT_Y", cfg.getNumberU32("r_clusterSizeY"));
-	consts.add("CLUSTER_COUNT_Z", cfg.getNumberU32("r_clusterSizeZ"));
+	ShaderProgramResourceVariantInitInfo2 variantInitInfo(m_prog);
+	variantInitInfo.addConstant("CLUSTER_COUNT_X", cfg.getNumberU32("r_clusterSizeX"));
+	variantInitInfo.addConstant("CLUSTER_COUNT_Y", cfg.getNumberU32("r_clusterSizeY"));
 
 
-	const ShaderProgramResourceVariant* variant;
-	m_prog->getOrCreateVariant(consts.get(), variant);
+	const ShaderProgramResourceVariant2* variant;
+	m_prog->getOrCreateVariant(variantInitInfo, variant);
 	m_grProg = variant->getProgram();
 	m_grProg = variant->getProgram();
 
 
 	// Create FB descr
 	// Create FB descr

+ 1 - 1
src/anki/renderer/GBufferPost.h

@@ -30,7 +30,7 @@ public:
 	void populateRenderGraph(RenderingContext& ctx);
 	void populateRenderGraph(RenderingContext& ctx);
 
 
 private:
 private:
-	ShaderProgramResourcePtr m_prog;
+	ShaderProgramResource2Ptr m_prog;
 	ShaderProgramPtr m_grProg;
 	ShaderProgramPtr m_grProg;
 
 
 	FramebufferDescription m_fbDescr;
 	FramebufferDescription m_fbDescr;

+ 18 - 6
src/anki/resource/ShaderProgramResource2.cpp

@@ -110,7 +110,11 @@ Error ShaderProgramResource2::load(const ResourceFilename& filename, Bool async)
 		}
 		}
 		else if(componentCount == 2)
 		else if(componentCount == 2)
 		{
 		{
-			if(c.m_type == ShaderVariableDataType::INT)
+			if(c.m_type == ShaderVariableDataType::UINT)
+			{
+				in.m_dataType = ShaderVariableDataType::UVEC2;
+			}
+			else if(c.m_type == ShaderVariableDataType::INT)
 			{
 			{
 				in.m_dataType = ShaderVariableDataType::IVEC2;
 				in.m_dataType = ShaderVariableDataType::IVEC2;
 			}
 			}
@@ -122,7 +126,11 @@ Error ShaderProgramResource2::load(const ResourceFilename& filename, Bool async)
 		}
 		}
 		else if(componentCount == 3)
 		else if(componentCount == 3)
 		{
 		{
-			if(c.m_type == ShaderVariableDataType::INT)
+			if(c.m_type == ShaderVariableDataType::UINT)
+			{
+				in.m_dataType = ShaderVariableDataType::UVEC3;
+			}
+			else if(c.m_type == ShaderVariableDataType::INT)
 			{
 			{
 				in.m_dataType = ShaderVariableDataType::IVEC3;
 				in.m_dataType = ShaderVariableDataType::IVEC3;
 			}
 			}
@@ -134,7 +142,11 @@ Error ShaderProgramResource2::load(const ResourceFilename& filename, Bool async)
 		}
 		}
 		else if(componentCount == 4)
 		else if(componentCount == 4)
 		{
 		{
-			if(c.m_type == ShaderVariableDataType::INT)
+			if(c.m_type == ShaderVariableDataType::UINT)
+			{
+				in.m_dataType = ShaderVariableDataType::UVEC4;
+			}
+			else if(c.m_type == ShaderVariableDataType::INT)
 			{
 			{
 				in.m_dataType = ShaderVariableDataType::IVEC4;
 				in.m_dataType = ShaderVariableDataType::IVEC4;
 			}
 			}
@@ -303,9 +315,9 @@ void ShaderProgramResource2::initVariant(
 				const U32 component = m_constBinaryMapping[binaryConstIdx].m_component;
 				const U32 component = m_constBinaryMapping[binaryConstIdx].m_component;
 				const Const& c = m_consts[constIdx];
 				const Const& c = m_consts[constIdx];
 				(void)c;
 				(void)c;
-				ANKI_ASSERT(c.m_dataType == ShaderVariableDataType::INT || c.m_dataType == ShaderVariableDataType::IVEC2
-							|| c.m_dataType == ShaderVariableDataType::IVEC3
-							|| c.m_dataType == ShaderVariableDataType::IVEC4);
+				ANKI_ASSERT(
+					c.m_dataType == ShaderVariableDataType::UINT || c.m_dataType == ShaderVariableDataType::UVEC2
+					|| c.m_dataType == ShaderVariableDataType::UVEC3 || c.m_dataType == ShaderVariableDataType::UVEC4);
 
 
 				// Find the value
 				// Find the value
 				for(U32 i = 0; i < m_consts.getSize(); ++i)
 				for(U32 i = 0; i < m_consts.getSize(); ++i)

+ 5 - 0
src/anki/resource/ShaderProgramResource2.h

@@ -102,6 +102,11 @@ class ShaderProgramResourceConstantValue2
 public:
 public:
 	union
 	union
 	{
 	{
+		U32 m_uint;
+		UVec2 m_uvec2;
+		UVec3 m_uvec3;
+		UVec4 m_uvec4;
+
 		I32 m_int;
 		I32 m_int;
 		IVec2 m_ivec2;
 		IVec2 m_ivec2;
 		IVec3 m_ivec3;
 		IVec3 m_ivec3;

+ 5 - 0
src/anki/shader_compiler/ShaderProgramParser.cpp

@@ -109,6 +109,11 @@ static const char* SHADER_HEADER = R"(#version 450 core
 #define ANKI_SPECIALIZATION_CONSTANT_IVEC3(n, id, defltVal) ANKI_SPECIALIZATION_CONSTANT_X3(IVec3, I32, n, id, defltVal)
 #define ANKI_SPECIALIZATION_CONSTANT_IVEC3(n, id, defltVal) ANKI_SPECIALIZATION_CONSTANT_X3(IVec3, I32, n, id, defltVal)
 #define ANKI_SPECIALIZATION_CONSTANT_IVEC4(n, id, defltVal) ANKI_SPECIALIZATION_CONSTANT_X4(IVec4, I32, n, id, defltVal)
 #define ANKI_SPECIALIZATION_CONSTANT_IVEC4(n, id, defltVal) ANKI_SPECIALIZATION_CONSTANT_X4(IVec4, I32, n, id, defltVal)
 
 
+#define ANKI_SPECIALIZATION_CONSTANT_U32(n, id, defltVal) ANKI_SPECIALIZATION_CONSTANT_X(U32, n, id, defltVal)
+#define ANKI_SPECIALIZATION_CONSTANT_UVEC2(n, id, defltVal) ANKI_SPECIALIZATION_CONSTANT_X2(UVec2, U32, n, id, defltVal)
+#define ANKI_SPECIALIZATION_CONSTANT_UVEC3(n, id, defltVal) ANKI_SPECIALIZATION_CONSTANT_X3(UVec3, U32, n, id, defltVal)
+#define ANKI_SPECIALIZATION_CONSTANT_UVEC4(n, id, defltVal) ANKI_SPECIALIZATION_CONSTANT_X4(UVec4, U32, n, id, defltVal)
+
 #define ANKI_SPECIALIZATION_CONSTANT_F32(n, id, defltVal) ANKI_SPECIALIZATION_CONSTANT_X(F32, n, id, defltVal)
 #define ANKI_SPECIALIZATION_CONSTANT_F32(n, id, defltVal) ANKI_SPECIALIZATION_CONSTANT_X(F32, n, id, defltVal)
 #define ANKI_SPECIALIZATION_CONSTANT_VEC2(n, id, defltVal) ANKI_SPECIALIZATION_CONSTANT_X2(Vec2, F32, n, id, defltVal)
 #define ANKI_SPECIALIZATION_CONSTANT_VEC2(n, id, defltVal) ANKI_SPECIALIZATION_CONSTANT_X2(Vec2, F32, n, id, defltVal)
 #define ANKI_SPECIALIZATION_CONSTANT_VEC3(n, id, defltVal) ANKI_SPECIALIZATION_CONSTANT_X3(Vec3, F32, n, id, defltVal)
 #define ANKI_SPECIALIZATION_CONSTANT_VEC3(n, id, defltVal) ANKI_SPECIALIZATION_CONSTANT_X3(Vec3, F32, n, id, defltVal)

+ 2 - 0
src/anki/shader_compiler/ShaderProgramReflection.cpp

@@ -523,6 +523,8 @@ Error SpirvReflector::constsReflection(DynamicArrayAuto<Const>& consts, ShaderTy
 		switch(type.basetype)
 		switch(type.basetype)
 		{
 		{
 		case spirv_cross::SPIRType::UInt:
 		case spirv_cross::SPIRType::UInt:
+			newConst.m_type = ShaderVariableDataType::UINT;
+			break;
 		case spirv_cross::SPIRType::Int:
 		case spirv_cross::SPIRType::Int:
 			newConst.m_type = ShaderVariableDataType::INT;
 			newConst.m_type = ShaderVariableDataType::INT;
 			break;
 			break;