Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_shader_builder.cc
| Show All 9 Lines | |||||
| #include <iostream> | #include <iostream> | ||||
| #include "GHOST_C-api.h" | #include "GHOST_C-api.h" | ||||
| #include "GPU_context.h" | #include "GPU_context.h" | ||||
| #include "GPU_init_exit.h" | #include "GPU_init_exit.h" | ||||
| #include "gpu_shader_create_info_private.hh" | #include "gpu_shader_create_info_private.hh" | ||||
| #include "BLI_vector.hh" | |||||
| #include "CLG_log.h" | #include "CLG_log.h" | ||||
| namespace blender::gpu::shader_builder { | namespace blender::gpu::shader_builder { | ||||
| class ShaderBuilder { | class ShaderBuilder { | ||||
| private: | private: | ||||
| GHOST_SystemHandle ghost_system_; | GHOST_SystemHandle ghost_system_; | ||||
| GHOST_ContextHandle ghost_context_; | GHOST_ContextHandle ghost_context_; | ||||
| Show All 10 Lines | bool ShaderBuilder::bake_create_infos() | ||||
| return gpu_shader_create_info_compile_all(); | return gpu_shader_create_info_compile_all(); | ||||
| } | } | ||||
| void ShaderBuilder::init() | void ShaderBuilder::init() | ||||
| { | { | ||||
| CLG_init(); | CLG_init(); | ||||
| GHOST_GLSettings glSettings = {0}; | GHOST_GLSettings glSettings = {0}; | ||||
| switch (GPU_backend_type_selection_get()) { | |||||
| case GPU_BACKEND_OPENGL: | |||||
| glSettings.context_type = GHOST_kDrawingContextTypeOpenGL; | |||||
| break; | |||||
| #ifdef WITH_METAL_BACKEND | |||||
| case GPU_BACKEND_METAL: | |||||
| glSettings.context_type = GHOST_kDrawingContextTypeMetal; | |||||
| break; | |||||
| #endif | |||||
| default: | |||||
| BLI_assert_unreachable(); | |||||
| break; | |||||
| } | |||||
| ghost_system_ = GHOST_CreateSystem(); | ghost_system_ = GHOST_CreateSystem(); | ||||
| ghost_context_ = GHOST_CreateOpenGLContext(ghost_system_, glSettings); | ghost_context_ = GHOST_CreateOpenGLContext(ghost_system_, glSettings); | ||||
| GHOST_ActivateOpenGLContext(ghost_context_); | GHOST_ActivateOpenGLContext(ghost_context_); | ||||
| gpu_context_ = GPU_context_create(nullptr, ghost_context_); | gpu_context_ = GPU_context_create(nullptr, ghost_context_); | ||||
| GPU_init(); | GPU_init(); | ||||
| } | } | ||||
| Show All 16 Lines | |||||
| { | { | ||||
| if (argc < 2) { | if (argc < 2) { | ||||
| printf("Usage: %s <data_file_to>\n", argv[0]); | printf("Usage: %s <data_file_to>\n", argv[0]); | ||||
| exit(1); | exit(1); | ||||
| } | } | ||||
| int exit_code = 0; | int exit_code = 0; | ||||
| struct NamedBackend { | |||||
| std::string name; | |||||
| eGPUBackendType backend; | |||||
| }; | |||||
MichaelPW: Metal availability on certain devices is dependent on certain available API features, which are… | |||||
| blender::Vector<NamedBackend> backends_to_validate; | |||||
| backends_to_validate.append({"OpenGL", GPU_BACKEND_OPENGL}); | |||||
| #ifdef WITH_METAL_BACKEND | |||||
| backends_to_validate.append({"Metal", GPU_BACKEND_METAL}); | |||||
| #endif | |||||
| for (NamedBackend &backend : backends_to_validate) { | |||||
| GPU_backend_type_selection_set(backend.backend); | |||||
| if (!GPU_backend_supported()) { | |||||
| printf("%s isn't supported on this platform. Shader compilation is skipped\n", | |||||
| backend.name.c_str()); | |||||
| continue; | |||||
| } | |||||
| blender::gpu::shader_builder::ShaderBuilder builder; | blender::gpu::shader_builder::ShaderBuilder builder; | ||||
| builder.init(); | builder.init(); | ||||
| if (!builder.bake_create_infos()) { | if (!builder.bake_create_infos()) { | ||||
| printf("Shader compilation failed for %s backend\n", backend.name.c_str()); | |||||
| exit_code = 1; | exit_code = 1; | ||||
| } | } | ||||
| builder.exit(); | builder.exit(); | ||||
| exit(exit_code); | exit(exit_code); | ||||
| } | |||||
| return exit_code; | return exit_code; | ||||
| } | } | ||||
Metal availability on certain devices is dependent on certain available API features, which are not available on all devices which do support Metal.
While the WITH_METAL_BACKEND CMake flag should guard against OS availability, this only applies to the build platform rather than the device that Blender is running on.
As a result, while I'm not sure how best to factor this into the code, it would be useful to ensure that areas in the code do not attempt to initialise a Metal device if the device fails compatibility as defined in: GPU_backend_supported().
The GPU_backend_supported() could also likely be refactored to take the backend type as a parameter, rather than reading the global for these cases. There may also be other places in the code that it makes sense to guard.