Comments (7)
On GL, measuring performance by putting start/stop timer code around GL function calls is generally tricky, because it's unpredictable where GL might decide to 'flush the pipeline'.
I wrote a drawcall-overhead testing tool recently in the wip webgpu branch (not yet in master):
https://floooh.github.io/sokol-html5/drawcallperf-sapp.html
...idea is that you can roughly see at what point (== number of draw calls) the render loop is no longer able to hit the target frame rate. This "no longer able to hit target frame rate" gives a good idea of the CPU overhead in different backend APIs for specific rendering code.
Source code for this is here: https://github.com/floooh/sokol-samples/blob/sgfx-wgpu/sapp/drawcallperf-sapp.c
If I'm looking for specific peformance hotspots, I use CPU profilers like Instruments on macOS.
I think the Metal debugger in Xcode can also provide some performance numbers.
from sokol.
IIRC this topic came up in another ticket as well. The sokol_gfx.h Metal backend does the frame synchronization in the first begin-pass of a frame here:
Line 11550 in b803c9a
E.g. at some point, sokol_gfx.h needs to wait for 'inflight resources' to become available again, and in the Metal backend there are two points where this might happen, either in that 'dispatch_semaphore_wait' call, or in sg_commit()
where a new swapchain drawable is requested:
Lines 11715 to 11719 in b803c9a
(I guess that when the begin-pass flips to being 'fast', then sg_commit() flips to being 'slow').
TL;DR: at some point in the frame sokol-gfx needs to synchronize with vsync, and this is what you are seeing. If you add more render workload (so that the actual rendering takes longer), than this waiting period you're seeing should also decrease.
from sokol.
Here's that other ticket (that was GL on Linux, but all backends needs to wait for vsync somewhere, in GL it's just much less predictable where exactly that wait happens):
from sokol.
Oh I understand it, thanks for your detailed explanation! next question, If I want to measure how much time my code costs in every frame,I should not include sg_commit or sg_begin_default_pass?
And I want to profile sokol metal vs opengl performance on iphone and mac, I wonder is there has some benchmark sample stuff? If no, could you please give me some suggestions?
from sokol.
I noticed drawcallperf sample. I ran that sample and found metal has much more performance than opengl on mac.
Is the test result means metal is that faster than GL?
Thank you for your advice, I'll try to use these tools.
from sokol.
Yeah, on Mac you're definitely better off with the Metal backend. Apple's OpenGL implementation is only what's minimally needed for backward compatibility with older applications.
I'll close this ticket btw :)
from sokol.
PS: also, when testing peformance, make sure the Metal validation layer is disabled (for instance it is enabled when starting in debug mode within Xcode), the validation layer easily cuts peformance by 10x.
from sokol.
Related Issues (20)
- [sokol_imgui] Manage ImDrawCallback_ResetRenderState HOT 3
- [sokol_gfx] Array of struct uniform HOT 1
- WebGPU samples currently broken. HOT 1
- Regression: swapchains with depth (not depth/stencil) buffers currently broken in Metal. HOT 2
- [sokol_app] A call to GetIntegerv in _sapp_wgl_create_context leaves the stack corrupted HOT 8
- Dear ImGui touch input broken on mobile browsers HOT 11
- sokol_app.h html5: event bubbling followup fixes... HOT 1
- Ability to label command encoders HOT 8
- Possible bug in #define _SAPP_CLEAR_ARC_STRUCT(type, item) HOT 1
- Difference between sokol_app events `KEY_DOWN` and `CHAR` HOT 4
- WebGL2: Emsdk 3.1.52 no longer enables ETC2 and ASTC extensions by default. HOT 1
- Redundant buffer bindings on metal when only changing vertex buffer offset
- Use retained command buffer in sokol_gfx HOT 4
- sokol_app.h: Resize callback is never unregistered giving javascript errors HOT 3
- Mutliple `sg_apply_uniforms` in a pipeline influence other render target HOT 4
- fullscreen working every other time on gnome HOT 1
- Can't Set Float Uniform Variable HOT 3
- WebGPU backend broke in sg_make_pipeline() HOT 1
- [sokol_app] Status of clipboard support on X11? HOT 2
- The WebGL renderer does not produce the same output as the GLES renderer after updating to samplers. HOT 23
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.