[Bf-blender-cvs] [d4c085c17d1] master: Metal: Resolve failing assertions relating to memory sizing and texture swizzle.

Jason Fielder noreply at git.blender.org
Sun Jan 8 14:10:43 CET 2023


Commit: d4c085c17d135df810951d5dff4c2693916ff1d6
Author: Jason Fielder
Date:   Sun Jan 8 14:03:22 2023 +0100
Branches: master
https://developer.blender.org/rBd4c085c17d135df810951d5dff4c2693916ff1d6

Metal: Resolve failing assertions relating to memory sizing and texture swizzle.

Required texture bytesize calculation for compacted data types was incorrectly calculated, resulting in an erroneous format conversion taking place instead of direct data upload.
Metal dummy buffer size also temporarily increased to address problematic cases where the bound buffer was too small for missing UBOs.

Authored by Apple: Michael Parkin-White

Ref T96261

Reviewed By: fclem

Maniphest Tasks: T96261

Differential Revision: https://developer.blender.org/D16904

===================================================================

M	source/blender/gpu/intern/gpu_texture_private.hh
M	source/blender/gpu/metal/mtl_context.mm
M	source/blender/gpu/metal/mtl_texture.mm
M	source/blender/imbuf/intern/util_gpu.c

===================================================================

diff --git a/source/blender/gpu/intern/gpu_texture_private.hh b/source/blender/gpu/intern/gpu_texture_private.hh
index 35e0bf7b953..554c1e03d77 100644
--- a/source/blender/gpu/intern/gpu_texture_private.hh
+++ b/source/blender/gpu/intern/gpu_texture_private.hh
@@ -477,6 +477,14 @@ inline size_t to_bytesize(eGPUDataFormat data_format)
 
 inline size_t to_bytesize(eGPUTextureFormat tex_format, eGPUDataFormat data_format)
 {
+  /* Special case for compacted types.
+   * Standard component len calcualtion does not apply, as the texture formats contain multiple
+   * channels, but associated data format contains several compacted components. */
+  if ((tex_format == GPU_R11F_G11F_B10F && data_format == GPU_DATA_10_11_11_REV) ||
+      (tex_format == GPU_RGB10_A2 && data_format == GPU_DATA_2_10_10_10_REV)) {
+    return 4;
+  }
+
   return to_component_len(tex_format) * to_bytesize(data_format);
 }
 
diff --git a/source/blender/gpu/metal/mtl_context.mm b/source/blender/gpu/metal/mtl_context.mm
index 530ea35294e..9ccb91f1104 100644
--- a/source/blender/gpu/metal/mtl_context.mm
+++ b/source/blender/gpu/metal/mtl_context.mm
@@ -480,7 +480,12 @@ id<MTLBuffer> MTLContext::get_null_buffer()
     return null_buffer_;
   }
 
-  static const int null_buffer_size = 4096;
+  /* TODO(mpw_apple_gpusw): Null buffer size temporarily increased to cover
+   * maximum possible UBO size. There are a number of cases which need to be
+   * resolved in the high level where an expected UBO does not have a bound
+   * buffer. The null buffer needs to at least cover the size of these
+   * UBOs to avoid any GPU memory issues. */
+  static const int null_buffer_size = 20480;
   null_buffer_ = [this->device newBufferWithLength:null_buffer_size
                                            options:MTLResourceStorageModeManaged];
   [null_buffer_ retain];
diff --git a/source/blender/gpu/metal/mtl_texture.mm b/source/blender/gpu/metal/mtl_texture.mm
index d2d466bffe1..2d6ee9a8e6a 100644
--- a/source/blender/gpu/metal/mtl_texture.mm
+++ b/source/blender/gpu/metal/mtl_texture.mm
@@ -473,7 +473,7 @@ void gpu::MTLTexture::update_sub(
   @autoreleasepool {
     /* Determine totalsize of INPUT Data. */
     int num_channels = to_component_len(format_);
-    int input_bytes_per_pixel = num_channels * to_bytesize(type);
+    int input_bytes_per_pixel = to_bytesize(format_, type);
     int totalsize = 0;
 
     /* If unpack row length is used, size of input data uses the unpack row length, rather than the
diff --git a/source/blender/imbuf/intern/util_gpu.c b/source/blender/imbuf/intern/util_gpu.c
index 5bd18ee028a..9f4e2cf179c 100644
--- a/source/blender/imbuf/intern/util_gpu.c
+++ b/source/blender/imbuf/intern/util_gpu.c
@@ -252,11 +252,11 @@ GPUTexture *IMB_touch_gpu_texture(const char *name,
   GPUTexture *tex;
   if (layers > 0) {
     tex = GPU_texture_create_2d_array_ex(
-        name, w, h, layers, 9999, tex_format, GPU_TEXTURE_USAGE_SHADER_READ, NULL);
+        name, w, h, layers, 9999, tex_format, GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW, NULL);
   }
   else {
     tex = GPU_texture_create_2d_ex(
-        name, w, h, 9999, tex_format, GPU_TEXTURE_USAGE_SHADER_READ, NULL);
+        name, w, h, 9999, tex_format, GPU_TEXTURE_USAGE_SHADER_READ | GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW, NULL);
   }
 
   GPU_texture_swizzle_set(tex, imb_gpu_get_swizzle(ibuf));



More information about the Bf-blender-cvs mailing list