Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vulkan] Fix vulkan initialization on macOS with cpu backend #4813

Merged
merged 3 commits into from
Apr 19, 2022

Conversation

bobcao3
Copy link
Collaborator

@bobcao3 bobcao3 commented Apr 18, 2022

Previously macOS GGUI is broken for CPU backend always segfaults and outputs some nonsense.

The cause of the issue is:

  1. When using CPU backend, the Vulkan program is not initialized, and the device is created through device creator.
  2. GLFW uses a few Vulkan calls to create a window surface, but because we are dynamically loading Vulkan on mac (and we are not linking to a loader), we need to set GLFW's vulkan loader function before calling glfwInit
  3. We only load the Vulkan when either 1. checking whether Vulkan is supported, however this is skipped when requesting CPU backend 2. or when creating the device
  4. In CPU mode GGUI, the glfw is initialized before creating vulkan device, causing glfw to fail to use our Vulkan loader.

The temporary fix is to check for vulkan support (and initialize glfw's vulkan loader ptr) before creating a GGUI window. The longer term fix would be to move window creation and handling into device API. (currently glfw is outside of device API and therefore we have a bit of a initialization problem)

Fixes taichi-dev/voxel-challenge#3
Fixes #4619

@bobcao3 bobcao3 requested review from k-ye and AmesingFlank April 18, 2022 18:41
@netlify
Copy link

netlify bot commented Apr 18, 2022

👷 Deploy Preview for docsite-preview processing.

Name Link
🔨 Latest commit cdf6931
🔍 Latest deploy log https://app.netlify.com/sites/docsite-preview/deploys/625f073aa9cd9c0009b2dc91

@bobcao3 bobcao3 requested a review from yuanming-hu April 18, 2022 18:46
Copy link
Member

@k-ye k-ye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! one nit

taichi/python/export_ggui.cpp Show resolved Hide resolved
@bobcao3 bobcao3 merged commit b0a66c7 into taichi-dev:master Apr 19, 2022
@k-ye k-ye added this to the Taichi v1.0.1 milestone Apr 20, 2022
k-ye pushed a commit to k-ye/taichi that referenced this pull request May 5, 2022
…dev#4813)

* Fix vulkan initialization on macOS with cpu backend

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Delete waterwave_caustics_ggui.py

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@bobcao3 bobcao3 deleted the bobcao3/vulkan-macos branch June 15, 2022 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants