Browse Source

Minor change in GLSL pointers

Panagiotis Christopoulos Charitos 4 years ago
parent
commit
9968b6a8d1
3 changed files with 33 additions and 22 deletions
  1. 10 2
      AnKi/ShaderCompiler/ShaderProgramParser.cpp
  2. 10 6
      AnKi/Shaders/RtShadowsHit.ankiprog
  3. 13 14
      Tests/Gr/Gr.cpp

+ 10 - 2
AnKi/ShaderCompiler/ShaderProgramParser.cpp

@@ -235,10 +235,18 @@ static const char* SHADER_HEADER = R"(#version 460 core
 #define ANKI_SPECIALIZATION_CONSTANT_VEC3(n, id) _ANKI_SCONST_X3(Vec3, F32, n, id,)
 #define ANKI_SPECIALIZATION_CONSTANT_VEC4(n, id) _ANKI_SCONST_X4(Vec4, F32, n, id,)
 
-#define ANKI_REF(type, alignment) \
-	layout(buffer_reference, scalar, buffer_reference_align = (alignment)) buffer type##Ref \
+#define ANKI_DEFINE_LOAD_STORE(type, alignment) \
+	layout(buffer_reference, scalar, buffer_reference_align = (alignment)) buffer _Ref##type \
 	{ \
 		type m_value; \
+	}; \
+	void load(U64 address, out type o) \
+	{ \
+		o = _Ref##type(address).m_value; \
+	} \
+	void store(U64 address, type i) \
+	{ \
+		_Ref##type(address).m_value = i; \
 	}
 
 #define ANKI_PADDING(bytes) U8 _padding_ ## __LINE__[bytes]

+ 10 - 6
AnKi/Shaders/RtShadowsHit.ankiprog

@@ -28,8 +28,8 @@ layout(location = 0) rayPayloadInEXT F32 g_payload;
 
 hitAttributeEXT vec2 g_attribs;
 
-ANKI_REF(U16Vec3, 2);
-ANKI_REF(MainVertex, ANKI_ALIGNOF(MainVertex));
+ANKI_DEFINE_LOAD_STORE(U16Vec3, 2)
+ANKI_DEFINE_LOAD_STORE(MainVertex, ANKI_ALIGNOF(MainVertex))
 
 void main()
 {
@@ -38,12 +38,16 @@ void main()
 	const MeshGpuDescriptor mesh = model.m_mesh;
 
 	const U32 offset = U32(gl_PrimitiveID) * ANKI_SIZEOF(U16Vec3);
-	const UVec3 indices = UVec3(U16Vec3Ref(mesh.m_indexBufferPtr + U64(offset)).m_value);
+	U16Vec3 indices16;
+	load(mesh.m_indexBufferPtr + U64(offset), indices16);
+	const UVec3 indices = UVec3(indices16);
+
 	const U64 vertBufferPtr = mesh.m_vertexBufferPtrs[VERTEX_ATTRIBUTE_BUFFER_ID_NORMAL_TANGENT_UV0];
 
-	const MainVertex vert0 = MainVertexRef(vertBufferPtr + U64(indices[0] * ANKI_SIZEOF(MainVertex))).m_value;
-	const MainVertex vert1 = MainVertexRef(vertBufferPtr + U64(indices[1] * ANKI_SIZEOF(MainVertex))).m_value;
-	const MainVertex vert2 = MainVertexRef(vertBufferPtr + U64(indices[2] * ANKI_SIZEOF(MainVertex))).m_value;
+	MainVertex vert0, vert1, vert2;
+	load(vertBufferPtr + U64(indices[0] * ANKI_SIZEOF(MainVertex)), vert0);
+	load(vertBufferPtr + U64(indices[1] * ANKI_SIZEOF(MainVertex)), vert1);
+	load(vertBufferPtr + U64(indices[2] * ANKI_SIZEOF(MainVertex)), vert2);
 
 	const Vec3 barycentrics = Vec3(1.0f - g_attribs.x - g_attribs.y, g_attribs.x, g_attribs.y);
 

+ 13 - 14
Tests/Gr/Gr.cpp

@@ -2310,22 +2310,22 @@ ANKI_TEST(Gr, BufferAddress)
 	static const char* PROG_SRC = R"(
 layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
 
-ANKI_REF(Vec4);
+ANKI_DEFINE_LOAD_STORE(Vec4, 4)
 
 layout(push_constant) uniform u_
 {
-	U64 u_bufferAddress;
-	U64 u_padding0;
-};
-
-layout(set = 0, binding = 0) writeonly buffer ss_
-{
-	Vec4 u_result;
+	U64 u_bufferAddressRead;
+	U64 u_bufferAddressWrite;
 };
 
 void main()
 {
-	u_result = Vec4Ref(u_bufferAddress).m_value + Vec4Ref(u_bufferAddress + 16u).m_value;
+	Vec4 a;
+	load(u_bufferAddressRead, a);
+	Vec4 b;
+	load(u_bufferAddressRead + 16ul, b);
+
+	store(u_bufferAddressWrite, a + b);
 })";
 
 	ShaderPtr shader = createShader(PROG_SRC, ShaderType::COMPUTE, *gr);
@@ -2359,14 +2359,13 @@ void main()
 
 	struct Address
 	{
-		PtrSize m_address;
-		PtrSize m_padding;
+		PtrSize m_addressRead;
+		PtrSize m_addressWrite;
 	} address;
-	address.m_address = ptrBuff->getGpuAddress();
+	address.m_addressRead = ptrBuff->getGpuAddress();
+	address.m_addressWrite = resBuff->getGpuAddress();
 	cmdb->setPushConstants(&address, sizeof(address));
 
-	cmdb->bindStorageBuffer(0, 0, resBuff, 0, MAX_PTR_SIZE);
-
 	cmdb->dispatchCompute(1, 1, 1);
 
 	cmdb->flush();