From 1993f3af5d1fd9cb0b2e08268f8a3d3b5d619440 Mon Sep 17 00:00:00 2001
From: Sascha Willems <webmaster@saschawillems.de>
Date: Mon, 18 Oct 2021 21:41:18 +0200
Subject: [PATCH] Changed ray tracing closest hit shader hit attributes to vec2

Fixes #878
---
 data/shaders/glsl/raytracingbasic/closesthit.rchit       | 2 +-
 data/shaders/glsl/raytracingcallable/closesthit.rchit    | 1 -
 data/shaders/glsl/raytracingreflections/closesthit.rchit | 2 +-
 data/shaders/glsl/raytracingshadows/closesthit.rchit     | 2 +-
 data/shaders/hlsl/compile.py                             | 5 ++++-
 data/shaders/hlsl/raytracingbasic/closesthit.rchit       | 2 +-
 data/shaders/hlsl/raytracingcallable/closesthit.rchit    | 7 +------
 data/shaders/hlsl/raytracingreflections/closesthit.rchit | 2 +-
 data/shaders/hlsl/raytracingshadows/closesthit.rchit     | 2 +-
 9 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/data/shaders/glsl/raytracingbasic/closesthit.rchit b/data/shaders/glsl/raytracingbasic/closesthit.rchit
index 743a2585..44936f20 100644
--- a/data/shaders/glsl/raytracingbasic/closesthit.rchit
+++ b/data/shaders/glsl/raytracingbasic/closesthit.rchit
@@ -3,7 +3,7 @@
 #extension GL_EXT_nonuniform_qualifier : enable
 
 layout(location = 0) rayPayloadInEXT vec3 hitValue;
-hitAttributeEXT vec3 attribs;
+hitAttributeEXT vec2 attribs;
 
 void main()
 {
diff --git a/data/shaders/glsl/raytracingcallable/closesthit.rchit b/data/shaders/glsl/raytracingcallable/closesthit.rchit
index 1b806736..210a2d59 100644
--- a/data/shaders/glsl/raytracingcallable/closesthit.rchit
+++ b/data/shaders/glsl/raytracingcallable/closesthit.rchit
@@ -4,7 +4,6 @@
 
 layout(location = 0) rayPayloadInEXT vec3 hitValue;
 layout(location = 0) callableDataEXT vec3 outColor;
-hitAttributeEXT vec3 attribs;
 
 layout(binding = 0, set = 0) uniform accelerationStructureEXT topLevelAS;
 
diff --git a/data/shaders/glsl/raytracingreflections/closesthit.rchit b/data/shaders/glsl/raytracingreflections/closesthit.rchit
index 6d057617..301686c7 100644
--- a/data/shaders/glsl/raytracingreflections/closesthit.rchit
+++ b/data/shaders/glsl/raytracingreflections/closesthit.rchit
@@ -11,7 +11,7 @@ struct RayPayload {
 
 layout(location = 0) rayPayloadInEXT RayPayload rayPayload;
 
-hitAttributeEXT vec3 attribs;
+hitAttributeEXT vec2 attribs;
 
 layout(binding = 0, set = 0) uniform accelerationStructureEXT topLevelAS;
 layout(binding = 2, set = 0) uniform UBO 
diff --git a/data/shaders/glsl/raytracingshadows/closesthit.rchit b/data/shaders/glsl/raytracingshadows/closesthit.rchit
index df016938..25079bdf 100644
--- a/data/shaders/glsl/raytracingshadows/closesthit.rchit
+++ b/data/shaders/glsl/raytracingshadows/closesthit.rchit
@@ -4,7 +4,7 @@
 
 layout(location = 0) rayPayloadInEXT vec3 hitValue;
 layout(location = 2) rayPayloadEXT bool shadowed;
-hitAttributeEXT vec3 attribs;
+hitAttributeEXT vec2 attribs;
 
 layout(binding = 0, set = 0) uniform accelerationStructureEXT topLevelAS;
 layout(binding = 2, set = 0) uniform UBO 
diff --git a/data/shaders/hlsl/compile.py b/data/shaders/hlsl/compile.py
index 24a9f250..2b44f4d2 100644
--- a/data/shaders/hlsl/compile.py
+++ b/data/shaders/hlsl/compile.py
@@ -37,6 +37,7 @@ for root, dirs, files in os.walk(dir_path):
             hlsl_file = os.path.join(root, file)
             spv_out = hlsl_file + ".spv"
 
+            target = ''
             profile = ''
             if(hlsl_file.find('.vert') != -1):
                 profile = 'vs_6_1'
@@ -53,6 +54,7 @@ for root, dirs, files in os.walk(dir_path):
             elif(hlsl_file.find('.rgen') != -1 or
 				hlsl_file.find('.rchit') != -1 or
 				hlsl_file.find('.rmiss') != -1):
+                target='-fspv-target-env=vulkan1.2'
                 profile = 'lib_6_3'
 
             print('Compiling %s' % (hlsl_file))
@@ -61,9 +63,10 @@ for root, dirs, files in os.walk(dir_path):
                 '-spirv',
                 '-T', profile,
                 '-E', 'main',
-                '-fspv-extension=SPV_NV_ray_tracing',
+                '-fspv-extension=SPV_KHR_ray_tracing',
                 '-fspv-extension=SPV_KHR_multiview',
                 '-fspv-extension=SPV_KHR_shader_draw_parameters',
                 '-fspv-extension=SPV_EXT_descriptor_indexing',
+                target,
                 hlsl_file,
                 '-Fo', spv_out])
