Skip to content

Commit 3409368

Browse files
committed
Disallow CreateHandle in SM66+ and library targets (#3629)
(cherry picked from commit 634cd49)
1 parent 7a1c0bd commit 3409368

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

lib/HLSL/DxilValidation.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2567,6 +2567,17 @@ static void ValidateDxilOperationCallInProfile(CallInst *CI,
25672567
ValCtx.EmitInstrFormatError(CI, ValidationRule::SmOpcodeInInvalidFunction,
25682568
{"64-bit atomic operations", "Shader Model 6.6+"});
25692569
} break;
2570+
case DXIL::OpCode::CreateHandle:
2571+
if (ValCtx.isLibProfile) {
2572+
ValCtx.EmitInstrFormatError(CI, ValidationRule::SmOpcodeInInvalidFunction,
2573+
{"CreateHandle", "non-library targets"});
2574+
}
2575+
// CreateHandle should not be used in SM 6.6 and above:
2576+
if (DXIL::CompareVersions(ValCtx.m_DxilMajor, ValCtx.m_DxilMinor, 1, 5) > 0) {
2577+
ValCtx.EmitInstrFormatError(CI, ValidationRule::SmOpcodeInInvalidFunction,
2578+
{"CreateHandle", "Shader model 6.5 and below"});
2579+
}
2580+
break;
25702581
default:
25712582
// TODO: make sure every opcode is checked.
25722583
// Skip opcodes don't need special check.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// RUN: %dxc -E main -T ps_6_0 %s
22

3+
Buffer<float4> g_buf;
4+
5+
[shader("pixel")]
36
float4 main() : SV_Target {
4-
return float4(1, 0, 0, 1);
7+
return g_buf.Load(0);
58
}

tools/clang/unittests/HLSL/ValidationTest.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ class ValidationTest : public ::testing::Test {
298298
TEST_METHOD(ValidatePrintfNotAllowed)
299299

300300
TEST_METHOD(ValidateVersionNotAllowed)
301+
TEST_METHOD(CreateHandleNotAllowedSM66)
301302

302303
dxc::DxcDllSupport m_dllSupport;
303304
VersionSupportInfo m_ver;
@@ -3858,3 +3859,18 @@ TEST_F(ValidationTest, ValidateVersionNotAllowed) {
38583859
("= !{i32 1, i32 " + higherDxilMinor + "}").c_str(),
38593860
("error: Dxil version in metadata (1." + higherDxilMinor + ") is not supported; maximum: (1." + maxDxilMinor + ")").c_str());
38603861
}
3862+
3863+
TEST_F(ValidationTest, CreateHandleNotAllowedSM66) {
3864+
if (m_ver.SkipDxilVersion(1, 6)) return;
3865+
RewriteAssemblyCheckMsg(L"..\\CodeGenHLSL\\basic.hlsl", "ps_6_5",
3866+
{"= !{i32 1, i32 5}", "= !{!\"ps\", i32 6, i32 5}"},
3867+
{"= !{i32 1, i32 6}", "= !{!\"ps\", i32 6, i32 6}"},
3868+
"opcode 'CreateHandle' should only be used in 'Shader model 6.5 and below'");
3869+
RewriteAssemblyCheckMsg(L"..\\CodeGenHLSL\\basic.hlsl", "lib_6_5",
3870+
{"call %dx.types.Handle @\"dx.op.createHandleForLib.class.Buffer<vector<float, 4> >\"\\(i32 160, %\"class.Buffer<vector<float, 4> >\" %[0-9]+\\)",
3871+
"declare %dx.types.Handle @\"dx.op.createHandleForLib.class.Buffer<vector<float, 4> >\"\\(i32, %\"class.Buffer<vector<float, 4> >\"\\) #1"},
3872+
{"call %dx.types.Handle @dx.op.createHandle(i32 57, i8 0, i32 0, i32 0, i1 false)",
3873+
"declare %dx.types.Handle @dx.op.createHandle(i32, i8, i32, i32, i1) #1"},
3874+
"opcode 'CreateHandle' should only be used in 'non-library targets'",
3875+
true);
3876+
}

0 commit comments

Comments
 (0)