microsoft / microsoft/DirectXShaderCompiler
Adding constant half precision value with 'h' postfix in HLSL promotes operation to full precision
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
Description
When adding a constant half precision value in HLSL using the 'h' postfix (e.g. + 1.0h), the resulting operation is incorrectly promoted to full precision. However, if the constant does not use the 'h' postfix (e.g. + 1.0), the operation remains in half precision as expected. This behavior is inconsistent and leads to incorrect precision in generated output.
Steps to Reproduce
See live example here: https://godbolt.org/z/hEjazrfvj
Actual Behavior
- Using
+ 1.0hcauses the addition to be performed in full precision. - Using
+ 1.0keeps the operation in half precision. - This is unexpected; both should result in half precision operations.
Environment
- DXC version:
- Host Operating System:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked Godbolt reproduction and compare generated output for the HLSL expressions using 1.0h and 1.0. Trace the compiler path responsible for HLSL constant precision and verify that both additions remain half precision in the generated output.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100