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

GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS too low on my machine #1193

Closed
questor opened this issue Jan 20, 2025 · 7 comments
Closed

GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS too low on my machine #1193

questor opened this issue Jan 20, 2025 · 7 comments
Assignees

Comments

@questor
Copy link

questor commented Jan 20, 2025

Hi!
during setup of sokol-gfx the library tries to initialize the cache of the buffer bindings (in _sg_gl_cache_clear_buffer_bindings) and tries to assign a zero-ptr to all GL_SHADER_STORAGE_BUFFER indices, but the library tries to initialize 16 buffers (hard compiled into the library configuration with _SG_GL_MAX_SBUF_BINDINGS which is defined as:
#define _SG_GL_MAX_SBUF_BINDINGS (2 * SG_MAX_STORAGEBUFFER_BINDSLOTS)
which in turn is defined as:
SG_MAX_STORAGEBUFFER_BINDSLOTS = 8,
)

so the library tries to set 16 buffers, but my current machine (a linux-machine running under vmware) only supports 8 buffers in total:
GL_MAX_UNIFORM_BUFFER_BINDINGS: 84
GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS: 8 <------

so setting indices 8..15 result in glerrors which are catched after initialization of the cache.

I can workaround that initialization by clearing the error, but I'm not sure what that means for the library as a whole or if this needs broader handling or is this case only on a tiny subset of graphic drivers. If you need more infos just ping me.
-Kai

PS: LinuxMint reports the graphic drivers as "VMware SVGA II Adapter":
Graphics:
Device-1: VMware SVGA II Adapter driver:vmwgfx v: 2.20.0.0 ports:
API: EGL v:1.5 platforms: device: 0 drv: vmwgfx device: 1 drv: swrast
API: OpenGL v: 4.5 compat-v: 4.3 vendor: vmware v: N/A glx-v: 1.4

@floooh
Copy link
Owner

floooh commented Jan 20, 2025

Thanks for the headsup. This is mostly a sokol-gfx bug, because the max number of storage buffer bindings across all shader stages is indeed expected to be 8 (as indicated by SG_MAX_STORAGEBUFFER_BINDSLOTS).

But that could mean 8 bindings on one stage, on none on the other, that's where the 2x in the GL backend comes from... the tricky thing is that GLSL has separate bind spaces for each shader stage, and mapping those separate bind spaces (with 8 slots each) to a common bind space with 16 slots was the convenient thing to do (e.g. vertex shaders use bind slot 0..7, and fragment shader 8..15).

I actually need to think about a good solution. Worst-case (and trivial) solution would be to restrict the number of per-stage bindings to GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS / 2, but maybe I can come up with something better...

@questor
Copy link
Author

questor commented Jan 21, 2025

do you need the number of buffers for the other stages as well to get an overview of the capabilities? for the time beeing I can apply my workaround as I don't need a high number of buffers, currently I'm using very simple graphics so no hurry needed from my side.

@floooh
Copy link
Owner

floooh commented Jan 21, 2025

do you need the number of buffers for the other stages as well

Thanks but probbaly not, I think the rest of the GL backend is already either 'minspec compatible' or uses dynamic limits because of the WebGL2 support.

Btw, another less intrusive fix might be to just tell sokol_app.h to initialize a GL 4.1 context via sapp_desc.gl_minor/major_version (in case you use sokol_app.h), this info then trickles into sokol_gfx.h via sg_environment and disables any storage buffer related code in the GL backend. In that case you may also need to change your shaders to #version 410 though.

Or alternatively, just hardwire this line to = false:

sokol/sokol_gfx.h

Line 7856 in 0925b88

_sg.features.storage_buffer = version >= 430;

@floooh
Copy link
Owner

floooh commented Jan 21, 2025

Reminder to self: check if sokol-shdc just directly uses the input bindings [0..7] (that's how it should be) instead of remapping them to a [0..16] range.

@floooh
Copy link
Owner

floooh commented Jan 22, 2025

FYI I'll start working on that now but it also needs a sokol-shdc update, so it's a bit bigger than expected.

@floooh
Copy link
Owner

floooh commented Jan 22, 2025

Turns out that the sokol_gfx.h fix is actually very simple (https://github.com/floooh/sokol/pull/1196/files), and the bigger change is indeed in sokol-shdc (although still quite small: https://github.com/floooh/sokol-tools/pull/170/files).

I'll merge this tomorrow after combing the comments and documentation for outdated info.

Also, technically this is a breaking change, so I'll need to write a proper changelog entry :)

@floooh floooh closed this as completed in 363189b Jan 23, 2025
@floooh
Copy link
Owner

floooh commented Jan 23, 2025

Should be fixed now. See changelog: https://github.com/floooh/sokol/blob/master/CHANGELOG.md#23-jan-2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants