2017-10-10 23:32:13 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "dxvk_image.h"
|
|
|
|
#include "dxvk_renderpass.h"
|
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Framebuffer size
|
|
|
|
*
|
|
|
|
* Stores the width, height and number of layers
|
|
|
|
* of a framebuffer. This can be used in case a
|
|
|
|
* framebuffer does not have any attachments.
|
|
|
|
*/
|
|
|
|
struct DxvkFramebufferSize {
|
|
|
|
uint32_t width;
|
|
|
|
uint32_t height;
|
|
|
|
uint32_t layers;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-04-30 13:12:28 +02:00
|
|
|
/**
|
|
|
|
* \brief Framebuffer attachment
|
|
|
|
*
|
|
|
|
* Stores an attachment, as well as the image layout
|
|
|
|
* that will be used for rendering to the attachment.
|
|
|
|
*/
|
2018-02-06 17:31:23 +01:00
|
|
|
struct DxvkAttachment {
|
|
|
|
Rc<DxvkImageView> view = nullptr;
|
|
|
|
VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-10-10 23:32:13 +02:00
|
|
|
/**
|
2018-04-30 13:12:28 +02:00
|
|
|
* \brief Render targets
|
2017-10-10 23:32:13 +02:00
|
|
|
*
|
2018-04-30 13:12:28 +02:00
|
|
|
* Stores all depth-stencil and color
|
|
|
|
* attachments attached to a framebuffer.
|
|
|
|
*/
|
|
|
|
struct DxvkRenderTargets {
|
|
|
|
DxvkAttachment depth;
|
|
|
|
DxvkAttachment color[MaxNumRenderTargets];
|
|
|
|
};
|
2021-02-09 17:53:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Render target layouts
|
|
|
|
*/
|
|
|
|
struct DxvkRenderTargetLayouts {
|
|
|
|
VkImageLayout color[MaxNumRenderTargets];
|
|
|
|
VkImageLayout depth;
|
|
|
|
};
|
2018-04-30 13:12:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Framebuffer
|
|
|
|
*
|
|
|
|
* A framebuffer either stores a set of image views
|
|
|
|
* that will be used as render targets, or in case
|
|
|
|
* no render targets are attached, fixed dimensions.
|
2017-10-10 23:32:13 +02:00
|
|
|
*/
|
2018-04-30 13:12:28 +02:00
|
|
|
class DxvkFramebuffer : public DxvkResource {
|
2017-10-10 23:32:13 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2018-04-30 13:12:28 +02:00
|
|
|
DxvkFramebuffer(
|
|
|
|
const Rc<vk::DeviceFn>& vkd,
|
2019-07-30 13:04:13 +02:00
|
|
|
DxvkRenderPass* renderPass,
|
2018-04-30 13:12:28 +02:00
|
|
|
const DxvkRenderTargets& renderTargets,
|
|
|
|
const DxvkFramebufferSize& defaultSize);
|
2017-10-10 23:32:13 +02:00
|
|
|
|
2018-04-30 13:12:28 +02:00
|
|
|
~DxvkFramebuffer();
|
2017-10-10 23:32:13 +02:00
|
|
|
|
|
|
|
/**
|
2018-04-30 13:12:28 +02:00
|
|
|
* \brief Framebuffer handle
|
|
|
|
* \returns Framebuffer handle
|
2017-10-10 23:32:13 +02:00
|
|
|
*/
|
2018-04-30 13:12:28 +02:00
|
|
|
VkFramebuffer handle() const {
|
|
|
|
return m_handle;
|
2017-10-10 23:32:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-04-30 13:12:28 +02:00
|
|
|
* \brief Framebuffer size
|
|
|
|
* \returns Framebuffer size
|
2017-10-10 23:32:13 +02:00
|
|
|
*/
|
2018-04-30 13:12:28 +02:00
|
|
|
DxvkFramebufferSize size() const {
|
|
|
|
return m_renderSize;
|
2017-10-10 23:32:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-09-18 13:21:58 +02:00
|
|
|
* \brief Framebuffer sample count
|
|
|
|
*
|
|
|
|
* Returns the sample count of the color
|
|
|
|
* and depth-stencil attachments, or 0 if
|
|
|
|
* there are no attachments.
|
2018-04-30 13:12:28 +02:00
|
|
|
* \returns Sample count
|
2017-10-10 23:32:13 +02:00
|
|
|
*/
|
2018-09-18 13:21:58 +02:00
|
|
|
VkSampleCountFlags getSampleCount() const {
|
|
|
|
return m_attachmentCount != 0
|
|
|
|
? m_renderPass->getSampleCount()
|
|
|
|
: 0;
|
2018-04-30 13:12:28 +02:00
|
|
|
}
|
2017-10-10 23:32:13 +02:00
|
|
|
|
|
|
|
/**
|
2018-04-30 13:12:28 +02:00
|
|
|
* \brief Retrieves default render pass handle
|
2017-10-10 23:32:13 +02:00
|
|
|
*
|
2018-04-30 13:12:28 +02:00
|
|
|
* Retrieves the render pass handle that was used
|
|
|
|
* to create the Vulkan framebuffer object with,
|
|
|
|
* and that should be used to create pipelines.
|
|
|
|
* \returns The default render pass handle
|
2017-10-10 23:32:13 +02:00
|
|
|
*/
|
2018-04-30 13:12:28 +02:00
|
|
|
VkRenderPass getDefaultRenderPassHandle() const {
|
|
|
|
return m_renderPass->getDefaultHandle();
|
|
|
|
}
|
2017-12-19 18:12:18 +01:00
|
|
|
|
2018-04-15 03:01:52 +02:00
|
|
|
/**
|
2018-04-30 13:12:28 +02:00
|
|
|
* \brief Retrieves render pass handle
|
2018-04-15 03:01:52 +02:00
|
|
|
*
|
2018-04-30 13:12:28 +02:00
|
|
|
* Retrieves a render pass handle that can
|
|
|
|
* be used to begin a render pass instance.
|
|
|
|
* \param [in] ops Render pass ops
|
|
|
|
* \returns The render pass handle
|
2018-04-30 18:47:07 +02:00
|
|
|
*/
|
2018-04-30 13:12:28 +02:00
|
|
|
VkRenderPass getRenderPassHandle(const DxvkRenderPassOps& ops) const {
|
|
|
|
return m_renderPass->getHandle(ops);
|
|
|
|
}
|
2018-04-30 18:47:07 +02:00
|
|
|
|
2018-05-03 19:33:41 +02:00
|
|
|
/**
|
|
|
|
* \brief Retrieves render pass
|
|
|
|
* \returns Render pass reference
|
|
|
|
*/
|
2019-07-30 13:15:45 +02:00
|
|
|
DxvkRenderPass* getRenderPass() const {
|
|
|
|
return m_renderPass;
|
2018-05-03 19:33:41 +02:00
|
|
|
}
|
|
|
|
|
2018-04-30 18:47:07 +02:00
|
|
|
/**
|
2018-04-30 13:12:28 +02:00
|
|
|
* \brief Depth-stencil target
|
|
|
|
* \returns Depth-stencil target
|
2018-04-30 18:47:07 +02:00
|
|
|
*/
|
2018-04-30 13:12:28 +02:00
|
|
|
const DxvkAttachment& getDepthTarget() const {
|
|
|
|
return m_renderTargets.depth;
|
|
|
|
}
|
2018-04-30 18:47:07 +02:00
|
|
|
|
|
|
|
/**
|
2018-04-30 13:12:28 +02:00
|
|
|
* \brief Color target
|
2018-04-30 18:47:07 +02:00
|
|
|
*
|
2018-04-30 13:12:28 +02:00
|
|
|
* \param [in] id Target Index
|
|
|
|
* \returns The color target
|
2017-10-10 23:32:13 +02:00
|
|
|
*/
|
2018-04-30 13:12:28 +02:00
|
|
|
const DxvkAttachment& getColorTarget(uint32_t id) const {
|
|
|
|
return m_renderTargets.color[id];
|
2017-10-10 23:32:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-04-30 13:12:28 +02:00
|
|
|
* \brief Number of framebuffer attachment
|
|
|
|
* \returns Total attachment count
|
2017-10-10 23:32:13 +02:00
|
|
|
*/
|
2018-04-30 13:12:28 +02:00
|
|
|
uint32_t numAttachments() const {
|
|
|
|
return m_attachmentCount;
|
2017-10-10 23:32:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-04-30 13:12:28 +02:00
|
|
|
* \brief Retrieves attachment by index
|
|
|
|
*
|
|
|
|
* \param [in] id Framebuffer attachment ID
|
|
|
|
* \returns The framebuffer attachment
|
2017-10-10 23:32:13 +02:00
|
|
|
*/
|
2018-04-30 13:12:28 +02:00
|
|
|
const DxvkAttachment& getAttachment(uint32_t id) const {
|
|
|
|
return *m_attachments[id];
|
2017-10-10 23:32:13 +02:00
|
|
|
}
|
|
|
|
|
2017-12-04 13:39:14 +01:00
|
|
|
/**
|
2018-04-30 13:12:28 +02:00
|
|
|
* \brief Finds attachment index by view
|
|
|
|
*
|
|
|
|
* Color attachments start at 0
|
|
|
|
* \param [in] view Image view
|
|
|
|
* \returns Attachment index
|
2017-12-04 13:39:14 +01:00
|
|
|
*/
|
2018-04-30 13:12:28 +02:00
|
|
|
int32_t findAttachment(const Rc<DxvkImageView>& view) const;
|
2017-12-04 13:39:14 +01:00
|
|
|
|
2017-12-12 00:27:49 +01:00
|
|
|
/**
|
2018-04-30 13:12:28 +02:00
|
|
|
* \brief Checks whether the framebuffer's targets match
|
|
|
|
*
|
|
|
|
* \param [in] renderTargets Render targets to check
|
|
|
|
* \returns \c true if the render targets are the same
|
|
|
|
* as the ones used for this framebuffer object.
|
2017-12-12 00:27:49 +01:00
|
|
|
*/
|
2019-02-04 07:31:17 +01:00
|
|
|
bool hasTargets(const DxvkRenderTargets& renderTargets);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Checks whether view and framebuffer sizes match
|
|
|
|
*
|
|
|
|
* Tests whether the size of the framebuffer is the same
|
|
|
|
* as the size of one of its views. This may be \c false
|
|
|
|
* when mixing attachments with mismatched dimensions.
|
|
|
|
* \param [in] view Image view to test
|
|
|
|
* \returns \c true if \c view has the same size as
|
|
|
|
* the framebuffer.
|
|
|
|
*/
|
|
|
|
bool isFullSize(const Rc<DxvkImageView>& view) const;
|
2017-12-12 00:27:49 +01:00
|
|
|
|
2018-03-17 17:59:43 +01:00
|
|
|
/**
|
2018-04-30 13:12:28 +02:00
|
|
|
* \brief Generatess render pass format
|
2018-03-17 17:59:43 +01:00
|
|
|
*
|
2018-04-30 13:12:28 +02:00
|
|
|
* This render pass format can be used to
|
|
|
|
* look up a compatible render pass.
|
|
|
|
* \param [in] renderTargets Render targets
|
|
|
|
* \returns The render pass format
|
2018-03-17 17:59:43 +01:00
|
|
|
*/
|
2018-04-30 13:12:28 +02:00
|
|
|
static DxvkRenderPassFormat getRenderPassFormat(
|
|
|
|
const DxvkRenderTargets& renderTargets);
|
2018-03-17 17:59:43 +01:00
|
|
|
|
2017-10-10 23:32:13 +02:00
|
|
|
private:
|
|
|
|
|
2018-04-30 13:12:28 +02:00
|
|
|
const Rc<vk::DeviceFn> m_vkd;
|
2019-07-30 13:04:13 +02:00
|
|
|
DxvkRenderPass* m_renderPass;
|
2018-04-30 13:12:28 +02:00
|
|
|
const DxvkRenderTargets m_renderTargets;
|
|
|
|
const DxvkFramebufferSize m_renderSize;
|
|
|
|
|
|
|
|
uint32_t m_attachmentCount = 0;
|
|
|
|
std::array<const DxvkAttachment*, MaxNumRenderTargets + 1> m_attachments;
|
2018-01-12 12:51:39 +01:00
|
|
|
|
2018-04-30 13:12:28 +02:00
|
|
|
VkFramebuffer m_handle = VK_NULL_HANDLE;
|
2018-01-12 12:51:39 +01:00
|
|
|
|
2018-04-30 13:12:28 +02:00
|
|
|
DxvkFramebufferSize computeRenderSize(
|
|
|
|
const DxvkFramebufferSize& defaultSize) const;
|
|
|
|
|
|
|
|
DxvkFramebufferSize computeRenderTargetSize(
|
|
|
|
const Rc<DxvkImageView>& renderTarget) const;
|
2017-10-10 23:32:13 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|