Blender V4.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.h"
14#include "BLI_fileops.h"
15#include "BLI_linklist.h"
16#include "BLI_path_utils.hh"
17#include "BLI_string.h"
18
19#include "BLT_translation.hh"
20
21#include "BKE_appdir.hh"
22#include "BKE_global.hh"
23
24#include "GPU_platform.hh"
25
26#define WM_PLATFORM_SUPPORT_TEXT_SIZE 1024
27
31static bool wm_platform_support_check_approval(const char *platform_support_key, bool update)
32{
33 if (G.factory_startup) {
34 return false;
35 }
36 const std::optional<std::string> cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, nullptr);
37 if (!cfgdir.has_value()) {
38 return false;
39 }
40
41 bool result = false;
42 char filepath[FILE_MAX];
43 BLI_path_join(filepath, sizeof(filepath), cfgdir->c_str(), BLENDER_PLATFORM_SUPPORT_FILE);
44 LinkNode *lines = BLI_file_read_as_lines(filepath);
45 for (LinkNode *line_node = lines; line_node; line_node = line_node->next) {
46 const char *line = static_cast<char *>(line_node->link);
47 if (STREQ(line, platform_support_key)) {
48 result = true;
49 break;
50 }
51 }
52
53 if (!result && update) {
54 FILE *fp = BLI_fopen(filepath, "a");
55 if (fp) {
56 fprintf(fp, "%s\n", platform_support_key);
57 fclose(fp);
58 }
59 }
60
62 return result;
63}
64
65static void wm_platform_support_create_link(char *link)
66{
67 DynStr *ds = BLI_dynstr_new();
68
69 BLI_dynstr_append(ds, "https://docs.blender.org/manual/en/dev/troubleshooting/gpu/");
70#if defined(_WIN32)
71 BLI_dynstr_append(ds, "windows/");
72#elif defined(__APPLE__)
73 BLI_dynstr_append(ds, "apple/");
74#else /* UNIX. */
75 BLI_dynstr_append(ds, "linux/");
76#endif
77
79 BLI_dynstr_append(ds, "intel.html");
80 }
82 BLI_dynstr_append(ds, "nvidia.html");
83 }
85 BLI_dynstr_append(ds, "amd.html");
86 }
87 else {
88 BLI_dynstr_append(ds, "unknown.html");
89 }
90
94}
95
97{
101
102 bool result = true;
103
105 const char *platform_key = GPU_platform_support_level_key();
106
107 /* Check if previous check matches the current check. Don't update the approval when running in
108 * `background`. this could have been triggered by installing add-ons via installers. */
109 if (support_level != GPU_SUPPORT_LEVEL_UNSUPPORTED && !G.factory_startup &&
110 wm_platform_support_check_approval(platform_key, !G.background))
111 {
112 /* If it matches the user has confirmed and wishes to use it. */
113 return result;
114 }
115
116 /* Update the message and link based on the found support level. */
117 GHOST_DialogOptions dialog_options = GHOST_DialogOptions(0);
118
119 switch (support_level) {
120 default:
122 break;
123
125 size_t slen = 0;
126 STR_CONCAT(title, slen, "Blender - ");
128 title, slen, CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Limited Platform Support"));
129 slen = 0;
131 message,
132 slen,
134 "Your graphics card or driver has limited support. It may work, but with "
135 "issues."));
136
137 /* TODO: Extra space is needed for the split function in GHOST_SystemX11. We should change
138 * the behavior in GHOST_SystemX11. */
139 STR_CONCAT(message, slen, "\n \n");
141 message,
142 slen,
144 "Newer graphics drivers may be available to improve Blender support."));
145 STR_CONCAT(message, slen, "\n \n");
146 STR_CONCAT(message, slen, CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Graphics card:\n"));
147 STR_CONCAT(message, slen, GPU_platform_gpu_name());
148
149 dialog_options = GHOST_DialogWarning;
150 break;
151 }
152
154 size_t slen = 0;
155 STR_CONCAT(title, slen, "Blender - ");
157 title, slen, CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Platform Unsupported"));
158 slen = 0;
159
160#ifdef __APPLE__
163 message,
164 slen,
165 CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Your graphics card is not supported"));
166 }
167 else {
168 STR_CONCAT(message,
169 slen,
171 "Your graphics card or macOS version is not supported"));
172 STR_CONCAT(message, slen, "\n \n");
173
175 message,
176 slen,
178 "Upgrading to the latest macOS version may improve Blender support"));
179 }
180#else
181 STR_CONCAT(message,
182 slen,
184 "Your graphics card or driver is not supported."));
185 STR_CONCAT(message, slen, "\n \n");
187 message,
188 slen,
190 "Newer graphics drivers may be available to improve Blender support."));
191
192 STR_CONCAT(message, slen, "\n \n");
193 STR_CONCAT(message, slen, CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Graphics card:\n"));
194 STR_CONCAT(message, slen, GPU_platform_gpu_name());
195#endif
196 STR_CONCAT(message, slen, "\n \n");
197
198 STR_CONCAT(message,
199 slen,
200 CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "The program will now close."));
201 dialog_options = GHOST_DialogError;
202 result = false;
203 break;
204 }
205 }
206
207 bool backend_detected = GPU_backend_get_type() != GPU_BACKEND_NONE;
208 bool show_message = ELEM(
210 bool show_continue = backend_detected;
211 bool show_link = backend_detected;
212 link[0] = '\0';
213 if (show_link) {
215 }
216
217 /* We are running in the background print the message in the console. */
218 if ((G.background || G.debug & G_DEBUG) && show_message) {
219 printf("%s\n\n%s\n%s\n", title, message, link);
220 }
221 if (G.background) {
222 /* Don't show the message-box when running in background mode.
223 * Printing to console is enough. */
224 result = true;
225 }
226 else if (show_message) {
228 message,
229 "Find Latest Drivers",
230 show_continue ? "Continue Anyway" : "Exit",
231 link,
232 dialog_options);
233 }
234
235 return result;
236}
@ BLENDER_USER_CONFIG
std::optional< std::string > BKE_appdir_folder_id(int folder_id, const char *subfolder) ATTR_WARN_UNUSED_RESULT
Definition appdir.cc:704
#define BLENDER_PLATFORM_SUPPORT_FILE
@ G_DEBUG
#define BLI_assert(a)
Definition BLI_assert.h:50
A dynamically sized string ADT.
int BLI_dynstr_get_len(const DynStr *ds) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition BLI_dynstr.c:128
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_get_cstring_ex(const DynStr *__restrict ds, char *__restrict rets) ATTR_NONNULL()
Definition BLI_dynstr.c:133
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
Definition BLI_dynstr.c:62
File and directory operations.
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
struct LinkNode * BLI_file_read_as_lines(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:554
void BLI_file_free_lines(struct LinkNode *lines)
Definition storage.cc:600
#define FILE_MAX
#define BLI_path_join(...)
#define STR_CONCAT(dst, len, suffix)
Definition BLI_string.h:602
#define ELEM(...)
#define STREQ(a, b)
#define BLT_I18NCONTEXT_ID_WINDOWMANAGER
#define CTX_IFACE_(context, msgid)
GHOST_DialogOptions
Definition GHOST_Types.h:80
@ GHOST_DialogError
Definition GHOST_Types.h:82
@ GHOST_DialogWarning
Definition GHOST_Types.h:81
eGPUBackendType GPU_backend_get_type()
@ GPU_DRIVER_ANY
const char * GPU_platform_gpu_name()
const char * GPU_platform_support_level_key()
eGPUSupportLevel
@ GPU_SUPPORT_LEVEL_LIMITED
@ GPU_SUPPORT_LEVEL_SUPPORTED
@ GPU_SUPPORT_LEVEL_UNSUPPORTED
@ GPU_OS_ANY
@ GPU_DEVICE_ATI
@ GPU_DEVICE_NVIDIA
@ GPU_DEVICE_INTEL
bool GPU_type_matches(eGPUDeviceType device, eGPUOSType os, eGPUDriverType driver)
eGPUSupportLevel GPU_platform_support_level()
#define printf
#define G(x, y, z)
static void update(bNodeTree *ntree)
struct LinkNode * next
static bool wm_platform_support_check_approval(const char *platform_support_key, bool update)
#define WM_PLATFORM_SUPPORT_TEXT_SIZE
bool WM_platform_support_perform_checks()
static void wm_platform_support_create_link(char *link)
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)