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/tests/end2end/BasicTests.cpp b/src/tests/end2end/BasicTests.cpp
index 1b594bd..98ecb2e 100644
--- a/src/tests/end2end/BasicTests.cpp
+++ b/src/tests/end2end/BasicTests.cpp
@@ -26,30 +26,30 @@
     ASSERT_EQ(GetAdapterProperties().vendorID, GetVendorIdFilter());
 }
 
-// Test Buffer::SetSubData changes the content of the buffer, but really this is the most
+// Test Queue::WriteBuffer changes the content of the buffer, but really this is the most
 // basic test possible, and tests the test harness
-TEST_P(BasicTests, BufferSetSubData) {
+TEST_P(BasicTests, QueueWriteBuffer) {
     wgpu::BufferDescriptor descriptor;
     descriptor.size = 4;
     descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
     wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
 
     uint32_t value = 0x01020304;
-    buffer.SetSubData(0, sizeof(value), &value);
+    queue.WriteBuffer(buffer, 0, &value, sizeof(value));
 
     EXPECT_BUFFER_U32_EQ(value, buffer, 0);
 }
 
-// Test a validation error for buffer setSubData, but really this is the most basic test possible
+// Test a validation error for Queue::WriteBuffer but really this is the most basic test possible
 // for ASSERT_DEVICE_ERROR
-TEST_P(BasicTests, BufferSetSubDataError) {
+TEST_P(BasicTests, QueueWriteBufferError) {
     wgpu::BufferDescriptor descriptor;
     descriptor.size = 4;
     descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
     wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
 
     uint8_t value = 187;
-    ASSERT_DEVICE_ERROR(buffer.SetSubData(1000, sizeof(value), &value));
+    ASSERT_DEVICE_ERROR(queue.WriteBuffer(buffer, 1000, &value, sizeof(value)));
 }
 
 DAWN_INSTANTIATE_TEST(BasicTests, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
diff --git a/src/tests/end2end/BindGroupTests.cpp b/src/tests/end2end/BindGroupTests.cpp
index 153c303..c288844 100644
--- a/src/tests/end2end/BindGroupTests.cpp
+++ b/src/tests/end2end/BindGroupTests.cpp
@@ -770,9 +770,9 @@
     wgpu::Buffer buffer2 = device.CreateBuffer(&bufferDescriptor);
 
     // Populate the values
-    buffer0.SetSubData(offsets[0], sizeof(uint32_t), &values[0]);
-    buffer2.SetSubData(offsets[1], sizeof(uint32_t), &values[1]);
-    buffer3.SetSubData(offsets[2], sizeof(uint32_t), &values[2]);
+    queue.WriteBuffer(buffer0, offsets[0], &values[0], sizeof(uint32_t));
+    queue.WriteBuffer(buffer2, offsets[1], &values[1], sizeof(uint32_t));
+    queue.WriteBuffer(buffer3, offsets[2], &values[2], sizeof(uint32_t));
 
     wgpu::Buffer outputBuffer = utils::CreateBufferFromData(
         device, wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::Storage, {0, 0, 0});
diff --git a/src/tests/end2end/BufferTests.cpp b/src/tests/end2end/BufferTests.cpp
index 04af878..504cf32 100644
--- a/src/tests/end2end/BufferTests.cpp
+++ b/src/tests/end2end/BufferTests.cpp
@@ -55,7 +55,7 @@
     wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
 
     uint32_t myData = 0x01020304;
-    buffer.SetSubData(0, sizeof(myData), &myData);
+    queue.WriteBuffer(buffer, 0, &myData, sizeof(myData));
 
     const void* mappedData = MapReadAsyncAndWait(buffer);
     ASSERT_EQ(myData, *reinterpret_cast<const uint32_t*>(mappedData));
@@ -71,7 +71,7 @@
     wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
 
     uint32_t myData = 0x01020304;
-    buffer.SetSubData(0, sizeof(myData), &myData);
+    queue.WriteBuffer(buffer, 0, &myData, sizeof(myData));
 
     const void* mappedData = MapReadAsyncAndWait(buffer);
     EXPECT_EQ(myData, *reinterpret_cast<const uint32_t*>(mappedData));
@@ -79,7 +79,7 @@
     UnmapBuffer(buffer);
 
     myData = 0x05060708;
-    buffer.SetSubData(0, sizeof(myData), &myData);
+    queue.WriteBuffer(buffer, 0, &myData, sizeof(myData));
 
     const void* mappedData1 = MapReadAsyncAndWait(buffer);
     EXPECT_EQ(myData, *reinterpret_cast<const uint32_t*>(mappedData1));
@@ -100,7 +100,7 @@
     descriptor.usage = wgpu::BufferUsage::MapRead | wgpu::BufferUsage::CopyDst;
     wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
 
-    buffer.SetSubData(0, kDataSize * sizeof(uint32_t), myData.data());
+    queue.WriteBuffer(buffer, 0, myData.data(), kDataSize * sizeof(uint32_t));
 
     const void* mappedData = MapReadAsyncAndWait(buffer);
     ASSERT_EQ(0, memcmp(mappedData, myData.data(), kDataSize * sizeof(uint32_t)));
@@ -233,144 +233,6 @@
 
 DAWN_INSTANTIATE_TEST(BufferMapWriteTests, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
 
-class BufferSetSubDataTests : public DawnTest {
-};
-
-// Test the simplest set sub data: setting one u32 at offset 0.
-TEST_P(BufferSetSubDataTests, SmallDataAtZero) {
-    wgpu::BufferDescriptor descriptor;
-    descriptor.size = 4;
-    descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
-    wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
-
-    uint32_t value = 0x01020304;
-    buffer.SetSubData(0, sizeof(value), &value);
-
-    EXPECT_BUFFER_U32_EQ(value, buffer, 0);
-}
-
-// Test the simplest set sub data: setting nothing
-TEST_P(BufferSetSubDataTests, ZeroSized) {
-    wgpu::BufferDescriptor descriptor;
-    descriptor.size = 4;
-    descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
-    wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
-
-    uint32_t initialValue = 0x42;
-    buffer.SetSubData(0, sizeof(initialValue), &initialValue);
-
-    buffer.SetSubData(0, 0, nullptr);
-
-    // The content of the buffer isn't changed
-    EXPECT_BUFFER_U32_EQ(initialValue, buffer, 0);
-}
-
-// Call SetSubData at offset 0 via a u32 twice. Test that data is updated accoordingly.
-TEST_P(BufferSetSubDataTests, SetTwice) {
-    wgpu::BufferDescriptor descriptor;
-    descriptor.size = 4;
-    descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
-    wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
-
-    uint32_t value = 0x01020304;
-    buffer.SetSubData(0, sizeof(value), &value);
-
-    EXPECT_BUFFER_U32_EQ(value, buffer, 0);
-
-    value = 0x05060708;
-    buffer.SetSubData(0, sizeof(value), &value);
-
-    EXPECT_BUFFER_U32_EQ(value, buffer, 0);
-}
-
-// Test that SetSubData offset works.
-TEST_P(BufferSetSubDataTests, SmallDataAtOffset) {
-    wgpu::BufferDescriptor descriptor;
-    descriptor.size = 4000;
-    descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
-    wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
-
-    constexpr uint64_t kOffset = 2000;
-    uint32_t value = 0x01020304;
-    buffer.SetSubData(kOffset, sizeof(value), &value);
-
-    EXPECT_BUFFER_U32_EQ(value, buffer, kOffset);
-}
-
-// Stress test for many calls to SetSubData
-TEST_P(BufferSetSubDataTests, ManySetSubData) {
-    // Note: Increasing the size of the buffer will likely cause timeout issues.
-    // In D3D12, timeout detection occurs when the GPU scheduler tries but cannot preempt the task
-    // executing these commands in-flight. If this takes longer than ~2s, a device reset occurs and
-    // fails the test. Since GPUs may or may not complete by then, this test must be disabled OR
-    // modified to be well-below the timeout limit.
-
-    // TODO (jiawei.shao@intel.com): find out why this test fails on Intel Vulkan Linux bots.
-    DAWN_SKIP_TEST_IF(IsIntel() && IsVulkan() && IsLinux());
-    // TODO(https://bugs.chromium.org/p/dawn/issues/detail?id=228): Re-enable
-    // once the issue with Metal on 10.14.6 is fixed.
-    DAWN_SKIP_TEST_IF(IsMacOS() && IsIntel() && IsMetal());
-
-    constexpr uint64_t kSize = 4000 * 1000;
-    constexpr uint32_t kElements = 500 * 500;
-    wgpu::BufferDescriptor descriptor;
-    descriptor.size = kSize;
-    descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
-    wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
-
-    std::vector<uint32_t> expectedData;
-    for (uint32_t i = 0; i < kElements; ++i) {
-        buffer.SetSubData(i * sizeof(uint32_t), sizeof(i), &i);
-        expectedData.push_back(i);
-    }
-
-    EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), buffer, 0, kElements);
-}
-
-// Test using SetSubData for lots of data
-TEST_P(BufferSetSubDataTests, LargeSetSubData) {
-    constexpr uint64_t kSize = 4000 * 1000;
-    constexpr uint32_t kElements = 1000 * 1000;
-    wgpu::BufferDescriptor descriptor;
-    descriptor.size = kSize;
-    descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
-    wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
-
-    std::vector<uint32_t> expectedData;
-    for (uint32_t i = 0; i < kElements; ++i) {
-        expectedData.push_back(i);
-    }
-
-    buffer.SetSubData(0, kElements * sizeof(uint32_t), expectedData.data());
-
-    EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), buffer, 0, kElements);
-}
-
-// Test using SetSubData for super large data block
-TEST_P(BufferSetSubDataTests, SuperLargeSetSubData) {
-    constexpr uint64_t kSize = 12000 * 1000;
-    constexpr uint64_t kElements = 3000 * 1000;
-    wgpu::BufferDescriptor descriptor;
-    descriptor.size = kSize;
-    descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
-    wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
-
-    std::vector<uint32_t> expectedData;
-    for (uint32_t i = 0; i < kElements; ++i) {
-        expectedData.push_back(i);
-    }
-
-    buffer.SetSubData(0, kElements * sizeof(uint32_t), expectedData.data());
-
-    EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), buffer, 0, kElements);
-}
-
-DAWN_INSTANTIATE_TEST(BufferSetSubDataTests,
-                     D3D12Backend(),
-                     MetalBackend(),
-                     OpenGLBackend(),
-                     VulkanBackend());
-
 // TODO(enga): These tests should use the testing toggle to initialize resources to 1.
 class CreateBufferMappedTests : public DawnTest {
     protected:
diff --git a/src/tests/end2end/ComputeCopyStorageBufferTests.cpp b/src/tests/end2end/ComputeCopyStorageBufferTests.cpp
index 569c82b..dcb762e 100644
--- a/src/tests/end2end/ComputeCopyStorageBufferTests.cpp
+++ b/src/tests/end2end/ComputeCopyStorageBufferTests.cpp
@@ -48,7 +48,7 @@
     for (uint32_t i = 0; i < kNumUints; ++i) {
         expected[i] = (i + 1u) * 0x11111111u;
     }
-    src.SetSubData(0, sizeof(expected), expected.data());
+    queue.WriteBuffer(src, 0, expected.data(), sizeof(expected));
     EXPECT_BUFFER_U32_RANGE_EQ(expected.data(), src, 0, kNumUints);
 
     // Set up dst storage buffer
@@ -59,7 +59,7 @@
     wgpu::Buffer dst = device.CreateBuffer(&dstDesc);
 
     std::array<uint32_t, kNumUints> zero{};
-    dst.SetSubData(0, sizeof(zero), zero.data());
+    queue.WriteBuffer(dst, 0, zero.data(), sizeof(zero));
 
     // Set up bind group and issue dispatch
     wgpu::BindGroup bindGroup = utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0),
