microsoft / microsoft/DirectXShaderCompiler
"External declaration [decl name] is unused" after resource assignment
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
Description
Given a global extern resource with an auto-assigned or user assigned resource register, reassigning the variable to a different resource (e.g. from ResourceDescriptorHeap) results in the "external declaration is unused" validation error, even if the resource is used prior to assignment.
Steps to Reproduce
RWByteAddressBuffer buffer : register(u0);
[numthreads(8, 8, 1)]
void CSMain(uint3 id : SV_DispatchThreadID)
{
buffer.Store(id.x, 0);
buffer = ResourceDescriptorHeap[0];
buffer.Store(id.x, 0);
}
Actual Behavior
error: validation errors
<source>:1: error: External declaration '\01?buffer@@3URWByteAddressBuffer@@A' is unused.
Validation failed.
Note that this may be intended behavior (understandably), however, I think in this case the error message is misleading and should directly indicate that this sort of reassignment is forbidden if so.
Environment
- DXC version 1.7.2207
- Host Operating System Windows
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the HLSL reproducer in the CE link and inspect the compiler validation path for a global extern resource that is used before reassignment. Determine whether the reassignment should be accepted; done means either correcting the misleading unused-declaration diagnostic or reporting clearly that this reassignment is forbidden, with coverage for the reproducer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100