Skip to content

Commit 221884f

Browse files
committed
Increase GPU limits to unconstrain size of resources that can be used
1 parent 4389072 commit 221884f

File tree

5 files changed

+55
-44
lines changed

5 files changed

+55
-44
lines changed

notes/storage_buffer_binding_size.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# `.maxStorageBufferBindingSize`
22

3+
_Amended: 2024-04-07_
4+
5+
> Dawn's internal storage buffer limit is 256 MiB, or `1 << 28` bytes.
6+
7+
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.
8+
9+
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.
10+
311
_Written: 2023-11-10_
412

513
_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._

src/pt/gpu_limits.hpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
3+
namespace nlrs
4+
{
5+
constexpr WGPULimits REQUIRED_LIMITS{
6+
.maxTextureDimension1D = 0,
7+
.maxTextureDimension2D = 0,
8+
.maxTextureDimension3D = 0,
9+
.maxTextureArrayLayers = 0,
10+
.maxBindGroups = 4,
11+
.maxBindGroupsPlusVertexBuffers = 0,
12+
.maxBindingsPerBindGroup = 8,
13+
.maxDynamicUniformBuffersPerPipelineLayout = 0,
14+
.maxDynamicStorageBuffersPerPipelineLayout = 0,
15+
.maxSampledTexturesPerShaderStage = 0,
16+
.maxSamplersPerShaderStage = 0,
17+
.maxStorageBuffersPerShaderStage = 8,
18+
.maxStorageTexturesPerShaderStage = 0,
19+
.maxUniformBuffersPerShaderStage = 1,
20+
.maxUniformBufferBindingSize = 1 << 10,
21+
.maxStorageBufferBindingSize = 1 << 30,
22+
.minUniformBufferOffsetAlignment = 256,
23+
.minStorageBufferOffsetAlignment = 256,
24+
.maxVertexBuffers = 4,
25+
.maxBufferSize = 1 << 30,
26+
.maxVertexAttributes = 8,
27+
.maxVertexBufferArrayStride = sizeof(float[4]),
28+
.maxInterStageShaderComponents = 0,
29+
.maxInterStageShaderVariables = 0,
30+
.maxColorAttachments = 4,
31+
.maxColorAttachmentBytesPerSample = 0,
32+
.maxComputeWorkgroupStorageSize = 0,
33+
.maxComputeInvocationsPerWorkgroup = 0,
34+
.maxComputeWorkgroupSizeX = 0,
35+
.maxComputeWorkgroupSizeY = 0,
36+
.maxComputeWorkgroupSizeZ = 0,
37+
.maxComputeWorkgroupsPerDimension = 0,
38+
};
39+
}

src/pt/main.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "fly_camera_controller.hpp"
22
#include "gpu_context.hpp"
3+
#include "gpu_limits.hpp"
34
#include "gui.hpp"
45
#include "deferred_renderer.hpp"
56
#include "reference_path_tracer.hpp"
@@ -112,11 +113,12 @@ try
112113
return 0;
113114
}
114115

115-
nlrs::GpuContext gpuContext{nlrs::ReferencePathTracer::wgpuRequiredLimits};
116-
nlrs::Window window = [&gpuContext]() -> nlrs::Window {
116+
nlrs::GpuContext gpuContext{
117+
WGPURequiredLimits{.nextInChain = nullptr, .limits = nlrs::REQUIRED_LIMITS}};
118+
nlrs::Window window = [&gpuContext]() -> nlrs::Window {
117119
const nlrs::WindowDescriptor windowDesc{
118-
.windowSize = nlrs::Extent2i{defaultWindowWidth, defaultWindowHeight},
119-
.title = "pt-playground 🛝",
120+
.windowSize = nlrs::Extent2i{defaultWindowWidth, defaultWindowHeight},
121+
.title = "pt-playground 🛝",
120122
};
121123
return nlrs::Window{windowDesc, gpuContext};
122124
}();

src/pt/reference_path_tracer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "gpu_bind_group_layout.hpp"
22
#include "gpu_context.hpp"
3+
#include "gpu_limits.hpp"
34
#include "reference_path_tracer.hpp"
45
#include "shader_source.hpp"
56
#include "webgpu_utils.hpp"
@@ -231,7 +232,7 @@ ReferencePathTracer::ReferencePathTracer(
231232

232233
const std::size_t textureDataNumBytes = textureData.size() * sizeof(Texture::BgraPixel);
233234
const std::size_t maxStorageBufferBindingSize =
234-
static_cast<std::size_t>(wgpuRequiredLimits.limits.maxStorageBufferBindingSize);
235+
static_cast<std::size_t>(REQUIRED_LIMITS.maxStorageBufferBindingSize);
235236
if (textureDataNumBytes > maxStorageBufferBindingSize)
236237
{
237238
throw std::runtime_error(fmt::format(

src/pt/reference_path_tracer.hpp

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -74,45 +74,6 @@ class ReferencePathTracer
7474
float averageRenderpassDurationMs() const;
7575
float renderProgressPercentage() const;
7676

77-
static constexpr WGPURequiredLimits wgpuRequiredLimits{
78-
.nextInChain = nullptr,
79-
.limits =
80-
WGPULimits{
81-
.maxTextureDimension1D = 0,
82-
.maxTextureDimension2D = 0,
83-
.maxTextureDimension3D = 0,
84-
.maxTextureArrayLayers = 0,
85-
.maxBindGroups = 2,
86-
.maxBindGroupsPlusVertexBuffers = 0,
87-
.maxBindingsPerBindGroup = 7,
88-
.maxDynamicUniformBuffersPerPipelineLayout = 0,
89-
.maxDynamicStorageBuffersPerPipelineLayout = 0,
90-
.maxSampledTexturesPerShaderStage = 0,
91-
.maxSamplersPerShaderStage = 0,
92-
.maxStorageBuffersPerShaderStage = 6,
93-
.maxStorageTexturesPerShaderStage = 0,
94-
.maxUniformBuffersPerShaderStage = 1,
95-
.maxUniformBufferBindingSize = 80,
96-
.maxStorageBufferBindingSize = 1 << 28, // 256 MiB
97-
.minUniformBufferOffsetAlignment = 256,
98-
.minStorageBufferOffsetAlignment = 256,
99-
.maxVertexBuffers = 1,
100-
.maxBufferSize = 0,
101-
.maxVertexAttributes = 2,
102-
.maxVertexBufferArrayStride = 2 * sizeof(float),
103-
.maxInterStageShaderComponents = 0,
104-
.maxInterStageShaderVariables = 0,
105-
.maxColorAttachments = 0,
106-
.maxColorAttachmentBytesPerSample = 0,
107-
.maxComputeWorkgroupStorageSize = 0,
108-
.maxComputeInvocationsPerWorkgroup = 0,
109-
.maxComputeWorkgroupSizeX = 0,
110-
.maxComputeWorkgroupSizeY = 0,
111-
.maxComputeWorkgroupSizeZ = 0,
112-
.maxComputeWorkgroupsPerDimension = 0,
113-
},
114-
};
115-
11677
private:
11778
GpuBuffer mVertexBuffer;
11879
GpuBuffer mRenderParamsBuffer;

0 commit comments

Comments
 (0)