Skip to content

Commit 7b41f68

Browse files
committed
[SER] REORDER_SCOPE Barrier semantic flag
- HLSL REORDER_SCOPE flag (available from SM6.9) - Make validator accept REORDER_SCOPE from DXIL 1.9
1 parent 206b775 commit 7b41f68

File tree

8 files changed

+75
-10
lines changed

8 files changed

+75
-10
lines changed

include/dxc/DXIL/DxilConstants.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,9 @@ enum class BarrierSemanticFlag : uint32_t {
18821882
GroupSync = 0x00000001, // GROUP_SYNC
18831883
GroupScope = 0x00000002, // GROUP_SCOPE
18841884
DeviceScope = 0x00000004, // DEVICE_SCOPE
1885-
ValidMask = 0x00000007,
1885+
ValidMask_1_8 = 0x00000007,
1886+
ReorderScope = 0x00000008, // REORDER_SCOPE
1887+
ValidMask = 0x0000000F,
18861888
GroupFlags = GroupSync | GroupScope,
18871889
};
18881890

lib/DxilValidation/DxilValidation.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,15 @@ std::string GetLaunchTypeStr(DXIL::NodeLaunchType LT) {
16211621
}
16221622
}
16231623

1624+
static unsigned getSemanticFlagValidMask(const ShaderModel *pSM) {
1625+
unsigned DxilMajor, DxilMinor;
1626+
pSM->GetDxilVersion(DxilMajor, DxilMinor);
1627+
// DXIL version >= 1.9
1628+
if (DxilMajor >= 2 || DxilMinor >= 9)
1629+
return (unsigned)hlsl::DXIL::BarrierSemanticFlag::ValidMask;
1630+
return (unsigned)hlsl::DXIL::BarrierSemanticFlag::ValidMask_1_8;
1631+
}
1632+
16241633
static void ValidateDxilOperationCallInProfile(CallInst *CI,
16251634
DXIL::OpCode opcode,
16261635
const ShaderModel *pSM,
@@ -1829,8 +1838,8 @@ static void ValidateDxilOperationCallInProfile(CallInst *CI,
18291838
(unsigned)hlsl::DXIL::MemoryTypeFlag::ValidMask,
18301839
"memory type", "BarrierByMemoryType");
18311840
ValidateBarrierFlagArg(ValCtx, CI, DI.get_SemanticFlags(),
1832-
(unsigned)hlsl::DXIL::BarrierSemanticFlag::ValidMask,
1833-
"semantic", "BarrierByMemoryType");
1841+
getSemanticFlagValidMask(pSM), "semantic",
1842+
"BarrierByMemoryType");
18341843
if (!isLibFunc && shaderKind != DXIL::ShaderKind::Node &&
18351844
OP::BarrierRequiresNode(CI)) {
18361845
ValCtx.EmitInstrError(CI, ValidationRule::InstrBarrierRequiresNode);
@@ -1846,8 +1855,7 @@ static void ValidateDxilOperationCallInProfile(CallInst *CI,
18461855
: "barrierByMemoryHandle";
18471856
DxilInst_BarrierByMemoryHandle DIMH(CI);
18481857
ValidateBarrierFlagArg(ValCtx, CI, DIMH.get_SemanticFlags(),
1849-
(unsigned)hlsl::DXIL::BarrierSemanticFlag::ValidMask,
1850-
"semantic", opName);
1858+
getSemanticFlagValidMask(pSM), "semantic", opName);
18511859
if (!isLibFunc && shaderKind != DXIL::ShaderKind::Node &&
18521860
OP::BarrierRequiresNode(CI)) {
18531861
ValCtx.EmitInstrError(CI, ValidationRule::InstrBarrierRequiresNode);

tools/clang/include/clang/Basic/DiagnosticSemaKinds.td

+1-1
Original file line numberDiff line numberDiff line change
@@ -7973,7 +7973,7 @@ def err_hlsl_barrier_invalid_memory_flags: Error<
79737973
"UAV_MEMORY, GROUP_SHARED_MEMORY, NODE_INPUT_MEMORY, NODE_OUTPUT_MEMORY flags">;
79747974
def err_hlsl_barrier_invalid_semantic_flags: Error<
79757975
"invalid SemanticFlags for Barrier operation; expected 0 or some combination of "
7976-
"GROUP_SYNC, GROUP_SCOPE, DEVICE_SCOPE flags">;
7976+
"GROUP_SYNC, GROUP_SCOPE, DEVICE_SCOPE, REORDER_SCOPE flags">;
79777977
def warn_hlsl_barrier_group_memory_requires_group: Warning<
79787978
"GROUP_SHARED_MEMORY specified for Barrier operation when context has no visible group">,
79797979
InGroup<HLSLBarrier>, DefaultError;

tools/clang/lib/AST/ASTContextHLSL.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,8 @@ void hlsl::AddSamplerFeedbackConstants(ASTContext &context) {
715715

716716
/// <summary> Adds all enums for Barrier intrinsic</summary>
717717
void hlsl::AddBarrierConstants(ASTContext &context) {
718+
VersionTuple VT69 = VersionTuple(6, 9);
719+
718720
AddTypedefPseudoEnum(
719721
context, "MEMORY_TYPE_FLAG",
720722
{{"UAV_MEMORY", (unsigned)DXIL::MemoryTypeFlag::UavMemory},
@@ -727,7 +729,9 @@ void hlsl::AddBarrierConstants(ASTContext &context) {
727729
context, "BARRIER_SEMANTIC_FLAG",
728730
{{"GROUP_SYNC", (unsigned)DXIL::BarrierSemanticFlag::GroupSync},
729731
{"GROUP_SCOPE", (unsigned)DXIL::BarrierSemanticFlag::GroupScope},
730-
{"DEVICE_SCOPE", (unsigned)DXIL::BarrierSemanticFlag::DeviceScope}});
732+
{"DEVICE_SCOPE", (unsigned)DXIL::BarrierSemanticFlag::DeviceScope},
733+
{"REORDER_SCOPE", (unsigned)DXIL::BarrierSemanticFlag::ReorderScope,
734+
ConstructAvailabilityAttribute(context, VT69)}});
731735
}
732736

733737
static Expr *IntConstantAsBoolExpr(clang::Sema &sema, uint64_t value) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
; RUN: %dxv %s | FileCheck %s
2+
3+
; CHECK: Validation succeeded.
4+
5+
target datalayout = "e-m:e-p:32:32-i1:32-i8:32-i16:32-i32:32-i64:64-f16:32-f32:32-f64:64-n8:16:32:64"
6+
target triple = "dxil-ms-dx"
7+
8+
; Function Attrs: nounwind
9+
define void @"\01?main@@YAXXZ"() #0 {
10+
call void @dx.op.barrierByMemoryType(i32 244, i32 1, i32 8) ; BarrierByMemoryType(MemoryTypeFlags,SemanticFlags)
11+
ret void
12+
}
13+
14+
; Function Attrs: noduplicate nounwind
15+
declare void @dx.op.barrierByMemoryType(i32, i32, i32) #1
16+
17+
attributes #0 = { nounwind }
18+
attributes #1 = { noduplicate nounwind }
19+
20+
!dx.version = !{!0}
21+
!dx.valver = !{!0}
22+
!dx.shaderModel = !{!1}
23+
!dx.typeAnnotations = !{!2}
24+
!dx.entryPoints = !{!6, !7}
25+
26+
!0 = !{i32 1, i32 9}
27+
!1 = !{!"lib", i32 6, i32 9}
28+
!2 = !{i32 1, void ()* @"\01?main@@YAXXZ", !3}
29+
!3 = !{!4}
30+
!4 = !{i32 1, !5, !5}
31+
!5 = !{}
32+
!6 = !{null, !"", null, null, null}
33+
!7 = !{void ()* @"\01?main@@YAXXZ", !"\01?main@@YAXXZ", null, null, !8}
34+
!8 = !{i32 8, i32 7, i32 5, !9}
35+
!9 = !{i32 0}
36+

tools/clang/test/SemaHLSL/hlsl/intrinsics/barrier/barrier-cs-local-errors.hlsl

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ void main() {
1313
Barrier(16, 0);
1414
// expected-error@+1{{invalid MemoryTypeFlags for Barrier operation; expected 0, ALL_MEMORY, or some combination of UAV_MEMORY, GROUP_SHARED_MEMORY, NODE_INPUT_MEMORY, NODE_OUTPUT_MEMORY flags}}
1515
Barrier(-1, 0);
16-
// expected-error@+1{{invalid SemanticFlags for Barrier operation; expected 0 or some combination of GROUP_SYNC, GROUP_SCOPE, DEVICE_SCOPE flags}}
17-
Barrier(0, 8);
18-
// expected-error@+1{{invalid SemanticFlags for Barrier operation; expected 0 or some combination of GROUP_SYNC, GROUP_SCOPE, DEVICE_SCOPE flags}}
16+
// expected-error@+1{{invalid SemanticFlags for Barrier operation; expected 0 or some combination of GROUP_SYNC, GROUP_SCOPE, DEVICE_SCOPE, REORDER_SCOPE flags}}
17+
Barrier(0, 16);
18+
// expected-error@+1{{invalid SemanticFlags for Barrier operation; expected 0 or some combination of GROUP_SYNC, GROUP_SCOPE, DEVICE_SCOPE, REORDER_SCOPE flags}}
1919
Barrier(0, -1);
2020
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %dxc -Tlib_6_8 -verify %s
2+
3+
[Shader("compute")]
4+
[numthreads(1, 1, 1)]
5+
void main() {
6+
// expected-warning@+1{{potential misuse of built-in constant 'REORDER_SCOPE' in shader model lib_6_8; introduced in shader model 6.9}}
7+
Barrier(0, REORDER_SCOPE);
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %dxc -T lib_6_9 -E main %s | FileCheck %s
2+
3+
[shader("raygeneration")]
4+
void main() {
5+
// CHECK: call void @dx.op.barrierByMemoryType(i32 244, i32 1, i32 8)
6+
Barrier(UAV_MEMORY, REORDER_SCOPE);
7+
}

0 commit comments

Comments
 (0)