Skip to content

Commit f14637e

Browse files
committed
[ser] implement GetMinShaderModelAndMask for REORDER_SCOPE / legacy semantic flags (and diag msg)
1 parent 8328f9e commit f14637e

File tree

8 files changed

+61
-16
lines changed

8 files changed

+61
-16
lines changed

include/dxc/DXIL/DxilConstants.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,7 @@ enum class BarrierSemanticFlag : uint32_t {
18871887
GroupSync = 0x00000001, // GROUP_SYNC
18881888
GroupScope = 0x00000002, // GROUP_SCOPE
18891889
DeviceScope = 0x00000004, // DEVICE_SCOPE
1890-
ValidMask_1_8 = 0x00000007,
1890+
LegacyFlags = 0x00000007,
18911891
ReorderScope = 0x00000008, // REORDER_SCOPE
18921892
ValidMask = 0x0000000F,
18931893
GroupFlags = GroupSync | GroupScope,

include/dxc/DXIL/DxilOperations.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ class OP {
151151
static bool IsDxilOpBarrier(OpCode C);
152152
static bool BarrierRequiresGroup(const llvm::CallInst *CI);
153153
static bool BarrierRequiresNode(const llvm::CallInst *CI);
154+
static bool BarrierRequiresReorder(const llvm::CallInst *CI);
154155
static DXIL::BarrierMode TranslateToBarrierMode(const llvm::CallInst *CI);
155156
static void GetMinShaderModelAndMask(OpCode C, bool bWithTranslation,
156157
unsigned &major, unsigned &minor,

lib/DXIL/DxilOperations.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
///////////////////////////////////////////////////////////////////////////////
1111

1212
#include "dxc/DXIL/DxilOperations.h"
13+
#include "dxc/DXIL/DxilConstants.h"
1314
#include "dxc/DXIL/DxilInstructions.h"
1415
#include "dxc/DXIL/DxilModule.h"
1516
#include "dxc/Support/Global.h"
@@ -3006,6 +3007,23 @@ bool OP::BarrierRequiresNode(const llvm::CallInst *CI) {
30063007
}
30073008
}
30083009

3010+
bool OP::BarrierRequiresReorder(const llvm::CallInst *CI) {
3011+
OpCode opcode = OP::GetDxilOpFuncCallInst(CI);
3012+
switch (opcode) {
3013+
case OpCode::BarrierByMemoryType: {
3014+
DxilInst_BarrierByMemoryType barrier(const_cast<CallInst *>(CI));
3015+
if (isa<ConstantInt>(barrier.get_SemanticFlags())) {
3016+
unsigned semanticFlags = barrier.get_SemanticFlags_val();
3017+
return (semanticFlags &
3018+
static_cast<unsigned>(DXIL::BarrierSemanticFlag::ReorderScope)) !=
3019+
0U;
3020+
}
3021+
return false;
3022+
}
3023+
default:
3024+
return false;
3025+
}
3026+
}
30093027
DXIL::BarrierMode OP::TranslateToBarrierMode(const llvm::CallInst *CI) {
30103028
OpCode opcode = OP::GetDxilOpFuncCallInst(CI);
30113029
switch (opcode) {
@@ -3028,6 +3046,12 @@ DXIL::BarrierMode OP::TranslateToBarrierMode(const llvm::CallInst *CI) {
30283046
semanticFlags = barrier.get_SemanticFlags_val();
30293047
}
30303048

3049+
// Disallow SM6.9+ semantic flags.
3050+
if (semanticFlags &
3051+
~static_cast<unsigned>(DXIL::BarrierSemanticFlag::LegacyFlags)) {
3052+
return DXIL::BarrierMode::Invalid;
3053+
}
3054+
30313055
// Mask to legacy flags, if allowed.
30323056
memoryTypeFlags = MaskMemoryTypeFlagsIfAllowed(
30333057
memoryTypeFlags, (unsigned)DXIL::MemoryTypeFlag::LegacyFlags);
@@ -3448,10 +3472,17 @@ void OP::GetMinShaderModelAndMask(const llvm::CallInst *CI,
34483472
minor = 8;
34493473
}
34503474
}
3475+
if (BarrierRequiresReorder(CI)) {
3476+
major = 6;
3477+
minor = 9;
3478+
mask &= SFLAG(Library) | SFLAG(RayGeneration);
3479+
return;
3480+
}
34513481
if (BarrierRequiresNode(CI)) {
34523482
mask &= SFLAG(Library) | SFLAG(Node);
34533483
return;
3454-
} else if (BarrierRequiresGroup(CI)) {
3484+
}
3485+
if (BarrierRequiresGroup(CI)) {
34553486
mask &= SFLAG(Library) | SFLAG(Compute) | SFLAG(Amplification) |
34563487
SFLAG(Mesh) | SFLAG(Node);
34573488
return;

lib/DxilValidation/DxilValidation.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,8 +1626,7 @@ static unsigned getSemanticFlagValidMask(const ShaderModel *pSM) {
16261626
pSM->GetDxilVersion(DxilMajor, DxilMinor);
16271627
// DXIL version >= 1.9
16281628
if (hlsl::DXIL::CompareVersions(DxilMajor, DxilMinor, 1, 9) < 0)
1629-
return static_cast<unsigned>(
1630-
hlsl::DXIL::BarrierSemanticFlag::ValidMask_1_8);
1629+
return static_cast<unsigned>(hlsl::DXIL::BarrierSemanticFlag::LegacyFlags);
16311630
return static_cast<unsigned>(hlsl::DXIL::BarrierSemanticFlag::ValidMask);
16321631
}
16331632

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7974,6 +7974,9 @@ def err_hlsl_controlpoints_size: Error<
79747974
def err_hlsl_barrier_invalid_memory_flags: Error<
79757975
"invalid MemoryTypeFlags for Barrier operation; expected 0, ALL_MEMORY, or some combination of "
79767976
"UAV_MEMORY, GROUP_SHARED_MEMORY, NODE_INPUT_MEMORY, NODE_OUTPUT_MEMORY flags">;
7977+
def err_hlsl_barrier_invalid_semantic_flags_legacy: Error<
7978+
"invalid SemanticFlags for Barrier operation; expected 0 or some combination of "
7979+
"GROUP_SYNC, GROUP_SCOPE, DEVICE_SCOPE flags">;
79777980
def err_hlsl_barrier_invalid_semantic_flags: Error<
79787981
"invalid SemanticFlags for Barrier operation; expected 0 or some combination of "
79797982
"GROUP_SYNC, GROUP_SCOPE, DEVICE_SCOPE, REORDER_SCOPE flags">;

tools/clang/lib/Sema/SemaHLSL.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11561,7 +11561,8 @@ static bool CheckFinishedCrossGroupSharingCall(Sema &S, CXXMethodDecl *MD,
1156111561
return false;
1156211562
}
1156311563

11564-
static bool CheckBarrierCall(Sema &S, FunctionDecl *FD, CallExpr *CE) {
11564+
static bool CheckBarrierCall(Sema &S, FunctionDecl *FD, CallExpr *CE,
11565+
const hlsl::ShaderModel *SM) {
1156511566
DXASSERT(FD->getNumParams() == 2, "otherwise, unknown Barrier overload");
1156611567

1156711568
// Emit error when MemoryTypeFlags are known to be invalid.
@@ -11591,12 +11592,19 @@ static bool CheckBarrierCall(Sema &S, FunctionDecl *FD, CallExpr *CE) {
1159111592
llvm::APSInt SemanticFlagsVal;
1159211593
if (SemanticFlagsExpr->isIntegerConstantExpr(SemanticFlagsVal, S.Context)) {
1159311594
SemanticFlags = SemanticFlagsVal.getLimitedValue();
11594-
if ((uint32_t)SemanticFlags &
11595-
~(uint32_t)DXIL::BarrierSemanticFlag::ValidMask) {
11596-
S.Diags.Report(SemanticFlagsExpr->getExprLoc(),
11597-
diag::err_hlsl_barrier_invalid_semantic_flags)
11598-
<< (uint32_t)SemanticFlags
11599-
<< (uint32_t)DXIL::BarrierSemanticFlag::ValidMask;
11595+
uint32_t ValidMask = 0U;
11596+
unsigned DiagID = 0;
11597+
if (SM->IsSM69Plus()) {
11598+
DiagID = diag::err_hlsl_barrier_invalid_semantic_flags;
11599+
ValidMask =
11600+
static_cast<unsigned>(hlsl::DXIL::BarrierSemanticFlag::ValidMask);
11601+
} else {
11602+
DiagID = diag::err_hlsl_barrier_invalid_semantic_flags_legacy;
11603+
ValidMask =
11604+
static_cast<unsigned>(hlsl::DXIL::BarrierSemanticFlag::LegacyFlags);
11605+
}
11606+
if ((uint32_t)SemanticFlags & ~ValidMask) {
11607+
S.Diags.Report(SemanticFlagsExpr->getExprLoc(), DiagID);
1160011608
return true;
1160111609
}
1160211610
}
@@ -11637,14 +11645,17 @@ void Sema::CheckHLSLFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall,
1163711645
if (!IsBuiltinTable(IntrinsicAttr->getGroup()))
1163811646
return;
1163911647

11648+
const auto *SM =
11649+
hlsl::ShaderModel::GetByName(getLangOpts().HLSLProfile.c_str());
11650+
1164011651
hlsl::IntrinsicOp opCode = (hlsl::IntrinsicOp)IntrinsicAttr->getOpcode();
1164111652
switch (opCode) {
1164211653
case hlsl::IntrinsicOp::MOP_FinishedCrossGroupSharing:
1164311654
CheckFinishedCrossGroupSharingCall(*this, cast<CXXMethodDecl>(FDecl),
1164411655
TheCall->getLocStart());
1164511656
break;
1164611657
case hlsl::IntrinsicOp::IOP_Barrier:
11647-
CheckBarrierCall(*this, FDecl, TheCall);
11658+
CheckBarrierCall(*this, FDecl, TheCall, SM);
1164811659
break;
1164911660
case hlsl::IntrinsicOp::IOP_Vkreinterpret_pointer_cast:
1165011661
CheckVKBufferPointerCast(*this, FDecl, TheCall, false);

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

Lines changed: 3 additions & 3 deletions
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, 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}}
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}}
1919
Barrier(0, -1);
2020
}

tools/clang/test/SemaHLSL/hlsl/intrinsics/barrier/reorder_scope_sm68_unavailable.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
[Shader("compute")]
44
[numthreads(1, 1, 1)]
55
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}}
6+
// expected-error@+1{{invalid SemanticFlags for Barrier operation; expected 0 or some combination of GROUP_SYNC, GROUP_SCOPE, DEVICE_SCOPE flags}}
77
Barrier(0, REORDER_SCOPE);
88
}

0 commit comments

Comments
 (0)