node: Throw a TypeError for unsupported GPUTextureFormats

The WebGPU spec requires this so that an extension not being enabled or
not implemented by the browser both behave the same.

Bug: None
Change-Id: Iba449c1f67d266aa53b924501577d646cd944f55
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/112421
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2022-12-05 11:50:49 +00:00 committed by Dawn LUCI CQ
parent 027bf02278
commit e2cdafbf8a
7 changed files with 153 additions and 68 deletions

View File

@ -14,6 +14,8 @@
#include "src/dawn/node/binding/Converter.h" #include "src/dawn/node/binding/Converter.h"
#include <cassert>
#include "src/dawn/node/binding/GPUBuffer.h" #include "src/dawn/node/binding/GPUBuffer.h"
#include "src/dawn/node/binding/GPUPipelineLayout.h" #include "src/dawn/node/binding/GPUPipelineLayout.h"
#include "src/dawn/node/binding/GPUQuerySet.h" #include "src/dawn/node/binding/GPUQuerySet.h"
@ -31,6 +33,13 @@ Converter::~Converter() {
} }
} }
bool Converter::HasFeature(wgpu::FeatureName feature) {
// Not all uses of the converter will have a device (for example for adapter-related
// conversions).
assert(device.Get() != nullptr);
return device.HasFeature(feature);
}
bool Converter::Convert(wgpu::Extent3D& out, const interop::GPUExtent3D& in) { bool Converter::Convert(wgpu::Extent3D& out, const interop::GPUExtent3D& in) {
out = {}; out = {};
if (auto* dict = std::get_if<interop::GPUExtent3DDict>(&in)) { if (auto* dict = std::get_if<interop::GPUExtent3DDict>(&in)) {
@ -172,6 +181,7 @@ bool Converter::Convert(wgpu::TextureDataLayout& out, const interop::GPUImageDat
bool Converter::Convert(wgpu::TextureFormat& out, const interop::GPUTextureFormat& in) { bool Converter::Convert(wgpu::TextureFormat& out, const interop::GPUTextureFormat& in) {
out = wgpu::TextureFormat::Undefined; out = wgpu::TextureFormat::Undefined;
wgpu::FeatureName requiredFeature = wgpu::FeatureName::Undefined;
switch (in) { switch (in) {
case interop::GPUTextureFormat::kR8Unorm: case interop::GPUTextureFormat::kR8Unorm:
out = wgpu::TextureFormat::R8Unorm; out = wgpu::TextureFormat::R8Unorm;
@ -296,168 +306,234 @@ bool Converter::Convert(wgpu::TextureFormat& out, const interop::GPUTextureForma
case interop::GPUTextureFormat::kDepth32Float: case interop::GPUTextureFormat::kDepth32Float:
out = wgpu::TextureFormat::Depth32Float; out = wgpu::TextureFormat::Depth32Float;
return true; return true;
case interop::GPUTextureFormat::kDepth32FloatStencil8: case interop::GPUTextureFormat::kDepth32FloatStencil8:
out = wgpu::TextureFormat::Depth32FloatStencil8; out = wgpu::TextureFormat::Depth32FloatStencil8;
return true; requiredFeature = wgpu::FeatureName::Depth32FloatStencil8;
break;
case interop::GPUTextureFormat::kBc1RgbaUnorm: case interop::GPUTextureFormat::kBc1RgbaUnorm:
out = wgpu::TextureFormat::BC1RGBAUnorm; out = wgpu::TextureFormat::BC1RGBAUnorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionBC;
break;
case interop::GPUTextureFormat::kBc1RgbaUnormSrgb: case interop::GPUTextureFormat::kBc1RgbaUnormSrgb:
out = wgpu::TextureFormat::BC1RGBAUnormSrgb; out = wgpu::TextureFormat::BC1RGBAUnormSrgb;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionBC;
break;
case interop::GPUTextureFormat::kBc2RgbaUnorm: case interop::GPUTextureFormat::kBc2RgbaUnorm:
out = wgpu::TextureFormat::BC2RGBAUnorm; out = wgpu::TextureFormat::BC2RGBAUnorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionBC;
break;
case interop::GPUTextureFormat::kBc2RgbaUnormSrgb: case interop::GPUTextureFormat::kBc2RgbaUnormSrgb:
out = wgpu::TextureFormat::BC2RGBAUnormSrgb; out = wgpu::TextureFormat::BC2RGBAUnormSrgb;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionBC;
break;
case interop::GPUTextureFormat::kBc3RgbaUnorm: case interop::GPUTextureFormat::kBc3RgbaUnorm:
out = wgpu::TextureFormat::BC3RGBAUnorm; out = wgpu::TextureFormat::BC3RGBAUnorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionBC;
break;
case interop::GPUTextureFormat::kBc3RgbaUnormSrgb: case interop::GPUTextureFormat::kBc3RgbaUnormSrgb:
out = wgpu::TextureFormat::BC3RGBAUnormSrgb; out = wgpu::TextureFormat::BC3RGBAUnormSrgb;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionBC;
break;
case interop::GPUTextureFormat::kBc4RUnorm: case interop::GPUTextureFormat::kBc4RUnorm:
out = wgpu::TextureFormat::BC4RUnorm; out = wgpu::TextureFormat::BC4RUnorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionBC;
break;
case interop::GPUTextureFormat::kBc4RSnorm: case interop::GPUTextureFormat::kBc4RSnorm:
out = wgpu::TextureFormat::BC4RSnorm; out = wgpu::TextureFormat::BC4RSnorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionBC;
break;
case interop::GPUTextureFormat::kBc5RgUnorm: case interop::GPUTextureFormat::kBc5RgUnorm:
out = wgpu::TextureFormat::BC5RGUnorm; out = wgpu::TextureFormat::BC5RGUnorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionBC;
break;
case interop::GPUTextureFormat::kBc5RgSnorm: case interop::GPUTextureFormat::kBc5RgSnorm:
out = wgpu::TextureFormat::BC5RGSnorm; out = wgpu::TextureFormat::BC5RGSnorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionBC;
break;
case interop::GPUTextureFormat::kBc6HRgbUfloat: case interop::GPUTextureFormat::kBc6HRgbUfloat:
out = wgpu::TextureFormat::BC6HRGBUfloat; out = wgpu::TextureFormat::BC6HRGBUfloat;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionBC;
break;
case interop::GPUTextureFormat::kBc6HRgbFloat: case interop::GPUTextureFormat::kBc6HRgbFloat:
out = wgpu::TextureFormat::BC6HRGBFloat; out = wgpu::TextureFormat::BC6HRGBFloat;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionBC;
break;
case interop::GPUTextureFormat::kBc7RgbaUnorm: case interop::GPUTextureFormat::kBc7RgbaUnorm:
out = wgpu::TextureFormat::BC7RGBAUnorm; out = wgpu::TextureFormat::BC7RGBAUnorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionBC;
break;
case interop::GPUTextureFormat::kBc7RgbaUnormSrgb: case interop::GPUTextureFormat::kBc7RgbaUnormSrgb:
out = wgpu::TextureFormat::BC7RGBAUnormSrgb; out = wgpu::TextureFormat::BC7RGBAUnormSrgb;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionBC;
break;
case interop::GPUTextureFormat::kEtc2Rgb8Unorm: case interop::GPUTextureFormat::kEtc2Rgb8Unorm:
out = wgpu::TextureFormat::ETC2RGB8Unorm; out = wgpu::TextureFormat::ETC2RGB8Unorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionETC2;
break;
case interop::GPUTextureFormat::kEtc2Rgb8UnormSrgb: case interop::GPUTextureFormat::kEtc2Rgb8UnormSrgb:
out = wgpu::TextureFormat::ETC2RGB8UnormSrgb; out = wgpu::TextureFormat::ETC2RGB8UnormSrgb;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionETC2;
break;
case interop::GPUTextureFormat::kEtc2Rgb8A1Unorm: case interop::GPUTextureFormat::kEtc2Rgb8A1Unorm:
out = wgpu::TextureFormat::ETC2RGB8A1Unorm; out = wgpu::TextureFormat::ETC2RGB8A1Unorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionETC2;
break;
case interop::GPUTextureFormat::kEtc2Rgb8A1UnormSrgb: case interop::GPUTextureFormat::kEtc2Rgb8A1UnormSrgb:
out = wgpu::TextureFormat::ETC2RGB8A1UnormSrgb; out = wgpu::TextureFormat::ETC2RGB8A1UnormSrgb;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionETC2;
break;
case interop::GPUTextureFormat::kEtc2Rgba8Unorm: case interop::GPUTextureFormat::kEtc2Rgba8Unorm:
out = wgpu::TextureFormat::ETC2RGBA8Unorm; out = wgpu::TextureFormat::ETC2RGBA8Unorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionETC2;
break;
case interop::GPUTextureFormat::kEtc2Rgba8UnormSrgb: case interop::GPUTextureFormat::kEtc2Rgba8UnormSrgb:
out = wgpu::TextureFormat::ETC2RGBA8UnormSrgb; out = wgpu::TextureFormat::ETC2RGBA8UnormSrgb;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionETC2;
break;
case interop::GPUTextureFormat::kEacR11Unorm: case interop::GPUTextureFormat::kEacR11Unorm:
out = wgpu::TextureFormat::EACR11Unorm; out = wgpu::TextureFormat::EACR11Unorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionETC2;
break;
case interop::GPUTextureFormat::kEacR11Snorm: case interop::GPUTextureFormat::kEacR11Snorm:
out = wgpu::TextureFormat::EACR11Snorm; out = wgpu::TextureFormat::EACR11Snorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionETC2;
break;
case interop::GPUTextureFormat::kEacRg11Unorm: case interop::GPUTextureFormat::kEacRg11Unorm:
out = wgpu::TextureFormat::EACRG11Unorm; out = wgpu::TextureFormat::EACRG11Unorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionETC2;
break;
case interop::GPUTextureFormat::kEacRg11Snorm: case interop::GPUTextureFormat::kEacRg11Snorm:
out = wgpu::TextureFormat::EACRG11Snorm; out = wgpu::TextureFormat::EACRG11Snorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionETC2;
break;
case interop::GPUTextureFormat::kAstc4X4Unorm: case interop::GPUTextureFormat::kAstc4X4Unorm:
out = wgpu::TextureFormat::ASTC4x4Unorm; out = wgpu::TextureFormat::ASTC4x4Unorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc4X4UnormSrgb: case interop::GPUTextureFormat::kAstc4X4UnormSrgb:
out = wgpu::TextureFormat::ASTC4x4UnormSrgb; out = wgpu::TextureFormat::ASTC4x4UnormSrgb;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc5X4Unorm: case interop::GPUTextureFormat::kAstc5X4Unorm:
out = wgpu::TextureFormat::ASTC5x4Unorm; out = wgpu::TextureFormat::ASTC5x4Unorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc5X4UnormSrgb: case interop::GPUTextureFormat::kAstc5X4UnormSrgb:
out = wgpu::TextureFormat::ASTC5x4UnormSrgb; out = wgpu::TextureFormat::ASTC5x4UnormSrgb;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc5X5Unorm: case interop::GPUTextureFormat::kAstc5X5Unorm:
out = wgpu::TextureFormat::ASTC5x5Unorm; out = wgpu::TextureFormat::ASTC5x5Unorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc5X5UnormSrgb: case interop::GPUTextureFormat::kAstc5X5UnormSrgb:
out = wgpu::TextureFormat::ASTC5x5UnormSrgb; out = wgpu::TextureFormat::ASTC5x5UnormSrgb;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc6X5Unorm: case interop::GPUTextureFormat::kAstc6X5Unorm:
out = wgpu::TextureFormat::ASTC6x5Unorm; out = wgpu::TextureFormat::ASTC6x5Unorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc6X5UnormSrgb: case interop::GPUTextureFormat::kAstc6X5UnormSrgb:
out = wgpu::TextureFormat::ASTC6x5UnormSrgb; out = wgpu::TextureFormat::ASTC6x5UnormSrgb;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc6X6Unorm: case interop::GPUTextureFormat::kAstc6X6Unorm:
out = wgpu::TextureFormat::ASTC6x6Unorm; out = wgpu::TextureFormat::ASTC6x6Unorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc6X6UnormSrgb: case interop::GPUTextureFormat::kAstc6X6UnormSrgb:
out = wgpu::TextureFormat::ASTC6x6UnormSrgb; out = wgpu::TextureFormat::ASTC6x6UnormSrgb;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc8X5Unorm: case interop::GPUTextureFormat::kAstc8X5Unorm:
out = wgpu::TextureFormat::ASTC8x5Unorm; out = wgpu::TextureFormat::ASTC8x5Unorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc8X5UnormSrgb: case interop::GPUTextureFormat::kAstc8X5UnormSrgb:
out = wgpu::TextureFormat::ASTC8x5UnormSrgb; out = wgpu::TextureFormat::ASTC8x5UnormSrgb;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc8X6Unorm: case interop::GPUTextureFormat::kAstc8X6Unorm:
out = wgpu::TextureFormat::ASTC8x6Unorm; out = wgpu::TextureFormat::ASTC8x6Unorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc8X6UnormSrgb: case interop::GPUTextureFormat::kAstc8X6UnormSrgb:
out = wgpu::TextureFormat::ASTC8x6UnormSrgb; out = wgpu::TextureFormat::ASTC8x6UnormSrgb;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc8X8Unorm: case interop::GPUTextureFormat::kAstc8X8Unorm:
out = wgpu::TextureFormat::ASTC8x8Unorm; out = wgpu::TextureFormat::ASTC8x8Unorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc8X8UnormSrgb: case interop::GPUTextureFormat::kAstc8X8UnormSrgb:
out = wgpu::TextureFormat::ASTC8x8UnormSrgb; out = wgpu::TextureFormat::ASTC8x8UnormSrgb;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc10X5Unorm: case interop::GPUTextureFormat::kAstc10X5Unorm:
out = wgpu::TextureFormat::ASTC10x5Unorm; out = wgpu::TextureFormat::ASTC10x5Unorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc10X5UnormSrgb: case interop::GPUTextureFormat::kAstc10X5UnormSrgb:
out = wgpu::TextureFormat::ASTC10x5UnormSrgb; out = wgpu::TextureFormat::ASTC10x5UnormSrgb;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc10X6Unorm: case interop::GPUTextureFormat::kAstc10X6Unorm:
out = wgpu::TextureFormat::ASTC10x6Unorm; out = wgpu::TextureFormat::ASTC10x6Unorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc10X6UnormSrgb: case interop::GPUTextureFormat::kAstc10X6UnormSrgb:
out = wgpu::TextureFormat::ASTC10x6UnormSrgb; out = wgpu::TextureFormat::ASTC10x6UnormSrgb;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc10X8Unorm: case interop::GPUTextureFormat::kAstc10X8Unorm:
out = wgpu::TextureFormat::ASTC10x8Unorm; out = wgpu::TextureFormat::ASTC10x8Unorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc10X8UnormSrgb: case interop::GPUTextureFormat::kAstc10X8UnormSrgb:
out = wgpu::TextureFormat::ASTC10x8UnormSrgb; out = wgpu::TextureFormat::ASTC10x8UnormSrgb;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc10X10Unorm: case interop::GPUTextureFormat::kAstc10X10Unorm:
out = wgpu::TextureFormat::ASTC10x10Unorm; out = wgpu::TextureFormat::ASTC10x10Unorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc10X10UnormSrgb: case interop::GPUTextureFormat::kAstc10X10UnormSrgb:
out = wgpu::TextureFormat::ASTC10x10UnormSrgb; out = wgpu::TextureFormat::ASTC10x10UnormSrgb;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc12X10Unorm: case interop::GPUTextureFormat::kAstc12X10Unorm:
out = wgpu::TextureFormat::ASTC12x10Unorm; out = wgpu::TextureFormat::ASTC12x10Unorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc12X10UnormSrgb: case interop::GPUTextureFormat::kAstc12X10UnormSrgb:
out = wgpu::TextureFormat::ASTC12x10UnormSrgb; out = wgpu::TextureFormat::ASTC12x10UnormSrgb;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc12X12Unorm: case interop::GPUTextureFormat::kAstc12X12Unorm:
out = wgpu::TextureFormat::ASTC12x12Unorm; out = wgpu::TextureFormat::ASTC12x12Unorm;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
case interop::GPUTextureFormat::kAstc12X12UnormSrgb: case interop::GPUTextureFormat::kAstc12X12UnormSrgb:
out = wgpu::TextureFormat::ASTC12x12UnormSrgb; out = wgpu::TextureFormat::ASTC12x12UnormSrgb;
return true; requiredFeature = wgpu::FeatureName::TextureCompressionASTC;
break;
default:
Napi::Error::New(env, "invalid value for GPUTextureFormat")
.ThrowAsJavaScriptException();
return false;
} }
Napi::Error::New(env, "invalid value for GPUTextureFormat").ThrowAsJavaScriptException();
return false; assert(requiredFeature != wgpu::FeatureName::Undefined);
if (!HasFeature(requiredFeature)) {
Napi::TypeError::New(env, "invalid value for GPUTextureFormat")
.ThrowAsJavaScriptException();
return false;
}
return true;
} }
bool Converter::Convert(interop::GPUTextureFormat& out, wgpu::TextureFormat in) { bool Converter::Convert(interop::GPUTextureFormat& out, wgpu::TextureFormat in) {

View File

@ -69,6 +69,8 @@ using ImplOf = typename ImplOfTraits<T>::type;
class Converter { class Converter {
public: public:
explicit Converter(Napi::Env e) : env(e) {} explicit Converter(Napi::Env e) : env(e) {}
Converter(Napi::Env e, wgpu::Device extensionDevice)
: env(e), device(std::move(extensionDevice)) {}
~Converter(); ~Converter();
// Conversion function. Converts the interop type IN to the Dawn type OUT. // Conversion function. Converts the interop type IN to the Dawn type OUT.
@ -408,6 +410,9 @@ class Converter {
} }
Napi::Env env; Napi::Env env;
wgpu::Device device = nullptr;
bool HasFeature(wgpu::FeatureName feature);
// Allocate() allocates and constructs an array of 'n' elements, and returns a pointer to // Allocate() allocates and constructs an array of 'n' elements, and returns a pointer to
// the first element. The array is freed when the Converter is destructed. // the first element. The array is freed when the Converter is destructed.

View File

@ -31,12 +31,13 @@ namespace wgpu::binding {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// wgpu::bindings::GPUCommandEncoder // wgpu::bindings::GPUCommandEncoder
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
GPUCommandEncoder::GPUCommandEncoder(wgpu::CommandEncoder enc) : enc_(std::move(enc)) {} GPUCommandEncoder::GPUCommandEncoder(wgpu::Device device, wgpu::CommandEncoder enc)
: device_(std::move(device)), enc_(std::move(enc)) {}
interop::Interface<interop::GPURenderPassEncoder> GPUCommandEncoder::beginRenderPass( interop::Interface<interop::GPURenderPassEncoder> GPUCommandEncoder::beginRenderPass(
Napi::Env env, Napi::Env env,
interop::GPURenderPassDescriptor descriptor) { interop::GPURenderPassDescriptor descriptor) {
Converter conv(env); Converter conv(env, device_);
wgpu::RenderPassDescriptor desc{}; wgpu::RenderPassDescriptor desc{};
wgpu::RenderPassDescriptorMaxDrawCount maxDrawCountDesc{}; wgpu::RenderPassDescriptorMaxDrawCount maxDrawCountDesc{};

View File

@ -28,7 +28,7 @@ namespace wgpu::binding {
// wgpu::CommandEncoder. // wgpu::CommandEncoder.
class GPUCommandEncoder final : public interop::GPUCommandEncoder { class GPUCommandEncoder final : public interop::GPUCommandEncoder {
public: public:
explicit GPUCommandEncoder(wgpu::CommandEncoder enc); GPUCommandEncoder(wgpu::Device device, wgpu::CommandEncoder enc);
// interop::GPUCommandEncoder interface compliance // interop::GPUCommandEncoder interface compliance
interop::Interface<interop::GPURenderPassEncoder> beginRenderPass( interop::Interface<interop::GPURenderPassEncoder> beginRenderPass(
@ -78,6 +78,7 @@ class GPUCommandEncoder final : public interop::GPUCommandEncoder {
void setLabel(Napi::Env, std::string value) override; void setLabel(Napi::Env, std::string value) override;
private: private:
wgpu::Device device_;
wgpu::CommandEncoder enc_; wgpu::CommandEncoder enc_;
}; };

View File

@ -225,7 +225,7 @@ interop::Interface<interop::GPUBuffer> GPUDevice::createBuffer(
interop::Interface<interop::GPUTexture> GPUDevice::createTexture( interop::Interface<interop::GPUTexture> GPUDevice::createTexture(
Napi::Env env, Napi::Env env,
interop::GPUTextureDescriptor descriptor) { interop::GPUTextureDescriptor descriptor) {
Converter conv(env); Converter conv(env, device_);
wgpu::TextureDescriptor desc{}; wgpu::TextureDescriptor desc{};
if (!conv(desc.label, descriptor.label) || !conv(desc.usage, descriptor.usage) || // if (!conv(desc.label, descriptor.label) || !conv(desc.usage, descriptor.usage) || //
@ -237,7 +237,7 @@ interop::Interface<interop::GPUTexture> GPUDevice::createTexture(
!conv(desc.viewFormats, desc.viewFormatCount, descriptor.viewFormats)) { !conv(desc.viewFormats, desc.viewFormatCount, descriptor.viewFormats)) {
return {}; return {};
} }
return interop::GPUTexture::Create<GPUTexture>(env, device_.CreateTexture(&desc)); return interop::GPUTexture::Create<GPUTexture>(env, device_, device_.CreateTexture(&desc));
} }
interop::Interface<interop::GPUSampler> GPUDevice::createSampler( interop::Interface<interop::GPUSampler> GPUDevice::createSampler(
@ -271,7 +271,7 @@ interop::Interface<interop::GPUExternalTexture> GPUDevice::importExternalTexture
interop::Interface<interop::GPUBindGroupLayout> GPUDevice::createBindGroupLayout( interop::Interface<interop::GPUBindGroupLayout> GPUDevice::createBindGroupLayout(
Napi::Env env, Napi::Env env,
interop::GPUBindGroupLayoutDescriptor descriptor) { interop::GPUBindGroupLayoutDescriptor descriptor) {
Converter conv(env); Converter conv(env, device_);
wgpu::BindGroupLayoutDescriptor desc{}; wgpu::BindGroupLayoutDescriptor desc{};
if (!conv(desc.label, descriptor.label) || if (!conv(desc.label, descriptor.label) ||
@ -345,7 +345,7 @@ interop::Interface<interop::GPUComputePipeline> GPUDevice::createComputePipeline
interop::Interface<interop::GPURenderPipeline> GPUDevice::createRenderPipeline( interop::Interface<interop::GPURenderPipeline> GPUDevice::createRenderPipeline(
Napi::Env env, Napi::Env env,
interop::GPURenderPipelineDescriptor descriptor) { interop::GPURenderPipelineDescriptor descriptor) {
Converter conv(env); Converter conv(env, device_);
wgpu::RenderPipelineDescriptor desc{}; wgpu::RenderPipelineDescriptor desc{};
if (!conv(desc, descriptor)) { if (!conv(desc, descriptor)) {
@ -404,7 +404,7 @@ GPUDevice::createRenderPipelineAsync(Napi::Env env,
interop::GPURenderPipelineDescriptor descriptor) { interop::GPURenderPipelineDescriptor descriptor) {
using Promise = interop::Promise<interop::Interface<interop::GPURenderPipeline>>; using Promise = interop::Promise<interop::Interface<interop::GPURenderPipeline>>;
Converter conv(env); Converter conv(env, device_);
wgpu::RenderPipelineDescriptor desc{}; wgpu::RenderPipelineDescriptor desc{};
if (!conv(desc, descriptor)) { if (!conv(desc, descriptor)) {
@ -447,13 +447,13 @@ interop::Interface<interop::GPUCommandEncoder> GPUDevice::createCommandEncoder(
interop::GPUCommandEncoderDescriptor descriptor) { interop::GPUCommandEncoderDescriptor descriptor) {
wgpu::CommandEncoderDescriptor desc{}; wgpu::CommandEncoderDescriptor desc{};
return interop::GPUCommandEncoder::Create<GPUCommandEncoder>( return interop::GPUCommandEncoder::Create<GPUCommandEncoder>(
env, device_.CreateCommandEncoder(&desc)); env, device_, device_.CreateCommandEncoder(&desc));
} }
interop::Interface<interop::GPURenderBundleEncoder> GPUDevice::createRenderBundleEncoder( interop::Interface<interop::GPURenderBundleEncoder> GPUDevice::createRenderBundleEncoder(
Napi::Env env, Napi::Env env,
interop::GPURenderBundleEncoderDescriptor descriptor) { interop::GPURenderBundleEncoderDescriptor descriptor) {
Converter conv(env); Converter conv(env, device_);
wgpu::RenderBundleEncoderDescriptor desc{}; wgpu::RenderBundleEncoderDescriptor desc{};
if (!conv(desc.label, descriptor.label) || if (!conv(desc.label, descriptor.label) ||

View File

@ -26,7 +26,8 @@ namespace wgpu::binding {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// wgpu::bindings::GPUTexture // wgpu::bindings::GPUTexture
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
GPUTexture::GPUTexture(wgpu::Texture texture) : texture_(std::move(texture)) {} GPUTexture::GPUTexture(wgpu::Device device, wgpu::Texture texture)
: device_(std::move(device)), texture_(std::move(texture)) {}
interop::Interface<interop::GPUTextureView> GPUTexture::createView( interop::Interface<interop::GPUTextureView> GPUTexture::createView(
Napi::Env env, Napi::Env env,
@ -37,7 +38,7 @@ interop::Interface<interop::GPUTextureView> GPUTexture::createView(
} }
wgpu::TextureViewDescriptor desc{}; wgpu::TextureViewDescriptor desc{};
Converter conv(env); Converter conv(env, device_);
if (!conv(desc.baseMipLevel, descriptor.baseMipLevel) || // if (!conv(desc.baseMipLevel, descriptor.baseMipLevel) || //
!conv(desc.mipLevelCount, descriptor.mipLevelCount) || // !conv(desc.mipLevelCount, descriptor.mipLevelCount) || //
!conv(desc.baseArrayLayer, descriptor.baseArrayLayer) || // !conv(desc.baseArrayLayer, descriptor.baseArrayLayer) || //

View File

@ -27,7 +27,7 @@ namespace wgpu::binding {
// GPUTexture is an implementation of interop::GPUTexture that wraps a wgpu::Texture. // GPUTexture is an implementation of interop::GPUTexture that wraps a wgpu::Texture.
class GPUTexture final : public interop::GPUTexture { class GPUTexture final : public interop::GPUTexture {
public: public:
explicit GPUTexture(wgpu::Texture texture); explicit GPUTexture(wgpu::Device device, wgpu::Texture texture);
// Implicit cast operator to Dawn GPU object // Implicit cast operator to Dawn GPU object
inline operator const wgpu::Texture&() const { return texture_; } inline operator const wgpu::Texture&() const { return texture_; }
@ -49,6 +49,7 @@ class GPUTexture final : public interop::GPUTexture {
void setLabel(Napi::Env, std::string value) override; void setLabel(Napi::Env, std::string value) override;
private: private:
wgpu::Device device_;
wgpu::Texture texture_; wgpu::Texture texture_;
}; };