floooh / sokol

minimal cross-platform standalone C headers
https://floooh.github.io/sokol-html5
zlib License
6.56k stars 469 forks source link

sokol_gfx: Compute shaders #219

Open amerkoleci opened 4 years ago

amerkoleci commented 4 years ago

Hi, I would like to add compute shaders support to sokol_gfx, of course using a feature flag, this would introduce new flag to sg_buffer_desc and sg_image_desc, currently we have render_target for image.

I would like to add new sg_texture_usage flags which can follow metal convention maybe, texture can be shader_read, shader_write, render_target instead of having single boolean field?

Buffer can have sg_buffer_usage flag which ban be shader_read and shader_write as well.

What do you think?

I have some D3D12 and Vulkan focused development here and would love to use sokol

https://github.com/amerkoleci/alimer/blob/master/third_party/vgpu/include/vgpu/vgpu.h

septag commented 4 years ago

I'm doing a very early draft version (currently D3d11) with the help of other contributors: sokol_gfx.h, here is the PR

It's very sketchy and still no support for buffers, but as you see in sg_image_desc, there is shader_write flag

raizam commented 4 years ago

compute and draw_indirect would be indeed very nice to have. @septag has done a lot of work to implement these, but his work will probably not get merged https://github.com/septag/rizz/commits/master/3rdparty/sokol/sokol_gfx.h

please @floooh, tell us you have a plan :)

floooh commented 4 years ago

Compute support definitely isn't off the table, I'm currently just distracted by other things (mostly emulator stuff), and there's a few smaller features on "backlog" which also need fixing :)

septag commented 4 years ago

Now that you have added WebGPU backend. it may be a good time to consider it. and I'm willing to help on D3d11 and OpenGL backends.

Here is a proof of concept for d3d11 backend: https://github.com/septag/sokol/blob/compute-shaders/sokol_gfx.h It's in sync with your current changes, so you can diff it

which is tested with an example (wrapped in my own engine): https://github.com/septag/rizz/tree/master/examples/07-nbody

ompadu commented 2 years ago

are we closer to having compute/draw_indirect since the last post was made?

floooh commented 2 years ago

No, not really. I spent some time updating the WebGPU backend in the wgpu branch, but the WebGPU API and shading language still changed too much during that time to consider merging it into master. Even with WebGPU in the next question is how much it makes sense to add features which can only be used on some backend (this would depend mainly on how much the public API would need to be changed to accomodate such features, and whether those changes would be compatible with the lowest-end backend (GLES2)).

crystalthoughts commented 10 months ago

Would love to see compute support

floooh commented 10 months ago

It's still on my mental todo list some time after the WebGPU backend is finalized (which is currently happening). Still, don't hold your breath.

I'd first like to do a resource update function revamp first though.

crystalthoughts commented 6 months ago

Having thought about this again - is there a way to write a DX12 / webgpu compute shader pipeline and hook it into a Sokol app in some way (if on the correct platform)? Does it require getting very deep into the source code or can it be done in a relatively simple way?

floooh commented 6 months ago

I think it would require pretty deep changes in the public APIs (basically adding the concept of a 'computer-shader-stage', and on the buffer size a new buffer type 'storage-buffer').

floooh commented 1 month ago

...as a first step, readonly storage buffer support is now implemented, and compute shader support is planned for the "not too distant future".

crystalthoughts commented 1 month ago

Exciting!