Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/metal/mtl_backend.mm
| /* SPDX-License-Identifier: GPL-2.0-or-later */ | /* SPDX-License-Identifier: GPL-2.0-or-later */ | ||||
| /** \file | /** \file | ||||
| * \ingroup gpu | * \ingroup gpu | ||||
| */ | */ | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "gpu_backend.hh" | #include "gpu_backend.hh" | ||||
| #include "mtl_backend.hh" | #include "mtl_backend.hh" | ||||
| #include "mtl_context.hh" | #include "mtl_context.hh" | ||||
| #include "mtl_framebuffer.hh" | #include "mtl_framebuffer.hh" | ||||
| #include "mtl_index_buffer.hh" | #include "mtl_index_buffer.hh" | ||||
| #include "mtl_query.hh" | #include "mtl_query.hh" | ||||
| #include "mtl_shader.hh" | |||||
| #include "mtl_uniform_buffer.hh" | #include "mtl_uniform_buffer.hh" | ||||
| #include "gpu_capabilities_private.hh" | #include "gpu_capabilities_private.hh" | ||||
| #include "gpu_platform_private.hh" | #include "gpu_platform_private.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> | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
| QueryPool *MTLBackend::querypool_alloc() | QueryPool *MTLBackend::querypool_alloc() | ||||
| { | { | ||||
| return new MTLQueryPool(); | return new MTLQueryPool(); | ||||
| }; | }; | ||||
| Shader *MTLBackend::shader_alloc(const char *name) | Shader *MTLBackend::shader_alloc(const char *name) | ||||
| { | { | ||||
| /* TODO(Metal): Implement MTLShader. */ | MTLContext *mtl_context = MTLContext::get(); | ||||
| return nullptr; | return new MTLShader(mtl_context, name); | ||||
| }; | }; | ||||
| Texture *MTLBackend::texture_alloc(const char *name) | Texture *MTLBackend::texture_alloc(const char *name) | ||||
| { | { | ||||
| return new gpu::MTLTexture(name); | return new gpu::MTLTexture(name); | ||||
| } | } | ||||
| UniformBuf *MTLBackend::uniformbuf_alloc(int size, const char *name) | UniformBuf *MTLBackend::uniformbuf_alloc(int size, const char *name) | ||||
| ▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | void MTLBackend::platform_init(MTLContext *ctx) | ||||
| } | } | ||||
| eGPUDeviceType device = GPU_DEVICE_UNKNOWN; | eGPUDeviceType device = GPU_DEVICE_UNKNOWN; | ||||
| eGPUOSType os = GPU_OS_ANY; | eGPUOSType os = GPU_OS_ANY; | ||||
| eGPUDriverType driver = GPU_DRIVER_ANY; | eGPUDriverType driver = GPU_DRIVER_ANY; | ||||
| eGPUSupportLevel support_level = GPU_SUPPORT_LEVEL_SUPPORTED; | eGPUSupportLevel support_level = GPU_SUPPORT_LEVEL_SUPPORTED; | ||||
| BLI_assert(ctx); | BLI_assert(ctx); | ||||
| id<MTLDevice> mtl_device = nil; /*ctx->device; TODO(Metal): Implement MTLContext. */ | id<MTLDevice> mtl_device = ctx->device; | ||||
| BLI_assert(device); | BLI_assert(device); | ||||
| NSString *gpu_name = [mtl_device name]; | NSString *gpu_name = [mtl_device name]; | ||||
| const char *vendor = [gpu_name UTF8String]; | const char *vendor = [gpu_name UTF8String]; | ||||
| const char *renderer = "Metal API"; | const char *renderer = "Metal API"; | ||||
| const char *version = "1.2"; | const char *version = "1.2"; | ||||
| printf("METAL API - DETECTED GPU: %s\n", vendor); | printf("METAL API - DETECTED GPU: %s\n", vendor); | ||||
| /* macOS is the only supported platform, but check to ensure we are not building with Metal | /* macOS is the only supported platform, but check to ensure we are not building with Metal | ||||
| * enablement on another platform. */ | * enablement on another platform. */ | ||||
| #ifdef _WIN32 | #ifdef _WIN32 | ||||
| os = GPU_OS_WIN; | os = GPU_OS_WIN; | ||||
| #elif defined(__APPLE__) | #elif defined(__APPLE__) | ||||
| os = GPU_OS_MAC; | os = GPU_OS_MAC; | ||||
| #else | #else | ||||
| os = GPU_OS_UNIX; | os = GPU_OS_UNIX; | ||||
| #endif | #endif | ||||
| BLI_assert(os == GPU_OS_MAC && "Platform must be macOS"); | BLI_assert_msg(os == GPU_OS_MAC, "Platform must be macOS"); | ||||
| /* Determine Vendor from name. */ | /* Determine Vendor from name. */ | ||||
| if (strstr(vendor, "ATI") || strstr(vendor, "AMD")) { | if (strstr(vendor, "ATI") || strstr(vendor, "AMD")) { | ||||
| device = GPU_DEVICE_ATI; | device = GPU_DEVICE_ATI; | ||||
| driver = GPU_DRIVER_OFFICIAL; | driver = GPU_DRIVER_OFFICIAL; | ||||
| } | } | ||||
| else if (strstr(vendor, "NVIDIA")) { | else if (strstr(vendor, "NVIDIA")) { | ||||
| device = GPU_DEVICE_NVIDIA; | device = GPU_DEVICE_NVIDIA; | ||||
| ▲ Show 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | if (@available(macOS 10.15, *)) { | ||||
| return result; | return result; | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| void MTLBackend::capabilities_init(MTLContext *ctx) | void MTLBackend::capabilities_init(MTLContext *ctx) | ||||
| { | { | ||||
| BLI_assert(ctx); | BLI_assert(ctx); | ||||
| id<MTLDevice> device = nil; /*ctx->device TODO(Metal): Implement MTLContext. */ | id<MTLDevice> device = ctx->device; | ||||
| BLI_assert(device); | BLI_assert(device); | ||||
| /* Initialize Capabilities. */ | /* Initialize Capabilities. */ | ||||
| MTLBackend::capabilities.supports_argument_buffers_tier2 = ([device argumentBuffersSupport] == | MTLBackend::capabilities.supports_argument_buffers_tier2 = ([device argumentBuffersSupport] == | ||||
| MTLArgumentBuffersTier2); | MTLArgumentBuffersTier2); | ||||
| MTLBackend::capabilities.supports_family_mac1 = [device supportsFamily:MTLGPUFamilyMac1]; | MTLBackend::capabilities.supports_family_mac1 = [device supportsFamily:MTLGPUFamilyMac1]; | ||||
| MTLBackend::capabilities.supports_family_mac2 = [device supportsFamily:MTLGPUFamilyMac2]; | MTLBackend::capabilities.supports_family_mac2 = [device supportsFamily:MTLGPUFamilyMac2]; | ||||
| MTLBackend::capabilities.supports_family_mac_catalyst1 = [device | MTLBackend::capabilities.supports_family_mac_catalyst1 = [device | ||||
| ▲ Show 20 Lines • Show All 83 Lines • Show Last 20 Lines | |||||