Description
When a global resource doesn't have a register binding attribute, we need to allocate a binding for the it. This is tightly related to diagnostic of non-local overlapping resource bindings (#110723).
DXC does this after optimizations, in DxilResourceRegisterAllocator::AllocateRegisters. At that point unused resources should be removed and not be allocated any binding location, and explicit bindings can only conflict between resources that are actually used in the same compiled entry point.
In #58051 we discussed doing this in Sema, but that requires us to become stricter than DXC about whether this diagnostic depends on optimization.
We need to decide on an approach and implement it.
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
struct MyBufs {
RWBuffer<float> Array[4];
};
MyBufs Many : register(u0);
RWBuffer<float> JustOne : register(u0);
RWBuffer<float> SecondOne;
[numthreads(4,1,1)]
void main() {
Many.Array[2][0] = 1.0; // gets u2
JustOne[0] = 2.0; // gets u0
SecondOne[0] = 3.0; // gets u1
}
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
RWBuffer<float> JustOne : register(u10);
RWBuffer<float> SecondOne;
RWBuffer<float> ArrayHere[4] : register(u0);
[numthreads(4,1,1)]
void main() {
ArrayHere[2][0] = 3.0; // gets u0
JustOne[0] = 2.0; // gets u10
SecondOne[0] = 2.0; // gets u4 - after the array
}
Metadata
Metadata
Assignees
Type
Projects
Status