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
This commit is contained in:
Jason Fielder 2023-01-08 14:03:22 +01:00 committed by Clément Foucault
parent ef78811ac7
commit d4c085c17d
Notes: blender-bot 2023-02-13 16:03:55 +01:00
Referenced by issue #96261, Metal Viewport
4 changed files with 17 additions and 4 deletions

View File

@ -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);
}

View File

@ -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];

View File

@ -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

View File

@ -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));