Add end2end tests for noop direct and indirect dispatches
- Add more end2end tests for direct and indirect dispatches, including 0x0x0, 0xNxM, Nx0xM, NxMx0 - For direct dispatch, they will cause system crash on Metal backend. Bug: dawn:640 Change-Id: I77a4bee87df89857b05b713de8d78b0cb1f0ca50 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/39520 Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Hao Li <hao.x.li@intel.com>
This commit is contained in:
parent
5ab1ed7e1e
commit
d5a0728b67
|
@ -276,7 +276,7 @@ source_set("dawn_end2end_tests_sources") {
|
|||
"end2end/ColorStateTests.cpp",
|
||||
"end2end/CompressedTextureFormatTests.cpp",
|
||||
"end2end/ComputeCopyStorageBufferTests.cpp",
|
||||
"end2end/ComputeIndirectTests.cpp",
|
||||
"end2end/ComputeDispatchTests.cpp",
|
||||
"end2end/ComputeSharedMemoryTests.cpp",
|
||||
"end2end/ComputeStorageBufferBarrierTests.cpp",
|
||||
"end2end/CopyTests.cpp",
|
||||
|
|
|
@ -0,0 +1,211 @@
|
|||
// Copyright 2019 The Dawn Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "tests/DawnTest.h"
|
||||
|
||||
#include "utils/WGPUHelpers.h"
|
||||
|
||||
#include <initializer_list>
|
||||
|
||||
constexpr static std::initializer_list<uint32_t> kSentinelData{0, 0, 0};
|
||||
|
||||
class ComputeDispatchTests : public DawnTest {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
DawnTest::SetUp();
|
||||
|
||||
// Write workgroup number into the output buffer if we saw the biggest dispatch
|
||||
// This is a workaround since D3D12 doesn't have gl_NumWorkGroups
|
||||
// To make sure the dispatch was not called, write maximum u32 value for 0 dispatches
|
||||
wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, R"(
|
||||
[[block]] struct InputBuf {
|
||||
[[offset(0)]] expectedDispatch : vec3<u32>;
|
||||
};
|
||||
[[block]] struct OutputBuf {
|
||||
[[offset(0)]] workGroups : vec3<u32>;
|
||||
};
|
||||
|
||||
[[group(0), binding(0)]] var<uniform> input : InputBuf;
|
||||
[[group(0), binding(1)]] var<storage_buffer> output : OutputBuf;
|
||||
|
||||
[[builtin(global_invocation_id)]] var<in> GlobalInvocationID : vec3<u32>;
|
||||
|
||||
[[stage(compute), workgroup_size(1, 1, 1)]]
|
||||
fn main() -> void {
|
||||
const dispatch : vec3<u32> = input.expectedDispatch;
|
||||
|
||||
if (dispatch.x == 0 || dispatch.y == 0 || dispatch.z == 0) {
|
||||
output.workGroups = vec3<u32>(0xFFFFFFFFu, 0xFFFFFFFFu, 0xFFFFFFFFu);
|
||||
return;
|
||||
}
|
||||
|
||||
if (all(GlobalInvocationID == dispatch - vec3<u32>(1u, 1u, 1u))) {
|
||||
output.workGroups = dispatch;
|
||||
}
|
||||
})");
|
||||
|
||||
wgpu::ComputePipelineDescriptor csDesc;
|
||||
csDesc.computeStage.module = module;
|
||||
csDesc.computeStage.entryPoint = "main";
|
||||
pipeline = device.CreateComputePipeline(&csDesc);
|
||||
}
|
||||
|
||||
void DirectTest(uint32_t x, uint32_t y, uint32_t z) {
|
||||
// Set up dst storage buffer to contain dispatch x, y, z
|
||||
wgpu::Buffer dst = utils::CreateBufferFromData<uint32_t>(
|
||||
device,
|
||||
wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst,
|
||||
kSentinelData);
|
||||
|
||||
std::initializer_list<uint32_t> expectedBufferData{x, y, z};
|
||||
wgpu::Buffer expectedBuffer = utils::CreateBufferFromData<uint32_t>(
|
||||
device, wgpu::BufferUsage::Uniform, expectedBufferData);
|
||||
|
||||
// Set up bind group and issue dispatch
|
||||
wgpu::BindGroup bindGroup =
|
||||
utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0),
|
||||
{
|
||||
{0, expectedBuffer, 0, 3 * sizeof(uint32_t)},
|
||||
{1, dst, 0, 3 * sizeof(uint32_t)},
|
||||
});
|
||||
|
||||
wgpu::CommandBuffer commands;
|
||||
{
|
||||
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
|
||||
wgpu::ComputePassEncoder pass = encoder.BeginComputePass();
|
||||
pass.SetPipeline(pipeline);
|
||||
pass.SetBindGroup(0, bindGroup);
|
||||
pass.Dispatch(x, y, z);
|
||||
pass.EndPass();
|
||||
|
||||
commands = encoder.Finish();
|
||||
}
|
||||
|
||||
queue.Submit(1, &commands);
|
||||
|
||||
std::vector<uint32_t> expected =
|
||||
x == 0 || y == 0 || z == 0 ? kSentinelData : expectedBufferData;
|
||||
|
||||
// Verify the dispatch got called if all group counts are not zero
|
||||
EXPECT_BUFFER_U32_RANGE_EQ(&expected[0], dst, 0, 3);
|
||||
}
|
||||
|
||||
void IndirectTest(std::vector<uint32_t> indirectBufferData, uint64_t indirectOffset) {
|
||||
// Set up dst storage buffer to contain dispatch x, y, z
|
||||
wgpu::Buffer dst = utils::CreateBufferFromData<uint32_t>(
|
||||
device,
|
||||
wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst,
|
||||
kSentinelData);
|
||||
|
||||
wgpu::Buffer indirectBuffer = utils::CreateBufferFromData(
|
||||
device, &indirectBufferData[0], indirectBufferData.size() * sizeof(uint32_t),
|
||||
wgpu::BufferUsage::Indirect);
|
||||
|
||||
uint32_t indirectStart = indirectOffset / sizeof(uint32_t);
|
||||
|
||||
wgpu::Buffer expectedBuffer =
|
||||
utils::CreateBufferFromData(device, &indirectBufferData[indirectStart],
|
||||
3 * sizeof(uint32_t), wgpu::BufferUsage::Uniform);
|
||||
|
||||
// Set up bind group and issue dispatch
|
||||
wgpu::BindGroup bindGroup =
|
||||
utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0),
|
||||
{
|
||||
{0, expectedBuffer, 0, 3 * sizeof(uint32_t)},
|
||||
{1, dst, 0, 3 * sizeof(uint32_t)},
|
||||
});
|
||||
|
||||
wgpu::CommandBuffer commands;
|
||||
{
|
||||
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
|
||||
wgpu::ComputePassEncoder pass = encoder.BeginComputePass();
|
||||
pass.SetPipeline(pipeline);
|
||||
pass.SetBindGroup(0, bindGroup);
|
||||
pass.DispatchIndirect(indirectBuffer, indirectOffset);
|
||||
pass.EndPass();
|
||||
|
||||
commands = encoder.Finish();
|
||||
}
|
||||
|
||||
queue.Submit(1, &commands);
|
||||
|
||||
std::vector<uint32_t> expected;
|
||||
if (indirectBufferData[indirectStart] == 0 || indirectBufferData[indirectStart + 1] == 0 ||
|
||||
indirectBufferData[indirectStart + 2] == 0) {
|
||||
expected = kSentinelData;
|
||||
} else {
|
||||
expected.assign(indirectBufferData.begin() + indirectStart,
|
||||
indirectBufferData.begin() + indirectStart + 3);
|
||||
}
|
||||
|
||||
// Verify the dispatch got called with group counts in indirect buffer if all group counts
|
||||
// are not zero
|
||||
EXPECT_BUFFER_U32_RANGE_EQ(&expected[0], dst, 0, 3);
|
||||
}
|
||||
|
||||
private:
|
||||
wgpu::ComputePipeline pipeline;
|
||||
};
|
||||
|
||||
// Test basic direct
|
||||
TEST_P(ComputeDispatchTests, DirectBasic) {
|
||||
DirectTest(2, 3, 4);
|
||||
}
|
||||
|
||||
// Test no-op direct
|
||||
TEST_P(ComputeDispatchTests, DirectNoop) {
|
||||
// All dimensions are 0s
|
||||
DirectTest(0, 0, 0);
|
||||
|
||||
// Only x dimension is 0
|
||||
DirectTest(0, 3, 4);
|
||||
|
||||
// Only y dimension is 0
|
||||
DirectTest(2, 0, 4);
|
||||
|
||||
// Only z dimension is 0
|
||||
DirectTest(2, 3, 0);
|
||||
}
|
||||
|
||||
// Test basic indirect
|
||||
TEST_P(ComputeDispatchTests, IndirectBasic) {
|
||||
IndirectTest({2, 3, 4}, 0);
|
||||
}
|
||||
|
||||
// Test no-op indirect
|
||||
TEST_P(ComputeDispatchTests, IndirectNoop) {
|
||||
// All dimensions are 0s
|
||||
IndirectTest({0, 0, 0}, 0);
|
||||
|
||||
// Only x dimension is 0
|
||||
IndirectTest({0, 3, 4}, 0);
|
||||
|
||||
// Only y dimension is 0
|
||||
IndirectTest({2, 0, 4}, 0);
|
||||
|
||||
// Only z dimension is 0
|
||||
IndirectTest({2, 3, 0}, 0);
|
||||
}
|
||||
|
||||
// Test indirect with buffer offset
|
||||
TEST_P(ComputeDispatchTests, IndirectOffset) {
|
||||
IndirectTest({0, 0, 0, 2, 3, 4}, 3 * sizeof(uint32_t));
|
||||
}
|
||||
|
||||
DAWN_INSTANTIATE_TEST(ComputeDispatchTests,
|
||||
D3D12Backend(),
|
||||
MetalBackend(),
|
||||
OpenGLBackend(),
|
||||
OpenGLESBackend(),
|
||||
VulkanBackend());
|
|
@ -1,115 +0,0 @@
|
|||
// Copyright 2019 The Dawn Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "tests/DawnTest.h"
|
||||
|
||||
#include "utils/WGPUHelpers.h"
|
||||
|
||||
#include <array>
|
||||
#include <initializer_list>
|
||||
|
||||
class ComputeIndirectTests : public DawnTest {
|
||||
public:
|
||||
void BasicTest(std::initializer_list<uint32_t> buffer, uint64_t indirectOffset);
|
||||
};
|
||||
|
||||
void ComputeIndirectTests::BasicTest(std::initializer_list<uint32_t> bufferList,
|
||||
uint64_t indirectOffset) {
|
||||
// Set up shader and pipeline
|
||||
|
||||
// Write into the output buffer if we saw the biggest dispatch
|
||||
// This is a workaround since D3D12 doesn't have gl_NumWorkGroups
|
||||
wgpu::ShaderModule module = utils::CreateShaderModuleFromWGSL(device, R"(
|
||||
[[block]] struct InputBuf {
|
||||
[[offset(0)]] expectedDispatch : vec3<u32>;
|
||||
};
|
||||
[[block]] struct OutputBuf {
|
||||
[[offset(0)]] workGroups : vec3<u32>;
|
||||
};
|
||||
|
||||
[[group(0), binding(0)]] var<uniform> input : InputBuf;
|
||||
[[group(0), binding(1)]] var<storage_buffer> output : OutputBuf;
|
||||
|
||||
[[builtin(global_invocation_id)]] var<in> GlobalInvocationID : vec3<u32>;
|
||||
|
||||
[[stage(compute), workgroup_size(1, 1, 1)]]
|
||||
fn main() -> void {
|
||||
if (all(GlobalInvocationID == input.expectedDispatch - vec3<u32>(1u, 1u, 1u))) {
|
||||
output.workGroups = input.expectedDispatch;
|
||||
}
|
||||
return;
|
||||
})");
|
||||
|
||||
wgpu::ComputePipelineDescriptor csDesc;
|
||||
csDesc.computeStage.module = module;
|
||||
csDesc.computeStage.entryPoint = "main";
|
||||
wgpu::ComputePipeline pipeline = device.CreateComputePipeline(&csDesc);
|
||||
|
||||
// Set up dst storage buffer to contain dispatch x, y, z
|
||||
wgpu::Buffer dst = utils::CreateBufferFromData<uint32_t>(
|
||||
device,
|
||||
wgpu::BufferUsage::Storage | wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst,
|
||||
{0, 0, 0});
|
||||
|
||||
std::vector<uint32_t> indirectBufferData = bufferList;
|
||||
|
||||
wgpu::Buffer indirectBuffer =
|
||||
utils::CreateBufferFromData<uint32_t>(device, wgpu::BufferUsage::Indirect, bufferList);
|
||||
|
||||
wgpu::Buffer expectedBuffer =
|
||||
utils::CreateBufferFromData(device, &indirectBufferData[indirectOffset / sizeof(uint32_t)],
|
||||
3 * sizeof(uint32_t), wgpu::BufferUsage::Uniform);
|
||||
|
||||
// Set up bind group and issue dispatch
|
||||
wgpu::BindGroup bindGroup =
|
||||
utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0),
|
||||
{
|
||||
{0, expectedBuffer, 0, 3 * sizeof(uint32_t)},
|
||||
{1, dst, 0, 3 * sizeof(uint32_t)},
|
||||
});
|
||||
|
||||
wgpu::CommandBuffer commands;
|
||||
{
|
||||
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
|
||||
wgpu::ComputePassEncoder pass = encoder.BeginComputePass();
|
||||
pass.SetPipeline(pipeline);
|
||||
pass.SetBindGroup(0, bindGroup);
|
||||
pass.DispatchIndirect(indirectBuffer, indirectOffset);
|
||||
pass.EndPass();
|
||||
|
||||
commands = encoder.Finish();
|
||||
}
|
||||
|
||||
queue.Submit(1, &commands);
|
||||
|
||||
// Verify the dispatch got called with group counts in indirect buffer
|
||||
EXPECT_BUFFER_U32_RANGE_EQ(&indirectBufferData[indirectOffset / sizeof(uint32_t)], dst, 0, 3);
|
||||
}
|
||||
|
||||
// Test basic indirect
|
||||
TEST_P(ComputeIndirectTests, Basic) {
|
||||
BasicTest({2, 3, 4}, 0);
|
||||
}
|
||||
|
||||
// Test indirect with buffer offset
|
||||
TEST_P(ComputeIndirectTests, IndirectOffset) {
|
||||
BasicTest({0, 0, 0, 2, 3, 4}, 3 * sizeof(uint32_t));
|
||||
}
|
||||
|
||||
DAWN_INSTANTIATE_TEST(ComputeIndirectTests,
|
||||
D3D12Backend(),
|
||||
MetalBackend(),
|
||||
OpenGLBackend(),
|
||||
OpenGLESBackend(),
|
||||
VulkanBackend());
|
Loading…
Reference in New Issue