Replies: 1 comment 1 reply
-
The API needs to remain compatible with GDScript and GDExtension, which doesn't have Span types or anything like that. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So after the NET6 merge I asked my self why Godot does not provide any way to use the high performance APIs Net6 provides.
I am talking especially about the extensive usage of Godot.Array instead of native T[] or Span. The current approach means a lot of copying back and forth which slows down performance without any reason.
Would be nice if we as developers could optimize for performance in the hot paths and use the simpler APIs everywhere else.
As an example I could name the SurfaceTool or ComputeShaders.
These are used in more performance critical situations (I assume) so allowing more performant types being used would really help.
Real world example: ComputeShaders
I experimented a bit lately with compute shaders and it is a very inefficent API to use.
I want to use compute shaders to generate a lot of noise really, really fast.
I use storage buffers to pass data between the CPU and the GPU.
In the current implementation I would need to:
Create a float[] for some input values.
Create a byte[] and Buffer.BlockCopy the floats over to the byte[].
Then I can actually do sth with it and call StorageBufferCreate
Then execute the shader.
To get the results I then call BufferGetData which will allocate another byte[] internally and returns it.
Create a float[] for the output values.
Another Buffer.BlockCopy the bytes over to the output array
So we have a total of 4 allocations which means 4 times the memory consumption and putting more pressure to the GC.
You usually don't use ComputeShaders for very small and simple scenarios so these arrays can get very big.
With the usage of Span we could Read and Write to the buffer using the original arrays and unsafe cast them to Span if even needed. We could even stackalloc them so no heap allocation at all.
Beta Was this translation helpful? Give feedback.
All reactions