Skip to content

Fix GL pixel shader debug failure with gl_FrontFacing#3855

Closed
fengT-T wants to merge 1 commit into
baldurk:v1.xfrom
fengT-T:v1.x
Closed

Fix GL pixel shader debug failure with gl_FrontFacing#3855
fengT-T wants to merge 1 commit into
baldurk:v1.xfrom
fengT-T:v1.x

Conversation

@fengT-T

@fengT-T fengT-T commented Jun 21, 2026

Copy link
Copy Markdown

Description

Pixel shader debug fails on any fragment shader that uses gl_FrontFacing in a
condition, like:

vec3 N = gl_FrontFacing ? normalize(v_view_normal) : -normalize(v_view_normal);                                                  

Turns out CreateInputFetcher() injects a macro:

  #define gl_FrontFacing (gl_FrontFacing ? 1u : 0u)                                                                                

which was meant to convert the built-in bool to uint for the SSBO output.
But it's global, so it also changes every use of gl_FrontFacing in the user's
own shader code. The ternary above becomes:

  (gl_FrontFacing ? 1u : 0u) ? normalize(...) : -normalize(...)                                                                    

GLSL needs a bool condition there, not uint, so the replacement shader fails
to compile.

Fix

Two lines:

  1. Drop the macro. gl_FrontFacing stays as the native bool built-in.
  2. Convert explicitly at the only spot that actually needs uint:
    isFrontFace = gl_FrontFacing ? 1u : 0u;

The inputs.gl_FrontFacing assignment is generated from GL reflection data
which already gets the type right — no conversion needed there.

Tested on

AMD RX 9070, RadeonSI driver, Linux, OpenGL 3.3 core.

Remove the global #define gl_FrontFacing macro that changed its type
from bool to uint, causing compile errors in user shader code when
gl_FrontFacing was used in ternary/if conditions.

Instead, use explicit bool-to-uint conversion at the single assignment
site where it's needed (isFrontFace for SSBO output).

The inputs.gl_FrontFacing capture already works via the GL reflection's
correct bool type — no conversion needed there.
@baldurk

baldurk commented Jun 21, 2026

Copy link
Copy Markdown
Owner

This doesn't make sense to me, can you please explain in more detail exactly what's going wrong? you briefly say "But it's global" about the macro but that's not how macros work, and the input fetcher shader is entirely generated and does not include user shader code.

How is that macro affecting any other shaders?

@fengT-T

fengT-T commented Jun 22, 2026

Copy link
Copy Markdown
Author

I’m sorry about the confusion earlier — I didn’t explain things clearly. I’m still pretty new to the RenderDoc codebase, so my understanding of the terminology and how everything flows is still rough. I just found that this change fixed my issue.

Here’s what caused it:

I have a fragment shader that uses gl_FrontFacing in a ternary:

vec3 N = gl_FrontFacing ? normalize(v_view_normal) : -normalize(v_view_normal);

Standard stuff, renders fine. But when I click the "Debug" button for pixel shader debugging, it always fails with "no write to the pixel at the current event." If I don’t use gl_FrontFacing at all, everything works normally.

Screenshot from 2026-06-22 15-28-56 Screenshot from 2026-06-22 15-29-18

Searching around for gl_FrontFacing, I found this macro:

#define gl_FrontFacing (gl_FrontFacing ? 1u : 0u)

After a quick look at how RenderDoc works, I guessed that this macro is causing a type mismatch that breaks debugging. So I tried changing it, and after the modification, I was able to debug shaders that use gl_FrontFacing without any problem.

@baldurk

baldurk commented Jun 22, 2026

Copy link
Copy Markdown
Owner

If you are making the change semi-blind and you don't understand how the code works I think it's best that you file an issue with a bug report, and include a full and reproducible test case. Then I can investigate and ensure the correct fix is made.

@baldurk baldurk closed this Jun 22, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jun 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants