Comments (12)
How did you measure it? I'm trying to finding the two best points to insert time measurements. For example, I've tried the following in the window example:
if let Some(drawable) = layer.next_drawable() {
let s = time::precise_time_ns();
....
let e = time::precise_time_ns();
println!("{:?}", e - s);
}
Then I get the following values:
1879944
898908
349323
249012
428890
584386
927518
1285250
826689
974424
397832
766317
408452
1542721
440585
which are too small and too variable to be vsynced. They should all be around 16666666 at 60Hz.
EDIT: Sorry, should have put the initial time measurement before the polling of events. When I do that, then I get a few values that are in the expected range, but the variability is much worse than what one finds with OpenGL. With Metal, I get a mean and std of ~8314262+/-7460716, which is far off, whereas with OpenGL, I get ~16571695+/-109656, which is getting close to perfect synchronization.
from metal-rs.
@rennis250 High Sierra has added an explicit displaySyncEnabled
property. I've not played with it so I'm not sure if it's on by default but it may be worth a shot. allowNextDrawableTimeout
might be related but there's no hint as to what they mean by that.
If you need high precision your best bet is probably to do an end-run around CAMetalLayer
entirely. macOS (and newer iOS) have an API-independent handle to a GPU-resident texture called IOSurface
that can be bound to a Metal texture. It's stable but almost entirely undocumented, however Chrome uses it and I've written a rough presentation system that uses it with Metal here. Note that you'd still need to use CVDisplayLink
to time the swapping of buffers (i.e. the present
function in the code I linked).
from metal-rs.
@JohnColanduoni and @fkaa are our main Metal experts, but they may not be fully responsive at this time.
From what I see in the docs, the method variant with afterMinimumDuration
parameter is only available on iOS 10.3 and tvOS 10.2. Are you trying to test it on a mac instead?
from metal-rs.
Oh, I should have taken a closer look. Well, that's disappointing... Thanks, though!
Hmm... I'll do a bit more searching, but I suppose that I will have to accept that there may be no decent Vsync for Metal on macOS for the time being.
from metal-rs.
from metal-rs.
As far as i can recall VSync is on by default on macOS, at least when I was working with it.
from metal-rs.
I took a look. Both GLFW’s and SDL’s vsync functionality is tied to OpenGL. I’m going to do a bit more searching.
from metal-rs.
Internally CAMetalLayer uses CVDisplayLink when VSync is enabled (which like @fkaa said appears to be by default). That at least used to be how Apple recommended OpenGL applications drive their render loops (see here) but that documentation is pretty outdated. It's possible you could get better results by registering a callback yourself and calling present:atTime:, but I've never tried it.
from metal-rs.
Thanks for that information. Doing a search for "CAMetalLayer CVDisplayLink" brought me to the following post, which seems to say that you need to explicitly ask for a CVDisplayLinkRef when working with Metal:
I'm going to try implementing this and see how it works.
Best,
Rob
from metal-rs.
Wow, I just re-ran the example to see something and now it works. I didn't do anything with CVDisplayLink yet. I'm not sure what was going wrong before, although I wasn't getting too much sleep in the past days, so most likely an inability to remember where and how I was placing the time::precise_time_ns()
statements...
Now, I get ~16674287+/-408055 ns for the Metal example.
Sorry about that! Thanks again for the help. This is pretty exciting, since I've wanted to try Metal for a while. :) 👍
Best,
Rob
from metal-rs.
Although, just as a warning, vsync precision has become more than 2x worse in High Sierra and is above the threshold for the line of work that I do, so that's unfortunate. Vsync precision was great in tests on Sierra, provided that one disabled a few of the fancy window animations and such things.
from metal-rs.
Interesting. Thanks a lot for this. When I again have some free time, I'll try it out. 👍
from metal-rs.
Related Issues (20)
- Different behaviour using Metal with Swift in Xcode vs Rust HOT 2
- Incorrect buffer value in compute example HOT 2
- Export MTLAccelerationStructure
- computation performs slower than cpu version in benchmark HOT 3
- Including `metal-rs` on `cargo.toml` results in a compile error due to `cocoa` HOT 1
- trouble with xcode shader debugger locating source code HOT 1
- Question about mesh shaders HOT 3
- Updating version on crates.io HOT 3
- Can't create indirect command buffers
- `new_render_command_encoder` assumes the return value can never be NULL
- MPS Matrix Multiplication HOT 2
- UB in `new_texture` if `newTextureWithDescriptor` fails? HOT 3
- Kernel stops running when I click on another window. HOT 1
- Inconsistent Performance across runs HOT 4
- Discrepency between GPU timing and CPU timing HOT 3
- Example does not support the latest winit HOT 7
- How does one launch a 2D grid of threads using dispatch_threads? HOT 1
- Metal Compiler header file caching HOT 2
- raytracing example bugg HOT 1
- new_library_with_data is broken HOT 1
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 metal-rs.