diff --git a/tools/clang/unittests/HLSLExec/LongVectorOps.def b/tools/clang/unittests/HLSLExec/LongVectorOps.def index f3908ff055..c881e779d4 100644 --- a/tools/clang/unittests/HLSLExec/LongVectorOps.def +++ b/tools/clang/unittests/HLSLExec/LongVectorOps.def @@ -63,6 +63,12 @@ OP(Bitwise, FirstBitLow, 1, "firstbitlow", "", "", "LongVectorOp", Bitwise, Defa OP_DEFAULT_DEFINES(Unary, Initialize, 1, "TestInitialize", "", " -DFUNC_INITIALIZE=1") +OP_DEFAULT_DEFINES(ArrayOperator, ArrayOperator_StaticAccess, 1, "TestArrayOperatorStaticAccess", "", + " -DTEST_ARRAY_OPERATOR") + +OP(ArrayOperator, ArrayOperator_DynamicAccess, 2, "TestArrayOperatorDynamicAccess", "", + " -DTEST_ARRAY_OPERATOR=1 -DDYNAMIC_ACCESS=1", "LongVectorOP", Default1, Zero, Default3) + #define OP_CAST_DEFAULT(GROUP, SYMBOL) \ OP_DEFAULT_DEFINES(GROUP, SYMBOL, 1, "TestCast", "", "-DFUNC_TEST_CAST=1") #define OP_CAST(GROUP, SYMBOL, INPUT_SET_1) \ diff --git a/tools/clang/unittests/HLSLExec/LongVectorTestData.h b/tools/clang/unittests/HLSLExec/LongVectorTestData.h index 519f8a8b63..7e147fe600 100644 --- a/tools/clang/unittests/HLSLExec/LongVectorTestData.h +++ b/tools/clang/unittests/HLSLExec/LongVectorTestData.h @@ -324,6 +324,7 @@ BEGIN_INPUT_SETS(uint16_t) INPUT_SET(InputSet::Default1, 1, 699, 3, 1023, 5, 6, 0, 8, 9, 10); INPUT_SET(InputSet::Default2, 2, 111, 3, 4, 5, 9, 21, 8, 9, 10); INPUT_SET(InputSet::Default3, 4, 112, 4, 5, 3, 7, 21, 1, 11, 9); +INPUT_SET(InputSet::Zero, 0); INPUT_SET(InputSet::BitShiftRhs, 1, 6, 3, 0, 9, 3, 12, 13, 14, 15); INPUT_SET(InputSet::Bitwise, 0, 1, 3, 6, 9, 0x5555, 0xAAAA, 0x8000, 127, std::numeric_limits::max()); @@ -335,6 +336,7 @@ BEGIN_INPUT_SETS(uint32_t) INPUT_SET(InputSet::Default1, 1, 2, 3, 4, 5, 0, 7, 8, 9, 10); INPUT_SET(InputSet::Default2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); INPUT_SET(InputSet::Default3, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1); +INPUT_SET(InputSet::Zero, 0); INPUT_SET(InputSet::BitShiftRhs, 1, 6, 3, 0, 9, 3, 30, 31, 32); INPUT_SET(InputSet::Bitwise, 0, 1, 3, 6, 9, 0x55555555, 0xAAAAAAAA, 0x80000000, 127, std::numeric_limits::max()); @@ -346,6 +348,7 @@ BEGIN_INPUT_SETS(uint64_t) INPUT_SET(InputSet::Default1, 1, 2, 3, 4, 5, 0, 7, 1000, 9, 10); INPUT_SET(InputSet::Default2, 1, 2, 1337, 4, 5, 6, 7, 8, 9, 10); INPUT_SET(InputSet::Default3, 10, 20, 1338, 40, 50, 60, 70, 80, 90, 11); +INPUT_SET(InputSet::Zero, 0); INPUT_SET(InputSet::BitShiftRhs, 1, 6, 3, 0, 9, 3, 62, 63, 64); INPUT_SET(InputSet::Bitwise, 0, 1, 3, 6, 9, 0x5555555555555555, 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, -1.0); INPUT_SET(InputSet::Default3, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0); +INPUT_SET(InputSet::Zero, 0.0); INPUT_SET(InputSet::RangeHalfPi, -1.073, 0.044, -1.047, 0.313, 1.447, -0.865, 1.364, -0.715, -0.800, 0.541); 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, -1.0); INPUT_SET(InputSet::Default3, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0); +INPUT_SET(InputSet::Zero, 0.0); INPUT_SET(InputSet::RangeHalfPi, 0.315f, -0.316f, 1.409f, -0.09f, -1.569f, 1.302f, -0.326f, 0.781f, -1.235f, 0.623f); 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, -1.0); INPUT_SET(InputSet::Default3, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0); +INPUT_SET(InputSet::Zero, 0.0); INPUT_SET(InputSet::RangeHalfPi, 0.807, 0.605, 1.317, 0.188, 1.566, -1.507, 0.67, -1.553, 0.194, -0.883); INPUT_SET(InputSet::RangeOne, 0.331, 0.277, -0.957, 0.677, -0.025, 0.495, 0.855, diff --git a/tools/clang/unittests/HLSLExec/LongVectors.cpp b/tools/clang/unittests/HLSLExec/LongVectors.cpp index 5ab16b75a8..74a56a4327 100644 --- a/tools/clang/unittests/HLSLExec/LongVectors.cpp +++ b/tools/clang/unittests/HLSLExec/LongVectors.cpp @@ -776,6 +776,48 @@ BITWISE_OP(OpType::FirstBitLow, (FirstBitLow(A))); DEFAULT_OP_1(OpType::Initialize, (A)); +template +struct Op : DefaultValidation {}; + +template +static std::vector buildExpectedArrayAccess(const InputSets &Inputs) { + const size_t VectorSize = Inputs[0].size(); + std::vector Expected; + const size_t IndexCount = 6; + Expected.resize(VectorSize); + + size_t IndexList[IndexCount] = { + 0, VectorSize - 1, 1, VectorSize - 2, VectorSize / 2, VectorSize / 2 + 1}; + size_t End = std::min(VectorSize, IndexCount); + for (size_t I = 0; I < End; ++I) + Expected[IndexList[I]] = Inputs[0][IndexList[I]]; + + return Expected; +} + +template +struct ExpectedBuilder { + static std::vector + buildExpected(Op, + const InputSets &Inputs) { + DXASSERT_NOMSG(Inputs.size() == 1); + return buildExpectedArrayAccess(Inputs); + } +}; + +template +struct Op : DefaultValidation {}; + +template +struct ExpectedBuilder { + static std::vector + buildExpected(Op, + const InputSets &Inputs) { + DXASSERT_NOMSG(Inputs.size() == 2); + return buildExpectedArrayAccess(Inputs); + } +}; + // // Cast // @@ -1862,15 +1904,35 @@ class DxilConf_SM69_Vectorized { // Unary HLK_TEST(Initialize, HLSLBool_t); + HLK_TEST(ArrayOperator_StaticAccess, HLSLBool_t); + HLK_TEST(ArrayOperator_DynamicAccess, HLSLBool_t); HLK_TEST(Initialize, int16_t); + HLK_TEST(ArrayOperator_StaticAccess, int16_t); + HLK_TEST(ArrayOperator_DynamicAccess, int16_t); HLK_TEST(Initialize, int32_t); + HLK_TEST(ArrayOperator_StaticAccess, int32_t); + HLK_TEST(ArrayOperator_DynamicAccess, int32_t); HLK_TEST(Initialize, int64_t); + HLK_TEST(ArrayOperator_StaticAccess, int64_t); + HLK_TEST(ArrayOperator_DynamicAccess, int64_t); HLK_TEST(Initialize, uint16_t); + HLK_TEST(ArrayOperator_StaticAccess, uint16_t); + HLK_TEST(ArrayOperator_DynamicAccess, uint16_t); HLK_TEST(Initialize, uint32_t); + HLK_TEST(ArrayOperator_StaticAccess, uint32_t); + HLK_TEST(ArrayOperator_DynamicAccess, uint32_t); HLK_TEST(Initialize, uint64_t); + HLK_TEST(ArrayOperator_StaticAccess, uint64_t); + HLK_TEST(ArrayOperator_DynamicAccess, uint64_t); HLK_TEST(Initialize, HLSLHalf_t); + HLK_TEST(ArrayOperator_StaticAccess, HLSLHalf_t); + HLK_TEST(ArrayOperator_DynamicAccess, HLSLHalf_t); HLK_TEST(Initialize, float); + HLK_TEST(ArrayOperator_StaticAccess, float); + HLK_TEST(ArrayOperator_DynamicAccess, float); HLK_TEST(Initialize, double); + HLK_TEST(ArrayOperator_StaticAccess, double); + HLK_TEST(ArrayOperator_DynamicAccess, double); HLK_TEST(ShuffleVector, HLSLBool_t); HLK_TEST(ShuffleVector, int16_t); diff --git a/tools/clang/unittests/HLSLExec/ShaderOpArith.xml b/tools/clang/unittests/HLSLExec/ShaderOpArith.xml index 5bc9f7118e..63d26910f0 100644 --- a/tools/clang/unittests/HLSLExec/ShaderOpArith.xml +++ b/tools/clang/unittests/HLSLExec/ShaderOpArith.xml @@ -4293,6 +4293,36 @@ void MSMain(uint GID : SV_GroupIndex, // Wave prefix ops store the output on a specific lane only. FUNC(Input1); return; + #elif TEST_ARRAY_OPERATOR + // This test case is for testing array operator []. + // It tests static array access with a compile time constant index array. + // Or dynamic access, by introducing a runtime dependency that prevents the + // index array from being a compile time constant. + const uint IndexCount = 6; + const uint IndexList[IndexCount] = { + 0, + OutNum - 1, + 1, + OutNum - 2, + OutNum / 2, + OutNum / 2 + 1 + }; + + OutputVector = 0; + uint End = min(OutNum, IndexCount); + + #if DYNAMIC_ACCESS + const uint Zero = (uint) Input2[0]; + #endif + + [unroll]for(uint i = 0; i < End; ++i) { + #if DYNAMIC_ACCESS + uint index = (uint)(IndexList[i] + Zero); + #else + uint index = (uint)(IndexList[i]); + #endif + OutputVector[index] = Input1[index]; + } #elif IS_UNARY_OP OutputVector = FUNC(Input1); #elif IS_BINARY_OP