1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "SupportedLimits.h"
8 #include "mozilla/dom/WebGPUBinding.h"
10 namespace mozilla::webgpu
{
12 GPU_IMPL_CYCLE_COLLECTION(SupportedLimits
, mParent
)
13 GPU_IMPL_JS_WRAP(SupportedLimits
)
15 SupportedLimits::SupportedLimits(Adapter
* const aParent
,
16 const ffi::WGPULimits
& aLimits
)
17 : ChildOf(aParent
), mFfi(std::make_unique
<ffi::WGPULimits
>(aLimits
)) {}
19 SupportedLimits::~SupportedLimits() = default;
21 uint64_t GetLimit(const ffi::WGPULimits
& limits
, const Limit limit
) {
23 case Limit::MaxTextureDimension1D
:
24 return limits
.max_texture_dimension_1d
;
25 case Limit::MaxTextureDimension2D
:
26 return limits
.max_texture_dimension_2d
;
27 case Limit::MaxTextureDimension3D
:
28 return limits
.max_texture_dimension_3d
;
29 case Limit::MaxTextureArrayLayers
:
30 return limits
.max_texture_array_layers
;
31 case Limit::MaxBindGroups
:
32 return limits
.max_bind_groups
;
33 case Limit::MaxBindGroupsPlusVertexBuffers
:
34 // Not in ffi::WGPULimits, so synthesize:
35 return GetLimit(limits
, Limit::MaxBindGroups
) +
36 GetLimit(limits
, Limit::MaxVertexBuffers
);
37 case Limit::MaxBindingsPerBindGroup
:
38 return limits
.max_bindings_per_bind_group
;
39 case Limit::MaxDynamicUniformBuffersPerPipelineLayout
:
40 return limits
.max_dynamic_uniform_buffers_per_pipeline_layout
;
41 case Limit::MaxDynamicStorageBuffersPerPipelineLayout
:
42 return limits
.max_dynamic_storage_buffers_per_pipeline_layout
;
43 case Limit::MaxSampledTexturesPerShaderStage
:
44 return limits
.max_sampled_textures_per_shader_stage
;
45 case Limit::MaxSamplersPerShaderStage
:
46 return limits
.max_samplers_per_shader_stage
;
47 case Limit::MaxStorageBuffersPerShaderStage
:
48 return limits
.max_storage_buffers_per_shader_stage
;
49 case Limit::MaxStorageTexturesPerShaderStage
:
50 return limits
.max_storage_textures_per_shader_stage
;
51 case Limit::MaxUniformBuffersPerShaderStage
:
52 return limits
.max_uniform_buffers_per_shader_stage
;
53 case Limit::MaxUniformBufferBindingSize
:
54 return limits
.max_uniform_buffer_binding_size
;
55 case Limit::MaxStorageBufferBindingSize
:
56 return limits
.max_storage_buffer_binding_size
;
57 case Limit::MinUniformBufferOffsetAlignment
:
58 return limits
.min_uniform_buffer_offset_alignment
;
59 case Limit::MinStorageBufferOffsetAlignment
:
60 return limits
.min_storage_buffer_offset_alignment
;
61 case Limit::MaxVertexBuffers
:
62 return limits
.max_vertex_buffers
;
63 case Limit::MaxBufferSize
:
64 return limits
.max_buffer_size
;
65 case Limit::MaxVertexAttributes
:
66 return limits
.max_vertex_attributes
;
67 case Limit::MaxVertexBufferArrayStride
:
68 return limits
.max_vertex_buffer_array_stride
;
69 case Limit::MaxInterStageShaderComponents
:
70 return limits
.max_inter_stage_shader_components
;
71 case Limit::MaxInterStageShaderVariables
:
72 return 16; // From the spec. (not in ffi::WGPULimits)
73 case Limit::MaxColorAttachments
:
74 return 8; // From the spec. (not in ffi::WGPULimits)
75 case Limit::MaxColorAttachmentBytesPerSample
:
76 return 32; // From the spec. (not in ffi::WGPULimits)
77 case Limit::MaxComputeWorkgroupStorageSize
:
78 return limits
.max_compute_workgroup_storage_size
;
79 case Limit::MaxComputeInvocationsPerWorkgroup
:
80 return limits
.max_compute_invocations_per_workgroup
;
81 case Limit::MaxComputeWorkgroupSizeX
:
82 return limits
.max_compute_workgroup_size_x
;
83 case Limit::MaxComputeWorkgroupSizeY
:
84 return limits
.max_compute_workgroup_size_y
;
85 case Limit::MaxComputeWorkgroupSizeZ
:
86 return limits
.max_compute_workgroup_size_z
;
87 case Limit::MaxComputeWorkgroupsPerDimension
:
88 return limits
.max_compute_workgroups_per_dimension
;
90 MOZ_CRASH("Bad Limit");
93 void SetLimit(ffi::WGPULimits
* const limits
, const Limit limit
,
95 const auto autoVal
= LazyAssertedCast(static_cast<uint64_t>(val
));
97 case Limit::MaxTextureDimension1D
:
98 limits
->max_texture_dimension_1d
= autoVal
;
100 case Limit::MaxTextureDimension2D
:
101 limits
->max_texture_dimension_2d
= autoVal
;
103 case Limit::MaxTextureDimension3D
:
104 limits
->max_texture_dimension_3d
= autoVal
;
106 case Limit::MaxTextureArrayLayers
:
107 limits
->max_texture_array_layers
= autoVal
;
109 case Limit::MaxBindGroups
:
110 limits
->max_bind_groups
= autoVal
;
112 case Limit::MaxBindGroupsPlusVertexBuffers
:
113 // Not in ffi::WGPULimits, and we're allowed to give back better
114 // limits than requested.
116 case Limit::MaxBindingsPerBindGroup
:
117 limits
->max_bindings_per_bind_group
= autoVal
;
119 case Limit::MaxDynamicUniformBuffersPerPipelineLayout
:
120 limits
->max_dynamic_uniform_buffers_per_pipeline_layout
= autoVal
;
122 case Limit::MaxDynamicStorageBuffersPerPipelineLayout
:
123 limits
->max_dynamic_storage_buffers_per_pipeline_layout
= autoVal
;
125 case Limit::MaxSampledTexturesPerShaderStage
:
126 limits
->max_sampled_textures_per_shader_stage
= autoVal
;
128 case Limit::MaxSamplersPerShaderStage
:
129 limits
->max_samplers_per_shader_stage
= autoVal
;
131 case Limit::MaxStorageBuffersPerShaderStage
:
132 limits
->max_storage_buffers_per_shader_stage
= autoVal
;
134 case Limit::MaxStorageTexturesPerShaderStage
:
135 limits
->max_storage_textures_per_shader_stage
= autoVal
;
137 case Limit::MaxUniformBuffersPerShaderStage
:
138 limits
->max_uniform_buffers_per_shader_stage
= autoVal
;
140 case Limit::MaxUniformBufferBindingSize
:
141 limits
->max_uniform_buffer_binding_size
= autoVal
;
143 case Limit::MaxStorageBufferBindingSize
:
144 limits
->max_storage_buffer_binding_size
= autoVal
;
146 case Limit::MinUniformBufferOffsetAlignment
:
147 limits
->min_uniform_buffer_offset_alignment
= autoVal
;
149 case Limit::MinStorageBufferOffsetAlignment
:
150 limits
->min_storage_buffer_offset_alignment
= autoVal
;
152 case Limit::MaxVertexBuffers
:
153 limits
->max_vertex_buffers
= autoVal
;
155 case Limit::MaxBufferSize
:
156 limits
->max_buffer_size
= autoVal
;
158 case Limit::MaxVertexAttributes
:
159 limits
->max_vertex_attributes
= autoVal
;
161 case Limit::MaxVertexBufferArrayStride
:
162 limits
->max_vertex_buffer_array_stride
= autoVal
;
164 case Limit::MaxInterStageShaderComponents
:
165 limits
->max_inter_stage_shader_components
= autoVal
;
167 case Limit::MaxInterStageShaderVariables
:
168 // Not in ffi::WGPULimits, and we're allowed to give back better
169 // limits than requested.
171 case Limit::MaxColorAttachments
:
172 // Not in ffi::WGPULimits, and we're allowed to give back better
173 // limits than requested.
175 case Limit::MaxColorAttachmentBytesPerSample
:
176 // Not in ffi::WGPULimits, and we're allowed to give back better
177 // limits than requested.
179 case Limit::MaxComputeWorkgroupStorageSize
:
180 limits
->max_compute_workgroup_storage_size
= autoVal
;
182 case Limit::MaxComputeInvocationsPerWorkgroup
:
183 limits
->max_compute_invocations_per_workgroup
= autoVal
;
185 case Limit::MaxComputeWorkgroupSizeX
:
186 limits
->max_compute_workgroup_size_x
= autoVal
;
188 case Limit::MaxComputeWorkgroupSizeY
:
189 limits
->max_compute_workgroup_size_y
= autoVal
;
191 case Limit::MaxComputeWorkgroupSizeZ
:
192 limits
->max_compute_workgroup_size_z
= autoVal
;
194 case Limit::MaxComputeWorkgroupsPerDimension
:
195 limits
->max_compute_workgroups_per_dimension
= autoVal
;
198 MOZ_CRASH("Bad Limit");
201 } // namespace mozilla::webgpu