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

Refactor getting/adding extension features to create a VkDevice with. #1013

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

asuessenbach
Copy link
Contributor

@asuessenbach asuessenbach commented Apr 3, 2024

Description

As described in #938, requesting and enabling extension features is currently incorrect. With this PR, this is done similar to how it's done for the simple PhysicalDeviceFeatures: one function to get the supported bits (get_extension_features) and one to actually set them into the structure chain (add_extension_features).
The perfect handling would look like this:

if (gpu.get_extension_features<VkExtensionFeaturesStruct>(VK_STRUCTURE_TYPE_EXTENSION_FEATURES_STRUCT).featureBit)
{
	gpu.add_extension_features<VkExtensionFeaturesStruct>(VK_STRUCTURE_TYPE_EXTENSION_FEATURES_STRUCT).featureBit = VK_TRUE;
}
else
{
	// some fallback or error handling!
}

To ease usage, [HPP]PhysicalDevice got two new template functions: request_optional_feature and request_required_feature, which log a message or throw an exception, respectively, if the requested feature is not supported.
To ease usage even more, some macros have been added, so that requesting a required feature would now look like

REQUEST_REQUIRED_FEATURE(gpu, VkExtensionFeaturesStruct, VK_STRUCTURE_TYPE_EXTENSION_FEATURES_STRUCT, featureBit);

Build tested on Win10 with VS2022. Run tested on Win10 with NVidia GPU.

Fixes #938

General Checklist:

Please ensure the following points are checked:

  • My code follows the coding style
  • I have reviewed file licenses
  • I have commented any added functions (in line with Doxygen)
  • I have commented any code that could be hard to understand
  • My changes do not add any new compiler warnings
  • My changes do not add any new validation layer errors or warnings
  • I have used existing framework/helper functions where possible
  • My changes do not add any regressions
  • I have tested every sample to ensure everything runs correctly
  • This PR describes the scope and expected impact of the changes I am making

Note: The Samples CI runs a number of checks including:

  • I have updated the header Copyright to reflect the current year (CI build will fail if Copyright is out of date)
  • My changes build on Windows, Linux, macOS and Android. Otherwise I have documented any exceptions

Sample Checklist

If your PR contains a new or modified sample, these further checks must be carried out in addition to the General Checklist:

  • I have tested the sample on at least one compliant Vulkan implementation
  • If the sample is vendor-specific, I have tagged it appropriately
  • I have stated on what implementation the sample has been tested so that others can test on different implementations and platforms
  • Any dependent assets have been merged and published in downstream modules
  • For new samples, I have added a paragraph with a summary to the appropriate chapter in the readme of the folder that the sample belongs to e.g. api samples readme
  • For new samples, I have added a tutorial README.md file to guide users through what they need to know to implement code using this feature. For example, see conditional_rendering
  • For new samples, I have added a link to the Antora navigation so that the sample will be listed at the Vulkan documentation site

@asuessenbach asuessenbach force-pushed the extension_features branch 5 times, most recently from 37787b5 to a6ce335 Compare April 3, 2024 16:05
@asuessenbach asuessenbach marked this pull request as ready for review April 4, 2024 06:20
@asuessenbach asuessenbach requested a review from a team April 4, 2024 06:20
Copy link
Contributor

@gary-sweet gary-sweet left a comment

Choose a reason for hiding this comment

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

I don't think we can just assert in all these cases can we?
It seems to prevent batch mode from running as soon as it finds an unsupported case.

@asuessenbach
Copy link
Contributor Author

I don't think we can just assert in all these cases can we?

You're kind of right. As I stated in the Description above, that should be replaced by some meaningful error or fall-back handling.
What would you suggest to do instead until then?

@gary-sweet
Copy link
Contributor

What would you suggest to do instead until then?

Well throwing a std::runtime_error would be better, as it doesn't terminate batch mode, just the current sample I guess.

I'm also not really sure what was wrong with just having a single call to request_extension_features? I can't see why unrolling that code everywhere is better. Maybe I'm just missing the issue that's being solved here.

@asuessenbach
Copy link
Contributor Author

I'm also not really sure what was wrong with just having a single call to request_extension_features?

The problem, as described in #938, was, that currently you get the supported extension features bits, possibly set some of them to true, no matter if they are supported at all, and store that structure in the structure chain for device creation.
That is, there are two issues:

  • All supported flags are requested, no matter if you actually need/want the support of all those flags.
  • Potentially support of a not supported feature is requested.

With this PR, you just set the flags you're interested in and when they're supported at all.

@asuessenbach
Copy link
Contributor Author

Well throwing a std::runtime_error would be better, as it doesn't terminate batch mode, just the current sample I guess.

Sounds good. I can change that accordingly.

@asuessenbach asuessenbach force-pushed the extension_features branch 4 times, most recently from 1f300b9 to 309c259 Compare April 10, 2024 14:05
@gary-sweet
Copy link
Contributor

I think you'll need to rebase this over #1031. A lot of the samples don't run without that, so testing this isn't really possible without it.

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.

Requesting extension features also enables all available features
2 participants