sokol icon indicating copy to clipboard operation
sokol copied to clipboard

sokol_gfx: Compute shaders

Open amerkoleci opened this issue 6 years ago • 12 comments

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

amerkoleci avatar Sep 18 '19 19:09 amerkoleci

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

septag avatar Sep 23 '19 16:09 septag

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 :)

raizam avatar Nov 04 '19 11:11 raizam

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 :)

floooh avatar Nov 05 '19 10:11 floooh

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

septag avatar May 16 '20 14:05 septag

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

ompadu avatar May 22 '22 12:05 ompadu

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)).

floooh avatar May 23 '22 10:05 floooh

Would love to see compute support

crystalthoughts avatar Aug 29 '23 13:08 crystalthoughts

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.

floooh avatar Aug 29 '23 13:08 floooh

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?

crystalthoughts avatar Jan 06 '24 16:01 crystalthoughts

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 avatar Jan 08 '24 13:01 floooh

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

floooh avatar May 13 '24 12:05 floooh

Exciting!

crystalthoughts avatar May 13 '24 12:05 crystalthoughts