summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Feng Chen2021-11-17 12:21:17 +0800
committerGravatar Feng Chen2021-11-17 12:21:17 +0800
commit894cc9d876a70947aecc7a1a3f9ef869e8088f42 (patch)
tree8982fd10149fcc865097502b4723399af4f3a13e
parentMerge pull request #7219 from FernandoS27/aristotles-right-testicle (diff)
downloadyuzu-894cc9d876a70947aecc7a1a3f9ef869e8088f42.tar.gz
yuzu-894cc9d876a70947aecc7a1a3f9ef869e8088f42.tar.xz
yuzu-894cc9d876a70947aecc7a1a3f9ef869e8088f42.zip
Fix image update/download error when width too small
Diffstat (limited to '')
-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 2f7d98d8b..5cfb6bb8a 100644
--- a/src/video_core/renderer_opengl/gl_texture_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp
@@ -317,13 +317,12 @@ void AttachTexture(GLuint fbo, GLenum attachment, const ImageView* image_view) {
317 } 317 }
318} 318}
319 319
320OGLTexture MakeImage(const VideoCommon::ImageInfo& info, GLenum gl_internal_format) { 320OGLTexture MakeImage(const VideoCommon::ImageInfo& info, GLenum gl_internal_format,
321 GLsizei gl_num_levels) {
321 const GLenum target = ImageTarget(info); 322 const GLenum target = ImageTarget(info);
322 const GLsizei width = info.size.width; 323 const GLsizei width = info.size.width;
323 const GLsizei height = info.size.height; 324 const GLsizei height = info.size.height;
324 const GLsizei depth = info.size.depth; 325 const GLsizei depth = info.size.depth;
325 const int max_host_mip_levels = std::bit_width(info.size.width);
326 const GLsizei num_levels = std::min(info.resources.levels, max_host_mip_levels);
327 const GLsizei num_layers = info.resources.layers; 326 const GLsizei num_layers = info.resources.layers;
328 const GLsizei num_samples = info.num_samples; 327 const GLsizei num_samples = info.num_samples;
329 328
@@ -335,10 +334,10 @@ OGLTexture MakeImage(const VideoCommon::ImageInfo& info, GLenum gl_internal_form
335 } 334 }
336 switch (target) { 335 switch (target) {
337 case GL_TEXTURE_1D_ARRAY: 336 case GL_TEXTURE_1D_ARRAY:
338 glTextureStorage2D(handle, num_levels, gl_internal_format, width, num_layers); 337 glTextureStorage2D(handle, gl_num_levels, gl_internal_format, width, num_layers);
339 break; 338 break;
340 case GL_TEXTURE_2D_ARRAY: 339 case GL_TEXTURE_2D_ARRAY:
341 glTextureStorage3D(handle, num_levels, gl_internal_format, width, height, num_layers); 340 glTextureStorage3D(handle, gl_num_levels, gl_internal_format, width, height, num_layers);
342 break; 341 break;
343 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: { 342 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY: {
344 // TODO: Where should 'fixedsamplelocations' come from? 343 // TODO: Where should 'fixedsamplelocations' come from?
@@ -348,10 +347,10 @@ OGLTexture MakeImage(const VideoCommon::ImageInfo& info, GLenum gl_internal_form
348 break; 347 break;
349 } 348 }
350 case GL_TEXTURE_RECTANGLE: 349 case GL_TEXTURE_RECTANGLE:
351 glTextureStorage2D(handle, num_levels, gl_internal_format, width, height); 350 glTextureStorage2D(handle, gl_num_levels, gl_internal_format, width, height);
352 break; 351 break;
353 case GL_TEXTURE_3D: 352 case GL_TEXTURE_3D:
354 glTextureStorage3D(handle, num_levels, gl_internal_format, width, height, depth); 353 glTextureStorage3D(handle, gl_num_levels, gl_internal_format, width, height, depth);
355 break; 354 break;
356 case GL_TEXTURE_BUFFER: 355 case GL_TEXTURE_BUFFER:
357 UNREACHABLE(); 356 UNREACHABLE();
@@ -686,7 +685,9 @@ Image::Image(TextureCacheRuntime& runtime_, const VideoCommon::ImageInfo& info_,
686 gl_format = tuple.format; 685 gl_format = tuple.format;
687 gl_type = tuple.type; 686 gl_type = tuple.type;
688 } 687 }
689 texture = MakeImage(info, gl_internal_format); 688 const int max_host_mip_levels = std::bit_width(info.size.width);
689 gl_num_levels = std::min(info.resources.levels, max_host_mip_levels);
690 texture = MakeImage(info, gl_internal_format, gl_num_levels);
690 current_texture = texture.handle; 691 current_texture = texture.handle;
691 if (runtime->device.HasDebuggingToolAttached()) { 692 if (runtime->device.HasDebuggingToolAttached()) {
692 const std::string name = VideoCommon::Name(*this); 693 const std::string name = VideoCommon::Name(*this);
@@ -714,6 +715,9 @@ void Image::UploadMemory(const ImageBufferMap& map,
714 u32 current_image_height = std::numeric_limits<u32>::max(); 715 u32 current_image_height = std::numeric_limits<u32>::max();
715 716
716 for (const VideoCommon::BufferImageCopy& copy : copies) { 717 for (const VideoCommon::BufferImageCopy& copy : copies) {
718 if (copy.image_subresource.base_level >= gl_num_levels) {
719 continue;
720 }
717 if (current_row_length != copy.buffer_row_length) { 721 if (current_row_length != copy.buffer_row_length) {
718 current_row_length = copy.buffer_row_length; 722 current_row_length = copy.buffer_row_length;
719 glPixelStorei(GL_UNPACK_ROW_LENGTH, current_row_length); 723 glPixelStorei(GL_UNPACK_ROW_LENGTH, current_row_length);
@@ -743,6 +747,9 @@ void Image::DownloadMemory(ImageBufferMap& map,
743 u32 current_image_height = std::numeric_limits<u32>::max(); 747 u32 current_image_height = std::numeric_limits<u32>::max();
744 748
745 for (const VideoCommon::BufferImageCopy& copy : copies) { 749 for (const VideoCommon::BufferImageCopy& copy : copies) {
750 if (copy.image_subresource.base_level >= gl_num_levels) {
751 continue;
752 }
746 if (current_row_length != copy.buffer_row_length) { 753 if (current_row_length != copy.buffer_row_length) {
747 current_row_length = copy.buffer_row_length; 754 current_row_length = copy.buffer_row_length;
748 glPixelStorei(GL_PACK_ROW_LENGTH, current_row_length); 755 glPixelStorei(GL_PACK_ROW_LENGTH, current_row_length);
@@ -782,7 +789,7 @@ GLuint Image::StorageHandle() noexcept {
782 } 789 }
783 store_view.Create(); 790 store_view.Create();
784 glTextureView(store_view.handle, ImageTarget(info), current_texture, GL_RGBA8, 0, 791 glTextureView(store_view.handle, ImageTarget(info), current_texture, GL_RGBA8, 0,
785 info.resources.levels, 0, info.resources.layers); 792 gl_num_levels, 0, info.resources.layers);
786 return store_view.handle; 793 return store_view.handle;
787 default: 794 default:
788 return current_texture; 795 return current_texture;
@@ -946,7 +953,7 @@ void Image::Scale(bool up_scale) {
946 auto dst_info = info; 953 auto dst_info = info;
947 dst_info.size.width = scaled_width; 954 dst_info.size.width = scaled_width;
948 dst_info.size.height = scaled_height; 955 dst_info.size.height = scaled_height;
949 upscaled_backup = MakeImage(dst_info, gl_internal_format); 956 upscaled_backup = MakeImage(dst_info, gl_internal_format, gl_num_levels);
950 } 957 }
951 const u32 src_width = up_scale ? original_width : scaled_width; 958 const u32 src_width = up_scale ? original_width : scaled_width;
952 const u32 src_height = up_scale ? original_height : scaled_height; 959 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 1bb762568..30037a6a2 100644
--- a/src/video_core/renderer_opengl/gl_texture_cache.h
+++ b/src/video_core/renderer_opengl/gl_texture_cache.h
@@ -219,6 +219,7 @@ private:
219 GLenum gl_internal_format = GL_NONE; 219 GLenum gl_internal_format = GL_NONE;
220 GLenum gl_format = GL_NONE; 220 GLenum gl_format = GL_NONE;
221 GLenum gl_type = GL_NONE; 221 GLenum gl_type = GL_NONE;
222 GLsizei gl_num_levels{};
222 TextureCacheRuntime* runtime{}; 223 TextureCacheRuntime* runtime{};
223 GLuint current_texture{}; 224 GLuint current_texture{};
224}; 225};