mirror of
https://github.com/EduApps-CDG/OpenDX
synced 2024-12-30 09:45:37 +01:00
[dxvk] Simplify DxvkShaderModule
This is merely a wrapper for a VkShaderModule now, so it really doesn't need anything fancy and definitely doesn't need to be heap-allocated.
This commit is contained in:
parent
2bd09e52e7
commit
cd93ba570e
@ -118,7 +118,7 @@ namespace dxvk {
|
|||||||
info.flags = baseHandle == VK_NULL_HANDLE
|
info.flags = baseHandle == VK_NULL_HANDLE
|
||||||
? VK_PIPELINE_CREATE_ALLOW_DERIVATIVES_BIT
|
? VK_PIPELINE_CREATE_ALLOW_DERIVATIVES_BIT
|
||||||
: VK_PIPELINE_CREATE_DERIVATIVE_BIT;
|
: VK_PIPELINE_CREATE_DERIVATIVE_BIT;
|
||||||
info.stage = csm->stageInfo(&specInfo);
|
info.stage = csm.stageInfo(&specInfo);
|
||||||
info.layout = m_layout->pipelineLayout();
|
info.layout = m_layout->pipelineLayout();
|
||||||
info.basePipelineHandle = baseHandle;
|
info.basePipelineHandle = baseHandle;
|
||||||
info.basePipelineIndex = -1;
|
info.basePipelineIndex = -1;
|
||||||
|
@ -213,11 +213,11 @@ namespace dxvk {
|
|||||||
auto tesm = createShaderModule(m_tes, moduleInfo);
|
auto tesm = createShaderModule(m_tes, moduleInfo);
|
||||||
auto fsm = createShaderModule(m_fs, moduleInfo);
|
auto fsm = createShaderModule(m_fs, moduleInfo);
|
||||||
|
|
||||||
if (m_vs != nullptr) stages.push_back(vsm->stageInfo(&specInfo));
|
if (vsm) stages.push_back(vsm.stageInfo(&specInfo));
|
||||||
if (m_tcs != nullptr) stages.push_back(tcsm->stageInfo(&specInfo));
|
if (tcsm) stages.push_back(tcsm.stageInfo(&specInfo));
|
||||||
if (m_tes != nullptr) stages.push_back(tesm->stageInfo(&specInfo));
|
if (tesm) stages.push_back(tesm.stageInfo(&specInfo));
|
||||||
if (m_gs != nullptr) stages.push_back(gsm->stageInfo(&specInfo));
|
if (gsm) stages.push_back(gsm.stageInfo(&specInfo));
|
||||||
if (m_fs != nullptr) stages.push_back(fsm->stageInfo(&specInfo));
|
if (fsm) stages.push_back(fsm.stageInfo(&specInfo));
|
||||||
|
|
||||||
// Fix up color write masks using the component mappings
|
// Fix up color write masks using the component mappings
|
||||||
std::array<VkPipelineColorBlendAttachmentState, MaxNumRenderTargets> omBlendAttachments;
|
std::array<VkPipelineColorBlendAttachmentState, MaxNumRenderTargets> omBlendAttachments;
|
||||||
@ -428,12 +428,12 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Rc<DxvkShaderModule> DxvkGraphicsPipeline::createShaderModule(
|
DxvkShaderModule DxvkGraphicsPipeline::createShaderModule(
|
||||||
const Rc<DxvkShader>& shader,
|
const Rc<DxvkShader>& shader,
|
||||||
const DxvkShaderModuleCreateInfo& info) const {
|
const DxvkShaderModuleCreateInfo& info) const {
|
||||||
return shader != nullptr
|
return shader != nullptr
|
||||||
? shader->createShaderModule(m_vkd, m_slotMapping, info)
|
? shader->createShaderModule(m_vkd, m_slotMapping, info)
|
||||||
: nullptr;
|
: DxvkShaderModule();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -280,7 +280,7 @@ namespace dxvk {
|
|||||||
void destroyPipeline(
|
void destroyPipeline(
|
||||||
VkPipeline pipeline) const;
|
VkPipeline pipeline) const;
|
||||||
|
|
||||||
Rc<DxvkShaderModule> createShaderModule(
|
DxvkShaderModule createShaderModule(
|
||||||
const Rc<DxvkShader>& shader,
|
const Rc<DxvkShader>& shader,
|
||||||
const DxvkShaderModuleCreateInfo& info) const;
|
const DxvkShaderModuleCreateInfo& info) const;
|
||||||
|
|
||||||
|
@ -38,11 +38,28 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DxvkShaderModule::DxvkShaderModule()
|
||||||
|
: m_vkd(nullptr), m_info {
|
||||||
|
VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
||||||
|
nullptr, 0, VkShaderStageFlagBits(0), VK_NULL_HANDLE, nullptr, nullptr } {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DxvkShaderModule::DxvkShaderModule(DxvkShaderModule&& other)
|
||||||
|
: m_vkd (std::move(other.m_vkd)),
|
||||||
|
m_info(std::exchange(m_info, VkPipelineShaderStageCreateInfo())) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
DxvkShaderModule::DxvkShaderModule(
|
DxvkShaderModule::DxvkShaderModule(
|
||||||
const Rc<vk::DeviceFn>& vkd,
|
const Rc<vk::DeviceFn>& vkd,
|
||||||
const Rc<DxvkShader>& shader,
|
const Rc<DxvkShader>& shader,
|
||||||
const SpirvCodeBuffer& code)
|
const SpirvCodeBuffer& code)
|
||||||
: m_vkd(vkd), m_shader(shader) {
|
: m_vkd(vkd), m_info {
|
||||||
|
VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
||||||
|
nullptr, 0, shader->stage(), VK_NULL_HANDLE, "main", nullptr } {
|
||||||
VkShaderModuleCreateInfo info;
|
VkShaderModuleCreateInfo info;
|
||||||
info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
|
||||||
info.pNext = nullptr;
|
info.pNext = nullptr;
|
||||||
@ -50,31 +67,26 @@ namespace dxvk {
|
|||||||
info.codeSize = code.size();
|
info.codeSize = code.size();
|
||||||
info.pCode = code.data();
|
info.pCode = code.data();
|
||||||
|
|
||||||
if (m_vkd->vkCreateShaderModule(m_vkd->device(),
|
if (m_vkd->vkCreateShaderModule(m_vkd->device(), &info, nullptr, &m_info.module) != VK_SUCCESS)
|
||||||
&info, nullptr, &m_module) != VK_SUCCESS)
|
|
||||||
throw DxvkError("DxvkComputePipeline::DxvkComputePipeline: Failed to create shader module");
|
throw DxvkError("DxvkComputePipeline::DxvkComputePipeline: Failed to create shader module");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DxvkShaderModule::~DxvkShaderModule() {
|
DxvkShaderModule::~DxvkShaderModule() {
|
||||||
m_vkd->vkDestroyShaderModule(
|
if (m_vkd != nullptr) {
|
||||||
m_vkd->device(), m_module, nullptr);
|
m_vkd->vkDestroyShaderModule(
|
||||||
|
m_vkd->device(), m_info.module, nullptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VkPipelineShaderStageCreateInfo DxvkShaderModule::stageInfo(const VkSpecializationInfo* specInfo) const {
|
DxvkShaderModule& DxvkShaderModule::operator = (DxvkShaderModule&& other) {
|
||||||
VkPipelineShaderStageCreateInfo info;
|
m_vkd = std::move(other.m_vkd);
|
||||||
info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
|
m_info = std::exchange(other.m_info, VkPipelineShaderStageCreateInfo());
|
||||||
info.pNext = nullptr;
|
return *this;
|
||||||
info.flags = 0;
|
|
||||||
info.stage = m_shader->stage();
|
|
||||||
info.module = m_module;
|
|
||||||
info.pName = "main";
|
|
||||||
info.pSpecializationInfo = specInfo;
|
|
||||||
return info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DxvkShader::DxvkShader(
|
DxvkShader::DxvkShader(
|
||||||
VkShaderStageFlagBits stage,
|
VkShaderStageFlagBits stage,
|
||||||
uint32_t slotCount,
|
uint32_t slotCount,
|
||||||
@ -137,7 +149,7 @@ namespace dxvk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Rc<DxvkShaderModule> DxvkShader::createShaderModule(
|
DxvkShaderModule DxvkShader::createShaderModule(
|
||||||
const Rc<vk::DeviceFn>& vkd,
|
const Rc<vk::DeviceFn>& vkd,
|
||||||
const DxvkDescriptorSlotMapping& mapping,
|
const DxvkDescriptorSlotMapping& mapping,
|
||||||
const DxvkShaderModuleCreateInfo& info) {
|
const DxvkShaderModuleCreateInfo& info) {
|
||||||
@ -155,7 +167,7 @@ namespace dxvk {
|
|||||||
if (info.fsDualSrcBlend && m_o1IdxOffset && m_o1LocOffset)
|
if (info.fsDualSrcBlend && m_o1IdxOffset && m_o1LocOffset)
|
||||||
std::swap(code[m_o1IdxOffset], code[m_o1LocOffset]);
|
std::swap(code[m_o1IdxOffset], code[m_o1LocOffset]);
|
||||||
|
|
||||||
return new DxvkShaderModule(vkd, this, spirvCode);
|
return DxvkShaderModule(vkd, this, spirvCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ namespace dxvk {
|
|||||||
* \param [in] info Module create info
|
* \param [in] info Module create info
|
||||||
* \returns The shader module
|
* \returns The shader module
|
||||||
*/
|
*/
|
||||||
Rc<DxvkShaderModule> createShaderModule(
|
DxvkShaderModule createShaderModule(
|
||||||
const Rc<vk::DeviceFn>& vkd,
|
const Rc<vk::DeviceFn>& vkd,
|
||||||
const DxvkDescriptorSlotMapping& mapping,
|
const DxvkDescriptorSlotMapping& mapping,
|
||||||
const DxvkShaderModuleCreateInfo& info);
|
const DxvkShaderModuleCreateInfo& info);
|
||||||
@ -269,9 +269,13 @@ namespace dxvk {
|
|||||||
* context will create pipeline objects on the
|
* context will create pipeline objects on the
|
||||||
* fly when executing draw calls.
|
* fly when executing draw calls.
|
||||||
*/
|
*/
|
||||||
class DxvkShaderModule : public RcObject {
|
class DxvkShaderModule {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
DxvkShaderModule();
|
||||||
|
|
||||||
|
DxvkShaderModule(DxvkShaderModule&& other);
|
||||||
|
|
||||||
DxvkShaderModule(
|
DxvkShaderModule(
|
||||||
const Rc<vk::DeviceFn>& vkd,
|
const Rc<vk::DeviceFn>& vkd,
|
||||||
@ -279,14 +283,8 @@ namespace dxvk {
|
|||||||
const SpirvCodeBuffer& code);
|
const SpirvCodeBuffer& code);
|
||||||
|
|
||||||
~DxvkShaderModule();
|
~DxvkShaderModule();
|
||||||
|
|
||||||
/**
|
DxvkShaderModule& operator = (DxvkShaderModule&& other);
|
||||||
* \brief Shader module handle
|
|
||||||
* \returns Shader module handle
|
|
||||||
*/
|
|
||||||
VkShaderModule handle() const {
|
|
||||||
return m_module;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Shader stage creation info
|
* \brief Shader stage creation info
|
||||||
@ -295,29 +293,24 @@ namespace dxvk {
|
|||||||
* \returns Shader stage create info
|
* \returns Shader stage create info
|
||||||
*/
|
*/
|
||||||
VkPipelineShaderStageCreateInfo stageInfo(
|
VkPipelineShaderStageCreateInfo stageInfo(
|
||||||
const VkSpecializationInfo* specInfo) const;
|
const VkSpecializationInfo* specInfo) const {
|
||||||
|
VkPipelineShaderStageCreateInfo info = m_info;
|
||||||
|
info.pSpecializationInfo = specInfo;
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Shader object
|
* \brief Checks whether module is valid
|
||||||
* \returns The shader
|
* \returns \c true if module is valid
|
||||||
*/
|
*/
|
||||||
Rc<DxvkShader> shader() const {
|
operator bool () const {
|
||||||
return m_shader;
|
return m_info.module != VK_NULL_HANDLE;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Retrieves shader key
|
|
||||||
* \returns Unique shader key
|
|
||||||
*/
|
|
||||||
DxvkShaderKey getShaderKey() const {
|
|
||||||
return m_shader->getShaderKey();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Rc<vk::DeviceFn> m_vkd;
|
Rc<vk::DeviceFn> m_vkd;
|
||||||
Rc<DxvkShader> m_shader;
|
VkPipelineShaderStageCreateInfo m_info;
|
||||||
VkShaderModule m_module;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user