dawn/node: Implement GPUBuffer.getMapState()

Bug: dawn:1761
Change-Id: Id01789a2df8afd5726f6fc776e7d825153fd0f85
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/127722
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
Jiawei Shao 2023-04-19 01:47:52 +00:00 committed by Dawn LUCI CQ
parent ee25184ea4
commit f4b9f95b68
3 changed files with 28 additions and 2 deletions

View File

@ -1722,6 +1722,21 @@ bool Converter::Convert(interop::GPUQueryType& out, wgpu::QueryType in) {
return false;
}
bool Convert(interop::GPUBufferMapState& out, wgpu::BufferMapState in) {
switch (in) {
case wgpu::BufferMapState::Unmapped:
out = interop::GPUBufferMapState::kUnmapped;
return true;
case wgpu::BufferMapState::Pending:
out = interop::GPUBufferMapState::kPending;
return true;
case wgpu::BufferMapState::Mapped:
out = interop::GPUBufferMapState::kMapped;
return true;
}
return false;
}
bool Converter::Convert(wgpu::AddressMode& out, const interop::GPUAddressMode& in) {
out = wgpu::AddressMode::Repeat;
switch (in) {

View File

@ -270,6 +270,8 @@ class Converter {
[[nodiscard]] bool Convert(interop::GPUQueryType& out, wgpu::QueryType in);
[[nodiscard]] bool Convert(interop::GPUBufferMapState& out, wgpu::BufferMapState in);
// The two conversion methods don't generate an error when false is returned. That
// responsibility is left to the caller if it is needed (it isn't always needed, see
// https://gpuweb.github.io/gpuweb/#gpu-supportedfeatures)

View File

@ -166,8 +166,17 @@ interop::GPUSize64 GPUBuffer::getSize(Napi::Env) {
return buffer_.GetSize();
}
interop::GPUBufferMapState GPUBuffer::getMapState(Napi::Env) {
UNIMPLEMENTED();
interop::GPUBufferMapState GPUBuffer::getMapState(Napi::Env env) {
interop::GPUBufferMapState result;
Converter conv(env);
if (!conv(result, buffer_.GetMapState())) {
Napi::Error::New(env, "Couldn't convert usage to a JavaScript value.")
.ThrowAsJavaScriptException();
return interop::GPUBufferMapState::kUnmapped;
}
return result;
}
interop::GPUBufferUsageFlags GPUBuffer::getUsage(Napi::Env env) {