diff options
| author | Tilka <tilkax@gmail.com> | 2019-02-26 04:21:05 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-26 04:21:05 +0000 |
| commit | 6ce7f44b8a0bb3b95d3f12ebffbef7a71a443fdd (patch) | |
| tree | 98380ce3a3284c52597a6fba86589c847219ecd5 /Source/Core/VideoBackends/Vulkan/VKShader.cpp | |
| parent | 19673ce79af814ca3b77d7f8ea60458e564bfa51 (diff) | |
| parent | f039149198657c1891e1c6462ed30c31ed4b8486 (diff) | |
Merge pull request #7753 from stenzek/videocommon-all-the-things
Move a significant amount of video backend logic to VideoCommon
Diffstat (limited to 'Source/Core/VideoBackends/Vulkan/VKShader.cpp')
| -rw-r--r-- | Source/Core/VideoBackends/Vulkan/VKShader.cpp | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/Source/Core/VideoBackends/Vulkan/VKShader.cpp b/Source/Core/VideoBackends/Vulkan/VKShader.cpp index 5b44ed99a4..1a95a9c1f8 100644 --- a/Source/Core/VideoBackends/Vulkan/VKShader.cpp +++ b/Source/Core/VideoBackends/Vulkan/VKShader.cpp @@ -5,8 +5,8 @@ #include "Common/Align.h" #include "Common/Assert.h" +#include "VideoBackends/Vulkan/ObjectCache.h" #include "VideoBackends/Vulkan/ShaderCompiler.h" -#include "VideoBackends/Vulkan/Util.h" #include "VideoBackends/Vulkan/VKShader.h" #include "VideoBackends/Vulkan/VulkanContext.h" @@ -48,26 +48,47 @@ AbstractShader::BinaryData VKShader::GetBinary() const static std::unique_ptr<VKShader> CreateShaderObject(ShaderStage stage, ShaderCompiler::SPIRVCodeVector spv) { - VkShaderModule mod = Util::CreateShaderModule(spv.data(), spv.size()); - if (mod == VK_NULL_HANDLE) - return nullptr; + VkShaderModuleCreateInfo info = {}; + info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + info.codeSize = spv.size() * sizeof(u32); + info.pCode = spv.data(); + + VkShaderModule mod; + VkResult res = vkCreateShaderModule(g_vulkan_context->GetDevice(), &info, nullptr, &mod); + if (res != VK_SUCCESS) + { + LOG_VULKAN_ERROR(res, "vkCreateShaderModule failed: "); + return VK_NULL_HANDLE; + } // If it's a graphics shader, we defer pipeline creation. if (stage != ShaderStage::Compute) return std::make_unique<VKShader>(stage, std::move(spv), mod); // If it's a compute shader, we create the pipeline straight away. - ComputePipelineInfo pinfo; - pinfo.pipeline_layout = g_object_cache->GetPipelineLayout(PIPELINE_LAYOUT_COMPUTE); - pinfo.cs = mod; - VkPipeline pipeline = g_shader_cache->CreateComputePipeline(pinfo); - if (pipeline == VK_NULL_HANDLE) + const VkComputePipelineCreateInfo pipeline_info = { + VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO, + nullptr, + 0, + {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0, VK_SHADER_STAGE_COMPUTE_BIT, + mod, "main", nullptr}, + g_object_cache->GetPipelineLayout(PIPELINE_LAYOUT_COMPUTE), + VK_NULL_HANDLE, + -1}; + + VkPipeline pipeline; + res = vkCreateComputePipelines(g_vulkan_context->GetDevice(), g_object_cache->GetPipelineCache(), + 1, &pipeline_info, nullptr, &pipeline); + + // Shader module is no longer needed, now it is compiled to a pipeline. + vkDestroyShaderModule(g_vulkan_context->GetDevice(), mod, nullptr); + + if (res != VK_SUCCESS) { - vkDestroyShaderModule(g_vulkan_context->GetDevice(), mod, nullptr); + LOG_VULKAN_ERROR(res, "vkCreateComputePipelines failed: "); return nullptr; } - // Shader module is no longer needed, now it is compiled to a pipeline. return std::make_unique<VKShader>(std::move(spv), pipeline); } |
