Repository navigation
[SPIR-V] Use pow for the lit specular term and support half - #9185
Open
Abir Deol (apollo-2006) wants to merge 2 commits into
Open
Abir Deol (apollo-2006) wants to merge 2 commits into
Abir Deol (apollo-2006) wants to merge 2 commits into
Conversation
lit() computed the specular term as n_dot_h * m instead of pow(n_dot_h, m), and always used float, so half arguments produced invalid SPIR-V or crashed in constant folding. Fixes microsoft#9123.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The corrected SPIR-V lit result and half compilation fix are user-visible compiler bug fixes, but they lack the entry under ### Upcoming Release in docs/ReleaseNotes.md required by CONTRIBUTING.md.
1 open issue
What changed in this PR
Fixes SPIR-V lit code generation to compute the correct specular term and support native half values, addressing #9123.
Changes:
- Uses
Powinstead of multiplication for the specular term. - Derives intermediate types and constants from the return element type.
- Adds half-precision and validation regression coverage.
| File | Description |
|---|---|
| tools/clang/test/CodeGenSPIRV/intrinsics.lit.validate.hlsl | Adds float and half validation with runtime and constant inputs. |
| tools/clang/test/CodeGenSPIRV/intrinsics.lit.hlsl | Updates float expectations to use Pow. |
| tools/clang/test/CodeGenSPIRV/intrinsics.lit.half.hlsl | Adds half-precision code generation checks. |
| tools/clang/lib/SPIRV/SpirvEmitter.cpp | Corrects specular calculation and preserves element types. |
Review effort: Balanced
Comment on lines
+12511
to
+12512
| auto *pow = spvBuilder.createGLSLExtInst(elemType, GLSLstd450::GLSLstd450Pow, | ||
| {nDotH, m}, loc, range); |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #9123, thanks joaosaffran for the really clear repro!
lithad two bugs on SPIR-V:n_dot_h * minstead ofpow(n_dot_h, m), solit(0.5, 0.25, 2)gave0.5instead of0.0625float, sohalffailed validation, or hit a SPIRV-Tools assert when the arguments were constantsIt now uses
Powand the return type's element type, matching DXIL.I updated the existing test and added a
halfone, plus one without-fcglso spirv-val runs on float and half. All three fail without the fix, and the CodeGenSPIRV suite passes. Happy to tweak anything :)