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

[WorkGraph][SM6.9] Implements [MaxRecordPerNode(N)] for NodeOutpurArray #7177

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

anupamachandra
Copy link
Collaborator

Implements the following spec:
https://github.com/microsoft/hlsl-specs/blob/main/proposals/0025-max-records-per-node.md

Adds some basic Filecheck tests.

@anupamachandra anupamachandra requested a review from a team as a code owner March 6, 2025 04:25
Copy link
Contributor

github-actions bot commented Mar 6, 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 0a1143572d107c8b6980df092b84a79190ec1fbd c1788dc5bb516633d87c54e98a5c7acd66f5010f -- include/dxc/DXIL/DxilMetadataHelper.h include/dxc/DXIL/DxilNodeProps.h lib/DXIL/DxilMetadataHelper.cpp lib/DxilContainer/DxilContainerAssembler.cpp tools/clang/include/clang/AST/HlslTypes.h tools/clang/lib/AST/HlslTypes.cpp tools/clang/lib/CodeGen/CGHLSLMS.cpp tools/clang/lib/Parse/ParseDecl.cpp tools/clang/lib/Sema/SemaHLSL.cpp
View the diff from clang-format here.
diff --git a/lib/DXIL/DxilMetadataHelper.cpp b/lib/DXIL/DxilMetadataHelper.cpp
index 31a1b9e6..30084eb6 100644
--- a/lib/DXIL/DxilMetadataHelper.cpp
+++ b/lib/DXIL/DxilMetadataHelper.cpp
@@ -1985,7 +1985,7 @@ void DxilMDHelper::SerializeNodeProps(SmallVectorImpl<llvm::Metadata *> &MDVals,
     MDVals.push_back(Uint32ToConstMD(nodeoutput.OutputArraySize));
     MDVals.push_back(BoolToConstMD(nodeoutput.AllowSparseNodes));
     MDVals.push_back(Uint32ToConstMD(nodeoutput.RecordType.alignment));
-    MDVals.push_back(Uint32ToConstMD(nodeoutput.MaxRecordsPerNode));    
+    MDVals.push_back(Uint32ToConstMD(nodeoutput.MaxRecordsPerNode));
   }
 }
 
@@ -2834,7 +2834,7 @@ DxilMDHelper::EmitDxilNodeIOState(const hlsl::NodeIOProperties &Node) {
       NodeOpIDVals.emplace_back(Uint32ToConstMD(Node.OutputID.Index));
       MDVals.emplace_back(MDNode::get(m_Ctx, NodeOpIDVals));
     }