diff --git a/src/tests/end2end/ComputeSharedMemoryTests.cpp b/src/tests/end2end/ComputeSharedMemoryTests.cpp
index 980735d..bb33856 100644
--- a/src/tests/end2end/ComputeSharedMemoryTests.cpp
+++ b/src/tests/end2end/ComputeSharedMemoryTests.cpp
@@ -42,7 +42,7 @@
     wgpu::Buffer dst = device.CreateBuffer(&dstDesc);
 
     const uint32_t zero = 0;
-    dst.SetSubData(0, sizeof(zero), &zero);
+    queue.WriteBuffer(dst, 0, &zero, sizeof(zero));
 
     // Set up bind group and issue dispatch
     wgpu::BindGroup bindGroup = utils::MakeBindGroup(device, pipeline.GetBindGroupLayout(0),
diff --git a/src/tests/end2end/CopyTests.cpp b/src/tests/end2end/CopyTests.cpp
index f9d768d..60e76e1 100644
--- a/src/tests/end2end/CopyTests.cpp
+++ b/src/tests/end2end/CopyTests.cpp
@@ -124,8 +124,8 @@
             bufDescriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
             wgpu::Buffer buffer = device.CreateBuffer(&bufDescriptor);
             std::vector<RGBA8> emptyData(bufferSpec.size / kBytesPerTexel * textureSpec.arraySize);
-            buffer.SetSubData(0, static_cast<uint32_t>(emptyData.size() * sizeof(RGBA8)),
-                              emptyData.data());
+            queue.WriteBuffer(buffer, 0, emptyData.data(),
+                              static_cast<uint32_t>(emptyData.size() * sizeof(RGBA8)));
 
             uint64_t bufferOffset = bufferSpec.offset;
             for (uint32_t slice = 0; slice < textureSpec.arraySize; ++slice) {
@@ -195,8 +195,8 @@
 
         std::vector<RGBA8> bufferData(bufferSpec.size / kBytesPerTexel);
         FillBufferData(bufferData.data(), bufferData.size());
-        buffer.SetSubData(0, static_cast<uint32_t>(bufferData.size() * sizeof(RGBA8)),
-                          bufferData.data());
+        queue.WriteBuffer(buffer, 0, bufferData.data(),
+                          static_cast<uint32_t>(bufferData.size() * sizeof(RGBA8)));
 
         // Create a texture that is `width` x `height` with (`level` + 1) mip levels.
         wgpu::TextureDescriptor descriptor;
diff --git a/src/tests/end2end/DeprecatedAPITests.cpp b/src/tests/end2end/DeprecatedAPITests.cpp
index 76e9e82..087d182 100644
--- a/src/tests/end2end/DeprecatedAPITests.cpp
+++ b/src/tests/end2end/DeprecatedAPITests.cpp
@@ -58,6 +58,30 @@
         }                                                                        \
     } while (0)
 
