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

sokol_gfx.h resource bindings cleanup (issue #1037) #1111

Merged
merged 86 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
7b94bf2
sokol_gfx.h: start with resource bindings cleanup
floooh Sep 6, 2024
2840080
sokol_gfx.h bindings cleanup wip
floooh Sep 6, 2024
a120657
sokol_gfx.h redesign sg_shader_desc
floooh Sep 7, 2024
643146c
sokol_gfx.h minor sg_shader_desc cleanup
floooh Sep 7, 2024
54eb91c
sokol_gfx.h SG_MAX_VERTEX_BUFFERS => SG_MAX_VERTEXBUFFER_BINDSLOTS
floooh Sep 8, 2024
4077cc9
sokol_gfx.h bindings cleanup wip
floooh Sep 8, 2024
91a068b
sokol_gfx.h bindings cleanup wip
floooh Sep 8, 2024
4f0e417
sokol_gfx.h bindings cleanup wip
floooh Sep 9, 2024
841c223
sokol_gfx.h bindings cleanup wip
floooh Sep 9, 2024
f161372
sokol_gfx.h tweak metal bindings cache, update shader-desc validation
floooh Sep 12, 2024
54ba59f
sokol_gfx.h add image-sampler-pair vs image/sampler stage validation …
floooh Sep 12, 2024
ef52889
sokol_gfx.h: add a couple fixme reminder comments
floooh Sep 13, 2024
4d154dd
sokol_gfx.h: add validation check for msl bind slot collisions
floooh Sep 14, 2024
92fd93a
sokol_gfx.h: fix image sampler pair validation
floooh Sep 14, 2024
aabd2ef
sokol_gfx.h: rename sg_shader_bind_stage to sg_shader_stage
floooh Sep 14, 2024
1489b61
sokol_gfx.h d3d11: bindings cleanup wip
floooh Sep 15, 2024
841999b
sokol_gfx d3d11: bindings cleanup finished
floooh Sep 16, 2024
ec921c0
sokol_gfx.h: fix unused variable warnings
floooh Sep 18, 2024
b353bab
sokol_gfx.h: rename vertex_attrs to attrs in sg_shader_desc
floooh Sep 18, 2024
2b16c89
sokol_gfx.h gl: bindings cleanup wip
floooh Sep 18, 2024
3550d1a
sokol_gfx.h gl: bindings cleanup wip
floooh Sep 19, 2024
ffa6768
sokol_gfx.h gl: bindings cleanup wip
floooh Sep 21, 2024
5f6b1b0
sokol_gfx.h gl: bring back glsl_name (required for GL 4.1 and WebGL2)
floooh Sep 21, 2024
0c5f4f4
sokol_gfx.h: remove pointless comment
floooh Sep 21, 2024
95af2b8
sokol_gfx.h fix release build errors
floooh Sep 22, 2024
3e518f7
sokol_gfx.h wgpu: bindings cleanip wip
floooh Sep 27, 2024
f703376
sokol_gfx.h wgpu: more bindings cleanup wip
floooh Sep 28, 2024
be542bf
sokol_gfx.h wgpu: more bindings cleanup wip
floooh Sep 29, 2024
630502f
sokol_gfx.h wgpu: Dawn vs Emscripten webgpu.h fixes
floooh Sep 29, 2024
25dbf0d
sokol_gfx.h wgpu: fix sign conversion warning
floooh Sep 30, 2024
a74b97d
sokol_gfx.h wgpu: get rid of special 'empty bindgroup' because settin…
floooh Sep 30, 2024
5b1b0b2
sokol_gfx.h wgpu: add WGSL bind slot validation
floooh Sep 30, 2024
fb14cf9
sokol_gfx.h wgpu: provide correct number of dynamic offset in _sg_wgp…
floooh Oct 1, 2024
e0c3774
sokol_gfx.h wgpu: fix uniform bind slot mapping
floooh Oct 1, 2024
79c888c
sokol_gfx.h wgpu: fix bind slot collision validation messages
floooh Oct 1, 2024
6fe5603
sokol_gfx.h wgpu: bring back the special empty bindgroup
floooh Oct 1, 2024
e97641f
sokol_gfx.h wgpu: deal with new WGPUOptionalBool type
floooh Oct 2, 2024
3244b9c
sokol_gfx.h: fix bindslot validation bitmask test
floooh Oct 6, 2024
e4ac395
sokol_gfx.h: fix Emscripten vs Dawn webgpu.h difference
floooh Oct 9, 2024
b804bfa
sokol_gfx.h wgpu: fix a C vs C++ incompatibility in the Emscripten vs…
floooh Oct 9, 2024
2eb669d
sokol_imgui.h: bindings cleanup changes (except d3d11/hlsl)
floooh Oct 9, 2024
3ddb9fd
sokol_imgui.h: fix a code style problem
floooh Oct 9, 2024
6b750da
sokol_debugtext.h: fix for bindings cleanup
floooh Oct 9, 2024
588e74c
sokol_fontstash.h, sokol_gl.h: fix for bindings cleanup (except hlsl)
floooh Oct 10, 2024
d39703d
sokol_gfx.h wgpu: fix max bindings vs max bindgroup slot confusion
floooh Oct 12, 2024
231d198
sokol_gfx.h wgpu: minor code cleanup
floooh Oct 12, 2024
e3f621a
sokol_gfx.h wgpu: don't set null bindgroups in begin pass, instead se…
floooh Oct 12, 2024
6ccc5b4
sokol_gfx.h wgpu: fix dynamic bind offset mapping (must be in binding…
floooh Oct 14, 2024
cfad5c6
fix sokol_spine.h for bindings cleanup (except hlsl)
floooh Oct 14, 2024
1b62020
fix sokol_nuklear.h for bindings cleanup (except hlsl)
floooh Oct 14, 2024
1080063
sokol_gfx.h: fix msvc warnings
floooh Oct 15, 2024
61a5acc
sokol_debugtext.h: update embedded d3d11 shader blobs
floooh Oct 15, 2024
e04b442
sokol_imgui.h: update d3d11 shader blobs
floooh Oct 15, 2024
8745e45
sokol_gl.h: update d3d11 shader blobs
floooh Oct 15, 2024
8624dd6
sokol_nuklear.h: update d3d11 shader blobs
floooh Oct 15, 2024
195d853
sokol_fontstash.h: update d3d11 shader blobs
floooh Oct 15, 2024
3094a1d
sokol_spine.h: update d3d11 shader blobs
floooh Oct 15, 2024
ebc078f
sokol_gfx.h gl: fix msvc warnings
floooh Oct 15, 2024
f0fc6c0
sokol_gfx_imgui.h: update for sokol-gfx bindings cleanup
floooh Oct 15, 2024
7d80263
sokol_gfx.h: minor naming cleanup and fixed unused warnings in releas…
floooh Oct 17, 2024
b26fa31
update sokol-gfx tests
floooh Oct 17, 2024
6c0ec0e
sokol_gfx.h validation layer: remove a redundant comparison >= 0
floooh Oct 17, 2024
0f058c8
gen_rust.py: update sg_apply_uniforms parameter type mapping
floooh Oct 20, 2024
3bec877
sokol_gl.h: remove obsolete comment
floooh Oct 25, 2024
e7d5229
cleanup bindings generation scripts
floooh Oct 25, 2024
abc9ece
Merge branch 'master' into issue1037_bindings_cleanup
floooh Oct 25, 2024
8bfb443
sokol_gfx.h: fix comment for sg_glsl_shader_uniform.offset
floooh Oct 25, 2024
195d8fe
sokol_gfx.h: remove sg_shader_uniform.offset
floooh Oct 26, 2024
405289e
sokol_gfx.h: turn GL_VERTEX_ATTRIBUTE_NOT_FOUND_IN_SHADER into a warning
floooh Oct 26, 2024
7338592
sokol_gfx.h: error check for required bindings and uniforms
floooh Oct 26, 2024
33e7c53
sokol_gfx.h: fix binding to allow shared binding structs and gaps
floooh Oct 26, 2024
f0eb6b6
sokol_gfx.h: fix a misleading vertex buffer validation message
floooh Oct 26, 2024
47c9668
sokol_gfx_imgui.h: update and fix bindings panel
floooh Oct 26, 2024
ff3ece0
sokol_gfx.h: fix new unused arg warning
floooh Oct 26, 2024
d8b95e6
sokol_gfx.h: remove outdated comment
floooh Oct 28, 2024
5e8ca1d
sokol_gfx.h: minor code cleanup
floooh Oct 28, 2024
dac9da6
sokol_gfx.h: validate correct uniform binding range, and better valid…
floooh Oct 28, 2024
733e8f3
sokol_gfx.h mtl: bind uniform buffers once in sg_begin_pass, not per …
floooh Oct 28, 2024
1db8dcf
sokoL_gfx.h gl: fix regression when GLSL compiler removes an unused v…
floooh Oct 29, 2024
ab5d834
sokol_gfx.h: update documentation, wip (bindings cleanup)
floooh Oct 31, 2024
8b3d531
sokol_gfx.h: documentation update wip (bindings cleanup)
floooh Nov 2, 2024
5e16039
sokol_gfx.h: documentation update wip (bindings cleanup)
floooh Nov 2, 2024
6b836bd
sokol_gfx.h: update documentation, wip (bindings cleanup)
floooh Nov 3, 2024
7ab7efa
sokoL_gfx.h: fix some comments
floooh Nov 5, 2024
fa9d23a
update changelog and readme (https://github.com/floooh/sokol/pull/1111)
floooh Nov 6, 2024
71d744d
changelog fix
floooh Nov 6, 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
90 changes: 90 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,95 @@
## Updates

### 07-Nov-2024

The sokol-gfx 'bindings cleanup update'. This is a breaking change.

Please read this blog post to get an idea what the update is about
and how existing code needs to be changed:

https://floooh.github.io/2024/11/04/sokol-fall-2024-update.html

TL;DR:

- sokol-shdc input shader sources now require to annotate uniform blocks,
textures, samplers and storage buffers with `layout(binding=N)` where `N`
directly maps to sokol-gfx bindslots
- the concept of 'shader stages' has mostly been removed from the sokol-gfx API
- in the `sg_bindings` struct, the nested per-shader-stage binding arrays have
been replaced with unified binding arrays
- in the function `sg_apply_uniforms()`, the shader stage parameter has been
removed
- only relevant if you don't use sokol-shdc: the interior of the `sg_shader_desc`
struct has been changed according to the new binding model, and additional
information must be provided for each resource binding:
- what shader change the binding appears in
- backend 3D API specific resource bindslots to map sokol-gfx
bindslots to 3D API bindslots

The update is implemented in PR https://github.com/floooh/sokol/pull/1111.

The detailed API changes in the sokol_gfx.h API:

- the `sg_apply_uniforms()` function no longer has a shader stage parameter:
```c
void sg_apply_uniforms(int ub_slot, const sg_range* data);
```
- the `sg_bindings` struct interior no longer separates resource
bindings by shader stages:
```c
typedef struct sg_bindings {
uint32_t _start_canary;
sg_buffer vertex_buffers[SG_MAX_VERTEXBUFFER_BINDSLOTS];
int vertex_buffer_offsets[SG_MAX_VERTEXBUFFER_BINDSLOTS];
sg_buffer index_buffer;
int index_buffer_offset;
sg_image images[SG_MAX_IMAGE_BINDSLOTS];
sg_sampler samplers[SG_MAX_SAMPLER_BINDSLOTS];
sg_buffer storage_buffers[SG_MAX_STORAGEBUFFER_BINDSLOTS];
uint32_t _end_canary;
} sg_bindings;
```
- some public constants starting with `SG_NUM_*` or `SG_MAX_*`
have been removed or renamed (those typically shouldn't show up
in user code)
- similar to the `sg_bindings` struct, the bindings reflection is no
longer split between shader stages:
```c
typedef struct sg_shader_desc {
uint32_t _start_canary;
sg_shader_function vertex_func;
sg_shader_function fragment_func;
sg_shader_vertex_attr attrs[SG_MAX_VERTEX_ATTRIBUTES];
sg_shader_uniform_block uniform_blocks[SG_MAX_UNIFORMBLOCK_BINDSLOTS];
sg_shader_storage_buffer storage_buffers[SG_MAX_STORAGEBUFFER_BINDSLOTS];
sg_shader_image images[SG_MAX_IMAGE_BINDSLOTS];
sg_shader_sampler samplers[SG_MAX_SAMPLER_BINDSLOTS];
sg_shader_image_sampler_pair image_sampler_pairs[SG_MAX_IMAGE_SAMPLER_PAIRS];
const char* label;
uint32_t _end_canary;
} sg_shader_desc;
```

Behaviour changes:

- Resource bindings can now have gaps, and validation of `sg_apply_bindings()`
has been relaxed to allow bindslots in `sg_bindings` to be occupied even
if those bindings are not used by the current shader. This allows to use the
same `sg_bindings` struct for different but related shader variants.
- Likewise, uniform block bindslots can now have gaps (but currently it's still
an error trying to apply uniform block data for a bindslot that's not used
by the current shader)
- In debug mode, `sg_draw()` now checks that `sg_apply_bindings()` and/or
`sg_apply_uniforms()` has been called after `sg_apply_pipeline()` when required.
- Lots of new validation checks for the new reflection information in `sg_shader_desc`.

Drive by fixes:

- the sokol_gfx.h WebGPU backend is now compatible again with the latest
Google Dawn library (Chrome's native WebGPU implementation)
- the [fips-dawn glue repository](https://github.com/fips-libs/fips-dawn) has been fixed to work with the latest
Dawn build system changes (still only tested on macOS though)

### 24-Oct-2024

- sokol_nuklear.h: Merged https://github.com/floooh/sokol/pull/1138 which
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Sokol

[**See what's new**](https://github.com/floooh/sokol/blob/master/CHANGELOG.md) (**17-Sep-2024** sokol_app.h: clipboard support for Linux)
[**See what's new**](https://github.com/floooh/sokol/blob/master/CHANGELOG.md) (**07-Nov-2024** sokol_gfx.h: the 'bindings cleanup' update

[![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)[![Dlang](https://github.com/kassane/sokol-d/actions/workflows/build.yml/badge.svg)](https://github.com/kassane/sokol-d/actions/workflows/build.yml)

Expand Down Expand Up @@ -155,8 +155,8 @@ static void init(void) {
.shader = sg_make_shader(triangle_shader_desc(sg_query_backend())),
.layout = {
.attrs = {
[ATTR_vs_position].format = SG_VERTEXFORMAT_FLOAT3,
[ATTR_vs_color0].format = SG_VERTEXFORMAT_FLOAT4
[ATTR_triangle_position].format = SG_VERTEXFORMAT_FLOAT3,
[ATTR_triangle_color0].format = SG_VERTEXFORMAT_FLOAT4
}
},
});
Expand Down
4 changes: 1 addition & 3 deletions bindgen/gen_d.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@
'sgl_error': 'sgl_get_error', # 'error' is reserved in Dlang
'sgl_deg': 'sgl_as_degrees',
'sgl_rad': 'sgl_as_radians',
'sg_context_desc.color_format': 'int',
'sg_context_desc.depth_format': 'int',
'sg_apply_uniforms.ub_index': 'uint32_t',
'sg_apply_uniforms.ub_slot': 'uint32_t',
'sg_draw.base_element': 'uint32_t',
'sg_draw.num_elements': 'uint32_t',
'sg_draw.num_instances': 'uint32_t',
Expand Down
9 changes: 1 addition & 8 deletions bindgen/gen_rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"type": "_type",
"ref": "_ref",

"sg_apply_uniforms.ub_index": "uintptr_t",
"sg_apply_uniforms.ub_slot": "uintptr_t",
"sg_draw.base_element": "uintptr_t",
"sg_draw.num_elements": "uintptr_t",
"sg_draw.num_instances": "uintptr_t",
Expand All @@ -83,13 +83,6 @@
"sapp_keycode::SAPP_KEYCODE_7": "SAPP_KEYCODE_NUM7",
"sapp_keycode::SAPP_KEYCODE_8": "SAPP_KEYCODE_NUM8",
"sapp_keycode::SAPP_KEYCODE_9": "SAPP_KEYCODE_NUM9",

# "sgl_error": "sgl_get_error", # 'error' is reserved in zig
# "sgl_deg": "sgl_as_degrees",
# "sgl_rad": "sgl_as_radians",
# "sg_context_desc.color_format": "int",
# "SGL_NO_ERROR": "SGL_ERROR_NO_ERROR",
# "sg_context_desc.depth_format": "int",
}

prim_types = {
Expand Down
2 changes: 1 addition & 1 deletion bindgen/gen_zig.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
'sgl_error': 'sgl_get_error', # 'error' is reserved in Zig
'sgl_deg': 'sgl_as_degrees',
'sgl_rad': 'sgl_as_radians',
'sg_apply_uniforms.ub_index': 'uint32_t',
'sg_apply_uniforms.ub_slot': 'uint32_t',
'sg_draw.base_element': 'uint32_t',
'sg_draw.num_elements': 'uint32_t',
'sg_draw.num_instances': 'uint32_t',
Expand Down
Loading