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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call Vec::set_len() after checking for Vulkan errors #684

Merged
merged 1 commit into from Nov 22, 2022

Conversation

MarijnS95
Copy link
Collaborator

The entire reason for calling unsafe set_len() after the Vulkan driver function call is to ensure the Vec never gives safe access to uninitialized values (as allocted via Vec::with_capacity()). This contract is broken within the implementation of these functions by temporarily setting a nonzero length when the Vulkan driver may not have initialized the underlying data at all, and communicated this by returning an error code.

Simply check the error code first, before jumping to a now-infallible codepath that calls .set_len() and always returns Ok().

TODO

We have to see what should happen in create_graphics_pipelines() and create_compute_pipelines() which always return the underlying Vec even on errors... 馃槹. Only do this if VK_PIPELINE_COMPILE_REQUIRED_EXT is returned (in addition to VK_SUCCESS), otherwise don't?

The entire reason for calling `unsafe` `set_len()` after the Vulkan
driver function call is to ensure the `Vec` never gives safe access to
uninitialized values (as allocted via `Vec::with_capacity()`).  This
contract is broken within the implementation of these functions by
temporarily setting a nonzero length when the Vulkan driver may not have
initialized the underlying data at all, and communicated this by
returning an error code.

Simply check the error code first, before jumping to a now-infallible
codepath that calls `.set_len()` and always returns `Ok()`.
@MarijnS95 MarijnS95 force-pushed the check-result-before-set_len branch 2 times, most recently from 989f684 to 8f22389 Compare November 22, 2022 00:27
@Ralith
Copy link
Collaborator

Ralith commented Nov 22, 2022

We have to see what should happen in create_graphics_pipelines() and create_compute_pipelines() which always return the underlying Vec even on errors

This is intended. See Multiple Pipeline Creation:

When an application attempts to create many pipelines in a single command, it is possible that some subset may fail creation. In that case, the corresponding entries in the pPipelines output array will be filled with VK_NULL_HANDLE values.

@MarijnS95
Copy link
Collaborator Author

@Ralith thanks, so if I understand correctly these functions will always initialize every entry of the array, even if one or more failed to create; good to know!

@MarijnS95 MarijnS95 merged commit 6ed9ba4 into master Nov 22, 2022
@MarijnS95 MarijnS95 deleted the check-result-before-set_len branch November 22, 2022 22:27
MarijnS95 added a commit that referenced this pull request Nov 22, 2022
The entire reason for calling `unsafe` `set_len()` after the Vulkan
driver function call is to ensure the `Vec` never gives safe access to
uninitialized values (as allocted via `Vec::with_capacity()`).  This
contract is broken within the implementation of these functions by
temporarily setting a nonzero length when the Vulkan driver may not have
initialized the underlying data at all, and communicated this by
returning an error code.

Simply check the error code first, before jumping to a now-infallible
codepath that calls `.set_len()` and always returns `Ok()`.
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.

None yet

2 participants