[Feature Request] Support `ReadOnlySpan<T>` for array parameters (like ResourceBarrier)
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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