From 622a0936b109004ec5c226755fe5091b8c74b14b Mon Sep 17 00:00:00 2001 From: ouczbs Date: Sat, 2 Nov 2024 17:55:55 +0800 Subject: [PATCH] git push --- engine/3rdparty/xmake.lua | 2 +- engine/assets/shader/simple.vert | 7 +- .../render/include/render/asset/shader.h | 11 ++- .../include/render/tool/glsl_to_spirv.h | 4 + .../engine/render/include/render/type.h | 17 ++++ .../engine/render/src/tool/glsl_to_spirv.cpp | 81 ++++++++++++++++++- engine/modules/engine/render/xmake.lua | 2 +- .../modules/engine/zlib/include/meta/enum.h | 9 ++- .../include/vkn/loader/vulkan_glsl_loader.h | 4 + .../modules/render/vulkan/include/vkn/type.h | 9 ++- .../vulkan/include/vkn/vulkan_api_help.h | 4 + .../include/vkn/wrapper/descriptorpool.h | 3 + .../vulkan/src/loader/vulkan_glsl_loader.cpp | 65 ++++++++++++++- .../modules/render/vulkan/src/vulkan_api.cpp | 35 +++++--- .../render/vulkan/src/vulkan_api_help.cpp | 22 +++++ 15 files changed, 247 insertions(+), 28 deletions(-) diff --git a/engine/3rdparty/xmake.lua b/engine/3rdparty/xmake.lua index 5dbb98c..de6aef7 100644 --- a/engine/3rdparty/xmake.lua +++ b/engine/3rdparty/xmake.lua @@ -1 +1 @@ -add_requires("spdlog", "lemon", "libsdl", "vulkansdk","shaderc") \ No newline at end of file +add_requires("spdlog", "lemon", "libsdl", "vulkansdk","shaderc","spirv","spirv-cross") \ No newline at end of file diff --git a/engine/assets/shader/simple.vert b/engine/assets/shader/simple.vert index 9bc5b28..c1b5970 100644 --- a/engine/assets/shader/simple.vert +++ b/engine/assets/shader/simple.vert @@ -1,10 +1,13 @@ #version 450 layout (location = 0) in vec3 iPos; +layout(set = 0, binding = 0) uniform ColorData { + vec4 uColor; // 从 uniform buffer 获取颜色 +}; layout (location = 0) out vec4 vColor; void main() { - gl_Position = vec4(iPos.x, iPos.y, iPos.z, 1.0); - vColor = vec4(1.0, 0.0, 0.0, 1.0); + gl_Position = vec4(iPos, 1.0); + vColor = uColor; // 使用 uniform 颜色 } diff --git a/engine/modules/engine/render/include/render/asset/shader.h b/engine/modules/engine/render/include/render/asset/shader.h index 316be4d..b763596 100644 --- a/engine/modules/engine/render/include/render/asset/shader.h +++ b/engine/modules/engine/render/include/render/asset/shader.h @@ -1,7 +1,16 @@ #pragma once #include "asset/asset.h" +#include "render/type.h" namespace api { - class ShaderProgram : public Resource {}; + class ShaderProgram : public Resource { + protected: + ShaderStage mStage; + public: + ShaderProgram(ShaderStage stage) : mStage(stage) {}; + ShaderStage GetStage() { + return mStage; + } + }; class Shader : public Asset { private: UPROPERTY() diff --git a/engine/modules/engine/render/include/render/tool/glsl_to_spirv.h b/engine/modules/engine/render/include/render/tool/glsl_to_spirv.h index b666c13..38a08a8 100644 --- a/engine/modules/engine/render/include/render/tool/glsl_to_spirv.h +++ b/engine/modules/engine/render/include/render/tool/glsl_to_spirv.h @@ -1,5 +1,6 @@ #pragma once #include "pmr/name.h" +#include "render/asset/shader.h" #include #include namespace api @@ -11,6 +12,9 @@ namespace api { public: static shaderc_shader_kind GetShaderKind(Name name); + static ShaderStage GetShaderStage(shaderc_shader_kind kind); static optional> ToSpirv(const pmr::string& glsl, shaderc_shader_kind kind, string_view code_id = "unknown_shader"); + static void LoadShaderLayout(ShaderProgram* program, const pmr::vector& spirv); + static void GetShaderLayout(ShaderDescriptorSet& descriptorSet, pmr::vector& programList); }; } \ No newline at end of file diff --git a/engine/modules/engine/render/include/render/type.h b/engine/modules/engine/render/include/render/type.h index 03df8da..eee3ed5 100644 --- a/engine/modules/engine/render/include/render/type.h +++ b/engine/modules/engine/render/include/render/type.h @@ -65,6 +65,23 @@ namespace api { TEX_3D = 0x04, TEX_CUBE = 0x08, }; + enum class ShaderDescriptorType : uint8_t{ + UNIFORM_BUFFER, + SAMPLER, + }; + enum class ShaderStage : uint32_t { + NONE = 0, + VERTEX = 0x1, + FRAGMENT = 0x2, + }; + struct ShaderDescriptorLayout { + uint32_t set : 8; + uint32_t binding : 8; + uint32_t size : 16; + ShaderDescriptorType type; + ShaderStage stageFlags; + }; + using ShaderDescriptorSet = pmr::vector; using ImagePtr = void*; using ImageViewPtr = void*; using BufferPtr = void*; diff --git a/engine/modules/engine/render/src/tool/glsl_to_spirv.cpp b/engine/modules/engine/render/src/tool/glsl_to_spirv.cpp index dbf5513..f6a1c7f 100644 --- a/engine/modules/engine/render/src/tool/glsl_to_spirv.cpp +++ b/engine/modules/engine/render/src/tool/glsl_to_spirv.cpp @@ -1,8 +1,12 @@ #include "render/tool/glsl_to_spirv.h" -#include +#include "render/type.h" #include "zlog.h" +#include "meta/enum.h" +#include +#include namespace api { + static pmr::table ShaderLayoutTable; optional> GlslToSpirv::ToSpirv(const pmr::string& glsl, shaderc_shader_kind kind, string_view code_id) { optional> spirv_out{FramePool()}; @@ -34,5 +38,78 @@ namespace api default: return shaderc_shader_kind::shaderc_miss_shader; } } - + ShaderStage GlslToSpirv::GetShaderStage(shaderc_shader_kind kind) + { + switch (kind) + { + case shaderc_shader_kind::shaderc_vertex_shader: + return ShaderStage::VERTEX; + case shaderc_shader_kind::shaderc_fragment_shader: + return ShaderStage::FRAGMENT; + default: + return ShaderStage::NONE; + } + } + void GlslToSpirv::LoadShaderLayout(ShaderProgram* program, const pmr::vector& spirv) { + ShaderStage stage = program->GetStage(); + spirv_cross::Compiler compiler(spirv.data(), spirv.size()); + auto resources = compiler.get_shader_resources(); + ShaderDescriptorSet descriptorSet; + // 遍历 uniform buffers (UBO) + for (auto& res : resources.uniform_buffers) + { + ShaderDescriptorLayout layout{}; + layout.set = compiler.get_decoration(res.id, spv::Decoration::DecorationDescriptorSet); + layout.binding = compiler.get_decoration(res.id, spv::Decoration::DecorationBinding); + auto type = compiler.get_type(res.type_id); + uint32_t size = type.width; + uint32_t i = 0; + for (auto& member_type : type.member_types) + { + auto tmp = compiler.get_type(member_type); + size += (uint32_t)(compiler.get_declared_struct_member_size(type, i++)); + } + layout.size = size; + layout.stageFlags = stage; + layout.type = ShaderDescriptorType::UNIFORM_BUFFER; + descriptorSet.push_back(layout); + } + // 遍历 sampled images (采样器/纹理) + for (const auto& res : resources.sampled_images) { + ShaderDescriptorLayout layout{}; + layout.set = compiler.get_decoration(res.id, spv::Decoration::DecorationDescriptorSet); + layout.binding = compiler.get_decoration(res.id, spv::Decoration::DecorationBinding); + layout.size = 0; + layout.stageFlags = stage; + layout.type = ShaderDescriptorType::SAMPLER; + descriptorSet.push_back(layout); + } + ShaderLayoutTable.emplace(program->GetGuid(), descriptorSet); + } + void GlslToSpirv::GetShaderLayout(ShaderDescriptorSet& descriptorSet, pmr::vector& programList) + { + table idTable{ FramePool() }; + for (auto program : programList) { + auto& itSet = ShaderLayoutTable[program->GetGuid()]; + for (ShaderDescriptorLayout& layout : itSet) { + uint32_t id = (layout.set << 8) + layout.binding; + auto itId = idTable.find(id); + if (itId == idTable.end()) { + descriptorSet.emplace_back(layout); + idTable[id] = descriptorSet.size() - 1; + } + else { + using ::operator|=; + ShaderDescriptorLayout& desc = descriptorSet[itId->second]; + desc.stageFlags |= layout.stageFlags; + } + } + } + std::sort(descriptorSet.begin(), descriptorSet.end(), [](auto& k1, auto& k2) { + if (k1.set != k2.set) { + return k1.set < k2.set; + } + return k1.binding < k2.binding; + }); + } } diff --git a/engine/modules/engine/render/xmake.lua b/engine/modules/engine/render/xmake.lua index 7dc0e16..766fba3 100644 --- a/engine/modules/engine/render/xmake.lua +++ b/engine/modules/engine/render/xmake.lua @@ -7,4 +7,4 @@ static_component("render","engine") add_files("src/**.cpp") add_deps("asset", "zlib", "core") add_syslinks("user32", {public = true}) - add_packages("lemon", "libsdl","shaderc", {public = true}) \ No newline at end of file + add_packages("lemon", "libsdl","shaderc","spirv-cross", {public = true}) \ No newline at end of file diff --git a/engine/modules/engine/zlib/include/meta/enum.h b/engine/modules/engine/zlib/include/meta/enum.h index cd9f25c..a6a4992 100644 --- a/engine/modules/engine/zlib/include/meta/enum.h +++ b/engine/modules/engine/zlib/include/meta/enum.h @@ -1,12 +1,15 @@ #pragma once +#include namespace meta { template - concept is_enum_t = requires { std::is_enum_v; }; + concept is_enum_t = std::is_enum_v; } +template +concept is_enum_t = std::is_enum_v; template -inline constexpr Enum operator|=(Enum& lhs, Enum rhs) noexcept { +inline constexpr Enum& operator|=(Enum& lhs, Enum rhs) noexcept { using underlying = std::underlying_type_t; - lhs = Enum(underlying(lhs) | underlying(rhs)); + lhs = static_cast(static_cast(lhs) | static_cast(rhs)); return lhs; } template diff --git a/engine/modules/render/vulkan/include/vkn/loader/vulkan_glsl_loader.h b/engine/modules/render/vulkan/include/vkn/loader/vulkan_glsl_loader.h index d91bb2b..2f44fb6 100644 --- a/engine/modules/render/vulkan/include/vkn/loader/vulkan_glsl_loader.h +++ b/engine/modules/render/vulkan/include/vkn/loader/vulkan_glsl_loader.h @@ -3,14 +3,17 @@ #include "asset/resource_system.h" #include "vkn/vulkan_api.h" namespace vkn { + using api::ShaderDescriptorSet; class vkShaderProgram : public api::ShaderProgram { private: VkShaderModule mPtr; public: + using api::ShaderProgram::ShaderProgram; VkShaderModule Ptr() { return mPtr; } void Load(const pmr::vector& spirv); + VkShaderStageFlagBits GetVkStage(); }; class VulkanGlslLoader : public api::IFileLoader { @@ -18,5 +21,6 @@ namespace vkn { public: static void Init(); api::ResourceBundle LoadFile(api::PackagePath handle, const api::MetaBundle& meta) override; + static uint32_t GetShaderLayout(VkDescriptorSetLayoutList& layoutList, pmr::vector& programList); }; } \ No newline at end of file diff --git a/engine/modules/render/vulkan/include/vkn/type.h b/engine/modules/render/vulkan/include/vkn/type.h index b68f528..27666f7 100644 --- a/engine/modules/render/vulkan/include/vkn/type.h +++ b/engine/modules/render/vulkan/include/vkn/type.h @@ -29,6 +29,9 @@ namespace vkn { constexpr uint32_t SHADER_MODULE_COUNT = 2; constexpr uint32_t VERTEX_ATTRIBUTE_COUNT = 16; constexpr uint32_t MAX_BUFFER_BIND_NUM = 16; + constexpr uint32_t MAX_SHADER_DESCRIPTOR_SET_COUNT = 3; + using VkDescriptorSetLayoutList = VkDescriptorSetLayout[MAX_SHADER_DESCRIPTOR_SET_COUNT]; + using VkDescriptorSetList = VkDescriptorSet[MAX_SHADER_DESCRIPTOR_SET_COUNT]; struct MeshVAO { uint32_t indexCount = 0; // 索引数量 @@ -96,10 +99,10 @@ namespace vkn { { Name name; // For debug VkPipeline pipeline = VK_NULL_HANDLE; - VkDescriptorSet descriptorSet = VK_NULL_HANDLE; VkPipelineLayout pipelineLayout = VK_NULL_HANDLE; - VkDescriptorSetLayout descriptorSetLayout = VK_NULL_HANDLE; - VkDescriptorSetLayout sceneDescriptorSetLayout = VK_NULL_HANDLE; // For ray tracing + VkDescriptorSetList descList{}; + VkDescriptorSetLayoutList descLayoutList{}; + uint32_t descCount = 0; bool inUse = false; }; } diff --git a/engine/modules/render/vulkan/include/vkn/vulkan_api_help.h b/engine/modules/render/vulkan/include/vkn/vulkan_api_help.h index 60cdee2..714bf2d 100644 --- a/engine/modules/render/vulkan/include/vkn/vulkan_api_help.h +++ b/engine/modules/render/vulkan/include/vkn/vulkan_api_help.h @@ -2,6 +2,8 @@ namespace vkn { using api::ResourceState; using api::TextureBarrier; + using api::ShaderDescriptorType; + using api::ShaderStage; struct VkTextureTransitionDesc { VkAccessFlags srcAccessMask; VkAccessFlags dstAccessMask; @@ -20,4 +22,6 @@ namespace vkn { VkImageCreateFlags vkApiGetImageCreateFlag(TextureDimension dimension, uint32_t arraySize); VkSampleCountFlagBits vkApiGetSmpleCountFlag(SampleCount sample); + VkDescriptorType vkApiGetDescriptorType(ShaderDescriptorType type); + VkShaderStageFlags vkApiGetShaderStageFlags(ShaderStage stage); } \ No newline at end of file diff --git a/engine/modules/render/vulkan/include/vkn/wrapper/descriptorpool.h b/engine/modules/render/vulkan/include/vkn/wrapper/descriptorpool.h index e3dc9fc..70ed82a 100644 --- a/engine/modules/render/vulkan/include/vkn/wrapper/descriptorpool.h +++ b/engine/modules/render/vulkan/include/vkn/wrapper/descriptorpool.h @@ -11,6 +11,9 @@ namespace vkn { public: DescriptorPool(Device& device, pmr::vector& pPoolSizes,uint32_t maxSets); + VkDescriptorPool Ptr() { + return mPtr; + } VkDescriptorSet Allocate(VkDescriptorSetLayout& descriptorSetLayout); public: static pmr::vector DefaultDescriptorPoolSize() { diff --git a/engine/modules/render/vulkan/src/loader/vulkan_glsl_loader.cpp b/engine/modules/render/vulkan/src/loader/vulkan_glsl_loader.cpp index 9806d9b..1d6e914 100644 --- a/engine/modules/render/vulkan/src/loader/vulkan_glsl_loader.cpp +++ b/engine/modules/render/vulkan/src/loader/vulkan_glsl_loader.cpp @@ -1,6 +1,7 @@ #include "vkn/loader/vulkan_glsl_loader.h" #include "vkn/vulkan_api.h" #include "vkn/wrapper/device.h" +#include "vkn/vulkan_api_help.h" #include "render/tool/glsl_to_spirv.h" #include "render/asset/vertex.h" #include "os/file_handle.h" @@ -19,8 +20,10 @@ namespace vkn { ResourceBundle VulkanGlslLoader::LoadFile(PackagePath path, const MetaBundle& meta) { auto m = meta.FetchMeta(); - auto program = m ? ResourceSystem::Ptr()->LoadEmplaceResource(m->guid) - : ResourceSystem::Ptr()->LoadEmplaceResource(); + auto shader_kind = GlslToSpirv::GetShaderKind(path.GetExtension().ToStringView()); + auto shader_stage = GlslToSpirv::GetShaderStage(shader_kind); + auto program = m ? ResourceSystem::Ptr()->LoadEmplaceResource(m->guid, shader_stage) + : ResourceSystem::Ptr()->LoadEmplaceResource(shader_stage); FileHandle handle(path); if (!handle.Open(FILE_OP::READ, mFileFlag & FileFlag::File_Binary)) { return program; @@ -34,7 +37,6 @@ namespace vkn { } else { pmr::string glsl = handle.ReadAll(); - auto shader_kind = GlslToSpirv::GetShaderKind(path.GetExtension().ToStringView()); auto spirv = GlslToSpirv::ToSpirv(glsl, shader_kind, path.GetFileName()); if (spirv) { program->Load(*spirv); @@ -43,10 +45,67 @@ namespace vkn { } return program; } + VkDescriptorSetLayout CreateShaderLayout(std::span descList, pmr::vector& bindingList) { + VkDescriptorSetLayout layout; + bindingList.resize(descList.size()); + uint32_t i = 0; + for (auto& desc : descList) { + VkDescriptorSetLayoutBinding binding = {}; + binding.binding = desc.binding; + binding.descriptorType = vkApiGetDescriptorType(desc.type); + binding.descriptorCount = 1; + binding.stageFlags = vkApiGetShaderStageFlags(desc.stageFlags); + bindingList[i++] = binding; + } + VkDescriptorSetLayoutCreateInfo layoutInfo = {}; + layoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + layoutInfo.pBindings = bindingList.data(); + layoutInfo.bindingCount = static_cast(bindingList.size()); + vkCreateDescriptorSetLayout(VulkanAPI::Ptr()->GetBackend().GetDevice().Ptr(), &layoutInfo, nullptr, &layout); + return layout; + } + uint32_t VulkanGlslLoader::GetShaderLayout(VkDescriptorSetLayoutList& layoutList, pmr::vector& programList) + { + ShaderDescriptorSet descList{FramePool()}; + GlslToSpirv::GetShaderLayout(descList, programList); + if (descList.empty()) { + return 0; + } + descList.push_back(ShaderDescriptorLayout{.set = 0xff}); + pmr::vector bindingList{FramePool()}; + uint32_t set = 0, binding = 0, count = 0; + for (auto it = descList.begin(), itEnd = descList.end(); it != itEnd; it++) { + if (set == it->set) { + binding++; + } + else { + if (binding > 0) { + assert(count < MAX_SHADER_DESCRIPTOR_SET_COUNT); + std::span spanList{ it - binding, binding }; + layoutList[count++] = CreateShaderLayout(spanList, bindingList); + } + set = it->set; + binding = 0; + } + } + return count; + } void vkShaderProgram::Load(const pmr::vector& spirv) { VulkanAPI* API = VulkanAPI::Ptr(); mPtr = API->GetBackend().GetDevice().CreateShaderModule(spirv); + GlslToSpirv::LoadShaderLayout(this, spirv); + } + VkShaderStageFlagBits vkShaderProgram::GetVkStage() + { + switch (mStage) { + case ShaderStage::VERTEX: + return VK_SHADER_STAGE_VERTEX_BIT; + case ShaderStage::FRAGMENT: + return VK_SHADER_STAGE_FRAGMENT_BIT; + default: + return VkShaderStageFlagBits(); + } } } diff --git a/engine/modules/render/vulkan/src/vulkan_api.cpp b/engine/modules/render/vulkan/src/vulkan_api.cpp index 148ab99..b0b7b7b 100644 --- a/engine/modules/render/vulkan/src/vulkan_api.cpp +++ b/engine/modules/render/vulkan/src/vulkan_api.cpp @@ -72,8 +72,8 @@ namespace vkn { vkCmdBindVertexBuffers(ptr, 0, 1, vertexBuffers, offsets); vkCmdBindIndexBuffer(ptr, vulkanVAO.indexBuffer, 0, VK_INDEX_TYPE_UINT32); vkCmdBindPipeline(ptr, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.pipeline); - if(pipeline.descriptorSet) - vkCmdBindDescriptorSets(ptr, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.pipelineLayout, 0, 1, &pipeline.descriptorSet, 0, VK_NULL_HANDLE); + if(pipeline.descCount > 0) + vkCmdBindDescriptorSets(ptr, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.pipelineLayout, 0, pipeline.descCount, pipeline.descList, 0, VK_NULL_HANDLE); vkCmdDrawIndexed(ptr, vulkanVAO.indexCount, 1, 0, 0, 0); } void VulkanAPI::LoadShader(Shader& shader, size_t passKey) @@ -86,10 +86,14 @@ namespace vkn { pmr::vector shaderStages; std::map shaderModules; auto& device = backend.GetDevice(); - auto vertModule = shader.GetVertHandle()->Ptr(); - shaderModules.insert(std::make_pair(VK_SHADER_STAGE_VERTEX_BIT, vertModule)); - auto fragModule = shader.GetFragHandle()->Ptr(); - shaderModules.insert(std::make_pair(VK_SHADER_STAGE_FRAGMENT_BIT, fragModule)); + pmr::vector programList; + programList.push_back(shader.GetVertHandle().Ptr()); + programList.push_back(shader.GetFragHandle().Ptr()); + for (auto program : programList) { + vkShaderProgram* vkProgram = (vkShaderProgram*)program; + auto shaderModule = vkProgram->Ptr(); + shaderModules.insert(std::make_pair(vkProgram->GetVkStage(), shaderModule)); + } for (auto& shaderModule : shaderModules) { VkPipelineShaderStageCreateInfo shaderStageInfo = {}; @@ -205,11 +209,21 @@ namespace vkn { depthStencilInfo.stencilTestEnable = VK_FALSE; depthStencilInfo.front = {}; depthStencilInfo.back = {}; - VkDescriptorSetLayout descriptorSetLayout{}; + + VulkanPipeline& vulkan_pipeline = PipelineTable[shader.GetGuid()]; + vulkan_pipeline.descCount = VulkanGlslLoader::GetShaderLayout(vulkan_pipeline.descLayoutList, programList); + VkDescriptorSet descriptorSet; + VkDescriptorSetAllocateInfo allocInfo{}; + allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + allocInfo.descriptorPool = backend.GetPool().Ptr(); + allocInfo.descriptorSetCount = vulkan_pipeline.descCount; + allocInfo.pSetLayouts = vulkan_pipeline.descLayoutList; + vkAllocateDescriptorSets(device.Ptr(), &allocInfo, vulkan_pipeline.descList); + VkPipelineLayoutCreateInfo pipelineLayoutInfo = {}; pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; - pipelineLayoutInfo.setLayoutCount = 0; // 没有描述符集布局时可以设置为0 - pipelineLayoutInfo.pSetLayouts = nullptr; + pipelineLayoutInfo.setLayoutCount = vulkan_pipeline.descCount; + pipelineLayoutInfo.pSetLayouts = vulkan_pipeline.descLayoutList; VkPipelineLayout pipelineLayout; if (vkCreatePipelineLayout(device.Ptr(), &pipelineLayoutInfo, nullptr, &pipelineLayout) != VK_SUCCESS) throw std::runtime_error("failed to create pipeline layout!"); @@ -239,13 +253,10 @@ namespace vkn { for (auto& shaderModule : shaderModules) vkDestroyShaderModule(device.Ptr(), shaderModule.second, nullptr); - VulkanPipeline& vulkan_pipeline = PipelineTable[shader.GetGuid()]; vulkan_pipeline.name = shader.Name(); vulkan_pipeline.pipeline = pipeLine; vulkan_pipeline.inUse = true; vulkan_pipeline.pipelineLayout = pipelineLayout; - vulkan_pipeline.descriptorSetLayout = descriptorSetLayout; - vulkan_pipeline.descriptorSet = descriptorSetLayout ? backend.GetPool().Allocate(descriptorSetLayout) : nullptr; } ImagePtr VulkanAPI::CreateTexture(TextureDesc desc) { diff --git a/engine/modules/render/vulkan/src/vulkan_api_help.cpp b/engine/modules/render/vulkan/src/vulkan_api_help.cpp index 062c87e..efa9916 100644 --- a/engine/modules/render/vulkan/src/vulkan_api_help.cpp +++ b/engine/modules/render/vulkan/src/vulkan_api_help.cpp @@ -233,4 +233,26 @@ namespace vkn { { return (VkSampleCountFlagBits)sample; } + VkDescriptorType vkApiGetDescriptorType(ShaderDescriptorType type) + { + switch (type) { + case ShaderDescriptorType::SAMPLER: + return VK_DESCRIPTOR_TYPE_SAMPLER; + case ShaderDescriptorType::UNIFORM_BUFFER: + return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + default: + return VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + } + } + VkShaderStageFlags vkApiGetShaderStageFlags(ShaderStage stage) + { + VkShaderStageFlags flags{}; + if (any(stage & ShaderStage::FRAGMENT)) { + flags |= VK_SHADER_STAGE_FRAGMENT_BIT; + } + if (any(stage & ShaderStage::VERTEX)) { + flags |= VK_SHADER_STAGE_VERTEX_BIT; + } + return flags; + } } \ No newline at end of file