-
-
Notifications
You must be signed in to change notification settings - Fork 22k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[.NET] Generate ReadOnlySpan<T>
Overloads for GodotSharp APIs
#96329
[.NET] Generate ReadOnlySpan<T>
Overloads for GodotSharp APIs
#96329
Conversation
49f1c2c
to
0aa2c07
Compare
0aa2c07
to
b4d916a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a massive compatibility break, so it's not acceptable. We could do it as long as it's only adding span overloads while keeping the array overloads, but only for non-virtual methods and spans should never be returned either.
b4d916a
to
34f85da
Compare
34f85da
to
6bdbeb7
Compare
ReadOnlySpan<T>
in APIsReadOnlySpan<T>
Overloads for GodotSharp APIs
51d5c9d
to
ba36a45
Compare
Does this also include to add overloads which take a buffer span instead of returning an Array? Currently one of my biggest performance issues are tied to GetBufferData in the RenderingDevice.BufferGetData. Internally most of these methods act on a pinned array which is created every single time you call this method. For RenderingDevice.BufferGetData the array is a byte[] which is incompatible with most of the other Apis so you have to allocate yet another array (float[]) and memory copy again. Doing this allows to use pooled arrays / instances and avoid allocations alltogether |
I have modified my PR to fit the compatibility requirements; now that span-related APIs are generated as overloads, no spans are returned by public APIs. |
@dotlogix In my original unmodified PR, yes, most arrays are directly replaced into Spans, including the return value. But for compatibility reasons, we can't do this, not on the main branch. |
Guess you forgot to revert: I don't mean return a ReadOnlySpan instead of a T[] but instead of creating an array and return it, take a Span and write to that instead. |
Good catch, thanks!
Oh, do you mean to return a Span for developers to write into, like a temporary buffer? As you mentioned, that would work by utilizing an array pool, but it would be challenging to manage the lifetime of the rented arrays. It sounds like a job for a custom struct-based, disposable array wrapper, but any of it is beyond the compatibility requirements. You can create a customized fork based on 34f85da if you wish. |
No I mean in addition to this: public byte[] BufferGetData(Rid buffer, uint offsetBytes = 0u, uint sizeBytes = 0u) Have an overload like this: public void BufferGetData(Rid buffer, Span<byte> target, uint offsetBytes = 0u, uint sizeBytes = 0u) |
I don't think this is possible. The C# binding layer does not contain Godot logic; the binding generator creates the APIs you see. |
Hm that's quite unfortunate. I would know how to implement that in C# pretty easily, but I just don't understand the binding generator (C++) so I can't just add it myself. |
Request removing |
a7b039f
to
c472476
Compare
ceb7079
to
c2b2963
Compare
c2b2963
to
5db07f9
Compare
540a55b
to
dedddee
Compare
I should probably generate ROS overloads for Edit: Done, public Error Rpc(StringName method, params Variant[] @args)
public Error Rpc(StringName method, ReadOnlySpan<Variant> @args)
public Variant New(params Variant[] @args)
public Variant New(ReadOnlySpan<Variant> @args)
public void CallGroupFlags(long flags, StringName group, StringName method, params Variant[] @args)
public void CallGroupFlags(long flags, StringName group, StringName method, ReadOnlySpan<Variant> @args) |
06ade5f
to
eb00fd7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thanks.
I have compared the generated bindings with the ones we were generating before this PR, and the changes look good. It also doesn't look like it breaks compatibility, I double-checked with APICompat.
ReadOnlySpan<T>
Overloads for GodotSharp APIsReadOnlySpan<T>
Overloads for GodotSharp APIs
eb00fd7
to
5bd5646
Compare
f39861c
to
98e1b82
Compare
048f6c0
to
799931b
Compare
799931b
to
9a3d085
Compare
Co-authored-by: Raul Santos <raulsntos@gmail.com> Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
9a3d085
to
d4695e8
Compare
Thanks! |
By adding
ReadOnlySpan<T>
API overloads, this PR aims to make the overall GodotSharp API more flexible by addressing the need for a dedicated data transactionT[]
when making API calls.Using the example from this proposal, the original
RenderingServer.MultimeshSetBuffer
will have an additional overload that takes
ReadOnlySpan<float>
:Bugsquad edit: