From 514adf4723ea377c8c47ef60ba50a6737f70b36d Mon Sep 17 00:00:00 2001 From: Jozsef Hapak Date: Tue, 27 Jan 2026 15:36:23 +0100 Subject: [PATCH 1/3] cube: build pipeline cache with sdk --- cube-vksc/CMakeLists.txt | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/cube-vksc/CMakeLists.txt b/cube-vksc/CMakeLists.txt index 4d1be3a9..645efb18 100644 --- a/cube-vksc/CMakeLists.txt +++ b/cube-vksc/CMakeLists.txt @@ -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) @@ -60,23 +61,33 @@ if (COMPILE_CUBE_SHADERS) DEPENDS cube.frag ${GLSLANG_VALIDATOR}) endif() -if(VKSC_PIPELINE_CACHE_COMPILER) +if(REBUILD_PIPELINE_CACHE) + find_package(VulkanSC CONFIG REQUIRED) + include(VulkanSCPccUtilities) + separate_arguments(VKSC_PIPELINE_CACHE_FLAGS NATIVE_COMMAND "${VKSC_PIPELINE_CACHE_FLAGS}") + + add_vksc_pipeline_cache(pipeline_cache + PATH . + FLAGS $<$:${VulkanSC_DEBUG_FLAG}> ${VKSC_PIPELINE_CACHE_FLAGS} + ) + + get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if(GENERATOR_IS_MULTI_CONFIG) + set(PIPELINE_CACHE_BIN "${CMAKE_CURRENT_BINARY_DIR}/$/pipeline_cache.bin") + else() + set(PIPELINE_CACHE_BIN "${CMAKE_CURRENT_BINARY_DIR}/pipeline_cache.bin") + endif() + 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 + COMMAND ${CMAKE_COMMAND} -D INPUT:FILEPATH=${PIPELINE_CACHE_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} MAIN_DEPENDENCY cube.pc.json DEPENDS + pipeline_cache cube.pc.json ${CMAKE_CURRENT_SOURCE_DIR}/cube.vert.spv ${CMAKE_CURRENT_SOURCE_DIR}/cube.frag.spv From 07ee96e8b775f8999187ef7f46022437f9219eb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Ferenc=20Nagy-Egri?= Date: Mon, 2 Feb 2026 09:39:42 +0100 Subject: [PATCH 2/3] cube: finish SDK build definition --- cube-vksc/CMakeLists.txt | 107 +++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 49 deletions(-) diff --git a/cube-vksc/CMakeLists.txt b/cube-vksc/CMakeLists.txt index 645efb18..abc04202 100644 --- a/cube-vksc/CMakeLists.txt +++ b/cube-vksc/CMakeLists.txt @@ -47,52 +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(REBUILD_PIPELINE_CACHE) find_package(VulkanSC CONFIG REQUIRED) include(VulkanSCPccUtilities) - separate_arguments(VKSC_PIPELINE_CACHE_FLAGS NATIVE_COMMAND "${VKSC_PIPELINE_CACHE_FLAGS}") + set(PIPELINE_CACHE_BIN "${CMAKE_CURRENT_BINARY_DIR}/pipeline_cache.$.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 . - FLAGS $<$:${VulkanSC_DEBUG_FLAG}> ${VKSC_PIPELINE_CACHE_FLAGS} + PATH "${CMAKE_CURRENT_SOURCE_DIR}" + OUT "${PIPELINE_CACHE_BIN}" + $<$:DEBUG> + FLAGS "${VKSC_PIPELINE_CACHE_FLAGS}" + ${DEPENDS_ARG} ) - get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) - if(GENERATOR_IS_MULTI_CONFIG) - set(PIPELINE_CACHE_BIN "${CMAKE_CURRENT_BINARY_DIR}/$/pipeline_cache.bin") - else() - set(PIPELINE_CACHE_BIN "${CMAKE_CURRENT_BINARY_DIR}/pipeline_cache.bin") + 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 "Compiling pipeline cache binary header" - OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/pipeline_cache.h - COMMAND ${CMAKE_COMMAND} -D INPUT:FILEPATH=${PIPELINE_CACHE_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} + 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 - pipeline_cache - 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) @@ -118,7 +126,6 @@ target_sources(vkcube PRIVATE cube.c cube.vert cube.frag - cube.pc.json pipeline_cache.h ) @@ -133,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) \ No newline at end of file From 7ff72a2e7ba9415379c03cafe223b390f3d05ab7 Mon Sep 17 00:00:00 2001 From: Jozsef Hapak Date: Tue, 3 Feb 2026 11:42:24 +0100 Subject: [PATCH 3/3] cube: update readme --- cube-vksc/README.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/cube-vksc/README.md b/cube-vksc/README.md index d6473a5e..cf6f1dc2 100644 --- a/cube-vksc/README.md +++ b/cube-vksc/README.md @@ -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.: ``` @@ -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= -D VKSC_PIPELINE_CACHE_FLAGS= -``` - -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= -D VKSC_PIPELINE_CACHE_FLAGS="-chip " +cmake ... -D REBUILD_PIPELINE_CACHE=ON -D VKSC_PIPELINE_CACHE_FLAGS= ``` +