+// Test that using SetSubData emits a deprecation warning.
+TEST_P(DeprecationTests, SetSubDataDeprecated) {
+    wgpu::BufferDescriptor descriptor;
+    descriptor.usage = wgpu::BufferUsage::CopyDst;
+    descriptor.size = 4;
+    wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
+
+    EXPECT_DEPRECATION_WARNING(buffer.SetSubData(0, 0, nullptr));
+}
+
+// Test that using SetSubData works
+TEST_P(DeprecationTests, SetSubDataStillWorks) {
+    DAWN_SKIP_TEST_IF(IsNull());
+
+    wgpu::BufferDescriptor descriptor;
+    descriptor.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::CopySrc;
+    descriptor.size = 4;
+    wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
+
+    uint32_t data = 2020;
+    EXPECT_DEPRECATION_WARNING(buffer.SetSubData(0, 4, &data));
+    EXPECT_BUFFER_U32_EQ(data, buffer, 0);
+}
+
 DAWN_INSTANTIATE_TEST(DeprecationTests,
                       D3D12Backend(),
                       MetalBackend(),
diff --git a/src/tests/end2end/DepthSamplingTests.cpp b/src/tests/end2end/DepthSamplingTests.cpp
index a8d08df..7c24a69 100644
--- a/src/tests/end2end/DepthSamplingTests.cpp
+++ b/src/tests/end2end/DepthSamplingTests.cpp
@@ -205,7 +205,7 @@
     }
 
     void UpdateInputTexture(wgpu::CommandEncoder commandEncoder, float textureValue) {
-        mTextureUploadBuffer.SetSubData(0, sizeof(float), &textureValue);
+        queue.WriteBuffer(mTextureUploadBuffer, 0, &textureValue, sizeof(float));
 
         wgpu::BufferCopyView bufferCopyView = {};
         bufferCopyView.buffer = mTextureUploadBuffer;
@@ -315,7 +315,7 @@
                           float compareRef,
                           wgpu::CompareFunction compare,
                           std::vector<float> textureValues) {
-        mUniformBuffer.SetSubData(0, sizeof(float), &compareRef);
+        queue.WriteBuffer(mUniformBuffer, 0, &compareRef, sizeof(float));
 
         wgpu::SamplerDescriptor samplerDesc;
         samplerDesc.compare = compare;
@@ -357,7 +357,7 @@
                           float compareRef,
                           wgpu::CompareFunction compare,
                           std::vector<float> textureValues) {
-        mUniformBuffer.SetSubData(0, sizeof(float), &compareRef);
+        queue.WriteBuffer(mUniformBuffer, 0, &compareRef, sizeof(float));
 
         wgpu::SamplerDescriptor samplerDesc;
         samplerDesc.compare = compare;
diff --git a/src/tests/end2end/DeviceLostTests.cpp b/src/tests/end2end/DeviceLostTests.cpp
index 5aa0263..e473533 100644
--- a/src/tests/end2end/DeviceLostTests.cpp
+++ b/src/tests/end2end/DeviceLostTests.cpp
@@ -320,8 +320,8 @@
     SetCallbackAndLoseForTesting();
 }
 
