Standardize the use of UNREACHABLE in switches.

A lot of our switches over enum values use the following pattern:

    default:
        UNREACHABLE();
        return foo;

This is problematic because when adding a new value to one of the WebGPU
enums, there is no compilation error for switches that are missing it.
Currently we're supposed to write code and tests and fix UNREACHABLEs when
we see them.

Instead we should strive to have most switches on enums to be complete
and explicitily tag unreachable values as UNREACHABLE. Some switches
might still want to use default: UNREACHABLE() if only a couple values
need to be handled out of very many.

In this CL we go through all the UNRAECHABLEs and change them if need
be. Also an ErrorQueue class is added to avoid having
QueueBase::SubmitImpl just be UNREACHABLE (and force overriding
instead).

Bug: dawn:527
Change-Id: I33dfb4703104912cc5f001f9faf907a61324de68
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/28501
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
Corentin Wallez
2020-09-24 14:56:50 +00:00
committed by Commit Bot service account
parent a46737c0aa
commit eec9edfd57
42 changed files with 136 additions and 276 deletions

View File

@@ -42,7 +42,7 @@ namespace dawn_native { namespace opengl {
return GL_UNSIGNED_SHORT;
case wgpu::IndexFormat::Uint32:
return GL_UNSIGNED_INT;
default:
case wgpu::IndexFormat::Undefined:
UNREACHABLE();
}
}
@@ -87,8 +87,6 @@ namespace dawn_native { namespace opengl {
case wgpu::VertexFormat::Int3:
case wgpu::VertexFormat::Int4:
return GL_INT;
default:
UNREACHABLE();
}
}
@@ -328,9 +326,9 @@ namespace dawn_native { namespace opengl {
case wgpu::BindingType::WriteonlyStorageTexture:
access = GL_WRITE_ONLY;
break;
default:
UNREACHABLE();
break;
}
// OpenGL ES only supports either binding a layer or the entire texture
@@ -466,7 +464,7 @@ namespace dawn_native { namespace opengl {
case Command::BeginComputePass: {
mCommands.NextCommand<BeginComputePassCmd>();
TransitionForPass(passResourceUsages[nextPassNumber]);
ExecuteComputePass();
DAWN_TRY(ExecuteComputePass());
nextPassNumber++;
break;
@@ -477,7 +475,7 @@ namespace dawn_native { namespace opengl {
TransitionForPass(passResourceUsages[nextPassNumber]);
LazyClearRenderPassAttachments(cmd);
ExecuteRenderPass(cmd);
DAWN_TRY(ExecuteRenderPass(cmd));
nextPassNumber++;
break;
@@ -581,7 +579,8 @@ namespace dawn_native { namespace opengl {
}
break;
default:
case wgpu::TextureDimension::e1D:
case wgpu::TextureDimension::e3D:
UNREACHABLE();
}
}
@@ -649,9 +648,9 @@ namespace dawn_native { namespace opengl {
glFormat = GL_STENCIL_INDEX;
glType = GL_UNSIGNED_BYTE;
break;
default:
case Aspect::None:
UNREACHABLE();
break;
}
uint8_t* offset =
@@ -680,7 +679,8 @@ namespace dawn_native { namespace opengl {
break;
}
default:
case wgpu::TextureDimension::e1D:
case wgpu::TextureDimension::e3D:
UNREACHABLE();
}
@@ -730,9 +730,7 @@ namespace dawn_native { namespace opengl {
}
case Command::WriteTimestamp: {
// WriteTimestamp is not supported on OpenGL
UNREACHABLE();
break;
return DAWN_UNIMPLEMENTED_ERROR("WriteTimestamp unimplemented");
}
case Command::InsertDebugMarker:
@@ -744,17 +742,15 @@ namespace dawn_native { namespace opengl {
break;
}
default: {
default:
UNREACHABLE();
break;
}
}
}
return {};
}
void CommandBuffer::ExecuteComputePass() {
MaybeError CommandBuffer::ExecuteComputePass() {
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl;
ComputePipeline* lastPipeline = nullptr;
BindGroupTracker bindGroupTracker = {};
@@ -764,7 +760,7 @@ namespace dawn_native { namespace opengl {
switch (type) {
case Command::EndComputePass: {
mCommands.NextCommand<EndComputePassCmd>();
return;
return {};
}
case Command::Dispatch: {
@@ -821,15 +817,11 @@ namespace dawn_native { namespace opengl {
}
case Command::WriteTimestamp: {
// WriteTimestamp is not supported on OpenGL
UNREACHABLE();
break;
return DAWN_UNIMPLEMENTED_ERROR("WriteTimestamp unimplemented");
}
default: {
default:
UNREACHABLE();
break;
}
}
}
@@ -837,7 +829,7 @@ namespace dawn_native { namespace opengl {
UNREACHABLE();
}
void CommandBuffer::ExecuteRenderPass(BeginRenderPassCmd* renderPass) {
MaybeError CommandBuffer::ExecuteRenderPass(BeginRenderPassCmd* renderPass) {
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl;
GLuint fbo = 0;
@@ -1159,7 +1151,7 @@ namespace dawn_native { namespace opengl {
ResolveMultisampledRenderTargets(gl, renderPass);
}
gl.DeleteFramebuffers(1, &fbo);
return;
return {};
}
case Command::SetStencilReference: {
@@ -1202,11 +1194,8 @@ namespace dawn_native { namespace opengl {
break;
}
case Command::WriteTimestamp: {
// WriteTimestamp is not supported on OpenGL
UNREACHABLE();
break;
}
case Command::WriteTimestamp:
return DAWN_UNIMPLEMENTED_ERROR("WriteTimestamp unimplemented");
default: {
DoRenderBundleCommand(&mCommands, type);

View File

@@ -32,8 +32,8 @@ namespace dawn_native { namespace opengl {
MaybeError Execute();
private:
void ExecuteComputePass();
void ExecuteRenderPass(BeginRenderPassCmd* renderPass);
MaybeError ExecuteComputePass();
MaybeError ExecuteRenderPass(BeginRenderPassCmd* renderPass);
};
}} // namespace dawn_native::opengl

View File

@@ -37,8 +37,6 @@ namespace dawn_native { namespace opengl {
return GL_FRAGMENT_SHADER;
case SingleShaderStage::Compute:
return GL_COMPUTE_SHADER;
default:
UNREACHABLE();
}
}

View File

@@ -35,8 +35,6 @@ namespace dawn_native { namespace opengl {
return GL_TRIANGLES;
case wgpu::PrimitiveTopology::TriangleStrip:
return GL_TRIANGLE_STRIP;
default:
UNREACHABLE();
}
}
@@ -86,8 +84,6 @@ namespace dawn_native { namespace opengl {
return alpha ? GL_CONSTANT_ALPHA : GL_CONSTANT_COLOR;
case wgpu::BlendFactor::OneMinusBlendColor:
return alpha ? GL_ONE_MINUS_CONSTANT_ALPHA : GL_ONE_MINUS_CONSTANT_COLOR;
default:
UNREACHABLE();
}
}
@@ -103,8 +99,6 @@ namespace dawn_native { namespace opengl {
return GL_MIN;
case wgpu::BlendOperation::Max:
return GL_MAX;
default:
UNREACHABLE();
}
}
@@ -149,8 +143,6 @@ namespace dawn_native { namespace opengl {
return GL_INCR_WRAP;
case wgpu::StencilOperation::DecrementWrap:
return GL_DECR_WRAP;
default:
UNREACHABLE();
}
}
@@ -249,8 +241,6 @@ namespace dawn_native { namespace opengl {
case wgpu::InputStepMode::Instance:
gl.VertexAttribDivisor(glAttrib, 1);
break;
default:
UNREACHABLE();
}
}
}

View File

@@ -27,8 +27,6 @@ namespace dawn_native { namespace opengl {
return GL_NEAREST;
case wgpu::FilterMode::Linear:
return GL_LINEAR;
default:
UNREACHABLE();
}
}
@@ -40,8 +38,6 @@ namespace dawn_native { namespace opengl {
return GL_NEAREST_MIPMAP_NEAREST;
case wgpu::FilterMode::Linear:
return GL_NEAREST_MIPMAP_LINEAR;
default:
UNREACHABLE();
}
case wgpu::FilterMode::Linear:
switch (mipMapFilter) {
@@ -49,11 +45,7 @@ namespace dawn_native { namespace opengl {
return GL_LINEAR_MIPMAP_NEAREST;
case wgpu::FilterMode::Linear:
return GL_LINEAR_MIPMAP_LINEAR;
default:
UNREACHABLE();
}
default:
UNREACHABLE();
}
}
@@ -65,8 +57,6 @@ namespace dawn_native { namespace opengl {
return GL_MIRRORED_REPEAT;
case wgpu::AddressMode::ClampToEdge:
return GL_CLAMP_TO_EDGE;
default:
UNREACHABLE();
}
}

View File

@@ -40,9 +40,9 @@ namespace dawn_native { namespace opengl {
}
}
default:
case wgpu::TextureDimension::e1D:
case wgpu::TextureDimension::e3D:
UNREACHABLE();
return GL_TEXTURE_2D;
}
}
@@ -62,9 +62,11 @@ namespace dawn_native { namespace opengl {
return GL_TEXTURE_CUBE_MAP;
case wgpu::TextureViewDimension::CubeArray:
return GL_TEXTURE_CUBE_MAP_ARRAY;
default:
case wgpu::TextureViewDimension::e1D:
case wgpu::TextureViewDimension::e3D:
case wgpu::TextureViewDimension::Undefined:
UNREACHABLE();
return GL_TEXTURE_2D;
}
}
@@ -141,7 +143,9 @@ namespace dawn_native { namespace opengl {
}
}
break;
default:
case wgpu::TextureDimension::e1D:
case wgpu::TextureDimension::e3D:
UNREACHABLE();
}
@@ -279,7 +283,8 @@ namespace dawn_native { namespace opengl {
}
break;
default:
case wgpu::TextureDimension::e1D:
case wgpu::TextureDimension::e3D:
UNREACHABLE();
}
}
@@ -386,7 +391,8 @@ namespace dawn_native { namespace opengl {
}
break;
default:
case wgpu::TextureDimension::e1D:
case wgpu::TextureDimension::e3D:
UNREACHABLE();
}
}

View File

@@ -36,7 +36,8 @@ namespace dawn_native { namespace opengl {
return GL_EQUAL;
case wgpu::CompareFunction::Always:
return GL_ALWAYS;
default:
case wgpu::CompareFunction::Undefined:
UNREACHABLE();
}
}
@@ -45,6 +46,7 @@ namespace dawn_native { namespace opengl {
switch (depthStencilFormat) {
case wgpu::TextureFormat::Depth24PlusStencil8:
return 0xFF;
default:
UNREACHABLE();
}