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

[vk] Migrate ash structs to builders #3409

Merged
merged 2 commits into from
Oct 18, 2020
Merged

[vk] Migrate ash structs to builders #3409

merged 2 commits into from
Oct 18, 2020

Conversation

str4d
Copy link
Contributor

@str4d str4d commented Oct 15, 2020

I didn't call builder methods for values that were clearly being set to their defaults in the struct. I did leave e.g. calls to *Flags::empty() and other non-obvious defaults, as well as any values that were default but marked as TODO.

PR checklist:

  • make succeeds (on *nix)
    • WSL doesn't have graphics drivers.
  • make reftests succeeds
    • I don't have make on Windows, so I manually ran cd src/warden && cargo run --bin reftest --features vulkan -- local
  • tested examples with the following backends: vulkan
    • Except mesh-shading (I didn't have that feature).

Excludes vk::WriteDescriptorSet due to the more complex way it is
constructed.
Copy link
Member

@kvark kvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an interesting pull request. Thank you for making it!
As usual with non-trivial PRs not linked to any issues, there comes a question of - what is the motivation for doing this?

One thing that's clearly a win is that we don't need to write vk::StructureType:: things in all the structs. This is an improvement.
On the other hand, builders hide the fields that we'd potentially want to set but not doing right now. Seeing let builder = ... builder.something(); in a few places is also technically worse than just modifying the structs.

In general, I think builders work best when used by a higher level logic. For example, by the user directly, or by an engine. In this case, they know what they need, and they leave everything else to be defaults. However, in gfx-rs case we pretty much want everything, so the builder makes less sense to use.

I just wanted to sync up on what you expect the outcomes to be from merging this.

depth_clamp_enable: if desc.rasterizer.depth_clamping {
this.rasterization_state = vk::PipelineRasterizationStateCreateInfo::builder()
.flags(vk::PipelineRasterizationStateCreateFlags::empty())
.depth_clamp_enable(if desc.rasterizer.depth_clamping {
if device.shared.features.contains(Features::DEPTH_CLAMP) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't really need to check for this, can just call depth_clamp_enable(desc.rasterizer.depth_clamping)

@str4d
Copy link
Contributor Author

str4d commented Oct 15, 2020

what is the motivation for doing this?

I'm attempting to add OpenXR support to the Vulkan backend (#3219), and I'm currently running into a problem at the top of Instance::enumerate_adapters where the OpenXR runtime is returning an RUNTIME_FAILURE error in the integration, but doesn't in the supposedly-equivalent code in the openxr crate's Vulkan example. I made these changes to gfx_backend_vulkan::Instance::create to reduce the differences between the two codebases (to make it easier to hunt down the issue).

I figured that the changes might be independently of interest, since I saw some existing places that gfx-backend-vulkan is using the ash builders (added in the last few months IIRC), and assumed that the reason for not using them was that they didn't exist three years ago when most of the code I touched was written. I don't have any particular motivation to get these changes merged; take what makes sense 🙂

@kvark
Copy link
Member

kvark commented Oct 15, 2020

Ok, I want to hear out if other members have opinions on this. Otherwise, we'll proceed (let's say, tomorrow)

@str4d
Copy link
Contributor Author

str4d commented Oct 17, 2020

Ooh, interesting development: my OpenXR diff crashes when based on master (specifically eeccf94, the parent of this branch), but does not crash when rebased on this branch. So there's maybe an actual bug being fixed by this PR...

p_application_info: &app_info,
enabled_layer_count: layers.len() as _,
pp_enabled_layer_names: str_pointers.as_ptr(),
enabled_extension_count: extensions.len() as _,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

False alarm. The bug was here: I was combining extensions with the set of extensions required by the OpenXR runtime, and didn't spot that the wrong length was being used here. The builder API "fixed" the bug because it takes a slice instead of a length+pointer, avoiding this kind of problem entirely.

@grovesNL
Copy link
Contributor

@kvark using the builders sounds alright to me 👍 I don't have much of a preference either way since the trade-offs seem pretty minor

Copy link
Member

@kvark kvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bors r+

@bors
Copy link
Contributor

bors bot commented Oct 18, 2020

@bors bors bot merged commit 4b3630f into gfx-rs:master Oct 18, 2020
@str4d str4d deleted the ash-builders branch October 18, 2020 03:03
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 this pull request may close these issues.

3 participants