dawn_node: Use wgpu::SupportedLimits

Query the Adapter / Device for limits instead of hardcoding them.

Bug: dawn:1143
Change-Id: Ib6d47bdb81df8e5e6eb767d35d346bbf34c5877a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/65722
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2021-10-11 15:42:12 +00:00 committed by Dawn LUCI CQ
parent 008cba9b29
commit 34206ec07b
4 changed files with 76 additions and 31 deletions

View File

@ -92,7 +92,43 @@ namespace wgpu { namespace binding {
} }
interop::Interface<interop::GPUSupportedLimits> GPUAdapter::getLimits(Napi::Env env) { interop::Interface<interop::GPUSupportedLimits> GPUAdapter::getLimits(Napi::Env env) {
return interop::GPUSupportedLimits::Create<GPUSupportedLimits>(env); WGPUSupportedLimits limits{};
if (!adapter_.GetLimits(&limits)) {
Napi::Error::New(env, "failed to get adapter limits").ThrowAsJavaScriptException();
}
wgpu::SupportedLimits wgpuLimits{};
#define COPY_LIMIT(LIMIT) wgpuLimits.limits.LIMIT = limits.limits.LIMIT
COPY_LIMIT(maxTextureDimension1D);
COPY_LIMIT(maxTextureDimension2D);
COPY_LIMIT(maxTextureDimension3D);
COPY_LIMIT(maxTextureArrayLayers);
COPY_LIMIT(maxBindGroups);
COPY_LIMIT(maxDynamicUniformBuffersPerPipelineLayout);
COPY_LIMIT(maxDynamicStorageBuffersPerPipelineLayout);
COPY_LIMIT(maxSampledTexturesPerShaderStage);
COPY_LIMIT(maxSamplersPerShaderStage);
COPY_LIMIT(maxStorageBuffersPerShaderStage);
COPY_LIMIT(maxStorageTexturesPerShaderStage);
COPY_LIMIT(maxUniformBuffersPerShaderStage);
COPY_LIMIT(maxUniformBufferBindingSize);
COPY_LIMIT(maxStorageBufferBindingSize);
COPY_LIMIT(minUniformBufferOffsetAlignment);
COPY_LIMIT(minStorageBufferOffsetAlignment);
COPY_LIMIT(maxVertexBuffers);
COPY_LIMIT(maxVertexAttributes);
COPY_LIMIT(maxVertexBufferArrayStride);
COPY_LIMIT(maxInterStageShaderComponents);
COPY_LIMIT(maxComputeWorkgroupStorageSize);
COPY_LIMIT(maxComputeInvocationsPerWorkgroup);
COPY_LIMIT(maxComputeWorkgroupSizeX);
COPY_LIMIT(maxComputeWorkgroupSizeY);
COPY_LIMIT(maxComputeWorkgroupSizeZ);
COPY_LIMIT(maxComputeWorkgroupsPerDimension);
#undef COPY_LIMIT
return interop::GPUSupportedLimits::Create<GPUSupportedLimits>(env, wgpuLimits);
} }
bool GPUAdapter::getIsFallbackAdapter(Napi::Env) { bool GPUAdapter::getIsFallbackAdapter(Napi::Env) {

View File

@ -126,7 +126,11 @@ namespace wgpu { namespace binding {
} }
interop::Interface<interop::GPUSupportedLimits> GPUDevice::getLimits(Napi::Env env) { interop::Interface<interop::GPUSupportedLimits> GPUDevice::getLimits(Napi::Env env) {
return interop::GPUSupportedLimits::Create<GPUSupportedLimits>(env); wgpu::SupportedLimits limits{};
if (!device_.GetLimits(&limits)) {
Napi::Error::New(env, "failed to get device limits").ThrowAsJavaScriptException();
}
return interop::GPUSupportedLimits::Create<GPUSupportedLimits>(env, limits);
} }
interop::Interface<interop::GPUQueue> GPUDevice::getQueue(Napi::Env env) { interop::Interface<interop::GPUQueue> GPUDevice::getQueue(Napi::Env env) {

View File

@ -20,112 +20,112 @@ namespace wgpu { namespace binding {
// wgpu::bindings::GPUSupportedLimits // wgpu::bindings::GPUSupportedLimits
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Values taken from. GPUSupportedLimits::GPUSupportedLimits(wgpu::SupportedLimits limits)
// https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/webgpu/gpu_supported_limits.h : limits_(std::move(limits)) {
// TODO(crbug.com/dawn/1131): Actually use limits reported by the device / adapter. }
uint32_t GPUSupportedLimits::getMaxTextureDimension1D(Napi::Env) { uint32_t GPUSupportedLimits::getMaxTextureDimension1D(Napi::Env) {
return 8192; return limits_.limits.maxTextureDimension1D;
} }
uint32_t GPUSupportedLimits::getMaxTextureDimension2D(Napi::Env) { uint32_t GPUSupportedLimits::getMaxTextureDimension2D(Napi::Env) {
return 8192; return limits_.limits.maxTextureDimension2D;
} }
uint32_t GPUSupportedLimits::getMaxTextureDimension3D(Napi::Env) { uint32_t GPUSupportedLimits::getMaxTextureDimension3D(Napi::Env) {
return 2048; return limits_.limits.maxTextureDimension3D;
} }
uint32_t GPUSupportedLimits::getMaxTextureArrayLayers(Napi::Env) { uint32_t GPUSupportedLimits::getMaxTextureArrayLayers(Napi::Env) {
return 2048; return limits_.limits.maxTextureArrayLayers;
} }
uint32_t GPUSupportedLimits::getMaxBindGroups(Napi::Env) { uint32_t GPUSupportedLimits::getMaxBindGroups(Napi::Env) {
return 4; return limits_.limits.maxBindGroups;
} }
uint32_t GPUSupportedLimits::getMaxDynamicUniformBuffersPerPipelineLayout(Napi::Env) { uint32_t GPUSupportedLimits::getMaxDynamicUniformBuffersPerPipelineLayout(Napi::Env) {
return 8; return limits_.limits.maxDynamicUniformBuffersPerPipelineLayout;
} }
uint32_t GPUSupportedLimits::getMaxDynamicStorageBuffersPerPipelineLayout(Napi::Env) { uint32_t GPUSupportedLimits::getMaxDynamicStorageBuffersPerPipelineLayout(Napi::Env) {
return 4; return limits_.limits.maxDynamicStorageBuffersPerPipelineLayout;
} }
uint32_t GPUSupportedLimits::getMaxSampledTexturesPerShaderStage(Napi::Env) { uint32_t GPUSupportedLimits::getMaxSampledTexturesPerShaderStage(Napi::Env) {
return 16; return limits_.limits.maxSampledTexturesPerShaderStage;
} }
uint32_t GPUSupportedLimits::getMaxSamplersPerShaderStage(Napi::Env) { uint32_t GPUSupportedLimits::getMaxSamplersPerShaderStage(Napi::Env) {
return 16; return limits_.limits.maxSamplersPerShaderStage;
} }
uint32_t GPUSupportedLimits::getMaxStorageBuffersPerShaderStage(Napi::Env) { uint32_t GPUSupportedLimits::getMaxStorageBuffersPerShaderStage(Napi::Env) {
return 4; return limits_.limits.maxStorageBuffersPerShaderStage;
} }
uint32_t GPUSupportedLimits::getMaxStorageTexturesPerShaderStage(Napi::Env) { uint32_t GPUSupportedLimits::getMaxStorageTexturesPerShaderStage(Napi::Env) {
return 4; return limits_.limits.maxStorageTexturesPerShaderStage;
} }
uint32_t GPUSupportedLimits::getMaxUniformBuffersPerShaderStage(Napi::Env) { uint32_t GPUSupportedLimits::getMaxUniformBuffersPerShaderStage(Napi::Env) {
return 12; return limits_.limits.maxUniformBuffersPerShaderStage;
} }
uint64_t GPUSupportedLimits::getMaxUniformBufferBindingSize(Napi::Env) { uint64_t GPUSupportedLimits::getMaxUniformBufferBindingSize(Napi::Env) {
return 16384; return limits_.limits.maxUniformBufferBindingSize;
} }
uint64_t GPUSupportedLimits::getMaxStorageBufferBindingSize(Napi::Env) { uint64_t GPUSupportedLimits::getMaxStorageBufferBindingSize(Napi::Env) {
return 134217728; return limits_.limits.maxStorageBufferBindingSize;
} }
uint32_t GPUSupportedLimits::getMinUniformBufferOffsetAlignment(Napi::Env) { uint32_t GPUSupportedLimits::getMinUniformBufferOffsetAlignment(Napi::Env) {
return 256; return limits_.limits.minUniformBufferOffsetAlignment;
} }
uint32_t GPUSupportedLimits::getMinStorageBufferOffsetAlignment(Napi::Env) { uint32_t GPUSupportedLimits::getMinStorageBufferOffsetAlignment(Napi::Env) {
return 256; return limits_.limits.minStorageBufferOffsetAlignment;
} }
uint32_t GPUSupportedLimits::getMaxVertexBuffers(Napi::Env) { uint32_t GPUSupportedLimits::getMaxVertexBuffers(Napi::Env) {
return 8; return limits_.limits.maxVertexBuffers;
} }
uint32_t GPUSupportedLimits::getMaxVertexAttributes(Napi::Env) { uint32_t GPUSupportedLimits::getMaxVertexAttributes(Napi::Env) {
return 16; return limits_.limits.maxVertexAttributes;
} }
uint32_t GPUSupportedLimits::getMaxVertexBufferArrayStride(Napi::Env) { uint32_t GPUSupportedLimits::getMaxVertexBufferArrayStride(Napi::Env) {
return 2048; return limits_.limits.maxVertexBufferArrayStride;
} }
uint32_t GPUSupportedLimits::getMaxInterStageShaderComponents(Napi::Env) { uint32_t GPUSupportedLimits::getMaxInterStageShaderComponents(Napi::Env) {
return 60; return limits_.limits.maxInterStageShaderComponents;
} }
uint32_t GPUSupportedLimits::getMaxComputeWorkgroupStorageSize(Napi::Env) { uint32_t GPUSupportedLimits::getMaxComputeWorkgroupStorageSize(Napi::Env) {
return 16352; return limits_.limits.maxComputeWorkgroupStorageSize;
} }
uint32_t GPUSupportedLimits::getMaxComputeInvocationsPerWorkgroup(Napi::Env) { uint32_t GPUSupportedLimits::getMaxComputeInvocationsPerWorkgroup(Napi::Env) {
return 256; return limits_.limits.maxComputeInvocationsPerWorkgroup;
} }
uint32_t GPUSupportedLimits::getMaxComputeWorkgroupSizeX(Napi::Env) { uint32_t GPUSupportedLimits::getMaxComputeWorkgroupSizeX(Napi::Env) {
return 256; return limits_.limits.maxComputeWorkgroupSizeX;
} }
uint32_t GPUSupportedLimits::getMaxComputeWorkgroupSizeY(Napi::Env) { uint32_t GPUSupportedLimits::getMaxComputeWorkgroupSizeY(Napi::Env) {
return 256; return limits_.limits.maxComputeWorkgroupSizeY;
} }
uint32_t GPUSupportedLimits::getMaxComputeWorkgroupSizeZ(Napi::Env) { uint32_t GPUSupportedLimits::getMaxComputeWorkgroupSizeZ(Napi::Env) {
return 64; return limits_.limits.maxComputeWorkgroupSizeZ;
} }
uint32_t GPUSupportedLimits::getMaxComputeWorkgroupsPerDimension(Napi::Env) { uint32_t GPUSupportedLimits::getMaxComputeWorkgroupsPerDimension(Napi::Env) {
return 65535; return limits_.limits.maxComputeWorkgroupsPerDimension;
} }
}} // namespace wgpu::binding }} // namespace wgpu::binding

View File

@ -25,6 +25,8 @@ namespace wgpu { namespace binding {
// GPUSupportedLimits is an implementation of interop::GPUSupportedLimits. // GPUSupportedLimits is an implementation of interop::GPUSupportedLimits.
class GPUSupportedLimits final : public interop::GPUSupportedLimits { class GPUSupportedLimits final : public interop::GPUSupportedLimits {
public: public:
GPUSupportedLimits(wgpu::SupportedLimits);
// interop::GPUSupportedLimits interface compliance // interop::GPUSupportedLimits interface compliance
uint32_t getMaxTextureDimension1D(Napi::Env) override; uint32_t getMaxTextureDimension1D(Napi::Env) override;
uint32_t getMaxTextureDimension2D(Napi::Env) override; uint32_t getMaxTextureDimension2D(Napi::Env) override;
@ -52,6 +54,9 @@ namespace wgpu { namespace binding {
uint32_t getMaxComputeWorkgroupSizeY(Napi::Env) override; uint32_t getMaxComputeWorkgroupSizeY(Napi::Env) override;
uint32_t getMaxComputeWorkgroupSizeZ(Napi::Env) override; uint32_t getMaxComputeWorkgroupSizeZ(Napi::Env) override;
uint32_t getMaxComputeWorkgroupsPerDimension(Napi::Env) override; uint32_t getMaxComputeWorkgroupsPerDimension(Napi::Env) override;
private:
wgpu::SupportedLimits limits_;
}; };
}} // namespace wgpu::binding }} // namespace wgpu::binding