mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-29 17:19:44 -06:00
VideoCommon: Add support for Abstract Framebuffers
This commit is contained in:
55
Source/Core/VideoCommon/AbstractFramebuffer.cpp
Normal file
55
Source/Core/VideoCommon/AbstractFramebuffer.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
// Copyright 2018 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "VideoCommon/AbstractFramebuffer.h"
|
||||
#include "VideoCommon/AbstractTexture.h"
|
||||
|
||||
AbstractFramebuffer::AbstractFramebuffer(AbstractTextureFormat color_format,
|
||||
AbstractTextureFormat depth_format, u32 width, u32 height,
|
||||
u32 layers, u32 samples)
|
||||
: m_color_format(color_format), m_depth_format(depth_format), m_width(width), m_height(height),
|
||||
m_layers(layers), m_samples(samples)
|
||||
{
|
||||
}
|
||||
|
||||
AbstractFramebuffer::~AbstractFramebuffer() = default;
|
||||
|
||||
bool AbstractFramebuffer::ValidateConfig(const AbstractTexture* color_attachment,
|
||||
const AbstractTexture* depth_attachment)
|
||||
{
|
||||
// Must have at least a color or depth attachment.
|
||||
if (!color_attachment && !depth_attachment)
|
||||
return false;
|
||||
|
||||
// Currently we only expose a single mip level for render target textures.
|
||||
// MSAA textures are not supported with mip levels on most backends, and it simplifies our
|
||||
// handling of framebuffers.
|
||||
auto CheckAttachment = [](const AbstractTexture* tex) {
|
||||
return tex->GetConfig().rendertarget && tex->GetConfig().levels == 1;
|
||||
};
|
||||
if ((color_attachment && !CheckAttachment(color_attachment)) ||
|
||||
depth_attachment && !CheckAttachment(depth_attachment))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// If both color and depth are present, their attributes must match.
|
||||
if (color_attachment && depth_attachment)
|
||||
{
|
||||
if (color_attachment->GetConfig().width != depth_attachment->GetConfig().width ||
|
||||
color_attachment->GetConfig().height != depth_attachment->GetConfig().height ||
|
||||
color_attachment->GetConfig().layers != depth_attachment->GetConfig().layers ||
|
||||
color_attachment->GetConfig().samples != depth_attachment->GetConfig().samples)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
MathUtil::Rectangle<int> AbstractFramebuffer::GetRect() const
|
||||
{
|
||||
return MathUtil::Rectangle<int>(0, 0, static_cast<int>(m_width), static_cast<int>(m_height));
|
||||
}
|
45
Source/Core/VideoCommon/AbstractFramebuffer.h
Normal file
45
Source/Core/VideoCommon/AbstractFramebuffer.h
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright 2018 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/MathUtil.h"
|
||||
#include "VideoCommon/TextureConfig.h"
|
||||
|
||||
class AbstractTexture;
|
||||
|
||||
// An abstract framebuffer wraps a backend framebuffer/view object, which can be used to
|
||||
// draw onto a texture. Currently, only single-level textures are supported. Multi-layer
|
||||
// textures will render by default only to the first layer, however, multiple layers
|
||||
// be rendered in parallel using geometry shaders and layer variable.
|
||||
|
||||
class AbstractFramebuffer
|
||||
{
|
||||
public:
|
||||
AbstractFramebuffer(AbstractTextureFormat color_format, AbstractTextureFormat depth_format,
|
||||
u32 width, u32 height, u32 layers, u32 samples);
|
||||
virtual ~AbstractFramebuffer();
|
||||
|
||||
static bool ValidateConfig(const AbstractTexture* color_attachment,
|
||||
const AbstractTexture* depth_attachment);
|
||||
|
||||
AbstractTextureFormat GetColorFormat() const { return m_color_format; }
|
||||
AbstractTextureFormat GetDepthFormat() const { return m_depth_format; }
|
||||
bool HasColorBuffer() const { return m_color_format != AbstractTextureFormat::Undefined; }
|
||||
bool HasDepthBuffer() const { return m_depth_format != AbstractTextureFormat::Undefined; }
|
||||
u32 GetWidth() const { return m_width; }
|
||||
u32 GetHeight() const { return m_height; }
|
||||
u32 GetLayers() const { return m_layers; }
|
||||
u32 GetSamples() const { return m_samples; }
|
||||
MathUtil::Rectangle<int> GetRect() const;
|
||||
|
||||
protected:
|
||||
AbstractTextureFormat m_color_format;
|
||||
AbstractTextureFormat m_depth_format;
|
||||
u32 m_width;
|
||||
u32 m_height;
|
||||
u32 m_layers;
|
||||
u32 m_samples;
|
||||
};
|
@ -78,6 +78,11 @@ bool AbstractTexture::IsDepthFormat(AbstractTextureFormat format)
|
||||
}
|
||||
}
|
||||
|
||||
bool AbstractTexture::IsStencilFormat(AbstractTextureFormat format)
|
||||
{
|
||||
return format == AbstractTextureFormat::D32F_S8;
|
||||
}
|
||||
|
||||
size_t AbstractTexture::CalculateStrideForFormat(AbstractTextureFormat format, u32 row_length)
|
||||
{
|
||||
switch (format)
|
||||
|
@ -40,6 +40,7 @@ public:
|
||||
|
||||
static bool IsCompressedFormat(AbstractTextureFormat format);
|
||||
static bool IsDepthFormat(AbstractTextureFormat format);
|
||||
static bool IsStencilFormat(AbstractTextureFormat format);
|
||||
static size_t CalculateStrideForFormat(AbstractTextureFormat format, u32 row_length);
|
||||
static size_t GetTexelSizeForFormat(AbstractTextureFormat format);
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
set(SRCS
|
||||
AbstractFramebuffer.cpp
|
||||
AbstractStagingTexture.cpp
|
||||
AbstractTexture.cpp
|
||||
AsyncRequests.cpp
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "Core/Movie.h"
|
||||
|
||||
#include "VideoCommon/AVIDump.h"
|
||||
#include "VideoCommon/AbstractFramebuffer.h"
|
||||
#include "VideoCommon/AbstractStagingTexture.h"
|
||||
#include "VideoCommon/AbstractTexture.h"
|
||||
#include "VideoCommon/BPMemory.h"
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <condition_variable>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
@ -32,6 +33,7 @@
|
||||
#include "VideoCommon/RenderState.h"
|
||||
#include "VideoCommon/VideoCommon.h"
|
||||
|
||||
class AbstractFramebuffer;
|
||||
class AbstractPipeline;
|
||||
class AbstractShader;
|
||||
class AbstractTexture;
|
||||
@ -63,6 +65,8 @@ public:
|
||||
Renderer(int backbuffer_width, int backbuffer_height);
|
||||
virtual ~Renderer();
|
||||
|
||||
using ClearColor = std::array<float, 4>;
|
||||
|
||||
enum PixelPerfQuery
|
||||
{
|
||||
PP_ZCOMP_INPUT_ZCOMPLOC,
|
||||
@ -95,6 +99,17 @@ public:
|
||||
virtual std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config) = 0;
|
||||
virtual std::unique_ptr<AbstractStagingTexture>
|
||||
CreateStagingTexture(StagingTextureType type, const TextureConfig& config) = 0;
|
||||
virtual std::unique_ptr<AbstractFramebuffer>
|
||||
CreateFramebuffer(const AbstractTexture* color_attachment,
|
||||
const AbstractTexture* depth_attachment) = 0;
|
||||
|
||||
// Framebuffer operations.
|
||||
virtual void SetFramebuffer(const AbstractFramebuffer* framebuffer) {}
|
||||
virtual void SetAndDiscardFramebuffer(const AbstractFramebuffer* framebuffer) {}
|
||||
virtual void SetAndClearFramebuffer(const AbstractFramebuffer* framebuffer,
|
||||
const ClearColor& color_value = {}, float depth_value = 0.0f)
|
||||
{
|
||||
}
|
||||
|
||||
// Shader modules/objects.
|
||||
virtual std::unique_ptr<AbstractShader>
|
||||
@ -104,6 +119,9 @@ public:
|
||||
virtual std::unique_ptr<AbstractPipeline>
|
||||
CreatePipeline(const AbstractPipelineConfig& config) = 0;
|
||||
|
||||
const AbstractFramebuffer* GetCurrentFramebuffer() const { return m_current_framebuffer; }
|
||||
u32 GetCurrentFramebufferWidth() const { return m_current_framebuffer_width; }
|
||||
u32 GetCurrentFramebufferHeight() const { return m_current_framebuffer_height; }
|
||||
// Ideal internal resolution - multiple of the native EFB resolution
|
||||
int GetTargetWidth() const { return m_target_width; }
|
||||
int GetTargetHeight() const { return m_target_height; }
|
||||
@ -192,6 +210,11 @@ protected:
|
||||
void CheckFifoRecording();
|
||||
void RecordVideoMemory();
|
||||
|
||||
// TODO: Remove the width/height parameters once we make the EFB an abstract framebuffer.
|
||||
const AbstractFramebuffer* m_current_framebuffer = nullptr;
|
||||
u32 m_current_framebuffer_width = 1;
|
||||
u32 m_current_framebuffer_height = 1;
|
||||
|
||||
Common::Flag m_screenshot_request;
|
||||
Common::Event m_screenshot_completed;
|
||||
std::mutex m_screenshot_lock;
|
||||
|
@ -36,6 +36,7 @@
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemGroup>
|
||||
<ClCompile Include="AbstractFramebuffer.cpp" />
|
||||
<ClCompile Include="AbstractStagingTexture.cpp" />
|
||||
<ClCompile Include="AbstractTexture.cpp" />
|
||||
<ClCompile Include="AsyncRequests.cpp" />
|
||||
@ -98,6 +99,7 @@
|
||||
<ClCompile Include="XFStructs.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="AbstractFramebuffer.h" />
|
||||
<ClInclude Include="AbstractStagingTexture.h" />
|
||||
<ClInclude Include="AbstractPipeline.h" />
|
||||
<ClInclude Include="AbstractShader.h" />
|
||||
|
@ -194,6 +194,9 @@
|
||||
<ClCompile Include="AbstractStagingTexture.cpp">
|
||||
<Filter>Base</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="AbstractFramebuffer.cpp">
|
||||
<Filter>Base</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="CommandProcessor.h" />
|
||||
@ -263,9 +266,6 @@
|
||||
<ClInclude Include="TextureConversionShader.h">
|
||||
<Filter>Shader Generators</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="TextureConvertionShaderGen.h">
|
||||
<Filter>Shader Generators</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="VertexShaderGen.h">
|
||||
<Filter>Shader Generators</Filter>
|
||||
</ClInclude>
|
||||
@ -374,6 +374,10 @@
|
||||
<ClInclude Include="AbstractPipeline.h">
|
||||
<Filter>Base</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="TextureConverterShaderGen.h" />
|
||||
<ClInclude Include="AbstractFramebuffer.h">
|
||||
<Filter>Base</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="CMakeLists.txt" />
|
||||
|
Reference in New Issue
Block a user