Blender V4.3
gpu_platform.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
12#include "MEM_guardedalloc.h"
13
14#include "BLI_dynstr.h"
15#include "BLI_string.h"
16#include "BLI_string_utils.hh"
17#include "BLI_vector.hh"
18
19#include "GPU_platform.hh"
20
22
23/* -------------------------------------------------------------------- */
27namespace blender::gpu {
28
30
31static char *create_key(eGPUSupportLevel support_level,
32 const char *vendor,
33 const char *renderer,
34 const char *version)
35{
36 DynStr *ds = BLI_dynstr_new();
37 BLI_dynstr_appendf(ds, "{%s/%s/%s}=", vendor, renderer, version);
38 if (support_level == GPU_SUPPORT_LEVEL_SUPPORTED) {
39 BLI_dynstr_append(ds, "SUPPORTED");
40 }
41 else if (support_level == GPU_SUPPORT_LEVEL_LIMITED) {
42 BLI_dynstr_append(ds, "LIMITED");
43 }
44 else {
45 BLI_dynstr_append(ds, "UNSUPPORTED");
46 }
47
48 char *support_key = BLI_dynstr_get_cstring(ds);
50 BLI_string_replace_char(support_key, '\n', ' ');
51 BLI_string_replace_char(support_key, '\r', ' ');
52 return support_key;
53}
54
55static char *create_gpu_name(const char *vendor, const char *renderer, const char *version)
56{
57 DynStr *ds = BLI_dynstr_new();
58 BLI_dynstr_appendf(ds, "%s %s %s", vendor, renderer, version);
59
60 char *gpu_name = BLI_dynstr_get_cstring(ds);
62 BLI_string_replace_char(gpu_name, '\n', ' ');
63 BLI_string_replace_char(gpu_name, '\r', ' ');
64 return gpu_name;
65}
66
68 eGPUOSType os_type,
69 eGPUDriverType driver_type,
70 eGPUSupportLevel gpu_support_level,
71 eGPUBackendType backend,
72 const char *vendor_str,
73 const char *renderer_str,
74 const char *version_str,
75 GPUArchitectureType arch_type)
76{
77 this->clear();
78
79 this->initialized = true;
80
81 this->device = gpu_device;
82 this->os = os_type;
83 this->driver = driver_type;
84 this->support_level = gpu_support_level;
85
86 const char *vendor = vendor_str ? vendor_str : "UNKNOWN";
87 const char *renderer = renderer_str ? renderer_str : "UNKNOWN";
88 const char *version = version_str ? version_str : "UNKNOWN";
89
90 this->vendor = BLI_strdup(vendor);
91 this->renderer = BLI_strdup(renderer);
92 this->version = BLI_strdup(version);
93 this->support_key = create_key(gpu_support_level, vendor, renderer, version);
94 this->gpu_name = create_gpu_name(vendor, renderer, version);
95 this->backend = backend;
96 this->architecture_type = arch_type;
97}
98
109
110} // namespace blender::gpu
111
114/* -------------------------------------------------------------------- */
118using namespace blender::gpu;
119
125
127{
129 return GPG.vendor;
130}
131
133{
135 return GPG.renderer;
136}
137
139{
141 return GPG.version;
142}
143
145{
147 return GPG.support_key;
148}
149
151{
153 return GPG.gpu_name;
154}
155
161
163{
164 return GPU_type_matches_ex(device, os, driver, GPU_BACKEND_ANY);
165}
166
168 eGPUOSType os,
169 eGPUDriverType driver,
170 eGPUBackendType backend)
171{
173 return (GPG.device & device) && (GPG.os & os) && (GPG.driver & driver) &&
174 (GPG.backend & backend);
175}
176
181
#define BLI_assert(a)
Definition BLI_assert.h:50
A dynamically sized string ADT.
char * BLI_dynstr_get_cstring(const DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition BLI_dynstr.c:149
DynStr * BLI_dynstr_new(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition BLI_dynstr.c:37
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
Definition BLI_dynstr.c:174
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:62
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
Definition string.c:40
void BLI_string_replace_char(char *str, char src, char dst) ATTR_NONNULL(1)
eGPUDriverType
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_support_level_key()
GPUArchitectureType
eGPUSupportLevel
@ GPU_SUPPORT_LEVEL_LIMITED
@ GPU_SUPPORT_LEVEL_SUPPORTED
const char * GPU_platform_renderer()
eGPUOSType
eGPUDeviceType
const char * GPU_platform_version()
bool GPU_type_matches(eGPUDeviceType device, eGPUOSType os, eGPUDriverType driver)
blender::Span< GPUDevice > GPU_platform_devices_list()
eGPUSupportLevel GPU_platform_support_level()
GPUArchitectureType GPU_platform_architecture()
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
Span< T > as_span() const
void clear_and_shrink()
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, GPUArchitectureType arch_type)
GPUPlatformGlobal GPG
static char * create_gpu_name(const char *vendor, const char *renderer, const char *version)
static char * create_key(eGPUSupportLevel support_level, const char *vendor, const char *renderer, const char *version)