Skip to content

Commit 86380ac

Browse files
Support gl_InstanceID in RT shaders.
1 parent b7823ec commit 86380ac

4 files changed

Lines changed: 18 additions & 5 deletions

File tree

reference/opt/shaders/vulkan/rchit/ray_tracing.nocompat.vk.rchit.vk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ layout(location = 0) rayPayloadInNV float payload;
55

66
void main()
77
{
8-
payload = 1.0;
8+
payload = 1.0 + float(gl_InstanceID);
99
}
1010

reference/shaders/vulkan/rchit/ray_tracing.nocompat.vk.rchit.vk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ layout(location = 0) rayPayloadInNV float payload;
55

66
void main()
77
{
8-
payload = 1.0;
8+
payload = 1.0 + float(gl_InstanceID);
99
}
1010

shaders/vulkan/rchit/ray_tracing.nocompat.vk.rchit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ layout(location = 0) rayPayloadInNV float payload;
55

66
void main()
77
{
8-
payload = 1.0;
8+
payload = 1.0 + float(gl_InstanceID);
99
}

spirv_glsl.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6792,8 +6792,21 @@ string CompilerGLSL::builtin_to_glsl(BuiltIn builtin, StorageClass storage)
67926792
return "gl_VertexID";
67936793
case BuiltInInstanceId:
67946794
if (options.vulkan_semantics)
6795-
SPIRV_CROSS_THROW(
6796-
"Cannot implement gl_InstanceID in Vulkan GLSL. This shader was created with GL semantics.");
6795+
{
6796+
auto model = get_entry_point().model;
6797+
switch (model)
6798+
{
6799+
case spv::ExecutionModelIntersectionKHR:
6800+
case spv::ExecutionModelAnyHitKHR:
6801+
case spv::ExecutionModelClosestHitKHR:
6802+
// gl_InstanceID is allowed in these shaders.
6803+
break;
6804+
6805+
default:
6806+
SPIRV_CROSS_THROW(
6807+
"Cannot implement gl_InstanceID in Vulkan GLSL. This shader was created with GL semantics.");
6808+
}
6809+
}
67976810
return "gl_InstanceID";
67986811
case BuiltInVertexIndex:
67996812
if (options.vulkan_semantics)

0 commit comments

Comments
 (0)