Deprecate Buffer::SetSubData in favor of Queue::WriteBuffer
Bug: dawn:22
Change-Id: I00b3cd65ac4eb494b05918251f4b3b2bcaf24f71
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/22200
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
diff --git a/src/dawn_native/Buffer.cpp b/src/dawn_native/Buffer.cpp
index 6da550b..2b738b2 100644
--- a/src/dawn_native/Buffer.cpp
+++ b/src/dawn_native/Buffer.cpp
@@ -19,6 +19,7 @@
#include "dawn_native/DynamicUploader.h"
#include "dawn_native/ErrorData.h"
#include "dawn_native/MapRequestTracker.h"
+#include "dawn_native/Queue.h"
#include "dawn_native/ValidationUtils_autogen.h"
#include <cstdio>
@@ -62,10 +63,6 @@
return {};
}
- MaybeError SetSubDataImpl(uint32_t start, uint32_t count, const void* data) override {
- UNREACHABLE();
- return {};
- }
MaybeError MapReadAsyncImpl(uint32_t serial) override {
UNREACHABLE();
return {};
@@ -186,7 +183,7 @@
return {};
}
- MaybeError BufferBase::ValidateCanUseInSubmitNow() const {
+ MaybeError BufferBase::ValidateCanUseOnQueueNow() const {
ASSERT(!IsError());
switch (mState) {
@@ -244,14 +241,10 @@
}
void BufferBase::SetSubData(uint32_t start, uint32_t count, const void* data) {
- if (GetDevice()->ConsumedError(ValidateSetSubData(start, count))) {
- return;
- }
- ASSERT(!IsError());
-
- if (GetDevice()->ConsumedError(SetSubDataImpl(start, count, data))) {
- return;
- }
+ Ref<QueueBase> queue = AcquireRef(GetDevice()->GetDefaultQueue());
+ GetDevice()->EmitDeprecationWarning(
+ "Buffer::SetSubData is deprecated, use Queue::WriteBuffer instead");
+ queue->WriteBuffer(this, start, data, count);
}
void BufferBase::MapReadAsync(WGPUBufferMapReadCallback callback, void* userdata) {
@@ -279,22 +272,6 @@
tracker->Track(this, mMapSerial, false);
}
- MaybeError BufferBase::SetSubDataImpl(uint32_t start, uint32_t count, const void* data) {
- DynamicUploader* uploader = GetDevice()->GetDynamicUploader();
-
- UploadHandle uploadHandle;
- DAWN_TRY_ASSIGN(uploadHandle,
- uploader->Allocate(count, GetDevice()->GetPendingCommandSerial()));
- ASSERT(uploadHandle.mappedBuffer != nullptr);
-
- memcpy(uploadHandle.mappedBuffer, data, count);
-
- DAWN_TRY(GetDevice()->CopyFromStagingToBuffer(
- uploadHandle.stagingBuffer, uploadHandle.startOffset, this, start, count));
-
- return {};
- }
-
void BufferBase::MapWriteAsync(WGPUBufferMapWriteCallback callback, void* userdata) {
WGPUBufferMapAsyncStatus status;
if (GetDevice()->ConsumedError(ValidateMap(wgpu::BufferUsage::MapWrite, &status))) {
@@ -378,45 +355,6 @@
mMapUserdata = 0;
}
- MaybeError BufferBase::ValidateSetSubData(uint32_t start, uint32_t count) const {
- DAWN_TRY(GetDevice()->ValidateIsAlive());
- DAWN_TRY(GetDevice()->ValidateObject(this));
-
- switch (mState) {
- case BufferState::Mapped:
- return DAWN_VALIDATION_ERROR("Buffer is mapped");
- case BufferState::Destroyed:
- return DAWN_VALIDATION_ERROR("Buffer is destroyed");
- case BufferState::Unmapped:
- break;
- }
-
- if (count > GetSize()) {
- return DAWN_VALIDATION_ERROR("Buffer subdata with too much data");
- }
-
- // Metal requests buffer to buffer copy size must be a multiple of 4 bytes on macOS
- if (count % 4 != 0) {
- return DAWN_VALIDATION_ERROR("Buffer subdata size must be a multiple of 4 bytes");
- }
-
- // Metal requests offset of buffer to buffer copy must be a multiple of 4 bytes on macOS
- if (start % 4 != 0) {
- return DAWN_VALIDATION_ERROR("Start position must be a multiple of 4 bytes");
- }
-
- // Note that no overflow can happen because we already checked for GetSize() >= count
- if (start > GetSize() - count) {
- return DAWN_VALIDATION_ERROR("Buffer subdata out of range");
- }
-
- if (!(mUsage & wgpu::BufferUsage::CopyDst)) {
- return DAWN_VALIDATION_ERROR("Buffer needs the CopyDst usage bit");
- }
-
- return {};
- }
-
MaybeError BufferBase::ValidateMap(wgpu::BufferUsage requiredUsage,
WGPUBufferMapAsyncStatus* status) const {
*status = WGPUBufferMapAsyncStatus_DeviceLost;