floooh / sokol-tools

Command line tools for use with sokol headers
MIT License
219 stars 54 forks source link

How to map runtime shader error line numbers back to the source? #98

Closed creikey closed 1 year ago

creikey commented 1 year ago

I've been using the wonderful sokol gfx and app headers to make this game: image

And have been using SOKOL_GLCORE33 backend, but now I want to make sure directx is still an option on desktop, and running with D3D11, I get this in the runtime console:

threedee.glsl(52,17-34): warning X3550: array reference cannot be used as an l-value; not natively addressable, forcing loop to unroll
threedee.glsl(52,17-29): warning X3550: array reference cannot be used as an l-value; not natively addressable, forcing loop to unroll

threedee.glsl(52,17-34): warning X3550: array reference cannot be used as an l-value; not natively addressable, forcing loop to unroll
threedee.glsl(52,17-29): warning X3550: array reference cannot be used as an l-value; not natively addressable, forcing loop to unroll

threedee.glsl(34,20-61): warning X3570: gradient instruction used in a loop with varying iteration, attempting to unroll the loop
threedee.glsl(34,20-61): warning X3570: gradient instruction used in a loop with varying iteration, attempting to unroll the loop
threedee.glsl(34,20-61): warning X3570: gradient instruction used in a loop with varying iteration, attempting to unroll the loop
threedee.glsl(34,20-61): warning X3570: gradient instruction used in a loop with varying iteration, attempting to unroll the loop
threedee.glsl(34,20-61): warning X3570: gradient instruction used in a loop with varying iteration, attempting to unroll the loop
threedee.glsl(34,20-61): warning X3570: gradient instruction used in a loop with varying iteration, attempting to unroll the loop
threedee.glsl(34,20-61): warning X3570: gradient instruction used in a loop with varying iteration, attempting to unroll the loop
threedee.glsl(34,20-61): warning X3570: gradient instruction used in a loop with varying iteration, attempting to unroll the loop

However, at these line numbers in the shader ( https://github.com/creikey/rpgpt/blob/8369c62f26cc8949a46fb153aa19c7227dcda1c2/threedee.glsl#L34 for line 34 ) this seems to not be what the error message is talking about. How can I map from these runtime (I'm assuming HLSL translated) shader errors to where in the glsl the problem is?

floooh commented 1 year ago

Yeah, unfortunately that's a bit of a problem in this case because these warnings are coming out of the D3D shader compiler which consumes the HLSL code generated by SPIRVCross.

The error/warning mapping only works for the first compile pass which compiles the input GLSL to SPIRV, but for any followup compile passes (in the D3D or Metal shader compilers) the line numbers are off, because they refer to the intermediate HLSL code.

Until recently the intermediate source code used to contain #line statements, but those were ignored by the D3D compiler anyway, and there were also so 'inprecise' that they were mostly useless even in Metal (where the line mapping via #line worked).

So for this specific case unfortunately there's no solution.

PS: to not leave you hanging dry completely: the generated HLSL shader code is included in the header output as comment block above the shader blob array, so there's where you would need to look up the error manually. Currently that's the only way.

floooh commented 1 year ago

PS: nice screenshot by the way, looks awesome :)

What technique do you use for the shadows (assuming they are realtime)

creikey commented 1 year ago

PS: nice screenshot by the way, looks awesome :)

What technique do you use for the shadows (assuming they are realtime)

The same one in the sokol example! I contracted somebody else to implement them nice actually so I don't know the details off the top of my head

Thanks for the tip about the hlsl being in the header! I didn't think of that