diff --git a/data/shaders/hlsl/raytracingbasic/closesthit.rchit b/data/shaders/hlsl/raytracingbasic/closesthit.rchit
index ace73d3d..2a8921ce 100644
--- a/data/shaders/hlsl/raytracingbasic/closesthit.rchit
+++ b/data/shaders/hlsl/raytracingbasic/closesthit.rchit
@@ -11,7 +11,7 @@ struct Payload
 };
 
 [shader("closesthit")]
-void main(inout Payload p, in float3 attribs)
+void main(inout Payload p, in float2 attribs)
 {
   const float3 barycentricCoords = float3(1.0f - attribs.x - attribs.y, attribs.x, attribs.y);
   p.hitValue = barycentricCoords;
diff --git a/data/shaders/hlsl/raytracingcallable/closesthit.rchit b/data/shaders/hlsl/raytracingcallable/closesthit.rchit
index 61caef21..80cd773d 100644
--- a/data/shaders/hlsl/raytracingcallable/closesthit.rchit
+++ b/data/shaders/hlsl/raytracingcallable/closesthit.rchit
@@ -1,10 +1,5 @@
 // Copyright 2021 Sascha Willems
 
-struct Attribute
-{
-  float2 attribs;
-};
-
 struct Payload
 {
 [[vk::location(0)]] float3 hitValue;
@@ -16,7 +11,7 @@ struct CallData
 };
 
 [shader("closesthit")]
-void main(inout Payload p, in float3 attribs)
+void main(inout Payload p, in float2 attribs)
 {
 	// Execute the callable shader indexed by the current geometry being hit
 	// For our sample this means that the first callable shader in the SBT is invoked for the first triangle, the second callable shader for the second triangle, etc.
diff --git a/data/shaders/hlsl/raytracingreflections/closesthit.rchit b/data/shaders/hlsl/raytracingreflections/closesthit.rchit
index aff970a4..643bfbe9 100644
--- a/data/shaders/hlsl/raytracingreflections/closesthit.rchit
+++ b/data/shaders/hlsl/raytracingreflections/closesthit.rchit
@@ -50,7 +50,7 @@ Vertex unpack(uint index)
 }
 
 [shader("closesthit")]
-void main(inout RayPayload rayPayload, in float3 attribs)
+void main(inout RayPayload rayPayload, in float2 attribs)
 {
 	uint PrimitiveID = PrimitiveIndex();
 	int3 index = int3(indices[3 * PrimitiveID], indices[3 * PrimitiveID + 1], indices[3 * PrimitiveID + 2]);
diff --git a/data/shaders/hlsl/raytracingshadows/closesthit.rchit b/data/shaders/hlsl/raytracingshadows/closesthit.rchit
index 0d04e5ee..4408f55c 100644
--- a/data/shaders/hlsl/raytracingshadows/closesthit.rchit
+++ b/data/shaders/hlsl/raytracingshadows/closesthit.rchit
@@ -52,7 +52,7 @@ Vertex unpack(uint index)
 }
 
 [shader("closesthit")]
-void main(in InPayload inPayload, inout InOutPayload inOutPayload, in float3 attribs)
+void main(in InPayload inPayload, inout InOutPayload inOutPayload, in float2 attribs)
 {
 	uint PrimitiveID = PrimitiveIndex();
 	int3 index = int3(indices[3 * PrimitiveID], indices[3 * PrimitiveID + 1], indices[3 * PrimitiveID + 2]);
-- 
GitLab