WebGPU error handling 1: Return error objects on errors.

Dawn used to return "nullptr" when an error happened while creating an
object. To match WebGPU we want to return valid pointers but to "error"
objects.

This commit implements WebGPU error handling for all "descriptorized"
objects and changes the nullptr error checks into "ValidateObject"
checks. This method is used both to check that the object isn't an
error, but also that all objects in a function call are from the same
device.

New validation is added to objects with methods (apart from Device) so
they check they aren't error objects.

A large number of ASSERTs were added to check that frontend objects
aren't accessed when they are errors, so that missing validation would
hit the asserts instead of crashing randomly.

The bind group validation tests were modified to test the behavior with
both nullptrs and error objects.

Future commits will change the CommandBufferBuilder to not be a builder
anymore but an "Encoder" instead with special-cased error handling. Then
once all objects are descriptorized, the notion of builders will be
removed from the code.

BUG=dawn:8

Change-Id: I8647712d5de3deb0e99e3bc58f34496f67710edd
Reviewed-on: https://dawn-review.googlesource.com/c/4360
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez
2019-02-13 13:09:18 +00:00
committed by Commit Bot service account
parent f872e6924c
commit a594f8fdb4
35 changed files with 471 additions and 112 deletions

View File

@@ -161,6 +161,19 @@ TEST_F(BindGroupValidationTest, SamplerBindingType) {
binding.buffer = mUBO;
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
binding.buffer = nullptr;
// Setting the sampler to an error sampler is an error.
{
dawn::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
samplerDesc.minFilter = static_cast<dawn::FilterMode>(0xFFFFFFFF);
dawn::Sampler errorSampler;
ASSERT_DEVICE_ERROR(errorSampler = device.CreateSampler(&samplerDesc));
binding.sampler = errorSampler;
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
binding.sampler = nullptr;
}
}
// Check that a texture binding must contain exactly a texture view
@@ -198,6 +211,24 @@ TEST_F(BindGroupValidationTest, TextureBindingType) {
binding.buffer = mUBO;
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
binding.buffer = nullptr;
// Setting the texture view to an error texture view is an error.
{
dawn::TextureViewDescriptor viewDesc;
viewDesc.format = dawn::TextureFormat::R8G8B8A8Unorm;
viewDesc.dimension = dawn::TextureViewDimension::e2D;
viewDesc.baseMipLevel = 0;
viewDesc.levelCount = 0;
viewDesc.baseArrayLayer = 0;
viewDesc.layerCount = 0;
dawn::TextureView errorView;
ASSERT_DEVICE_ERROR(errorView = mSampledTexture.CreateTextureView(&viewDesc));
binding.textureView = errorView;
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
binding.textureView = nullptr;
}
}
// Check that a buffer binding must contain exactly a buffer
@@ -235,6 +266,20 @@ TEST_F(BindGroupValidationTest, BufferBindingType) {
binding.sampler = mSampler;
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
binding.sampler = nullptr;
// Setting the buffer to an error buffer is an error.
{
dawn::BufferDescriptor bufferDesc;
bufferDesc.size = 1024;
bufferDesc.usage = static_cast<dawn::BufferUsageBit>(0xFFFFFFFF);
dawn::Buffer errorBuffer;
ASSERT_DEVICE_ERROR(errorBuffer = device.CreateBuffer(&bufferDesc));
binding.buffer = errorBuffer;
ASSERT_DEVICE_ERROR(device.CreateBindGroup(&descriptor));
binding.buffer = nullptr;
}
}
// Check that a texture must have the correct usage
@@ -338,6 +383,25 @@ TEST_F(BindGroupValidationTest, BufferBindingOOB) {
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, layout, {{0, buffer, 256, uint32_t(0) - uint32_t(256)}}));
}
// Test what happens when the layout is an error.
TEST_F(BindGroupValidationTest, ErrorLayout) {
dawn::BindGroupLayout goodLayout = utils::MakeBindGroupLayout(device, {
{0, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer},
});
dawn::BindGroupLayout errorLayout;
ASSERT_DEVICE_ERROR(errorLayout = utils::MakeBindGroupLayout(device, {
{0, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer},
{0, dawn::ShaderStageBit::Vertex, dawn::BindingType::UniformBuffer},
}));
// Control case, creating with the good layout works
utils::MakeBindGroup(device, goodLayout, {{0, mUBO, 0, 256}});
// Control case, creating with the good layout works
ASSERT_DEVICE_ERROR(utils::MakeBindGroup(device, errorLayout, {{0, mUBO, 0, 256}}));
}
class BindGroupLayoutValidationTest : public ValidationTest {
};