Skip to content

Commit c2e2dee

Browse files
committed
Test all MaybeReorderThread variants (in wave-incoherent execution)
1 parent 5a31d33 commit c2e2dee

2 files changed

Lines changed: 113 additions & 0 deletions

File tree

tools/clang/unittests/HLSLExec/ExecutionTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ class ExecutionTest {
631631
TEST_METHOD(SERShaderTableIndexTest);
632632
TEST_METHOD(SERLoadLocalRootTableConstantTest);
633633
TEST_METHOD(SERInvokeNoSBTTest);
634+
TEST_METHOD(SERMaybeReorderThreadTest)
634635

635636
dxc::DxcDllSupport m_support;
636637

tools/clang/unittests/HLSLExec/ExecutionTest_SER.h

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,4 +1899,116 @@ void closesthit(inout PerRayData payload, in Attrs attrs)
18991899
VERIFY_ARE_EQUAL(Histo.size(), 2);
19001900
VERIFY_ARE_EQUAL(Histo[8], 66);
19011901
VERIFY_ARE_EQUAL(Histo[16], 4030);
1902+
}
1903+
1904+
TEST_F(ExecutionTest, SERMaybeReorderThreadTest) {
1905+
// SER: Test MaybeReorderThread variants.
1906+
static const char *ShaderSrc = R"(
1907+
struct SceneConstants
1908+
{
1909+
float4 eye;
1910+
float4 U;
1911+
float4 V;
1912+
float4 W;
1913+
float sceneScale;
1914+
uint2 windowSize;
1915+
int rayFlags;
1916+
};
1917+
1918+
struct[raypayload] PerRayData
1919+
{
1920+
uint visited : read(anyhit,closesthit,miss,caller) : write(anyhit,miss,closesthit,caller);
1921+
};
1922+
1923+
struct Attrs
1924+
{
1925+
float2 barycentrics : BARYCENTRICS;
1926+
};
1927+
1928+
RWStructuredBuffer<int> testBuffer : register(u0);
1929+
RaytracingAccelerationStructure topObject : register(t0);
1930+
ConstantBuffer<SceneConstants> sceneConstants : register(b0);
1931+
1932+
RayDesc ComputeRay()
1933+
{
1934+
uint2 launchIndex = DispatchRaysIndex().xy;
1935+
uint2 launchDim = DispatchRaysDimensions().xy;
1936+
1937+
float2 d = float2(DispatchRaysIndex().xy) / float2(DispatchRaysDimensions().xy) * 2.0f - 1.0f;
1938+
RayDesc ray;
1939+
ray.Origin = sceneConstants.eye.xyz;
1940+
ray.Direction = normalize(d.x*sceneConstants.U.xyz + d.y*sceneConstants.V.xyz + sceneConstants.W.xyz);
1941+
ray.TMin = 0;
1942+
ray.TMax = 1e18;
1943+
1944+
return ray;
1945+
}
1946+
1947+
[shader("raygeneration")]
1948+
void raygen()
1949+
{
1950+
uint2 launchIndex = DispatchRaysIndex().xy;
1951+
uint2 launchDim = DispatchRaysDimensions().xy;
1952+
1953+
RayDesc ray = ComputeRay();
1954+
1955+
PerRayData payload;
1956+
payload.visited = 0;
1957+
1958+
dx::HitObject hitObject = dx::HitObject::TraceRay(topObject, RAY_FLAG_NONE, 0xFF, 0, 1, 0, ray, payload);
1959+
1960+
if (launchIndex.x % 3 == 0) {
1961+
dx::MaybeReorderThread(hitObject);
1962+
}
1963+
else if (launchIndex.x % 3 == 1) {
1964+
dx::MaybeReorderThread(hitObject, 0xFF, 7);
1965+
}
1966+
else {
1967+
dx::MaybeReorderThread(0xFFF, 5);
1968+
}
1969+
1970+
dx::HitObject::Invoke(hitObject, payload);
1971+
1972+
int id = launchIndex.x + launchIndex.y * launchDim.x;
1973+
testBuffer[id] = payload.visited;
1974+
}
1975+
1976+
[shader("miss")]
1977+
void miss(inout PerRayData payload)
1978+
{
1979+
payload.visited |= 2U;
1980+
}
1981+
1982+
[shader("anyhit")]
1983+
void anyhit(inout PerRayData payload, in Attrs attrs)
1984+
{
1985+
payload.visited |= 1U;
1986+
}
1987+
1988+
[shader("closesthit")]
1989+
void closesthit(inout PerRayData payload, in Attrs attrs)
1990+
{
1991+
payload.visited |= 4U;
1992+
}
1993+
1994+
)";
1995+
1996+
CComPtr<ID3D12Device> Device;
1997+
if (!CreateDXRDevice(&Device, D3D_SHADER_MODEL_6_9, false))
1998+
return;
1999+
2000+
// Initialize test data.
2001+
const int WindowSize = 64;
2002+
std::vector<int> TestData(WindowSize * WindowSize, 0);
2003+
LPCWSTR Args[] = {L"-HV 2021", L"-Vd"};
2004+
2005+
RunDXRTest(Device, ShaderSrc, L"lib_6_9", Args, _countof(Args), TestData,
2006+
WindowSize, WindowSize, true /*useMesh*/,
2007+
false /*useProceduralGeometry*/, false /*useIS*/);
2008+
std::map<int, int> Histo;
2009+
for (int Val : TestData)
2010+
++Histo[Val];
2011+
VERIFY_ARE_EQUAL(Histo.size(), 2);
2012+
VERIFY_ARE_EQUAL(Histo[2], 4030);
2013+
VERIFY_ARE_EQUAL(Histo[5], 66);
19022014
}

0 commit comments

Comments
 (0)