Improve validation errors, Part 3

Modified ConsumedError and TryEncode methods to allow for top-level
error context messages. Applied them to:
 - ComputePassEncoder
 - ProgrammablePassEncoder
 - RenderEncoderBase
 - RenderPassEncoder
 - Device

Bug: dawn:563
Change-Id: I4a989763f57afbcf6b1cfe87ccaaba502ebd29fe
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/65101
Commit-Queue: Brandon Jones <bajones@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Brandon Jones 2021-09-29 18:39:23 +00:00 committed by Dawn LUCI CQ
parent caba9139a0
commit 9b643b72f7
10 changed files with 995 additions and 731 deletions

View File

@ -21,6 +21,36 @@
namespace dawn_native {
//
// Structs (Manually written)
//
absl::FormatConvertResult<absl::FormatConversionCharSet::kString>
AbslFormatConvert(const Color* value,
const absl::FormatConversionSpec& spec,
absl::FormatSink* s) {
if (value == nullptr) {
s->Append("[null]");
return {true};
}
s->Append(absl::StrFormat("[Color r:%f, g:%f, b:%f, a:%f]",
value->r, value->g, value->b, value->a));
return {true};
}
absl::FormatConvertResult<absl::FormatConversionCharSet::kString>
AbslFormatConvert(const Extent3D* value,
const absl::FormatConversionSpec& spec,
absl::FormatSink* s) {
if (value == nullptr) {
s->Append("[null]");
return {true};
}
s->Append(absl::StrFormat("[Extent3D width:%u, height:%u, depthOrArrayLayers:%u]",
value->width, value->height, value->depthOrArrayLayers));
return {true};
}
//
// Objects
//
@ -29,6 +59,10 @@ namespace dawn_native {
AbslFormatConvert(const DeviceBase* value,
const absl::FormatConversionSpec& spec,
absl::FormatSink* s) {
if (value == nullptr) {
s->Append("[null]");
return {true};
}
s->Append("[Device");
const std::string& label = value->GetLabel();
if (!label.empty()) {
@ -42,6 +76,10 @@ namespace dawn_native {
AbslFormatConvert(const ApiObjectBase* value,
const absl::FormatConversionSpec& spec,
absl::FormatSink* s) {
if (value == nullptr) {
s->Append("[null]");
return {true};
}
s->Append("[");
s->Append(ObjectTypeAsString(value->GetType()));
const std::string& label = value->GetLabel();
@ -56,6 +94,10 @@ namespace dawn_native {
AbslFormatConvert(const TextureViewBase* value,
const absl::FormatConversionSpec& spec,
absl::FormatSink* s) {
if (value == nullptr) {
s->Append("[null]");
return {true};
}
s->Append("[");
s->Append(ObjectTypeAsString(value->GetType()));
const std::string& label = value->GetLabel();
@ -81,6 +123,10 @@ namespace dawn_native {
AbslFormatConvert(const {{as_cppType(type.name)}}* value,
const absl::FormatConversionSpec& spec,
absl::FormatSink* s) {
if (value == nullptr) {
s->Append("[null]");
return {true};
}
s->Append("[{{as_cppType(type.name)}}");
if (value->label != nullptr) {
s->Append(absl::StrFormat(" \"%s\"", value->label));

View File

@ -21,6 +21,22 @@
namespace dawn_native {
//
// Structs (Manually written)
//
struct Color;
absl::FormatConvertResult<absl::FormatConversionCharSet::kString>
AbslFormatConvert(const Color* value,
const absl::FormatConversionSpec& spec,
absl::FormatSink* s);
struct Extent3D;
absl::FormatConvertResult<absl::FormatConversionCharSet::kString>
AbslFormatConvert(const Extent3D* value,
const absl::FormatConversionSpec& spec,
absl::FormatSink* s);
//
// Objects
//

View File

@ -486,14 +486,16 @@ namespace dawn_native {
const ComputePassDescriptor* descriptor) {
DeviceBase* device = GetDevice();
bool success =
mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
bool success = mEncodingContext.TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
DAWN_TRY(ValidateComputePassDescriptor(device, descriptor));
allocator->Allocate<BeginComputePassCmd>(Command::BeginComputePass);
return {};
});
},
"encoding BeginComputePass(%s).", descriptor);
if (success) {
ComputePassEncoder* passEncoder =
@ -513,8 +515,9 @@ namespace dawn_native {
uint32_t width = 0;
uint32_t height = 0;
Ref<AttachmentState> attachmentState;
bool success =
mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
bool success = mEncodingContext.TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
uint32_t sampleCount = 0;
DAWN_TRY(ValidateRenderPassDescriptor(device, descriptor, &width, &height,
@ -576,7 +579,8 @@ namespace dawn_native {
cmd->occlusionQuerySet = descriptor->occlusionQuerySet;
return {};
});
},
"encoding BeginRenderPass(%s).", descriptor);
if (success) {
RenderPassEncoder* passEncoder = new RenderPassEncoder(
@ -594,7 +598,9 @@ namespace dawn_native {
BufferBase* destination,
uint64_t destinationOffset,
uint64_t size) {
mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext.TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (GetDevice()->IsValidationEnabled()) {
DAWN_TRY(GetDevice()->ValidateObject(source));
DAWN_TRY(GetDevice()->ValidateObject(destination));
@ -624,13 +630,17 @@ namespace dawn_native {
copy->size = size;
return {};
});
},
"encoding CopyBufferToBuffer(%s, %u, %s, %u, %u).", source, sourceOffset, destination,
destinationOffset, size);
}
void CommandEncoder::APICopyBufferToTexture(const ImageCopyBuffer* source,
const ImageCopyTexture* destination,
const Extent3D* copySize) {
mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext.TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (GetDevice()->IsValidationEnabled()) {
DAWN_TRY(ValidateImageCopyBuffer(GetDevice(), *source));
DAWN_TRY(ValidateCanUseAs(source->buffer, wgpu::BufferUsage::CopySrc));
@ -676,13 +686,17 @@ namespace dawn_native {
copy->copySize = *copySize;
return {};
});
},
"encoding CopyBufferToTexture(%s, %s, %s).", source->buffer, destination->texture,
copySize);
}
void CommandEncoder::APICopyTextureToBuffer(const ImageCopyTexture* source,
const ImageCopyBuffer* destination,
const Extent3D* copySize) {
mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext.TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (GetDevice()->IsValidationEnabled()) {
DAWN_TRY(ValidateImageCopyTexture(GetDevice(), *source, *copySize));
DAWN_TRY(ValidateCanUseAs(source->texture, wgpu::TextureUsage::CopySrc));
@ -727,7 +741,9 @@ namespace dawn_native {
copy->copySize = *copySize;
return {};
});
},
"encoding CopyTextureToBuffer(%s, %s, %s).", source->texture, destination->buffer,
copySize);
}
void CommandEncoder::APICopyTextureToTexture(const ImageCopyTexture* source,
@ -746,7 +762,9 @@ namespace dawn_native {
void CommandEncoder::APICopyTextureToTextureHelper(const ImageCopyTexture* source,
const ImageCopyTexture* destination,
const Extent3D* copySize) {
mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext.TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (GetDevice()->IsValidationEnabled()) {
DAWN_TRY(GetDevice()->ValidateObject(source->texture));
DAWN_TRY(GetDevice()->ValidateObject(destination->texture));
@ -769,7 +787,8 @@ namespace dawn_native {
wgpu::TextureUsage::CopyDst));
} else {
DAWN_TRY(ValidateCanUseAs(source->texture, wgpu::TextureUsage::CopySrc));
DAWN_TRY(ValidateCanUseAs(destination->texture, wgpu::TextureUsage::CopyDst));
DAWN_TRY(
ValidateCanUseAs(destination->texture, wgpu::TextureUsage::CopyDst));
}
mTopLevelTextures.insert(source->texture);
@ -790,7 +809,9 @@ namespace dawn_native {
copy->copySize = *copySize;
return {};
});
},
"encoding CopyTextureToTexture(%s, %s, %s).", source->texture, destination->texture,
copySize);
}
void CommandEncoder::APIInjectValidationError(const char* message) {
@ -800,7 +821,9 @@ namespace dawn_native {
}
void CommandEncoder::APIInsertDebugMarker(const char* groupLabel) {
mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext.TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
InsertDebugMarkerCmd* cmd =
allocator->Allocate<InsertDebugMarkerCmd>(Command::InsertDebugMarker);
cmd->length = strlen(groupLabel);
@ -809,25 +832,32 @@ namespace dawn_native {
memcpy(label, groupLabel, cmd->length + 1);
return {};
});
},
"encoding InsertDebugMarker(\"%s\").", groupLabel);
}
void CommandEncoder::APIPopDebugGroup() {
mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext.TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (GetDevice()->IsValidationEnabled()) {
if (mDebugGroupStackSize == 0) {
return DAWN_VALIDATION_ERROR("Pop must be balanced by a corresponding Push.");
return DAWN_VALIDATION_ERROR(
"Pop must be balanced by a corresponding Push.");
}
}
allocator->Allocate<PopDebugGroupCmd>(Command::PopDebugGroup);
mDebugGroupStackSize--;
return {};
});
},
"encoding PopDebugGroup().");
}
void CommandEncoder::APIPushDebugGroup(const char* groupLabel) {
mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext.TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
PushDebugGroupCmd* cmd =
allocator->Allocate<PushDebugGroupCmd>(Command::PushDebugGroup);
cmd->length = strlen(groupLabel);
@ -838,7 +868,8 @@ namespace dawn_native {
mDebugGroupStackSize++;
return {};
});
},
"encoding PushDebugGroup(\"%s\").", groupLabel);
}
void CommandEncoder::APIResolveQuerySet(QuerySetBase* querySet,
@ -846,7 +877,9 @@ namespace dawn_native {
uint32_t queryCount,
BufferBase* destination,
uint64_t destinationOffset) {
mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext.TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (GetDevice()->IsValidationEnabled()) {
DAWN_TRY(GetDevice()->ValidateObject(querySet));
DAWN_TRY(GetDevice()->ValidateObject(destination));
@ -875,14 +908,18 @@ namespace dawn_native {
}
return {};
});
},
"encoding ResolveQuerySet(%s, %u, %u, %s, %u).", querySet, firstQuery, queryCount,
destination, destinationOffset);
}
void CommandEncoder::APIWriteBuffer(BufferBase* buffer,
uint64_t bufferOffset,
const uint8_t* data,
uint64_t size) {
mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext.TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (GetDevice()->IsValidationEnabled()) {
DAWN_TRY(ValidateWriteBuffer(GetDevice(), buffer, bufferOffset, size));
}
@ -898,11 +935,14 @@ namespace dawn_native {
mTopLevelBuffers.insert(buffer);
return {};
});
},
"encoding WriteBuffer(%s, %u, ..., %u).", buffer, bufferOffset, size);
}
void CommandEncoder::APIWriteTimestamp(QuerySetBase* querySet, uint32_t queryIndex) {
mEncodingContext.TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext.TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (GetDevice()->IsValidationEnabled()) {
DAWN_TRY(GetDevice()->ValidateObject(querySet));
DAWN_TRY(ValidateTimestampQuery(querySet, queryIndex));
@ -916,7 +956,8 @@ namespace dawn_native {
cmd->queryIndex = queryIndex;
return {};
});
},
"encoding WriteTimestamp(%s, %u).", querySet, queryIndex);
}
CommandBufferBase* CommandEncoder::APIFinish(const CommandBufferDescriptor* descriptor) {

View File

@ -63,7 +63,9 @@ namespace dawn_native {
}
void ComputePassEncoder::APIEndPass() {
if (mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
if (mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) {
DAWN_TRY(ValidateProgrammableEncoderEnd());
}
@ -71,13 +73,16 @@ namespace dawn_native {
allocator->Allocate<EndComputePassCmd>(Command::EndComputePass);
return {};
})) {
},
"encoding EndPass()")) {
mEncodingContext->ExitComputePass(this, mUsageTracker.AcquireResourceUsage());
}
}
void ComputePassEncoder::APIDispatch(uint32_t x, uint32_t y, uint32_t z) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) {
DAWN_TRY(mCommandBufferState.ValidateCanDispatch());
DAWN_TRY(ValidatePerDimensionDispatchSizeLimit(x));
@ -85,7 +90,8 @@ namespace dawn_native {
DAWN_TRY(ValidatePerDimensionDispatchSizeLimit(z));
}
// Record the synchronization scope for Dispatch, which is just the current bindgroups.
// Record the synchronization scope for Dispatch, which is just the current
// bindgroups.
AddDispatchSyncScope();
DispatchCmd* dispatch = allocator->Allocate<DispatchCmd>(Command::Dispatch);
@ -94,20 +100,23 @@ namespace dawn_native {
dispatch->z = z;
return {};
});
},
"encoding Dispatch (x: %u, y: %u, z: %u)", x, y, z);
}
void ComputePassEncoder::APIDispatchIndirect(BufferBase* indirectBuffer,
uint64_t indirectOffset) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) {
DAWN_TRY(GetDevice()->ValidateObject(indirectBuffer));
DAWN_TRY(ValidateCanUseAs(indirectBuffer, wgpu::BufferUsage::Indirect));
DAWN_TRY(mCommandBufferState.ValidateCanDispatch());
// Indexed dispatches need a compute-shader based validation to check that the
// dispatch sizes aren't too big. Disallow them as unsafe until the validation is
// implemented.
// dispatch sizes aren't too big. Disallow them as unsafe until the validation
// is implemented.
if (GetDevice()->IsToggleEnabled(Toggle::DisallowUnsafeAPIs)) {
return DAWN_VALIDATION_ERROR(
"DispatchIndirect is disallowed because it doesn't validate that the "
@ -125,8 +134,8 @@ namespace dawn_native {
}
}
// Record the synchronization scope for Dispatch, both the bindgroups and the indirect
// buffer.
// Record the synchronization scope for Dispatch, both the bindgroups and the
// indirect buffer.
SyncScopeUsageTracker scope;
scope.BufferUsedAs(indirectBuffer, wgpu::BufferUsage::Indirect);
mUsageTracker.AddReferencedBuffer(indirectBuffer);
@ -138,11 +147,14 @@ namespace dawn_native {
dispatch->indirectOffset = indirectOffset;
return {};
});
},
"encoding DispatchIndirect with %s", indirectBuffer);
}
void ComputePassEncoder::APISetPipeline(ComputePipelineBase* pipeline) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) {
DAWN_TRY(GetDevice()->ValidateObject(pipeline));
}
@ -154,32 +166,39 @@ namespace dawn_native {
cmd->pipeline = pipeline;
return {};
});
},
"encoding SetPipeline with %s", pipeline);
}
void ComputePassEncoder::APISetBindGroup(uint32_t groupIndexIn,
BindGroupBase* group,
uint32_t dynamicOffsetCount,
const uint32_t* dynamicOffsets) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
BindGroupIndex groupIndex(groupIndexIn);
if (IsValidationEnabled()) {
DAWN_TRY(
ValidateSetBindGroup(groupIndex, group, dynamicOffsetCount, dynamicOffsets));
DAWN_TRY(ValidateSetBindGroup(groupIndex, group, dynamicOffsetCount,
dynamicOffsets));
}
mUsageTracker.AddResourcesReferencedByBindGroup(group);
RecordSetBindGroup(allocator, groupIndex, group, dynamicOffsetCount, dynamicOffsets);
RecordSetBindGroup(allocator, groupIndex, group, dynamicOffsetCount,
dynamicOffsets);
mCommandBufferState.SetBindGroup(groupIndex, group);
return {};
});
},
"encoding SetBindGroup with %s at index %u", group, groupIndexIn);
}
void ComputePassEncoder::APIWriteTimestamp(QuerySetBase* querySet, uint32_t queryIndex) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) {
DAWN_TRY(GetDevice()->ValidateObject(querySet));
DAWN_TRY(ValidateTimestampQuery(querySet, queryIndex));
@ -193,7 +212,8 @@ namespace dawn_native {
cmd->queryIndex = queryIndex;
return {};
});
},
"encoding WriteTimestamp to %s.", querySet);
}
void ComputePassEncoder::AddDispatchSyncScope(SyncScopeUsageTracker scope) {

View File

@ -484,6 +484,7 @@ namespace dawn_native {
"%s is associated with %s, and cannot be used with %s.", object,
object->GetDevice(), this);
// TODO(dawn:563): Preserve labels for error objects.
DAWN_INVALID_IF(object->IsError(), "%s is an error.", object);
return {};
@ -852,7 +853,8 @@ namespace dawn_native {
BindGroupBase* DeviceBase::APICreateBindGroup(const BindGroupDescriptor* descriptor) {
Ref<BindGroupBase> result;
if (ConsumedError(CreateBindGroup(descriptor), &result)) {
if (ConsumedError(CreateBindGroup(descriptor), &result, "calling CreateBindGroup(%s).",
descriptor)) {
return BindGroupBase::MakeError(this);
}
return result.Detach();
@ -860,14 +862,16 @@ namespace dawn_native {
BindGroupLayoutBase* DeviceBase::APICreateBindGroupLayout(
const BindGroupLayoutDescriptor* descriptor) {
Ref<BindGroupLayoutBase> result;
if (ConsumedError(CreateBindGroupLayout(descriptor), &result)) {
if (ConsumedError(CreateBindGroupLayout(descriptor), &result,
"calling CreateBindGroupLayout(%s).", descriptor)) {
return BindGroupLayoutBase::MakeError(this);
}
return result.Detach();
}
BufferBase* DeviceBase::APICreateBuffer(const BufferDescriptor* descriptor) {
Ref<BufferBase> result = nullptr;
if (ConsumedError(CreateBuffer(descriptor), &result)) {
if (ConsumedError(CreateBuffer(descriptor), &result, "calling CreateBuffer(%s).",
descriptor)) {
ASSERT(result == nullptr);
return BufferBase::MakeError(this, descriptor);
}
@ -880,7 +884,8 @@ namespace dawn_native {
ComputePipelineBase* DeviceBase::APICreateComputePipeline(
const ComputePipelineDescriptor* descriptor) {
Ref<ComputePipelineBase> result;
if (ConsumedError(CreateComputePipeline(descriptor), &result)) {
if (ConsumedError(CreateComputePipeline(descriptor), &result,
"calling CreateComputePipeline(%s).", descriptor)) {
return ComputePipelineBase::MakeError(this);
}
return result.Detach();
@ -902,21 +907,24 @@ namespace dawn_native {
PipelineLayoutBase* DeviceBase::APICreatePipelineLayout(
const PipelineLayoutDescriptor* descriptor) {
Ref<PipelineLayoutBase> result;
if (ConsumedError(CreatePipelineLayout(descriptor), &result)) {
if (ConsumedError(CreatePipelineLayout(descriptor), &result,
"calling CreatePipelineLayout(%s).", descriptor)) {
return PipelineLayoutBase::MakeError(this);
}
return result.Detach();
}
QuerySetBase* DeviceBase::APICreateQuerySet(const QuerySetDescriptor* descriptor) {
Ref<QuerySetBase> result;
if (ConsumedError(CreateQuerySet(descriptor), &result)) {
if (ConsumedError(CreateQuerySet(descriptor), &result, "calling CreateQuerySet(%s).",
descriptor)) {
return QuerySetBase::MakeError(this);
}
return result.Detach();
}
SamplerBase* DeviceBase::APICreateSampler(const SamplerDescriptor* descriptor) {
Ref<SamplerBase> result;
if (ConsumedError(CreateSampler(descriptor), &result)) {
if (ConsumedError(CreateSampler(descriptor), &result, "calling CreateSampler(%s).",
descriptor)) {
return SamplerBase::MakeError(this);
}
return result.Detach();
@ -924,6 +932,7 @@ namespace dawn_native {
void DeviceBase::APICreateRenderPipelineAsync(const RenderPipelineDescriptor* descriptor,
WGPUCreateRenderPipelineAsyncCallback callback,
void* userdata) {
// TODO(dawn:563): Add validation error context.
MaybeError maybeResult = CreateRenderPipelineAsync(descriptor, callback, userdata);
// Call the callback directly when a validation error has been found in the front-end
@ -938,7 +947,8 @@ namespace dawn_native {
RenderBundleEncoder* DeviceBase::APICreateRenderBundleEncoder(
const RenderBundleEncoderDescriptor* descriptor) {
Ref<RenderBundleEncoder> result;
if (ConsumedError(CreateRenderBundleEncoder(descriptor), &result)) {
if (ConsumedError(CreateRenderBundleEncoder(descriptor), &result,
"calling CreateRenderBundleEncoder(%s).", descriptor)) {
return RenderBundleEncoder::MakeError(this);
}
return result.Detach();
@ -946,7 +956,8 @@ namespace dawn_native {
RenderPipelineBase* DeviceBase::APICreateRenderPipeline(
const RenderPipelineDescriptor* descriptor) {
Ref<RenderPipelineBase> result;
if (ConsumedError(CreateRenderPipeline(descriptor), &result)) {
if (ConsumedError(CreateRenderPipeline(descriptor), &result,
"calling CreateRenderPipeline(%s).", descriptor)) {
return RenderPipelineBase::MakeError(this);
}
return result.Detach();
@ -955,7 +966,8 @@ namespace dawn_native {
Ref<ShaderModuleBase> result;
std::unique_ptr<OwnedCompilationMessages> compilationMessages(
std::make_unique<OwnedCompilationMessages>());
if (ConsumedError(CreateShaderModule(descriptor, compilationMessages.get()), &result)) {
if (ConsumedError(CreateShaderModule(descriptor, compilationMessages.get()), &result,
"calling CreateShaderModule(%s).", descriptor)) {
DAWN_ASSERT(result == nullptr);
result = ShaderModuleBase::MakeError(this);
}
@ -968,14 +980,16 @@ namespace dawn_native {
SwapChainBase* DeviceBase::APICreateSwapChain(Surface* surface,
const SwapChainDescriptor* descriptor) {
Ref<SwapChainBase> result;
if (ConsumedError(CreateSwapChain(surface, descriptor), &result)) {
if (ConsumedError(CreateSwapChain(surface, descriptor), &result,
"calling CreateSwapChain(%s).", descriptor)) {
return SwapChainBase::MakeError(this);
}
return result.Detach();
}
TextureBase* DeviceBase::APICreateTexture(const TextureDescriptor* descriptor) {
Ref<TextureBase> result;
if (ConsumedError(CreateTexture(descriptor), &result)) {
if (ConsumedError(CreateTexture(descriptor), &result, "calling CreateTexture(%s).",
descriptor)) {
return TextureBase::MakeError(this);
}
return result.Detach();
@ -1042,7 +1056,8 @@ namespace dawn_native {
ExternalTextureBase* DeviceBase::APICreateExternalTexture(
const ExternalTextureDescriptor* descriptor) {
Ref<ExternalTextureBase> result = nullptr;
if (ConsumedError(CreateExternalTexture(descriptor), &result)) {
if (ConsumedError(CreateExternalTexture(descriptor), &result,
"calling CreateExternalTexture(%s).", descriptor)) {
return ExternalTextureBase::MakeError(this);
}

View File

@ -78,6 +78,27 @@ namespace dawn_native {
return false;
}
template <typename T, typename... Args>
bool ConsumedError(ResultOrError<T> resultOrError,
T* result,
const char* formatStr,
const Args&... args) {
if (DAWN_UNLIKELY(resultOrError.IsError())) {
std::unique_ptr<ErrorData> error = resultOrError.AcquireError();
if (error->GetType() == InternalErrorType::Validation) {
std::string out;
absl::UntypedFormatSpec format(formatStr);
if (absl::FormatUntyped(&out, format, {absl::FormatArg(args)...})) {
error->AppendContext(std::move(out));
}
}
ConsumeError(std::move(error));
return true;
}
*result = resultOrError.AcquireSuccess();
return false;
}
MaybeError ValidateObject(const ApiObjectBase* object) const;
AdapterBase* GetAdapter() const;

View File

@ -51,6 +51,25 @@ namespace dawn_native {
return false;
}
template <typename... Args>
inline bool ConsumedError(MaybeError maybeError,
const char* formatStr,
const Args&... args) {
if (DAWN_UNLIKELY(maybeError.IsError())) {
std::unique_ptr<ErrorData> error = maybeError.AcquireError();
if (error->GetType() == InternalErrorType::Validation) {
std::string out;
absl::UntypedFormatSpec format(formatStr);
if (absl::FormatUntyped(&out, format, {absl::FormatArg(args)...})) {
error->AppendContext(std::move(out));
}
}
HandleError(std::move(error));
return true;
}
return false;
}
inline bool CheckCurrentEncoder(const ObjectBase* encoder) {
if (DAWN_UNLIKELY(encoder != mCurrentEncoder)) {
if (mCurrentEncoder != mTopLevelEncoder) {
@ -74,6 +93,18 @@ namespace dawn_native {
return !ConsumedError(encodeFunction(&mPendingCommands));
}
template <typename EncodeFunction, typename... Args>
inline bool TryEncode(const ObjectBase* encoder,
EncodeFunction&& encodeFunction,
const char* formatStr,
const Args&... args) {
if (!CheckCurrentEncoder(encoder)) {
return false;
}
ASSERT(!mWasMovedToIterator);
return !ConsumedError(encodeFunction(&mPendingCommands), formatStr, args...);
}
// Must be called prior to encoding a BeginRenderPassCmd. Note that it's OK to call this
// and then not actually call EnterPass+ExitRenderPass, for example if some other pass setup
// failed validation before the BeginRenderPassCmd could be encoded.

View File

@ -55,7 +55,9 @@ namespace dawn_native {
}
void ProgrammablePassEncoder::APIInsertDebugMarker(const char* groupLabel) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
InsertDebugMarkerCmd* cmd =
allocator->Allocate<InsertDebugMarkerCmd>(Command::InsertDebugMarker);
cmd->length = strlen(groupLabel);
@ -64,25 +66,32 @@ namespace dawn_native {
memcpy(label, groupLabel, cmd->length + 1);
return {};
});
},
"encoding InsertDebugMarker(\"%s\")", groupLabel);
}
void ProgrammablePassEncoder::APIPopDebugGroup() {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) {
if (mDebugGroupStackSize == 0) {
return DAWN_VALIDATION_ERROR("Pop must be balanced by a corresponding Push.");
return DAWN_VALIDATION_ERROR(
"Pop must be balanced by a corresponding Push.");
}
}
allocator->Allocate<PopDebugGroupCmd>(Command::PopDebugGroup);
mDebugGroupStackSize--;
return {};
});
},
"encoding PopDebugGroup()");
}
void ProgrammablePassEncoder::APIPushDebugGroup(const char* groupLabel) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
PushDebugGroupCmd* cmd =
allocator->Allocate<PushDebugGroupCmd>(Command::PushDebugGroup);
cmd->length = strlen(groupLabel);
@ -93,7 +102,8 @@ namespace dawn_native {
mDebugGroupStackSize++;
return {};
});
},
"encoding PushDebugGroup(\"%s\")", groupLabel);
}
MaybeError ProgrammablePassEncoder::ValidateSetBindGroup(

View File

@ -61,7 +61,9 @@ namespace dawn_native {
uint32_t instanceCount,
uint32_t firstVertex,
uint32_t firstInstance) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) {
DAWN_TRY(mCommandBufferState.ValidateCanDraw());
@ -70,8 +72,8 @@ namespace dawn_native {
DAWN_TRY(mCommandBufferState.ValidateBufferInRangeForVertexBuffer(vertexCount,
firstVertex));
DAWN_TRY(mCommandBufferState.ValidateBufferInRangeForInstanceBuffer(instanceCount,
firstInstance));
DAWN_TRY(mCommandBufferState.ValidateBufferInRangeForInstanceBuffer(
instanceCount, firstInstance));
}
DrawCmd* draw = allocator->Allocate<DrawCmd>(Command::Draw);
@ -81,7 +83,9 @@ namespace dawn_native {
draw->firstInstance = firstInstance;
return {};
});
},
"encoding Draw(%u, %u, %u, %u).", vertexCount, instanceCount, firstVertex,
firstInstance);
}
void RenderEncoderBase::APIDrawIndexed(uint32_t indexCount,
@ -89,7 +93,9 @@ namespace dawn_native {
uint32_t firstIndex,
int32_t baseVertex,
uint32_t firstInstance) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) {
DAWN_TRY(mCommandBufferState.ValidateCanDrawIndexed());
@ -99,14 +105,15 @@ namespace dawn_native {
DAWN_INVALID_IF(mDisableBaseVertex && baseVertex != 0,
"Base vertex (%u) must be zero.", baseVertex);
DAWN_TRY(mCommandBufferState.ValidateIndexBufferInRange(indexCount, firstIndex));
DAWN_TRY(
mCommandBufferState.ValidateIndexBufferInRange(indexCount, firstIndex));
// Although we don't know actual vertex access range in CPU, we still call the
// ValidateBufferInRangeForVertexBuffer in order to deal with those vertex step mode
// vertex buffer with an array stride of zero.
// ValidateBufferInRangeForVertexBuffer in order to deal with those vertex step
// mode vertex buffer with an array stride of zero.
DAWN_TRY(mCommandBufferState.ValidateBufferInRangeForVertexBuffer(0, 0));
DAWN_TRY(mCommandBufferState.ValidateBufferInRangeForInstanceBuffer(instanceCount,
firstInstance));
DAWN_TRY(mCommandBufferState.ValidateBufferInRangeForInstanceBuffer(
instanceCount, firstInstance));
}
DrawIndexedCmd* draw = allocator->Allocate<DrawIndexedCmd>(Command::DrawIndexed);
@ -117,11 +124,15 @@ namespace dawn_native {
draw->firstInstance = firstInstance;
return {};
});
},
"encoding DrawIndexed(%u, %u, %u, %i, %u).", indexCount, instanceCount, firstIndex,
baseVertex, firstInstance);
}
void RenderEncoderBase::APIDrawIndirect(BufferBase* indirectBuffer, uint64_t indirectOffset) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) {
DAWN_TRY(GetDevice()->ValidateObject(indirectBuffer));
DAWN_TRY(ValidateCanUseAs(indirectBuffer, wgpu::BufferUsage::Indirect));
@ -144,12 +155,15 @@ namespace dawn_native {
mUsageTracker.BufferUsedAs(indirectBuffer, wgpu::BufferUsage::Indirect);
return {};
});
},
"encoding DrawIndirect(%s, %u).", indirectBuffer, indirectOffset);
}
void RenderEncoderBase::APIDrawIndexedIndirect(BufferBase* indirectBuffer,
uint64_t indirectOffset) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) {
DAWN_TRY(GetDevice()->ValidateObject(indirectBuffer));
DAWN_TRY(ValidateCanUseAs(indirectBuffer, wgpu::BufferUsage::Indirect));
@ -170,24 +184,30 @@ namespace dawn_native {
if (IsValidationEnabled()) {
cmd->indirectBufferLocation = BufferLocation::New();
mIndirectDrawMetadata.AddIndexedIndirectDraw(
mCommandBufferState.GetIndexFormat(), mCommandBufferState.GetIndexBufferSize(),
indirectBuffer, indirectOffset, cmd->indirectBufferLocation.Get());
mCommandBufferState.GetIndexFormat(),
mCommandBufferState.GetIndexBufferSize(), indirectBuffer, indirectOffset,
cmd->indirectBufferLocation.Get());
} else {
cmd->indirectBufferLocation = BufferLocation::New(indirectBuffer, indirectOffset);
cmd->indirectBufferLocation =
BufferLocation::New(indirectBuffer, indirectOffset);
}
mUsageTracker.BufferUsedAs(indirectBuffer, wgpu::BufferUsage::Indirect);
return {};
});
},
"encoding DrawIndexedIndirect(%s, %u).", indirectBuffer, indirectOffset);
}
void RenderEncoderBase::APISetPipeline(RenderPipelineBase* pipeline) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) {
DAWN_TRY(GetDevice()->ValidateObject(pipeline));
// TODO(dawn:563): More detail about why the states are incompatible would be nice.
// TODO(dawn:563): More detail about why the states are incompatible would be
// nice.
DAWN_INVALID_IF(
pipeline->GetAttachmentState() != mAttachmentState.Get(),
"Attachment state of %s is not compatible with the attachment state of %s",
@ -201,14 +221,17 @@ namespace dawn_native {
cmd->pipeline = pipeline;
return {};
});
},
"encoding SetPipeline(%s).", pipeline);
}
void RenderEncoderBase::APISetIndexBuffer(BufferBase* buffer,
wgpu::IndexFormat format,
uint64_t offset,
uint64_t size) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) {
DAWN_TRY(GetDevice()->ValidateObject(buffer));
DAWN_TRY(ValidateCanUseAs(buffer, wgpu::BufferUsage::Index));
@ -235,15 +258,16 @@ namespace dawn_native {
GetDevice()->EmitDeprecationWarning(
"Using size=0 to indicate default binding size for setIndexBuffer "
"is deprecated. In the future it will result in a zero-size binding. "
"Use `undefined` (wgpu::kWholeSize) or just omit the parameter instead.");
"Use `undefined` (wgpu::kWholeSize) or just omit the parameter "
"instead.");
}
if (size == wgpu::kWholeSize) {
size = remainingSize;
} else {
DAWN_INVALID_IF(
size > remainingSize,
"Index buffer range (offset: %u, size: %u) doesn't fit in the size (%u) of "
DAWN_INVALID_IF(size > remainingSize,
"Index buffer range (offset: %u, size: %u) doesn't fit in "
"the size (%u) of "
"%s.",
offset, size, bufferSize, buffer);
}
@ -266,14 +290,17 @@ namespace dawn_native {
mUsageTracker.BufferUsedAs(buffer, wgpu::BufferUsage::Index);
return {};
});
},
"encoding SetIndexBuffer(%s, %s, %u, %u).", buffer, format, offset, size);
}
void RenderEncoderBase::APISetVertexBuffer(uint32_t slot,
BufferBase* buffer,
uint64_t offset,
uint64_t size) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) {
DAWN_TRY(GetDevice()->ValidateObject(buffer));
DAWN_TRY(ValidateCanUseAs(buffer, wgpu::BufferUsage::Vertex));
@ -282,8 +309,8 @@ namespace dawn_native {
"Vertex buffer slot (%u) is larger the maximum (%u)", slot,
kMaxVertexBuffers - 1);
DAWN_INVALID_IF(offset % 4 != 0, "Vertex buffer offset (%u) is not a multiple of 4",
offset);
DAWN_INVALID_IF(offset % 4 != 0,
"Vertex buffer offset (%u) is not a multiple of 4", offset);
uint64_t bufferSize = buffer->GetSize();
DAWN_INVALID_IF(offset > bufferSize,
@ -299,15 +326,16 @@ namespace dawn_native {
GetDevice()->EmitDeprecationWarning(
"Using size=0 to indicate default binding size for setVertexBuffer "
"is deprecated. In the future it will result in a zero-size binding. "
"Use `undefined` (wgpu::kWholeSize) or just omit the parameter instead.");
"Use `undefined` (wgpu::kWholeSize) or just omit the parameter "
"instead.");
}
if (size == wgpu::kWholeSize) {
size = remainingSize;
} else {
DAWN_INVALID_IF(
size > remainingSize,
"Vertex buffer range (offset: %u, size: %u) doesn't fit in the size (%u) "
DAWN_INVALID_IF(size > remainingSize,
"Vertex buffer range (offset: %u, size: %u) doesn't fit in "
"the size (%u) "
"of %s.",
offset, size, bufferSize, buffer);
}
@ -330,27 +358,32 @@ namespace dawn_native {
mUsageTracker.BufferUsedAs(buffer, wgpu::BufferUsage::Vertex);
return {};
});
},
"encoding SetVertexBuffer(%u, %s, %u, %u).", slot, buffer, offset, size);
}
void RenderEncoderBase::APISetBindGroup(uint32_t groupIndexIn,
BindGroupBase* group,
uint32_t dynamicOffsetCount,
const uint32_t* dynamicOffsets) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
BindGroupIndex groupIndex(groupIndexIn);
if (IsValidationEnabled()) {
DAWN_TRY(
ValidateSetBindGroup(groupIndex, group, dynamicOffsetCount, dynamicOffsets));
DAWN_TRY(ValidateSetBindGroup(groupIndex, group, dynamicOffsetCount,
dynamicOffsets));
}
RecordSetBindGroup(allocator, groupIndex, group, dynamicOffsetCount, dynamicOffsets);
RecordSetBindGroup(allocator, groupIndex, group, dynamicOffsetCount,
dynamicOffsets);
mCommandBufferState.SetBindGroup(groupIndex, group);
mUsageTracker.AddBindGroup(group);
return {};
});
},
"encoding SetBindGroup(%u, %s, %u).", groupIndexIn, group, dynamicOffsetCount);
}
} // namespace dawn_native

