Skip to content

[SPIRV] Fix sign() result type for uint matrices - #8859

Open
David Browne (djb) wants to merge 1 commit into
microsoft:mainfrom
djb:fix-spirv-sign-of-uint-matrix-result-type
Open

[SPIRV] Fix sign() result type for uint matrices#8859
David Browne (djb) wants to merge 1 commit into
microsoft:mainfrom
djb:fix-spirv-sign-of-uint-matrix-result-type

Conversation

@djb

@djb David Browne (djb) commented Aug 30, 2026

Copy link
Copy Markdown

HLSL's sign() returns a signed integer matrix for an unsigned integer matrix argument. SPIR-V codegen instead used the argument composite's type as the result type of OpCompositeConstruct, constructing an unsigned composite from signed vector constituents, which fails validation.

Pass the call expression's result type to processEachVectorInMatrix so the composite is constructed with the intrinsic's signed result type, fixing the validation error.

This issue affected all uintMxN matrices with M, N > 1.

Fixes #8858

Assisted-by: GPT 5.6 Sol

HLSL's sign() returns a signed integer matrix for an unsigned integer
matrix argument. SPIR-V codegen instead used the argument composite's
type as the result type of OpCompositeConstruct, constructing an
unsigned composite from signed vector constituents, which fails
validation.

Pass the call expression's result type to processEachVectorInMatrix so
the composite is constructed with the intrinsic's signed result type,
fixing the validation error.

This issue affected all uintMxN matrices with M,N > 1.

Fixes microsoft#8858
Copilot AI balanced review requested due to automatic review settings August 30, 2026 21:41
@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.

Pull request overview

Fixes invalid SPIR-V generation for sign() on unsigned integer matrices.

Changes:

  • Constructs signed result matrices using the intrinsic’s return type.
  • Updates the SPIR-V regression expectation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tools/clang/lib/SPIRV/SpirvEmitter.cpp Uses the signed call result type for matrix construction.
tools/clang/test/CodeGenSPIRV/intrinsics.uintsign.hlsl Verifies signed matrix SPIR-V output.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

}
return processEachVectorInMatrix(firstArg, doExpr(firstArg), actOnEachVec,
srcLoc, srcRange);
return processEachVectorInMatrix(firstArg, callExpr->getType(),
@djb

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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] sign() on uint matrices with at least two rows and two columns constructs an unsigned result array

2 participants