MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/Falcor / testWaveMinMax

Function testWaveMinMax

Source/Tools/FalcorTest/Tests/Slang/WaveOps.cpp:113–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111}
112
113void testWaveMinMax(GPUUnitTestContext& ctx, bool conditional)
114{
115 ref<Device> pDevice = ctx.getDevice();
116
117 DefineList defines = {{"CONDITIONAL", conditional ? "1" : "0"}};
118 ctx.createProgram(kShaderFilename, "testWaveMinMax", defines, SlangCompilerFlags::None, ShaderModel::SM6_0);
119 ctx.allocateStructuredBuffer("result", kNumElems * 2);
120
121 auto var = ctx.vars().getRootVar();
122 uint32_t zero = 0;
123 auto pLaneCount = pDevice->createTypedBuffer<uint32_t>(1, ResourceBindFlags::UnorderedAccess, MemoryType::DeviceLocal, &zero);
124 var["laneCount"] = pLaneCount;
125
126 std::uniform_real_distribution<float> u(0.f, 1.f);
127 std::vector<float> testData(kNumElems);
128 for (size_t i = 0; i < testData.size(); i += 32)
129 {
130 float offset = 10.f * u(rng) - 5.f;
131 for (size_t j = 0; j < 32; j++)
132 testData[i + j] = offset + 2.f * u(rng) - 1.f;
133 }
134 var["testData"] = pDevice->createTypedBuffer<uint32_t>(
135 kNumElems, ResourceBindFlags::ShaderResource, MemoryType::DeviceLocal, (uint32_t*)testData.data()
136 );
137
138 ctx.runProgram(kNumElems, 1, 1);
139
140 // Get the lane count. We abort the test if it is an unsupported count.
141 uint32_t laneCount = pLaneCount->getElement<uint32_t>(0);
142 if (laneCount < 4 || laneCount > 128)
143 FALCOR_THROW("Unsupported wave lane count");
144
145 // Verify results of wave min/max.
146 std::vector<float> expectedResult = computeMinMaxResult(testData, laneCount, conditional);
147 FALCOR_ASSERT(expectedResult.size() == testData.size() * 2);
148
149 std::vector<float4> result = ctx.readBuffer<float4>("result");
150 for (size_t i = 0; i < testData.size(); i++)
151 {
152 EXPECT_EQ(result[2 * i + 0].x, expectedResult[2 * i + 0]) << "WaveActiveMin (i = " << i << ")";
153 EXPECT_EQ(result[2 * i + 1].x, expectedResult[2 * i + 1]) << "WaveActiveMax (i = " << i << ")";
154 }
155}
156
157uint32_t queryLaneCount(GPUUnitTestContext& ctx)
158{

Callers 2

GPU_TESTFunction · 0.85
WaveOps.cppFile · 0.85

Calls 9

computeMinMaxResultFunction · 0.85
getRootVarMethod · 0.80
runProgramMethod · 0.80
uFunction · 0.50
getDeviceMethod · 0.45
createProgramMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected