Skip to content

Commit 10a4f01

Browse files
authored
Adding array operator long vector tests to HLK (#7887)
This patch is adding array operator long vector test to HLK. There are 3 scenarios that were identified when doing those tests: - **Dynamic Element Access**: the generated dxil uses a GEP instruction to calculate the correct address to access. - **Static element access**: the code uses `extracelement` and `insertelement`. Closes: #7618
1 parent 82af40d commit 10a4f01

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed

tools/clang/unittests/HLSLExec/LongVectorOps.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ OP(Bitwise, FirstBitLow, 1, "firstbitlow", "", "", "LongVectorOp", Bitwise, Defa
6363
OP_DEFAULT_DEFINES(Unary, Initialize, 1, "TestInitialize", "",
6464
" -DFUNC_INITIALIZE=1")
6565

66+
OP_DEFAULT_DEFINES(ArrayOperator, ArrayOperator_StaticAccess, 1, "TestArrayOperatorStaticAccess", "",
67+
" -DTEST_ARRAY_OPERATOR")
68+
69+
OP(ArrayOperator, ArrayOperator_DynamicAccess, 2, "TestArrayOperatorDynamicAccess", "",
70+
" -DTEST_ARRAY_OPERATOR=1 -DDYNAMIC_ACCESS=1", "LongVectorOP", Default1, Zero, Default3)
71+
6672
#define OP_CAST_DEFAULT(GROUP, SYMBOL) \
6773
OP_DEFAULT_DEFINES(GROUP, SYMBOL, 1, "TestCast", "", "-DFUNC_TEST_CAST=1")
6874
#define OP_CAST(GROUP, SYMBOL, INPUT_SET_1) \

tools/clang/unittests/HLSLExec/LongVectorTestData.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ BEGIN_INPUT_SETS(uint16_t)
324324
INPUT_SET(InputSet::Default1, 1, 699, 3, 1023, 5, 6, 0, 8, 9, 10);
325325
INPUT_SET(InputSet::Default2, 2, 111, 3, 4, 5, 9, 21, 8, 9, 10);
326326
INPUT_SET(InputSet::Default3, 4, 112, 4, 5, 3, 7, 21, 1, 11, 9);
327+
INPUT_SET(InputSet::Zero, 0);
327328
INPUT_SET(InputSet::BitShiftRhs, 1, 6, 3, 0, 9, 3, 12, 13, 14, 15);
328329
INPUT_SET(InputSet::Bitwise, 0, 1, 3, 6, 9, 0x5555, 0xAAAA, 0x8000, 127,
329330
std::numeric_limits<uint16_t>::max());
@@ -335,6 +336,7 @@ BEGIN_INPUT_SETS(uint32_t)
335336
INPUT_SET(InputSet::Default1, 1, 2, 3, 4, 5, 0, 7, 8, 9, 10);
336337
INPUT_SET(InputSet::Default2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
337338
INPUT_SET(InputSet::Default3, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1);
339+
INPUT_SET(InputSet::Zero, 0);
338340
INPUT_SET(InputSet::BitShiftRhs, 1, 6, 3, 0, 9, 3, 30, 31, 32);
339341
INPUT_SET(InputSet::Bitwise, 0, 1, 3, 6, 9, 0x55555555, 0xAAAAAAAA, 0x80000000,
340342
127, std::numeric_limits<uint32_t>::max());
@@ -346,6 +348,7 @@ BEGIN_INPUT_SETS(uint64_t)
346348
INPUT_SET(InputSet::Default1, 1, 2, 3, 4, 5, 0, 7, 1000, 9, 10);
347349
INPUT_SET(InputSet::Default2, 1, 2, 1337, 4, 5, 6, 7, 8, 9, 10);
348350
INPUT_SET(InputSet::Default3, 10, 20, 1338, 40, 50, 60, 70, 80, 90, 11);
351+
INPUT_SET(InputSet::Zero, 0);
349352
INPUT_SET(InputSet::BitShiftRhs, 1, 6, 3, 0, 9, 3, 62, 63, 64);
350353
INPUT_SET(InputSet::Bitwise, 0, 1, 3, 6, 9, 0x5555555555555555,
351354
0xAAAAAAAAAAAAAAAA, 0x8000000000000000, 127,
@@ -361,6 +364,7 @@ INPUT_SET(InputSet::Default2, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0,
361364
-1.0);
362365
INPUT_SET(InputSet::Default3, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0,
363366
1.0);
367+
INPUT_SET(InputSet::Zero, 0.0);
364368
INPUT_SET(InputSet::RangeHalfPi, -1.073, 0.044, -1.047, 0.313, 1.447, -0.865,
365369
1.364, -0.715, -0.800, 0.541);
366370
INPUT_SET(InputSet::RangeOne, 0.331, 0.727, -0.957, 0.677, -0.025, 0.495, 0.855,
@@ -392,6 +396,7 @@ INPUT_SET(InputSet::Default2, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0,
392396
-1.0);
393397
INPUT_SET(InputSet::Default3, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0,
394398
1.0);
399+
INPUT_SET(InputSet::Zero, 0.0);
395400
INPUT_SET(InputSet::RangeHalfPi, 0.315f, -0.316f, 1.409f, -0.09f, -1.569f,
396401
1.302f, -0.326f, 0.781f, -1.235f, 0.623f);
397402
INPUT_SET(InputSet::RangeOne, 0.727f, 0.331f, -0.957f, 0.677f, -0.025f, 0.495f,
@@ -420,6 +425,7 @@ INPUT_SET(InputSet::Default2, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0,
420425
-1.0);
421426
INPUT_SET(InputSet::Default3, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0,
422427
1.0);
428+
INPUT_SET(InputSet::Zero, 0.0);
423429
INPUT_SET(InputSet::RangeHalfPi, 0.807, 0.605, 1.317, 0.188, 1.566, -1.507,
424430
0.67, -1.553, 0.194, -0.883);
425431
INPUT_SET(InputSet::RangeOne, 0.331, 0.277, -0.957, 0.677, -0.025, 0.495, 0.855,

tools/clang/unittests/HLSLExec/LongVectors.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,48 @@ BITWISE_OP(OpType::FirstBitLow, (FirstBitLow(A)));
777777

778778
DEFAULT_OP_1(OpType::Initialize, (A));
779779

780+
template <typename T>
781+
struct Op<OpType::ArrayOperator_StaticAccess, T, 1> : DefaultValidation<T> {};
782+
783+
template <typename T>
784+
static std::vector<T> buildExpectedArrayAccess(const InputSets<T> &Inputs) {
785+
const size_t VectorSize = Inputs[0].size();
786+
std::vector<T> Expected;
787+
const size_t IndexCount = 6;
788+
Expected.resize(VectorSize);
789+
790+
size_t IndexList[IndexCount] = {
791+
0, VectorSize - 1, 1, VectorSize - 2, VectorSize / 2, VectorSize / 2 + 1};
792+
size_t End = std::min(VectorSize, IndexCount);
793+
for (size_t I = 0; I < End; ++I)
794+
Expected[IndexList[I]] = Inputs[0][IndexList[I]];
795+
796+
return Expected;
797+
}
798+
799+
template <typename T>
800+
struct ExpectedBuilder<OpType::ArrayOperator_StaticAccess, T> {
801+
static std::vector<T>
802+
buildExpected(Op<OpType::ArrayOperator_StaticAccess, T, 1>,
803+
const InputSets<T> &Inputs) {
804+
DXASSERT_NOMSG(Inputs.size() == 1);
805+
return buildExpectedArrayAccess(Inputs);
806+
}
807+
};
808+
809+
template <typename T>
810+
struct Op<OpType::ArrayOperator_DynamicAccess, T, 2> : DefaultValidation<T> {};
811+
812+
template <typename T>
813+
struct ExpectedBuilder<OpType::ArrayOperator_DynamicAccess, T> {
814+
static std::vector<T>
815+
buildExpected(Op<OpType::ArrayOperator_DynamicAccess, T, 2>,
816+
const InputSets<T> &Inputs) {
817+
DXASSERT_NOMSG(Inputs.size() == 2);
818+
return buildExpectedArrayAccess(Inputs);
819+
}
820+
};
821+
780822
//
781823
// Cast
782824
//
@@ -1863,15 +1905,35 @@ class DxilConf_SM69_Vectorized {
18631905
// Unary
18641906

18651907
HLK_TEST(Initialize, HLSLBool_t);
1908+
HLK_TEST(ArrayOperator_StaticAccess, HLSLBool_t);
1909+
HLK_TEST(ArrayOperator_DynamicAccess, HLSLBool_t);
18661910
HLK_TEST(Initialize, int16_t);
1911+
HLK_TEST(ArrayOperator_StaticAccess, int16_t);
1912+
HLK_TEST(ArrayOperator_DynamicAccess, int16_t);
18671913
HLK_TEST(Initialize, int32_t);
1914+
HLK_TEST(ArrayOperator_StaticAccess, int32_t);
1915+
HLK_TEST(ArrayOperator_DynamicAccess, int32_t);
18681916
HLK_TEST(Initialize, int64_t);
1917+
HLK_TEST(ArrayOperator_StaticAccess, int64_t);
1918+
HLK_TEST(ArrayOperator_DynamicAccess, int64_t);
18691919
HLK_TEST(Initialize, uint16_t);
1920+
HLK_TEST(ArrayOperator_StaticAccess, uint16_t);
1921+
HLK_TEST(ArrayOperator_DynamicAccess, uint16_t);
18701922
HLK_TEST(Initialize, uint32_t);
1923+
HLK_TEST(ArrayOperator_StaticAccess, uint32_t);
1924+
HLK_TEST(ArrayOperator_DynamicAccess, uint32_t);
18711925
HLK_TEST(Initialize, uint64_t);
1926+
HLK_TEST(ArrayOperator_StaticAccess, uint64_t);
1927+
HLK_TEST(ArrayOperator_DynamicAccess, uint64_t);
18721928
HLK_TEST(Initialize, HLSLHalf_t);
1929+
HLK_TEST(ArrayOperator_StaticAccess, HLSLHalf_t);
1930+
HLK_TEST(ArrayOperator_DynamicAccess, HLSLHalf_t);
18731931
HLK_TEST(Initialize, float);
1932+
HLK_TEST(ArrayOperator_StaticAccess, float);
1933+
HLK_TEST(ArrayOperator_DynamicAccess, float);
18741934
HLK_TEST(Initialize, double);
1935+
HLK_TEST(ArrayOperator_StaticAccess, double);
1936+
HLK_TEST(ArrayOperator_DynamicAccess, double);
18751937

18761938
HLK_TEST(ShuffleVector, HLSLBool_t);
18771939
HLK_TEST(ShuffleVector, int16_t);

tools/clang/unittests/HLSLExec/ShaderOpArith.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4293,6 +4293,36 @@ void MSMain(uint GID : SV_GroupIndex,
42934293
// Wave prefix ops store the output on a specific lane only.
42944294
FUNC(Input1);
42954295
return;
4296+
#elif TEST_ARRAY_OPERATOR
4297+
// This test case is for testing array operator [].
4298+
// It tests static array access with a compile time constant index array.
4299+
// Or dynamic access, by introducing a runtime dependency that prevents the
4300+
// index array from being a compile time constant.
4301+
const uint IndexCount = 6;
4302+
const uint IndexList[IndexCount] = {
4303+
0,
4304+
OutNum - 1,
4305+
1,
4306+
OutNum - 2,
4307+
OutNum / 2,
4308+
OutNum / 2 + 1
4309+
};
4310+
4311+
OutputVector = 0;
4312+
uint End = min(OutNum, IndexCount);
4313+
4314+
#if DYNAMIC_ACCESS
4315+
const uint Zero = (uint) Input2[0];
4316+
#endif
4317+
4318+
[unroll]for(uint i = 0; i < End; ++i) {
4319+
#if DYNAMIC_ACCESS
4320+
uint index = (uint)(IndexList[i] + Zero);
4321+
#else
4322+
uint index = (uint)(IndexList[i]);
4323+
#endif
4324+
OutputVector[index] = Input1[index];
4325+
}
42964326
#elif IS_UNARY_OP
42974327
OutputVector = FUNC(Input1);
42984328
#elif IS_BINARY_OP

0 commit comments

Comments
 (0)