-
Notifications
You must be signed in to change notification settings - Fork 796
Allows Vulkan spec constants as attribute arguments. #7439
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
8e898bf
27547de
a9e9d4b
eb2dc82
423617d
793f8f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -328,6 +328,19 @@ class CGMSHLSLRuntime : public CGHLSLRuntime { | |||||||
}; | ||||||||
} // namespace | ||||||||
|
||||||||
static uint32_t GetIntConstAttrArg(ASTContext &astContext, const Expr *expr, | ||||||||
uint32_t defaultVal = 0) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Doesn't look like this is ever called without a default value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've changed this to use llvm::Optional so that an absent default indicates that expr should be non-null. (See note on SemaHLSL below.) |
||||||||
if (expr) { | ||||||||
llvm::APSInt apsInt; | ||||||||
APValue apValue; | ||||||||
if (expr->isIntegerConstantExpr(apsInt, astContext)) | ||||||||
return (uint32_t)apsInt.getSExtValue(); | ||||||||
if (expr->isVulkanSpecConstantExpr(astContext, &apValue) && apValue.isInt()) | ||||||||
return (uint32_t)apValue.getInt().getSExtValue(); | ||||||||
} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We should be erroring in Sema if this isn't a constant expression or spec constant. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed as suggested. |
||||||||
return defaultVal; | ||||||||
} | ||||||||
|
||||||||
//------------------------------------------------------------------------------ | ||||||||
// | ||||||||
// CGMSHLSLRuntime methods. | ||||||||
|
@@ -1422,6 +1435,7 @@ void CGMSHLSLRuntime::AddHLSLFunctionInfo(Function *F, const FunctionDecl *FD) { | |||||||
} | ||||||||
|
||||||||
DiagnosticsEngine &Diags = CGM.getDiags(); | ||||||||
ASTContext &astContext = CGM.getTypes().getContext(); | ||||||||
|
||||||||
std::unique_ptr<DxilFunctionProps> funcProps = | ||||||||
llvm::make_unique<DxilFunctionProps>(); | ||||||||
|
@@ -1632,10 +1646,9 @@ void CGMSHLSLRuntime::AddHLSLFunctionInfo(Function *F, const FunctionDecl *FD) { | |||||||
|
||||||||
// Populate numThreads | ||||||||
if (const HLSLNumThreadsAttr *Attr = FD->getAttr<HLSLNumThreadsAttr>()) { | ||||||||
|
||||||||
funcProps->numThreads[0] = Attr->getX(); | ||||||||
funcProps->numThreads[1] = Attr->getY(); | ||||||||
funcProps->numThreads[2] = Attr->getZ(); | ||||||||
funcProps->numThreads[0] = GetIntConstAttrArg(astContext, Attr->getX(), 1); | ||||||||
funcProps->numThreads[1] = GetIntConstAttrArg(astContext, Attr->getY(), 1); | ||||||||
funcProps->numThreads[2] = GetIntConstAttrArg(astContext, Attr->getZ(), 1); | ||||||||
|
||||||||
if (isEntry && !SM->IsCS() && !SM->IsMS() && !SM->IsAS()) { | ||||||||
unsigned DiagID = Diags.getCustomDiagID( | ||||||||
|
@@ -1808,7 +1821,8 @@ void CGMSHLSLRuntime::AddHLSLFunctionInfo(Function *F, const FunctionDecl *FD) { | |||||||
|
||||||||
if (const auto *pAttr = FD->getAttr<HLSLNodeIdAttr>()) { | ||||||||
funcProps->NodeShaderID.Name = pAttr->getName().str(); | ||||||||
funcProps->NodeShaderID.Index = pAttr->getArrayIndex(); | ||||||||
funcProps->NodeShaderID.Index = | ||||||||
GetIntConstAttrArg(astContext, pAttr->getArrayIndex(), 0); | ||||||||
} else { | ||||||||
funcProps->NodeShaderID.Name = FD->getName().str(); | ||||||||
funcProps->NodeShaderID.Index = 0; | ||||||||
|
@@ -1819,20 +1833,28 @@ void CGMSHLSLRuntime::AddHLSLFunctionInfo(Function *F, const FunctionDecl *FD) { | |||||||
} | ||||||||
if (const auto *pAttr = FD->getAttr<HLSLNodeShareInputOfAttr>()) { | ||||||||
funcProps->NodeShaderSharedInput.Name = pAttr->getName().str(); | ||||||||
funcProps->NodeShaderSharedInput.Index = pAttr->getArrayIndex(); | ||||||||
funcProps->NodeShaderSharedInput.Index = | ||||||||
GetIntConstAttrArg(astContext, pAttr->getArrayIndex(), 0); | ||||||||
} | ||||||||
if (const auto *pAttr = FD->getAttr<HLSLNodeDispatchGridAttr>()) { | ||||||||
funcProps->Node.DispatchGrid[0] = pAttr->getX(); | ||||||||
funcProps->Node.DispatchGrid[1] = pAttr->getY(); | ||||||||
funcProps->Node.DispatchGrid[2] = pAttr->getZ(); | ||||||||
funcProps->Node.DispatchGrid[0] = | ||||||||
GetIntConstAttrArg(astContext, pAttr->getX(), 1); | ||||||||
funcProps->Node.DispatchGrid[1] = | ||||||||
GetIntConstAttrArg(astContext, pAttr->getY(), 1); | ||||||||
funcProps->Node.DispatchGrid[2] = | ||||||||
GetIntConstAttrArg(astContext, pAttr->getZ(), 1); | ||||||||
} | ||||||||
if (const auto *pAttr = FD->getAttr<HLSLNodeMaxDispatchGridAttr>()) { | ||||||||
funcProps->Node.MaxDispatchGrid[0] = pAttr->getX(); | ||||||||
funcProps->Node.MaxDispatchGrid[1] = pAttr->getY(); | ||||||||
funcProps->Node.MaxDispatchGrid[2] = pAttr->getZ(); | ||||||||
funcProps->Node.MaxDispatchGrid[0] = | ||||||||
GetIntConstAttrArg(astContext, pAttr->getX(), 1); | ||||||||
funcProps->Node.MaxDispatchGrid[1] = | ||||||||
GetIntConstAttrArg(astContext, pAttr->getY(), 1); | ||||||||
funcProps->Node.MaxDispatchGrid[2] = | ||||||||
GetIntConstAttrArg(astContext, pAttr->getZ(), 1); | ||||||||
} | ||||||||
if (const auto *pAttr = FD->getAttr<HLSLNodeMaxRecursionDepthAttr>()) { | ||||||||
funcProps->Node.MaxRecursionDepth = pAttr->getCount(); | ||||||||
funcProps->Node.MaxRecursionDepth = | ||||||||
GetIntConstAttrArg(astContext, pAttr->getCount(), 0); | ||||||||
} | ||||||||
if (!FD->getAttr<HLSLNumThreadsAttr>()) { | ||||||||
// NumThreads wasn't specified. | ||||||||
|
@@ -2346,8 +2368,9 @@ void CGMSHLSLRuntime::AddHLSLFunctionInfo(Function *F, const FunctionDecl *FD) { | |||||||
NodeInputRecordParams[ArgIt].MetadataIdx = NodeInputParamIdx++; | ||||||||
|
||||||||
if (parmDecl->hasAttr<HLSLMaxRecordsAttr>()) { | ||||||||
node.MaxRecords = | ||||||||
parmDecl->getAttr<HLSLMaxRecordsAttr>()->getMaxCount(); | ||||||||
node.MaxRecords = GetIntConstAttrArg( | ||||||||
astContext, | ||||||||
parmDecl->getAttr<HLSLMaxRecordsAttr>()->getMaxCount(), 1); | ||||||||
} | ||||||||
if (parmDecl->hasAttr<HLSLGloballyCoherentAttr>()) | ||||||||
node.Flags.SetGloballyCoherent(); | ||||||||
|
@@ -2378,7 +2401,8 @@ void CGMSHLSLRuntime::AddHLSLFunctionInfo(Function *F, const FunctionDecl *FD) { | |||||||
// OutputID from attribute | ||||||||
if (const auto *Attr = parmDecl->getAttr<HLSLNodeIdAttr>()) { | ||||||||
node.OutputID.Name = Attr->getName().str(); | ||||||||
node.OutputID.Index = Attr->getArrayIndex(); | ||||||||
node.OutputID.Index = | ||||||||
GetIntConstAttrArg(astContext, Attr->getArrayIndex(), 0); | ||||||||
} else { | ||||||||
node.OutputID.Name = parmDecl->getName().str(); | ||||||||
node.OutputID.Index = 0; | ||||||||
|
@@ -2437,7 +2461,7 @@ void CGMSHLSLRuntime::AddHLSLFunctionInfo(Function *F, const FunctionDecl *FD) { | |||||||
node.MaxRecordsSharedWith = ix; | ||||||||
} | ||||||||
if (const auto *Attr = parmDecl->getAttr<HLSLMaxRecordsAttr>()) | ||||||||
node.MaxRecords = Attr->getMaxCount(); | ||||||||
node.MaxRecords = GetIntConstAttrArg(astContext, Attr->getMaxCount(), 0); | ||||||||
} | ||||||||
|
||||||||
if (inputPatchCount > 1) { | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've got a fair amount of mixing coding style, and DXC is a bit inconsistent.
In general if you're adding code in a part of the codebase that isn't otherwise following a consistent style we follow the LLVM Coding Standards. LLVM uses
CamelCase
for variable names and type names (see: https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.