-    
+
     if (Node.MaxRecordsPerNode) {
       MDVals.emplace_back(
           Uint32ToConstMD(DxilMDHelper::kDxilNodeMaxRecordsPerNodeTag));
diff --git a/lib/DxilContainer/DxilContainerAssembler.cpp b/lib/DxilContainer/DxilContainerAssembler.cpp
index 9505279b..9ff31ff2 100644
--- a/lib/DxilContainer/DxilContainerAssembler.cpp
+++ b/lib/DxilContainer/DxilContainerAssembler.cpp
@@ -1169,21 +1169,21 @@ private:
               (uint32_t)RDAT::NodeAttribKind::MaxRecordsSharedWith;
           nAttrib.MaxRecordsSharedWith = N.MaxRecordsSharedWith;
           nodeAttribs.push_back(Builder.InsertRecord(nAttrib));
-        } 
-        
+        }
+
         if (N.MaxRecordsPerNode > 0) {
-            nAttrib = {};
-            nAttrib.AttribKind = (uint32_t)NodeAttribKind::MaxRecordsPerNode;
-            nAttrib.MaxRecordsPerNode = N.MaxRecordsPerNode;
-            nodeAttribs.push_back(Builder.InsertRecord(nAttrib));
-         }
+          nAttrib = {};
+          nAttrib.AttribKind = (uint32_t)NodeAttribKind::MaxRecordsPerNode;
+          nAttrib.MaxRecordsPerNode = N.MaxRecordsPerNode;
+          nodeAttribs.push_back(Builder.InsertRecord(nAttrib));
+        }
 
         if (N.AllowSparseNodes) {
           nAttrib = {};
           nAttrib.AttribKind = (uint32_t)RDAT::NodeAttribKind::AllowSparseNodes;
           nAttrib.AllowSparseNodes = N.AllowSparseNodes;
           nodeAttribs.push_back(Builder.InsertRecord(nAttrib));
-        }        
+        }
       } else if (N.Flags.IsInputRecord()) {
         if (N.MaxRecords) {
           nAttrib = {};
diff --git a/tools/clang/lib/AST/HlslTypes.cpp b/tools/clang/lib/AST/HlslTypes.cpp
index 15d07993..6cb145ae 100644
--- a/tools/clang/lib/AST/HlslTypes.cpp
+++ b/tools/clang/lib/AST/HlslTypes.cpp
@@ -705,7 +705,7 @@ bool IsHLSLNodeOutputArrayType(clang::QualType type) {
           (static_cast<uint32_t>(DXIL::NodeIOFlags::Output) |
            static_cast<uint32_t>(DXIL::NodeIOFlags::NodeArray) |
            static_cast<uint32_t>(DXIL::NodeIOFlags::RecordGranularityMask))) ==
-          (static_cast<uint32_t>(DXIL::NodeIOFlags::Output) | 
+         (static_cast<uint32_t>(DXIL::NodeIOFlags::Output) |
           static_cast<uint32_t>(DXIL::NodeIOFlags::NodeArray));
 }
 
diff --git a/tools/clang/lib/CodeGen/CGHLSLMS.cpp b/tools/clang/lib/CodeGen/CGHLSLMS.cpp
index 517a8b75..bbec7e14 100644
--- a/tools/clang/lib/CodeGen/CGHLSLMS.cpp
+++ b/tools/clang/lib/CodeGen/CGHLSLMS.cpp
@@ -2435,18 +2435,19 @@ void CGMSHLSLRuntime::AddHLSLFunctionInfo(Function *F, const FunctionDecl *FD) {
     }
     if (const auto *Attr = parmDecl->getAttr<HLSLMaxRecordsAttr>())
       node.MaxRecords = Attr->getMaxCount();
-      // Check for SM6.9 Attributes
-     if (SM->IsSM69Plus()) {
-        // Though MaxRecordsPerNode is a required attribute, this requirement
-        // can be overriden, in which case when the attribute is not present
-        // set the value to MaxRecords.
-        node.MaxRecordsPerNode = node.MaxRecords;
-        if (const auto *Attr = parmDecl->getAttr<HLSLMaxRecordsPerNodeAttr>()) {
-          node.MaxRecordsPerNode = Attr->getMaxCount();
-          DXASSERT(node.MaxRecordsPerNode <= node.MaxRecords,
-                 "MaxRecordsPerNode value should be less than or equal to the MaxRecords value");
-        }
-     }  
+    // Check for SM6.9 Attributes
+    if (SM->IsSM69Plus()) {
+      // Though MaxRecordsPerNode is a required attribute, this requirement
+      // can be overriden, in which case when the attribute is not present
+      // set the value to MaxRecords.
+      node.MaxRecordsPerNode = node.MaxRecords;
+      if (const auto *Attr = parmDecl->getAttr<HLSLMaxRecordsPerNodeAttr>()) {
+        node.MaxRecordsPerNode = Attr->getMaxCount();
+        DXASSERT(node.MaxRecordsPerNode <= node.MaxRecords,
+                 "MaxRecordsPerNode value should be less than or equal to the "
+                 "MaxRecords value");
+      }
+    }
   }
 
   if (inputPatchCount > 1) {
diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp
index 0552e758..d1fd63aa 100644
--- a/tools/clang/lib/Sema/SemaHLSL.cpp
+++ b/tools/clang/lib/Sema/SemaHLSL.cpp
@@ -13386,7 +13386,7 @@ void hlsl::HandleDeclAttributeForHLSL(Sema &S, Decl *D, const AttributeList &A,
         A.getRange(), S.Context, ValidateAttributeIntArg(S, A),
         A.getAttributeSpellingListIndex());
     break;
-   }
+  }
   case AttributeList::AT_HLSLNodeArraySize: {
     declAttr = ::new (S.Context) HLSLNodeArraySizeAttr(
         A.getRange(), S.Context, ValidateAttributeIntArg(S, A),
@@ -15979,12 +15979,13 @@ void DiagnoseNodeEntry(Sema &S, FunctionDecl *FD, llvm::StringRef StageName,
         bool OutputFound = false;
         DiagnoseDispatchGridSemantics(S, NodeStructDecl, PD->getLocation(),
                                       OutputFound);
-      }      
+      }
       if (hlsl::IsHLSLNodeOutputArrayType(ParamType)) {
         std::string profile = S.getLangOpts().HLSLProfile;
         const ShaderModel *SM = hlsl::ShaderModel::GetByName(profile.c_str());
-        if (SM->IsSM69Plus() &&!PD->getAttr<HLSLMaxRecordsPerNodeAttr>()) {
-          S.Diags.Report(PD->getLocation(),
+        if (SM->IsSM69Plus() && !PD->getAttr<HLSLMaxRecordsPerNodeAttr>()) {
+          S.Diags.Report(
+              PD->getLocation(),
               diag::warn_hlsl_max_records_per_node_required_attribute);
         }
       }
@@ -16006,8 +16007,7 @@ void DiagnoseNodeEntry(Sema &S, FunctionDecl *FD, llvm::StringRef StageName,
     auto *NodeArraySizeAttr = Param->getAttr<HLSLNodeArraySizeAttr>();
     auto *UnboundedSparseNodesAttr =
         Param->getAttr<HLSLUnboundedSparseNodesAttr>();
-    auto *MaxRecordsPerNodeAttr =
-        Param->getAttr<HLSLMaxRecordsPerNodeAttr>();
+    auto *MaxRecordsPerNodeAttr = Param->getAttr<HLSLMaxRecordsPerNodeAttr>();
     // Check any node input is compatible with the node launch type
     if (hlsl::IsHLSLNodeInputType(ParamTy)) {
       InputCount++;
@@ -16038,7 +16038,8 @@ void DiagnoseNodeEntry(Sema &S, FunctionDecl *FD, llvm::StringRef StageName,
       // If node output is not an array, diagnose array only attributes
       if (((uint32_t)GetNodeIOType(ParamTy) &
            (uint32_t)DXIL::NodeIOFlags::NodeArray) == 0) {
-        Attr *ArrayAttrs[] = {NodeArraySizeAttr, UnboundedSparseNodesAttr, MaxRecordsPerNodeAttr};
+        Attr *ArrayAttrs[] = {NodeArraySizeAttr, UnboundedSparseNodesAttr,
+                              MaxRecordsPerNodeAttr};
         for (auto *A : ArrayAttrs) {
           if (A) {
             S.Diags.Report(A->getLocation(),
  • Check this box to apply formatting changes to this branch.

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.

1 participant