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 { 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 // Objects
// //
@ -29,6 +59,10 @@ namespace dawn_native {
AbslFormatConvert(const DeviceBase* value, AbslFormatConvert(const DeviceBase* value,
const absl::FormatConversionSpec& spec, const absl::FormatConversionSpec& spec,
absl::FormatSink* s) { absl::FormatSink* s) {
if (value == nullptr) {
s->Append("[null]");
return {true};
}
s->Append("[Device"); s->Append("[Device");
const std::string& label = value->GetLabel(); const std::string& label = value->GetLabel();
if (!label.empty()) { if (!label.empty()) {
@ -42,6 +76,10 @@ namespace dawn_native {
AbslFormatConvert(const ApiObjectBase* value, AbslFormatConvert(const ApiObjectBase* value,
const absl::FormatConversionSpec& spec, const absl::FormatConversionSpec& spec,
absl::FormatSink* s) { absl::FormatSink* s) {
if (value == nullptr) {
s->Append("[null]");
return {true};
}
s->Append("["); s->Append("[");
s->Append(ObjectTypeAsString(value->GetType())); s->Append(ObjectTypeAsString(value->GetType()));
const std::string& label = value->GetLabel(); const std::string& label = value->GetLabel();
@ -56,6 +94,10 @@ namespace dawn_native {
AbslFormatConvert(const TextureViewBase* value, AbslFormatConvert(const TextureViewBase* value,
const absl::FormatConversionSpec& spec, const absl::FormatConversionSpec& spec,
absl::FormatSink* s) { absl::FormatSink* s) {
if (value == nullptr) {
s->Append("[null]");
return {true};
}
s->Append("["); s->Append("[");
s->Append(ObjectTypeAsString(value->GetType())); s->Append(ObjectTypeAsString(value->GetType()));
const std::string& label = value->GetLabel(); const std::string& label = value->GetLabel();
@ -81,6 +123,10 @@ namespace dawn_native {
AbslFormatConvert(const {{as_cppType(type.name)}}* value, AbslFormatConvert(const {{as_cppType(type.name)}}* value,
const absl::FormatConversionSpec& spec, const absl::FormatConversionSpec& spec,
absl::FormatSink* s) { absl::FormatSink* s) {
if (value == nullptr) {
s->Append("[null]");
return {true};
}
s->Append("[{{as_cppType(type.name)}}"); s->Append("[{{as_cppType(type.name)}}");
if (value->label != nullptr) { if (value->label != nullptr) {
s->Append(absl::StrFormat(" \"%s\"", value->label)); s->Append(absl::StrFormat(" \"%s\"", value->label));

View File

@ -21,6 +21,22 @@
namespace dawn_native { 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 // Objects
// //

View File

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

View File

@ -63,7 +63,9 @@ namespace dawn_native {
} }
void ComputePassEncoder::APIEndPass() { void ComputePassEncoder::APIEndPass() {
if (mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError { if (mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) { if (IsValidationEnabled()) {
DAWN_TRY(ValidateProgrammableEncoderEnd()); DAWN_TRY(ValidateProgrammableEncoderEnd());
} }
@ -71,13 +73,16 @@ namespace dawn_native {
allocator->Allocate<EndComputePassCmd>(Command::EndComputePass); allocator->Allocate<EndComputePassCmd>(Command::EndComputePass);
return {}; return {};
})) { },
"encoding EndPass()")) {
mEncodingContext->ExitComputePass(this, mUsageTracker.AcquireResourceUsage()); mEncodingContext->ExitComputePass(this, mUsageTracker.AcquireResourceUsage());
} }
} }
void ComputePassEncoder::APIDispatch(uint32_t x, uint32_t y, uint32_t z) { 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()) { if (IsValidationEnabled()) {
DAWN_TRY(mCommandBufferState.ValidateCanDispatch()); DAWN_TRY(mCommandBufferState.ValidateCanDispatch());
DAWN_TRY(ValidatePerDimensionDispatchSizeLimit(x)); DAWN_TRY(ValidatePerDimensionDispatchSizeLimit(x));
@ -85,7 +90,8 @@ namespace dawn_native {
DAWN_TRY(ValidatePerDimensionDispatchSizeLimit(z)); 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(); AddDispatchSyncScope();
DispatchCmd* dispatch = allocator->Allocate<DispatchCmd>(Command::Dispatch); DispatchCmd* dispatch = allocator->Allocate<DispatchCmd>(Command::Dispatch);
@ -94,20 +100,23 @@ namespace dawn_native {
dispatch->z = z; dispatch->z = z;
return {}; return {};
}); },
"encoding Dispatch (x: %u, y: %u, z: %u)", x, y, z);
} }
void ComputePassEncoder::APIDispatchIndirect(BufferBase* indirectBuffer, void ComputePassEncoder::APIDispatchIndirect(BufferBase* indirectBuffer,
uint64_t indirectOffset) { uint64_t indirectOffset) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError { mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) { if (IsValidationEnabled()) {
DAWN_TRY(GetDevice()->ValidateObject(indirectBuffer)); DAWN_TRY(GetDevice()->ValidateObject(indirectBuffer));
DAWN_TRY(ValidateCanUseAs(indirectBuffer, wgpu::BufferUsage::Indirect)); DAWN_TRY(ValidateCanUseAs(indirectBuffer, wgpu::BufferUsage::Indirect));
DAWN_TRY(mCommandBufferState.ValidateCanDispatch()); DAWN_TRY(mCommandBufferState.ValidateCanDispatch());
// Indexed dispatches need a compute-shader based validation to check that the // 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 // dispatch sizes aren't too big. Disallow them as unsafe until the validation
// implemented. // is implemented.
if (GetDevice()->IsToggleEnabled(Toggle::DisallowUnsafeAPIs)) { if (GetDevice()->IsToggleEnabled(Toggle::DisallowUnsafeAPIs)) {
return DAWN_VALIDATION_ERROR( return DAWN_VALIDATION_ERROR(
"DispatchIndirect is disallowed because it doesn't validate that the " "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 // Record the synchronization scope for Dispatch, both the bindgroups and the
// buffer. // indirect buffer.
SyncScopeUsageTracker scope; SyncScopeUsageTracker scope;
scope.BufferUsedAs(indirectBuffer, wgpu::BufferUsage::Indirect); scope.BufferUsedAs(indirectBuffer, wgpu::BufferUsage::Indirect);
mUsageTracker.AddReferencedBuffer(indirectBuffer); mUsageTracker.AddReferencedBuffer(indirectBuffer);
@ -138,11 +147,14 @@ namespace dawn_native {
dispatch->indirectOffset = indirectOffset; dispatch->indirectOffset = indirectOffset;
return {}; return {};
}); },
"encoding DispatchIndirect with %s", indirectBuffer);
} }
void ComputePassEncoder::APISetPipeline(ComputePipelineBase* pipeline) { void ComputePassEncoder::APISetPipeline(ComputePipelineBase* pipeline) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError { mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) { if (IsValidationEnabled()) {
DAWN_TRY(GetDevice()->ValidateObject(pipeline)); DAWN_TRY(GetDevice()->ValidateObject(pipeline));
} }
@ -154,32 +166,39 @@ namespace dawn_native {
cmd->pipeline = pipeline; cmd->pipeline = pipeline;
return {}; return {};
}); },
"encoding SetPipeline with %s", pipeline);
} }
void ComputePassEncoder::APISetBindGroup(uint32_t groupIndexIn, void ComputePassEncoder::APISetBindGroup(uint32_t groupIndexIn,
BindGroupBase* group, BindGroupBase* group,
uint32_t dynamicOffsetCount, uint32_t dynamicOffsetCount,
const uint32_t* dynamicOffsets) { const uint32_t* dynamicOffsets) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError { mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
BindGroupIndex groupIndex(groupIndexIn); BindGroupIndex groupIndex(groupIndexIn);
if (IsValidationEnabled()) { if (IsValidationEnabled()) {
DAWN_TRY( DAWN_TRY(ValidateSetBindGroup(groupIndex, group, dynamicOffsetCount,
ValidateSetBindGroup(groupIndex, group, dynamicOffsetCount, dynamicOffsets)); dynamicOffsets));
} }
mUsageTracker.AddResourcesReferencedByBindGroup(group); mUsageTracker.AddResourcesReferencedByBindGroup(group);
RecordSetBindGroup(allocator, groupIndex, group, dynamicOffsetCount, dynamicOffsets); RecordSetBindGroup(allocator, groupIndex, group, dynamicOffsetCount,
dynamicOffsets);
mCommandBufferState.SetBindGroup(groupIndex, group); mCommandBufferState.SetBindGroup(groupIndex, group);
return {}; return {};
}); },
"encoding SetBindGroup with %s at index %u", group, groupIndexIn);
} }
void ComputePassEncoder::APIWriteTimestamp(QuerySetBase* querySet, uint32_t queryIndex) { void ComputePassEncoder::APIWriteTimestamp(QuerySetBase* querySet, uint32_t queryIndex) {
mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError { mEncodingContext->TryEncode(
this,
[&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) { if (IsValidationEnabled()) {
DAWN_TRY(GetDevice()->ValidateObject(querySet)); DAWN_TRY(GetDevice()->ValidateObject(querySet));
DAWN_TRY(ValidateTimestampQuery(querySet, queryIndex)); DAWN_TRY(ValidateTimestampQuery(querySet, queryIndex));
@ -193,7 +212,8 @@ namespace dawn_native {
cmd->queryIndex = queryIndex; cmd->queryIndex = queryIndex;
return {}; return {};
}); },
"encoding WriteTimestamp to %s.", querySet);
} }
void ComputePassEncoder::AddDispatchSyncScope(SyncScopeUsageTracker scope) { 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, "%s is associated with %s, and cannot be used with %s.", object,
object->GetDevice(), this); object->GetDevice(), this);
// TODO(dawn:563): Preserve labels for error objects.
DAWN_INVALID_IF(object->IsError(), "%s is an error.", object); DAWN_INVALID_IF(object->IsError(), "%s is an error.", object);
return {}; return {};
@ -852,7 +853,8 @@ namespace dawn_native {
BindGroupBase* DeviceBase::APICreateBindGroup(const BindGroupDescriptor* descriptor) { BindGroupBase* DeviceBase::APICreateBindGroup(const BindGroupDescriptor* descriptor) {
Ref<BindGroupBase> result; Ref<BindGroupBase> result;
if (ConsumedError(CreateBindGroup(descriptor), &result)) { if (ConsumedError(CreateBindGroup(descriptor), &result, "calling CreateBindGroup(%s).",
descriptor)) {
return BindGroupBase::MakeError(this); return BindGroupBase::MakeError(this);
} }
return result.Detach(); return result.Detach();
@ -860,14 +862,16 @@ namespace dawn_native {
BindGroupLayoutBase* DeviceBase::APICreateBindGroupLayout( BindGroupLayoutBase* DeviceBase::APICreateBindGroupLayout(
const BindGroupLayoutDescriptor* descriptor) { const BindGroupLayoutDescriptor* descriptor) {
Ref<BindGroupLayoutBase> result; Ref<BindGroupLayoutBase> result;
if (ConsumedError(CreateBindGroupLayout(descriptor), &result)) { if (ConsumedError(CreateBindGroupLayout(descriptor), &result,
"calling CreateBindGroupLayout(%s).", descriptor)) {
return BindGroupLayoutBase::MakeError(this); return BindGroupLayoutBase::MakeError(this);
} }
return result.Detach(); return result.Detach();
} }
BufferBase* DeviceBase::APICreateBuffer(const BufferDescriptor* descriptor) { BufferBase* DeviceBase::APICreateBuffer(const BufferDescriptor* descriptor) {
Ref<BufferBase> result = nullptr; Ref<BufferBase> result = nullptr;
if (ConsumedError(CreateBuffer(descriptor), &result)) { if (ConsumedError(CreateBuffer(descriptor), &result, "calling CreateBuffer(%s).",
descriptor)) {
ASSERT(result == nullptr); ASSERT(result == nullptr);
return BufferBase::MakeError(this, descriptor); return BufferBase::MakeError(this, descriptor);
} }
@ -880,7 +884,8 @@ namespace dawn_native {
ComputePipelineBase* DeviceBase::APICreateComputePipeline( ComputePipelineBase* DeviceBase::APICreateComputePipeline(
const ComputePipelineDescriptor* descriptor) { const ComputePipelineDescriptor* descriptor) {
Ref<ComputePipelineBase> result; Ref<ComputePipelineBase> result;
if (ConsumedError(CreateComputePipeline(descriptor), &result)) { if (ConsumedError(CreateComputePipeline(descriptor), &result,
"calling CreateComputePipeline(%s).", descriptor)) {
return ComputePipelineBase::MakeError(this); return ComputePipelineBase::MakeError(this);
} }
return result.Detach(); return result.Detach();
@ -902,21 +907,24 @@ namespace dawn_native {
PipelineLayoutBase* DeviceBase::APICreatePipelineLayout( PipelineLayoutBase* DeviceBase::APICreatePipelineLayout(
const PipelineLayoutDescriptor* descriptor) { const PipelineLayoutDescriptor* descriptor) {
Ref<PipelineLayoutBase> result; Ref<PipelineLayoutBase> result;
if (ConsumedError(CreatePipelineLayout(descriptor), &result)) { if (ConsumedError(CreatePipelineLayout(descriptor), &result,
"calling CreatePipelineLayout(%s).", descriptor)) {
return PipelineLayoutBase::MakeError(this); return PipelineLayoutBase::MakeError(this);
} }
return result.Detach(); return result.Detach();
} }
QuerySetBase* DeviceBase::APICreateQuerySet(const QuerySetDescriptor* descriptor) { QuerySetBase* DeviceBase::APICreateQuerySet(const QuerySetDescriptor* descriptor) {
Ref<QuerySetBase> result; Ref<QuerySetBase> result;
if (ConsumedError(CreateQuerySet(descriptor), &result)) { if (ConsumedError(CreateQuerySet(descriptor), &result, "calling CreateQuerySet(%s).",
descriptor)) {
return QuerySetBase::MakeError(this); return QuerySetBase::MakeError(this);
} }
return result.Detach(); return result.Detach();
} }
SamplerBase* DeviceBase::APICreateSampler(const SamplerDescriptor* descriptor) { SamplerBase* DeviceBase::APICreateSampler(const SamplerDescriptor* descriptor) {
Ref<SamplerBase> result; Ref<SamplerBase> result;
if (ConsumedError(CreateSampler(descriptor), &result)) { if (ConsumedError(CreateSampler(descriptor), &result, "calling CreateSampler(%s).",
descriptor)) {
return SamplerBase::MakeError(this); return SamplerBase::MakeError(this);
} }
return result.Detach(); return result.Detach();
@ -924,6 +932,7 @@ namespace dawn_native {
void DeviceBase::APICreateRenderPipelineAsync(const RenderPipelineDescriptor* descriptor, void DeviceBase::APICreateRenderPipelineAsync(const RenderPipelineDescriptor* descriptor,
WGPUCreateRenderPipelineAsyncCallback callback, WGPUCreateRenderPipelineAsyncCallback callback,
void* userdata) { void* userdata) {
// TODO(dawn:563): Add validation error context.
MaybeError maybeResult = CreateRenderPipelineAsync(descriptor, callback, userdata); MaybeError maybeResult = CreateRenderPipelineAsync(descriptor, callback, userdata);
// Call the callback directly when a validation error has been found in the front-end // 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( RenderBundleEncoder* DeviceBase::APICreateRenderBundleEncoder(
const RenderBundleEncoderDescriptor* descriptor) { const RenderBundleEncoderDescriptor* descriptor) {
Ref<RenderBundleEncoder> result; Ref<RenderBundleEncoder> result;
if (ConsumedError(CreateRenderBundleEncoder(descriptor), &result)) { if (ConsumedError(CreateRenderBundleEncoder(descriptor), &result,
"calling CreateRenderBundleEncoder(%s).", descriptor)) {
return RenderBundleEncoder::MakeError(this); return RenderBundleEncoder::MakeError(this);
} }
return result.Detach(); return result.Detach();
@ -946,7 +956,8 @@ namespace dawn_native {
RenderPipelineBase* DeviceBase::APICreateRenderPipeline( RenderPipelineBase* DeviceBase::APICreateRenderPipeline(
const RenderPipelineDescriptor* descriptor) { const RenderPipelineDescriptor* descriptor) {
Ref<RenderPipelineBase> result; Ref<RenderPipelineBase> result;
if (ConsumedError(CreateRenderPipeline(descriptor), &result)) { if (ConsumedError(CreateRenderPipeline(descriptor), &result,
"calling CreateRenderPipeline(%s).", descriptor)) {
return RenderPipelineBase::MakeError(this); return RenderPipelineBase::MakeError(this);
} }
return result.Detach(); return result.Detach();
@ -955,7 +966,8 @@ namespace dawn_native {
Ref<ShaderModuleBase> result; Ref<ShaderModuleBase> result;
std::unique_ptr<OwnedCompilationMessages> compilationMessages( std::unique_ptr<OwnedCompilationMessages> compilationMessages(
std::make_unique<OwnedCompilationMessages>()); 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); DAWN_ASSERT(result == nullptr);
result = ShaderModuleBase::MakeError(this); result = ShaderModuleBase::MakeError(this);
} }
@ -968,14 +980,16 @@ namespace dawn_native {
SwapChainBase* DeviceBase::APICreateSwapChain(Surface* surface, SwapChainBase* DeviceBase::APICreateSwapChain(Surface* surface,
const SwapChainDescriptor* descriptor) { const SwapChainDescriptor* descriptor) {
Ref<SwapChainBase> result; Ref<SwapChainBase> result;
if (ConsumedError(CreateSwapChain(surface, descriptor), &result)) { if (ConsumedError(CreateSwapChain(surface, descriptor), &result,
"calling CreateSwapChain(%s).", descriptor)) {
return SwapChainBase::MakeError(this); return SwapChainBase::MakeError(this);
} }
return result.Detach(); return result.Detach();
} }
TextureBase* DeviceBase::APICreateTexture(const TextureDescriptor* descriptor) { TextureBase* DeviceBase::APICreateTexture(const TextureDescriptor* descriptor) {
Ref<TextureBase> result; Ref<TextureBase> result;
if (ConsumedError(CreateTexture(descriptor), &result)) { if (ConsumedError(CreateTexture(descriptor), &result, "calling CreateTexture(%s).",
descriptor)) {
return TextureBase::MakeError(this); return TextureBase::MakeError(this);
} }
return result.Detach(); return result.Detach();
@ -1042,7 +1056,8 @@ namespace dawn_native {
ExternalTextureBase* DeviceBase::APICreateExternalTexture( ExternalTextureBase* DeviceBase::APICreateExternalTexture(
const ExternalTextureDescriptor* descriptor) { const ExternalTextureDescriptor* descriptor) {
Ref<ExternalTextureBase> result = nullptr; Ref<ExternalTextureBase> result = nullptr;
if (ConsumedError(CreateExternalTexture(descriptor), &result)) { if (ConsumedError(CreateExternalTexture(descriptor), &result,
"calling CreateExternalTexture(%s).", descriptor)) {
return ExternalTextureBase::MakeError(this); return ExternalTextureBase::MakeError(this);
} }

View File

@ -78,6 +78,27 @@ namespace dawn_native {
return false; 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; MaybeError ValidateObject(const ApiObjectBase* object) const;
AdapterBase* GetAdapter() const; AdapterBase* GetAdapter() const;

View File

@ -51,6 +51,25 @@ namespace dawn_native {
return false; 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) { inline bool CheckCurrentEncoder(const ObjectBase* encoder) {
if (DAWN_UNLIKELY(encoder != mCurrentEncoder)) { if (DAWN_UNLIKELY(encoder != mCurrentEncoder)) {
if (mCurrentEncoder != mTopLevelEncoder) { if (mCurrentEncoder != mTopLevelEncoder) {
@ -74,6 +93,18 @@ namespace dawn_native {
return !ConsumedError(encodeFunction(&mPendingCommands)); 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 // 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 // and then not actually call EnterPass+ExitRenderPass, for example if some other pass setup
// failed validation before the BeginRenderPassCmd could be encoded. // failed validation before the BeginRenderPassCmd could be encoded.

View File

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

View File

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

View File

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