From 8027f98eaeef00c09551a3cc46c2ce1e1ab71727 Mon Sep 17 00:00:00 2001 From: dpjudas Date: Sun, 6 Apr 2025 02:11:38 +0200 Subject: [PATCH] More pipeline lookup code --- .../vulkan/pipelines/vk_renderpass.cpp | 45 ++++++++++++++++--- .../vulkan/pipelines/vk_renderpass.h | 13 ++++++ 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/common/rendering/vulkan/pipelines/vk_renderpass.cpp b/src/common/rendering/vulkan/pipelines/vk_renderpass.cpp index f9eb2da98..ef7a30a86 100644 --- a/src/common/rendering/vulkan/pipelines/vk_renderpass.cpp +++ b/src/common/rendering/vulkan/pipelines/vk_renderpass.cpp @@ -376,6 +376,40 @@ std::unique_ptr VkRenderPassSetup::CreatePipeline(const VkPipeli return CreateWithStats(builder); } +VulkanPipeline* VkRenderPassSetup::GetVertexInputLibrary(int vertexFormat, bool useLevelMesh, int userUniformSize) +{ + uint64_t key = + (static_cast(vertexFormat)) | + (static_cast(useLevelMesh) << 31) | + (static_cast(userUniformSize) << 32); + + auto& pipeline = Libraries.VertexInput[key]; + if (!pipeline) + pipeline = CreateVertexInputLibrary(vertexFormat, useLevelMesh, userUniformSize); + return pipeline.get(); +} + +VulkanPipeline* VkRenderPassSetup::GetFragmentOutputLibrary(FRenderStyle renderStyle, VkColorComponentFlags colorMask) +{ + uint64_t key = static_cast(renderStyle.AsDWORD) | (static_cast(colorMask) << 32); + auto& pipeline = Libraries.FragmentOutput[key]; + if (!pipeline) + pipeline = CreateFragmentOutputLibrary(renderStyle, colorMask); + return pipeline.get(); +} + +VulkanPipeline* VkRenderPassSetup::GetVertexShaderLibrary(const VkPipelineKey& key, bool isUberShader) +{ + // To do: look up pipeline + return nullptr; +} + +VulkanPipeline* VkRenderPassSetup::GetFragmentShaderLibrary(const VkPipelineKey& key, bool isUberShader) +{ + // To do: look up pipeline + return nullptr; +} + std::unique_ptr VkRenderPassSetup::LinkPipeline(const VkPipelineKey& key, bool isUberShader, UniformStructHolder& Uniforms) { VkShaderProgram* program = fb->GetShaderManager()->Get(key.ShaderKey, isUberShader); @@ -383,15 +417,12 @@ std::unique_ptr VkRenderPassSetup::LinkPipeline(const VkPipeline Uniforms.Clear(); Uniforms = program->Uniforms; - // To do: look up these - std::unique_ptr vertexInput, vertexShader, fragmentShader, fragmentOutput; - GraphicsPipelineBuilder builder; builder.Cache(fb->GetRenderPassManager()->GetCache()); - builder.AddLibrary(vertexInput.get()); - builder.AddLibrary(vertexShader.get()); - builder.AddLibrary(fragmentShader.get()); - builder.AddLibrary(fragmentOutput.get()); + builder.AddLibrary(GetVertexInputLibrary(key.ShaderKey.VertexFormat, key.ShaderKey.Layout.UseLevelMesh, program->Uniforms.sz)); + builder.AddLibrary(GetVertexShaderLibrary(key, isUberShader)); + builder.AddLibrary(GetFragmentShaderLibrary(key, isUberShader)); + builder.AddLibrary(GetFragmentOutputLibrary(key.RenderStyle, (VkColorComponentFlags)key.ColorMask)); return CreateWithStats(builder); } diff --git a/src/common/rendering/vulkan/pipelines/vk_renderpass.h b/src/common/rendering/vulkan/pipelines/vk_renderpass.h index d96d20613..3f435a1a6 100644 --- a/src/common/rendering/vulkan/pipelines/vk_renderpass.h +++ b/src/common/rendering/vulkan/pipelines/vk_renderpass.h @@ -92,6 +92,11 @@ private: std::unique_ptr LinkPipeline(const VkPipelineKey& key, bool isUberShader, UniformStructHolder& Uniforms); std::unique_ptr CreateWithStats(GraphicsPipelineBuilder& builder); + VulkanPipeline* GetVertexInputLibrary(int vertexFormat, bool useLevelMesh, int userUniformSize); + VulkanPipeline* GetVertexShaderLibrary(const VkPipelineKey& key, bool isUberShader); + VulkanPipeline* GetFragmentShaderLibrary(const VkPipelineKey& key, bool isUberShader); + VulkanPipeline* GetFragmentOutputLibrary(FRenderStyle renderStyle, VkColorComponentFlags colorMask); + std::unique_ptr CreateVertexInputLibrary(int vertexFormat, bool useLevelMesh, int userUniformSize); std::unique_ptr CreateVertexShaderLibrary(const VkPipelineKey& key, bool isUberShader); std::unique_ptr CreateFragmentShaderLibrary(const VkPipelineKey& key, bool isUberShader); @@ -108,6 +113,14 @@ private: std::unique_ptr RenderPasses[8]; std::map GeneralizedPipelines; std::map SpecializedPipelines; + + struct + { + std::map> VertexInput; + std::map> VertexShader; + std::map> FragmentShader; + std::map> FragmentOutput; + } Libraries; }; class VkVertexFormat