dawn/node: Fix array buffer view conversion
A Napi::TypedArray may have a non-zero offset on its underlying ArrayBuffer backing buffer. Also use the length of the typed array, not the backing buffer. Change-Id: Icaa310ef8f87393b4d7582ba0a0afb2b87318664 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/121820 Reviewed-by: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: James Price <jrprice@google.com>
This commit is contained in:
parent
148e7fab1c
commit
ae3e9adc1b
|
@ -153,15 +153,20 @@ bool Converter::Convert(wgpu::ImageCopyBuffer& out, const interop::GPUImageCopyB
|
|||
bool Converter::Convert(BufferSource& out, interop::BufferSource in) {
|
||||
out = {};
|
||||
if (auto* view = std::get_if<interop::ArrayBufferView>(&in)) {
|
||||
std::visit(
|
||||
return std::visit(
|
||||
[&](auto&& v) {
|
||||
auto arr = v.ArrayBuffer();
|
||||
out.data = arr.Data();
|
||||
out.size = arr.ByteLength();
|
||||
if (v.ByteOffset() + v.ByteLength() > arr.ByteLength()) {
|
||||
Napi::Error::New(env, "offset + length exceeds underlying buffer size")
|
||||
.ThrowAsJavaScriptException();
|
||||
return false;
|
||||
}
|
||||
out.data = static_cast<uint8_t*>(arr.Data()) + v.ByteOffset();
|
||||
out.size = v.ByteLength();
|
||||
out.bytesPerElement = v.ElementSize();
|
||||
return true;
|
||||
},
|
||||
*view);
|
||||
return true;
|
||||
}
|
||||
if (auto* arr = std::get_if<interop::ArrayBuffer>(&in)) {
|
||||
out.data = arr->Data();
|
||||
|
|
Loading…
Reference in New Issue