-
Notifications
You must be signed in to change notification settings - Fork 652
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 ext shader object optional layer #780
base: main
Are you sure you want to change the base?
Changes from all commits
89d6fe8
c76194e
2b0356d
53482ab
a86f7d2
fb01dcf
33bdc15
ad8e78c
9290b5f
d1cb82d
892f289
48d8b14
e92bdb0
3b73db8
d2b132c
27e35ba
709d7de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,41 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL debug_callback(VkDebugReportFlagsEXT flags | |
} | ||
#endif | ||
|
||
bool validate_layers(std::unordered_map<const char *, bool> &required, | ||
const std::vector<vk::LayerProperties> &available) | ||
{ | ||
std::vector<const char *> remove_vec; | ||
for (auto layer : required) | ||
{ | ||
bool found = false; | ||
for (auto &available_layer : available) | ||
{ | ||
if (strcmp(available_layer.layerName, layer.first) == 0) | ||
{ | ||
found = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!found) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can replace the loop over the |
||
{ | ||
if (!layer.second) | ||
{ | ||
LOGW("Optional Layer {} not found, removing it", layer.first) | ||
remove_vec.push_back(layer.first); | ||
continue; | ||
} | ||
LOGE("Validation Layer {} not found", layer.first) | ||
return false; | ||
} | ||
} | ||
for (auto &rem : remove_vec) | ||
{ | ||
required.erase(rem); | ||
} | ||
return true; | ||
} | ||
|
||
bool validate_layers(const std::vector<const char *> &required, | ||
const std::vector<vk::LayerProperties> &available) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case, you want to change a little more, this version of
|
||
|
@@ -186,6 +221,7 @@ bool enable_all_extensions(const std::vector<const char *> required_ | |
HPPInstance::HPPInstance(const std::string &application_name, | ||
const std::unordered_map<const char *, bool> &required_extensions, | ||
const std::vector<const char *> &required_validation_layers, | ||
const std::unordered_map<const char *, bool> &requested_layers, | ||
bool headless, | ||
uint32_t api_version) | ||
{ | ||
|
@@ -299,6 +335,20 @@ HPPInstance::HPPInstance(const std::string &applicati | |
throw std::runtime_error("Required validation layers are missing."); | ||
} | ||
|
||
std::unordered_map<const char *, bool> layers = (std::unordered_map<const char *, bool>) (requested_layers); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. |
||
if (validate_layers(layers, supported_validation_layers)) | ||
{ | ||
LOGI("Enabled Validation Layers:") | ||
for (const auto &layer : layers) | ||
{ | ||
LOGI(" \t{}", layer.first); | ||
} | ||
} | ||
else | ||
{ | ||
throw std::runtime_error("Required validation layers are missing."); | ||
} | ||
|
||
vk::ApplicationInfo app_info(application_name.c_str(), 0, "Vulkan Samples", 0, api_version); | ||
|
||
vk::InstanceCreateInfo instance_info({}, &app_info, requested_validation_layers, enabled_extensions); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,41 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL debug_callback(VkDebugReportFlagsEXT flags | |
} | ||
#endif | ||
|
||
bool validate_layers(std::unordered_map<const char *, bool> &required, | ||
const std::vector<VkLayerProperties> &available) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same comments as for hpp_instance.cpp hold here. |
||
{ | ||
std::vector<const char *> remove_vec; | ||
for (auto layer : required) | ||
{ | ||
bool found = false; | ||
for (auto &available_layer : available) | ||
{ | ||
if (strcmp(available_layer.layerName, layer.first) == 0) | ||
{ | ||
found = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!found) | ||
{ | ||
if (!layer.second) | ||
{ | ||
LOGW("Optional Layer {} not found, removing it", layer.first) | ||
remove_vec.push_back(layer.first); | ||
continue; | ||
} | ||
LOGE("Validation Layer {} not found", layer.first) | ||
return false; | ||
} | ||
} | ||
for (auto &rem : remove_vec) | ||
{ | ||
required.erase(rem); | ||
} | ||
return true; | ||
} | ||
|
||
bool validate_layers(const std::vector<const char *> &required, | ||
const std::vector<VkLayerProperties> &available) | ||
{ | ||
|
@@ -186,6 +221,7 @@ bool enable_all_extensions(const std::vector<const char *> required_ex | |
Instance::Instance(const std::string &application_name, | ||
const std::unordered_map<const char *, bool> &required_extensions, | ||
const std::vector<const char *> &required_validation_layers, | ||
const std::unordered_map<const char *, bool> &requested_layers, | ||
bool headless, | ||
uint32_t api_version) | ||
{ | ||
|
@@ -311,6 +347,20 @@ Instance::Instance(const std::string &application_nam | |
throw std::runtime_error("Required validation layers are missing."); | ||
} | ||
|
||
std::unordered_map<const char *, bool> layers = (std::unordered_map<const char *, bool>) (requested_layers); | ||
if (validate_layers(layers, supported_validation_layers)) | ||
{ | ||
LOGI("Enabled Validation Layers:") | ||
for (const auto &layer : layers) | ||
{ | ||
LOGI(" \t{}", layer.first); | ||
} | ||
} | ||
else | ||
{ | ||
throw std::runtime_error("Required validation layers are missing."); | ||
} | ||
|
||
VkApplicationInfo app_info{VK_STRUCTURE_TYPE_APPLICATION_INFO}; | ||
|
||
app_info.pApplicationName = application_name.c_str(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
//// | ||
- Copyright 2023 Nintendo | ||
- Copyright 2024 Nintendo | ||
- | ||
- Licensed under the Apache License, Version 2.0 (the "License"); | ||
- you may not use this file except in compliance with the License. | ||
|
@@ -436,13 +436,15 @@ The layer can be shipped with your application, and it will disable itself if a | |
The emulation layer can be enabled by adding `VK_LAYER_KHRONOS_shader_object` to `ppEnabledLayerNames` in `VkDeviceCreateInfo`. | ||
|
||
The sample framework already has an existing abstraction normally used for enabling the validation layer. | ||
This sample repurposes this mechanism to instead load the emulation layer. | ||
This | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Newline here? Besides that, is that description still valid? We now have some |
||
sample repurposes this mechanism to instead load the emulation layer. NB: the layer is set to be optional as that's | ||
what the false does. | ||
|
||
[,CPP] | ||
---- | ||
const std::vector<const char *> ShaderObject::get_validation_layers() | ||
const std::unordered_map<const char *, bool> ShaderObject::get_validation_layers() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no |
||
{ | ||
return {"VK_LAYER_KHRONOS_shader_object"}; | ||
return {"VK_LAYER_KHRONOS_shader_object", false}; | ||
} | ||
---- | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,9 @@ ShaderObject::ShaderObject() | |
|
||
// Enable extensions for sample | ||
add_device_extension(VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME); | ||
|
||
// Enable the shader object layer if it's available. Its optional. | ||
add_layer("VK_LAYER_KHRONOS_shader_object", false); | ||
} | ||
|
||
ShaderObject::~ShaderObject() | ||
|
@@ -105,13 +108,6 @@ ShaderObject::~ShaderObject() | |
} | ||
} | ||
|
||
// Currently the sample calls through this function in order to get the list of any instance layers, not just validation layers. | ||
// This is not suitable for a real application implementation using the layer, the layer will need to be shipped with the application. | ||
const std::vector<const char *> ShaderObject::get_validation_layers() | ||
{ | ||
return {"VK_LAYER_KHRONOS_shader_object"}; | ||
} | ||
|
||
bool ShaderObject::resize(const uint32_t _width, const uint32_t _height) | ||
{ | ||
if (!has_device()) | ||
|
@@ -229,6 +225,11 @@ void ShaderObject::setup_framebuffer() | |
// Create render pass for UI drawing | ||
void ShaderObject::setup_render_pass() | ||
{ | ||
// delete existing render pass | ||
if (render_pass != VK_NULL_HANDLE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @asuessenbach , per discussion today, can you open an issue so we don't lose the context? We're going to merge this one soon w/o capturing this - but want to circle back later There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I missed the meeting where this was discussed... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea is to fix this after this PR has been merged. The PR is kinda urgent, and the line you highlighted is not new to the PR but already present in the base sample. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SaschaWillems so it seems, you know about the issue to be resolved later. Would you be so kind and file that issue, instead of me guessing what's meant to be done here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I was under the impression that this change was already present beforehand. But as this code is new to this PR you're right to mention this and it indeed needs fixing in this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did this change because renderpass was being created by the vulkansample in the framework automatically. I can take this change out, but then validation layers correctly identifies a render_pass object not getting released. The rest of the changes are updated to conform with your requests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. We should keep that change then :) |
||
{ | ||
vkDestroyRenderPass(get_device().get_handle(), render_pass, VK_NULL_HANDLE); | ||
} | ||
VkAttachmentDescription color_attachment{}; | ||
|
||
// Color attachment set to load color and ignore stencil | ||
|
@@ -414,6 +415,10 @@ void ShaderObject::load_assets() | |
|
||
VkSamplerCreateInfo sampler_create_info = vkb::initializers::sampler_create_info(); | ||
|
||
// destroy created sampler before re-creating | ||
vkDestroySampler(get_device().get_handle(), heightmap_texture.sampler, nullptr); | ||
vkDestroySampler(get_device().get_handle(), terrain_array_textures.sampler, nullptr); | ||
|
||
// Setup a mirroring sampler for the height map | ||
vkDestroySampler(get_device().get_handle(), heightmap_texture.sampler, nullptr); | ||
sampler_create_info.magFilter = filter; | ||
|
@@ -1950,7 +1955,7 @@ void ShaderObject::build_linked_shaders(VkDevice device, ShaderObject::Shader *v | |
shader_create.flags |= VK_SHADER_CREATE_LINK_STAGE_BIT_EXT; | ||
} | ||
|
||
VkShaderEXT shaderEXTs[2]; | ||
VkShaderEXT shaderEXTs[2] = {VK_NULL_HANDLE, VK_NULL_HANDLE}; | ||
|
||
// Create the shader objects | ||
VkResult result = vkCreateShadersEXT(device, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
required
layers here actually are not required (they're allowed to be optional), but requested. Maybe rename the argument?