-// Test that SetSubData fails after device is lost
-TEST_P(DeviceLostTest, SetSubDataFails) {
+// Test that WriteBuffer fails after device is lost
+TEST_P(DeviceLostTest, WriteBufferFails) {
     wgpu::BufferDescriptor bufferDescriptor;
     bufferDescriptor.size = sizeof(float);
     bufferDescriptor.usage = wgpu::BufferUsage::MapRead | wgpu::BufferUsage::CopyDst;
@@ -329,8 +329,8 @@
     wgpu::Buffer buffer = device.CreateBuffer(&bufferDescriptor);
 
     SetCallbackAndLoseForTesting();
-    std::array<float, 1> data = {12};
-    ASSERT_DEVICE_ERROR(buffer.SetSubData(0, sizeof(float), data.data()));
+    float data = 12.0f;
+    ASSERT_DEVICE_ERROR(queue.WriteBuffer(buffer, 0, &data, sizeof(data)));
 }
 
 // Test that Command Encoder Finish fails when device lost
diff --git a/src/tests/end2end/GpuMemorySynchronizationTests.cpp b/src/tests/end2end/GpuMemorySynchronizationTests.cpp
index d396a5f..3b4dcd1 100644
--- a/src/tests/end2end/GpuMemorySynchronizationTests.cpp
+++ b/src/tests/end2end/GpuMemorySynchronizationTests.cpp
@@ -29,7 +29,7 @@
         wgpu::Buffer buffer = device.CreateBuffer(&srcDesc);
 
         int myData = 0;
-        buffer.SetSubData(0, sizeof(myData), &myData);
+        queue.WriteBuffer(buffer, 0, &myData, sizeof(myData));
         return buffer;
     }
 
@@ -432,7 +432,7 @@
         wgpu::Buffer buffer = device.CreateBuffer(&srcDesc);
 
         std::vector<uint8_t> zeros(size, 0);
-        buffer.SetSubData(0, size, zeros.data());
+        queue.WriteBuffer(buffer, 0, zeros.data(), size);
 
         return buffer;
     }
diff --git a/src/tests/end2end/QueueTests.cpp b/src/tests/end2end/QueueTests.cpp
index 710caec..bc83a1b 100644
--- a/src/tests/end2end/QueueTests.cpp
+++ b/src/tests/end2end/QueueTests.cpp
@@ -34,3 +34,140 @@
                       NullBackend(),
                       OpenGLBackend(),
                       VulkanBackend());
