microsoft / microsoft/CsWin32

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

Open
#1,605 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
C#
Stars
2.5k
Forks
124
Avg merge
1d 3h
Merged PRs (30d)
9

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the generator code that produces the ResourceBarrier array overload and the related friendly overload generation path; the issue does not name a source file or test. Determine how a ReadOnlySpan overload should be generated for array parameters, then verify that the generated ResourceBarrier API accepts collection expressions without the unwanted array allocation.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.