Skip to content

Commit 6274e17

Browse files
author
Tim Foley
authored
Initial work to support OptiX output for ray tracing shaders (shader-slang#1307)
* Initial work to support OptiX output for ray tracing shaders This change represents in-progress work toward allowing Slang/HLSL ray-tracing shaders to be cross-compiled for execution on top of OptiX. The work as it exists here is incomplete, but the changes are incremental and should not disturb existing supported use cases. One major unresolved issue in this work is that the OptiX SDK does not appear to set an environment variable Changes include: * Modified the premake script to support new options for adding OptiX to the build. Right now the default path to the OptiX SDK is hard-coded because the installer doesn't seem to set an environment variable. We will want to update that to have a reasonable default path for both Windows and Unix-y platforms in a later chance. * I ran the premake generator on the project since I added new options, which resulted in a bunch of diffs to the Visual Studio project files that are unrelated to this change. Many of the diffs come from previous edits that added files using only the Visual Studio IDE rather than by re-running premake, so it is arguably better to have the checked-in project files more accurately reflect the generated files used for CI builds. * The "downstream compiler" abstraction was extended to have an explicit notion of the kind of pipeline that shaders are being compiled for (e.g., compute vs. rasterization vs. ray tracing). This option is used to tell the NVRTC case when it needs to include the OptiX SDK headers in the search path for shader compilation (and also when it should add a `#define` to make the prelude pull in OptiX). This code again uses a hard-coded default path for the OptiX SDK; we will need to modify that to have a better discovery approach and also to support an API or command-line override. * One note for the future is that instead of passing down a "pipeline type" we could instead pass down the list/set of stages for the kernels being compiled, and the OptiX support could be enabled whenever there is *any* ray tracing entry point present in a module. That approach would allow mixing RT and compute kernels during downstream compilation. We will need to revisit these choices when we start supporting code generation for multiple entry points at a time. * The CUDA emit logic is currently mostly unchanged. The biggest difference is that when emitting a ray-tracing entry point we prefix the name of the generated `__global__` function with a marker for its stage type, as required by the OptiX runtime (e.g., a `__raygen__` prefix is required on all ray-generation entry points). * The `Renderer` abstraction had a bare minimum of changes made to be able to understand that ray-tracing pipelines exist, and also that some APIs will require the name of each entry point along with its binary data in order to create a program. * The `ShaderCompileRequest` type was updated so that only a single "source" is supported (rather than distinct source for each entry point), and also the entry points have been turned into a single list where each entry identifies its stage instead of a fixed list of fields for the supported entry-point types. * The CUDA compute path had a lot of code added to support execution for the new ray-tracing pipeline type. The logic is mostly derived from the `optixHello` example in the OptiX SDK, and at present only supports running a single ray-generation shader with no parameters. The code here is not intended to be ready for use, but represents a signficiant amount of learning-by-doing. * The `slang-support.cpp` file in `render-test` was updated so that instead of having separate compilation logic for compute vs. rasterization shaders (which would mean adding a third path for ray tracing), there is now a single flow to the code that works for all pipeline types and any kind of entry points. * Implicit in the new code is dropping support for the way GLSL was being compiled for pass-through render tests, which means pass-through GLSL render tests will no longer work. It seems like we didn't have any of those to begin with, though, so it is no great loss. * Also implicit are some new invariants about how shaders without known/default entry points need to be handled. For example, the ray tracing case intentionally does not fill in entry points on the `ShaderCompileRequest` and instead fully relies on the Slang compiler's support for discovering and enumerating entry points via reflection. As a consequence of those edits the `-no-default-entry-point` flag on `render-test` is probably not working, but it seems like we don't have any test cases that use that flag anyway. Given the seemingly breaking changes in those last two bullets, I was surprised to find that all our current tests seem to pass with this change. If there are things that I'm missing, I hope they will come up in review. * fixup: issues from review and CI * Some issues noted during the review process (e.g., a missing `break`) * Fix logic for render tests with `-no-default-entry-point`. I had somehow missed that we had tests reliant on that flag. This required a bit of refactoring to pass down the relevant flag (luckily the function in question was already being passed most of what was in `Options`, so that just passing that in directly actually simplifies the call sites a bit. * There was a missing line of code to actually add the default compute entry points to the compile request. I think this was a problem that slipped in as part of some pre-PR refactoring/cleanup changes that I failed to re-test.
1 parent f38c082 commit 6274e17

19 files changed

+784
-285
lines changed

examples/gpu-printing/gpu-printing.vcxproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@
161161
<OptimizeReferences>true</OptimizeReferences>
162162
</Link>
163163
</ItemDefinitionGroup>
164+
<ItemGroup>
165+
<ClInclude Include="gpu-printing-ops.h" />
166+
<ClInclude Include="gpu-printing.h" />
167+
</ItemGroup>
164168
<ItemGroup>
165169
<ClCompile Include="gpu-printing.cpp" />
166170
<ClCompile Include="main.cpp" />
@@ -180,10 +184,6 @@
180184
<Project>{222F7498-B40C-4F3F-A704-DDEB91A4484A}</Project>
181185
</ProjectReference>
182186
</ItemGroup>
183-
<ItemGroup>
184-
<ClInclude Include="gpu-printing-ops.h" />
185-
<ClInclude Include="gpu-printing.h" />
186-
</ItemGroup>
187187
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
188188
<ImportGroup Label="ExtensionTargets">
189189
</ImportGroup>
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ItemGroup>
4+
<Filter Include="Header Files">
5+
<UniqueIdentifier>{21EB8090-0D4E-1035-B6D3-48EBA215DCB7}</UniqueIdentifier>
6+
</Filter>
47
<Filter Include="Source Files">
58
<UniqueIdentifier>{E9C7FDCE-D52A-8D73-7EB0-C5296AF258F6}</UniqueIdentifier>
69
</Filter>
710
</ItemGroup>
811
<ItemGroup>
9-
<ClCompile Include="main.cpp">
12+
<ClInclude Include="gpu-printing-ops.h">
13+
<Filter>Header Files</Filter>
14+
</ClInclude>
15+
<ClInclude Include="gpu-printing.h">
16+
<Filter>Header Files</Filter>
17+
</ClInclude>
18+
</ItemGroup>
19+
<ItemGroup>
20+
<ClCompile Include="gpu-printing.cpp">
1021
<Filter>Source Files</Filter>
1122
</ClCompile>
12-
<ClCompile Include="gpu-printing.cpp">
23+
<ClCompile Include="main.cpp">
1324
<Filter>Source Files</Filter>
1425
</ClCompile>
1526
</ItemGroup>
@@ -21,12 +32,4 @@
2132
<Filter>Source Files</Filter>
2233
</None>
2334
</ItemGroup>
24-
<ItemGroup>
25-
<ClInclude Include="gpu-printing-ops.h">
26-
<Filter>Source Files</Filter>
27-
</ClInclude>
28-
<ClInclude Include="gpu-printing.h">
29-
<Filter>Source Files</Filter>
30-
</ClInclude>
31-
</ItemGroup>
3235
</Project>

prelude/slang-cuda-prelude.h

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#ifdef SLANG_CUDA_ENABLE_OPTIX
2+
#include <optix.h>
3+
#endif
4+
15

26
// Must be large enough to cause overflow and therefore infinity
37
#ifndef SLANG_INFINITY

premake5.lua

+30-3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,21 @@ newoption {
9797
value = "path"
9898
}
9999

100+
newoption {
101+
trigger = "enable-optix",
102+
description = "(Optional) If true will enable OptiX build/ tests (also implicitly enables CUDA)",
103+
value = "bool",
104+
default = "false",
105+
allowed = { { "true", "True"}, { "false", "False" } }
106+
}
107+
108+
newoption {
109+
trigger = "optix-sdk-path",
110+
description = "(Optional) Path to the root of OptiX SDK. (Implicitly enabled OptiX and CUDA)",
111+
value = "path"
112+
}
113+
114+
100115
newoption {
101116
trigger = "enable-profile",
102117
description = "(Optional) If true will enable slang-profile tool - suitable for gprof usage on linux",
@@ -111,13 +126,21 @@ targetDetail = _OPTIONS["target-detail"]
111126
buildGlslang = (_OPTIONS["build-glslang"] == "true")
112127
enableCuda = not not (_OPTIONS["enable-cuda"] == "true" or _OPTIONS["cuda-sdk-path"])
113128
enableProfile = (_OPTIONS["enable-profile"] == "true")
129+
optixPath = _OPTIONS["optix-sdk-path"]
130+
enableOptix = not not (_OPTIONS["enable-optix"] == "true" or optixPath)
131+
enableProfile = (_OPTIONS["enable-profile"] == "true")
132+
133+
if enableOptix then
134+
optixPath = optixPath or "C:/ProgramData/NVIDIA Corporation/OptiX SDK 7.0.0/"
135+
enableCuda = true;
136+
end
114137

115138
-- cudaPath is only set if cuda is enabled, and CUDA_PATH enviromental variable is set
116139
cudaPath = nil
117140
if enableCuda then
118141
-- Get the CUDA path. Use the value set on cuda-sdk-path by default, if not set use the environment variable.
119142
cudaPath = (_OPTIONS["cuda-sdk-path"] or os.getenv("CUDA_PATH"))
120-
end
143+
end
121144

122145
-- Is true when the target is really windows (ie not something on top of windows like cygwin)
123146
local isTargetWindows = (os.target() == "windows") and not (targetDetail == "mingw" or targetDetail == "cygwin")
@@ -568,15 +591,19 @@ toolSharedLibrary "render-test"
568591
defines { "RENDER_TEST_CUDA" }
569592
includedirs { cudaPath .. "/include" }
570593
includedirs { cudaPath .. "/include", cudaPath .. "/common/inc" }
594+
595+
if optixPath then
596+
defines { "RENDER_TEST_OPTIX" }
597+
includedirs { optixPath .. "include/" }
598+
end
571599

572600
links { "cuda", "cudart" }
573601

574602
filter { "platforms:x86" }
575603
libdirs { cudaPath .. "/lib/Win32/" }
576604

577605
filter { "platforms:x64" }
578-
libdirs { cudaPath .. "/lib/x64/" }
579-
606+
libdirs { cudaPath .. "/lib/x64/" }
580607
end
581608

582609
--

0 commit comments

Comments
 (0)