Implement drawIndexedIndirect validation

Every render pass which invokes DrawIndexedIndirect, either directly or
through a RenderBundle execution, is now preceded immediately by at
least one validation pass.

All indirect buffer offests used with DII are validated, and their
validated values are copied into a separate scratch buffer (or zeroed
out there, in the case of validation failure). All encoded DII commands
are rewritten to use the validated parameters instead of the original
ones.

Bug: dawn:809
Change-Id: I5eead937f19536f84f89e2c8e6fed7f18f0aee9f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/63461
Commit-Queue: Ken Rockot <rockot@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Ken Rockot
2021-09-23 00:15:19 +00:00
committed by Dawn LUCI CQ
parent 95cfd263ab
commit ebf183bde4
36 changed files with 1585 additions and 120 deletions

View File

@@ -28,87 +28,6 @@ class UnsafeAPIValidationTest : public ValidationTest {
}
};
// Check that DrawIndexedIndirect is disallowed as part of unsafe APIs.
TEST_F(UnsafeAPIValidationTest, DrawIndexedIndirectDisallowed) {
// Create the index and indirect buffers.
wgpu::BufferDescriptor indexBufferDesc;
indexBufferDesc.size = 4;
indexBufferDesc.usage = wgpu::BufferUsage::Index;
wgpu::Buffer indexBuffer = device.CreateBuffer(&indexBufferDesc);
wgpu::BufferDescriptor indirectBufferDesc;
indirectBufferDesc.size = 64;
indirectBufferDesc.usage = wgpu::BufferUsage::Indirect;
wgpu::Buffer indirectBuffer = device.CreateBuffer(&indirectBufferDesc);
// The RenderPassDescriptor, RenderBundleDescriptor and pipeline for all sub-tests below.
DummyRenderPass renderPass(device);
utils::ComboRenderBundleEncoderDescriptor bundleDesc = {};
bundleDesc.colorFormatsCount = 1;
bundleDesc.cColorFormats[0] = renderPass.attachmentFormat;
utils::ComboRenderPipelineDescriptor desc;
desc.vertex.module = utils::CreateShaderModule(
device,
R"([[stage(vertex)]] fn main() -> [[builtin(position)]] vec4<f32> {
return vec4<f32>();
})");
desc.cFragment.module = utils::CreateShaderModule(device, "[[stage(fragment)]] fn main() {}");
desc.cTargets[0].writeMask = wgpu::ColorWriteMask::None;
wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&desc);
// Control cases: DrawIndirect and DrawIndexed are allowed inside a render pass.
{
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
pass.SetPipeline(pipeline);
pass.SetIndexBuffer(indexBuffer, wgpu::IndexFormat::Uint32);
pass.DrawIndexed(1);
pass.DrawIndirect(indirectBuffer, 0);
pass.EndPass();
encoder.Finish();
}
// Control case: DrawIndirect and DrawIndexed are allowed inside a render bundle.
{
wgpu::RenderBundleEncoder encoder = device.CreateRenderBundleEncoder(&bundleDesc);
encoder.SetPipeline(pipeline);
encoder.SetIndexBuffer(indexBuffer, wgpu::IndexFormat::Uint32);
encoder.DrawIndexed(1);
encoder.DrawIndirect(indirectBuffer, 0);
encoder.Finish();
}
// Error case, DrawIndexedIndirect is disallowed inside a render pass.
{
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
wgpu::RenderPassEncoder pass = encoder.BeginRenderPass(&renderPass);
pass.SetPipeline(pipeline);
pass.SetIndexBuffer(indexBuffer, wgpu::IndexFormat::Uint32);
pass.DrawIndexedIndirect(indirectBuffer, 0);
pass.EndPass();
ASSERT_DEVICE_ERROR(encoder.Finish());
}
// Error case, DrawIndexedIndirect is disallowed inside a render bundle.
{
wgpu::RenderBundleEncoder encoder = device.CreateRenderBundleEncoder(&bundleDesc);
encoder.SetPipeline(pipeline);
encoder.SetIndexBuffer(indexBuffer, wgpu::IndexFormat::Uint32);
encoder.DrawIndexedIndirect(indirectBuffer, 0);
ASSERT_DEVICE_ERROR(encoder.Finish());
}
}
// Check that DispatchIndirect is disallowed as part of unsafe APIs.
TEST_F(UnsafeAPIValidationTest, DispatchIndirectDisallowed) {
// Create the index and indirect buffers.