Skip to content

Support #pragma once and multiple inclusions of the same file in HLSL editing#3769

Merged
baldurk merged 1 commit intobaldurk:v1.xfrom
qwmnerbvqwmn:pr/support-pragma-once
Jan 22, 2026
Merged

Support #pragma once and multiple inclusions of the same file in HLSL editing#3769
baldurk merged 1 commit intobaldurk:v1.xfrom
qwmnerbvqwmn:pr/support-pragma-once

Conversation

@qwmnerbvqwmn
Copy link

@qwmnerbvqwmn qwmnerbvqwmn commented Jan 16, 2026

Description

Updated the shader compilation logic during editing to correctly handle #pragma once directives and avoid re-inclusion errors when the same header is included multiple times.

The original implementation simply replaced #include with the file content and used only a local exclude list to prevent circular references. This led to a situation where if a file (especially one using #pragma once) was included multiple times (for example, A includes B and C, and both B and C include D), the expanded single large file would contain multiple copies of D's content, resulting in a redefinition error. Furthermore, the retained #pragma once in the expanded file would also trigger warnings from dxc.

This is my capture file(https://drive.google.com/file/d/12XYiIW-N2RjH6wmydqmQOzi5bpLIEkQc/view). After opening it, you can search for "ScreenSpaceProbeTemporalFilterCS" pass. It uses include and pragma once. Compiling it directly will result in the errors shown in the screenshot. Basically, all passes use include and pragma once, so most passes will fail to compile.

Compile Error log

image

Running "F:/Users/xxx/scoop/shims/dxc.exe"  -E CSMain -T cs_6_6 -I F:\Code\TestProj\TestProj\Shaders -Qembed_debug -Zi -Od -Fo C:/Users/xxx/AppData/Local/Temp/shader_output C:/Users/xxx/AppData/Local/Temp/shader_input
C:/Users/xxx/AppData/Local/Temp/shader_input:5:9: warning: #pragma once in main file
#pragma once
        ^
C:/Users/xxx/AppData/Local/Temp/shader_input:8:9: warning: #pragma once in main file
#pragma once
        ^
C:/Users/xxx/AppData/Local/Temp/shader_input:172:9: warning: #pragma once in main file
#pragma once
        ^
C:/Users/xxx/AppData/Local/Temp/shader_input:2528:9: warning: #pragma once in main file
#pragma once
        ^
C:/Users/xxx/AppData/Local/Temp/shader_input:2532:9: warning: #pragma once in main file
#pragma once
        ^
C:/Users/xxx/AppData/Local/Temp/shader_input:2535:9: warning: #pragma once in main file
#pragma once
        ^
C:/Users/xxx/AppData/Local/Temp/shader_input:2538:20: error: redefinition of 'PI'
const static float PI = 3.1415926535897932384626433832795f;
                   ^
C:/Users/xxx/AppData/Local/Temp/shader_input:11:20: note: previous definition is here
const static float PI = 3.1415926535897932384626433832795f;
                   ^
C:/Users/xxx/AppData/Local/Temp/shader_input:2539:20: error: redefinition of 'kAngleToRadian'
const static float kAngleToRadian = PI / 180.0f;
                   ^
C:/Users/xxx/AppData/Local/Temp/shader_input:12:20: note: previous definition is here
const static float kAngleToRadian = PI / 180.0f;
                   ^
C:/Users/xxx/AppData/Local/Temp/shader_input:2540:20: error: redefinition of 'kMaxFloat'
const static float kMaxFloat = 3.402823466e+38F;
                   ^
C:/Users/xxx/AppData/Local/Temp/shader_input:13:20: note: previous definition is here
const static float kMaxFloat = 3.402823466e+38F;
                   ^
C:/Users/xxx/AppData/Local/Temp/shader_input:2541:20: error: redefinition of 'kMinFloat'
const static float kMinFloat = -3.402823466e+38F;

My modifications include:

  • Introduce global tracking: During the entire include expansion process, use an allIncluded list to record all files that have been processed.
  • When processing #pragma once: During expansion, if a file is found to have already been processed and contains a #pragma once directive, skip the repeated expansion and insert a comment to explain.
  • Automatic cleanup instruction: When processing each file (including the main file and included files), #pragma once will be automatically replaced with the comment // #pragma once. This not only preserves the file structure information but also eliminates the warning from dxc regarding "including #pragma once in the main file".
  • Corrected recursive logic: Updated the signature of ProcessIncludeDirectives to ensure the correct passing of the global included list and the recursive detection list of the current path during recursive calls.

These changes enable RenderDoc to behave more closely to the actual compiler when manually expanding HLSL files, addressing issues such as redefinition errors and #pragma once warnings.

@qwmnerbvqwmn qwmnerbvqwmn force-pushed the pr/support-pragma-once branch from 5b98e15 to 6ea112c Compare January 16, 2026 19:25
@qwmnerbvqwmn qwmnerbvqwmn force-pushed the pr/support-pragma-once branch from 6ea112c to ddfd68b Compare January 22, 2026 17:26
@baldurk baldurk merged commit 67a6f20 into baldurk:v1.x Jan 22, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants