From 41b4674458595d3d5cd938c06ce651b6d80d305c Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Sat, 11 May 2019 00:17:47 -0400 Subject: [PATCH] gl_texture_cache: Make main views be proxy textures instead of a full view. --- .../renderer_opengl/gl_texture_cache.cpp | 28 ++++++++++++------- .../renderer_opengl/gl_texture_cache.h | 8 +++++- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp index 32cb08963..a55097e5f 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.cpp +++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp @@ -228,10 +228,9 @@ CachedSurface::CachedSurface(const GPUVAddr gpu_addr, const SurfaceParams& param target = GetTextureTarget(params.target); texture = CreateTexture(params, target, internal_format); DecorateSurfaceName(); - main_view = CreateView( - ViewParams(params.target, 0, params.is_layered ? params.depth : 1, 0, params.num_levels)); - main_view->DecorateViewName(gpu_addr, - params.TargetName() + "V:" + std::to_string(view_count++)); + main_view = CreateViewInner( + ViewParams(params.target, 0, params.is_layered ? params.depth : 1, 0, params.num_levels), + true); } CachedSurface::~CachedSurface() { @@ -351,16 +350,24 @@ void CachedSurfaceView::DecorateViewName(GPUVAddr gpu_addr, std::string prefix) } View CachedSurface::CreateView(const ViewParams& view_key) { - auto view = std::make_shared(*this, view_key); + return CreateViewInner(view_key, false); +} + +View CachedSurface::CreateViewInner(const ViewParams& view_key, const bool is_proxy) { + auto view = std::make_shared(*this, view_key, is_proxy); views[view_key] = view; - view->DecorateViewName(gpu_addr, params.TargetName() + "V:" + std::to_string(view_count++)); + if (!is_proxy) + view->DecorateViewName(gpu_addr, params.TargetName() + "V:" + std::to_string(view_count++)); return view; } -CachedSurfaceView::CachedSurfaceView(CachedSurface& surface, const ViewParams& params) - : VideoCommon::ViewBase(params), surface{surface} { +CachedSurfaceView::CachedSurfaceView(CachedSurface& surface, const ViewParams& params, + const bool is_proxy) + : VideoCommon::ViewBase(params), surface{surface}, is_proxy{is_proxy} { target = GetTextureTarget(params.target); - texture_view = CreateTextureView(); + if (!is_proxy) { + texture_view = CreateTextureView(); + } swizzle = EncodeSwizzle(SwizzleSource::R, SwizzleSource::G, SwizzleSource::B, SwizzleSource::A); } @@ -401,7 +408,8 @@ void CachedSurfaceView::ApplySwizzle(SwizzleSource x_source, SwizzleSource y_sou const std::array gl_swizzle = {GetSwizzleSource(x_source), GetSwizzleSource(y_source), GetSwizzleSource(z_source), GetSwizzleSource(w_source)}; - glTextureParameteriv(texture_view.handle, GL_TEXTURE_SWIZZLE_RGBA, gl_swizzle.data()); + const GLuint handle = GetTexture(); + glTextureParameteriv(handle, GL_TEXTURE_SWIZZLE_RGBA, gl_swizzle.data()); } OGLTextureView CachedSurfaceView::CreateTextureView() const { diff --git a/src/video_core/renderer_opengl/gl_texture_cache.h b/src/video_core/renderer_opengl/gl_texture_cache.h index 0a1b57014..0ba42dbab 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.h +++ b/src/video_core/renderer_opengl/gl_texture_cache.h @@ -51,6 +51,7 @@ protected: void DecorateSurfaceName(); View CreateView(const ViewParams& view_key) override; + View CreateViewInner(const ViewParams& view_key, const bool is_proxy); private: void UploadTextureMipmap(u32 level, std::vector& staging_buffer); @@ -67,13 +68,17 @@ private: class CachedSurfaceView final : public VideoCommon::ViewBase { public: - explicit CachedSurfaceView(CachedSurface& surface, const ViewParams& params); + explicit CachedSurfaceView(CachedSurface& surface, const ViewParams& params, + const bool is_proxy); ~CachedSurfaceView(); /// Attaches this texture view to the current bound GL_DRAW_FRAMEBUFFER void Attach(GLenum attachment) const; GLuint GetTexture() { + if (is_proxy) { + return surface.GetTexture(); + } return texture_view.handle; } @@ -119,6 +124,7 @@ private: OGLTextureView texture_view; u32 swizzle; + bool is_proxy; }; class TextureCacheOpenGL final : public TextureCacheBase {