mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-04-01 09:25:24 +02:00
[dxvk] Don't create shader modules for internal resolve pipelines
This commit is contained in:
parent
ca2160c17e
commit
9e33073a5f
@ -1,5 +1,6 @@
|
|||||||
#include "dxvk_device.h"
|
#include "dxvk_device.h"
|
||||||
#include "dxvk_meta_resolve.h"
|
#include "dxvk_meta_resolve.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>
|
||||||
@ -49,38 +50,20 @@ namespace dxvk {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
DxvkMetaResolveObjects::DxvkMetaResolveObjects(const DxvkDevice* device)
|
DxvkMetaResolveObjects::DxvkMetaResolveObjects(DxvkDevice* device)
|
||||||
: m_vkd (device->vkd()),
|
: m_device(device) {
|
||||||
m_shaderFragF (createShaderModule(dxvk_resolve_frag_f)),
|
|
||||||
m_shaderFragU (createShaderModule(dxvk_resolve_frag_u)),
|
|
||||||
m_shaderFragI (createShaderModule(dxvk_resolve_frag_i)),
|
|
||||||
m_shaderFragD (createShaderModule(dxvk_resolve_frag_d)) {
|
|
||||||
if (device->features().extShaderStencilExport)
|
|
||||||
m_shaderFragDS = createShaderModule(dxvk_resolve_frag_ds);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DxvkMetaResolveObjects::~DxvkMetaResolveObjects() {
|
DxvkMetaResolveObjects::~DxvkMetaResolveObjects() {
|
||||||
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_shaderFragDS, nullptr);
|
for (const auto& pair : m_pipelines) {
|
||||||
m_vkd->vkDestroyShaderModule(m_vkd->device(), m_shaderFragD, nullptr);
|
vk->vkDestroyPipeline(vk->device(), pair.second.pipeHandle, nullptr);
|
||||||
m_vkd->vkDestroyShaderModule(m_vkd->device(), m_shaderFragF, nullptr);
|
vk->vkDestroyPipelineLayout(vk->device(), pair.second.pipeLayout, nullptr);
|
||||||
m_vkd->vkDestroyShaderModule(m_vkd->device(), m_shaderFragI, nullptr);
|
vk->vkDestroyDescriptorSetLayout(vk->device(), pair.second.dsetLayout, nullptr);
|
||||||
m_vkd->vkDestroyShaderModule(m_vkd->device(), m_shaderFragU, nullptr);
|
}
|
||||||
m_vkd->vkDestroyShaderModule(m_vkd->device(), m_shaderGeom, nullptr);
|
|
||||||
m_vkd->vkDestroyShaderModule(m_vkd->device(), m_shaderVert, nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -96,7 +79,7 @@ namespace dxvk {
|
|||||||
key.samples = samples;
|
key.samples = samples;
|
||||||
key.modeD = depthResolveMode;
|
key.modeD = depthResolveMode;
|
||||||
key.modeS = stencilResolveMode;
|
key.modeS = stencilResolveMode;
|
||||||
|
|
||||||
auto entry = m_pipelines.find(key);
|
auto entry = m_pipelines.find(key);
|
||||||
if (entry != m_pipelines.end())
|
if (entry != m_pipelines.end())
|
||||||
return entry->second;
|
return entry->second;
|
||||||
@ -105,21 +88,8 @@ namespace dxvk {
|
|||||||
m_pipelines.insert({ key, pipeline });
|
m_pipelines.insert({ key, pipeline });
|
||||||
return pipeline;
|
return pipeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VkShaderModule DxvkMetaResolveObjects::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("DxvkMetaCopyObjects: Failed to create shader module");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DxvkMetaResolvePipeline DxvkMetaResolveObjects::createPipeline(
|
DxvkMetaResolvePipeline DxvkMetaResolveObjects::createPipeline(
|
||||||
const DxvkMetaResolvePipelineKey& key) {
|
const DxvkMetaResolvePipelineKey& key) {
|
||||||
DxvkMetaResolvePipeline pipeline;
|
DxvkMetaResolvePipeline pipeline;
|
||||||
@ -132,24 +102,30 @@ namespace dxvk {
|
|||||||
|
|
||||||
VkDescriptorSetLayout DxvkMetaResolveObjects::createDescriptorSetLayout(
|
VkDescriptorSetLayout DxvkMetaResolveObjects::createDescriptorSetLayout(
|
||||||
const DxvkMetaResolvePipelineKey& key) {
|
const DxvkMetaResolvePipelineKey& key) {
|
||||||
|
auto vk = m_device->vkd();
|
||||||
|
|
||||||
std::array<VkDescriptorSetLayoutBinding, 2> bindings = {{
|
std::array<VkDescriptorSetLayoutBinding, 2> bindings = {{
|
||||||
{ 0, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr },
|
{ 0, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr },
|
||||||
{ 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr },
|
{ 1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr },
|
||||||
}};
|
}};
|
||||||
|
|
||||||
VkDescriptorSetLayoutCreateInfo info = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO };
|
VkDescriptorSetLayoutCreateInfo info = { VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO };
|
||||||
info.bindingCount = bindings.size();
|
info.bindingCount = bindings.size();
|
||||||
info.pBindings = bindings.data();
|
info.pBindings = bindings.data();
|
||||||
|
|
||||||
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("DxvkMetaResolveObjects: Failed to create descriptor set layout");
|
throw DxvkError("DxvkMetaResolveObjects: Failed to create descriptor set layout");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VkPipelineLayout DxvkMetaResolveObjects::createPipelineLayout(
|
VkPipelineLayout DxvkMetaResolveObjects::createPipelineLayout(
|
||||||
VkDescriptorSetLayout descriptorSetLayout) {
|
VkDescriptorSetLayout descriptorSetLayout) {
|
||||||
|
auto vk = m_device->vkd();
|
||||||
|
|
||||||
VkPushConstantRange push = { VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(VkOffset2D) };
|
VkPushConstantRange push = { VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(VkOffset2D) };
|
||||||
|
|
||||||
VkPipelineLayoutCreateInfo info = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO };
|
VkPipelineLayoutCreateInfo info = { VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO };
|
||||||
@ -159,8 +135,10 @@ namespace dxvk {
|
|||||||
info.pPushConstantRanges = &push;
|
info.pPushConstantRanges = &push;
|
||||||
|
|
||||||
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("DxvkMetaCopyObjects: Failed to create pipeline layout");
|
throw DxvkError("DxvkMetaCopyObjects: Failed to create pipeline layout");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,10 +146,10 @@ namespace dxvk {
|
|||||||
VkPipeline DxvkMetaResolveObjects::createPipelineObject(
|
VkPipeline DxvkMetaResolveObjects::createPipelineObject(
|
||||||
const DxvkMetaResolvePipelineKey& key,
|
const DxvkMetaResolvePipelineKey& key,
|
||||||
VkPipelineLayout pipelineLayout) {
|
VkPipelineLayout pipelineLayout) {
|
||||||
|
auto vk = m_device->vkd();
|
||||||
auto formatInfo = lookupFormatInfo(key.format);
|
auto formatInfo = lookupFormatInfo(key.format);
|
||||||
|
|
||||||
std::array<VkPipelineShaderStageCreateInfo, 3> stages;
|
util::DxvkBuiltInShaderStages stages = { };
|
||||||
uint32_t stageCount = 0;
|
|
||||||
|
|
||||||
std::array<VkSpecializationMapEntry, 3> specEntries = {{
|
std::array<VkSpecializationMapEntry, 3> specEntries = {{
|
||||||
{ 0, offsetof(DxvkMetaResolvePipelineKey, samples), sizeof(VkSampleCountFlagBits) },
|
{ 0, offsetof(DxvkMetaResolvePipelineKey, samples), sizeof(VkSampleCountFlagBits) },
|
||||||
@ -179,43 +157,35 @@ namespace dxvk {
|
|||||||
{ 2, offsetof(DxvkMetaResolvePipelineKey, modeS), sizeof(VkResolveModeFlagBits) },
|
{ 2, offsetof(DxvkMetaResolvePipelineKey, modeS), sizeof(VkResolveModeFlagBits) },
|
||||||
}};
|
}};
|
||||||
|
|
||||||
VkSpecializationInfo specInfo;
|
VkSpecializationInfo specInfo = { };
|
||||||
specInfo.mapEntryCount = specEntries.size();
|
specInfo.mapEntryCount = specEntries.size();
|
||||||
specInfo.pMapEntries = specEntries.data();
|
specInfo.pMapEntries = specEntries.data();
|
||||||
specInfo.dataSize = sizeof(key);
|
specInfo.dataSize = sizeof(key);
|
||||||
specInfo.pData = &key;
|
specInfo.pData = &key;
|
||||||
|
|
||||||
stages[stageCount++] = VkPipelineShaderStageCreateInfo {
|
if (m_device->features().vk12.shaderOutputLayer) {
|
||||||
VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
|
stages.addStage(VK_SHADER_STAGE_VERTEX_BIT, dxvk_fullscreen_layer_vert, nullptr);
|
||||||
VK_SHADER_STAGE_VERTEX_BIT, m_shaderVert, "main" };
|
} else {
|
||||||
|
stages.addStage(VK_SHADER_STAGE_VERTEX_BIT, dxvk_fullscreen_vert, nullptr);
|
||||||
if (m_shaderGeom) {
|
stages.addStage(VK_SHADER_STAGE_GEOMETRY_BIT, dxvk_fullscreen_geom, nullptr);
|
||||||
stages[stageCount++] = VkPipelineShaderStageCreateInfo {
|
|
||||||
VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
|
|
||||||
VK_SHADER_STAGE_GEOMETRY_BIT, m_shaderGeom, "main" };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VkShaderModule psModule = VK_NULL_HANDLE;
|
|
||||||
|
|
||||||
if ((formatInfo->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT) && key.modeS != VK_RESOLVE_MODE_NONE_KHR) {
|
if (key.modeS && (formatInfo->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
|
||||||
if (m_shaderFragDS) {
|
if (m_device->features().extShaderStencilExport) {
|
||||||
psModule = m_shaderFragDS;
|
stages.addStage(VK_SHADER_STAGE_FRAGMENT_BIT, dxvk_resolve_frag_ds, &specInfo);
|
||||||
} else {
|
} else {
|
||||||
psModule = m_shaderFragD;
|
stages.addStage(VK_SHADER_STAGE_FRAGMENT_BIT, dxvk_resolve_frag_d, &specInfo);
|
||||||
Logger::err("DXVK: Stencil export not supported by device, skipping stencil resolve");
|
Logger::warn("DXVK: Stencil export not supported by device, skipping stencil resolve");
|
||||||
}
|
}
|
||||||
} else if (formatInfo->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT)
|
} else if (formatInfo->aspectMask & VK_IMAGE_ASPECT_DEPTH_BIT) {
|
||||||
psModule = m_shaderFragD;
|
stages.addStage(VK_SHADER_STAGE_FRAGMENT_BIT, dxvk_resolve_frag_d, &specInfo);
|
||||||
else if (formatInfo->flags.test(DxvkFormatFlag::SampledUInt))
|
} else if (formatInfo->flags.test(DxvkFormatFlag::SampledUInt)) {
|
||||||
psModule = m_shaderFragU;
|
stages.addStage(VK_SHADER_STAGE_FRAGMENT_BIT, dxvk_resolve_frag_u, &specInfo);
|
||||||
else if (formatInfo->flags.test(DxvkFormatFlag::SampledSInt))
|
} else if (formatInfo->flags.test(DxvkFormatFlag::SampledSInt)) {
|
||||||
psModule = m_shaderFragI;
|
stages.addStage(VK_SHADER_STAGE_FRAGMENT_BIT, dxvk_resolve_frag_i, &specInfo);
|
||||||
else
|
} else {
|
||||||
psModule = m_shaderFragF;
|
stages.addStage(VK_SHADER_STAGE_FRAGMENT_BIT, dxvk_resolve_frag_f, &specInfo);
|
||||||
|
}
|
||||||
stages[stageCount++] = VkPipelineShaderStageCreateInfo {
|
|
||||||
VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
|
|
||||||
VK_SHADER_STAGE_FRAGMENT_BIT, psModule, "main", &specInfo };
|
|
||||||
|
|
||||||
std::array<VkDynamicState, 2> dynStates = {{
|
std::array<VkDynamicState, 2> dynStates = {{
|
||||||
VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT,
|
VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT,
|
||||||
@ -283,8 +253,8 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
@ -297,8 +267,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("DxvkMetaCopyObjects: Failed to create graphics pipeline");
|
throw DxvkError("DxvkMetaCopyObjects: Failed to create graphics pipeline");
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ namespace dxvk {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
DxvkMetaResolveObjects(const DxvkDevice* device);
|
DxvkMetaResolveObjects(DxvkDevice* device);
|
||||||
~DxvkMetaResolveObjects();
|
~DxvkMetaResolveObjects();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -102,15 +102,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_shaderFragF = VK_NULL_HANDLE;
|
|
||||||
VkShaderModule m_shaderFragU = VK_NULL_HANDLE;
|
|
||||||
VkShaderModule m_shaderFragI = VK_NULL_HANDLE;
|
|
||||||
VkShaderModule m_shaderFragD = VK_NULL_HANDLE;
|
|
||||||
VkShaderModule m_shaderFragDS = VK_NULL_HANDLE;
|
|
||||||
|
|
||||||
dxvk::mutex m_mutex;
|
dxvk::mutex m_mutex;
|
||||||
|
|
||||||
@ -118,23 +110,20 @@ namespace dxvk {
|
|||||||
DxvkMetaResolvePipelineKey,
|
DxvkMetaResolvePipelineKey,
|
||||||
DxvkMetaResolvePipeline,
|
DxvkMetaResolvePipeline,
|
||||||
DxvkHash, DxvkEq> m_pipelines;
|
DxvkHash, DxvkEq> m_pipelines;
|
||||||
|
|
||||||
VkShaderModule createShaderModule(
|
|
||||||
const SpirvCodeBuffer& code) const;
|
|
||||||
|
|
||||||
DxvkMetaResolvePipeline createPipeline(
|
DxvkMetaResolvePipeline createPipeline(
|
||||||
const DxvkMetaResolvePipelineKey& key);
|
const DxvkMetaResolvePipelineKey& key);
|
||||||
|
|
||||||
VkDescriptorSetLayout createDescriptorSetLayout(
|
VkDescriptorSetLayout createDescriptorSetLayout(
|
||||||
const DxvkMetaResolvePipelineKey& key);
|
const DxvkMetaResolvePipelineKey& key);
|
||||||
|
|
||||||
VkPipelineLayout createPipelineLayout(
|
VkPipelineLayout createPipelineLayout(
|
||||||
VkDescriptorSetLayout descriptorSetLayout);
|
VkDescriptorSetLayout descriptorSetLayout);
|
||||||
|
|
||||||
VkPipeline createPipelineObject(
|
VkPipeline createPipelineObject(
|
||||||
const DxvkMetaResolvePipelineKey& key,
|
const DxvkMetaResolvePipelineKey& key,
|
||||||
VkPipelineLayout pipelineLayout);
|
VkPipelineLayout pipelineLayout);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user