Skip to content

Commit ec5324d

Browse files
authored
NFC: Update HLSL_INTRINSIC struct for Flags and MinShaderModel fields (#7199)
HLSL_INTRINSIC will need to be updated for SM 6.9, specifically: - to add a new flag - to encode minimum shader model version for an availability attribute Changing this structure is a breaking change to the internal intrinsic table protocol, which is used for the extension mechanism. This change separates out the breaking change with no functional changes for simpler review and testing. For the new flag, this change switches to using a UINT Flags field to make flags extensible without breaking the table format. For the version, a UINT MinShaderModel will be the encoded version format used elsewhere: (Major << 4) | (Minor & 0xF) Commented code for using the MinShaderModel is provided for when a subsequent change will implement the availability attribute checks.
1 parent 3d69171 commit ec5324d

File tree

5 files changed

+106
-44
lines changed

5 files changed

+106
-44
lines changed

include/dxc/dxcapi.internal.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,16 @@ struct HLSL_INTRINSIC_ARGUMENT {
160160
// matching input constraints.
161161
};
162162

163+
// HLSL_INTRINSIC flags
164+
static const UINT INTRIN_FLAG_READ_ONLY = 1U << 0;
165+
static const UINT INTRIN_FLAG_READ_NONE = 1U << 1;
166+
static const UINT INTRIN_FLAG_IS_WAVE = 1U << 2;
167+
163168
struct HLSL_INTRINSIC {
164169
UINT Op; // Intrinsic Op ID
165-
BOOL bReadOnly; // Only read memory
166-
BOOL bReadNone; // Not read memory
167-
BOOL bIsWave; // Is a wave-sensitive op
170+
UINT Flags; // INTRIN_FLAG_* flags
171+
UINT MinShaderModel; // Encoded minimum shader model, 0 = no minimum
172+
// (Major << 4) + (Minor & 0xf)
168173
INT iOverloadParamIndex; // Parameter decide the overload type, -1 means ret
169174
// type
170175
UINT uNumArgs; // Count of arguments in pArgs.

tools/clang/lib/Sema/SemaHLSL.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,12 +1810,21 @@ static void AddHLSLIntrinsicAttr(FunctionDecl *FD, ASTContext &context,
18101810
}
18111811
FD->addAttr(
18121812
HLSLIntrinsicAttr::CreateImplicit(context, tableName, lowering, opcode));
1813-
if (pIntrinsic->bReadNone)
1813+
if (pIntrinsic->Flags & INTRIN_FLAG_READ_NONE)
18141814
FD->addAttr(ConstAttr::CreateImplicit(context));
1815-
if (pIntrinsic->bReadOnly)
1815+
if (pIntrinsic->Flags & INTRIN_FLAG_READ_ONLY)
18161816
FD->addAttr(PureAttr::CreateImplicit(context));
1817-
if (pIntrinsic->bIsWave)
1817+
if (pIntrinsic->Flags & INTRIN_FLAG_IS_WAVE)
18181818
FD->addAttr(HLSLWaveSensitiveAttr::CreateImplicit(context));
1819+
// TBD: Add availability attribute if MinShaderModel is set.
1820+
// if (pIntrinsic->MinShaderModel) {
1821+
// unsigned Major = pIntrinsic->MinShaderModel >> 4;
1822+
// unsigned Minor = pIntrinsic->MinShaderModel & 0xF;
1823+
// FD->addAttr(AvailabilityAttr::CreateImplicit(
1824+
// context, &context.Idents.get(""), clang::VersionTuple(Major, Minor),
1825+
// clang::VersionTuple(), clang::VersionTuple(), false,
1826+
// "HLSL Intrinsic availability limited by shader model."));
1827+
//}
18191828
}
18201829

18211830
static FunctionDecl *

tools/clang/unittests/HLSL/ExtensionTest.cpp

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -204,79 +204,86 @@ Intrinsic Intrinsics[] = {
204204
{L"test_fn",
205205
DEFAULT_NAME,
206206
"r",
207-
{1, false, true, false, -1, countof(TestFnArgs), TestFnArgs}},
207+
{1, INTRIN_FLAG_READ_NONE, 0, -1, countof(TestFnArgs), TestFnArgs}},
208208
{L"test_proc",
209209
DEFAULT_NAME,
210210
"r",
211-
{2, false, false, false, -1, countof(TestProcArgs), TestProcArgs}},
211+
{2, 0, 0, -1, countof(TestProcArgs), TestProcArgs}},
212212
{L"test_poly",
213213
"test_poly.$o",
214214
"r",
215-
{3, false, true, false, -1, countof(TestFnCustomArgs), TestFnCustomArgs}},
215+
{3, INTRIN_FLAG_READ_NONE, 0, -1, countof(TestFnCustomArgs),
216+
TestFnCustomArgs}},
216217
{L"test_int",
217218
"test_int",
218219
"r",
219-
{4, false, true, false, -1, countof(TestFnIntArgs), TestFnIntArgs}},
220+
{4, INTRIN_FLAG_READ_NONE, 0, -1, countof(TestFnIntArgs), TestFnIntArgs}},
220221
{L"test_nolower",
221222
"test_nolower.$o",
222223
"n",
223-
{5, false, true, false, -1, countof(TestFnNoLowerArgs),
224+
{5, INTRIN_FLAG_READ_NONE, 0, -1, countof(TestFnNoLowerArgs),
224225
TestFnNoLowerArgs}},
225226
{L"test_pack_0",
226227
"test_pack_0.$o",
227228
"p",
228-
{6, false, false, false, -1, countof(TestFnPack0), TestFnPack0}},
229+
{6, 0, 0, -1, countof(TestFnPack0), TestFnPack0}},
229230
{L"test_pack_1",
230231
"test_pack_1.$o",
231232
"p",
232-
{7, false, true, false, -1, countof(TestFnPack1), TestFnPack1}},
233+
{7, INTRIN_FLAG_READ_NONE, 0, -1, countof(TestFnPack1), TestFnPack1}},
233234
{L"test_pack_2",
234235
"test_pack_2.$o",
235236
"p",
236-
{8, false, true, false, -1, countof(TestFnPack2), TestFnPack2}},
237+
{8, INTRIN_FLAG_READ_NONE, 0, -1, countof(TestFnPack2), TestFnPack2}},
237238
{L"test_pack_3",
238239
"test_pack_3.$o",
239240
"p",
240-
{9, false, true, false, -1, countof(TestFnPack3), TestFnPack3}},
241+
{9, INTRIN_FLAG_READ_NONE, 0, -1, countof(TestFnPack3), TestFnPack3}},
241242
{L"test_pack_4",
242243
"test_pack_4.$o",
243244
"p",
244-
{10, false, false, false, -1, countof(TestFnPack4), TestFnPack4}},
245+
{10, 0, 0, -1, countof(TestFnPack4), TestFnPack4}},
245246
{L"test_rand",
246247
"test_rand",
247248
"r",
248-
{11, false, false, false, -1, countof(TestRand), TestRand}},
249+
{11, 0, 0, -1, countof(TestRand), TestRand}},
249250
{L"test_isinf",
250251
"test_isinf",
251252
"d",
252-
{13, true, true, false, -1, countof(TestIsInf), TestIsInf}},
253+
{13, INTRIN_FLAG_READ_ONLY | INTRIN_FLAG_READ_NONE, 0, -1,
254+
countof(TestIsInf), TestIsInf}},
253255
{L"test_ibfe",
254256
"test_ibfe",
255257
"d",
256-
{14, true, true, false, -1, countof(TestIBFE), TestIBFE}},
258+
{14, INTRIN_FLAG_READ_ONLY | INTRIN_FLAG_READ_NONE, 0, -1,
259+
countof(TestIBFE), TestIBFE}},
257260
// Make this intrinsic have the same opcode as an hlsl intrinsic with an
258261
// unsigned counterpart for testing purposes.
259262
{L"test_unsigned",
260263
"test_unsigned",
261264
"n",
262-
{static_cast<unsigned>(hlsl::IntrinsicOp::IOP_min), false, true, false, -1,
263-
countof(TestUnsigned), TestUnsigned}},
265+
{static_cast<unsigned>(hlsl::IntrinsicOp::IOP_min), INTRIN_FLAG_READ_NONE,
266+
0, -1, countof(TestUnsigned), TestUnsigned}},
264267
{L"wave_proc",
265268
DEFAULT_NAME,
266269
"r",
267-
{16, false, true, true, -1, countof(WaveProcArgs), WaveProcArgs}},
270+
{16, INTRIN_FLAG_READ_NONE | INTRIN_FLAG_IS_WAVE, 0, -1,
271+
countof(WaveProcArgs), WaveProcArgs}},
268272
{L"test_o_1",
269273
"test_o_1.$o:1",
270274
"r",
271-
{18, false, true, true, -1, countof(TestOverloadArgs), TestOverloadArgs}},
275+
{18, INTRIN_FLAG_READ_NONE | INTRIN_FLAG_IS_WAVE, 0, -1,
276+
countof(TestOverloadArgs), TestOverloadArgs}},
272277
{L"test_o_2",
273278
"test_o_2.$o:2",
274279
"r",
275-
{19, false, true, true, -1, countof(TestOverloadArgs), TestOverloadArgs}},
280+
{19, INTRIN_FLAG_READ_NONE | INTRIN_FLAG_IS_WAVE, 0, -1,
281+
countof(TestOverloadArgs), TestOverloadArgs}},
276282
{L"test_o_3",
277283
"test_o_3.$o:3",
278284
"r",
279-
{20, false, true, true, -1, countof(TestOverloadArgs), TestOverloadArgs}},
285+
{20, INTRIN_FLAG_READ_NONE | INTRIN_FLAG_IS_WAVE, 0, -1,
286+
countof(TestOverloadArgs), TestOverloadArgs}},
280287
// custom lowering with both optional arguments and vector exploding.
281288
// Arg 0 = Opcode
282289
// Arg 1 = Pass as is
@@ -286,24 +293,26 @@ Intrinsic Intrinsics[] = {
286293
{L"CustomLoadOp",
287294
"CustomLoadOp",
288295
"c:{\"default\" : \"0,1,2:?i1,3.0:?i32,3.1:?i32\"}",
289-
{21, true, false, false, -1, countof(TestCustomLoadOp), TestCustomLoadOp}},
296+
{21, INTRIN_FLAG_READ_ONLY, 0, -1, countof(TestCustomLoadOp),
297+
TestCustomLoadOp}},
290298
{L"CustomLoadOp",
291299
"CustomLoadOp",
292300
"c:{\"default\" : \"0,1,2:?i1,3.0:?i32,3.1:?i32\"}",
293-
{21, true, false, false, -1, countof(TestCustomLoadOpBool),
301+
{21, INTRIN_FLAG_READ_ONLY, 0, -1, countof(TestCustomLoadOpBool),
294302
TestCustomLoadOpBool}},
295303
{L"CustomLoadOp",
296304
"CustomLoadOp",
297305
"c:{\"default\" : \"0,1,2:?i1,3.0:?i32,3.1:?i32\"}",
298-
{21, true, false, false, -1, countof(TestCustomLoadOpSubscript),
306+
{21, INTRIN_FLAG_READ_ONLY, 0, -1, countof(TestCustomLoadOpSubscript),
299307
TestCustomLoadOpSubscript}},
300308
};
301309

302310
Intrinsic BufferIntrinsics[] = {
303311
{L"MyBufferOp",
304312
"MyBufferOp",
305313
"m",
306-
{12, false, true, false, -1, countof(TestMyBufferOp), TestMyBufferOp}},
314+
{12, INTRIN_FLAG_READ_NONE, 0, -1, countof(TestMyBufferOp),
315+
TestMyBufferOp}},
307316
};
308317

