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

225 lines
5.5 KiB
C
Raw Normal View History

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;
};
struct DxvkAttachment {
Rc<DxvkImageView> view = nullptr;
VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED;
};
2017-10-10 23:32:13 +02:00
/**
* \brief Render target description
2017-10-10 23:32:13 +02:00
*
* Stores render targets for a framebuffer object
* and provides methods to query the render pass
* format. Note that all render target views must
* have the same size and number of array layers.
2017-10-10 23:32:13 +02:00
*/
class DxvkRenderTargets {
2017-10-10 23:32:13 +02:00
public:
DxvkRenderTargets();
~DxvkRenderTargets();
2017-10-10 23:32:13 +02:00
/**
* \brief Retrieves color target
*
* \param [in] id Color attachment ID
* \returns Render target view
2017-10-10 23:32:13 +02:00
*/
DxvkAttachment getColorTarget(uint32_t id) const {
return m_colorTargets.at(id);
2017-10-10 23:32:13 +02:00
}
/**
* \brief Retrieves depth-stencil target
* \returns Depth-stencil target view
2017-10-10 23:32:13 +02:00
*/
DxvkAttachment getDepthTarget() const {
return m_depthTarget;
2017-10-10 23:32:13 +02:00
}
/**
* \brief Sets color target
*
* \param [in] id Color attachment ID
* \param [in] view Render target view
* \param [in] layout Layout to use for rendering
2017-10-10 23:32:13 +02:00
*/
void setColorTarget(
uint32_t id,
const Rc<DxvkImageView>& view,
VkImageLayout layout) {
m_colorTargets.at(id) = { view, layout };
2017-10-10 23:32:13 +02:00
}
/**
* \brief Sets depth-stencil target
2017-10-10 23:32:13 +02:00
*
* \param [in] layout Layout to use for rendering
* \param [in] view Depth-stencil target view
2017-10-10 23:32:13 +02:00
*/
void setDepthTarget(
const Rc<DxvkImageView>& view,
VkImageLayout layout) {
m_depthTarget = { view, layout };
}
2017-10-10 23:32:13 +02:00
/**
* \brief Render pass format
2017-10-10 23:32:13 +02:00
*
* Computes the render pass format based on
* the color and depth-stencil attachments.
* \returns Render pass format
2017-10-10 23:32:13 +02:00
*/
DxvkRenderPassFormat renderPassFormat() const;
2017-10-10 23:32:13 +02:00
/**
* \brief Creates attachment list
*
* \param [out] viewHandles Attachment handles
* \returns Framebuffer attachment count
*/
uint32_t getAttachments(VkImageView* viewHandles) const;
/**
* \brief Framebuffer size
*
* The width, height and layer count of the
* attached render targets.
* \param [in] defaultSize Size to use when
* there are no framebuffer attachments.
* \returns Framebuffer size
*/
DxvkFramebufferSize getImageSize(
const DxvkFramebufferSize& defaultSize) const;
/**
* \brief Checks whether any attachments are defined
* \returns \c false if no attachments are defined
*/
bool hasAttachments() const;
/**
* \brief Compares two sets of render targets
*
* Checks whether two sets of render targets
* are identical, including the image layout.
* \param [in] other Render target set to compare to
* \returns \c true if the render targets are the same
*/
bool matches(const DxvkRenderTargets& other) const;
private:
std::array<DxvkAttachment, MaxNumRenderTargets> m_colorTargets;
DxvkAttachment m_depthTarget;
DxvkFramebufferSize renderTargetSize(
const Rc<DxvkImageView>& renderTarget) const;
};
/**
* \brief DXVK framebuffer
*
* A framebuffer either stores a set of image views
* that will be used as render targets, or in case
* no render targets are being used, fixed viewport
* dimensions.
*/
class DxvkFramebuffer : public DxvkResource {
public:
DxvkFramebuffer(
const Rc<vk::DeviceFn>& vkd,
const Rc<DxvkRenderPass>& renderPass,
const DxvkRenderTargets& renderTargets,
const DxvkFramebufferSize& defaultSize);
~DxvkFramebuffer();
/**
* \brief Framebuffer handle
* \returns Framebuffer handle
2017-10-10 23:32:13 +02:00
*/
VkFramebuffer handle() const {
return m_framebuffer;
2017-10-10 23:32:13 +02:00
}
/**
* \brief Render pass handle
* \returns Render pass handle
2017-10-10 23:32:13 +02:00
*/
VkRenderPass renderPass() const {
return m_renderPass->handle();
2017-10-10 23:32:13 +02:00
}
/**
* \brief Framebuffer size
* \returns Framebuffer size
2017-10-10 23:32:13 +02:00
*/
DxvkFramebufferSize size() const {
return m_framebufferSize;
2017-10-10 23:32:13 +02:00
}
/**
* \brief Render target info
* \returns Render target info
*/
const DxvkRenderTargets& renderTargets() const {
return m_renderTargets;
}
/**
* \brief Sample count
* \returns Sample count
*/
VkSampleCountFlagBits sampleCount() const {
return m_renderPass->sampleCount();
}
/**
* \brief Retrieves index of a given attachment
*
* \param [in] view The image view to look up
* \returns The attachment index, or \c 0 for a depth-stencil
* attachment, or \c MaxNumRenderTargets if the given
* view is not a framebuffer attachment.
*/
uint32_t findAttachment(
const Rc<DxvkImageView>& view) const;
2017-10-10 23:32:13 +02:00
private:
Rc<vk::DeviceFn> m_vkd;
Rc<DxvkRenderPass> m_renderPass;
2018-01-12 12:51:39 +01:00
DxvkRenderTargets m_renderTargets;
DxvkFramebufferSize m_framebufferSize = { 0, 0, 0 };
2018-01-12 12:51:39 +01:00
VkFramebuffer m_framebuffer = VK_NULL_HANDLE;
2017-10-10 23:32:13 +02:00
};
}