summaryrefslogtreecommitdiff
path: root/drivers/vulkan
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/vulkan')
-rw-r--r--drivers/vulkan/rendering_device_vulkan.cpp77
-rw-r--r--drivers/vulkan/rendering_device_vulkan.h2
-rw-r--r--drivers/vulkan/vulkan_context.cpp306
-rw-r--r--drivers/vulkan/vulkan_context.h4
4 files changed, 212 insertions, 177 deletions
diff --git a/drivers/vulkan/rendering_device_vulkan.cpp b/drivers/vulkan/rendering_device_vulkan.cpp
index 708ea4b265..ba623eb298 100644
--- a/drivers/vulkan/rendering_device_vulkan.cpp
+++ b/drivers/vulkan/rendering_device_vulkan.cpp
@@ -387,14 +387,6 @@ const VkFormat RenderingDeviceVulkan::vulkan_formats[RenderingDevice::DATA_FORMA
VK_FORMAT_G16_B16_R16_3PLANE_422_UNORM,
VK_FORMAT_G16_B16R16_2PLANE_422_UNORM,
VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM,
- VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG,
- VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG,
- VK_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG,
- VK_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG,
- VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG,
- VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG,
- VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG,
- VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG,
};
const char *RenderingDeviceVulkan::named_formats[RenderingDevice::DATA_FORMAT_MAX] = {
@@ -616,14 +608,6 @@ const char *RenderingDeviceVulkan::named_formats[RenderingDevice::DATA_FORMAT_MA
"G16_B16_R16_3Plane_422_Unorm",
"G16_B16R16_2Plane_422_Unorm",
"G16_B16_R16_3Plane_444_Unorm",
- "Pvrtc1_2Bpp_Unorm_Block_Img",
- "Pvrtc1_4Bpp_Unorm_Block_Img",
- "Pvrtc2_2Bpp_Unorm_Block_Img",
- "Pvrtc2_4Bpp_Unorm_Block_Img",
- "Pvrtc1_2Bpp_Srgb_Block_Img",
- "Pvrtc1_4Bpp_Srgb_Block_Img",
- "Pvrtc2_2Bpp_Srgb_Block_Img",
- "Pvrtc2_4Bpp_Srgb_Block_Img"
};
int RenderingDeviceVulkan::get_format_vertex_size(DataFormat p_format) {
@@ -970,15 +954,6 @@ uint32_t RenderingDeviceVulkan::get_image_format_pixel_size(DataFormat p_format)
case DATA_FORMAT_G16_B16R16_2PLANE_422_UNORM:
case DATA_FORMAT_G16_B16_R16_3PLANE_444_UNORM:
return 8;
- case DATA_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG:
- case DATA_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG:
- case DATA_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG:
- case DATA_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG:
- case DATA_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG:
- case DATA_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG:
- case DATA_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG:
- case DATA_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG:
- return 1;
default: {
ERR_PRINT("Format not handled, bug");
}
@@ -1048,20 +1023,6 @@ void RenderingDeviceVulkan::get_compressed_image_format_block_dimensions(DataFor
r_w = 4;
r_h = 4;
return;
- case DATA_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG:
- case DATA_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG:
- case DATA_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG:
- case DATA_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG:
- r_w = 4;
- r_h = 4;
- return;
- case DATA_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG:
- case DATA_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG:
- case DATA_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG:
- case DATA_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG:
- r_w = 8;
- r_h = 4;
- return;
default: {
r_w = 1;
r_h = 1;
@@ -1138,15 +1099,6 @@ uint32_t RenderingDeviceVulkan::get_compressed_image_format_block_byte_size(Data
case DATA_FORMAT_ASTC_12x12_UNORM_BLOCK:
case DATA_FORMAT_ASTC_12x12_SRGB_BLOCK:
return 8; //wrong
- case DATA_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG:
- case DATA_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG:
- case DATA_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG:
- case DATA_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG:
- case DATA_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG:
- case DATA_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG:
- case DATA_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG:
- case DATA_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG:
- return 8; //what varies is resolution
default: {
}
}
@@ -1167,16 +1119,7 @@ uint32_t RenderingDeviceVulkan::get_compressed_image_format_pixel_rshift(DataFor
case DATA_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
case DATA_FORMAT_EAC_R11_UNORM_BLOCK:
case DATA_FORMAT_EAC_R11_SNORM_BLOCK:
- case DATA_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG:
- case DATA_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG:
- case DATA_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG:
- case DATA_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG:
return 1;
- case DATA_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG: //these formats are quarter byte size, so rshift is 1
- case DATA_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG:
- case DATA_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG:
- case DATA_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG:
- return 2;
default: {
}
}
@@ -7575,6 +7518,9 @@ Error RenderingDeviceVulkan::draw_list_switch_to_next_pass_split(uint32_t p_spli
}
Error RenderingDeviceVulkan::_draw_list_allocate(const Rect2i &p_viewport, uint32_t p_splits, uint32_t p_subpass) {
+ // Lock while draw_list is active
+ _THREAD_SAFE_LOCK_
+
if (p_splits == 0) {
draw_list = memnew(DrawList);
draw_list->command_buffer = frames[frame].draw_command_buffer;
@@ -7685,6 +7631,9 @@ void RenderingDeviceVulkan::_draw_list_free(Rect2i *r_last_viewport) {
memdelete(draw_list);
draw_list = nullptr;
}
+
+ // draw_list is no longer active
+ _THREAD_SAFE_UNLOCK_
}
void RenderingDeviceVulkan::draw_list_end(uint32_t p_post_barrier) {
@@ -7798,6 +7747,9 @@ RenderingDevice::ComputeListID RenderingDeviceVulkan::compute_list_begin(bool p_
ERR_FAIL_COND_V_MSG(!p_allow_draw_overlap && draw_list != nullptr, INVALID_ID, "Only one draw list can be active at the same time.");
ERR_FAIL_COND_V_MSG(compute_list != nullptr, INVALID_ID, "Only one draw/compute list can be active at the same time.");
+ // Lock while compute_list is active
+ _THREAD_SAFE_LOCK_
+
compute_list = memnew(ComputeList);
compute_list->command_buffer = frames[frame].draw_command_buffer;
compute_list->state.allow_draw_overlap = p_allow_draw_overlap;
@@ -8271,6 +8223,9 @@ void RenderingDeviceVulkan::compute_list_end(uint32_t p_post_barrier) {
memdelete(compute_list);
compute_list = nullptr;
+
+ // compute_list is no longer active
+ _THREAD_SAFE_UNLOCK_
}
void RenderingDeviceVulkan::barrier(uint32_t p_from, uint32_t p_to) {
@@ -8429,11 +8384,11 @@ void RenderingDeviceVulkan::_free_internal(RID p_id) {
} else if (uniform_set_owner.owns(p_id)) {
UniformSet *uniform_set = uniform_set_owner.get_or_null(p_id);
frames[frame].uniform_sets_to_dispose_of.push_back(*uniform_set);
+ uniform_set_owner.free(p_id);
+
if (uniform_set->invalidated_callback != nullptr) {
- uniform_set->invalidated_callback(p_id, uniform_set->invalidated_callback_userdata);
+ uniform_set->invalidated_callback(uniform_set->invalidated_callback_userdata);
}
-
- uniform_set_owner.free(p_id);
} else if (render_pipeline_owner.owns(p_id)) {
RenderPipeline *pipeline = render_pipeline_owner.get_or_null(p_id);
frames[frame].render_pipelines_to_dispose_of.push_back(*pipeline);
@@ -8986,7 +8941,7 @@ void RenderingDeviceVulkan::_free_rids(T &p_owner, const char *p_type) {
}
void RenderingDeviceVulkan::capture_timestamp(const String &p_name) {
- ERR_FAIL_COND_MSG(draw_list != nullptr, "Capturing timestamps during draw list creation is not allowed. Offending timestap was: " + p_name);
+ ERR_FAIL_COND_MSG(draw_list != nullptr, "Capturing timestamps during draw list creation is not allowed. Offending timestamp was: " + p_name);
ERR_FAIL_COND(frames[frame].timestamp_count >= max_timestamp_query_elements);
//this should be optional for profiling, else it will slow things down
diff --git a/drivers/vulkan/rendering_device_vulkan.h b/drivers/vulkan/rendering_device_vulkan.h
index 408fddf4bf..f42929ffa4 100644
--- a/drivers/vulkan/rendering_device_vulkan.h
+++ b/drivers/vulkan/rendering_device_vulkan.h
@@ -175,7 +175,7 @@ class RenderingDeviceVulkan : public RenderingDevice {
// These are temporary buffers on CPU memory that hold
// the information until the CPU fetches it and places it
// either on GPU buffers, or images (textures). It ensures
- // updates are properly synchronized with whathever the
+ // updates are properly synchronized with whatever the
// GPU is doing.
//
// The logic here is as follows, only 3 of these
diff --git a/drivers/vulkan/vulkan_context.cpp b/drivers/vulkan/vulkan_context.cpp
index 75a3ab26ea..44455b927b 100644
--- a/drivers/vulkan/vulkan_context.cpp
+++ b/drivers/vulkan/vulkan_context.cpp
@@ -538,7 +538,7 @@ Error VulkanContext::_check_capabilities() {
VkPhysicalDeviceShaderFloat16Int8FeaturesKHR shader_features;
shader_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES_KHR;
- shader_features.pNext = NULL;
+ shader_features.pNext = nullptr;
device_features.pNext = &shader_features;
@@ -547,7 +547,7 @@ Error VulkanContext::_check_capabilities() {
VkPhysicalDevice16BitStorageFeaturesKHR storage_feature;
storage_feature.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR;
- storage_feature.pNext = NULL;
+ storage_feature.pNext = nullptr;
device_features.pNext = &storage_feature;
@@ -615,7 +615,7 @@ Error VulkanContext::_check_capabilities() {
return OK;
}
-Error VulkanContext::_create_physical_device() {
+Error VulkanContext::_create_instance() {
/* obtain version */
_obtain_vulkan_version();
@@ -678,8 +678,6 @@ Error VulkanContext::_create_physical_device() {
inst_info.pNext = &dbg_report_callback_create_info;
}
- uint32_t gpu_count;
-
VkResult err = vkCreateInstance(&inst_info, nullptr, &inst);
ERR_FAIL_COND_V_MSG(err == VK_ERROR_INCOMPATIBLE_DRIVER, ERR_CANT_CREATE,
"Cannot find a compatible Vulkan installable client driver (ICD).\n\n"
@@ -700,10 +698,85 @@ Error VulkanContext::_create_physical_device() {
volkLoadInstance(inst);
#endif
+ if (enabled_debug_utils) {
+ // Setup VK_EXT_debug_utils function pointers always (we use them for
+ // debug labels and names).
+ CreateDebugUtilsMessengerEXT =
+ (PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(inst, "vkCreateDebugUtilsMessengerEXT");
+ DestroyDebugUtilsMessengerEXT =
+ (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(inst, "vkDestroyDebugUtilsMessengerEXT");
+ SubmitDebugUtilsMessageEXT =
+ (PFN_vkSubmitDebugUtilsMessageEXT)vkGetInstanceProcAddr(inst, "vkSubmitDebugUtilsMessageEXT");
+ CmdBeginDebugUtilsLabelEXT =
+ (PFN_vkCmdBeginDebugUtilsLabelEXT)vkGetInstanceProcAddr(inst, "vkCmdBeginDebugUtilsLabelEXT");
+ CmdEndDebugUtilsLabelEXT =
+ (PFN_vkCmdEndDebugUtilsLabelEXT)vkGetInstanceProcAddr(inst, "vkCmdEndDebugUtilsLabelEXT");
+ CmdInsertDebugUtilsLabelEXT =
+ (PFN_vkCmdInsertDebugUtilsLabelEXT)vkGetInstanceProcAddr(inst, "vkCmdInsertDebugUtilsLabelEXT");
+ SetDebugUtilsObjectNameEXT =
+ (PFN_vkSetDebugUtilsObjectNameEXT)vkGetInstanceProcAddr(inst, "vkSetDebugUtilsObjectNameEXT");
+ if (nullptr == CreateDebugUtilsMessengerEXT || nullptr == DestroyDebugUtilsMessengerEXT ||
+ nullptr == SubmitDebugUtilsMessageEXT || nullptr == CmdBeginDebugUtilsLabelEXT ||
+ nullptr == CmdEndDebugUtilsLabelEXT || nullptr == CmdInsertDebugUtilsLabelEXT ||
+ nullptr == SetDebugUtilsObjectNameEXT) {
+ ERR_FAIL_V_MSG(ERR_CANT_CREATE,
+ "GetProcAddr: Failed to init VK_EXT_debug_utils\n"
+ "GetProcAddr: Failure");
+ }
+
+ err = CreateDebugUtilsMessengerEXT(inst, &dbg_messenger_create_info, nullptr, &dbg_messenger);
+ switch (err) {
+ case VK_SUCCESS:
+ break;
+ case VK_ERROR_OUT_OF_HOST_MEMORY:
+ ERR_FAIL_V_MSG(ERR_CANT_CREATE,
+ "CreateDebugUtilsMessengerEXT: out of host memory\n"
+ "CreateDebugUtilsMessengerEXT Failure");
+ break;
+ default:
+ ERR_FAIL_V_MSG(ERR_CANT_CREATE,
+ "CreateDebugUtilsMessengerEXT: unknown failure\n"
+ "CreateDebugUtilsMessengerEXT Failure");
+ ERR_FAIL_V(ERR_CANT_CREATE);
+ break;
+ }
+ } else if (enabled_debug_report) {
+ CreateDebugReportCallbackEXT = (PFN_vkCreateDebugReportCallbackEXT)vkGetInstanceProcAddr(inst, "vkCreateDebugReportCallbackEXT");
+ DebugReportMessageEXT = (PFN_vkDebugReportMessageEXT)vkGetInstanceProcAddr(inst, "vkDebugReportMessageEXT");
+ DestroyDebugReportCallbackEXT = (PFN_vkDestroyDebugReportCallbackEXT)vkGetInstanceProcAddr(inst, "vkDestroyDebugReportCallbackEXT");
+
+ if (nullptr == CreateDebugReportCallbackEXT || nullptr == DebugReportMessageEXT || nullptr == DestroyDebugReportCallbackEXT) {
+ ERR_FAIL_V_MSG(ERR_CANT_CREATE,
+ "GetProcAddr: Failed to init VK_EXT_debug_report\n"
+ "GetProcAddr: Failure");
+ }
+
+ err = CreateDebugReportCallbackEXT(inst, &dbg_report_callback_create_info, nullptr, &dbg_debug_report);
+ switch (err) {
+ case VK_SUCCESS:
+ break;
+ case VK_ERROR_OUT_OF_HOST_MEMORY:
+ ERR_FAIL_V_MSG(ERR_CANT_CREATE,
+ "CreateDebugReportCallbackEXT: out of host memory\n"
+ "CreateDebugReportCallbackEXT Failure");
+ break;
+ default:
+ ERR_FAIL_V_MSG(ERR_CANT_CREATE,
+ "CreateDebugReportCallbackEXT: unknown failure\n"
+ "CreateDebugReportCallbackEXT Failure");
+ ERR_FAIL_V(ERR_CANT_CREATE);
+ break;
+ }
+ }
+
+ return OK;
+}
+
+Error VulkanContext::_create_physical_device(VkSurfaceKHR p_surface) {
/* Make initial call to query gpu_count, then second call for gpu info*/
- err = vkEnumeratePhysicalDevices(inst, &gpu_count, nullptr);
+ uint32_t gpu_count = 0;
+ VkResult err = vkEnumeratePhysicalDevices(inst, &gpu_count, nullptr);
ERR_FAIL_COND_V(err, ERR_CANT_CREATE);
-
ERR_FAIL_COND_V_MSG(gpu_count == 0, ERR_CANT_CREATE,
"vkEnumeratePhysicalDevices reported zero accessible devices.\n\n"
"Do you have a compatible Vulkan installable client driver (ICD) installed?\n"
@@ -716,24 +789,120 @@ Error VulkanContext::_create_physical_device() {
ERR_FAIL_V(ERR_CANT_CREATE);
}
+ static const struct {
+ uint32_t id;
+ const char *name;
+ } vendor_names[] = {
+ { 0x1002, "AMD" },
+ { 0x1010, "ImgTec" },
+ { 0x106B, "Apple" },
+ { 0x10DE, "NVIDIA" },
+ { 0x13B5, "ARM" },
+ { 0x5143, "Qualcomm" },
+ { 0x8086, "Intel" },
+ { 0, nullptr },
+ };
+
// TODO: At least on Linux Laptops integrated GPUs fail with Vulkan in many instances.
// The device should really be a preference, but for now choosing a discrete GPU over the
// integrated one is better than the default.
- // Default to first device
- uint32_t device_index = 0;
-
+ int32_t device_index = -1;
+ int type_selected = -1;
+ print_verbose("Vulkan devices:");
for (uint32_t i = 0; i < gpu_count; ++i) {
VkPhysicalDeviceProperties props;
vkGetPhysicalDeviceProperties(physical_devices[i], &props);
- if (props.deviceType == VkPhysicalDeviceType::VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) {
- // Prefer discrete GPU.
- device_index = i;
- break;
+ bool present_supported = false;
+
+ uint32_t device_queue_family_count = 0;
+ vkGetPhysicalDeviceQueueFamilyProperties(physical_devices[i], &device_queue_family_count, nullptr);
+ VkQueueFamilyProperties *device_queue_props = (VkQueueFamilyProperties *)malloc(device_queue_family_count * sizeof(VkQueueFamilyProperties));
+ vkGetPhysicalDeviceQueueFamilyProperties(physical_devices[i], &device_queue_family_count, device_queue_props);
+ for (uint32_t j = 0; j < device_queue_family_count; j++) {
+ VkBool32 supports;
+ vkGetPhysicalDeviceSurfaceSupportKHR(physical_devices[i], j, p_surface, &supports);
+ if (supports && ((device_queue_props[j].queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0)) {
+ present_supported = true;
+ } else {
+ continue;
+ }
+ }
+ String name = props.deviceName;
+ String vendor = "Unknown";
+ String dev_type;
+ switch (props.deviceType) {
+ case VkPhysicalDeviceType::VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU: {
+ dev_type = "Discrete";
+ } break;
+ case VkPhysicalDeviceType::VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU: {
+ dev_type = "Integrated";
+ } break;
+ case VkPhysicalDeviceType::VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU: {
+ dev_type = "Virtual";
+ } break;
+ case VkPhysicalDeviceType::VK_PHYSICAL_DEVICE_TYPE_CPU: {
+ dev_type = "CPU";
+ } break;
+ default: {
+ dev_type = "Other";
+ } break;
+ }
+ uint32_t vendor_idx = 0;
+ while (vendor_names[vendor_idx].name != nullptr) {
+ if (props.vendorID == vendor_names[vendor_idx].id) {
+ vendor = vendor_names[vendor_idx].name;
+ break;
+ }
+ vendor_idx++;
+ }
+ free(device_queue_props);
+ print_verbose(" #" + itos(i) + ": " + vendor + " " + name + " - " + (present_supported ? "Supported" : "Unsupported") + ", " + dev_type);
+
+ if (present_supported) { // Select first supported device of preffered type: Discrete > Integrated > Virtual > CPU > Other.
+ switch (props.deviceType) {
+ case VkPhysicalDeviceType::VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU: {
+ if (type_selected < 4) {
+ type_selected = 4;
+ device_index = i;
+ }
+ } break;
+ case VkPhysicalDeviceType::VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU: {
+ if (type_selected < 3) {
+ type_selected = 3;
+ device_index = i;
+ }
+ } break;
+ case VkPhysicalDeviceType::VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU: {
+ if (type_selected < 2) {
+ type_selected = 2;
+ device_index = i;
+ }
+ } break;
+ case VkPhysicalDeviceType::VK_PHYSICAL_DEVICE_TYPE_CPU: {
+ if (type_selected < 1) {
+ type_selected = 1;
+ device_index = i;
+ }
+ } break;
+ default: {
+ if (type_selected < 0) {
+ type_selected = 0;
+ device_index = i;
+ }
+ } break;
+ }
}
}
+ int32_t user_device_index = Engine::get_singleton()->get_gpu_index(); // Force user selected GPU.
+ if (user_device_index >= 0 && user_device_index < (int32_t)gpu_count) {
+ device_index = user_device_index;
+ }
+
+ ERR_FAIL_COND_V_MSG(device_index == -1, ERR_CANT_CREATE, "None of Vulkan devices supports both graphics and present queues.");
+
gpu = physical_devices[device_index];
free(physical_devices);
@@ -746,19 +915,6 @@ Error VulkanContext::_create_physical_device() {
/* Get identifier properties */
vkGetPhysicalDeviceProperties(gpu, &gpu_props);
- static const struct {
- uint32_t id;
- const char *name;
- } vendor_names[] = {
- { 0x1002, "AMD" },
- { 0x1010, "ImgTec" },
- { 0x106B, "Apple" },
- { 0x10DE, "NVIDIA" },
- { 0x13B5, "ARM" },
- { 0x5143, "Qualcomm" },
- { 0x8086, "Intel" },
- { 0, nullptr },
- };
device_name = gpu_props.deviceName;
device_type = gpu_props.deviceType;
pipeline_cache_id = String::hex_encode_buffer(gpu_props.pipelineCacheUUID, VK_UUID_SIZE);
@@ -851,77 +1007,6 @@ Error VulkanContext::_create_physical_device() {
" extension.\n\nDo you have a compatible Vulkan installable client driver (ICD) installed?\n"
"vkCreateInstance Failure");
- if (enabled_debug_utils) {
- // Setup VK_EXT_debug_utils function pointers always (we use them for
- // debug labels and names).
- CreateDebugUtilsMessengerEXT =
- (PFN_vkCreateDebugUtilsMessengerEXT)vkGetInstanceProcAddr(inst, "vkCreateDebugUtilsMessengerEXT");
- DestroyDebugUtilsMessengerEXT =
- (PFN_vkDestroyDebugUtilsMessengerEXT)vkGetInstanceProcAddr(inst, "vkDestroyDebugUtilsMessengerEXT");
- SubmitDebugUtilsMessageEXT =
- (PFN_vkSubmitDebugUtilsMessageEXT)vkGetInstanceProcAddr(inst, "vkSubmitDebugUtilsMessageEXT");
- CmdBeginDebugUtilsLabelEXT =
- (PFN_vkCmdBeginDebugUtilsLabelEXT)vkGetInstanceProcAddr(inst, "vkCmdBeginDebugUtilsLabelEXT");
- CmdEndDebugUtilsLabelEXT =
- (PFN_vkCmdEndDebugUtilsLabelEXT)vkGetInstanceProcAddr(inst, "vkCmdEndDebugUtilsLabelEXT");
- CmdInsertDebugUtilsLabelEXT =
- (PFN_vkCmdInsertDebugUtilsLabelEXT)vkGetInstanceProcAddr(inst, "vkCmdInsertDebugUtilsLabelEXT");
- SetDebugUtilsObjectNameEXT =
- (PFN_vkSetDebugUtilsObjectNameEXT)vkGetInstanceProcAddr(inst, "vkSetDebugUtilsObjectNameEXT");
- if (nullptr == CreateDebugUtilsMessengerEXT || nullptr == DestroyDebugUtilsMessengerEXT ||
- nullptr == SubmitDebugUtilsMessageEXT || nullptr == CmdBeginDebugUtilsLabelEXT ||
- nullptr == CmdEndDebugUtilsLabelEXT || nullptr == CmdInsertDebugUtilsLabelEXT ||
- nullptr == SetDebugUtilsObjectNameEXT) {
- ERR_FAIL_V_MSG(ERR_CANT_CREATE,
- "GetProcAddr: Failed to init VK_EXT_debug_utils\n"
- "GetProcAddr: Failure");
- }
-
- err = CreateDebugUtilsMessengerEXT(inst, &dbg_messenger_create_info, nullptr, &dbg_messenger);
- switch (err) {
- case VK_SUCCESS:
- break;
- case VK_ERROR_OUT_OF_HOST_MEMORY:
- ERR_FAIL_V_MSG(ERR_CANT_CREATE,
- "CreateDebugUtilsMessengerEXT: out of host memory\n"
- "CreateDebugUtilsMessengerEXT Failure");
- break;
- default:
- ERR_FAIL_V_MSG(ERR_CANT_CREATE,
- "CreateDebugUtilsMessengerEXT: unknown failure\n"
- "CreateDebugUtilsMessengerEXT Failure");
- ERR_FAIL_V(ERR_CANT_CREATE);
- break;
- }
- } else if (enabled_debug_report) {
- CreateDebugReportCallbackEXT = (PFN_vkCreateDebugReportCallbackEXT)vkGetInstanceProcAddr(inst, "vkCreateDebugReportCallbackEXT");
- DebugReportMessageEXT = (PFN_vkDebugReportMessageEXT)vkGetInstanceProcAddr(inst, "vkDebugReportMessageEXT");
- DestroyDebugReportCallbackEXT = (PFN_vkDestroyDebugReportCallbackEXT)vkGetInstanceProcAddr(inst, "vkDestroyDebugReportCallbackEXT");
-
- if (nullptr == CreateDebugReportCallbackEXT || nullptr == DebugReportMessageEXT || nullptr == DestroyDebugReportCallbackEXT) {
- ERR_FAIL_V_MSG(ERR_CANT_CREATE,
- "GetProcAddr: Failed to init VK_EXT_debug_report\n"
- "GetProcAddr: Failure");
- }
-
- err = CreateDebugReportCallbackEXT(inst, &dbg_report_callback_create_info, nullptr, &dbg_debug_report);
- switch (err) {
- case VK_SUCCESS:
- break;
- case VK_ERROR_OUT_OF_HOST_MEMORY:
- ERR_FAIL_V_MSG(ERR_CANT_CREATE,
- "CreateDebugReportCallbackEXT: out of host memory\n"
- "CreateDebugReportCallbackEXT Failure");
- break;
- default:
- ERR_FAIL_V_MSG(ERR_CANT_CREATE,
- "CreateDebugReportCallbackEXT: unknown failure\n"
- "CreateDebugReportCallbackEXT Failure");
- ERR_FAIL_V(ERR_CANT_CREATE);
- break;
- }
- }
-
/* Call with nullptr data to get count */
vkGetPhysicalDeviceQueueFamilyProperties(gpu, &queue_family_count, nullptr);
ERR_FAIL_COND_V(queue_family_count == 0, ERR_CANT_CREATE);
@@ -957,6 +1042,7 @@ Error VulkanContext::_create_physical_device() {
}
}
+ device_initialized = true;
return OK;
}
@@ -1209,25 +1295,17 @@ bool VulkanContext::_use_validation_layers() {
Error VulkanContext::_window_create(DisplayServer::WindowID p_window_id, DisplayServer::VSyncMode p_vsync_mode, VkSurfaceKHR p_surface, int p_width, int p_height) {
ERR_FAIL_COND_V(windows.has(p_window_id), ERR_INVALID_PARAMETER);
+ if (!device_initialized) {
+ Error err = _create_physical_device(p_surface);
+ ERR_FAIL_COND_V(err != OK, ERR_CANT_CREATE);
+ }
+
if (!queues_initialized) {
// We use a single GPU, but we need a surface to initialize the
// queues, so this process must be deferred until a surface
// is created.
Error err = _initialize_queues(p_surface);
ERR_FAIL_COND_V(err != OK, ERR_CANT_CREATE);
- } else {
- // make sure any of the surfaces supports present (validation layer complains if this is not done).
- bool any_supports_present = false;
- for (uint32_t i = 0; i < queue_family_count; i++) {
- VkBool32 supports;
- fpGetPhysicalDeviceSurfaceSupportKHR(gpu, i, p_surface, &supports);
- if (supports) {
- any_supports_present = true;
- break;
- }
- }
-
- ERR_FAIL_COND_V_MSG(!any_supports_present, ERR_CANT_CREATE, "Surface passed for sub-window creation does not support presenting");
}
Window window;
@@ -1694,12 +1772,12 @@ Error VulkanContext::initialize() {
return FAILED;
}
#endif
- Error err = _create_physical_device();
- if (err) {
+
+ Error err = _create_instance();
+ if (err != OK) {
return err;
}
- device_initialized = true;
return OK;
}
diff --git a/drivers/vulkan/vulkan_context.h b/drivers/vulkan/vulkan_context.h
index 5cac7e7771..67a675f6c6 100644
--- a/drivers/vulkan/vulkan_context.h
+++ b/drivers/vulkan/vulkan_context.h
@@ -224,7 +224,9 @@ private:
const char *pMessage,
void *pUserData);
- Error _create_physical_device();
+ Error _create_instance();
+
+ Error _create_physical_device(VkSurfaceKHR p_surface);
Error _initialize_queues(VkSurfaceKHR p_surface);