CopyFromStagingToBuffer: ASSERT size is not 0

Zero-sized copies are invalid in a couple backends, and in follow up
CLs CreateBufferMapped will be change to handle zero-sized buffers
correctly.

Bug: chromium:1069076
Change-Id: Ieef62a13182bbe1e939a3847980c91339e42aa8f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/22460
Reviewed-by: Stephen White <senorblanco@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2020-06-05 15:44:03 +00:00 committed by Commit Bot service account
parent 0a6a9d8692
commit 45aed839e9
4 changed files with 17 additions and 14 deletions

View File

@ -319,6 +319,10 @@ namespace dawn_native {
MaybeError BufferBase::CopyFromStagingBuffer() { MaybeError BufferBase::CopyFromStagingBuffer() {
ASSERT(mStagingBuffer); ASSERT(mStagingBuffer);
if (GetSize() == 0) {
return {};
}
DAWN_TRY(GetDevice()->CopyFromStagingToBuffer(mStagingBuffer.get(), 0, this, 0, GetSize())); DAWN_TRY(GetDevice()->CopyFromStagingToBuffer(mStagingBuffer.get(), 0, this, 0, GetSize()));
DynamicUploader* uploader = GetDevice()->GetDynamicUploader(); DynamicUploader* uploader = GetDevice()->GetDynamicUploader();

View File

@ -113,6 +113,10 @@ namespace dawn_native {
uint64_t bufferOffset, uint64_t bufferOffset,
const void* data, const void* data,
size_t size) { size_t size) {
if (size == 0) {
return {};
}
DeviceBase* device = GetDevice(); DeviceBase* device = GetDevice();
UploadHandle uploadHandle; UploadHandle uploadHandle;
@ -122,10 +126,8 @@ namespace dawn_native {
memcpy(uploadHandle.mappedBuffer, data, size); memcpy(uploadHandle.mappedBuffer, data, size);
DAWN_TRY(device->CopyFromStagingToBuffer( return device->CopyFromStagingToBuffer(uploadHandle.stagingBuffer, uploadHandle.startOffset,
uploadHandle.stagingBuffer, uploadHandle.startOffset, buffer, bufferOffset, size)); buffer, bufferOffset, size);
return {};
} }
MaybeError QueueBase::ValidateSubmit(uint32_t commandCount, MaybeError QueueBase::ValidateSubmit(uint32_t commandCount,

View File

@ -247,10 +247,9 @@ namespace dawn_native { namespace metal {
BufferBase* destination, BufferBase* destination,
uint64_t destinationOffset, uint64_t destinationOffset,
uint64_t size) { uint64_t size) {
// Metal validation layers forbid 0-sized copies, skip it since it is a noop. // Metal validation layers forbid 0-sized copies, assert it is skipped prior to calling
if (size == 0) { // this function.
return {}; ASSERT(size != 0);
}
id<MTLBuffer> uploadBuffer = ToBackend(source)->GetBufferHandle(); id<MTLBuffer> uploadBuffer = ToBackend(source)->GetBufferHandle();
id<MTLBuffer> buffer = ToBackend(destination)->GetMTLBuffer(); id<MTLBuffer> buffer = ToBackend(destination)->GetMTLBuffer();

View File

@ -541,12 +541,9 @@ namespace dawn_native { namespace vulkan {
BufferBase* destination, BufferBase* destination,
uint64_t destinationOffset, uint64_t destinationOffset,
uint64_t size) { uint64_t size) {
// It is a validation error to do a 0-sized copy in Vulkan skip it since it is a noop. // It is a validation error to do a 0-sized copy in Vulkan, check it is skipped prior to
if (size == 0) { // calling this function.
return {}; ASSERT(size != 0);
}
CommandRecordingContext* recordingContext = GetPendingRecordingContext();
// Insert memory barrier to ensure host write operations are made visible before // Insert memory barrier to ensure host write operations are made visible before
// copying from the staging buffer. However, this barrier can be removed (see note below). // copying from the staging buffer. However, this barrier can be removed (see note below).
@ -557,6 +554,7 @@ namespace dawn_native { namespace vulkan {
// Insert pipeline barrier to ensure correct ordering with previous memory operations on the // Insert pipeline barrier to ensure correct ordering with previous memory operations on the
// buffer. // buffer.
CommandRecordingContext* recordingContext = GetPendingRecordingContext();
ToBackend(destination)->TransitionUsageNow(recordingContext, wgpu::BufferUsage::CopyDst); ToBackend(destination)->TransitionUsageNow(recordingContext, wgpu::BufferUsage::CopyDst);
VkBufferCopy copy; VkBufferCopy copy;