Skip to content
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

flip_y_requires_shift #238

Closed
EriKWDev opened this issue Dec 27, 2024 · 2 comments · Fixed by #239
Closed

flip_y_requires_shift #238

EriKWDev opened this issue Dec 27, 2024 · 2 comments · Fixed by #239

Comments

@EriKWDev
Copy link
Contributor

EriKWDev commented Dec 27, 2024

I have just spent a some time debugging why my set_viewport calls seem to cause inconsistent behaviour between metal on macos and my vulkan linux. After some investigation into wgpu-hal and blade, I found a difference in how viewports are created.

In blade, the viewport in vulkan always has the y set to the height upon starting a render

/// blade:s begin_render
let viewport = vk::Viewport {
    x: 0.0,
    y: target_size[1] as f32, // AHA! Missed this.. We shift it here already
    width: target_size[0] as f32,
    height: -(target_size[1] as f32),
    min_depth: 0.0,
    max_depth: 1.0,
};

but wgpu-hal sometimes has it set to 0

/// wgpu-hal:s, begin_render
let vk_viewports = [vk::Viewport {
    x: 0.0,
    y: if self.device.private_caps.flip_y_requires_shift {
        desc.extent.height as f32
    } else {
        0.0
    },
    width: desc.extent.width as f32,
    height: -(desc.extent.height as f32),
    min_depth: 0.0,
    max_depth: 1.0,
}];
let vk_viewports = [vk::Viewport {
    x: rect.x,
    y: if self.device.private_caps.flip_y_requires_shift {
        rect.y + rect.h // shift is applied..
    } else {
        rect.y
    },
    width: rect.w,
    height: -rect.h, // flip Y
    min_depth: depth_range.start,
    max_depth: depth_range.end,
}];

In wgpu-hal vulkan/mod.rs they state:

struct PrivateCapabilities {
    /// Y-flipping is implemented with either `VK_AMD_negative_viewport_height` or `VK_KHR_maintenance1`/1.1+. The AMD extension for negative viewport height does not require a Y shift.
    ///
    /// This flag is `true` if the device has `VK_KHR_maintenance1`/1.1+ and `false` otherwise (i.e. in the case of `VK_AMD_negative_viewport_height`).
    flip_y_requires_shift: bool,
    // ..
}
@EriKWDev
Copy link
Contributor Author

perhaps a throwback, but here was a PR that introduced the flip_y_requires_shift flag in gfx instead of the maintenance_level: u8

gfx-rs/gfx#3624

@EriKWDev
Copy link
Contributor Author

EriKWDev commented Dec 27, 2024

Do I understand it correctly that since blade requires vulkan be >= API_VERSION_1_1, and always has a flipped y, blade should always set the viewport:s y to rect.y + rect.h?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant