Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/metal/mtl_context.hh
| Show All 22 Lines | |||||
| #include "mtl_memory.hh" | #include "mtl_memory.hh" | ||||
| #include "mtl_shader.hh" | #include "mtl_shader.hh" | ||||
| #include "mtl_shader_interface.hh" | #include "mtl_shader_interface.hh" | ||||
| #include "mtl_texture.hh" | #include "mtl_texture.hh" | ||||
| #include <Cocoa/Cocoa.h> | #include <Cocoa/Cocoa.h> | ||||
| #include <Metal/Metal.h> | #include <Metal/Metal.h> | ||||
| #include <QuartzCore/QuartzCore.h> | #include <QuartzCore/QuartzCore.h> | ||||
| #include <mutex> | |||||
| @class CAMetalLayer; | @class CAMetalLayer; | ||||
| @class MTLCommandQueue; | @class MTLCommandQueue; | ||||
| @class MTLRenderPipelineState; | @class MTLRenderPipelineState; | ||||
| namespace blender::gpu { | namespace blender::gpu { | ||||
| /* Forward Declarations */ | /* Forward Declarations */ | ||||
| ▲ Show 20 Lines • Show All 266 Lines • ▼ Show 20 Lines | struct MTLContextTextureUtils { | ||||
| } | } | ||||
| void cleanup() | void cleanup() | ||||
| { | { | ||||
| if (fullscreen_blit_shader) { | if (fullscreen_blit_shader) { | ||||
| GPU_shader_free(fullscreen_blit_shader); | GPU_shader_free(fullscreen_blit_shader); | ||||
| } | } | ||||
| /* Free depth 2D Update shaders */ | |||||
| for (auto item : depth_2d_update_shaders.items()) { | |||||
| GPU_shader_free(item.value); | |||||
| } | |||||
| depth_2d_update_shaders.clear(); | |||||
| /* Free Read shader maps */ | /* Free Read shader maps */ | ||||
| free_cached_pso_map(texture_1d_read_compute_psos); | free_cached_pso_map(texture_1d_read_compute_psos); | ||||
| free_cached_pso_map(texture_1d_read_compute_psos); | free_cached_pso_map(texture_1d_read_compute_psos); | ||||
| free_cached_pso_map(texture_1d_array_read_compute_psos); | free_cached_pso_map(texture_1d_array_read_compute_psos); | ||||
| free_cached_pso_map(texture_2d_read_compute_psos); | free_cached_pso_map(texture_2d_read_compute_psos); | ||||
| free_cached_pso_map(texture_2d_array_read_compute_psos); | free_cached_pso_map(texture_2d_array_read_compute_psos); | ||||
| free_cached_pso_map(texture_3d_read_compute_psos); | free_cached_pso_map(texture_3d_read_compute_psos); | ||||
| free_cached_pso_map(texture_cube_read_compute_psos); | free_cached_pso_map(texture_cube_read_compute_psos); | ||||
| ▲ Show 20 Lines • Show All 273 Lines • ▼ Show 20 Lines | |||||
| #ifndef NDEBUG | #ifndef NDEBUG | ||||
| /* Label for Context debug name assignment. */ | /* Label for Context debug name assignment. */ | ||||
| NSString *label = nil; | NSString *label = nil; | ||||
| #endif | #endif | ||||
| /* Memory Management. */ | /* Memory Management. */ | ||||
| MTLScratchBufferManager memory_manager; | MTLScratchBufferManager memory_manager; | ||||
| static MTLBufferPool global_memory_manager; | static std::mutex global_memory_manager_reflock; | ||||
| static int global_memory_manager_refcount; | |||||
| static MTLBufferPool *global_memory_manager; | |||||
fclem: Shouldn't these be protected for multithreading? (Render, IconRenderPreview etc...) | |||||
| /* CommandBuffer managers. */ | /* CommandBuffer managers. */ | ||||
| MTLCommandBufferManager main_command_buffer; | MTLCommandBufferManager main_command_buffer; | ||||
| private: | private: | ||||
| /* Parent Context. */ | /* Parent Context. */ | ||||
| GHOST_ContextCGL *ghost_context_; | GHOST_ContextCGL *ghost_context_; | ||||
| /* Render Passes and Frame-buffers. */ | /* Render Passes and Frame-buffers. */ | ||||
| ▲ Show 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | uint get_current_frame_index() | ||||
| return current_frame_index_; | return current_frame_index_; | ||||
| } | } | ||||
| MTLScratchBufferManager &get_scratchbuffer_manager() | MTLScratchBufferManager &get_scratchbuffer_manager() | ||||
| { | { | ||||
| return this->memory_manager; | return this->memory_manager; | ||||
| } | } | ||||
| static MTLBufferPool &get_global_memory_manager() | static void global_memory_manager_acquire_ref() | ||||
| { | |||||
| MTLContext::global_memory_manager_reflock.lock(); | |||||
| if (MTLContext::global_memory_manager == nullptr) { | |||||
| BLI_assert(MTLContext::global_memory_manager_refcount == 0); | |||||
| MTLContext::global_memory_manager = new MTLBufferPool(); | |||||
| } | |||||
| MTLContext::global_memory_manager_refcount++; | |||||
| MTLContext::global_memory_manager_reflock.unlock(); | |||||
| } | |||||
| static void global_memory_manager_release_ref() | |||||
| { | |||||
| MTLContext::global_memory_manager_reflock.lock(); | |||||
| MTLContext::global_memory_manager_refcount--; | |||||
| BLI_assert(MTLContext::global_memory_manager_refcount >= 0); | |||||
| BLI_assert(MTLContext::global_memory_manager != nullptr); | |||||
| if (MTLContext::global_memory_manager_refcount <= 0) { | |||||
| delete MTLContext::global_memory_manager; | |||||
| MTLContext::global_memory_manager = nullptr; | |||||
| } | |||||
| MTLContext::global_memory_manager_reflock.unlock(); | |||||
| } | |||||
| static MTLBufferPool *get_global_memory_manager() | |||||
| { | { | ||||
| BLI_assert(MTLContext::global_memory_manager != nullptr); | |||||
| return MTLContext::global_memory_manager; | return MTLContext::global_memory_manager; | ||||
| } | } | ||||
| /* Swap-chain and latency management. */ | /* Swap-chain and latency management. */ | ||||
| static void latency_resolve_average(int64_t frame_latency_us) | static void latency_resolve_average(int64_t frame_latency_us) | ||||
| { | { | ||||
| int64_t avg = 0; | int64_t avg = 0; | ||||
| int64_t frame_c = 0; | int64_t frame_c = 0; | ||||
| Show All 28 Lines | |||||
Shouldn't these be protected for multithreading? (Render, IconRenderPreview etc...)