Whilst working on upgrading a project to 5.7, we noticed errors like the following when cooking for Win64 for the first time:
LogShaderCompilers: Error: Shader compiler returned a non-zero error code (-1073741819).
The errors disappeared in subsequent cooks, which suggested that despite the error above the shaders had made their way to the DDC. In fact, if using -noshaderddc we are then able to reproduce these problems on every cook, although the number of errors the cooks hit seems to vary on each run. The errors always occurred when compiling shaders for PCD3D_SM6 (not with other shader formats) and early in the cook process.
The error code above maps to 0xC0000005 (“The instruction at … referenced memory at … The memory could not be …”). The bespoke exception handler in ShaderCompileWorker didn’t seem to trigger as no crash output files were being generated.
Something to note is that we are using Incredibuild. We tried invoking ShaderCompileWorker directly and also using UBA instead, and interestingly the errors did not seem to appear.
I should also mention that this problem is not specific to the project in question as we have been able to reproduce the same crashes on stock 5.7.1 using QAGame.
Eventually we managed to attach a debugger to crashing ShaderCompileWorker instances and got the callstack attached to the question and the exception details: “Exception thrown at 0x00007FFC8D8C2A95 (ntdll.dll) in ShaderCompileWorker.exe: 0xC0000005: Access violation reading location 0x0000000000000000.”
The crash occurring after main() explains that the bespoke exception handler in ShaderCompileWorker was not having an effect, and could explain why the shaders made their way to the DDC (as the ShaderCompileWorker would have generated all the output files prior to the crash), but we did not confirm this last detail.
We then decided to replace the dxcompiler.dll in 5.7 with the version that was included in 5.6, and the problems went away. This suggested an incompatibility between 5.7’s dxcompiler.dll and either Incredibuild or ShaderCompileWorker’s handling of Incredibuild.
We then noticed that ShaderCompileWorker uses module bootstrapping when run under Incredibuild. We have run some tests and so far the errors do not seem to occur when preventing all ShaderCompileWorkers from bootstrapping. When the crashes do occur, so far we have always seen warnings indicating a worker could not load the bootstrapping file, which according to a comment in ShaderCompileWorker.cpp is expected behaviour due to an issue in XGE, though this may suggest that changes in the way modules are loaded and unloaded by the different workers may be a factor in the crash.
We are not blocked by this issue at present as using 5.6’s dxcompiler.dll works for us for now (Perforce history suggested nothing in the new version was a must-have) and it could also be argued that we could add a workaround to ignore these particular errors given the crash happens after ShaderCompileWorker has successfully generated its outputs but in the long term it would be preferable if a proper resolution is found.
[Attachment Removed]