Skip to content

Commit 0c44292

Browse files
committed
scripts: Fix PccDiscovery for plain PATH resolution
1 parent 6acb230 commit 0c44292

File tree

1 file changed

+48
-23
lines changed

1 file changed

+48
-23
lines changed

cmake/Modules/VulkanSCPccDiscovery.cmake

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,29 @@ find_program(VulkanSC_PCCTOOL_EXECUTABLE
1212
"$ENV{VULKANSC_SDK}/bin"
1313
)
1414

15+
function(resolve_vksc_pcc_executable PCC_EXECUTABLE PCC_JSON_PATH OUT_VAR)
16+
message(DEBUG "PCC entry: ${PCC_EXECUTABLE}")
17+
if(WIN32)
18+
set(NATIVE_PATH_SEPARATOR_REGEX [[\\]])
19+
else()
20+
set(NATIVE_PATH_SEPARATOR_REGEX [[/]])
21+
endif()
22+
if(NOT PCC_EXECUTABLE MATCHES ${NATIVE_PATH_SEPARATOR_REGEX})
23+
separate_arguments(PCC_EXECUTABLE NATIVE_COMMAND PROGRAM "${PCC_EXECUTABLE}")
24+
list(POP_BACK PCC_EXECUTABLE) # pop the empty element due to separate_arguments not having <args>
25+
else()
26+
cmake_path(IS_RELATIVE PCC_EXECUTABLE PCC_EXECUTABLE_IS_RELATIVE)
27+
if(PCC_EXECUTABLE_IS_RELATIVE)
28+
cmake_path(GET PCC_JSON_PATH PARENT_PATH PCC_JSON_PARENT_PATH)
29+
cmake_path(ABSOLUTE_PATH PCC_EXECUTABLE BASE_DIRECTORY "${PCC_JSON_PARENT_PATH}" NORMALIZE)
30+
else()
31+
cmake_path(NORMAL_PATH PCC_EXECUTABLE)
32+
endif()
33+
endif()
34+
set(${OUT_VAR} "${PCC_EXECUTABLE}" PARENT_SCOPE)
35+
message(DEBUG "PCC resolved: ${PCC_EXECUTABLE}")
36+
endfunction()
37+
1538
# If a PCC executable is set manually then do not perform the PCC discovery
1639
if(NOT "${VulkanSC_PCC_EXECUTABLE}")
1740
if(WIN32)
@@ -22,9 +45,15 @@ if(NOT "${VulkanSC_PCC_EXECUTABLE}")
2245
RESULT PCC_PROP_NAMES
2346
QUERY WINDOWS_REGISTRY "${HIVE}/SOFTWARE/Khronos/VulkanSC/PCC" VALUE_NAMES
2447
)
25-
if(PCC_PROP_NAMES)
26-
list(APPEND PCC_JSON_PATHS "${PCC_PROP_NAMES}")
27-
endif()
48+
foreach(PCC_PROP_NAME IN LISTS PCC_PROP_NAMES)
49+
file(REAL_PATH "${PCC_PROP_NAME}" PCC_PROP_NAME)
50+
if(NOT PCC_PROP_NAME IN_LIST PCC_JSON_PATHS)
51+
message(VERBOSE "PCJSON discovered: ${PCC_PROP_NAME}")
52+
list(APPEND PCC_JSON_PATHS "${PCC_PROP_NAME}")
53+
else()
54+
message(DEBUG "PCJSON skipped: ${PCC_PROP_NAME} (a registry entry resolving to the same file already found)")
55+
endif()
56+
endforeach()
2857
endforeach()
2958
else()
3059
message(FATAL_ERROR "PCC (pipeline cache compiler) discovery on Windows requires CMake 3.24 or newer")
@@ -42,13 +71,19 @@ if(NOT "${VulkanSC_PCC_EXECUTABLE}")
4271
/etc/xdg/vulkansc/pcc.d
4372
)
4473
file(GLOB PCC_GLOBBED_PATHS "${MANIFEST_DIR}/*.json")
45-
if(PCC_GLOBBED_PATHS)
46-
list(APPEND PCC_JSON_PATHS "${PCC_GLOBBED_PATHS}")
47-
endif()
74+
foreach(PCC_GLOBBED_PATH IN LISTS PCC_GLOBBED_PATHS)
75+
file(REAL_PATH "${PCC_GLOBBED_PATH}" PCC_GLOBBED_PATH)
76+
if(NOT PCC_GLOBBED_PATH IN_LIST PCC_JSON_PATHS)
77+
message(VERBOSE "PCJSON discovered: ${PCC_GLOBBED_PATH}")
78+
list(APPEND PCC_JSON_PATHS "${PCC_GLOBBED_PATH}")
79+
else()
80+
message(DEBUG "PCJSON skipped: ${PCC_PROP_NAME} (a file resolving to the same file already found)")
81+
endif()
82+
endforeach()
4883
endforeach()
4984
endif()
5085
foreach(PCC_JSON_PATH IN LISTS PCC_JSON_PATHS)
51-
message(DEBUG "Reading PCJSON: ${PCC_JSON_PATH}")
86+
message(DEBUG "PCJSON processing: ${PCC_JSON_PATH}")
5287
file(READ "${PCC_JSON_PATH}" PCC_JSON)
5388
string(JSON PCC_NAME GET "${PCC_JSON}" "name")
5489

