dawn-cmake/src/dawn/node/binding/GPUBuffer.cpp
Corentin Wallez cf8513d4e5 Roll third_party/gpuweb/ 3c4734b09..0f5fc665a (381 commits)
And update dawn/node accordingly.

3c4734b09c...0f5fc665a0

$ git log 3c4734b09..0f5fc665a --date=short --no-merges --format='%ad %ae %s'
2022-11-25 alanbaker Deploying to gh-pages from @ gpuweb/gpuweb@6b7d8f4947 🚀
2022-11-24 dneto Deploying to gh-pages from @ gpuweb/gpuweb@7eea224a85 🚀
2022-11-23 dneto Deploying to gh-pages from @ gpuweb/gpuweb@c11820e695 🚀
2022-11-23 alanbaker Deploying to gh-pages from @ gpuweb/gpuweb@162e04d0c0 🚀
2022-11-22 dneto Deploying to gh-pages from @ gpuweb/gpuweb@58a9410e38 🚀
2022-11-22 dneto Deploying to gh-pages from @ gpuweb/gpuweb@9fa1932d13 🚀
2022-11-22 dneto Deploying to gh-pages from @ gpuweb/gpuweb@39f2321f54 🚀
2022-11-21 alanbaker Deploying to gh-pages from @ gpuweb/gpuweb@cc0fc37636 🚀
2022-11-18 mehmetoguzderin Deploying to gh-pages from @ gpuweb/gpuweb@684c5104ce 🚀
2022-11-18 mehmetoguzderin Deploying to gh-pages from @ gpuweb/gpuweb@6049e8fc99 🚀
2022-11-17 dneto Deploying to gh-pages from @ gpuweb/gpuweb@0812694055 🚀
2022-11-17 dneto Deploying to gh-pages from @ gpuweb/gpuweb@9b65623938 🚀
2022-11-17 kainino1 Deploying to gh-pages from @ gpuweb/gpuweb@30e78fb154 🚀
2022-11-16 mehmetoguzderin Deploying to gh-pages from @ gpuweb/gpuweb@8b9da345bd 🚀
2022-11-16 kainino1 Deploying to gh-pages from @ gpuweb/gpuweb@113555271f 🚀
2022-11-13 dneto Deploying to gh-pages from @ gpuweb/gpuweb@9c39cc1f0e 🚀
2022-11-11 dneto Deploying to gh-pages from @ gpuweb/gpuweb@a3d767aff4 🚀
2022-11-09 dneto Deploying to gh-pages from @ gpuweb/gpuweb@576b7c97c7 🚀
2022-11-09 dneto Deploying to gh-pages from @ gpuweb/gpuweb@f2fadab356 🚀
2022-11-09 dneto Deploying to gh-pages from @ gpuweb/gpuweb@a291e74d7e 🚀
2022-11-09 dneto Deploying to gh-pages from @ gpuweb/gpuweb@0f69fcba15 🚀
2022-11-09 jdashg Deploying to gh-pages from @ gpuweb/gpuweb@f02d667d59 🚀
2022-11-07 dneto Deploying to gh-pages from @ gpuweb/gpuweb@0fdebc2886 🚀
2022-11-07 dneto Deploying to gh-pages from @ gpuweb/gpuweb@44164a2c63 🚀
2022-11-07 alanbaker Deploying to gh-pages from @ gpuweb/gpuweb@a5cebd5772 🚀
2022-11-07 dneto Deploying to gh-pages from @ gpuweb/gpuweb@c322a6fed4 🚀
2022-11-07 dneto Deploying to gh-pages from @ gpuweb/gpuweb@7ef39cfc0e 🚀
2022-11-07 dneto Deploying to gh-pages from @ gpuweb/gpuweb@572fc32a83 🚀
2022-11-07 dneto Deploying to gh-pages from @ gpuweb/gpuweb@4bb872ac55 🚀
2022-11-02 dneto Deploying to gh-pages from @ gpuweb/gpuweb@98f851baa4 🚀
2022-11-02 dneto Deploying to gh-pages from @ gpuweb/gpuweb@5c6f648919 🚀
2022-11-02 dneto Deploying to gh-pages from @ gpuweb/gpuweb@bf1d73a036 🚀
2022-11-01 dneto Deploying to gh-pages from @ gpuweb/gpuweb@2371712042 🚀
2022-11-01 dneto Deploying to gh-pages from @ gpuweb/gpuweb@acdc5b3e83 🚀
2022-11-01 dneto Deploying to gh-pages from @ gpuweb/gpuweb@8304c57556 🚀
2022-10-27 mehmetoguzderin Deploying to gh-pages from @ gpuweb/gpuweb@27c5c15c84 🚀
2022-10-26 corentin Deploying to gh-pages from @ gpuweb/gpuweb@4048adbfb3 🚀
2022-10-26 shaobo.yan Deploying to gh-pages from @ gpuweb/gpuweb@b85a821e2f 🚀
2022-10-18 alanbaker Deploying to gh-pages from @ gpuweb/gpuweb@63a7a24e4d 🚀
2022-10-18 dneto Deploying to gh-pages from @ gpuweb/gpuweb@6678c9478d 🚀
2022-10-18 dneto Deploying to gh-pages from @ gpuweb/gpuweb@b56d95976d 🚀
2022-10-18 alanbaker Deploying to gh-pages from @ gpuweb/gpuweb@44cf3bf01c 🚀
2022-10-17 kainino1 Deploying to gh-pages from @ gpuweb/gpuweb@1e332763cd 🚀
2022-10-14 mehmetoguzderin Deploying to gh-pages from @ gpuweb/gpuweb@49eae687bf 🚀
2022-10-14 mehmetoguzderin Deploying to gh-pages from @ gpuweb/gpuweb@d7402a1367 🚀
2022-10-13 kainino1 Deploying to gh-pages from @ gpuweb/gpuweb@d2ef870027 🚀
2022-10-12 kainino1 Deploying to gh-pages from @ gpuweb/gpuweb@db76cc3158 🚀
2022-10-11 kainino1 Deploying to gh-pages from @ gpuweb/gpuweb@823a357986 🚀
2022-10-11 dneto Deploying to gh-pages from @ gpuweb/gpuweb@7857eee214 🚀
2022-10-11 kainino1 Deploying to gh-pages from @ gpuweb/gpuweb@6f93d67391 🚀
(...)
2022-06-14 jimb Correct '/' to '.' in 'derive render targets layout from pipeline'. (#3041)
2022-06-14 corentin Deploying to gh-pages from @ gpuweb/gpuweb@d47a377c38 🚀
2022-06-14 dsinclair Combine section headers which define the same function (#3020)
2022-06-14 dsinclair Combine section headers which define the same function (#3020)
2022-06-14 dsinclair Combine section headers which define the same function (#3020)
2022-06-14 dneto Deploying to gh-pages from @ gpuweb/gpuweb@e37fc8f57a 🚀
2022-06-13 mehmetoguzderin Shorthand
2022-06-13 mehmetoguzderin Shorthand
2022-06-13 mehmetoguzderin Shorthand
2022-06-13 mehmetoguzderin Deploying to gh-pages from @ gpuweb/gpuweb@170f891c4b 🚀
2022-06-13 dneto Add WGSL strict LALR(1) check to CI (#3037)
2022-06-13 dneto Add WGSL strict LALR(1) check to CI (#3037)
2022-06-13 dneto Add WGSL strict LALR(1) check to CI (#3037)
2022-06-13 dneto Deploying to gh-pages from @ gpuweb/gpuweb@edca8002ab 🚀
2022-06-11 kainino editorial nit: specify units for limits where relevant
2022-06-11 kainino editorial nit: specify units for limits where relevant
2022-06-11 kainino editorial nit: specify units for limits where relevant
2022-06-11 tojiro Deploying to gh-pages from @ gpuweb/gpuweb@02dac6eb8a 🚀
2022-06-10 dneto Add WGSL grammar analyzer (#2754)
2022-06-10 dneto Add WGSL grammar analyzer (#2754)
2022-06-10 dneto Add WGSL grammar analyzer (#2754)
2022-06-10 dneto Deploying to gh-pages from @ gpuweb/gpuweb@5fec9c7776 🚀
2022-06-10 kainino fix typo comparison_sampler -> sampler_comparison
2022-06-10 kainino fix typo comparison_sampler -> sampler_comparison
2022-06-10 kainino fix typo comparison_sampler -> sampler_comparison
2022-06-10 kainino1 Deploying to gh-pages from @ gpuweb/gpuweb@d3faddafb9 🚀
2022-06-09 jiawei.shao Ensure the formats supporting multisampling must support rendering (#3018)
2022-06-09 jiawei.shao Ensure the formats supporting multisampling must support rendering (#3018)
2022-06-09 jiawei.shao Ensure the formats supporting multisampling must support rendering (#3018)
2022-06-09 kainino1 Deploying to gh-pages from @ gpuweb/gpuweb@6ab558611a 🚀
2022-06-08 dom Align phrasing of Firing an event with DOM (#3019)
2022-06-08 dom Align phrasing of Firing an event with DOM (#3019)
2022-06-08 dom Align phrasing of Firing an event with DOM (#3019)
2022-06-08 kainino1 Deploying to gh-pages from @ gpuweb/gpuweb@72ce3910cf 🚀
2022-06-08 dsinclair Move builtin names to section headers. (#3016)
2022-06-08 dsinclair Move builtin names to section headers. (#3016)
2022-06-08 dsinclair Move builtin names to section headers. (#3016)
2022-06-08 bclayton wgsl: Allow phony assignment of abstract numeric type
2022-06-08 bclayton wgsl: Allow phony assignment of abstract numeric type
2022-06-08 bclayton wgsl: Allow phony assignment of abstract numeric type
2022-06-08 bclayton Deploying to gh-pages from @ gpuweb/gpuweb@1cfd17eed1 🚀
2022-06-07 kainino Add maxColorAttachments missing from GPUSupportedLimits (#2985)
2022-06-07 kainino Add maxColorAttachments missing from GPUSupportedLimits (#2985)
2022-06-07 kainino Add maxColorAttachments missing from GPUSupportedLimits (#2985)
2022-06-07 kainino1 Deploying to gh-pages from @ gpuweb/gpuweb@356791fbc0 🚀
2022-06-07 kainino Support building multi-file specs with the Bikeshed API (#2856)
2022-06-07 kainino Support building multi-file specs with the Bikeshed API (#2856)
2022-06-07 kainino Support building multi-file specs with the Bikeshed API (#2856)
2022-06-07 kainino1 Deploying to gh-pages from @ gpuweb/gpuweb@22eae85031 🚀
2022-06-07 kainino Format internal slots consistently with IDL attributes (#3011)

Created with:
  roll-dep third_party/gpuweb

Change-Id: Iebc959cfe54e64c17e7d6175379dbd2cfe840986
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/111801
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
2022-12-01 13:03:06 +00:00

202 lines
6.6 KiB
C++

// Copyright 2021 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/dawn/node/binding/GPUBuffer.h"
#include <memory>
#include <utility>
#include "src/dawn/node/binding/Converter.h"
#include "src/dawn/node/binding/Errors.h"
#include "src/dawn/node/utils/Debug.h"
namespace wgpu::binding {
////////////////////////////////////////////////////////////////////////////////
// wgpu::bindings::GPUBuffer
// TODO(crbug.com/dawn/1134): We may be doing more validation here than necessary. Once CTS is
// robustly passing, pull out validation and see what / if breaks.
////////////////////////////////////////////////////////////////////////////////
GPUBuffer::GPUBuffer(wgpu::Buffer buffer,
wgpu::BufferDescriptor desc,
wgpu::Device device,
std::shared_ptr<AsyncRunner> async)
: buffer_(std::move(buffer)),
desc_(desc),
device_(std::move(device)),
async_(std::move(async)) {
if (desc.mappedAtCreation) {
state_ = State::MappedAtCreation;
}
}
interop::Promise<void> GPUBuffer::mapAsync(Napi::Env env,
interop::GPUMapModeFlags mode,
interop::GPUSize64 offset,
std::optional<interop::GPUSize64> size) {
wgpu::MapMode md{};
Converter conv(env);
if (!conv(md, mode)) {
interop::Promise<void> promise(env, PROMISE_INFO);
promise.Reject(Errors::OperationError(env));
return promise;
}
if (state_ != State::Unmapped) {
interop::Promise<void> promise(env, PROMISE_INFO);
promise.Reject(Errors::OperationError(env));
device_.InjectError(wgpu::ErrorType::Validation,
"mapAsync called on buffer that is not in the unmapped state");
return promise;
}
struct Context {
Napi::Env env;
interop::Promise<void> promise;
AsyncTask task;
State& state;
};
auto ctx =
new Context{env, interop::Promise<void>(env, PROMISE_INFO), AsyncTask(async_), state_};
auto promise = ctx->promise;
uint64_t s = size.has_value() ? size.value().value : (desc_.size - offset);
state_ = State::MappingPending;
buffer_.MapAsync(
md, offset, s,
[](WGPUBufferMapAsyncStatus status, void* userdata) {
auto c = std::unique_ptr<Context>(static_cast<Context*>(userdata));
c->state = State::Unmapped;
switch (status) {
case WGPUBufferMapAsyncStatus_Force32:
UNREACHABLE("WGPUBufferMapAsyncStatus_Force32");
break;
case WGPUBufferMapAsyncStatus_Success:
c->promise.Resolve();
c->state = State::Mapped;
break;
case WGPUBufferMapAsyncStatus_Error:
c->promise.Reject(Errors::OperationError(c->env));
break;
case WGPUBufferMapAsyncStatus_UnmappedBeforeCallback:
case WGPUBufferMapAsyncStatus_DestroyedBeforeCallback:
c->promise.Reject(Errors::AbortError(c->env));
break;
case WGPUBufferMapAsyncStatus_Unknown:
case WGPUBufferMapAsyncStatus_DeviceLost:
// TODO(dawn:1123): The spec is a bit vague around what the promise should
// do here.
c->promise.Reject(Errors::UnknownError(c->env));
break;
}
},
ctx);
return promise;
}
interop::ArrayBuffer GPUBuffer::getMappedRange(Napi::Env env,
interop::GPUSize64 offset,
std::optional<interop::GPUSize64> size) {
if (state_ != State::Mapped && state_ != State::MappedAtCreation) {
Errors::OperationError(env).ThrowAsJavaScriptException();
return {};
}
uint64_t s = size.has_value() ? size.value().value : (desc_.size - offset);
uint64_t start = offset;
uint64_t end = offset + s;
for (auto& mapping : mapped_) {
if (mapping.Intersects(start, end)) {
Errors::OperationError(env).ThrowAsJavaScriptException();
return {};
}
}
auto* ptr = (desc_.usage & wgpu::BufferUsage::MapWrite)
? buffer_.GetMappedRange(offset, s)
: const_cast<void*>(buffer_.GetConstMappedRange(offset, s));
if (!ptr) {
Errors::OperationError(env).ThrowAsJavaScriptException();
return {};
}
auto array_buffer = Napi::ArrayBuffer::New(env, ptr, s);
// TODO(crbug.com/dawn/1135): Ownership here is the wrong way around.
mapped_.emplace_back(Mapping{start, end, Napi::Persistent(array_buffer)});
return array_buffer;
}
void GPUBuffer::unmap(Napi::Env env) {
buffer_.Unmap();
if (state_ != State::Destroyed && state_ != State::Unmapped) {
DetachMappings();
state_ = State::Unmapped;
}
}
void GPUBuffer::destroy(Napi::Env) {
if (state_ == State::Destroyed) {
return;
}
if (state_ != State::Unmapped) {
DetachMappings();
}
buffer_.Destroy();
state_ = State::Destroyed;
}
interop::GPUSize64 GPUBuffer::getSize(Napi::Env) {
return buffer_.GetSize();
}
interop::GPUBufferMapState GPUBuffer::getMapState(Napi::Env) {
UNIMPLEMENTED();
}
interop::GPUBufferUsageFlags GPUBuffer::getUsage(Napi::Env env) {
interop::GPUBufferUsageFlags result;
Converter conv(env);
if (!conv(result, buffer_.GetUsage())) {
Napi::Error::New(env, "Couldn't convert usage to a JavaScript value.")
.ThrowAsJavaScriptException();
return {0u}; // Doesn't get used.
}
return result;
}
void GPUBuffer::DetachMappings() {
for (auto& mapping : mapped_) {
mapping.buffer.Value().Detach();
}
mapped_.clear();
}
std::string GPUBuffer::getLabel(Napi::Env) {
UNIMPLEMENTED();
}
void GPUBuffer::setLabel(Napi::Env, std::string value) {
UNIMPLEMENTED();
}
} // namespace wgpu::binding