Skip to content

Commit a5918e7

Browse files
committed
finishing dynamic access test
1 parent ab7707f commit a5918e7

File tree

4 files changed

+32
-68
lines changed

4 files changed

+32
-68
lines changed

tools/clang/unittests/HLSLExec/LongVectorOps.def

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ INPUT_SET(Positive)
1919
INPUT_SET(Bitwise)
2020
INPUT_SET(SelectCond)
2121
INPUT_SET(FloatSpecial)
22-
INPUT_SET(DynamicIndexes)
2322

2423
#undef INPUT_SET
2524

@@ -66,8 +65,8 @@ OP_DEFAULT_DEFINES(Unary, Initialize, 1, "TestInitialize", "",
6665
OP_DEFAULT_DEFINES(ArrayOperator, ArrayOperator_StaticAccess, 1, "TestArrayOperatorStaticAccess", "",
6766
" -DTEST_ARRAY_OPERATOR_STATIC_ACCESS=1")
6867

69-
OP(ArrayOperator, ArrayOperator_DynamicAccess, 2, "TestArrayOperatorDynamicAccess", "", " -DTEST_ARRAY_OPERATOR_DYNAMIC_ACCESS=1 -DINDEX=1.0", "LongVectorOp", \
70-
Default1, DynamicIndexes, Default3)
68+
OP(ArrayOperator, ArrayOperator_DynamicAccess, 2, "TestArrayOperatorDynamicAccess", "",
69+
" -DTEST_ARRAY_OPERATOR_DYNAMIC_ACCESS=1", "LongVectorOP", Default1, Zero, Default3)
7170

7271
#define OP_CAST_DEFAULT(GROUP, SYMBOL) \
7372
OP_DEFAULT_DEFINES(GROUP, SYMBOL, 1, "TestCast", "", "-DFUNC_TEST_CAST=1")

tools/clang/unittests/HLSLExec/LongVectorTestData.h

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,12 @@ enum class InputSet {
240240
#include "LongVectorOps.def"
241241
};
242242

243-
template <typename T>
244-
const std::vector<T> &getInputSet(InputSet InputSet, size_t SizeToTest) {
243+
template <typename T> const std::vector<T> &getInputSet(InputSet InputSet) {
245244
static_assert(false, "No InputSet for this type");
246245
}
247246

248247
#define BEGIN_INPUT_SETS(TYPE) \
249-
template <> \
250-
const std::vector<TYPE> &getInputSet<TYPE>(InputSet InputSet, \
251-
size_t SizeToTest) { \
248+
template <> const std::vector<TYPE> &getInputSet<TYPE>(InputSet InputSet) { \
252249
using T = TYPE; \
253250
switch (InputSet) {
254251

@@ -290,9 +287,6 @@ INPUT_SET(InputSet::Bitwise, std::numeric_limits<int16_t>::min(), -1, 0, 1, 3,
290287
6, 9, 0x5555, static_cast<int16_t>(0xAAAA),
291288
std::numeric_limits<int16_t>::max());
292289
INPUT_SET(InputSet::SelectCond, 0, 1);
293-
INPUT_SET(InputSet::DynamicIndexes, 0, (int16_t)(SizeToTest - 1), 1,
294-
(int16_t)(SizeToTest - 2), (int16_t)(SizeToTest / 2),
295-
(int16_t)(SizeToTest / 2 + 1));
296290
END_INPUT_SETS()
297291

298292
BEGIN_INPUT_SETS(int32_t)
@@ -306,10 +300,6 @@ INPUT_SET(InputSet::Bitwise, std::numeric_limits<int32_t>::min(), -1, 0, 1, 3,
306300
6, 9, 0x55555555, static_cast<int32_t>(0xAAAAAAAA),
307301
std::numeric_limits<int32_t>::max());
308302
INPUT_SET(InputSet::SelectCond, 0, 1);
309-
// {0, VectorSize - 1, 1, VectorSize - 2, VectorSize / 2, VectorSize / 2 + 1};
310-
INPUT_SET(InputSet::DynamicIndexes, 0, (int32_t)(SizeToTest - 1), 1,
311-
(int32_t)(SizeToTest - 2), (int32_t)(SizeToTest / 2),
312-
(int32_t)(SizeToTest / 2 + 1));
313303
END_INPUT_SETS()
314304

315305
BEGIN_INPUT_SETS(int64_t)
@@ -323,49 +313,40 @@ INPUT_SET(InputSet::Bitwise, std::numeric_limits<int64_t>::min(), -1, 0, 1, 3,
323313
6, 9, 0x5555555555555555LL, 0xAAAAAAAAAAAAAAAALL,
324314
std::numeric_limits<int64_t>::max());
325315
INPUT_SET(InputSet::SelectCond, 0, 1);
326-
INPUT_SET(InputSet::DynamicIndexes, 0, (int64_t)(SizeToTest - 1), 1,
327-
(int64_t)(SizeToTest - 2), (int64_t)(SizeToTest / 2),
328-
(int64_t)(SizeToTest / 2 + 1));
329316
END_INPUT_SETS()
330317

331318
BEGIN_INPUT_SETS(uint16_t)
332319
INPUT_SET(InputSet::Default1, 1, 699, 3, 1023, 5, 6, 0, 8, 9, 10);
333320
INPUT_SET(InputSet::Default2, 2, 111, 3, 4, 5, 9, 21, 8, 9, 10);
334321
INPUT_SET(InputSet::Default3, 4, 112, 4, 5, 3, 7, 21, 1, 11, 9);
322+
INPUT_SET(InputSet::Zero, 0);
335323
INPUT_SET(InputSet::BitShiftRhs, 1, 6, 3, 0, 9, 3, 12, 13, 14, 15);
336324
INPUT_SET(InputSet::Bitwise, 0, 1, 3, 6, 9, 0x5555, 0xAAAA, 0x8000, 127,
337325
std::numeric_limits<uint16_t>::max());
338326
INPUT_SET(InputSet::SelectCond, 0, 1);
339-
INPUT_SET(InputSet::DynamicIndexes, 0, (uint16_t)(SizeToTest - 1), 1,
340-
(uint16_t)(SizeToTest - 2), (uint16_t)(SizeToTest / 2),
341-
(uint16_t)(SizeToTest / 2 + 1));
342327
END_INPUT_SETS()
343328

344329
BEGIN_INPUT_SETS(uint32_t)
345330
INPUT_SET(InputSet::Default1, 1, 2, 3, 4, 5, 0, 7, 8, 9, 10);
346331
INPUT_SET(InputSet::Default2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
347332
INPUT_SET(InputSet::Default3, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1);
333+
INPUT_SET(InputSet::Zero, 0);
348334
INPUT_SET(InputSet::BitShiftRhs, 1, 6, 3, 0, 9, 3, 30, 31, 32);
349335
INPUT_SET(InputSet::Bitwise, 0, 1, 3, 6, 9, 0x55555555, 0xAAAAAAAA, 0x80000000,
350336
127, std::numeric_limits<uint32_t>::max());
351337
INPUT_SET(InputSet::SelectCond, 0, 1);
352-
INPUT_SET(InputSet::DynamicIndexes, 0, (uint32_t)(SizeToTest - 1), 1,
353-
(uint32_t)(SizeToTest - 2), (uint32_t)(SizeToTest / 2),
354-
(uint32_t)(SizeToTest / 2 + 1));
355338
END_INPUT_SETS()
356339

357340
BEGIN_INPUT_SETS(uint64_t)
358341
INPUT_SET(InputSet::Default1, 1, 2, 3, 4, 5, 0, 7, 1000, 9, 10);
359342
INPUT_SET(InputSet::Default2, 1, 2, 1337, 4, 5, 6, 7, 8, 9, 10);
360343
INPUT_SET(InputSet::Default3, 10, 20, 1338, 40, 50, 60, 70, 80, 90, 11);
344+
INPUT_SET(InputSet::Zero, 0);
361345
INPUT_SET(InputSet::BitShiftRhs, 1, 6, 3, 0, 9, 3, 62, 63, 64);
362346
INPUT_SET(InputSet::Bitwise, 0, 1, 3, 6, 9, 0x5555555555555555,
363347
0xAAAAAAAAAAAAAAAA, 0x8000000000000000, 127,
364348
std::numeric_limits<uint64_t>::max());
365349
INPUT_SET(InputSet::SelectCond, 0, 1);
366-
INPUT_SET(InputSet::DynamicIndexes, 0, (uint64_t)(SizeToTest - 1), 1,
367-
(uint64_t)(SizeToTest - 2), (uint64_t)(SizeToTest / 2),
368-
(uint64_t)(SizeToTest / 2 + 1));
369350
END_INPUT_SETS()
370351

371352
BEGIN_INPUT_SETS(HLSLHalf_t)
@@ -375,6 +356,8 @@ INPUT_SET(InputSet::Default2, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0,
375356
-1.0);
376357
INPUT_SET(InputSet::Default3, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0,
377358
1.0);
359+
INPUT_SET(InputSet::Zero, 0.0);
360+
378361
INPUT_SET(InputSet::RangeHalfPi, -1.073, 0.044, -1.047, 0.313, 1.447, -0.865,
379362
1.364, -0.715, -0.800, 0.541);
380363
INPUT_SET(InputSet::RangeOne, 0.331, 0.727, -0.957, 0.677, -0.025, 0.495, 0.855,
@@ -396,9 +379,6 @@ INPUT_SET(InputSet::FloatSpecial, std::numeric_limits<float>::infinity(),
396379
-std::numeric_limits<float>::max(),
397380
std::numeric_limits<float>::denorm_min(),
398381
std::numeric_limits<float>::denorm_min() * 10.0, 1.0 / 3.0);
399-
INPUT_SET(InputSet::DynamicIndexes, 0.0, (float)(SizeToTest - 1), 1.0,
400-
(float)(SizeToTest - 2), (float)(SizeToTest / 2),
401-
(float)(SizeToTest / 2 + 1));
402382
END_INPUT_SETS()
403383

404384
BEGIN_INPUT_SETS(float)
@@ -408,6 +388,7 @@ INPUT_SET(InputSet::Default2, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0,
408388
-1.0);
409389
INPUT_SET(InputSet::Default3, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0,
410390
1.0);
391+
INPUT_SET(InputSet::Zero, 0.0);
411392
INPUT_SET(InputSet::RangeHalfPi, 0.315f, -0.316f, 1.409f, -0.09f, -1.569f,
412393
1.302f, -0.326f, 0.781f, -1.235f, 0.623f);
413394
INPUT_SET(InputSet::RangeOne, 0.727f, 0.331f, -0.957f, 0.677f, -0.025f, 0.495f,
@@ -426,9 +407,6 @@ INPUT_SET(InputSet::FloatSpecial, std::numeric_limits<float>::infinity(),
426407
-std::numeric_limits<float>::max(),
427408
std::numeric_limits<float>::denorm_min(),
428409
std::numeric_limits<float>::denorm_min() * 10.0f, 1.0f / 3.0f);
429-
INPUT_SET(InputSet::DynamicIndexes, 0.0, (float)(SizeToTest - 1), 1.0,
430-
(float)(SizeToTest - 2), (float)(SizeToTest / 2),
431-
(float)(SizeToTest / 2 + 1));
432410
END_INPUT_SETS()
433411

434412
BEGIN_INPUT_SETS(double)
@@ -438,6 +416,7 @@ INPUT_SET(InputSet::Default2, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0,
438416
-1.0);
439417
INPUT_SET(InputSet::Default3, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0,
440418
1.0);
419+
INPUT_SET(InputSet::Zero, 0.0);
441420
INPUT_SET(InputSet::RangeHalfPi, 0.807, 0.605, 1.317, 0.188, 1.566, -1.507,
442421
0.67, -1.553, 0.194, -0.883);
443422
INPUT_SET(InputSet::RangeOne, 0.331, 0.277, -0.957, 0.677, -0.025, 0.495, 0.855,
@@ -447,9 +426,6 @@ INPUT_SET(InputSet::SplitDouble, 0.0, -1.0, 1.0, -1.0, 12345678.87654321, -1.0,
447426
INPUT_SET(InputSet::Positive, 1.0, 1.0, 65535.0, 0.01, 5531.0, 0.01, 1.0, 0.01,
448427
331.2330, 3250.01);
449428
INPUT_SET(InputSet::SelectCond, 0.0, 1.0);
450-
INPUT_SET(InputSet::DynamicIndexes, 0.0, (double)(SizeToTest - 1), 1.0,
451-
(double)(SizeToTest - 2), (double)(SizeToTest / 2),
452-
(double)(SizeToTest / 2 + 1));
453429
END_INPUT_SETS()
454430

455431
#undef BEGIN_INPUT_SETS

tools/clang/unittests/HLSLExec/LongVectors.cpp

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ void configureLoadAndStoreShaderOp(const Operation &Operation,
535535

536536
template <typename T>
537537
std::vector<T> buildTestInput(InputSet InputSet, size_t SizeToTest) {
538-
const std::vector<T> &RawValueSet = getInputSet<T>(InputSet, SizeToTest);
538+
const std::vector<T> &RawValueSet = getInputSet<T>(InputSet);
539539

540540
std::vector<T> ValueSet;
541541
ValueSet.reserve(SizeToTest);
@@ -771,26 +771,27 @@ DEFAULT_OP_1(OpType::Initialize, (A));
771771
template <typename T>
772772
struct Op<OpType::ArrayOperator_StaticAccess, T, 1> : DefaultValidation<T> {};
773773

774+
template <typename T>
775+
static std::vector<T> buildExpectedArrayAccess(const InputSets<T> &Inputs) {
776+
const size_t VectorSize = Inputs[0].size();
777+
std::vector<T> Expected;
778+
Expected.resize(VectorSize);
779+
780+
size_t IndexList[6] = {
781+
0, VectorSize - 1, 1, VectorSize - 2, VectorSize / 2, VectorSize / 2 + 1};
782+
for (size_t i = 0; i < 6; ++i)
783+
Expected[IndexList[i]] = Inputs[0][IndexList[i]] + static_cast<T>(1.0);
784+
785+
return Expected;
786+
}
787+
774788
template <typename T>
775789
struct ExpectedBuilder<OpType::ArrayOperator_StaticAccess, T> {
776790
static std::vector<T>
777791
buildExpected(Op<OpType::ArrayOperator_StaticAccess, T, 1>,
778792
const InputSets<T> &Inputs) {
779793
DXASSERT_NOMSG(Inputs.size() == 1);
780-
const size_t VectorSize = Inputs[0].size();
781-
std::vector<T> Expected;
782-
Expected.resize(VectorSize);
783-
784-
size_t IndexList[6] = {0,
785-
VectorSize - 1,
786-
1,
787-
VectorSize - 2,
788-
VectorSize / 2,
789-
VectorSize / 2 + 1};
790-
for (size_t i = 0; i < 6; ++i)
791-
Expected[IndexList[i]] = Inputs[0][IndexList[i]] + static_cast<T>(1.0);
792-
793-
return Expected;
794+
return buildExpectedArrayAccess(Inputs);
794795
}
795796
};
796797

@@ -803,17 +804,7 @@ struct ExpectedBuilder<OpType::ArrayOperator_DynamicAccess, T> {
803804
buildExpected(Op<OpType::ArrayOperator_DynamicAccess, T, 2>,
804805
const InputSets<T> &Inputs) {
805806
DXASSERT_NOMSG(Inputs.size() == 2);
806-
const size_t IndexVectorSize = Inputs[1].size();
807-
808-
std::vector<T> Expected;
809-
Expected.resize(IndexVectorSize);
810-
size_t End = std::min(IndexVectorSize, static_cast<size_t>(6));
811-
for (size_t i = 0; i < End; ++i) {
812-
const size_t Index = static_cast<size_t>(Inputs[1][i]);
813-
Expected[Index] = Inputs[0][Index] + static_cast<T>(1.0);
814-
}
815-
816-
return Expected;
807+
return buildExpectedArrayAccess(Inputs);
817808
}
818809
};
819810

tools/clang/unittests/HLSLExec/ShaderOpArith.xml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4135,16 +4135,14 @@ void MSMain(uint GID : SV_GroupIndex,
41354135
[unroll]for(uint i = 0; i < 6; ++i)
41364136
OutputVector[IndexList[i]] = (OUT_TYPE)Input1[IndexList[i]] + (OUT_TYPE)1;
41374137
#elif TEST_ARRAY_OPERATOR_DYNAMIC_ACCESS
4138+
// Input2 will always be 0. This is added so the compiler cannot optimize the array access.
4139+
uint Modifier = (uint) Input2[0];
4140+
uint IndexList[6] = {0 + Modifier, OutNum - 1 + Modifier, 1 + Modifier, OutNum - 2 + Modifier, OutNum / 2 + Modifier, OutNum / 2 + 1 + Modifier};
41384141
vector<OUT_TYPE, OutNum> OutputVector = 0;
41394142
uint End = min(OutNum, 6);
41404143
[unroll]for(uint i = 0; i < End; ++i){
4141-
uint index = (uint)(Input2[i]);
4142-
// this doesn't work
4143-
// OutputVector[index] = Input1[i] + (OUT_TYPE)1;
4144-
// this also doesn't work
4144+
uint index = (uint)(IndexList[i]);
41454145
OutputVector[index] = Input1[index] + (OUT_TYPE)1;
4146-
// this works
4147-
// OutputVector[i] = Input1[index] + (OUT_TYPE)1;
41484146
}
41494147
#elif IS_UNARY_OP
41504148
vector<OUT_TYPE, OutNum> OutputVector = FUNC(Input1);

0 commit comments

Comments
 (0)