Blender  V3.3
gpu_platform.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2005 Blender Foundation. All rights reserved. */
3 
11 #include "MEM_guardedalloc.h"
12 
13 #include "BLI_dynstr.h"
14 #include "BLI_string.h"
15 
16 #include "GPU_platform.h"
17 
18 #include "gpu_platform_private.hh"
19 
20 /* -------------------------------------------------------------------- */
24 namespace blender::gpu {
25 
27 
28 static char *create_key(eGPUSupportLevel support_level,
29  const char *vendor,
30  const char *renderer,
31  const char *version)
32 {
33  DynStr *ds = BLI_dynstr_new();
34  BLI_dynstr_appendf(ds, "{%s/%s/%s}=", vendor, renderer, version);
35  if (support_level == GPU_SUPPORT_LEVEL_SUPPORTED) {
36  BLI_dynstr_append(ds, "SUPPORTED");
37  }
38  else if (support_level == GPU_SUPPORT_LEVEL_LIMITED) {
39  BLI_dynstr_append(ds, "LIMITED");
40  }
41  else {
42  BLI_dynstr_append(ds, "UNSUPPORTED");
43  }
44 
45  char *support_key = BLI_dynstr_get_cstring(ds);
46  BLI_dynstr_free(ds);
47  BLI_str_replace_char(support_key, '\n', ' ');
48  BLI_str_replace_char(support_key, '\r', ' ');
49  return support_key;
50 }
51 
52 static char *create_gpu_name(const char *vendor, const char *renderer, const char *version)
53 {
54  DynStr *ds = BLI_dynstr_new();
55  BLI_dynstr_appendf(ds, "%s %s %s", vendor, renderer, version);
56 
57  char *gpu_name = BLI_dynstr_get_cstring(ds);
58  BLI_dynstr_free(ds);
59  BLI_str_replace_char(gpu_name, '\n', ' ');
60  BLI_str_replace_char(gpu_name, '\r', ' ');
61  return gpu_name;
62 }
63 
65  eGPUOSType os_type,
66  eGPUDriverType driver_type,
67  eGPUSupportLevel gpu_support_level,
68  eGPUBackendType backend,
69  const char *vendor_str,
70  const char *renderer_str,
71  const char *version_str)
72 {
73  this->clear();
74 
75  this->initialized = true;
76 
77  this->device = gpu_device;
78  this->os = os_type;
79  this->driver = driver_type;
80  this->support_level = gpu_support_level;
81 
82  this->vendor = BLI_strdup(vendor_str);
83  this->renderer = BLI_strdup(renderer_str);
84  this->version = BLI_strdup(version_str);
85  this->support_key = create_key(gpu_support_level, vendor_str, renderer_str, version_str);
86  this->gpu_name = create_gpu_name(vendor_str, renderer_str, version_str);
87  this->backend = backend;
88 }
89 
91 {
97  initialized = false;
98 }
99 
100 } // namespace blender::gpu
101 
104 /* -------------------------------------------------------------------- */
108 using namespace blender::gpu;
109 
111 {
113  return GPG.support_level;
114 }
115 
116 const char *GPU_platform_vendor()
117 {
119  return GPG.vendor;
120 }
121 
123 {
125  return GPG.renderer;
126 }
127 
128 const char *GPU_platform_version()
129 {
131  return GPG.version;
132 }
133 
135 {
137  return GPG.support_key;
138 }
139 
141 {
143  return GPG.gpu_name;
144 }
145 
147 {
148  return GPU_type_matches_ex(device, os, driver, GPU_BACKEND_ANY);
149 }
150 
152  eGPUOSType os,
153  eGPUDriverType driver,
154  eGPUBackendType backend)
155 {
157  return (GPG.device & device) && (GPG.os & os) && (GPG.driver & driver) &&
158  (GPG.backend & backend);
159 }
160 
#define BLI_assert(a)
Definition: BLI_assert.h:46
A dynamically sized string ADT.
DynStr * BLI_dynstr_new(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: BLI_dynstr.c:50
char * BLI_dynstr_get_cstring(const DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: BLI_dynstr.c:256
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
Definition: BLI_dynstr.c:281
void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format,...) ATTR_PRINTF_FORMAT(2
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
Definition: BLI_dynstr.c:75
void BLI_str_replace_char(char *str, char src, char dst) ATTR_NONNULL()
Definition: string.c:503
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
Definition: string.c:42
eGPUBackendType
Definition: GPU_platform.h:15
@ GPU_BACKEND_ANY
Definition: GPU_platform.h:19
eGPUDriverType
Definition: GPU_platform.h:43
eGPUSupportLevel
Definition: GPU_platform.h:50
@ GPU_SUPPORT_LEVEL_LIMITED
Definition: GPU_platform.h:52
@ GPU_SUPPORT_LEVEL_SUPPORTED
Definition: GPU_platform.h:51
eGPUOSType
Definition: GPU_platform.h:36
eGPUDeviceType
Definition: GPU_platform.h:23
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
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)
Definition: gpu_platform.cc:64
const char * GPU_platform_vendor()
const char * GPU_platform_gpu_name()
bool GPU_type_matches_ex(eGPUDeviceType device, eGPUOSType os, eGPUDriverType driver, eGPUBackendType backend)
const char * GPU_platform_renderer()
const char * GPU_platform_support_level_key()
const char * GPU_platform_version()
bool GPU_type_matches(eGPUDeviceType device, eGPUOSType os, eGPUDriverType driver)
eGPUSupportLevel GPU_platform_support_level()
GPUPlatformGlobal GPG
Definition: gpu_platform.cc:26
static char * create_gpu_name(const char *vendor, const char *renderer, const char *version)
Definition: gpu_platform.cc:52
static char * create_key(eGPUSupportLevel support_level, const char *vendor, const char *renderer, const char *version)
Definition: gpu_platform.cc:28