Skip to content

[SPIR-V]: Fix spirv codegen for uabs intrinsic when argument is unsigned. - #7750

Merged
Steven Perron (s-perron) merged 1 commit into
microsoft:mainfrom
luciechoi:7512
Sep 10, 2025
Merged

Steven Perron (s-perron) merged 1 commit into
microsoft:mainfrom
luciechoi:7512

Conversation

@luciechoi

@luciechoi Lucie Choi (luciechoi) commented Sep 9, 2025 •

Copy link
Copy Markdown
Collaborator

Fix the spirv codegen for abs() on uint, to not generate OpExtInst instruction but simply load and pass the value. Fixes #7512

Example

[numthreads(1,1,1)]
void main() {
  uint32_t A = uint32_t(0xffffffff);
  uint32_t B = abs(A);
}

Previously generated SPIR-V

 %A = OpVariable %_ptr_Function_uint Function
 %B = OpVariable %_ptr_Function_uint Function
      OpStore %A %uint_4294967295
%13 = OpLoad %uint %A
%14 = OpExtInst %int %1 SAbs %13
      OpStore %B %14

Fix

 %A = OpVariable %_ptr_Function_uint Function
 %B = OpVariable %_ptr_Function_uint Function
      OpStore %A %uint_4294967295
%13 = OpLoad %uint %A
      OpStore %B %13

which is equivalent to

[numthreads(1,1,1)]
void main() {
  uint32_t A = uint32_t(0xffffffff);
  uint32_t B = A;
}

@s-perron

Copy link
Copy Markdown
Collaborator

/AzurePipelines run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@s-perron
Steven Perron (s-perron) merged commit 368da36 into microsoft:main Sep 10, 2025
@github-project-automation github-project-automation Bot moved this from New to Done in HLSL Roadmap Sep 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[SPIR-V] Performing Signed absolute value on UINT

2 participants