Skip to content

Conversation

@damyanp
Copy link
Member

@damyanp damyanp commented Apr 9, 2025

Conflicts:

    both modified:   include/dxc/DXIL/DxilConstants.h
    both modified:   include/dxc/DXIL/DxilOperations.h
    both modified:   lib/DXIL/DxilOperations.cpp
    both modified:   lib/DxilValidation/DxilValidation.cpp
    both modified:   lib/HLSL/DxilLinker.cpp
    both added:      lib/HLSL/DxilScalarizeVectorLoadStores.cpp
    both modified:   lib/HLSL/HLOperationLower.cpp
    both modified:   tools/clang/lib/Sema/SemaHLSL.cpp
    both added:      tools/clang/test/CodeGenDXIL/hlsl/intrinsics/buffer-load-stores-sm69.hlsl
    both added:      tools/clang/test/CodeGenDXIL/hlsl/types/longvec-operators-cs.hlsl
    both added:      tools/clang/test/DXILValidation/vector-validation.hlsl
    both modified:   utils/hct/hctdb.py
    both modified:   utils/hct/hctdb_instrhelp.py

llvm-beanz and others added 19 commits April 1, 2025 12:10
Hopefully this works and gets us able to build with CMake 4+.
microsoft#7259)

This change adds vector and multi-dimensional overload support for DXIL
operations.

Multi-dimensional (or "extended") overloads are added, where two or more
types in a DXIL Op function signature may vary independently, such as
both the return type and a parameter type. Until now, only one overload
dimension has been necessary.

For single-dim overloads, any number of parameters in a DXIL op may
refer to this single overload type.
For multi-dim overloads, each type that can vary must have a unique
overload dimension, even when two or more types must be the same. This
follows a pattern from llvm intrinsics. If two or more of the types need
to be the same, this constraint must be handled manually, outside the
automatic overload constraints defined by the DXIL op definitions.

Vector overloads are also added, requiring an additional set of scalar
overload types to define the allowed vector element types, on top of the
original set describing the allowed scalar overloads for an operation,
since both scalar and vector overloads may be allowed on the same
operation.

There are several components involved in handling DXIL operation
overloads, with some changes:

- DXIL Op definitions in `hctdb.py` use a string of characters to define
the allowed overloads, and special type names used in parameter
definitions that refer to the overload type.
  - Overload string syntax updated and more heavily validated.
  - `','` may separate dimensions for multi-dim overloads
- `'<'` indicates that a vector overload is allowed, in which case,
scalar components on the left indicate normal scalar overloads allowed,
and scalar components on the right indicate the allowed vector element
overloads.
- If scalar overloads are present to the left, and omitted to the right,
the scalar components are replicated to the right automatically. For
instance: `"hf<"` is equivalent to `"hf<hf"`.
- `dxil_max_overload_dims = 2` is introduced to define the maximum
number of overload dimensions currently supported.
- This is used to generate the `DXIL::kDxilMaxOloadDims` definition in
`DxilConstants.h`.
- `"$x0"` and `"$x1"` are used to reference each overloaded dxil type in
parameter definitions when more than one overload dimension is defined
for a DXIL op. Other special overload types are not allowed for
multi-dim overloads, which means you cannot (currently) describe a
multi-dim overload where a returned overload type is wrapped in a
resource return struct along with residency status. This could be
changed in the future if necessary.
- Enforced rules for multi-dim overloads keep them compatible with the
llvm intrinsic overloading scheme.
- `hctdb_instrhelp.py` translates overload and param type info from DXIL
operation definitions into code inserted into `DxilOperations.cpp`.
- `DxilOperations.h|cpp` encodes allowed overloads inside
`OpCodeProperty` state for each operation in the `m_OpCodeProps` table.
It uses this information, along with generated code, to enforce overload
rules on DXIL ops.
- The allowed overload definition in `OpCodeProperty` has been rewritten
to use a more compact `OverloadMask` type, support multi-dim overloads,
and add a second layer `AllowedVectorElements` for vector overloads for
each dimension.
- There are assumptions that one `llvm::Type*` describes the overload
type, such as with: `GetOpFunc`, `GetOpFuncList`, `GetOverloadType`,
`IsOverloadLegal`, and `m_OpCodeClassCache`. The scheme used for
multi-dim overloads is to encode each of the overload types in a single
unnamed `StructType`, like `type {i32, <4 x float>}`. This makes it
compatible with all these existing mechanisms without requiring an API
overhaul impacting the broader code base. `GetExtendedOverloadType` is
used to construct this type from multiple types.

While updating `DxilOperations.h|cpp`, I noticed and removed some unused
methods: `IsDxilOpTypeName`, `IsDxilOpType`, `IsDupDxilOpType`,
`GetOriginalDxilOpType`.

---------

Co-authored-by: Greg Roth <grroth@microsoft.com>
…icrosoft#7238)

The DXR invocation counting pass calls a function to add an output UAV
twice. As part of adding the UAV, any DXIL-defined rootsigs will be
extended to include this new UAV. If the UAV already exists in the
rootsig, we should not add it again. (Doing so results in root sig that
will fail validation.)