@@ -59,13 +94,7 @@ if(NOT "${VulkanSC_PCC_EXECUTABLE}")
5994
foreach(ARCH_INDEX RANGE ${ARCH_LENGTH_STOP})
6095
string(JSON ARCH_NAME MEMBER "${PCC_JSON}" "architectures" ${ARCH_INDEX})
6196
string(JSON PCC_EXECUTABLE GET "${PCC_JSON}" "architectures" ${ARCH_NAME} "pipeline_cache_compiler")
62-
cmake_path(IS_RELATIVE PCC_EXECUTABLE PCC_EXECUTABLE_IS_RELATIVE)
63-
if(PCC_EXECUTABLE_IS_RELATIVE)
64-
cmake_path(GET PCC_JSON_PATH PARENT_PATH PCC_JSON_PARENT_PATH)
65-
cmake_path(ABSOLUTE_PATH PCC_EXECUTABLE BASE_DIRECTORY "${PCC_JSON_PARENT_PATH}" NORMALIZE)
66-
else()
67-
cmake_path(NORMAL_PATH PCC_EXECUTABLE)
68-
endif()
97+
resolve_vksc_pcc_executable("${PCC_EXECUTABLE}" "${PCC_JSON_PATH}" PCC_EXECUTABLE)
6998
string(JSON FLAGS GET "${PCC_JSON}" "architectures" ${ARCH_NAME} "pipeline_cache_flags")
7099
string(JSON DEBUG_FLAG GET "${PCC_JSON}" "architectures" ${ARCH_NAME} "pipeline_cache_debug_flag")
71100
string(JSON VENDOR_ID_FILTER ERROR_VARIABLE VENDOR_ID_FILTER_ERROR GET "${PCC_JSON}" "architectures" ${ARCH_NAME} "vendor_id_filter")
@@ -74,6 +103,7 @@ if(NOT "${VulkanSC_PCC_EXECUTABLE}")
74103

75104
# Only add a configuration if one with the same name does not exist yet
76105
if(NOT DEFINED VulkanSC_PCC_EXECUTABLE_${PCC_NAME}_${ARCH_NAME})
106+
message(VERBOSE "PCC discovered: ${PCC_NAME} - ${ARCH_NAME}")
77107
set(VulkanSC_PCC_EXECUTABLE_${PCC_NAME}_${ARCH_NAME} "${PCC_EXECUTABLE}")
78108
set(VulkanSC_FLAGS_${PCC_NAME}_${ARCH_NAME} "${FLAGS}")
79109
set(VulkanSC_DEBUG_FLAG_${PCC_NAME}_${ARCH_NAME} "${DEBUG_FLAG}")
@@ -88,7 +118,7 @@ if(NOT "${VulkanSC_PCC_EXECUTABLE}")
88118
endif()
89119
list(APPEND VulkanSC_PCC_OPTIONS "${PCC_NAME} - ${ARCH_NAME}")
90120
else()
91-
message(DEBUG "Skipping architecture ${PCC_NAME} - ${ARCH_NAME} as an entry with the same name is already registered")
121+
message(DEBUG "PCC skipped: ${PCC_NAME} - ${ARCH_NAME} (an entry with the same name is already registered)")
92122
endif()
93123
endforeach()
94124
endif()
@@ -129,18 +159,13 @@ if(NOT "${VulkanSC_PCC_EXECUTABLE}")
129159
set(DEVICE_ID "${CMAKE_MATCH_1}")
130160
set(DEVICE_NAME "${CMAKE_MATCH_2}")
131161
string(JSON PCC_EXECUTABLE GET "${PCC_JSON}" "devices" ${DEV_INDEX} "pipeline_cache_compiler")
132-
cmake_path(IS_RELATIVE PCC_EXECUTABLE PCC_EXECUTABLE_IS_RELATIVE)
133-
if(PCC_EXECUTABLE_IS_RELATIVE)
134-
cmake_path(GET PCC_JSON_PATH PARENT_PATH PCC_JSON_PARENT_PATH)
135-
cmake_path(ABSOLUTE_PATH PCC_EXECUTABLE BASE_DIRECTORY "${PCC_JSON_PARENT_PATH}" NORMALIZE)
136-
else()
137-
cmake_path(NORMAL_PATH PCC_EXECUTABLE)
138-
endif()
162+
resolve_vksc_pcc_executable("${PCC_EXECUTABLE}" "${PCC_JSON_PATH}" PCC_EXECUTABLE)
139163
string(JSON DEVICE_FLAG GET "${PCC_JSON}" "devices" ${DEV_INDEX} "pipeline_cache_device_flag")
140164
string(JSON DEBUG_FLAG GET "${PCC_JSON}" "devices" ${DEV_INDEX} "pipeline_cache_debug_flag")
141165

142166
# Only add a configuration if one with the same name does not exist yet
143167
if(NOT DEFINED VulkanSC_PCC_EXECUTABLE_${PCC_NAME}_${DEVICE_NAME})
168+
message(VERBOSE "PCC discovered: ${PCC_NAME} - ${DEVICE_NAME}")
144169
set(VulkanSC_PCC_EXECUTABLE_${PCC_NAME}_${DEVICE_NAME} "${PCC_EXECUTABLE}")
145170
set(VulkanSC_DEVICE_FLAGS_${PCC_NAME}_${DEVICE_NAME} "${DEVICE_FLAG} ${DEVICE_ID}")
146171
set(VulkanSC_DEBUG_FLAG_${PCC_NAME}_${DEVICE_NAME} "${DEBUG_FLAG}")
@@ -153,7 +178,7 @@ if(NOT "${VulkanSC_PCC_EXECUTABLE}")
153178
endif()
154179
list(APPEND VulkanSC_PCC_OPTIONS "${PCC_NAME} - ${DEVICE_NAME}")
155180
else()
156-
message(DEBUG "Skipping device ${PCC_NAME} - ${DEVICE_NAME} as an entry with the same name is already registered")
181+
message(DEBUG "PCC skipped: ${PCC_NAME} - ${DEVICE_NAME} (an entry with the same name is already registered)")
157182
endif()
158183
endif()
159184
endforeach()

0 commit comments

Comments
 (0)