Comments (2)
Yes, the restriction exists to prevent lock-stalls where the CPU would be blocked until a buffer is no longer in use by the GPU. Some APIs provide internal buffer renaming (e.g. D3D's LockDiscard and LockNoOverwrite), but on OpenGL and especially WebGL it's more complicated (in OpenGL there are tricks like buffer orphaning, but none of this works in WebGL). Metal is yet another issue. So sokol-gfx does its own double-buffering (except on D3D11 where LOCK_DISCARD is used, so that D3D switches buffer under the hood itself). Each dynamic buffer is allocated twice, and while the CPU copies data to one buffer, the GPU uses the other one for rendering, and in the next frame roles are switched.
Removing the above check might work on OpenGL, but depending on the driver and OpenGL variant (GLES2, WebGL etc...) a CPU lock-stall will happen, and on Metal you'll most likely get rendering artefacts.
from sokol.
PS: there's a few ways to solve the issue, in your code you could have a buffer pool, which you initialize with different size buckets, for instance 16 buffer with room for 1024 vertices, 8 buffers room for 2048, etc... in spritebatch_end() you grab a buffer which is closest to the required size, and copy the data over. If there's no free buffer, create a new one. At the end of the frame, move all used buffers back into the free buckets.
The other option is to create one buffer with the max number of indexable vertices (64k for 16-bit indices), and a second memory buffer of the same size. Fill the memory buffer up during the frame, and keep a record where each sprite batch starts in the vertex/index buffer and the number of elements to render in that batch (don't render them yet in spritebatch_end(). At the end of the frame, have a spritebatches_draw(), which does one big buffer update copy, and renders all sprite batches in a loop. This is probably the most efficient way.
from sokol.
Related Issues (20)
- [sokol_app] Alt-tabbing issues on windows in a FPS game on a multi-monitor setup HOT 2
- D3D11 storage buffers do not compile on wine HOT 1
- Seems .c file not generated in bindgen, producing errors HOT 2
- test
- Sokol Fetch Http response 200 is reported as an error HOT 7
- [sokol_gfx d3d11] update_image is wrong for 3d textures HOT 10
- Offscreen with alpha background. Is it possible? HOT 4
- [webgpu] Bindgroups cache breaks down with init/uninit pattern.
- macOS huge memory usage when window minimized HOT 1
- Questions regarding default GL version HOT 5
- App Window Size on Android HOT 3
- Default value _sg_gl_uniform_t::gl_loc when uniform_desc's name isn't given in sokol_gfx HOT 1
- sokol_gfx.h: wrong define in log related to SOKOL_TRACE_HOOKS HOT 1
- WebGPU TextureView validation error HOT 6
- sokol_fetch on Android
- partial updates to buffers/textures (e.g. offset and size args to glBufferSubData, glTexSubImage) HOT 1
- Right shift is recognized as "invalid key" on Windows. HOT 9
- SAPP_EVENT_CHAR for Space is fired when Ctrl+Space is pressed. HOT 2
- Key events on Linux always use the **first** keyboard layout in the system's keyboard layout list. HOT 1
- Continuous Bind Slots Restriction Unnecessary? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sokol.