I'm porting C code to HLSL (compute shader). The compiler is crazy with one of the for loops. At runtime, the display device driver detect an unreasonable amount of time to execute the code.
Here is the partial source code with the offending for loop:
P = FloatToAsciiNoExponent(F * Factor, DstBuf, 7);
uint TmpBuf[FTOA_BUFFER_SIZE];
uint BytesWritten = IntToAscii(Exp10, TmpBuf, BASE10);
DstBuf[P++] = 'E';
[fastopt]
for (uint I = 0; I < BytesWritten; I++)
DstBuf[P++] = TmpBuf[I];
At run time, I got the following debug message:
D3D11 ERROR: ID3D11Device::RemoveDevice: Device removal has been triggered for the following reason (DXGI_ERROR_DEVICE_HUNG: The Device took an unreasonable amount of time to execute its commands, or the hardware crashed/hung. As a result, the TDR (Timeout Detection and Recovery) mechanism has been triggered. The current Device Context was executing commands when the hang occurred. The application may want to respawn and fallback to less aggressive use of the display hardware). EXECUTION ERROR #378: DEVICE_REMOVAL_PROCESS_AT_FAULT]
If I comment out the two for-loop lines, everything is OK (Except of course the final result which lacks his last part).
FloatToAsciiNoExponent()
is a function which convert his first argument into a list or ascii code stored in the second argument (an array of uint). The last argument is the numeration base for conversion. It has been validated.
IntToAscii()
is a function converting his first argument into a list of ascii code stored in the second argument (an array of uint). It has been validated.
The original C source code I'm porting can be found here: https://searchcode.com/codesearch/view/14753060/
I'm running on Windows 7 and DirectX SDK of June 2010 (The last one running on Windows 7). Windows update has been executed and every update installed. The graphic card is an NVidia Quadro K4200 having 24GB of RAM with driver version 431.02.
Any help appreciated.
Answering myself:
I upgraded my PC to Win10 which includes DirectX12. Now the source code is working as expected. This confirm that the June 2010 compiler is bugged.