1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-04-03 07:25:18 +02:00

[dxvk] Don't create shader modules for internal blit pipelines

This commit is contained in:
Philip Rebohle 2025-03-23 23:05:42 +01:00
parent 662df399b2
commit ca2160c17e
2 changed files with 72 additions and 92 deletions

View File

@ -1,5 +1,6 @@
#include "dxvk_device.h" #include "dxvk_device.h"
#include "dxvk_meta_blit.h" #include "dxvk_meta_blit.h"
#include "dxvk_util.h"
#include <dxvk_fullscreen_geom.h> #include <dxvk_fullscreen_geom.h>
#include <dxvk_fullscreen_vert.h> #include <dxvk_fullscreen_vert.h>
@ -11,32 +12,20 @@
namespace dxvk { namespace dxvk {
DxvkMetaBlitObjects::DxvkMetaBlitObjects(const DxvkDevice* device) DxvkMetaBlitObjects::DxvkMetaBlitObjects(DxvkDevice* device)
: m_vkd (device->vkd()), : m_device(device) {
m_shaderFrag1D(createShaderModule(dxvk_blit_frag_1d)),
m_shaderFrag2D(createShaderModule(dxvk_blit_frag_2d)),
m_shaderFrag3D(createShaderModule(dxvk_blit_frag_3d)) {
if (device->features().vk12.shaderOutputLayer) {
m_shaderVert = createShaderModule(dxvk_fullscreen_layer_vert);
} else {
m_shaderVert = createShaderModule(dxvk_fullscreen_vert);
m_shaderGeom = createShaderModule(dxvk_fullscreen_geom);
}
} }
DxvkMetaBlitObjects::~DxvkMetaBlitObjects() { DxvkMetaBlitObjects::~DxvkMetaBlitObjects() {
for (const auto& pair : m_pipelines) { auto vk = m_device->vkd();
m_vkd->vkDestroyPipeline(m_vkd->device(), pair.second.pipeHandle, nullptr);
m_vkd->vkDestroyPipelineLayout(m_vkd->device(), pair.second.pipeLayout, nullptr);
m_vkd->vkDestroyDescriptorSetLayout (m_vkd->device(), pair.second.dsetLayout, nullptr);
}
m_vkd->vkDestroyShaderModule(m_vkd->device(), m_shaderFrag3D, nullptr); for (const auto& pair : m_pipelines) {
m_vkd->vkDestroyShaderModule(m_vkd->device(), m_shaderFrag2D, nullptr); vk->vkDestroyPipeline(vk->device(), pair.second.pipeHandle, nullptr);
m_vkd->vkDestroyShaderModule(m_vkd->device(), m_shaderFrag1D, nullptr); vk->vkDestroyPipelineLayout(vk->device(), pair.second.pipeLayout, nullptr);
m_vkd->vkDestroyShaderModule(m_vkd->device(), m_shaderGeom, nullptr); vk->vkDestroyDescriptorSetLayout(vk->device(), pair.second.dsetLayout, nullptr);
m_vkd->vkDestroyShaderModule(m_vkd->device(), m_shaderVert, nullptr); }
} }
@ -61,21 +50,9 @@ namespace dxvk {
} }
VkShaderModule DxvkMetaBlitObjects::createShaderModule(const SpirvCodeBuffer& code) const {
VkShaderModuleCreateInfo info = { VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO };
info.codeSize = code.size();
info.pCode = code.data();
VkShaderModule result = VK_NULL_HANDLE;
if (m_vkd->vkCreateShaderModule(m_vkd->device(), &info, nullptr, &result) != VK_SUCCESS)
throw DxvkError("DxvkMetaBlitObjects: Failed to create shader module");
return result;
}
DxvkMetaBlitPipeline DxvkMetaBlitObjects::createPipeline( DxvkMetaBlitPipeline DxvkMetaBlitObjects::createPipeline(
const DxvkMetaBlitPipelineKey& key) { const DxvkMetaBlitPipelineKey& key) {
DxvkMetaBlitPipeline pipe; DxvkMetaBlitPipeline pipe = { };
pipe.dsetLayout = this->createDescriptorSetLayout(key.viewType); pipe.dsetLayout = this->createDescriptorSetLayout(key.viewType);
pipe.pipeLayout = this->createPipelineLayout(pipe.dsetLayout); pipe.pipeLayout = this->createPipelineLayout(pipe.dsetLayout);
pipe.pipeHandle = this->createPipeline(pipe.pipeLayout, pipe.pipeHandle = this->createPipeline(pipe.pipeLayout,
@ -86,6 +63,8 @@ namespace dxvk {
VkDescriptorSetLayout DxvkMetaBlitObjects::createDescriptorSetLayout( VkDescriptorSetLayout DxvkMetaBlitObjects::createDescriptorSetLayout(
VkImageViewType viewType) const { VkImageViewType viewType) const {
auto vk = m_device->vkd();
VkDescriptorSetLayoutBinding binding = { 0, VkDescriptorSetLayoutBinding binding = { 0,
VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT }; VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT };
@ -94,14 +73,18 @@ namespace dxvk {
info.pBindings = &binding; info.pBindings = &binding;
VkDescriptorSetLayout result = VK_NULL_HANDLE; VkDescriptorSetLayout result = VK_NULL_HANDLE;
if (m_vkd->vkCreateDescriptorSetLayout(m_vkd->device(), &info, nullptr, &result) != VK_SUCCESS)
if (vk->vkCreateDescriptorSetLayout(vk->device(), &info, nullptr, &result) != VK_SUCCESS)
throw DxvkError("DxvkMetaBlitObjects: Failed to create descriptor set layout"); throw DxvkError("DxvkMetaBlitObjects: Failed to create descriptor set layout");
return result; return result;
} }
VkPipelineLayout DxvkMetaBlitObjects::createPipelineLayout( VkPipelineLayout DxvkMetaBlitObjects::createPipelineLayout(
VkDescriptorSetLayout descriptorSetLayout) const { VkDescriptorSetLayout descriptorSetLayout) const {
auto vk = m_device->vkd();
VkPushConstantRange pushRange = { VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(DxvkMetaBlitPushConstants) }; VkPushConstantRange pushRange = { VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(DxvkMetaBlitPushConstants) };
VkPipelineLayoutCreateInfo info = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO }; VkPipelineLayoutCreateInfo info = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO };
@ -111,8 +94,10 @@ namespace dxvk {
info.pPushConstantRanges = &pushRange; info.pPushConstantRanges = &pushRange;
VkPipelineLayout result = VK_NULL_HANDLE; VkPipelineLayout result = VK_NULL_HANDLE;
if (m_vkd->vkCreatePipelineLayout(m_vkd->device(), &info, nullptr, &result) != VK_SUCCESS)
if (vk->vkCreatePipelineLayout(vk->device(), &info, nullptr, &result) != VK_SUCCESS)
throw DxvkError("DxvkMetaBlitObjects: Failed to create pipeline layout"); throw DxvkError("DxvkMetaBlitObjects: Failed to create pipeline layout");
return result; return result;
} }
@ -122,31 +107,33 @@ namespace dxvk {
VkImageViewType imageViewType, VkImageViewType imageViewType,
VkFormat format, VkFormat format,
VkSampleCountFlagBits samples) const { VkSampleCountFlagBits samples) const {
std::array<VkPipelineShaderStageCreateInfo, 3> stages; auto vk = m_device->vkd();
uint32_t stageCount = 0;
stages[stageCount++] = VkPipelineShaderStageCreateInfo { util::DxvkBuiltInShaderStages stages = { };
VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
VK_SHADER_STAGE_VERTEX_BIT, m_shaderVert, "main" };
if (m_shaderGeom) { if (m_device->features().vk12.shaderOutputLayer) {
stages[stageCount++] = VkPipelineShaderStageCreateInfo { stages.addStage(VK_SHADER_STAGE_VERTEX_BIT, dxvk_fullscreen_layer_vert, nullptr);
VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0, } else {
VK_SHADER_STAGE_GEOMETRY_BIT, m_shaderGeom, "main" }; stages.addStage(VK_SHADER_STAGE_VERTEX_BIT, dxvk_fullscreen_vert, nullptr);
stages.addStage(VK_SHADER_STAGE_GEOMETRY_BIT, dxvk_fullscreen_geom, nullptr);
} }
VkShaderModule psModule = VK_NULL_HANDLE;
switch (imageViewType) { switch (imageViewType) {
case VK_IMAGE_VIEW_TYPE_1D_ARRAY: psModule = m_shaderFrag1D; break; case VK_IMAGE_VIEW_TYPE_1D_ARRAY:
case VK_IMAGE_VIEW_TYPE_2D_ARRAY: psModule = m_shaderFrag2D; break; stages.addStage(VK_SHADER_STAGE_FRAGMENT_BIT, dxvk_blit_frag_1d, nullptr);
case VK_IMAGE_VIEW_TYPE_3D: psModule = m_shaderFrag3D; break; break;
default: throw DxvkError("DxvkMetaBlitObjects: Invalid view type");
}
stages[stageCount++] = VkPipelineShaderStageCreateInfo { case VK_IMAGE_VIEW_TYPE_2D_ARRAY:
VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0, stages.addStage(VK_SHADER_STAGE_FRAGMENT_BIT, dxvk_blit_frag_2d, nullptr);
VK_SHADER_STAGE_FRAGMENT_BIT, psModule, "main" }; break;
case VK_IMAGE_VIEW_TYPE_3D:
stages.addStage(VK_SHADER_STAGE_FRAGMENT_BIT, dxvk_blit_frag_3d, nullptr);
break;
default:
throw DxvkError("DxvkMetaBlitObjects: Invalid view type");
}
std::array<VkDynamicState, 2> dynStates = {{ std::array<VkDynamicState, 2> dynStates = {{
VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT, VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT,
@ -190,8 +177,8 @@ namespace dxvk {
rtState.pColorAttachmentFormats = &format; rtState.pColorAttachmentFormats = &format;
VkGraphicsPipelineCreateInfo info = { VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, &rtState }; VkGraphicsPipelineCreateInfo info = { VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, &rtState };
info.stageCount = stageCount; info.stageCount = stages.count();
info.pStages = stages.data(); info.pStages = stages.infos();
info.pVertexInputState = &viState; info.pVertexInputState = &viState;
info.pInputAssemblyState = &iaState; info.pInputAssemblyState = &iaState;
info.pViewportState = &vpState; info.pViewportState = &vpState;
@ -203,8 +190,10 @@ namespace dxvk {
info.basePipelineIndex = -1; info.basePipelineIndex = -1;
VkPipeline result = VK_NULL_HANDLE; VkPipeline result = VK_NULL_HANDLE;
if (m_vkd->vkCreateGraphicsPipelines(m_vkd->device(), VK_NULL_HANDLE, 1, &info, nullptr, &result) != VK_SUCCESS)
if (vk->vkCreateGraphicsPipelines(vk->device(), VK_NULL_HANDLE, 1, &info, nullptr, &result) != VK_SUCCESS)
throw DxvkError("DxvkMetaBlitObjects: Failed to create graphics pipeline"); throw DxvkError("DxvkMetaBlitObjects: Failed to create graphics pipeline");
return result; return result;
} }

View File

@ -99,7 +99,7 @@ namespace dxvk {
public: public:
DxvkMetaBlitObjects(const DxvkDevice* device); DxvkMetaBlitObjects(DxvkDevice* device);
~DxvkMetaBlitObjects(); ~DxvkMetaBlitObjects();
/** /**
@ -117,13 +117,7 @@ namespace dxvk {
private: private:
Rc<vk::DeviceFn> m_vkd; DxvkDevice* m_device = nullptr;
VkShaderModule m_shaderVert = VK_NULL_HANDLE;
VkShaderModule m_shaderGeom = VK_NULL_HANDLE;
VkShaderModule m_shaderFrag1D = VK_NULL_HANDLE;
VkShaderModule m_shaderFrag2D = VK_NULL_HANDLE;
VkShaderModule m_shaderFrag3D = VK_NULL_HANDLE;
dxvk::mutex m_mutex; dxvk::mutex m_mutex;
@ -132,9 +126,6 @@ namespace dxvk {
DxvkMetaBlitPipeline, DxvkMetaBlitPipeline,
DxvkHash, DxvkEq> m_pipelines; DxvkHash, DxvkEq> m_pipelines;
VkShaderModule createShaderModule(
const SpirvCodeBuffer& code) const;
DxvkMetaBlitPipeline createPipeline( DxvkMetaBlitPipeline createPipeline(
const DxvkMetaBlitPipelineKey& key); const DxvkMetaBlitPipelineKey& key);