Issue 179303
Summary [HLSL] Resolve local resource access to non-unique global resources
Labels new issue
Assignees
Reporter inbelic
    This issue tracks that Clang generates `dx.types.handle`s 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](https://github.com/llvm/llvm-project/pull/176797).

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](https://godbolt.org/z/GE3hz4qcj). This requires we conditionally track assignments and only generate errors at resource usage. The [current approach](https://github.com/llvm/llvm-project/pull/176793) does not handle constant folding and local resource arrays.
- DXC has some inconsistent [cases](https://godbolt.org/z/rsGEns4vK), that should be re-evaluated if it is the correct behaviour.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to