Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/metal/mtl_texture_util.mm
| Show First 20 Lines • Show All 299 Lines • ▼ Show 20 Lines | |||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Texture data upload routines | /** \name Texture data upload routines | ||||
| * \{ */ | * \{ */ | ||||
| id<MTLComputePipelineState> gpu::MTLTexture::mtl_texture_update_impl( | id<MTLComputePipelineState> gpu::MTLTexture::mtl_texture_update_impl( | ||||
| TextureUpdateRoutineSpecialisation specialisation_params, | TextureUpdateRoutineSpecialisation specialization_params, | ||||
| blender::Map<TextureUpdateRoutineSpecialisation, id<MTLComputePipelineState>> | blender::Map<TextureUpdateRoutineSpecialisation, id<MTLComputePipelineState>> | ||||
| &specialisation_cache, | &specialization_cache, | ||||
| eGPUTextureType texture_type) | eGPUTextureType texture_type) | ||||
| { | { | ||||
| /* Check whether the Kernel exists. */ | /* Check whether the Kernel exists. */ | ||||
| id<MTLComputePipelineState> *result = specialisation_cache.lookup_ptr(specialisation_params); | id<MTLComputePipelineState> *result = specialization_cache.lookup_ptr(specialization_params); | ||||
| if (result != nullptr) { | if (result != nullptr) { | ||||
| return *result; | return *result; | ||||
| } | } | ||||
| id<MTLComputePipelineState> return_pso = nil; | id<MTLComputePipelineState> return_pso = nil; | ||||
| @autoreleasepool { | @autoreleasepool { | ||||
| /* Fetch active context. */ | /* Fetch active context. */ | ||||
| MTLContext *ctx = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | MTLContext *ctx = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | ||||
| BLI_assert(ctx); | BLI_assert(ctx); | ||||
| /** SOURCE. **/ | /** SOURCE. **/ | ||||
| NSString *tex_update_kernel_src = [NSString | NSString *tex_update_kernel_src = [NSString | ||||
| stringWithUTF8String:datatoc_compute_texture_update_msl]; | stringWithUTF8String:datatoc_compute_texture_update_msl]; | ||||
| /* Prepare options and specializations. */ | /* Prepare options and specializations. */ | ||||
| MTLCompileOptions *options = [[[MTLCompileOptions alloc] init] autorelease]; | MTLCompileOptions *options = [[[MTLCompileOptions alloc] init] autorelease]; | ||||
| options.languageVersion = MTLLanguageVersion2_2; | options.languageVersion = MTLLanguageVersion2_2; | ||||
| options.preprocessorMacros = @{ | options.preprocessorMacros = @{ | ||||
| @"INPUT_DATA_TYPE" : | @"INPUT_DATA_TYPE" : | ||||
| [NSString stringWithUTF8String:specialisation_params.input_data_type.c_str()], | [NSString stringWithUTF8String:specialization_params.input_data_type.c_str()], | ||||
| @"OUTPUT_DATA_TYPE" : | @"OUTPUT_DATA_TYPE" : | ||||
| [NSString stringWithUTF8String:specialisation_params.output_data_type.c_str()], | [NSString stringWithUTF8String:specialization_params.output_data_type.c_str()], | ||||
| @"COMPONENT_COUNT_INPUT" : | @"COMPONENT_COUNT_INPUT" : | ||||
| [NSNumber numberWithInt:specialisation_params.component_count_input], | [NSNumber numberWithInt:specialization_params.component_count_input], | ||||
| @"COMPONENT_COUNT_OUTPUT" : | @"COMPONENT_COUNT_OUTPUT" : | ||||
| [NSNumber numberWithInt:specialisation_params.component_count_output], | [NSNumber numberWithInt:specialization_params.component_count_output], | ||||
| @"TEX_TYPE" : [NSNumber numberWithInt:((int)(texture_type))] | @"TEX_TYPE" : [NSNumber numberWithInt:((int)(texture_type))] | ||||
| }; | }; | ||||
| /* Prepare shader library for conversion routine. */ | /* Prepare shader library for conversion routine. */ | ||||
| NSError *error = NULL; | NSError *error = nullptr; | ||||
| id<MTLLibrary> temp_lib = [[ctx->device newLibraryWithSource:tex_update_kernel_src | id<MTLLibrary> temp_lib = [[ctx->device newLibraryWithSource:tex_update_kernel_src | ||||
| options:options | options:options | ||||
| error:&error] autorelease]; | error:&error] autorelease]; | ||||
| if (error) { | if (error) { | ||||
| NSLog(@"Compile Error - Metal Shader Library error %@ ", error); | NSLog(@"Compile Error - Metal Shader Library error %@ ", error); | ||||
| BLI_assert(false); | BLI_assert(false); | ||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| Show All 10 Lines | id<MTLComputePipelineState> compute_pso = [ctx->device | ||||
| error:&error]; | error:&error]; | ||||
| if (error || compute_pso == nil) { | if (error || compute_pso == nil) { | ||||
| NSLog(@"Failed to prepare texture_update MTLComputePipelineState %@", error); | NSLog(@"Failed to prepare texture_update MTLComputePipelineState %@", error); | ||||
| BLI_assert(false); | BLI_assert(false); | ||||
| } | } | ||||
| /* Store PSO. */ | /* Store PSO. */ | ||||
| [compute_pso retain]; | [compute_pso retain]; | ||||
| specialisation_cache.add_new(specialisation_params, compute_pso); | specialization_cache.add_new(specialization_params, compute_pso); | ||||
| return_pso = compute_pso; | return_pso = compute_pso; | ||||
| } | } | ||||
| BLI_assert(return_pso != nil); | BLI_assert(return_pso != nil); | ||||
| return return_pso; | return return_pso; | ||||
| } | } | ||||
| id<MTLComputePipelineState> gpu::MTLTexture::texture_update_1d_get_kernel( | id<MTLComputePipelineState> gpu::MTLTexture::texture_update_1d_get_kernel( | ||||
| TextureUpdateRoutineSpecialisation specialisation) | TextureUpdateRoutineSpecialisation specialization) | ||||
| { | { | ||||
| MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | ||||
| BLI_assert(mtl_context != nullptr); | BLI_assert(mtl_context != nullptr); | ||||
| return mtl_texture_update_impl(specialisation, | return mtl_texture_update_impl(specialization, | ||||
| mtl_context->get_texture_utils().texture_1d_update_compute_psos, | mtl_context->get_texture_utils().texture_1d_update_compute_psos, | ||||
| GPU_TEXTURE_1D); | GPU_TEXTURE_1D); | ||||
| } | } | ||||
| id<MTLComputePipelineState> gpu::MTLTexture::texture_update_1d_array_get_kernel( | id<MTLComputePipelineState> gpu::MTLTexture::texture_update_1d_array_get_kernel( | ||||
| TextureUpdateRoutineSpecialisation specialisation) | TextureUpdateRoutineSpecialisation specialization) | ||||
| { | { | ||||
| MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | ||||
| BLI_assert(mtl_context != nullptr); | BLI_assert(mtl_context != nullptr); | ||||
| return mtl_texture_update_impl( | return mtl_texture_update_impl( | ||||
| specialisation, | specialization, | ||||
| mtl_context->get_texture_utils().texture_1d_array_update_compute_psos, | mtl_context->get_texture_utils().texture_1d_array_update_compute_psos, | ||||
| GPU_TEXTURE_1D_ARRAY); | GPU_TEXTURE_1D_ARRAY); | ||||
| } | } | ||||
| id<MTLComputePipelineState> gpu::MTLTexture::texture_update_2d_get_kernel( | id<MTLComputePipelineState> gpu::MTLTexture::texture_update_2d_get_kernel( | ||||
| TextureUpdateRoutineSpecialisation specialisation) | TextureUpdateRoutineSpecialisation specialization) | ||||
| { | { | ||||
| MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | ||||
| BLI_assert(mtl_context != nullptr); | BLI_assert(mtl_context != nullptr); | ||||
| return mtl_texture_update_impl(specialisation, | return mtl_texture_update_impl(specialization, | ||||
| mtl_context->get_texture_utils().texture_2d_update_compute_psos, | mtl_context->get_texture_utils().texture_2d_update_compute_psos, | ||||
| GPU_TEXTURE_2D); | GPU_TEXTURE_2D); | ||||
| } | } | ||||
| id<MTLComputePipelineState> gpu::MTLTexture::texture_update_2d_array_get_kernel( | id<MTLComputePipelineState> gpu::MTLTexture::texture_update_2d_array_get_kernel( | ||||
| TextureUpdateRoutineSpecialisation specialisation) | TextureUpdateRoutineSpecialisation specialization) | ||||
| { | { | ||||
| MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | ||||
| BLI_assert(mtl_context != nullptr); | BLI_assert(mtl_context != nullptr); | ||||
| return mtl_texture_update_impl( | return mtl_texture_update_impl( | ||||
| specialisation, | specialization, | ||||
| mtl_context->get_texture_utils().texture_2d_array_update_compute_psos, | mtl_context->get_texture_utils().texture_2d_array_update_compute_psos, | ||||
| GPU_TEXTURE_2D_ARRAY); | GPU_TEXTURE_2D_ARRAY); | ||||
| } | } | ||||
| id<MTLComputePipelineState> gpu::MTLTexture::texture_update_3d_get_kernel( | id<MTLComputePipelineState> gpu::MTLTexture::texture_update_3d_get_kernel( | ||||
| TextureUpdateRoutineSpecialisation specialisation) | TextureUpdateRoutineSpecialisation specialization) | ||||
| { | { | ||||
| MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | ||||
| BLI_assert(mtl_context != nullptr); | BLI_assert(mtl_context != nullptr); | ||||
| return mtl_texture_update_impl(specialisation, | return mtl_texture_update_impl(specialization, | ||||
| mtl_context->get_texture_utils().texture_3d_update_compute_psos, | mtl_context->get_texture_utils().texture_3d_update_compute_psos, | ||||
| GPU_TEXTURE_3D); | GPU_TEXTURE_3D); | ||||
| } | } | ||||
| /* TODO(Metal): Data upload routine kernel for texture cube and texture cube array. | /* TODO(Metal): Data upload routine kernel for texture cube and texture cube array. | ||||
| * Currently does not appear to be hit. */ | * Currently does not appear to be hit. */ | ||||
| GPUShader *gpu::MTLTexture::depth_2d_update_sh_get( | GPUShader *gpu::MTLTexture::depth_2d_update_sh_get( | ||||
| DepthTextureUpdateRoutineSpecialisation specialisation) | DepthTextureUpdateRoutineSpecialisation specialization) | ||||
| { | { | ||||
| /* Check whether the Kernel exists. */ | /* Check whether the Kernel exists. */ | ||||
| MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | ||||
| BLI_assert(mtl_context != nullptr); | BLI_assert(mtl_context != nullptr); | ||||
| GPUShader **result = mtl_context->get_texture_utils().depth_2d_update_shaders.lookup_ptr( | GPUShader **result = mtl_context->get_texture_utils().depth_2d_update_shaders.lookup_ptr( | ||||
| specialisation); | specialization); | ||||
| if (result != nullptr) { | if (result != nullptr) { | ||||
| return *result; | return *result; | ||||
| } | } | ||||
| const char *fragment_source = nullptr; | const char *fragment_source = nullptr; | ||||
| switch (specialisation.data_mode) { | switch (specialization.data_mode) { | ||||
| case MTL_DEPTH_UPDATE_MODE_FLOAT: | case MTL_DEPTH_UPDATE_MODE_FLOAT: | ||||
| fragment_source = datatoc_depth_2d_update_float_frag_glsl; | fragment_source = datatoc_depth_2d_update_float_frag_glsl; | ||||
| break; | break; | ||||
| case MTL_DEPTH_UPDATE_MODE_INT24: | case MTL_DEPTH_UPDATE_MODE_INT24: | ||||
| fragment_source = datatoc_depth_2d_update_int24_frag_glsl; | fragment_source = datatoc_depth_2d_update_int24_frag_glsl; | ||||
| break; | break; | ||||
| case MTL_DEPTH_UPDATE_MODE_INT32: | case MTL_DEPTH_UPDATE_MODE_INT32: | ||||
| fragment_source = datatoc_depth_2d_update_int32_frag_glsl; | fragment_source = datatoc_depth_2d_update_int32_frag_glsl; | ||||
| break; | break; | ||||
| default: | default: | ||||
| BLI_assert(false && "Invalid format mode\n"); | BLI_assert(false && "Invalid format mode\n"); | ||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| GPUShader *shader = GPU_shader_create(datatoc_depth_2d_update_vert_glsl, | GPUShader *shader = GPU_shader_create(datatoc_depth_2d_update_vert_glsl, | ||||
| fragment_source, | fragment_source, | ||||
| nullptr, | nullptr, | ||||
| nullptr, | nullptr, | ||||
| nullptr, | nullptr, | ||||
| "depth_2d_update_sh_get"); | "depth_2d_update_sh_get"); | ||||
| mtl_context->get_texture_utils().depth_2d_update_shaders.add_new(specialisation, shader); | mtl_context->get_texture_utils().depth_2d_update_shaders.add_new(specialization, shader); | ||||
| return shader; | return shader; | ||||
| } | } | ||||
| GPUShader *gpu::MTLTexture::fullscreen_blit_sh_get() | GPUShader *gpu::MTLTexture::fullscreen_blit_sh_get() | ||||
| { | { | ||||
| MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | ||||
| BLI_assert(mtl_context != nullptr); | BLI_assert(mtl_context != nullptr); | ||||
| Show All 21 Lines | void gpu::MTLTexture::update_sub_depth_2d( | ||||
| BLI_assert(validate_data_format_mtl(format_, type)); | BLI_assert(validate_data_format_mtl(format_, type)); | ||||
| BLI_assert(ELEM(type, GPU_DATA_FLOAT, GPU_DATA_UINT_24_8, GPU_DATA_UINT)); | BLI_assert(ELEM(type, GPU_DATA_FLOAT, GPU_DATA_UINT_24_8, GPU_DATA_UINT)); | ||||
| /* Determine whether we are in GPU_DATA_UINT_24_8 or GPU_DATA_FLOAT mode. */ | /* Determine whether we are in GPU_DATA_UINT_24_8 or GPU_DATA_FLOAT mode. */ | ||||
| bool is_float = (type == GPU_DATA_FLOAT); | bool is_float = (type == GPU_DATA_FLOAT); | ||||
| eGPUTextureFormat format = (is_float) ? GPU_R32F : GPU_R32I; | eGPUTextureFormat format = (is_float) ? GPU_R32F : GPU_R32I; | ||||
| /* Shader key - Add parameters here for different configurations. */ | /* Shader key - Add parameters here for different configurations. */ | ||||
| DepthTextureUpdateRoutineSpecialisation specialisation; | DepthTextureUpdateRoutineSpecialisation specialization; | ||||
| switch (type) { | switch (type) { | ||||
| case GPU_DATA_FLOAT: | case GPU_DATA_FLOAT: | ||||
| specialisation.data_mode = MTL_DEPTH_UPDATE_MODE_FLOAT; | specialization.data_mode = MTL_DEPTH_UPDATE_MODE_FLOAT; | ||||
| break; | break; | ||||
| case GPU_DATA_UINT_24_8: | case GPU_DATA_UINT_24_8: | ||||
| specialisation.data_mode = MTL_DEPTH_UPDATE_MODE_INT24; | specialization.data_mode = MTL_DEPTH_UPDATE_MODE_INT24; | ||||
| break; | break; | ||||
| case GPU_DATA_UINT: | case GPU_DATA_UINT: | ||||
| specialisation.data_mode = MTL_DEPTH_UPDATE_MODE_INT32; | specialization.data_mode = MTL_DEPTH_UPDATE_MODE_INT32; | ||||
| break; | break; | ||||
| default: | default: | ||||
| BLI_assert(false && "Unsupported eGPUDataFormat being passed to depth texture update\n"); | BLI_assert(false && "Unsupported eGPUDataFormat being passed to depth texture update\n"); | ||||
| return; | return; | ||||
| } | } | ||||
| /* Push contents into an r32_tex and render contents to depth using a shader. */ | /* Push contents into an r32_tex and render contents to depth using a shader. */ | ||||
| Show All 9 Lines | void gpu::MTLTexture::update_sub_depth_2d( | ||||
| GPU_framebuffer_texture_attach(depth_fb_temp, wrap(static_cast<Texture *>(this)), 0, mip); | GPU_framebuffer_texture_attach(depth_fb_temp, wrap(static_cast<Texture *>(this)), 0, mip); | ||||
| GPU_framebuffer_bind(depth_fb_temp); | GPU_framebuffer_bind(depth_fb_temp); | ||||
| if (extent[0] == w_ && extent[1] == h_) { | if (extent[0] == w_ && extent[1] == h_) { | ||||
| /* Skip load if the whole texture is being updated. */ | /* Skip load if the whole texture is being updated. */ | ||||
| GPU_framebuffer_clear_depth(depth_fb_temp, 0.0); | GPU_framebuffer_clear_depth(depth_fb_temp, 0.0); | ||||
| GPU_framebuffer_clear_stencil(depth_fb_temp, 0); | GPU_framebuffer_clear_stencil(depth_fb_temp, 0); | ||||
| } | } | ||||
| GPUShader *depth_2d_update_sh = depth_2d_update_sh_get(specialisation); | GPUShader *depth_2d_update_sh = depth_2d_update_sh_get(specialization); | ||||
| BLI_assert(depth_2d_update_sh != nullptr); | BLI_assert(depth_2d_update_sh != nullptr); | ||||
| GPUBatch *quad = GPU_batch_preset_quad(); | GPUBatch *quad = GPU_batch_preset_quad(); | ||||
| GPU_batch_set_shader(quad, depth_2d_update_sh); | GPU_batch_set_shader(quad, depth_2d_update_sh); | ||||
| GPU_batch_texture_bind(quad, "source_data", r32_tex_tmp); | GPU_batch_texture_bind(quad, "source_data", r32_tex_tmp); | ||||
| GPU_batch_uniform_1i(quad, "mip", mip); | GPU_batch_uniform_1i(quad, "mip", mip); | ||||
| GPU_batch_uniform_2f(quad, "extent", (float)extent[0], (float)extent[1]); | GPU_batch_uniform_2f(quad, "extent", (float)extent[0], (float)extent[1]); | ||||
| GPU_batch_uniform_2f(quad, "offset", (float)offset[0], (float)offset[1]); | GPU_batch_uniform_2f(quad, "offset", (float)offset[0], (float)offset[1]); | ||||
| Show All 30 Lines | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Texture data read routines | /** \name Texture data read routines | ||||
| * \{ */ | * \{ */ | ||||
| id<MTLComputePipelineState> gpu::MTLTexture::mtl_texture_read_impl( | id<MTLComputePipelineState> gpu::MTLTexture::mtl_texture_read_impl( | ||||
| TextureReadRoutineSpecialisation specialisation_params, | TextureReadRoutineSpecialisation specialization_params, | ||||
| blender::Map<TextureReadRoutineSpecialisation, id<MTLComputePipelineState>> | blender::Map<TextureReadRoutineSpecialisation, id<MTLComputePipelineState>> | ||||
| &specialisation_cache, | &specialization_cache, | ||||
| eGPUTextureType texture_type) | eGPUTextureType texture_type) | ||||
| { | { | ||||
| /* Check whether the Kernel exists. */ | /* Check whether the Kernel exists. */ | ||||
| id<MTLComputePipelineState> *result = specialisation_cache.lookup_ptr(specialisation_params); | id<MTLComputePipelineState> *result = specialization_cache.lookup_ptr(specialization_params); | ||||
| if (result != nullptr) { | if (result != nullptr) { | ||||
| return *result; | return *result; | ||||
| } | } | ||||
| id<MTLComputePipelineState> return_pso = nil; | id<MTLComputePipelineState> return_pso = nil; | ||||
| @autoreleasepool { | @autoreleasepool { | ||||
| /* Fetch active context. */ | /* Fetch active context. */ | ||||
| MTLContext *ctx = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | MTLContext *ctx = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | ||||
| BLI_assert(ctx); | BLI_assert(ctx); | ||||
| /** SOURCE. **/ | /** SOURCE. **/ | ||||
| NSString *tex_update_kernel_src = [NSString | NSString *tex_update_kernel_src = [NSString | ||||
| stringWithUTF8String:datatoc_compute_texture_read_msl]; | stringWithUTF8String:datatoc_compute_texture_read_msl]; | ||||
| /* Defensive Debug Checks. */ | /* Defensive Debug Checks. */ | ||||
| long long int depth_scale_factor = 1; | long long int depth_scale_factor = 1; | ||||
| if (specialisation_params.depth_format_mode > 0) { | if (specialization_params.depth_format_mode > 0) { | ||||
| BLI_assert(specialisation_params.component_count_input == 1); | BLI_assert(specialization_params.component_count_input == 1); | ||||
| BLI_assert(specialisation_params.component_count_output == 1); | BLI_assert(specialization_params.component_count_output == 1); | ||||
| switch (specialisation_params.depth_format_mode) { | switch (specialization_params.depth_format_mode) { | ||||
| case 1: | case 1: | ||||
| /* FLOAT */ | /* FLOAT */ | ||||
| depth_scale_factor = 1; | depth_scale_factor = 1; | ||||
| break; | break; | ||||
| case 2: | case 2: | ||||
| /* D24 uint */ | /* D24 uint */ | ||||
| depth_scale_factor = 0xFFFFFFu; | depth_scale_factor = 0xFFFFFFu; | ||||
| break; | break; | ||||
| case 4: | case 4: | ||||
| /* D32 uint */ | /* D32 uint */ | ||||
| depth_scale_factor = 0xFFFFFFFFu; | depth_scale_factor = 0xFFFFFFFFu; | ||||
| break; | break; | ||||
| default: | default: | ||||
| BLI_assert_msg(0, "Unrecognised mode"); | BLI_assert_msg(0, "Unrecognised mode"); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| /* Prepare options and specializations. */ | /* Prepare options and specializations. */ | ||||
| MTLCompileOptions *options = [[[MTLCompileOptions alloc] init] autorelease]; | MTLCompileOptions *options = [[[MTLCompileOptions alloc] init] autorelease]; | ||||
| options.languageVersion = MTLLanguageVersion2_2; | options.languageVersion = MTLLanguageVersion2_2; | ||||
| options.preprocessorMacros = @{ | options.preprocessorMacros = @{ | ||||
| @"INPUT_DATA_TYPE" : | @"INPUT_DATA_TYPE" : | ||||
| [NSString stringWithUTF8String:specialisation_params.input_data_type.c_str()], | [NSString stringWithUTF8String:specialization_params.input_data_type.c_str()], | ||||
| @"OUTPUT_DATA_TYPE" : | @"OUTPUT_DATA_TYPE" : | ||||
| [NSString stringWithUTF8String:specialisation_params.output_data_type.c_str()], | [NSString stringWithUTF8String:specialization_params.output_data_type.c_str()], | ||||
| @"COMPONENT_COUNT_INPUT" : | @"COMPONENT_COUNT_INPUT" : | ||||
| [NSNumber numberWithInt:specialisation_params.component_count_input], | [NSNumber numberWithInt:specialization_params.component_count_input], | ||||
| @"COMPONENT_COUNT_OUTPUT" : | @"COMPONENT_COUNT_OUTPUT" : | ||||
| [NSNumber numberWithInt:specialisation_params.component_count_output], | [NSNumber numberWithInt:specialization_params.component_count_output], | ||||
| @"WRITE_COMPONENT_COUNT" : | @"WRITE_COMPONENT_COUNT" : | ||||
| [NSNumber numberWithInt:min_ii(specialisation_params.component_count_input, | [NSNumber numberWithInt:min_ii(specialization_params.component_count_input, | ||||
| specialisation_params.component_count_output)], | specialization_params.component_count_output)], | ||||
| @"IS_DEPTH_FORMAT" : | @"IS_DEPTH_FORMAT" : | ||||
| [NSNumber numberWithInt:((specialisation_params.depth_format_mode > 0) ? 1 : 0)], | [NSNumber numberWithInt:((specialization_params.depth_format_mode > 0) ? 1 : 0)], | ||||
| @"DEPTH_SCALE_FACTOR" : [NSNumber numberWithLongLong:depth_scale_factor], | @"DEPTH_SCALE_FACTOR" : [NSNumber numberWithLongLong:depth_scale_factor], | ||||
| @"TEX_TYPE" : [NSNumber numberWithInt:((int)(texture_type))] | @"TEX_TYPE" : [NSNumber numberWithInt:((int)(texture_type))] | ||||
| }; | }; | ||||
| /* Prepare shader library for conversion routine. */ | /* Prepare shader library for conversion routine. */ | ||||
| NSError *error = NULL; | NSError *error = nullptr; | ||||
| id<MTLLibrary> temp_lib = [[ctx->device newLibraryWithSource:tex_update_kernel_src | id<MTLLibrary> temp_lib = [[ctx->device newLibraryWithSource:tex_update_kernel_src | ||||
| options:options | options:options | ||||
| error:&error] autorelease]; | error:&error] autorelease]; | ||||
| if (error) { | if (error) { | ||||
| NSLog(@"Compile Error - Metal Shader Library error %@ ", error); | NSLog(@"Compile Error - Metal Shader Library error %@ ", error); | ||||
| BLI_assert(false); | BLI_assert(false); | ||||
| return nil; | return nil; | ||||
| } | } | ||||
| Show All 11 Lines | @autoreleasepool { | ||||
| if (error || compute_pso == nil) { | if (error || compute_pso == nil) { | ||||
| NSLog(@"Failed to prepare texture_read MTLComputePipelineState %@", error); | NSLog(@"Failed to prepare texture_read MTLComputePipelineState %@", error); | ||||
| BLI_assert(false); | BLI_assert(false); | ||||
| return nil; | return nil; | ||||
| } | } | ||||
| /* Store PSO. */ | /* Store PSO. */ | ||||
| [compute_pso retain]; | [compute_pso retain]; | ||||
| specialisation_cache.add_new(specialisation_params, compute_pso); | specialization_cache.add_new(specialization_params, compute_pso); | ||||
| return_pso = compute_pso; | return_pso = compute_pso; | ||||
| } | } | ||||
| BLI_assert(return_pso != nil); | BLI_assert(return_pso != nil); | ||||
| return return_pso; | return return_pso; | ||||
| } | } | ||||
| id<MTLComputePipelineState> gpu::MTLTexture::texture_read_2d_get_kernel( | id<MTLComputePipelineState> gpu::MTLTexture::texture_read_2d_get_kernel( | ||||
| TextureReadRoutineSpecialisation specialisation) | TextureReadRoutineSpecialisation specialization) | ||||
| { | { | ||||
| MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | ||||
| BLI_assert(mtl_context != nullptr); | BLI_assert(mtl_context != nullptr); | ||||
| return mtl_texture_read_impl(specialisation, | return mtl_texture_read_impl(specialization, | ||||
| mtl_context->get_texture_utils().texture_2d_read_compute_psos, | mtl_context->get_texture_utils().texture_2d_read_compute_psos, | ||||
| GPU_TEXTURE_2D); | GPU_TEXTURE_2D); | ||||
| } | } | ||||
| id<MTLComputePipelineState> gpu::MTLTexture::texture_read_2d_array_get_kernel( | id<MTLComputePipelineState> gpu::MTLTexture::texture_read_2d_array_get_kernel( | ||||
| TextureReadRoutineSpecialisation specialisation) | TextureReadRoutineSpecialisation specialization) | ||||
| { | { | ||||
| MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | ||||
| BLI_assert(mtl_context != nullptr); | BLI_assert(mtl_context != nullptr); | ||||
| return mtl_texture_read_impl(specialisation, | return mtl_texture_read_impl(specialization, | ||||
| mtl_context->get_texture_utils().texture_2d_array_read_compute_psos, | mtl_context->get_texture_utils().texture_2d_array_read_compute_psos, | ||||
| GPU_TEXTURE_2D_ARRAY); | GPU_TEXTURE_2D_ARRAY); | ||||
| } | } | ||||
| id<MTLComputePipelineState> gpu::MTLTexture::texture_read_1d_get_kernel( | id<MTLComputePipelineState> gpu::MTLTexture::texture_read_1d_get_kernel( | ||||
| TextureReadRoutineSpecialisation specialisation) | TextureReadRoutineSpecialisation specialization) | ||||
| { | { | ||||
| MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | ||||
| BLI_assert(mtl_context != nullptr); | BLI_assert(mtl_context != nullptr); | ||||
| return mtl_texture_read_impl(specialisation, | return mtl_texture_read_impl(specialization, | ||||
| mtl_context->get_texture_utils().texture_1d_read_compute_psos, | mtl_context->get_texture_utils().texture_1d_read_compute_psos, | ||||
| GPU_TEXTURE_1D); | GPU_TEXTURE_1D); | ||||
| } | } | ||||
| id<MTLComputePipelineState> gpu::MTLTexture::texture_read_1d_array_get_kernel( | id<MTLComputePipelineState> gpu::MTLTexture::texture_read_1d_array_get_kernel( | ||||
| TextureReadRoutineSpecialisation specialisation) | TextureReadRoutineSpecialisation specialization) | ||||
| { | { | ||||
| MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | ||||
| BLI_assert(mtl_context != nullptr); | BLI_assert(mtl_context != nullptr); | ||||
| return mtl_texture_read_impl(specialisation, | return mtl_texture_read_impl(specialization, | ||||
| mtl_context->get_texture_utils().texture_1d_array_read_compute_psos, | mtl_context->get_texture_utils().texture_1d_array_read_compute_psos, | ||||
| GPU_TEXTURE_1D_ARRAY); | GPU_TEXTURE_1D_ARRAY); | ||||
| } | } | ||||
| id<MTLComputePipelineState> gpu::MTLTexture::texture_read_3d_get_kernel( | id<MTLComputePipelineState> gpu::MTLTexture::texture_read_3d_get_kernel( | ||||
| TextureReadRoutineSpecialisation specialisation) | TextureReadRoutineSpecialisation specialization) | ||||
| { | { | ||||
| MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | MTLContext *mtl_context = static_cast<MTLContext *>(unwrap(GPU_context_active_get())); | ||||
| BLI_assert(mtl_context != nullptr); | BLI_assert(mtl_context != nullptr); | ||||
| return mtl_texture_read_impl(specialisation, | return mtl_texture_read_impl(specialization, | ||||
| mtl_context->get_texture_utils().texture_3d_read_compute_psos, | mtl_context->get_texture_utils().texture_3d_read_compute_psos, | ||||
| GPU_TEXTURE_3D); | GPU_TEXTURE_3D); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| } // namespace blender::gpu | } // namespace blender::gpu | ||||