Skip to content

Commit f255809

Browse files
[HLK] Modify Wave match test logic to support modifications in different lanes and vector position (#7991)
This patch modifies the Wave Match test to test modifications in different lanes and vector indexes. This is achieved by forcing lanes `0`, `WAVE_SIZE/2` and `WAVE_SIZE -1`, to modify the vector at indexes `0`, `WAVE_SIZE/2` or `WAVE_SIZE -1`, respectively. --------- Co-authored-by: Joao Saffran <[email protected]>
1 parent 33cdb85 commit f255809

2 files changed

Lines changed: 52 additions & 33 deletions

File tree

tools/clang/unittests/HLSLExec/LongVectors.cpp

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,41 +1614,54 @@ template <typename T> T waveMultiPrefixProduct(T A, UINT) {
16141614

16151615
template <typename T> struct Op<OpType::WaveMatch, T, 1> : StrictValidation {};
16161616

1617+
static void WriteExpectedValueForLane(UINT *Dest, const UINT LaneID,
1618+
const std::bitset<128> &ExpectedValue) {
1619+
std::bitset<128> Lo32Mask;
1620+
Lo32Mask.set();
1621+
Lo32Mask >>= 128 - 32;
1622+
1623+
UINT Offset = 4 * LaneID;
1624+
for (uint32_t I = 0; I < 4; I++) {
1625+
uint32_t V = ((ExpectedValue >> (I * 32)) & Lo32Mask).to_ulong();
1626+
Dest[Offset++] = V;
1627+
}
1628+
}
1629+
16171630
template <typename T> struct ExpectedBuilder<OpType::WaveMatch, T> {
16181631
static std::vector<UINT> buildExpected(Op<OpType::WaveMatch, T, 1> &,
1619-
const InputSets<T> &,
1632+
const InputSets<T> &Inputs,
16201633
const UINT WaveSize) {
1621-
// For this test, the shader arranges it so that lane 0 is different from
1622-
// all the other lanes. Besides that all other lines write their result of
1623-
// WaveMatch as well.
1634+
// This test sets lanes (0, min(VectorSize/2, WaveSize/2), and
1635+
// min(VectorSize-1, WaveSize-1)) to unique values and has them modify the
1636+
// vector at their respective indices. Remaining lanes remain unchanged.
1637+
DXASSERT_NOMSG(Inputs.size() == 1);
16241638

1639+
const UINT VectorSize = static_cast<UINT>(Inputs[0].size());
16251640
std::vector<UINT> Expected;
16261641
Expected.assign(WaveSize * 4, 0);
16271642

1628-
const UINT LowWaves = std::min(64U, WaveSize);
1629-
const UINT HighWaves = WaveSize - LowWaves;
1630-
1631-
const uint64_t LowWaveMask =
1632-
(LowWaves < 64) ? (1ULL << LowWaves) - 1 : ~0ULL;
1643+
const UINT MidLaneID = std::min(VectorSize / 2, WaveSize / 2);
1644+
const UINT LastLaneID = std::min(VectorSize - 1, WaveSize - 1);
16331645

1634-
const uint64_t HighWaveMask =
1635-
(HighWaves < 64) ? (1ULL << HighWaves) - 1 : ~0ULL;
1646+
// Use a std::bitset<128> to represent the uint4 returned by WaveMatch as
1647+
// its convenient this way in c++
1648+
std::bitset<128> DefaultExpectedValue;
16361649

1637-
const uint64_t LowExpected = ~1ULL & LowWaveMask;
1638-
const uint64_t HighExpected = ~0ULL & HighWaveMask;
1650+
for (UINT I = 0; I < WaveSize; ++I)
1651+
DefaultExpectedValue.set(I);
16391652

1640-
Expected[0] = 1;
1641-
Expected[1] = 0;
1642-
Expected[2] = 0;
1643-
Expected[3] = 0;
1653+
DefaultExpectedValue.reset(0);
1654+
DefaultExpectedValue.reset(MidLaneID);
1655+
DefaultExpectedValue.reset(LastLaneID);
16441656

1645-
// all lanes other than the first one have the same result
1646-
for (UINT I = 1; I < WaveSize; ++I) {
1647-
const UINT Index = I * 4;
1648-
Expected[Index] = static_cast<UINT>(LowExpected);
1649-
Expected[Index + 1] = static_cast<UINT>(LowExpected >> 32);
1650-
Expected[Index + 2] = static_cast<UINT>(HighExpected);
1651-
Expected[Index + 3] = static_cast<UINT>(HighExpected >> 32);
1657+
for (UINT LaneID = 0; LaneID < WaveSize; ++LaneID) {
1658+
if (LaneID == 0 || LaneID == MidLaneID || LaneID == LastLaneID) {
1659+
std::bitset<128> ExpectedValue(0);
1660+
ExpectedValue.set(LaneID);
1661+
WriteExpectedValueForLane(Expected.data(), LaneID, ExpectedValue);
1662+
continue;
1663+
}
1664+
WriteExpectedValueForLane(Expected.data(), LaneID, DefaultExpectedValue);
16521665
}
16531666

16541667
return Expected;

tools/clang/unittests/HLSLExec/ShaderOpArith.xml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4408,19 +4408,25 @@ void MSMain(uint GID : SV_GroupIndex,
44084408
#ifdef FUNC_WAVE_MATCH
44094409
void TestWaveMatch(vector<TYPE, NUM> Vector)
44104410
{
4411-
if(WaveGetLaneIndex() == 0)
4411+
uint LaneIndex = WaveGetLaneIndex();
4412+
bool ShouldModify = ( LaneIndex == 0 ||
4413+
LaneIndex == min(NUM / 2, WAVE_SIZE / 2) ||
4414+
LaneIndex == min(NUM - 1, WAVE_SIZE - 1) );
4415+
4416+
if(ShouldModify)
44124417
{
4413-
if(Vector[0] == (TYPE)0)
4414-
Vector[0] = (TYPE) 1;
4415-
else if(Vector[0] == (TYPE)1)
4416-
Vector[0] = (TYPE) 0;
4418+
if(Vector[LaneIndex] == (TYPE) 0)
4419+
Vector[LaneIndex] = (TYPE) 1;
4420+
else if(Vector[LaneIndex] == (TYPE) 1)
4421+
Vector[LaneIndex] = (TYPE) 0;
44174422
else
4418-
Vector[0] = (TYPE) 1;
4423+
Vector[LaneIndex] = (TYPE) 1;
44194424
}
4420-
uint4 result = WaveMatch(Vector);
4421-
uint index = WaveGetLaneIndex();
44224425
4423-
g_OutputVector.Store<uint4>(index * sizeof(uint4), result);
4426+
uint4 Result = WaveMatch(Vector);
4427+
uint Index = WaveGetLaneIndex();
4428+
4429+
g_OutputVector.Store<uint4>(Index * sizeof(uint4), Result);
44244430
}
44254431
#endif
44264432

0 commit comments

Comments
 (0)