Skip to content
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

Initial (readonly) storage buffer support. #1007

Merged
merged 33 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
cf2b5e3
sokol_gfx.h: start implementing storage buffer support
floooh Mar 5, 2024
7284793
sokol_gfx.h: storage buffer code cleanup and additional validation ch…
floooh Mar 8, 2024
bc4886b
sokol_gfx.h metal: filter redundant storage buffer bindings
floooh Mar 8, 2024
025df96
sokol_gfx.h wgpu: initial storage buffer support
floooh Mar 8, 2024
34b92a6
sokol_gfx.h, sokol_gfx_imgui.h: minor storage buffer related code cle…
floooh Mar 9, 2024
71df9eb
sokol_gfx.h d3d11: initial storage buffer support
floooh Mar 9, 2024
fb77929
replace SOKOL_GLCORE33 with SOKOL_GLCORE
floooh Mar 10, 2024
daedb63
sokol_gfx.h gl: storage buffers wip
floooh Mar 11, 2024
9fa8312
sokol_gfx.h gl: more storage buffer wip
floooh Mar 11, 2024
3226c30
sokol_gfx.h gl: make GL_SHADER_STORAGE_BUFFER const generally availab…
floooh Mar 11, 2024
e8c89c7
sokol_gfx.h: fix sg_environment default setup, add glBindBufferBase()…
floooh Mar 11, 2024
6549864
sokol_gfx_imgui.h: add SG_BUFFERTYPE_STORAGEBUFFER
floooh Apr 3, 2024
c2c709b
sokol_gfx.h: allow draws without resource bindings.
floooh Apr 4, 2024
cb7bcf6
sokol_app.h gl: update GL context initialization
floooh Apr 8, 2024
1b5d2f4
sokol_glue.h: initialize env.gl.major/minor_version
floooh Apr 8, 2024
19903d7
sokol_gfx.h d3d11, gl: fix instanced drawing if no pipeline vertex la…
floooh Apr 8, 2024
e9b356d
sokol_gfx.h: bump max storage buffers per stage to 8, fix wgpu bind s…
floooh Apr 15, 2024
ca23e46
update embedded shaders for changed wgpu bind slots and glsl v410
floooh Apr 15, 2024
7e1035c
sokol_gfx.h: validate that storage buffers used in shaders are readonly
floooh Apr 20, 2024
4fac1bb
Merge branch 'master' into storage-buffers
floooh Apr 21, 2024
fcd5f96
sokol_gfx.h: fix merge problem when setting D3D11 input layout label
floooh Apr 29, 2024
1c80c14
sokol_gfx.h gl: fix fragment stage storage buffer bind slot offset fo…
floooh Apr 29, 2024
e98ec4e
sokol_gfx.h wgpu: fix stage mismatch in storage buffer bind size
floooh May 1, 2024
5d59b76
sokol_gfx.h: rename SG_MAX_SHADERSTAGE_STORAGE_BUFFERS to SG_MAX_SHAD…
floooh May 1, 2024
d50223a
sokol_gfx_imgui.h: add storage buffers to shader and apply-bindings p…
floooh May 1, 2024
8e88de6
Merge branch 'master' into storage-buffers
floooh May 3, 2024
a302849
forgot changelog item credits
floooh May 3, 2024
aa08a50
sokol_gfx.h: storage buffer documentation wip
floooh May 3, 2024
cf77f41
sokol_gfx.h: storage buffer documentation and general doc comment cle…
floooh May 4, 2024
208aef6
sokol_gfx.h gl: don't require passing in major and minor GL version
floooh May 5, 2024
179a03f
sokol_gfx.h: add GL_MAJOR/MINOR_VERSION to win32 GL loader
floooh May 6, 2024
5cb19c7
update changelog and readme
floooh May 8, 2024
7b7c31d
Merge branch 'master' into storage-buffers
floooh May 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 115 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,118 @@
## Updates

### 09-May-2024

The 'storage buffer update'. sokol_gfx.h now has (readonly) storage buffer support, providing
a more flexible way to pass array-like random access data from the CPU to the GPU side.

