google / google/shaderc

Proper handling of namespace in HLSL

Open
#1,375 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.2k
Forks
445
Avg merge
11h 6m
Merged PRs (30d)
6

Description

The hlsl parser fails to parse type names when they are prefixed by a namespace, for example `Test::TestS ts;` will fail, but `TestS ts; `will parse (improperly).

The following code reproduces the issue with the command line:
```
/usr/local/bin/glslc -x hlsl -fentry-point=pixelShader -fshader-stage=fragment --target-env=vulkan1.2 -o x.spirv ./example.hlsl
```

```
struct v2p {
float4 p : SV_POSITION;
float2 uv : TEXCOORD0;
float4 c : TEXCOORD1;
};

namespace Test {
struct TestS {
float4 t;
float4 v;
};

float4 testF(TestS ts) {
return ts.t * ts.v;
}

}

sampler2D MyTexture;

float4 pixelShader(v2p i) : SV_TARGET {
Test::TestS ts; // FAILS HERE, /*Test::*/TestS ts; works, but should fail.
ts.v = i.c;
ts.t = tex2D(MyTexture, i.uv);
return Test::testF(ts);
}
```

Note: glslc version tested:

```
/usr/local/bin/glslc --version
shaderc v2023.6 v2023.6
spirv-tools v2023.4 v2022.4-296-ge553b884
glslang 11.1.0-763-g76b52ebf

Target: SPIR-V 1.0
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.