From 18d24fbdd00ee2d05cd02c2794d56b396118f9d5 Mon Sep 17 00:00:00 2001
From: Fernando Sahmkow <fsahmkow27@gmail.com>
Date: Tue, 25 Jun 2019 17:40:08 -0400
Subject: [PATCH] gl_texture_cache: Corrections and fixes

---
 .../renderer_opengl/gl_texture_cache.cpp         | 16 ++++++----------
 .../renderer_opengl/gl_texture_cache.h           |  6 +++---
 2 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp
index c5e3b7a947..d539bf07cf 100644
--- a/src/video_core/renderer_opengl/gl_texture_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp
@@ -244,7 +244,6 @@ CachedSurface::~CachedSurface() {
 void CachedSurface::DownloadTexture(std::vector<u8>& staging_buffer) {
     MICROPROFILE_SCOPE(OpenGL_Texture_Download);
 
-    // TODO(Rodrigo): Optimize alignment
     SCOPE_EXIT({ glPixelStorei(GL_PACK_ROW_LENGTH, 0); });
 
     for (u32 level = 0; level < params.emulated_levels; ++level) {
@@ -272,7 +271,6 @@ void CachedSurface::UploadTexture(std::vector<u8>& staging_buffer) {
 }
 
 void CachedSurface::UploadTextureMipmap(u32 level, std::vector<u8>& staging_buffer) {
-    // TODO(Rodrigo): Optimize alignment
     glPixelStorei(GL_UNPACK_ALIGNMENT, std::min(8U, params.GetRowAlignment(level)));
     glPixelStorei(GL_UNPACK_ROW_LENGTH, static_cast<GLint>(params.GetMipWidth(level)));
 
@@ -421,10 +419,10 @@ void CachedSurfaceView::ApplySwizzle(SwizzleSource x_source, SwizzleSource y_sou
 
 OGLTextureView CachedSurfaceView::CreateTextureView() const {
     const auto& owner_params = surface.GetSurfaceParams();
-    OGLTextureView tv;
-    tv.Create();
+    OGLTextureView texture_view;
+    texture_view.Create();
 
-    const GLuint handle{tv.handle};
+    const GLuint handle{texture_view.handle};
     const FormatTuple& tuple{
         GetFormatTuple(owner_params.pixel_format, owner_params.component_type)};
 
@@ -433,7 +431,7 @@ OGLTextureView CachedSurfaceView::CreateTextureView() const {
 
     ApplyTextureDefaults(owner_params, handle);
 
-    return tv;
+    return texture_view;
 }
 
 TextureCacheOpenGL::TextureCacheOpenGL(Core::System& system,
@@ -529,6 +527,7 @@ void TextureCacheOpenGL::ImageBlit(View& src_view, View& dst_view,
 void TextureCacheOpenGL::BufferCopy(Surface& src_surface, Surface& dst_surface) {
     const auto& src_params = src_surface->GetSurfaceParams();
     const auto& dst_params = dst_surface->GetSurfaceParams();
+    UNIMPLEMENTED_IF(src_params.num_levels > 1 || dst_params.num_levels > 1);
 
     const auto source_format = GetFormatTuple(src_params.pixel_format, src_params.component_type);
     const auto dest_format = GetFormatTuple(dst_params.pixel_format, dst_params.component_type);
@@ -591,10 +590,7 @@ void TextureCacheOpenGL::BufferCopy(Surface& src_surface, Surface& dst_surface)
 }
 
 GLuint TextureCacheOpenGL::FetchPBO(std::size_t buffer_size) {
-    if (buffer_size < 0) {
-        UNREACHABLE();
-        return 0;
-    }
+    ASSERT_OR_EXECUTE(buffer_size <= 0, { return 0; });
     const u32 l2 = Common::Log2Ceil64(static_cast<u64>(buffer_size));
     OGLBuffer& cp = copy_pbo_cache[l2];
     if (cp.handle == 0) {
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.h b/src/video_core/renderer_opengl/gl_texture_cache.h
index cdc44a60c6..8da81dba3a 100644
--- a/src/video_core/renderer_opengl/gl_texture_cache.h
+++ b/src/video_core/renderer_opengl/gl_texture_cache.h
@@ -90,17 +90,17 @@ public:
     }
 
     u32 GetWidth() const {
-        const auto owner_params = GetSurfaceParams();
+        const auto& owner_params = GetSurfaceParams();
         return owner_params.GetMipWidth(params.base_level);
     }
 
     u32 GetHeight() const {
-        const auto owner_params = GetSurfaceParams();
+        const auto& owner_params = GetSurfaceParams();
         return owner_params.GetMipHeight(params.base_level);
     }
 
     u32 GetDepth() const {
-        const auto owner_params = GetSurfaceParams();
+        const auto& owner_params = GetSurfaceParams();
         return owner_params.GetMipDepth(params.base_level);
     }