Changeset View
Standalone View
source/blender/windowmanager/intern/wm_platform_support.c
- This file was added.
| /* | |||||
| * This program is free software; you can redistribute it and/or | |||||
| * modify it under the terms of the GNU General Public License | |||||
| * as published by the Free Software Foundation; either version 2 | |||||
| * of the License, or (at your option) any later version. | |||||
| * | |||||
| * This program is distributed in the hope that it will be useful, | |||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
| * GNU General Public License for more details. | |||||
| * | |||||
| * You should have received a copy of the GNU General Public License | |||||
| * along with this program; if not, write to the Free Software Foundation, | |||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
| * | |||||
| * The Original Code is Copyright (C) 2019 Blender Foundation. | |||||
| * All rights reserved. | |||||
| */ | |||||
| /** \file | |||||
| * \ingroup wm | |||||
| */ | |||||
| #include "wm_platform_support.h" | |||||
| #include "wm_window_private.h" | |||||
| #include <string.h> | |||||
| #include "BLI_sys_types.h" | |||||
| #include "BLI_dynstr.h" | |||||
| #include "BLI_path_util.h" | |||||
| #include "BLI_fileops.h" | |||||
| #include "BLI_string.h" | |||||
| #include "BLI_linklist.h" | |||||
| #include "BLT_translation.h" | |||||
| #include "BKE_appdir.h" | |||||
| #include "BKE_global.h" | |||||
| #include "GPU_platform.h" | |||||
| #include "GHOST_C-api.h" | |||||
| #define WM_PLATFORM_SUPPORT_TEXT_SIZE 1024 | |||||
| /* Check if user has already approved the given platform_support_key. */ | |||||
| static bool wm_platform_support_check_approval(const char *platform_support_key, bool update) | |||||
| { | |||||
| const char *const cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, NULL); | |||||
| bool result = false; | |||||
| if (G.factory_startup) { | |||||
| return result; | |||||
| } | |||||
| if (cfgdir) { | |||||
| char filepath[FILE_MAX]; | |||||
| BLI_make_file_string("/", filepath, cfgdir, BLENDER_PLATFORM_SUPPORT_FILE); | |||||
| LinkNode *lines = BLI_file_read_as_lines(filepath); | |||||
| for (LinkNode *line_node = lines; line_node; line_node = line_node->next) { | |||||
| char *line = line_node->link; | |||||
| if (STREQ(line, platform_support_key)) { | |||||
| result = true; | |||||
| break; | |||||
| } | |||||
| } | |||||
| if (!result && update) { | |||||
| FILE *fp = BLI_fopen(filepath, "a"); | |||||
| if (fp) { | |||||
| fprintf(fp, "%s\n", platform_support_key); | |||||
| fclose(fp); | |||||
| } | |||||
| } | |||||
| BLI_file_free_lines(lines); | |||||
| } | |||||
| return result; | |||||
| } | |||||
| static void wm_platform_support_create_link(char *link) | |||||
| { | |||||
| DynStr *ds = BLI_dynstr_new(); | |||||
| BLI_dynstr_append(ds, "https://docs.blender.org/manual/en/latest/troubleshooting/gpu/"); | |||||
| #if defined(_WIN32) | |||||
brecht: Don't show a warning for unknown vendors, we should purely be blacklisting, not whitelisting. | |||||
Done Inline ActionsChange latest to dev since the 2.80 manual does not have this info. We could change it after the release, though maybe it is better regardless to always link to the very latest manual, in case the driver download links change or we want to add extra info. brecht: Change `latest` to `dev` since the 2.80 manual does not have this info.
We could change it… | |||||
| BLI_dynstr_append(ds, "windows/"); | |||||
| #elif defined(__APPLE__) | |||||
| BLI_dynstr_append(ds, "apple/"); | |||||
| #else /* UNIX */ | |||||
| BLI_dynstr_append(ds, "linux/"); | |||||
| #endif | |||||
| if (GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_ANY, GPU_DRIVER_ANY)) { | |||||
| BLI_dynstr_append(ds, "intel.html"); | |||||
| } | |||||
| else if (GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_ANY, GPU_DRIVER_ANY)) { | |||||
| BLI_dynstr_append(ds, "nvidia.html"); | |||||
| } | |||||
Done Inline ActionsIf a computer has graphics switching and both cards are unsupported, we will show the warning many times. So I think this should store multiple keys. For the implementation, BLI_file_read_as_lines could be used. New lines would have to be stripped. It's may also be simplest if wm_platform_support_load_state and wm_platform_support_save_state get merged into a single function. It can check if the given key is in the file, and if not append it. brecht: If a computer has graphics switching and both cards are unsupported, we will show the warning… | |||||
| else if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY)) { | |||||
| BLI_dynstr_append(ds, "amd.html"); | |||||
| } | |||||
| else { | |||||
| BLI_dynstr_append(ds, "unknown.html"); | |||||
| } | |||||
| BLI_assert(BLI_dynstr_get_len(ds) < WM_PLATFORM_SUPPORT_TEXT_SIZE); | |||||
| BLI_dynstr_get_cstring_ex(ds, link); | |||||
| BLI_dynstr_free(ds); | |||||
| } | |||||
| bool WM_platform_support_perform_checks() | |||||
| { | |||||
| char title[WM_PLATFORM_SUPPORT_TEXT_SIZE]; | |||||
| char message[WM_PLATFORM_SUPPORT_TEXT_SIZE]; | |||||
| char link[WM_PLATFORM_SUPPORT_TEXT_SIZE]; | |||||
| bool result = true; | |||||
| eGPUSupportLevel support_level = GPU_platform_support_level(); | |||||
| const char *platform_key = GPU_platform_support_level_key(); | |||||
| /* check if previous check matches the current check. Don't update the approval when running in | |||||
| * `background`. this could have been triggered by installing addons via installers. */ | |||||
| if (support_level != GPU_SUPPORT_LEVEL_UNSUPPORTED && !G.factory_startup && | |||||
| wm_platform_support_check_approval(platform_key, !G.background)) { | |||||
| /* if it matches the user has confirmed and whishes to use it */ | |||||
| return result; | |||||
| } | |||||
| /* update the message and link based on the found support level */ | |||||
| GHOST_DialogOptions dialog_options = 0; | |||||
| /* TODO: do not translate Application name */ | |||||
| switch (support_level) { | |||||
Done Inline Actionsthis writes a \n that later will be returned in wm_platform_support_load_state causing the strcmp later on to fail and give the popup every time the user starts blender. LazyDodo: this writes a `\n` that later will be returned in `wm_platform_support_load_state` causing the… | |||||
Done Inline ActionsGotcha! well we will be refactoring load_state and save_state so this will not be an issue anymore jbakker: Gotcha! well we will be refactoring load_state and save_state so this will not be an issue… | |||||
| default: | |||||
| case GPU_SUPPORT_LEVEL_SUPPORTED: | |||||
| break; | |||||
| case GPU_SUPPORT_LEVEL_LIMITED: | |||||
| strcpy( | |||||
| title, | |||||
| BLI_strdupcat("Blender - ", | |||||
| CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Limited Platform Support"))); | |||||
| strcpy(message, | |||||
| CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, | |||||
| "Your graphics card or driver has limited support. It may work, but with " | |||||
| "issues.\n\n" | |||||
| "Press help to see if the support can be improved.")); | |||||
| dialog_options = GHOST_DialogWarning; | |||||
| break; | |||||
| case GPU_SUPPORT_LEVEL_UNSUPPORTED: | |||||
| strcpy(title, | |||||
| BLI_strdupcat("Blender - ", | |||||
| CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Platform Unsupported"))); | |||||
| strcpy(message, | |||||
| CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, | |||||
| "Your graphics card or driver is not supported.\n\n" | |||||
| "Press help to see if the support can be improved.\n\n" | |||||
| "The program will now close.")); | |||||
| dialog_options = GHOST_DialogError; | |||||
| result = false; | |||||
| break; | |||||
| } | |||||
| wm_platform_support_create_link(link); | |||||
| bool show_message = ELEM( | |||||
| support_level, GPU_SUPPORT_LEVEL_LIMITED, GPU_SUPPORT_LEVEL_UNSUPPORTED); | |||||
| /* We are running in the background print the message in the console. */ | |||||
| if ((G.background || G.debug & G_DEBUG) && show_message) { | |||||
Done Inline ActionsI think we should deduplicate this code with gpu_extensions_init. What I suggest is to add gpu_platform.c containing gpu_platform_init() to detect GG.device, GG.driver and GG.os. GPU_type_matches(), eWM_SupportLevel, WM_PlatformSupportTest would all in that file as well then. gpu_extensions_init() would use GPU_type_matches(). brecht: I think we should deduplicate this code with `gpu_extensions_init`.
What I suggest is to add… | |||||
| printf("%s\n\n%s\n%s\n", title, message, link); | |||||
| } | |||||
| if (G.background) { | |||||
| /* don't show the messagebox when running in background mode. Printing to | |||||
| * console is enough. */ | |||||
| result = true; | |||||
| } | |||||
| else if (show_message) { | |||||
| WM_ghost_show_message_box(title, message, link, dialog_options); | |||||
| } | |||||
| return result; | |||||
| } | |||||
| No newline at end of file | |||||
Done Inline ActionsLimitted -> Limited brecht: Limitted -> Limited | |||||
Done Inline Actions__APPLE -> __APPLE__ brecht: `__APPLE` -> `__APPLE__` | |||||
Done Inline ActionsWhy not save in background mode? brecht: Why not save in background mode? | |||||
Done Inline ActionsWhen running in background mode the user might not notice that there is a support issue. By not doing this during background we know for sure that the message has been seen. jbakker: When running in background mode the user might not notice that there is a support issue.
There… | |||||
Done Inline Actionsand -> or brecht: and -> or | |||||
Done Inline ActionsThis seems to say a solution is definitely possible, might want to formulate it a bit different. brecht: This seems to say a solution is definitely possible, might want to formulate it a bit different. | |||||
Done Inline ActionsLazyDodo: {F7785798}
1) layout doesn't look great
2) `Your graphics card and driver has limited.`… | |||||
Done Inline Actionsis -> are LazyDodo: is -> are | |||||

Don't show a warning for unknown vendors, we should purely be blacklisting, not whitelisting.