Skip to content

[SPIR-V] Use pow for the lit specular term and support half - #9185

Open
Abir Deol (apollo-2006) wants to merge 2 commits into
microsoft:mainfrom
apollo-2006:spirv-lit-pow
Open

Abir Deol (apollo-2006) wants to merge 2 commits into
microsoft:mainfrom
apollo-2006:spirv-lit-pow

Conversation

@apollo-2006

Copy link
Copy Markdown
Contributor

Fixes #9123, thanks joaosaffran for the really clear repro!

lit had two bugs on SPIR-V:

  • the specular term was n_dot_h * m instead of pow(n_dot_h, m), so lit(0.5, 0.25, 2) gave 0.5 instead of 0.0625
  • everything was built as float, so half failed validation, or hit a SPIRV-Tools assert when the arguments were constants

It now uses Pow and the return type's element type, matching DXIL.

I updated the existing test and added a half one, plus one without -fcgl so spirv-val runs on float and half. All three fail without the fix, and the CodeGenSPIRV suite passes. Happy to tweak anything :)

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.
Copilot AI balanced review requested due to automatic review settings December 3, 2026 15:43
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 Pow instead 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);
Copilot AI balanced review requested due to automatic review settings December 3, 2026 15:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No actionable issues were found in the reviewed changes.

1 open issue

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

[SPIR-V] lit computes specular as n_dot_h * m and fails for half

2 participants