From 557c4669945fa7a30d3c6af25ce383d507232a7e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 8 Aug 2018 23:14:54 -0400 Subject: [PATCH 1/3] gl_rasterizer_cache: Make pointer const in LoadGLBuffer() This is only ever read from, so we can make the data it's pointing to const. --- src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index 257aa95714..ecc84293e1 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp @@ -447,7 +447,7 @@ MICROPROFILE_DEFINE(OpenGL_SurfaceLoad, "OpenGL", "Surface Load", MP_RGB(128, 64 void CachedSurface::LoadGLBuffer() { ASSERT(params.type != SurfaceType::Fill); - u8* const texture_src_data = Memory::GetPointer(params.GetCpuAddr()); + const u8* const texture_src_data = Memory::GetPointer(params.GetCpuAddr()); ASSERT(texture_src_data); From 434f352eb37fba2a5c80bead61a8c5593785730d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 8 Aug 2018 23:28:01 -0400 Subject: [PATCH 2/3] gl_rasterizer_cache: Use std::vector::assign in LoadGLBuffer() for the non-tiled case resize() causes the vector to expand and zero out the added members to the vector, however we can avoid this zeroing by using assign(). Given we have the pointer to the data we want to copy, we can calculate the end pointer and directly copy the range of data without the need to perform the resize() beforehand. --- src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index ecc84293e1..9efb5cea4b 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp @@ -451,16 +451,18 @@ void CachedSurface::LoadGLBuffer() { ASSERT(texture_src_data); - gl_buffer.resize(params.width * params.height * GetGLBytesPerPixel(params.pixel_format)); + const u32 bytes_per_pixel = GetGLBytesPerPixel(params.pixel_format); + const u32 copy_size = params.width * params.height * bytes_per_pixel; MICROPROFILE_SCOPE(OpenGL_SurfaceLoad); if (!params.is_tiled) { - const u32 bytes_per_pixel{params.GetFormatBpp() >> 3}; + const u8* const texture_src_data_end = texture_src_data + copy_size; - std::memcpy(gl_buffer.data(), texture_src_data, - bytes_per_pixel * params.width * params.height); + gl_buffer.assign(texture_src_data, texture_src_data_end); } else { + gl_buffer.resize(copy_size); + morton_to_gl_fns[static_cast(params.pixel_format)]( params.width, params.block_height, params.height, gl_buffer.data(), params.addr); } From e831b80d699b5912597c572f197a879bcdfab45a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 8 Aug 2018 23:30:53 -0400 Subject: [PATCH 3/3] gl_rasterizer_cache: Invert conditional in LoadGLBuffer() It's generally easier to follow code using conditionals that operate in terms of the true case followed by the false case (no chance of overlooking the exclamation mark). --- src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index 9efb5cea4b..9b202e5c38 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp @@ -456,15 +456,15 @@ void CachedSurface::LoadGLBuffer() { MICROPROFILE_SCOPE(OpenGL_SurfaceLoad); - if (!params.is_tiled) { - const u8* const texture_src_data_end = texture_src_data + copy_size; - - gl_buffer.assign(texture_src_data, texture_src_data_end); - } else { + if (params.is_tiled) { gl_buffer.resize(copy_size); morton_to_gl_fns[static_cast(params.pixel_format)]( params.width, params.block_height, params.height, gl_buffer.data(), params.addr); + } else { + const u8* const texture_src_data_end = texture_src_data + copy_size; + + gl_buffer.assign(texture_src_data, texture_src_data_end); } ConvertFormatAsNeeded_LoadGLBuffer(gl_buffer, params.pixel_format, params.width, params.height);