diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2020-09-07 16:39:47 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2020-09-07 20:37:04 +0300 |
commit | 360489c75167d47653bc34ad9ba9a65076bf384c (patch) | |
tree | f4d28e3add0893ae47146314d893e925dc30120e /source/blender | |
parent | 9cac181fbead28c0bf963bf2b9f82fddf3c2b7df (diff) |
GPUPlatform: GL backend isolation
Part of the vulkan implementation T68990.
Pretty straight forward. Just move the GL code inside the GLBackend and
make the GPUPlatformGlobal a class object.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/gpu/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_init_exit.c | 2 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_platform.cc | 217 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_platform_private.hh | 53 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_private.h | 4 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_backend.cc | 135 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_backend.hh | 9 |
7 files changed, 250 insertions, 172 deletions
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 5cce4f84aea..47ce113230b 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -87,6 +87,7 @@ set(SRC intern/gpu_vertex_format.cc intern/gpu_viewport.c + opengl/gl_backend.cc opengl/gl_batch.cc opengl/gl_context.cc opengl/gl_drawlist.cc @@ -143,6 +144,7 @@ set(SRC intern/gpu_matrix_private.h intern/gpu_node_graph.h intern/gpu_private.h + intern/gpu_platform_private.hh intern/gpu_select_private.h intern/gpu_shader_private.hh intern/gpu_shader_interface.hh diff --git a/source/blender/gpu/intern/gpu_init_exit.c b/source/blender/gpu/intern/gpu_init_exit.c index 4cb43db9bce..f265d841922 100644 --- a/source/blender/gpu/intern/gpu_init_exit.c +++ b/source/blender/gpu/intern/gpu_init_exit.c @@ -48,7 +48,6 @@ void GPU_init(void) } initialized = true; - gpu_platform_init(); gpu_extensions_init(); /* must come first */ gpu_codegen_init(); @@ -81,7 +80,6 @@ void GPU_exit(void) gpu_codegen_exit(); gpu_extensions_exit(); - gpu_platform_exit(); /* must come last */ initialized = false; } diff --git a/source/blender/gpu/intern/gpu_platform.cc b/source/blender/gpu/intern/gpu_platform.cc index 5cabde61bc3..e4db8c93f1d 100644 --- a/source/blender/gpu/intern/gpu_platform.cc +++ b/source/blender/gpu/intern/gpu_platform.cc @@ -23,75 +23,31 @@ * Wrap OpenGL features such as textures, shaders and GLSL * with checks for drivers and GPU support. */ -#include "GPU_platform.h" -#include "GPU_glew.h" -#include "gpu_private.h" -#include <string.h> +#include "MEM_guardedalloc.h" #include "BLI_dynstr.h" #include "BLI_string.h" -#include "MEM_guardedalloc.h" +#include "GPU_platform.h" -static struct GPUPlatformGlobal { - bool initialized; - eGPUDeviceType device; - eGPUOSType os; - eGPUDriverType driver; - eGPUSupportLevel support_level; - char *support_key; - char *gpu_name; -} GPG = {false}; - -/* Remove this? */ -#if 0 -typedef struct GPUPlatformSupportTest { - eGPUSupportLevel support_level; - eGPUDeviceType device; - eGPUOSType os; - eGPUDriverType driver; - const char *vendor; - const char *renderer; - const char *version; -} GPUPlatformSupportTest; -#endif +#include "gpu_platform_private.hh" -eGPUSupportLevel GPU_platform_support_level(void) -{ - return GPG.support_level; -} +/* -------------------------------------------------------------------- */ +/** \name GPUPlatformGlobal + * \{ */ -const char *GPU_platform_support_level_key(void) -{ - return GPG.support_key; -} +namespace blender::gpu { -const char *GPU_platform_gpu_name(void) -{ - return GPG.gpu_name; -} +GPUPlatformGlobal GPG; -/* GPU Types */ -bool GPU_type_matches(eGPUDeviceType device, eGPUOSType os, eGPUDriverType driver) -{ - return (GPG.device & device) && (GPG.os & os) && (GPG.driver & driver); -} - -static char *gpu_platform_create_key(eGPUSupportLevel support_level, - const char *vendor, - const char *renderer, - const char *version) +void GPUPlatformGlobal::create_key(eGPUSupportLevel support_level, + const char *vendor, + const char *renderer, + const char *version) { DynStr *ds = BLI_dynstr_new(); - BLI_dynstr_append(ds, "{"); - BLI_dynstr_append(ds, vendor); - BLI_dynstr_append(ds, "/"); - BLI_dynstr_append(ds, renderer); - BLI_dynstr_append(ds, "/"); - BLI_dynstr_append(ds, version); - BLI_dynstr_append(ds, "}"); - BLI_dynstr_append(ds, "="); + BLI_dynstr_appendf(ds, "{%s/%s/%s}=", vendor, renderer, version); if (support_level == GPU_SUPPORT_LEVEL_SUPPORTED) { BLI_dynstr_append(ds, "SUPPORTED"); } @@ -102,132 +58,61 @@ static char *gpu_platform_create_key(eGPUSupportLevel support_level, BLI_dynstr_append(ds, "UNSUPPORTED"); } - char *support_key = BLI_dynstr_get_cstring(ds); + support_key = BLI_dynstr_get_cstring(ds); BLI_dynstr_free(ds); BLI_str_replace_char(support_key, '\n', ' '); BLI_str_replace_char(support_key, '\r', ' '); - return support_key; } -static char *gpu_platform_create_gpu_name(const char *vendor, - const char *renderer, - const char *version) +void GPUPlatformGlobal::create_gpu_name(const char *vendor, + const char *renderer, + const char *version) { DynStr *ds = BLI_dynstr_new(); - BLI_dynstr_append(ds, vendor); - BLI_dynstr_append(ds, " "); - BLI_dynstr_append(ds, renderer); - BLI_dynstr_append(ds, " "); - BLI_dynstr_append(ds, version); + BLI_dynstr_appendf(ds, "%s %s %s", vendor, renderer, version); - char *gpu_name = BLI_dynstr_get_cstring(ds); + gpu_name = BLI_dynstr_get_cstring(ds); BLI_dynstr_free(ds); BLI_str_replace_char(gpu_name, '\n', ' '); BLI_str_replace_char(gpu_name, '\r', ' '); - return gpu_name; } -void gpu_platform_init(void) +void GPUPlatformGlobal::clear(void) { - if (GPG.initialized) { - return; - } + MEM_SAFE_FREE(GPG.support_key); + MEM_SAFE_FREE(GPG.gpu_name); + initialized = false; +} -#ifdef _WIN32 - GPG.os = GPU_OS_WIN; -#elif defined(__APPLE__) - GPG.os = GPU_OS_MAC; -#else - GPG.os = GPU_OS_UNIX; -#endif - - const char *vendor = (const char *)glGetString(GL_VENDOR); - const char *renderer = (const char *)glGetString(GL_RENDERER); - const char *version = (const char *)glGetString(GL_VERSION); - - if (strstr(vendor, "ATI") || strstr(vendor, "AMD")) { - GPG.device = GPU_DEVICE_ATI; - GPG.driver = GPU_DRIVER_OFFICIAL; - } - else if (strstr(vendor, "NVIDIA")) { - GPG.device = GPU_DEVICE_NVIDIA; - GPG.driver = GPU_DRIVER_OFFICIAL; - } - else if (strstr(vendor, "Intel") || - /* src/mesa/drivers/dri/intel/intel_context.c */ - strstr(renderer, "Mesa DRI Intel") || strstr(renderer, "Mesa DRI Mobile Intel")) { - GPG.device = GPU_DEVICE_INTEL; - GPG.driver = GPU_DRIVER_OFFICIAL; - - if (strstr(renderer, "UHD Graphics") || - /* Not UHD but affected by the same bugs. */ - strstr(renderer, "HD Graphics 530") || strstr(renderer, "Kaby Lake GT2") || - strstr(renderer, "Whiskey Lake")) { - GPG.device |= GPU_DEVICE_INTEL_UHD; - } - } - else if ((strstr(renderer, "Mesa DRI R")) || - (strstr(renderer, "Radeon") && strstr(vendor, "X.Org")) || - (strstr(renderer, "AMD") && strstr(vendor, "X.Org")) || - (strstr(renderer, "Gallium ") && strstr(renderer, " on ATI ")) || - (strstr(renderer, "Gallium ") && strstr(renderer, " on AMD "))) { - GPG.device = GPU_DEVICE_ATI; - GPG.driver = GPU_DRIVER_OPENSOURCE; - } - else if (strstr(renderer, "Nouveau") || strstr(vendor, "nouveau")) { - GPG.device = GPU_DEVICE_NVIDIA; - GPG.driver = GPU_DRIVER_OPENSOURCE; - } - else if (strstr(vendor, "Mesa")) { - GPG.device = GPU_DEVICE_SOFTWARE; - GPG.driver = GPU_DRIVER_SOFTWARE; - } - else if (strstr(vendor, "Microsoft")) { - GPG.device = GPU_DEVICE_SOFTWARE; - GPG.driver = GPU_DRIVER_SOFTWARE; - } - else if (strstr(renderer, "Apple Software Renderer")) { - GPG.device = GPU_DEVICE_SOFTWARE; - GPG.driver = GPU_DRIVER_SOFTWARE; - } - else if (strstr(renderer, "llvmpipe") || strstr(renderer, "softpipe")) { - GPG.device = GPU_DEVICE_SOFTWARE; - GPG.driver = GPU_DRIVER_SOFTWARE; - } - else { - printf("Warning: Could not find a matching GPU name. Things may not behave as expected.\n"); - printf("Detected OpenGL configuration:\n"); - printf("Vendor: %s\n", vendor); - printf("Renderer: %s\n", renderer); - GPG.device = GPU_DEVICE_ANY; - GPG.driver = GPU_DRIVER_ANY; - } +} // namespace blender::gpu - /* Detect support level */ - if (!GLEW_VERSION_3_3) { - GPG.support_level = GPU_SUPPORT_LEVEL_UNSUPPORTED; - } - else { - if (GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_WIN, GPU_DRIVER_ANY)) { - /* Old Intel drivers with known bugs that cause material properties to crash. - * Version Build 10.18.14.5067 is the latest available and appears to be working - * ok with our workarounds, so excluded from this list. */ - if (strstr(version, "Build 7.14") || strstr(version, "Build 7.15") || - strstr(version, "Build 8.15") || strstr(version, "Build 9.17") || - strstr(version, "Build 9.18") || strstr(version, "Build 10.18.10.3") || - strstr(version, "Build 10.18.10.4") || strstr(version, "Build 10.18.10.5") || - strstr(version, "Build 10.18.14.4")) { - GPG.support_level = GPU_SUPPORT_LEVEL_LIMITED; - } - } - } - GPG.support_key = gpu_platform_create_key(GPG.support_level, vendor, renderer, version); - GPG.gpu_name = gpu_platform_create_gpu_name(vendor, renderer, version); - GPG.initialized = true; +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name C-API + * \{ */ + +using namespace blender::gpu; + +eGPUSupportLevel GPU_platform_support_level(void) +{ + return GPG.support_level; } -void gpu_platform_exit(void) +const char *GPU_platform_support_level_key(void) { - MEM_SAFE_FREE(GPG.support_key); - MEM_SAFE_FREE(GPG.gpu_name); + return GPG.support_key; +} + +const char *GPU_platform_gpu_name(void) +{ + return GPG.gpu_name; } + +/* GPU Types */ +bool GPU_type_matches(eGPUDeviceType device, eGPUOSType os, eGPUDriverType driver) +{ + return (GPG.device & device) && (GPG.os & os) && (GPG.driver & driver); +} + +/** \} */
\ No newline at end of file diff --git a/source/blender/gpu/intern/gpu_platform_private.hh b/source/blender/gpu/intern/gpu_platform_private.hh new file mode 100644 index 00000000000..e882672fdda --- /dev/null +++ b/source/blender/gpu/intern/gpu_platform_private.hh @@ -0,0 +1,53 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2020, Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#pragma once + +#include "GPU_platform.h" + +namespace blender::gpu { + +class GPUPlatformGlobal { + public: + bool initialized = false; + eGPUDeviceType device; + eGPUOSType os; + eGPUDriverType driver; + eGPUSupportLevel support_level; + char *support_key = nullptr; + char *gpu_name = nullptr; + + public: + void create_key(eGPUSupportLevel support_level, + const char *vendor, + const char *renderer, + const char *version); + + void create_gpu_name(const char *vendor, const char *renderer, const char *version); + + void clear(void); +}; + +extern GPUPlatformGlobal GPG; + +} // namespace blender::gpu
\ No newline at end of file diff --git a/source/blender/gpu/intern/gpu_private.h b/source/blender/gpu/intern/gpu_private.h index 505ac3b0278..059d19f1002 100644 --- a/source/blender/gpu/intern/gpu_private.h +++ b/source/blender/gpu/intern/gpu_private.h @@ -25,10 +25,6 @@ extern "C" { #endif /* call this before running any of the functions below */ -void gpu_platform_init(void); -void gpu_platform_exit(void); - -/* call this before running any of the functions below */ void gpu_extensions_init(void); void gpu_extensions_exit(void); diff --git a/source/blender/gpu/opengl/gl_backend.cc b/source/blender/gpu/opengl/gl_backend.cc new file mode 100644 index 00000000000..d44bb9ba481 --- /dev/null +++ b/source/blender/gpu/opengl/gl_backend.cc @@ -0,0 +1,135 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2020, Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup gpu + */ + +#include "gpu_platform_private.hh" + +#include "glew-mx.h" + +#include "gl_backend.hh" + +namespace blender::gpu { + +void GLBackend::platform_init(void) +{ + BLI_assert(!GPG.initialized); + GPG.initialized = true; + +#ifdef _WIN32 + GPG.os = GPU_OS_WIN; +#elif defined(__APPLE__) + GPG.os = GPU_OS_MAC; +#else + GPG.os = GPU_OS_UNIX; +#endif + + const char *vendor = (const char *)glGetString(GL_VENDOR); + const char *renderer = (const char *)glGetString(GL_RENDERER); + const char *version = (const char *)glGetString(GL_VERSION); + + if (strstr(vendor, "ATI") || strstr(vendor, "AMD")) { + GPG.device = GPU_DEVICE_ATI; + GPG.driver = GPU_DRIVER_OFFICIAL; + } + else if (strstr(vendor, "NVIDIA")) { + GPG.device = GPU_DEVICE_NVIDIA; + GPG.driver = GPU_DRIVER_OFFICIAL; + } + else if (strstr(vendor, "Intel") || + /* src/mesa/drivers/dri/intel/intel_context.c */ + strstr(renderer, "Mesa DRI Intel") || strstr(renderer, "Mesa DRI Mobile Intel")) { + GPG.device = GPU_DEVICE_INTEL; + GPG.driver = GPU_DRIVER_OFFICIAL; + + if (strstr(renderer, "UHD Graphics") || + /* Not UHD but affected by the same bugs. */ + strstr(renderer, "HD Graphics 530") || strstr(renderer, "Kaby Lake GT2") || + strstr(renderer, "Whiskey Lake")) { + GPG.device |= GPU_DEVICE_INTEL_UHD; + } + } + else if ((strstr(renderer, "Mesa DRI R")) || + (strstr(renderer, "Radeon") && strstr(vendor, "X.Org")) || + (strstr(renderer, "AMD") && strstr(vendor, "X.Org")) || + (strstr(renderer, "Gallium ") && strstr(renderer, " on ATI ")) || + (strstr(renderer, "Gallium ") && strstr(renderer, " on AMD "))) { + GPG.device = GPU_DEVICE_ATI; + GPG.driver = GPU_DRIVER_OPENSOURCE; + } + else if (strstr(renderer, "Nouveau") || strstr(vendor, "nouveau")) { + GPG.device = GPU_DEVICE_NVIDIA; + GPG.driver = GPU_DRIVER_OPENSOURCE; + } + else if (strstr(vendor, "Mesa")) { + GPG.device = GPU_DEVICE_SOFTWARE; + GPG.driver = GPU_DRIVER_SOFTWARE; + } + else if (strstr(vendor, "Microsoft")) { + GPG.device = GPU_DEVICE_SOFTWARE; + GPG.driver = GPU_DRIVER_SOFTWARE; + } + else if (strstr(renderer, "Apple Software Renderer")) { + GPG.device = GPU_DEVICE_SOFTWARE; + GPG.driver = GPU_DRIVER_SOFTWARE; + } + else if (strstr(renderer, "llvmpipe") || strstr(renderer, "softpipe")) { + GPG.device = GPU_DEVICE_SOFTWARE; + GPG.driver = GPU_DRIVER_SOFTWARE; + } + else { + printf("Warning: Could not find a matching GPU name. Things may not behave as expected.\n"); + printf("Detected OpenGL configuration:\n"); + printf("Vendor: %s\n", vendor); + printf("Renderer: %s\n", renderer); + GPG.device = GPU_DEVICE_ANY; + GPG.driver = GPU_DRIVER_ANY; + } + + /* Detect support level */ + if (!GLEW_VERSION_3_3) { + GPG.support_level = GPU_SUPPORT_LEVEL_UNSUPPORTED; + } + else { + if (GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_WIN, GPU_DRIVER_ANY)) { + /* Old Intel drivers with known bugs that cause material properties to crash. + * Version Build 10.18.14.5067 is the latest available and appears to be working + * ok with our workarounds, so excluded from this list. */ + if (strstr(version, "Build 7.14") || strstr(version, "Build 7.15") || + strstr(version, "Build 8.15") || strstr(version, "Build 9.17") || + strstr(version, "Build 9.18") || strstr(version, "Build 10.18.10.3") || + strstr(version, "Build 10.18.10.4") || strstr(version, "Build 10.18.10.5") || + strstr(version, "Build 10.18.14.4")) { + GPG.support_level = GPU_SUPPORT_LEVEL_LIMITED; + } + } + } + GPG.create_key(GPG.support_level, vendor, renderer, version); + GPG.create_gpu_name(vendor, renderer, version); +} + +void GLBackend::platform_exit(void) +{ + BLI_assert(GPG.initialized); + GPG.clear(); +} + +} // namespace blender::gpu
\ No newline at end of file diff --git a/source/blender/gpu/opengl/gl_backend.hh b/source/blender/gpu/opengl/gl_backend.hh index c178aa537a0..9548aa9dd92 100644 --- a/source/blender/gpu/opengl/gl_backend.hh +++ b/source/blender/gpu/opengl/gl_backend.hh @@ -47,11 +47,16 @@ class GLBackend : public GPUBackend { public: GLBackend() { + /* platform_init needs to go first. */ + GLBackend::platform_init(); + GLTexture::samplers_init(); } ~GLBackend() { GLTexture::samplers_free(); + + GLBackend::platform_exit(); } static GLBackend *get(void) @@ -118,6 +123,10 @@ class GLBackend : public GPUBackend { orphan_list.append(id); list_mutex.unlock(); } + + private: + static void platform_init(void); + static void platform_exit(void); }; } // namespace gpu |