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 <unordered_set>
|
||||
|
||||
#include "src/dawn_node/binding/GPUDevice.h"
|
||||
#include "src/dawn_node/binding/GPUSupportedLimits.h"
|
||||
|
||||
|
@ -27,26 +29,27 @@ namespace wgpu { namespace binding {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
class Features : public interop::GPUSupportedFeatures {
|
||||
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) {
|
||||
switch (feature) {
|
||||
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;
|
||||
return enabled_.count(feature) != 0;
|
||||
}
|
||||
|
||||
// interop::GPUSupportedFeatures compliance
|
||||
|
@ -57,9 +60,17 @@ namespace wgpu { namespace binding {
|
|||
}
|
||||
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:
|
||||
WGPUDeviceProperties properties_;
|
||||
std::unordered_set<interop::GPUFeatureName> enabled_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -118,6 +118,9 @@ namespace wgpu { namespace binding {
|
|||
bool has(Napi::Env, std::string feature) override {
|
||||
UNIMPLEMENTED();
|
||||
}
|
||||
std::vector<std::string> keys(Napi::Env) override {
|
||||
UNIMPLEMENTED();
|
||||
}
|
||||
};
|
||||
return interop::GPUSupportedFeatures::Create<Features>(env);
|
||||
}
|
||||
|
|
|
@ -143,6 +143,7 @@ Wrappers* Wrappers::instance = nullptr;
|
|||
return DefineClass(env, "{{$.Name}}", {
|
||||
{{ if $s := SetlikeOf $}}
|
||||
InstanceMethod("has", &W{{$.Name}}::has),
|
||||
InstanceMethod("keys", &W{{$.Name}}::keys),
|
||||
{{- end}}
|
||||
{{- range $m := MethodsOf $}}
|
||||
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();
|
||||
return {};
|
||||
}
|
||||
Napi::Value keys(const Napi::CallbackInfo& info) {
|
||||
return ToJS(info.Env(), impl->keys(info.Env()));
|
||||
}
|
||||
{{- end}}
|
||||
{{- range $m := MethodsOf $}}
|
||||
Napi::Value {{$m.Name}}(const Napi::CallbackInfo& info) {
|
||||
|
@ -330,26 +334,34 @@ bool Converter<{{$.Name}}>::FromString(std::string str, {{$.Name}}& out) {
|
|||
{{- end}}
|
||||
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) {
|
||||
return FromString(value.ToString(), out);
|
||||
}
|
||||
|
||||
Napi::Value Converter<{{$.Name}}>::ToJS(Napi::Env env, {{$.Name}} value) {
|
||||
switch (value) {
|
||||
{{- range $e := $.Values}}
|
||||
case {{$.Name}}::{{EnumEntryName $e.Value}}:
|
||||
return Napi::String::New(env, {{$e.Value}});
|
||||
break;
|
||||
{{- end}}
|
||||
}
|
||||
return env.Undefined();
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& o, {{$.Name}} value) {
|
||||
switch (value) {
|
||||
{{- range $e := $.Values}}
|
||||
case {{$.Name}}::{{EnumEntryName $e.Value}}:
|
||||
return o << {{$e.Value}};
|
||||
{{- end}}
|
||||
if (auto* s = Converter<{{$.Name}}>::ToString(value)) {
|
||||
return o << s;
|
||||
}
|
||||
return o << "undefined<{{$.Name}}>";
|
||||
}
|
||||
|
|
|
@ -169,6 +169,7 @@ public:
|
|||
static bool FromJS(Napi::Env, Napi::Value, {{$.Name}}&);
|
||||
static Napi::Value ToJS(Napi::Env, {{$.Name}});
|
||||
static bool FromString(std::string, {{$.Name}}&);
|
||||
static const char* ToString({{$.Name}});
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& o, {{$.Name}});
|
||||
|
@ -195,8 +196,9 @@ std::ostream& operator<<(std::ostream& o, {{$.Name}});
|
|||
*/ -}}
|
||||
{{- define "InterfaceSetlike"}}
|
||||
virtual bool has(Napi::Env, {{template "Type" $.Elem}}) = 0;
|
||||
virtual std::vector<{{template "Type" $.Elem}}> keys(Napi::Env) = 0;
|
||||
{{- /* TODO(crbug.com/dawn/1143):
|
||||
entries, forEach, keys, size, values
|
||||
entries, forEach, size, values
|
||||
read-write: add, clear, or delete
|
||||
*/}}
|
||||
{{- end }}
|
||||
|
|
Loading…
Reference in New Issue