diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt index ae14c317cb..a6e1d01b61 100644 --- a/framework/CMakeLists.txt +++ b/framework/CMakeLists.txt @@ -52,7 +52,6 @@ set(FRAMEWORK_FILES structure_chain_builder.h # Source Files drawer.cpp - spirv_reflection.cpp gltf_loader.cpp debug_info.cpp fence_pool.cpp @@ -238,14 +237,12 @@ set(CORE_FILES core/hpp_queue.h core/hpp_render_pass.h core/hpp_sampler.h - core/hpp_shader_module.h core/hpp_swapchain.h core/vulkan_resource.h # Source Files core/command_pool_base.cpp core/debug.cpp core/image_core.cpp - core/shader_module.cpp core/pipeline_layout.cpp core/pipeline.cpp core/descriptor_set_layout.cpp diff --git a/framework/common/hpp_resource_caching.h b/framework/common/hpp_resource_caching.h index 6758343e2d..04c6e6ca11 100644 --- a/framework/common/hpp_resource_caching.h +++ b/framework/common/hpp_resource_caching.h @@ -21,7 +21,6 @@ #include "core/hpp_descriptor_set.h" #include "core/hpp_image_view.h" #include "core/hpp_render_pass.h" -#include "core/hpp_shader_module.h" #include "hpp_resource_record.h" #include "resource_caching.h" #include @@ -157,58 +156,6 @@ struct hash } }; -template <> -struct hash -{ - size_t operator()(const vkb::core::HPPShaderModule &shader_module) const - { - return std::hash()(reinterpret_cast(shader_module)); - } -}; - -template <> -struct hash -{ - size_t operator()(vkb::core::HPPShaderResource const &shader_resource) const - { - size_t result = 0; - vkb::hash_combine(result, shader_resource.stages); - vkb::hash_combine(result, shader_resource.type); - vkb::hash_combine(result, shader_resource.mode); - vkb::hash_combine(result, shader_resource.set); - vkb::hash_combine(result, shader_resource.binding); - vkb::hash_combine(result, shader_resource.location); - vkb::hash_combine(result, shader_resource.input_attachment_index); - vkb::hash_combine(result, shader_resource.vec_size); - vkb::hash_combine(result, shader_resource.columns); - vkb::hash_combine(result, shader_resource.array_size); - vkb::hash_combine(result, shader_resource.offset); - vkb::hash_combine(result, shader_resource.size); - vkb::hash_combine(result, shader_resource.constant_id); - vkb::hash_combine(result, shader_resource.qualifiers); - vkb::hash_combine(result, shader_resource.name); - return result; - } -}; - -template <> -struct hash -{ - size_t operator()(const vkb::core::HPPShaderSource &shader_source) const - { - return std::hash()(reinterpret_cast(shader_source)); - } -}; - -template <> -struct hash -{ - size_t operator()(const vkb::core::HPPShaderVariant &shader_variant) const - { - return std::hash()(reinterpret_cast(shader_variant)); - } -}; - template <> struct hash { @@ -281,20 +228,6 @@ struct HPPRecordHelper {} }; -template -struct HPPRecordHelper -{ - size_t record(HPPResourceRecord &recorder, A &...args) - { - return recorder.register_shader_module(args...); - } - - void index(HPPResourceRecord &recorder, size_t index, vkb::core::HPPShaderModule &shader_module) - { - recorder.set_shader_module(index, shader_module); - } -}; - template struct HPPRecordHelper { diff --git a/framework/common/resource_caching.h b/framework/common/resource_caching.h index 808c5f9345..1fd0c7876a 100644 --- a/framework/common/resource_caching.h +++ b/framework/common/resource_caching.h @@ -34,9 +34,9 @@ namespace std { template <> -struct hash +struct hash { - std::size_t operator()(const vkb::ShaderSource &shader_source) const + std::size_t operator()(const vkb::core::ShaderSource &shader_source) const { std::size_t result = 0; @@ -47,9 +47,9 @@ struct hash }; template <> -struct hash +struct hash { - std::size_t operator()(const vkb::ShaderVariant &shader_variant) const + std::size_t operator()(const vkb::core::ShaderVariant &shader_variant) const { std::size_t result = 0; @@ -59,10 +59,10 @@ struct hash } }; -template <> -struct hash +template +struct hash> { - std::size_t operator()(const vkb::ShaderModule &shader_module) const + std::size_t operator()(const vkb::core::ShaderModule &shader_module) const { std::size_t result = 0; @@ -205,17 +205,17 @@ struct hash } }; -template <> -struct hash +template +struct hash> { - std::size_t operator()(const vkb::ShaderResource &shader_resource) const + std::size_t operator()(const vkb::core::ShaderResource &shader_resource) const { std::size_t result = 0; - if (shader_resource.type == vkb::ShaderResourceType::Input || - shader_resource.type == vkb::ShaderResourceType::Output || - shader_resource.type == vkb::ShaderResourceType::PushConstant || - shader_resource.type == vkb::ShaderResourceType::SpecializationConstant) + if (shader_resource.type == vkb::core::ShaderResourceType::Input || + shader_resource.type == vkb::core::ShaderResourceType::Output || + shader_resource.type == vkb::core::ShaderResourceType::PushConstant || + shader_resource.type == vkb::core::ShaderResourceType::SpecializationConstant) { return result; } @@ -223,7 +223,7 @@ struct hash vkb::hash_combine(result, shader_resource.set); vkb::hash_combine(result, shader_resource.binding); vkb::hash_combine(result, - static_cast::type>(shader_resource.type)); + static_cast::type>(shader_resource.type)); vkb::hash_combine(result, shader_resource.mode); return result; @@ -617,7 +617,8 @@ inline void hash_param>(size_t &seed, const std::vector } template <> -inline void hash_param>(size_t &seed, const std::vector &value) +inline void hash_param>(size_t &seed, + const std::vector &value) { for (auto &shader_module : value) { @@ -626,7 +627,8 @@ inline void hash_param>(size_t &seed, const std::vec } template <> -inline void hash_param>(size_t &seed, const std::vector &value) +inline void hash_param>(size_t &seed, + const std::vector &value) { for (auto &resource : value) { @@ -686,15 +688,15 @@ struct RecordHelper {} }; -template -struct RecordHelper +template +struct RecordHelper, A...> { size_t record(ResourceRecord &recorder, A &...args) { return recorder.register_shader_module(args...); } - void index(ResourceRecord &recorder, size_t index, ShaderModule &shader_module) + void index(ResourceRecord &recorder, size_t index, vkb::core::ShaderModule &shader_module) { recorder.set_shader_module(index, shader_module); } diff --git a/framework/common/strings.cpp b/framework/common/strings.cpp index 639945e48e..f08e993359 100644 --- a/framework/common/strings.cpp +++ b/framework/common/strings.cpp @@ -1477,31 +1477,31 @@ const std::string to_string(bool flag) return "false"; } -const std::string to_string(ShaderResourceType type) +const std::string to_string(vkb::core::ShaderResourceType type) { switch (type) { - case ShaderResourceType::Input: + case vkb::core::ShaderResourceType::Input: return "Input"; - case ShaderResourceType::InputAttachment: + case vkb::core::ShaderResourceType::InputAttachment: return "InputAttachment"; - case ShaderResourceType::Output: + case vkb::core::ShaderResourceType::Output: return "Output"; - case ShaderResourceType::Image: + case vkb::core::ShaderResourceType::Image: return "Image"; - case ShaderResourceType::ImageSampler: + case vkb::core::ShaderResourceType::ImageSampler: return "ImageSampler"; - case ShaderResourceType::ImageStorage: + case vkb::core::ShaderResourceType::ImageStorage: return "ImageStorage"; - case ShaderResourceType::Sampler: + case vkb::core::ShaderResourceType::Sampler: return "Sampler"; - case ShaderResourceType::BufferUniform: + case vkb::core::ShaderResourceType::BufferUniform: return "BufferUniform"; - case ShaderResourceType::BufferStorage: + case vkb::core::ShaderResourceType::BufferStorage: return "BufferStorage"; - case ShaderResourceType::PushConstant: + case vkb::core::ShaderResourceType::PushConstant: return "PushConstant"; - case ShaderResourceType::SpecializationConstant: + case vkb::core::ShaderResourceType::SpecializationConstant: return "SpecializationConstant"; default: return "Unkown Type"; diff --git a/framework/common/strings.h b/framework/common/strings.h index 13fd8abed6..ac80f6e69c 100644 --- a/framework/common/strings.h +++ b/framework/common/strings.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2018-2024, Arm Limited and Contributors +/* Copyright (c) 2018-2026, Arm Limited and Contributors * * SPDX-License-Identifier: Apache-2.0 * @@ -27,8 +27,10 @@ namespace vkb { +namespace core +{ enum class ShaderResourceType; - +} namespace sg { enum class AlphaMode; @@ -210,7 +212,7 @@ const std::string to_string(bool flag); * @param type Vulkan ShaderResourceType to convert * @return The string to return */ -const std::string to_string(ShaderResourceType type); +const std::string to_string(vkb::core::ShaderResourceType type); /** * @brief Helper generic function to convert a bitmask to a string of its components diff --git a/framework/core/descriptor_set_layout.cpp b/framework/core/descriptor_set_layout.cpp index eb67c0b76a..176d0c9fae 100644 --- a/framework/core/descriptor_set_layout.cpp +++ b/framework/core/descriptor_set_layout.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2019-2025, Arm Limited and Contributors +/* Copyright (c) 2019-2026, Arm Limited and Contributors * * SPDX-License-Identifier: Apache-2.0 * @@ -25,26 +25,26 @@ namespace vkb { namespace { -inline VkDescriptorType find_descriptor_type(ShaderResourceType resource_type, bool dynamic) +inline VkDescriptorType find_descriptor_type(vkb::core::ShaderResourceType resource_type, bool dynamic) { switch (resource_type) { - case ShaderResourceType::InputAttachment: + case vkb::core::ShaderResourceType::InputAttachment: return VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; break; - case ShaderResourceType::Image: + case vkb::core::ShaderResourceType::Image: return VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; break; - case ShaderResourceType::ImageSampler: + case vkb::core::ShaderResourceType::ImageSampler: return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; break; - case ShaderResourceType::ImageStorage: + case vkb::core::ShaderResourceType::ImageStorage: return VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; break; - case ShaderResourceType::Sampler: + case vkb::core::ShaderResourceType::Sampler: return VK_DESCRIPTOR_TYPE_SAMPLER; break; - case ShaderResourceType::BufferUniform: + case vkb::core::ShaderResourceType::BufferUniform: if (dynamic) { return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; @@ -54,7 +54,7 @@ inline VkDescriptorType find_descriptor_type(ShaderResourceType resource_type, b return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; } break; - case ShaderResourceType::BufferStorage: + case vkb::core::ShaderResourceType::BufferStorage: if (dynamic) { return VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC; @@ -96,10 +96,10 @@ inline bool validate_flags(vkb::core::PhysicalDeviceC const &gpu, } } // namespace -DescriptorSetLayout::DescriptorSetLayout(vkb::core::DeviceC &device, - const uint32_t set_index, - const std::vector &shader_modules, - const std::vector &resource_set) : +DescriptorSetLayout::DescriptorSetLayout(vkb::core::DeviceC &device, + const uint32_t set_index, + const std::vector &shader_modules, + const std::vector &resource_set) : device{device}, set_index{set_index}, shader_modules{shader_modules} @@ -111,18 +111,18 @@ DescriptorSetLayout::DescriptorSetLayout(vkb::core::DeviceC &devi for (auto &resource : resource_set) { // Skip shader resources whitout a binding point - if (resource.type == ShaderResourceType::Input || - resource.type == ShaderResourceType::Output || - resource.type == ShaderResourceType::PushConstant || - resource.type == ShaderResourceType::SpecializationConstant) + if (resource.type == vkb::core::ShaderResourceType::Input || + resource.type == vkb::core::ShaderResourceType::Output || + resource.type == vkb::core::ShaderResourceType::PushConstant || + resource.type == vkb::core::ShaderResourceType::SpecializationConstant) { continue; } // Convert from ShaderResourceType to VkDescriptorType. - auto descriptor_type = find_descriptor_type(resource.type, resource.mode == ShaderResourceMode::Dynamic); + auto descriptor_type = find_descriptor_type(resource.type, resource.mode == vkb::core::ShaderResourceMode::Dynamic); - if (resource.mode == ShaderResourceMode::UpdateAfterBind) + if (resource.mode == vkb::core::ShaderResourceMode::UpdateAfterBind) { binding_flags.push_back(VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT); } @@ -160,11 +160,11 @@ DescriptorSetLayout::DescriptorSetLayout(vkb::core::DeviceC &devi // Handle update-after-bind extensions VkDescriptorSetLayoutBindingFlagsCreateInfoEXT binding_flags_create_info{VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_BINDING_FLAGS_CREATE_INFO_EXT}; if (std::ranges::find_if(resource_set, - [](const ShaderResource &shader_resource) { return shader_resource.mode == ShaderResourceMode::UpdateAfterBind; }) != resource_set.end()) + [](const vkb::core::ShaderResourceC &shader_resource) { return shader_resource.mode == vkb::core::ShaderResourceMode::UpdateAfterBind; }) != resource_set.end()) { // Spec states you can't have ANY dynamic resources if you have one of the bindings set to update-after-bind if (std::ranges::find_if(resource_set, - [](const ShaderResource &shader_resource) { return shader_resource.mode == ShaderResourceMode::Dynamic; }) != resource_set.end()) + [](const vkb::core::ShaderResourceC &shader_resource) { return shader_resource.mode == vkb::core::ShaderResourceMode::Dynamic; }) != resource_set.end()) { throw std::runtime_error("Cannot create descriptor set layout, dynamic resources are not allowed if at least one resource is update-after-bind."); } @@ -269,7 +269,7 @@ VkDescriptorBindingFlagsEXT DescriptorSetLayout::get_layout_binding_flag(const u return it->second; } -const std::vector &DescriptorSetLayout::get_shader_modules() const +const std::vector &DescriptorSetLayout::get_shader_modules() const { return shader_modules; } diff --git a/framework/core/descriptor_set_layout.h b/framework/core/descriptor_set_layout.h index d36e555cce..cd91a9a62d 100644 --- a/framework/core/descriptor_set_layout.h +++ b/framework/core/descriptor_set_layout.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2019-2025, Arm Limited and Contributors +/* Copyright (c) 2019-2026, Arm Limited and Contributors * * SPDX-License-Identifier: Apache-2.0 * @@ -19,13 +19,11 @@ #include "common/helpers.h" #include "common/vk_common.h" +#include "core/shader_module.h" namespace vkb { class DescriptorPool; -class ShaderModule; - -struct ShaderResource; namespace core { @@ -48,10 +46,10 @@ class DescriptorSetLayout * @param shader_modules The shader modules this set layout will be used for * @param resource_set A grouping of shader resources belonging to the same set */ - DescriptorSetLayout(vkb::core::DeviceC &device, - const uint32_t set_index, - const std::vector &shader_modules, - const std::vector &resource_set); + DescriptorSetLayout(vkb::core::DeviceC &device, + const uint32_t set_index, + const std::vector &shader_modules, + const std::vector &resource_set); DescriptorSetLayout(const DescriptorSetLayout &) = delete; @@ -77,7 +75,7 @@ class DescriptorSetLayout VkDescriptorBindingFlagsEXT get_layout_binding_flag(const uint32_t binding_index) const; - const std::vector &get_shader_modules() const; + const std::vector &get_shader_modules() const; private: vkb::core::DeviceC &device; @@ -96,6 +94,6 @@ class DescriptorSetLayout std::unordered_map resources_lookup; - std::vector shader_modules; + std::vector shader_modules; }; } // namespace vkb diff --git a/framework/core/hpp_descriptor_set_layout.h b/framework/core/hpp_descriptor_set_layout.h index 55f047fda3..659fbf5260 100644 --- a/framework/core/hpp_descriptor_set_layout.h +++ b/framework/core/hpp_descriptor_set_layout.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2023-2025, NVIDIA CORPORATION. All rights reserved. +/* Copyright (c) 2023-2026, NVIDIA CORPORATION. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -29,9 +29,6 @@ class Device; using DeviceCpp = Device; using DeviceC = Device; -class HPPShaderModule; -struct HPPShaderResource; - /** * @brief facade class around vkb::DescriptorSetLayout, providing a vulkan.hpp-based interface * @@ -45,12 +42,12 @@ class HPPDescriptorSetLayout : private vkb::DescriptorSetLayout public: HPPDescriptorSetLayout(vkb::core::DeviceCpp &device, const uint32_t set_index, - const std::vector &shader_modules, - const std::vector &resource_set) : + const std::vector &shader_modules, + const std::vector &resource_set) : vkb::DescriptorSetLayout(reinterpret_cast(device), set_index, - reinterpret_cast const &>(shader_modules), - reinterpret_cast const &>(resource_set)) + reinterpret_cast const &>(shader_modules), + reinterpret_cast const &>(resource_set)) {} vk::DescriptorSetLayout get_handle() const diff --git a/framework/core/hpp_pipeline_layout.cpp b/framework/core/hpp_pipeline_layout.cpp index 61c08d0c93..4b9b4112a1 100644 --- a/framework/core/hpp_pipeline_layout.cpp +++ b/framework/core/hpp_pipeline_layout.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2023-2025, NVIDIA CORPORATION. All rights reserved. +/* Copyright (c) 2023-2026, NVIDIA CORPORATION. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -18,13 +18,11 @@ #include "hpp_pipeline_layout.h" #include "core/device.h" -#include - namespace vkb { namespace core { -HPPPipelineLayout::HPPPipelineLayout(vkb::core::DeviceCpp &device, const std::vector &shader_modules) : +HPPPipelineLayout::HPPPipelineLayout(vkb::core::DeviceCpp &device, const std::vector &shader_modules) : device{device}, shader_modules{shader_modules} { @@ -37,7 +35,7 @@ HPPPipelineLayout::HPPPipelineLayout(vkb::core::DeviceCpp &device, const std::ve std::string key = shader_resource.name; // Since 'Input' and 'Output' resources can have the same name, we modify the key string - if (shader_resource.type == vkb::core::HPPShaderResourceType::Input || shader_resource.type == vkb::core::HPPShaderResourceType::Output) + if (shader_resource.type == vkb::core::ShaderResourceType::Input || shader_resource.type == vkb::core::ShaderResourceType::Output) { key = std::to_string(static_cast(shader_resource.stages)) + "_" + key; } @@ -74,7 +72,7 @@ HPPPipelineLayout::HPPPipelineLayout(vkb::core::DeviceCpp &device, const std::ve else { // Create a new set index and with the first resource - shader_sets.emplace(shader_resource.set, std::vector{shader_resource}); + shader_sets.emplace(shader_resource.set, std::vector{shader_resource}); } } @@ -94,7 +92,7 @@ HPPPipelineLayout::HPPPipelineLayout(vkb::core::DeviceCpp &device, const std::ve // Collect all the push constant shader resources std::vector push_constant_ranges; - for (auto &push_constant_resource : get_resources(vkb::core::HPPShaderResourceType::PushConstant)) + for (auto &push_constant_resource : get_resources(vkb::core::ShaderResourceType::PushConstant)) { push_constant_ranges.push_back({push_constant_resource.stages, push_constant_resource.offset, push_constant_resource.size}); } @@ -148,7 +146,7 @@ vk::ShaderStageFlags HPPPipelineLayout::get_push_constant_range_stage(uint32_t s { vk::ShaderStageFlags stages; - for (auto &push_constant_resource : get_resources(vkb::core::HPPShaderResourceType::PushConstant)) + for (auto &push_constant_resource : get_resources(vkb::core::ShaderResourceType::PushConstant)) { if (push_constant_resource.offset <= offset && offset + size <= push_constant_resource.offset + push_constant_resource.size) { @@ -158,15 +156,15 @@ vk::ShaderStageFlags HPPPipelineLayout::get_push_constant_range_stage(uint32_t s return stages; } -std::vector HPPPipelineLayout::get_resources(const vkb::core::HPPShaderResourceType &type, vk::ShaderStageFlagBits stage) const +std::vector HPPPipelineLayout::get_resources(const vkb::core::ShaderResourceType &type, vk::ShaderStageFlagBits stage) const { - std::vector found_resources; + std::vector found_resources; for (auto &it : shader_resources) { auto &shader_resource = it.second; - if (shader_resource.type == type || type == vkb::core::HPPShaderResourceType::All) + if (shader_resource.type == type || type == vkb::core::ShaderResourceType::All) { if (shader_resource.stages == stage || stage == vk::ShaderStageFlagBits::eAll) { @@ -178,12 +176,12 @@ std::vector HPPPipelineLayout::get_resources(const return found_resources; } -const std::vector &HPPPipelineLayout::get_shader_modules() const +const std::vector &HPPPipelineLayout::get_shader_modules() const { return shader_modules; } -const std::unordered_map> &HPPPipelineLayout::get_shader_sets() const +const std::unordered_map> &HPPPipelineLayout::get_shader_sets() const { return shader_sets; } diff --git a/framework/core/hpp_pipeline_layout.h b/framework/core/hpp_pipeline_layout.h index 8e0515a662..aefd31f9af 100644 --- a/framework/core/hpp_pipeline_layout.h +++ b/framework/core/hpp_pipeline_layout.h @@ -17,7 +17,7 @@ #pragma once -#include +#include "core/shader_module.h" #include #include @@ -25,6 +25,10 @@ namespace vkb { namespace core { +template +class Device; +using DeviceCpp = Device; + class HPPDescriptorSetLayout; /** @@ -34,7 +38,7 @@ class HPPDescriptorSetLayout; class HPPPipelineLayout { public: - HPPPipelineLayout(vkb::core::DeviceCpp &device, const std::vector &shader_modules); + HPPPipelineLayout(vkb::core::DeviceCpp &device, const std::vector &shader_modules); HPPPipelineLayout(const HPPPipelineLayout &) = delete; HPPPipelineLayout(HPPPipelineLayout &&other); ~HPPPipelineLayout(); @@ -42,22 +46,31 @@ class HPPPipelineLayout HPPPipelineLayout &operator=(const HPPPipelineLayout &) = delete; HPPPipelineLayout &operator=(HPPPipelineLayout &&) = delete; - vkb::core::HPPDescriptorSetLayout const &get_descriptor_set_layout(const uint32_t set_index) const; - vk::PipelineLayout get_handle() const; - vk::ShaderStageFlags get_push_constant_range_stage(uint32_t size, uint32_t offset = 0) const; - std::vector get_resources(const vkb::core::HPPShaderResourceType &type = vkb::core::HPPShaderResourceType::All, - vk::ShaderStageFlagBits stage = vk::ShaderStageFlagBits::eAll) const; - const std::vector &get_shader_modules() const; - const std::unordered_map> &get_shader_sets() const; + vkb::core::HPPDescriptorSetLayout const &get_descriptor_set_layout(const uint32_t set_index) const; + vk::PipelineLayout get_handle() const; + vk::ShaderStageFlags get_push_constant_range_stage(uint32_t size, uint32_t offset = 0) const; + std::vector + get_resources(const vkb::core::ShaderResourceType &type = vkb::core::ShaderResourceType::All, + vk::ShaderStageFlagBits stage = vk::ShaderStageFlagBits::eAll) const; + const std::vector &get_shader_modules() const; + const std::unordered_map> &get_shader_sets() const; bool has_descriptor_set_layout(const uint32_t set_index) const; private: - vkb::core::DeviceCpp &device; - vk::PipelineLayout handle; - std::vector shader_modules; // The shader modules that this pipeline layout uses - std::unordered_map shader_resources; // The shader resources that this pipeline layout uses, indexed by their name - std::unordered_map> shader_sets; // A map of each set and the resources it owns used by the pipeline layout - std::vector descriptor_set_layouts; // The different descriptor set layouts for this pipeline layout + vkb::core::DeviceCpp &device; + vk::PipelineLayout handle; + + // The shader modules that this pipeline layout uses + std::vector shader_modules; + + // The shader resources that this pipeline layout uses, indexed by their name + std::unordered_map shader_resources; + + // A map of each set and the resources it owns used by the pipeline layout + std::unordered_map> shader_sets; + + // The different descriptor set layouts for this pipeline layout + std::vector descriptor_set_layouts; }; } // namespace core } // namespace vkb diff --git a/framework/core/hpp_shader_module.h b/framework/core/hpp_shader_module.h deleted file mode 100644 index 1f27d87e62..0000000000 --- a/framework/core/hpp_shader_module.h +++ /dev/null @@ -1,122 +0,0 @@ -/* Copyright (c) 2023-2025, NVIDIA CORPORATION. All rights reserved. - * - * 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 "core/shader_module.h" -#include - -namespace vkb -{ -namespace core -{ -template -class Device; -using DeviceCpp = Device; -using DeviceC = Device; - -/** - * @brief facade class around vkb::ShaderModule, providing a vulkan.hpp-based interface - * - * See vkb::ShaderModule for documentation - */ - -/// Types of shader resources -enum class HPPShaderResourceType -{ - Input, - InputAttachment, - Output, - Image, - ImageSampler, - ImageStorage, - Sampler, - BufferUniform, - BufferStorage, - PushConstant, - SpecializationConstant, - All -}; - -/// This determines the type and method of how descriptor set should be created and bound -enum class HPPShaderResourceMode -{ - Static, - Dynamic, - UpdateAfterBind -}; - -/// Store shader resource data. -/// Used by the shader module. -struct HPPShaderResource -{ - vk::ShaderStageFlags stages; - HPPShaderResourceType type; - HPPShaderResourceMode mode; - uint32_t set; - uint32_t binding; - uint32_t location; - uint32_t input_attachment_index; - uint32_t vec_size; - uint32_t columns; - uint32_t array_size; - uint32_t offset; - uint32_t size; - uint32_t constant_id; - uint32_t qualifiers; - std::string name; -}; - -class HPPShaderSource : private vkb::ShaderSource -{ - public: - HPPShaderSource() = default; - HPPShaderSource(const std::string &filename) : - vkb::ShaderSource(filename) - {} -}; - -class HPPShaderVariant : private vkb::ShaderVariant -{}; - -class HPPShaderModule : private vkb::ShaderModule -{ - public: - using vkb::ShaderModule::get_id; - using vkb::ShaderModule::set_resource_mode; - - public: - HPPShaderModule(vkb::core::DeviceCpp &device, - vk::ShaderStageFlagBits stage, - const vkb::core::HPPShaderSource &glsl_source, - const std::string &entry_point, - const vkb::core::HPPShaderVariant &shader_variant) : - vkb::ShaderModule(reinterpret_cast(device), - static_cast(stage), - reinterpret_cast(glsl_source), - entry_point, - reinterpret_cast(shader_variant)) - {} - - const std::vector &get_resources() const - { - return reinterpret_cast const &>(vkb::ShaderModule::get_resources()); - } -}; - -} // namespace core -} // namespace vkb diff --git a/framework/core/pipeline.cpp b/framework/core/pipeline.cpp index d55127be1f..e17a9d1085 100644 --- a/framework/core/pipeline.cpp +++ b/framework/core/pipeline.cpp @@ -60,7 +60,7 @@ ComputePipeline::ComputePipeline(vkb::core::DeviceC &device, vkb::rendering::PipelineStateC &pipeline_state) : Pipeline{device} { - const ShaderModule *shader_module = pipeline_state.get_pipeline_layout().get_shader_modules().front(); + const vkb::core::ShaderModuleC *shader_module = pipeline_state.get_pipeline_layout().get_shader_modules().front(); if (shader_module->get_stage() != VK_SHADER_STAGE_COMPUTE_BIT) { @@ -150,7 +150,7 @@ GraphicsPipeline::GraphicsPipeline(vkb::core::DeviceC &device, specialization_info.dataSize = data.size(); specialization_info.pData = data.data(); - for (const ShaderModule *shader_module : pipeline_state.get_pipeline_layout().get_shader_modules()) + for (const vkb::core::ShaderModuleC *shader_module : pipeline_state.get_pipeline_layout().get_shader_modules()) { VkPipelineShaderStageCreateInfo stage_create_info{VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO}; diff --git a/framework/core/pipeline_layout.cpp b/framework/core/pipeline_layout.cpp index 7035f26ea3..0bed479187 100644 --- a/framework/core/pipeline_layout.cpp +++ b/framework/core/pipeline_layout.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2019-2025, Arm Limited and Contributors +/* Copyright (c) 2019-2026, Arm Limited and Contributors * * SPDX-License-Identifier: Apache-2.0 * @@ -25,7 +25,7 @@ namespace vkb { -PipelineLayout::PipelineLayout(vkb::core::DeviceC &device, const std::vector &shader_modules) : +PipelineLayout::PipelineLayout(vkb::core::DeviceC &device, const std::vector &shader_modules) : device{device}, shader_modules{shader_modules} { @@ -38,7 +38,7 @@ PipelineLayout::PipelineLayout(vkb::core::DeviceC &device, const std::vector{shader_resource}); + shader_sets.emplace(shader_resource.set, std::vector{shader_resource}); } } @@ -101,7 +101,7 @@ PipelineLayout::PipelineLayout(vkb::core::DeviceC &device, const std::vector push_constant_ranges; - for (auto &push_constant_resource : get_resources(ShaderResourceType::PushConstant)) + for (auto &push_constant_resource : get_resources(vkb::core::ShaderResourceType::PushConstant)) { push_constant_ranges.push_back({push_constant_resource.stages, push_constant_resource.offset, push_constant_resource.size}); } @@ -147,20 +147,20 @@ VkPipelineLayout PipelineLayout::get_handle() const return handle; } -const std::vector &PipelineLayout::get_shader_modules() const +const std::vector &PipelineLayout::get_shader_modules() const { return shader_modules; } -const std::vector PipelineLayout::get_resources(const ShaderResourceType &type, VkShaderStageFlagBits stage) const +const std::vector PipelineLayout::get_resources(const vkb::core::ShaderResourceType &type, VkShaderStageFlagBits stage) const { - std::vector found_resources; + std::vector found_resources; for (auto &it : shader_resources) { auto &shader_resource = it.second; - if (shader_resource.type == type || type == ShaderResourceType::All) + if (shader_resource.type == type || type == vkb::core::ShaderResourceType::All) { if (shader_resource.stages == stage || stage == VK_SHADER_STAGE_ALL) { @@ -172,7 +172,7 @@ const std::vector PipelineLayout::get_resources(const ShaderReso return found_resources; } -const std::unordered_map> &PipelineLayout::get_shader_sets() const +const std::unordered_map> &PipelineLayout::get_shader_sets() const { return shader_sets; } @@ -198,7 +198,7 @@ VkShaderStageFlags PipelineLayout::get_push_constant_range_stage(uint32_t size, { VkShaderStageFlags stages = 0; - for (auto &push_constant_resource : get_resources(ShaderResourceType::PushConstant)) + for (auto &push_constant_resource : get_resources(vkb::core::ShaderResourceType::PushConstant)) { if (offset >= push_constant_resource.offset && offset + size <= push_constant_resource.offset + push_constant_resource.size) { diff --git a/framework/core/pipeline_layout.h b/framework/core/pipeline_layout.h index 438e1a9599..0adb7f148c 100644 --- a/framework/core/pipeline_layout.h +++ b/framework/core/pipeline_layout.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2019-2025, Arm Limited and Contributors +/* Copyright (c) 2019-2026, Arm Limited and Contributors * * SPDX-License-Identifier: Apache-2.0 * @@ -24,13 +24,12 @@ namespace vkb { -class ShaderModule; class DescriptorSetLayout; class PipelineLayout { public: - PipelineLayout(vkb::core::DeviceC &device, const std::vector &shader_modules); + PipelineLayout(vkb::core::DeviceC &device, const std::vector &shader_modules); PipelineLayout(const PipelineLayout &) = delete; @@ -44,11 +43,11 @@ class PipelineLayout VkPipelineLayout get_handle() const; - const std::vector &get_shader_modules() const; + const std::vector &get_shader_modules() const; - const std::vector get_resources(const ShaderResourceType &type = ShaderResourceType::All, VkShaderStageFlagBits stage = VK_SHADER_STAGE_ALL) const; + const std::vector get_resources(const vkb::core::ShaderResourceType &type = vkb::core::ShaderResourceType::All, VkShaderStageFlagBits stage = VK_SHADER_STAGE_ALL) const; - const std::unordered_map> &get_shader_sets() const; + const std::unordered_map> &get_shader_sets() const; bool has_descriptor_set_layout(const uint32_t set_index) const; @@ -62,13 +61,13 @@ class PipelineLayout VkPipelineLayout handle{VK_NULL_HANDLE}; // The shader modules that this pipeline layout uses - std::vector shader_modules; + std::vector shader_modules; // The shader resources that this pipeline layout uses, indexed by their name - std::unordered_map shader_resources; + std::unordered_map shader_resources; // A map of each set and the resources it owns used by the pipeline layout - std::unordered_map> shader_sets; + std::unordered_map> shader_sets; // The different descriptor set layouts for this pipeline layout std::vector descriptor_set_layouts; diff --git a/framework/core/shader_module.cpp b/framework/core/shader_module.cpp deleted file mode 100644 index 9dc4c38213..0000000000 --- a/framework/core/shader_module.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/* Copyright (c) 2019-2025, Arm Limited and Contributors - * - * 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 "shader_module.h" - -#include "core/util/logging.hpp" -#include "device.h" -#include "filesystem/legacy.h" -#include "spirv_reflection.h" - -namespace vkb -{ -ShaderModule::ShaderModule(vkb::core::DeviceC &device, - VkShaderStageFlagBits stage, - const ShaderSource &shader_source, - const std::string &entry_point, - const ShaderVariant &shader_variant) : - device{device}, stage{stage}, entry_point{entry_point} -{ - debug_name = fmt::format("{} [variant {:X}] [entrypoint {}]", shader_source.get_filename(), shader_variant.get_id(), entry_point); - - // Shaders in binary SPIR-V format can be loaded directly - spirv = vkb::fs::read_shader_binary_u32(shader_source.get_filename()); - - // Reflection is used to dynamically create descriptor bindings - - SPIRVReflection spirv_reflection; - // Reflect all shader resources - if (!spirv_reflection.reflect_shader_resources(stage, spirv, resources, shader_variant)) - { - throw VulkanException{VK_ERROR_INITIALIZATION_FAILED}; - } - - // Generate a unique id, determined by source and variant - std::hash hasher{}; - id = hasher(std::string{reinterpret_cast(spirv.data()), - reinterpret_cast(spirv.data() + spirv.size())}); -} - -ShaderModule::ShaderModule(ShaderModule &&other) : - device{other.device}, - id{other.id}, - stage{other.stage}, - entry_point{other.entry_point}, - debug_name{other.debug_name}, - spirv{other.spirv}, - resources{other.resources} -{ - other.stage = {}; -} - -size_t ShaderModule::get_id() const -{ - return id; -} - -VkShaderStageFlagBits ShaderModule::get_stage() const -{ - return stage; -} - -const std::string &ShaderModule::get_entry_point() const -{ - return entry_point; -} - -const std::vector &ShaderModule::get_resources() const -{ - return resources; -} - -const std::vector &ShaderModule::get_binary() const -{ - return spirv; -} - -void ShaderModule::set_resource_mode(const std::string &resource_name, const ShaderResourceMode &resource_mode) -{ - auto it = std::ranges::find_if(resources, [&resource_name](const ShaderResource &resource) { return resource.name == resource_name; }); - - if (it != resources.end()) - { - if (resource_mode == ShaderResourceMode::Dynamic) - { - if (it->type == ShaderResourceType::BufferUniform || it->type == ShaderResourceType::BufferStorage) - { - it->mode = resource_mode; - } - else - { - LOGW("Resource `{}` does not support dynamic.", resource_name); - } - } - else - { - it->mode = resource_mode; - } - } - else - { - LOGW("Resource `{}` not found for shader.", resource_name); - } -} - -size_t ShaderVariant::get_id() const -{ - return id; -} - -void ShaderVariant::add_runtime_array_size(const std::string &runtime_array_name, size_t size) -{ - if (runtime_array_sizes.find(runtime_array_name) == runtime_array_sizes.end()) - { - runtime_array_sizes.insert({runtime_array_name, size}); - } - else - { - runtime_array_sizes[runtime_array_name] = size; - } -} - -void ShaderVariant::set_runtime_array_sizes(const std::unordered_map &sizes) -{ - this->runtime_array_sizes = sizes; -} - -const std::unordered_map &ShaderVariant::get_runtime_array_sizes() const -{ - return runtime_array_sizes; -} - -void ShaderVariant::clear() -{ - runtime_array_sizes.clear(); - id = 0; -} - -ShaderSource::ShaderSource(const std::string &filename) : - filename{filename}, - source{fs::read_text_file(filename)} -{ - std::hash hasher{}; - id = hasher(std::string{this->source.cbegin(), this->source.cend()}); -} - -size_t ShaderSource::get_id() const -{ - return id; -} - -const std::string &ShaderSource::get_filename() const -{ - return filename; -} - -void ShaderSource::set_source(const std::string &source_) -{ - source = source_; - std::hash hasher{}; - id = hasher(std::string{this->source.cbegin(), this->source.cend()}); -} - -const std::string &ShaderSource::get_source() const -{ - return source; -} -} // namespace vkb diff --git a/framework/core/shader_module.h b/framework/core/shader_module.h index ceb66c8b20..efa2cddc0f 100644 --- a/framework/core/shader_module.h +++ b/framework/core/shader_module.h @@ -1,4 +1,5 @@ -/* Copyright (c) 2019-2025, Arm Limited and Contributors +/* Copyright (c) 2019-2026, Arm Limited and Contributors + * Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -17,12 +18,10 @@ #pragma once -#include "common/helpers.h" +#include "common/hpp_error.h" #include "common/vk_common.h" - -#if defined(VK_USE_PLATFORM_XLIB_KHR) -# undef None -#endif +#include "filesystem/legacy.h" +#include namespace vkb { @@ -30,10 +29,10 @@ namespace core { template class Device; -using DeviceC = Device; -} // namespace core +using DeviceCpp = Device; +using DeviceC = Device; -/// Types of shader resources +// Types of shader resources enum class ShaderResourceType { Input, @@ -50,7 +49,7 @@ enum class ShaderResourceType All }; -/// This determines the type and method of how descriptor set should be created and bound +// This determines the type and method of how descriptor set should be created and bound enum class ShaderResourceMode { Static, @@ -58,80 +57,63 @@ enum class ShaderResourceMode UpdateAfterBind }; -/// A bitmask of qualifiers applied to a resource -struct ShaderResourceQualifiers +// A bitmask of qualifiers applied to a resource +enum class ShaderResourceQualifierFlagBits { - enum : uint32_t - { - None = 0, - NonReadable = 1, - NonWritable = 2, - }; + NonReadable = 1, + NonWritable = 2, }; +using ShaderResourceQualifierFlags = vk::Flags; -/// Store shader resource data. -/// Used by the shader module. +// Store shader resource data. +// Used by the shader module. +template struct ShaderResource { - VkShaderStageFlags stages; - - ShaderResourceType type; - - ShaderResourceMode mode; - - uint32_t set; - - uint32_t binding; - - uint32_t location; - - uint32_t input_attachment_index; - - uint32_t vec_size; - - uint32_t columns; - - uint32_t array_size; - - uint32_t offset; - - uint32_t size; - - uint32_t constant_id; - - uint32_t qualifiers; - - std::string name; + using ShaderStageFlagsType = std::conditional_t; + + ShaderStageFlagsType stages; + vkb::core::ShaderResourceType type; + vkb::core::ShaderResourceMode mode; + uint32_t set; + uint32_t binding; + uint32_t location; + uint32_t input_attachment_index; + uint32_t vec_size; + uint32_t columns; + uint32_t array_size; + uint32_t offset; + uint32_t size; + uint32_t constant_id; + vkb::core::ShaderResourceQualifierFlags qualifiers; + std::string name; }; +using ShaderResourceC = ShaderResource; +using ShaderResourceCpp = ShaderResource; /** - * @brief Adds support for C style preprocessor macros to glsl shaders - * enabling you to define or undefine certain symbols + * @brief Adds support for C style preprocessor macros to glsl shaders enabling you to define or undefine certain symbols */ class ShaderVariant { public: ShaderVariant() = default; - size_t get_id() const; - /** * @brief Specifies the size of a named runtime array for automatic reflection. If already specified, overrides the size. * @param runtime_array_name String under which the runtime array is named in the shader * @param size Integer specifying the wanted size of the runtime array (in number of elements, not size in bytes), used for automatic allocation of buffers. * See get_declared_struct_size_runtime_array() in spirv_cross.h */ - void add_runtime_array_size(const std::string &runtime_array_name, size_t size); + void add_runtime_array_size(std::string const &runtime_array_name, size_t size); - void set_runtime_array_sizes(const std::unordered_map &sizes); - - const std::unordered_map &get_runtime_array_sizes() const; - - void clear(); + void clear(); + size_t get_id() const; + std::unordered_map const &get_runtime_array_sizes() const; + void set_runtime_array_sizes(std::unordered_map const &sizes); private: - size_t id; - + size_t id; std::unordered_map runtime_array_sizes; }; @@ -139,22 +121,16 @@ class ShaderSource { public: ShaderSource() = default; + ShaderSource(std::string const &filename); - ShaderSource(const std::string &filename); - - size_t get_id() const; - - const std::string &get_filename() const; - - void set_source(const std::string &source); - - const std::string &get_source() const; + std::string const &get_filename() const; + size_t get_id() const; + std::string const &get_source() const; + void set_source(std::string const &source); private: - size_t id; - + size_t id; std::string filename; - std::string source; }; @@ -167,68 +143,259 @@ class ShaderSource * It works similarly for attribute locations. A current limitation is that only set 0 * is considered. Uniform buffers are currently hardcoded as well. */ +template class ShaderModule { public: - ShaderModule(vkb::core::DeviceC &device, - VkShaderStageFlagBits stage, - const ShaderSource &shader_source, - const std::string &entry_point, - const ShaderVariant &shader_variant); + using ShaderStageFlagBitsType = std::conditional_t; - ShaderModule(const ShaderModule &) = delete; + public: + ShaderModule(vkb::core::Device & /* device*/, + ShaderStageFlagBitsType stage, + vkb::core::ShaderSource const &shader_source, + std::string const &entry_point, + vkb::core::ShaderVariant const &shader_variant); + ShaderModule(ShaderModule const &) = delete; ShaderModule(ShaderModule &&other); - ShaderModule &operator=(const ShaderModule &) = delete; + ShaderModule &operator=(ShaderModule const &) = delete; + ShaderModule &operator=(ShaderModule &&) = delete; - ShaderModule &operator=(ShaderModule &&) = delete; + std::vector const &get_binary() const; + std::string const &get_debug_name() const; + std::string const &get_entry_point() const; + size_t get_id() const; + std::vector> const &get_resources() const; + ShaderStageFlagBitsType get_stage() const; + void set_debug_name(std::string const &name); - size_t get_id() const; + /** + * @brief Flags a resource to use a different method of being bound to the shader + * @param resource_name The name of the shader resource + * @param resource_mode The mode of how the shader resource will be bound + */ + void set_resource_mode(std::string const &resource_name, vkb::core::ShaderResourceMode const &resource_mode); - VkShaderStageFlagBits get_stage() const; + private: + void init(vkb::core::ShaderSource const &shader_source, vkb::core::ShaderVariant const &shader_variant); - const std::string &get_entry_point() const; + private: + std::string debug_name; // Human-readable name for the shader + size_t id; // Shader unique id + std::string entry_point; // Name of the main function + std::vector resources; + std::vector spirv; // Compiled source + vk::ShaderStageFlagBits stage = {}; // Stage of the shader (vertex, fragment, etc) +}; - const std::vector &get_resources() const; +using ShaderModuleC = ShaderModule; +using ShaderModuleCpp = ShaderModule; +} // namespace core +} // namespace vkb - const std::vector &get_binary() const; +#include "spirv_reflection.h" - inline const std::string &get_debug_name() const - { - return debug_name; - } +namespace vkb +{ +namespace core +{ +inline void ShaderVariant::add_runtime_array_size(std::string const &runtime_array_name, size_t size) +{ + runtime_array_sizes[runtime_array_name] = size; +} + +inline void ShaderVariant::clear() +{ + runtime_array_sizes.clear(); + id = 0; +} + +inline size_t ShaderVariant::get_id() const +{ + return id; +} + +inline std::unordered_map const &ShaderVariant::get_runtime_array_sizes() const +{ + return runtime_array_sizes; +} + +inline void ShaderVariant::set_runtime_array_sizes(std::unordered_map const &sizes) +{ + runtime_array_sizes = sizes; +} + +inline ShaderSource::ShaderSource(std::string const &filename) : + filename{filename}, source{fs::read_text_file(filename)} +{ + std::hash hasher{}; + id = hasher(std::string{this->source.cbegin(), this->source.cend()}); +} - inline void set_debug_name(const std::string &name) +inline std::string const &ShaderSource::get_filename() const +{ + return filename; +} + +inline size_t ShaderSource::get_id() const +{ + return id; +} + +inline std::string const &ShaderSource::get_source() const +{ + return source; +} + +inline void ShaderSource::set_source(std::string const &source_) +{ + source = source_; + std::hash hasher{}; + id = hasher(std::string{this->source.cbegin(), this->source.cend()}); +} + +template <> +inline ShaderModule::ShaderModule([[maybe_unused]] vkb::core::DeviceC &device, + VkShaderStageFlagBits stage, + vkb::core::ShaderSource const &shader_source, + std::string const &entry_point, + vkb::core::ShaderVariant const &shader_variant) : + stage{static_cast(stage)}, entry_point{entry_point} +{ + init(shader_source, shader_variant); +} + +template <> +inline ShaderModule::ShaderModule([[maybe_unused]] vkb::core::DeviceCpp &device, + vk::ShaderStageFlagBits stage, + vkb::core::ShaderSource const &shader_source, + std::string const &entry_point, + vkb::core::ShaderVariant const &shader_variant) : + stage{stage}, entry_point{entry_point} +{ + init(shader_source, shader_variant); +} + +template +inline void ShaderModule::init(vkb::core::ShaderSource const &shader_source, vkb::core::ShaderVariant const &shader_variant) +{ + debug_name = fmt::format("{} [variant {:X}] [entrypoint {}]", shader_source.get_filename(), shader_variant.get_id(), entry_point); + + // Shaders in binary SPIR-V format can be loaded directly + spirv = vkb::fs::read_shader_binary_u32(shader_source.get_filename()); + + // Reflection is used to dynamically create descriptor bindings + + SPIRVReflectionCpp spirv_reflection; + // Reflect all shader resources + if (!spirv_reflection.reflect_shader_resources(stage, spirv, resources, shader_variant)) { - debug_name = name; + throw vkb::common::HPPVulkanException(vk::Result::eErrorInitializationFailed); } - /** - * @brief Flags a resource to use a different method of being bound to the shader - * @param resource_name The name of the shader resource - * @param resource_mode The mode of how the shader resource will be bound - */ - void set_resource_mode(const std::string &resource_name, const ShaderResourceMode &resource_mode); + // Generate a unique id, determined by source and variant + std::hash hasher{}; + id = hasher(std::string{reinterpret_cast(spirv.data()), reinterpret_cast(spirv.data() + spirv.size())}); +} - private: - vkb::core::DeviceC &device; +template +inline ShaderModule::ShaderModule(ShaderModule &&other) : + id{other.id}, + stage{other.stage}, + entry_point{other.entry_point}, + debug_name{other.debug_name}, + spirv{other.spirv}, + resources{other.resources} +{ + other.stage = {}; +} - /// Shader unique id - size_t id; +template +inline std::vector const &ShaderModule::get_binary() const +{ + return spirv; +} - /// Stage of the shader (vertex, fragment, etc) - VkShaderStageFlagBits stage{}; +template +inline std::string const &ShaderModule::get_debug_name() const +{ + return debug_name; +} - /// Name of the main function - std::string entry_point; +template +inline std::string const &ShaderModule::get_entry_point() const +{ + return entry_point; +} - /// Human-readable name for the shader - std::string debug_name; +template +inline size_t ShaderModule::get_id() const +{ + return id; +} - /// Compiled source - std::vector spirv; +template +inline std::vector> const &ShaderModule::get_resources() const +{ + if constexpr (bindingType == vkb::BindingType::Cpp) + { + return resources; + } + else + { + return reinterpret_cast const &>(resources); + } +} - std::vector resources; -}; +template +inline typename ShaderModule::ShaderStageFlagBitsType ShaderModule::get_stage() const +{ + if constexpr (bindingType == vkb::BindingType::Cpp) + { + return stage; + } + else + { + return static_cast(stage); + } +} + +template +inline void ShaderModule::set_debug_name(std::string const &name) +{ + debug_name = name; +} + +template +inline void ShaderModule::set_resource_mode(std::string const &resource_name, vkb::core::ShaderResourceMode const &resource_mode) +{ + auto it = std::ranges::find_if(resources, [&resource_name](vkb::core::ShaderResourceCpp const &resource) { return resource.name == resource_name; }); + + if (it != resources.end()) + { + if (resource_mode == vkb::core::ShaderResourceMode::Dynamic) + { + if (it->type == vkb::core::ShaderResourceType::BufferUniform || + it->type == vkb::core::ShaderResourceType::BufferStorage) + { + it->mode = resource_mode; + } + else + { + LOGW("Resource `{}` does not support dynamic.", resource_name); + } + } + else + { + it->mode = resource_mode; + } + } + else + { + LOGW("Resource `{}` not found for shader.", resource_name); + } +} + +} // namespace core } // namespace vkb diff --git a/framework/gui.h b/framework/gui.h index 5f084960d4..016a66b286 100644 --- a/framework/gui.h +++ b/framework/gui.h @@ -485,10 +485,10 @@ inline Gui::Gui( vkb::common::make_filters_valid(device.get_gpu().get_handle(), font_image->get_format(), &filter); // Load shaders - vkb::core::HPPShaderSource vert_shader("imgui.vert.spv"); - vkb::core::HPPShaderSource frag_shader("imgui.frag.spv"); + vkb::core::ShaderSource vert_shader("imgui.vert.spv"); + vkb::core::ShaderSource frag_shader("imgui.frag.spv"); - std::vector shader_modules; + std::vector shader_modules; shader_modules.push_back(&device.get_resource_cache().request_shader_module(vk::ShaderStageFlagBits::eVertex, vert_shader, {})); shader_modules.push_back(&device.get_resource_cache().request_shader_module(vk::ShaderStageFlagBits::eFragment, frag_shader, {})); diff --git a/framework/hpp_resource_cache.cpp b/framework/hpp_resource_cache.cpp index b35d299a99..bf1435c184 100644 --- a/framework/hpp_resource_cache.cpp +++ b/framework/hpp_resource_cache.cpp @@ -84,8 +84,8 @@ vkb::core::HPPDescriptorSet &HPPResourceCache::request_descriptor_set(vkb::core: } vkb::core::HPPDescriptorSetLayout &HPPResourceCache::request_descriptor_set_layout(const uint32_t set_index, - const std::vector &shader_modules, - const std::vector &set_resources) + const std::vector &shader_modules, + const std::vector &set_resources) { return request_resource(device, recorder, descriptor_set_layout_mutex, state.descriptor_set_layouts, set_index, shader_modules, set_resources); } @@ -101,7 +101,7 @@ vkb::core::HPPGraphicsPipeline &HPPResourceCache::request_graphics_pipeline(vkb: return request_resource(device, recorder, graphics_pipeline_mutex, state.graphics_pipelines, pipeline_cache, pipeline_state); } -vkb::core::HPPPipelineLayout &HPPResourceCache::request_pipeline_layout(const std::vector &shader_modules) +vkb::core::HPPPipelineLayout &HPPResourceCache::request_pipeline_layout(const std::vector &shader_modules) { return request_resource(device, recorder, pipeline_layout_mutex, state.pipeline_layouts, shader_modules); } @@ -113,9 +113,9 @@ vkb::core::HPPRenderPass &HPPResourceCache::request_render_pass(const std::vecto return request_resource(device, recorder, render_pass_mutex, state.render_passes, attachments, load_store_infos, subpasses); } -vkb::core::HPPShaderModule &HPPResourceCache::request_shader_module(vk::ShaderStageFlagBits stage, - const vkb::core::HPPShaderSource &glsl_source, - const vkb::core::HPPShaderVariant &shader_variant) +vkb::core::ShaderModuleCpp &HPPResourceCache::request_shader_module(vk::ShaderStageFlagBits stage, + const vkb::core::ShaderSource &glsl_source, + const vkb::core::ShaderVariant &shader_variant) { std::string entry_point{"main"}; return request_resource(device, recorder, shader_module_mutex, state.shader_modules, stage, glsl_source, entry_point, shader_variant); diff --git a/framework/hpp_resource_cache.h b/framework/hpp_resource_cache.h index 9cebfb3be7..f8bae0970f 100644 --- a/framework/hpp_resource_cache.h +++ b/framework/hpp_resource_cache.h @@ -52,7 +52,7 @@ using RenderTargetCpp = RenderTarget; */ struct HPPResourceCacheState { - std::unordered_map shader_modules; + std::unordered_map shader_modules; std::unordered_map pipeline_layouts; std::unordered_map descriptor_set_layouts; std::unordered_map descriptor_pools; @@ -87,16 +87,16 @@ class HPPResourceCache const BindingMap &buffer_infos, const BindingMap &image_infos); vkb::core::HPPDescriptorSetLayout &request_descriptor_set_layout(const uint32_t set_index, - const std::vector &shader_modules, - const std::vector &set_resources); + const std::vector &shader_modules, + const std::vector &set_resources); vkb::core::HPPFramebuffer &request_framebuffer(const vkb::rendering::RenderTargetCpp &render_target, const vkb::core::HPPRenderPass &render_pass); vkb::core::HPPGraphicsPipeline &request_graphics_pipeline(vkb::rendering::PipelineStateCpp &pipeline_state); - vkb::core::HPPPipelineLayout &request_pipeline_layout(const std::vector &shader_modules); + vkb::core::HPPPipelineLayout &request_pipeline_layout(const std::vector &shader_modules); vkb::core::HPPRenderPass &request_render_pass(const std::vector &attachments, const std::vector &load_store_infos, const std::vector &subpasses); - vkb::core::HPPShaderModule &request_shader_module( - vk::ShaderStageFlagBits stage, const vkb::core::HPPShaderSource &glsl_source, const vkb::core::HPPShaderVariant &shader_variant = {}); + vkb::core::ShaderModuleCpp &request_shader_module( + vk::ShaderStageFlagBits stage, const vkb::core::ShaderSource &glsl_source, const vkb::core::ShaderVariant &shader_variant = {}); std::vector serialize(); void set_pipeline_cache(vk::PipelineCache pipeline_cache); diff --git a/framework/hpp_resource_record.h b/framework/hpp_resource_record.h index 39a249cbc5..47dad7655a 100644 --- a/framework/hpp_resource_record.h +++ b/framework/hpp_resource_record.h @@ -31,12 +31,17 @@ namespace core class HPPGraphicsPipeline; class HPPPipelineLayout; class HPPRenderPass; -class HPPShaderModule; -class HPPShaderSource; -class HPPShaderVariant; struct HPPSubpassInfo; } // namespace core +namespace rendering +{ +template +class PipelineState; +using PipelineStateCpp = PipelineState; +using PipelineStateC = PipelineState; +} // namespace rendering + /** * @brief facade class around vkb::ResourceRecord, providing a vulkan.hpp-based interface * @@ -54,9 +59,9 @@ class HPPResourceRecord : private vkb::ResourceRecord reinterpret_cast(pipeline_state)); } - size_t register_pipeline_layout(const std::vector &shader_modules) + size_t register_pipeline_layout(const std::vector &shader_modules) { - return vkb::ResourceRecord::register_pipeline_layout(reinterpret_cast const &>(shader_modules)); + return vkb::ResourceRecord::register_pipeline_layout(reinterpret_cast const &>(shader_modules)); } size_t register_render_pass(const std::vector &attachments, @@ -68,15 +73,15 @@ class HPPResourceRecord : private vkb::ResourceRecord reinterpret_cast const &>(subpasses)); } - size_t register_shader_module(vk::ShaderStageFlagBits stage, - const vkb::core::HPPShaderSource &glsl_source, - const std::string &entry_point, - const vkb::core::HPPShaderVariant &shader_variant) + size_t register_shader_module(vk::ShaderStageFlagBits stage, + const vkb::core::ShaderSource &glsl_source, + const std::string &entry_point, + const vkb::core::ShaderVariant &shader_variant) { return vkb::ResourceRecord::register_shader_module(static_cast(stage), - reinterpret_cast(glsl_source), + reinterpret_cast(glsl_source), entry_point, - reinterpret_cast(shader_variant)); + reinterpret_cast(shader_variant)); } void set_graphics_pipeline(size_t index, const vkb::core::HPPGraphicsPipeline &graphics_pipeline) @@ -94,9 +99,9 @@ class HPPResourceRecord : private vkb::ResourceRecord vkb::ResourceRecord::set_render_pass(index, reinterpret_cast(render_pass)); } - void set_shader_module(size_t index, const vkb::core::HPPShaderModule &shader_module) + void set_shader_module(size_t index, const vkb::core::ShaderModuleCpp &shader_module) { - vkb::ResourceRecord::set_shader_module(index, reinterpret_cast(shader_module)); + vkb::ResourceRecord::set_shader_module(index, reinterpret_cast(shader_module)); } }; } // namespace vkb diff --git a/framework/rendering/postprocessing_computepass.cpp b/framework/rendering/postprocessing_computepass.cpp index f4c83e6ea4..378e81447e 100644 --- a/framework/rendering/postprocessing_computepass.cpp +++ b/framework/rendering/postprocessing_computepass.cpp @@ -21,7 +21,7 @@ namespace vkb { -PostProcessingComputePass::PostProcessingComputePass(PostProcessingPipeline *parent, const ShaderSource &cs_source, const ShaderVariant &cs_variant, +PostProcessingComputePass::PostProcessingComputePass(PostProcessingPipeline *parent, const vkb::core::ShaderSource &cs_source, const vkb::core::ShaderVariant &cs_variant, std::shared_ptr &&default_sampler) : PostProcessingPass{parent}, cs_source{cs_source}, @@ -161,8 +161,8 @@ void PostProcessingComputePass::transition_images(vkb::core::CommandBufferC &com continue; } - const bool readable = !(resource->qualifiers & ShaderResourceQualifiers::NonReadable); - const bool writable = !(resource->qualifiers & ShaderResourceQualifiers::NonReadable); + const bool readable = !(resource->qualifiers & vkb::core::ShaderResourceQualifierFlagBits::NonReadable); + const bool writable = !(resource->qualifiers & vkb::core::ShaderResourceQualifierFlagBits::NonWritable); vkb::ImageMemoryBarrier barrier; barrier.old_layout = storage_rt->get_layout(*attachment); diff --git a/framework/rendering/postprocessing_computepass.h b/framework/rendering/postprocessing_computepass.h index cf9b45e83e..d4aabf5f06 100644 --- a/framework/rendering/postprocessing_computepass.h +++ b/framework/rendering/postprocessing_computepass.h @@ -35,7 +35,7 @@ using SampledImageMap = std::unordered_map; class PostProcessingComputePass : public PostProcessingPass { public: - PostProcessingComputePass(PostProcessingPipeline *parent, const ShaderSource &cs_source, const ShaderVariant &cs_variant = {}, + PostProcessingComputePass(PostProcessingPipeline *parent, const vkb::core::ShaderSource &cs_source, const vkb::core::ShaderVariant &cs_variant = {}, std::shared_ptr &&default_sampler = {}); PostProcessingComputePass(const PostProcessingComputePass &to_copy) = delete; @@ -146,9 +146,9 @@ class PostProcessingComputePass : public PostProcessingPass n_workgroups{1, 1, 1}; + vkb::core::ShaderSource cs_source; + vkb::core::ShaderVariant cs_variant; + glm::tvec3 n_workgroups{1, 1, 1}; std::shared_ptr default_sampler{}; std::shared_ptr default_sampler_nearest{}; diff --git a/framework/rendering/postprocessing_pass.cpp b/framework/rendering/postprocessing_pass.cpp index 385e0ad6ce..121d5f0e84 100644 --- a/framework/rendering/postprocessing_pass.cpp +++ b/framework/rendering/postprocessing_pass.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2020-2025, Arm Limited and Contributors +/* Copyright (c) 2020-2026, Arm Limited and Contributors * * SPDX-License-Identifier: Apache-2.0 * @@ -30,7 +30,7 @@ vkb::rendering::RenderContextC &PostProcessingPassBase::get_render_context() con return *parent->render_context; } -ShaderSource &PostProcessingPassBase::get_triangle_vs() const +vkb::core::ShaderSource &PostProcessingPassBase::get_triangle_vs() const { return parent->triangle_vs; } diff --git a/framework/rendering/postprocessing_pass.h b/framework/rendering/postprocessing_pass.h index d030d18da5..2c5ac9566f 100644 --- a/framework/rendering/postprocessing_pass.h +++ b/framework/rendering/postprocessing_pass.h @@ -89,7 +89,7 @@ class PostProcessingPassBase /** * @brief Returns the parent's fullscreen triangle vertex shader source. */ - ShaderSource &get_triangle_vs() const; + vkb::core::ShaderSource &get_triangle_vs() const; struct BarrierInfo { diff --git a/framework/rendering/postprocessing_pipeline.cpp b/framework/rendering/postprocessing_pipeline.cpp index 83f7d81359..59b7472abe 100644 --- a/framework/rendering/postprocessing_pipeline.cpp +++ b/framework/rendering/postprocessing_pipeline.cpp @@ -21,7 +21,7 @@ namespace vkb { -PostProcessingPipeline::PostProcessingPipeline(vkb::rendering::RenderContextC &render_context, ShaderSource triangle_vs) : +PostProcessingPipeline::PostProcessingPipeline(vkb::rendering::RenderContextC &render_context, vkb::core::ShaderSource triangle_vs) : render_context{&render_context}, triangle_vs{std::move(triangle_vs)} {} diff --git a/framework/rendering/postprocessing_pipeline.h b/framework/rendering/postprocessing_pipeline.h index 91d4663f27..9fceba62b5 100644 --- a/framework/rendering/postprocessing_pipeline.h +++ b/framework/rendering/postprocessing_pipeline.h @@ -34,7 +34,7 @@ class PostProcessingPipeline /** * @brief Creates a rendering pipeline entirely made of fullscreen post-processing subpasses. */ - PostProcessingPipeline(vkb::rendering::RenderContextC &render_context, ShaderSource triangle_vs); + PostProcessingPipeline(vkb::rendering::RenderContextC &render_context, vkb::core::ShaderSource triangle_vs); PostProcessingPipeline(const PostProcessingPipeline &to_copy) = delete; PostProcessingPipeline &operator=(const PostProcessingPipeline &to_copy) = delete; @@ -97,7 +97,7 @@ class PostProcessingPipeline private: vkb::rendering::RenderContextC *render_context{nullptr}; - ShaderSource triangle_vs; + vkb::core::ShaderSource triangle_vs; std::vector> passes{}; size_t current_pass_index{0}; }; diff --git a/framework/rendering/postprocessing_renderpass.cpp b/framework/rendering/postprocessing_renderpass.cpp index ea3bb93749..3d399a0d8d 100644 --- a/framework/rendering/postprocessing_renderpass.cpp +++ b/framework/rendering/postprocessing_renderpass.cpp @@ -26,9 +26,9 @@ constexpr uint32_t ATTACHMENT_BITMASK = 0x7FFFFFFF; PostProcessingSubpass::PostProcessingSubpass(PostProcessingRenderPass *parent, vkb::rendering::RenderContextC &render_context, - ShaderSource &&triangle_vs, - ShaderSource &&fs, - ShaderVariant &&fs_variant) : + vkb::core::ShaderSource &&triangle_vs, + vkb::core::ShaderSource &&fs, + vkb::core::ShaderVariant &&fs_variant) : Subpass(render_context, std::move(triangle_vs), std::move(fs)), parent{parent}, fs_variant{std::move(fs_variant)} @@ -129,7 +129,7 @@ void PostProcessingSubpass::draw(vkb::core::CommandBufferC &command_buffer) auto &vert_shader_module = resource_cache.request_shader_module(VK_SHADER_STAGE_VERTEX_BIT, get_vertex_shader()); auto &frag_shader_module = resource_cache.request_shader_module(VK_SHADER_STAGE_FRAGMENT_BIT, get_fragment_shader(), fs_variant); - std::vector shader_modules{&vert_shader_module, &frag_shader_module}; + std::vector shader_modules{&vert_shader_module, &frag_shader_module}; // Create pipeline layout and bind it auto &pipeline_layout = resource_cache.request_pipeline_layout(shader_modules); diff --git a/framework/rendering/postprocessing_renderpass.h b/framework/rendering/postprocessing_renderpass.h index f19e418146..691dd223dc 100644 --- a/framework/rendering/postprocessing_renderpass.h +++ b/framework/rendering/postprocessing_renderpass.h @@ -73,9 +73,9 @@ class PostProcessingSubpass : public vkb::rendering::SubpassC public: PostProcessingSubpass(PostProcessingRenderPass *parent, vkb::rendering::RenderContextC &render_context, - ShaderSource &&triangle_vs, - ShaderSource &&fs, - ShaderVariant &&fs_variant = {}); + vkb::core::ShaderSource &&triangle_vs, + vkb::core::ShaderSource &&fs, + vkb::core::ShaderVariant &&fs_variant = {}); PostProcessingSubpass(const PostProcessingSubpass &to_copy) = delete; PostProcessingSubpass &operator=(const PostProcessingSubpass &to_copy) = delete; @@ -117,7 +117,7 @@ class PostProcessingSubpass : public vkb::rendering::SubpassC /** * @brief Returns the shader variant used for this postprocess' fragment shader. */ - inline ShaderVariant &get_fs_variant() + inline vkb::core::ShaderVariant &get_fs_variant() { return fs_variant; } @@ -125,7 +125,7 @@ class PostProcessingSubpass : public vkb::rendering::SubpassC /** * @brief Sets the shader variant that will be used for this postprocess' fragment shader. */ - inline PostProcessingSubpass &set_fs_variant(ShaderVariant &&new_variant) + inline PostProcessingSubpass &set_fs_variant(vkb::core::ShaderVariant &&new_variant) { fs_variant = std::move(new_variant); @@ -202,7 +202,7 @@ class PostProcessingSubpass : public vkb::rendering::SubpassC private: PostProcessingRenderPass *parent; - ShaderVariant fs_variant{}; + vkb::core::ShaderVariant fs_variant{}; AttachmentMap input_attachments{}; SampledMap sampled_images{}; @@ -251,9 +251,9 @@ class PostProcessingRenderPass : public PostProcessingPass PostProcessingSubpass &add_subpass(ConstructorArgs &&...args) { - ShaderSource vs_copy = get_triangle_vs(); - auto new_subpass = std::make_unique(this, get_render_context(), std::move(vs_copy), std::forward(args)...); - auto &new_subpass_ref = *new_subpass; + vkb::core::ShaderSource vs_copy = get_triangle_vs(); + auto new_subpass = std::make_unique(this, get_render_context(), std::move(vs_copy), std::forward(args)...); + auto &new_subpass_ref = *new_subpass; pipeline.add_subpass(std::move(new_subpass)); diff --git a/framework/rendering/subpass.h b/framework/rendering/subpass.h index 57fb9d7654..dbaee2b001 100644 --- a/framework/rendering/subpass.h +++ b/framework/rendering/subpass.h @@ -78,10 +78,8 @@ class Subpass using ResolveModeFlagBitsType = typename std::conditional::type; using SampleCountflagBitsType = typename std::conditional::type; - using ShaderSourceType = typename std::conditional::type; - public: - Subpass(vkb::rendering::RenderContext &render_context, ShaderSourceType &&vertex_shader, ShaderSourceType &&fragment_shader); + Subpass(vkb::rendering::RenderContext &render_context, vkb::core::ShaderSource &&vertex_shader, vkb::core::ShaderSource &&fragment_shader); Subpass(const Subpass &) = delete; Subpass(Subpass &&) = default; @@ -111,28 +109,28 @@ class Subpass void allocate_lights(const std::vector &scene_lights, size_t max_lights_per_type); - const std::vector &get_color_resolve_attachments() const; - const std::string &get_debug_name() const; - const uint32_t &get_depth_stencil_resolve_attachment() const; - ResolveModeFlagBitsType get_depth_stencil_resolve_mode() const; - vkb::rendering::DepthStencilState &get_depth_stencil_state(); - const bool &get_disable_depth_stencil_attachment() const; - const ShaderSourceType &get_fragment_shader() const; - const std::vector &get_input_attachments() const; - LightingState &get_lighting_state(); - const std::vector &get_output_attachments() const; - RenderContext &get_render_context(); - std::unordered_map const &get_resource_mode_map() const; - SampleCountflagBitsType get_sample_count() const; - const ShaderSourceType &get_vertex_shader() const; - void set_color_resolve_attachments(std::vector const &color_resolve); - void set_debug_name(const std::string &name); - void set_disable_depth_stencil_attachment(bool disable_depth_stencil); - void set_depth_stencil_resolve_attachment(uint32_t depth_stencil_resolve); - void set_depth_stencil_resolve_mode(ResolveModeFlagBitsType mode); - void set_input_attachments(std::vector const &input); - void set_output_attachments(std::vector const &output); - void set_sample_count(SampleCountflagBitsType sample_count); + const std::vector &get_color_resolve_attachments() const; + const std::string &get_debug_name() const; + const uint32_t &get_depth_stencil_resolve_attachment() const; + ResolveModeFlagBitsType get_depth_stencil_resolve_mode() const; + vkb::rendering::DepthStencilState &get_depth_stencil_state(); + const bool &get_disable_depth_stencil_attachment() const; + const vkb::core::ShaderSource &get_fragment_shader() const; + const std::vector &get_input_attachments() const; + LightingState &get_lighting_state(); + const std::vector &get_output_attachments() const; + RenderContext &get_render_context(); + std::unordered_map const &get_resource_mode_map() const; + SampleCountflagBitsType get_sample_count() const; + const vkb::core::ShaderSource &get_vertex_shader() const; + void set_color_resolve_attachments(std::vector const &color_resolve); + void set_debug_name(const std::string &name); + void set_disable_depth_stencil_attachment(bool disable_depth_stencil); + void set_depth_stencil_resolve_attachment(uint32_t depth_stencil_resolve); + void set_depth_stencil_resolve_mode(ResolveModeFlagBitsType mode); + void set_input_attachments(std::vector const &input); + void set_output_attachments(std::vector const &output); + void set_sample_count(SampleCountflagBitsType sample_count); /** * @brief Updates the render target attachments with the ones stored in this subpass @@ -143,11 +141,9 @@ class Subpass protected: vkb::rendering::DepthStencilStateCpp const &get_depth_stencil_state_impl() const; - vkb::core::HPPShaderSource const &get_fragment_shader_impl() const; LightingStateCpp &get_lighting_state_impl(); vk::SampleCountFlagBits get_sample_count_impl() const; vkb::rendering::RenderContextCpp &get_render_context_impl(); - vkb::core::HPPShaderSource const &get_vertex_shader_impl() const; private: /// Default to no color resolve attachments @@ -176,7 +172,7 @@ class Subpass /// The structure containing all the requested render-ready lights for the scene LightingStateCpp lighting_state{}; - vkb::core::HPPShaderSource fragment_shader; + vkb::core::ShaderSource fragment_shader; /// Default to no input attachments std::vector input_attachments = {}; @@ -187,10 +183,10 @@ class Subpass vkb::rendering::RenderContextCpp &render_context; // A map of shader resource names and the mode of constant data - std::unordered_map resource_mode_map; + std::unordered_map resource_mode_map; - vk::SampleCountFlagBits sample_count{vk::SampleCountFlagBits::e1}; - vkb::core::HPPShaderSource vertex_shader; + vk::SampleCountFlagBits sample_count{vk::SampleCountFlagBits::e1}; + vkb::core::ShaderSource vertex_shader; }; using SubpassC = Subpass; @@ -207,21 +203,10 @@ inline glm::mat4 vulkan_style_projection(const glm::mat4 &proj) template inline Subpass::Subpass(vkb::rendering::RenderContext &render_context, - ShaderSourceType &&vertex_source, - ShaderSourceType &&fragment_source) : - render_context{reinterpret_cast(render_context)} -{ - if constexpr (bindingType == vkb::BindingType::Cpp) - { - vertex_shader = std::move(vertex_source); - fragment_shader = std::move(fragment_source); - } - else - { - vertex_shader = std::move(reinterpret_cast(vertex_source)); - fragment_shader = std::move(reinterpret_cast(fragment_source)); - } -} + vkb::core::ShaderSource &&vertex_source, + vkb::core::ShaderSource &&fragment_source) : + render_context{reinterpret_cast(render_context)}, vertex_shader{std::move(vertex_source)}, fragment_shader{std::move(fragment_source)} +{} template inline const std::vector &Subpass::get_input_attachments() const @@ -262,7 +247,7 @@ inline typename vkb::rendering::RenderContext &Subpass } template -std::unordered_map const &Subpass::get_resource_mode_map() const +std::unordered_map const &Subpass::get_resource_mode_map() const { return resource_mode_map; } @@ -281,16 +266,9 @@ inline typename Subpass::SampleCountflagBitsType Subpass -inline const typename Subpass::ShaderSourceType &Subpass::get_vertex_shader() const +inline const typename vkb::core::ShaderSource &Subpass::get_vertex_shader() const { - if constexpr (bindingType == vkb::BindingType::Cpp) - { - return get_vertex_shader_impl(); - } - else - { - return reinterpret_cast(get_vertex_shader_impl()); - } + return vertex_shader; } template @@ -418,16 +396,9 @@ inline const bool &Subpass::get_disable_depth_stencil_attachment() } template -inline const typename Subpass::ShaderSourceType &Subpass::get_fragment_shader() const +inline const typename vkb::core::ShaderSource &Subpass::get_fragment_shader() const { - if constexpr (bindingType == vkb::BindingType::Cpp) - { - return get_fragment_shader_impl(); - } - else - { - return reinterpret_cast(get_fragment_shader_impl()); - } + return fragment_shader; } template @@ -499,12 +470,6 @@ inline void Subpass::update_render_target_attachments(vkb::renderin render_target.set_output_attachments(output_attachments); } -template -inline vkb::core::HPPShaderSource const &Subpass::get_fragment_shader_impl() const -{ - return fragment_shader; -} - template inline vk::SampleCountFlagBits Subpass::get_sample_count_impl() const { @@ -529,11 +494,5 @@ inline vkb::rendering::RenderContextCpp &Subpass::get_render_contex return render_context; } -template -inline vkb::core::HPPShaderSource const &Subpass::get_vertex_shader_impl() const -{ - return vertex_shader; -} - } // namespace rendering } // namespace vkb diff --git a/framework/rendering/subpasses/forward_subpass.h b/framework/rendering/subpasses/forward_subpass.h index 0be625f2d0..c064df5f1b 100644 --- a/framework/rendering/subpasses/forward_subpass.h +++ b/framework/rendering/subpasses/forward_subpass.h @@ -53,9 +53,6 @@ namespace subpasses template class ForwardSubpass : public vkb::rendering::subpasses::GeometrySubpass { - public: - using ShaderSourceType = typename std::conditional::type; - public: /** * @brief Constructs a subpass designed for forward rendering @@ -66,8 +63,8 @@ class ForwardSubpass : public vkb::rendering::subpasses::GeometrySubpass &render_context, - ShaderSourceType &&vertex_shader, - ShaderSourceType &&fragment_shader, + vkb::core::ShaderSource &&vertex_shader, + vkb::core::ShaderSource &&fragment_shader, vkb::scene_graph::Scene &scene, sg::Camera &camera); @@ -85,8 +82,8 @@ using ForwardSubpassCpp = ForwardSubpass; template inline ForwardSubpass::ForwardSubpass(vkb::rendering::RenderContext &render_context, - ShaderSourceType &&vertex_source, - ShaderSourceType &&fragment_source, + vkb::core::ShaderSource &&vertex_source, + vkb::core::ShaderSource &&fragment_source, vkb::scene_graph::Scene &scene_, sg::Camera &camera) : GeometrySubpass{render_context, std::move(vertex_source), std::move(fragment_source), scene_, camera} @@ -110,8 +107,8 @@ inline void ForwardSubpass::prepare() for (auto &sub_mesh : mesh->get_submeshes()) { auto &variant = sub_mesh->get_mut_shader_variant(); - auto &vert_module = device.get_resource_cache().request_shader_module(vk::ShaderStageFlagBits::eVertex, this->get_vertex_shader_impl(), variant); - auto &frag_module = device.get_resource_cache().request_shader_module(vk::ShaderStageFlagBits::eFragment, this->get_fragment_shader_impl(), variant); + auto &vert_module = device.get_resource_cache().request_shader_module(vk::ShaderStageFlagBits::eVertex, this->get_vertex_shader(), variant); + auto &frag_module = device.get_resource_cache().request_shader_module(vk::ShaderStageFlagBits::eFragment, this->get_fragment_shader(), variant); } } } diff --git a/framework/rendering/subpasses/geometry_subpass.h b/framework/rendering/subpasses/geometry_subpass.h index bec2069ec7..6189bd232c 100644 --- a/framework/rendering/subpasses/geometry_subpass.h +++ b/framework/rendering/subpasses/geometry_subpass.h @@ -89,8 +89,6 @@ class GeometrySubpass : public vkb::rendering::Subpass using MeshType = typename std::conditional::type; using PipelineLayoutType = typename std::conditional::type; - using ShaderModuleType = typename std::conditional::type; - using ShaderSourceType = typename std::conditional::type; using SubMeshType = typename std::conditional::type; public: @@ -103,8 +101,8 @@ class GeometrySubpass : public vkb::rendering::Subpass * @param camera Camera used to look at the scene */ GeometrySubpass(vkb::rendering::RenderContext &render_context, - ShaderSourceType &&vertex_shader, - ShaderSourceType &&fragment_shader, + vkb::core::ShaderSource &&vertex_shader, + vkb::core::ShaderSource &&fragment_shader, vkb::scene_graph::Scene &scene, sg::Camera &camera); @@ -140,7 +138,7 @@ class GeometrySubpass : public vkb::rendering::Subpass uint32_t get_thread_index() const; void set_rasterization_state(const vkb::rendering::RasterizationState &rasterization_state); - virtual PipelineLayoutType &prepare_pipeline_layout(vkb::core::CommandBuffer &command_buffer, const std::vector &shader_modules); + virtual PipelineLayoutType &prepare_pipeline_layout(vkb::core::CommandBuffer &command_buffer, const std::vector *> &shader_modules); virtual void prepare_pipeline_state(vkb::core::CommandBuffer &command_buffer, FrontFaceType front_face, bool double_sided_material); virtual void prepare_push_constants(vkb::core::CommandBuffer &command_buffer, SubMeshType &sub_mesh); virtual void update_uniform(vkb::core::CommandBuffer &command_buffer, vkb::scene_graph::Node &node, size_t thread_index); @@ -156,7 +154,7 @@ class GeometrySubpass : public vkb::rendering::Subpass void get_sorted_nodes_impl(std::multimap> &opaque_nodes, std::multimap> &transparent_nodes); vkb::core::HPPPipelineLayout &prepare_pipeline_layout_impl(vkb::core::CommandBufferCpp &command_buffer, - const std::vector &shader_modules); + const std::vector &shader_modules); void prepare_pipeline_state_impl(vkb::core::CommandBufferCpp &command_buffer, vk::FrontFace front_face, bool double_sided_material); virtual void prepare_push_constants_impl(vkb::core::CommandBufferCpp &command_buffer, vkb::scene_graph::components::HPPSubMesh &sub_mesh); void update_uniform_impl(vkb::core::CommandBufferCpp &command_buffer, vkb::scene_graph::NodeCpp &node, size_t thread_index); @@ -176,8 +174,8 @@ using GeometrySubpassCpp = GeometrySubpass; template inline GeometrySubpass::GeometrySubpass(vkb::rendering::RenderContext &render_context, - ShaderSourceType &&vertex_source, - ShaderSourceType &&fragment_source, + vkb::core::ShaderSource &&vertex_source, + vkb::core::ShaderSource &&fragment_source, vkb::scene_graph::Scene &scene_, sg::Camera &camera) : Subpass{render_context, std::move(vertex_source), std::move(fragment_source)}, camera{camera} @@ -286,8 +284,8 @@ inline void GeometrySubpass::prepare() for (auto &sub_mesh : mesh->get_submeshes()) { auto &variant = sub_mesh->get_shader_variant(); - auto &vert_module = resource_cache.request_shader_module(vk::ShaderStageFlagBits::eVertex, this->get_vertex_shader_impl(), variant); - auto &frag_module = resource_cache.request_shader_module(vk::ShaderStageFlagBits::eFragment, this->get_fragment_shader_impl(), variant); + auto &vert_module = resource_cache.request_shader_module(vk::ShaderStageFlagBits::eVertex, this->get_vertex_shader(), variant); + auto &frag_module = resource_cache.request_shader_module(vk::ShaderStageFlagBits::eFragment, this->get_fragment_shader(), variant); } } } @@ -451,8 +449,8 @@ inline void GeometrySubpass::set_rasterization_state(const vkb::ren template inline typename GeometrySubpass::PipelineLayoutType & - GeometrySubpass::prepare_pipeline_layout(vkb::core::CommandBuffer &command_buffer, - const std::vector &shader_modules) + GeometrySubpass::prepare_pipeline_layout(vkb::core::CommandBuffer &command_buffer, + const std::vector *> &shader_modules) { if constexpr (bindingType == BindingType::Cpp) { @@ -462,14 +460,14 @@ inline typename GeometrySubpass::PipelineLayoutType & { return reinterpret_cast( prepare_pipeline_layout_impl(reinterpret_cast(command_buffer), - reinterpret_cast &>(shader_modules))); + reinterpret_cast &>(shader_modules))); } } template inline vkb::core::HPPPipelineLayout & GeometrySubpass::prepare_pipeline_layout_impl(vkb::core::CommandBufferCpp &command_buffer, - const std::vector &shader_modules) + const std::vector &shader_modules) { // Sets any specified resource modes for (auto &shader_module : shader_modules) @@ -511,13 +509,13 @@ inline void GeometrySubpass::draw_submesh_impl(vkb::core::CommandBu auto &resource_cache = command_buffer.get_device().get_resource_cache(); auto &vert_shader_module = - resource_cache.request_shader_module(vk::ShaderStageFlagBits::eVertex, this->get_vertex_shader_impl(), sub_mesh.get_shader_variant()); + resource_cache.request_shader_module(vk::ShaderStageFlagBits::eVertex, this->get_vertex_shader(), sub_mesh.get_shader_variant()); auto &frag_shader_module = - resource_cache.request_shader_module(vk::ShaderStageFlagBits::eFragment, this->get_fragment_shader_impl(), sub_mesh.get_shader_variant()); + resource_cache.request_shader_module(vk::ShaderStageFlagBits::eFragment, this->get_fragment_shader(), sub_mesh.get_shader_variant()); auto &pipeline_layout = reinterpret_cast( prepare_pipeline_layout(reinterpret_cast &>(command_buffer), - {reinterpret_cast(&vert_shader_module), reinterpret_cast(&frag_shader_module)})); + {reinterpret_cast *>(&vert_shader_module), reinterpret_cast *>(&frag_shader_module)})); command_buffer.bind_pipeline_layout(pipeline_layout); @@ -544,7 +542,7 @@ inline void GeometrySubpass::draw_submesh_impl(vkb::core::CommandBu } } - auto vertex_input_resources = pipeline_layout.get_resources(vkb::core::HPPShaderResourceType::Input, vk::ShaderStageFlagBits::eVertex); + auto vertex_input_resources = pipeline_layout.get_resources(vkb::core::ShaderResourceType::Input, vk::ShaderStageFlagBits::eVertex); vkb::rendering::VertexInputStateCpp vertex_input_state; diff --git a/framework/rendering/subpasses/lighting_subpass.cpp b/framework/rendering/subpasses/lighting_subpass.cpp index 8b0d12980c..04ea3289db 100644 --- a/framework/rendering/subpasses/lighting_subpass.cpp +++ b/framework/rendering/subpasses/lighting_subpass.cpp @@ -27,7 +27,7 @@ namespace vkb { LightingSubpass::LightingSubpass( - vkb::rendering::RenderContextC &render_context, ShaderSource &&vertex_shader, ShaderSource &&fragment_shader, sg::Camera &cam, vkb::scene_graph::SceneC &scene_) : + vkb::rendering::RenderContextC &render_context, vkb::core::ShaderSource &&vertex_shader, vkb::core::ShaderSource &&fragment_shader, sg::Camera &cam, vkb::scene_graph::SceneC &scene_) : Subpass{render_context, std::move(vertex_shader), std::move(fragment_shader)}, camera{cam}, scene{scene_} { } @@ -50,14 +50,14 @@ void LightingSubpass::draw(vkb::core::CommandBufferC &command_buffer) auto &vert_shader_module = resource_cache.request_shader_module(VK_SHADER_STAGE_VERTEX_BIT, get_vertex_shader(), lighting_variant); auto &frag_shader_module = resource_cache.request_shader_module(VK_SHADER_STAGE_FRAGMENT_BIT, get_fragment_shader(), lighting_variant); - std::vector shader_modules{&vert_shader_module, &frag_shader_module}; + std::vector shader_modules{&vert_shader_module, &frag_shader_module}; // Create pipeline layout and bind it auto &pipeline_layout = resource_cache.request_pipeline_layout(shader_modules); command_buffer.bind_pipeline_layout(pipeline_layout); // we know, that the lighting subpass does not have any vertex stage input -> reset the vertex input state - assert(pipeline_layout.get_resources(ShaderResourceType::Input, VK_SHADER_STAGE_VERTEX_BIT).empty()); + assert(pipeline_layout.get_resources(vkb::core::ShaderResourceType::Input, VK_SHADER_STAGE_VERTEX_BIT).empty()); command_buffer.set_vertex_input_state({}); // Get image views of the attachments diff --git a/framework/rendering/subpasses/lighting_subpass.h b/framework/rendering/subpasses/lighting_subpass.h index eca8a598ef..a88a77407f 100644 --- a/framework/rendering/subpasses/lighting_subpass.h +++ b/framework/rendering/subpasses/lighting_subpass.h @@ -66,7 +66,7 @@ class LightingSubpass : public vkb::rendering::SubpassC { public: LightingSubpass( - vkb::rendering::RenderContextC &render_context, ShaderSource &&vertex_shader, ShaderSource &&fragment_shader, sg::Camera &camera, vkb::scene_graph::SceneC &scene); + vkb::rendering::RenderContextC &render_context, vkb::core::ShaderSource &&vertex_shader, vkb::core::ShaderSource &&fragment_shader, sg::Camera &camera, vkb::scene_graph::SceneC &scene); virtual void prepare() override; @@ -77,7 +77,7 @@ class LightingSubpass : public vkb::rendering::SubpassC vkb::scene_graph::SceneC &scene; - ShaderVariant lighting_variant; + vkb::core::ShaderVariant lighting_variant; }; } // namespace vkb diff --git a/framework/resource_cache.cpp b/framework/resource_cache.cpp index 8701645bc2..30851a5d6e 100644 --- a/framework/resource_cache.cpp +++ b/framework/resource_cache.cpp @@ -57,20 +57,20 @@ void ResourceCache::set_pipeline_cache(VkPipelineCache new_pipeline_cache) pipeline_cache = new_pipeline_cache; } -ShaderModule &ResourceCache::request_shader_module(VkShaderStageFlagBits stage, const ShaderSource &glsl_source, const ShaderVariant &shader_variant) +vkb::core::ShaderModuleC &ResourceCache::request_shader_module(VkShaderStageFlagBits stage, const vkb::core::ShaderSource &glsl_source, const vkb::core::ShaderVariant &shader_variant) { std::string entry_point{"main"}; return request_resource(device, recorder, shader_module_mutex, state.shader_modules, stage, glsl_source, entry_point, shader_variant); } -PipelineLayout &ResourceCache::request_pipeline_layout(const std::vector &shader_modules) +PipelineLayout &ResourceCache::request_pipeline_layout(const std::vector &shader_modules) { return request_resource(device, recorder, pipeline_layout_mutex, state.pipeline_layouts, shader_modules); } -DescriptorSetLayout &ResourceCache::request_descriptor_set_layout(const uint32_t set_index, - const std::vector &shader_modules, - const std::vector &set_resources) +DescriptorSetLayout &ResourceCache::request_descriptor_set_layout(const uint32_t set_index, + const std::vector &shader_modules, + const std::vector &set_resources) { return request_resource(device, recorder, descriptor_set_layout_mutex, state.descriptor_set_layouts, set_index, shader_modules, set_resources); } diff --git a/framework/resource_cache.h b/framework/resource_cache.h index 1316b60c81..1f007aaff7 100644 --- a/framework/resource_cache.h +++ b/framework/resource_cache.h @@ -47,7 +47,7 @@ class ImageView; */ struct ResourceCacheState { - std::unordered_map shader_modules; + std::unordered_map shader_modules; std::unordered_map pipeline_layouts; @@ -97,13 +97,13 @@ class ResourceCache void set_pipeline_cache(VkPipelineCache pipeline_cache); - ShaderModule &request_shader_module(VkShaderStageFlagBits stage, const ShaderSource &glsl_source, const ShaderVariant &shader_variant = {}); + vkb::core::ShaderModuleC &request_shader_module(VkShaderStageFlagBits stage, const vkb::core::ShaderSource &glsl_source, const vkb::core::ShaderVariant &shader_variant = {}); - PipelineLayout &request_pipeline_layout(const std::vector &shader_modules); + PipelineLayout &request_pipeline_layout(const std::vector &shader_modules); - DescriptorSetLayout &request_descriptor_set_layout(const uint32_t set_index, - const std::vector &shader_modules, - const std::vector &set_resources); + DescriptorSetLayout &request_descriptor_set_layout(const uint32_t set_index, + const std::vector &shader_modules, + const std::vector &set_resources); GraphicsPipeline &request_graphics_pipeline(vkb::rendering::PipelineStateC &pipeline_state); diff --git a/framework/resource_record.cpp b/framework/resource_record.cpp index a1811a6b6f..ad69ae2f94 100644 --- a/framework/resource_record.cpp +++ b/framework/resource_record.cpp @@ -55,7 +55,7 @@ const std::ostringstream &ResourceRecord::get_stream() return stream; } -size_t ResourceRecord::register_shader_module(VkShaderStageFlagBits stage, const ShaderSource &glsl_source, const std::string &entry_point, const ShaderVariant &shader_variant) +size_t ResourceRecord::register_shader_module(VkShaderStageFlagBits stage, const vkb::core::ShaderSource &glsl_source, const std::string &entry_point, const vkb::core::ShaderVariant &shader_variant) { shader_module_indices.push_back(shader_module_indices.size()); @@ -64,13 +64,13 @@ size_t ResourceRecord::register_shader_module(VkShaderStageFlagBits stage, const return shader_module_indices.back(); } -size_t ResourceRecord::register_pipeline_layout(const std::vector &shader_modules) +size_t ResourceRecord::register_pipeline_layout(const std::vector &shader_modules) { pipeline_layout_indices.push_back(pipeline_layout_indices.size()); std::vector shader_indices(shader_modules.size()); std::transform(shader_modules.begin(), shader_modules.end(), shader_indices.begin(), - [this](ShaderModule *shader_module) { return shader_module_to_index.at(shader_module); }); + [this](vkb::core::ShaderModuleC *shader_module) { return shader_module_to_index.at(shader_module); }); write(stream, ResourceType::PipelineLayout, @@ -134,7 +134,7 @@ size_t ResourceRecord::register_graphics_pipeline(VkPipelineCache /*pipeline_cac return graphics_pipeline_indices.back(); } -void ResourceRecord::set_shader_module(size_t index, const ShaderModule &shader_module) +void ResourceRecord::set_shader_module(size_t index, const vkb::core::ShaderModuleC &shader_module) { shader_module_to_index[&shader_module] = index; } diff --git a/framework/resource_record.h b/framework/resource_record.h index 034b835ee8..e34f24e73b 100644 --- a/framework/resource_record.h +++ b/framework/resource_record.h @@ -18,7 +18,7 @@ #pragma once #include "core/render_pass.h" -#include "rendering/pipeline_state.h" +#include "core/shader_module.h" #include namespace vkb @@ -26,13 +26,16 @@ namespace vkb class GraphicsPipeline; class PipelineLayout; class RenderPass; -class ShaderModule; namespace rendering { template struct Attachment; using AttachmentC = Attachment; + +template +class PipelineState; +using PipelineStateC = PipelineState; } // namespace rendering enum class ResourceType @@ -55,12 +58,12 @@ class ResourceRecord const std::ostringstream &get_stream(); - size_t register_shader_module(VkShaderStageFlagBits stage, - const ShaderSource &glsl_source, - const std::string &entry_point, - const ShaderVariant &shader_variant); + size_t register_shader_module(VkShaderStageFlagBits stage, + const vkb::core::ShaderSource &glsl_source, + const std::string &entry_point, + const vkb::core::ShaderVariant &shader_variant); - size_t register_pipeline_layout(const std::vector &shader_modules); + size_t register_pipeline_layout(const std::vector &shader_modules); size_t register_render_pass(const std::vector &attachments, const std::vector &load_store_infos, @@ -69,7 +72,7 @@ class ResourceRecord size_t register_graphics_pipeline(VkPipelineCache pipeline_cache, vkb::rendering::PipelineStateC &pipeline_state); - void set_shader_module(size_t index, const ShaderModule &shader_module); + void set_shader_module(size_t index, const vkb::core::ShaderModuleC &shader_module); void set_pipeline_layout(size_t index, const PipelineLayout &pipeline_layout); @@ -88,7 +91,7 @@ class ResourceRecord std::vector graphics_pipeline_indices; - std::unordered_map shader_module_to_index; + std::unordered_map shader_module_to_index; std::unordered_map pipeline_layout_to_index; diff --git a/framework/resource_replay.cpp b/framework/resource_replay.cpp index 3dec7c2d71..dd0694cc3c 100644 --- a/framework/resource_replay.cpp +++ b/framework/resource_replay.cpp @@ -90,9 +90,9 @@ void ResourceReplay::create_shader_module(ResourceCache &resource_cache, std::is glsl_source, entry_point); - ShaderSource shader_source{}; + vkb::core::ShaderSource shader_source{}; shader_source.set_source(std::move(glsl_source)); - ShaderVariant shader_variant; + vkb::core::ShaderVariant shader_variant; auto &shader_module = resource_cache.request_shader_module(stage, shader_source, shader_variant); @@ -106,7 +106,7 @@ void ResourceReplay::create_pipeline_layout(ResourceCache &resource_cache, std:: read(stream, shader_indices); - std::vector shader_stages(shader_indices.size()); + std::vector shader_stages(shader_indices.size()); std::transform(shader_indices.begin(), shader_indices.end(), shader_stages.begin(), diff --git a/framework/resource_replay.h b/framework/resource_replay.h index d6cddc3bb1..f096fb6ccc 100644 --- a/framework/resource_replay.h +++ b/framework/resource_replay.h @@ -49,7 +49,7 @@ class ResourceReplay std::unordered_map stream_resources; - std::vector shader_modules; + std::vector shader_modules; std::vector pipeline_layouts; diff --git a/framework/scene_graph/components/hpp_sub_mesh.h b/framework/scene_graph/components/hpp_sub_mesh.h index 7e2dac26cd..4afb2e9591 100644 --- a/framework/scene_graph/components/hpp_sub_mesh.h +++ b/framework/scene_graph/components/hpp_sub_mesh.h @@ -17,7 +17,6 @@ #pragma once -#include #include #include @@ -67,14 +66,14 @@ class HPPSubMesh : private vkb::sg::SubMesh return reinterpret_cast(vkb::sg::SubMesh::get_material()); } - vkb::core::HPPShaderVariant &get_mut_shader_variant() + vkb::core::ShaderVariant &get_mut_shader_variant() { - return reinterpret_cast(vkb::sg::SubMesh::get_mut_shader_variant()); + return reinterpret_cast(vkb::sg::SubMesh::get_mut_shader_variant()); } - const vkb::core::HPPShaderVariant &get_shader_variant() const + const vkb::core::ShaderVariant &get_shader_variant() const { - return reinterpret_cast(vkb::sg::SubMesh::get_shader_variant()); + return reinterpret_cast(vkb::sg::SubMesh::get_shader_variant()); } vkb::core::BufferCpp const &get_vertex_buffer(std::string const &name) const diff --git a/framework/scene_graph/components/sub_mesh.cpp b/framework/scene_graph/components/sub_mesh.cpp index 04b84c0535..d8c5ff2809 100644 --- a/framework/scene_graph/components/sub_mesh.cpp +++ b/framework/scene_graph/components/sub_mesh.cpp @@ -87,12 +87,12 @@ const Material *SubMesh::get_material() const return material; } -const ShaderVariant &SubMesh::get_shader_variant() const +const vkb::core::ShaderVariant &SubMesh::get_shader_variant() const { return shader_variant; } -ShaderVariant &SubMesh::get_mut_shader_variant() +vkb::core::ShaderVariant &SubMesh::get_mut_shader_variant() { return shader_variant; } diff --git a/framework/scene_graph/components/sub_mesh.h b/framework/scene_graph/components/sub_mesh.h index 2b36e5668a..fe33a9f29b 100644 --- a/framework/scene_graph/components/sub_mesh.h +++ b/framework/scene_graph/components/sub_mesh.h @@ -79,16 +79,16 @@ class SubMesh : public Component const Material *get_material() const; - const ShaderVariant &get_shader_variant() const; + const vkb::core::ShaderVariant &get_shader_variant() const; - ShaderVariant &get_mut_shader_variant(); + vkb::core::ShaderVariant &get_mut_shader_variant(); private: std::unordered_map vertex_attributes; const Material *material{nullptr}; - ShaderVariant shader_variant; + vkb::core::ShaderVariant shader_variant; }; } // namespace sg } // namespace vkb diff --git a/framework/spirv_reflection.cpp b/framework/spirv_reflection.cpp deleted file mode 100644 index 83912fb17a..0000000000 --- a/framework/spirv_reflection.cpp +++ /dev/null @@ -1,455 +0,0 @@ -/* Copyright (c) 2019-2020, Arm Limited and Contributors - * - * 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 "spirv_reflection.h" - -namespace vkb -{ -namespace -{ -template -inline void read_shader_resource(const spirv_cross::Compiler &compiler, - VkShaderStageFlagBits stage, - std::vector &resources, - const ShaderVariant & variant) -{ - LOGE("Not implemented! Read shader resources of type."); -} - -template -inline void read_resource_decoration(const spirv_cross::Compiler & /*compiler*/, - const spirv_cross::Resource & /*resource*/, - ShaderResource & /*shader_resource*/, - const ShaderVariant & /* variant */) -{ - LOGE("Not implemented! Read resources decoration of type."); -} - -template <> -inline void read_resource_decoration(const spirv_cross::Compiler &compiler, - const spirv_cross::Resource &resource, - ShaderResource & shader_resource, - const ShaderVariant & variant) -{ - shader_resource.location = compiler.get_decoration(resource.id, spv::DecorationLocation); -} - -template <> -inline void read_resource_decoration(const spirv_cross::Compiler &compiler, - const spirv_cross::Resource &resource, - ShaderResource & shader_resource, - const ShaderVariant & variant) -{ - shader_resource.set = compiler.get_decoration(resource.id, spv::DecorationDescriptorSet); -} - -template <> -inline void read_resource_decoration(const spirv_cross::Compiler &compiler, - const spirv_cross::Resource &resource, - ShaderResource & shader_resource, - const ShaderVariant & variant) -{ - shader_resource.binding = compiler.get_decoration(resource.id, spv::DecorationBinding); -} - -template <> -inline void read_resource_decoration(const spirv_cross::Compiler &compiler, - const spirv_cross::Resource &resource, - ShaderResource & shader_resource, - const ShaderVariant & variant) -{ - shader_resource.input_attachment_index = compiler.get_decoration(resource.id, spv::DecorationInputAttachmentIndex); -} - -template <> -inline void read_resource_decoration(const spirv_cross::Compiler &compiler, - const spirv_cross::Resource &resource, - ShaderResource & shader_resource, - const ShaderVariant & variant) -{ - shader_resource.qualifiers |= ShaderResourceQualifiers::NonWritable; -} - -template <> -inline void read_resource_decoration(const spirv_cross::Compiler &compiler, - const spirv_cross::Resource &resource, - ShaderResource & shader_resource, - const ShaderVariant & variant) -{ - shader_resource.qualifiers |= ShaderResourceQualifiers::NonReadable; -} - -inline void read_resource_vec_size(const spirv_cross::Compiler &compiler, - const spirv_cross::Resource &resource, - ShaderResource & shader_resource, - const ShaderVariant & variant) -{ - const auto &spirv_type = compiler.get_type_from_variable(resource.id); - - shader_resource.vec_size = spirv_type.vecsize; - shader_resource.columns = spirv_type.columns; -} - -inline void read_resource_array_size(const spirv_cross::Compiler &compiler, - const spirv_cross::Resource &resource, - ShaderResource & shader_resource, - const ShaderVariant & variant) -{ - const auto &spirv_type = compiler.get_type_from_variable(resource.id); - - shader_resource.array_size = spirv_type.array.size() ? spirv_type.array[0] : 1; -} - -inline void read_resource_size(const spirv_cross::Compiler &compiler, - const spirv_cross::Resource &resource, - ShaderResource & shader_resource, - const ShaderVariant & variant) -{ - const auto &spirv_type = compiler.get_type_from_variable(resource.id); - - size_t array_size = 0; - if (variant.get_runtime_array_sizes().count(resource.name) != 0) - { - array_size = variant.get_runtime_array_sizes().at(resource.name); - } - - shader_resource.size = to_u32(compiler.get_declared_struct_size_runtime_array(spirv_type, array_size)); -} - -inline void read_resource_size(const spirv_cross::Compiler & compiler, - const spirv_cross::SPIRConstant &constant, - ShaderResource & shader_resource, - const ShaderVariant & variant) -{ - auto spirv_type = compiler.get_type(constant.constant_type); - - switch (spirv_type.basetype) - { - case spirv_cross::SPIRType::BaseType::Boolean: - case spirv_cross::SPIRType::BaseType::Char: - case spirv_cross::SPIRType::BaseType::Int: - case spirv_cross::SPIRType::BaseType::UInt: - case spirv_cross::SPIRType::BaseType::Float: - shader_resource.size = 4; - break; - case spirv_cross::SPIRType::BaseType::Int64: - case spirv_cross::SPIRType::BaseType::UInt64: - case spirv_cross::SPIRType::BaseType::Double: - shader_resource.size = 8; - break; - default: - shader_resource.size = 0; - break; - } -} - -template <> -inline void read_shader_resource(const spirv_cross::Compiler &compiler, - VkShaderStageFlagBits stage, - std::vector &resources, - const ShaderVariant & variant) -{ - auto input_resources = compiler.get_shader_resources().stage_inputs; - - for (auto &resource : input_resources) - { - ShaderResource shader_resource{}; - shader_resource.type = ShaderResourceType::Input; - shader_resource.stages = stage; - shader_resource.name = resource.name; - - read_resource_vec_size(compiler, resource, shader_resource, variant); - read_resource_array_size(compiler, resource, shader_resource, variant); - read_resource_decoration(compiler, resource, shader_resource, variant); - - resources.push_back(shader_resource); - } -} - -template <> -inline void read_shader_resource(const spirv_cross::Compiler &compiler, - VkShaderStageFlagBits /*stage*/, - std::vector &resources, - const ShaderVariant & variant) -{ - auto subpass_resources = compiler.get_shader_resources().subpass_inputs; - - for (auto &resource : subpass_resources) - { - ShaderResource shader_resource{}; - shader_resource.type = ShaderResourceType::InputAttachment; - shader_resource.stages = VK_SHADER_STAGE_FRAGMENT_BIT; - shader_resource.name = resource.name; - - read_resource_array_size(compiler, resource, shader_resource, variant); - read_resource_decoration(compiler, resource, shader_resource, variant); - read_resource_decoration(compiler, resource, shader_resource, variant); - read_resource_decoration(compiler, resource, shader_resource, variant); - - resources.push_back(shader_resource); - } -} - -template <> -inline void read_shader_resource(const spirv_cross::Compiler &compiler, - VkShaderStageFlagBits stage, - std::vector &resources, - const ShaderVariant & variant) -{ - auto output_resources = compiler.get_shader_resources().stage_outputs; - - for (auto &resource : output_resources) - { - ShaderResource shader_resource{}; - shader_resource.type = ShaderResourceType::Output; - shader_resource.stages = stage; - shader_resource.name = resource.name; - - read_resource_array_size(compiler, resource, shader_resource, variant); - read_resource_vec_size(compiler, resource, shader_resource, variant); - read_resource_decoration(compiler, resource, shader_resource, variant); - - resources.push_back(shader_resource); - } -} - -template <> -inline void read_shader_resource(const spirv_cross::Compiler &compiler, - VkShaderStageFlagBits stage, - std::vector &resources, - const ShaderVariant & variant) -{ - auto image_resources = compiler.get_shader_resources().separate_images; - - for (auto &resource : image_resources) - { - ShaderResource shader_resource{}; - shader_resource.type = ShaderResourceType::Image; - shader_resource.stages = stage; - shader_resource.name = resource.name; - - read_resource_array_size(compiler, resource, shader_resource, variant); - read_resource_decoration(compiler, resource, shader_resource, variant); - read_resource_decoration(compiler, resource, shader_resource, variant); - - resources.push_back(shader_resource); - } -} - -template <> -inline void read_shader_resource(const spirv_cross::Compiler &compiler, - VkShaderStageFlagBits stage, - std::vector &resources, - const ShaderVariant & variant) -{ - auto image_resources = compiler.get_shader_resources().sampled_images; - - for (auto &resource : image_resources) - { - ShaderResource shader_resource{}; - shader_resource.type = ShaderResourceType::ImageSampler; - shader_resource.stages = stage; - shader_resource.name = resource.name; - - read_resource_array_size(compiler, resource, shader_resource, variant); - read_resource_decoration(compiler, resource, shader_resource, variant); - read_resource_decoration(compiler, resource, shader_resource, variant); - - resources.push_back(shader_resource); - } -} - -template <> -inline void read_shader_resource(const spirv_cross::Compiler &compiler, - VkShaderStageFlagBits stage, - std::vector &resources, - const ShaderVariant & variant) -{ - auto storage_resources = compiler.get_shader_resources().storage_images; - - for (auto &resource : storage_resources) - { - ShaderResource shader_resource{}; - shader_resource.type = ShaderResourceType::ImageStorage; - shader_resource.stages = stage; - shader_resource.name = resource.name; - - read_resource_array_size(compiler, resource, shader_resource, variant); - read_resource_decoration(compiler, resource, shader_resource, variant); - read_resource_decoration(compiler, resource, shader_resource, variant); - read_resource_decoration(compiler, resource, shader_resource, variant); - read_resource_decoration(compiler, resource, shader_resource, variant); - - resources.push_back(shader_resource); - } -} - -template <> -inline void read_shader_resource(const spirv_cross::Compiler &compiler, - VkShaderStageFlagBits stage, - std::vector &resources, - const ShaderVariant & variant) -{ - auto sampler_resources = compiler.get_shader_resources().separate_samplers; - - for (auto &resource : sampler_resources) - { - ShaderResource shader_resource{}; - shader_resource.type = ShaderResourceType::Sampler; - shader_resource.stages = stage; - shader_resource.name = resource.name; - - read_resource_array_size(compiler, resource, shader_resource, variant); - read_resource_decoration(compiler, resource, shader_resource, variant); - read_resource_decoration(compiler, resource, shader_resource, variant); - - resources.push_back(shader_resource); - } -} - -template <> -inline void read_shader_resource(const spirv_cross::Compiler &compiler, - VkShaderStageFlagBits stage, - std::vector &resources, - const ShaderVariant & variant) -{ - auto uniform_resources = compiler.get_shader_resources().uniform_buffers; - - for (auto &resource : uniform_resources) - { - ShaderResource shader_resource{}; - shader_resource.type = ShaderResourceType::BufferUniform; - shader_resource.stages = stage; - shader_resource.name = resource.name; - - read_resource_size(compiler, resource, shader_resource, variant); - read_resource_array_size(compiler, resource, shader_resource, variant); - read_resource_decoration(compiler, resource, shader_resource, variant); - read_resource_decoration(compiler, resource, shader_resource, variant); - - resources.push_back(shader_resource); - } -} - -template <> -inline void read_shader_resource(const spirv_cross::Compiler &compiler, - VkShaderStageFlagBits stage, - std::vector &resources, - const ShaderVariant & variant) -{ - auto storage_resources = compiler.get_shader_resources().storage_buffers; - - for (auto &resource : storage_resources) - { - ShaderResource shader_resource; - shader_resource.type = ShaderResourceType::BufferStorage; - shader_resource.stages = stage; - shader_resource.name = resource.name; - - read_resource_size(compiler, resource, shader_resource, variant); - read_resource_array_size(compiler, resource, shader_resource, variant); - read_resource_decoration(compiler, resource, shader_resource, variant); - read_resource_decoration(compiler, resource, shader_resource, variant); - read_resource_decoration(compiler, resource, shader_resource, variant); - read_resource_decoration(compiler, resource, shader_resource, variant); - - resources.push_back(shader_resource); - } -} -} // namespace - -bool SPIRVReflection::reflect_shader_resources(VkShaderStageFlagBits stage, const std::vector &spirv, std::vector &resources, const ShaderVariant &variant) -{ - spirv_cross::CompilerGLSL compiler{spirv}; - - auto opts = compiler.get_common_options(); - opts.enable_420pack_extension = true; - - compiler.set_common_options(opts); - - parse_shader_resources(compiler, stage, resources, variant); - parse_push_constants(compiler, stage, resources, variant); - parse_specialization_constants(compiler, stage, resources, variant); - - return true; -} - -void SPIRVReflection::parse_shader_resources(const spirv_cross::Compiler &compiler, VkShaderStageFlagBits stage, std::vector &resources, const ShaderVariant &variant) -{ - read_shader_resource(compiler, stage, resources, variant); - read_shader_resource(compiler, stage, resources, variant); - read_shader_resource(compiler, stage, resources, variant); - read_shader_resource(compiler, stage, resources, variant); - read_shader_resource(compiler, stage, resources, variant); - read_shader_resource(compiler, stage, resources, variant); - read_shader_resource(compiler, stage, resources, variant); - read_shader_resource(compiler, stage, resources, variant); - read_shader_resource(compiler, stage, resources, variant); -} - -void SPIRVReflection::parse_push_constants(const spirv_cross::Compiler &compiler, VkShaderStageFlagBits stage, std::vector &resources, const ShaderVariant &variant) -{ - auto shader_resources = compiler.get_shader_resources(); - - for (auto &resource : shader_resources.push_constant_buffers) - { - const auto &spivr_type = compiler.get_type_from_variable(resource.id); - - std::uint32_t offset = std::numeric_limits::max(); - - for (auto i = 0U; i < spivr_type.member_types.size(); ++i) - { - auto mem_offset = compiler.get_member_decoration(spivr_type.self, i, spv::DecorationOffset); - - offset = std::min(offset, mem_offset); - } - - ShaderResource shader_resource{}; - shader_resource.type = ShaderResourceType::PushConstant; - shader_resource.stages = stage; - shader_resource.name = resource.name; - shader_resource.offset = offset; - - read_resource_size(compiler, resource, shader_resource, variant); - - shader_resource.size -= shader_resource.offset; - - resources.push_back(shader_resource); - } -} - -void SPIRVReflection::parse_specialization_constants(const spirv_cross::Compiler &compiler, VkShaderStageFlagBits stage, std::vector &resources, const ShaderVariant &variant) -{ - auto specialization_constants = compiler.get_specialization_constants(); - - for (auto &resource : specialization_constants) - { - auto &spirv_value = compiler.get_constant(resource.id); - - ShaderResource shader_resource{}; - shader_resource.type = ShaderResourceType::SpecializationConstant; - shader_resource.stages = stage; - shader_resource.name = compiler.get_name(resource.id); - shader_resource.offset = 0; - shader_resource.constant_id = resource.constant_id; - - read_resource_size(compiler, spirv_value, shader_resource, variant); - - resources.push_back(shader_resource); - } -} -} // namespace vkb diff --git a/framework/spirv_reflection.h b/framework/spirv_reflection.h index 3e04977a68..68579596eb 100644 --- a/framework/spirv_reflection.h +++ b/framework/spirv_reflection.h @@ -1,4 +1,5 @@ -/* Copyright (c) 2019-2025, Arm Limited and Contributors +/* Copyright (c) 2019-2026, Arm Limited and Contributors + * Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -17,50 +18,470 @@ #pragma once -#include -#include -#include - -#include "common/error.h" +#include "common/helpers.h" +#include "core/shader_module.h" #pragma warning(push) #pragma warning(disable : 4065) #include #pragma warning(pop) -#include "common/vk_common.h" -#include "core/shader_module.h" - namespace vkb { /// Generate a list of shader resource based on SPIRV reflection code, and provided ShaderVariant +template class SPIRVReflection { + public: + using ShaderStageFlagBitsType = typename std::conditional::type; + public: /// @brief Reflects shader resources from SPIRV code /// @param stage The Vulkan shader stage flag /// @param spirv The SPIRV code of shader /// @param[out] resources The list of reflected shader resources /// @param variant ShaderVariant used for reflection to specify the size of the runtime arrays in Storage Buffers - bool reflect_shader_resources(VkShaderStageFlagBits stage, - const std::vector &spirv, - std::vector &resources, - const ShaderVariant &variant); + bool reflect_shader_resources(ShaderStageFlagBitsType stage, + std::vector const &spirv, + std::vector> &resources, + vkb::core::ShaderVariant const &variant); private: - void parse_shader_resources(const spirv_cross::Compiler &compiler, - VkShaderStageFlagBits stage, - std::vector &resources, - const ShaderVariant &variant); - - void parse_push_constants(const spirv_cross::Compiler &compiler, - VkShaderStageFlagBits stage, - std::vector &resources, - const ShaderVariant &variant); - - void parse_specialization_constants(const spirv_cross::Compiler &compiler, - VkShaderStageFlagBits stage, - std::vector &resources, - const ShaderVariant &variant); + void parse_push_constants(spirv_cross::Compiler const &compiler, + ShaderStageFlagBitsType stage, + std::vector> &resources, + vkb::core::ShaderVariant const &variant); + void parse_shader_resources(spirv_cross::Compiler const &compiler, + ShaderStageFlagBitsType stage, + std::vector> &resources, + vkb::core::ShaderVariant const &variant); + void parse_specialization_constants(spirv_cross::Compiler const &compiler, + ShaderStageFlagBitsType stage, + std::vector> &resources, + vkb::core::ShaderVariant const &variant); }; + +using SPIRVReflectionC = SPIRVReflection; +using SPIRVReflectionCpp = SPIRVReflection; + +namespace +{ +inline void read_resource_size(const spirv_cross::Compiler &compiler, + const spirv_cross::Resource &resource, + vkb::core::ShaderResourceCpp &shader_resource, + const vkb::core::ShaderVariant &variant) +{ + const auto &spirv_type = compiler.get_type_from_variable(resource.id); + + auto const &array_sizes = variant.get_runtime_array_sizes(); + auto it = array_sizes.find(resource.name); + size_t array_size = (it == array_sizes.end()) ? 0 : it->second; + + shader_resource.size = to_u32(compiler.get_declared_struct_size_runtime_array(spirv_type, array_size)); +} + +template +inline void read_resource_decoration([[maybe_unused]] spirv_cross::Compiler const &compiler, + [[maybe_unused]] spirv_cross::Resource const &resource, + [[maybe_unused]] vkb::core::ShaderResourceCpp &shader_resource, + [[maybe_unused]] vkb::core::ShaderVariant const &variant) +{ + LOGE("Not implemented! Read resources decoration of type."); +} + +template <> +inline void read_resource_decoration(spirv_cross::Compiler const &compiler, + spirv_cross::Resource const &resource, + vkb::core::ShaderResourceCpp &shader_resource, + [[maybe_unused]] vkb::core::ShaderVariant const &variant) +{ + shader_resource.binding = compiler.get_decoration(resource.id, spv::DecorationBinding); +} + +template <> +inline void read_resource_decoration(spirv_cross::Compiler const &compiler, + spirv_cross::Resource const &resource, + vkb::core::ShaderResourceCpp &shader_resource, + [[maybe_unused]] vkb::core::ShaderVariant const &variant) +{ + shader_resource.set = compiler.get_decoration(resource.id, spv::DecorationDescriptorSet); +} + +template <> +inline void read_resource_decoration(spirv_cross::Compiler const &compiler, + spirv_cross::Resource const &resource, + vkb::core::ShaderResourceCpp &shader_resource, + [[maybe_unused]] vkb::core::ShaderVariant const &variant) +{ + shader_resource.input_attachment_index = compiler.get_decoration(resource.id, spv::DecorationInputAttachmentIndex); +} + +template <> +inline void read_resource_decoration(spirv_cross::Compiler const &compiler, + spirv_cross::Resource const &resource, + vkb::core::ShaderResourceCpp &shader_resource, + [[maybe_unused]] vkb::core::ShaderVariant const &variant) +{ + shader_resource.location = compiler.get_decoration(resource.id, spv::DecorationLocation); +} + +template <> +inline void read_resource_decoration([[maybe_unused]] spirv_cross::Compiler const &compiler, + [[maybe_unused]] spirv_cross::Resource const &resource, + vkb::core::ShaderResourceCpp &shader_resource, + [[maybe_unused]] vkb::core::ShaderVariant const &variant) +{ + shader_resource.qualifiers |= vkb::core::ShaderResourceQualifierFlagBits::NonReadable; +} + +template <> +inline void read_resource_decoration([[maybe_unused]] spirv_cross::Compiler const &compiler, + [[maybe_unused]] spirv_cross::Resource const &resource, + vkb::core::ShaderResourceCpp &shader_resource, + [[maybe_unused]] vkb::core::ShaderVariant const &variant) +{ + shader_resource.qualifiers |= vkb::core::ShaderResourceQualifierFlagBits::NonWritable; +} + +inline void read_resource_array_size(spirv_cross::Compiler const &compiler, + spirv_cross::Resource const &resource, + vkb::core::ShaderResourceCpp &shader_resource, + [[maybe_unused]] vkb::core::ShaderVariant const &variant) +{ + const auto &spirv_type = compiler.get_type_from_variable(resource.id); + + shader_resource.array_size = spirv_type.array.size() ? spirv_type.array[0] : 1; +} + +inline void read_resource_size(spirv_cross::Compiler const &compiler, + spirv_cross::SPIRConstant const &constant, + vkb::core::ShaderResourceCpp &shader_resource, + [[maybe_unused]] vkb::core::ShaderVariant const &variant) +{ + auto spirv_type = compiler.get_type(constant.constant_type); + + switch (spirv_type.basetype) + { + case spirv_cross::SPIRType::BaseType::Boolean: + case spirv_cross::SPIRType::BaseType::Char: + case spirv_cross::SPIRType::BaseType::Int: + case spirv_cross::SPIRType::BaseType::UInt: + case spirv_cross::SPIRType::BaseType::Float: + shader_resource.size = 4; + break; + case spirv_cross::SPIRType::BaseType::Int64: + case spirv_cross::SPIRType::BaseType::UInt64: + case spirv_cross::SPIRType::BaseType::Double: + shader_resource.size = 8; + break; + default: + shader_resource.size = 0; + break; + } +} + +inline void read_resource_vec_size(spirv_cross::Compiler const &compiler, + spirv_cross::Resource const &resource, + vkb::core::ShaderResourceCpp &shader_resource, + [[maybe_unused]] vkb::core::ShaderVariant const &variant) +{ + const auto &spirv_type = compiler.get_type_from_variable(resource.id); + + shader_resource.vec_size = spirv_type.vecsize; + shader_resource.columns = spirv_type.columns; +} + +template +inline void read_shader_resource([[maybe_unused]] spirv_cross::Compiler const &compiler, + [[maybe_unused]] vk::ShaderStageFlagBits stage, + [[maybe_unused]] std::vector &resources, + [[maybe_unused]] vkb::core::ShaderVariant const &variant) +{ + LOGE("Not implemented! Read shader resources of type."); +} + +template <> +inline void read_shader_resource(spirv_cross::Compiler const &compiler, + vk::ShaderStageFlagBits stage, + std::vector &resources, + vkb::core::ShaderVariant const &variant) +{ + auto input_resources = compiler.get_shader_resources().stage_inputs; + + for (auto &resource : input_resources) + { + vkb::core::ShaderResourceCpp shader_resource{.stages = stage, .type = vkb::core::ShaderResourceType::Input, .name = resource.name}; + + read_resource_vec_size(compiler, resource, shader_resource, variant); + read_resource_array_size(compiler, resource, shader_resource, variant); + read_resource_decoration(compiler, resource, shader_resource, variant); + + resources.push_back(shader_resource); + } +} + +template <> +inline void read_shader_resource(spirv_cross::Compiler const &compiler, + [[maybe_unused]] vk::ShaderStageFlagBits stage, + std::vector &resources, + vkb::core::ShaderVariant const &variant) +{ + auto subpass_resources = compiler.get_shader_resources().subpass_inputs; + + for (auto &resource : subpass_resources) + { + vkb::core::ShaderResourceCpp shader_resource{.stages = vk::ShaderStageFlagBits::eFragment, + .type = vkb::core::ShaderResourceType::InputAttachment, + .name = resource.name}; + + read_resource_array_size(compiler, resource, shader_resource, variant); + read_resource_decoration(compiler, resource, shader_resource, variant); + read_resource_decoration(compiler, resource, shader_resource, variant); + read_resource_decoration(compiler, resource, shader_resource, variant); + + resources.push_back(shader_resource); + } +} + +template <> +inline void read_shader_resource(spirv_cross::Compiler const &compiler, + vk::ShaderStageFlagBits stage, + std::vector &resources, + vkb::core::ShaderVariant const &variant) +{ + auto output_resources = compiler.get_shader_resources().stage_outputs; + + for (auto &resource : output_resources) + { + vkb::core::ShaderResourceCpp shader_resource{.stages = stage, .type = vkb::core::ShaderResourceType::Output, .name = resource.name}; + + read_resource_array_size(compiler, resource, shader_resource, variant); + read_resource_vec_size(compiler, resource, shader_resource, variant); + read_resource_decoration(compiler, resource, shader_resource, variant); + + resources.push_back(shader_resource); + } +} + +template <> +inline void read_shader_resource(spirv_cross::Compiler const &compiler, + vk::ShaderStageFlagBits stage, + std::vector &resources, + vkb::core::ShaderVariant const &variant) +{ + auto image_resources = compiler.get_shader_resources().separate_images; + + for (auto &resource : image_resources) + { + vkb::core::ShaderResourceCpp shader_resource{.stages = stage, .type = vkb::core::ShaderResourceType::Image, .name = resource.name}; + + read_resource_array_size(compiler, resource, shader_resource, variant); + read_resource_decoration(compiler, resource, shader_resource, variant); + read_resource_decoration(compiler, resource, shader_resource, variant); + + resources.push_back(shader_resource); + } +} + +template <> +inline void read_shader_resource(spirv_cross::Compiler const &compiler, + vk::ShaderStageFlagBits stage, + std::vector &resources, + vkb::core::ShaderVariant const &variant) +{ + auto image_resources = compiler.get_shader_resources().sampled_images; + + for (auto &resource : image_resources) + { + vkb::core::ShaderResourceCpp shader_resource{.stages = stage, .type = vkb::core::ShaderResourceType::ImageSampler, .name = resource.name}; + + read_resource_array_size(compiler, resource, shader_resource, variant); + read_resource_decoration(compiler, resource, shader_resource, variant); + read_resource_decoration(compiler, resource, shader_resource, variant); + + resources.push_back(shader_resource); + } +} + +template <> +inline void read_shader_resource(spirv_cross::Compiler const &compiler, + vk::ShaderStageFlagBits stage, + std::vector &resources, + vkb::core::ShaderVariant const &variant) +{ + auto storage_resources = compiler.get_shader_resources().storage_images; + + for (auto &resource : storage_resources) + { + vkb::core::ShaderResourceCpp shader_resource{.stages = stage, .type = vkb::core::ShaderResourceType::ImageStorage, .name = resource.name}; + + read_resource_array_size(compiler, resource, shader_resource, variant); + read_resource_decoration(compiler, resource, shader_resource, variant); + read_resource_decoration(compiler, resource, shader_resource, variant); + read_resource_decoration(compiler, resource, shader_resource, variant); + read_resource_decoration(compiler, resource, shader_resource, variant); + + resources.push_back(shader_resource); + } +} + +template <> +inline void read_shader_resource(spirv_cross::Compiler const &compiler, + vk::ShaderStageFlagBits stage, + std::vector &resources, + vkb::core::ShaderVariant const &variant) +{ + auto sampler_resources = compiler.get_shader_resources().separate_samplers; + + for (auto &resource : sampler_resources) + { + vkb::core::ShaderResourceCpp shader_resource{.stages = stage, .type = vkb::core::ShaderResourceType::Sampler, .name = resource.name}; + + read_resource_array_size(compiler, resource, shader_resource, variant); + read_resource_decoration(compiler, resource, shader_resource, variant); + read_resource_decoration(compiler, resource, shader_resource, variant); + + resources.push_back(shader_resource); + } +} + +template <> +inline void read_shader_resource(spirv_cross::Compiler const &compiler, + vk::ShaderStageFlagBits stage, + std::vector &resources, + vkb::core::ShaderVariant const &variant) +{ + auto uniform_resources = compiler.get_shader_resources().uniform_buffers; + + for (auto &resource : uniform_resources) + { + vkb::core::ShaderResourceCpp shader_resource{.stages = stage, .type = vkb::core::ShaderResourceType::BufferUniform, .name = resource.name}; + + read_resource_size(compiler, resource, shader_resource, variant); + read_resource_array_size(compiler, resource, shader_resource, variant); + read_resource_decoration(compiler, resource, shader_resource, variant); + read_resource_decoration(compiler, resource, shader_resource, variant); + + resources.push_back(shader_resource); + } +} + +template <> +inline void read_shader_resource(spirv_cross::Compiler const &compiler, + vk::ShaderStageFlagBits stage, + std::vector &resources, + vkb::core::ShaderVariant const &variant) +{ + auto storage_resources = compiler.get_shader_resources().storage_buffers; + + for (auto &resource : storage_resources) + { + vkb::core::ShaderResourceCpp shader_resource{.stages = stage, .type = vkb::core::ShaderResourceType::BufferStorage, .name = resource.name}; + + read_resource_size(compiler, resource, shader_resource, variant); + read_resource_array_size(compiler, resource, shader_resource, variant); + read_resource_decoration(compiler, resource, shader_resource, variant); + read_resource_decoration(compiler, resource, shader_resource, variant); + read_resource_decoration(compiler, resource, shader_resource, variant); + read_resource_decoration(compiler, resource, shader_resource, variant); + + resources.push_back(shader_resource); + } +} +} // namespace + +template +inline bool SPIRVReflection::reflect_shader_resources(ShaderStageFlagBitsType stage, + std::vector const &spirv, + std::vector> &resources, + vkb::core::ShaderVariant const &variant) +{ + spirv_cross::CompilerGLSL compiler{spirv}; + + auto opts = compiler.get_common_options(); + opts.enable_420pack_extension = true; + + compiler.set_common_options(opts); + + parse_shader_resources(compiler, stage, resources, variant); + parse_push_constants(compiler, stage, resources, variant); + parse_specialization_constants(compiler, stage, resources, variant); + + return true; +} + +template +inline void SPIRVReflection::parse_push_constants(spirv_cross::Compiler const &compiler, + ShaderStageFlagBitsType stage, + std::vector> &resources, + vkb::core::ShaderVariant const &variant) +{ + auto shader_resources = compiler.get_shader_resources(); + + for (auto &resource : shader_resources.push_constant_buffers) + { + const auto &spivr_type = compiler.get_type_from_variable(resource.id); + + std::uint32_t offset = std::numeric_limits::max(); + + for (auto i = 0U; i < spivr_type.member_types.size(); ++i) + { + auto mem_offset = compiler.get_member_decoration(spivr_type.self, i, spv::DecorationOffset); + + offset = std::min(offset, mem_offset); + } + + vkb::core::ShaderResourceCpp shader_resource{ + .stages = stage, .type = vkb::core::ShaderResourceType::PushConstant, .offset = offset, .name = resource.name}; + + read_resource_size(compiler, resource, shader_resource, variant); + + shader_resource.size -= shader_resource.offset; + + resources.push_back(shader_resource); + } +} + +template +inline void SPIRVReflection::parse_shader_resources(spirv_cross::Compiler const &compiler, + ShaderStageFlagBitsType stage, + std::vector> &resources, + vkb::core::ShaderVariant const &variant) +{ + read_shader_resource(compiler, stage, resources, variant); + read_shader_resource(compiler, stage, resources, variant); + read_shader_resource(compiler, stage, resources, variant); + read_shader_resource(compiler, stage, resources, variant); + read_shader_resource(compiler, stage, resources, variant); + read_shader_resource(compiler, stage, resources, variant); + read_shader_resource(compiler, stage, resources, variant); + read_shader_resource(compiler, stage, resources, variant); + read_shader_resource(compiler, stage, resources, variant); +} + +template +inline void SPIRVReflection::parse_specialization_constants(spirv_cross::Compiler const &compiler, + ShaderStageFlagBitsType stage, + std::vector> &resources, + const vkb::core::ShaderVariant &variant) +{ + auto specialization_constants = compiler.get_specialization_constants(); + + for (auto &resource : specialization_constants) + { + auto &spirv_value = compiler.get_constant(resource.id); + + vkb::core::ShaderResourceCpp shader_resource{ + .stages = stage, + .type = vkb::core::ShaderResourceType::SpecializationConstant, + .offset = 0, + .constant_id = resource.constant_id, + .name = compiler.get_name(resource.id), + }; + + read_resource_size(compiler, spirv_value, shader_resource, variant); + + resources.push_back(shader_resource); + } +} } // namespace vkb diff --git a/samples/extensions/dynamic_multisample_rasterization/dynamic_multisample_rasterization.cpp b/samples/extensions/dynamic_multisample_rasterization/dynamic_multisample_rasterization.cpp index 8217922cd7..dc5b8038bf 100644 --- a/samples/extensions/dynamic_multisample_rasterization/dynamic_multisample_rasterization.cpp +++ b/samples/extensions/dynamic_multisample_rasterization/dynamic_multisample_rasterization.cpp @@ -758,10 +758,10 @@ void DynamicMultisampleRasterization::prepare_gui_pipeline() VkPipelineDynamicStateCreateInfo dynamic_state = vkb::initializers::pipeline_dynamic_state_create_info(dynamic_state_enables); - std::vector shader_modules; + std::vector shader_modules; - vkb::ShaderSource vert_shader("uioverlay/uioverlay.vert.spv"); - vkb::ShaderSource frag_shader("uioverlay/uioverlay.frag.spv"); + vkb::core::ShaderSource vert_shader("uioverlay/uioverlay.vert.spv"); + vkb::core::ShaderSource frag_shader("uioverlay/uioverlay.frag.spv"); shader_modules.push_back(&get_device().get_resource_cache().request_shader_module(VK_SHADER_STAGE_VERTEX_BIT, vert_shader, {})); shader_modules.push_back(&get_device().get_resource_cache().request_shader_module(VK_SHADER_STAGE_FRAGMENT_BIT, frag_shader, {})); diff --git a/samples/extensions/tensor_and_data_graph/compute_shaders_with_tensors/compute_shaders_with_tensors.cpp b/samples/extensions/tensor_and_data_graph/compute_shaders_with_tensors/compute_shaders_with_tensors.cpp index 97c0423d34..ffa7466503 100644 --- a/samples/extensions/tensor_and_data_graph/compute_shaders_with_tensors/compute_shaders_with_tensors.cpp +++ b/samples/extensions/tensor_and_data_graph/compute_shaders_with_tensors/compute_shaders_with_tensors.cpp @@ -380,8 +380,8 @@ void ComputeShadersWithTensors::prepare_data_graph_pipeline_descriptor_set() void ComputeShadersWithTensors::prepare_preprocessing_pipeline() { // Load the compute shader - vkb::ShaderModule &input_comp = - get_device().get_resource_cache().request_shader_module(VK_SHADER_STAGE_COMPUTE_BIT, vkb::ShaderSource{"tensor_and_data_graph/compute_shaders_with_tensors/glsl/preprocessing.comp.spv"}); + vkb::core::ShaderModuleC &input_comp = + get_device().get_resource_cache().request_shader_module(VK_SHADER_STAGE_COMPUTE_BIT, vkb::core::ShaderSource{"tensor_and_data_graph/compute_shaders_with_tensors/glsl/preprocessing.comp.spv"}); // Create pipeline layout from the reflected shader code. Note that this will include bindings to Tensor resources, so we use our own // class to do this, rather than the sample framework's vkb::PipelineLayout. @@ -420,8 +420,8 @@ void ComputeShadersWithTensors::prepare_preprocessing_pipeline_descriptor_set() void ComputeShadersWithTensors::prepare_postprocessing_pipeline() { // Load the compute shader - vkb::ShaderModule &output_comp = - get_device().get_resource_cache().request_shader_module(VK_SHADER_STAGE_COMPUTE_BIT, vkb::ShaderSource{"tensor_and_data_graph/compute_shaders_with_tensors/glsl/postprocessing.comp.spv"}); + vkb::core::ShaderModuleC &output_comp = + get_device().get_resource_cache().request_shader_module(VK_SHADER_STAGE_COMPUTE_BIT, vkb::core::ShaderSource{"tensor_and_data_graph/compute_shaders_with_tensors/glsl/postprocessing.comp.spv"}); // Create pipeline layout from the reflected shader code. Note that this will include bindings to Tensor resources, so we use our own // class to do this, rather than the sample framework's vkb::PipelineLayout. @@ -464,8 +464,8 @@ void ComputeShadersWithTensors::prepare_postprocessing_pipeline_descriptor_set() void ComputeShadersWithTensors::prepare_visualization_pipeline() { // Load the compute shader - vkb::ShaderModule &visualization_comp = - get_device().get_resource_cache().request_shader_module(VK_SHADER_STAGE_COMPUTE_BIT, vkb::ShaderSource{"tensor_and_data_graph/compute_shaders_with_tensors/glsl/visualization_three_tensors.comp.spv"}); + vkb::core::ShaderModuleC &visualization_comp = + get_device().get_resource_cache().request_shader_module(VK_SHADER_STAGE_COMPUTE_BIT, vkb::core::ShaderSource{"tensor_and_data_graph/compute_shaders_with_tensors/glsl/visualization_three_tensors.comp.spv"}); // Create pipeline layout from the reflected shader code. Note that this will include bindings to Tensor resources, so we use our own // class to do this, rather than the sample framework's vkb::PipelineLayout. diff --git a/samples/extensions/tensor_and_data_graph/graph_constants/graph_constants.cpp b/samples/extensions/tensor_and_data_graph/graph_constants/graph_constants.cpp index e6a81cd19f..45c432dadd 100644 --- a/samples/extensions/tensor_and_data_graph/graph_constants/graph_constants.cpp +++ b/samples/extensions/tensor_and_data_graph/graph_constants/graph_constants.cpp @@ -379,8 +379,8 @@ void GraphConstants::prepare_data_graph_pipeline_descriptor_set() void GraphConstants::prepare_visualization_pipeline() { // Load the compute shader - vkb::ShaderModule &visualization_comp = - get_device().get_resource_cache().request_shader_module(VK_SHADER_STAGE_COMPUTE_BIT, vkb::ShaderSource{"tensor_and_data_graph/glsl/visualization_two_tensors.comp.spv"}); + vkb::core::ShaderModuleC &visualization_comp = + get_device().get_resource_cache().request_shader_module(VK_SHADER_STAGE_COMPUTE_BIT, vkb::core::ShaderSource{"tensor_and_data_graph/glsl/visualization_two_tensors.comp.spv"}); // Create pipeline layout from the reflected shader code. Note that this will include bindings to Tensor resources, so we use our own // class to do this, rather than the sample framework's vkb::PipelineLayout. diff --git a/samples/extensions/tensor_and_data_graph/postprocessing_with_vgf/postprocessing_with_vgf.cpp b/samples/extensions/tensor_and_data_graph/postprocessing_with_vgf/postprocessing_with_vgf.cpp index a1235712a3..6cf49ed5b9 100644 --- a/samples/extensions/tensor_and_data_graph/postprocessing_with_vgf/postprocessing_with_vgf.cpp +++ b/samples/extensions/tensor_and_data_graph/postprocessing_with_vgf/postprocessing_with_vgf.cpp @@ -111,9 +111,9 @@ bool PostprocessingWithVgf::prepare(const vkb::ApplicationOptions &options) vkb::sg::Camera &camera = camera_node.get_component(); // Create a forward rendering pipeline to render the scene. - vkb::ShaderSource vert_shader("base.vert.spv"); - vkb::ShaderSource frag_shader("base.frag.spv"); - auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), camera); + vkb::core::ShaderSource vert_shader("base.vert.spv"); + vkb::core::ShaderSource frag_shader("base.frag.spv"); + auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), camera); auto render_pipeline = std::make_unique(); render_pipeline->add_subpass(std::move(scene_subpass)); diff --git a/samples/extensions/tensor_and_data_graph/simple_tensor_and_data_graph/simple_tensor_and_data_graph.cpp b/samples/extensions/tensor_and_data_graph/simple_tensor_and_data_graph/simple_tensor_and_data_graph.cpp index 505955f368..cccae2eea2 100644 --- a/samples/extensions/tensor_and_data_graph/simple_tensor_and_data_graph/simple_tensor_and_data_graph.cpp +++ b/samples/extensions/tensor_and_data_graph/simple_tensor_and_data_graph/simple_tensor_and_data_graph.cpp @@ -261,8 +261,8 @@ void SimpleTensorAndDataGraph::prepare_data_graph_pipeline_descriptor_set() void SimpleTensorAndDataGraph::prepare_visualization_pipeline() { // Load the compute shader - vkb::ShaderModule &visualization_comp = - get_device().get_resource_cache().request_shader_module(VK_SHADER_STAGE_COMPUTE_BIT, vkb::ShaderSource{"tensor_and_data_graph/glsl/visualization_two_tensors.comp.spv"}); + vkb::core::ShaderModuleC &visualization_comp = + get_device().get_resource_cache().request_shader_module(VK_SHADER_STAGE_COMPUTE_BIT, vkb::core::ShaderSource{"tensor_and_data_graph/glsl/visualization_two_tensors.comp.spv"}); // Create pipeline layout from the reflected shader code. Note that this will include bindings to Tensor resources, so we use our own // class to do this, rather than the sample framework's vkb::PipelineLayout. diff --git a/samples/extensions/tensor_and_data_graph/tensor_and_data_graph_common.cpp b/samples/extensions/tensor_and_data_graph/tensor_and_data_graph_common.cpp index e5d9e03ca4..13bb202c48 100644 --- a/samples/extensions/tensor_and_data_graph/tensor_and_data_graph_common.cpp +++ b/samples/extensions/tensor_and_data_graph/tensor_and_data_graph_common.cpp @@ -589,15 +589,15 @@ DataGraphPipelineSession::~DataGraphPipelineSession() } } -ComputePipelineLayoutWithTensors::ComputePipelineLayoutWithTensors(vkb::core::DeviceC &device, vkb::ShaderModule &shader_module) : +ComputePipelineLayoutWithTensors::ComputePipelineLayoutWithTensors(vkb::core::DeviceC &device, vkb::core::ShaderModuleC &shader_module) : vkb::core::VulkanResourceC(nullptr, &device) { // Create a regular vkb::PipelineLayout to reflect all the regular shader resources except tensors - std::unique_ptr layout_without_tensors = std::make_unique(device, std::vector{&shader_module}); + std::unique_ptr layout_without_tensors = std::make_unique(device, std::vector{&shader_module}); // Gather all the binding info that was found std::map> all_bindings; - for (const std::pair> set_and_resources : layout_without_tensors->get_shader_sets()) + for (const std::pair> set_and_resources : layout_without_tensors->get_shader_sets()) { uint32_t set_idx = set_and_resources.first; all_bindings[set_idx] = layout_without_tensors->get_descriptor_set_layout(set_idx).get_bindings(); @@ -650,7 +650,7 @@ ComputePipelineLayoutWithTensors::ComputePipelineLayoutWithTensors(vkb::core::De // Collect all the push constant shader resources std::vector push_constant_ranges; - for (const auto &push_constant_resource : layout_without_tensors->get_resources(vkb::ShaderResourceType::PushConstant)) + for (const auto &push_constant_resource : layout_without_tensors->get_resources(vkb::core::ShaderResourceType::PushConstant)) { push_constant_ranges.push_back({push_constant_resource.stages, push_constant_resource.offset, push_constant_resource.size}); } @@ -675,7 +675,7 @@ const std::map &ComputePipelineLayoutWithTensor return descriptor_set_layouts; } -ComputePipelineWithTensors::ComputePipelineWithTensors(vkb::core::DeviceC &device, VkPipelineLayout layout, vkb::ShaderModule &shader) : +ComputePipelineWithTensors::ComputePipelineWithTensors(vkb::core::DeviceC &device, VkPipelineLayout layout, vkb::core::ShaderModuleC &shader) : vkb::core::VulkanResourceC(VK_NULL_HANDLE, &device) { // Create shader module @@ -705,17 +705,17 @@ ComputePipelineWithTensors::~ComputePipelineWithTensors() } BlitSubpass::BlitSubpass(vkb::rendering::RenderContextC &renderContext, vkb::core::ImageView *source) : - vkb::rendering::SubpassC(renderContext, vkb::ShaderSource{"tensor_and_data_graph/glsl/fullscreen.vert.spv"}, vkb::ShaderSource{"tensor_and_data_graph/glsl/blit.frag.spv"}), + vkb::rendering::SubpassC(renderContext, vkb::core::ShaderSource{"tensor_and_data_graph/glsl/fullscreen.vert.spv"}, vkb::core::ShaderSource{"tensor_and_data_graph/glsl/blit.frag.spv"}), source(source) { } void BlitSubpass::prepare() { - vkb::ShaderModule &fullscreen_vert = - get_render_context().get_device().get_resource_cache().request_shader_module(VK_SHADER_STAGE_VERTEX_BIT, vkb::ShaderSource{"tensor_and_data_graph/glsl/fullscreen.vert.spv"}); - vkb::ShaderModule &blit_frag = - get_render_context().get_device().get_resource_cache().request_shader_module(VK_SHADER_STAGE_FRAGMENT_BIT, vkb::ShaderSource{"tensor_and_data_graph/glsl/blit.frag.spv"}); + vkb::core::ShaderModuleC &fullscreen_vert = + get_render_context().get_device().get_resource_cache().request_shader_module(VK_SHADER_STAGE_VERTEX_BIT, vkb::core::ShaderSource{"tensor_and_data_graph/glsl/fullscreen.vert.spv"}); + vkb::core::ShaderModuleC &blit_frag = + get_render_context().get_device().get_resource_cache().request_shader_module(VK_SHADER_STAGE_FRAGMENT_BIT, vkb::core::ShaderSource{"tensor_and_data_graph/glsl/blit.frag.spv"}); pipeline_layout = &get_render_context().get_device().get_resource_cache().request_pipeline_layout({&fullscreen_vert, &blit_frag}); VkSamplerCreateInfo sampler_create_info{VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO}; diff --git a/samples/extensions/tensor_and_data_graph/tensor_and_data_graph_common.h b/samples/extensions/tensor_and_data_graph/tensor_and_data_graph_common.h index d572308cd4..078fa48422 100644 --- a/samples/extensions/tensor_and_data_graph/tensor_and_data_graph_common.h +++ b/samples/extensions/tensor_and_data_graph/tensor_and_data_graph_common.h @@ -280,7 +280,7 @@ class DataGraphPipelineSession : public vkb::allocated::AllocatedC { public: - ComputePipelineLayoutWithTensors(vkb::core::DeviceC &device, vkb::ShaderModule &shader_module); + ComputePipelineLayoutWithTensors(vkb::core::DeviceC &device, vkb::core::ShaderModuleC &shader_module); ~ComputePipelineLayoutWithTensors(); const std::map &get_descriptor_set_layouts() const; @@ -293,12 +293,12 @@ class ComputePipelineLayoutWithTensors : public vkb::core::VulkanResourceC { public: - ComputePipelineWithTensors(vkb::core::DeviceC &device, VkPipelineLayout layout, vkb::ShaderModule &shader); + ComputePipelineWithTensors(vkb::core::DeviceC &device, VkPipelineLayout layout, vkb::core::ShaderModuleC &shader); ~ComputePipelineWithTensors(); private: diff --git a/samples/extensions/tensor_and_data_graph/tensor_image_aliasing/tensor_image_aliasing.cpp b/samples/extensions/tensor_and_data_graph/tensor_image_aliasing/tensor_image_aliasing.cpp index 6a3435c0dc..ae802181c2 100644 --- a/samples/extensions/tensor_and_data_graph/tensor_image_aliasing/tensor_image_aliasing.cpp +++ b/samples/extensions/tensor_and_data_graph/tensor_image_aliasing/tensor_image_aliasing.cpp @@ -108,9 +108,9 @@ bool TensorImageAliasing::prepare(const vkb::ApplicationOptions &options) vkb::sg::Camera &camera = camera_node.get_component(); // Create a forward rendering pipeline to render the scene. - vkb::ShaderSource vert_shader("base.vert.spv"); - vkb::ShaderSource frag_shader("base.frag.spv"); - auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), camera); + vkb::core::ShaderSource vert_shader("base.vert.spv"); + vkb::core::ShaderSource frag_shader("base.frag.spv"); + auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), camera); auto render_pipeline = std::make_unique(); render_pipeline->add_subpass(std::move(scene_subpass)); diff --git a/samples/performance/16bit_arithmetic/16bit_arithmetic.cpp b/samples/performance/16bit_arithmetic/16bit_arithmetic.cpp index b6e3d683ba..d4cee05699 100644 --- a/samples/performance/16bit_arithmetic/16bit_arithmetic.cpp +++ b/samples/performance/16bit_arithmetic/16bit_arithmetic.cpp @@ -147,24 +147,24 @@ bool KHR16BitArithmeticSample::prepare(const vkb::ApplicationOptions &options) // Load shader modules. auto &module = device.get_resource_cache().request_shader_module(VK_SHADER_STAGE_COMPUTE_BIT, - vkb::ShaderSource{"16bit_arithmetic/compute_buffer.comp.spv"}); + vkb::core::ShaderSource{"16bit_arithmetic/compute_buffer.comp.spv"}); compute_layout = &device.get_resource_cache().request_pipeline_layout({&module}); if (supported_extensions) { - vkb::ShaderVariant variant; + vkb::core::ShaderVariant variant; if (supports_push_constant16) { auto &module_fp16 = device.get_resource_cache().request_shader_module(VK_SHADER_STAGE_COMPUTE_BIT, - vkb::ShaderSource{"16bit_arithmetic/compute_buffer_fp16.comp.spv"}, variant); + vkb::core::ShaderSource{"16bit_arithmetic/compute_buffer_fp16.comp.spv"}, variant); compute_layout_fp16 = &device.get_resource_cache().request_pipeline_layout({&module_fp16}); } else { auto &module_fp16 = device.get_resource_cache().request_shader_module(VK_SHADER_STAGE_COMPUTE_BIT, - vkb::ShaderSource{"16bit_arithmetic/compute_buffer_fp16_fallback.comp.spv"}, variant); + vkb::core::ShaderSource{"16bit_arithmetic/compute_buffer_fp16_fallback.comp.spv"}, variant); compute_layout_fp16 = &device.get_resource_cache().request_pipeline_layout({&module_fp16}); } } @@ -174,9 +174,9 @@ bool KHR16BitArithmeticSample::prepare(const vkb::ApplicationOptions &options) } // Setup the visualization subpass which is there to blit the final result to screen. - vkb::ShaderSource vertex_source{"16bit_arithmetic/visualize.vert.spv"}; - vkb::ShaderSource fragment_source{"16bit_arithmetic/visualize.frag.spv"}; - auto subpass = std::make_unique(get_render_context(), std::move(vertex_source), std::move(fragment_source)); + vkb::core::ShaderSource vertex_source{"16bit_arithmetic/visualize.vert.spv"}; + vkb::core::ShaderSource fragment_source{"16bit_arithmetic/visualize.frag.spv"}; + auto subpass = std::make_unique(get_render_context(), std::move(vertex_source), std::move(fragment_source)); subpass->view = image_view.get(); subpass->sampler = sampler.get(); @@ -190,8 +190,8 @@ bool KHR16BitArithmeticSample::prepare(const vkb::ApplicationOptions &options) } KHR16BitArithmeticSample::VisualizationSubpass::VisualizationSubpass(vkb::rendering::RenderContextC &context, - vkb::ShaderSource &&vertex_source, - vkb::ShaderSource &&fragment_source) : + vkb::core::ShaderSource &&vertex_source, + vkb::core::ShaderSource &&fragment_source) : vkb::rendering::SubpassC(context, std::move(vertex_source), std::move(fragment_source)) { set_output_attachments({0}); @@ -215,10 +215,10 @@ void KHR16BitArithmeticSample::VisualizationSubpass::draw(vkb::core::CommandBuff void KHR16BitArithmeticSample::VisualizationSubpass::prepare() { - auto &device = get_render_context().get_device(); - auto &vert_shader_module = device.get_resource_cache().request_shader_module(VK_SHADER_STAGE_VERTEX_BIT, get_vertex_shader()); - auto &frag_shader_module = device.get_resource_cache().request_shader_module(VK_SHADER_STAGE_FRAGMENT_BIT, get_fragment_shader()); - std::vector shader_modules{&vert_shader_module, &frag_shader_module}; + auto &device = get_render_context().get_device(); + auto &vert_shader_module = device.get_resource_cache().request_shader_module(VK_SHADER_STAGE_VERTEX_BIT, get_vertex_shader()); + auto &frag_shader_module = device.get_resource_cache().request_shader_module(VK_SHADER_STAGE_FRAGMENT_BIT, get_fragment_shader()); + std::vector shader_modules{&vert_shader_module, &frag_shader_module}; layout = &device.get_resource_cache().request_pipeline_layout(shader_modules); } diff --git a/samples/performance/16bit_arithmetic/16bit_arithmetic.h b/samples/performance/16bit_arithmetic/16bit_arithmetic.h index 5cc906e8d3..744d2a33aa 100644 --- a/samples/performance/16bit_arithmetic/16bit_arithmetic.h +++ b/samples/performance/16bit_arithmetic/16bit_arithmetic.h @@ -59,7 +59,7 @@ class KHR16BitArithmeticSample : public vkb::VulkanSampleC struct VisualizationSubpass : vkb::rendering::SubpassC { - VisualizationSubpass(vkb::rendering::RenderContextC &context, vkb::ShaderSource &&vertex_source, vkb::ShaderSource &&fragment_source); + VisualizationSubpass(vkb::rendering::RenderContextC &context, vkb::core::ShaderSource &&vertex_source, vkb::core::ShaderSource &&fragment_source); virtual void prepare() override; virtual void draw(vkb::core::CommandBufferC &command_buffer) override; diff --git a/samples/performance/16bit_storage_input_output/16bit_storage_input_output.cpp b/samples/performance/16bit_storage_input_output/16bit_storage_input_output.cpp index 66fb224e81..faf276256c 100644 --- a/samples/performance/16bit_storage_input_output/16bit_storage_input_output.cpp +++ b/samples/performance/16bit_storage_input_output/16bit_storage_input_output.cpp @@ -154,9 +154,9 @@ void KHR16BitStorageInputOutputSample::update_pipeline() fragment_path = "16bit_storage_input_output_disabled.frag.spv"; } - vkb::ShaderSource vert_shader(base_path + vertex_path); - vkb::ShaderSource frag_shader(base_path + fragment_path); - auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); + vkb::core::ShaderSource vert_shader(base_path + vertex_path); + vkb::core::ShaderSource frag_shader(base_path + fragment_path); + auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); auto render_pipeline = std::make_unique(); render_pipeline->add_subpass(std::move(scene_subpass)); diff --git a/samples/performance/afbc/afbc.cpp b/samples/performance/afbc/afbc.cpp index 1d0120c44e..1aea2ad729 100644 --- a/samples/performance/afbc/afbc.cpp +++ b/samples/performance/afbc/afbc.cpp @@ -60,9 +60,9 @@ bool AFBCSample::prepare(const vkb::ApplicationOptions &options) auto &camera_node = vkb::add_free_camera(get_scene(), "main_camera", get_render_context().get_surface_extent()); camera = &camera_node.get_component(); - vkb::ShaderSource vert_shader("base.vert.spv"); - vkb::ShaderSource frag_shader("base.frag.spv"); - auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); + vkb::core::ShaderSource vert_shader("base.vert.spv"); + vkb::core::ShaderSource frag_shader("base.frag.spv"); + auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); auto render_pipeline = std::make_unique(); render_pipeline->add_subpass(std::move(scene_subpass)); diff --git a/samples/performance/async_compute/async_compute.cpp b/samples/performance/async_compute/async_compute.cpp index 423fa18d09..b0dd50bcd6 100644 --- a/samples/performance/async_compute/async_compute.cpp +++ b/samples/performance/async_compute/async_compute.cpp @@ -265,21 +265,21 @@ bool AsyncComputeSample::prepare(const vkb::ApplicationOptions &options) prepare_render_targets(); - vkb::ShaderSource vert_shader("async_compute/forward.vert.spv"); - vkb::ShaderSource frag_shader("async_compute/forward.frag.spv"); - auto scene_subpass = + vkb::core::ShaderSource vert_shader("async_compute/forward.vert.spv"); + vkb::core::ShaderSource frag_shader("async_compute/forward.frag.spv"); + auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera, *shadow_camera); - vkb::ShaderSource shadow_vert_shader("async_compute/shadow.vert.spv"); - vkb::ShaderSource shadow_frag_shader("async_compute/shadow.frag.spv"); - auto shadow_scene_subpass = + vkb::core::ShaderSource shadow_vert_shader("async_compute/shadow.vert.spv"); + vkb::core::ShaderSource shadow_frag_shader("async_compute/shadow.frag.spv"); + auto shadow_scene_subpass = std::make_unique(get_render_context(), std::move(shadow_vert_shader), std::move(shadow_frag_shader), get_scene(), *shadow_camera); shadow_render_pipeline.add_subpass(std::move(shadow_scene_subpass)); shadow_render_pipeline.set_load_store({{VK_ATTACHMENT_LOAD_OP_CLEAR, VK_ATTACHMENT_STORE_OP_STORE}}); - vkb::ShaderSource composite_vert_shader("async_compute/composite.vert.spv"); - vkb::ShaderSource composite_frag_shader("async_compute/composite.frag.spv"); - auto composite_scene_subpass = + vkb::core::ShaderSource composite_vert_shader("async_compute/composite.vert.spv"); + vkb::core::ShaderSource composite_frag_shader("async_compute/composite.frag.spv"); + auto composite_scene_subpass = std::make_unique(get_render_context(), std::move(composite_vert_shader), std::move(composite_frag_shader)); forward_render_pipeline.add_subpass(std::move(scene_subpass)); @@ -306,11 +306,11 @@ bool AsyncComputeSample::prepare(const vkb::ApplicationOptions &options) create_gui(*window, &get_stats()); auto &threshold_module = get_device().get_resource_cache().request_shader_module(VK_SHADER_STAGE_COMPUTE_BIT, - vkb::ShaderSource("async_compute/threshold.comp.spv")); + vkb::core::ShaderSource("async_compute/threshold.comp.spv")); auto &blur_up_module = get_device().get_resource_cache().request_shader_module(VK_SHADER_STAGE_COMPUTE_BIT, - vkb::ShaderSource("async_compute/blur_up.comp.spv")); + vkb::core::ShaderSource("async_compute/blur_up.comp.spv")); auto &blur_down_module = get_device().get_resource_cache().request_shader_module(VK_SHADER_STAGE_COMPUTE_BIT, - vkb::ShaderSource("async_compute/blur_down.comp.spv")); + vkb::core::ShaderSource("async_compute/blur_down.comp.spv")); threshold_pipeline = &get_device().get_resource_cache().request_pipeline_layout({&threshold_module}); blur_up_pipeline = &get_device().get_resource_cache().request_pipeline_layout({&blur_up_module}); blur_down_pipeline = &get_device().get_resource_cache().request_pipeline_layout({&blur_down_module}); @@ -824,7 +824,7 @@ std::unique_ptr create_async_compute() } AsyncComputeSample::DepthMapSubpass::DepthMapSubpass(vkb::rendering::RenderContextC &render_context, - vkb::ShaderSource &&vertex_shader, vkb::ShaderSource &&fragment_shader, + vkb::core::ShaderSource &&vertex_shader, vkb::core::ShaderSource &&fragment_shader, vkb::scene_graph::SceneC &scene, vkb::sg::Camera &camera) : vkb::rendering::subpasses::ForwardSubpassC(render_context, std::move(vertex_shader), std::move(fragment_shader), scene, camera) { @@ -842,7 +842,7 @@ void AsyncComputeSample::DepthMapSubpass::draw(vkb::core::CommandBufferC &comman } AsyncComputeSample::ShadowMapForwardSubpass::ShadowMapForwardSubpass(vkb::rendering::RenderContextC &render_context, - vkb::ShaderSource &&vertex_shader, vkb::ShaderSource &&fragment_shader, + vkb::core::ShaderSource &&vertex_shader, vkb::core::ShaderSource &&fragment_shader, vkb::scene_graph::SceneC &scene, vkb::sg::Camera &camera, vkb::sg::Camera &shadow_camera_) : vkb::rendering::subpasses::ForwardSubpassC(render_context, std::move(vertex_shader), std::move(fragment_shader), scene, camera), shadow_camera(shadow_camera_) @@ -875,8 +875,8 @@ void AsyncComputeSample::ShadowMapForwardSubpass::draw(vkb::core::CommandBufferC } AsyncComputeSample::CompositeSubpass::CompositeSubpass(vkb::rendering::RenderContextC &render_context, - vkb::ShaderSource &&vertex_shader, - vkb::ShaderSource &&fragment_shader) : + vkb::core::ShaderSource &&vertex_shader, + vkb::core::ShaderSource &&fragment_shader) : vkb::rendering::SubpassC(render_context, std::move(vertex_shader), std::move(fragment_shader)) { } diff --git a/samples/performance/async_compute/async_compute.h b/samples/performance/async_compute/async_compute.h index 9bd925d7c9..c5ffecf8c1 100644 --- a/samples/performance/async_compute/async_compute.h +++ b/samples/performance/async_compute/async_compute.h @@ -84,8 +84,8 @@ class AsyncComputeSample : public vkb::VulkanSampleC struct DepthMapSubpass : vkb::rendering::subpasses::ForwardSubpassC { DepthMapSubpass(vkb::rendering::RenderContextC &render_context, - vkb::ShaderSource &&vertex_shader, - vkb::ShaderSource &&fragment_shader, + vkb::core::ShaderSource &&vertex_shader, + vkb::core::ShaderSource &&fragment_shader, vkb::scene_graph::SceneC &scene, vkb::sg::Camera &camera); virtual void draw(vkb::core::CommandBufferC &command_buffer) override; @@ -94,8 +94,8 @@ class AsyncComputeSample : public vkb::VulkanSampleC struct ShadowMapForwardSubpass : vkb::rendering::subpasses::ForwardSubpassC { ShadowMapForwardSubpass(vkb::rendering::RenderContextC &render_context, - vkb::ShaderSource &&vertex_shader, - vkb::ShaderSource &&fragment_shader, + vkb::core::ShaderSource &&vertex_shader, + vkb::core::ShaderSource &&fragment_shader, vkb::scene_graph::SceneC &scene, vkb::sg::Camera &camera, vkb::sg::Camera &shadow_camera); @@ -109,7 +109,7 @@ class AsyncComputeSample : public vkb::VulkanSampleC struct CompositeSubpass : vkb::rendering::SubpassC { - CompositeSubpass(vkb::rendering::RenderContextC &render_context, vkb::ShaderSource &&vertex_shader, vkb::ShaderSource &&fragment_shader); + CompositeSubpass(vkb::rendering::RenderContextC &render_context, vkb::core::ShaderSource &&vertex_shader, vkb::core::ShaderSource &&fragment_shader); void set_texture(const vkb::core::ImageView *hdr_view, const vkb::core::ImageView *bloom_view, const vkb::core::Sampler *sampler); virtual void draw(vkb::core::CommandBufferC &command_buffer) override; diff --git a/samples/performance/command_buffer_usage/command_buffer_usage.cpp b/samples/performance/command_buffer_usage/command_buffer_usage.cpp index 17a256beba..aacc8a6a4c 100644 --- a/samples/performance/command_buffer_usage/command_buffer_usage.cpp +++ b/samples/performance/command_buffer_usage/command_buffer_usage.cpp @@ -63,9 +63,9 @@ bool CommandBufferUsage::prepare(const vkb::ApplicationOptions &options) auto &camera_node = vkb::add_free_camera(get_scene(), "main_camera", get_render_context().get_surface_extent()); camera = dynamic_cast(&camera_node.get_component()); - vkb::ShaderSource vert_shader("base.vert.spv"); - vkb::ShaderSource frag_shader("base.frag.spv"); - auto scene_subpass = + vkb::core::ShaderSource vert_shader("base.vert.spv"); + vkb::core::ShaderSource frag_shader("base.frag.spv"); + auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); auto render_pipeline = std::make_unique(); @@ -254,8 +254,8 @@ void CommandBufferUsage::draw_renderpass(vkb::core::CommandBufferC &primary_comm } CommandBufferUsage::ForwardSubpassSecondary::ForwardSubpassSecondary(vkb::rendering::RenderContextC &render_context, - vkb::ShaderSource &&vertex_shader, - vkb::ShaderSource &&fragment_shader, + vkb::core::ShaderSource &&vertex_shader, + vkb::core::ShaderSource &&fragment_shader, vkb::scene_graph::SceneC &scene_, vkb::sg::Camera &camera) : vkb::rendering::subpasses::ForwardSubpassC{render_context, std::move(vertex_shader), std::move(fragment_shader), scene_, camera} diff --git a/samples/performance/command_buffer_usage/command_buffer_usage.h b/samples/performance/command_buffer_usage/command_buffer_usage.h index 33a31cd2a4..f224e8c38c 100644 --- a/samples/performance/command_buffer_usage/command_buffer_usage.h +++ b/samples/performance/command_buffer_usage/command_buffer_usage.h @@ -145,8 +145,8 @@ class CommandBufferUsage : public vkb::VulkanSampleC { public: ForwardSubpassSecondary(vkb::rendering::RenderContextC &render_context, - vkb::ShaderSource &&vertex_source, - vkb::ShaderSource &&fragment_source, + vkb::core::ShaderSource &&vertex_source, + vkb::core::ShaderSource &&fragment_source, vkb::scene_graph::SceneC &scene, vkb::sg::Camera &camera); diff --git a/samples/performance/constant_data/constant_data.cpp b/samples/performance/constant_data/constant_data.cpp index 6c11df7500..5c5dc9a4f2 100644 --- a/samples/performance/constant_data/constant_data.cpp +++ b/samples/performance/constant_data/constant_data.cpp @@ -309,8 +309,8 @@ void ConstantData::PushConstantSubpass::update_uniform(vkb::core::CommandBufferC mvp_uniform = fill_mvp(node, get_camera()); } -vkb::PipelineLayout &ConstantData::PushConstantSubpass::prepare_pipeline_layout(vkb::core::CommandBufferC &command_buffer, - const std::vector &shader_modules) +vkb::PipelineLayout &ConstantData::PushConstantSubpass::prepare_pipeline_layout(vkb::core::CommandBufferC &command_buffer, + const std::vector &shader_modules) { /** * POI @@ -361,8 +361,8 @@ void ConstantData::DescriptorSetSubpass::update_uniform(vkb::core::CommandBuffer command_buffer.bind_buffer(allocation.get_buffer(), allocation.get_offset(), allocation.get_size(), 0, 1, 0); } -vkb::PipelineLayout &ConstantData::DescriptorSetSubpass::prepare_pipeline_layout(vkb::core::CommandBufferC &command_buffer, - const std::vector &shader_modules) +vkb::PipelineLayout &ConstantData::DescriptorSetSubpass::prepare_pipeline_layout(vkb::core::CommandBufferC &command_buffer, + const std::vector &shader_modules) { /** * POI @@ -373,15 +373,15 @@ vkb::PipelineLayout &ConstantData::DescriptorSetSubpass::prepare_pipeline_layout { if (method == Method::DescriptorSets) { - shader_module->set_resource_mode("MVPUniform", vkb::ShaderResourceMode::Static); + shader_module->set_resource_mode("MVPUniform", vkb::core::ShaderResourceMode::Static); } else if (method == Method::DynamicDescriptorSets) { - shader_module->set_resource_mode("MVPUniform", vkb::ShaderResourceMode::Dynamic); + shader_module->set_resource_mode("MVPUniform", vkb::core::ShaderResourceMode::Dynamic); } else if (method == Method::UpdateAfterBindDescriptorSets) { - shader_module->set_resource_mode("MVPUniform", vkb::ShaderResourceMode::UpdateAfterBind); + shader_module->set_resource_mode("MVPUniform", vkb::core::ShaderResourceMode::UpdateAfterBind); } } @@ -450,8 +450,8 @@ void ConstantData::BufferArraySubpass::update_uniform(vkb::core::CommandBufferC return; } -vkb::PipelineLayout &ConstantData::BufferArraySubpass::prepare_pipeline_layout(vkb::core::CommandBufferC &command_buffer, - const std::vector &shader_modules) +vkb::PipelineLayout &ConstantData::BufferArraySubpass::prepare_pipeline_layout(vkb::core::CommandBufferC &command_buffer, + const std::vector &shader_modules) { /** * POI diff --git a/samples/performance/constant_data/constant_data.h b/samples/performance/constant_data/constant_data.h index 10669ab41a..43a569703a 100644 --- a/samples/performance/constant_data/constant_data.h +++ b/samples/performance/constant_data/constant_data.h @@ -106,8 +106,8 @@ class ConstantData : public vkb::VulkanSampleC { public: ConstantDataSubpass(vkb::rendering::RenderContextC &render_context, - vkb::ShaderSource &&vertex_shader, - vkb::ShaderSource &&fragment_shader, + vkb::core::ShaderSource &&vertex_shader, + vkb::core::ShaderSource &&fragment_shader, vkb::scene_graph::SceneC &scene, vkb::sg::Camera &camera) : vkb::rendering::subpasses::ForwardSubpassC(render_context, std::move(vertex_shader), std::move(fragment_shader), scene, camera) @@ -127,8 +127,8 @@ class ConstantData : public vkb::VulkanSampleC { public: PushConstantSubpass(vkb::rendering::RenderContextC &render_context, - vkb::ShaderSource &&vertex_shader, - vkb::ShaderSource &&fragment_shader, + vkb::core::ShaderSource &&vertex_shader, + vkb::core::ShaderSource &&fragment_shader, vkb::scene_graph::SceneC &scene, vkb::sg::Camera &camera) : ConstantDataSubpass(render_context, std::move(vertex_shader), std::move(fragment_shader), scene, camera) @@ -142,8 +142,8 @@ class ConstantData : public vkb::VulkanSampleC /** * @brief Overridden to intentionally disable any dynamic shader module updates */ - virtual vkb::PipelineLayout &prepare_pipeline_layout(vkb::core::CommandBufferC &command_buffer, - const std::vector &shader_modules) override; + virtual vkb::PipelineLayout &prepare_pipeline_layout(vkb::core::CommandBufferC &command_buffer, + const std::vector &shader_modules) override; /** * @brief Overridden to push a custom data structure to the shader @@ -164,8 +164,8 @@ class ConstantData : public vkb::VulkanSampleC { public: DescriptorSetSubpass(vkb::rendering::RenderContextC &render_context, - vkb::ShaderSource &&vertex_shader, - vkb::ShaderSource &&fragment_shader, + vkb::core::ShaderSource &&vertex_shader, + vkb::core::ShaderSource &&fragment_shader, vkb::scene_graph::SceneC &scene, vkb::sg::Camera &camera) : ConstantDataSubpass(render_context, std::move(vertex_shader), std::move(fragment_shader), scene, camera) @@ -179,8 +179,8 @@ class ConstantData : public vkb::VulkanSampleC /** * @brief Dynamically retrieves the correct pipeline layout depending on the method of UBO */ - virtual vkb::PipelineLayout &prepare_pipeline_layout(vkb::core::CommandBufferC &command_buffer, - const std::vector &shader_modules) override; + virtual vkb::PipelineLayout &prepare_pipeline_layout(vkb::core::CommandBufferC &command_buffer, + const std::vector &shader_modules) override; /** * @brief Overridden to intentionally disable any push constants @@ -201,8 +201,8 @@ class ConstantData : public vkb::VulkanSampleC { public: BufferArraySubpass(vkb::rendering::RenderContextC &render_context, - vkb::ShaderSource &&vertex_shader, - vkb::ShaderSource &&fragment_shader, + vkb::core::ShaderSource &&vertex_shader, + vkb::core::ShaderSource &&fragment_shader, vkb::scene_graph::SceneC &scene, vkb::sg::Camera &camera) : ConstantDataSubpass(render_context, std::move(vertex_shader), std::move(fragment_shader), scene, camera) @@ -218,8 +218,8 @@ class ConstantData : public vkb::VulkanSampleC /** * @brief Returns a default pipeline layout */ - virtual vkb::PipelineLayout &prepare_pipeline_layout(vkb::core::CommandBufferC &command_buffer, - const std::vector &shader_modules) override; + virtual vkb::PipelineLayout &prepare_pipeline_layout(vkb::core::CommandBufferC &command_buffer, + const std::vector &shader_modules) override; /** * @brief Overridden to intentionally disable any push constants @@ -239,8 +239,8 @@ class ConstantData : public vkb::VulkanSampleC { static_assert(std::is_base_of::value, "T is an invalid type. Must be a derived class from ConstantDataSubpass"); - vkb::ShaderSource vert_shader(vertex_shader); - vkb::ShaderSource frag_shader(fragment_shader); + vkb::core::ShaderSource vert_shader(vertex_shader); + vkb::core::ShaderSource frag_shader(fragment_shader); auto subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); diff --git a/samples/performance/descriptor_management/descriptor_management.cpp b/samples/performance/descriptor_management/descriptor_management.cpp index cab68f1c7f..58263298f5 100644 --- a/samples/performance/descriptor_management/descriptor_management.cpp +++ b/samples/performance/descriptor_management/descriptor_management.cpp @@ -50,10 +50,10 @@ bool DescriptorManagement::prepare(const vkb::ApplicationOptions &options) auto &camera_node = vkb::add_free_camera(get_scene(), "main_camera", get_render_context().get_surface_extent()); camera = dynamic_cast(&camera_node.get_component()); - vkb::ShaderSource vert_shader("base.vert.spv"); - vkb::ShaderSource frag_shader("base.frag.spv"); - auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); - auto render_pipeline = std::make_unique(); + vkb::core::ShaderSource vert_shader("base.vert.spv"); + vkb::core::ShaderSource frag_shader("base.frag.spv"); + auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); + auto render_pipeline = std::make_unique(); render_pipeline->add_subpass(std::move(scene_subpass)); set_render_pipeline(std::move(render_pipeline)); diff --git a/samples/performance/hpp_pipeline_cache/hpp_pipeline_cache.cpp b/samples/performance/hpp_pipeline_cache/hpp_pipeline_cache.cpp index 0d3289e293..0d8823032c 100644 --- a/samples/performance/hpp_pipeline_cache/hpp_pipeline_cache.cpp +++ b/samples/performance/hpp_pipeline_cache/hpp_pipeline_cache.cpp @@ -104,9 +104,9 @@ bool HPPPipelineCache::prepare(const vkb::ApplicationOptions &options) auto &camera_node = vkb::common::add_free_camera(get_scene(), "main_camera", get_render_context().get_surface_extent()); camera = &camera_node.get_component(); - vkb::core::HPPShaderSource vert_shader("base.vert.spv"); - vkb::core::HPPShaderSource frag_shader("base.frag.spv"); - auto scene_subpass = std::make_unique( + vkb::core::ShaderSource vert_shader("base.vert.spv"); + vkb::core::ShaderSource frag_shader("base.frag.spv"); + auto scene_subpass = std::make_unique( get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); auto render_pipeline = std::make_unique(); diff --git a/samples/performance/hpp_swapchain_images/hpp_swapchain_images.cpp b/samples/performance/hpp_swapchain_images/hpp_swapchain_images.cpp index 50f4856d71..455baea266 100644 --- a/samples/performance/hpp_swapchain_images/hpp_swapchain_images.cpp +++ b/samples/performance/hpp_swapchain_images/hpp_swapchain_images.cpp @@ -39,9 +39,9 @@ bool HPPSwapchainImages::prepare(const vkb::ApplicationOptions &options) auto &camera_node = vkb::common::add_free_camera(get_scene(), "main_camera", get_render_context().get_surface_extent()); camera = &camera_node.get_component(); - vkb::core::HPPShaderSource vert_shader("base.vert.spv"); - vkb::core::HPPShaderSource frag_shader("base.frag.spv"); - auto scene_subpass = std::make_unique( + vkb::core::ShaderSource vert_shader("base.vert.spv"); + vkb::core::ShaderSource frag_shader("base.frag.spv"); + auto scene_subpass = std::make_unique( get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); auto render_pipeline = std::make_unique(); diff --git a/samples/performance/hpp_texture_compression_comparison/hpp_texture_compression_comparison.cpp b/samples/performance/hpp_texture_compression_comparison/hpp_texture_compression_comparison.cpp index 435e6dd5ef..206f833010 100644 --- a/samples/performance/hpp_texture_compression_comparison/hpp_texture_compression_comparison.cpp +++ b/samples/performance/hpp_texture_compression_comparison/hpp_texture_compression_comparison.cpp @@ -230,9 +230,9 @@ std::unique_ptr HPPTextureCompressionCom void HPPTextureCompressionComparison::create_subpass() { - vkb::core::HPPShaderSource vert_shader("base.vert.spv"); - vkb::core::HPPShaderSource frag_shader("base.frag.spv"); - auto scene_sub_pass = std::make_unique( + vkb::core::ShaderSource vert_shader("base.vert.spv"); + vkb::core::ShaderSource frag_shader("base.frag.spv"); + auto scene_sub_pass = std::make_unique( get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); auto render_pipeline = std::make_unique(); diff --git a/samples/performance/image_compression_control/image_compression_control.cpp b/samples/performance/image_compression_control/image_compression_control.cpp index 0bfcae08ca..53d09aabbc 100644 --- a/samples/performance/image_compression_control/image_compression_control.cpp +++ b/samples/performance/image_compression_control/image_compression_control.cpp @@ -70,9 +70,9 @@ bool ImageCompressionControlSample::prepare(const vkb::ApplicationOptions &optio auto &camera_node = vkb::add_free_camera(get_scene(), "main_camera", get_render_context().get_surface_extent()); camera = dynamic_cast(&camera_node.get_component()); - vkb::ShaderSource scene_vs("base.vert.spv"); - vkb::ShaderSource scene_fs("base.frag.spv"); - auto scene_subpass = std::make_unique(get_render_context(), std::move(scene_vs), std::move(scene_fs), get_scene(), *camera); + vkb::core::ShaderSource scene_vs("base.vert.spv"); + vkb::core::ShaderSource scene_fs("base.frag.spv"); + auto scene_subpass = std::make_unique(get_render_context(), std::move(scene_vs), std::move(scene_fs), get_scene(), *camera); scene_subpass->set_output_attachments({static_cast(Attachments::Color)}); // Forward rendering pass @@ -82,9 +82,9 @@ bool ImageCompressionControlSample::prepare(const vkb::ApplicationOptions &optio set_render_pipeline(std::move(render_pipeline)); // Post-processing pass (chromatic aberration) - vkb::ShaderSource postprocessing_vs("postprocessing/postprocessing.vert.spv"); + vkb::core::ShaderSource postprocessing_vs("postprocessing/postprocessing.vert.spv"); postprocessing_pipeline = std::make_unique(get_render_context(), std::move(postprocessing_vs)); - postprocessing_pipeline->add_pass().add_subpass(vkb::ShaderSource("postprocessing/chromatic_aberration.frag.spv")); + postprocessing_pipeline->add_pass().add_subpass(vkb::core::ShaderSource("postprocessing/chromatic_aberration.frag.spv")); // Trigger recreation of Swapchain and render targets, with initial compression parameters update_render_targets(); diff --git a/samples/performance/layout_transitions/layout_transitions.cpp b/samples/performance/layout_transitions/layout_transitions.cpp index 592d180a08..ec4efa9f82 100644 --- a/samples/performance/layout_transitions/layout_transitions.cpp +++ b/samples/performance/layout_transitions/layout_transitions.cpp @@ -50,8 +50,8 @@ bool LayoutTransitions::prepare(const vkb::ApplicationOptions &options) auto &camera_node = vkb::add_free_camera(get_scene(), "main_camera", get_render_context().get_surface_extent()); camera = &camera_node.get_component(); - auto geometry_vs = vkb::ShaderSource{"deferred/geometry.vert.spv"}; - auto geometry_fs = vkb::ShaderSource{"deferred/geometry.frag.spv"}; + auto geometry_vs = vkb::core::ShaderSource{"deferred/geometry.vert.spv"}; + auto geometry_fs = vkb::core::ShaderSource{"deferred/geometry.frag.spv"}; std::unique_ptr gbuffer_pass = std::make_unique( get_render_context(), std::move(geometry_vs), std::move(geometry_fs), get_scene(), *camera); @@ -59,8 +59,8 @@ bool LayoutTransitions::prepare(const vkb::ApplicationOptions &options) gbuffer_pipeline.add_subpass(std::move(gbuffer_pass)); gbuffer_pipeline.set_load_store(vkb::gbuffer::get_clear_store_all()); - auto lighting_vs = vkb::ShaderSource{"deferred/lighting.vert.spv"}; - auto lighting_fs = vkb::ShaderSource{"deferred/lighting.frag.spv"}; + auto lighting_vs = vkb::core::ShaderSource{"deferred/lighting.vert.spv"}; + auto lighting_fs = vkb::core::ShaderSource{"deferred/lighting.frag.spv"}; std::unique_ptr lighting_subpass = std::make_unique(get_render_context(), std::move(lighting_vs), std::move(lighting_fs), *camera, get_scene()); diff --git a/samples/performance/msaa/msaa.cpp b/samples/performance/msaa/msaa.cpp index 78ce41c80f..59d4b44074 100644 --- a/samples/performance/msaa/msaa.cpp +++ b/samples/performance/msaa/msaa.cpp @@ -110,19 +110,19 @@ bool MSAASample::prepare(const vkb::ApplicationOptions &options) auto &camera_node = vkb::add_free_camera(get_scene(), "main_camera", get_render_context().get_surface_extent()); camera = dynamic_cast(&camera_node.get_component()); - vkb::ShaderSource scene_vs{"base.vert.spv"}; - vkb::ShaderSource scene_fs{"base.frag.spv"}; - auto scene_subpass = std::make_unique(get_render_context(), std::move(scene_vs), std::move(scene_fs), get_scene(), *camera); - scene_pipeline = std::make_unique(); + vkb::core::ShaderSource scene_vs{"base.vert.spv"}; + vkb::core::ShaderSource scene_fs{"base.frag.spv"}; + auto scene_subpass = std::make_unique(get_render_context(), std::move(scene_vs), std::move(scene_fs), get_scene(), *camera); + scene_pipeline = std::make_unique(); scene_pipeline->add_subpass(std::move(scene_subpass)); - postprocessing_pipeline = std::make_unique(get_render_context(), vkb::ShaderSource{"postprocessing/postprocessing.vert.spv"}); + postprocessing_pipeline = std::make_unique(get_render_context(), vkb::core::ShaderSource{"postprocessing/postprocessing.vert.spv"}); postprocessing_pipeline->add_pass() - .add_subpass(vkb::ShaderSource{"postprocessing/outline.frag.spv"}); + .add_subpass(vkb::core::ShaderSource{"postprocessing/outline.frag.spv"}); - ms_depth_postprocessing_pipeline = std::make_unique(get_render_context(), vkb::ShaderSource{"postprocessing/postprocessing.vert.spv"}); + ms_depth_postprocessing_pipeline = std::make_unique(get_render_context(), vkb::core::ShaderSource{"postprocessing/postprocessing.vert.spv"}); ms_depth_postprocessing_pipeline->add_pass() - .add_subpass(vkb::ShaderSource{"postprocessing/outline_ms_depth.frag.spv"}); + .add_subpass(vkb::core::ShaderSource{"postprocessing/outline_ms_depth.frag.spv"}); update_pipelines(); diff --git a/samples/performance/multithreading_render_passes/multithreading_render_passes.cpp b/samples/performance/multithreading_render_passes/multithreading_render_passes.cpp index cf2390e84f..113fa86f4d 100644 --- a/samples/performance/multithreading_render_passes/multithreading_render_passes.cpp +++ b/samples/performance/multithreading_render_passes/multithreading_render_passes.cpp @@ -113,8 +113,8 @@ std::unique_ptr MultithreadingRenderPasses::creat std::unique_ptr MultithreadingRenderPasses::create_shadow_renderpass() { // Shadowmap subpass - auto shadowmap_vs = vkb::ShaderSource{"shadows/shadowmap.vert.spv"}; - auto shadowmap_fs = vkb::ShaderSource{"shadows/shadowmap.frag.spv"}; + auto shadowmap_vs = vkb::core::ShaderSource{"shadows/shadowmap.vert.spv"}; + auto shadowmap_fs = vkb::core::ShaderSource{"shadows/shadowmap.frag.spv"}; auto scene_subpass = std::make_unique(get_render_context(), std::move(shadowmap_vs), std::move(shadowmap_fs), get_scene(), *shadowmap_camera); shadow_subpass = scene_subpass.get(); @@ -129,8 +129,8 @@ std::unique_ptr MultithreadingRenderPasses::cre std::unique_ptr MultithreadingRenderPasses::create_main_renderpass() { // Main subpass - auto main_vs = vkb::ShaderSource{"shadows/main.vert.spv"}; - auto main_fs = vkb::ShaderSource{"shadows/main.frag.spv"}; + auto main_vs = vkb::core::ShaderSource{"shadows/main.vert.spv"}; + auto main_fs = vkb::core::ShaderSource{"shadows/main.frag.spv"}; auto scene_subpass = std::make_unique( get_render_context(), std::move(main_vs), std::move(main_fs), get_scene(), *camera, *shadowmap_camera, shadow_render_targets); @@ -442,8 +442,8 @@ void MultithreadingRenderPasses::draw_main_pass(vkb::core::CommandBufferC &comma } MultithreadingRenderPasses::MainSubpass::MainSubpass(vkb::rendering::RenderContextC &render_context, - vkb::ShaderSource &&vertex_source, - vkb::ShaderSource &&fragment_source, + vkb::core::ShaderSource &&vertex_source, + vkb::core::ShaderSource &&fragment_source, vkb::scene_graph::SceneC &scene, vkb::sg::Camera &camera, vkb::sg::Camera &shadowmap_camera, @@ -499,8 +499,8 @@ void MultithreadingRenderPasses::MainSubpass::draw(vkb::core::CommandBufferC &co } MultithreadingRenderPasses::ShadowSubpass::ShadowSubpass(vkb::rendering::RenderContextC &render_context, - vkb::ShaderSource &&vertex_source, - vkb::ShaderSource &&fragment_source, + vkb::core::ShaderSource &&vertex_source, + vkb::core::ShaderSource &&fragment_source, vkb::scene_graph::SceneC &scene, vkb::sg::Camera &camera) : vkb::rendering::subpasses::GeometrySubpassC{render_context, std::move(vertex_source), std::move(fragment_source), scene, camera} @@ -531,14 +531,14 @@ void MultithreadingRenderPasses::ShadowSubpass::prepare_pipeline_state(vkb::core command_buffer.set_multisample_state(multisample_state); } -vkb::PipelineLayout &MultithreadingRenderPasses::ShadowSubpass::prepare_pipeline_layout(vkb::core::CommandBufferC &command_buffer, - const std::vector &shader_modules) +vkb::PipelineLayout &MultithreadingRenderPasses::ShadowSubpass::prepare_pipeline_layout(vkb::core::CommandBufferC &command_buffer, + const std::vector &shader_modules) { // Only vertex shader is needed in the shadow subpass assert(!shader_modules.empty()); auto vertex_shader_module = shader_modules[0]; - vertex_shader_module->set_resource_mode("GlobalUniform", vkb::ShaderResourceMode::Dynamic); + vertex_shader_module->set_resource_mode("GlobalUniform", vkb::core::ShaderResourceMode::Dynamic); return command_buffer.get_device().get_resource_cache().request_pipeline_layout({vertex_shader_module}); } diff --git a/samples/performance/multithreading_render_passes/multithreading_render_passes.h b/samples/performance/multithreading_render_passes/multithreading_render_passes.h index c6fac00d93..79c76104e1 100644 --- a/samples/performance/multithreading_render_passes/multithreading_render_passes.h +++ b/samples/performance/multithreading_render_passes/multithreading_render_passes.h @@ -62,16 +62,16 @@ class MultithreadingRenderPasses : public vkb::VulkanSampleC { public: ShadowSubpass(vkb::rendering::RenderContextC &render_context, - vkb::ShaderSource &&vertex_source, - vkb::ShaderSource &&fragment_source, + vkb::core::ShaderSource &&vertex_source, + vkb::core::ShaderSource &&fragment_source, vkb::scene_graph::SceneC &scene, vkb::sg::Camera &camera); protected: virtual void prepare_pipeline_state(vkb::core::CommandBufferC &command_buffer, VkFrontFace front_face, bool double_sided_material) override; - virtual vkb::PipelineLayout &prepare_pipeline_layout(vkb::core::CommandBufferC &command_buffer, - const std::vector &shader_modules) override; + virtual vkb::PipelineLayout &prepare_pipeline_layout(vkb::core::CommandBufferC &command_buffer, + const std::vector &shader_modules) override; virtual void prepare_push_constants(vkb::core::CommandBufferC &command_buffer, vkb::sg::SubMesh &sub_mesh) override; }; @@ -84,8 +84,8 @@ class MultithreadingRenderPasses : public vkb::VulkanSampleC { public: MainSubpass(vkb::rendering::RenderContextC &render_context, - vkb::ShaderSource &&vertex_source, - vkb::ShaderSource &&fragment_source, + vkb::core::ShaderSource &&vertex_source, + vkb::core::ShaderSource &&fragment_source, vkb::scene_graph::SceneC &scene, vkb::sg::Camera &camera, vkb::sg::Camera &shadowmap_camera, diff --git a/samples/performance/pipeline_barriers/pipeline_barriers.cpp b/samples/performance/pipeline_barriers/pipeline_barriers.cpp index 369793db7a..6e13feceae 100644 --- a/samples/performance/pipeline_barriers/pipeline_barriers.cpp +++ b/samples/performance/pipeline_barriers/pipeline_barriers.cpp @@ -84,8 +84,8 @@ bool PipelineBarriers::prepare(const vkb::ApplicationOptions &options) auto &camera_node = vkb::add_free_camera(get_scene(), "main_camera", get_render_context().get_surface_extent()); camera = &camera_node.get_component(); - auto geometry_vs = vkb::ShaderSource{"deferred/geometry.vert.spv"}; - auto geometry_fs = vkb::ShaderSource{"deferred/geometry.frag.spv"}; + auto geometry_vs = vkb::core::ShaderSource{"deferred/geometry.vert.spv"}; + auto geometry_fs = vkb::core::ShaderSource{"deferred/geometry.frag.spv"}; auto gbuffer_pass = std::make_unique( get_render_context(), std::move(geometry_vs), std::move(geometry_fs), get_scene(), *camera); @@ -93,8 +93,8 @@ bool PipelineBarriers::prepare(const vkb::ApplicationOptions &options) gbuffer_pipeline.add_subpass(std::move(gbuffer_pass)); gbuffer_pipeline.set_load_store(vkb::gbuffer::get_clear_store_all()); - auto lighting_vs = vkb::ShaderSource{"deferred/lighting.vert.spv"}; - auto lighting_fs = vkb::ShaderSource{"deferred/lighting.frag.spv"}; + auto lighting_vs = vkb::core::ShaderSource{"deferred/lighting.vert.spv"}; + auto lighting_fs = vkb::core::ShaderSource{"deferred/lighting.frag.spv"}; auto lighting_subpass = std::make_unique(get_render_context(), std::move(lighting_vs), std::move(lighting_fs), *camera, get_scene()); lighting_subpass->set_input_attachments({1, 2, 3}); diff --git a/samples/performance/pipeline_cache/pipeline_cache.cpp b/samples/performance/pipeline_cache/pipeline_cache.cpp index e7f5098976..fa76cc9ebf 100644 --- a/samples/performance/pipeline_cache/pipeline_cache.cpp +++ b/samples/performance/pipeline_cache/pipeline_cache.cpp @@ -136,9 +136,9 @@ bool PipelineCache::prepare(const vkb::ApplicationOptions &options) auto &camera_node = vkb::add_free_camera(get_scene(), "main_camera", get_render_context().get_surface_extent()); camera = &camera_node.get_component(); - vkb::ShaderSource vert_shader("base.vert.spv"); - vkb::ShaderSource frag_shader("base.frag.spv"); - auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); + vkb::core::ShaderSource vert_shader("base.vert.spv"); + vkb::core::ShaderSource frag_shader("base.frag.spv"); + auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); auto render_pipeline = std::make_unique(); render_pipeline->add_subpass(std::move(scene_subpass)); diff --git a/samples/performance/render_passes/render_passes.cpp b/samples/performance/render_passes/render_passes.cpp index 290c6b08f5..690347870b 100644 --- a/samples/performance/render_passes/render_passes.cpp +++ b/samples/performance/render_passes/render_passes.cpp @@ -114,9 +114,9 @@ bool RenderPassesSample::prepare(const vkb::ApplicationOptions &options) auto &camera_node = vkb::add_free_camera(get_scene(), "main_camera", get_render_context().get_surface_extent()); camera = dynamic_cast(&camera_node.get_component()); - vkb::ShaderSource vert_shader("base.vert.spv"); - vkb::ShaderSource frag_shader("base.frag.spv"); - auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); + vkb::core::ShaderSource vert_shader("base.vert.spv"); + vkb::core::ShaderSource frag_shader("base.frag.spv"); + auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); auto render_pipeline = std::make_unique(); render_pipeline->add_subpass(std::move(scene_subpass)); diff --git a/samples/performance/specialization_constants/specialization_constants.cpp b/samples/performance/specialization_constants/specialization_constants.cpp index bf45fd9632..0cc9ddb919 100644 --- a/samples/performance/specialization_constants/specialization_constants.cpp +++ b/samples/performance/specialization_constants/specialization_constants.cpp @@ -35,8 +35,8 @@ SpecializationConstants::SpecializationConstants() } SpecializationConstants::ForwardSubpassCustomLights::ForwardSubpassCustomLights(vkb::rendering::RenderContextC &render_context, - vkb::ShaderSource &&vertex_shader, - vkb::ShaderSource &&fragment_shader, + vkb::core::ShaderSource &&vertex_shader, + vkb::core::ShaderSource &&fragment_shader, vkb::scene_graph::SceneC &scene_, vkb::sg::Camera &camera) : vkb::rendering::subpasses::ForwardSubpassC{render_context, std::move(vertex_shader), std::move(fragment_shader), scene_, camera} @@ -103,9 +103,9 @@ void SpecializationConstants::render(vkb::core::CommandBufferC &command_buffer) std::unique_ptr SpecializationConstants::create_specialization_renderpass() { // Scene subpass - vkb::ShaderSource vert_shader{"base.vert.spv"}; - vkb::ShaderSource frag_shader{"specialization_constants/specialization_constants.frag.spv"}; - auto scene_subpass = + vkb::core::ShaderSource vert_shader{"base.vert.spv"}; + vkb::core::ShaderSource frag_shader{"specialization_constants/specialization_constants.frag.spv"}; + auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); // Create specialization constants pipeline @@ -120,9 +120,9 @@ std::unique_ptr SpecializationConstants::create std::unique_ptr SpecializationConstants::create_standard_renderpass() { // Scene subpass - vkb::ShaderSource vert_shader{"base.vert.spv"}; - vkb::ShaderSource frag_shader{"specialization_constants/UBOs.frag.spv"}; - auto scene_subpass = + vkb::core::ShaderSource vert_shader{"base.vert.spv"}; + vkb::core::ShaderSource frag_shader{"specialization_constants/UBOs.frag.spv"}; + auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); // Create base pipeline diff --git a/samples/performance/specialization_constants/specialization_constants.h b/samples/performance/specialization_constants/specialization_constants.h index 3818149794..1d4da52fd9 100644 --- a/samples/performance/specialization_constants/specialization_constants.h +++ b/samples/performance/specialization_constants/specialization_constants.h @@ -53,8 +53,8 @@ class SpecializationConstants : public vkb::VulkanSampleC { public: ForwardSubpassCustomLights(vkb::rendering::RenderContextC &render_context, - vkb::ShaderSource &&vertex_source, - vkb::ShaderSource &&fragment_source, + vkb::core::ShaderSource &&vertex_source, + vkb::core::ShaderSource &&fragment_source, vkb::scene_graph::SceneC &scene, vkb::sg::Camera &camera); diff --git a/samples/performance/subpasses/subpasses.cpp b/samples/performance/subpasses/subpasses.cpp index ea08914e1f..a7d04ad7d5 100644 --- a/samples/performance/subpasses/subpasses.cpp +++ b/samples/performance/subpasses/subpasses.cpp @@ -300,8 +300,8 @@ void Subpasses::draw_gui() std::unique_ptr Subpasses::create_one_renderpass_two_subpasses() { // Geometry subpass - auto geometry_vs = vkb::ShaderSource{"deferred/geometry.vert.spv"}; - auto geometry_fs = vkb::ShaderSource{"deferred/geometry.frag.spv"}; + auto geometry_vs = vkb::core::ShaderSource{"deferred/geometry.vert.spv"}; + auto geometry_fs = vkb::core::ShaderSource{"deferred/geometry.frag.spv"}; auto scene_subpass = std::make_unique( get_render_context(), std::move(geometry_vs), std::move(geometry_fs), get_scene(), *camera); @@ -309,8 +309,8 @@ std::unique_ptr Subpasses::create_one_renderpas scene_subpass->set_output_attachments({1, 2, 3}); // Lighting subpass - auto lighting_vs = vkb::ShaderSource{"deferred/lighting.vert.spv"}; - auto lighting_fs = vkb::ShaderSource{"deferred/lighting.frag.spv"}; + auto lighting_vs = vkb::core::ShaderSource{"deferred/lighting.vert.spv"}; + auto lighting_fs = vkb::core::ShaderSource{"deferred/lighting.frag.spv"}; auto lighting_subpass = std::make_unique(get_render_context(), std::move(lighting_vs), std::move(lighting_fs), *camera, get_scene()); // Inputs are depth, albedo, and normal from the geometry subpass @@ -333,8 +333,8 @@ std::unique_ptr Subpasses::create_one_renderpas std::unique_ptr Subpasses::create_geometry_renderpass() { // Geometry subpass - auto geometry_vs = vkb::ShaderSource{"deferred/geometry.vert.spv"}; - auto geometry_fs = vkb::ShaderSource{"deferred/geometry.frag.spv"}; + auto geometry_vs = vkb::core::ShaderSource{"deferred/geometry.vert.spv"}; + auto geometry_fs = vkb::core::ShaderSource{"deferred/geometry.frag.spv"}; auto scene_subpass = std::make_unique( get_render_context(), std::move(geometry_vs), std::move(geometry_fs), get_scene(), *camera); @@ -357,8 +357,8 @@ std::unique_ptr Subpasses::create_geometry_rend std::unique_ptr Subpasses::create_lighting_renderpass() { // Lighting subpass - auto lighting_vs = vkb::ShaderSource{"deferred/lighting.vert.spv"}; - auto lighting_fs = vkb::ShaderSource{"deferred/lighting.frag.spv"}; + auto lighting_vs = vkb::core::ShaderSource{"deferred/lighting.vert.spv"}; + auto lighting_fs = vkb::core::ShaderSource{"deferred/lighting.frag.spv"}; auto lighting_subpass = std::make_unique(get_render_context(), std::move(lighting_vs), std::move(lighting_fs), *camera, get_scene()); // Inputs are depth, albedo, and normal from the geometry subpass diff --git a/samples/performance/surface_rotation/surface_rotation.cpp b/samples/performance/surface_rotation/surface_rotation.cpp index 2dc9b07447..acc6f8c4b9 100644 --- a/samples/performance/surface_rotation/surface_rotation.cpp +++ b/samples/performance/surface_rotation/surface_rotation.cpp @@ -62,9 +62,9 @@ bool SurfaceRotation::prepare(const vkb::ApplicationOptions &options) auto &camera_node = vkb::add_free_camera(get_scene(), "main_camera", get_render_context().get_surface_extent()); camera = dynamic_cast(&camera_node.get_component()); - vkb::ShaderSource vert_shader("base.vert.spv"); - vkb::ShaderSource frag_shader("base.frag.spv"); - auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); + vkb::core::ShaderSource vert_shader("base.vert.spv"); + vkb::core::ShaderSource frag_shader("base.frag.spv"); + auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); auto render_pipeline = std::make_unique(); render_pipeline->add_subpass(std::move(scene_subpass)); diff --git a/samples/performance/swapchain_images/swapchain_images.cpp b/samples/performance/swapchain_images/swapchain_images.cpp index f463fc0fd6..115d8f7e76 100644 --- a/samples/performance/swapchain_images/swapchain_images.cpp +++ b/samples/performance/swapchain_images/swapchain_images.cpp @@ -49,9 +49,9 @@ bool SwapchainImages::prepare(const vkb::ApplicationOptions &options) auto &camera_node = vkb::add_free_camera(get_scene(), "main_camera", get_render_context().get_surface_extent()); camera = &camera_node.get_component(); - vkb::ShaderSource vert_shader("base.vert.spv"); - vkb::ShaderSource frag_shader("base.frag.spv"); - auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); + vkb::core::ShaderSource vert_shader("base.vert.spv"); + vkb::core::ShaderSource frag_shader("base.frag.spv"); + auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); auto render_pipeline = std::make_unique(); render_pipeline->add_subpass(std::move(scene_subpass)); diff --git a/samples/performance/texture_compression_comparison/texture_compression_comparison.cpp b/samples/performance/texture_compression_comparison/texture_compression_comparison.cpp index 089083ba12..7e8439ed52 100644 --- a/samples/performance/texture_compression_comparison/texture_compression_comparison.cpp +++ b/samples/performance/texture_compression_comparison/texture_compression_comparison.cpp @@ -209,9 +209,9 @@ void TextureCompressionComparison::load_assets() void TextureCompressionComparison::create_subpass() { - vkb::ShaderSource vert_shader("base.vert.spv"); - vkb::ShaderSource frag_shader("base.frag.spv"); - auto scene_sub_pass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); + vkb::core::ShaderSource vert_shader("base.vert.spv"); + vkb::core::ShaderSource frag_shader("base.frag.spv"); + auto scene_sub_pass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); auto render_pipeline = std::make_unique(); render_pipeline->add_subpass(std::move(scene_sub_pass)); diff --git a/samples/performance/wait_idle/wait_idle.cpp b/samples/performance/wait_idle/wait_idle.cpp index 2caaa87230..7e05fb9c87 100644 --- a/samples/performance/wait_idle/wait_idle.cpp +++ b/samples/performance/wait_idle/wait_idle.cpp @@ -48,10 +48,10 @@ bool WaitIdle::prepare(const vkb::ApplicationOptions &options) camera = dynamic_cast(&camera_node.get_component()); // Example Scene Render Pipeline - vkb::ShaderSource vert_shader("base.vert.spv"); - vkb::ShaderSource frag_shader("base.frag.spv"); - auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); - auto render_pipeline = std::make_unique(); + vkb::core::ShaderSource vert_shader("base.vert.spv"); + vkb::core::ShaderSource frag_shader("base.frag.spv"); + auto scene_subpass = std::make_unique(get_render_context(), std::move(vert_shader), std::move(frag_shader), get_scene(), *camera); + auto render_pipeline = std::make_unique(); render_pipeline->add_subpass(std::move(scene_subpass)); set_render_pipeline(std::move(render_pipeline));