Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Fielder <jason_apple>2022-03-22 14:38:28 +0300
committerClément Foucault <foucault.clem@gmail.com>2022-03-22 14:54:34 +0300
commit309ea314858a9b7892ea2c8a6fe55ab2a1028697 (patch)
treead153ceb5e7e90c5cac65b59b99bb2d708577dba /source/blender/gpu/intern
parent913b6b9ec1b1f3cf83b21956b06e2f6d3341c78c (diff)
Metal: Initial Implementation of Metal Backend for GPU Module.
Adding WITH_METAL option to CMAKE to guard compilation for macOS only. Implemented stub METALBackend to mirror GPUBackend interface and added capabilities initialisation, along with API initialisation paths. Global rendering coordination commands added to backend with GPU_render_begin and GPU_render_end() commands globally wrapping GPU work. This is required for Metal to ensure temporary resources are generated within an NSAutoReleasePool and freed accordingly. Authored by Apple: Michael Parkin-White, Vil Harvey, Marco Giordano, Michael Jones, Morteza Mostajabodaveh, Jason Fielder Ref T96261 Reviewed By: fclem Maniphest Tasks: T96261 Differential Revision: https://developer.blender.org/D14293
Diffstat (limited to 'source/blender/gpu/intern')
-rw-r--r--source/blender/gpu/intern/gpu_backend.hh6
-rw-r--r--source/blender/gpu/intern/gpu_capabilities_private.hh8
-rw-r--r--source/blender/gpu/intern/gpu_context.cc70
-rw-r--r--source/blender/gpu/intern/gpu_platform.cc9
-rw-r--r--source/blender/gpu/intern/gpu_platform_private.hh2
5 files changed, 92 insertions, 3 deletions
diff --git a/source/blender/gpu/intern/gpu_backend.hh b/source/blender/gpu/intern/gpu_backend.hh
index ad906c74980..6e07e6c3229 100644
--- a/source/blender/gpu/intern/gpu_backend.hh
+++ b/source/blender/gpu/intern/gpu_backend.hh
@@ -49,6 +49,12 @@ class GPUBackend {
virtual UniformBuf *uniformbuf_alloc(int size, const char *name) = 0;
virtual StorageBuf *storagebuf_alloc(int size, GPUUsageType usage, const char *name) = 0;
virtual VertBuf *vertbuf_alloc() = 0;
+
+ /* Render Frame Coordination --
+ * Used for performing per-frame actions globally */
+ virtual void render_begin() = 0;
+ virtual void render_end() = 0;
+ virtual void render_step() = 0;
};
} // namespace gpu
diff --git a/source/blender/gpu/intern/gpu_capabilities_private.hh b/source/blender/gpu/intern/gpu_capabilities_private.hh
index d645d82a879..4a951eb8458 100644
--- a/source/blender/gpu/intern/gpu_capabilities_private.hh
+++ b/source/blender/gpu/intern/gpu_capabilities_private.hh
@@ -20,11 +20,13 @@ namespace blender::gpu {
*/
struct GPUCapabilities {
int max_texture_size = 0;
+ int max_texture_3d_size = 0;
int max_texture_layers = 0;
int max_textures = 0;
int max_textures_vert = 0;
int max_textures_geom = 0;
int max_textures_frag = 0;
+ int max_samplers = 0;
int max_work_group_count[3] = {0, 0, 0};
int max_work_group_size[3] = {0, 0, 0};
int max_uniforms_vert = 0;
@@ -41,6 +43,8 @@ struct GPUCapabilities {
bool compute_shader_support = false;
bool shader_storage_buffer_objects_support = false;
bool shader_image_load_store_support = false;
+ bool transform_feedback_support = false;
+
/* OpenGL related workarounds. */
bool mip_render_workaround = false;
bool depth_blitting_workaround = false;
@@ -48,6 +52,10 @@ struct GPUCapabilities {
bool broken_amd_driver = false;
bool use_hq_normals_workaround = false;
/* Vulkan related workarounds. */
+
+ /* Metal related workarounds. */
+ /* Minimum per-vertex stride in bytes (For a vertex buffer). */
+ int minimum_per_vertex_stride = 1;
};
extern GPUCapabilities GCaps;
diff --git a/source/blender/gpu/intern/gpu_context.cc b/source/blender/gpu/intern/gpu_context.cc
index 60e95e09a99..5b40d3850a5 100644
--- a/source/blender/gpu/intern/gpu_context.cc
+++ b/source/blender/gpu/intern/gpu_context.cc
@@ -13,7 +13,9 @@
*/
/* TODO: Create cmake option. */
-#define WITH_OPENGL_BACKEND 1
+#if WITH_OPENGL
+ #define WITH_OPENGL_BACKEND 1
+#endif
#include "BLI_assert.h"
#include "BLI_utildefines.h"
@@ -32,6 +34,9 @@
# include "gl_backend.hh"
# include "gl_context.hh"
#endif
+#ifdef WITH_METAL_BACKEND
+# include "mtl_backend.hh"
+#endif
#include <mutex>
#include <vector>
@@ -141,21 +146,73 @@ void GPU_context_main_unlock()
/** \} */
/* -------------------------------------------------------------------- */
+/** \name GPU Begin/end work blocks
+ *
+ * Used to explicitly define a per-frame block within which GPU work will happen.
+ * Used for global autoreleasepool flushing in Metal
+ * \{ */
+
+void GPU_render_begin() {
+ GPUBackend* backend = GPUBackend::get();
+ BLI_assert(backend);
+ backend->render_begin();
+}
+void GPU_render_end() {
+ GPUBackend* backend = GPUBackend::get();
+ BLI_assert(backend);
+ backend->render_end();
+}
+void GPU_render_step() {
+ GPUBackend* backend = GPUBackend::get();
+ BLI_assert(backend);
+ backend->render_step();
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
/** \name Backend selection
* \{ */
static GPUBackend *g_backend;
+bool GPU_backend_supported(eGPUBackendType type)
+{
+ switch (type) {
+ case GPU_BACKEND_OPENGL:
+#ifdef WITH_OPENGL_BACKEND
+ return true;
+#else
+ return false;
+#endif
+ case GPU_BACKEND_METAL:
+#ifdef WITH_METAL_BACKEND
+ return MTLBackend::metal_is_supported();
+#else
+ return false;
+#endif
+ default:
+ BLI_assert(false && "No backend specified");
+ return false;
+ }
+}
+
void GPU_backend_init(eGPUBackendType backend_type)
{
BLI_assert(g_backend == nullptr);
+ BLI_assert(GPU_backend_supported(backend_type));
switch (backend_type) {
-#if WITH_OPENGL_BACKEND
+#ifdef WITH_OPENGL_BACKEND
case GPU_BACKEND_OPENGL:
g_backend = new GLBackend;
break;
#endif
+#ifdef WITH_METAL_BACKEND
+ case GPU_BACKEND_METAL:
+ g_backend = new MTLBackend;
+ break;
+#endif
default:
BLI_assert(0);
break;
@@ -172,9 +229,18 @@ void GPU_backend_exit()
eGPUBackendType GPU_backend_get_type()
{
+
+#ifdef WITH_OPENGL_BACKEND
if (g_backend && dynamic_cast<GLBackend *>(g_backend) != nullptr) {
return GPU_BACKEND_OPENGL;
}
+#endif
+
+#ifdef WITH_METAL_BACKEND
+ if (g_backend && dynamic_cast<MTLBackend *>(g_backend) != nullptr) {
+ return GPU_BACKEND_METAL;
+ }
+#endif
return GPU_BACKEND_NONE;
}
diff --git a/source/blender/gpu/intern/gpu_platform.cc b/source/blender/gpu/intern/gpu_platform.cc
index 969a3033c6f..8d4e80abd97 100644
--- a/source/blender/gpu/intern/gpu_platform.cc
+++ b/source/blender/gpu/intern/gpu_platform.cc
@@ -65,6 +65,7 @@ void GPUPlatformGlobal::init(eGPUDeviceType gpu_device,
eGPUOSType os_type,
eGPUDriverType driver_type,
eGPUSupportLevel gpu_support_level,
+ eGPUBackendType backend,
const char *vendor_str,
const char *renderer_str,
const char *version_str)
@@ -83,6 +84,7 @@ void GPUPlatformGlobal::init(eGPUDeviceType gpu_device,
this->version = BLI_strdup(version_str);
this->support_key = create_key(gpu_support_level, vendor_str, renderer_str, version_str);
this->gpu_name = create_gpu_name(vendor_str, renderer_str, version_str);
+ this->backend = backend;
}
void GPUPlatformGlobal::clear()
@@ -143,8 +145,13 @@ const char *GPU_platform_gpu_name()
bool GPU_type_matches(eGPUDeviceType device, eGPUOSType os, eGPUDriverType driver)
{
+ return GPU_type_matches_ex(device, os, driver, GPU_BACKEND_ANY);
+}
+
+bool GPU_type_matches_ex(eGPUDeviceType device, eGPUOSType os, eGPUDriverType driver, eGPUBackendType backend)
+{
BLI_assert(GPG.initialized);
- return (GPG.device & device) && (GPG.os & os) && (GPG.driver & driver);
+ return (GPG.device & device) && (GPG.os & os) && (GPG.driver & driver) && (GPG.backend & backend);
}
/** \} */
diff --git a/source/blender/gpu/intern/gpu_platform_private.hh b/source/blender/gpu/intern/gpu_platform_private.hh
index a6c400ad319..6e6c24a8662 100644
--- a/source/blender/gpu/intern/gpu_platform_private.hh
+++ b/source/blender/gpu/intern/gpu_platform_private.hh
@@ -23,12 +23,14 @@ class GPUPlatformGlobal {
char *version = nullptr;
char *support_key = nullptr;
char *gpu_name = nullptr;
+ eGPUBackendType backend = GPU_BACKEND_NONE;
public:
void init(eGPUDeviceType gpu_device,
eGPUOSType os_type,
eGPUDriverType driver_type,
eGPUSupportLevel gpu_support_level,
+ eGPUBackendType backend,
const char *vendor_str,
const char *renderer_str,
const char *version_str);