This issue tracks that Clang generates dx.types.handles to a unique global resource when resolving local resources. This issue is not concerned with the cases when the local resource can be replaced by an index to a unique global resource, this is handled here.
This should be done by either:
- Legalizing the generated handles by reconstructing control around resource usage and then merging redundant blocks
- Matching DXC behaviour and enforcing that the use of local resources can only refer to a unique global resource at the time of resource usage
Current Clang Behaviour
The clang front-end allows local resources to be arbitrarily re-assigned which results in the code generation of phi/select nodes of dx.types.handle or their resulting ptr. This currently causes clang to crash during dxil-resource-access, but would be invalid DXIL regardless.
Current DXC Behaviour
DXC enforces that, at the time of usage, a local resource refers to a unique global resource. It enforces this by generating a 'local resource not guaranteed to map to unique global resource.' error.
Implementation Considerations
If legalizing, there should be care to ensure we generate an error in the case a resource could be uninitialized at usage. It is required that we do try to merge generated control flow blocks/erase dead ones to prevent a large increase of branches.
From initial prototyping, the handling of this case is rather tricky wrt convergent ops and llvm infrastructure.
If matching DXC behaviour, we should create the best user diagnostics by generating the errors during semantic analysis. This creates some difficulty when replicating the behaviour:
- DXC does local resource usage analysis after constant folding and simple DCE, this why no error is generated in these examples. This requires we conditionally track assignments and only generate errors at resource usage. The current approach does not handle constant folding and local resource arrays.
- DXC has some inconsistent cases, that should be re-evaluated if it is the correct behaviour.
This issue tracks that Clang generates
dx.types.handles to a unique global resource when resolving local resources. This issue is not concerned with the cases when the local resource can be replaced by an index to a unique global resource, this is handled here.This should be done by either:
Current Clang Behaviour
The clang front-end allows local resources to be arbitrarily re-assigned which results in the code generation of
phi/selectnodes ofdx.types.handleor their resultingptr. This currently causes clang to crash duringdxil-resource-access, but would be invalid DXIL regardless.Current DXC Behaviour
DXC enforces that, at the time of usage, a local resource refers to a unique global resource. It enforces this by generating a
'local resource not guaranteed to map to unique global resource.'error.Implementation Considerations
If legalizing, there should be care to ensure we generate an error in the case a resource could be uninitialized at usage. It is required that we do try to merge generated control flow blocks/erase dead ones to prevent a large increase of branches.
From initial prototyping, the handling of this case is rather tricky wrt convergent ops and llvm infrastructure.
If matching DXC behaviour, we should create the best user diagnostics by generating the errors during semantic analysis. This creates some difficulty when replicating the behaviour: