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. |
0d836a3 to
e134c44
Compare
|
Any additional opinion anyone? |
|
I've been thinking about this. I'm good with both ways of doing it. I know that's kind of a cop out. Sascha's preference and the current way we do it has the potential problem that it could be called from anywhere at anytime as the "customer" of the API (framework) has control over when those calls are made. In Andreas' version, the Framework has control, it is mandatory how it's called and when in the setup. There's no ambiguity about it. However, if we're telling people that the samples are the best practices that people should try to replicate; then it absolutely is a good idea to demonstrate good architecture design of the API we choose to use ourselves. Thus, I think I'd slightly favor refactoring. Even though that argument does fall flat in the face of there's plenty of other instances that are much more egregious to proper architecture than this lone example and thus, we shouldn't really worry too much about it. |
d294eea to
b4bdf46
Compare
b4bdf46 to
09293a8
Compare
gpx1000
left a comment
There was a problem hiding this comment.
I'm fine with these changes as noted in my earlier review. I think this is best practice architecture; however, I'm still okay if we decide to not take this. However, mechanically, this is a PR that is proper to receive a thumb up from me.
|
This doesn't run for me, batch mode immediately spits out this for example: |
|
Great catch! |
SaschaWillems
left a comment
There was a problem hiding this comment.
As discussed on the last call I'm okay with this.
Did a full batch run on Win11 + RTX 4070 with the latest developer driver and saw no crashes or validation errors outside of those already known and not caused by this PR.
Correct, no GLFW on our platform. The samples work fine now though. Thanks |
|
3 approvals - merging |
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: