mirror of
https://github.com/EduApps-CDG/OpenDX
synced 2024-12-30 09:45:37 +01:00
[dxvk] Use shader key structs to store shaders in DxvkPipeline objects
Mostly a code cleanup to make constructing these objects a bit easier.
This commit is contained in:
parent
604e89b97a
commit
8d4996bcda
@ -20,11 +20,11 @@ namespace dxvk {
|
|||||||
|
|
||||||
|
|
||||||
DxvkComputePipeline::DxvkComputePipeline(
|
DxvkComputePipeline::DxvkComputePipeline(
|
||||||
DxvkPipelineManager* pipeMgr,
|
DxvkPipelineManager* pipeMgr,
|
||||||
const Rc<DxvkShader>& cs)
|
DxvkComputePipelineShaders shaders)
|
||||||
: m_vkd(pipeMgr->m_device->vkd()),
|
: m_vkd(pipeMgr->m_device->vkd()), m_pipeMgr(pipeMgr),
|
||||||
m_pipeMgr(pipeMgr), m_cs(cs) {
|
m_shaders(std::move(shaders)) {
|
||||||
cs->defineResourceSlots(m_slotMapping);
|
m_shaders.cs->defineResourceSlots(m_slotMapping);
|
||||||
|
|
||||||
m_slotMapping.makeDescriptorsDynamic(
|
m_slotMapping.makeDescriptorsDynamic(
|
||||||
m_pipeMgr->m_device->options().maxNumDynamicUniformBuffers,
|
m_pipeMgr->m_device->options().maxNumDynamicUniformBuffers,
|
||||||
@ -86,7 +86,7 @@ namespace dxvk {
|
|||||||
|
|
||||||
if (Logger::logLevel() <= LogLevel::Debug) {
|
if (Logger::logLevel() <= LogLevel::Debug) {
|
||||||
Logger::debug("Compiling compute pipeline...");
|
Logger::debug("Compiling compute pipeline...");
|
||||||
Logger::debug(str::format(" cs : ", m_cs->debugName()));
|
Logger::debug(str::format(" cs : ", m_shaders.cs->debugName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
DxvkSpecConstants specData;
|
DxvkSpecConstants specData;
|
||||||
@ -98,7 +98,7 @@ namespace dxvk {
|
|||||||
DxvkShaderModuleCreateInfo moduleInfo;
|
DxvkShaderModuleCreateInfo moduleInfo;
|
||||||
moduleInfo.fsDualSrcBlend = false;
|
moduleInfo.fsDualSrcBlend = false;
|
||||||
|
|
||||||
auto csm = m_cs->createShaderModule(m_vkd, m_slotMapping, moduleInfo);
|
auto csm = m_shaders.cs->createShaderModule(m_vkd, m_slotMapping, moduleInfo);
|
||||||
|
|
||||||
VkComputePipelineCreateInfo info;
|
VkComputePipelineCreateInfo info;
|
||||||
info.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO;
|
info.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO;
|
||||||
@ -116,7 +116,7 @@ namespace dxvk {
|
|||||||
if (m_vkd->vkCreateComputePipelines(m_vkd->device(),
|
if (m_vkd->vkCreateComputePipelines(m_vkd->device(),
|
||||||
m_pipeMgr->m_cache->handle(), 1, &info, nullptr, &pipeline) != VK_SUCCESS) {
|
m_pipeMgr->m_cache->handle(), 1, &info, nullptr, &pipeline) != VK_SUCCESS) {
|
||||||
Logger::err("DxvkComputePipeline: Failed to compile pipeline");
|
Logger::err("DxvkComputePipeline: Failed to compile pipeline");
|
||||||
Logger::err(str::format(" cs : ", m_cs->debugName()));
|
Logger::err(str::format(" cs : ", m_shaders.cs->debugName()));
|
||||||
return VK_NULL_HANDLE;
|
return VK_NULL_HANDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,8 +139,8 @@ namespace dxvk {
|
|||||||
|
|
||||||
DxvkStateCacheKey key;
|
DxvkStateCacheKey key;
|
||||||
|
|
||||||
if (m_cs != nullptr)
|
if (m_shaders.cs != nullptr)
|
||||||
key.cs = m_cs->getShaderKey();
|
key.cs = m_shaders.cs->getShaderKey();
|
||||||
|
|
||||||
m_pipeMgr->m_stateCache->addComputePipeline(key, state);
|
m_pipeMgr->m_stateCache->addComputePipeline(key, state);
|
||||||
}
|
}
|
||||||
|
@ -47,8 +47,9 @@ namespace dxvk {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
DxvkComputePipeline(
|
DxvkComputePipeline(
|
||||||
DxvkPipelineManager* pipeMgr,
|
DxvkPipelineManager* pipeMgr,
|
||||||
const Rc<DxvkShader>& cs);
|
DxvkComputePipelineShaders shaders);
|
||||||
|
|
||||||
~DxvkComputePipeline();
|
~DxvkComputePipeline();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,13 +80,13 @@ namespace dxvk {
|
|||||||
VkPipeline pipeline;
|
VkPipeline pipeline;
|
||||||
};
|
};
|
||||||
|
|
||||||
Rc<vk::DeviceFn> m_vkd;
|
Rc<vk::DeviceFn> m_vkd;
|
||||||
DxvkPipelineManager* m_pipeMgr;
|
DxvkPipelineManager* m_pipeMgr;
|
||||||
|
|
||||||
DxvkDescriptorSlotMapping m_slotMapping;
|
DxvkComputePipelineShaders m_shaders;
|
||||||
|
DxvkDescriptorSlotMapping m_slotMapping;
|
||||||
|
|
||||||
Rc<DxvkShader> m_cs;
|
Rc<DxvkPipelineLayout> m_layout;
|
||||||
Rc<DxvkPipelineLayout> m_layout;
|
|
||||||
|
|
||||||
sync::Spinlock m_mutex;
|
sync::Spinlock m_mutex;
|
||||||
std::vector<PipelineStruct> m_pipelines;
|
std::vector<PipelineStruct> m_pipelines;
|
||||||
|
@ -38,19 +38,15 @@ namespace dxvk {
|
|||||||
|
|
||||||
|
|
||||||
DxvkGraphicsPipeline::DxvkGraphicsPipeline(
|
DxvkGraphicsPipeline::DxvkGraphicsPipeline(
|
||||||
DxvkPipelineManager* pipeMgr,
|
DxvkPipelineManager* pipeMgr,
|
||||||
const Rc<DxvkShader>& vs,
|
DxvkGraphicsPipelineShaders shaders)
|
||||||
const Rc<DxvkShader>& tcs,
|
|
||||||
const Rc<DxvkShader>& tes,
|
|
||||||
const Rc<DxvkShader>& gs,
|
|
||||||
const Rc<DxvkShader>& fs)
|
|
||||||
: m_vkd(pipeMgr->m_device->vkd()), m_pipeMgr(pipeMgr),
|
: m_vkd(pipeMgr->m_device->vkd()), m_pipeMgr(pipeMgr),
|
||||||
m_vs(vs), m_tcs(tcs), m_tes(tes), m_gs(gs), m_fs(fs) {
|
m_shaders(std::move(shaders)) {
|
||||||
if (vs != nullptr) vs ->defineResourceSlots(m_slotMapping);
|
if (m_shaders.vs != nullptr) m_shaders.vs ->defineResourceSlots(m_slotMapping);
|
||||||
if (tcs != nullptr) tcs->defineResourceSlots(m_slotMapping);
|
if (m_shaders.tcs != nullptr) m_shaders.tcs->defineResourceSlots(m_slotMapping);
|
||||||
if (tes != nullptr) tes->defineResourceSlots(m_slotMapping);
|
if (m_shaders.tes != nullptr) m_shaders.tes->defineResourceSlots(m_slotMapping);
|
||||||
if (gs != nullptr) gs ->defineResourceSlots(m_slotMapping);
|
if (m_shaders.gs != nullptr) m_shaders.gs ->defineResourceSlots(m_slotMapping);
|
||||||
if (fs != nullptr) fs ->defineResourceSlots(m_slotMapping);
|
if (m_shaders.fs != nullptr) m_shaders.fs ->defineResourceSlots(m_slotMapping);
|
||||||
|
|
||||||
m_slotMapping.makeDescriptorsDynamic(
|
m_slotMapping.makeDescriptorsDynamic(
|
||||||
pipeMgr->m_device->options().maxNumDynamicUniformBuffers,
|
pipeMgr->m_device->options().maxNumDynamicUniformBuffers,
|
||||||
@ -59,10 +55,10 @@ namespace dxvk {
|
|||||||
m_layout = new DxvkPipelineLayout(m_vkd,
|
m_layout = new DxvkPipelineLayout(m_vkd,
|
||||||
m_slotMapping, VK_PIPELINE_BIND_POINT_GRAPHICS);
|
m_slotMapping, VK_PIPELINE_BIND_POINT_GRAPHICS);
|
||||||
|
|
||||||
m_vsIn = vs != nullptr ? vs->interfaceSlots().inputSlots : 0;
|
m_vsIn = m_shaders.vs != nullptr ? m_shaders.vs->interfaceSlots().inputSlots : 0;
|
||||||
m_fsOut = fs != nullptr ? fs->interfaceSlots().outputSlots : 0;
|
m_fsOut = m_shaders.fs != nullptr ? m_shaders.fs->interfaceSlots().outputSlots : 0;
|
||||||
|
|
||||||
if (gs != nullptr && gs->hasCapability(spv::CapabilityTransformFeedback))
|
if (m_shaders.gs != nullptr && m_shaders.gs->hasCapability(spv::CapabilityTransformFeedback))
|
||||||
m_flags.set(DxvkGraphicsPipelineFlag::HasTransformFeedback);
|
m_flags.set(DxvkGraphicsPipelineFlag::HasTransformFeedback);
|
||||||
|
|
||||||
VkShaderStageFlags stoStages = m_layout->getStorageDescriptorStages();
|
VkShaderStageFlags stoStages = m_layout->getStorageDescriptorStages();
|
||||||
@ -73,7 +69,7 @@ namespace dxvk {
|
|||||||
if (stoStages & ~VK_SHADER_STAGE_FRAGMENT_BIT)
|
if (stoStages & ~VK_SHADER_STAGE_FRAGMENT_BIT)
|
||||||
m_flags.set(DxvkGraphicsPipelineFlag::HasVsStorageDescriptors);
|
m_flags.set(DxvkGraphicsPipelineFlag::HasVsStorageDescriptors);
|
||||||
|
|
||||||
m_common.msSampleShadingEnable = fs != nullptr && fs->hasCapability(spv::CapabilitySampleRateShading);
|
m_common.msSampleShadingEnable = m_shaders.fs != nullptr && m_shaders.fs->hasCapability(spv::CapabilitySampleRateShading);
|
||||||
m_common.msSampleShadingFactor = 1.0f;
|
m_common.msSampleShadingFactor = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,11 +83,11 @@ namespace dxvk {
|
|||||||
Rc<DxvkShader> DxvkGraphicsPipeline::getShader(
|
Rc<DxvkShader> DxvkGraphicsPipeline::getShader(
|
||||||
VkShaderStageFlagBits stage) const {
|
VkShaderStageFlagBits stage) const {
|
||||||
switch (stage) {
|
switch (stage) {
|
||||||
case VK_SHADER_STAGE_VERTEX_BIT: return m_vs;
|
case VK_SHADER_STAGE_VERTEX_BIT: return m_shaders.vs;
|
||||||
case VK_SHADER_STAGE_GEOMETRY_BIT: return m_gs;
|
case VK_SHADER_STAGE_GEOMETRY_BIT: return m_shaders.gs;
|
||||||
case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT: return m_tcs;
|
case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT: return m_shaders.tcs;
|
||||||
case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT: return m_tes;
|
case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT: return m_shaders.tes;
|
||||||
case VK_SHADER_STAGE_FRAGMENT_BIT: return m_fs;
|
case VK_SHADER_STAGE_FRAGMENT_BIT: return m_shaders.fs;
|
||||||
default:
|
default:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -212,11 +208,11 @@ namespace dxvk {
|
|||||||
util::isDualSourceBlendFactor(state.omBlendAttachments[0].srcAlphaBlendFactor) ||
|
util::isDualSourceBlendFactor(state.omBlendAttachments[0].srcAlphaBlendFactor) ||
|
||||||
util::isDualSourceBlendFactor(state.omBlendAttachments[0].dstAlphaBlendFactor));
|
util::isDualSourceBlendFactor(state.omBlendAttachments[0].dstAlphaBlendFactor));
|
||||||
|
|
||||||
auto vsm = createShaderModule(m_vs, moduleInfo);
|
auto vsm = createShaderModule(m_shaders.vs, moduleInfo);
|
||||||
auto gsm = createShaderModule(m_gs, moduleInfo);
|
auto gsm = createShaderModule(m_shaders.gs, moduleInfo);
|
||||||
auto tcsm = createShaderModule(m_tcs, moduleInfo);
|
auto tcsm = createShaderModule(m_shaders.tcs, moduleInfo);
|
||||||
auto tesm = createShaderModule(m_tes, moduleInfo);
|
auto tesm = createShaderModule(m_shaders.tes, moduleInfo);
|
||||||
auto fsm = createShaderModule(m_fs, moduleInfo);
|
auto fsm = createShaderModule(m_shaders.fs, moduleInfo);
|
||||||
|
|
||||||
std::vector<VkPipelineShaderStageCreateInfo> stages;
|
std::vector<VkPipelineShaderStageCreateInfo> stages;
|
||||||
if (vsm) stages.push_back(vsm.stageInfo(&specInfo));
|
if (vsm) stages.push_back(vsm.stageInfo(&specInfo));
|
||||||
@ -262,8 +258,8 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t rasterizedStream = m_gs != nullptr
|
int32_t rasterizedStream = m_shaders.gs != nullptr
|
||||||
? m_gs->shaderOptions().rasterizedStream
|
? m_shaders.gs->shaderOptions().rasterizedStream
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
// Compact vertex bindings so that we can more easily update vertex buffers
|
// Compact vertex bindings so that we can more easily update vertex buffers
|
||||||
@ -475,7 +471,7 @@ namespace dxvk {
|
|||||||
|
|
||||||
// If there are no tessellation shaders, we
|
// If there are no tessellation shaders, we
|
||||||
// obviously cannot use tessellation patches.
|
// obviously cannot use tessellation patches.
|
||||||
if ((state.iaPatchVertexCount != 0) && (m_tcs == nullptr || m_tes == nullptr))
|
if ((state.iaPatchVertexCount != 0) && (m_shaders.tcs == nullptr || m_shaders.tes == nullptr))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Prevent unintended out-of-bounds access to the IL arrays
|
// Prevent unintended out-of-bounds access to the IL arrays
|
||||||
@ -495,11 +491,11 @@ namespace dxvk {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
DxvkStateCacheKey key;
|
DxvkStateCacheKey key;
|
||||||
if (m_vs != nullptr) key.vs = m_vs->getShaderKey();
|
if (m_shaders.vs != nullptr) key.vs = m_shaders.vs->getShaderKey();
|
||||||
if (m_tcs != nullptr) key.tcs = m_tcs->getShaderKey();
|
if (m_shaders.tcs != nullptr) key.tcs = m_shaders.tcs->getShaderKey();
|
||||||
if (m_tes != nullptr) key.tes = m_tes->getShaderKey();
|
if (m_shaders.tes != nullptr) key.tes = m_shaders.tes->getShaderKey();
|
||||||
if (m_gs != nullptr) key.gs = m_gs->getShaderKey();
|
if (m_shaders.gs != nullptr) key.gs = m_shaders.gs->getShaderKey();
|
||||||
if (m_fs != nullptr) key.fs = m_fs->getShaderKey();
|
if (m_shaders.fs != nullptr) key.fs = m_shaders.fs->getShaderKey();
|
||||||
|
|
||||||
m_pipeMgr->m_stateCache->addGraphicsPipeline(key, state, format);
|
m_pipeMgr->m_stateCache->addGraphicsPipeline(key, state, format);
|
||||||
}
|
}
|
||||||
@ -508,11 +504,11 @@ namespace dxvk {
|
|||||||
void DxvkGraphicsPipeline::logPipelineState(
|
void DxvkGraphicsPipeline::logPipelineState(
|
||||||
LogLevel level,
|
LogLevel level,
|
||||||
const DxvkGraphicsPipelineStateInfo& state) const {
|
const DxvkGraphicsPipelineStateInfo& state) const {
|
||||||
if (m_vs != nullptr) Logger::log(level, str::format(" vs : ", m_vs ->debugName()));
|
if (m_shaders.vs != nullptr) Logger::log(level, str::format(" vs : ", m_shaders.vs ->debugName()));
|
||||||
if (m_tcs != nullptr) Logger::log(level, str::format(" tcs : ", m_tcs->debugName()));
|
if (m_shaders.tcs != nullptr) Logger::log(level, str::format(" tcs : ", m_shaders.tcs->debugName()));
|
||||||
if (m_tes != nullptr) Logger::log(level, str::format(" tes : ", m_tes->debugName()));
|
if (m_shaders.tes != nullptr) Logger::log(level, str::format(" tes : ", m_shaders.tes->debugName()));
|
||||||
if (m_gs != nullptr) Logger::log(level, str::format(" gs : ", m_gs ->debugName()));
|
if (m_shaders.gs != nullptr) Logger::log(level, str::format(" gs : ", m_shaders.gs ->debugName()));
|
||||||
if (m_fs != nullptr) Logger::log(level, str::format(" fs : ", m_fs ->debugName()));
|
if (m_shaders.fs != nullptr) Logger::log(level, str::format(" fs : ", m_shaders.fs ->debugName()));
|
||||||
|
|
||||||
for (uint32_t i = 0; i < state.ilAttributeCount; i++) {
|
for (uint32_t i = 0; i < state.ilAttributeCount; i++) {
|
||||||
const VkVertexInputAttributeDescription& attr = state.ilAttributes[i];
|
const VkVertexInputAttributeDescription& attr = state.ilAttributes[i];
|
||||||
|
@ -203,12 +203,9 @@ namespace dxvk {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
DxvkGraphicsPipeline(
|
DxvkGraphicsPipeline(
|
||||||
DxvkPipelineManager* pipeMgr,
|
DxvkPipelineManager* pipeMgr,
|
||||||
const Rc<DxvkShader>& vs,
|
DxvkGraphicsPipelineShaders shaders);
|
||||||
const Rc<DxvkShader>& tcs,
|
|
||||||
const Rc<DxvkShader>& tes,
|
|
||||||
const Rc<DxvkShader>& gs,
|
|
||||||
const Rc<DxvkShader>& fs);
|
|
||||||
~DxvkGraphicsPipeline();
|
~DxvkGraphicsPipeline();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -263,17 +260,13 @@ namespace dxvk {
|
|||||||
VkPipeline pipeline;
|
VkPipeline pipeline;
|
||||||
};
|
};
|
||||||
|
|
||||||
Rc<vk::DeviceFn> m_vkd;
|
Rc<vk::DeviceFn> m_vkd;
|
||||||
DxvkPipelineManager* m_pipeMgr;
|
DxvkPipelineManager* m_pipeMgr;
|
||||||
|
|
||||||
DxvkDescriptorSlotMapping m_slotMapping;
|
DxvkGraphicsPipelineShaders m_shaders;
|
||||||
|
DxvkDescriptorSlotMapping m_slotMapping;
|
||||||
|
|
||||||
Rc<DxvkShader> m_vs;
|
Rc<DxvkPipelineLayout> m_layout;
|
||||||
Rc<DxvkShader> m_tcs;
|
|
||||||
Rc<DxvkShader> m_tes;
|
|
||||||
Rc<DxvkShader> m_gs;
|
|
||||||
Rc<DxvkShader> m_fs;
|
|
||||||
Rc<DxvkPipelineLayout> m_layout;
|
|
||||||
|
|
||||||
uint32_t m_vsIn = 0;
|
uint32_t m_vsIn = 0;
|
||||||
uint32_t m_fsOut = 0;
|
uint32_t m_fsOut = 0;
|
||||||
|
@ -70,8 +70,7 @@ namespace dxvk {
|
|||||||
if (pair != m_computePipelines.end())
|
if (pair != m_computePipelines.end())
|
||||||
return pair->second;
|
return pair->second;
|
||||||
|
|
||||||
const Rc<DxvkComputePipeline> pipeline
|
Rc<DxvkComputePipeline> pipeline = new DxvkComputePipeline(this, key);
|
||||||
= new DxvkComputePipeline(this, cs);
|
|
||||||
|
|
||||||
m_computePipelines.insert(std::make_pair(key, pipeline));
|
m_computePipelines.insert(std::make_pair(key, pipeline));
|
||||||
return pipeline;
|
return pipeline;
|
||||||
@ -100,8 +99,7 @@ namespace dxvk {
|
|||||||
if (pair != m_graphicsPipelines.end())
|
if (pair != m_graphicsPipelines.end())
|
||||||
return pair->second;
|
return pair->second;
|
||||||
|
|
||||||
Rc<DxvkGraphicsPipeline> pipeline = new DxvkGraphicsPipeline(
|
Rc<DxvkGraphicsPipeline> pipeline = new DxvkGraphicsPipeline(this, key);
|
||||||
this, vs, tcs, tes, gs, fs);
|
|
||||||
|
|
||||||
m_graphicsPipelines.insert(std::make_pair(key, pipeline));
|
m_graphicsPipelines.insert(std::make_pair(key, pipeline));
|
||||||
return pipeline;
|
return pipeline;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user