Skip to content

Commit ad36a55

Browse files
committed
[Vulkan] Add support for MoltenVK on macOS
This gets Vulkan support working on macOS if the Vulkan SDK and MoltenVK are available. All current Vulkan tests except particle_life pass with Vulkan on macOS with DXC, and sign.32.test fails with Clang.
1 parent f3a594a commit ad36a55

File tree

10 files changed

+44
-5
lines changed

10 files changed

+44
-5
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ macro(add_offloadtest_library name)
4141
set_target_properties(OffloadTest${name} PROPERTIES FOLDER "Offload Test/Libraries")
4242
endmacro()
4343

44-
find_package(Vulkan)
44+
if (APPLE)
45+
set(OPTIONAL_MOLTEN COMPONENTS MoltenVK)
46+
endif()
47+
48+
find_package(Vulkan ${OPTIONAL_MOLTEN})
4549
message(STATUS "Vulkan Include Dirs: ${Vulkan_INCLUDE_DIRS}")
4650
if (Vulkan_INCLUDE_DIRS)
4751
set(OFFLOADTEST_ENABLE_VULKAN On)

docs/MoltenVK.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Enabling Vulkan on macOS with MoltenVK
2+
3+
To enable Vulkan testing on macOS you first need to download and install the
4+
Vulkan SDK from [here](https://vulkan.lunarg.com).
5+
6+
By default the SDK installs into your home directory under
7+
`~/VulkanSDK/${SDK_Version}/macOS`. For CMake to find the SDK you either need to
8+
set the `VULKAN_SDK` environment variable to the macOS subdirectory of the
9+
VulkanSDK installation you wish to use. You also need to run `sudo
10+
~/VulkanSDK/${SDK_Version}/install_vulkan.py --force-install`, to install the
11+
development binaries into `/usr/local/...` so that launched applications can
12+
find them.
13+
14+
Once the SDK is installed and exposed to CMake, a clean configuration will
15+
detect Vulkan and the MoltenVK portability layer and enable the Vulkan test
16+
configurations.

lib/API/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ if (APPLE)
2424
"-framework MetalKit"
2525
"-framework AppKit"
2626
"-framework Foundation"
27-
"-framework QuartzCore")
27+
"-framework QuartzCore"
28+
${api_frameworks})
2829
list(APPEND api_headers PRIVATE ${METAL_INCLUDE_DIRS})
2930
endif()
3031

lib/API/VK/Device.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ class VKContext {
957957
VkResult Res = vkCreateInstance(&CreateInfo, NULL, &Instance);
958958
if (Res == VK_ERROR_INCOMPATIBLE_DRIVER)
959959
return llvm::createStringError(std::errc::no_such_device,
960-
"Cannot find a compatible Vulkan device");
960+
"Cannot find a base Vulkan device");
961961
if (Res)
962962
return llvm::createStringError(std::errc::no_such_device,
963963
"Unknown Vulkan initialization error: %d",

test/Feature/HLSLLib/sign.32.test

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ Buffers:
7474
- Name: Out2
7575
Format: Int32
7676
Stride: 16
77-
ZeroInitSize: 48
77+
ZeroInitSize: 48
7878
- Name: ExpectedOut2 # The result we expect
7979
Format: Int32
8080
Stride: 16
8181
Data: [1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0] # Last two are filler
8282
- Name: Out3
8383
Format: Int32
8484
Stride: 16
85-
ZeroInitSize: 48
85+
ZeroInitSize: 48
8686
- Name: ExpectedOut3 # The result we expect
8787
Format: Int32
8888
Stride: 16
@@ -176,6 +176,9 @@ DescriptorSets:
176176
# https://github.com/microsoft/DirectXShaderCompiler/issues/7512
177177
# XFAIL: DXC-Vulkan
178178

179+
# No idea what is going on here, but Out1 and Out3 are coming through as 0's.
180+
# XFAIL: Clang && Vulkan-Darwin
181+
179182
# RUN: split-file %s %t
180183
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
181184
# RUN: %offloader %t/pipeline.yaml %t.o

test/UseCase/particle-life.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@ DescriptorSets:
357357
# https://github.com/llvm/offload-test-suite/issues/55
358358
# UNSUPPORTED: Metal
359359

360+
# No idea what is going on here, but the results are _way_ off.
361+
# XFAIL: Vulkan-Darwin
362+
360363
# RUN: split-file %s %t
361364
# RUN: %if !Vulkan %{ %dxc_target -T cs_6_0 -Fo %t.o %t/particle-life.hlsl %}
362365
# RUN: %if Vulkan %{ %dxc_target -T cs_6_0 -fspv-target-env=vulkan1.3 -fvk-use-scalar-layout -Fo %t.o %t/particle-life.hlsl %}

test/lit.cfg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
def setDeviceFeatures(config, device, compiler):
5252
API = device["API"]
5353
config.available_features.add(API)
54+
config.available_features.add("%s-%s" % (API, config.offloadtest_os))
5455
if "Microsoft Basic Render Driver" in device["Description"]:
5556
config.available_features.add("%s-WARP" % API)
5657
if "Intel" in device["Description"]:

test/lit.site.cfg.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ config.offloadtest_suite = "@suite@"
1616
config.offloadtest_enable_d3d12 = @TEST_d3d12@
1717
config.offloadtest_enable_vulkan = @TEST_vk@
1818
config.offloadtest_enable_metal = @TEST_mtl@
19+
config.offloadtest_os = "@CMAKE_SYSTEM_NAME@"
1920

2021
import lit.llvm
2122
lit.llvm.initialize(lit_config, config)

tools/api-query/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ add_offloadtest_tool(api-query
22
api-query.cpp)
33

44
target_link_libraries(api-query PRIVATE LLVMSupport OffloadTestAPI)
5+
6+
if (APPLE AND OFFLOADTEST_ENABLE_VULKAN)
7+
set_property(TARGET api-query APPEND_STRING PROPERTY
8+
LINK_FLAGS " -Wl,-rpath,/usr/local/lib ")
9+
endif()

tools/offloader/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ target_link_libraries(offloader PRIVATE
66
OffloadTestAPI
77
OffloadTestImage
88
OffloadTestSupport)
9+
10+
if (APPLE AND OFFLOADTEST_ENABLE_VULKAN)
11+
set_property(TARGET offloader APPEND_STRING PROPERTY
12+
LINK_FLAGS " -Wl,-rpath,/usr/local/lib ")
13+
endif()

0 commit comments

Comments
 (0)