Skip to content

Commit e6314c4

Browse files
authored
DX12 increase max_storage_buffers_per_shader_stage and max_storage_textures_per_shader_stage (#3798)
1 parent 307f7ac commit e6314c4

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ Bottom level categories:
4646

4747
- Change `AdapterInfo::{device,vendor}` to be `u32` instead of `usize`. By @ameknite in [#3760](https://github.com/gfx-rs/wgpu/pull/3760)
4848

49+
#### DX12
50+
51+
- Increase the `max_storage_buffers_per_shader_stage` and `max_storage_textures_per_shader_stage` limits based on what the hardware supports. by @Elabajaba in [#3798]https://github.com/gfx-rs/wgpu/pull/3798
52+
4953
### Documentation
5054

5155
#### General

wgpu-hal/src/dx12/adapter.rs

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,29 @@ impl super::Adapter {
7474

7575
profiling::scope!("feature queries");
7676

77+
// Detect the highest supported feature level.
78+
let d3d_feature_level = [
79+
d3d12::FeatureLevel::L12_1,
80+
d3d12::FeatureLevel::L12_0,
81+
d3d12::FeatureLevel::L11_1,
82+
d3d12::FeatureLevel::L11_0,
83+
];
84+
let mut device_levels: d3d12_ty::D3D12_FEATURE_DATA_FEATURE_LEVELS =
85+
unsafe { mem::zeroed() };
86+
device_levels.NumFeatureLevels = d3d_feature_level.len() as u32;
87+
device_levels.pFeatureLevelsRequested = d3d_feature_level.as_ptr().cast();
88+
unsafe {
89+
device.CheckFeatureSupport(
90+
d3d12_ty::D3D12_FEATURE_FEATURE_LEVELS,
91+
&mut device_levels as *mut _ as *mut _,
92+
mem::size_of::<d3d12_ty::D3D12_FEATURE_DATA_FEATURE_LEVELS>() as _,
93+
)
94+
};
95+
// This cast should never fail because we only requested feature levels that are already in the enum.
96+
let max_feature_level =
97+
d3d12::FeatureLevel::try_from(device_levels.MaxSupportedFeatureLevel)
98+
.expect("Unexpected feature level");
99+
77100
// We have found a possible adapter.
78101
// Acquire the device information.
79102
let mut desc: dxgi1_2::DXGI_ADAPTER_DESC2 = unsafe { mem::zeroed() };
@@ -182,11 +205,18 @@ impl super::Adapter {
182205
// Theoretically vram limited, but in practice 2^20 is the limit
183206
let tier3_practical_descriptor_limit = 1 << 20;
184207

185-
let (full_heap_count, _uav_count) = match options.ResourceBindingTier {
186-
d3d12_ty::D3D12_RESOURCE_BINDING_TIER_1 => (
187-
d3d12_ty::D3D12_MAX_SHADER_VISIBLE_DESCRIPTOR_HEAP_SIZE_TIER_1,
188-
8, // conservative, is 64 on feature level 11.1
189-
),
208+
let (full_heap_count, uav_count) = match options.ResourceBindingTier {
209+
d3d12_ty::D3D12_RESOURCE_BINDING_TIER_1 => {
210+
let uav_count = match max_feature_level {
211+
d3d12::FeatureLevel::L11_0 => 8,
212+
_ => 64,
213+
};
214+
215+
(
216+
d3d12_ty::D3D12_MAX_SHADER_VISIBLE_DESCRIPTOR_HEAP_SIZE_TIER_1,
217+
uav_count,
218+
)
219+
}
190220
d3d12_ty::D3D12_RESOURCE_BINDING_TIER_2 => (
191221
d3d12_ty::D3D12_MAX_SHADER_VISIBLE_DESCRIPTOR_HEAP_SIZE_TIER_2,
192222
64,
@@ -284,9 +314,10 @@ impl super::Adapter {
284314
_ => d3d12_ty::D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE,
285315
},
286316
// these both account towards `uav_count`, but we can't express the limit as as sum
287-
max_storage_buffers_per_shader_stage: base.max_storage_buffers_per_shader_stage,
288-
max_storage_textures_per_shader_stage: base
289-
.max_storage_textures_per_shader_stage,
317+
// of the two, so we divide it by 4 to account for the worst case scenario
318+
// (2 shader stages, with both using 16 storage textures and 16 storage buffers)
319+
max_storage_buffers_per_shader_stage: uav_count / 4,
320+
max_storage_textures_per_shader_stage: uav_count / 4,
290321
max_uniform_buffers_per_shader_stage: full_heap_count,
291322
max_uniform_buffer_binding_size:
292323
d3d12_ty::D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * 16,

wgpu-types/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ pub struct Limits {
844844
pub max_samplers_per_shader_stage: u32,
845845
/// Amount of storage buffers visible in a single shader stage. Defaults to 8. Higher is "better".
846846
pub max_storage_buffers_per_shader_stage: u32,
847-
/// Amount of storage textures visible in a single shader stage. Defaults to 8. Higher is "better".
847+
/// Amount of storage textures visible in a single shader stage. Defaults to 4. Higher is "better".
848848
pub max_storage_textures_per_shader_stage: u32,
849849
/// Amount of uniform buffers visible in a single shader stage. Defaults to 12. Higher is "better".
850850
pub max_uniform_buffers_per_shader_stage: u32,

0 commit comments

Comments
 (0)