Blender V5.0
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
11
12#include <cstdint>
13
14#include "MEM_guardedalloc.h"
15
16#include "BLI_dynstr.h"
17#include "BLI_string.h"
18#include "BLI_string_utils.hh"
19#include "BLI_vector.hh"
20
21#include "GPU_platform.hh"
22
24
25/* -------------------------------------------------------------------- */
28
29namespace blender::gpu {
30
32
33static char *create_key(GPUSupportLevel support_level,
34 const char *vendor,
35 const char *renderer,
36 const char *version)
37{
38 DynStr *ds = BLI_dynstr_new();
39 BLI_dynstr_appendf(ds, "{%s/%s/%s}=", vendor, renderer, version);
40 if (support_level == GPU_SUPPORT_LEVEL_SUPPORTED) {
41 BLI_dynstr_append(ds, "SUPPORTED");
42 }
43 else if (support_level == GPU_SUPPORT_LEVEL_LIMITED) {
44 BLI_dynstr_append(ds, "LIMITED");
45 }
46 else {
47 BLI_dynstr_append(ds, "UNSUPPORTED");
48 }
49
50 char *support_key = BLI_dynstr_get_cstring(ds);
52 BLI_string_replace_char(support_key, '\n', ' ');
53 BLI_string_replace_char(support_key, '\r', ' ');
54 return support_key;
55}
56
57static char *create_gpu_name(const char *vendor, const char *renderer, const char *version)
58{
59 DynStr *ds = BLI_dynstr_new();
60 BLI_dynstr_appendf(ds, "%s %s %s", vendor, renderer, version);
61
62 char *gpu_name = BLI_dynstr_get_cstring(ds);
64 BLI_string_replace_char(gpu_name, '\n', ' ');
65 BLI_string_replace_char(gpu_name, '\r', ' ');
66 return gpu_name;
67}
68
70 GPUOSType os_type,
71 GPUDriverType driver_type,
72 GPUSupportLevel gpu_support_level,
74 const char *vendor_str,
75 const char *renderer_str,
76 const char *version_str,
77 GPUArchitectureType arch_type)
78{
79 this->clear();
80
81 this->initialized = true;
82
83 this->device = gpu_device;
84 this->os = os_type;
85 this->driver = driver_type;
86 this->support_level = gpu_support_level;
87
88 const char *vendor = vendor_str ? vendor_str : "UNKNOWN";
89 const char *renderer = renderer_str ? renderer_str : "UNKNOWN";
90 const char *version = version_str ? version_str : "UNKNOWN";
91
92 this->vendor = BLI_strdup(vendor);
93 this->renderer = BLI_strdup(renderer);
94 this->version = BLI_strdup(version);
95 this->support_key = create_key(gpu_support_level, vendor, renderer, version);
97 this->backend = backend;
98 this->architecture_type = arch_type;
99}
100
102{
108 devices.clear_and_shrink();
109 device_uuid.reinitialize(0);
110 device_luid.reinitialize(0);
112 initialized = false;
113}
114
115} // namespace blender::gpu
116
118
119/* -------------------------------------------------------------------- */
122
123using namespace blender::gpu;
124
126{
127 BLI_assert(GPG.initialized);
128 return GPG.support_level;
129}
130
132{
133 BLI_assert(GPG.initialized);
134 return GPG.vendor;
135}
136
138{
139 BLI_assert(GPG.initialized);
140 return GPG.renderer;
141}
142
144{
145 BLI_assert(GPG.initialized);
146 return GPG.version;
147}
148
150{
151 BLI_assert(GPG.initialized);
152 return GPG.support_key;
153}
154
156{
157 BLI_assert(GPG.initialized);
158 return GPG.gpu_name;
159}
160
162{
163 BLI_assert(GPG.initialized);
164 return GPG.architecture_type;
165}
166
168{
169 return GPU_type_matches_ex(device, os, driver, GPU_BACKEND_ANY);
170}
171
173 GPUOSType os,
174 GPUDriverType driver,
175 GPUBackendType backend)
176{
177 BLI_assert(GPG.initialized);
178 return (GPG.device & device) && (GPG.os & os) && (GPG.driver & driver) &&
179 (GPG.backend & backend);
180}
181
183{
184 return GPG.devices.as_span();
185}
186
188{
189 return GPG.device_uuid.as_span();
190}
191
193{
194 return GPG.device_luid.as_span();
195}
196
198{
199 return GPG.device_luid_node_mask;
200}
201
#define BLI_assert(a)
Definition BLI_assert.h:46
A dynamically sized string ADT.
char * BLI_dynstr_get_cstring(const DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
DynStr * BLI_dynstr_new(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition BLI_dynstr.cc:37
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
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.cc:56
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
Definition string.cc:41
void BLI_string_replace_char(char *str, char src, char dst) ATTR_NONNULL(1)
GPUDeviceType
blender::Span< uint8_t > GPU_platform_uuid()
GPUSupportLevel GPU_platform_support_level()
const char * GPU_platform_vendor()
const char * GPU_platform_gpu_name()
const char * GPU_platform_support_level_key()
GPUArchitectureType
bool GPU_type_matches(GPUDeviceType device, GPUOSType os, GPUDriverType driver)
blender::Span< uint8_t > GPU_platform_luid()
const char * GPU_platform_renderer()
GPUSupportLevel
@ GPU_SUPPORT_LEVEL_LIMITED
@ GPU_SUPPORT_LEVEL_SUPPORTED
uint32_t GPU_platform_luid_node_mask()
const char * GPU_platform_version()
GPUDriverType
blender::Span< GPUDevice > GPU_platform_devices_list()
GPUOSType
bool GPU_type_matches_ex(GPUDeviceType device, GPUOSType os, GPUDriverType driver, GPUBackendType backend)
GPUArchitectureType GPU_platform_architecture()
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
void init(GPUDeviceType gpu_device, GPUOSType os_type, GPUDriverType driver_type, GPUSupportLevel gpu_support_level, GPUBackendType backend, const char *vendor_str, const char *renderer_str, const char *version_str, GPUArchitectureType arch_type)
GPUPlatformGlobal GPG
static char * create_key(GPUSupportLevel support_level, const char *vendor, const char *renderer, const char *version)
static char * create_gpu_name(const char *vendor, const char *renderer, const char *version)