summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorameerj <52414509+ameerj@users.noreply.github.com>2021-09-22 02:28:22 +0200
committerFernando Sahmkow <fsahmkow27@gmail.com>2021-11-16 22:11:30 +0100
commit8183142cd4c70355e6275eaba3d2939211b4b9c9 (patch)
tree16c370b346e5934ee957f90def3b691b54aefa17
parentvk_rasterizer: Fix scaling on Y_NEGATE (diff)
downloadyuzu-8183142cd4c70355e6275eaba3d2939211b4b9c9.tar
yuzu-8183142cd4c70355e6275eaba3d2939211b4b9c9.tar.gz
yuzu-8183142cd4c70355e6275eaba3d2939211b4b9c9.tar.bz2
yuzu-8183142cd4c70355e6275eaba3d2939211b4b9c9.tar.lz
yuzu-8183142cd4c70355e6275eaba3d2939211b4b9c9.tar.xz
yuzu-8183142cd4c70355e6275eaba3d2939211b4b9c9.tar.zst
yuzu-8183142cd4c70355e6275eaba3d2939211b4b9c9.zip
-rw-r--r--src/video_core/renderer_opengl/gl_texture_cache.cpp33
-rw-r--r--src/video_core/renderer_opengl/gl_texture_cache.h3
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_,
gl_type = tuple.type;
}
texture = MakeImage(info, gl_internal_format);
+ original_backup = texture.handle;
if (runtime->device.HasDebuggingToolAttached()) {
const std::string name = VideoCommon::Name(*this);
glObjectLabel(ImageTarget(info) == GL_TEXTURE_BUFFER ? GL_BUFFER : GL_TEXTURE,
@@ -697,7 +698,6 @@ void Image::UploadMemory(const ImageBufferMap& map,
const bool is_rescaled = True(flags & ImageFlagBits::Rescaled);
if (is_rescaled) {
ScaleDown();
- scale_backup.Release();
}
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, map.buffer);
glFlushMappedBufferRange(GL_PIXEL_UNPACK_BUFFER, map.offset, unswizzled_size_bytes);
@@ -729,7 +729,6 @@ void Image::DownloadMemory(ImageBufferMap& map,
const bool is_rescaled = True(flags & ImageFlagBits::Rescaled);
if (is_rescaled) {
ScaleDown();
- scale_backup.Release();
}
glBindBuffer(GL_PIXEL_PACK_BUFFER, map.buffer);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
@@ -749,7 +748,7 @@ void Image::DownloadMemory(ImageBufferMap& map,
CopyImageToBuffer(copy, map.offset);
}
if (is_rescaled) {
- ScaleUp();
+ texture.handle = upscaled_backup.handle;
}
}
@@ -885,11 +884,6 @@ void Image::CopyImageToBuffer(const VideoCommon::BufferImageCopy& copy, size_t b
}
bool Image::Scale() {
- if (scale_backup.handle) {
- // This was a texture which was scaled previously, no need to repeat scaling
- std::swap(texture, scale_backup);
- return true;
- }
const auto format_type = GetFormatType(info.format);
const GLenum attachment = [format_type] {
switch (format_type) {
@@ -949,8 +943,9 @@ bool Image::Scale() {
auto dst_info = info;
dst_info.size.width = scaled_width;
dst_info.size.height = scaled_height;
- scale_backup = MakeImage(dst_info, gl_internal_format);
-
+ if (!upscaled_backup.handle) {
+ upscaled_backup = MakeImage(dst_info, gl_internal_format);
+ }
const GLuint read_fbo = runtime->rescale_read_fbos[fbo_index].handle;
const GLuint draw_fbo = runtime->rescale_draw_fbos[fbo_index].handle;
for (s32 layer = 0; layer < info.resources.layers; ++layer) {
@@ -960,13 +955,14 @@ bool Image::Scale() {
const u32 dst_level_width = std::max(1u, scaled_width >> level);
const u32 dst_level_height = std::max(1u, scaled_height >> level);
- glNamedFramebufferTextureLayer(read_fbo, attachment, texture.handle, level, layer);
- glNamedFramebufferTextureLayer(draw_fbo, attachment, scale_backup.handle, level, layer);
+ glNamedFramebufferTextureLayer(read_fbo, attachment, original_backup, level, layer);
+ glNamedFramebufferTextureLayer(draw_fbo, attachment, upscaled_backup.handle, level,
+ layer);
glBlitNamedFramebuffer(read_fbo, draw_fbo, 0, 0, src_level_width, src_level_height, 0,
0, dst_level_width, dst_level_height, mask, filter);
}
}
- std::swap(texture, scale_backup);
+ texture.handle = upscaled_backup.handle;
return true;
}
@@ -985,20 +981,19 @@ bool Image::ScaleUp() {
UNIMPLEMENTED();
return false;
}
+ if (!Scale()) {
+ return false;
+ }
flags |= ImageFlagBits::Rescaled;
- return Scale();
+ return true;
}
bool Image::ScaleDown() {
if (False(flags & ImageFlagBits::Rescaled)) {
return false;
}
- if (!scale_backup.handle) {
- LOG_ERROR(Render_OpenGL, "Downscaling an upscaled texture that didn't backup original");
- return false;
- }
flags &= ~ImageFlagBits::Rescaled;
- std::swap(texture, scale_backup);
+ texture.handle = original_backup;
return true;
}
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:
bool Scale();
OGLTexture texture;
- OGLTexture scale_backup;
+ OGLTexture upscaled_backup;
OGLTextureView store_view;
GLenum gl_internal_format = GL_NONE;
GLenum gl_format = GL_NONE;
GLenum gl_type = GL_NONE;
TextureCacheRuntime* runtime{};
+ GLuint original_backup{};
};
class ImageView : public VideoCommon::ImageViewBase {