Closed Pixel300 closed 1 week ago
How are you creating the surface?
Heres how im creating my surface:
//Main File
let mut window = video_subsystem
.window("Test Window", 812, 420)
.vulkan()
.position_centered()
.resizable()
.build()
.unwrap();
//Instance code above
let surface = unsafe { sdl2_to_surface(instance.clone(), &window) };
// Surface File
pub unsafe fn sdl2_to_surface(instance: Arc<Instance>, window: &Window) -> Result<Arc<Surface>, ErrorType> {
let wayland_or_x11: &str = &env::var("XDG_SESSION_TYPE").unwrap();
if wayland_or_x11 == "x11" {
let display = wm_info.info.x11.display;
let window = wm_info.info.x11.window;
return Ok(Surface::from_xlib(instance, display, window, None).unwrap());
} else if wayland_or_x11 == "wayland" {
let display = wm_info.info.wl.display;
let surface = wm_info.info.wl.surface;
return Ok(Surface::from_wayland(instance, display, surface, None).unwrap());
}
return Err(ErrorType::UnknownUnix);
}
EDIT: Maybe this will help? (Surface Capabilities)
SurfaceCapabilities { min_image_count: 2, max_image_count: Some(8), current_extent: None, min_image_extent: [1, 1], max_image_extent: [16384, 16384], max_image_array_layers: 1, supported_transforms: IDENTITY, current_transform: Identity, supported_composite_alpha: INHERIT, supported_usage_flags: TRANSFER_SRC | TRANSFER_DST | SAMPLED | STORAGE | COLOR_ATTACHMENT | INPUT_ATTACHMENT, compatible_present_modes: [], supported_present_scaling: empty(), supported_present_gravity: [empty(), empty()], min_scaled_image_extent: Some([1, 1]), max_scaled_image_extent: Some([16384, 16384]), supports_protected: false, full_screen_exclusive_supported: false }
I don't think that's sound. SDL doesn't determine whether it uses X11 or Wayland based on a single enviroment variable. SDL_SysWMinfo
has a field called subsystem
which tells you which video driver is in use. If you don't follow this, you could be reading garbage when accessing the x11
or wl
union fields. They are not struct fields (which is why they are unsafe to access).
Much more importantly however, I wouldn't be using an example that has been outdated for 7 years. The example for using the sdl2 crate together with vulkano can be found right in their readme. In today's day and age we have the raw-window-handle crate which serves as the bridging point between any windowing library and any graphics library. Note that this requires sdl2 0.36 and vulkano 0.34 or the version of raw-window-handle that they both use won't match up. Doing this manually like you're trying requires a lot of tricky-to-get-right unsafe code. So while my suggestion likely won't fix your issue immediately, it will reduce the unsafe code to a single line (Surface::from_window_ref
), which eliminates a lot of factors.
Thank you! That fixed it for me! However i'm getting another error that I can't wrap my head around.
X Error of failed request: BadWindow (invalid Window parameter) Major opcode of failed request: 3 (X_GetWindowAttributes) Resource id in failed request: 0x2200002 Serial number of failed request: 309 Current serial number in output stream: 310
Swapchain creation works now. So I wonder whats happening with this error?
And you have removed your use of unsafe code and replaced it with Surface::from_window_ref
?
I tried that it does not work. Surface::from_window_ref
is still unsafe code and I get the same error. Thank you for the suggestion.
I even tried Surface::from_window as well.
let surface = unsafe { Surface::from_window_ref(instance.clone(), &window) };
Yes that function is unsafe, but the point is that this function has a single unsafe precondition, unlike the heaps of unsafe that you would have otherwise. So assuming you're following this one single precondition, and there's no other unsafe code in your application, it means your code is not at fault. At least, that's the promise of safe Rust and the purpose of isolating unsafe code.
So is it SDL2's fault?
I did some more testing if I remove the code that recreates the swapchain I don't get any error. If I keep the code in my program it works just fine for 2 loops and on the 3rd loop it crashes.
I couldn't tell you. I've never seen that error and don't even know if it's coming from SDL2 itself, X11, or the video driver.
Alright, I will try and debug it further. Hopefully I can get my code to work. Thank you for your time and help.
I have one last question, have you seen this before?
thread 'main' panicked at src/Output/Window/mod.rs:446:24:
called `Result::unwrap()` on an `Err` value: a validation error occurred
Caused by:
`PhysicalDevice::surface_capabilities` returned an error
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
(I switched to integrated intel GPU)
What I can tell you is that the following code works for me on X11 and NVIDIA:
If this exact code does not work for you, then I would first look toward your system configuration or environment in which you're running the app. From what I've gathered you seem to be forcing the app to run under Xwayland for this testing, and I suspect the way you're doing that might have something to do with it.
Seriously thank you. Your code works.
I found the real reason my code does not work is i'm using canvas in SDL2. If I remove that my code works!
Thank you! You solved my issue!
Great to hear.
My issue is i'm trying to set up and remake the swapchain. I have no idea what i'm doing wrong. I have never really dealt with a segmentation fault error on wayland before and I followed the tutorials. On x11 the swapchain get's created successfully but recreating it does not work. It just crashes.
Tutorial I'm Following -->: https://github.com/dariost/vulkano-sdl2/blob/master/examples/triangle.rs
If anyone is willing to help that would be very nice. Thank you for your time.