webgpu: Use wgpu's instead of string errors and update limits handling (#32925)

* Use wgpu specific errors

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* fixup expect

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* WIP

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* Fix records erasing enforcerange

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* page can already be destroyed

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* Support more limits

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* Set good results

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* Set OK (not PASS) expect CRASH

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* fixup expectation

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* bad expectations

https://github.com/gfx-rs/wgpu/issues/6075
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* set bad expectation

render bundleencoder needs to be rewritten

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
Samson 2024-08-04 19:19:46 +02:00 committed by GitHub
parent b366a02318
commit 5e59988c87
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 496 additions and 871 deletions

View file

@ -3,6 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use dom_struct::dom_struct;
use num_traits::bounds::UpperBounded;
use webgpu::wgt::Limits;
use GPUSupportedLimits_Binding::GPUSupportedLimitsMethods;
@ -173,4 +174,144 @@ impl GPUSupportedLimitsMethods for GPUSupportedLimits {
fn MaxComputeWorkgroupsPerDimension(&self) -> u32 {
self.limits.max_compute_workgroups_per_dimension
}
/// <https://gpuweb.github.io/gpuweb/#dom-gpusupportedlimits-maxbindgroupsplusvertexbuffers>
fn MaxBindGroupsPlusVertexBuffers(&self) -> u32 {
// Not on wgpu yet, so we craft it manually
self.limits.max_bind_groups + self.limits.max_vertex_buffers
}
/// <https://gpuweb.github.io/gpuweb/#dom-gpusupportedlimits-maxinterstageshadervariables>
fn MaxInterStageShaderVariables(&self) -> u32 {
// Not in wgpu yet, so we use default value from spec
16
}
/// <https://gpuweb.github.io/gpuweb/#dom-gpusupportedlimits-maxcolorattachments>
fn MaxColorAttachments(&self) -> u32 {
self.limits.max_color_attachments
}
/// <https://gpuweb.github.io/gpuweb/#dom-gpusupportedlimits-maxcolorattachmentbytespersample>
fn MaxColorAttachmentBytesPerSample(&self) -> u32 {
self.limits.max_color_attachment_bytes_per_sample
}
}
/// Returns false if unknown limit or other value error
pub fn set_limit(limits: &mut Limits, limit: &str, value: u64) -> bool {
/// per spec defaults are lower bounds for values
///
/// https://www.w3.org/TR/webgpu/#limit-class-maximum
fn set_maximum<T>(limit: &mut T, value: u64) -> bool
where
T: Ord + Copy + TryFrom<u64> + UpperBounded,
{
if let Ok(value) = T::try_from(value) {
*limit = value.max(*limit);
true
} else {
false
}
}
/// per spec defaults are higher bounds for values
///
/// <https://www.w3.org/TR/webgpu/#limit-class-alignment>
fn set_alignment<T>(limit: &mut T, value: u64) -> bool
where
T: Ord + Copy + TryFrom<u64> + UpperBounded,
{
if !value.is_power_of_two() {
return false;
}
if let Ok(value) = T::try_from(value) {
*limit = value.min(*limit);
true
} else {
false
}
}
match limit {
"maxTextureDimension1D" => set_maximum(&mut limits.max_texture_dimension_1d, value),
"maxTextureDimension2D" => set_maximum(&mut limits.max_texture_dimension_2d, value),
"maxTextureDimension3D" => set_maximum(&mut limits.max_texture_dimension_3d, value),
"maxTextureArrayLayers" => set_maximum(&mut limits.max_texture_array_layers, value),
"maxBindGroups" => set_maximum(&mut limits.max_bind_groups, value),
"maxBindGroupsPlusVertexBuffers" => {
// not in wgpu but we're allowed to give back better limits than requested.
// we use dummy value to still produce value verification
let mut v: u32 = 0;
set_maximum(&mut v, value)
},
"maxBindingsPerBindGroup" => set_maximum(&mut limits.max_bindings_per_bind_group, value),
"maxDynamicUniformBuffersPerPipelineLayout" => set_maximum(
&mut limits.max_dynamic_uniform_buffers_per_pipeline_layout,
value,
),
"maxDynamicStorageBuffersPerPipelineLayout" => set_maximum(
&mut limits.max_dynamic_storage_buffers_per_pipeline_layout,
value,
),
"maxSampledTexturesPerShaderStage" => {
set_maximum(&mut limits.max_sampled_textures_per_shader_stage, value)
},
"maxSamplersPerShaderStage" => {
set_maximum(&mut limits.max_samplers_per_shader_stage, value)
},
"maxStorageBuffersPerShaderStage" => {
set_maximum(&mut limits.max_storage_buffers_per_shader_stage, value)
},
"maxStorageTexturesPerShaderStage" => {
set_maximum(&mut limits.max_storage_textures_per_shader_stage, value)
},
"maxUniformBuffersPerShaderStage" => {
set_maximum(&mut limits.max_uniform_buffers_per_shader_stage, value)
},
"maxUniformBufferBindingSize" => {
set_maximum(&mut limits.max_uniform_buffer_binding_size, value)
},
"maxStorageBufferBindingSize" => {
set_maximum(&mut limits.max_storage_buffer_binding_size, value)
},
"minUniformBufferOffsetAlignment" => {
set_alignment(&mut limits.min_uniform_buffer_offset_alignment, value)
},
"minStorageBufferOffsetAlignment" => {
set_alignment(&mut limits.min_storage_buffer_offset_alignment, value)
},
"maxVertexBuffers" => set_maximum(&mut limits.max_vertex_buffers, value),
"maxBufferSize" => set_maximum(&mut limits.max_buffer_size, value),
"maxVertexAttributes" => set_maximum(&mut limits.max_vertex_attributes, value),
"maxVertexBufferArrayStride" => {
set_maximum(&mut limits.max_vertex_buffer_array_stride, value)
},
"maxInterStageShaderComponents" => {
set_maximum(&mut limits.max_inter_stage_shader_components, value)
},
"maxInterStageShaderVariables" => {
// not in wgpu but we're allowed to give back better limits than requested.
// we use dummy value to still produce value verification
let mut v: u32 = 0;
set_maximum(&mut v, value)
},
"maxColorAttachments" => set_maximum(&mut limits.max_color_attachments, value),
"maxColorAttachmentBytesPerSample" => {
set_maximum(&mut limits.max_color_attachment_bytes_per_sample, value)
},
"maxComputeWorkgroupStorageSize" => {
set_maximum(&mut limits.max_compute_workgroup_storage_size, value)
},
"maxComputeInvocationsPerWorkgroup" => {
set_maximum(&mut limits.max_compute_invocations_per_workgroup, value)
},
"maxComputeWorkgroupSizeX" => set_maximum(&mut limits.max_compute_workgroup_size_x, value),
"maxComputeWorkgroupSizeY" => set_maximum(&mut limits.max_compute_workgroup_size_y, value),
"maxComputeWorkgroupSizeZ" => set_maximum(&mut limits.max_compute_workgroup_size_z, value),
"maxComputeWorkgroupsPerDimension" => {
set_maximum(&mut limits.max_compute_workgroups_per_dimension, value)
},
_ => false,
}
}