1
0
mirror of https://github.com/EduApps-CDG/OpenDX synced 2024-12-30 09:45:37 +01:00
OpenDX/src/dxvk/dxvk_renderpass.cpp

158 lines
5.4 KiB
C++
Raw Normal View History

2017-10-10 23:32:13 +02:00
#include "dxvk_renderpass.h"
namespace dxvk {
DxvkRenderPassFormat::DxvkRenderPassFormat() {
2017-10-14 13:37:40 +02:00
for (uint32_t i = 0; i < MaxNumRenderTargets; i++)
m_color[i] = VK_FORMAT_UNDEFINED;
2017-10-10 23:32:13 +02:00
m_depth = VK_FORMAT_UNDEFINED;
m_samples = VK_SAMPLE_COUNT_1_BIT;
}
size_t DxvkRenderPassFormat::hash() const {
DxvkHashState result;
std::hash<VkFormat> fhash;
std::hash<VkSampleCountFlagBits> shash;
2017-10-14 13:37:40 +02:00
for (uint32_t i = 0; i < MaxNumRenderTargets; i++)
result.add(fhash(m_color[i]));
2017-10-10 23:32:13 +02:00
result.add(fhash(m_depth));
result.add(shash(m_samples));
return result;
}
bool DxvkRenderPassFormat::operator == (const DxvkRenderPassFormat& other) const {
bool equal = m_depth == other.m_depth
&& m_samples == other.m_samples;
2017-10-14 13:37:40 +02:00
for (uint32_t i = 0; i < MaxNumRenderTargets && !equal; i++)
equal = m_color[i] == other.m_color[i];
2017-10-10 23:32:13 +02:00
return equal;
}
bool DxvkRenderPassFormat::operator != (const DxvkRenderPassFormat& other) const {
return !this->operator == (other);
}
DxvkRenderPass::DxvkRenderPass(
const Rc<vk::DeviceFn>& vkd,
const DxvkRenderPassFormat& fmt)
2017-10-10 23:32:13 +02:00
: m_vkd(vkd), m_format(fmt) {
std::vector<VkAttachmentDescription> attachments;
VkAttachmentReference depthRef;
2017-10-14 13:37:40 +02:00
std::array<VkAttachmentReference, MaxNumRenderTargets> colorRef;
2017-10-10 23:32:13 +02:00
// Render passes may not require the previous
// contents of the attachments to be preserved.
if (fmt.getDepthFormat() != VK_FORMAT_UNDEFINED) {
VkAttachmentDescription desc;
desc.flags = 0;
desc.format = fmt.getDepthFormat();
desc.samples = fmt.getSampleCount();
desc.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
2017-10-10 23:32:13 +02:00
depthRef.attachment = attachments.size();
depthRef.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
attachments.push_back(desc);
}
2017-10-14 13:37:40 +02:00
for (uint32_t i = 0; i < MaxNumRenderTargets; i++) {
colorRef[i].attachment = VK_ATTACHMENT_UNUSED;
colorRef[i].layout = VK_IMAGE_LAYOUT_UNDEFINED;
2017-10-10 23:32:13 +02:00
if (fmt.getColorFormat(i) != VK_FORMAT_UNDEFINED) {
VkAttachmentDescription desc;
desc.flags = 0;
desc.format = fmt.getColorFormat(i);
desc.samples = fmt.getSampleCount();
desc.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
desc.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
2017-10-10 23:32:13 +02:00
colorRef[i].attachment = attachments.size();
colorRef[i].layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
2017-10-10 23:32:13 +02:00
attachments.push_back(desc);
}
}
VkSubpassDescription subpass;
subpass.flags = 0;
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpass.inputAttachmentCount = 0;
subpass.pInputAttachments = nullptr;
subpass.colorAttachmentCount = colorRef.size();
subpass.pColorAttachments = colorRef.data();
subpass.pResolveAttachments = nullptr;
subpass.pDepthStencilAttachment = fmt.getDepthFormat() != VK_FORMAT_UNDEFINED ? &depthRef : nullptr;
subpass.preserveAttachmentCount = 0;
subpass.pPreserveAttachments = nullptr;
VkRenderPassCreateInfo info;
info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
info.pNext = nullptr;
info.flags = 0;
info.attachmentCount = attachments.size();
info.pAttachments = attachments.data();
info.subpassCount = 1;
info.pSubpasses = &subpass;
info.dependencyCount = 0;
info.pDependencies = nullptr;
if (m_vkd->vkCreateRenderPass(m_vkd->device(), &info, nullptr, &m_renderPass) != VK_SUCCESS)
throw DxvkError("DxvkRenderPass::DxvkRenderPass: Failed to create render pass object");
}
DxvkRenderPass::~DxvkRenderPass() {
m_vkd->vkDestroyRenderPass(
m_vkd->device(), m_renderPass, nullptr);
}
DxvkRenderPassPool::DxvkRenderPassPool(const Rc<vk::DeviceFn>& vkd)
2017-10-11 00:27:33 +02:00
: m_vkd(vkd) {
2017-11-26 14:01:41 +01:00
2017-10-11 00:27:33 +02:00
}
2017-10-10 23:32:13 +02:00
DxvkRenderPassPool::~DxvkRenderPassPool() {
2017-11-26 14:01:41 +01:00
2017-10-10 23:32:13 +02:00
}
Rc<DxvkRenderPass> DxvkRenderPassPool::getRenderPass(
const DxvkRenderPassFormat& fmt) {
std::lock_guard<std::mutex> lock(m_mutex);
auto rp = m_renderPasses.find(fmt);
if (rp != m_renderPasses.end())
return rp->second;
auto result = this->createRenderPass(fmt);
m_renderPasses.insert(std::make_pair(fmt, result));
return result;
}
Rc<DxvkRenderPass> DxvkRenderPassPool::createRenderPass(
const DxvkRenderPassFormat& fmt) {
return new DxvkRenderPass(m_vkd, fmt);
2017-10-10 23:32:13 +02:00
}
}