KhronosGroup / KhronosGroup/glslang
HLSL precision propagation issue when compiling with glslang
- Dominant language
- C++
- Stars
- 3.6k
- Forks
- 989
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 31
Description
**Description**
There is a precision propagation issue when compiling HLSL code with glslang. Specifically, when mixing `min16float3` and `float` types, the precision of `min16float3` is not correctly updated during conversion operations.
**Example HLSL Shader Code:**
```hlsl
// HLSL Fragment Shader (Pixel Shader)
// Input structure from vertex shader
struct PSInput {
float4 position : SV_POSITION;
float2 texCoord : TEXCOORD0;
min16float3 normal : NORMAL;
};
// Output structure
struct PSOutput {
float4 color : SV_TARGET0;
};
// Pixel shader main function
PSOutput main(PSInput input) {
PSOutput output;
float a = input.position.x + input.position.y + input.position.z;
float3 normal_offset1 = (input.normal * a);
output.color = float4(normal_offset1, 1.0);
return output;
}
```
**Compilation Command:**
```
glslang -V --target-env spirv1.4 -D -e main -S frag -Od -o test_out.spv test.hlsl
```
**Steps to Reproduce:**
1. Compile the sample HLSL code above using the provided command.
2. Inspect the resulting SPIR-V for precision propagation in the result of `input.normal * a`.
**Impact:**
Incorrect precision propagation may lead to unintended behavior or loss of precision in shader calculations.
**Environment:**
- glslang version: main
- Platform: windows
Contributor guide
Research direction
Start with the provided HLSL shader and compile it using the glslang command with SPIR-V 1.4 targeting. Inspect test_out.spv around the result of input.normal * a and trace the HLSL-to-SPIR-V precision handling for min16float3 and float conversions. Done means the generated result reflects the intended precision propagation without regressing related shader compilation.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100