You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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:
Yep, I've wanted to fix this but the usability of &[ManuallyDrop<Option<T>>] isn't ideal compared with C++. But I agree the extra reference bumps aren't great. Perhaps if there were some kind of IntoParam specialization for this as we do for non-array parameters.
That's an interesting issue indeed. While &[] doesn't move/transfer ownership, the API indeed "requires" the caller to put multiple owned ID3D12DescriptorHeaps in a contiguous array which can only happen by incrementing the refcount.
The only alternative I'd like to mention, for single descriptor heaps, is the existence of std::slice::from_ref(&T) -> &[T], which turns a borrow of an object into a slice of length 1.
Given there is no way to turn an Option<&T> into an &Option<T>, I see now that I ended up implementing that via a transmute in our own codebase though...
Suggestion
IIRC, most D3D12 structs that hold references to other D3D objects take these via
ManuallyDrop
. eg: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:
As a result it's necessary to clone values passed in to this array:
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:
Ideally, it would be:
But I suspect that we don't have any metadata to indicate that null values aren't valid in the array.
The text was updated successfully, but these errors were encountered: