Metal: Optimize texture usage in glutil
Ensure compression is enabled by using shader_read flag only. Also ensure that MTLTexture contents remain in optimal layout for reading after any data modifications. Authored by Apple: Michael Parkin-White Pull Request: https://projects.blender.org/blender/blender/pulls/106234
This commit is contained in:
parent
1658b8ab46
commit
ec94b1da58
@ -81,7 +81,7 @@ void immDrawPixelsTexScaledFullSize(const IMMDrawPixelsTexState *state,
|
||||
const int mip_len = use_mipmap ? 9999 : 1;
|
||||
|
||||
GPUTexture *tex = GPU_texture_create_2d(
|
||||
"immDrawPixels", img_w, img_h, mip_len, gpu_format, GPU_TEXTURE_USAGE_GENERAL, NULL);
|
||||
"immDrawPixels", img_w, img_h, mip_len, gpu_format, GPU_TEXTURE_USAGE_SHADER_READ, NULL);
|
||||
|
||||
const bool use_float_data = ELEM(gpu_format, GPU_RGBA16F, GPU_RGB16F, GPU_R16F);
|
||||
eGPUDataFormat gpu_data_format = (use_float_data) ? GPU_DATA_FLOAT : GPU_DATA_UBYTE;
|
||||
@ -183,7 +183,7 @@ void immDrawPixelsTexTiled_scaling_clipping(IMMDrawPixelsTexState *state,
|
||||
size_t stride = components * ((use_float_data) ? sizeof(float) : sizeof(uchar));
|
||||
|
||||
GPUTexture *tex = GPU_texture_create_2d(
|
||||
"immDrawPixels", tex_w, tex_h, 1, gpu_format, GPU_TEXTURE_USAGE_GENERAL, NULL);
|
||||
"immDrawPixels", tex_w, tex_h, 1, gpu_format, GPU_TEXTURE_USAGE_SHADER_READ, NULL);
|
||||
|
||||
GPU_texture_filter_mode(tex, use_filter);
|
||||
GPU_texture_wrap_mode(tex, false, true);
|
||||
|
@ -1041,14 +1041,17 @@ void gpu::MTLTexture::update_sub(
|
||||
if (texture_.storageMode == MTLStorageModeManaged) {
|
||||
[blit_encoder synchronizeResource:texture_];
|
||||
}
|
||||
[blit_encoder optimizeContentsForGPUAccess:texture_];
|
||||
}
|
||||
else {
|
||||
/* Textures which use MTLStorageModeManaged need to have updated contents
|
||||
* synced back to CPU to avoid an automatic flush overwriting contents. */
|
||||
blit_encoder = ctx->main_command_buffer.ensure_begin_blit_encoder();
|
||||
if (texture_.storageMode == MTLStorageModeManaged) {
|
||||
blit_encoder = ctx->main_command_buffer.ensure_begin_blit_encoder();
|
||||
|
||||
[blit_encoder synchronizeResource:texture_];
|
||||
}
|
||||
[blit_encoder optimizeContentsForGPUAccess:texture_];
|
||||
}
|
||||
|
||||
/* Decrement texture reference counts. This ensures temporary texture views are released. */
|
||||
@ -1110,6 +1113,7 @@ void MTLTexture::update_sub(int offset[3],
|
||||
if (texture_.storageMode == MTLStorageModeManaged) {
|
||||
[blit_encoder synchronizeResource:texture_];
|
||||
}
|
||||
[blit_encoder optimizeContentsForGPUAccess:texture_];
|
||||
}
|
||||
else {
|
||||
BLI_assert(false);
|
||||
@ -1230,6 +1234,7 @@ void gpu::MTLTexture::copy_to(Texture *dst)
|
||||
BLI_assert(mt_dst->d_ == d_);
|
||||
[blit_encoder copyFromTexture:this->get_metal_handle_base()
|
||||
toTexture:mt_dst->get_metal_handle_base()];
|
||||
[blit_encoder optimizeContentsForGPUAccess:mt_dst->get_metal_handle_base()];
|
||||
} break;
|
||||
default: {
|
||||
int slice = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user