309318
// Test adding a method to an object that normally has no methods (SamplerState
@@ -312,7 +321,8 @@ Intrinsic SamplerIntrinsics[] = {
312321
{L"MySamplerOp",
313322
"MySamplerOp",
314323
"m",
315-
{15, false, true, false, -1, countof(TestMySamplerOp), TestMySamplerOp}},
324+
{15, INTRIN_FLAG_READ_NONE, 0, -1, countof(TestMySamplerOp),
325+
TestMySamplerOp}},
316326
};
317327

318328
// Define a lowering string to target a common dxil extension operation defined
@@ -345,20 +355,20 @@ Intrinsic Texture1DIntrinsics[] = {
345355
{L"MyTextureOp",
346356
"MyTextureOp",
347357
MyTextureOp_LoweringInfo,
348-
{17, false, true, false, -1, countof(TestMyTexture1DOp_0),
358+
{17, INTRIN_FLAG_READ_NONE, 0, -1, countof(TestMyTexture1DOp_0),
349359
TestMyTexture1DOp_0}},
350360
{L"MyTextureOp",
351361
"MyTextureOp",
352362
MyTextureOp_LoweringInfo,
353-
{17, false, true, false, -1, countof(TestMyTexture1DOp_1),
363+
{17, INTRIN_FLAG_READ_NONE, 0, -1, countof(TestMyTexture1DOp_1),
354364
TestMyTexture1DOp_1}},
355365
};
356366

357367
Intrinsic Texture2DIntrinsics[] = {
358368
{L"MyTextureOp",
359369
"MyTextureOp",
360370
MyTextureOp_LoweringInfo,
361-
{17, false, true, false, -1, countof(TestMyTexture2DOp),
371+
{17, INTRIN_FLAG_READ_NONE, 0, -1, countof(TestMyTexture2DOp),
362372
TestMyTexture2DOp}},
363373
};
364374

@@ -1497,8 +1507,8 @@ TEST_F(ExtensionTest, EvalAttributeCollision) {
14971507
Intrinsic Intrinsic = {L"collide_proc",
14981508
"collide_proc",
14991509
"r",
1500-
{static_cast<unsigned>(op), true, false, false, -1,
1501-
countof(Args), Args}};
1510+
{static_cast<unsigned>(op), INTRIN_FLAG_READ_ONLY, 0,
1511+
-1, countof(Args), Args}};
15021512
Compiler c(m_dllSupport);
15031513
c.RegisterIntrinsicTable(new TestIntrinsicTable(&Intrinsic, 1));
15041514
c.Compile(R"(
@@ -1532,10 +1542,8 @@ TEST_F(ExtensionTest, NoUnwind) {
15321542
IA_C},
15331543
{"value", AR_QUAL_IN, 1, LITEMPLATE_ANY, 1, LICOMPTYPE_NUMERIC, 1, IA_C}};
15341544

1535-
Intrinsic Intrinsic = {L"test_proc",
1536-
"test_proc",
1537-
"r",
1538-
{1, false, false, false, -1, countof(Args), Args}};
1545+
Intrinsic Intrinsic = {
1546+
L"test_proc", "test_proc", "r", {1, 0, 0, -1, countof(Args), Args}};
15391547
Compiler c(m_dllSupport);
15401548
c.RegisterIntrinsicTable(new TestIntrinsicTable(&Intrinsic, 1));
15411549
c.Compile(R"(
@@ -1572,7 +1580,8 @@ TEST_F(ExtensionTest, DCE) {
15721580
Intrinsic Intrinsic = {L"test_proc",
15731581
"test_proc",
15741582
"r",
1575-
{1, true, true, false, -1, countof(Args), Args}};
1583+
{1, INTRIN_FLAG_READ_ONLY | INTRIN_FLAG_READ_NONE, 0,
1584+
-1, countof(Args), Args}};
15761585
Compiler c(m_dllSupport);
15771586
c.RegisterIntrinsicTable(new TestIntrinsicTable(&Intrinsic, 1));
15781587
c.Compile(R"(

utils/hct/hctdb.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8208,6 +8208,7 @@ def __init__(
82088208
unsigned_op,
82098209
overload_idx,
82108210
hidden,
8211+
min_shader_model,
82118212
):
82128213
self.name = name # Function name
82138214
self.idx = idx # Unique number within namespace
@@ -8235,6 +8236,12 @@ def __init__(
82358236
overload_idx # Parameter determines the overload type, -1 means ret type
82368237
)
82378238
self.hidden = hidden # Internal high-level op, not exposed to HLSL
8239+
# Encoded minimum shader model for this intrinsic
8240+
self.min_shader_model = 0
8241+
if min_shader_model:
8242+
self.min_shader_model = (min_shader_model[0] << 4) | (
8243+
min_shader_model[1] & 0x0F
8244+
)
82388245
self.key = (
82398246
("%3d" % ns_idx)
82408247
+ "!"
@@ -8612,6 +8619,7 @@ def process_attr(attr):
86128619
-1
86138620
) # Parameter determines the overload type, -1 means ret type.
86148621
hidden = False
8622+
min_shader_model = (0, 0)
86158623
for a in attrs:
86168624
if a == "":
86178625
continue
@@ -8644,6 +8652,24 @@ def process_attr(attr):
86448652
if d == "overload":
86458653
overload_param_index = int(v)
86468654
continue
8655+
if d == "min_sm":
8656+
# min_sm is a string like "6.0" or "6.5"
8657+
# Convert to a tuple of integers (major, minor)
8658+
try:
8659+
major_minor = v.split(".")
8660+
if len(major_minor) != 2:
8661+
raise ValueError
8662+
major, minor = major_minor
8663+
major = int(major)
8664+
minor = int(minor)
8665+
# minor of 15 has special meaning, and larger values
8666+
# cannot be encoded in the version DWORD.
8667+
if major < 0 or minor < 0 or minor > 14:
8668+
raise ValueError
8669+
min_shader_model = (major, minor)
8670+
except ValueError:
8671+
assert False, "invalid min_sm: %s" % (v)
8672+
continue
86478673
assert False, "invalid attr %s" % (a)
86488674

86498675
return (
@@ -8654,6 +8680,7 @@ def process_attr(attr):
86548680
unsigned_op,
86558681
overload_param_index,
86568682
hidden,
8683+
min_shader_model,
86578684
)
86588685

86598686
current_namespace = None
@@ -8701,6 +8728,7 @@ def process_attr(attr):
87018728
unsigned_op,
87028729
overload_param_index,
87038730
hidden,
8731+
min_shader_model,
87048732
) = process_attr(attr)
87058733
# Add an entry for this intrinsic.
87068734
if bracket_cleanup_re.search(opts):
@@ -8739,6 +8767,7 @@ def process_attr(attr):
87398767
unsigned_op,
87408768
overload_param_index,
87418769
hidden,
8770+
min_shader_model,
87428771
)
87438772
)
87448773
num_entries += 1

utils/hct/hctdb_instrhelp.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -989,13 +989,23 @@ def get_hlsl_intrinsics():
989989
result += "#ifdef ENABLE_SPIRV_CODEGEN\n\n"
990990
# SPIRV Change Ends
991991
arg_idx = 0
992-
ns_table += " {(UINT)%s::%s_%s, %s, %s, %s, %d, %d, g_%s_Args%s},\n" % (
992+
flags = []
993+
if i.readonly:
994+
flags.append("INTRIN_FLAG_READ_ONLY")
995+
if i.readnone:
996+
flags.append("INTRIN_FLAG_READ_NONE")
997+
if i.wave:
998+
flags.append("INTRIN_FLAG_IS_WAVE")
999+
if flags:
1000+
flags = " | ".join(flags)
1001+
else:
1002+
flags = "0"
1003+
ns_table += " {(UINT)%s::%s_%s, %s, 0x%x, %d, %d, g_%s_Args%s},\n" % (
9931004
opcode_namespace,
9941005
id_prefix,
9951006
i.name,
996-
str(i.readonly).lower(),
997-
str(i.readnone).lower(),
998-
str(i.wave).lower(),
1007+
flags,
1008+
i.min_shader_model,
9991009
i.overload_param_index,
10001010
len(i.params),
10011011
last_ns,

0 commit comments

Comments
 (0)