Skip to content

Commit

Permalink
Merge pull request #865 from floooh/sgfx-wgpu
Browse files Browse the repository at this point in the history
sokol-gfx: finalize wgpu backend
  • Loading branch information
floooh authored Oct 22, 2023
2 parents 31f3dfc + cf0df6b commit 2f1ccc0
Show file tree
Hide file tree
Showing 15 changed files with 3,788 additions and 2,587 deletions.
97 changes: 97 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,102 @@
## Updates

#### 21-Oct-2023

The major topic of this update is the 'finalized' WebGPU support in sokol_gfx.h and sokol_app.h.

- WebGPU samples are hosted here:

https://floooh.github.io/sokol-webgpu/

- WebGL2 samples remain hosted here:

https://floooh.github.io/sokol-html5/

- Please read the following blog post as introduction:

https://floooh.github.io/2023/10/16/sokol-webgpu.html

- ...and the changelog and updated documentation in the sokol-shdc repository:

https://github.com/floooh/sokol-tools

- You'll also need to update the sokol-shdc binaries:

https://github.com/floooh/sokol-tools-bin

- Please also read the following new or updated sections in the embedded sokol_gfx.h header documentation:

- `ON SHADER CREATION`
- `ON SG_IMAGESAMPLETYPE_UNFILTERABLE_FLOAT AND SG_SAMPLERTYPE_NONFILTERING`
- `WEBGPU CAVEATS`

Please do this especially when using any of the following texture pixel formats, as you will most likely encounter new validation layer errors:

- `SG_PIXELFORMAT_R32F`
- `SG_PIXELFORMAT_RG32F`
- `SG_PIXELFORMAT_RGBA32F`

- There is a tiny breaking change in the sokol_gfx.h API (only requires action when not using sokol-shdc):

- the following `sg_sampler_type` enum items have been renamed to better match their WebGPU counterparts:
- SG_SAMPLERTYPE_SAMPLE => SG_SAMPLERTYPE_FILTERING
- SG_SAMPLERTYPE_COMPARE => SG_SAMPLERTYPE_COMPARISON

- the enum `sg_image_sample_type` gained a new item:
- SG_IMAGESAMPLETYPE_UNFILTERABLE_FLOAT

- the enum `sg_sampler_type` gained a new item:
- SG_SAMPLERTYPE_NONFILTERING

- The sokol_gfx.h struct `sg_desc` has two new items:
- `.wgpu_bindgroups_cache_size` - must be power-of-2, default: 1024
- `.wgpu_disable_bindgroups_cache` - default: false

- sokol_gfx.h gained the following new public API functions to query per-frame information:
- `sg_frame_stats sg_query_frame_stats()`
- `void sg_enable_frame_stats(void)`
- `void sg_disable_frame_stats(void)`
- `bool sg_frame_stats_enabled(void)`

Frame statistics gathering is enabled after startup, but can be temporarily
disabled and enabled again via `sg_disable_frame_stats()` and `sg_enable_frame_stats`.

- The sokol_gfx.h validation layer has new validation checks in `sg_make_shader()`
regarding image/sampler pair compatibility (WebGPU is particularly strict about
this stuff).

- In sokol_app.h, the old wip WebGPU device and swapchain setup code is now implemented
in pure C code (previously this was a mix of Javascript and C).

- Also note that sokol_app.h currently only supports WebGPU in the Emscripten backend.
If you want to use sokol_gfx.h with the WebGPU backend in a native scenario, you'll have
to use a different window system glue library (like GLFW). The sokol-samples directory
has a handful of examples for using sokol_gfx.h + Dawn + GLFW.

- The following headers have been made compatible with the sokol_gfx.h WebGPU backend
(mainly by embedding WGSL shader code):
- sokol_debugtext.h
- sokol_fontstash.h
- sokol_gl.h
- sokol_spine.h
- sokol_imgui.h (also required some more changes for embedding `unfilterable-float`
textures, since these now require separate shader and pipeline objects)
- sokol_nuklear.h (works in WebGPU, but doesn't contain the work from sokol_imgui.h
to support `unfilterable-float` user textures)

- sokol_gfx_imgui.h gained a new function `sg_imgui_draw_menu()` which renders a
menu panel to show/hide all debug windows. Previously this had to be done
outside the header.

- sokol_gfx_imgui.h gained a new 'frame stats' window, which allows to peak into
sokol_gfx.h frame-rendering internals. This basically visualizes the struct
`sg_frame_stats` returned by the new sokol_gfx.h function `sg_query_frame_stats()`.

- The sokol-samples repository gained 3 new samples:
- cubemap-jpeg-sapp.c (load a cubemap from seperate JPEG files)
- cubemaprt-sapp.c (render into cubemap faces - this demo actually existed a while but wasn't "official" so far)
- drawcallperf-sapp.c (a sample to explore the performance overhead of sg_apply_bindings, sg_apply_uniforms and sg_draw)

#### 03-Oct-2023

- sokol_app.h win/gl: PR https://github.com/floooh/sokol/pull/886 has been merged, this makes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Simple
[STB-style](https://github.com/nothings/stb/blob/master/docs/stb_howto.txt)
cross-platform libraries for C and C++, written in C.

[**See what's new**](https://github.com/floooh/sokol/blob/master/CHANGELOG.md) (**25-Sep-2023** POTENTIALLY BREAKING: allocator callbacks have been renamed)
[**See what's new**](https://github.com/floooh/sokol/blob/master/CHANGELOG.md) (**21-Oct-2023** WebGPU!)

[![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
Loading

0 comments on commit 2f1ccc0

Please sign in to comment.