6 changed files with 148 additions and 62 deletions
-
2src/video_core/CMakeLists.txt
-
73src/video_core/renderer_opengl/gl_framebuffer_cache.cpp
-
68src/video_core/renderer_opengl/gl_framebuffer_cache.h
-
59src/video_core/renderer_opengl/gl_rasterizer.cpp
-
6src/video_core/renderer_opengl/gl_rasterizer.h
-
2src/video_core/texture_cache/texture_cache.h
@ -0,0 +1,73 @@ |
|||
// Copyright 2019 yuzu Emulator Project
|
|||
// Licensed under GPLv2 or any later version
|
|||
// Refer to the license.txt file included.
|
|||
|
|||
#include <tuple>
|
|||
|
|||
#include "common/cityhash.h"
|
|||
#include "common/scope_exit.h"
|
|||
#include "video_core/engines/maxwell_3d.h"
|
|||
#include "video_core/renderer_opengl/gl_framebuffer_cache.h"
|
|||
#include "video_core/renderer_opengl/gl_state.h"
|
|||
|
|||
namespace OpenGL { |
|||
|
|||
using Maxwell = Tegra::Engines::Maxwell3D::Regs; |
|||
|
|||
FramebufferCacheOpenGL::FramebufferCacheOpenGL() = default; |
|||
|
|||
FramebufferCacheOpenGL::~FramebufferCacheOpenGL() = default; |
|||
|
|||
GLuint FramebufferCacheOpenGL::GetFramebuffer(const FramebufferCacheKey& key) { |
|||
const auto [entry, is_cache_miss] = cache.try_emplace(key); |
|||
auto& framebuffer{entry->second}; |
|||
if (is_cache_miss) { |
|||
framebuffer = CreateFramebuffer(key); |
|||
} |
|||
return framebuffer.handle; |
|||
} |
|||
|
|||
OGLFramebuffer FramebufferCacheOpenGL::CreateFramebuffer(const FramebufferCacheKey& key) { |
|||
OGLFramebuffer framebuffer; |
|||
framebuffer.Create(); |
|||
|
|||
// TODO(Rodrigo): Use DSA here after Nvidia fixes their framebuffer DSA bugs.
|
|||
local_state.draw.draw_framebuffer = framebuffer.handle; |
|||
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]); |
|||
glDrawBuffer(key.color_attachments[0]); |
|||
} else { |
|||
glDrawBuffer(GL_NONE); |
|||
} |
|||
} else { |
|||
for (std::size_t index = 0; index < Maxwell::NumRenderTargets; ++index) { |
|||
if (key.colors[index]) { |
|||
key.colors[index]->Attach(GL_COLOR_ATTACHMENT0 + static_cast<GLenum>(index)); |
|||
} |
|||
} |
|||
glDrawBuffers(key.colors_count, key.color_attachments.data()); |
|||
} |
|||
|
|||
if (key.zeta) { |
|||
key.zeta->Attach(key.stencil_enable ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT); |
|||
} |
|||
|
|||
return framebuffer; |
|||
} |
|||
|
|||
std::size_t FramebufferCacheKey::Hash() const { |
|||
static_assert(sizeof(*this) % sizeof(u64) == 0, "Unaligned struct"); |
|||
return static_cast<std::size_t>( |
|||
Common::CityHash64(reinterpret_cast<const char*>(this), sizeof(*this))); |
|||
} |
|||
|
|||
bool FramebufferCacheKey::operator==(const FramebufferCacheKey& rhs) const { |
|||
return std::tie(is_single_buffer, stencil_enable, colors_count, color_attachments, colors, |
|||
zeta) == std::tie(rhs.is_single_buffer, rhs.stencil_enable, rhs.colors_count, |
|||
rhs.color_attachments, rhs.colors, rhs.zeta); |
|||
} |
|||
|
|||
} // namespace OpenGL
|
|||
@ -0,0 +1,68 @@ |
|||
// Copyright 2019 yuzu Emulator Project |
|||
// Licensed under GPLv2 or any later version |
|||
// Refer to the license.txt file included. |
|||
|
|||
#pragma once |
|||
|
|||
#include <array> |
|||
#include <cstddef> |
|||
#include <unordered_map> |
|||
|
|||
#include <glad/glad.h> |
|||
|
|||
#include "common/common_types.h" |
|||
#include "video_core/engines/maxwell_3d.h" |
|||
#include "video_core/renderer_opengl/gl_resource_manager.h" |
|||
#include "video_core/renderer_opengl/gl_state.h" |
|||
#include "video_core/renderer_opengl/gl_texture_cache.h" |
|||
|
|||
namespace OpenGL { |
|||
|
|||
struct alignas(sizeof(u64)) FramebufferCacheKey { |
|||
bool is_single_buffer = false; |
|||
bool stencil_enable = false; |
|||
u16 colors_count = 0; |
|||
|
|||
std::array<GLenum, Tegra::Engines::Maxwell3D::Regs::NumRenderTargets> color_attachments{}; |
|||
std::array<View, Tegra::Engines::Maxwell3D::Regs::NumRenderTargets> colors; |
|||
View zeta; |
|||
|
|||
std::size_t Hash() const; |
|||
|
|||
bool operator==(const FramebufferCacheKey& rhs) const; |
|||
|
|||
bool operator!=(const FramebufferCacheKey& rhs) const { |
|||
return !operator==(rhs); |
|||
} |
|||
}; |
|||
|
|||
} // namespace OpenGL |
|||
|
|||
namespace std { |
|||
|
|||
template <> |
|||
struct hash<OpenGL::FramebufferCacheKey> { |
|||
std::size_t operator()(const OpenGL::FramebufferCacheKey& k) const noexcept { |
|||
return k.Hash(); |
|||
} |
|||
}; |
|||
|
|||
} // namespace std |
|||
|
|||
namespace OpenGL { |
|||
|
|||
class FramebufferCacheOpenGL { |
|||
public: |
|||
FramebufferCacheOpenGL(); |
|||
~FramebufferCacheOpenGL(); |
|||
|
|||
GLuint GetFramebuffer(const FramebufferCacheKey& key); |
|||
|
|||
private: |
|||
OGLFramebuffer CreateFramebuffer(const FramebufferCacheKey& key); |
|||
|
|||
OpenGLState local_state; |
|||
std::unordered_map<FramebufferCacheKey, OGLFramebuffer> cache; |
|||
}; |
|||
|
|||
} // namespace OpenGL |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue