diff options
| author | 2021-09-21 20:28:22 -0400 | |
|---|---|---|
| committer | 2021-11-16 22:11:30 +0100 | |
| commit | 8183142cd4c70355e6275eaba3d2939211b4b9c9 (patch) | |
| tree | 16c370b346e5934ee957f90def3b691b54aefa17 /src | |
| parent | vk_rasterizer: Fix scaling on Y_NEGATE (diff) | |
| download | yuzu-8183142cd4c70355e6275eaba3d2939211b4b9c9.tar.gz yuzu-8183142cd4c70355e6275eaba3d2939211b4b9c9.tar.xz yuzu-8183142cd4c70355e6275eaba3d2939211b4b9c9.zip | |
gl_texture_cache: Fix scaling backup logic
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_texture_cache.cpp | 33 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_texture_cache.h | 3 |
2 files changed, 16 insertions, 20 deletions
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp index c75386e37..7ded7415d 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.cpp +++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp | |||
| @@ -681,6 +681,7 @@ Image::Image(TextureCacheRuntime& runtime_, const VideoCommon::ImageInfo& info_, | |||
| 681 | gl_type = tuple.type; | 681 | gl_type = tuple.type; |
| 682 | } | 682 | } |
| 683 | texture = MakeImage(info, gl_internal_format); | 683 | texture = MakeImage(info, gl_internal_format); |
| 684 | original_backup = texture.handle; | ||
| 684 | if (runtime->device.HasDebuggingToolAttached()) { | 685 | if (runtime->device.HasDebuggingToolAttached()) { |
| 685 | const std::string name = VideoCommon::Name(*this); | 686 | const std::string name = VideoCommon::Name(*this); |
| 686 | glObjectLabel(ImageTarget(info) == GL_TEXTURE_BUFFER ? GL_BUFFER : GL_TEXTURE, | 687 | glObjectLabel(ImageTarget(info) == GL_TEXTURE_BUFFER ? GL_BUFFER : GL_TEXTURE, |
| @@ -697,7 +698,6 @@ void Image::UploadMemory(const ImageBufferMap& map, | |||
| 697 | const bool is_rescaled = True(flags & ImageFlagBits::Rescaled); | 698 | const bool is_rescaled = True(flags & ImageFlagBits::Rescaled); |
| 698 | if (is_rescaled) { | 699 | if (is_rescaled) { |
| 699 | ScaleDown(); | 700 | ScaleDown(); |
| 700 | scale_backup.Release(); | ||
| 701 | } | 701 | } |
| 702 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, map.buffer); | 702 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, map.buffer); |
| 703 | glFlushMappedBufferRange(GL_PIXEL_UNPACK_BUFFER, map.offset, unswizzled_size_bytes); | 703 | glFlushMappedBufferRange(GL_PIXEL_UNPACK_BUFFER, map.offset, unswizzled_size_bytes); |
| @@ -729,7 +729,6 @@ void Image::DownloadMemory(ImageBufferMap& map, | |||
| 729 | const bool is_rescaled = True(flags & ImageFlagBits::Rescaled); | 729 | const bool is_rescaled = True(flags & ImageFlagBits::Rescaled); |
| 730 | if (is_rescaled) { | 730 | if (is_rescaled) { |
| 731 | ScaleDown(); | 731 | ScaleDown(); |
| 732 | scale_backup.Release(); | ||
| 733 | } | 732 | } |
| 734 | glBindBuffer(GL_PIXEL_PACK_BUFFER, map.buffer); | 733 | glBindBuffer(GL_PIXEL_PACK_BUFFER, map.buffer); |
| 735 | glPixelStorei(GL_PACK_ALIGNMENT, 1); | 734 | glPixelStorei(GL_PACK_ALIGNMENT, 1); |
| @@ -749,7 +748,7 @@ void Image::DownloadMemory(ImageBufferMap& map, | |||
| 749 | CopyImageToBuffer(copy, map.offset); | 748 | CopyImageToBuffer(copy, map.offset); |
| 750 | } | 749 | } |
| 751 | if (is_rescaled) { | 750 | if (is_rescaled) { |
| 752 | ScaleUp(); | 751 | texture.handle = upscaled_backup.handle; |
| 753 | } | 752 | } |
| 754 | } | 753 | } |
| 755 | 754 | ||
| @@ -885,11 +884,6 @@ void Image::CopyImageToBuffer(const VideoCommon::BufferImageCopy& copy, size_t b | |||
| 885 | } | 884 | } |
| 886 | 885 | ||
| 887 | bool Image::Scale() { | 886 | bool Image::Scale() { |
| 888 | if (scale_backup.handle) { | ||
| 889 | // This was a texture which was scaled previously, no need to repeat scaling | ||
| 890 | std::swap(texture, scale_backup); | ||
| 891 | return true; | ||
| 892 | } | ||
| 893 | const auto format_type = GetFormatType(info.format); | 887 | const auto format_type = GetFormatType(info.format); |
| 894 | const GLenum attachment = [format_type] { | 888 | const GLenum attachment = [format_type] { |
| 895 | switch (format_type) { | 889 | switch (format_type) { |
| @@ -949,8 +943,9 @@ bool Image::Scale() { | |||
| 949 | auto dst_info = info; | 943 | auto dst_info = info; |
| 950 | dst_info.size.width = scaled_width; | 944 | dst_info.size.width = scaled_width; |
| 951 | dst_info.size.height = scaled_height; | 945 | dst_info.size.height = scaled_height; |
| 952 | scale_backup = MakeImage(dst_info, gl_internal_format); | 946 | if (!upscaled_backup.handle) { |
| 953 | 947 | upscaled_backup = MakeImage(dst_info, gl_internal_format); | |
| 948 | } | ||
| 954 | const GLuint read_fbo = runtime->rescale_read_fbos[fbo_index].handle; | 949 | const GLuint read_fbo = runtime->rescale_read_fbos[fbo_index].handle; |
| 955 | const GLuint draw_fbo = runtime->rescale_draw_fbos[fbo_index].handle; | 950 | const GLuint draw_fbo = runtime->rescale_draw_fbos[fbo_index].handle; |
| 956 | for (s32 layer = 0; layer < info.resources.layers; ++layer) { | 951 | for (s32 layer = 0; layer < info.resources.layers; ++layer) { |
| @@ -960,13 +955,14 @@ bool Image::Scale() { | |||
| 960 | const u32 dst_level_width = std::max(1u, scaled_width >> level); | 955 | const u32 dst_level_width = std::max(1u, scaled_width >> level); |
| 961 | const u32 dst_level_height = std::max(1u, scaled_height >> level); | 956 | const u32 dst_level_height = std::max(1u, scaled_height >> level); |
| 962 | 957 | ||
| 963 | glNamedFramebufferTextureLayer(read_fbo, attachment, texture.handle, level, layer); | 958 | glNamedFramebufferTextureLayer(read_fbo, attachment, original_backup, level, layer); |
| 964 | glNamedFramebufferTextureLayer(draw_fbo, attachment, scale_backup.handle, level, layer); | 959 | glNamedFramebufferTextureLayer(draw_fbo, attachment, upscaled_backup.handle, level, |
| 960 | layer); | ||
| 965 | glBlitNamedFramebuffer(read_fbo, draw_fbo, 0, 0, src_level_width, src_level_height, 0, | 961 | glBlitNamedFramebuffer(read_fbo, draw_fbo, 0, 0, src_level_width, src_level_height, 0, |
| 966 | 0, dst_level_width, dst_level_height, mask, filter); | 962 | 0, dst_level_width, dst_level_height, mask, filter); |
| 967 | } | 963 | } |
| 968 | } | 964 | } |
| 969 | std::swap(texture, scale_backup); | 965 | texture.handle = upscaled_backup.handle; |
| 970 | return true; | 966 | return true; |
| 971 | } | 967 | } |
| 972 | 968 | ||
| @@ -985,20 +981,19 @@ bool Image::ScaleUp() { | |||
| 985 | UNIMPLEMENTED(); | 981 | UNIMPLEMENTED(); |
| 986 | return false; | 982 | return false; |
| 987 | } | 983 | } |
| 984 | if (!Scale()) { | ||
| 985 | return false; | ||
| 986 | } | ||
| 988 | flags |= ImageFlagBits::Rescaled; | 987 | flags |= ImageFlagBits::Rescaled; |
| 989 | return Scale(); | 988 | return true; |
| 990 | } | 989 | } |
| 991 | 990 | ||
| 992 | bool Image::ScaleDown() { | 991 | bool Image::ScaleDown() { |
| 993 | if (False(flags & ImageFlagBits::Rescaled)) { | 992 | if (False(flags & ImageFlagBits::Rescaled)) { |
| 994 | return false; | 993 | return false; |
| 995 | } | 994 | } |
| 996 | if (!scale_backup.handle) { | ||
| 997 | LOG_ERROR(Render_OpenGL, "Downscaling an upscaled texture that didn't backup original"); | ||
| 998 | return false; | ||
| 999 | } | ||
| 1000 | flags &= ~ImageFlagBits::Rescaled; | 995 | flags &= ~ImageFlagBits::Rescaled; |
| 1001 | std::swap(texture, scale_backup); | 996 | texture.handle = original_backup; |
| 1002 | return true; | 997 | return true; |
| 1003 | } | 998 | } |
| 1004 | 999 | ||
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.h b/src/video_core/renderer_opengl/gl_texture_cache.h index 79448f670..61f9b0259 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.h +++ b/src/video_core/renderer_opengl/gl_texture_cache.h | |||
| @@ -205,12 +205,13 @@ private: | |||
| 205 | bool Scale(); | 205 | bool Scale(); |
| 206 | 206 | ||
| 207 | OGLTexture texture; | 207 | OGLTexture texture; |
| 208 | OGLTexture scale_backup; | 208 | OGLTexture upscaled_backup; |
| 209 | OGLTextureView store_view; | 209 | OGLTextureView store_view; |
| 210 | GLenum gl_internal_format = GL_NONE; | 210 | GLenum gl_internal_format = GL_NONE; |
| 211 | GLenum gl_format = GL_NONE; | 211 | GLenum gl_format = GL_NONE; |
| 212 | GLenum gl_type = GL_NONE; | 212 | GLenum gl_type = GL_NONE; |
| 213 | TextureCacheRuntime* runtime{}; | 213 | TextureCacheRuntime* runtime{}; |
| 214 | GLuint original_backup{}; | ||
| 214 | }; | 215 | }; |
| 215 | 216 | ||
| 216 | class ImageView : public VideoCommon::ImageViewBase { | 217 | class ImageView : public VideoCommon::ImageViewBase { |