View File

@ -93,7 +93,9 @@ namespace dawn_native {
}
void RenderPassEncoder::APIEndPass() {
if (mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
if (mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) {
DAWN_TRY(ValidateProgrammableEncoderEnd());
@ -108,28 +110,35 @@ namespace dawn_native {
mCommandEncoder.Get(),
std::move(mIndirectDrawMetadata)));
return {};
})) {
},
"encoding EndPass().")) {
}
}
void RenderPassEncoder::APISetStencilReference(uint32_t reference) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
SetStencilReferenceCmd* cmd =
allocator->Allocate<SetStencilReferenceCmd>(Command::SetStencilReference);
cmd->reference = reference;
return {};
});
},
"encoding SetStencilReference(%u)", reference);
}
void RenderPassEncoder::APISetBlendConstant(const Color* color) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
SetBlendConstantCmd* cmd =
allocator->Allocate<SetBlendConstantCmd>(Command::SetBlendConstant);
cmd->color = *color;
return {};
});
},
"encoding SetBlendConstant(%s).", color);
}
void RenderPassEncoder::APISetViewport(float x,
@ -138,10 +147,13 @@ namespace dawn_native {
float height,
float minDepth,
float maxDepth) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) {
DAWN_INVALID_IF((isnan(x) || isnan(y) || isnan(width) || isnan(height) ||
isnan(minDepth) || isnan(maxDepth)),
DAWN_INVALID_IF(
(isnan(x) || isnan(y) || isnan(width) || isnan(height) || isnan(minDepth) ||
isnan(maxDepth)),
"A parameter of the viewport (x: %f, y: %f, width: %f, height: %f, "
"minDepth: %f, maxDepth: %f) is NaN.",
x, y, width, height, minDepth, maxDepth);
@ -154,14 +166,15 @@ namespace dawn_native {
DAWN_INVALID_IF(
x + width > mRenderTargetWidth || y + height > mRenderTargetHeight,
"Viewport bounds (x: %f, y: %f, width: %f, height: %f) are not contained in "
"Viewport bounds (x: %f, y: %f, width: %f, height: %f) are not contained "
"in "
"the render target dimensions (%u x %u).",
x, y, width, height, mRenderTargetWidth, mRenderTargetHeight);
// Check for depths being in [0, 1] and min <= max in 3 checks instead of 5.
DAWN_INVALID_IF(
minDepth < 0 || minDepth > maxDepth || maxDepth > 1,
"Viewport minDepth (%f) and maxDepth (%f) are not in [0, 1] or minDepth was "
DAWN_INVALID_IF(minDepth < 0 || minDepth > maxDepth || maxDepth > 1,
"Viewport minDepth (%f) and maxDepth (%f) are not in [0, 1] or "
"minDepth was "
"greater than maxDepth.",
minDepth, maxDepth);
}
@ -175,14 +188,18 @@ namespace dawn_native {
cmd->maxDepth = maxDepth;
return {};
});
},
"encoding SetViewport(%f, %f, %f, %f, %f, %f).", x, y, width, height, minDepth,
maxDepth);
}
void RenderPassEncoder::APISetScissorRect(uint32_t x,
uint32_t y,
uint32_t width,
uint32_t height) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) {
DAWN_INVALID_IF(
width > mRenderTargetWidth || height > mRenderTargetHeight ||
@ -200,12 +217,15 @@ namespace dawn_native {
cmd->height = height;
return {};
});
},
"encoding SetScissorRect(%u, %u, %u, %u).", x, y, width, height);
}
void RenderPassEncoder::APIExecuteBundles(uint32_t count,
RenderBundleBase* const* renderBundles) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) {
for (uint32_t i = 0; i < count; ++i) {
DAWN_TRY(GetDevice()->ValidateObject(renderBundles[i]));
@ -225,7 +245,8 @@ namespace dawn_native {
allocator->Allocate<ExecuteBundlesCmd>(Command::ExecuteBundles);
cmd->count = count;
Ref<RenderBundleBase>* bundles = allocator->AllocateData<Ref<RenderBundleBase>>(count);
Ref<RenderBundleBase>* bundles =
allocator->AllocateData<Ref<RenderBundleBase>>(count);
for (uint32_t i = 0; i < count; ++i) {
bundles[i] = renderBundles[i];
@ -245,11 +266,14 @@ namespace dawn_native {
}
return {};
});
},
"encoding ExecuteBundles(%u, ...)", count);
}
void RenderPassEncoder::APIBeginOcclusionQuery(uint32_t queryIndex) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) {
DAWN_INVALID_IF(mOcclusionQuerySet.Get() == nullptr,
"The occlusionQuerySet in RenderPassDescriptor is not set.");
@ -282,11 +306,14 @@ namespace dawn_native {
cmd->queryIndex = queryIndex;
return {};
});
},
"encoding BeginOcclusionQuery(%u)", queryIndex);
}
void RenderPassEncoder::APIEndOcclusionQuery() {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) {
DAWN_INVALID_IF(!mOcclusionQueryActive, "No occlusion queries are active.");
}
@ -301,18 +328,21 @@ namespace dawn_native {
cmd->queryIndex = mCurrentOcclusionQueryIndex;
return {};
});
},
"encoding EndOcclusionQuery()");
}
void RenderPassEncoder::APIWriteTimestamp(QuerySetBase* querySet, uint32_t queryIndex) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) {
DAWN_TRY(GetDevice()->ValidateObject(querySet));
DAWN_TRY(ValidateTimestampQuery(querySet, queryIndex));
DAWN_TRY_CONTEXT(ValidateQueryIndexOverwrite(
querySet, queryIndex, mUsageTracker.GetQueryAvailabilityMap()),
"validating the timestamp query index (%u) of %s", queryIndex,
querySet);
DAWN_TRY_CONTEXT(
ValidateQueryIndexOverwrite(querySet, queryIndex,
mUsageTracker.GetQueryAvailabilityMap()),
"validating the timestamp query index (%u) of %s", queryIndex, querySet);
}
TrackQueryAvailability(querySet, queryIndex);
@ -323,7 +353,8 @@ namespace dawn_native {
cmd->queryIndex = queryIndex;
return {};
});
},
"encoding WriteTimestamp(%s, %u).", querySet, queryIndex);
}
} // namespace dawn_native