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

226 lines
5.8 KiB
C
Raw Normal View History

2017-10-10 23:32:13 +02:00
#pragma once
#include <mutex>
#include <vector>
2017-10-10 23:32:13 +02:00
#include "dxvk_hash.h"
#include "dxvk_include.h"
2017-10-14 13:37:40 +02:00
#include "dxvk_limits.h"
2017-10-10 23:32:13 +02:00
namespace dxvk {
/**
* \brief Format and layout for a render target
*
* Stores the image format of the attachment and
* the image layout that is used while rendering.
*/
struct DxvkAttachmentFormat {
VkFormat format = VK_FORMAT_UNDEFINED;
VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED;
};
2017-10-10 23:32:13 +02:00
/**
* \brief Render pass format
*
* Stores the attachment formats for all depth and
* color attachments, as well as the sample count.
2017-10-10 23:32:13 +02:00
*/
struct DxvkRenderPassFormat {
VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
DxvkAttachmentFormat depth;
DxvkAttachmentFormat color[MaxNumRenderTargets];
bool matches(const DxvkRenderPassFormat& fmt) const;
};
/**
* \brief Color attachment transitions
*
* Stores the load/store ops and the initial
* and final layout of a single attachment.
*/
struct DxvkColorAttachmentOps {
VkAttachmentLoadOp loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
VkImageLayout loadLayout = VK_IMAGE_LAYOUT_UNDEFINED;
VkAttachmentStoreOp storeOp = VK_ATTACHMENT_STORE_OP_STORE;
VkImageLayout storeLayout = VK_IMAGE_LAYOUT_GENERAL;
};
/**
* \brief Depth attachment transitions
*
* Stores the load/store ops and the initial and
* final layout of the depth-stencil attachment.
*/
struct DxvkDepthAttachmentOps {
VkAttachmentLoadOp loadOpD = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
VkAttachmentLoadOp loadOpS = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
VkImageLayout loadLayout = VK_IMAGE_LAYOUT_UNDEFINED;
VkAttachmentStoreOp storeOpD = VK_ATTACHMENT_STORE_OP_STORE;
VkAttachmentStoreOp storeOpS = VK_ATTACHMENT_STORE_OP_STORE;
VkImageLayout storeLayout = VK_IMAGE_LAYOUT_GENERAL;
};
/**
* \brief Render pass barrier
*
* External subpass dependency that is to be
* executed after a render pass has completed.
*/
struct DxvkRenderPassBarrier {
VkPipelineStageFlags srcStages = 0;
VkAccessFlags srcAccess = 0;
VkPipelineStageFlags dstStages = 0;
VkAccessFlags dstAccess = 0;
};
/**
* \brief Render pass transitions
*
* Stores transitions for all depth and color attachments.
* This is used to select a specific render pass object
* from a group of render passes with the same format.
*/
struct DxvkRenderPassOps {
DxvkRenderPassBarrier barrier;
DxvkDepthAttachmentOps depthOps;
DxvkColorAttachmentOps colorOps[MaxNumRenderTargets];
};
/**
* \brief Render pass object
*
* Manages a set of compatible render passes, i.e.
* render passes which share the same format but
* may differ in their attachment operations.
*/
class DxvkRenderPass : public RcObject {
2017-10-10 23:32:13 +02:00
public:
DxvkRenderPass(
const Rc<vk::DeviceFn>& vkd,
const DxvkRenderPassFormat& fmt);
~DxvkRenderPass();
2017-10-10 23:32:13 +02:00
/**
* \brief Retrieves render pass format
* \returns The render pass format
*/
DxvkRenderPassFormat format() const {
return m_format;
}
2017-10-10 23:32:13 +02:00
/**
* \brief Checks whether a format is compatible
2017-10-10 23:32:13 +02:00
*
* Two render pass formats are considered compatible
* if all the relevant attachment formats match.
* \param [in] fmt The render pass format to check
* \returns \c true if this render pass is compatible.
2017-10-10 23:32:13 +02:00
*/
bool hasCompatibleFormat(
const DxvkRenderPassFormat& fmt) const;
2017-10-10 23:32:13 +02:00
/**
* \brief Retrieves sample count
*
* If no sample count has been explicitly specitied,
* this will return \c VK_SAMPLE_COUNT_1_BIT.
* \returns Sample count
*/
VkSampleCountFlagBits getSampleCount() const {
return m_format.sampleCount;
2017-10-10 23:32:13 +02:00
}
/**
* \brief Returns handle of default render pass
2017-10-10 23:32:13 +02:00
*
* The default render pass handle should be used to
* create pipelines and framebuffer objects. It can
* \e not be used for \c vkCmdBeginRenderPass calls.
* \returns The default render pass handle
2017-10-10 23:32:13 +02:00
*/
VkRenderPass getDefaultHandle() const {
return m_default;
2017-10-10 23:32:13 +02:00
}
/**
* \brief Returns handle to a specialized render pass
*
* Returns a handle to a render pass with the given
* set of parameters. This should be used for calls
* to \c vkCmdBeginRenderPass.
* \param [in] ops Attachment ops
* \returns Render pass handle
2017-10-10 23:32:13 +02:00
*/
VkRenderPass getHandle(
const DxvkRenderPassOps& ops);
2017-10-10 23:32:13 +02:00
private:
struct Instance {
DxvkRenderPassOps ops;
VkRenderPass handle;
};
2017-10-10 23:32:13 +02:00
Rc<vk::DeviceFn> m_vkd;
DxvkRenderPassFormat m_format;
VkRenderPass m_default;
sync::Spinlock m_mutex;
std::vector<Instance> m_instances;
VkRenderPass createRenderPass(
const DxvkRenderPassOps& ops);
2017-10-10 23:32:13 +02:00
static bool compareOps(
const DxvkRenderPassOps& a,
const DxvkRenderPassOps& b);
2017-10-10 23:32:13 +02:00
};
/**
* \brief Render pass pool
*
* Manages render pass objects. For each render
* pass format, a new render pass object will
* be created, but no two render pass objects
* will have the same format.
2017-10-10 23:32:13 +02:00
*/
class DxvkRenderPassPool : public RcObject {
2017-10-10 23:32:13 +02:00
public:
DxvkRenderPassPool(
const Rc<vk::DeviceFn>& vkd);
2017-10-10 23:32:13 +02:00
~DxvkRenderPassPool();
/**
* \brief Retrieves a render pass object
*
* \param [in] fmt The render pass format
* \returns Matching render pass object
2017-10-10 23:32:13 +02:00
*/
Rc<DxvkRenderPass> getRenderPass(
const DxvkRenderPassFormat& fmt);
2017-10-10 23:32:13 +02:00
private:
const Rc<vk::DeviceFn> m_vkd;
2017-10-10 23:32:13 +02:00
std::mutex m_mutex;
std::vector<Rc<DxvkRenderPass>> m_renderPasses;
2017-10-10 23:32:13 +02:00
};
}