2
1
Fork 0
mirror of https://github.com/yuzu-emu/yuzu.git synced 2024-07-04 23:31:19 +01:00

gl_texture_cache: Attach surface textures instead of views

This commit is contained in:
ReinUsesLisp 2019-04-14 18:16:27 -03:00
parent fb94871791
commit 84139586c9
3 changed files with 32 additions and 20 deletions

View file

@ -83,10 +83,10 @@ struct FramebufferCacheKey {
bool stencil_enable = false;
std::array<GLenum, Maxwell::NumRenderTargets> color_attachments{};
std::array<GLuint, Tegra::Engines::Maxwell3D::Regs::NumRenderTargets> colors{};
std::array<CachedSurfaceView*, Tegra::Engines::Maxwell3D::Regs::NumRenderTargets> colors{};
u32 colors_count = 0;
GLuint zeta = 0;
CachedSurfaceView* zeta = nullptr;
auto Tie() const {
return std::tie(is_single_buffer, stencil_enable, color_attachments, colors, colors_count,
@ -367,25 +367,21 @@ void RasterizerOpenGL::SetupCachedFramebuffer(const FramebufferCacheKey& fbkey,
if (fbkey.is_single_buffer) {
if (fbkey.color_attachments[0] != GL_NONE) {
glFramebufferTexture(GL_DRAW_FRAMEBUFFER, fbkey.color_attachments[0], fbkey.colors[0],
0);
fbkey.colors[0]->Attach(fbkey.color_attachments[0]);
}
glDrawBuffer(fbkey.color_attachments[0]);
} else {
for (std::size_t index = 0; index < Maxwell::NumRenderTargets; ++index) {
if (fbkey.colors[index]) {
glFramebufferTexture(GL_DRAW_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0 + static_cast<GLenum>(index),
fbkey.colors[index], 0);
fbkey.colors[index]->Attach(GL_COLOR_ATTACHMENT0 + static_cast<GLenum>(index));
}
}
glDrawBuffers(fbkey.colors_count, fbkey.color_attachments.data());
}
if (fbkey.zeta) {
GLenum zeta_attachment =
fbkey.stencil_enable ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT;
glFramebufferTexture(GL_DRAW_FRAMEBUFFER, zeta_attachment, fbkey.zeta, 0);
fbkey.zeta->Attach(fbkey.stencil_enable ? GL_DEPTH_STENCIL_ATTACHMENT
: GL_DEPTH_ATTACHMENT);
}
}
@ -509,7 +505,7 @@ std::pair<bool, bool> RasterizerOpenGL::ConfigureFramebuffers(
fbkey.is_single_buffer = true;
fbkey.color_attachments[0] =
GL_COLOR_ATTACHMENT0 + static_cast<GLenum>(*single_color_target);
fbkey.colors[0] = color_surface != nullptr ? color_surface->GetTexture() : 0;
fbkey.colors[0] = color_surface;
} else {
// Multiple color attachments are enabled
for (std::size_t index = 0; index < Maxwell::NumRenderTargets; ++index) {
@ -529,7 +525,7 @@ std::pair<bool, bool> RasterizerOpenGL::ConfigureFramebuffers(
fbkey.color_attachments[index] =
GL_COLOR_ATTACHMENT0 + regs.rt_control.GetMap(index);
fbkey.colors[index] = color_surface != nullptr ? color_surface->GetTexture() : 0;
fbkey.colors[index] = color_surface;
}
fbkey.is_single_buffer = false;
fbkey.colors_count = regs.rt_control.count;
@ -544,7 +540,7 @@ std::pair<bool, bool> RasterizerOpenGL::ConfigureFramebuffers(
// the shader doesn't actually write to it.
depth_surface->MarkAsModified(true);
fbkey.zeta = depth_surface->GetTexture();
fbkey.zeta = depth_surface;
fbkey.stencil_enable = regs.stencil_enable && depth_surface->GetSurfaceParams().GetType() ==
SurfaceType::DepthStencil;
}

View file

@ -428,13 +428,28 @@ CachedSurfaceView::CachedSurfaceView(CachedSurface& surface, ViewKey key)
CachedSurfaceView::~CachedSurfaceView() = default;
GLuint CachedSurfaceView::GetTexture() {
// TODO(Rodrigo): Remove this entry and attach the super texture to the framebuffer through
// legacy API (also dropping Intel driver issues).
if (texture_view_2d.texture.handle == 0) {
texture_view_2d = CreateTextureView(GL_TEXTURE_2D);
void CachedSurfaceView::Attach(GLenum attachment) const {
ASSERT(key.num_layers == 1 && key.num_levels == 1);
switch (params.GetTarget()) {
case SurfaceTarget::Texture1D:
glFramebufferTexture1D(GL_DRAW_FRAMEBUFFER, attachment, surface.GetTarget(),
surface.GetTexture(), key.base_level);
break;
case SurfaceTarget::Texture2D:
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, attachment, surface.GetTarget(),
surface.GetTexture(), key.base_level);
break;
case SurfaceTarget::Texture1DArray:
case SurfaceTarget::Texture2DArray:
case SurfaceTarget::TextureCubemap:
case SurfaceTarget::TextureCubeArray:
glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, attachment, surface.GetTexture(),
key.base_level, key.base_layer);
break;
default:
UNIMPLEMENTED();
}
return texture_view_2d.texture.handle;
}
GLuint CachedSurfaceView::GetTexture(Tegra::Shader::TextureType texture_type, bool is_array,

View file

@ -73,7 +73,8 @@ public:
explicit CachedSurfaceView(CachedSurface& surface, ViewKey key);
~CachedSurfaceView();
GLuint GetTexture();
/// Attaches this texture view to the current bound GL_DRAW_FRAMEBUFFER
void Attach(GLenum attachment) const;
GLuint GetTexture(Tegra::Shader::TextureType texture_type, bool is_array,
Tegra::Texture::SwizzleSource x_source,