Browse Source

Making GLSL's matrices row major

Panagiotis Christopoulos Charitos 10 years ago
parent
commit
7491f6f8d1

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

@@ -43,6 +43,7 @@ template<typename T>
 using GrAllocator = HeapAllocator<T>;
 
 // Some constants
+// WARNING: If you change those update the shaders
 const U MAX_VERTEX_ATTRIBUTES = 8;
 const U MAX_COLOR_ATTACHMENTS = 4;
 const U MAX_MIPMAPS = 16;

+ 1 - 0
shaders/Common.glsl

@@ -30,6 +30,7 @@ const float PI = 3.14159265358979323846;
 
 // Binding
 #define SS_BINDING(slot_, binding_) binding = slot_ * 8 + binding_
+#define UBO_BINDING(slot_, binding_) binding = slot_ * 8 + binding_
 #define TEX_BINDING(slot_, binding_) binding = slot_ * 8 + binding_
 
 // Common locations

+ 0 - 18
shaders/IsCommon.glsl

@@ -1,18 +0,0 @@
-// Copyright (C) 2009-2015, Panagiotis Christopoulos Charitos.
-// All rights reserved.
-// Code licensed under the BSD License.
-// http://www.anki3d.org/LICENSE
-
-// Contains common structures for IS
-
-#pragma anki include "shaders/Common.glsl"
-
-// Common uniforms between lights
-layout(std140, row_major, binding = 0) readonly buffer _s0
-{
-	vec4 u_projectionParams;
-	vec4 u_sceneAmbientColor;
-	vec4 u_groundLightDir;
-	vec4 u_clustererParams;
-	mat4 u_viewMat;
-};

+ 1 - 1
shaders/LfOcclusion.vert.glsl

@@ -8,7 +8,7 @@
 #pragma anki type vert
 #pragma anki include "shaders/Common.glsl"
 
-layout(binding = 0, std140) uniform _block
+layout(UBO_BINDING(0, 0), std140, row_major) uniform _block
 {
 	mat4 u_mvp;
 };

+ 3 - 2
shaders/LightResources.glsl

@@ -51,12 +51,13 @@ struct SpotLight
 	mat4 texProjectionMat;
 };
 
-layout(std140, SS_BINDING(LIGHT_SET, LIGHT_SS_BINDING + 2)) readonly buffer _s2
+layout(SS_BINDING(LIGHT_SET, LIGHT_SS_BINDING + 2), std140, row_major)
+	readonly buffer _s2
 {
 	SpotLight u_spotLights[];
 };
 
-layout(std430, SS_BINDING(LIGHT_SET, LIGHT_SS_BINDING + 3)) readonly buffer _s3
+layout(SS_BINDING(LIGHT_SET, LIGHT_SS_BINDING + 3), std430) readonly buffer _s3
 {
 	uint u_clusters[];
 };

+ 21 - 15
shaders/PpsSsao.frag.glsl

@@ -19,25 +19,30 @@ const float DARKNESS_MULTIPLIER = 2.5;
 
 layout(location = 0) in vec2 in_texCoords;
 
-layout(location = 0) out float outColor;
+layout(location = 0) out float out_color;
 
-layout(std140, binding = 0) uniform _blk
+struct Uniforms
 {
-	vec4 uProjectionParams;
+	vec4 projectionParams;
 
 	/// The projection matrix
-	mat4 uProjectionMatrix;
+	mat4 projectionMatrix;
 };
 
-layout(binding = 0) uniform sampler2D uMsDepthRt;
-layout(binding = 1) uniform sampler2D uMsRt;
-layout(binding = 2) uniform sampler2D uNoiseMap;
+layout(UBO_BINDING(0, 0), std140, row_major) uniform _blk
+{
+	Uniforms u_uniforms;
+};
+
+layout(TEX_BINDING(0, 0)) uniform sampler2D u_mMsDepthRt;
+layout(TEX_BINDING(0, 1)) uniform sampler2D u_msRt;
+layout(TEX_BINDING(0, 2)) uniform sampler2D u_noiseMap;
 
 // Get normal
 vec3 readNormal(in vec2 uv)
 {
 	vec3 normal;
-	readNormalFromGBuffer(uMsRt, uv, normal);
+	readNormalFromGBuffer(u_msRt, uv, normal);
 	return normal;
 }
 
@@ -48,7 +53,7 @@ vec3 readRandom(in vec2 uv)
 		float(WIDTH) / float(NOISE_MAP_SIZE),
 		float(HEIGHT) / float(NOISE_MAP_SIZE));
 
-	vec3 noise = texture(uNoiseMap, tmp * uv).xyz;
+	vec3 noise = texture(u_noiseMap, tmp * uv).xyz;
 	//return normalize(noise * 2.0 - 1.0);
 	return noise;
 }
