This is the implicit bindings part of the bindings approach originally described in #58051, and is a follow up to #110719.
We need to handle implicit bindings in step 3 of #110719's binding handling, as part of SemaHLSL::handleBindings.
There are two approaches to this:
Mark the bindings as "implicit" and calculate their actual locations later in the compiler
Fill out the bindings as we go.
Approach (2) would be a departure from DXC. There is some discussion of this starting in https://github.com/llvm/llvm-project/issues/58051#issuecomment-2239952237 but we need to discuss this in further detail if we want to pursue it. We would probably need to do some reachability analysis if we wanted to do this.
Some parts of approach (1) are probably necessary regardless of whether we adopt approach (2), because explicitly unbound resources exist in library shaders.
For example, in this case DXC assigns the implicit binding in codegen after optimizations based on which resources in Array are accessed:
https://godbolt.org/z/hGYG4rcqb
However, when a resource array is a global variable, DXC assumes all values will be used and assigns a slot after the array no matter which values of the array are accessed:
https://godbolt.org/z/sdTPh58hc
This is the implicit bindings part of the bindings approach originally described in #58051, and is a follow up to #110719.
We need to handle implicit bindings in step 3 of #110719's binding handling, as part of
SemaHLSL::handleBindings
.There are two approaches to this:
Approach (2) would be a departure from DXC. There is some discussion of this starting in https://github.com/llvm/llvm-project/issues/58051#issuecomment-2239952237 but we need to discuss this in further detail if we want to pursue it. We would probably need to do some reachability analysis if we wanted to do this.
Some parts of approach (1) are probably necessary regardless of whether we adopt approach (2), because explicitly unbound resources exist in library shaders.
For example, in this case DXC assigns the implicit binding in codegen after optimizations based on which resources in
Array
are accessed: https://godbolt.org/z/hGYG4rcqbHowever, when a resource array is a global variable, DXC assumes all values will be used and assigns a slot after the array no matter which values of the array are accessed: https://godbolt.org/z/sdTPh58hc