mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-08-23 23:27:18 +02:00
gl_rasterizer: Remove unused code paths from ConfigureFramebuffers
This commit is contained in:
parent
393cc3ef2f
commit
af809b491e
@ -35,21 +35,16 @@ OGLFramebuffer FramebufferCacheOpenGL::CreateFramebuffer(const FramebufferCacheK
|
|||||||
local_state.draw.draw_framebuffer = framebuffer.handle;
|
local_state.draw.draw_framebuffer = framebuffer.handle;
|
||||||
local_state.ApplyFramebufferState();
|
local_state.ApplyFramebufferState();
|
||||||
|
|
||||||
if (key.is_single_buffer) {
|
|
||||||
if (key.color_attachments[0] != GL_NONE && key.colors[0]) {
|
|
||||||
key.colors[0]->Attach(key.color_attachments[0], GL_DRAW_FRAMEBUFFER);
|
|
||||||
glDrawBuffer(key.color_attachments[0]);
|
|
||||||
} else {
|
|
||||||
glDrawBuffer(GL_NONE);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (std::size_t index = 0; index < Maxwell::NumRenderTargets; ++index) {
|
for (std::size_t index = 0; index < Maxwell::NumRenderTargets; ++index) {
|
||||||
if (key.colors[index]) {
|
if (key.colors[index]) {
|
||||||
key.colors[index]->Attach(GL_COLOR_ATTACHMENT0 + static_cast<GLenum>(index),
|
key.colors[index]->Attach(GL_COLOR_ATTACHMENT0 + static_cast<GLenum>(index),
|
||||||
GL_DRAW_FRAMEBUFFER);
|
GL_DRAW_FRAMEBUFFER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (key.colors_count) {
|
||||||
glDrawBuffers(key.colors_count, key.color_attachments.data());
|
glDrawBuffers(key.colors_count, key.color_attachments.data());
|
||||||
|
} else {
|
||||||
|
glDrawBuffer(GL_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key.zeta) {
|
if (key.zeta) {
|
||||||
@ -67,9 +62,9 @@ std::size_t FramebufferCacheKey::Hash() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool FramebufferCacheKey::operator==(const FramebufferCacheKey& rhs) const {
|
bool FramebufferCacheKey::operator==(const FramebufferCacheKey& rhs) const {
|
||||||
return std::tie(is_single_buffer, stencil_enable, colors_count, color_attachments, colors,
|
return std::tie(stencil_enable, colors_count, color_attachments, colors, zeta) ==
|
||||||
zeta) == std::tie(rhs.is_single_buffer, rhs.stencil_enable, rhs.colors_count,
|
std::tie(rhs.stencil_enable, rhs.colors_count, rhs.color_attachments, rhs.colors,
|
||||||
rhs.color_attachments, rhs.colors, rhs.zeta);
|
rhs.zeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace OpenGL
|
} // namespace OpenGL
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
namespace OpenGL {
|
namespace OpenGL {
|
||||||
|
|
||||||
struct alignas(sizeof(u64)) FramebufferCacheKey {
|
struct alignas(sizeof(u64)) FramebufferCacheKey {
|
||||||
bool is_single_buffer = false;
|
|
||||||
bool stencil_enable = false;
|
bool stencil_enable = false;
|
||||||
u16 colors_count = 0;
|
u16 colors_count = 0;
|
||||||
|
|
||||||
|
@ -445,65 +445,26 @@ void RasterizerOpenGL::LoadDiskResources(const std::atomic_bool& stop_loading,
|
|||||||
shader_cache.LoadDiskCache(stop_loading, callback);
|
shader_cache.LoadDiskCache(stop_loading, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<bool, bool> RasterizerOpenGL::ConfigureFramebuffers(
|
void RasterizerOpenGL::ConfigureFramebuffers() {
|
||||||
OpenGLState& current_state, bool using_color_fb, bool using_depth_fb, bool preserve_contents,
|
|
||||||
std::optional<std::size_t> single_color_target) {
|
|
||||||
MICROPROFILE_SCOPE(OpenGL_Framebuffer);
|
MICROPROFILE_SCOPE(OpenGL_Framebuffer);
|
||||||
auto& gpu = system.GPU().Maxwell3D();
|
auto& gpu = system.GPU().Maxwell3D();
|
||||||
const auto& regs = gpu.regs;
|
if (!gpu.dirty.render_settings) {
|
||||||
|
return;
|
||||||
const FramebufferConfigState fb_config_state{using_color_fb, using_depth_fb, preserve_contents,
|
|
||||||
single_color_target};
|
|
||||||
if (fb_config_state == current_framebuffer_config_state && !gpu.dirty.render_settings) {
|
|
||||||
// Only skip if the previous ConfigureFramebuffers call was from the same kind (multiple or
|
|
||||||
// single color targets). This is done because the guest registers may not change but the
|
|
||||||
// host framebuffer may contain different attachments
|
|
||||||
return current_depth_stencil_usage;
|
|
||||||
}
|
}
|
||||||
gpu.dirty.render_settings = false;
|
gpu.dirty.render_settings = false;
|
||||||
current_framebuffer_config_state = fb_config_state;
|
|
||||||
|
|
||||||
texture_cache.GuardRenderTargets(true);
|
texture_cache.GuardRenderTargets(true);
|
||||||
|
|
||||||
View depth_surface{};
|
View depth_surface = texture_cache.GetDepthBufferSurface(true);
|
||||||
if (using_depth_fb) {
|
|
||||||
depth_surface = texture_cache.GetDepthBufferSurface(preserve_contents);
|
|
||||||
} else {
|
|
||||||
texture_cache.SetEmptyDepthBuffer();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const auto& regs = gpu.regs;
|
||||||
|
state.framebuffer_srgb.enabled = regs.framebuffer_srgb != 0;
|
||||||
UNIMPLEMENTED_IF(regs.rt_separate_frag_data == 0);
|
UNIMPLEMENTED_IF(regs.rt_separate_frag_data == 0);
|
||||||
|
|
||||||
// Bind the framebuffer surfaces
|
// Bind the framebuffer surfaces
|
||||||
current_state.framebuffer_srgb.enabled = regs.framebuffer_srgb != 0;
|
|
||||||
|
|
||||||
FramebufferCacheKey fbkey;
|
FramebufferCacheKey fbkey;
|
||||||
|
|
||||||
if (using_color_fb) {
|
|
||||||
if (single_color_target) {
|
|
||||||
// Used when just a single color attachment is enabled, e.g. for clearing a color buffer
|
|
||||||
View color_surface{
|
|
||||||
texture_cache.GetColorBufferSurface(*single_color_target, preserve_contents)};
|
|
||||||
|
|
||||||
if (color_surface) {
|
|
||||||
// Assume that a surface will be written to if it is used as a framebuffer, even if
|
|
||||||
// the shader doesn't actually write to it.
|
|
||||||
texture_cache.MarkColorBufferInUse(*single_color_target);
|
|
||||||
}
|
|
||||||
|
|
||||||
fbkey.is_single_buffer = true;
|
|
||||||
fbkey.color_attachments[0] =
|
|
||||||
GL_COLOR_ATTACHMENT0 + static_cast<GLenum>(*single_color_target);
|
|
||||||
fbkey.colors[0] = color_surface;
|
|
||||||
for (std::size_t index = 0; index < Maxwell::NumRenderTargets; ++index) {
|
for (std::size_t index = 0; index < Maxwell::NumRenderTargets; ++index) {
|
||||||
if (index != *single_color_target) {
|
View color_surface{texture_cache.GetColorBufferSurface(index, true)};
|
||||||
texture_cache.SetEmptyColorBuffer(index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Multiple color attachments are enabled
|
|
||||||
for (std::size_t index = 0; index < Maxwell::NumRenderTargets; ++index) {
|
|
||||||
View color_surface{texture_cache.GetColorBufferSurface(index, preserve_contents)};
|
|
||||||
|
|
||||||
if (color_surface) {
|
if (color_surface) {
|
||||||
// Assume that a surface will be written to if it is used as a framebuffer, even
|
// Assume that a surface will be written to if it is used as a framebuffer, even
|
||||||
@ -511,33 +472,24 @@ std::pair<bool, bool> RasterizerOpenGL::ConfigureFramebuffers(
|
|||||||
texture_cache.MarkColorBufferInUse(index);
|
texture_cache.MarkColorBufferInUse(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
fbkey.color_attachments[index] =
|
fbkey.color_attachments[index] = GL_COLOR_ATTACHMENT0 + regs.rt_control.GetMap(index);
|
||||||
GL_COLOR_ATTACHMENT0 + regs.rt_control.GetMap(index);
|
fbkey.colors[index] = std::move(color_surface);
|
||||||
fbkey.colors[index] = color_surface;
|
|
||||||
}
|
}
|
||||||
fbkey.is_single_buffer = false;
|
|
||||||
fbkey.colors_count = regs.rt_control.count;
|
fbkey.colors_count = regs.rt_control.count;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// No color attachments are enabled - leave them as zero
|
|
||||||
fbkey.is_single_buffer = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (depth_surface) {
|
if (depth_surface) {
|
||||||
// Assume that a surface will be written to if it is used as a framebuffer, even if
|
// Assume that a surface will be written to if it is used as a framebuffer, even if
|
||||||
// the shader doesn't actually write to it.
|
// the shader doesn't actually write to it.
|
||||||
texture_cache.MarkDepthBufferInUse();
|
texture_cache.MarkDepthBufferInUse();
|
||||||
|
|
||||||
fbkey.zeta = depth_surface;
|
|
||||||
fbkey.stencil_enable = depth_surface->GetSurfaceParams().type == SurfaceType::DepthStencil;
|
fbkey.stencil_enable = depth_surface->GetSurfaceParams().type == SurfaceType::DepthStencil;
|
||||||
|
fbkey.zeta = std::move(depth_surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
texture_cache.GuardRenderTargets(false);
|
texture_cache.GuardRenderTargets(false);
|
||||||
|
|
||||||
current_state.draw.draw_framebuffer = framebuffer_cache.GetFramebuffer(fbkey);
|
state.draw.draw_framebuffer = framebuffer_cache.GetFramebuffer(fbkey);
|
||||||
SyncViewport(current_state);
|
SyncViewport(state);
|
||||||
|
|
||||||
return current_depth_stencil_usage = {static_cast<bool>(depth_surface), fbkey.stencil_enable};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerOpenGL::ConfigureClearFramebuffer(OpenGLState& current_state, bool using_color_fb,
|
void RasterizerOpenGL::ConfigureClearFramebuffer(OpenGLState& current_state, bool using_color_fb,
|
||||||
@ -757,7 +709,7 @@ void RasterizerOpenGL::DrawArrays() {
|
|||||||
SetupShaders(params.primitive_mode);
|
SetupShaders(params.primitive_mode);
|
||||||
texture_cache.GuardSamplers(false);
|
texture_cache.GuardSamplers(false);
|
||||||
|
|
||||||
ConfigureFramebuffers(state);
|
ConfigureFramebuffers();
|
||||||
|
|
||||||
// Signal the buffer cache that we are not going to upload more things.
|
// Signal the buffer cache that we are not going to upload more things.
|
||||||
const bool invalidate = buffer_cache.Unmap();
|
const bool invalidate = buffer_cache.Unmap();
|
||||||
|
@ -77,39 +77,8 @@ public:
|
|||||||
const VideoCore::DiskResourceLoadCallback& callback) override;
|
const VideoCore::DiskResourceLoadCallback& callback) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct FramebufferConfigState {
|
/// Configures the color and depth framebuffer states.
|
||||||
bool using_color_fb{};
|
void ConfigureFramebuffers();
|
||||||
bool using_depth_fb{};
|
|
||||||
bool preserve_contents{};
|
|
||||||
std::optional<std::size_t> single_color_target;
|
|
||||||
|
|
||||||
bool operator==(const FramebufferConfigState& rhs) const {
|
|
||||||
return std::tie(using_color_fb, using_depth_fb, preserve_contents,
|
|
||||||
single_color_target) == std::tie(rhs.using_color_fb, rhs.using_depth_fb,
|
|
||||||
rhs.preserve_contents,
|
|
||||||
rhs.single_color_target);
|
|
||||||
}
|
|
||||||
bool operator!=(const FramebufferConfigState& rhs) const {
|
|
||||||
return !operator==(rhs);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configures the color and depth framebuffer states.
|
|
||||||
*
|
|
||||||
* @param current_state The current OpenGL state.
|
|
||||||
* @param using_color_fb If true, configure color framebuffers.
|
|
||||||
* @param using_depth_fb If true, configure the depth/stencil framebuffer.
|
|
||||||
* @param preserve_contents If true, tries to preserve data from a previously used
|
|
||||||
* framebuffer.
|
|
||||||
* @param single_color_target Specifies if a single color buffer target should be used.
|
|
||||||
*
|
|
||||||
* @returns If depth (first) or stencil (second) are being stored in the bound zeta texture
|
|
||||||
* (requires using_depth_fb to be true)
|
|
||||||
*/
|
|
||||||
std::pair<bool, bool> ConfigureFramebuffers(
|
|
||||||
OpenGLState& current_state, bool using_color_fb = true, bool using_depth_fb = true,
|
|
||||||
bool preserve_contents = true, std::optional<std::size_t> single_color_target = {});
|
|
||||||
|
|
||||||
void ConfigureClearFramebuffer(OpenGLState& current_state, bool using_color_fb,
|
void ConfigureClearFramebuffer(OpenGLState& current_state, bool using_color_fb,
|
||||||
bool using_depth_fb, bool using_stencil_fb);
|
bool using_depth_fb, bool using_stencil_fb);
|
||||||
@ -228,9 +197,6 @@ private:
|
|||||||
OGLVertexArray>
|
OGLVertexArray>
|
||||||
vertex_array_cache;
|
vertex_array_cache;
|
||||||
|
|
||||||
FramebufferConfigState current_framebuffer_config_state;
|
|
||||||
std::pair<bool, bool> current_depth_stencil_usage{};
|
|
||||||
|
|
||||||
static constexpr std::size_t STREAM_BUFFER_SIZE = 128 * 1024 * 1024;
|
static constexpr std::size_t STREAM_BUFFER_SIZE = 128 * 1024 * 1024;
|
||||||
OGLBufferCache buffer_cache;
|
OGLBufferCache buffer_cache;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user