gl_texture_cache: Attach surface textures instead of views
This commit is contained in:
parent
fb94871791
commit
84139586c9
@ -83,10 +83,10 @@ struct FramebufferCacheKey {
|
|||||||
bool stencil_enable = false;
|
bool stencil_enable = false;
|
||||||
|
|
||||||
std::array<GLenum, Maxwell::NumRenderTargets> color_attachments{};
|
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;
|
u32 colors_count = 0;
|
||||||
|
|
||||||
GLuint zeta = 0;
|
CachedSurfaceView* zeta = nullptr;
|
||||||
|
|
||||||
auto Tie() const {
|
auto Tie() const {
|
||||||
return std::tie(is_single_buffer, stencil_enable, color_attachments, colors, colors_count,
|
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.is_single_buffer) {
|
||||||
if (fbkey.color_attachments[0] != GL_NONE) {
|
if (fbkey.color_attachments[0] != GL_NONE) {
|
||||||
glFramebufferTexture(GL_DRAW_FRAMEBUFFER, fbkey.color_attachments[0], fbkey.colors[0],
|
fbkey.colors[0]->Attach(fbkey.color_attachments[0]);
|
||||||
0);
|
|
||||||
}
|
}
|
||||||
glDrawBuffer(fbkey.color_attachments[0]);
|
glDrawBuffer(fbkey.color_attachments[0]);
|
||||||
} else {
|
} else {
|
||||||
for (std::size_t index = 0; index < Maxwell::NumRenderTargets; ++index) {
|
for (std::size_t index = 0; index < Maxwell::NumRenderTargets; ++index) {
|
||||||
if (fbkey.colors[index]) {
|
if (fbkey.colors[index]) {
|
||||||
glFramebufferTexture(GL_DRAW_FRAMEBUFFER,
|
fbkey.colors[index]->Attach(GL_COLOR_ATTACHMENT0 + static_cast<GLenum>(index));
|
||||||
GL_COLOR_ATTACHMENT0 + static_cast<GLenum>(index),
|
|
||||||
fbkey.colors[index], 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glDrawBuffers(fbkey.colors_count, fbkey.color_attachments.data());
|
glDrawBuffers(fbkey.colors_count, fbkey.color_attachments.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fbkey.zeta) {
|
if (fbkey.zeta) {
|
||||||
GLenum zeta_attachment =
|
fbkey.zeta->Attach(fbkey.stencil_enable ? GL_DEPTH_STENCIL_ATTACHMENT
|
||||||
fbkey.stencil_enable ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT;
|
: GL_DEPTH_ATTACHMENT);
|
||||||
glFramebufferTexture(GL_DRAW_FRAMEBUFFER, zeta_attachment, fbkey.zeta, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -509,7 +505,7 @@ std::pair<bool, bool> RasterizerOpenGL::ConfigureFramebuffers(
|
|||||||
fbkey.is_single_buffer = true;
|
fbkey.is_single_buffer = true;
|
||||||
fbkey.color_attachments[0] =
|
fbkey.color_attachments[0] =
|
||||||
GL_COLOR_ATTACHMENT0 + static_cast<GLenum>(*single_color_target);
|
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 {
|
} else {
|
||||||
// Multiple color attachments are enabled
|
// Multiple color attachments are enabled
|
||||||
for (std::size_t index = 0; index < Maxwell::NumRenderTargets; ++index) {
|
for (std::size_t index = 0; index < Maxwell::NumRenderTargets; ++index) {
|
||||||
@ -529,7 +525,7 @@ std::pair<bool, bool> RasterizerOpenGL::ConfigureFramebuffers(
|
|||||||
|
|
||||||
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] = color_surface != nullptr ? color_surface->GetTexture() : 0;
|
fbkey.colors[index] = color_surface;
|
||||||
}
|
}
|
||||||
fbkey.is_single_buffer = false;
|
fbkey.is_single_buffer = false;
|
||||||
fbkey.colors_count = regs.rt_control.count;
|
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.
|
// the shader doesn't actually write to it.
|
||||||
depth_surface->MarkAsModified(true);
|
depth_surface->MarkAsModified(true);
|
||||||
|
|
||||||
fbkey.zeta = depth_surface->GetTexture();
|
fbkey.zeta = depth_surface;
|
||||||
fbkey.stencil_enable = regs.stencil_enable && depth_surface->GetSurfaceParams().GetType() ==
|
fbkey.stencil_enable = regs.stencil_enable && depth_surface->GetSurfaceParams().GetType() ==
|
||||||
SurfaceType::DepthStencil;
|
SurfaceType::DepthStencil;
|
||||||
}
|
}
|
||||||
|
@ -428,13 +428,28 @@ CachedSurfaceView::CachedSurfaceView(CachedSurface& surface, ViewKey key)
|
|||||||
|
|
||||||
CachedSurfaceView::~CachedSurfaceView() = default;
|
CachedSurfaceView::~CachedSurfaceView() = default;
|
||||||
|
|
||||||
GLuint CachedSurfaceView::GetTexture() {
|
void CachedSurfaceView::Attach(GLenum attachment) const {
|
||||||
// TODO(Rodrigo): Remove this entry and attach the super texture to the framebuffer through
|
ASSERT(key.num_layers == 1 && key.num_levels == 1);
|
||||||
// legacy API (also dropping Intel driver issues).
|
|
||||||
if (texture_view_2d.texture.handle == 0) {
|
switch (params.GetTarget()) {
|
||||||
texture_view_2d = CreateTextureView(GL_TEXTURE_2D);
|
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,
|
GLuint CachedSurfaceView::GetTexture(Tegra::Shader::TextureType texture_type, bool is_array,
|
||||||
|
@ -73,7 +73,8 @@ public:
|
|||||||
explicit CachedSurfaceView(CachedSurface& surface, ViewKey key);
|
explicit CachedSurfaceView(CachedSurface& surface, ViewKey key);
|
||||||
~CachedSurfaceView();
|
~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,
|
GLuint GetTexture(Tegra::Shader::TextureType texture_type, bool is_array,
|
||||||
Tegra::Texture::SwizzleSource x_source,
|
Tegra::Texture::SwizzleSource x_source,
|
||||||
|
Loading…
Reference in New Issue
Block a user