+
+class QueueWriteBufferTests : public DawnTest {};
+
+// Test the simplest WriteBuffer setting one u32 at offset 0.
+TEST_P(QueueWriteBufferTests, SmallDataAtZero) {
+    wgpu::BufferDescriptor descriptor;
+    descriptor.size = 4;
+    descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
+    wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
+
+    uint32_t value = 0x01020304;
+    queue.WriteBuffer(buffer, 0, &value, sizeof(value));
+
+    EXPECT_BUFFER_U32_EQ(value, buffer, 0);
+}
+
+// Test an empty WriteBuffer
+TEST_P(QueueWriteBufferTests, ZeroSized) {
+    wgpu::BufferDescriptor descriptor;
+    descriptor.size = 4;
+    descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
+    wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
+
+    uint32_t initialValue = 0x42;
+    queue.WriteBuffer(buffer, 0, &initialValue, sizeof(initialValue));
+
+    queue.WriteBuffer(buffer, 0, nullptr, 0);
+
+    // The content of the buffer isn't changed
+    EXPECT_BUFFER_U32_EQ(initialValue, buffer, 0);
+}
+
+// Call WriteBuffer at offset 0 via a u32 twice. Test that data is updated accoordingly.
+TEST_P(QueueWriteBufferTests, SetTwice) {
+    wgpu::BufferDescriptor descriptor;
+    descriptor.size = 4;
+    descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
+    wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
+
+    uint32_t value = 0x01020304;
+    queue.WriteBuffer(buffer, 0, &value, sizeof(value));
+
+    EXPECT_BUFFER_U32_EQ(value, buffer, 0);
+
+    value = 0x05060708;
+    queue.WriteBuffer(buffer, 0, &value, sizeof(value));
+
+    EXPECT_BUFFER_U32_EQ(value, buffer, 0);
+}
+
+// Test that WriteBuffer offset works.
+TEST_P(QueueWriteBufferTests, SmallDataAtOffset) {
+    wgpu::BufferDescriptor descriptor;
+    descriptor.size = 4000;
+    descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
+    wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
+
+    constexpr uint64_t kOffset = 2000;
+    uint32_t value = 0x01020304;
+    queue.WriteBuffer(buffer, kOffset, &value, sizeof(value));
+
+    EXPECT_BUFFER_U32_EQ(value, buffer, kOffset);
+}
+
+// Stress test for many calls to WriteBuffer
+TEST_P(QueueWriteBufferTests, ManyWriteBuffer) {
+    // Note: Increasing the size of the buffer will likely cause timeout issues.
+    // In D3D12, timeout detection occurs when the GPU scheduler tries but cannot preempt the task
+    // executing these commands in-flight. If this takes longer than ~2s, a device reset occurs and
+    // fails the test. Since GPUs may or may not complete by then, this test must be disabled OR
+    // modified to be well-below the timeout limit.
+
+    // TODO (jiawei.shao@intel.com): find out why this test fails on Intel Vulkan Linux bots.
+    DAWN_SKIP_TEST_IF(IsIntel() && IsVulkan() && IsLinux());
+    // TODO(https://bugs.chromium.org/p/dawn/issues/detail?id=228): Re-enable
+    // once the issue with Metal on 10.14.6 is fixed.
+    DAWN_SKIP_TEST_IF(IsMacOS() && IsIntel() && IsMetal());
+
+    constexpr uint64_t kSize = 4000 * 1000;
+    constexpr uint32_t kElements = 500 * 500;
+    wgpu::BufferDescriptor descriptor;
+    descriptor.size = kSize;
+    descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
+    wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
+
+    std::vector<uint32_t> expectedData;
+    for (uint32_t i = 0; i < kElements; ++i) {
+        queue.WriteBuffer(buffer, i * sizeof(uint32_t), &i, sizeof(i));
+        expectedData.push_back(i);
+    }
+
+    EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), buffer, 0, kElements);
+}
+
+// Test using WriteBuffer for lots of data
+TEST_P(QueueWriteBufferTests, LargeWriteBuffer) {
+    constexpr uint64_t kSize = 4000 * 1000;
+    constexpr uint32_t kElements = 1000 * 1000;
+    wgpu::BufferDescriptor descriptor;
+    descriptor.size = kSize;
+    descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
+    wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
+
+    std::vector<uint32_t> expectedData;
+    for (uint32_t i = 0; i < kElements; ++i) {
+        expectedData.push_back(i);
+    }
+
+    queue.WriteBuffer(buffer, 0, expectedData.data(), kElements * sizeof(uint32_t));
+
+    EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), buffer, 0, kElements);
+}
+
+// Test using WriteBuffer for super large data block
+TEST_P(QueueWriteBufferTests, SuperLargeWriteBuffer) {
+    constexpr uint64_t kSize = 12000 * 1000;
+    constexpr uint64_t kElements = 3000 * 1000;
+    wgpu::BufferDescriptor descriptor;
+    descriptor.size = kSize;
+    descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
+    wgpu::Buffer buffer = device.CreateBuffer(&descriptor);
+
+    std::vector<uint32_t> expectedData;
+    for (uint32_t i = 0; i < kElements; ++i) {
+        expectedData.push_back(i);
+    }
+
+    queue.WriteBuffer(buffer, 0, expectedData.data(), kElements * sizeof(uint32_t));
+
+    EXPECT_BUFFER_U32_RANGE_EQ(expectedData.data(), buffer, 0, kElements);
+}
+
+DAWN_INSTANTIATE_TEST(QueueWriteBufferTests,
+                      D3D12Backend(),
+                      MetalBackend(),
+                      OpenGLBackend(),
+                      VulkanBackend());
diff --git a/src/tests/end2end/TextureFormatTests.cpp b/src/tests/end2end/TextureFormatTests.cpp
index cad0bc9..b6fbdb1 100644
--- a/src/tests/end2end/TextureFormatTests.cpp
+++ b/src/tests/end2end/TextureFormatTests.cpp
@@ -224,7 +224,7 @@
         ASSERT(sampleDataSize % sampleFormatInfo.texelByteSize == 0);
         uint32_t width = sampleDataSize / sampleFormatInfo.texelByteSize;
 
-        // The input data must be a multiple of 4 byte in length for setSubData
+        // The input data must be a multiple of 4 byte in length for WriteBuffer
         ASSERT(sampleDataSize % 4 == 0);
         ASSERT(expectedRenderDataSize % 4 == 0);
 
diff --git a/src/tests/end2end/TextureZeroInitTests.cpp b/src/tests/end2end/TextureZeroInitTests.cpp
index d6b0df8..40962f5 100644
--- a/src/tests/end2end/TextureZeroInitTests.cpp
+++ b/src/tests/end2end/TextureZeroInitTests.cpp
@@ -586,7 +586,7 @@
     wgpu::Buffer bufferTex = device.CreateBuffer(&bufferDescriptor);
     // Add data to buffer to ensure it is initialized
     uint32_t data = 100;
-    bufferTex.SetSubData(0, sizeof(data), &data);
+    queue.WriteBuffer(bufferTex, 0, &data, sizeof(data));
 
     wgpu::SamplerDescriptor samplerDesc = utils::GetDefaultSamplerDescriptor();
     wgpu::Sampler sampler = device.CreateSampler(&samplerDesc);