Please see the following [blog post](https://floooh.github.io/2024/05/06/sokol-storage-buffers.html)
and the [associated PR #1007](https://github.com/floooh/sokol/pull/1007) for details.

Please also note the new documentation section `ON STORAGE BUFFERS` in sokol_gfx.h.

Also see the related [changes in sokol-shdc](https://github.com/floooh/sokol-tools/blob/master/CHANGELOG.md).

...and finally the following new samples (note that the demo are running on WebGPU and currently
require a recent Chrome on macOS or Windows):

- rendering without buffer bindings (this sample actually also runs on WebGL2):
- WebGPU: https://floooh.github.io/2024/05/06/sokol-storage-buffers.html
- C source: https://github.com/floooh/sokol-samples/blob/master/sapp/triangle-bufferless-sapp.c
- GLSL source: https://github.com/floooh/sokol-samples/blob/master/sapp/triangle-bufferless-sapp.glsl
- vertex pulling from a storage buffer:
- WebGPU: https://floooh.github.io/sokol-webgpu/vertexpull-sapp.html
- C source: https://github.com/floooh/sokol-samples/tree/master/sapp/vertexpull-sapp.c
- GLSL source: https://github.com/floooh/sokol-samples/tree/master/sapp/vertexpull-sapp.glsl
- reading storage buffer content in fragment shader:
- WebGPU: https://floooh.github.io/sokol-webgpu/sbuftex-sapp.html
- C source: https://github.com/floooh/sokol-samples/tree/master/sapp/sbuftex-sapp.c
- GLSL source: https://github.com/floooh/sokol-samples/tree/master/sapp/sbuftex-sapp.glsl
- instanced rendering via storage buffer:
- WebGPU: https://floooh.github.io/sokol-webgpu/instancing-pull-sapp.html
- C source: https://github.com/floooh/sokol-samples/tree/master/sapp/instancing-pull.c
- GLSL source: https://github.com/floooh/sokol-samples/tree/master/sapp/instancing-pull.glsl
- skinned character rendering via storage buffers:
- WebGPU: https://floooh.github.io/sokol-webgpu/ozz-storagebuffer-sapp.html
- C source: https://github.com/floooh/sokol-samples/tree/master/sapp/ozz-storagebuffer-sapp.c
- GLSL source: https://github.com/floooh/sokol-samples/tree/master/sapp/ozz-storagebuffer-sapp.glsl

Also see the following backend-specific samples which don't use sokol-shdc:

- D3D11: https://github.com/floooh/sokol-samples/blob/master/d3d11/vertexpulling-d3d11.c
- Metal: https://github.com/floooh/sokol-samples/blob/master/metal/vertexpulling-metal.c
- WebGPU: https://github.com/floooh/sokol-samples/blob/master/wgpu/vertexpulling-wgpu.c
- Desktop GL: https://github.com/floooh/sokol-samples/blob/master/glfw/vertexpulling-glfw.c

Storage support is not available on the following platform/backend combos:

- macOS + GL (stuck at GL 4.1)
- iOS + GL (stuck at GLES 3.0)
- WebGL2 (stuck at GLES 3.0)
- Android (support may be implemented at a later time)

#### **BREAKING CHANGES**

- the config define `SOKOL_GLCORE33` has been renamed to `SOKOL_GLCORE`, this affects
the following headers:
- sokol_gfx.h
- sokol_app.gh
- sokol_debugtext.h
- sokol_fontstash.h
- sokol_gl.h
- sokol_imgui.h
- sokol_nuklear.h
- sokol_spine.h
- likewise in the sokol_gfx.h enum `sg_backend` the enum item `SG_BACKEND_GLCORE33` has been
renamed to `SG_BACKEND_GLCORE`
- sokol_gfx.h now expects a minimal desktop GL version of 4.1 on macOS, and 4.3 on other
platforms (this only matters if you don't use sokol_app.h), storage buffer support is only
available on GL 4.3 contexts
- likewise, shaders passed into sokol_gfx.h when the desktop GL backend is active are now expected
to be `#version 410` or `#version 430` (`#version 330` may still work but though but is untested)
- likewise, by default sokol_app.h now creates a GL 4.1 context on macOS and a GL 4.3 context on other
desktop platforms when `SOKOL_GLCORE` is defined
- if you're passing WGSL shaders directly into sokol_gfx.h (instead of using sokol-shdc), please
be aware that the binding offets for the different shader resource types have moved:
- vertex shader stage:
- textures: `@group(1) @binding(0..15)`
- samplers: `@group(1) @binding(16..31)`
- storage buffers: `@group(1) @binding(32..37)`
- fragment shader stage:
- textures: `@group(1) @binding(48..63)`
- samplers: `@group(1) @binding(64..79)`
- storage buffers `@group(1) @binding(80..95)`

#### **NON-BREAKING CHANGES**

- **sokol_app.h** learned two new functions to get the desktop GL version (note that on GLES
these return 0, this behaviour may change at a later time):
- `int sapp_gl_get_major_version(void)`
- `int sapp_gl_get_minor_version(void)`

- **sokol_gfx.h**:
- The enum `sg_buffer_type` has a new member `SG_BUFFERTYPE_STORAGEBUFFER`, used
in the `sg_make_buffer()` call to create a storage buffer
- The struct `sg_features` has a new member `bool storage_buffer`, used to indicate
that the current 3D backend supports storage buffers
- The stats struct `sg_frame_stats_metal_bindings` has a new member `num_set_fragment_buffer`
- There are various new error codes and validation checks related to storage buffers
- A new struct `sg_shader_storage_buffer_desc`, nested in `sg_shader_desc`.
This is used in the `sg_make_shader()` call to communicate to sokol_gfx.h
what storage buffer bind slots are used in a shader

- **sokol_gfx_imgui.h**: The debug UI panels have been updated to visualize the new
storage buffer related state

- in the following headers, the embedded shaders have been updated via the new
sokol-shdc version, switching the embedded GLSL shaders to `#version 410`
- sokol_debugtext.h
- sokol_fontstash.h
- sokol_gl.h
- sokol_imgui.h
- sokol_nuklear.h
- sokol_spine.h


### 03-May-2024:

- sokol_app.h win32: Merged PR https://github.com/floooh/sokol/pull/1034, this adds a NOAPI mode
Expand Down Expand Up @@ -1281,8 +1394,8 @@ GLES2/WebGL1 support has been removed from the sokol headers (now that
GLX for the window system glue code and can create a GLES2 or GLES3 context
instead of a 'desktop GL' context.
To get EGL+GLES2/GLES3, just define SOKOL_GLES2 or SOKOL_GLES3 to compile the
implementation. To get EGL+GL, define SOKOL_GLCORE33 *and* SOKOL_FORCE_EGL.
By default, defining just SOKOL_GLCORE33 uses GLX for the window system glue
implementation. To get EGL+GL, define SOKOL_GLCORE *and* SOKOL_FORCE_EGL.
By default, defining just SOKOL_GLCORE uses GLX for the window system glue
(just as before). Many thanks to GH user @billzez for the PR!

- **10-Sep-2022**: sokol_app.h and sokol_args.h has been fixed for Emscripten 3.21, those headers
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

# Sokol

[**See what's new**](https://github.com/floooh/sokol/blob/master/CHANGELOG.md) (**29-Feb-2024**: **BREAKING CHANGES** 'unified render pass'
cleanup in sokol_gfx.h)
[**See what's new**](https://github.com/floooh/sokol/blob/master/CHANGELOG.md) (**09-May-2024**: **BREAKING CHANGES** 'storage buffer support' in sokol_gfx.h

[![Build](/../../actions/workflows/main.yml/badge.svg)](/../../actions/workflows/main.yml) [![Bindings](/../../actions/workflows/gen_bindings.yml/badge.svg)](/../../actions/workflows/gen_bindings.yml) [![build](https://github.com/floooh/sokol-zig/actions/workflows/main.yml/badge.svg)](https://github.com/floooh/sokol-zig/actions/workflows/main.yml) [![build](https://github.com/floooh/sokol-nim/actions/workflows/main.yml/badge.svg)](https://github.com/floooh/sokol-nim/actions/workflows/main.yml) [![Odin](https://github.com/floooh/sokol-odin/actions/workflows/main.yml/badge.svg)](https://github.com/floooh/sokol-odin/actions/workflows/main.yml)[![Rust](https://github.com/floooh/sokol-rust/actions/workflows/main.yml/badge.svg)](https://github.com/floooh/sokol-rust/actions/workflows/main.yml)

Expand Down
6 changes: 3 additions & 3 deletions bindgen/gen_nim.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def gen_extra(inp):
l(' when not defined vcc:')
l(' {.passl:"-lkernel32 -luser32 -lshell32 -lgdi32".}')
l(' when defined gl:')
l(' {.passc:"-DSOKOL_GLCORE33".}')
l(' {.passc:"-DSOKOL_GLCORE".}')
l(' else:')
l(' {.passc:"-DSOKOL_D3D11".}')
l(' when not defined vcc:')
Expand All @@ -522,13 +522,13 @@ def gen_extra(inp):
l(' {.passc:"-x objective-c".}')
l(' {.passl:"-framework Cocoa -framework QuartzCore".}')
l(' when defined gl:')
l(' {.passc:"-DSOKOL_GLCORE33".}')
l(' {.passc:"-DSOKOL_GLCORE".}')
l(' {.passl:"-framework OpenGL".}')
l(' else:')
l(' {.passc:"-DSOKOL_METAL".}')
l(' {.passl:"-framework Metal -framework MetalKit".}')
l('elif defined linux:')
l(' {.passc:"-DSOKOL_GLCORE33".}')
l(' {.passc:"-DSOKOL_GLCORE".}')
l(' {.passl:"-lX11 -lXi -lXcursor -lGL -lm -ldl -lpthread".}')
l('else:')
l(' error("unsupported platform")')
Expand Down
Loading
Loading