microsoft / microsoft/DirectXShaderCompiler

pragma once is case sensitive

Open
#8,527 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs-triage
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

Description

Hi,
Consider we have an hlsl file with two includes that both include a same third file, but with different character case. pragma once will then fail to detect them as the same include and will report symbol redefinitions errors for example.
A simple example
cs_pragma_hlsli:

#pragma once

struct Foo
{
    float4 m_scale;
};

includeA.hlsli:

#pragma once

#include "cs_pragma.hlsli"

includeB.hlsli:

#pragma once

#include "cs_Pragma.hlsli" // notice the 'P' instead of 'p'

main file cs_pragma.hlsl, to be compiled with -T cs_6_6:

#include "includeA.hlsli"
#include "includeB.hlsli"

RWTexture2D<float4> myOutput: register(u0);
Texture2D<float4> myTexInput: register(t0);
ConstantBuffer<Foo> Bar: register(b0);

[RootSignature("RootFlags(0), DescriptorTable(UAV(u0), CBV(b0), SRV(t0))")]
[numthreads(8, 8, 1)]
void main(uint3 thread_id : SV_DispatchThreadID)
{
    float4 outValue = myTexInput.Load(int3(thread_id.xy, 0));
    myOutput[thread_id.xy] = outValue * Bar.m_scale;
}

preprocessed code in godbolt: https://godbolt.org/z/qdosafc4E

Actual Behavior
Output of the example above:

E:\Temp\pragma_once\dxc_2026_05_27\bin\x64>dxc -T cs_6_6 e:\temp\pragma_once\cs_pragma.hlsl
In file included from e:\temp\pragma_once\cs_pragma.hlsl:2:
In file included from e:\temp\pragma_once/includeB.hlsli:3:
e:\temp\pragma_once/cs_Pragma.hlsli:3:8: error: redefinition of 'Foo'
struct Foo
       ^
e:\temp\pragma_once/cs_pragma.hlsli:3:8: note: previous definition is here
struct Foo
       ^


E:\Temp\pragma_once\dxc_2026_05_27\bin\x64>

Environment

  • DXC version: 1.9(5191-d355aa83)(1.9.2602.24) - 1.9.2602.24 (d355aa836)
  • Host Operating System: Windows11 23H2 22631.6936

This mostly prevents us from using pragma once on a non case sensitive file system such as windows.

Best!
Olivier

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided HLSL example with the shown dxc command and compare the two differently cased include paths. Trace the compiler's pragma-once and include-path handling, then verify that the sample compiles without duplicate Foo definitions on Windows.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.