Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 71 additions & 51 deletions cube-vksc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
# ~~~

option(BUILD_WSI_DISPLAY_SUPPORT "Build DISPLAY WSI support" ON)
set(VKSC_PIPELINE_CACHE_COMPILER "" CACHE FILEPATH "Path to the Vulkan SC pipeline cache compiler")
option(REBUILD_PIPELINE_CACHE "Rebuild pipeline cache" OFF)
set(VKSC_PIPELINE_CACHE_FLAGS "" CACHE STRING "Additional flags to pass to the pipeline cache compiler")

if(NOT VKSC_PIPELINE_CACHE_COMPILER)
message(STATUS "Using self-hosted Vulkan SC Emulation ICD pipeline cache. Provide a pipeline cache compile via VKSC_PIPELINE_CACHE_COMPILER should a different one be needed.")
if(NOT REBUILD_PIPELINE_CACHE)
message(STATUS "Using self-hosted Vulkan SC Emulation ICD pipeline cache. "
"Use REBUILD_PIPELINE_CACHE to rebuild pipeline cache with the Pipeline Cache Compiler discovered by the VulkanSC SDK.")
endif()

if(BUILD_WSI_DISPLAY_SUPPORT)
Expand All @@ -46,42 +47,60 @@ if (COMPILE_CUBE_SHADERS)
# Try to find glslang in system paths or in an SDK if the VULKAN_SDK env-var is set
find_program(GLSLANG_VALIDATOR names glslang glslangValidator HINTS $ENV{GLSLANG_INSTALL_DIR} $ENV{VULKAN_SDK}/bin $ENV{VULKAN_SDK}/Bin)

add_custom_command(COMMENT "Compiling cube vertex shader"
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/cube.vert.spv
COMMAND ${GLSLANG_VALIDATOR} --target-env vulkan1.2 -o ${CMAKE_CURRENT_SOURCE_DIR}/cube.vert.spv
${CMAKE_CURRENT_SOURCE_DIR}/cube.vert
MAIN_DEPENDENCY cube.vert
DEPENDS cube.vert ${GLSLANG_VALIDATOR})
add_custom_command(COMMENT "Compiling cube fragment shader"
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/cube.frag.spv
COMMAND ${GLSLANG_VALIDATOR} --target-env vulkan1.2 -o ${CMAKE_CURRENT_SOURCE_DIR}/cube.frag.spv
${CMAKE_CURRENT_SOURCE_DIR}/cube.frag
MAIN_DEPENDENCY cube.frag
DEPENDS cube.frag ${GLSLANG_VALIDATOR})
function(add_glsl_shader INPUT OUTPUT)
file(RELATIVE_PATH SPV_PATH "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/${OUTPUT}")
file(TO_NATIVE_PATH "${SPV_PATH}" SPV_PATH)
add_custom_command(COMMENT "Compiling GLSL shader ${SPV_PATH}"
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${OUTPUT}
COMMAND ${GLSLANG_VALIDATOR} --target-env vulkan1.2 -o ${CMAKE_CURRENT_SOURCE_DIR}/${OUTPUT} --quiet
${CMAKE_CURRENT_SOURCE_DIR}/${INPUT}
MAIN_DEPENDENCY ${INPUT}
DEPENDS ${INPUT} ${GLSLANG_VALIDATOR})
endfunction()

add_glsl_shader(cube.vert cube.vert.spv)
add_glsl_shader(cube.frag cube.frag.spv)
endif()