Note: the test is not a file-check style because dxil-defined subobjects
don't get rehydrated into the DxilModule when the output of dxc.exe is
piped into the input of opt.exe, meaning that the broken case can't be
exercised.
When emitting discard in an unreachable code context (e.g. after an
infinite loop), DXC would assert (if asserts enabled), or trigger a
UBSAN failure because the discard instruction would have no parent. When
an infinite loop is emitted during CodeGen, the InsertPt is cleared,
thus subsequent discard instructions would be created, but no parent
set. We skip emitting discard in this case, which follows the same
pattern as is done for EmitIfStmt, and EmitSwitchStmt.
MS just changed policy to enforce code owners across the whole
enterprise, which is _not_ what we want. So we need to disable this in
main for the time being.
Keep seeing this comment typo and wanted to rectify.
…ests to spec. (microsoft#7281)

This PR adds 2 tests that were mentioned in the spec that haven't yet
been added.
1. A test that makes sure that restricted flags are diagnosed in DXR
entry shaders.
2. A test that makes sure that no diagnostics are emitted when a
restricted flag is used for a subobject in a non-library shadaer target.

Fixes microsoft#7282
If `"SPV_KHR_quad_control"` can be used, uses
`OpGroupNonUniformQuadAnyKHR` and `OpGroupNonUniformQuadAllKHR`. If not,
falls back to constructing the value using
`OpGroupNonUniformQuadSwap`.

Fixes microsoft#7247
Fixes microsoft#7248

Fix Clang Compilation on Linux without Microsoft extensions enabled.

## Rationale
Clang support depends on the `-fms-extensions` compiler flag.
[[1]](https://clang.llvm.org/docs/UsersManual.html#microsoft-extensions)
If enabled, the `_MSC_EXTENSIONS` macro is defined.
[[2]](https://github.com/llvm/llvm-project/blob/19a319667b567a26a20f9829a0ae7e6a5c259cba/clang/lib/Basic/Targets/OSTargets.cpp#L248)
This change seeks to address some recent questions about how the LLLVM
Coding Standards are applied in DXC.

---------

Co-authored-by: Ashley Coleman <ascoleman@microsoft.com>
…ts vk::BufferPointer proposal) (microsoft#7306)

#ifdef ENABLE_SPIRV_CODEGEN was omitted in several places.
)

Capitalize all the variables and rename a few in DxilValidation.cpp in
keeping with
https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly

As this file was easily mistaken for applying to the golden rule:
https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly
it is at serious risk of receiving changes that will get hung up by
requirements to follow the LLVM coding guidelines. This brings the cases
where variable capitalization is not in line with the coding standards
to avoid such pitfalls in the future.
Enables the declaration of long vector types for raw buffers, the
lowering of those and traditional vectors in loads and stores maintaining
the native types with new dxil ops along with validation and testing
support of the same.

Allow declaring long vector rawbuffer resources.
Previously disallowed along with other global types, this provides a
mechanism for indicating which buffers are raw and allowing them to
contain long vectors, continuing to produce an error for other resource
types verified by existing tests

Introduce native vector DXIL load/store intrinsics.
Add new raw buffer vector load/store intrinsics using the new vector
overload types.
Include them in validation associated with similar load/stores

Lower native vector raw buffers load/stores into new ops.
When the loaded/stored type is a vector of more than 1 element, the
shader model is 6.9 or higher, and the operation is on a raw buffer,
enable the generation of a native vector raw buffer load or store.

Incidental removal of unused parameter in load translation and some
refactoring
of the lowering to flow better with the new resret types.

add validation and compute shader tests

Vector to scalar raw buffer load lowering pass
Native vector loads and stores are generated for 6.9 targets and above.
This includes the 6.x target used when compiling to libraries. This adds
a pass run when linking that will lower the vector operations to scalar
operations for shader models that don't have native vector support. This
allows libraries compiled for supportive shader models to be linked to
targets without support.

Validate native vector loads and stores for properly defined parameters
of the correct type. Add tests for both vector load/stores and the
original scalar load/stores since they share a lot of validation code.

Fixes microsoft#7118
I provided feedback during code review that this function should be
named following LLVM conventions. That feedback did not account for the
fact that SemaHLSL is otherwise consistent using CamelCase instead of
camelCase naming.

This corrects my error by renaming to match the consistent style in
SemaHLSL.h.

I've also updated the parameter naming in the source file to conform to
LLVM style since I was in the area anyways.
… into a UAV (microsoft#7272)

This is a pass to add instructions to determine missing usage of the
NonUniformResourceIndex qualifier when dynamically indexing resources.
The instruction numbers will be written out to a UAV for later ingestion
by PIX to present a view of the output.
Bumps [cryptography](https://github.com/pyca/cryptography) from 43.0.1
to 44.0.1.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/pyca/cryptography/blob/main/CHANGELOG.rst">cryptography's
changelog</a>.</em></p>
<blockquote>
<p>44.0.1 - 2025-02-11</p>
<pre><code>
* Updated Windows, macOS, and Linux wheels to be compiled with OpenSSL
3.4.1.
* We now build ``armv7l`` ``manylinux`` wheels and publish them to PyPI.
* We now build ``manylinux_2_34`` wheels and publish them to PyPI.
<p>.. _v44-0-0:</p>
<p>44.0.0 - 2024-11-27
</code></pre></p>
<ul>
<li><strong>BACKWARDS INCOMPATIBLE:</strong> Dropped support for
LibreSSL &lt; 3.9.</li>
<li>Deprecated Python 3.7 support. Python 3.7 is no longer supported by
the
Python core team. Support for Python 3.7 will be removed in a future
<code>cryptography</code> release.</li>
<li>Updated Windows, macOS, and Linux wheels to be compiled with OpenSSL
3.4.0.</li>
<li>macOS wheels are now built against the macOS 10.13 SDK. Users on
older
versions of macOS should upgrade, or they will need to build
<code>cryptography</code> themselves.</li>
<li>Enforce the :rfc:<code>5280</code> requirement that extended key
usage extensions must
not be empty.</li>
<li>Added support for timestamp extraction to the
:class:<code>~cryptography.fernet.MultiFernet</code> class.</li>
<li>Relax the Authority Key Identifier requirements on root CA
certificates
during X.509 verification to allow fields permitted by
:rfc:<code>5280</code> but
forbidden by the CA/Browser BRs.</li>
<li>Added support for
:class:<code>~cryptography.hazmat.primitives.kdf.argon2.Argon2id</code>
when using OpenSSL 3.2.0+.</li>
<li>Added support for the
:class:<code>~cryptography.x509.Admissions</code> certificate
extension.</li>
<li>Added basic support for PKCS7 decryption (including S/MIME 3.2) via

:func:<code>~cryptography.hazmat.primitives.serialization.pkcs7.pkcs7_decrypt_der</code>,

:func:<code>~cryptography.hazmat.primitives.serialization.pkcs7.pkcs7_decrypt_pem</code>,
and

:func:<code>~cryptography.hazmat.primitives.serialization.pkcs7.pkcs7_decrypt_smime</code>.</li>
</ul>
<p>.. _v43-0-3:</p>
<p>43.0.3 - 2024-10-18</p>
<pre><code>
* Fixed release metadata for ``cryptography-vectors``
<p>.. _v43-0-2:</p>
<p>43.0.2 - 2024-10-18
</code></pre></p>
<ul>
<li>Fixed compilation when using LibreSSL 4.0.0.</li>
</ul>
<p>.. _v43-0-1:</p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/pyca/cryptography/commit/adaaaed77db676bbaa9d171175db81dce056e2a7"><code>adaaaed</code></a>
Bump for 44.0.1 release (<a
href="https://redirect.github.com/pyca/cryptography/issues/12441">#12441</a>)</li>
<li><a
href="https://github.com/pyca/cryptography/commit/ccc61dabe38b86956bf218565cd4e82b918345a1"><code>ccc61da</code></a>
[backport] test and build on armv7l (<a
href="https://redirect.github.com/pyca/cryptography/issues/12420">#12420</a>)
(<a
href="https://redirect.github.com/pyca/cryptography/issues/12431">#12431</a>)</li>
<li><a
href="https://github.com/pyca/cryptography/commit/f299a48153650f2dd87716343f2daa7cd39a1f59"><code>f299a48</code></a>
remove deprecated call (<a
href="https://redirect.github.com/pyca/cryptography/issues/12052">#12052</a>)</li>
<li><a
href="https://github.com/pyca/cryptography/commit/439eb0594a9ffb7c9adedb2490998d83914d141e"><code>439eb05</code></a>
Bump version for 44.0.0 (<a
href="https://redirect.github.com/pyca/cryptography/issues/12051">#12051</a>)</li>
<li><a
href="https://github.com/pyca/cryptography/commit/2c5ad4d8dcec1b8f833198bc2f3b4634c4fd9d78"><code>2c5ad4d</code></a>
chore(deps): bump maturin from 1.7.4 to 1.7.5 in /.github/requirements
(<a
href="https://redirect.github.com/pyca/cryptography/issues/12050">#12050</a>)</li>
<li><a
href="https://github.com/pyca/cryptography/commit/d23968adddd79aa8508d7c1f985da09383b3808f"><code>d23968a</code></a>
chore(deps): bump libc from 0.2.165 to 0.2.166 (<a
href="https://redirect.github.com/pyca/cryptography/issues/12049">#12049</a>)</li>
<li><a
href="https://github.com/pyca/cryptography/commit/133c0e02edf2f172318eb27d8f50525ed64c9ec3"><code>133c0e0</code></a>
Bump x509-limbo and/or wycheproof in CI (<a
href="https://redirect.github.com/pyca/cryptography/issues/12047">#12047</a>)</li>
<li><a
href="https://github.com/pyca/cryptography/commit/f2259d7aa0d134c839ebe298baa8b63de9ead804"><code>f2259d7</code></a>
Bump BoringSSL and/or OpenSSL in CI (<a
href="https://redirect.github.com/pyca/cryptography/issues/12046">#12046</a>)</li>
<li><a
href="https://github.com/pyca/cryptography/commit/e201c870b89fd2606d67230a97e50c3badb07907"><code>e201c87</code></a>
fixed metadata in changelog (<a
href="https://redirect.github.com/pyca/cryptography/issues/12044">#12044</a>)</li>
<li><a
href="https://github.com/pyca/cryptography/commit/c6104cc3669585941dc1d2b9c6507621c53d242f"><code>c6104cc</code></a>
Prohibit Python 3.9.0, 3.9.1 -- they have a bug that causes errors (<a
href="https://redirect.github.com/pyca/cryptography/issues/12045">#12045</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/pyca/cryptography/compare/43.0.1...44.0.1">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=cryptography&package-manager=pip&previous-version=43.0.1&new-version=44.0.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts
page](https://github.com/microsoft/DirectXShaderCompiler/network/alerts).

</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@github-actions
Copy link
Contributor

github-actions bot commented Apr 9, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff c940161bb3398ff988fafc343ed1623d4a3fad6c aca1035850604853d49d11accd9821330e55742d -- include/dxc/DXIL/DxilInstructions.h include/dxc/Test/WEXAdapter.h lib/DXIL/DxilOperations.cpp lib/DxilValidation/DxilValidation.cpp lib/HLSL/DxilLinker.cpp lib/HLSL/HLOperationLower.cpp tools/clang/lib/Sema/SemaHLSL.cpp tools/clang/unittests/HLSLExec/ExecutionTest.cpp
View the diff from clang-format here.
diff --git a/lib/DxilValidation/DxilValidation.cpp b/lib/DxilValidation/DxilValidation.cpp
index 9e8f8574..a788f21d 100644
--- a/lib/DxilValidation/DxilValidation.cpp
+++ b/lib/DxilValidation/DxilValidation.cpp
@@ -2723,7 +2723,8 @@ static void ValidateFunctionBody(Function *F, ValidationContext &ValCtx) {
       }
 
       // Instructions must be allowed.
-      if (!IsLLVMInstructionAllowed(I) || !IsLLVMInstructionAllowedForShaderModel(I, ValCtx)) {
+      if (!IsLLVMInstructionAllowed(I) ||
+          !IsLLVMInstructionAllowedForShaderModel(I, ValCtx)) {
         if (!IsLLVMInstructionAllowedForLib(I, ValCtx)) {
           ValCtx.EmitInstrError(&I, ValidationRule::InstrAllowed);
           continue;
diff --git a/lib/HLSL/DxilLinker.cpp b/lib/HLSL/DxilLinker.cpp
index c4dae4b6..c58a2e90 100644
--- a/lib/HLSL/DxilLinker.cpp
+++ b/lib/HLSL/DxilLinker.cpp
@@ -1278,7 +1278,7 @@ void DxilLinkJob::RunPreparePass(Module &M) {
   PM.add(createScalarizerPass());
 
   // Need dxilelimvector for pre 6.9
-  //PM.add(createDxilEliminateVectorPass());
+  // PM.add(createDxilEliminateVectorPass());
 
   PM.add(createPromoteMemoryToRegisterPass());
 
diff --git a/lib/HLSL/HLOperationLower.cpp b/lib/HLSL/HLOperationLower.cpp
index 60784558..a68bddaf 100644
--- a/lib/HLSL/HLOperationLower.cpp
+++ b/lib/HLSL/HLOperationLower.cpp
@@ -485,11 +485,11 @@ Value *TrivialDxilOperation(OP::OpCode opcode, ArrayRef<Value *> refArgs,
 }
 
 Value *TrivialDxilVectorOperation(Function *dxilFunc, OP::OpCode opcode,
-                            ArrayRef<Value *> refArgs, Type *Ty,
-                            OP *hlslOP, IRBuilder<> &Builder) {
+                                  ArrayRef<Value *> refArgs, Type *Ty,
+                                  OP *hlslOP, IRBuilder<> &Builder) {
   if (!Ty->isVoidTy()) {
     Value *retVal =
-      Builder.CreateCall(dxilFunc, refArgs, hlslOP->GetOpCodeName(opcode));
+        Builder.CreateCall(dxilFunc, refArgs, hlslOP->GetOpCodeName(opcode));
     return retVal;
   } else {
     // Cannot add name to void.
@@ -497,20 +497,22 @@ Value *TrivialDxilVectorOperation(Function *dxilFunc, OP::OpCode opcode,
   }
 }
 
-
-Value *TrivialDxilVectorUnaryOperationRet(OP::OpCode opcode, Value *src, Type *Ty,
-					  OP *hlslOP, IRBuilder<> &Builder) {
+Value *TrivialDxilVectorUnaryOperationRet(OP::OpCode opcode, Value *src,
+                                          Type *Ty, OP *hlslOP,
+                                          IRBuilder<> &Builder) {
 
   Constant *opArg = hlslOP->GetU32Const((unsigned)opcode);
   Value *args[] = {opArg, src};
 
   Function *dxilFunc = hlslOP->GetOpFunc(opcode, Ty);
 
-  return TrivialDxilVectorOperation(dxilFunc, opcode, args, Ty, hlslOP, Builder);
+  return TrivialDxilVectorOperation(dxilFunc, opcode, args, Ty, hlslOP,
+                                    Builder);
 }
 
-Value *TrivialDxilVectorBinaryOperation(OP::OpCode opcode, Value *src0, Value *src1,
-                                  hlsl::OP *hlslOP, IRBuilder<> &Builder) {
+Value *TrivialDxilVectorBinaryOperation(OP::OpCode opcode, Value *src0,
+                                        Value *src1, hlsl::OP *hlslOP,
+                                        IRBuilder<> &Builder) {
   Type *Ty = src0->getType();
 
   Constant *opArg = hlslOP->GetU32Const((unsigned)opcode);
@@ -518,7 +520,8 @@ Value *TrivialDxilVectorBinaryOperation(OP::OpCode opcode, Value *src0, Value *s
 
   Function *dxilFunc = hlslOP->GetOpFunc(opcode, Ty);
 
-  return TrivialDxilVectorOperation(dxilFunc, opcode, args, Ty, hlslOP, Builder);
+  return TrivialDxilVectorOperation(dxilFunc, opcode, args, Ty, hlslOP,
+                                    Builder);
 }
 
 Value *TrivialDxilUnaryOperationRet(OP::OpCode opcode, Value *src, Type *RetTy,
@@ -547,24 +550,26 @@ Value *TrivialDxilBinaryOperation(OP::OpCode opcode, Value *src0, Value *src1,
   return TrivialDxilOperation(opcode, args, Ty, Ty, hlslOP, Builder);
 }
 
-Value *TrivialDxilTrinaryOperationRet(OP::OpCode opcode, Value *src0, Value *src1,
-				      Value *src2, Type *Ty, hlsl::OP *hlslOP,
-				      IRBuilder<> &Builder) {
+Value *TrivialDxilTrinaryOperationRet(OP::OpCode opcode, Value *src0,
+                                      Value *src1, Value *src2, Type *Ty,
+                                      hlsl::OP *hlslOP, IRBuilder<> &Builder) {
   Constant *opArg = hlslOP->GetU32Const((unsigned)opcode);
   Value *args[] = {opArg, src0, src1, src2};
 
   return TrivialDxilOperation(opcode, args, Ty, Ty, hlslOP, Builder);
 }
 
-Value *TrivialDxilVectorTrinaryOperationRet(OP::OpCode opcode, Value *src0, Value *src1,
-					    Value *src2, Type *Ty, hlsl::OP *hlslOP,
-					    IRBuilder<> &Builder) {
+Value *TrivialDxilVectorTrinaryOperationRet(OP::OpCode opcode, Value *src0,
+                                            Value *src1, Value *src2, Type *Ty,
+                                            hlsl::OP *hlslOP,
+                                            IRBuilder<> &Builder) {
   Constant *opArg = hlslOP->GetU32Const((unsigned)opcode);
   Value *args[] = {opArg, src0, src1, src2};
 
   Function *dxilFunc = hlslOP->GetOpFunc(opcode, Ty);
 
-  return TrivialDxilVectorOperation(dxilFunc, opcode, args, Ty, hlslOP, Builder);
+  return TrivialDxilVectorOperation(dxilFunc, opcode, args, Ty, hlslOP,
+                                    Builder);
 }
 
 Value *TrivialUnaryOperation(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
@@ -579,22 +584,20 @@ Value *TrivialUnaryOperation(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
   return retVal;
 }
 
-Value *TrivialVectorizableUnaryOperation(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
-					 HLOperationLowerHelper &helper,
-					 HLObjectOperationLowerHelper *pObjHelper,
-					 bool &Translated) {
+Value *TrivialVectorizableUnaryOperation(
+    CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
+    HLOperationLowerHelper &helper, HLObjectOperationLowerHelper *pObjHelper,
+    bool &Translated) {
   Value *src0 = CI->getArgOperand(HLOperandIndex::kUnaryOpSrc0Idx);
   Type *Ty = CI->getType();
   IRBuilder<> Builder(CI);
   hlsl::OP *hlslOP = &helper.hlslOP;
 
-  if (Ty->isVectorTy() &&
-      helper.M.GetShaderModel()->IsSM69Plus())
-    return TrivialDxilVectorUnaryOperationRet(opcode, src0, Ty,
-					      hlslOP, Builder);
+  if (Ty->isVectorTy() && helper.M.GetShaderModel()->IsSM69Plus())
+    return TrivialDxilVectorUnaryOperationRet(opcode, src0, Ty, hlslOP,
+                                              Builder);
   else
-    return TrivialDxilUnaryOperationRet(opcode, src0, Ty,
-					hlslOP, Builder);
+    return TrivialDxilUnaryOperationRet(opcode, src0, Ty, hlslOP, Builder);
 }
 
 Value *TrivialBinaryOperation(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
@@ -611,10 +614,11 @@ Value *TrivialBinaryOperation(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
   return binOp;
 }
 
-Value *TrivialVectorBinaryOperation(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
-				    HLOperationLowerHelper &helper,
-				    HLObjectOperationLowerHelper *pObjHelper,
-				    bool &Translated) {
+Value *TrivialVectorBinaryOperation(CallInst *CI, IntrinsicOp IOP,
+                                    OP::OpCode opcode,
+                                    HLOperationLowerHelper &helper,
+                                    HLObjectOperationLowerHelper *pObjHelper,
+                                    bool &Translated) {
   hlsl::OP *hlslOP = &helper.hlslOP;
   Value *src0 = CI->getArgOperand(HLOperandIndex::kBinaryOpSrc0Idx);
   Value *src1 = CI->getArgOperand(HLOperandIndex::kBinaryOpSrc1Idx);
@@ -626,9 +630,9 @@ Value *TrivialVectorBinaryOperation(CallInst *CI, IntrinsicOp IOP, OP::OpCode op
 }
 
 Value *TranslateFMA(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
-		    HLOperationLowerHelper &helper,
-		    HLObjectOperationLowerHelper *pObjHelper,
-		    bool &Translated) {
+                    HLOperationLowerHelper &helper,
+                    HLObjectOperationLowerHelper *pObjHelper,
+                    bool &Translated) {
   hlsl::OP *hlslOP = &helper.hlslOP;
   Type *Ty = CI->getType();
   Value *src0 = CI->getArgOperand(HLOperandIndex::kTrinaryOpSrc0Idx);
@@ -636,11 +640,12 @@ Value *TranslateFMA(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
   Value *src2 = CI->getArgOperand(HLOperandIndex::kTrinaryOpSrc2Idx);
   IRBuilder<> Builder(CI);
 
-  if (Ty->isVectorTy() &&
-      helper.M.GetShaderModel()->IsSM69Plus())
-    return TrivialDxilVectorTrinaryOperationRet(opcode, src0, src1, src2, Ty, hlslOP, Builder);
+  if (Ty->isVectorTy() && helper.M.GetShaderModel()->IsSM69Plus())
+    return TrivialDxilVectorTrinaryOperationRet(opcode, src0, src1, src2, Ty,
+                                                hlslOP, Builder);
   else
-    return TrivialDxilTrinaryOperationRet(opcode, src0, src1, src2, Ty, hlslOP, Builder);
+    return TrivialDxilTrinaryOperationRet(opcode, src0, src1, src2, Ty, hlslOP,
+                                          Builder);
 }
 
 Value *TrivialIsSpecialFloat(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
@@ -1986,15 +1991,16 @@ Value *TranslateClamp(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
 
   IRBuilder<> Builder(CI);
   // min(max(x, minVal), maxVal).
-  if (Ty->isVectorTy() &&
-      helper.M.GetShaderModel()->IsSM69Plus()) {
+  if (Ty->isVectorTy() && helper.M.GetShaderModel()->IsSM69Plus()) {
     Value *maxXMinVal =
-      TrivialDxilVectorBinaryOperation(maxOp, x, minVal, hlslOP, Builder);
-    return TrivialDxilVectorBinaryOperation(minOp, maxXMinVal, maxVal, hlslOP, Builder);
+        TrivialDxilVectorBinaryOperation(maxOp, x, minVal, hlslOP, Builder);
+    return TrivialDxilVectorBinaryOperation(minOp, maxXMinVal, maxVal, hlslOP,
+                                            Builder);
   } else {
     Value *maxXMinVal =
-      TrivialDxilBinaryOperation(maxOp, x, minVal, hlslOP, Builder);
-    return TrivialDxilBinaryOperation(minOp, maxXMinVal, maxVal, hlslOP, Builder);
+        TrivialDxilBinaryOperation(maxOp, x, minVal, hlslOP, Builder);
+    return TrivialDxilBinaryOperation(minOp, maxXMinVal, maxVal, hlslOP,
+                                      Builder);
   }
 }
 
@@ -2308,11 +2314,12 @@ Value *TranslateExp(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
         ConstantVector::getSplat(Ty->getVectorNumElements(), log2eConst);
   }
   val = Builder.CreateFMul(log2eConst, val);
-  if (Ty->isVectorTy() &&
-      helper.M.GetShaderModel()->IsSM69Plus())
-    return TrivialDxilVectorUnaryOperationRet(OP::OpCode::Exp, val, Ty, hlslOP, Builder);
+  if (Ty->isVectorTy() && helper.M.GetShaderModel()->IsSM69Plus())
+    return TrivialDxilVectorUnaryOperationRet(OP::OpCode::Exp, val, Ty, hlslOP,
+                                              Builder);
   else
-    return TrivialDxilUnaryOperationRet(OP::OpCode::Exp, val, Ty, hlslOP, Builder);
+    return TrivialDxilUnaryOperationRet(OP::OpCode::Exp, val, Ty, hlslOP,
+                                        Builder);
 }
 
 Value *TranslateLog(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
@@ -2328,11 +2335,12 @@ Value *TranslateLog(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
     ln2Const = ConstantVector::getSplat(Ty->getVectorNumElements(), ln2Const);
   }
   Value *log = nullptr;
-  if (Ty->isVectorTy() &&
-      helper.M.GetShaderModel()->IsSM69Plus())
-    log = TrivialDxilVectorUnaryOperationRet(OP::OpCode::Log, val, Ty, hlslOP, Builder);
+  if (Ty->isVectorTy() && helper.M.GetShaderModel()->IsSM69Plus())
+    log = TrivialDxilVectorUnaryOperationRet(OP::OpCode::Log, val, Ty, hlslOP,
+                                             Builder);
   else
-    log = TrivialDxilUnaryOperationRet(OP::OpCode::Log, val, Ty, hlslOP, Builder);
+    log =
+        TrivialDxilUnaryOperationRet(OP::OpCode::Log, val, Ty, hlslOP, Builder);
 
   return Builder.CreateFMul(ln2Const, log);
 }
@@ -2392,13 +2400,12 @@ Value *TranslateFUIBinary(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
       break;
     }
   }
-  if (CI->getType()->isVectorTy() &&
-      helper.M.GetShaderModel()->IsSM69Plus())
+  if (CI->getType()->isVectorTy() && helper.M.GetShaderModel()->IsSM69Plus())
     return TrivialVectorBinaryOperation(CI, IOP, opcode, helper, pObjHelper,
-					Translated);
+                                        Translated);
   else
     return TrivialBinaryOperation(CI, IOP, opcode, helper, pObjHelper,
-				  Translated);
+                                  Translated);
 }
 
 Value *TranslateFUITrinary(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
@@ -2423,7 +2430,8 @@ Value *TranslateFUITrinary(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
   Value *src2 = CI->getArgOperand(HLOperandIndex::kTrinaryOpSrc2Idx);
   IRBuilder<> Builder(CI);
 
-  return TrivialDxilTrinaryOperationRet(opcode, src0, src1, src2, Ty, hlslOP, Builder);
+  return TrivialDxilTrinaryOperationRet(opcode, src0, src1, src2, Ty, hlslOP,
+                                        Builder);
 }
 
 Value *TranslateFrexp(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
@@ -2547,9 +2555,8 @@ Value *TrivialDotOperation(OP::OpCode opcode, Value *src0, Value *src1,
 
 // Instead of using a DXIL intrinsic, implement a dot product operation using
 // multiply and add operations. Used for integer dots and long vectors.
-Value *ExpandDot(Value *arg0, Value *arg1, unsigned vecSize,
-		 hlsl::OP *hlslOP, IRBuilder<> &Builder,
-		 bool Unsigned = false) {
+Value *ExpandDot(Value *arg0, Value *arg1, unsigned vecSize, hlsl::OP *hlslOP,
+                 IRBuilder<> &Builder, bool Unsigned = false) {
   auto madOpCode = Unsigned ? DXIL::OpCode::UMad : DXIL::OpCode::IMad;
   if (arg0->getType()->getScalarType()->isFloatingPointTy())
     madOpCode = DXIL::OpCode::FMad;
@@ -2559,8 +2566,8 @@ Value *ExpandDot(Value *arg0, Value *arg1, unsigned vecSize,
   for (unsigned Elt = 1; Elt < vecSize; ++Elt) {
     Elt0 = Builder.CreateExtractElement(arg0, Elt);
     Elt1 = Builder.CreateExtractElement(arg1, Elt);
-    Result = TrivialDxilTrinaryOperationRet(madOpCode, Elt0, Elt1, Result, Elt0->getType(), hlslOP,
-					    Builder);
+    Result = TrivialDxilTrinaryOperationRet(madOpCode, Elt0, Elt1, Result,
+                                            Elt0->getType(), hlslOP, Builder);
   }
 
   return Result;
@@ -2598,11 +2605,12 @@ Value *TranslateDot(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
   unsigned vecSize = Ty->getVectorNumElements();
   Value *arg1 = CI->getArgOperand(HLOperandIndex::kBinaryOpSrc1Idx);
   IRBuilder<> Builder(CI);
-  if (Ty->getScalarType()->isFloatingPointTy() && Ty->getVectorNumElements() <= 4) {
+  if (Ty->getScalarType()->isFloatingPointTy() &&
+      Ty->getVectorNumElements() <= 4) {
     return TranslateFDot(arg0, arg1, vecSize, hlslOP, Builder);
   } else {
     return ExpandDot(arg0, arg1, vecSize, hlslOP, Builder,
-                         IOP == IntrinsicOp::IOP_udot);
+                     IOP == IntrinsicOp::IOP_udot);
   }
 }
 
@@ -2785,8 +2793,9 @@ Value *TranslateMSad4(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
   byteSrc = Builder.CreateInsertElement(byteSrc, byteSrcElt, 3);
 
   // Msad on vecref and byteSrc.
-  return TrivialDxilTrinaryOperationRet(DXIL::OpCode::Msad, vecRef, byteSrc, accum,
-					vecRef->getType(), hlslOP, Builder);
+  return TrivialDxilTrinaryOperationRet(DXIL::OpCode::Msad, vecRef, byteSrc,
+                                        accum, vecRef->getType(), hlslOP,
+                                        Builder);
 }
 
 Value *TranslateRCP(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
@@ -3151,7 +3160,7 @@ Value *TranslateMul(CallInst *CI, IntrinsicOp IOP, OP::OpCode opcode,
         return TranslateFDot(arg0, arg1, vecSize, hlslOP, Builder);
       } else {
         return ExpandDot(arg0, arg1, vecSize, hlslOP, Builder,
-                             IOP == IntrinsicOp::IOP_umul);
+                         IOP == IntrinsicOp::IOP_umul);
       }
     } else {
       // mul(vector, scalar) == vector * scalar-splat
@@ -6554,7 +6563,8 @@ IntrinsicLower gLowerTable[] = {
     {IntrinsicOp::IOP_asint16, TranslateBitcast, DXIL::OpCode::NumOpCodes},
     {IntrinsicOp::IOP_asuint, TranslateAsUint, DXIL::OpCode::SplitDouble},
     {IntrinsicOp::IOP_asuint16, TranslateAsUint, DXIL::OpCode::NumOpCodes},
-    {IntrinsicOp::IOP_atan, TrivialVectorizableUnaryOperation, DXIL::OpCode::Atan},
+    {IntrinsicOp::IOP_atan, TrivialVectorizableUnaryOperation,
+     DXIL::OpCode::Atan},
     {IntrinsicOp::IOP_atan2, TranslateAtan2, DXIL::OpCode::NumOpCodes},
     {IntrinsicOp::IOP_ceil, TrivialUnaryOperation, DXIL::OpCode::Round_pi},
     {IntrinsicOp::IOP_clamp, TranslateClamp, DXIL::OpCode::NumOpCodes},
@@ -6645,7 +6655,8 @@ IntrinsicLower gLowerTable[] = {
     {IntrinsicOp::IOP_sqrt, TrivialUnaryOperation, DXIL::OpCode::Sqrt},
     {IntrinsicOp::IOP_step, TranslateStep, DXIL::OpCode::NumOpCodes},
     {IntrinsicOp::IOP_tan, TrivialUnaryOperation, DXIL::OpCode::Tan},
-    {IntrinsicOp::IOP_tanh, TrivialVectorizableUnaryOperation, DXIL::OpCode::Htan},
+    {IntrinsicOp::IOP_tanh, TrivialVectorizableUnaryOperation,
+     DXIL::OpCode::Htan},
     {IntrinsicOp::IOP_tex1D, EmptyLower, DXIL::OpCode::NumOpCodes},
     {IntrinsicOp::IOP_tex1Dbias, EmptyLower, DXIL::OpCode::NumOpCodes},
     {IntrinsicOp::IOP_tex1Dgrad, EmptyLower, DXIL::OpCode::NumOpCodes},
diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp
index 2ad97dcd..1ef555c6 100644
--- a/tools/clang/lib/Sema/SemaHLSL.cpp
+++ b/tools/clang/lib/Sema/SemaHLSL.cpp
@@ -389,7 +389,7 @@ enum ArBasicKind {
   (IS_BPROP_AINT(_Props) && GET_BPROP_BITS(_Props) != BPROP_BITS12)
 
 #define IS_BPROP_ENUM(_Props) (((_Props)&BPROP_ENUM) != 0)
-#define IS_BPROP_RAWBUFFER(_Props) (((_Props)&BPROP_RAWBUFFER) != 0)
+#define IS_BPROP_RAWBUFFER(_Props) (((_Props) & BPROP_RAWBUFFER) != 0)
 
 const UINT g_uBasicKindProps[] = {
     BPROP_PRIMITIVE | BPROP_BOOLEAN | BPROP_INTEGER | BPROP_NUMERIC |
@@ -518,14 +518,22 @@ const UINT g_uBasicKindProps[] = {
     BPROP_OBJECT | BPROP_RWBUFFER | BPROP_TEXTURE, // AR_OBJECT_RWTEXTURE3D
     BPROP_OBJECT | BPROP_RWBUFFER,                 // AR_OBJECT_RWBUFFER
 
-    BPROP_OBJECT | BPROP_RBUFFER | BPROP_RAWBUFFER,  // AR_OBJECT_BYTEADDRESS_BUFFER
-    BPROP_OBJECT | BPROP_RWBUFFER | BPROP_RAWBUFFER, // AR_OBJECT_RWBYTEADDRESS_BUFFER
-    BPROP_OBJECT | BPROP_RBUFFER | BPROP_RAWBUFFER,  // AR_OBJECT_STRUCTURED_BUFFER
-    BPROP_OBJECT | BPROP_RWBUFFER | BPROP_RAWBUFFER, // AR_OBJECT_RWSTRUCTURED_BUFFER
-    BPROP_OBJECT | BPROP_RWBUFFER | BPROP_RAWBUFFER, // AR_OBJECT_RWSTRUCTURED_BUFFER_ALLOC
-    BPROP_OBJECT | BPROP_RWBUFFER | BPROP_RAWBUFFER, // AR_OBJECT_RWSTRUCTURED_BUFFER_CONSUME
-    BPROP_OBJECT | BPROP_RWBUFFER | BPROP_RAWBUFFER, // AR_OBJECT_APPEND_STRUCTURED_BUFFER
-    BPROP_OBJECT | BPROP_RWBUFFER | BPROP_RAWBUFFER, // AR_OBJECT_CONSUME_STRUCTURED_BUFFER
+    BPROP_OBJECT | BPROP_RBUFFER |
+        BPROP_RAWBUFFER, // AR_OBJECT_BYTEADDRESS_BUFFER
+    BPROP_OBJECT | BPROP_RWBUFFER |
+        BPROP_RAWBUFFER, // AR_OBJECT_RWBYTEADDRESS_BUFFER
+    BPROP_OBJECT | BPROP_RBUFFER |
+        BPROP_RAWBUFFER, // AR_OBJECT_STRUCTURED_BUFFER
+    BPROP_OBJECT | BPROP_RWBUFFER |
+        BPROP_RAWBUFFER, // AR_OBJECT_RWSTRUCTURED_BUFFER
+    BPROP_OBJECT | BPROP_RWBUFFER |
+        BPROP_RAWBUFFER, // AR_OBJECT_RWSTRUCTURED_BUFFER_ALLOC
+    BPROP_OBJECT | BPROP_RWBUFFER |
+        BPROP_RAWBUFFER, // AR_OBJECT_RWSTRUCTURED_BUFFER_CONSUME
+    BPROP_OBJECT | BPROP_RWBUFFER |
+        BPROP_RAWBUFFER, // AR_OBJECT_APPEND_STRUCTURED_BUFFER
+    BPROP_OBJECT | BPROP_RWBUFFER |
+        BPROP_RAWBUFFER, // AR_OBJECT_CONSUME_STRUCTURED_BUFFER
 
     BPROP_OBJECT | BPROP_RBUFFER, // AR_OBJECT_CONSTANT_BUFFER
     BPROP_OBJECT | BPROP_RBUFFER, // AR_OBJECT_TEXTURE_BUFFER
  • Check this box to apply formatting changes to this branch.

@damyanp damyanp marked this pull request as ready for review April 9, 2025 17:23
@damyanp damyanp changed the base branch from main to staging-sm6.9 April 9, 2025 21:59
@damyanp damyanp requested a review from a team as a code owner April 9, 2025 21:59
@damyanp
Copy link
Member Author

damyanp commented Apr 10, 2025

Merging this now so we can unblock the tests for #7290

@damyanp damyanp merged commit d478b86 into microsoft:staging-sm6.9 Apr 10, 2025
11 checks passed
@github-project-automation github-project-automation bot moved this from New to Done in HLSL Roadmap Apr 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.