ConfettiFX / The-Forge

The Forge Cross-Platform Rendering Framework PC Windows, Steamdeck (native), Ray Tracing, macOS / iOS, Android, XBOX, PS4, PS5, Switch, Quest 2
Apache License 2.0
4.83k stars 505 forks source link

[Shader Debug] Enable debugging on shaders - vulkan GL_EXT_debug_printf #315

Closed Hideman85 closed 2 months ago

Hideman85 commented 2 months ago

I would like to enable shader debugging to help me find issues in my implementation. Right now I'm using Vulkan backend only and so I would like to have printf with #extension GL_EXT_debug_printf : enable but no way to have this working. As soon as I put a string in my shader, I'm getting the compilation error

ERROR :  'string literal' : required extension not requested: Possible extensions include:
GL_EXT_debug_printf
GL_EXT_spirv_intrinsics

And when I put #extension GL_EXT_debug_printf : enable I'm getting

error: invalid preprocessing directive #extension
    1 | #extension GL_EXT_debug_printf : enable

I checked the fsl.py compiler and seem no options for enabling this. How can I do so?

david-tf commented 2 months ago

This does not work because fsl runs its own preprocessor step, you can use this:

@fsl_extension GL_EXT_debug_printf: enable

float4 PS_MAIN(VSOutput In)
{
    INIT_MAIN;
    float4 Out;
    debugPrintfEXT("Hello World!");
Hideman85 commented 2 months ago

Thanks @david-tf for your reply 🙌

It seems it needs something more when using the shader in the app cause now it isnt running.

vkCreateShaderModule(): The SPIR-V Extension (SPV_KHR_non_semantic_info) was declared, but none of the requirements were met to use it. The Vulkan spec states: If pCode declares any of the SPIR-V extensions listed in the SPIR-V Environment appendix, one of the corresponding requirements must be satisfied.

Do you know what I should do in the app code? I havent found something in ShaderLoadDesc that I could flag on.

Thanks in advance for your help 🙏

david-tf commented 2 months ago

You will need to add VK_KHR_SHADER_NON_SEMANTIC_INFO_EXTENSION_NAME to the ppDeviceExtensions/mDeviceExtensionCount RendererDesc.

Hideman85 commented 2 months ago

Perfect, thanks again 🙌

I cant see any logs for some reason even tho my shader is running. Note the documentation said that by default the Debug callback handle it (the one created by The Forge) but nothing is dumped. I tried with the env VK_LAYER_PRINTF_TO_STDOUT=1 that should redirect to stdout but nothing either. Any Idea?