https://github.com/shader-slang/slang
Revision 3ae31a6ed8d79c23b2ab5a7d7d755dd7e42618f7 authored by Tim Foley on 25 March 2019, 19:36:41 UTC, committed by GitHub on 25 March 2019, 19:36:41 UTC
If the user declares global shader parameters for D3D SM5.1+ or Vulkan, then they need to go into an appropriate `space` or `set`:

```hlsl
Texture2D    t; // should go in space/set 0
SamplerState s; // same here...
```

This also applies to allocation of spaces/sets to parameter blocks:

```hlsl
ParameterBlock<X> x; // should get space/set 0
ParameterBlock<Y> y; // should get space/set 1
```

In cases where there are a combination of explicitly and implicitly bound parameters, anything left implicitly bound goes into a "default" space/set:

```
ParameterBlock<X> x : register(space0); // this has claimed space/set 0

Texture2D    t; // this needs a space, so a "default" space/set of 1 will be claimed
SamplerState s; // this also needs a space/set, and will use the default
```

The logic for deciding when a default space/set was needing was, more or less, looking at all the global shader parameters and seeing if any of them needed a `register`/`binding`, and if so determining that a default space /set would be needed.

There was a bug in that logic, though, because of cases like the following:

```hlsl
ParameterBlock<X> x;
Texture2D         t : register(t0, space99);
```

In this case, the parameter `t` already has an explicit binding, so it doesn't actually need a default space to be allocated. If we allocate a default space/set of 0 on the basis of `t`, then `x` will end up being shifted to space/set 1.

The fix is to only consider global parameters that need `register`s/`binding`s *if* they don't have an explicit binding already (which is luckily something we are tracking during parameter binding).

Note: just to clarify the behavior here, the "do we need a default space/set?" logic is done *before* automatic binding of parameters, so in a shader with any global texture/buffer/sampler parameters, those will all end up in space/set zero (in the absence of explicit bindings), and explicit blocks will start at space/set one, independent of the order of declaration. This behavior is maybe too subtle, and we might decide we need to change it, but it will have to do for now.
1 parent 2f4029a
History
Tip revision: 3ae31a6ed8d79c23b2ab5a7d7d755dd7e42618f7 authored by Tim Foley on 25 March 2019, 19:36:41 UTC
Improve logic for when a "default space" is needed (#925)
Tip revision: 3ae31a6
File Mode Size
docs
examples
external
source
tests
tools
.editorconfig -rw-r--r-- 937 bytes
.gitattributes -rw-r--r-- 95 bytes
.gitignore -rw-r--r-- 407 bytes
.gitmodules -rw-r--r-- 406 bytes
.travis.yml -rw-r--r-- 1.7 KB
CODE_OF_CONDUCT.md -rw-r--r-- 3.1 KB
LICENSE -rw-r--r-- 1.1 KB
Makefile -rw-r--r-- 6.0 KB
README.md -rw-r--r-- 6.7 KB
appveyor.yml -rw-r--r-- 3.7 KB
premake5.lua -rw-r--r-- 25.3 KB
slang-com-helper.h -rw-r--r-- 4.8 KB
slang-com-ptr.h -rw-r--r-- 4.8 KB
slang.h -rw-r--r-- 88.4 KB
slang.sln -rw-r--r-- 9.8 KB
test.bat -rw-r--r-- 1.4 KB
travis_build.sh -rw-r--r-- 304 bytes
travis_test.sh -rw-r--r-- 435 bytes

README.md

back to top