GHOST: Rename Metal Context from ContextCGL to ContextMTL
This commit renames the GHOST Metal graphic context class and related files / references from `GHOST_ContextCGL` to `GHOST_ContextMTL`. When the Metal backend was first introduced, this context file contained both the old OpenGL context (CGL, for macOS Core OpenGL API), and the newer Metal context. Since #110185 all CGL related code was removed from the class, making it Metal only, and thus rendering the old class name outdated and potentially misleading. In addition to the rename, unused OpenGL related forward declarations and old TODOs were also removed. Pull Request: https://projects.blender.org/blender/blender/pulls/142519
This commit is contained in:
@@ -517,9 +517,9 @@ endif()
|
||||
if(APPLE)
|
||||
if(WITH_METAL_BACKEND)
|
||||
list(APPEND SRC
|
||||
intern/GHOST_ContextCGL.mm
|
||||
intern/GHOST_ContextMTL.mm
|
||||
|
||||
intern/GHOST_ContextCGL.hh
|
||||
intern/GHOST_ContextMTL.hh
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -19,12 +19,9 @@
|
||||
@class MTLDevice;
|
||||
@class MTLRenderPipelineState;
|
||||
@class MTLTexture;
|
||||
@class NSOpenGLContext;
|
||||
@class NSOpenGLView;
|
||||
@class NSView;
|
||||
|
||||
class GHOST_ContextCGL : public GHOST_Context {
|
||||
|
||||
class GHOST_ContextMTL : public GHOST_Context {
|
||||
public:
|
||||
/* Defines the number of simultaneous command buffers which can be in flight.
|
||||
* The default limit of `64` is considered to be optimal for Blender. Too many command buffers
|
||||
@@ -44,12 +41,12 @@ class GHOST_ContextCGL : public GHOST_Context {
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
GHOST_ContextCGL(bool stereoVisual, NSView *metalView, CAMetalLayer *metalLayer, int debug);
|
||||
GHOST_ContextMTL(bool stereoVisual, NSView *metalView, CAMetalLayer *metalLayer, int debug);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~GHOST_ContextCGL() override;
|
||||
~GHOST_ContextMTL() override;
|
||||
|
||||
/**
|
||||
* Swaps front and back buffers of a window.
|
||||
@@ -5,7 +5,7 @@
|
||||
/** \file
|
||||
* \ingroup GHOST
|
||||
*
|
||||
* Definition of GHOST_ContextCGL class.
|
||||
* Definition of GHOST_ContextMTL class.
|
||||
*/
|
||||
|
||||
/* Don't generate OpenGL deprecation warning. This is a known thing, and is not something easily
|
||||
@@ -14,7 +14,7 @@
|
||||
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
|
||||
#include "GHOST_ContextCGL.hh"
|
||||
#include "GHOST_ContextMTL.hh"
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <Metal/Metal.h>
|
||||
@@ -43,10 +43,10 @@ static void ghost_fatal_error_dialog(const char *msg)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
MTLCommandQueue *GHOST_ContextCGL::s_sharedMetalCommandQueue = nil;
|
||||
int GHOST_ContextCGL::s_sharedCount = 0;
|
||||
MTLCommandQueue *GHOST_ContextMTL::s_sharedMetalCommandQueue = nil;
|
||||
int GHOST_ContextMTL::s_sharedCount = 0;
|
||||
|
||||
GHOST_ContextCGL::GHOST_ContextCGL(bool stereoVisual,
|
||||
GHOST_ContextMTL::GHOST_ContextMTL(bool stereoVisual,
|
||||
NSView *metalView,
|
||||
CAMetalLayer *metalLayer,
|
||||
int debug)
|
||||
@@ -114,7 +114,7 @@ GHOST_ContextCGL::GHOST_ContextCGL(bool stereoVisual,
|
||||
}
|
||||
}
|
||||
|
||||
GHOST_ContextCGL::~GHOST_ContextCGL()
|
||||
GHOST_ContextMTL::~GHOST_ContextMTL()
|
||||
{
|
||||
metalFree();
|
||||
|
||||
@@ -133,7 +133,7 @@ GHOST_ContextCGL::~GHOST_ContextCGL()
|
||||
}
|
||||
}
|
||||
|
||||
GHOST_TSuccess GHOST_ContextCGL::swapBuffers()
|
||||
GHOST_TSuccess GHOST_ContextMTL::swapBuffers()
|
||||
{
|
||||
if (m_metalView) {
|
||||
metalSwapBuffers();
|
||||
@@ -141,37 +141,37 @@ GHOST_TSuccess GHOST_ContextCGL::swapBuffers()
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
|
||||
GHOST_TSuccess GHOST_ContextCGL::setSwapInterval(int interval)
|
||||
GHOST_TSuccess GHOST_ContextMTL::setSwapInterval(int interval)
|
||||
{
|
||||
mtl_SwapInterval = interval;
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
|
||||
GHOST_TSuccess GHOST_ContextCGL::getSwapInterval(int &intervalOut)
|
||||
GHOST_TSuccess GHOST_ContextMTL::getSwapInterval(int &intervalOut)
|
||||
{
|
||||
intervalOut = mtl_SwapInterval;
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
|
||||
GHOST_TSuccess GHOST_ContextCGL::activateDrawingContext()
|
||||
GHOST_TSuccess GHOST_ContextMTL::activateDrawingContext()
|
||||
{
|
||||
active_context_ = this;
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
|
||||
GHOST_TSuccess GHOST_ContextCGL::releaseDrawingContext()
|
||||
GHOST_TSuccess GHOST_ContextMTL::releaseDrawingContext()
|
||||
{
|
||||
active_context_ = nullptr;
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
|
||||
unsigned int GHOST_ContextCGL::getDefaultFramebuffer()
|
||||
unsigned int GHOST_ContextMTL::getDefaultFramebuffer()
|
||||
{
|
||||
/* NOTE(Metal): This is not valid. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
GHOST_TSuccess GHOST_ContextCGL::updateDrawingContext()
|
||||
GHOST_TSuccess GHOST_ContextMTL::updateDrawingContext()
|
||||
{
|
||||
if (m_metalView) {
|
||||
metalUpdateFramebuffer();
|
||||
@@ -180,7 +180,7 @@ GHOST_TSuccess GHOST_ContextCGL::updateDrawingContext()
|
||||
return GHOST_kFailure;
|
||||
}
|
||||
|
||||
id<MTLTexture> GHOST_ContextCGL::metalOverlayTexture()
|
||||
id<MTLTexture> GHOST_ContextMTL::metalOverlayTexture()
|
||||
{
|
||||
/* Increment Swap-chain - Only needed if context is requesting a new texture */
|
||||
current_swapchain_index = (current_swapchain_index + 1) % METAL_SWAPCHAIN_SIZE;
|
||||
@@ -192,23 +192,23 @@ id<MTLTexture> GHOST_ContextCGL::metalOverlayTexture()
|
||||
return m_defaultFramebufferMetalTexture[current_swapchain_index].texture;
|
||||
}
|
||||
|
||||
MTLCommandQueue *GHOST_ContextCGL::metalCommandQueue()
|
||||
MTLCommandQueue *GHOST_ContextMTL::metalCommandQueue()
|
||||
{
|
||||
return s_sharedMetalCommandQueue;
|
||||
}
|
||||
MTLDevice *GHOST_ContextCGL::metalDevice()
|
||||
MTLDevice *GHOST_ContextMTL::metalDevice()
|
||||
{
|
||||
id<MTLDevice> device = m_metalLayer.device;
|
||||
return (MTLDevice *)device;
|
||||
}
|
||||
|
||||
void GHOST_ContextCGL::metalRegisterPresentCallback(void (*callback)(
|
||||
void GHOST_ContextMTL::metalRegisterPresentCallback(void (*callback)(
|
||||
MTLRenderPassDescriptor *, id<MTLRenderPipelineState>, id<MTLTexture>, id<CAMetalDrawable>))
|
||||
{
|
||||
this->contextPresentCallback = callback;
|
||||
}
|
||||
|
||||
GHOST_TSuccess GHOST_ContextCGL::initializeDrawingContext()
|
||||
GHOST_TSuccess GHOST_ContextMTL::initializeDrawingContext()
|
||||
{
|
||||
@autoreleasepool {
|
||||
if (m_metalView) {
|
||||
@@ -219,14 +219,14 @@ GHOST_TSuccess GHOST_ContextCGL::initializeDrawingContext()
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
|
||||
GHOST_TSuccess GHOST_ContextCGL::releaseNativeHandles()
|
||||
GHOST_TSuccess GHOST_ContextMTL::releaseNativeHandles()
|
||||
{
|
||||
m_metalView = nil;
|
||||
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
|
||||
void GHOST_ContextCGL::metalInit()
|
||||
void GHOST_ContextMTL::metalInit()
|
||||
{
|
||||
@autoreleasepool {
|
||||
id<MTLDevice> device = m_metalLayer.device;
|
||||
@@ -236,7 +236,7 @@ void GHOST_ContextCGL::metalInit()
|
||||
* to ensure correct ordering of work submitted from multiple contexts. */
|
||||
if (s_sharedMetalCommandQueue == nil) {
|
||||
s_sharedMetalCommandQueue = (MTLCommandQueue *)[device
|
||||
newCommandQueueWithMaxCommandBufferCount:GHOST_ContextCGL::max_command_buffer_count];
|
||||
newCommandQueueWithMaxCommandBufferCount:GHOST_ContextMTL::max_command_buffer_count];
|
||||
}
|
||||
/* Ensure active GHOSTContext retains a reference to the shared context. */
|
||||
[s_sharedMetalCommandQueue retain];
|
||||
@@ -284,7 +284,7 @@ void GHOST_ContextCGL::metalInit()
|
||||
id<MTLLibrary> library = [device newLibraryWithSource:source options:options error:&error];
|
||||
if (error) {
|
||||
ghost_fatal_error_dialog(
|
||||
"GHOST_ContextCGL::metalInit: newLibraryWithSource:options:error: failed!");
|
||||
"GHOST_ContextMTL::metalInit: newLibraryWithSource:options:error: failed!");
|
||||
}
|
||||
|
||||
/* Create a render pipeline for blit operation. */
|
||||
@@ -303,7 +303,7 @@ void GHOST_ContextCGL::metalInit()
|
||||
error:&error];
|
||||
if (error) {
|
||||
ghost_fatal_error_dialog(
|
||||
"GHOST_ContextCGL::metalInit: newRenderPipelineStateWithDescriptor:error: failed!");
|
||||
"GHOST_ContextMTL::metalInit: newRenderPipelineStateWithDescriptor:error: failed!");
|
||||
}
|
||||
|
||||
/* Create a render pipeline to composite things rendered with Metal on top
|
||||
@@ -316,7 +316,7 @@ void GHOST_ContextCGL::metalInit()
|
||||
|
||||
if (error) {
|
||||
ghost_fatal_error_dialog(
|
||||
"GHOST_ContextCGL::metalInit: newRenderPipelineStateWithDescriptor:error: failed (when "
|
||||
"GHOST_ContextMTL::metalInit: newRenderPipelineStateWithDescriptor:error: failed (when "
|
||||
"creating the Metal overlay pipeline)!");
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ void GHOST_ContextCGL::metalInit()
|
||||
}
|
||||
}
|
||||
|
||||
void GHOST_ContextCGL::metalFree()
|
||||
void GHOST_ContextMTL::metalFree()
|
||||
{
|
||||
if (m_metalRenderPipeline) {
|
||||
[m_metalRenderPipeline release];
|
||||
@@ -340,12 +340,12 @@ void GHOST_ContextCGL::metalFree()
|
||||
}
|
||||
}
|
||||
|
||||
void GHOST_ContextCGL::metalInitFramebuffer()
|
||||
void GHOST_ContextMTL::metalInitFramebuffer()
|
||||
{
|
||||
updateDrawingContext();
|
||||
}
|
||||
|
||||
void GHOST_ContextCGL::metalUpdateFramebuffer()
|
||||
void GHOST_ContextMTL::metalUpdateFramebuffer()
|
||||
{
|
||||
@autoreleasepool {
|
||||
const NSRect bounds = [m_metalView bounds];
|
||||
@@ -375,7 +375,7 @@ void GHOST_ContextCGL::metalUpdateFramebuffer()
|
||||
id<MTLTexture> overlayTex = [device newTextureWithDescriptor:overlayDesc];
|
||||
if (!overlayTex) {
|
||||
ghost_fatal_error_dialog(
|
||||
"GHOST_ContextCGL::metalUpdateFramebuffer: failed to create Metal overlay texture!");
|
||||
"GHOST_ContextMTL::metalUpdateFramebuffer: failed to create Metal overlay texture!");
|
||||
}
|
||||
else {
|
||||
overlayTex.label = [NSString
|
||||
@@ -405,7 +405,7 @@ void GHOST_ContextCGL::metalUpdateFramebuffer()
|
||||
}
|
||||
}
|
||||
|
||||
void GHOST_ContextCGL::metalSwapBuffers()
|
||||
void GHOST_ContextMTL::metalSwapBuffers()
|
||||
{
|
||||
@autoreleasepool {
|
||||
updateDrawingContext();
|
||||
@@ -23,7 +23,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef WITH_METAL_BACKEND
|
||||
# include "GHOST_ContextCGL.hh"
|
||||
# include "GHOST_ContextMTL.hh"
|
||||
#endif
|
||||
|
||||
#ifdef WITH_VULKAN_BACKEND
|
||||
@@ -793,8 +793,7 @@ GHOST_IContext *GHOST_SystemCocoa::createOffscreenContext(GHOST_GPUSettings gpuS
|
||||
|
||||
#ifdef WITH_METAL_BACKEND
|
||||
case GHOST_kDrawingContextTypeMetal: {
|
||||
/* TODO(fclem): Remove OpenGL support and rename context to ContextMTL */
|
||||
GHOST_Context *context = new GHOST_ContextCGL(false, nullptr, nullptr, debug_context);
|
||||
GHOST_Context *context = new GHOST_ContextMTL(false, nullptr, nullptr, debug_context);
|
||||
if (context->initializeDrawingContext()) {
|
||||
return context;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef WITH_METAL_BACKEND
|
||||
# include "GHOST_ContextCGL.hh"
|
||||
# include "GHOST_ContextMTL.hh"
|
||||
#endif
|
||||
|
||||
#ifdef WITH_VULKAN_BACKEND
|
||||
@@ -911,7 +911,7 @@ GHOST_Context *GHOST_WindowCocoa::newDrawingContext(GHOST_TDrawingContextType ty
|
||||
|
||||
#ifdef WITH_METAL_BACKEND
|
||||
case GHOST_kDrawingContextTypeMetal: {
|
||||
GHOST_Context *context = new GHOST_ContextCGL(
|
||||
GHOST_Context *context = new GHOST_ContextMTL(
|
||||
m_wantStereoVisual, m_metalView, m_metalLayer, false);
|
||||
if (context->initializeDrawingContext()) {
|
||||
return context;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "mtl_debug.hh"
|
||||
#include "mtl_framebuffer.hh"
|
||||
|
||||
#include "intern/GHOST_ContextCGL.hh"
|
||||
#include "intern/GHOST_ContextMTL.hh"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
@@ -51,7 +51,7 @@ id<MTLCommandBuffer> MTLCommandBufferManager::ensure_begin()
|
||||
* NOTE: We currently stall until completion of GPU work upon ::submit if we have reached the
|
||||
* in-flight command buffer limit. */
|
||||
BLI_assert(MTLCommandBufferManager::num_active_cmd_bufs_in_system <
|
||||
GHOST_ContextCGL::max_command_buffer_count);
|
||||
GHOST_ContextMTL::max_command_buffer_count);
|
||||
|
||||
if (G.debug & G_DEBUG_GPU) {
|
||||
/* Debug: Enable Advanced Errors for GPU work execution. */
|
||||
@@ -138,12 +138,12 @@ bool MTLCommandBufferManager::submit(bool wait)
|
||||
/* If we have too many active command buffers in flight, wait until completed to avoid running
|
||||
* out. We can increase */
|
||||
if (MTLCommandBufferManager::num_active_cmd_bufs_in_system >=
|
||||
(GHOST_ContextCGL::max_command_buffer_count - 1))
|
||||
(GHOST_ContextMTL::max_command_buffer_count - 1))
|
||||
{
|
||||
wait = true;
|
||||
MTL_LOG_WARNING(
|
||||
"Maximum number of command buffers in flight. Host will wait until GPU work has "
|
||||
"completed. Consider increasing GHOST_ContextCGL::max_command_buffer_count or reducing "
|
||||
"completed. Consider increasing GHOST_ContextMTL::max_command_buffer_count or reducing "
|
||||
"work fragmentation to better utilize system hardware. Command buffers are flushed upon "
|
||||
"GPUContext switches, this is the most common cause of excessive command buffer "
|
||||
"generation.");
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#endif
|
||||
|
||||
#include "intern/GHOST_Context.hh"
|
||||
#include "intern/GHOST_ContextCGL.hh"
|
||||
#include "intern/GHOST_ContextMTL.hh"
|
||||
#include "intern/GHOST_Window.hh"
|
||||
|
||||
#include "mtl_backend.hh"
|
||||
@@ -728,7 +728,7 @@ class MTLContext : public Context {
|
||||
|
||||
private:
|
||||
/* Parent Context. */
|
||||
GHOST_ContextCGL *ghost_context_;
|
||||
GHOST_ContextMTL *ghost_context_;
|
||||
|
||||
/* Render Passes and Frame-buffers. */
|
||||
id<MTLTexture> default_fbo_mtltexture_ = nil;
|
||||
|
||||
@@ -98,13 +98,13 @@ void MTLContext::set_ghost_context(GHOST_ContextHandle ghostCtxHandle)
|
||||
mtl_front_left->remove_all_attachments();
|
||||
mtl_back_left->remove_all_attachments();
|
||||
|
||||
GHOST_ContextCGL *ghost_cgl_ctx = dynamic_cast<GHOST_ContextCGL *>(ghost_ctx);
|
||||
if (ghost_cgl_ctx != nullptr) {
|
||||
default_fbo_mtltexture_ = ghost_cgl_ctx->metalOverlayTexture();
|
||||
GHOST_ContextMTL *ghost_mtl_ctx = dynamic_cast<GHOST_ContextMTL *>(ghost_ctx);
|
||||
if (ghost_mtl_ctx != nullptr) {
|
||||
default_fbo_mtltexture_ = ghost_mtl_ctx->metalOverlayTexture();
|
||||
|
||||
MTL_LOG_DEBUG(
|
||||
"Binding GHOST context CGL %p to GPU context %p. (Device: %p, queue: %p, texture: %p)",
|
||||
ghost_cgl_ctx,
|
||||
"Binding GHOST context MTL %p to GPU context %p. (Device: %p, queue: %p, texture: %p)",
|
||||
ghost_mtl_ctx,
|
||||
this,
|
||||
this->device,
|
||||
this->queue,
|
||||
@@ -154,7 +154,7 @@ void MTLContext::set_ghost_context(GHOST_ContextHandle ghostCtxHandle)
|
||||
MTL_LOG_DEBUG(
|
||||
"-- Bound context %p for GPU context: %p is offscreen and does not have a default "
|
||||
"framebuffer",
|
||||
ghost_cgl_ctx,
|
||||
ghost_mtl_ctx,
|
||||
this);
|
||||
#ifndef NDEBUG
|
||||
this->label = @"Offscreen Metal Context";
|
||||
@@ -163,10 +163,10 @@ void MTLContext::set_ghost_context(GHOST_ContextHandle ghostCtxHandle)
|
||||
}
|
||||
else {
|
||||
MTL_LOG_DEBUG(
|
||||
" Failed to bind GHOST context to MTLContext -- GHOST_ContextCGL is null "
|
||||
"(GhostContext: %p, GhostContext_CGL: %p)",
|
||||
" Failed to bind GHOST context to MTLContext -- GHOST_ContextMTL is null "
|
||||
"(GhostContext: %p, GhostContext_MTL: %p)",
|
||||
ghost_ctx,
|
||||
ghost_cgl_ctx);
|
||||
ghost_mtl_ctx);
|
||||
BLI_assert(false);
|
||||
}
|
||||
}
|
||||
@@ -221,7 +221,7 @@ MTLContext::MTLContext(void *ghost_window, void *ghost_context)
|
||||
ghost_context = (ghostWin ? ghostWin->getContext() : nullptr);
|
||||
}
|
||||
BLI_assert(ghost_context);
|
||||
this->ghost_context_ = static_cast<GHOST_ContextCGL *>(ghost_context);
|
||||
this->ghost_context_ = static_cast<GHOST_ContextMTL *>(ghost_context);
|
||||
this->queue = (id<MTLCommandQueue>)this->ghost_context_->metalCommandQueue();
|
||||
this->device = (id<MTLDevice>)this->ghost_context_->metalDevice();
|
||||
BLI_assert(this->queue);
|
||||
|
||||
Reference in New Issue
Block a user