@@ -56,21 +61,22 @@ vec3 readRandom(in vec2 uv)
 // Returns the Z of the position in view space
 float readZ(in vec2 uv)
 {
-	float depth = textureLod(uMsDepthRt, uv, 1.0).r;
-	float z = uProjectionParams.z / (uProjectionParams.w + depth);
+	float depth = textureLod(u_mMsDepthRt, uv, 1.0).r;
+	float z = u_uniforms.projectionParams.z
+		/ (u_uniforms.projectionParams.w + depth);
 	return z;
 }
 
 // Read position in view space
 vec3 readPosition(in vec2 uv)
 {
-	float depth = textureLod(uMsDepthRt, uv, 1.0).r;
+	float depth = textureLod(u_mMsDepthRt, uv, 1.0).r;
 
 	vec3 fragPosVspace;
 	fragPosVspace.z = readZ(uv);
 
 	fragPosVspace.xy =
-		(2.0 * uv - 1.0) * uProjectionParams.xy * fragPosVspace.z;
+		(2.0 * uv - 1.0) * u_uniforms.projectionParams.xy * fragPosVspace.z;
 
 	return fragPosVspace;
 }
@@ -96,7 +102,7 @@ void main(void)
 
 		// project sample position:
 		vec4 offset = vec4(sample_, 1.0);
-		offset = uProjectionMatrix * offset;
+		offset = u_uniforms.projectionMatrix * offset;
 		offset.xy = offset.xy / (2.0 * offset.w) + 0.5; // persp div &
 		                                                // to NDC -> [0, 1]
 
@@ -118,6 +124,6 @@ void main(void)
 #endif
 	}
 
-	outColor = 1.0 - factor;
+	out_color = 1.0 - factor;
 }
 

+ 2 - 1
src/event/EventManager.cpp

@@ -15,11 +15,12 @@ EventManager::EventManager()
 //==============================================================================
 EventManager::~EventManager()
 {
-	iterateEvents([&](Event& event) -> Error
+	Error err = iterateEvents([&](Event& event) -> Error
 	{
 		event.setMarkedForDeletion();
 		return ErrorCode::NONE;
 	});
+	(void)err;
 
 	deleteEventsMarkedForDeletion();
 }

+ 1 - 2
src/gr/Shader.cpp

@@ -79,8 +79,7 @@ static void writeShaderBlockMemoryMatrix(
 	for(U i = 0; i < elementsCount; i++)
 	{
 		U8* subbuff = buff;
-		T matrix = reinterpret_cast<const T*>(elements)[i];
-		matrix.transpose();
+		const T& matrix = static_cast<const T*>(elements)[i];
 		for(U j = 0; j < sizeof(T) / sizeof(Vec); j++)
 		{
 			ANKI_ASSERT(

+ 0 - 3
src/renderer/Is.cpp

@@ -697,9 +697,6 @@ I Is::writeSpotLight(const LightComponent& lightc,
 			* lightFrc->getViewProjectionMatrix()
 			* Mat4(camMove.getWorldTransform());
 
-		// Transpose because of driver bug
-		light.m_texProjectionMat.transpose();
-
 		shadowmapIndex = (F32)lightc.getShadowMapIndex();
 	}
 

+ 1 - 1
src/renderer/Lf.cpp

@@ -188,7 +188,7 @@ void Lf::runOcclusionTests(CommandBufferPtr& cmdb)
 		// Setup MVP UBO
 		Mat4* mvp = nullptr;
 		cmdb->updateDynamicUniforms(sizeof(Mat4), mvp);
-		*mvp = camFr.getViewProjectionMatrix().getTransposed();
+		*mvp = camFr.getViewProjectionMatrix();
 
 		// Allocate vertices and fire write job
 		BufferPtr& positionsVertBuff = m_positionsVertBuff[frame];

+ 1 - 1
src/renderer/Ssao.cpp

@@ -284,7 +284,7 @@ void Ssao::run(CommandBufferPtr& cmdb)
 		blk = static_cast<ShaderCommonUniforms*>(data);
 
 		blk->m_projectionParams = m_r->getProjectionParameters();
-		blk->m_projectionMatrix = camFr.getProjectionMatrix().getTransposed();
+		blk->m_projectionMatrix = camFr.getProjectionMatrix();
 
 		m_commonUboUpdateTimestamp = getGlobalTimestamp();
 	}

+ 2 - 1
src/resource/MaterialProgramCreator.cpp

@@ -250,7 +250,8 @@ Error MaterialProgramCreator::parseProgramTag(
 		&& (m_uniformBlockReferencedMask & glshaderbit) != ShaderTypeBit::NONE)
 	{
 		lines.pushBackSprintf(m_alloc,
-			"\nlayout(binding = 0, std140) uniform bDefaultBlock\n{");
+			"\nlayout(UBO_BINDING(0, 0), std140, row_major) "
+			"uniform bDefaultBlock\n{");
 
 		for(auto& str : m_uniformBlock)
 		{