2017-12-03 20:23:26 +01:00
|
|
|
#include <cstring>
|
|
|
|
|
2017-12-03 00:40:58 +01:00
|
|
|
#include "dxvk_pipeline.h"
|
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
|
|
|
DxvkBindingLayout::DxvkBindingLayout(
|
2017-12-03 20:23:26 +01:00
|
|
|
const Rc<vk::DeviceFn>& vkd,
|
|
|
|
uint32_t bindingCount,
|
|
|
|
const DxvkDescriptorSlot* bindingInfos)
|
2017-12-03 00:40:58 +01:00
|
|
|
: m_vkd(vkd) {
|
|
|
|
|
2017-12-03 20:23:26 +01:00
|
|
|
m_bindingSlots.resize(bindingCount);
|
|
|
|
std::memcpy(m_bindingSlots.data(), bindingInfos,
|
|
|
|
bindingCount * sizeof(DxvkDescriptorSlot));
|
|
|
|
|
|
|
|
std::vector<VkDescriptorSetLayoutBinding> bindings;
|
|
|
|
|
2017-12-03 00:40:58 +01:00
|
|
|
for (uint32_t i = 0; i < bindingCount; i++) {
|
|
|
|
VkDescriptorSetLayoutBinding binding;
|
|
|
|
binding.binding = i;
|
|
|
|
binding.descriptorType = bindingInfos[i].type;
|
2017-12-03 20:23:26 +01:00
|
|
|
binding.descriptorCount = 1;
|
2017-12-03 00:40:58 +01:00
|
|
|
binding.stageFlags = bindingInfos[i].stages;
|
|
|
|
binding.pImmutableSamplers = nullptr;
|
2017-12-03 20:23:26 +01:00
|
|
|
bindings.push_back(binding);
|
2017-12-03 00:40:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
VkDescriptorSetLayoutCreateInfo dsetInfo;
|
|
|
|
dsetInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
|
|
|
|
dsetInfo.pNext = nullptr;
|
|
|
|
dsetInfo.flags = 0;
|
2017-12-03 20:23:26 +01:00
|
|
|
dsetInfo.bindingCount = bindings.size();
|
|
|
|
dsetInfo.pBindings = bindings.data();
|
2017-12-03 00:40:58 +01:00
|
|
|
|
|
|
|
if (m_vkd->vkCreateDescriptorSetLayout(m_vkd->device(),
|
|
|
|
&dsetInfo, nullptr, &m_descriptorSetLayout) != VK_SUCCESS)
|
|
|
|
throw DxvkError("DxvkBindingLayout: Failed to create descriptor set layout");
|
|
|
|
|
|
|
|
VkPipelineLayoutCreateInfo pipeInfo;
|
|
|
|
pipeInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
|
|
|
|
pipeInfo.pNext = nullptr;
|
|
|
|
pipeInfo.flags = 0;
|
|
|
|
pipeInfo.setLayoutCount = 1;
|
|
|
|
pipeInfo.pSetLayouts = &m_descriptorSetLayout;
|
|
|
|
pipeInfo.pushConstantRangeCount = 0;
|
|
|
|
pipeInfo.pPushConstantRanges = nullptr;
|
|
|
|
|
|
|
|
if (m_vkd->vkCreatePipelineLayout(m_vkd->device(),
|
|
|
|
&pipeInfo, nullptr, &m_pipelineLayout) != VK_SUCCESS) {
|
|
|
|
m_vkd->vkDestroyDescriptorSetLayout(
|
|
|
|
m_vkd->device(), m_descriptorSetLayout, nullptr);
|
|
|
|
throw DxvkError("DxvkBindingLayout: Failed to create pipeline layout");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DxvkBindingLayout::~DxvkBindingLayout() {
|
|
|
|
if (m_pipelineLayout != VK_NULL_HANDLE) {
|
|
|
|
m_vkd->vkDestroyPipelineLayout(
|
|
|
|
m_vkd->device(), m_pipelineLayout, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_descriptorSetLayout != VK_NULL_HANDLE) {
|
|
|
|
m_vkd->vkDestroyDescriptorSetLayout(
|
|
|
|
m_vkd->device(), m_descriptorSetLayout, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|