Skip to content

Commit 101e9a5

Browse files
authored
Make sure to copy all of the buffers into the resource array for dx12. (#5091)
* Make sure to copy all of the buffers into the resource array for dx12. Fixes #5088. Even though we're telling DX12 that the maximum frame latency should be our non-padded value, the swap chain may request any of the buffers allocated to it. * Up the maximum frame latency on the DX12 backend to allow a larger range.
1 parent d678c7a commit 101e9a5

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

wgpu-hal/src/dx12/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -660,10 +660,14 @@ impl crate::Surface<Api> for Surface {
660660

661661
let non_srgb_format = auxil::dxgi::conv::map_texture_format_nosrgb(config.format);
662662

663+
// The range for `SetMaximumFrameLatency` is 1-16 so the maximum latency requested should be 15 because we add 1.
664+
// https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgidevice1-setmaximumframelatency
665+
debug_assert!(config.maximum_frame_latency <= 15);
666+
663667
// Nvidia recommends to use 1-2 more buffers than the maximum latency
664668
// https://developer.nvidia.com/blog/advanced-api-performance-swap-chains/
665669
// For high latency extra buffers seems excessive, so go with a minimum of 3 and beyond that add 1.
666-
let swap_chain_buffer = (config.maximum_frame_latency + 1).min(3);
670+
let swap_chain_buffer = (config.maximum_frame_latency + 1).min(16);
667671

668672
let swap_chain = match self.swap_chain.write().take() {
669673
//Note: this path doesn't properly re-initialize all of the things
@@ -805,8 +809,8 @@ impl crate::Surface<Api> for Surface {
805809
unsafe { swap_chain.SetMaximumFrameLatency(config.maximum_frame_latency) };
806810
let waitable = unsafe { swap_chain.GetFrameLatencyWaitableObject() };
807811

808-
let mut resources = Vec::with_capacity(config.maximum_frame_latency as usize);
809-
for i in 0..config.maximum_frame_latency {
812+
let mut resources = Vec::with_capacity(swap_chain_buffer as usize);
813+
for i in 0..swap_chain_buffer {
810814
let mut resource = d3d12::Resource::null();
811815
unsafe {
812816
swap_chain.GetBuffer(i, &d3d12_ty::ID3D12Resource::uuidof(), resource.mut_void())

0 commit comments

Comments
 (0)