Skip to content

[Feature Request] Support ReadOnlySpan<T> for array parameters (like ResourceBarrier) #1605

@littletoxic

Description

@littletoxic

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)
{ ... }

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