Blender V5.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
11
12#include <cstdint>
13
14#include "MEM_guardedalloc.h"
15
16#include "BLI_dynstr.hh"
17#include "BLI_string.hh"
18#include "BLI_string_utils.hh"
19#include "BLI_vector.hh"
20
21#include "GPU_platform.hh"
22
24
25namespace blender {
26
27/* -------------------------------------------------------------------- */
30
31namespace gpu {
32
34
35static char *create_key(GPUSupportLevel support_level,
36 const char *vendor,
37 const char *renderer,
38 const char *version)
39{
40 DynStr *ds = BLI_dynstr_new();
41 BLI_dynstr_appendf(ds, "{%s/%s/%s}=", vendor, renderer, version);
42 if (support_level == GPU_SUPPORT_LEVEL_SUPPORTED) {
43 BLI_dynstr_append(ds, "SUPPORTED");
44 }
45 else if (support_level == GPU_SUPPORT_LEVEL_LIMITED) {
46 BLI_dynstr_append(ds, "LIMITED");
47 }
48 else {
49 BLI_dynstr_append(ds, "UNSUPPORTED");
50 }
51
52 char *support_key = BLI_dynstr_get_cstring(ds);
54 BLI_string_replace_char(support_key, '\n', ' ');
55 BLI_string_replace_char(support_key, '\r', ' ');
56 return support_key;
57}
58
59static char *create_gpu_name(const char *vendor, const char *renderer, const char *version)
60{
61 DynStr *ds = BLI_dynstr_new();
62 BLI_dynstr_appendf(ds, "%s %s %s", vendor, renderer, version);
63
64 char *gpu_name = BLI_dynstr_get_cstring(ds);
66 BLI_string_replace_char(gpu_name, '\n', ' ');
67 BLI_string_replace_char(gpu_name, '\r', ' ');
68 return gpu_name;
69}
70
72 GPUOSType os_type,
73 GPUDriverType driver_type,
74 GPUSupportLevel gpu_support_level,
76 const char *vendor_str,
77 const char *renderer_str,
78 const char *version_str,
79 GPUArchitectureType arch_type)
80{
81 this->clear();
82
83 this->initialized = true;
84
85 this->device = gpu_device;
86 this->os = os_type;
87 this->driver = driver_type;
88 this->support_level = gpu_support_level;
89
90 const char *vendor = vendor_str ? vendor_str : "UNKNOWN";
91 const char *renderer = renderer_str ? renderer_str : "UNKNOWN";
92 const char *version = version_str ? version_str : "UNKNOWN";
93
94 this->vendor = BLI_strdup(vendor);
95 this->renderer = BLI_strdup(renderer);
96 this->version = BLI_strdup(version);
97 this->support_key = create_key(gpu_support_level, vendor, renderer, version);
99 this->backend = backend;
100 this->architecture_type = arch_type;
101}
102
104{
105 MEM_SAFE_DELETE(vendor);
106 MEM_SAFE_DELETE(renderer);
107 MEM_SAFE_DELETE(version);
108 MEM_SAFE_DELETE(support_key);
109 MEM_SAFE_DELETE(gpu_name);
110 devices.clear_and_shrink();
114 initialized = false;
115}
116
117} // namespace gpu
118
120
121/* -------------------------------------------------------------------- */
124
125using namespace blender::gpu;
126
132
134{
136 return GPG.vendor;
137}
138
140{
142 return GPG.renderer;
143}
144
146{
148 return GPG.version;
149}
150
152{
154 return GPG.support_key;
155}
156
158{
160 return GPG.gpu_name;
161}
162
168
170{
171 return GPU_type_matches_ex(device, os, driver, GPU_BACKEND_ANY);
172}
173
175 GPUOSType os,
176 GPUDriverType driver,
177 GPUBackendType backend)
178{
180 return (GPG.device & device) && (GPG.os & os) && (GPG.driver & driver) &&
181 (GPG.backend & backend);
182}
183
185{
186 return GPG.devices.as_span();
187}
188
193
198
203
205{
206 /* Source for device IDs:
207 * https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/include/pci_ids/iris_pci_ids.h
208 */
209 switch (device_id & 0xFF00) {
210 case 0x2900: // Broadwater
211 case 0x2A00: // Broadwater/Eagle Lake
212 case 0x2E00: // Eagle Lake
213 case 0x0000: // Iron Lake
214 case 0x0100: // Ivy Bridge/Sandy Bridge/Baytrail
215 case 0x0F00: // Baytrail
216 case 0x0400: // Haswell
217 case 0x0C00: // Haswell
218 case 0x0D00: // Haswell
219 case 0x0A00: // Haswell / Appollo Lake
220 case 0x2200: // Cherrytrail
221 case 0x1600: // Broadwell
222 case 0x5A00: // Apollo Lake
223 case 0x1900: // Skylake
224 case 0x1A00: // Apollo Lake
225 case 0x3100: // Gemini Lake
226 case 0x5900: // Kaby Lake/Amber Lake
227 case 0x8700: // Kaby Lake/Coffee Lake
228 case 0x3E00: // Coffee Lake/Whiskey Lake
229 case 0x9B00: // Comet Lake
231 case 0x8A00: // Ice Lake
232 case 0x4500: // Elkhart Lake
233 case 0x4E00: // Jasper Lake
235 case 0x9A00: // Tiger Lake
236 case 0x4C00: // Rocket Lake
237 case 0x4900: // DG1
238 case 0x4600: // Alder Lake
239 case 0x4F00: // Alchemist
240 case 0x5600: // Alchemist
241 case 0xA700: // Raptor Lake
242 case 0x7D00: // Meteor Lake / Arrow Lake
243 case 0xB600: // Meteor Lake / Arrow Lake
244 return GPUIntelGpuArch::Xe;
245 case 0x6400: // Lunar Lake
246 case 0xE200: // Battlemage
248 case 0xB000: // Panther Lake
249 case 0xFD00: // Wildcat Lake
250 default:
252 }
253}
254
256
257} // namespace blender
A dynamically sized string ADT.
Read Blender memory allocation and freeing.
Span< T > as_span() const
Definition BLI_array.hh:254
void reinitialize(const int64_t new_size)
Definition BLI_array.hh:430
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)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format,...) ATTR_PRINTF_FORMAT(2
uint32_t GPU_platform_luid_node_mask()
bool GPU_type_matches_ex(GPUDeviceType device, GPUOSType os, GPUDriverType driver, GPUBackendType backend)
const char * GPU_platform_version()
Span< GPUDevice > GPU_platform_devices_list()
void BLI_string_replace_char(char *str, char src, char dst) ATTR_NONNULL(1)
const char * GPU_platform_gpu_name()
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
@ GPU_SUPPORT_LEVEL_LIMITED
@ GPU_SUPPORT_LEVEL_SUPPORTED
GPUSupportLevel GPU_platform_support_level()
unsigned int uint32_t
Definition BKE_text.h:81
bool GPU_type_matches(GPUDeviceType device, GPUOSType os, GPUDriverType driver)
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
Definition BLI_dynstr.cc:58
Span< uint8_t > GPU_platform_luid()
const char * GPU_platform_renderer()
GPUArchitectureType GPU_platform_architecture()
GPUIntelGpuArch GPU_platform_get_intel_arch(uint32_t device_id)
char * BLI_dynstr_get_cstring(const DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
const char * GPU_platform_vendor()
const char * GPU_platform_support_level_key()
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
Span< uint8_t > GPU_platform_uuid()
DynStr * BLI_dynstr_new() ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition BLI_dynstr.cc:39