summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar bunnei2021-11-19 15:56:27 -0800
committerGravatar GitHub2021-11-19 15:56:27 -0800
commitc3e1ffc44b6a6c3929e8ac6eb527fe450cfc5268 (patch)
tree044f08c48ec328b1ea2c32041d12b8b3e596c6f6
parentMerge pull request #7369 from Morph1984/amd-fsr-statusbar (diff)
parentFix image update/download error when width too small (diff)
downloadyuzu-c3e1ffc44b6a6c3929e8ac6eb527fe450cfc5268.tar.gz
yuzu-c3e1ffc44b6a6c3929e8ac6eb527fe450cfc5268.tar.xz
yuzu-c3e1ffc44b6a6c3929e8ac6eb527fe450cfc5268.zip
Merge pull request #7294 from vonchenplus/fix_image_update_error_when_width_too_small
Fix image update/download error when width too small
-rw-r--r--src/video_core/renderer_opengl/gl_texture_cache.cpp27
-rw-r--r--src/video_core/renderer_opengl/gl_texture_cache.h1
2 files changed, 18 insertions, 10 deletions
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp
index 9e7850428..3dbdcc2c4 100644
--- a/src/video_core/renderer_opengl/gl_texture_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp
@@ -319,13 +319,12 @@ void AttachTexture(GLuint fbo, GLenum attachment, const ImageView* image_view) {
319 } 319 }
320} 320}
321 321
322OGLTexture MakeImage(const VideoCommon::ImageInfo& info, GLenum gl_internal_format) { 322OGLTexture MakeImage(const VideoCommon::ImageInfo& info, GLenum gl_internal_format,
323 GLsizei gl_num_levels) {
323 const GLenum target = ImageTarget(info); 324 const GLenum target = ImageTarget(info);
324 const GLsizei width = info.size.width; 325 const GLsizei width = info.size.width;
325 const GLsizei height = info.size.height; 326 const GLsizei height = info.size.height;
326 const GLsizei depth = info.size.depth; 327 const GLsizei depth = info.size.depth;
327 const int max_host_mip_levels = std::bit_width(info.size.width);
328 const GLsizei num_levels = std::min(info.resources.levels, max_host_mip_levels);
329 const GLsizei num_layers = info.resources.layers; 328 const GLsizei num_layers = info.resources.layers;
330 const GLsizei num_samples = info.num_samples; 329 const GLsizei num_samples = info.num_samples;
331 330
@@ -337,10 +336,10 @@ OGLTexture MakeImage(const VideoCommon::ImageInfo& info, GLenum gl_internal_form
337 } 336 }
338 switch (target) { 337 switch (target) {
339 case GL_TEXTURE_1D_ARRAY: 338 case GL_TEXTURE_1D_ARRAY:
340 glTextureStorage2D(handle, num_levels, gl_internal_format, width, num_layers); 339 glTextureStorage2D(handle, gl_num_levels, gl_internal_format, width, num_layers);
341 break; 340 break;
342 case GL_TEXTURE_2D_ARRAY: 341 case GL_TEXTURE_2D_ARRAY:
343 glTextureStorage3D(handle, num_levels, gl_internal_format, width, height, num_layers); 342 glTextureStorage3D(handle, gl_num_levels, gl_internal_format, width, height, num_layers);
344 break; 343 break;
345 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: { 344 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: {
346 // TODO: Where should 'fixedsamplelocations' come from? 345 // TODO: Where should 'fixedsamplelocations' come from?
@@ -350,10 +349,10 @@ OGLTexture MakeImage(const VideoCommon::ImageInfo& info, GLenum gl_internal_form
350 break; 349 break;
351 } 350 }
352 case GL_TEXTURE_RECTANGLE: 351 case GL_TEXTURE_RECTANGLE:
353 glTextureStorage2D(handle, num_levels, gl_internal_format, width, height); 352 glTextureStorage2D(handle, gl_num_levels, gl_internal_format, width, height);
354 break; 353 break;
355 case GL_TEXTURE_3D: 354 case GL_TEXTURE_3D:
356 glTextureStorage3D(handle, num_levels, gl_internal_format, width, height, depth); 355 glTextureStorage3D(handle, gl_num_levels, gl_internal_format, width, height, depth);
357 break; 356 break;
358 case GL_TEXTURE_BUFFER: 357 case GL_TEXTURE_BUFFER:
359 UNREACHABLE(); 358 UNREACHABLE();
@@ -698,7 +697,9 @@ Image::Image(TextureCacheRuntime& runtime_, const VideoCommon::ImageInfo& info_,
698 gl_format = tuple.format; 697 gl_format = tuple.format;
699 gl_type = tuple.type; 698 gl_type = tuple.type;
700 } 699 }
701 texture = MakeImage(info, gl_internal_format); 700 const int max_host_mip_levels = std::bit_width(info.size.width);
701 gl_num_levels = std::min(info.resources.levels, max_host_mip_levels);
702 texture = MakeImage(info, gl_internal_format, gl_num_levels);
702 current_texture = texture.handle; 703 current_texture = texture.handle;
703 if (runtime->device.HasDebuggingToolAttached()) { 704 if (runtime->device.HasDebuggingToolAttached()) {
704 const std::string name = VideoCommon::Name(*this); 705 const std::string name = VideoCommon::Name(*this);
@@ -726,6 +727,9 @@ void Image::UploadMemory(const ImageBufferMap& map,
726 u32 current_image_height = std::numeric_limits<u32>::max(); 727 u32 current_image_height = std::numeric_limits<u32>::max();
727 728
728 for (const VideoCommon::BufferImageCopy& copy : copies) { 729 for (const VideoCommon::BufferImageCopy& copy : copies) {
730 if (copy.image_subresource.base_level >= gl_num_levels) {
731 continue;
732 }
729 if (current_row_length != copy.buffer_row_length) { 733 if (current_row_length != copy.buffer_row_length) {
730 current_row_length = copy.buffer_row_length; 734 current_row_length = copy.buffer_row_length;
731 glPixelStorei(GL_UNPACK_ROW_LENGTH, current_row_length); 735 glPixelStorei(GL_UNPACK_ROW_LENGTH, current_row_length);
@@ -755,6 +759,9 @@ void Image::DownloadMemory(ImageBufferMap& map,
755 u32 current_image_height = std::numeric_limits<u32>::max(); 759 u32 current_image_height = std::numeric_limits<u32>::max();
756 760
757 for (const VideoCommon::BufferImageCopy& copy : copies) { 761 for (const VideoCommon::BufferImageCopy& copy : copies) {
762 if (copy.image_subresource.base_level >= gl_num_levels) {
763 continue;
764 }
758 if (current_row_length != copy.buffer_row_length) { 765 if (current_row_length != copy.buffer_row_length) {
759 current_row_length = copy.buffer_row_length; 766 current_row_length = copy.buffer_row_length;
760 glPixelStorei(GL_PACK_ROW_LENGTH, current_row_length); 767 glPixelStorei(GL_PACK_ROW_LENGTH, current_row_length);
@@ -794,7 +801,7 @@ GLuint Image::StorageHandle() noexcept {
794 } 801 }
795 store_view.Create(); 802 store_view.Create();
796 glTextureView(store_view.handle, ImageTarget(info), current_texture, GL_RGBA8, 0, 803 glTextureView(store_view.handle, ImageTarget(info), current_texture, GL_RGBA8, 0,
797 info.resources.levels, 0, info.resources.layers); 804 gl_num_levels, 0, info.resources.layers);
798 return store_view.handle; 805 return store_view.handle;
799 default: 806 default:
800 return current_texture; 807 return current_texture;
@@ -964,7 +971,7 @@ void Image::Scale(bool up_scale) {
964 auto dst_info = info; 971 auto dst_info = info;
965 dst_info.size.width = scaled_width; 972 dst_info.size.width = scaled_width;
966 dst_info.size.height = scaled_height; 973 dst_info.size.height = scaled_height;
967 upscaled_backup = MakeImage(dst_info, gl_internal_format); 974 upscaled_backup = MakeImage(dst_info, gl_internal_format, gl_num_levels);
968 } 975 }
969 const u32 src_width = up_scale ? original_width : scaled_width; 976 const u32 src_width = up_scale ? original_width : scaled_width;
970 const u32 src_height = up_scale ? original_height : scaled_height; 977 const u32 src_height = up_scale ? original_height : scaled_height;
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.h b/src/video_core/renderer_opengl/gl_texture_cache.h
index 40acc8fad..c0534b1f1 100644
--- a/src/video_core/renderer_opengl/gl_texture_cache.h
+++ b/src/video_core/renderer_opengl/gl_texture_cache.h
@@ -221,6 +221,7 @@ private:
221 GLenum gl_internal_format = GL_NONE; 221 GLenum gl_internal_format = GL_NONE;
222 GLenum gl_format = GL_NONE; 222 GLenum gl_format = GL_NONE;
223 GLenum gl_type = GL_NONE; 223 GLenum gl_type = GL_NONE;
224 GLsizei gl_num_levels{};
224 TextureCacheRuntime* runtime{}; 225 TextureCacheRuntime* runtime{};
225 GLuint current_texture{}; 226 GLuint current_texture{};
226}; 227};