Skip to content

Commit

Permalink
[vulkan] Fix GGUI and vulkan swapchain on AMD drivers (taichi-dev#7382)
Browse files Browse the repository at this point in the history
Issue: taichi-dev#7291

This might also fix Intel. Can anyone with intel iGPU check for me?

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and quadpixels committed May 13, 2023
1 parent e2b3f51 commit 342a41b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
17 changes: 12 additions & 5 deletions taichi/rhi/vulkan/vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2633,6 +2633,12 @@ void VulkanSurface::create_swap_chain() {
VkSurfaceCapabilitiesKHR capabilities;
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device_->vk_physical_device(),
surface_, &capabilities);
if (capabilities.maxImageCount == 0) {
// https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkSurfaceCapabilitiesKHR.html
// When maxImageCount is 0, there is no limit on the number of images.
capabilities.maxImageCount =
std::max<uint32_t>(capabilities.minImageCount, 3);
}

VkBool32 supported = false;
vkGetPhysicalDeviceSurfaceSupportKHR(device_->vk_physical_device(),
Expand Down Expand Up @@ -2677,8 +2683,8 @@ void VulkanSurface::create_swap_chain() {
{
std::array<char, 512> msg_buf;
RHI_DEBUG_SNPRINTF(msg_buf.data(), msg_buf.size(),
"Creating suface of %u x %u", extent.width,
extent.height);
"Creating suface of %u x %u, present mode %d",
extent.width, extent.height, present_mode);
RHI_LOG_DEBUG(msg_buf.data());
}
VkImageUsageFlags usage =
Expand Down Expand Up @@ -2789,9 +2795,10 @@ StreamSemaphore VulkanSurface::acquire_next_image() {
image_index_ = (image_index_ + 1) % uint32_t(swapchain_images_.size());
return nullptr;
} else {
vkAcquireNextImageKHR(device_->vk_device(), swapchain_, UINT64_MAX,
image_available_->semaphore, VK_NULL_HANDLE,
&image_index_);
VkResult res = vkAcquireNextImageKHR(
device_->vk_device(), swapchain_, uint64_t(4 * 1e9),
image_available_->semaphore, VK_NULL_HANDLE, &image_index_);
BAIL_ON_VK_BAD_RESULT_NO_RETURN(res, "vkAcquireNextImageKHR failed");
return std::make_shared<VulkanStreamSemaphoreObject>(image_available_);
}
}
Expand Down
5 changes: 5 additions & 0 deletions taichi/rhi/vulkan/vulkan_device_creator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ VulkanQueueFamilyIndices find_queue_families(VkPhysicalDevice device,
VkBool32 present_support = false;
vkGetPhysicalDeviceSurfaceSupportKHR(device, i, surface,
&present_support);
char msg_buf[128];
RHI_DEBUG_SNPRINTF(msg_buf, sizeof(msg_buf),
"Queue %d %s support for presenting", i,
present_support ? "has" : "does NOT have");
RHI_LOG_DEBUG(msg_buf);

if (present_support) {
indices.present_family = i;
Expand Down

0 comments on commit 342a41b

Please sign in to comment.