Commit a8bf3c4b authored by Austin Eng's avatar Austin Eng Committed by Commit Bot

[WebGPU] Add FlexibleArrayBufferView to GPUBuffer.setSubData src

FlexibleArrayBufferView allows small ArrayBufferViews to be passed as a
temporary on the stack. This saves creating global handles and weak
roots in V8.

Bug: 852089
Change-Id: Ic0e8ee941c5175ac5232d5b6a2c1f3f1a315bf9e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1894409Reviewed-by: default avatarKai Ninomiya <kainino@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711593}
parent 6272af25
......@@ -128,13 +128,13 @@ void GPUBuffer::Trace(blink::Visitor* visitor) {
}
void GPUBuffer::setSubData(uint64_t dst_byte_offset,
const MaybeShared<DOMArrayBufferView>& src,
const FlexibleArrayBufferView& src,
uint64_t src_byte_offset,
uint64_t byte_length,
ExceptionState& exception_state) {
const uint8_t* src_base =
reinterpret_cast<const uint8_t*>(src.View()->BaseAddress());
size_t src_byte_length = src.View()->byteLength();
reinterpret_cast<const uint8_t*>(src.BaseAddressMaybeOnStack());
size_t src_byte_length = src.ByteLength();
if (src_byte_offset > src_byte_length) {
exception_state.ThrowRangeError("srcOffset is too large");
......
......@@ -7,6 +7,7 @@
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/core/typed_arrays/array_buffer_view_helpers.h"
#include "third_party/blink/renderer/core/typed_arrays/flexible_array_buffer_view.h"
#include "third_party/blink/renderer/modules/webgpu/dawn_object.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
......@@ -33,7 +34,7 @@ class GPUBuffer : public DawnObject<WGPUBuffer> {
// gpu_buffer.idl
void setSubData(uint64_t dst_byte_offset,
const MaybeShared<DOMArrayBufferView>& src,
const FlexibleArrayBufferView& src,
uint64_t src_byte_offset,
uint64_t byte_length,
ExceptionState& exception_state);
......
......@@ -9,7 +9,7 @@
] interface GPUBuffer {
[RaisesException] void setSubData(
unsigned long long dstOffset,
[AllowShared] ArrayBufferView src,
[AllowShared, FlexibleArrayBufferView] ArrayBufferView src,
optional unsigned long long srcOffset = 0,
optional unsigned long long byteLength = 0);
[CallWith=ScriptState, RaisesException] Promise<ArrayBuffer> mapReadAsync();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment