Skip to content
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

[SM6.9] Generate native vector variants of elementwise operators #7123

Open
Tracked by #7067
pow2clk opened this issue Feb 4, 2025 · 0 comments · May be fixed by #7155
Open
Tracked by #7067

[SM6.9] Generate native vector variants of elementwise operators #7123

pow2clk opened this issue Feb 4, 2025 · 0 comments · May be fixed by #7155
Assignees
Labels
enhancement Feature suggestion sm6.9 Shader Model 6.9

Comments

@pow2clk
Copy link
Member

pow2clk commented Feb 4, 2025

In 6.9, elementwise vector operators should produce operators that work on the native vectors instead of scalarizing them. These operations include:

  • arithmetic operations: +, -(unary and binary), *, /, %, +=, -=, *=, /=
  • bitwise operations: |, &, ^, ~, |=, &=, ^=
  • equality operations: ==, !=, <, >, <=, >=
  • logic operations: ||, &&, ?:

Note that logic operations are disallowed for vectors as of HLSL2021 in favor of and, or, and select

This will largely be accomplished by disabling the scalarization passes that previously converted vectors to scalar variants. Testing should verify that the DXIL output preserves the vectors as arguments for all of these operators.

@pow2clk pow2clk changed the title Support long vectors on native operators Generate native vector variants of elementwise operators Feb 4, 2025
@pow2clk pow2clk changed the title Generate native vector variants of elementwise operators [SM6.9] Generate native vector variants of elementwise operators Feb 4, 2025
@pow2clk pow2clk added enhancement Feature suggestion sm6.9 Shader Model 6.9 labels Feb 4, 2025
@pow2clk pow2clk self-assigned this Feb 4, 2025
@pow2clk pow2clk moved this to Active in HLSL Support Feb 4, 2025
@pow2clk pow2clk moved this from Active to Planning in HLSL Support Feb 4, 2025
@damyanp damyanp moved this from Planning to Active in HLSL Support Feb 10, 2025
pow2clk added a commit to pow2clk/DirectXShaderCompiler that referenced this issue Feb 20, 2025
Disables various forms of scalarization and vector elimination to permit
vectors to pass through to final DXIL when used in native LLVM
operations and loading/storing.

Introduces a few vector manipulation llvm instructions to DXIL allowing
for them to appear in output DXIL.

Skips passes for 6.9 that scalarize, convert to arrays, or otherwise eliminate vectors.
This eliminates the element-by-element loading of the vectors
In many cases, this required plumbing the shader model information to
passes that didn't have it before.

Many changes were needed for the MatrixBitcastLower pass related to
linking to avoid converting matrix vectors, but also to perform the
conversion if a shader was compiled for 6.9+, but then linked to a
earlier target.
This now adapts to the linker target to either preserve vectors for 6.9 or arrays for previous versions.
This requires running the DynamicIndexing VectorToArray pass during linking since 6_x and 6_9+ will fail to run this in the initial compile, but will still need to lower vectors to arrays.

Ternary conditional/select operators were element extracted in codegen.
Removing this allows 6.9 to preserve the vectors, but also maintains
behavior for previous shader models because the operations get
scalarized later anyway.

Keep groupshared variables as vectors for 6.9. They are no longer represented as indivual groupshared scalars.

Adds extensive tests for these operations using different types and
sizes and testing them appropriately. Booleans produce significantly
different code, so they get their own test.

Fixes microsoft#7123
@pow2clk pow2clk linked a pull request Feb 20, 2025 that will close this issue
@damyanp damyanp moved this from Active to Needs Review in HLSL Support Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature suggestion sm6.9 Shader Model 6.9
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant