-
Notifications
You must be signed in to change notification settings - Fork 654
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new plugin: real time shader selection (#733)
* Add new plugin real time shader selection * Add new plugin real time shader selection * Add new plugin: real time shader selection * Add new plugin: real time shader selection * Add new plugin: real time shader selection * Remove unnecessary code after merge. Signed-off-by: pawel-jastrzebski-mobica <[email protected]> * Remove plugin support for Samples. Signed-off-by: pawel-jastrzebski-mobica <[email protected]> * Fix return value and code style. Signed-off-by: pawel-jastrzebski-mobica <[email protected]> * Add missing new line. Signed-off-by: pawel-jastrzebski-mobica <[email protected]> * Remove unneeded shaders. Signed-off-by: pawel-jastrzebski-mobica <[email protected]> * Remove unneeded copyright. Signed-off-by: pawel-jastrzebski-mobica <[email protected]> * Fix copyright year. Signed-off-by: pawel-jastrzebski-mobica <[email protected]> * Remove unneeded changes. Signed-off-by: pawel-jastrzebski-mobica <[email protected]> * Update copyright year. Signed-off-by: pawel-jastrzebski-mobica <[email protected]> * Fix build issues in hpp_oit_linked_lists sample * Update copyright year * Fix formatting * Remove unnecessary copyright year updates and add missing blank line in "dynamic_uniform_buffers.cpp" * Small change to re-trigger CI checks * Revert "Small change to re-trigger CI checks" This reverts commit 5051505. --------- Signed-off-by: pawel-jastrzebski-mobica <[email protected]> Co-authored-by: Dawid Lorenz <[email protected]> Co-authored-by: pawel-jastrzebski-mobica <[email protected]> Co-authored-by: Seweryn Zielas <[email protected]>
- Loading branch information
1 parent
4353c55
commit 8ee282f
Showing
44 changed files
with
823 additions
and
707 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,5 @@ khrplatform.h | |
clang_format.py | ||
run-clang-tidy.py | ||
package-list.txt | ||
.spv | ||
.pre-commit-config.yaml |
106 changes: 106 additions & 0 deletions
106
app/plugins/real_time_shader_selection/real_time_shader_selection.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* Copyright (c) 2024, Mobica Limited | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 the "License"; | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "real_time_shader_selection.h" | ||
|
||
#include "platform/platform.h" | ||
|
||
namespace plugins | ||
{ | ||
RealTimeShaderSelection::RealTimeShaderSelection() : | ||
RealTimeShaderSelectionTags("Real Time Shader Selection", | ||
"Enable dynamic shader selection for samples.", | ||
{vkb::Hook::OnAppStart, vkb::Hook::OnUpdateUi}, | ||
{&realtimeshaderselection_flag}), | ||
active_shader(0), | ||
min_size_for_shaders(2) | ||
{ | ||
} | ||
|
||
bool RealTimeShaderSelection::is_active(const vkb::CommandParser &parser) | ||
{ | ||
return parser.contains(&realtimeshaderselection_flag); | ||
} | ||
|
||
void RealTimeShaderSelection::init(const vkb::CommandParser &parser) | ||
{ | ||
} | ||
|
||
void RealTimeShaderSelection::on_app_start(const std::string &app_info) | ||
{ | ||
if (platform->get_app().get_available_shaders().size() < min_size_for_shaders) | ||
{ | ||
LOGE("Sample doesn't support RealTimeShaderSelection plugin, sample should add available shaders please see Application::store_shaders."); | ||
LOGE("Sample, defined {} shaders, minimum number of defined shaders is {}", platform->get_app().get_available_shaders().size(), min_size_for_shaders); | ||
return; | ||
} | ||
|
||
for (auto const &shader : platform->get_app().get_available_shaders()) | ||
{ | ||
switch (shader.first) | ||
{ | ||
case vkb::ShaderSourceLanguage::GLSL: | ||
language_names.emplace_back("GLSL"); | ||
break; | ||
case vkb::ShaderSourceLanguage::HLSL: | ||
language_names.emplace_back("HLSL"); | ||
break; | ||
case vkb::ShaderSourceLanguage::SPV: | ||
language_names.emplace_back("SPV"); | ||
break; | ||
default: | ||
LOGE("Not supported shader language"); | ||
assert(false); | ||
} | ||
} | ||
} | ||
|
||
void RealTimeShaderSelection::on_update_ui_overlay(vkb::Drawer &drawer) | ||
{ | ||
if (platform->get_app().get_available_shaders().size() >= min_size_for_shaders) | ||
{ | ||
if (drawer.header("Real Time Shader Selection")) | ||
{ | ||
if (drawer.combo_box("Shader language", &active_shader, language_names)) | ||
{ | ||
std::string selectedShader = language_names[active_shader]; | ||
vkb::ShaderSourceLanguage shaderType = vkb::ShaderSourceLanguage::GLSL; | ||
if (selectedShader == "GLSL") | ||
{ | ||
shaderType = vkb::ShaderSourceLanguage::GLSL; | ||
} | ||
else if (selectedShader == "HLSL") | ||
{ | ||
shaderType = vkb::ShaderSourceLanguage::HLSL; | ||
} | ||
else if (selectedShader == "SPV") | ||
{ | ||
shaderType = vkb::ShaderSourceLanguage::SPV; | ||
} | ||
else | ||
{ | ||
LOGE("Not supported shader language"); | ||
assert(false); | ||
} | ||
auto it = platform->get_app().get_available_shaders().find(shaderType); | ||
platform->get_app().change_shader(it->first); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} // namespace plugins |
62 changes: 62 additions & 0 deletions
62
app/plugins/real_time_shader_selection/real_time_shader_selection.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* Copyright (c) 2024, Mobica Limited | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 the "License"; | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "common/vk_common.h" | ||
#include "platform/plugins/plugin_base.h" | ||
#include <map> | ||
#include <vector> | ||
|
||
namespace plugins | ||
{ | ||
class RealTimeShaderSelection; | ||
|
||
// Passive behaviour | ||
using RealTimeShaderSelectionTags = vkb::PluginBase<RealTimeShaderSelection, vkb::tags::Passive>; | ||
|
||
/** | ||
* @brief Real Time Shader Selection | ||
* | ||
* When this option is enabled, the samples get the ability to dynamically choose which shaders are available for a given sample. | ||
* | ||
* Usage: vulkan_samples sample afbc --realtimeshaderselection | ||
* | ||
*/ | ||
class RealTimeShaderSelection : public RealTimeShaderSelectionTags | ||
{ | ||
public: | ||
RealTimeShaderSelection(); | ||
|
||
virtual ~RealTimeShaderSelection() = default; | ||
|
||
virtual bool is_active(const vkb::CommandParser &parser) override; | ||
|
||
virtual void init(const vkb::CommandParser &parser) override; | ||
|
||
virtual void on_app_start(const std::string &app_info) override; | ||
|
||
virtual void on_update_ui_overlay(vkb::Drawer &drawer) override; | ||
|
||
vkb::FlagCommand realtimeshaderselection_flag = {vkb::FlagType::FlagOnly, "realtimeshaderselection", "", "Enable dynamic shader selection"}; | ||
|
||
private: | ||
std::vector<std::string> language_names; | ||
int active_shader; | ||
const int min_size_for_shaders; | ||
}; | ||
} // namespace plugins |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.