mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-20 22:41:07 +01:00
[vk] lower relevant per stage limits to stay under Vulkan's
`maxPerStageResources` limit Fixes #9151.
This commit is contained in:
1 parent
085fd3c565
commit
3f90204744
2 files changed
+77
-25
No files matched your search
@@ -185,3 +185,43 @@ pub(crate) fn apply_hal_limits(mut limits: wgt::Limits) -> wgt::Limits {
|
||||
|
||||
limits
|
||||
}
|
||||
|
||||
/// Evenly allocates space to each limit,
|
||||
/// capping them only if strictly necessary.
|
||||
pub fn cap_limits_to_be_under_the_sum_limit<const N: usize>(
|
||||
mut limits: [&mut u32; N],
|
||||
sum_limit: u32,
|
||||
) {
|
||||
limits.sort();
|
||||
|
||||
let mut rem_limit = sum_limit;
|
||||
let mut divisor = limits.len() as u32;
|
||||
for limit_to_adjust in limits {
|
||||
let limit = rem_limit / divisor;
|
||||
*limit_to_adjust = (*limit_to_adjust).min(limit);
|
||||
rem_limit -= *limit_to_adjust;
|
||||
divisor -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_cap_limits_to_be_under_the_sum_limit() {
|
||||
test([3, 3, 3], 3, [1, 1, 1]);
|
||||
test([3, 2, 1], 3, [1, 1, 1]);
|
||||
test([1, 2, 3], 6, [1, 2, 3]);
|
||||
test([1, 2, 3], 3, [1, 1, 1]);
|
||||
test([1, 8, 100], 6, [1, 2, 3]);
|
||||
test([2, 80, 80], 6, [2, 2, 2]);
|
||||
test([2, 80, 80], 12, [2, 5, 5]);
|
||||
|
||||
#[track_caller]
|
||||
fn test<const N: usize>(mut input: [u32; N], limit: u32, output: [u32; N]) {
|
||||
cap_limits_to_be_under_the_sum_limit(input.each_mut(), limit);
|
||||
assert_eq!(input, output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1478,31 +1478,43 @@ impl PhysicalDeviceProperties {
|
||||
]
|
||||
.contains(&self.properties.vendor_id);
|
||||
|
||||
if !ignore_max_fragment_combined_output_resources
|
||||
&& max_storage_textures_per_shader_stage
|
||||
+ max_storage_buffers_per_shader_stage
|
||||
+ max_color_attachments
|
||||
> limits.max_fragment_combined_output_resources
|
||||
{
|
||||
// Divide the limit equally between the 3 limits while allowing
|
||||
// unused limit capacity to be used by some limits that
|
||||
// can make use of it.
|
||||
let mut rem_limit = limits.max_fragment_combined_output_resources;
|
||||
let limit = rem_limit / 3;
|
||||
let diff = limit.saturating_sub(max_storage_textures_per_shader_stage);
|
||||
max_storage_textures_per_shader_stage =
|
||||
max_storage_textures_per_shader_stage.min(limit);
|
||||
|
||||
rem_limit -= limit + diff;
|
||||
let limit = rem_limit / 2;
|
||||
let diff = limit.saturating_sub(max_storage_buffers_per_shader_stage);
|
||||
max_storage_buffers_per_shader_stage = max_storage_buffers_per_shader_stage.min(limit);
|
||||
|
||||
rem_limit -= limit + diff;
|
||||
let limit = rem_limit;
|
||||
max_color_attachments = max_color_attachments.min(limit);
|
||||
if !ignore_max_fragment_combined_output_resources {
|
||||
crate::auxil::cap_limits_to_be_under_the_sum_limit(
|
||||
[
|
||||
&mut max_storage_textures_per_shader_stage,
|
||||
&mut max_storage_buffers_per_shader_stage,
|
||||
&mut max_color_attachments,
|
||||
],
|
||||
limits.max_fragment_combined_output_resources,
|
||||
);
|
||||
}
|
||||
|
||||
// When summed, the 5 limits below must be under Vulkan's maxPerStageResources.
|
||||
//
|
||||
// - maxUniformBuffersPerShaderStage, WebGPU default: 12
|
||||
// - maxSampledTexturesPerShaderStage, WebGPU default: 16
|
||||
// - maxStorageTexturesPerShaderStage, WebGPU default: 4
|
||||
// - maxStorageBuffersPerShaderStage, WebGPU default: 8
|
||||
// - maxColorAttachments, WebGPU default: 8
|
||||
//
|
||||
// Note: Vulkan's texel buffers and input attachments also count towards
|
||||
// maxPerStageResources but we don't make use of them.
|
||||
let mut max_sampled_textures_per_shader_stage =
|
||||
limits.max_per_stage_descriptor_sampled_images;
|
||||
let mut max_uniform_buffers_per_shader_stage =
|
||||
limits.max_per_stage_descriptor_uniform_buffers;
|
||||
|
||||
crate::auxil::cap_limits_to_be_under_the_sum_limit(
|
||||
[
|
||||
&mut max_sampled_textures_per_shader_stage,
|
||||
&mut max_uniform_buffers_per_shader_stage,
|
||||
&mut max_storage_textures_per_shader_stage,
|
||||
&mut max_storage_buffers_per_shader_stage,
|
||||
&mut max_color_attachments,
|
||||
],
|
||||
limits.max_per_stage_resources,
|
||||
);
|
||||
|
||||
// TODO: programmatically determine this, if possible. It's unclear whether we can
|
||||
// as of https://github.com/gpuweb/gpuweb/issues/2965#issuecomment-1361315447.
|
||||
//
|
||||
@@ -1552,10 +1564,10 @@ impl PhysicalDeviceProperties {
|
||||
max_dynamic_storage_buffers_per_pipeline_layout: limits
|
||||
.max_descriptor_set_storage_buffers_dynamic,
|
||||
max_samplers_per_shader_stage: limits.max_per_stage_descriptor_samplers,
|
||||
max_sampled_textures_per_shader_stage: limits.max_per_stage_descriptor_sampled_images,
|
||||
max_sampled_textures_per_shader_stage,
|
||||
max_storage_textures_per_shader_stage,
|
||||
max_storage_buffers_per_shader_stage,
|
||||
max_uniform_buffers_per_shader_stage: limits.max_per_stage_descriptor_uniform_buffers,
|
||||
max_uniform_buffers_per_shader_stage,
|
||||
max_vertex_buffers: limits.max_vertex_input_bindings,
|
||||
max_buffer_size,
|
||||
max_uniform_buffer_binding_size: limits
|
||||
|
||||
Reference in new issue
Block a user