58 VkPhysicalDeviceProperties2 vk_physical_device_properties = {};
59 VkPhysicalDeviceDriverProperties vk_physical_device_driver_properties = {};
60 vk_physical_device_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
61 vk_physical_device_driver_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES;
62 vk_physical_device_properties.pNext = &vk_physical_device_driver_properties;
63 vkGetPhysicalDeviceProperties2(vk_physical_device, &vk_physical_device_properties);
77 if (vk_physical_device_driver_properties.driverID == VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS &&
78 vk_physical_device_properties.properties.deviceType ==
79 VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU)
81 const uint32_t driver_version = vk_physical_device_properties.properties.driverVersion;
82 uint32_t driver_version_major = driver_version >> 14u;
83 uint32_t driver_version_minor = driver_version & 0x3fffu;
84 if (driver_version_major < 101 || (driver_version_major == 101 && driver_version_minor < 2140))
97 uint32_t conformance_version = VK_MAKE_API_VERSION(
98 vk_physical_device_driver_properties.conformanceVersion.major,
99 vk_physical_device_driver_properties.conformanceVersion.minor,
100 vk_physical_device_driver_properties.conformanceVersion.subminor,
101 vk_physical_device_driver_properties.conformanceVersion.patch);
102 if (vk_physical_device_driver_properties.driverID == VK_DRIVER_ID_NVIDIA_PROPRIETARY &&
103 conformance_version < VK_MAKE_API_VERSION(1, 3, 7, 2))
112 if (vk_physical_device_driver_properties.driverID == VK_DRIVER_ID_NVIDIA_PROPRIETARY &&
113 ((
StringRefNull(vk_physical_device_driver_properties.driverInfo).
find(
"580.76.5", 0) !=
115 (
StringRefNull(vk_physical_device_driver_properties.driverInfo).
find(
"580.76.05", 0) !=
123 if (vk_physical_device_driver_properties.driverID == VK_DRIVER_ID_QUALCOMM_PROPRIETARY) {
130 const uint32_t driver_version = vk_physical_device_properties.properties.driverVersion;
131 constexpr uint32_t version_31_0_112 = VK_MAKE_VERSION(512, 827, 0);
132 if (driver_version < version_31_0_112) {
134 "Detected qualcomm driver is not supported. To run the Vulkan backend "
135 "driver 31.0.112.0 or later is required. Switching to OpenGL.");
150 vkEnumerateDeviceExtensionProperties(vk_physical_device,
nullptr, &vk_extension_count,
nullptr);
153 vkEnumerateDeviceExtensionProperties(
154 vk_physical_device,
nullptr, &vk_extension_count, vk_extensions.
data());
156 for (VkExtensionProperties &vk_extension : vk_extensions) {
157 extensions.
add(vk_extension.extensionName);
160 if (!extensions.
contains(VK_KHR_SWAPCHAIN_EXTENSION_NAME)) {
161 missing_capabilities.append(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
163 if (!extensions.
contains(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME)) {
164 missing_capabilities.append(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME);
166 if (!extensions.
contains(VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME)) {
167 missing_capabilities.append(VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME);
169 if (!extensions.
contains(VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME)) {
170 missing_capabilities.append(VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME);
172 if (!extensions.
contains(VK_KHR_SEPARATE_DEPTH_STENCIL_LAYOUTS_EXTENSION_NAME)) {
173 missing_capabilities.append(VK_KHR_SEPARATE_DEPTH_STENCIL_LAYOUTS_EXTENSION_NAME);
177 VkPhysicalDeviceFeatures2 features = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2};
178 vkGetPhysicalDeviceFeatures2(vk_physical_device, &features);
182 if (features.features.geometryShader == VK_FALSE) {
183 missing_capabilities.append(
"geometry shaders");
186 if (features.features.fragmentStoresAndAtomics == VK_FALSE) {
187 missing_capabilities.append(
"fragment stores and atomics");
189 if (features.features.dualSrcBlend == VK_FALSE) {
190 missing_capabilities.append(
"dual source blending");
192 if (features.features.imageCubeArray == VK_FALSE) {
193 missing_capabilities.append(
"image cube array");
195 if (features.features.drawIndirectFirstInstance == VK_FALSE) {
196 missing_capabilities.append(
"draw indirect first instance");
199 return missing_capabilities;
213 std::stringstream allowed_layers;
214 allowed_layers <<
"VK_LAYER_KHRONOS_*";
215 allowed_layers <<
",VK_LAYER_AMD_*";
216 allowed_layers <<
",VK_LAYER_INTEL_*";
217 allowed_layers <<
",VK_LAYER_NV_*";
218 allowed_layers <<
",VK_LAYER_MESA_*";
220 allowed_layers <<
",VK_LAYER_LUNARG_*";
221 allowed_layers <<
",VK_LAYER_RENDERDOC_*";
223 BLI_setenv(
"VK_LOADER_LAYERS_DISABLE",
"~implicit~");
224 BLI_setenv(
"VK_LOADER_LAYERS_ALLOW", allowed_layers.str().c_str());
231 VkResult vk_result = volkInitialize();
232 if (vk_result != VK_SUCCESS) {
234 "Error initializing Vulkan loader: VkResult=%d, most likely cannot find the Vulkan "
235 "Loader provided by GPU driver/OS.",
241 VkApplicationInfo vk_application_info = {VK_STRUCTURE_TYPE_APPLICATION_INFO};
242 vk_application_info.pApplicationName =
"Blender";
243 vk_application_info.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
244 vk_application_info.pEngineName =
"Blender";
245 vk_application_info.engineVersion = VK_MAKE_VERSION(1, 0, 0);
246 vk_application_info.apiVersion = VK_API_VERSION_1_1;
248 const char *vk_instance_extensions[] = {
249 VK_KHR_SURFACE_EXTENSION_NAME,
252 VkInstanceCreateInfo vk_instance_info = {VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO};
253 vk_instance_info.pApplicationInfo = &vk_application_info;
254 vk_instance_info.ppEnabledExtensionNames = vk_instance_extensions;
255 vk_instance_info.enabledExtensionCount = 1;
257 *r_instance = VK_NULL_HANDLE;
258 vkCreateInstance(&vk_instance_info,
nullptr, r_instance);
260 return *r_instance != VK_NULL_HANDLE;
267 VkInstance vk_instance = VK_NULL_HANDLE;
269 CLOG_WARN(&
LOG,
"Unable to initialize a Vulkan 1.1 instance.");
272 volkLoadInstanceOnly(vk_instance);
275 uint32_t physical_devices_count = 0;
276 vkEnumeratePhysicalDevices(vk_instance, &physical_devices_count,
nullptr);
278 vkEnumeratePhysicalDevices(vk_instance, &physical_devices_count, vk_physical_devices.
data());
280 for (VkPhysicalDevice vk_physical_device : vk_physical_devices) {
281 VkPhysicalDeviceProperties vk_properties = {};
282 vkGetPhysicalDeviceProperties(vk_physical_device, &vk_properties);
286 "Installed driver for device [%s] has known issues and will not be used. Updating "
287 "driver might improve compatibility.",
288 vk_properties.deviceName);
294 if (missing_capabilities.is_empty()) {
298 "Device [%s] supports minimum requirements. Skip checking other GPUs. Another GPU "
299 "can still be selected during auto-detection.",
300 vk_properties.deviceName);
302 vkDestroyInstance(vk_instance,
nullptr);
306 std::stringstream ss;
307 ss <<
"Device [" << vk_properties.deviceName
308 <<
"] does not meet minimum requirements. Missing features are [";
310 ss << feature <<
", ";
312 ss.seekp(-2, std::ios_base::end);
319 vkDestroyInstance(vk_instance,
nullptr);
321 "No Vulkan device found that meets the minimum requirements. "
322 "Updating GPU driver can improve compatibility.");
330 VkInstance vk_instance = VK_NULL_HANDLE;
332 fprintf(fp,
"Unable to initialize a Vulkan 1.2 instance.\n");
335 volkLoadInstanceOnly(vk_instance);
337 uint32_t physical_devices_count = 0;
338 vkEnumeratePhysicalDevices(vk_instance, &physical_devices_count,
nullptr);
340 vkEnumeratePhysicalDevices(vk_instance, &physical_devices_count, vk_physical_devices.
data());
344 std::string identifier;
349 for (VkPhysicalDevice vk_physical_device : vk_physical_devices) {
353 VkPhysicalDeviceProperties vk_properties = {};
354 vkGetPhysicalDeviceProperties(vk_physical_device, &vk_properties);
355 std::stringstream identifier;
356 identifier << std::hex << vk_properties.vendorID <<
"/" << vk_properties.deviceID <<
"/"
358 rows.append({
index, identifier.str(), std::string(vk_properties.deviceName)});
363 if (rows.is_empty()) {
364 fprintf(fp,
" (no supported Vulkan devices found)\n");
365 vkDestroyInstance(vk_instance,
nullptr);
369 const char *col_index =
"Index";
370 const char *col_id =
"Device-ID";
371 const char *col_name =
"Name";
372 size_t w_index = strlen(col_index);
373 size_t w_id = strlen(col_id);
374 for (
const Row &row : rows) {
376 w_index = std::max(w_index,
SNPRINTF_RLEN(buf,
"%d", row.index));
377 w_id = std::max(w_id, row.identifier.size());
380 fprintf(fp,
" %-*s %-*s %s\n",
int(w_index), col_index,
int(w_id), col_id, col_name);
381 for (
const Row &row : rows) {
387 row.identifier.c_str(),
391 vkDestroyInstance(vk_instance,
nullptr);
398#elif defined(__APPLE__)
420 GHOST_VulkanHandles vulkan_handles = {};
421 ghost_context->getVulkanHandles(vulkan_handles);
423 uint32_t physical_devices_count = 0;
424 vkEnumeratePhysicalDevices(vulkan_handles.instance, &physical_devices_count,
nullptr);
426 vkEnumeratePhysicalDevices(
427 vulkan_handles.instance, &physical_devices_count, vk_physical_devices.
data());
429 for (VkPhysicalDevice vk_physical_device : vk_physical_devices) {
433 VkPhysicalDeviceProperties vk_properties = {};
434 vkGetPhysicalDeviceProperties(vk_physical_device, &vk_properties);
435 std::stringstream identifier;
436 identifier << std::hex << vk_properties.vendorID <<
"/" << vk_properties.deviceID <<
"/"
440 vk_properties.vendorID,
441 vk_properties.deviceID,
442 std::string(vk_properties.deviceName)});
448 if (a.name == b.name) {
449 return a.index < b.index;
451 return a.
name <
b.name;
477 properties.deviceName,
478 driver_version.c_str(),
486 if (id_properties.deviceLUIDValid) {
496 "Using vendor [%s] device [%s] driver version [%s].",
498 device.vk_physical_device_properties_.deviceName,
499 driver_version.c_str());
502void VKBackend::detect_workarounds(
VKDevice &device)
508 CLOG_WARN(&
LOG,
"Forcing workarounds and disabling features and extensions");
530 device.workarounds_ = workarounds;
531 device.extensions_ = extensions;
546 VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_EXTENSION_NAME);
550 VK_KHR_FRAGMENT_SHADER_BARYCENTRIC_EXTENSION_NAME);
552 VK_KHR_DYNAMIC_RENDERING_LOCAL_READ_EXTENSION_NAME);
554 VK_EXT_DYNAMIC_RENDERING_UNUSED_ATTACHMENTS_EXTENSION_NAME);
559 VK_EXT_PAGEABLE_DEVICE_LOCAL_MEMORY_EXTENSION_NAME);
561 VK_EXT_GRAPHICS_PIPELINE_LIBRARY_EXTENSION_NAME);
563 VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME);
565 VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME);
567 VK_EXT_VERTEX_INPUT_DYNAMIC_STATE_EXTENSION_NAME);
576 VK_KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME);
577#elif not defined(__APPLE__)
666 if (driver_version <= VK_MAKE_API_VERSION(2, 0, 294, 0)) {
675 device.workarounds_ = workarounds;
676 device.extensions_ = extensions;
679void VKBackend::platform_exit()
683 if (
device.is_initialized()) {
708 context.render_graph().add_node(dispatch_info);
721 context.render_graph().add_node(dispatch_indirect_info);
726 if (!
device.is_initialized()) {
727 device.init(ghost_context);
728 device.extensions_get().log();
729 device.workarounds_get().log();
734 device.context_register(*context);
735 ghost_context->setVulkanSwapBuffersCallbacks(
838 if (context !=
nullptr) {
841 std::scoped_lock
lock(
device.orphaned_data.mutex_get());
842 device.orphaned_data.move_data(
device.orphaned_data_render,
843 device.orphaned_data.timeline_ + 1);
851 std::scoped_lock
lock(
device.orphaned_data.mutex_get());
852 device.orphaned_data.move_data(
device.orphaned_data_render,
853 device.orphaned_data.timeline_ + 1);
859 if (force_resource_release) {
860 std::scoped_lock
lock(
device.orphaned_data.mutex_get());
861 device.orphaned_data.move_data(
device.orphaned_data_render,
862 device.orphaned_data.timeline_ + 1);
869 const VkPhysicalDeviceLimits &limits = properties.limits;
875 VK_EXT_SHADER_STENCIL_EXPORT_EXTENSION_NAME);
888 limits.maxViewports >= GPU_MAX_VIEWPORTS;
898 for (
int i = 0; i < 3; i++) {
903 limits.maxPerStageDescriptorUniformBuffers,
INT_MAX);
909 limits.maxPerStageDescriptorStorageBuffers,
INT_MAX);
918 vkEnumerateDeviceExtensionProperties(
923 detect_workarounds(
device);
#define SNPRINTF_RLEN(dst, format,...)
#define CLOG_ERROR(clg_ref,...)
#define CLOG_DEBUG(clg_ref,...)
#define CLOG_WARN(clg_ref,...)
void CLG_logref_init(CLG_LogRef *clg_ref)
#define CLOG_TRACE(clg_ref,...)
#define CLOG_INFO(clg_ref,...)
#define BLI_assert_msg(a, msg)
void reinitialize(const int64_t new_size)
bool contains(const Key &key) const
static constexpr int64_t not_found
constexpr int64_t find(char c, int64_t pos=0) const
ShaderCompiler * compiler_
void render_step(bool) override
TexturePool * texturepool_alloc() override
TopLevelAS * tlas_alloc(const char *name) override
Batch * batch_alloc() override
StorageBuf * storagebuf_alloc(size_t size, GPUUsageType usage, const char *name) override
static void capabilities_init(VKDevice &device)
IndexBuf * indexbuf_alloc() override
BottomLevelAS * blas_alloc(const char *name) override
static void platform_init(const VKDevice &device)
QueryPool * querypool_alloc() override
static bool is_supported()
UniformBuf * uniformbuf_alloc(size_t size, const char *name) override
Texture * texture_alloc(const char *name) override
PixelBuffer * pixelbuf_alloc(size_t size) override
void render_begin() override
Shader * shader_alloc(const char *name) override
void render_end() override
FrameBuffer * framebuffer_alloc(const char *name) override
void compute_dispatch(int groups_x_len, int groups_y_len, int groups_z_len) override
void compute_dispatch_indirect(StorageBuf *indirect_buf) override
void delete_resources() override
void init_resources() override
VertBuf * vertbuf_alloc() override
Context * context_alloc(GHOST_IWindow *ghost_window, GHOST_IContext *ghost_context) override
WorkInFlight * work_in_flight_alloc(unsigned int max_in_flight) override
Fence * fence_alloc() override
static void supported_devices_print(FILE *fp)
VKBottomLevelAS(const char *name)
static void swap_buffer_draw_callback(const GHOST_VulkanSwapChainData *data, bool wait_for_submission)
VKContext(GHOST_IWindow *ghost_window, GHOST_IContext *ghost_context)
static void openxr_acquire_framebuffer_image_callback(GHOST_VulkanOpenXRData *data)
static void swap_buffer_acquired_callback()
static void openxr_release_framebuffer_image_callback(GHOST_VulkanOpenXRData *data)
const char * extension_name_get(int index) const
const VkPhysicalDeviceFeatures & physical_device_features_get() const
GPUDriverType driver_type() const
bool supports_extension(const char *extension_name) const
const VkPhysicalDeviceProperties & physical_device_properties_get() const
std::string vendor_name() const
std::string driver_version() const
GPUDeviceType device_type() const
const VkPhysicalDeviceIDProperties & physical_device_id_properties_get() const
const VkPhysicalDeviceAccelerationStructurePropertiesKHR & physical_device_acceleration_structure_properties_get()
VkPhysicalDevice physical_device_get() const
VKFrameBuffer(const char *name)
VKPixelBuffer(size_t size)
VKShader(const char *name)
const VKResourceWithHandle< VkBuffer > & resource() const
VKStorageBuffer(size_t size, GPUUsageType usage, const char *name)
VKTexture(const char *name)
VKTopLevelAS(const char *name)
VKWorkInFlight(unsigned int max_in_flight)
VKDispatchCreateInfo CreateInfo
bool GPU_vulkan_is_supported_driver(VkPhysicalDevice vk_physical_device)
static void vk_restrict_loader_layers()
static bool vk_instance_create_for_platform_checks(VkInstance *r_instance)
BLI_INLINE MTLTexture * unwrap(Texture *tex)
static GPUOSType determine_os_type()
static void init_device_list(GHOST_IContext *ghost_context)
static const char * vk_extension_get(int index)
static Vector< StringRefNull > missing_capabilities_get(VkPhysicalDevice vk_physical_device)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE int max_ii(int a, int b)
void BLI_setenv(const char *env, const char *val) ATTR_NONNULL(1)
@ G_DEBUG_GPU_NO_HW_RAYTRACING
@ G_DEBUG_GPU_NO_TEXTURE_POOL
@ G_DEBUG_GPU_FORCE_VULKAN_LOCAL_READ
@ G_DEBUG_GPU_FORCE_WORKAROUNDS
@ GPU_SUPPORT_LEVEL_SUPPORTED
int BLI_system_thread_count()
bool GPU_type_matches(GPUDeviceType device, GPUOSType os, GPUDriverType driver)
GPUIntelGpuArch GPU_platform_get_intel_arch(uint32_t device_id)
int GPU_max_parallel_compilations()
MINLINE uint min_uu(uint a, uint b)
int max_shader_storage_buffer_bindings
bool multi_viewport_support
int max_parallel_compilations
bool geometry_shader_support
bool texture_pool_workaround
int max_work_group_size[3]
size_t max_uniform_buffer_size
const char *(*) extension_get(int)
uint32_t max_buffer_texture_size
int max_work_group_count[3]
int max_compute_shader_storage_blocks
size_t storage_buffer_alignment
bool vertex_pipeline_stores_and_atomics_support
bool stencil_export_support
bool srgb_write_view_support
size_t max_storage_buffer_size
bool dynamic_rendering_unused_attachments
bool extended_dynamic_state
bool fragment_shader_barycentric
bool pageable_device_local_memory
bool shader_clip_distance
bool graphics_pipeline_library
bool dynamic_rendering_local_read
bool shader_viewport_index_layer
bool vertex_input_dynamic_state
bool not_aligned_pixel_formats
bool missing_srgb_clear_conversion
bool static_viewport_scissor
VKDispatchData dispatch_node
VKPipelineData pipeline_data
VKDispatchIndirectData dispatch_indirect_node
VKPipelineData pipeline_data
VKResourceWithHandle< VkBuffer > buffer