-
Notifications
You must be signed in to change notification settings - Fork 12
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
Black Screen #15
Comments
Hey, Thanks for reporting the issue. I'm afraid I can not test on MacOS myself. Could you perhabs modify one of the examples to enable logging and post the result? If you're not sure exactly how to do that, I can help with that. |
The main branch now uses env_logger in the examples. This means you can use Could you try it and share the output? |
Hi, I have just experienced the same issue, also on macOS Big Sur. This is the output when opening an image and then scrolling:
|
After poking around a bit, I think the problem is how the transform matrix is transferred to the vertex shader. (Maybe because macOS, unlike other platforms, uses Metal). The scale value ends up in However I could not figure out why the matrix is messed up like that. (Printing the value from the CPU side returns a correct looking matrix) |
Interesting, that's very useful information. It would have taken a while before I would start suspecting that the transformation. I will have to investigate more, but maybe metal has different padding on matrices. You could try playing with the alignment values here: show-image-rs/src/backend/window.rs Line 545 in 28c941d
Maybe just remove the alignas to remove all internal padding in the matrix. If that turns out to be the problem, we'll have to pass the matrix in a more portable form. |
I have suspected the alignment to be a problem as well, as the metal specifications say that float3x2 (which should be the mat3x2 equivalent) is 8 byte aligned by default. (https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf, page 28). Simply changing the Mat3x2 struct to use Vec2A8 or setting Vec2A16 to be
This makes me think that the spir-v shader specifies 16 byte alignment, but the metal translation layer of wgpu somehow does not correctly handle this. When using naga (the shader cross-compiler from wgpu) to convert the spir-v to metal it does indeed give an incorrect format for the uniform buffer: struct WindowUniforms {
metal::float3x2 transform;
char _pad1[24];
metal::float2 image_size;
}; I'll open an issue for naga Edit: There is ongoing discussion about incorrect matrix strides at naga here: gfx-rs/naga#1400 |
Hmm, I wonder if this can be easily solved by naga. Maybe they can tell metal it's a 3x3 matrix and inject code to slice it into a 2x3 when used. In the mean time, a simple solution for |
I have just figured out it's possible to use std430 alignment in the current glsl shader which emits 8 byte alignment in the spirv. Together with changing Mat3x2 to use Vec2A8 this works for me. Unfortunately I can't validate this solution with anything else than Metal right now, but I'll submit it as a PR. |
Hmm, I'm a little worried that std430 layout may not work for all older systems. I'm not 100% sure any-more, but I think I had a laptop that didn't support it. If std430 is widely supported on older hardware too, then it sounds good. But otherwise I would prefer to go with a mat3x3. |
You might be right on that one. Naga seems to ignore the MatrixStride when outputting GLSL as well, so this might break the OpenGL backend |
Fixed by #17 and released as 0.9.4 🚀 Thank again @xanecs for debugging and fixing this, and @jeffreyrosenbluth for reporting it :) |
When running examples, the window only contains solid black, no image.
MacOS Big Sur
iMac Pro 2017
The text was updated successfully, but these errors were encountered: