Don't expose internal buffer usages in error messages

Previously the error messages about buffer usages would also include
the internal ones that are not set by the base WebGPU API (e.g.
kInternalStorageBuffer is showed when the buffer usage includes Indirect
or QueryResolve), which may confuse the developers.

This patch fixes this issue by implementing Buffer::GetUsageExternalOnly()
for front-end validations which only return the usages with which the
buffer was created using the base WebGPU API.

BUG=dawn:1382

Change-Id: Ie13135efaf2c3dab729d75a80eff486efa525c7e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/87382
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Jiawei Shao 2022-04-25 08:38:17 +00:00 committed by Dawn LUCI CQ
parent 534a353c7c
commit bd0f0a279c
5 changed files with 17 additions and 6 deletions

View File

@ -103,7 +103,7 @@ namespace dawn::native {
DAWN_INVALID_IF(!(entry.buffer->GetUsage() & requiredUsage),
"Binding usage (%s) of %s doesn't match expected usage (%s).",
entry.buffer->GetUsage(), entry.buffer, requiredUsage);
entry.buffer->GetUsageExternalOnly(), entry.buffer, requiredUsage);
DAWN_INVALID_IF(bindingSize < bindingInfo.buffer.minBindingSize,
"Binding size (%u) is smaller than the minimum binding size (%u).",

View File

@ -225,6 +225,10 @@ namespace dawn::native {
return mUsage;
}
wgpu::BufferUsage BufferBase::GetUsageExternalOnly() const {
return GetUsage() & ~kAllInternalBufferUsages;
}
MaybeError BufferBase::MapAtCreation() {
DAWN_TRY(MapAtCreationInternal());

View File

@ -56,7 +56,12 @@ namespace dawn::native {
uint64_t GetSize() const;
uint64_t GetAllocatedSize() const;
// |GetUsageExternalOnly| returns the usage with which the buffer was created using the
// base WebGPU API. Additional usages may be added for internal state tracking. |GetUsage|
// returns the union of base usage and the usages added internally.
wgpu::BufferUsage GetUsage() const;
wgpu::BufferUsage GetUsageExternalOnly() const;
MaybeError MapAtCreation();
void OnMapRequestCompleted(MapRequestID mapID, WGPUBufferMapAsyncStatus status);

View File

@ -97,9 +97,7 @@ namespace dawn::native {
"Write range (bufferOffset: %u, size: %u) does not fit in %s size (%u).",
bufferOffset, size, buffer, bufferSize);
DAWN_INVALID_IF(!(buffer->GetUsage() & wgpu::BufferUsage::CopyDst),
"%s usage (%s) does not include %s.", buffer, buffer->GetUsage(),
wgpu::BufferUsage::CopyDst);
DAWN_TRY(ValidateCanUseAs(buffer, wgpu::BufferUsage::CopyDst));
return {};
}
@ -485,8 +483,9 @@ namespace dawn::native {
MaybeError ValidateCanUseAs(const BufferBase* buffer, wgpu::BufferUsage usage) {
ASSERT(wgpu::HasZeroOrOneBits(usage));
DAWN_INVALID_IF(!(buffer->GetUsage() & usage), "%s usage (%s) doesn't include %s.", buffer,
buffer->GetUsage(), usage);
DAWN_INVALID_IF(!(buffer->GetUsageExternalOnly() & usage),
"%s usage (%s) doesn't include %s.", buffer, buffer->GetUsageExternalOnly(),
usage);
return {};
}

View File

@ -38,6 +38,9 @@ namespace dawn::native {
static constexpr wgpu::BufferUsage kReadOnlyStorageBuffer =
static_cast<wgpu::BufferUsage>(0x80000000);
static constexpr wgpu::BufferUsage kAllInternalBufferUsages =
kInternalStorageBuffer | kReadOnlyStorageBuffer;
// Extra texture usages
// Add an extra texture usage (readonly render attachment usage) for render pass resource
// tracking