-
Notifications
You must be signed in to change notification settings - Fork 510
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
Miscellaneous features required by a game engine #342
Comments
Wow these are great changes! I'll just give some very quick feedback for now, but I think all of them should be considered for inclusion one way or another (either through PRs or I simply add them when I get around to it)
Excellent!
Also a great fix, but I'd make it configurable via sapp_desc (similar to the other sapp_desc.html5_* items that already exist)
This is a wonderful fix, I wasn't aware of the maximumFramesPerSecond UIScreen member yet! PS: we probably need something better than the current sapp_desc.swap_interval though, because a game that should run with 60fps on a 120Hz display shouldn't fall back to 30fps on a 60Hz display... there's also a separate related discussion about being able to disable vsync.
I was a bit hesitant to add the SRGB pixel formats because I had various problems in GL with them in the past, but I guess it makes sense to add them (my advice so far was to handle the SRGB conversion in the pixel shader as needed). ASTC: no objections of course :) Thanks for doing the cross-platform research!
I was considering this as a low-priority task. We need to make sure that the string pointer passed into D3D11 and Metal don't have to remain valid for the lifetime of the resources (otherwise we need to copy them into small buffers in the sokol-gfx resource structs, like I did in sokol_gfx_imgui.h)
At some time in the hopefully not-to-distant-future I want to overhaul the resource-updating functions in sokol-gfx completely, as this is currently the weakest part of the entire API IMHO. I've collected a few general ideas in my head while working on the Metal and WebGPU backends, but I need to get some order into that first... quick brain dump:
(when I write "API", I mean a group of functions, not a separate sokol header) |
This is actually pretty tricky from an API standpoint, for my use case something like
In my experience at least WebGL2 sRGB support is solid for sampling as a texture, though there might be mipmap weirdness I have dodged (https://twitter.com/won3d/status/1287047957544685569). Unfortunately I had to drop WebGL1 support so I haven't been able to test On the other hand rendering to sRGB framebuffers is super wonky on WebGL1/2 as you can't choose between linear/sRGB like you can on desktop using
My current implementation actually does support this, and I use dynamic resource names a lot! Only render passes need to keep the name cached in Sokol and I have (arbitrarily chosen) 64 character inline strings in the
The resource update overhaul sounds super useful! I'm not certain but it might be that WebGL1/GLES2 sadly doesn't support buffer copies. With buffer copies you could do partial buffer updates with staging resources in a neat way: void *data;
// This returns a buffer handle that doesn't need to be freed and is only valid for this frame
// Backends could linearly sub-allocate these out of larger buffers if possible.
// `data` is either mapped or temporarily allocated if it's not supported.
sg_buffer_t temp_buffer = sg_push_mapped_temp_buffer(&data, num_bytes);
write_data(data);
// This is either a no-op, unmap, or glBufferSubData() and free()
sg_commit_mapped_buffer(temp_buffer, data);
// sg_copy_buffer(dst_buffer, dst_offset, src_buffer, src_offset, num_bytes)
// As `temp_buffer` is uploaded to the GPU as well there's no risk for a stall here
// even if we're currently using `persistent_buffer` for rendering.
sg_copy_buffer(persistent_buffer, offset, temp_buffer, 0, num_bytes); You could also do something similar and still support WebGL1 like this: // WebGL1: No GPU resource, temporary CPU allocation
// WebGL2: Temporary GPU buffer (slice), temporary CPU allocation
// Other APIs: Temporary GPU buffer, mapped CPU pointer
void *data = sg_begin_buffer_update(num_bytes);
write_data(data);
// WebGL1: glBufferSubData(persistent) and hope the driver doesn't cause a stall
// WebGL2: glBufferSubData(temporary) glCopyBufferSubData(persistent, temporary)
// Other APIs: CopyBuffer(persistent, temporary)
sg_commit_buffer_update(persistent_buffer, offset, data); |
One more half-baked feature for consideration: I needed to reset the "key down" state when the user deactivates the window. Currently implemented using |
Hi, thanks for the amazing libraries! I've needed to add some small features here and there for my game project. Most of these probably don't fit your vision of the libraries (and that's totally fine!) but I thought I'd list them anyway. The implementations of these are not the most robust (yet) but have been tested on Windows D3D11/GLCORE33, Windows/MacOS/Linux Chrome/Firefox WebGL2, macOS Metal, iOS Metal. I can clean any of these up for PR or you can just yoink some code yourself if you're interested!
I've kept some
bqq_
namespacing in places to make merging with new versions of Sokol easier, just ignore those as they would be removed if integrated.sokol_fetch.h: CURL for HTTP(S) requests on non-web platforms
https://github.com/bqqbarbhg/spear/blob/6e5017491fe3d9c4ac667a3d96585ccd55f7bc8a/src/ext/sokol/sokol_fetch_impl.h#L1673-L2001
Handle requests with
http://
orhttps://
prefix using CURL. Initially I implemented support for it without requiring any build-time dependency on Windows by copy-pasting header bits and dynamically loading the functions withGetProcAddress()
. This still exists in the code but has some issues, and should probably be removed if integrated. TheSOKOL_CURL_STATIC
define requires the user to include a couple of CURL headers before the implementation inclusion (I guess they could be included bysokol_fetch.h
, at least optionally, if the feature is enabled).sokol_fetch.h: NSURLSession for HTTP(S) requests on Apple platforms
https://github.com/bqqbarbhg/spear/blob/6e5017491fe3d9c4ac667a3d96585ccd55f7bc8a/src/ext/sokol/sokol_fetch_impl.h#L2003-L2037
I gave up on getting CURL to work on iOS so I implemented the internal "CURL API" using
NSURLSession
if__APPLE__
is defined.sokol_app.h: Use high performance WebGL rendering context
https://github.com/bqqbarbhg/spear/blob/d59a2896afec32e22aadd1f544fada02f4a96e87/src/ext/sokol/sokol_app_impl.h#L2463-L2464
In my project I want to always request a high performance context so it's hard-coded to use
powerPreference
ofEM_WEBGL_POWER_PREFERENCE_HIGH_PERFORMANCE
. This could probably be a user-facing option insapp_desc
?sokol_app.h: Target actual screen frame rate on iOS
https://github.com/bqqbarbhg/spear/blob/d59a2896afec32e22aadd1f544fada02f4a96e87/src/ext/sokol/sokol_app_impl.h#L1606
Use
UIScreen.mainScreen.maximumFramesPerSecond
instead of fixed 60Hz to get 120Hz on iPad Pro. Again a hard-coded default but could be an option?sokol_gfx.h: Additional sampled texture formats
Additional texture formats, mostly just sRGB versions of existing ones. ASTC would have a lot more size options, but listing them all would add a ton of new formats.
D3D11
GLCORE33
GLES2
GLES3
METAL_MACOS
METAL_IOS
SG_PIXELFORMAT_BQQ_SRGBA8
SG_PIXELFORMAT_BQQ_BC1_SRGB
SG_PIXELFORMAT_BQQ_BC3_SRGB
SG_PIXELFORMAT_BQQ_BC7_SRGB
SG_PIXELFORMAT_BQQ_ASTC_4X4_RGBA
SG_PIXELFORMAT_BQQ_ASTC_4X4_SRGB
SG_PIXELFORMAT_BQQ_ASTC_8X8_RGBA
SG_PIXELFORMAT_BQQ_ASTC_8X8_SRGB
* Could be supported as Ext using
EXT_sRGB
which is pretty widely supported.sokol_gfx.h: Resource / render pass labels
Use
ID3D11*_SetPrivateData()
(D3D11) /.label =
(Metal) to name images and buffers. UseID3DUserDefinedAnnotation_Begin/EndEvent()
(D3D11) /.label =
(Metal) to tag render pass names. Could add support for GL debug names too, but I don't think WebGL supports them (well it doesn't have a debugger so it wouldn't really be useful).sokol_gfx.h: Update subimage of an existing image
https://github.com/bqqbarbhg/spear/blob/d59a2896afec32e22aadd1f544fada02f4a96e87/src/ext/sokol/sokol_gfx_impl.h#L10130-L10137
If an image is created with
bqq_copy_target
set totrue
indesc
you can later update regions of it usingsg_bqq_update_subimage()
. The implementation is not the most optimal, but in practice usingglTexSubImage2D()
/UpdateSubresource
/replaceRegion
seems not to stall the GPU.sokol_gfx.h: Copy image regions
https://github.com/bqqbarbhg/spear/blob/d59a2896afec32e22aadd1f544fada02f4a96e87/src/ext/sokol/sokol_gfx.h#L1612-L1632
This is a wild one, it allows you to copy regions of an image to another one on the GPU. Like the above extension it requires
bqq_copy_target
to be set for the destination image. The reason for the batch API is that setting up the copying requires some heavyweight setup on OpenGL and some on Metal. The function is a bit limited on GLES2 where you can only copy to the top-level mip of an image.The text was updated successfully, but these errors were encountered: