microsoft / microsoft/DirectXShaderCompiler

Adding constant half precision value with 'h' postfix in HLSL promotes operation to full precision

Open
#7,811 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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.0h causes the addition to be performed in full precision.
  • Using + 1.0 keeps the operation in half precision.
  • This is unexpected; both should result in half precision operations.

Environment

  • DXC version:
  • Host Operating System:

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.