if(VKSC_PIPELINE_CACHE_COMPILER)
separate_arguments(VKSC_PIPELINE_CACHE_FLAGS NATIVE_COMMAND "${VKSC_PIPELINE_CACHE_FLAGS}")
add_custom_command(COMMENT "Compiling pipeline cache binary header"
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/pipeline_cache.h
BYPRODUCTS
cube.pc.json.log
${CMAKE_CURRENT_BINARY_DIR}/pipeline_cache.h.bin
COMMAND ${VKSC_PIPELINE_CACHE_COMPILER} --path ${CMAKE_CURRENT_SOURCE_DIR}
--out ${CMAKE_CURRENT_BINARY_DIR}/pipeline_cache.h.bin
--log ${CMAKE_CURRENT_BINARY_DIR}/cube.pc.json.log
${VKSC_PIPELINE_CACHE_FLAGS}
COMMAND ${CMAKE_COMMAND} -D INPUT:FILEPATH=${CMAKE_CURRENT_BINARY_DIR}/pipeline_cache.h.bin
-D OUTPUT:FILEPATH=${CMAKE_CURRENT_SOURCE_DIR}/pipeline_cache.h
-P ${CMAKE_CURRENT_SOURCE_DIR}/bin_to_c_hex_array.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
if(REBUILD_PIPELINE_CACHE)
find_package(VulkanSC CONFIG REQUIRED)
include(VulkanSCPccUtilities)

set(PIPELINE_CACHE_BIN "${CMAKE_CURRENT_BINARY_DIR}/pipeline_cache.$<CONFIG>.bin")
set(PIPELINE_CACHE_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/pipeline_cache.h")

if(COMPILE_CUBE_SHADERS)
# NOTE: Intra-target custom_command inter-dependencies for invocation ordering via dyndep files isn't resolved.
# If pipeline cache compilation has inputs which are outputs of custom commands and have no target of their
# for pipeline_cache to DEPEND on, these generated inputs need to be explicit.
set(DEPENDS_ARG DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/cube.vert.spv"
"${CMAKE_CURRENT_SOURCE_DIR}/cube.frag.spv"
)
endif()

add_vksc_pipeline_cache(pipeline_cache
PATH "${CMAKE_CURRENT_SOURCE_DIR}"
OUT "${PIPELINE_CACHE_BIN}"
$<$<CONFIG:Debug,RelWithDebInfo>:DEBUG>
FLAGS "${VKSC_PIPELINE_CACHE_FLAGS}"
${DEPENDS_ARG}
)

file(RELATIVE_PATH HDR_PATH "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/pipeline_cache.h")
if(WIN32)
string(REPLACE "/" "\\" HDR_PATH "${HDR_PATH}")
endif()
add_custom_command(COMMENT "Generating PC header ${HDR_PATH}"
OUTPUT "${PIPELINE_CACHE_HEADER}"
COMMAND "${CMAKE_COMMAND}"
-D "INPUT:FILEPATH=${PIPELINE_CACHE_BIN}"
-D "OUTPUT:FILEPATH=${PIPELINE_CACHE_HEADER}"
-P "${CMAKE_CURRENT_SOURCE_DIR}/bin_to_c_hex_array.cmake"
MAIN_DEPENDENCY cube.pc.json
DEPENDS
cube.pc.json
${CMAKE_CURRENT_SOURCE_DIR}/cube.vert.spv
${CMAKE_CURRENT_SOURCE_DIR}/cube.frag.spv
${VKSC_PIPELINE_CACHE_COMPILER}
${CMAKE_CURRENT_SOURCE_DIR}/bin_to_c_hex_array.cmake)
"${PIPELINE_CACHE_BIN}"
"${CMAKE_CURRENT_SOURCE_DIR}/bin_to_c_hex_array.cmake")
endif()

if(WIN32)
Expand All @@ -107,7 +126,6 @@ target_sources(vkcube PRIVATE
cube.c
cube.vert
cube.frag
cube.pc.json
pipeline_cache.h
)

Expand All @@ -122,23 +140,25 @@ elseif(WIN32)
else()
message(FATAL_ERROR "Unsupported Platform!")
endif()
target_compile_definitions(vkcube PRIVATE ${ENABLED_CUBE_PLATFORMS})
target_include_directories(vkcube PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}") # xyz_loader.h, linmath.h, etc.
set_target_properties(vkcube PROPERTIES OUTPUT_NAME vksccube)

# We have to manually search for VulkanSC library, due to currently lacking a `Vulkan::Vulkan` equivalent target in Vulkan SC.
if(WIN32)
set(_VulkanSC_library_name vulkansc-1)
if(NOT REBUILD_PIPELINE_CACHE)
# We have to manually search for VulkanSC library, due to currently lacking a `Vulkan::Vulkan` equivalent target in Vulkan SC.
if(WIN32)
set(_VulkanSC_library_name vulkansc-1)
else()
set(_VulkanSC_library_name vulkansc)
endif()
find_library(VulkanSC_LIBRARY
NAMES ${_VulkanSC_library_name}
)
mark_as_advanced(VulkanSC_LIBRARY)

target_link_libraries(vkcube PRIVATE Vulkan::Headers "${VulkanSC_LIBRARY}")
else()
set(_VulkanSC_library_name vulkansc)
target_link_libraries(vkcube PRIVATE VulkanSC::VulkanSC)
endif()
find_library(VulkanSC_LIBRARY
NAMES ${_VulkanSC_library_name}
)
mark_as_advanced(VulkanSC_LIBRARY)

target_compile_definitions(vkcube PRIVATE ${ENABLED_CUBE_PLATFORMS})
target_include_directories(vkcube PRIVATE
${CMAKE_CURRENT_SOURCE_DIR} # xyz_loader.h, linmath.h, etc.
)
target_link_libraries(vkcube PRIVATE Vulkan::Headers "${VulkanSC_LIBRARY}")
set_target_properties(vkcube PROPERTIES OUTPUT_NAME vksccube)

install(TARGETS vkcube)
17 changes: 8 additions & 9 deletions cube-vksc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ component to execute properly: a pipeline cache compiler (PCC). As a convenience
pipeline cache binary using the Khronos Vulkan SC Emulation ICD PCC (`pcconvk`). This pipeline cache can be used with
the Vulkan SC Emulation ICD on top of any compatible Vulkan implementation.

If you want to run the application using any other Vulkan SC ICD, you'll need to compile the pipline cache JSON
If you want to run the application using any other Vulkan SC ICD, you'll need to compile the pipeline cache JSON
(`cube-vksc/cube.pc.json`) offline and specify the built pipeline cache binary at run-time, e.g.:

```
Expand All @@ -35,15 +35,14 @@ vksccube --pipeline-cache pipeline_cache.bin
```

Alternatively, you can embed a custom pipeline cache binary into `vksccube` built using the pipeline cache compiler
of your choice instead of the Vulkan SC EMulation ICD's PCC by adding the `VKSC_PIPELINE_CACHE_COMPILER` (and if any
additional compiler specific flags are needed, the `VKSC_PIPELINE_CACHE_FLAGS`) configuration-time option(s):
discovered and configured by the Vulkan SC SDK by setting the `REBUILD_PIPELINE_CACHE` configuration-time option.

```
cmake ... -D VKSC_PIPELINE_CACHE_COMPILER:FILEPATH=<path-to-pcc> -D VKSC_PIPELINE_CACHE_FLAGS=<additional-args>
```

For example, NVIDIA's Vulkan SC PCC requires an additional argument to specify the target GPU instruction set:
The Vulkan SC SDK implicitly provides any required arguments for the configured PCC.
For example, in case NVIDIA's Vulkan SC PCC, the target GPU instruction set.
If any additional compiler specific flags are needed, they can be set as a command-line fragment using the
`VKSC_PIPELINE_CACHE_FLAGS`

```
cmake ... -D VKSC_PIPELINE_CACHE_COMPILER:FILEPATH=<path-to-nvidia-pcc> -D VKSC_PIPELINE_CACHE_FLAGS="-chip <target>"
cmake ... -D REBUILD_PIPELINE_CACHE=ON -D VKSC_PIPELINE_CACHE_FLAGS=<additional-args>
```

Loading