Blender V5.3
wm_platform_support.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include <cstring>
12
13#include "BLI_dynstr.hh"
14#include "BLI_fileops.hh"
15#include "BLI_linklist.hh"
16#include "BLI_path_utils.hh"
17#include "BLI_string.hh"
18
19#include "BLT_translation.hh"
20
21#include "BKE_appdir.hh"
22#include "BKE_global.hh"
23
24#include "GPU_context.hh"
25#include "GPU_platform.hh"
26
27#include "CLG_log.h"
28
29namespace blender {
30
31#define WM_PLATFORM_SUPPORT_TEXT_SIZE 1024
32
33static CLG_LogRef LOG = {"gpu.platform"};
34
38static bool wm_platform_support_check_approval(const char *platform_support_key, bool update)
39{
40 if (G.factory_startup) {
41 return false;
42 }
43 const std::optional<std::string> cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, nullptr);
44 if (!cfgdir.has_value()) {
45 return false;
46 }
47
48 bool result = false;
49 char filepath[FILE_MAX];
50 BLI_path_join(filepath, sizeof(filepath), cfgdir->c_str(), BLENDER_PLATFORM_SUPPORT_FILE);
51 LinkNode *lines = BLI_file_read_as_lines(filepath);
52 for (LinkNode *line_node = lines; line_node; line_node = line_node->next) {
53 const char *line = static_cast<char *>(line_node->link);
54 if (STREQ(line, platform_support_key)) {
55 result = true;
56 break;
57 }
58 }
59
60 if (!result && update) {
61 FILE *fp = BLI_fopen(filepath, "a");
62 if (fp) {
63 fprintf(fp, "%s\n", platform_support_key);
64 fclose(fp);
65 }
66 }
67
69 return result;
70}
71
72static void wm_platform_support_create_link(char *link)
73{
74 DynStr *ds = BLI_dynstr_new();
75
76 BLI_dynstr_append(ds, "https://docs.blender.org/manual/en/dev/troubleshooting/gpu/");
77#if defined(_WIN32)
78 BLI_dynstr_append(ds, "windows/");
79#elif defined(__APPLE__)
80 BLI_dynstr_append(ds, "apple/");
81#else /* UNIX. */
82 BLI_dynstr_append(ds, "linux/");
83#endif
84
86 BLI_dynstr_append(ds, "intel.html");
87 }
89 BLI_dynstr_append(ds, "nvidia.html");
90 }
92 BLI_dynstr_append(ds, "amd.html");
93 }
94 else {
95 BLI_dynstr_append(ds, "unknown.html");
96 }
97
100 BLI_dynstr_free(ds);
101}
102
104{
106 char message[WM_PLATFORM_SUPPORT_TEXT_SIZE];
108
109 bool result = true;
110
112 const char *platform_key = GPU_platform_support_level_key();
113
114 CLOG_INFO(&LOG, "Using GPU \"%s\"", GPU_platform_gpu_name());
115 CLOG_INFO(&LOG, "Using Backend \"%s\"", GPU_backend_get_name());
116
117 /* Check if previous check matches the current check. Don't update the approval when running in
118 * `background`. this could have been triggered by installing add-ons via installers. */
119 if (support_level != GPU_SUPPORT_LEVEL_UNSUPPORTED && !G.factory_startup &&
120 wm_platform_support_check_approval(platform_key, !G.background))
121 {
122 /* If it matches the user has confirmed and wishes to use it. */
123 return result;
124 }
125
126 bool backend_detected = GPU_backend_get_type() != GPU_BACKEND_NONE;
127 bool show_message = ELEM(
129 bool show_continue = backend_detected && support_level != GPU_SUPPORT_LEVEL_UNSUPPORTED;
130 bool show_link = backend_detected;
131 link[0] = '\0';
132 if (show_link) {
134 }
135
136 /* Update the message and link based on the found support level. */
137 GHOST_DialogOptions dialog_options = GHOST_DialogOptions(0);
138
139 switch (support_level) {
140 default:
142 break;
143
145 size_t slen = 0;
146 STR_CONCAT(title, slen, "Blender - ");
148 title, slen, CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Limited Platform Support"));
149 slen = 0;
151 message,
152 slen,
155 "Your graphics card or driver version has limited support. It may work, but with "
156 "issues."));
157
158 /* TODO: Extra space is needed for the split function in GHOST_SystemX11. We should change
159 * the behavior in GHOST_SystemX11. */
160 STR_CONCAT(message, slen, "\n \n");
162 message,
163 slen,
166 "Newer graphics drivers might be available with better Blender compatibility."));
167 STR_CONCAT(message, slen, "\n \n");
168 STR_CONCAT(message, slen, CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Graphics card:\n"));
169 STR_CONCAT(message, slen, GPU_platform_gpu_name());
170
171 dialog_options = GHOST_DialogWarning;
172 break;
173 }
174
176 size_t slen = 0;
177 STR_CONCAT(title, slen, "Blender - ");
179 title, slen, CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Platform Unsupported"));
180 slen = 0;
181
182#ifdef __APPLE__
185 message,
186 slen,
187 CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Your graphics card is not supported"));
188 }
189 else {
190 STR_CONCAT(message,
191 slen,
193 "Your graphics card or macOS version is not supported"));
194 STR_CONCAT(message, slen, "\n \n");
195
197 message,
198 slen,
200 "Upgrading to the latest macOS version may improve Blender support"));
201 }
202#else
203 STR_CONCAT(message,
204 slen,
206 "Your graphics card or driver version is not supported."));
207 STR_CONCAT(message, slen, "\n \n");
209 message,
210 slen,
213 "Newer graphics drivers might be available with better Blender compatibility."));
214
215 STR_CONCAT(message, slen, "\n \n");
216 STR_CONCAT(message, slen, CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Graphics card:\n"));
217 STR_CONCAT(message, slen, GPU_platform_gpu_name());
218#endif
219 STR_CONCAT(message, slen, "\n \n");
220
221 if (!show_continue) {
222 STR_CONCAT(message,
223 slen,
224 CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Blender will now close."));
225 dialog_options = GHOST_DialogError;
226 result = false;
227 }
228 break;
229 }
230 }
231
232 if (show_message) {
233 /* Always print when in background mode or using debug argument. */
234 if (G.background || G.debug & G_DEBUG) {
235 CLOG_INFO_NOCHECK(&LOG, "%s\n\n%s\n%s\n", title, message, link);
236 }
237 else {
238 CLOG_INFO(&LOG, "%s\n\n%s\n%s\n", title, message, link);
239 }
240 }
241 if (G.background) {
242 /* Don't show the message-box when running in background mode.
243 * Printing to console is enough. */
244 result = true;
245 }
246 else if (show_message) {
248 message,
249 "Find Latest Drivers",
250 show_continue ? "Continue Anyway" : "Exit",
251 link,
252 dialog_options);
253 }
254
255 return result;
256}
257
258} // namespace blender
#define BLENDER_PLATFORM_SUPPORT_FILE
A dynamically sized string ADT.
File and directory operations.
#define FILE_MAX
#define BLI_path_join(...)
#define STR_CONCAT(dst, len, suffix)
#define BLT_I18NCONTEXT_ID_WINDOWMANAGER
#define CTX_IFACE_(context, msgid)
#define CLOG_INFO_NOCHECK(clg_ref, format,...)
Definition CLG_log.h:204
#define CLOG_INFO(clg_ref,...)
Definition CLG_log.h:190
GHOST_DialogOptions
@ GHOST_DialogError
@ GHOST_DialogWarning
#define ELEM(...)
#define STREQ(a, b)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
GPUBackendType GPU_backend_get_type()
bool WM_platform_support_perform_checks()
const char * GPU_platform_gpu_name()
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
@ GPU_SUPPORT_LEVEL_UNSUPPORTED
@ GPU_SUPPORT_LEVEL_LIMITED
@ GPU_SUPPORT_LEVEL_SUPPORTED
Global G
Definition blender.cc:57
struct LinkNode * BLI_file_read_as_lines(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:591
GPUSupportLevel GPU_platform_support_level()
static bool wm_platform_support_check_approval(const char *platform_support_key, bool update)
bool GPU_type_matches(GPUDeviceType device, GPUOSType os, GPUDriverType driver)
std::optional< std::string > BKE_appdir_folder_id(int folder_id, const char *subfolder) ATTR_WARN_UNUSED_RESULT
Definition appdir.cc:762
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
Definition BLI_dynstr.cc:58
static void wm_platform_support_create_link(char *link)
const char * GPU_backend_get_name()
const char * GPU_platform_support_level_key()
static CLG_LogRef LOG
Definition logging.cpp:12
void WM_ghost_show_message_box(const char *title, const char *message, const char *help_label, const char *continue_label, const char *link, GHOST_DialogOptions dialog_options)
@ BLENDER_USER_CONFIG
void BLI_dynstr_get_cstring_ex(const DynStr *__restrict ds, char *__restrict rets) ATTR_NONNULL()
int BLI_dynstr_get_len(const DynStr *ds) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void BLI_file_free_lines(struct LinkNode *lines)
Definition storage.cc:637
DynStr * BLI_dynstr_new() ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition BLI_dynstr.cc:39
@ GPU_DEVICE_INTEL
@ GPU_DEVICE_NVIDIA
#define WM_PLATFORM_SUPPORT_TEXT_SIZE