diff --git a/src/tests/perf_tests/BufferUploadPerf.cpp b/src/tests/perf_tests/BufferUploadPerf.cpp
index 5849bba..49e52f5 100644
--- a/src/tests/perf_tests/BufferUploadPerf.cpp
+++ b/src/tests/perf_tests/BufferUploadPerf.cpp
@@ -22,7 +22,7 @@
     constexpr unsigned int kNumIterations = 50;
 
     enum class UploadMethod {
-        SetSubData,
+        WriteBuffer,
         CreateBufferMapped,
     };
 
@@ -52,8 +52,8 @@
         ostream << static_cast<const AdapterTestParam&>(param);
 
         switch (param.uploadMethod) {
-            case UploadMethod::SetSubData:
-                ostream << "_SetSubData";
+            case UploadMethod::WriteBuffer:
+                ostream << "_WriteBuffer";
                 break;
             case UploadMethod::CreateBufferMapped:
                 ostream << "_CreateBufferMapped";
@@ -113,11 +113,11 @@
 
 void BufferUploadPerf::Step() {
     switch (GetParam().uploadMethod) {
-        case UploadMethod::SetSubData: {
+        case UploadMethod::WriteBuffer: {
             for (unsigned int i = 0; i < kNumIterations; ++i) {
-                dst.SetSubData(0, data.size(), data.data());
+                queue.WriteBuffer(dst, 0, data.data(), data.size());
             }
-            // Make sure all SetSubData's are flushed.
+            // Make sure all WriteBuffer's are flushed.
             queue.Submit(0, nullptr);
             break;
         }
@@ -150,7 +150,7 @@
 DAWN_INSTANTIATE_PERF_TEST_SUITE_P(BufferUploadPerf,
                                    {D3D12Backend(), MetalBackend(), OpenGLBackend(),
                                     VulkanBackend()},
-                                   {UploadMethod::SetSubData, UploadMethod::CreateBufferMapped},
+                                   {UploadMethod::WriteBuffer, UploadMethod::CreateBufferMapped},
                                    {UploadSize::BufferSize_1KB, UploadSize::BufferSize_64KB,
                                     UploadSize::BufferSize_1MB, UploadSize::BufferSize_4MB,
                                     UploadSize::BufferSize_16MB});
diff --git a/src/tests/perf_tests/DrawCallPerf.cpp b/src/tests/perf_tests/DrawCallPerf.cpp
index 72e837a..1b1fe58 100644
--- a/src/tests/perf_tests/DrawCallPerf.cpp
+++ b/src/tests/perf_tests/DrawCallPerf.cpp
@@ -568,18 +568,20 @@
         switch (GetParam().bindGroupType) {
             case BindGroup::NoChange:
             case BindGroup::Redundant:
-                mUniformBuffers[0].SetSubData(0, 3 * sizeof(float), mUniformBufferData.data());
+                queue.WriteBuffer(mUniformBuffers[0], 0, mUniformBufferData.data(),
+                                  3 * sizeof(float));
                 break;
             case BindGroup::NoReuse:
             case BindGroup::Multiple:
                 for (uint32_t i = 0; i < kNumDraws; ++i) {
-                    mUniformBuffers[i].SetSubData(
-                        0, 3 * sizeof(float), mUniformBufferData.data() + i * mNumUniformFloats);
+                    queue.WriteBuffer(mUniformBuffers[i], 0,
+                                      mUniformBufferData.data() + i * mNumUniformFloats,
+                                      3 * sizeof(float));
                 }
                 break;
             case BindGroup::Dynamic:
-                mUniformBuffers[0].SetSubData(0, mUniformBufferData.size() * sizeof(float),
-                                              mUniformBufferData.data());
+                queue.WriteBuffer(mUniformBuffers[0], 0, mUniformBufferData.data(),
+                                  mUniformBufferData.size() * sizeof(float));
                 break;
         }
     }
diff --git a/src/tests/unittests/validation/BufferValidationTests.cpp b/src/tests/unittests/validation/BufferValidationTests.cpp
index 1bda448..0f74d66 100644
--- a/src/tests/unittests/validation/BufferValidationTests.cpp
+++ b/src/tests/unittests/validation/BufferValidationTests.cpp
@@ -74,13 +74,6 @@
 
           return device.CreateBuffer(&descriptor);
       }
-      wgpu::Buffer CreateSetSubDataBuffer(uint64_t size) {
-          wgpu::BufferDescriptor descriptor;
-          descriptor.size = size;
-          descriptor.usage = wgpu::BufferUsage::CopyDst;
-
-          return device.CreateBuffer(&descriptor);
-      }
 
       wgpu::CreateBufferMappedResult CreateBufferMapped(uint64_t size, wgpu::BufferUsage usage) {
           wgpu::BufferDescriptor descriptor;
@@ -429,72 +422,6 @@
     queue.Submit(0, nullptr);
 }
 
-// Test the success case for Buffer::SetSubData
-TEST_F(BufferValidationTest, SetSubDataSuccess) {
-    wgpu::Buffer buf = CreateSetSubDataBuffer(4);
-
-    uint32_t foo = 0x01020304;
-    buf.SetSubData(0, sizeof(foo), &foo);
-}
-
-// Test error case for SetSubData out of bounds
-TEST_F(BufferValidationTest, SetSubDataOutOfBounds) {
-    wgpu::Buffer buf = CreateSetSubDataBuffer(1);
-
-    uint8_t foo[2] = {0, 0};
-    ASSERT_DEVICE_ERROR(buf.SetSubData(0, 2, foo));
-}
-
-// Test error case for SetSubData out of bounds with an overflow
-TEST_F(BufferValidationTest, SetSubDataOutOfBoundsOverflow) {
-    wgpu::Buffer buf = CreateSetSubDataBuffer(1000);
-
-    uint8_t foo[2] = {0, 0};
-
-    // An offset that when added to "2" would overflow to be zero and pass validation without
-    // overflow checks.
-    uint64_t offset = uint64_t(int64_t(0) - int64_t(2));
-
-    ASSERT_DEVICE_ERROR(buf.SetSubData(offset, 2, foo));
-}
-
-// Test error case for SetSubData with the wrong usage
-TEST_F(BufferValidationTest, SetSubDataWrongUsage) {
-    wgpu::BufferDescriptor descriptor;
-    descriptor.size = 4;
-    descriptor.usage = wgpu::BufferUsage::Vertex;
-
-    wgpu::Buffer buf = device.CreateBuffer(&descriptor);
-
-    uint8_t foo = 0;
-    ASSERT_DEVICE_ERROR(buf.SetSubData(0, sizeof(foo), &foo));
-}
-
-// Test SetSubData with unaligned size
-TEST_F(BufferValidationTest, SetSubDataWithUnalignedSize) {
-    wgpu::BufferDescriptor descriptor;
-    descriptor.size = 4;
-    descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
-
-    wgpu::Buffer buf = device.CreateBuffer(&descriptor);
-
-    uint8_t value = 123;
-    ASSERT_DEVICE_ERROR(buf.SetSubData(0, sizeof(value), &value));
-}
-
-// Test SetSubData with unaligned offset
-TEST_F(BufferValidationTest, SetSubDataWithUnalignedOffset) {
-    wgpu::BufferDescriptor descriptor;
-    descriptor.size = 4000;
-    descriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
-
-    wgpu::Buffer buf = device.CreateBuffer(&descriptor);
-
-    uint64_t kOffset = 2999;
-    uint32_t value = 0x01020304;
-    ASSERT_DEVICE_ERROR(buf.SetSubData(kOffset, sizeof(value), &value));
-}
-
 // Test that it is valid to destroy an unmapped buffer
 TEST_F(BufferValidationTest, DestroyUnmappedBuffer) {
     {
@@ -547,7 +474,7 @@
 
 // Test that it is valid to Destroy a destroyed buffer
 TEST_F(BufferValidationTest, DestroyDestroyedBuffer) {
-    wgpu::Buffer buf = CreateSetSubDataBuffer(4);
+    wgpu::Buffer buf = CreateMapWriteBuffer(4);
     buf.Destroy();
     buf.Destroy();
 }
@@ -580,14 +507,6 @@
     }
 }
 
-// Test that it is invalid to call SetSubData on a destroyed buffer
-TEST_F(BufferValidationTest, SetSubDataDestroyedBuffer) {
-    wgpu::Buffer buf = CreateSetSubDataBuffer(4);
-    buf.Destroy();
-    uint8_t foo = 0;
-    ASSERT_DEVICE_ERROR(buf.SetSubData(0, sizeof(foo), &foo));
-}
-
 // Test that is is invalid to Map a mapped buffer
 TEST_F(BufferValidationTest, MapMappedBuffer) {
     {
@@ -618,24 +537,6 @@
     }
 }
 
-// Test that it is invalid to call SetSubData on a mapped buffer
-TEST_F(BufferValidationTest, SetSubDataMappedBuffer) {
-    {
-        wgpu::Buffer buf = CreateMapReadBuffer(4);
-        buf.MapReadAsync(ToMockBufferMapReadCallback, nullptr);
-        uint8_t foo = 0;
-        ASSERT_DEVICE_ERROR(buf.SetSubData(0, sizeof(foo), &foo));
-        queue.Submit(0, nullptr);
-    }
-    {
-        wgpu::Buffer buf = CreateMapWriteBuffer(4);
-        buf.MapWriteAsync(ToMockBufferMapWriteCallback, nullptr);
-        uint8_t foo = 0;
-        ASSERT_DEVICE_ERROR(buf.SetSubData(0, sizeof(foo), &foo));
-        queue.Submit(0, nullptr);
-    }
-}
-
 // Test that it is valid to submit a buffer in a queue with a map usage if it is unmapped
 TEST_F(BufferValidationTest, SubmitBufferWithMapUsage) {
     wgpu::BufferDescriptor descriptorA;
@@ -732,7 +633,11 @@
 
 // Test that a map usage is required to call Unmap
 TEST_F(BufferValidationTest, UnmapWithoutMapUsage) {
-    wgpu::Buffer buf = CreateSetSubDataBuffer(4);
+    wgpu::BufferDescriptor descriptor;
+    descriptor.size = 4;
+    descriptor.usage = wgpu::BufferUsage::CopyDst;
+    wgpu::Buffer buf = device.CreateBuffer(&descriptor);
+
     ASSERT_DEVICE_ERROR(buf.Unmap());
 }
 
diff --git a/src/tests/unittests/validation/QueueSubmitValidationTests.cpp b/src/tests/unittests/validation/QueueSubmitValidationTests.cpp
index 66e0691..a74dd7e 100644
--- a/src/tests/unittests/validation/QueueSubmitValidationTests.cpp
+++ b/src/tests/unittests/validation/QueueSubmitValidationTests.cpp
@@ -66,4 +66,125 @@
     queue.Submit(1, &commands);
 }
 
+class QueueWriteBufferValidationTest : public ValidationTest {
+  private:
+    void SetUp() override {
+        ValidationTest::SetUp();
+        queue = device.GetDefaultQueue();
+    }
+
+  protected:
+    wgpu::Buffer CreateBuffer(uint64_t size) {
+        wgpu::BufferDescriptor descriptor;
+        descriptor.size = size;
+        descriptor.usage = wgpu::BufferUsage::CopyDst;
+        return device.CreateBuffer(&descriptor);
+    }
+
+    wgpu::Queue queue;
+};
+
+// Test the success case for WriteBuffer
+TEST_F(QueueWriteBufferValidationTest, Success) {
+    wgpu::Buffer buf = CreateBuffer(4);
+
+    uint32_t foo = 0x01020304;
+    queue.WriteBuffer(buf, 0, &foo, sizeof(foo));
+}
+
+// Test error case for WriteBuffer out of bounds
+TEST_F(QueueWriteBufferValidationTest, OutOfBounds) {
+    wgpu::Buffer buf = CreateBuffer(4);
+
+    uint32_t foo[2] = {0, 0};
+    ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, foo, 8));
+}
+
+// Test error case for WriteBuffer out of bounds with an overflow
+TEST_F(QueueWriteBufferValidationTest, OutOfBoundsOverflow) {
+    wgpu::Buffer buf = CreateBuffer(1024);
+
+    uint32_t foo[2] = {0, 0};
+
+    // An offset that when added to "4" would overflow to be zero and pass validation without
+    // overflow checks.
+    uint64_t offset = uint64_t(int64_t(0) - int64_t(4));
+
+    ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, offset, foo, 4));
+}
+
+// Test error case for WriteBuffer with the wrong usage
+TEST_F(QueueWriteBufferValidationTest, WrongUsage) {
+    wgpu::BufferDescriptor descriptor;
+    descriptor.size = 4;
+    descriptor.usage = wgpu::BufferUsage::Vertex;
+    wgpu::Buffer buf = device.CreateBuffer(&descriptor);
+
+    uint32_t foo = 0;
+    ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, &foo, sizeof(foo)));
+}
+
+// Test WriteBuffer with unaligned size
+TEST_F(QueueWriteBufferValidationTest, UnalignedSize) {
+    wgpu::Buffer buf = CreateBuffer(4);
+
+    uint16_t value = 123;
+    ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, &value, sizeof(value)));
+}
+
+// Test WriteBuffer with unaligned offset
+TEST_F(QueueWriteBufferValidationTest, UnalignedOffset) {
+    wgpu::Buffer buf = CreateBuffer(8);
+
+    uint32_t value = 0x01020304;
+    ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 2, &value, sizeof(value)));
+}
+
+// Test WriteBuffer with destroyed buffer
+TEST_F(QueueWriteBufferValidationTest, DestroyedBuffer) {
+    wgpu::Buffer buf = CreateBuffer(4);
+    buf.Destroy();
+
+    uint32_t value = 0;
+    ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, &value, sizeof(value)));
+}
+
+// Test WriteBuffer with mapped buffer
+TEST_F(QueueWriteBufferValidationTest, MappedBuffer) {
+    // CreateBufferMapped
+    {
+        wgpu::BufferDescriptor descriptor;
+        descriptor.size = 4;
+        descriptor.usage = wgpu::BufferUsage::CopyDst;
+        wgpu::CreateBufferMappedResult result = device.CreateBufferMapped(&descriptor);
+
+        uint32_t value = 0;
+        ASSERT_DEVICE_ERROR(queue.WriteBuffer(result.buffer, 0, &value, sizeof(value)));
+    }
+
+    // MapReadAsync
+    {
+        wgpu::BufferDescriptor descriptor;
+        descriptor.size = 4;
+        descriptor.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::MapRead;
+        wgpu::Buffer buf = device.CreateBuffer(&descriptor);
+
+        buf.MapReadAsync(nullptr, nullptr);
+        uint32_t value = 0;
+        ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, &value, sizeof(value)));
+    }
+
+    // MapWriteAsync
+    {
+        wgpu::BufferDescriptor descriptor;
+        descriptor.size = 4;
+        descriptor.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::MapRead;
+        wgpu::Buffer buf = device.CreateBuffer(&descriptor);
+
+        buf.MapReadAsync(nullptr, nullptr);
+        uint32_t value = 0;
+        ASSERT_DEVICE_ERROR(queue.WriteBuffer(buf, 0, &value, sizeof(value)));
+    }
+}
+
 }  // anonymous namespace
