@@ -38,9 +38,9 @@ float3 calculateNormals(int primID, STriangleGeomInfo geom, float2 bary)
3838
3939 if (normalBufferAddress == 0 )
4040 {
41- float3 v0 = vk::RawBufferLoad <float3 >(vertexBufferAddress + indices[0 ] * 12 , 8 );
42- float3 v1 = vk::RawBufferLoad <float3 >(vertexBufferAddress + indices[1 ] * 12 , 8 );
43- float3 v2 = vk::RawBufferLoad <float3 >(vertexBufferAddress + indices[2 ] * 12 , 8 );
41+ float3 v0 = (nbl::hlsl::bda::__ptr <float3 >:: create (vertexBufferAddress) + indices[0 ]). deref (). load ( );
42+ float3 v1 = (nbl::hlsl::bda::__ptr <float3 >:: create (vertexBufferAddress) + indices[1 ]). deref (). load ( );
43+ float3 v2 = (nbl::hlsl::bda::__ptr <float3 >:: create (vertexBufferAddress) + indices[2 ]). deref (). load ( );
4444
4545 return normalize (cross (v2 - v0, v1 - v0));
4646 }
@@ -50,9 +50,9 @@ float3 calculateNormals(int primID, STriangleGeomInfo geom, float2 bary)
5050 {
5151 case NT_R8G8B8A8_SNORM:
5252 {
53- uint32_t v0 = vk::RawBufferLoad <uint32_t>(normalBufferAddress + indices[0 ] * 4 , 8 );
54- uint32_t v1 = vk::RawBufferLoad <uint32_t>(normalBufferAddress + indices[1 ] * 4 , 8 );
55- uint32_t v2 = vk::RawBufferLoad <uint32_t>(normalBufferAddress + indices[2 ] * 4 , 8 );
53+ uint32_t v0 = (nbl::hlsl::bda::__ptr <uint32_t>:: create (normalBufferAddress) + indices[0 ]). deref (). load ( );
54+ uint32_t v1 = (nbl::hlsl::bda::__ptr <uint32_t>:: create (normalBufferAddress) + indices[1 ]). deref (). load ( );
55+ uint32_t v2 = (nbl::hlsl::bda::__ptr <uint32_t>:: create (normalBufferAddress) + indices[2 ]). deref (). load ( );
5656
5757 n0 = normalize (nbl::hlsl::spirv::unpackSnorm4x8 (v0).xyz);
5858 n1 = normalize (nbl::hlsl::spirv::unpackSnorm4x8 (v1).xyz);
@@ -61,9 +61,13 @@ float3 calculateNormals(int primID, STriangleGeomInfo geom, float2 bary)
6161 break ;
6262 case NT_R32G32B32_SFLOAT:
6363 {
64- n0 = normalize (vk::RawBufferLoad<float3 >(normalBufferAddress + indices[0 ] * 12 , 8 ));
65- n1 = normalize (vk::RawBufferLoad<float3 >(normalBufferAddress + indices[1 ] * 12 , 8 ));
66- n2 = normalize (vk::RawBufferLoad<float3 >(normalBufferAddress + indices[2 ] * 12 , 8 ));
64+ float3 v0 = (nbl::hlsl::bda::__ptr<float3 >::create (normalBufferAddress) + indices[0 ]).deref ().load ();
65+ float3 v1 = (nbl::hlsl::bda::__ptr<float3 >::create (normalBufferAddress) + indices[1 ]).deref ().load ();
66+ float3 v2 = (nbl::hlsl::bda::__ptr<float3 >::create (normalBufferAddress) + indices[2 ]).deref ().load ();
67+
68+ n0 = normalize (v0);
69+ n1 = normalize (v1);
70+ n2 = normalize (v2);
6771 }
6872 break ;
6973 }
@@ -81,7 +85,8 @@ void main(inout PrimaryPayload payload, in BuiltInTriangleIntersectionAttributes
8185 const int primID = spirv::PrimitiveId;
8286 const int instanceCustomIndex = spirv::InstanceCustomIndexKHR;
8387 const int geometryIndex = spirv::RayGeometryIndexKHR;
84- const STriangleGeomInfo geom = vk::RawBufferLoad < STriangleGeomInfo > (pc.triangleGeomInfoBuffer + (instanceCustomIndex + geometryIndex) * sizeof (STriangleGeomInfo), 8 );
88+ const static uint64_t STriangleGeomInfoAlignment = nbl::hlsl::alignment_of_v<STriangleGeomInfo>;
89+ const STriangleGeomInfo geom = vk::BufferPointer<STriangleGeomInfo, STriangleGeomInfoAlignment>(pc.triangleGeomInfoBuffer + (instanceCustomIndex + geometryIndex) * sizeof (STriangleGeomInfo)).Get ();
8590 const float32_t3 vertexNormal = calculateNormals (primID, geom, attribs.barycentrics);
8691 const float32_t3 worldNormal = normalize (mul (vertexNormal, transpose (spirv::WorldToObjectKHR)).xyz);
8792
0 commit comments