Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/metal/mtl_texture_util.mm
| Show All 16 Lines | |||||
| #include "mtl_backend.hh" | #include "mtl_backend.hh" | ||||
| #include "mtl_context.hh" | #include "mtl_context.hh" | ||||
| #include "mtl_texture.hh" | #include "mtl_texture.hh" | ||||
| /* Utility file for secondary functionality which supports mtl_texture.mm. */ | /* Utility file for secondary functionality which supports mtl_texture.mm. */ | ||||
| extern char datatoc_compute_texture_update_msl[]; | extern char datatoc_compute_texture_update_msl[]; | ||||
| extern char datatoc_depth_2d_update_vert_glsl[]; | |||||
| extern char datatoc_depth_2d_update_float_frag_glsl[]; | |||||
| extern char datatoc_depth_2d_update_int24_frag_glsl[]; | |||||
| extern char datatoc_depth_2d_update_int32_frag_glsl[]; | |||||
| extern char datatoc_compute_texture_read_msl[]; | extern char datatoc_compute_texture_read_msl[]; | ||||
| extern char datatoc_gpu_shader_fullscreen_blit_vert_glsl[]; | |||||
| extern char datatoc_gpu_shader_fullscreen_blit_frag_glsl[]; | |||||
| namespace blender::gpu { | namespace blender::gpu { | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Texture Utility Functions | /** \name Texture Utility Functions | ||||
| * \{ */ | * \{ */ | ||||
| MTLPixelFormat gpu_texture_format_to_metal(eGPUTextureFormat tex_format) | MTLPixelFormat gpu_texture_format_to_metal(eGPUTextureFormat tex_format) | ||||
| ▲ Show 20 Lines • Show All 402 Lines • ▼ Show 20 Lines | GPUShader *gpu::MTLTexture::depth_2d_update_sh_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( | ||||
| specialization); | specialization); | ||||
| if (result != nullptr) { | if (result != nullptr) { | ||||
| return *result; | return *result; | ||||
| } | } | ||||
| const char *fragment_source = nullptr; | const char *depth_2d_info_variant = nullptr; | ||||
| switch (specialization.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; | depth_2d_info_variant = "depth_2d_update_float"; | ||||
| break; | break; | ||||
| case MTL_DEPTH_UPDATE_MODE_INT24: | case MTL_DEPTH_UPDATE_MODE_INT24: | ||||
| fragment_source = datatoc_depth_2d_update_int24_frag_glsl; | depth_2d_info_variant = "depth_2d_update_int24"; | ||||
| break; | break; | ||||
| case MTL_DEPTH_UPDATE_MODE_INT32: | case MTL_DEPTH_UPDATE_MODE_INT32: | ||||
| fragment_source = datatoc_depth_2d_update_int32_frag_glsl; | depth_2d_info_variant = "depth_2d_update_int32"; | ||||
| 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_from_info_name(depth_2d_info_variant); | ||||
| fragment_source, | |||||
| nullptr, | |||||
| nullptr, | |||||
| nullptr, | |||||
| "depth_2d_update_sh_get"); | |||||
| mtl_context->get_texture_utils().depth_2d_update_shaders.add_new(specialization, 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); | ||||
| if (mtl_context->get_texture_utils().fullscreen_blit_shader == nullptr) { | if (mtl_context->get_texture_utils().fullscreen_blit_shader == nullptr) { | ||||
| const char *vertex_source = datatoc_gpu_shader_fullscreen_blit_vert_glsl; | GPUShader *shader = GPU_shader_create_from_info_name("fullscreen_blit"); | ||||
| const char *fragment_source = datatoc_gpu_shader_fullscreen_blit_frag_glsl; | |||||
| GPUShader *shader = GPU_shader_create( | |||||
| vertex_source, fragment_source, nullptr, nullptr, nullptr, "fullscreen_blit"); | |||||
| mtl_context->get_texture_utils().fullscreen_blit_shader = shader; | mtl_context->get_texture_utils().fullscreen_blit_shader = shader; | ||||
| } | } | ||||
| return mtl_context->get_texture_utils().fullscreen_blit_shader; | return mtl_context->get_texture_utils().fullscreen_blit_shader; | ||||
| } | } | ||||
| /* Special routine for updating 2D depth textures using the rendering pipeline. */ | /* Special routine for updating 2D depth textures using the rendering pipeline. */ | ||||
| void gpu::MTLTexture::update_sub_depth_2d( | void gpu::MTLTexture::update_sub_depth_2d( | ||||
| int mip, int offset[3], int extent[3], eGPUDataFormat type, const void *data) | int mip, int offset[3], int extent[3], eGPUDataFormat type, const void *data) | ||||
| ▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | @autoreleasepool { | ||||
| 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; | int64_t depth_scale_factor = 1; | ||||
| if (specialization_params.depth_format_mode > 0) { | if (specialization_params.depth_format_mode > 0) { | ||||
| BLI_assert(specialization_params.component_count_input == 1); | BLI_assert(specialization_params.component_count_input == 1); | ||||
| BLI_assert(specialization_params.component_count_output == 1); | BLI_assert(specialization_params.component_count_output == 1); | ||||
| switch (specialization_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; | ||||
| ▲ Show 20 Lines • Show All 125 Lines • Show Last 20 Lines | |||||