Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dx12: Add dynamically sized CPU descriptor heaps #2110

Merged
merged 4 commits into from
Jun 5, 2018

Conversation

msiglreith
Copy link
Contributor

@msiglreith msiglreith commented Jun 5, 2018

Dynamic allocator for CPU descriptor heaps. We currently have 2 ways of allocating CPU descriptors: from a device global heap and command local linear allocators. This PR cleans up the two paths a bit and fixes the current size limitation for the first kind by dynamically creating new small fixed size CPU heaps.

Freeing currently not support but that's not an regression as we didn't support it before either.
Small 'regression' concerning fill_buffer which was implemented incorrectly as far as I can see. Probably would work only on AMD. This breaks the fill reftests.

Fixes #1945
PR checklist:

  • tested quad, relevant CTS and a few vulkan samples with the following backends: dx12

@msiglreith msiglreith changed the title [WIP] dx12: Add dynamically sized CPU descriptor heaps dx12: Add dynamically sized CPU descriptor heaps Jun 5, 2018
Copy link
Member

@kvark kvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit, otherwise good to sail!

}
}

// Fixed-size (64) free-list allocator for CPU descriptors.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's have this defined as a constant here


pub fn alloc_handle(&mut self) -> d3d12::D3D12_CPU_DESCRIPTOR_HANDLE {
// Find first free slot
let slot = (0..64)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add TODO to use https://doc.rust-lang.org/std/intrinsics/fn.ctlz.html (or actually do it behind the nightly` feature ;) )

Copy link
Member

@kvark kvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love those trailing zeroes:) A few more concerns below:

//
// 0 - Occupied
// 1 - free
occupancy: u64,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be renamed into availability to avoid confusion

}
}

pub fn full(&self) -> bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that this is not an accessor, I don't think it's idiomatic to omit the verb here. Should be is_full() to mimic is_empty() in standard collections

assert!(!self.full());

// Find first free slot.
let slot = self.occupancy.trailing_zeros() as usize;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nice! What's the result if we were running it on !0? should we perhaps move the assert down here checking for slot < HEAP_SIZE_FIXED?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!0 returns 0.
yes, that assert check looks a bit nicer.

@kvark
Copy link
Member

kvark commented Jun 5, 2018

Greatness here!
bors r+

bors bot added a commit that referenced this pull request Jun 5, 2018
2110: dx12: Add dynamically sized CPU descriptor heaps r=kvark a=msiglreith

Dynamic allocator for CPU descriptor heaps. We currently have 2 ways of allocating CPU descriptors: from a device global heap and command local linear allocators. This PR cleans up the two paths a bit and fixes the current size limitation for the first kind by dynamically creating new small fixed size CPU heaps.

Freeing currently not support but that's not an regression as we didn't support it before either.
Small 'regression' concerning `fill_buffer` which was implemented incorrectly as far as I can see. Probably would work only on AMD. This breaks the fill reftests.

Fixes #1915
PR checklist:
- [x] tested quad, relevant CTS and a few vulkan samples with the following backends: dx12


Co-authored-by: msiglreith <m.siglreith@gmail.com>
@bors
Copy link
Contributor

bors bot commented Jun 5, 2018

@bors bors bot merged commit 8e6c759 into gfx-rs:master Jun 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[dx12] Increase max RTV allocations (or make it configurable).
2 participants