opened
nbenty
username_0
[Blit.ps.glsl.txt](https://github.com/shader-slang/slang/files/1155911/Blit.ps.glsl.txt)
[MySlang.slang.txt](https://github.com/shader-slang/slang/files/1155910/MySlang.slang.txt)

(remove the `.txt`. GitHub wouldn't let me upload the slang/glsl files)

Slang declares the textures in struct like so:
```C++
layout(binding = 1)
uniform texture2DArray  SLANG_parameterBlock_PerFrameCB_gCsmData_shadowMap[4];
layout(binding = 2)
uniform sampler  SLANG_parameterBlock_PerFrameCB_gCsmData_csmSampler[4];
```

But binding (1) is already used by `gSampler`. The issue is that the location is computed relative to the constant-buffer binding (I confirmed that it can be fixed by changing the CB binding).

This is another thing we need to solve before the release, as CSM uses texture-in-array-of-struct. Slang/glslang gives no indication that something went wrong and the user will have a hard time debugging it.
Incorrect binding calculation for textures in array-of-structs
issue
created
tangent-vector
username_1
What is the behavior you'd expect? It looks to me like the Slang compiler is doing exactly what you told if to, and the problem is that the original problem has overlapping bindings.

To put it in terms of a simpler example, suppose I had:

```
struct S { Texture2D a; Texture2D b; };

layout(binding = 0) S foo;
layout(binding = 1) S bar;
```

In this case `foo.b` and `bar.a` will both have the same binding, but that is just because Slang did what the user said. I can try to issue an error on this (and I really will try to do that once I have time to work on it), but I can't go and move bindings around - the user told me what they expected.

In Slang's view of the world, a `cbuffer` is really no different from a `struct` variable at global scope. This means that whatever bindings it uses will always be sequential, and if the user gave us an explicit starting binding, we'll respect it.

If there is something else you think Slang should do, let me know. Unfortunately, having Slang allocate bindings for stuff inside a CB independent of the CB itself is pretty much not possible.

I can see a few workarounds:
- Don't use explicit bindings on a CB that contains a `Material` or similar
- Use an explicit binding, but put the CB in its own set, or *after* anything else explicit in the same set
- I expect the implementation in Slang won't handle it, but it would be nice if you could just specify a `set` (no `binding`) and have Slang put the CB off by itself.
comment
created
nbenty
username_0
Duplicate of #96
comment
closed
nbenty
username_0
issue