summaryrefslogtreecommitdiffstats
path: root/tests/vkray
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-11-12 09:57:46 -0800
committerGitHub <noreply@github.com>2018-11-12 09:57:46 -0800
commit039c233d9e4617ba9edd702a8275df0837ca8365 (patch)
tree75d22b74eb2e163bf5d57dc1a202b1b90aba10bd /tests/vkray
parentc07f60af241b1b0f7b7eba62c65d9fe750f8f3b7 (diff)
Add callable shader support for Vulkan ray tracing (#718)
* Add callable shader support for Vulkan ray tracing This change extends the previous work to update Vulkan ray tracing support for the finished `GL_NV_ray_tracing` spec. One of the features missing in the experimental extension that was added to the final spec is "callable shaders," which allow ray tracing shaders to call other shaders as general-purpose subroutines. Most of the implementation work here mirrors what was done for the `TraceRay()` function to map it to `traceNV()`. We map the generic `CallShader<P>` function to the non-generic `executeCallableNV`, with a payload identifier that indicates a specific global variable of type `P` (the global variable being generated from a `static` local in `CallShader`). A new modifier is added to identify the payload structure, and the parameter binding/layout logic introduces a new resource kind for callable-shader payload data (where previously the logic had assumed ray and callable payloads should use the same resource kind). Two test shaders are included: one for the callable shader (`callable.slang`) and one for a ray generation shader that calls it (`callable-caller.slang`). Just for kicks, the payload data type is defined in a shared file so that we can be sure the two agree (trying to emulate what might be good practice, and ensure that ray tracing support works together with other Slang mechanisms). * Typo fix: assocaited->associated One instance was found in review, but I went ahead and fixed a bunch since I seem to make this typo a lot. * Typo fix: defintiion->definition
Diffstat (limited to 'tests/vkray')
-rw-r--r--tests/vkray/callable-caller.slang23
-rw-r--r--tests/vkray/callable-caller.slang.glsl67
-rw-r--r--tests/vkray/callable-shared.slang8
-rw-r--r--tests/vkray/callable.slang16
-rw-r--r--tests/vkray/callable.slang.glsl26
5 files changed, 140 insertions, 0 deletions
diff --git a/tests/vkray/callable-caller.slang b/tests/vkray/callable-caller.slang
new file mode 100644
index 000000000..e423f2bec
--- /dev/null
+++ b/tests/vkray/callable-caller.slang
@@ -0,0 +1,23 @@
+// callable-caller.slang
+
+//TEST:CROSS_COMPILE: -profile sm_6_3 -stage raygeneration -entry main -target spirv-assembly
+
+import callable_shared;
+
+cbuffer C
+{
+ uint shaderIndex;
+};
+
+RWTexture2D<float4> gImage;
+
+void main()
+{
+ MaterialPayload payload;
+ payload.albedo = 0;
+ payload.uv = float2(DispatchRaysIndex().xy) / float2(DispatchRaysDimensions().xy);
+
+ CallShader(shaderIndex, payload);
+
+ gImage[DispatchRaysIndex().xy] = payload.albedo;
+}
diff --git a/tests/vkray/callable-caller.slang.glsl b/tests/vkray/callable-caller.slang.glsl
new file mode 100644
index 000000000..2704e6720
--- /dev/null
+++ b/tests/vkray/callable-caller.slang.glsl
@@ -0,0 +1,67 @@
+#version 460
+
+layout(row_major) uniform;
+layout(row_major) buffer;
+#extension GL_NV_ray_tracing : require
+
+struct SLANG_ParameterGroup_C_0
+{
+ uint shaderIndex_0;
+};
+
+layout(binding = 0)
+layout(std140) uniform C_0
+{
+ uint shaderIndex_0;
+};
+
+struct MaterialPayload_0
+{
+ vec4 albedo_0;
+ vec2 uv_0;
+};
+
+layout(location = 0)
+rayPayloadNV MaterialPayload_0 p_0;
+
+layout(rgba32f)
+layout(binding = 1)
+uniform image2D gImage_0;
+
+void CallShader_0(
+ uint shaderIndex_1,
+ inout MaterialPayload_0 payload_0)
+{
+ p_0 = payload_0;
+ executeCallableNV(shaderIndex_1, (0));
+ payload_0 = p_0;
+ return;
+}
+
+void main()
+{
+ MaterialPayload_0 payload_1;
+ payload_1.albedo_0 = vec4(0);
+
+ uvec3 _S1 = gl_LaunchIDNV;
+ vec2 _S2 = vec2(_S1.xy);
+
+ uvec3 _S3 = gl_LaunchSizeNV;
+ vec2 _S4 = _S2 / vec2(_S3.xy);
+
+ payload_1.uv_0 = _S4;
+
+ uint _S5 = shaderIndex_0;
+
+ MaterialPayload_0 _S6;
+ _S6 = payload_1;
+ CallShader_0(_S5, _S6);
+ payload_1 = _S6;
+
+ uvec3 _S7 = gl_LaunchIDNV;
+ imageStore(
+ gImage_0,
+ ivec2(_S7.xy),
+ payload_1.albedo_0);
+ return;
+}
diff --git a/tests/vkray/callable-shared.slang b/tests/vkray/callable-shared.slang
new file mode 100644
index 000000000..09e76aab1
--- /dev/null
+++ b/tests/vkray/callable-shared.slang
@@ -0,0 +1,8 @@
+// callable-shared.slang
+//TEST_IGNORE_FILE:
+
+struct MaterialPayload
+{
+ float4 albedo;
+ float2 uv;
+};
diff --git a/tests/vkray/callable.slang b/tests/vkray/callable.slang
new file mode 100644
index 000000000..59d42546a
--- /dev/null
+++ b/tests/vkray/callable.slang
@@ -0,0 +1,16 @@
+// callable.slang
+
+//TEST:CROSS_COMPILE: -profile sm_6_3 -stage callable -entry main -target spirv-assembly
+
+import callable_shared;
+
+Texture2D gAlbedoMap;
+SamplerState gSampler;
+
+void main(in out MaterialPayload ioPayload)
+{
+ ioPayload.albedo = gAlbedoMap.SampleLevel(
+ gSampler,
+ ioPayload.uv,
+ 0);
+}
diff --git a/tests/vkray/callable.slang.glsl b/tests/vkray/callable.slang.glsl
new file mode 100644
index 000000000..9b573a8ab
--- /dev/null
+++ b/tests/vkray/callable.slang.glsl
@@ -0,0 +1,26 @@
+#version 460
+
+#extension GL_NV_ray_tracing : require
+
+layout(binding = 0) uniform texture2D gAlbedoMap_0;
+layout(binding = 1) uniform sampler gSampler_0;
+
+struct MaterialPayload_0
+{
+ vec4 albedo_0;
+ vec2 uv_0;
+};
+
+callableDataInNV MaterialPayload_0 _S1;
+
+void main()
+{
+ vec4 _S2 = textureLod(
+ sampler2D(gAlbedoMap_0,gSampler_0),
+ _S1.uv_0,
+ float(0));
+
+ _S1.albedo_0 = _S2;
+
+ return;
+}