Skip to content

Make ID3D12GraphicsCommandList::SetDescriptorHeaps take ManuallyDrop'd references #2930

@damyanp

Description

@damyanp

Suggestion

IIRC, most D3D12 structs that hold references to other D3D objects take these via ManuallyDrop. eg:

}
#[repr(C)]
pub struct D3D12_BUFFER_BARRIER {
    pub SyncBefore: D3D12_BARRIER_SYNC,
    pub SyncAfter: D3D12_BARRIER_SYNC,
    pub AccessBefore: D3D12_BARRIER_ACCESS,
    pub AccessAfter: D3D12_BARRIER_ACCESS,
    pub pResource: ::std::mem::ManuallyDrop<::core::option::Option<ID3D12Resource>>,
    pub Offset: u64,
    pub Size: u64,
}

However, when a function such as SetDescriptorHeaps does use a struct, but just expects an array of pointers to objects, these aren't wrapped in ManuallyDrop:

pub unsafe fn SetDescriptorHeaps(
    &self,
    ppdescriptorheaps: &[::core::option::Option<ID3D12DescriptorHeap>],
)

As a result it's necessary to clone values passed in to this array:

command_list.SetDescriptorHeaps(&[Some(resources.srv_heap.clone())]);

Although this works, it does mean that there's an unnecessary AddRef/Release going on for each call to SetDescriptorHeaps. This is unfortunate as this is one of the high frequency methods that we expect D3D12 apps to call fairly often so the overhead of AddRef/Release could start to add up.

The solution that I think would fit well here would be if we could get SetDescriptorHeaps to be:

pub unsafe fn SetDescriptorHeaps(
    &self,
    ppdescriptorheaps: &[::std::mem::ManuallyDrop<::core::option::Option<ID3D12DescriptorHeap>>],
) {

Ideally, it would be:

pub unsafe fn SetDescriptorHeaps(
    &self,
    ppdescriptorheaps: &[::std::mem::ManuallyDrop<ID3D12DescriptorHeap>],
) {

But I suspect that we don't have any metadata to indicate that null values aren't valid in the array.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions