-
Notifications
You must be signed in to change notification settings - Fork 115
Description
Is your feature request related to a problem? Please describe.
I am learning DirectX 12 using CsWin32.
I noticed that for methods like ResourceBarrier, CsWin32 generates an overload that takes an array (D3D12_RESOURCE_BARRIER[]).
When I use the C# 12 collection expression:
m_CommandList.ResourceBarrier([barrier]);The compiler creates a new array object every time.
Describe the solution you'd like
It would be great if CsWin32 could generate an overload that accepts ReadOnlySpan<T>.
// Desired generated code
void ResourceBarrier(ReadOnlySpan<D3D12_RESOURCE_BARRIER> pBarriers);If this overload exists, the C# compiler can automatically implicit cast [...] to a Span (using stackalloc) and avoid unnecessary memory allocation.
Describe alternatives you've considered
I can write my own extension method to accept ReadOnlySpan, but since CsWin32 already generates friendly overloads, supporting Span seems like a good addition.
Additional context
Currently, the generated code forces me to use an array:
internal static unsafe void ResourceBarrier(this ID3D12GraphicsCommandList @this, D3D12_RESOURCE_BARRIER[] pBarriers)
{ ... }