Skip to content

Commit

Permalink
hal: limit binding sizes to i32
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Jan 6, 2022
1 parent eda3d4f commit 4bfa272
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions wgpu-hal/src/auxil/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ pub mod db {
}
}

/// Maximum binding size for the shaders that only support `i32` indexing.
/// Interestingly, the index itself can't reach that high, because the minimum
/// element size is 4 bytes, but the compiler toolchain still computes the
/// offset at some intermediate point, internally, as i32.
pub const MAX_I32_BINDING_SIZE: u32 = 1 << 31;

pub fn map_naga_stage(stage: naga::ShaderStage) -> wgt::ShaderStages {
match stage {
naga::ShaderStage::Vertex => wgt::ShaderStages::VERTEX,
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/dx12/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl super::Adapter {
max_uniform_buffers_per_shader_stage: full_heap_count,
max_uniform_buffer_binding_size: d3d12::D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT
* 16,
max_storage_buffer_binding_size: !0,
max_storage_buffer_binding_size: crate::auxil::MAX_I32_BINDING_SIZE,
max_vertex_buffers: d3d12::D3D12_VS_INPUT_REGISTER_COUNT
.min(crate::MAX_VERTEX_BUFFERS as u32),
max_vertex_attributes: d3d12::D3D12_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
Expand Down
8 changes: 6 additions & 2 deletions wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,12 @@ impl PhysicalDeviceCapabilities {
max_storage_buffers_per_shader_stage: max_storage_buffers,
max_storage_textures_per_shader_stage: max_storage_textures,
max_uniform_buffers_per_shader_stage: max_uniform_buffers,
max_uniform_buffer_binding_size: limits.max_uniform_buffer_range,
max_storage_buffer_binding_size: limits.max_storage_buffer_range,
max_uniform_buffer_binding_size: limits
.max_uniform_buffer_range
.min(crate::auxil::MAX_I32_BINDING_SIZE),
max_storage_buffer_binding_size: limits
.max_storage_buffer_range
.min(crate::auxil::MAX_I32_BINDING_SIZE),
max_vertex_buffers: limits
.max_vertex_input_bindings
.min(crate::MAX_VERTEX_BUFFERS as u32),
Expand Down

0 comments on commit 4bfa272

Please sign in to comment.