https://github.com/shader-slang/slang
Revision 0ab4d044896ad3d8c5c9cedbb7bd7ec94be81d69 authored by Tim Foley on 29 January 2021, 21:17:51 UTC, committed by GitHub on 29 January 2021, 21:17:51 UTC
The problem would manifest for any code that declared a DXR 1.1 `RayQuery` value, but then only used it as one location in their code.
The most common way for this to arise in user code was declaring a `RayQuery` and then handing it off to a helper/worker subroutine.

    RayQuery<0> myRayQuery;
    helperRoutine(myRayQuery, ...);

The root cause was in the emit logic, where the initialization of `myRayQuery` above (a `defaultConstruct` operation in our IR) was getting folded into its (only) use site.
This folding makes some sense, because the initialization of a ray query is not an operation with side effects, but doesn't work in practice because our way of handling default construction in HLSL output is by using a variable declaration.

The simple fix here is to ensure that `defaultConstruct` instructions never get folded into use sites.

If we decide to revisit the logic here, it might be possible to separate out the case where a `defaultConstruct` is being used as a stand-alone instruction, where we can emit it as:

    RayQuery<0> myRayQuery;

versus cases where the `defaultConstruct` is being used as a sub-expression, such as:

    helperRoutine(RayQuery<0>(), ...);

Whether or not we can emit the latter form (or if it would be equivalent) depends on details of how constructors like this are being implemented in dxc.
For now it seems safest to emit things in a form that is obviously expected to work.

Aside: Historically, the HLSL language has had no notion of "constructors" as being a thing.
A variable that is declared but not initialized in HLSL has always been left uninitialized, since the first version of the language.
The `RayQuery` type in DXR 1.1 is the first example of a type that appears to have a C++-style "default constructor," although HLSL as implemented by dxc still does not expose constructors as a user-visible or documented feature.
(There is the small detail that the DXR 1.0 `HitGroup` type also relied on C++ constructor syntax, but I'm not aware of anybody using that feature right now, so it is mostly a curiosity.)
1 parent da6463a
History
Tip revision: 0ab4d044896ad3d8c5c9cedbb7bd7ec94be81d69 authored by Tim Foley on 29 January 2021, 21:17:51 UTC
Fix issue when passing ray query to a subroutine (#1680)
Tip revision: 0ab4d04
File Mode Size
.github
build
docs
examples
external
extras
prelude
source
tests
tools
.editorconfig -rw-r--r-- 937 bytes
.gitattributes -rw-r--r-- 95 bytes
.gitignore -rw-r--r-- 1023 bytes
.gitmodules -rw-r--r-- 951 bytes
CODE_OF_CONDUCT.md -rw-r--r-- 3.1 KB
LICENSE -rw-r--r-- 1.1 KB
README.md -rw-r--r-- 8.6 KB
github_build.sh -rw-r--r-- 495 bytes
github_test.sh -rw-r--r-- 546 bytes
premake.bat -rw-r--r-- 120 bytes
premake5.lua -rw-r--r-- 46.9 KB
slang-com-helper.h -rw-r--r-- 4.8 KB
slang-com-ptr.h -rw-r--r-- 4.9 KB
slang-tag-version.h -rw-r--r-- 36 bytes
slang.h -rw-r--r-- 167.3 KB
slang.sln -rw-r--r-- 18.8 KB
test.bat -rw-r--r-- 1.4 KB

README.md

back to top