Skip to content

[SM6.9] Enable Native Vector Overloads for Derivatives #7598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pow2clk
Copy link
Contributor

@pow2clk pow2clk commented Jun 30, 2025

This enables derivative operations using native vectors by allowing native vectors in temporary convergent functions. HLSL intrinsics that lower to DXIL derivative ops get their parameters marked as convergent by passing their parameters to a temporary convergent function. This function scalarized vectors, leading to the results remaining scalarized.

This change adds native vector support overloads to the convergent function and generates them in the convergent pass. This preserves the native vectors throughout final DXIL.

Moves tests for the until now scalarized intrinsics to native vector test locations. fwidth requires some more involved expansion while the derivative operations can be tested trivially.

Fixes #7343

HLSL intrinsics that lower to DXIL derivative ops get their parameters marked as convergent by passing their parameters to a temporary convergent function. This function scalarized vectors, leading to the results remaining scalarized.

This change adds native vector support overloads to the convergent function and generates them in the convergent pass. This preserves the native vectors throughout final DXIL.

Fixes microsoft#7343
@tex3d
Copy link
Contributor

tex3d commented Jun 30, 2025

This has IR breaking implications, which I think should be made clear from the title. What about:
SM6.9 DXIL change: add vector overloads for derivative ops

This most important high-level change is not currently made clear in either the title or description.

It reminds me that we need to make sure we don't expose new vector overloads for existing DXIL ops when on an earlier shader model than 6.9, even when crafted directly with IR. For instance, in libraries, we allow vector in export function signature, so we could craft a validator test that takes a vector from function input and passes it directly to an existing intrinsic with a new vector overload, and make sure the validator will fail any vector passed to, or returned from, any DXIL intrinsic, if SM < 6.9.

@pow2clk pow2clk changed the title Enable native vector convergent intrinsics [SM6.9] Enable Native Vector Overloads for Derivatives Jul 2, 2025
@pow2clk
Copy link
Contributor Author

pow2clk commented Jul 2, 2025

I've changed the title. The first sentence of the description mentions derivatives. I didn't really consider adding another valid opcode value to the already native vector overloaded dx.op.unary was fully an IR change really.

Copy link
Collaborator

@llvm-beanz llvm-beanz left a comment

Choose a reason for hiding this comment

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

One small readability nit, apply or not at you discretion.

Comment on lines +94 to +98
if (VectorType *VTy = dyn_cast<VectorType>(Ty))
if (!SupportsVectors || VTy->getNumElements() == 1) {
Ty = Ty->getScalarType();
NeedVectorExpansion = true;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor style nit to reduce levels of indentation.

Suggested change
if (VectorType *VTy = dyn_cast<VectorType>(Ty))
if (!SupportsVectors || VTy->getNumElements() == 1) {
Ty = Ty->getScalarType();
NeedVectorExpansion = true;
}
VectorType *VTy = dyn_cast<VectorType>(Ty);
if (VTy && !SupportsVectors || VTy->getNumElements() == 1) {
Ty = Ty->getScalarType();
NeedVectorExpansion = true;
}

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.

[SM6.9] Handle native vector operations in DXIL Convergence Mark pass
3 participants