Blender  V2.93
gpu_platform.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2005 Blender Foundation.
17  * All rights reserved.
18  */
19 
27 #include "MEM_guardedalloc.h"
28 
29 #include "BLI_dynstr.h"
30 #include "BLI_string.h"
31 
32 #include "GPU_platform.h"
33 
34 #include "gpu_platform_private.hh"
35 
36 /* -------------------------------------------------------------------- */
40 namespace blender::gpu {
41 
43 
45  const char *vendor,
46  const char *renderer,
47  const char *version)
48 {
49  DynStr *ds = BLI_dynstr_new();
50  BLI_dynstr_appendf(ds, "{%s/%s/%s}=", vendor, renderer, version);
52  BLI_dynstr_append(ds, "SUPPORTED");
53  }
55  BLI_dynstr_append(ds, "LIMITED");
56  }
57  else {
58  BLI_dynstr_append(ds, "UNSUPPORTED");
59  }
60 
62  BLI_dynstr_free(ds);
65 }
66 
67 void GPUPlatformGlobal::create_gpu_name(const char *vendor,
68  const char *renderer,
69  const char *version)
70 {
71  DynStr *ds = BLI_dynstr_new();
72  BLI_dynstr_appendf(ds, "%s %s %s", vendor, renderer, version);
73 
75  BLI_dynstr_free(ds);
76  BLI_str_replace_char(gpu_name, '\n', ' ');
77  BLI_str_replace_char(gpu_name, '\r', ' ');
78 }
79 
81 {
84  initialized = false;
85 }
86 
87 } // namespace blender::gpu
88 
91 /* -------------------------------------------------------------------- */
95 using namespace blender::gpu;
96 
98 {
99  return GPG.support_level;
100 }
101 
103 {
104  return GPG.support_key;
105 }
106 
107 const char *GPU_platform_gpu_name(void)
108 {
109  return GPG.gpu_name;
110 }
111 
112 /* GPU Types */
114 {
115  return (GPG.device & device) && (GPG.os & os) && (GPG.driver & driver);
116 }
117 
A dynamically sized string ADT.
DynStr * BLI_dynstr_new(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: BLI_dynstr.c:71
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
Definition: BLI_dynstr.c:358
void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format,...) ATTR_PRINTF_FORMAT(2
char * BLI_dynstr_get_cstring(DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: BLI_dynstr.c:323
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
Definition: BLI_dynstr.c:107
void BLI_str_replace_char(char *string, char src, char dst) ATTR_NONNULL()
Definition: string.c:532
eGPUDriverType
Definition: GPU_platform.h:52
eGPUSupportLevel
Definition: GPU_platform.h:59
@ GPU_SUPPORT_LEVEL_LIMITED
Definition: GPU_platform.h:61
@ GPU_SUPPORT_LEVEL_SUPPORTED
Definition: GPU_platform.h:60
eGPUOSType
Definition: GPU_platform.h:45
eGPUDeviceType
Definition: GPU_platform.h:32
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
void create_gpu_name(const char *vendor, const char *renderer, const char *version)
Definition: gpu_platform.cc:67
void create_key(eGPUSupportLevel support_level, const char *vendor, const char *renderer, const char *version)
Definition: gpu_platform.cc:44
const char * GPU_platform_gpu_name(void)
const char * GPU_platform_support_level_key()
bool GPU_type_matches(eGPUDeviceType device, eGPUOSType os, eGPUDriverType driver)
eGPUSupportLevel GPU_platform_support_level()
Definition: gpu_platform.cc:97
GPUPlatformGlobal GPG
Definition: gpu_platform.cc:42