dawn_node: Implement setlike keys()
Used by a number of CTS tests (webgpu:idl,constants,flags:*) Bug: dawn:1143 Change-Id: Idd76c35a4debf54d5c53df11f59419de90f90162 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/65660 Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
5d58bd1a4a
commit
14d33c36c1
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
#include "src/dawn_node/binding/GPUAdapter.h"
|
#include "src/dawn_node/binding/GPUAdapter.h"
|
||||||
|
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
#include "src/dawn_node/binding/GPUDevice.h"
|
#include "src/dawn_node/binding/GPUDevice.h"
|
||||||
#include "src/dawn_node/binding/GPUSupportedLimits.h"
|
#include "src/dawn_node/binding/GPUSupportedLimits.h"
|
||||||
|
|
||||||
|
@ -27,26 +29,27 @@ namespace wgpu { namespace binding {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
class Features : public interop::GPUSupportedFeatures {
|
class Features : public interop::GPUSupportedFeatures {
|
||||||
public:
|
public:
|
||||||
Features(WGPUDeviceProperties properties) : properties_(std::move(properties)) {
|
Features(WGPUDeviceProperties properties) {
|
||||||
|
if (properties.depthClamping) {
|
||||||
|
enabled_.emplace(interop::GPUFeatureName::kDepthClamping);
|
||||||
|
}
|
||||||
|
if (properties.pipelineStatisticsQuery) {
|
||||||
|
enabled_.emplace(interop::GPUFeatureName::kPipelineStatisticsQuery);
|
||||||
|
}
|
||||||
|
if (properties.textureCompressionBC) {
|
||||||
|
enabled_.emplace(interop::GPUFeatureName::kTextureCompressionBc);
|
||||||
|
}
|
||||||
|
if (properties.timestampQuery) {
|
||||||
|
enabled_.emplace(interop::GPUFeatureName::kTimestampQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(crbug.com/dawn/1130)
|
||||||
|
// interop::GPUFeatureName::kDepth24UnormStencil8:
|
||||||
|
// interop::GPUFeatureName::kDepth32FloatStencil8:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool has(interop::GPUFeatureName feature) {
|
bool has(interop::GPUFeatureName feature) {
|
||||||
switch (feature) {
|
return enabled_.count(feature) != 0;
|
||||||
case interop::GPUFeatureName::kDepthClamping:
|
|
||||||
return properties_.depthClamping;
|
|
||||||
case interop::GPUFeatureName::kDepth24UnormStencil8:
|
|
||||||
return false; // TODO(crbug.com/dawn/1130)
|
|
||||||
case interop::GPUFeatureName::kDepth32FloatStencil8:
|
|
||||||
return false; // TODO(crbug.com/dawn/1130)
|
|
||||||
case interop::GPUFeatureName::kPipelineStatisticsQuery:
|
|
||||||
return properties_.pipelineStatisticsQuery;
|
|
||||||
case interop::GPUFeatureName::kTextureCompressionBc:
|
|
||||||
return properties_.textureCompressionBC;
|
|
||||||
case interop::GPUFeatureName::kTimestampQuery:
|
|
||||||
return properties_.timestampQuery;
|
|
||||||
}
|
|
||||||
UNIMPLEMENTED("feature: ", feature);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// interop::GPUSupportedFeatures compliance
|
// interop::GPUSupportedFeatures compliance
|
||||||
|
@ -57,9 +60,17 @@ namespace wgpu { namespace binding {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
std::vector<std::string> keys(Napi::Env) override {
|
||||||
|
std::vector<std::string> out;
|
||||||
|
out.reserve(enabled_.size());
|
||||||
|
for (auto feature : enabled_) {
|
||||||
|
out.push_back(interop::Converter<interop::GPUFeatureName>::ToString(feature));
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WGPUDeviceProperties properties_;
|
std::unordered_set<interop::GPUFeatureName> enabled_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -118,6 +118,9 @@ namespace wgpu { namespace binding {
|
||||||
bool has(Napi::Env, std::string feature) override {
|
bool has(Napi::Env, std::string feature) override {
|
||||||
UNIMPLEMENTED();
|
UNIMPLEMENTED();
|
||||||
}
|
}
|
||||||
|
std::vector<std::string> keys(Napi::Env) override {
|
||||||
|
UNIMPLEMENTED();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
return interop::GPUSupportedFeatures::Create<Features>(env);
|
return interop::GPUSupportedFeatures::Create<Features>(env);
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,6 +143,7 @@ Wrappers* Wrappers::instance = nullptr;
|
||||||
return DefineClass(env, "{{$.Name}}", {
|
return DefineClass(env, "{{$.Name}}", {
|
||||||
{{ if $s := SetlikeOf $}}
|
{{ if $s := SetlikeOf $}}
|
||||||
InstanceMethod("has", &W{{$.Name}}::has),
|
InstanceMethod("has", &W{{$.Name}}::has),
|
||||||
|
InstanceMethod("keys", &W{{$.Name}}::keys),
|
||||||
{{- end}}
|
{{- end}}
|
||||||
{{- range $m := MethodsOf $}}
|
{{- range $m := MethodsOf $}}
|
||||||
InstanceMethod("{{$m.Name}}", &W{{$.Name}}::{{$m.Name}}),
|
InstanceMethod("{{$m.Name}}", &W{{$.Name}}::{{$m.Name}}),
|
||||||
|
@ -169,6 +170,9 @@ Wrappers* Wrappers::instance = nullptr;
|
||||||
Napi::Error::New(info.Env(), "invalid arguments to has()").ThrowAsJavaScriptException();
|
Napi::Error::New(info.Env(), "invalid arguments to has()").ThrowAsJavaScriptException();
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
Napi::Value keys(const Napi::CallbackInfo& info) {
|
||||||
|
return ToJS(info.Env(), impl->keys(info.Env()));
|
||||||
|
}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
{{- range $m := MethodsOf $}}
|
{{- range $m := MethodsOf $}}
|
||||||
Napi::Value {{$m.Name}}(const Napi::CallbackInfo& info) {
|
Napi::Value {{$m.Name}}(const Napi::CallbackInfo& info) {
|
||||||
|
@ -330,26 +334,34 @@ bool Converter<{{$.Name}}>::FromString(std::string str, {{$.Name}}& out) {
|
||||||
{{- end}}
|
{{- end}}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* Converter<{{$.Name}}>::ToString({{$.Name}} value) {
|
||||||
|
switch (value) {
|
||||||
|
{{- range $e := $.Values}}
|
||||||
|
case {{$.Name}}::{{EnumEntryName $e.Value}}:
|
||||||
|
return {{$e.Value}};
|
||||||
|
{{- end}}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
bool Converter<{{$.Name}}>::FromJS(Napi::Env env, Napi::Value value, {{$.Name}}& out) {
|
bool Converter<{{$.Name}}>::FromJS(Napi::Env env, Napi::Value value, {{$.Name}}& out) {
|
||||||
return FromString(value.ToString(), out);
|
return FromString(value.ToString(), out);
|
||||||
}
|
}
|
||||||
|
|
||||||
Napi::Value Converter<{{$.Name}}>::ToJS(Napi::Env env, {{$.Name}} value) {
|
Napi::Value Converter<{{$.Name}}>::ToJS(Napi::Env env, {{$.Name}} value) {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
{{- range $e := $.Values}}
|
{{- range $e := $.Values}}
|
||||||
case {{$.Name}}::{{EnumEntryName $e.Value}}:
|
case {{$.Name}}::{{EnumEntryName $e.Value}}:
|
||||||
return Napi::String::New(env, {{$e.Value}});
|
return Napi::String::New(env, {{$e.Value}});
|
||||||
break;
|
|
||||||
{{- end}}
|
{{- end}}
|
||||||
}
|
}
|
||||||
return env.Undefined();
|
return env.Undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& o, {{$.Name}} value) {
|
std::ostream& operator<<(std::ostream& o, {{$.Name}} value) {
|
||||||
switch (value) {
|
if (auto* s = Converter<{{$.Name}}>::ToString(value)) {
|
||||||
{{- range $e := $.Values}}
|
return o << s;
|
||||||
case {{$.Name}}::{{EnumEntryName $e.Value}}:
|
|
||||||
return o << {{$e.Value}};
|
|
||||||
{{- end}}
|
|
||||||
}
|
}
|
||||||
return o << "undefined<{{$.Name}}>";
|
return o << "undefined<{{$.Name}}>";
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,6 +169,7 @@ public:
|
||||||
static bool FromJS(Napi::Env, Napi::Value, {{$.Name}}&);
|
static bool FromJS(Napi::Env, Napi::Value, {{$.Name}}&);
|
||||||
static Napi::Value ToJS(Napi::Env, {{$.Name}});
|
static Napi::Value ToJS(Napi::Env, {{$.Name}});
|
||||||
static bool FromString(std::string, {{$.Name}}&);
|
static bool FromString(std::string, {{$.Name}}&);
|
||||||
|
static const char* ToString({{$.Name}});
|
||||||
};
|
};
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& o, {{$.Name}});
|
std::ostream& operator<<(std::ostream& o, {{$.Name}});
|
||||||
|
@ -195,8 +196,9 @@ std::ostream& operator<<(std::ostream& o, {{$.Name}});
|
||||||
*/ -}}
|
*/ -}}
|
||||||
{{- define "InterfaceSetlike"}}
|
{{- define "InterfaceSetlike"}}
|
||||||
virtual bool has(Napi::Env, {{template "Type" $.Elem}}) = 0;
|
virtual bool has(Napi::Env, {{template "Type" $.Elem}}) = 0;
|
||||||
|
virtual std::vector<{{template "Type" $.Elem}}> keys(Napi::Env) = 0;
|
||||||
{{- /* TODO(crbug.com/dawn/1143):
|
{{- /* TODO(crbug.com/dawn/1143):
|
||||||
entries, forEach, keys, size, values
|
entries, forEach, size, values
|
||||||
read-write: add, clear, or delete
|
read-write: add, clear, or delete
|
||||||
*/}}
|
*/}}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
Loading…
Reference in New Issue