Skip to content

[HLSL] Diagnose overlapping resource bindings #110723

Closed
@bogner

Description

@bogner

If there are two separate resources bound to the same or overlapping registers, the compiler needs to diagnose this. It needs to happen after optimizations because it must be reported only for resources that are used. Overlapping binding on unused resources is not reported.

Example 1 - two resources with overlapping binding:

RWBuffer<float> A[10] : register(u0);
RWBuffer<float> B[10] : register(u5);

[numthreads(1,1,1)]
void main() {
    A[0][0] = B[0][0];
}

https://godbolt.org/z/zGrM7MaW5
Expected: <source>:2:1: error: resource B at register 5 overlaps with resource A at register 0, space 0

The DXILResourceBindingAnalysis (currently in review) detects this case and sets its hasOverlappingBinding flag. Detailed diagnostic should be added to the DXIL post-optimization validation pass and should include the conflicting resource names.

Example 2 - two resources with identical binding:

RWBuffer<float> A : register(u0);
RWBuffer<float> B : register(u0);

[numthreads(1,1,1)]
void main() {
    A[0] = B[0];
}

https://godbolt.org/z/1Pv5rWj7P

Expected: <source>:2:1: error: resource B at register 0 overlaps with resource A at register 0, space 0

Clang currently treats two resources of the same type mapped to the same register as a single resource, which is not correct. The problem is that since the global resource variables are marked internal by Clang, they get optimized away before the DXILResourceBindingAnalysis analysis runs, and there is no way of distinguishing between 2 resources instances initialized with identical llvm.dx.resource.handlefrombinding calls.

We need to re-open the conversation about having the global resource variables present in the module until we are done with the resource processing and diagnostics passes. Theoretically we could distinguish the resources based on the debug information, but the diagnostic cannot rely on that.

Related issue: #105059

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Closed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions