From 221884f03d90e5ae6d1e0c172c1f78392002ba6a Mon Sep 17 00:00:00 2001 From: Johann Muszynski Date: Sun, 7 Apr 2024 10:28:19 +0300 Subject: [PATCH] Increase GPU limits to unconstrain size of resources that can be used --- notes/storage_buffer_binding_size.md | 8 ++++++ src/pt/gpu_limits.hpp | 39 ++++++++++++++++++++++++++++ src/pt/main.cpp | 10 ++++--- src/pt/reference_path_tracer.cpp | 3 ++- src/pt/reference_path_tracer.hpp | 39 ---------------------------- 5 files changed, 55 insertions(+), 44 deletions(-) create mode 100644 src/pt/gpu_limits.hpp diff --git a/notes/storage_buffer_binding_size.md b/notes/storage_buffer_binding_size.md index 1f7fe3a..04b40b5 100644 --- a/notes/storage_buffer_binding_size.md +++ b/notes/storage_buffer_binding_size.md @@ -1,5 +1,13 @@ # `.maxStorageBufferBindingSize` +_Amended: 2024-04-07_ + +> Dawn's internal storage buffer limit is 256 MiB, or `1 << 28` bytes. + +The default max buffer size is 256 MiB. Increasing the max storage buffer binding size alone has not effect, as it is constrained by the max buffer size. Setting `maxBufferSize` > $2^{28}$ bytes unconstrains the storage buffer limit again. At the time of writing, the `maxBufferSize` was 10 GiB on both macOS and Windows. + +The storage buffer binding size limit is the one which validation triggers when creating buffers larger than the limit, hence the initial focus on this particular value. + _Written: 2023-11-10_ _Context: when doing texture lookup on the GPU for the first time, it was observed that a single texture buffer can exceed Dawn's internal storage buffer size limit._ diff --git a/src/pt/gpu_limits.hpp b/src/pt/gpu_limits.hpp new file mode 100644 index 0000000..9a113f3 --- /dev/null +++ b/src/pt/gpu_limits.hpp @@ -0,0 +1,39 @@ +#pragma once + +namespace nlrs +{ +constexpr WGPULimits REQUIRED_LIMITS{ + .maxTextureDimension1D = 0, + .maxTextureDimension2D = 0, + .maxTextureDimension3D = 0, + .maxTextureArrayLayers = 0, + .maxBindGroups = 4, + .maxBindGroupsPlusVertexBuffers = 0, + .maxBindingsPerBindGroup = 8, + .maxDynamicUniformBuffersPerPipelineLayout = 0, + .maxDynamicStorageBuffersPerPipelineLayout = 0, + .maxSampledTexturesPerShaderStage = 0, + .maxSamplersPerShaderStage = 0, + .maxStorageBuffersPerShaderStage = 8, + .maxStorageTexturesPerShaderStage = 0, + .maxUniformBuffersPerShaderStage = 1, + .maxUniformBufferBindingSize = 1 << 10, + .maxStorageBufferBindingSize = 1 << 30, + .minUniformBufferOffsetAlignment = 256, + .minStorageBufferOffsetAlignment = 256, + .maxVertexBuffers = 4, + .maxBufferSize = 1 << 30, + .maxVertexAttributes = 8, + .maxVertexBufferArrayStride = sizeof(float[4]), + .maxInterStageShaderComponents = 0, + .maxInterStageShaderVariables = 0, + .maxColorAttachments = 4, + .maxColorAttachmentBytesPerSample = 0, + .maxComputeWorkgroupStorageSize = 0, + .maxComputeInvocationsPerWorkgroup = 0, + .maxComputeWorkgroupSizeX = 0, + .maxComputeWorkgroupSizeY = 0, + .maxComputeWorkgroupSizeZ = 0, + .maxComputeWorkgroupsPerDimension = 0, +}; +} diff --git a/src/pt/main.cpp b/src/pt/main.cpp index ae8ff75..eb15467 100644 --- a/src/pt/main.cpp +++ b/src/pt/main.cpp @@ -1,5 +1,6 @@ #include "fly_camera_controller.hpp" #include "gpu_context.hpp" +#include "gpu_limits.hpp" #include "gui.hpp" #include "deferred_renderer.hpp" #include "reference_path_tracer.hpp" @@ -112,11 +113,12 @@ try return 0; } - nlrs::GpuContext gpuContext{nlrs::ReferencePathTracer::wgpuRequiredLimits}; - nlrs::Window window = [&gpuContext]() -> nlrs::Window { + nlrs::GpuContext gpuContext{ + WGPURequiredLimits{.nextInChain = nullptr, .limits = nlrs::REQUIRED_LIMITS}}; + nlrs::Window window = [&gpuContext]() -> nlrs::Window { const nlrs::WindowDescriptor windowDesc{ - .windowSize = nlrs::Extent2i{defaultWindowWidth, defaultWindowHeight}, - .title = "pt-playground 🛝", + .windowSize = nlrs::Extent2i{defaultWindowWidth, defaultWindowHeight}, + .title = "pt-playground 🛝", }; return nlrs::Window{windowDesc, gpuContext}; }(); diff --git a/src/pt/reference_path_tracer.cpp b/src/pt/reference_path_tracer.cpp index 7493b8e..7831f09 100644 --- a/src/pt/reference_path_tracer.cpp +++ b/src/pt/reference_path_tracer.cpp @@ -1,5 +1,6 @@ #include "gpu_bind_group_layout.hpp" #include "gpu_context.hpp" +#include "gpu_limits.hpp" #include "reference_path_tracer.hpp" #include "shader_source.hpp" #include "webgpu_utils.hpp" @@ -231,7 +232,7 @@ ReferencePathTracer::ReferencePathTracer( const std::size_t textureDataNumBytes = textureData.size() * sizeof(Texture::BgraPixel); const std::size_t maxStorageBufferBindingSize = - static_cast(wgpuRequiredLimits.limits.maxStorageBufferBindingSize); + static_cast(REQUIRED_LIMITS.maxStorageBufferBindingSize); if (textureDataNumBytes > maxStorageBufferBindingSize) { throw std::runtime_error(fmt::format( diff --git a/src/pt/reference_path_tracer.hpp b/src/pt/reference_path_tracer.hpp index f82408b..a9e4f63 100644 --- a/src/pt/reference_path_tracer.hpp +++ b/src/pt/reference_path_tracer.hpp @@ -74,45 +74,6 @@ class ReferencePathTracer float averageRenderpassDurationMs() const; float renderProgressPercentage() const; - static constexpr WGPURequiredLimits wgpuRequiredLimits{ - .nextInChain = nullptr, - .limits = - WGPULimits{ - .maxTextureDimension1D = 0, - .maxTextureDimension2D = 0, - .maxTextureDimension3D = 0, - .maxTextureArrayLayers = 0, - .maxBindGroups = 2, - .maxBindGroupsPlusVertexBuffers = 0, - .maxBindingsPerBindGroup = 7, - .maxDynamicUniformBuffersPerPipelineLayout = 0, - .maxDynamicStorageBuffersPerPipelineLayout = 0, - .maxSampledTexturesPerShaderStage = 0, - .maxSamplersPerShaderStage = 0, - .maxStorageBuffersPerShaderStage = 6, - .maxStorageTexturesPerShaderStage = 0, - .maxUniformBuffersPerShaderStage = 1, - .maxUniformBufferBindingSize = 80, - .maxStorageBufferBindingSize = 1 << 28, // 256 MiB - .minUniformBufferOffsetAlignment = 256, - .minStorageBufferOffsetAlignment = 256, - .maxVertexBuffers = 1, - .maxBufferSize = 0, - .maxVertexAttributes = 2, - .maxVertexBufferArrayStride = 2 * sizeof(float), - .maxInterStageShaderComponents = 0, - .maxInterStageShaderVariables = 0, - .maxColorAttachments = 0, - .maxColorAttachmentBytesPerSample = 0, - .maxComputeWorkgroupStorageSize = 0, - .maxComputeInvocationsPerWorkgroup = 0, - .maxComputeWorkgroupSizeX = 0, - .maxComputeWorkgroupSizeY = 0, - .maxComputeWorkgroupSizeZ = 0, - .maxComputeWorkgroupsPerDimension = 0, - }, - }; - private: GpuBuffer mVertexBuffer; GpuBuffer mRenderParamsBuffer;