Rename Error.h macros from NXT to DAWN

This commit is contained in:
Corentin Wallez 2018-07-18 11:45:17 +02:00 committed by Corentin Wallez
parent 226110f958
commit 33ca49614d
11 changed files with 152 additions and 152 deletions

View File

@ -24,7 +24,7 @@ namespace backend {
return {}; return {};
{% endfor %} {% endfor %}
default: default:
NXT_RETURN_ERROR("Invalid value for {{as_cType(type.name)}}"); DAWN_RETURN_ERROR("Invalid value for {{as_cType(type.name)}}");
} }
} }
@ -35,7 +35,7 @@ namespace backend {
if ((value & static_cast<nxt::{{as_cppType(type.name)}}>(~{{type.full_mask}})) == 0) { if ((value & static_cast<nxt::{{as_cppType(type.name)}}>(~{{type.full_mask}})) == 0) {
return {}; return {};
} }
NXT_RETURN_ERROR("Invalid value for {{as_cType(type.name)}}"); DAWN_RETURN_ERROR("Invalid value for {{as_cType(type.name)}}");
} }
{% endfor %} {% endfor %}

View File

@ -260,7 +260,7 @@
namespace nxt { namespace wire { namespace nxt { namespace wire {
// Macro to simplify error handling, similar to NXT_TRY but for DeserializeResult. // Macro to simplify error handling, similar to DAWN_TRY but for DeserializeResult.
#define DESERIALIZE_TRY(EXPR) \ #define DESERIALIZE_TRY(EXPR) \
{ \ { \
DeserializeResult exprResult = EXPR; \ DeserializeResult exprResult = EXPR; \

View File

@ -26,17 +26,17 @@ namespace backend {
MaybeError ValidateBindGroupLayoutDescriptor( MaybeError ValidateBindGroupLayoutDescriptor(
DeviceBase*, DeviceBase*,
const dawn::BindGroupLayoutDescriptor* descriptor) { const dawn::BindGroupLayoutDescriptor* descriptor) {
NXT_TRY_ASSERT(descriptor->nextInChain == nullptr, "nextInChain must be nullptr"); DAWN_TRY_ASSERT(descriptor->nextInChain == nullptr, "nextInChain must be nullptr");
std::bitset<kMaxBindingsPerGroup> bindingsSet; std::bitset<kMaxBindingsPerGroup> bindingsSet;
for (uint32_t i = 0; i < descriptor->numBindings; ++i) { for (uint32_t i = 0; i < descriptor->numBindings; ++i) {
auto& binding = descriptor->bindings[i]; auto& binding = descriptor->bindings[i];
NXT_TRY_ASSERT(binding.binding <= kMaxBindingsPerGroup, DAWN_TRY_ASSERT(binding.binding <= kMaxBindingsPerGroup,
"some binding index exceeds the maximum value"); "some binding index exceeds the maximum value");
NXT_TRY(ValidateShaderStageBit(binding.visibility)); DAWN_TRY(ValidateShaderStageBit(binding.visibility));
NXT_TRY(ValidateBindingType(binding.type)); DAWN_TRY(ValidateBindingType(binding.type));
NXT_TRY_ASSERT(!bindingsSet[i], "some binding index was specified more than once"); DAWN_TRY_ASSERT(!bindingsSet[i], "some binding index was specified more than once");
bindingsSet.set(binding.binding); bindingsSet.set(binding.binding);
} }
return {}; return {};

View File

@ -35,7 +35,7 @@ namespace backend {
MaybeError ValidateCopyLocationFitsInTexture(const TextureCopyLocation& location) { MaybeError ValidateCopyLocationFitsInTexture(const TextureCopyLocation& location) {
const TextureBase* texture = location.texture.Get(); const TextureBase* texture = location.texture.Get();
if (location.level >= texture->GetNumMipLevels()) { if (location.level >= texture->GetNumMipLevels()) {
NXT_RETURN_ERROR("Copy mip-level out of range"); DAWN_RETURN_ERROR("Copy mip-level out of range");
} }
// All texture dimensions are in uint32_t so by doing checks in uint64_t we avoid // All texture dimensions are in uint32_t so by doing checks in uint64_t we avoid
@ -45,13 +45,13 @@ namespace backend {
(static_cast<uint64_t>(texture->GetWidth()) >> level) || (static_cast<uint64_t>(texture->GetWidth()) >> level) ||
uint64_t(location.y) + uint64_t(location.height) > uint64_t(location.y) + uint64_t(location.height) >
(static_cast<uint64_t>(texture->GetHeight()) >> level)) { (static_cast<uint64_t>(texture->GetHeight()) >> level)) {
NXT_RETURN_ERROR("Copy would touch outside of the texture"); DAWN_RETURN_ERROR("Copy would touch outside of the texture");
} }
// TODO(cwallez@chromium.org): Check the depth bound differently for 2D arrays and 3D // TODO(cwallez@chromium.org): Check the depth bound differently for 2D arrays and 3D
// textures // textures
if (location.z != 0 || location.depth != 1) { if (location.z != 0 || location.depth != 1) {
NXT_RETURN_ERROR("No support for z != 0 and depth != 1 for now"); DAWN_RETURN_ERROR("No support for z != 0 and depth != 1 for now");
} }
return {}; return {};
@ -65,7 +65,7 @@ namespace backend {
MaybeError ValidateCopySizeFitsInBuffer(const BufferCopyLocation& location, MaybeError ValidateCopySizeFitsInBuffer(const BufferCopyLocation& location,
uint32_t dataSize) { uint32_t dataSize) {
if (!FitsInBuffer(location.buffer.Get(), location.offset, dataSize)) { if (!FitsInBuffer(location.buffer.Get(), location.offset, dataSize)) {
NXT_RETURN_ERROR("Copy would overflow the buffer"); DAWN_RETURN_ERROR("Copy would overflow the buffer");
} }
return {}; return {};
@ -76,7 +76,7 @@ namespace backend {
uint32_t texelSize = uint32_t texelSize =
static_cast<uint32_t>(TextureFormatPixelSize(texture->GetFormat())); static_cast<uint32_t>(TextureFormatPixelSize(texture->GetFormat()));
if (location.offset % texelSize != 0) { if (location.offset % texelSize != 0) {
NXT_RETURN_ERROR("Buffer offset must be a multiple of the texel size"); DAWN_RETURN_ERROR("Buffer offset must be a multiple of the texel size");
} }
return {}; return {};
@ -98,12 +98,12 @@ namespace backend {
MaybeError ValidateRowPitch(const TextureCopyLocation& location, uint32_t rowPitch) { MaybeError ValidateRowPitch(const TextureCopyLocation& location, uint32_t rowPitch) {
if (rowPitch % kTextureRowPitchAlignment != 0) { if (rowPitch % kTextureRowPitchAlignment != 0) {
NXT_RETURN_ERROR("Row pitch must be a multiple of 256"); DAWN_RETURN_ERROR("Row pitch must be a multiple of 256");
} }
uint32_t texelSize = TextureFormatPixelSize(location.texture.Get()->GetFormat()); uint32_t texelSize = TextureFormatPixelSize(location.texture.Get()->GetFormat());
if (rowPitch < location.width * texelSize) { if (rowPitch < location.width * texelSize) {
NXT_RETURN_ERROR("Row pitch must not be less than the number of bytes per row"); DAWN_RETURN_ERROR("Row pitch must not be less than the number of bytes per row");
} }
return {}; return {};
@ -112,7 +112,7 @@ namespace backend {
MaybeError ValidateCanUseAs(BufferBase* buffer, dawn::BufferUsageBit usage) { MaybeError ValidateCanUseAs(BufferBase* buffer, dawn::BufferUsageBit usage) {
ASSERT(HasZeroOrOneBits(usage)); ASSERT(HasZeroOrOneBits(usage));
if (!(buffer->GetAllowedUsage() & usage)) { if (!(buffer->GetAllowedUsage() & usage)) {
NXT_RETURN_ERROR("buffer doesn't have the required usage."); DAWN_RETURN_ERROR("buffer doesn't have the required usage.");
} }
return {}; return {};
@ -121,7 +121,7 @@ namespace backend {
MaybeError ValidateCanUseAs(TextureBase* texture, dawn::TextureUsageBit usage) { MaybeError ValidateCanUseAs(TextureBase* texture, dawn::TextureUsageBit usage) {
ASSERT(HasZeroOrOneBits(usage)); ASSERT(HasZeroOrOneBits(usage));
if (!(texture->GetAllowedUsage() & usage)) { if (!(texture->GetAllowedUsage() & usage)) {
NXT_RETURN_ERROR("texture doesn't have the required usage."); DAWN_RETURN_ERROR("texture doesn't have the required usage.");
} }
return {}; return {};
@ -168,7 +168,7 @@ namespace backend {
MaybeError ValidateUsages(PassType pass) const { MaybeError ValidateUsages(PassType pass) const {
// Storage resources cannot be used twice in the same compute pass // Storage resources cannot be used twice in the same compute pass
if (pass == PassType::Compute && mStorageUsedMultipleTimes) { if (pass == PassType::Compute && mStorageUsedMultipleTimes) {
NXT_RETURN_ERROR("Storage resource used multiple times in compute pass"); DAWN_RETURN_ERROR("Storage resource used multiple times in compute pass");
} }
// Buffers can only be used as single-write or multiple read. // Buffers can only be used as single-write or multiple read.
@ -177,14 +177,14 @@ namespace backend {
dawn::BufferUsageBit usage = it.second; dawn::BufferUsageBit usage = it.second;
if (usage & ~buffer->GetAllowedUsage()) { if (usage & ~buffer->GetAllowedUsage()) {
NXT_RETURN_ERROR("Buffer missing usage for the pass"); DAWN_RETURN_ERROR("Buffer missing usage for the pass");
} }
bool readOnly = (usage & kReadOnlyBufferUsages) == usage; bool readOnly = (usage & kReadOnlyBufferUsages) == usage;
bool singleUse = dawn::HasZeroOrOneBits(usage); bool singleUse = dawn::HasZeroOrOneBits(usage);
if (!readOnly && !singleUse) { if (!readOnly && !singleUse) {
NXT_RETURN_ERROR( DAWN_RETURN_ERROR(
"Buffer used as writeable usage and another usage in pass"); "Buffer used as writeable usage and another usage in pass");
} }
} }
@ -196,13 +196,13 @@ namespace backend {
dawn::TextureUsageBit usage = it.second; dawn::TextureUsageBit usage = it.second;
if (usage & ~texture->GetAllowedUsage()) { if (usage & ~texture->GetAllowedUsage()) {
NXT_RETURN_ERROR("Texture missing usage for the pass"); DAWN_RETURN_ERROR("Texture missing usage for the pass");
} }
// For textures the only read-only usage in a pass is Sampled, so checking the // For textures the only read-only usage in a pass is Sampled, so checking the
// usage constraint simplifies to checking a single usage bit is set. // usage constraint simplifies to checking a single usage bit is set.
if (!dawn::HasZeroOrOneBits(it.second)) { if (!dawn::HasZeroOrOneBits(it.second)) {
NXT_RETURN_ERROR("Texture used with more than one usage in pass"); DAWN_RETURN_ERROR("Texture used with more than one usage in pass");
} }
} }
@ -324,66 +324,66 @@ namespace backend {
switch (type) { switch (type) {
case Command::BeginComputePass: { case Command::BeginComputePass: {
mIterator.NextCommand<BeginComputePassCmd>(); mIterator.NextCommand<BeginComputePassCmd>();
NXT_TRY(ValidateComputePass()); DAWN_TRY(ValidateComputePass());
} break; } break;
case Command::BeginRenderPass: { case Command::BeginRenderPass: {
BeginRenderPassCmd* cmd = mIterator.NextCommand<BeginRenderPassCmd>(); BeginRenderPassCmd* cmd = mIterator.NextCommand<BeginRenderPassCmd>();
NXT_TRY(ValidateRenderPass(cmd->info.Get())); DAWN_TRY(ValidateRenderPass(cmd->info.Get()));
} break; } break;
case Command::CopyBufferToBuffer: { case Command::CopyBufferToBuffer: {
CopyBufferToBufferCmd* copy = mIterator.NextCommand<CopyBufferToBufferCmd>(); CopyBufferToBufferCmd* copy = mIterator.NextCommand<CopyBufferToBufferCmd>();
NXT_TRY(ValidateCopySizeFitsInBuffer(copy->source, copy->size)); DAWN_TRY(ValidateCopySizeFitsInBuffer(copy->source, copy->size));
NXT_TRY(ValidateCopySizeFitsInBuffer(copy->destination, copy->size)); DAWN_TRY(ValidateCopySizeFitsInBuffer(copy->destination, copy->size));
NXT_TRY(ValidateCanUseAs(copy->source.buffer.Get(), DAWN_TRY(ValidateCanUseAs(copy->source.buffer.Get(),
dawn::BufferUsageBit::TransferSrc)); dawn::BufferUsageBit::TransferSrc));
NXT_TRY(ValidateCanUseAs(copy->destination.buffer.Get(), DAWN_TRY(ValidateCanUseAs(copy->destination.buffer.Get(),
dawn::BufferUsageBit::TransferDst)); dawn::BufferUsageBit::TransferDst));
} break; } break;
case Command::CopyBufferToTexture: { case Command::CopyBufferToTexture: {
CopyBufferToTextureCmd* copy = mIterator.NextCommand<CopyBufferToTextureCmd>(); CopyBufferToTextureCmd* copy = mIterator.NextCommand<CopyBufferToTextureCmd>();
uint32_t bufferCopySize = 0; uint32_t bufferCopySize = 0;
NXT_TRY(ValidateRowPitch(copy->destination, copy->rowPitch)); DAWN_TRY(ValidateRowPitch(copy->destination, copy->rowPitch));
NXT_TRY(ComputeTextureCopyBufferSize(copy->destination, copy->rowPitch, DAWN_TRY(ComputeTextureCopyBufferSize(copy->destination, copy->rowPitch,
&bufferCopySize)); &bufferCopySize));
NXT_TRY(ValidateCopyLocationFitsInTexture(copy->destination)); DAWN_TRY(ValidateCopyLocationFitsInTexture(copy->destination));
NXT_TRY(ValidateCopySizeFitsInBuffer(copy->source, bufferCopySize)); DAWN_TRY(ValidateCopySizeFitsInBuffer(copy->source, bufferCopySize));
NXT_TRY( DAWN_TRY(
ValidateTexelBufferOffset(copy->destination.texture.Get(), copy->source)); ValidateTexelBufferOffset(copy->destination.texture.Get(), copy->source));
NXT_TRY(ValidateCanUseAs(copy->source.buffer.Get(), DAWN_TRY(ValidateCanUseAs(copy->source.buffer.Get(),
dawn::BufferUsageBit::TransferSrc)); dawn::BufferUsageBit::TransferSrc));
NXT_TRY(ValidateCanUseAs(copy->destination.texture.Get(), DAWN_TRY(ValidateCanUseAs(copy->destination.texture.Get(),
dawn::TextureUsageBit::TransferDst)); dawn::TextureUsageBit::TransferDst));
} break; } break;
case Command::CopyTextureToBuffer: { case Command::CopyTextureToBuffer: {
CopyTextureToBufferCmd* copy = mIterator.NextCommand<CopyTextureToBufferCmd>(); CopyTextureToBufferCmd* copy = mIterator.NextCommand<CopyTextureToBufferCmd>();
uint32_t bufferCopySize = 0; uint32_t bufferCopySize = 0;
NXT_TRY(ValidateRowPitch(copy->source, copy->rowPitch)); DAWN_TRY(ValidateRowPitch(copy->source, copy->rowPitch));
NXT_TRY(ComputeTextureCopyBufferSize(copy->source, copy->rowPitch, DAWN_TRY(ComputeTextureCopyBufferSize(copy->source, copy->rowPitch,
&bufferCopySize)); &bufferCopySize));
NXT_TRY(ValidateCopyLocationFitsInTexture(copy->source)); DAWN_TRY(ValidateCopyLocationFitsInTexture(copy->source));
NXT_TRY(ValidateCopySizeFitsInBuffer(copy->destination, bufferCopySize)); DAWN_TRY(ValidateCopySizeFitsInBuffer(copy->destination, bufferCopySize));
NXT_TRY( DAWN_TRY(
ValidateTexelBufferOffset(copy->source.texture.Get(), copy->destination)); ValidateTexelBufferOffset(copy->source.texture.Get(), copy->destination));
NXT_TRY(ValidateCanUseAs(copy->source.texture.Get(), DAWN_TRY(ValidateCanUseAs(copy->source.texture.Get(),
dawn::TextureUsageBit::TransferSrc)); dawn::TextureUsageBit::TransferSrc));
NXT_TRY(ValidateCanUseAs(copy->destination.buffer.Get(), DAWN_TRY(ValidateCanUseAs(copy->destination.buffer.Get(),
dawn::BufferUsageBit::TransferDst)); dawn::BufferUsageBit::TransferDst));
} break; } break;
default: default:
NXT_RETURN_ERROR("Command disallowed outside of a pass"); DAWN_RETURN_ERROR("Command disallowed outside of a pass");
} }
} }
@ -399,7 +399,7 @@ namespace backend {
case Command::EndComputePass: { case Command::EndComputePass: {
mIterator.NextCommand<EndComputePassCmd>(); mIterator.NextCommand<EndComputePassCmd>();
NXT_TRY(usageTracker.ValidateUsages(PassType::Compute)); DAWN_TRY(usageTracker.ValidateUsages(PassType::Compute));
mPassResourceUsages.push_back(usageTracker.AcquireResourceUsage()); mPassResourceUsages.push_back(usageTracker.AcquireResourceUsage());
mState->EndPass(); mState->EndPass();
@ -408,7 +408,7 @@ namespace backend {
case Command::Dispatch: { case Command::Dispatch: {
mIterator.NextCommand<DispatchCmd>(); mIterator.NextCommand<DispatchCmd>();
NXT_TRY(mState->ValidateCanDispatch()); DAWN_TRY(mState->ValidateCanDispatch());
} break; } break;
case Command::SetComputePipeline: { case Command::SetComputePipeline: {
@ -424,7 +424,7 @@ namespace backend {
// recorded because it impacts the size of an allocation in the // recorded because it impacts the size of an allocation in the
// CommandAllocator. // CommandAllocator.
if (cmd->stages & ~dawn::ShaderStageBit::Compute) { if (cmd->stages & ~dawn::ShaderStageBit::Compute) {
NXT_RETURN_ERROR( DAWN_RETURN_ERROR(
"SetPushConstants stage must be compute or 0 in compute passes"); "SetPushConstants stage must be compute or 0 in compute passes");
} }
} break; } break;
@ -437,11 +437,11 @@ namespace backend {
} break; } break;
default: default:
NXT_RETURN_ERROR("Command disallowed inside a compute pass"); DAWN_RETURN_ERROR("Command disallowed inside a compute pass");
} }
} }
NXT_RETURN_ERROR("Unfinished compute pass"); DAWN_RETURN_ERROR("Unfinished compute pass");
} }
MaybeError CommandBufferBuilder::ValidateRenderPass(RenderPassDescriptorBase* renderPass) { MaybeError CommandBufferBuilder::ValidateRenderPass(RenderPassDescriptorBase* renderPass) {
@ -464,7 +464,7 @@ namespace backend {
case Command::EndRenderPass: { case Command::EndRenderPass: {
mIterator.NextCommand<EndRenderPassCmd>(); mIterator.NextCommand<EndRenderPassCmd>();
NXT_TRY(usageTracker.ValidateUsages(PassType::Render)); DAWN_TRY(usageTracker.ValidateUsages(PassType::Render));
mPassResourceUsages.push_back(usageTracker.AcquireResourceUsage()); mPassResourceUsages.push_back(usageTracker.AcquireResourceUsage());
mState->EndPass(); mState->EndPass();
@ -473,12 +473,12 @@ namespace backend {
case Command::DrawArrays: { case Command::DrawArrays: {
mIterator.NextCommand<DrawArraysCmd>(); mIterator.NextCommand<DrawArraysCmd>();
NXT_TRY(mState->ValidateCanDrawArrays()); DAWN_TRY(mState->ValidateCanDrawArrays());
} break; } break;
case Command::DrawElements: { case Command::DrawElements: {
mIterator.NextCommand<DrawElementsCmd>(); mIterator.NextCommand<DrawElementsCmd>();
NXT_TRY(mState->ValidateCanDrawElements()); DAWN_TRY(mState->ValidateCanDrawElements());
} break; } break;
case Command::SetRenderPipeline: { case Command::SetRenderPipeline: {
@ -486,7 +486,7 @@ namespace backend {
RenderPipelineBase* pipeline = cmd->pipeline.Get(); RenderPipelineBase* pipeline = cmd->pipeline.Get();
if (!pipeline->IsCompatibleWith(renderPass)) { if (!pipeline->IsCompatibleWith(renderPass)) {
NXT_RETURN_ERROR("Pipeline is incompatible with this render pass"); DAWN_RETURN_ERROR("Pipeline is incompatible with this render pass");
} }
mState->SetRenderPipeline(pipeline); mState->SetRenderPipeline(pipeline);
@ -500,7 +500,7 @@ namespace backend {
// CommandAllocator. // CommandAllocator.
if (cmd->stages & if (cmd->stages &
~(dawn::ShaderStageBit::Vertex | dawn::ShaderStageBit::Fragment)) { ~(dawn::ShaderStageBit::Vertex | dawn::ShaderStageBit::Fragment)) {
NXT_RETURN_ERROR( DAWN_RETURN_ERROR(
"SetPushConstants stage must be a subset of (vertex|fragment) in " "SetPushConstants stage must be a subset of (vertex|fragment) in "
"render passes"); "render passes");
} }
@ -529,7 +529,7 @@ namespace backend {
SetIndexBufferCmd* cmd = mIterator.NextCommand<SetIndexBufferCmd>(); SetIndexBufferCmd* cmd = mIterator.NextCommand<SetIndexBufferCmd>();
usageTracker.BufferUsedAs(cmd->buffer.Get(), dawn::BufferUsageBit::Index); usageTracker.BufferUsedAs(cmd->buffer.Get(), dawn::BufferUsageBit::Index);
NXT_TRY(mState->SetIndexBuffer()); DAWN_TRY(mState->SetIndexBuffer());
} break; } break;
case Command::SetVertexBuffers: { case Command::SetVertexBuffers: {
@ -539,16 +539,16 @@ namespace backend {
for (uint32_t i = 0; i < cmd->count; ++i) { for (uint32_t i = 0; i < cmd->count; ++i) {
usageTracker.BufferUsedAs(buffers[i].Get(), dawn::BufferUsageBit::Vertex); usageTracker.BufferUsedAs(buffers[i].Get(), dawn::BufferUsageBit::Vertex);
NXT_TRY(mState->SetVertexBuffer(cmd->startSlot + i)); DAWN_TRY(mState->SetVertexBuffer(cmd->startSlot + i));
} }
} break; } break;
default: default:
NXT_RETURN_ERROR("Command disallowed inside a render pass"); DAWN_RETURN_ERROR("Command disallowed inside a render pass");
} }
} }
NXT_RETURN_ERROR("Unfinished render pass"); DAWN_RETURN_ERROR("Unfinished render pass");
} }
// Implementation of the API's command recording methods // Implementation of the API's command recording methods

View File

@ -38,11 +38,11 @@ namespace backend {
} }
if (!mAspects[VALIDATION_ASPECT_PIPELINE]) { if (!mAspects[VALIDATION_ASPECT_PIPELINE]) {
NXT_RETURN_ERROR("No active compute pipeline"); DAWN_RETURN_ERROR("No active compute pipeline");
} }
// Compute the lazily computed mAspects // Compute the lazily computed mAspects
if (!RecomputeHaveAspectBindGroups()) { if (!RecomputeHaveAspectBindGroups()) {
NXT_RETURN_ERROR("Bind group state not valid"); DAWN_RETURN_ERROR("Bind group state not valid");
} }
return {}; return {};
} }
@ -69,7 +69,7 @@ namespace backend {
} }
if (!mAspects[VALIDATION_ASPECT_INDEX_BUFFER]) { if (!mAspects[VALIDATION_ASPECT_INDEX_BUFFER]) {
NXT_RETURN_ERROR("Cannot DrawElements without index buffer set"); DAWN_RETURN_ERROR("Cannot DrawElements without index buffer set");
} }
return RevalidateCanDraw(); return RevalidateCanDraw();
} }
@ -96,7 +96,7 @@ namespace backend {
MaybeError CommandBufferStateTracker::SetIndexBuffer() { MaybeError CommandBufferStateTracker::SetIndexBuffer() {
if (!HavePipeline()) { if (!HavePipeline()) {
NXT_RETURN_ERROR("Can't set the index buffer without a pipeline"); DAWN_RETURN_ERROR("Can't set the index buffer without a pipeline");
} }
mAspects.set(VALIDATION_ASPECT_INDEX_BUFFER); mAspects.set(VALIDATION_ASPECT_INDEX_BUFFER);
@ -105,7 +105,7 @@ namespace backend {
MaybeError CommandBufferStateTracker::SetVertexBuffer(uint32_t index) { MaybeError CommandBufferStateTracker::SetVertexBuffer(uint32_t index) {
if (!HavePipeline()) { if (!HavePipeline()) {
NXT_RETURN_ERROR("Can't set vertex buffers without a pipeline"); DAWN_RETURN_ERROR("Can't set vertex buffers without a pipeline");
} }
mInputsSet.set(index); mInputsSet.set(index);
@ -152,14 +152,14 @@ namespace backend {
MaybeError CommandBufferStateTracker::RevalidateCanDraw() { MaybeError CommandBufferStateTracker::RevalidateCanDraw() {
if (!mAspects[VALIDATION_ASPECT_PIPELINE]) { if (!mAspects[VALIDATION_ASPECT_PIPELINE]) {
NXT_RETURN_ERROR("No active render pipeline"); DAWN_RETURN_ERROR("No active render pipeline");
} }
// Compute the lazily computed mAspects // Compute the lazily computed mAspects
if (!RecomputeHaveAspectBindGroups()) { if (!RecomputeHaveAspectBindGroups()) {
NXT_RETURN_ERROR("Bind group state not valid"); DAWN_RETURN_ERROR("Bind group state not valid");
} }
if (!RecomputeHaveAspectVertexBuffers()) { if (!RecomputeHaveAspectVertexBuffers()) {
NXT_RETURN_ERROR("Some vertex buffers are not set"); DAWN_RETURN_ERROR("Some vertex buffers are not set");
} }
return {}; return {};
} }

View File

@ -84,7 +84,7 @@ namespace backend {
} }
BindGroupLayoutBase* backendObj; BindGroupLayoutBase* backendObj;
NXT_TRY_ASSIGN(backendObj, CreateBindGroupLayoutImpl(descriptor)); DAWN_TRY_ASSIGN(backendObj, CreateBindGroupLayoutImpl(descriptor));
mCaches->bindGroupLayouts.insert(backendObj); mCaches->bindGroupLayouts.insert(backendObj);
return backendObj; return backendObj;
} }
@ -194,28 +194,28 @@ namespace backend {
MaybeError DeviceBase::CreateBindGroupLayoutInternal( MaybeError DeviceBase::CreateBindGroupLayoutInternal(
BindGroupLayoutBase** result, BindGroupLayoutBase** result,
const dawn::BindGroupLayoutDescriptor* descriptor) { const dawn::BindGroupLayoutDescriptor* descriptor) {
NXT_TRY(ValidateBindGroupLayoutDescriptor(this, descriptor)); DAWN_TRY(ValidateBindGroupLayoutDescriptor(this, descriptor));
NXT_TRY_ASSIGN(*result, GetOrCreateBindGroupLayout(descriptor)); DAWN_TRY_ASSIGN(*result, GetOrCreateBindGroupLayout(descriptor));
return {}; return {};
} }
MaybeError DeviceBase::CreatePipelineLayoutInternal( MaybeError DeviceBase::CreatePipelineLayoutInternal(
PipelineLayoutBase** result, PipelineLayoutBase** result,
const dawn::PipelineLayoutDescriptor* descriptor) { const dawn::PipelineLayoutDescriptor* descriptor) {
NXT_TRY(ValidatePipelineLayoutDescriptor(this, descriptor)); DAWN_TRY(ValidatePipelineLayoutDescriptor(this, descriptor));
NXT_TRY_ASSIGN(*result, CreatePipelineLayoutImpl(descriptor)); DAWN_TRY_ASSIGN(*result, CreatePipelineLayoutImpl(descriptor));
return {}; return {};
} }
MaybeError DeviceBase::CreateQueueInternal(QueueBase** result) { MaybeError DeviceBase::CreateQueueInternal(QueueBase** result) {
NXT_TRY_ASSIGN(*result, CreateQueueImpl()); DAWN_TRY_ASSIGN(*result, CreateQueueImpl());
return {}; return {};
} }
MaybeError DeviceBase::CreateSamplerInternal(SamplerBase** result, MaybeError DeviceBase::CreateSamplerInternal(SamplerBase** result,
const dawn::SamplerDescriptor* descriptor) { const dawn::SamplerDescriptor* descriptor) {
NXT_TRY(ValidateSamplerDescriptor(this, descriptor)); DAWN_TRY(ValidateSamplerDescriptor(this, descriptor));
NXT_TRY_ASSIGN(*result, CreateSamplerImpl(descriptor)); DAWN_TRY_ASSIGN(*result, CreateSamplerImpl(descriptor));
return {}; return {};
} }

View File

@ -35,29 +35,29 @@ namespace backend {
// return SomethingOfTypeT; // for ResultOrError<T> // return SomethingOfTypeT; // for ResultOrError<T>
// //
// Returning an error is done via: // Returning an error is done via:
// NXT_RETURN_ERROR("My error message"); // DAWN_RETURN_ERROR("My error message");
#define NXT_RETURN_ERROR(MESSAGE) return MakeError(MESSAGE, __FILE__, __func__, __LINE__) #define DAWN_RETURN_ERROR(MESSAGE) return MakeError(MESSAGE, __FILE__, __func__, __LINE__)
#define NXT_TRY_ASSERT(EXPR, MESSAGE) \ #define DAWN_TRY_ASSERT(EXPR, MESSAGE) \
{ \ { \
if (!(EXPR)) { \ if (!(EXPR)) { \
NXT_RETURN_ERROR(MESSAGE); \ DAWN_RETURN_ERROR(MESSAGE); \
} \ } \
} \ } \
for (;;) \ for (;;) \
break break
#define NXT_CONCAT1(x, y) x##y #define DAWN_CONCAT1(x, y) x##y
#define NXT_CONCAT2(x, y) NXT_CONCAT1(x, y) #define DAWN_CONCAT2(x, y) DAWN_CONCAT1(x, y)
#define NXT_LOCAL_VAR NXT_CONCAT2(_localVar, __LINE__) #define DAWN_LOCAL_VAR DAWN_CONCAT2(_localVar, __LINE__)
// When Errors aren't handled explicitly, calls to functions returning errors should be // When Errors aren't handled explicitly, calls to functions returning errors should be
// wrapped in an NXT_TRY. It will return the error if any, otherwise keep executing // wrapped in an DAWN_TRY. It will return the error if any, otherwise keep executing
// the current function. // the current function.
#define NXT_TRY(EXPR) \ #define DAWN_TRY(EXPR) \
{ \ { \
auto NXT_LOCAL_VAR = EXPR; \ auto DAWN_LOCAL_VAR = EXPR; \
if (NXT_UNLIKELY(NXT_LOCAL_VAR.IsError())) { \ if (NXT_UNLIKELY(DAWN_LOCAL_VAR.IsError())) { \
ErrorData* error = NXT_LOCAL_VAR.AcquireError(); \ ErrorData* error = DAWN_LOCAL_VAR.AcquireError(); \
AppendBacktrace(error, __FILE__, __func__, __LINE__); \ AppendBacktrace(error, __FILE__, __func__, __LINE__); \
return {error}; \ return {error}; \
} \ } \
@ -65,25 +65,25 @@ namespace backend {
for (;;) \ for (;;) \
break break
// NXT_TRY_ASSIGN is the same as NXT_TRY for ResultOrError and assigns the success value, if // DAWN_TRY_ASSIGN is the same as DAWN_TRY for ResultOrError and assigns the success value, if
// any, to VAR. // any, to VAR.
#define NXT_TRY_ASSIGN(VAR, EXPR) \ #define DAWN_TRY_ASSIGN(VAR, EXPR) \
{ \ { \
auto NXT_LOCAL_VAR = EXPR; \ auto DAWN_LOCAL_VAR = EXPR; \
if (NXT_UNLIKELY(NXT_LOCAL_VAR.IsError())) { \ if (NXT_UNLIKELY(DAWN_LOCAL_VAR.IsError())) { \
ErrorData* error = NXT_LOCAL_VAR.AcquireError(); \ ErrorData* error = DAWN_LOCAL_VAR.AcquireError(); \
AppendBacktrace(error, __FILE__, __func__, __LINE__); \ AppendBacktrace(error, __FILE__, __func__, __LINE__); \
return {error}; \ return {error}; \
} \ } \
VAR = NXT_LOCAL_VAR.AcquireSuccess(); \ VAR = DAWN_LOCAL_VAR.AcquireSuccess(); \
} \ } \
for (;;) \ for (;;) \
break break
// Implementation detail of NXT_TRY and NXT_TRY_ASSIGN's adding to the Error's backtrace. // Implementation detail of DAWN_TRY and DAWN_TRY_ASSIGN's adding to the Error's backtrace.
void AppendBacktrace(ErrorData* error, const char* file, const char* function, int line); void AppendBacktrace(ErrorData* error, const char* file, const char* function, int line);
// Implementation detail of NXT_RETURN_ERROR // Implementation detail of DAWN_RETURN_ERROR
ErrorData* MakeError(const char* message, const char* file, const char* function, int line); ErrorData* MakeError(const char* message, const char* file, const char* function, int line);
} // namespace backend } // namespace backend

View File

@ -22,12 +22,12 @@ namespace backend {
MaybeError ValidatePipelineLayoutDescriptor(DeviceBase*, MaybeError ValidatePipelineLayoutDescriptor(DeviceBase*,
const dawn::PipelineLayoutDescriptor* descriptor) { const dawn::PipelineLayoutDescriptor* descriptor) {
NXT_TRY_ASSERT(descriptor->nextInChain == nullptr, "nextInChain must be nullptr"); DAWN_TRY_ASSERT(descriptor->nextInChain == nullptr, "nextInChain must be nullptr");
NXT_TRY_ASSERT(descriptor->numBindGroupLayouts <= kMaxBindGroups, DAWN_TRY_ASSERT(descriptor->numBindGroupLayouts <= kMaxBindGroups,
"too many bind group layouts"); "too many bind group layouts");
for (uint32_t i = 0; i < descriptor->numBindGroupLayouts; ++i) { for (uint32_t i = 0; i < descriptor->numBindGroupLayouts; ++i) {
NXT_TRY_ASSERT(descriptor->bindGroupLayouts[i].Get() != nullptr, DAWN_TRY_ASSERT(descriptor->bindGroupLayouts[i].Get() != nullptr,
"bind group layouts may not be null"); "bind group layouts may not be null");
} }
return {}; return {};
} }

View File

@ -36,7 +36,7 @@ namespace backend {
"invalid command buffer type"); "invalid command buffer type");
for (uint32_t i = 0; i < numCommands; ++i) { for (uint32_t i = 0; i < numCommands; ++i) {
NXT_TRY(ValidateSubmitCommand(commands[i])); DAWN_TRY(ValidateSubmitCommand(commands[i]));
} }
return {}; return {};
} }

View File

@ -20,13 +20,13 @@
namespace backend { namespace backend {
MaybeError ValidateSamplerDescriptor(DeviceBase*, const dawn::SamplerDescriptor* descriptor) { MaybeError ValidateSamplerDescriptor(DeviceBase*, const dawn::SamplerDescriptor* descriptor) {
NXT_TRY_ASSERT(descriptor->nextInChain == nullptr, "nextInChain must be nullptr"); DAWN_TRY_ASSERT(descriptor->nextInChain == nullptr, "nextInChain must be nullptr");
NXT_TRY(ValidateFilterMode(descriptor->minFilter)); DAWN_TRY(ValidateFilterMode(descriptor->minFilter));
NXT_TRY(ValidateFilterMode(descriptor->magFilter)); DAWN_TRY(ValidateFilterMode(descriptor->magFilter));
NXT_TRY(ValidateFilterMode(descriptor->mipmapFilter)); DAWN_TRY(ValidateFilterMode(descriptor->mipmapFilter));
NXT_TRY(ValidateAddressMode(descriptor->addressModeU)); DAWN_TRY(ValidateAddressMode(descriptor->addressModeU));
NXT_TRY(ValidateAddressMode(descriptor->addressModeV)); DAWN_TRY(ValidateAddressMode(descriptor->addressModeV));
NXT_TRY(ValidateAddressMode(descriptor->addressModeW)); DAWN_TRY(ValidateAddressMode(descriptor->addressModeW));
return {}; return {};
} }

View File

@ -34,10 +34,10 @@ TEST(ErrorTests, Error_Success) {
ASSERT_TRUE(result.IsSuccess()); ASSERT_TRUE(result.IsSuccess());
} }
// Check returning an error MaybeError with NXT_RETURN_ERROR // Check returning an error MaybeError with DAWN_RETURN_ERROR
TEST(ErrorTests, Error_Error) { TEST(ErrorTests, Error_Error) {
auto ReturnError = []() -> MaybeError { auto ReturnError = []() -> MaybeError {
NXT_RETURN_ERROR(dummyErrorMessage); DAWN_RETURN_ERROR(dummyErrorMessage);
}; };
MaybeError result = ReturnError(); MaybeError result = ReturnError();
@ -59,10 +59,10 @@ TEST(ErrorTests, ResultOrError_Success) {
ASSERT_EQ(result.AcquireSuccess(), &dummySuccess); ASSERT_EQ(result.AcquireSuccess(), &dummySuccess);
} }
// Check returning an error ResultOrError with NXT_RETURN_ERROR // Check returning an error ResultOrError with DAWN_RETURN_ERROR
TEST(ErrorTests, ResultOrError_Error) { TEST(ErrorTests, ResultOrError_Error) {
auto ReturnError = []() -> ResultOrError<int*> { auto ReturnError = []() -> ResultOrError<int*> {
NXT_RETURN_ERROR(dummyErrorMessage); DAWN_RETURN_ERROR(dummyErrorMessage);
}; };
ResultOrError<int*> result = ReturnError(); ResultOrError<int*> result = ReturnError();
@ -73,17 +73,17 @@ TEST(ErrorTests, ResultOrError_Error) {
delete errorData; delete errorData;
} }
// Check NXT_TRY handles successes correctly. // Check DAWN_TRY handles successes correctly.
TEST(ErrorTests, TRY_Success) { TEST(ErrorTests, TRY_Success) {
auto ReturnSuccess = []() -> MaybeError { auto ReturnSuccess = []() -> MaybeError {
return {}; return {};
}; };
// We need to check that NXT_TRY doesn't return on successes // We need to check that DAWN_TRY doesn't return on successes
bool tryReturned = true; bool tryReturned = true;
auto Try = [ReturnSuccess, &tryReturned]() -> MaybeError { auto Try = [ReturnSuccess, &tryReturned]() -> MaybeError {
NXT_TRY(ReturnSuccess()); DAWN_TRY(ReturnSuccess());
tryReturned = false; tryReturned = false;
return {}; return {};
}; };
@ -93,15 +93,15 @@ TEST(ErrorTests, TRY_Success) {
ASSERT_FALSE(tryReturned); ASSERT_FALSE(tryReturned);
} }
// Check NXT_TRY handles errors correctly. // Check DAWN_TRY handles errors correctly.
TEST(ErrorTests, TRY_Error) { TEST(ErrorTests, TRY_Error) {
auto ReturnError = []() -> MaybeError { auto ReturnError = []() -> MaybeError {
NXT_RETURN_ERROR(dummyErrorMessage); DAWN_RETURN_ERROR(dummyErrorMessage);
}; };
auto Try = [ReturnError]() -> MaybeError { auto Try = [ReturnError]() -> MaybeError {
NXT_TRY(ReturnError()); DAWN_TRY(ReturnError());
// NXT_TRY should return before this point // DAWN_TRY should return before this point
EXPECT_FALSE(true); EXPECT_FALSE(true);
return {}; return {};
}; };
@ -114,19 +114,19 @@ TEST(ErrorTests, TRY_Error) {
delete errorData; delete errorData;
} }
// Check NXT_TRY adds to the backtrace. // Check DAWN_TRY adds to the backtrace.
TEST(ErrorTests, TRY_AddsToBacktrace) { TEST(ErrorTests, TRY_AddsToBacktrace) {
auto ReturnError = []() -> MaybeError { auto ReturnError = []() -> MaybeError {
NXT_RETURN_ERROR(dummyErrorMessage); DAWN_RETURN_ERROR(dummyErrorMessage);
}; };
auto SingleTry = [ReturnError]() -> MaybeError { auto SingleTry = [ReturnError]() -> MaybeError {
NXT_TRY(ReturnError()); DAWN_TRY(ReturnError());
return {}; return {};
}; };
auto DoubleTry = [SingleTry]() -> MaybeError { auto DoubleTry = [SingleTry]() -> MaybeError {
NXT_TRY(SingleTry()); DAWN_TRY(SingleTry());
return {}; return {};
}; };
@ -145,18 +145,18 @@ TEST(ErrorTests, TRY_AddsToBacktrace) {
delete doubleData; delete doubleData;
} }
// Check NXT_TRY_ASSIGN handles successes correctly. // Check DAWN_TRY_ASSIGN handles successes correctly.
TEST(ErrorTests, TRY_RESULT_Success) { TEST(ErrorTests, TRY_RESULT_Success) {
auto ReturnSuccess = []() -> ResultOrError<int*> { auto ReturnSuccess = []() -> ResultOrError<int*> {
return &dummySuccess; return &dummySuccess;
}; };
// We need to check that NXT_TRY doesn't return on successes // We need to check that DAWN_TRY doesn't return on successes
bool tryReturned = true; bool tryReturned = true;
auto Try = [ReturnSuccess, &tryReturned]() -> ResultOrError<int*> { auto Try = [ReturnSuccess, &tryReturned]() -> ResultOrError<int*> {
int* result = nullptr; int* result = nullptr;
NXT_TRY_ASSIGN(result, ReturnSuccess()); DAWN_TRY_ASSIGN(result, ReturnSuccess());
tryReturned = false; tryReturned = false;
EXPECT_EQ(result, &dummySuccess); EXPECT_EQ(result, &dummySuccess);
@ -169,18 +169,18 @@ TEST(ErrorTests, TRY_RESULT_Success) {
ASSERT_EQ(result.AcquireSuccess(), &dummySuccess); ASSERT_EQ(result.AcquireSuccess(), &dummySuccess);
} }
// Check NXT_TRY_ASSIGN handles errors correctly. // Check DAWN_TRY_ASSIGN handles errors correctly.
TEST(ErrorTests, TRY_RESULT_Error) { TEST(ErrorTests, TRY_RESULT_Error) {
auto ReturnError = []() -> ResultOrError<int*> { auto ReturnError = []() -> ResultOrError<int*> {
NXT_RETURN_ERROR(dummyErrorMessage); DAWN_RETURN_ERROR(dummyErrorMessage);
}; };
auto Try = [ReturnError]() -> ResultOrError<int*> { auto Try = [ReturnError]() -> ResultOrError<int*> {
int* result = nullptr; int* result = nullptr;
NXT_TRY_ASSIGN(result, ReturnError()); DAWN_TRY_ASSIGN(result, ReturnError());
NXT_UNUSED(result); NXT_UNUSED(result);
// NXT_TRY should return before this point // DAWN_TRY should return before this point
EXPECT_FALSE(true); EXPECT_FALSE(true);
return &dummySuccess; return &dummySuccess;
}; };
@ -193,19 +193,19 @@ TEST(ErrorTests, TRY_RESULT_Error) {
delete errorData; delete errorData;
} }
// Check NXT_TRY_ASSIGN adds to the backtrace. // Check DAWN_TRY_ASSIGN adds to the backtrace.
TEST(ErrorTests, TRY_RESULT_AddsToBacktrace) { TEST(ErrorTests, TRY_RESULT_AddsToBacktrace) {
auto ReturnError = []() -> ResultOrError<int*> { auto ReturnError = []() -> ResultOrError<int*> {
NXT_RETURN_ERROR(dummyErrorMessage); DAWN_RETURN_ERROR(dummyErrorMessage);
}; };
auto SingleTry = [ReturnError]() -> ResultOrError<int*> { auto SingleTry = [ReturnError]() -> ResultOrError<int*> {
NXT_TRY(ReturnError()); DAWN_TRY(ReturnError());
return &dummySuccess; return &dummySuccess;
}; };
auto DoubleTry = [SingleTry]() -> ResultOrError<int*> { auto DoubleTry = [SingleTry]() -> ResultOrError<int*> {
NXT_TRY(SingleTry()); DAWN_TRY(SingleTry());
return &dummySuccess; return &dummySuccess;
}; };
@ -224,15 +224,15 @@ TEST(ErrorTests, TRY_RESULT_AddsToBacktrace) {
delete doubleData; delete doubleData;
} }
// Check a ResultOrError can be NXT_TRY_ASSIGNED in a function that returns an Error // Check a ResultOrError can be DAWN_TRY_ASSIGNED in a function that returns an Error
TEST(ErrorTests, TRY_RESULT_ConversionToError) { TEST(ErrorTests, TRY_RESULT_ConversionToError) {
auto ReturnError = []() -> ResultOrError<int*> { auto ReturnError = []() -> ResultOrError<int*> {
NXT_RETURN_ERROR(dummyErrorMessage); DAWN_RETURN_ERROR(dummyErrorMessage);
}; };
auto Try = [ReturnError]() -> MaybeError { auto Try = [ReturnError]() -> MaybeError {
int* result = nullptr; int* result = nullptr;
NXT_TRY_ASSIGN(result, ReturnError()); DAWN_TRY_ASSIGN(result, ReturnError());
NXT_UNUSED(result); NXT_UNUSED(result);
return {}; return {};
@ -247,14 +247,14 @@ TEST(ErrorTests, TRY_RESULT_ConversionToError) {
} }
// Check a MaybeError can be NXT_TRIED in a function that returns an ResultOrError // Check a MaybeError can be NXT_TRIED in a function that returns an ResultOrError
// Check NXT_TRY handles errors correctly. // Check DAWN_TRY handles errors correctly.
TEST(ErrorTests, TRY_ConversionToErrorOrResult) { TEST(ErrorTests, TRY_ConversionToErrorOrResult) {
auto ReturnError = []() -> MaybeError { auto ReturnError = []() -> MaybeError {
NXT_RETURN_ERROR(dummyErrorMessage); DAWN_RETURN_ERROR(dummyErrorMessage);
}; };
auto Try = [ReturnError]() -> ResultOrError<int*>{ auto Try = [ReturnError]() -> ResultOrError<int*>{
NXT_TRY(ReturnError()); DAWN_TRY(ReturnError());
return &dummySuccess; return &dummySuccess;
}; };