diff --git a/src/tests/white_box/D3D12DescriptorHeapTests.cpp b/src/tests/white_box/D3D12DescriptorHeapTests.cpp
index b6eb4a6..9b4ffe7 100644
--- a/src/tests/white_box/D3D12DescriptorHeapTests.cpp
+++ b/src/tests/white_box/D3D12DescriptorHeapTests.cpp
@@ -601,7 +601,7 @@
     // Re-encode the first bindgroup again.
     {
         std::array<float, 4> greenColor = {0, 1, 0, 1};
-        firstUniformBuffer.SetSubData(0, sizeof(greenColor), &greenColor);
+        queue.WriteBuffer(firstUniformBuffer, 0, &greenColor, sizeof(greenColor));
 
         wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
         {
diff --git a/src/tests/white_box/D3D12ResidencyTests.cpp b/src/tests/white_box/D3D12ResidencyTests.cpp
index e58e48a..8d958ab5 100644
--- a/src/tests/white_box/D3D12ResidencyTests.cpp
+++ b/src/tests/white_box/D3D12ResidencyTests.cpp
@@ -217,7 +217,7 @@
     wgpu::Buffer buffer = CreateBuffer(4, kMapReadBufferUsage);
 
     uint32_t data = 12345;
-    buffer.SetSubData(0, sizeof(uint32_t), &data);
+    queue.WriteBuffer(buffer, 0, &data, sizeof(uint32_t));
 
     // The mappable buffer should be resident.
     EXPECT_TRUE(CheckIfBufferIsResident(buffer));