Repository navigation
Description
Functional impact
The debug info (/Zi) output of compiling certain shaders is not deterministic (i.e. given identical inputs, the outputs are not always identical). Our content build pipeline relies on determinism for various things (caching etc.) so this is a pretty big problem for us. Having debugged the issue it is clear that certain processing is erroneously skipped for certain global variables, so this may be the source of correctness issues as well, but I have not been able to confirm that.
Analysis
I have debugged this issue at length, and I believe it is caused by use of stale pointers inside SROAGlobalAndAllocas.
- At the start of the function pointers to all of the module's static globals (
M.globals()) are added to to thestaticGVsset. - During the course of the function, globals may be removed from the module and freed (
eraseFromParent), leaving stale pointers instaticGVs. - The function can also allocate new globals. If it is "unlucky", the allocator will return the exact same pointer as one of the globals that was freed.
- When it comes to process this new global, it first checks if it's in
staticGVs. It should not be, because the set is only filled at the start with the initial set, so should not contain the newly-allocated variable. But if you were "unlucky" it will, since it happens to have the same pointer as one of the stale entries still in the set. When this happens, the new variable is erroneously skipped from further processing. - The end result is that this global does not have debug data added for it (like I said above, there may be other effects as well). This affects the final pdb data, and since it depends on the allocator reusing an address, it doesn't happen consistently, hence the indeterminism.
Proposed Fix
The issue can be resolved by removing entries from the staticGVs set before freeing them. From what I can tell this is done in just two places inside the function. So I propose adding a staticGVs.remove(GV); call before the 2 GV->eraseFromParent(); calls inside SROAGlobalAndAllocas.
Repro
- Download the attached HLSL file and powershell script.
- Remove .txt extension (github didn't like hlsl/ps1 files).
- Update the path to dxc.exe in the script.
- Run the script from the same directory as the HLSL file.
Files:
NonDetermisticDebugData.hlsl.txt
Repro.ps1.txt
The script is very basic/unsophisticated, but was useful for me when debugging this. It compiles the shader 100 times, and compares the hash of the pdb to the that from the first run. If it's different it prints out a message.
Note that due to the nature of this bug I found it to be extremely sensitive to seemingly unrelated factors -- even the path of the directory I put the files in seemed to affect it. I found that generally it would be "different" about 5-10% of the time, but sometimes it would be as low as 1-2% or as high as 50%, seemingly for no reason. Your millage may vary :).
I tried this with various version of DXC, including the latest release (v1.7.2212.1) and the current head (2dd8344), and all seemed to demonstrate the same problem.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
Fix debug info nondeterminism in SROAGlobalsAndAllocas from staticGVs (…