-
Notifications
You must be signed in to change notification settings - Fork 781
Refactor instance creation #1455
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
base: main
Are you sure you want to change the base?
Refactor instance creation #1455
Conversation
3f8e331 to
ee9b7f5
Compare
|
Not sure about this :/ Probably a personal preference, but I prefer the old way over this. This is kinda odd to read (and write) and having instance and device creation getting setup in two very different ways feels somewhat unnatural. |
Sure. I had planned to adjust the device creation accordingly, if this approach would be approved.
Could you elaborate a bit more on this? What is odd? |
0ebcf3a to
c3994de
Compare
|
As for the odd part, I personally find this: add_instance_extension(VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME);
add_instance_extension(VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME);
add_instance_extension(VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME);Easier to write, easier to read and easier to remember than this: void OpenCLInterop::request_instance_extensions(std::unordered_map<std::string, vkb::RequestMode> &requested_extensions) const
{
ApiVulkanSample::request_instance_extensions(requested_extensions);
requested_extensions[VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME] = vkb::RequestMode::Required;
requested_extensions[VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME] = vkb::RequestMode::Required;
requested_extensions[VK_KHR_EXTERNAL_FENCE_CAPABILITIES_EXTENSION_NAME] = vkb::RequestMode::Required;
}Interestingly I've been undoing similar constructs like these in my samples to make them easier to maintain and to follow. Maybe that's because I'm a mostly pragmatic programmer trying to keep code as simple as possible, esp. when writing code that people should learn from ;) |
|
I personally find it more clear and easier to understand, if there's one function (e.g. But if it's consensus to keep the add/set functions and to not introduce those virtual functions, I could revert that part of this PR. |
94fddec to
0d836a3
Compare
0d836a3 to
e134c44
Compare
|
Any additional opinion anyone? |
Description
This is a suggestion on how the instance creation could be simplified.
The main goal was to move all the application specific logic out of
vkb::core::Instanceintovkb::VulkanSampleand the sample specific code.This means that the
vkb::core::Instanceconstructor now only receives the data that is to be used for the actual instantiation and checks its validity. As the structures chained into thevk::InstanceCreateInfoviapNextmight depend on the actually enabled layers or extensions, it also takes a function to determine those structures.In
vkb::VulkanSample::create_instance, a couple of virtual functions are called (get_name,get_api_version,request_layers,request_instance_extension) or provided (get_instance_create_info_extensions) to actually get the data needed to instantiate thatvkb::core::Instance. The default implementations invkb::VulkanSamplefit to the needs of most samples, and some samples override some of them for special needs. Those virtual functions replace some calls previously done in the samples constructor or prepare function.To summarize, this MR makes more clear when and where data needed for vkb::core::Instance creation is provided by the samples.
Build tested on Win11 with VS2022. Run tested on Win10 with NVidia GPU.
General Checklist:
Please ensure the following points are checked:
Note: The Samples CI runs a number of checks including:
If this PR contains framework changes:
batchcommand line argument to make sure all samples still work properlySample Checklist
If your PR contains a new or modified sample, these further checks must be carried out in addition to the General Checklist: