Skip to content

Commit e89f1f3

Browse files
committed
modify test logic to test value changed in different waves and vector positions
1 parent b06a58d commit e89f1f3

File tree

2 files changed

+63
-21
lines changed

2 files changed

+63
-21
lines changed

tools/clang/unittests/HLSLExec/LongVectors.cpp

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,9 +1597,11 @@ template <typename T> struct ExpectedBuilder<OpType::WaveMatch, T> {
15971597
static std::vector<UINT> buildExpected(Op<OpType::WaveMatch, T, 1> &,
15981598
const InputSets<T> &,
15991599
const UINT WaveSize) {
1600-
// For this test, the shader arranges it so that lane 0 is different from
1601-
// all the other lanes. Besides that all other lines write their result of
1602-
// WaveMatch as well.
1600+
// For this test, the shader arranges it so that lanes 0, WAVE_SIZE/2 and
1601+
// WAVE_SIZE-1 are different from all the other lanes, also those
1602+
// lanes modify the vector at positions 0, WAVE_SIZE/2 and WAVE_SIZE-1
1603+
// respectively, if the input vector has enough elements. Besides that all
1604+
// other lanes write their result of WaveMatch as well.
16031605

16041606
std::vector<UINT> Expected;
16051607
Expected.assign(WaveSize * 4, 0);
@@ -1613,21 +1615,52 @@ template <typename T> struct ExpectedBuilder<OpType::WaveMatch, T> {
16131615
const uint64_t HighWaveMask =
16141616
(HighWaves < 64) ? (1ULL << HighWaves) - 1 : ~0ULL;
16151617

1616-
const uint64_t LowExpected = ~1ULL & LowWaveMask;
1617-
const uint64_t HighExpected = ~0ULL & HighWaveMask;
1618+
const UINT MidBit = WaveSize / 2;
1619+
const UINT LastBit = WaveSize - 1;
16181620

1619-
Expected[0] = 1;
1620-
Expected[1] = 0;
1621-
Expected[2] = 0;
1622-
Expected[3] = 0;
1621+
uint64_t LowUnchangedLanes = ~1ULL; // Clear bit 0
1622+
uint64_t HighUnchangedLanes = ~0ULL;
16231623

1624-
// all lanes other than the first one have the same result
1625-
for (UINT I = 1; I < WaveSize; ++I) {
1624+
if (MidBit < 64)
1625+
LowUnchangedLanes &= ~(1ULL << MidBit);
1626+
else
1627+
HighUnchangedLanes &= ~(1ULL << (MidBit - 64));
1628+
1629+
if (LastBit < 64)
1630+
LowUnchangedLanes &= ~(1ULL << LastBit);
1631+
else
1632+
HighUnchangedLanes &= ~(1ULL << (LastBit - 64));
1633+
1634+
// Removing bits outside the wave size.
1635+
LowUnchangedLanes &= LowWaveMask;
1636+
HighUnchangedLanes &= HighWaveMask;
1637+
1638+
for (UINT I = 0; I < WaveSize; ++I) {
16261639
const UINT Index = I * 4;
1627-
Expected[Index] = static_cast<UINT>(LowExpected);
1628-
Expected[Index + 1] = static_cast<UINT>(LowExpected >> 32);
1629-
Expected[Index + 2] = static_cast<UINT>(HighExpected);
1630-
Expected[Index + 3] = static_cast<UINT>(HighExpected >> 32);
1640+
1641+
if (I == 0 || MidBit == I || LastBit == I) {
1642+
uint64_t LowChangedLanes = 0ULL;
1643+
uint64_t HighChangedLanes = 0ULL;
1644+
1645+
if (I < 64)
1646+
LowChangedLanes = (1ULL << I);
1647+
else
1648+
HighChangedLanes = (1ULL << (I - 64));
1649+
1650+
LowChangedLanes &= LowWaveMask;
1651+
HighChangedLanes &= HighWaveMask;
1652+
1653+
Expected[Index] = static_cast<UINT>(LowChangedLanes);
1654+
Expected[Index + 1] = static_cast<UINT>(LowChangedLanes >> 32);
1655+
Expected[Index + 2] = static_cast<UINT>(HighChangedLanes);
1656+
Expected[Index + 3] = static_cast<UINT>(HighChangedLanes >> 32);
1657+
continue;
1658+
}
1659+
1660+
Expected[Index] = static_cast<UINT>(LowUnchangedLanes);
1661+
Expected[Index + 1] = static_cast<UINT>(LowUnchangedLanes >> 32);
1662+
Expected[Index + 2] = static_cast<UINT>(HighUnchangedLanes);
1663+
Expected[Index + 3] = static_cast<UINT>(HighUnchangedLanes >> 32);
16311664
}
16321665

16331666
return Expected;

tools/clang/unittests/HLSLExec/ShaderOpArith.xml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4408,15 +4408,24 @@ 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 == (WAVE_SIZE / 2) ||
4414+
LaneIndex == (WAVE_SIZE - 1));
4415+
4416+
if(ShouldModify && LaneIndex < NUM)
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
}
4425+
4426+
// Making sure all lanes finish updating their vectors.
4427+
AllMemoryBarrierWithGroupSync();
4428+
44204429
uint4 result = WaveMatch(Vector);
44214430
uint index = WaveGetLaneIndex();
44224431

0 commit comments

Comments
 (0)