Skip to content

Commit 6a4aca0

Browse files
committed
AMD SPIR-V work graphs extensions
1 parent 5fbf9f6 commit 6a4aca0

File tree

66 files changed

+3540
-183
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+3540
-183
lines changed

include/dxc/DXIL/DxilSigPoint.inl

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
// This file is distributed under the University of Illinois Open Source //
66
// License. See LICENSE.TXT for details. //
77
// //
8+
// Modifications Copyright(C) 2025 Advanced Micro Devices, Inc. //
9+
// All rights reserved. //
10+
// //
811
///////////////////////////////////////////////////////////////////////////////
912

1013
/* <py>
@@ -309,6 +312,7 @@ DXIL::SigPointKind SigPoint::GetKind(DXIL::ShaderKind shaderKind,
309312
}
310313
break;
311314
case DXIL::ShaderKind::Compute:
315+
case DXIL::ShaderKind::Node:
312316
switch (sigKind) {
313317
case DXIL::SignatureKind::Input:
314318
return DXIL::SigPointKind::CSIn;

include/dxc/DXIL/DxilUtil.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
// This file is distributed under the University of Illinois Open Source //
66
// License. See LICENSE.TXT for details. //
77
// //
8+
// Modifications Copyright(C) 2025 Advanced Micro Devices, Inc. //
9+
// All rights reserved. //
10+
// //
811
// DXIL helper functions. //
912
// //
1013
///////////////////////////////////////////////////////////////////////////////
@@ -178,7 +181,6 @@ bool IsHLSLRWNodeInputRecordType(llvm::Type *Ty);
178181
bool IsHLSLNodeOutputRecordType(llvm::Type *Ty);
179182
bool IsHLSLGSNodeOutputRecordType(llvm::Type *Ty);
180183
bool IsHLSLNodeRecordType(llvm::Type *Ty);
181-
bool IsHLSLNodeInputOutputType(llvm::Type *Ty);
182184

183185
llvm::Type *
184186
StripArrayTypes(llvm::Type *Ty,

lib/DXIL/DxilTypeSystem.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
// This file is distributed under the University of Illinois Open Source //
66
// License. See LICENSE.TXT for details. //
77
// //
8+
// Modifications Copyright(C) 2025 Advanced Micro Devices, Inc. //
9+
// All rights reserved. //
10+
// //
811
///////////////////////////////////////////////////////////////////////////////
912

1013
#include "dxc/DXIL/DxilTypeSystem.h"
@@ -756,6 +759,7 @@ DXIL::SigPointKind SigPointFromInputQual(DxilParamInputQual Q,
756759
}
757760
break;
758761
case DXIL::ShaderKind::Compute:
762+
case DXIL::ShaderKind::Node:
759763
switch (Q) {
760764
case DxilParamInputQual::In:
761765
return DXIL::SigPointKind::CSIn;

lib/DxcSupport/HLSLOptions.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
// This file is distributed under the University of Illinois Open Source //
77
// License. See LICENSE.TXT for details. //
88
// //
9+
// Modifications Copyright(C) 2025 Advanced Micro Devices, Inc. //
10+
// All rights reserved. //
11+
// //
912
///////////////////////////////////////////////////////////////////////////////
1013

1114
#include "dxc/Support/WinIncludes.h"
@@ -1238,7 +1241,9 @@ int ReadDxcOpts(const OptTable *optionTable, unsigned flagsToInclude,
12381241
}
12391242

12401243
opts.SpirvOptions.targetEnv =
1241-
Args.getLastArgValue(OPT_fspv_target_env_EQ, "vulkan1.0");
1244+
Major > 6 || (Major == 6 && Minor > 7)
1245+
? Args.getLastArgValue(OPT_fspv_target_env_EQ, "vulkan1.3")
1246+
: Args.getLastArgValue(OPT_fspv_target_env_EQ, "vulkan1.0");
12421247

12431248
llvm::APInt maxId;
12441249

tools/clang/include/clang/AST/ASTContext.h

+19
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
// This file is distributed under the University of Illinois Open Source
66
// License. See LICENSE.TXT for details.
77
//
8+
// Modifications Copyright(C) 2025 Advanced Micro Devices, Inc.
9+
// All rights reserved.
10+
//
811
//===----------------------------------------------------------------------===//
912
///
1013
/// \file
@@ -295,6 +298,13 @@ class ASTContext : public RefCountedBase<ASTContext> {
295298
/// definitions of that entity.
296299
llvm::DenseMap<NamedDecl*, llvm::TinyPtrVector<Module*>> MergedDefModules;
297300

301+
/// \brief A mapping from attribute definitions to their parameter
302+
/// expressions.
303+
///
304+
/// This would not be necessary if Attrs contained the expressions in the
305+
/// first place rather than just bare integers etc.
306+
llvm::DenseMap<const Attr *, llvm::ArrayRef<const DeclRefExpr *>> AttrArgs;
307+
298308
public:
299309
/// \brief A type synonym for the TemplateOrInstantiation mapping.
300310
typedef llvm::PointerUnion<VarTemplateDecl *, MemberSpecializationInfo *>
@@ -704,6 +714,15 @@ class ASTContext : public RefCountedBase<ASTContext> {
704714
/// \brief Erase the attributes corresponding to the given declaration.
705715
void eraseDeclAttrs(const Decl *D);
706716

717+
void setAttrArgExprs(ArrayRef<const DeclRefExpr *> exprs, Attr *attr) {
718+
AttrArgs[attr] = exprs;
719+
}
720+
721+
ArrayRef<const DeclRefExpr *> getAttrArgExprs(const Attr *attr) {
722+
return AttrArgs.count(attr) ? AttrArgs[attr]
723+
: ArrayRef<const DeclRefExpr *>();
724+
}
725+
707726
/// \brief If this variable is an instantiated static data member of a
708727
/// class template specialization, returns the templated static data member
709728
/// from which it was instantiated.

tools/clang/include/clang/AST/HlslTypes.h

+5
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,10 @@ bool IsHLSLObjectWithImplicitMemberAccess(clang::QualType type);
488488
bool IsHLSLObjectWithImplicitROMemberAccess(clang::QualType type);
489489
bool IsHLSLRWNodeInputRecordType(clang::QualType type);
490490
bool IsHLSLRONodeInputRecordType(clang::QualType type);
491+
bool IsHLSLDispatchNodeInputRecordType(clang::QualType type);
492+
bool IsHLSLNodeRecordArrayType(clang::QualType type);
491493
bool IsHLSLNodeOutputType(clang::QualType type);
494+
bool IsHLSLEmptyNodeRecordType(clang::QualType type);
492495

493496
DXIL::NodeIOKind GetNodeIOType(clang::QualType type);
494497

@@ -499,6 +502,8 @@ bool IsHLSLCopyableAnnotatableRecord(clang::QualType QT);
499502
bool IsHLSLBuiltinRayAttributeStruct(clang::QualType QT);
500503
bool IsHLSLAggregateType(clang::QualType type);
501504
clang::QualType GetHLSLResourceResultType(clang::QualType type);
505+
clang::QualType GetHLSLNodeIOResultType(clang::ASTContext &astContext,
506+
clang::QualType type);
502507
unsigned GetHLSLResourceTemplateUInt(clang::QualType type);
503508
bool IsIncompleteHLSLResourceArrayType(clang::ASTContext &context,
504509
clang::QualType type);

tools/clang/include/clang/SPIRV/FeatureManager.h

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
//
55
// This file is distributed under the University of Illinois Open Source
66
// License. See LICENSE.TXT for details.
7+
//
8+
// Modifications Copyright(C) 2025 Advanced Micro Devices, Inc.
9+
// All rights reserved.
10+
//
711
//===----------------------------------------------------------------------===//
812
//
913
// This file defines a SPIR-V version and extension manager.
@@ -57,6 +61,7 @@ enum class Extension {
5761
KHR_ray_query,
5862
EXT_shader_image_int64,
5963
KHR_physical_storage_buffer,
64+
AMD_shader_enqueue,
6065
KHR_vulkan_memory_model,
6166
NV_compute_shader_derivatives,
6267
KHR_compute_shader_derivatives,

tools/clang/include/clang/SPIRV/SpirvBuilder.h

+80-5
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,25 @@ class SpirvBuilder {
437437
QualType resultType, NonSemanticDebugPrintfInstructions instId,
438438
llvm::ArrayRef<SpirvInstruction *> operands, SourceLocation);
439439

440+
SpirvInstruction *createIsNodePayloadValid(SpirvInstruction *payloadArray,
441+
SpirvInstruction *nodeIndex,
442+
SourceLocation);
443+
444+
SpirvInstruction *createNodePayloadArrayLength(SpirvInstruction *payloadArray,
445+
SourceLocation);
446+
447+
SpirvInstruction *createAllocateNodePayloads(QualType resultType,
448+
spv::Scope allocationScope,
449+
SpirvInstruction *shaderIndex,
450+
SpirvInstruction *recordCount,
451+
SourceLocation);
452+
453+
void createEnqueueOutputNodePayloads(SpirvInstruction *payload,
454+
SourceLocation);
455+
456+
SpirvInstruction *createFinishWritingNodePayload(SpirvInstruction *payload,
457+
SourceLocation);
458+
440459
/// \brief Creates an OpMemoryBarrier or OpControlBarrier instruction with the
441460
/// given flags. If execution scope (exec) is provided, an OpControlBarrier
442461
/// is created; otherwise an OpMemoryBarrier is created.
@@ -445,6 +464,13 @@ class SpirvBuilder {
445464
llvm::Optional<spv::Scope> exec, SourceLocation,
446465
SourceRange range = {});
447466

467+
/// \brief Creates an OpMemoryBarrier or OpControlBarrier instruction with the
468+
/// given flags. If execution scope (exec) has its low-order bit set, an
469+
/// OpControlBarrier is created; otherwise an OpMemoryBarrier is created.
470+
void createBarrier(SpirvInstruction *memoryScope,
471+
SpirvInstruction *memorySemantics,
472+
SpirvInstruction *execScope, SourceLocation);
473+
448474
/// \brief Creates an OpBitFieldInsert SPIR-V instruction for the given
449475
/// arguments.
450476
SpirvInstruction *createBitFieldInsert(QualType resultType,
@@ -609,14 +635,27 @@ class SpirvBuilder {
609635
const std::vector<llvm::StringRef> &name,
610636
llvm::StringRef content = "");
611637

638+
/// \brief Adds an execution mode to the module under construction if it does
639+
/// not already exist. Return the newly added instruction or the existing
640+
/// instruction, if one already exists.
641+
inline SpirvInstruction *addExecutionMode(SpirvFunction *entryPoint,
642+
spv::ExecutionMode em,
643+
SourceLocation);
644+
612645
/// \brief Adds an execution mode to the module under construction if it does
613646
/// not already exist. Return the newly added instruction or the existing
614647
/// instruction, if one already exists.
615648
inline SpirvInstruction *addExecutionMode(SpirvFunction *entryPoint,
616649
spv::ExecutionMode em,
617650
llvm::ArrayRef<uint32_t> params,
618-
SourceLocation,
619-
bool useIdParams = false);
651+
SourceLocation);
652+
653+
/// \brief Adds an execution mode to the module under construction if it does
654+
/// not already exist. Return the newly added instruction or the existing
655+
/// instruction, if one already exists.
656+
inline SpirvInstruction *
657+
addExecutionMode(SpirvFunction *entryPoint, spv::ExecutionMode em,
658+
llvm::ArrayRef<SpirvInstruction *> params, SourceLocation);
620659

621660
/// \brief Adds an OpModuleProcessed instruction to the module under
622661
/// construction.
@@ -759,6 +798,7 @@ class SpirvBuilder {
759798
llvm::ArrayRef<SpirvConstant *> constituents,
760799
bool specConst = false);
761800
SpirvConstant *getConstantNull(QualType);
801+
SpirvConstant *getConstantString(llvm::StringRef str, bool specConst = false);
762802
SpirvUndef *getUndef(QualType);
763803

764804
SpirvString *createString(llvm::StringRef str);
@@ -960,17 +1000,52 @@ SpirvBuilder::setDebugSource(uint32_t major, uint32_t minor,
9601000
return mainSource->getFile();
9611001
}
9621002

1003+
SpirvInstruction *SpirvBuilder::addExecutionMode(SpirvFunction *entryPoint,
1004+
spv::ExecutionMode em,
1005+
SourceLocation loc) {
1006+
SpirvExecutionMode *mode = nullptr;
1007+
SpirvExecutionMode *existingInstruction =
1008+
mod->findExecutionMode(entryPoint, em);
1009+
1010+
if (!existingInstruction) {
1011+
mode = new (context)
1012+
SpirvExecutionMode(loc, entryPoint, em, ArrayRef<uint32_t>());
1013+
mod->addExecutionMode(mode);
1014+
} else {
1015+
mode = existingInstruction;
1016+
}
1017+
1018+
return mode;
1019+
}
1020+
9631021
SpirvInstruction *
9641022
SpirvBuilder::addExecutionMode(SpirvFunction *entryPoint, spv::ExecutionMode em,
9651023
llvm::ArrayRef<uint32_t> params,
966-
SourceLocation loc, bool useIdParams) {
1024+
SourceLocation loc) {
9671025
SpirvExecutionMode *mode = nullptr;
9681026
SpirvExecutionMode *existingInstruction =
9691027
mod->findExecutionMode(entryPoint, em);
9701028

9711029
if (!existingInstruction) {
972-
mode = new (context)
973-
SpirvExecutionMode(loc, entryPoint, em, params, useIdParams);
1030+
mode = new (context) SpirvExecutionMode(loc, entryPoint, em, params);
1031+
mod->addExecutionMode(mode);
1032+
} else {
1033+
mode = existingInstruction;
1034+
}
1035+
1036+
return mode;
1037+
}
1038+
1039+
SpirvInstruction *
1040+
SpirvBuilder::addExecutionMode(SpirvFunction *entryPoint, spv::ExecutionMode em,
1041+
llvm::ArrayRef<SpirvInstruction *> params,
1042+
SourceLocation loc) {
1043+
SpirvExecutionMode *mode = nullptr;
1044+
SpirvExecutionMode *existingInstruction =
1045+
mod->findExecutionMode(entryPoint, em);
1046+
1047+
if (!existingInstruction) {
1048+
mode = new (context) SpirvExecutionMode(loc, entryPoint, em, params);
9741049
mod->addExecutionMode(mode);
9751050
} else {
9761051
mode = existingInstruction;

0 commit comments

Comments
 (0)