Skip to content

Commit

Permalink
[build] Fix build of RHI examples (temporarily) (#8213)
Browse files Browse the repository at this point in the history
Issue: #

### Brief Summary

<!--
copilot:summary
-->
### <samp>🤖 Generated by Copilot at 5bc5eb1</samp>

This pull request fixes some bugs and improves the compatibility of the
`rhi_examples` that demonstrate the use of the Vulkan backend for the
Taichi programming language. It fixes the linking error in
`CMakeLists.txt`, the Vulkan loader initialization in `common.h`, and
the swapchain recreation in `vulkan_device.cpp`.

### Walkthrough

<!--
copilot:walkthrough
-->
### <samp>🤖 Generated by Copilot at 5bc5eb1</samp>

* Fix linking error for rhi_examples by using `taichi_core` library
([link](https://github.com/taichi-dev/taichi/pull/8213/files?diff=unified&w=0#diff-ce18c0b2ae4fee335806357f23ceb248ed7b32ab121fdd4f750e5856bfc65328L27-R27))
* Initialize Vulkan loader for GLFW to create Vulkan window and surface
([link](https://github.com/taichi-dev/taichi/pull/8213/files?diff=unified&w=0#diff-675d40050ebb39182902d37dca8b430ff301ef0a6834221993580761300c850eR48))
* Handle `VK_SUBOPTIMAL_KHR` result from `vkAcquireNextImageKHR` to
avoid aborting program and allow swapchain recreation
([link](https://github.com/taichi-dev/taichi/pull/8213/files?diff=unified&w=0#diff-4479f242ce99cd434c015531997155aa7faa38fb3ead6b0997caf097b05cecb8L2807-R2809))

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
bobcao3 and pre-commit-ci[bot] authored Jun 25, 2023
1 parent 4eb2cff commit ffb349c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cpp_examples/rhi_examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ target_include_directories(${executable_name} SYSTEM
PUBLIC
${PROJECT_SOURCE_DIR}/external/VulkanMemoryAllocator/include
)
target_link_libraries(${executable_name} taichi_c_api ti_device_api glfw)
target_link_libraries(${executable_name} taichi_core glfw)
endmacro()

make_sample(sample_1_window sample_1_window.cpp)
Expand Down
1 change: 1 addition & 0 deletions cpp_examples/rhi_examples/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class App {
TI_INFO("Creating App '{}' of {}x{}", title, width, height);

TI_ASSERT(taichi::lang::vulkan::is_vulkan_api_available());
glfwInitVulkanLoader(vkGetInstanceProcAddr);

if (glfwInit()) {
TI_INFO("Initialized GLFW");
Expand Down
4 changes: 3 additions & 1 deletion taichi/rhi/vulkan/vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2804,7 +2804,9 @@ StreamSemaphore VulkanSurface::acquire_next_image() {
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");
if (res != VK_SUCCESS && res != VK_SUBOPTIMAL_KHR) {
BAIL_ON_VK_BAD_RESULT_NO_RETURN(res, "vkAcquireNextImageKHR failed");
}
return std::make_shared<VulkanStreamSemaphoreObject>(image_available_);
}
}
Expand Down

0 comments on commit ffb349c

Please sign in to comment.