-
Notifications
You must be signed in to change notification settings - Fork 8
Draft: Compute pipeline support #728
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
base: main
Are you sure you want to change the base?
Conversation
119d1c9
to
8f27022
Compare
@adamwych Hey, thanks for the interest. I understand that compute is something that is of interest for people as one of major attractions of using SDL_GPU compared to other rendering libraries. I took a look at this PR as it is. I've been working on compute also these past few weeks to add the example https://github.com/TheSpydog/SDL_gpu_examples/blob/main/Examples/BasicCompute.c I pushed my changes so far (not finished yet) to I'll compare and contrast to your MR and discuss more here as I go. |
Okay. I see you've chosen to merge the compute shader with the compute pipeline into one class. I kept it separate, since that's how it works on the lower level, but I can update the code to work like that too. Looking at my user code it seems like it will make it somewhat cleaner too. |
Yeah, looking at the SDL_GPU example for compute it appears that |
Hey @adamwych I made some progress on the I was wrestling with passing two arrays with I'll be looking next into folding |
Any reason why |
Error:
I find this one to be the deal breaker because using |
Since private GpuStorageTextureReadWriteBinding[] _bindingsSomewhereOnHeap;
private void Foo() {
var computePassParameters = default(GpuComputePassParameters);
computePassParameters.SetBindingsTextureWrite(_bindingsSomewhereOnHeap);
// <- if GC happens to run here, between those calls - `_bindingsSomewhereOnHeap` might be moved to a different location and the pointer inside `NativeArray` points to invalid data
var computePass = commandBuffer.BeginComputePass(computePassParameters);
} It seems to me like |
I would be inclined to say that's on the developer to maintain that the pointer is valid for the call to the native function. Also how are you calling the method If I change the struct to:
Then try to call the method like so:
I get a compile time error:
|
Doesn't that defeat the purpose of providing a more idiomatic API? Unless someone looks at what I'm also not sure if there is a clear way for a dev to ensure that the pointer is valid other than by than creating a local copy of the entire array, using
In my proposal there was no need for separate variables, you can just use it like so: var computePass = commandBuffer.BeginComputePass(
new GpuComputePassParameters
{
StorageTextureBindings = [],
StorageBufferBindings =
[
new() { Buffer = _drawCommandsBuffer },
new() { Buffer = _meshDataBuffer },
// ...
]
}
); (Note that this requires copying in Generally I'm all for removing the need to create copies in |
OK this wasn't in this MR and is new information to me but nice. I did not know one could use spans like that inline. I would say that then this is most likely the best way to get about doing it. I'll try it out. |
Yup, that works great 👍 , updated |
I merged |
c078649
to
4b07205
Compare
I updated the PR with
|
4b07205
to
33fc459
Compare
👍
There is only
SDL properties should be handled internally by C# idiomatic API. See |
Not finished, but it does work. I started adding support for the compute pipeline, so I can play around and implement a GPU-driven renderer - might as well make a PR.
(I tried to make the API feel similar to how the graphics pipeline works.)
ToDo:
SDL_GPUComputePipelineCreateInfo
options:props