1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
|
# ~~~
# Copyright (c) 2014-2023 Valve Corporation
# Copyright (c) 2014-2023 LunarG, Inc.
# Copyright (c) 2023-2023 RasterGrid Kft.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ~~~
# These variables enable downstream users to customize the CMake targets
# based on the target API variant (e.g. Vulkan SC)
set(API_TYPE "vulkan")
set(LAYER_NAME "VkLayer_khronos_validation")
add_library(VkLayer_utils STATIC)
target_sources(VkLayer_utils PRIVATE
containers/custom_containers.h
error_message/logging.h
error_message/logging.cpp
external/xxhash.h
external/xxhash.cpp
${API_TYPE}/generated/lvt_function_pointers.cpp
${API_TYPE}/generated/lvt_function_pointers.h
${API_TYPE}/generated/vk_format_utils.h
${API_TYPE}/generated/vk_format_utils.cpp
${API_TYPE}/generated/vk_validation_error_messages.h
${API_TYPE}/generated/vk_layer_dispatch_table.h
${API_TYPE}/generated/vk_dispatch_table_helper.h
${API_TYPE}/generated/vk_safe_struct.h
${API_TYPE}/generated/vk_safe_struct_utils.cpp
${API_TYPE}/generated/vk_safe_struct_core.cpp
${API_TYPE}/generated/vk_safe_struct_khr.cpp
${API_TYPE}/generated/vk_safe_struct_ext.cpp
${API_TYPE}/generated/vk_safe_struct_vendor.cpp
${API_TYPE}/generated/vk_enum_string_helper.h
${API_TYPE}/generated/vk_object_types.h
${API_TYPE}/generated/vk_extension_helper.h
${API_TYPE}/generated/vk_typemap_helper.h
utils/cast_utils.h
utils/convert_to_renderpass2.cpp
utils/convert_to_renderpass2.h
utils/hash_util.h
utils/hash_vk_types.h
utils/vk_layer_extension_utils.cpp
utils/vk_layer_extension_utils.h
utils/vk_layer_utils.cpp
utils/vk_layer_utils.h
vk_layer_config.h
vk_layer_config.cpp
)
# XXH_NO_LONG_LONG: removes compilation of algorithms relying on 64-bit types (XXH3 and XXH64). Only XXH32 will be compiled.
# We only need XXH32 due to restrictions requiring a 32 bit hash. This also reduces binary size.
#
# v0.8.1 also has compilation issues that are removed by setting this define.
# https://github.com/KhronosGroup/Vulkan-ValidationLayers/pull/4639
# https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/4640
target_compile_definitions(VkLayer_utils PUBLIC XXH_NO_LONG_LONG)
target_link_libraries(VkLayer_utils PUBLIC Vulkan::Headers)
target_include_directories(VkLayer_utils SYSTEM PRIVATE external)
target_include_directories(VkLayer_utils PUBLIC . ${API_TYPE})
find_package(robin_hood CONFIG)
option(USE_ROBIN_HOOD_HASHING "robin_hood provides faster versions of std::unordered_map and std::unordered_set" ${robin_hood_FOUND})
if (USE_ROBIN_HOOD_HASHING)
target_link_libraries(VkLayer_utils PRIVATE robin_hood::robin_hood)
target_compile_definitions(robin_hood::robin_hood INTERFACE USE_ROBIN_HOOD_HASHING)
endif()
# TODO: This should be removed once the official "Vulkan-Utility-Libraries" library is available for consumption
if(BUILD_LAYER_SUPPORT_FILES)
install(FILES ${CMAKE_SOURCE_DIR}/layers/${API_TYPE}/generated/vk_enum_string_helper.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/vulkan)
install(FILES ${CMAKE_SOURCE_DIR}/layers/containers/custom_containers.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/vulkan/containers)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/layers/error_message
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/vulkan
FILES_MATCHING PATTERN "logging.*")
install(DIRECTORY ${CMAKE_SOURCE_DIR}/layers/external
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/vulkan
FILES_MATCHING PATTERN "xxhash.*")
install(FILES ${CMAKE_SOURCE_DIR}/layers/${API_TYPE}/generated/vk_format_utils.h
${CMAKE_SOURCE_DIR}/layers/${API_TYPE}/generated/vk_format_utils.cpp
${CMAKE_SOURCE_DIR}/layers/${API_TYPE}/generated/vk_validation_error_messages.h
${CMAKE_SOURCE_DIR}/layers/${API_TYPE}/generated/vk_layer_dispatch_table.h
${CMAKE_SOURCE_DIR}/layers/${API_TYPE}/generated/vk_dispatch_table_helper.h
${CMAKE_SOURCE_DIR}/layers/${API_TYPE}/generated/vk_safe_struct.h
${CMAKE_SOURCE_DIR}/layers/${API_TYPE}/generated/vk_safe_struct_utils.cpp
${CMAKE_SOURCE_DIR}/layers/${API_TYPE}/generated/vk_safe_struct_core.cpp
${CMAKE_SOURCE_DIR}/layers/${API_TYPE}/generated/vk_safe_struct_khr.cpp
${CMAKE_SOURCE_DIR}/layers/${API_TYPE}/generated/vk_safe_struct_ext.cpp
${CMAKE_SOURCE_DIR}/layers/${API_TYPE}/generated/vk_safe_struct_vendor.cpp
${CMAKE_SOURCE_DIR}/layers/${API_TYPE}/generated/vk_enum_string_helper.h
${CMAKE_SOURCE_DIR}/layers/${API_TYPE}/generated/vk_object_types.h
${CMAKE_SOURCE_DIR}/layers/${API_TYPE}/generated/vk_extension_helper.h
${CMAKE_SOURCE_DIR}/layers/${API_TYPE}/generated/vk_typemap_helper.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/vulkan/generated)
install(FILES ${CMAKE_SOURCE_DIR}/layers/utils/cast_utils.h
${CMAKE_SOURCE_DIR}/layers/utils/hash_util.h
${CMAKE_SOURCE_DIR}/layers/utils/hash_vk_types.h
${CMAKE_SOURCE_DIR}/layers/utils/vk_layer_extension_utils.cpp
${CMAKE_SOURCE_DIR}/layers/utils/vk_layer_extension_utils.h
${CMAKE_SOURCE_DIR}/layers/utils/vk_layer_utils.cpp
${CMAKE_SOURCE_DIR}/layers/utils/vk_layer_utils.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/vulkan/utils)
install(FILES vk_layer_config.h
vk_layer_config.cpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/vulkan)
install(TARGETS VkLayer_utils)
endif()
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
target_compile_options(VkLayer_utils PRIVATE
-Wno-sign-conversion
-Wno-implicit-int-conversion
)
endif()
if (NOT BUILD_LAYERS)
return()
endif()
# Represents all SPIRV libraries we need
add_library(VVL-SPIRV-LIBS INTERFACE)
find_package(SPIRV-Headers REQUIRED CONFIG QUIET)
target_link_libraries(VVL-SPIRV-LIBS INTERFACE SPIRV-Headers::SPIRV-Headers)
find_package(SPIRV-Tools-opt REQUIRED CONFIG QUIET)
target_link_libraries(VVL-SPIRV-LIBS INTERFACE SPIRV-Tools-opt)
find_package(SPIRV-Tools REQUIRED CONFIG QUIET)
# See https://github.com/KhronosGroup/SPIRV-Tools/issues/3909 for background on this.
# The targets available from SPIRV-Tools change depending on how SPIRV_TOOLS_BUILD_STATIC is set.
# Try to handle all possible combinations so that we work with externally built packages.
if (TARGET SPIRV-Tools)
target_link_libraries(VVL-SPIRV-LIBS INTERFACE SPIRV-Tools)
elseif(TARGET SPIRV-Tools-static)
target_link_libraries(VVL-SPIRV-LIBS INTERFACE SPIRV-Tools-static)
elseif(TARGET SPIRV-Tools-shared)
target_link_libraries(VVL-SPIRV-LIBS INTERFACE SPIRV-Tools-shared)
else()
message(FATAL_ERROR "Cannot determine SPIRV-Tools target name")
endif()
# NOTE: Our custom code generation target isn't desirable for system package managers or add_subdirectory users.
# So this target needs to be off by default to avoid obtuse build errors or patches.
option(VVL_CODEGEN "Enable vulkan validation layer code generation")
if (VVL_CODEGEN)
find_package(Python3 REQUIRED QUIET)
add_custom_target(vvl_codegen
COMMAND Python3::Interpreter "${VVL_SOURCE_DIR}/scripts/generate_source.py"
${VULKAN_HEADERS_REGISTRY_DIRECTORY} "${SPIRV_HEADERS_INSTALL_DIR}/include/spirv/unified1"
--incremental --generated-version ${VulkanHeaders_VERSION} --api ${API_TYPE}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${API_TYPE}/generated
)
endif()
add_library(vvl MODULE)
target_sources(vvl PRIVATE
best_practices/best_practices_error_enums.h
best_practices/best_practices_utils.cpp
best_practices/bp_buffer.cpp
best_practices/bp_cmd_buffer.cpp
best_practices/bp_copy_blit_resolve.cpp
best_practices/bp_descriptor.cpp
best_practices/bp_device_memory.cpp
best_practices/bp_drawdispatch.cpp
best_practices/bp_framebuffer.cpp
best_practices/bp_image.cpp
best_practices/bp_instance_device.cpp
best_practices/bp_pipeline.cpp
best_practices/bp_ray_tracing.cpp
best_practices/bp_render_pass.cpp
best_practices/bp_synchronization.cpp
best_practices/bp_video.cpp
best_practices/bp_wsi.cpp
best_practices/best_practices_validation.h
containers/qfo_transfer.h
containers/range_vector.h
containers/sparse_containers.h
containers/subresource_adapter.cpp
containers/subresource_adapter.h
core_checks/cc_android.cpp
core_checks/cc_buffer.cpp
core_checks/cc_buffer_address.h
core_checks/cc_cmd_buffer_dynamic.cpp
core_checks/cc_cmd_buffer.cpp
core_checks/cc_copy_blit_resolve.cpp
core_checks/core_validation.h
core_checks/cc_descriptor.cpp
core_checks/cc_device.cpp
core_checks/cc_device_memory.cpp
core_checks/cc_drawdispatch.cpp
core_checks/cc_external_object.cpp
core_checks/cc_image.cpp
core_checks/cc_image_layout.cpp
core_checks/cc_pipeline_compute.cpp
core_checks/cc_pipeline_graphics.cpp
core_checks/cc_pipeline_ray_tracing.cpp
core_checks/cc_pipeline.cpp
core_checks/cc_query.cpp
core_checks/cc_queue.cpp
core_checks/cc_ray_tracing.cpp
core_checks/cc_render_pass.cpp
core_checks/cc_shader.cpp
core_checks/cc_shader.h
core_checks/cc_synchronization.cpp
core_checks/cc_video.cpp
core_checks/cc_wsi.cpp
core_checks/cc_ycbcr.cpp
error_message/core_error_location.cpp
error_message/core_error_location.h
error_message/validation_error_enums.h
external/vma/vma.h
external/vma/vma.cpp
${API_TYPE}/generated/best_practices.cpp
${API_TYPE}/generated/best_practices.h
${API_TYPE}/generated/chassis.cpp
${API_TYPE}/generated/valid_param_values.cpp
${API_TYPE}/generated/command_validation.cpp
${API_TYPE}/generated/dynamic_state_helper.cpp
${API_TYPE}/generated/enum_flag_bits.h
${API_TYPE}/generated/layer_chassis_dispatch.cpp
${API_TYPE}/generated/object_tracker.cpp
${API_TYPE}/generated/object_tracker.h
${API_TYPE}/generated/parameter_validation.cpp
${API_TYPE}/generated/parameter_validation.h
${API_TYPE}/generated/spirv_grammar_helper.cpp
${API_TYPE}/generated/spirv_validation_helper.cpp
${API_TYPE}/generated/sync_validation_types.cpp
${API_TYPE}/generated/thread_safety.cpp
${API_TYPE}/generated/thread_safety.h
${API_TYPE}/generated/vk_safe_struct_utils.cpp
${API_TYPE}/generated/vk_safe_struct_core.cpp
${API_TYPE}/generated/vk_safe_struct_khr.cpp
${API_TYPE}/generated/vk_safe_struct_ext.cpp
${API_TYPE}/generated/vk_safe_struct_vendor.cpp
${API_TYPE}/generated/vk_safe_struct.h
gpu_validation/debug_printf.cpp
gpu_validation/debug_printf.h
gpu_validation/gpu_utils.cpp
gpu_validation/gpu_utils.h
gpu_validation/gpu_validation.cpp
gpu_validation/gpu_validation.cpp
gpu_validation/gpu_validation.h
gpu_validation/gv_descriptor_sets.cpp
gpu_validation/gv_descriptor_sets.h
object_tracker/object_lifetime_validation.h
object_tracker/object_tracker_utils.cpp
state_tracker/base_node.cpp
state_tracker/base_node.h
state_tracker/buffer_state.cpp
state_tracker/buffer_state.h
state_tracker/cmd_buffer_state.cpp
state_tracker/cmd_buffer_state.h
state_tracker/descriptor_sets.cpp
state_tracker/descriptor_sets.h
state_tracker/device_memory_state.cpp
state_tracker/device_memory_state.h
state_tracker/device_state.h
state_tracker/image_layout_map.cpp
state_tracker/image_layout_map.h
state_tracker/image_state.cpp
state_tracker/image_state.h
state_tracker/pipeline_layout_state.cpp
state_tracker/pipeline_layout_state.h
state_tracker/pipeline_state.cpp
state_tracker/pipeline_state.h
state_tracker/pipeline_sub_state.cpp
state_tracker/pipeline_sub_state.h
state_tracker/query_state.h
state_tracker/queue_state.cpp
state_tracker/queue_state.h
state_tracker/ray_tracing_state.h
state_tracker/render_pass_state.cpp
state_tracker/render_pass_state.h
state_tracker/sampler_state.h
state_tracker/shader_instruction.cpp
state_tracker/shader_instruction.h
state_tracker/shader_module.cpp
state_tracker/shader_module.h
state_tracker/state_tracker.cpp
state_tracker/state_tracker.h
state_tracker/video_session_state.cpp
state_tracker/video_session_state.h
stateless/parameter_name.h
stateless/sl_buffer.cpp
stateless/sl_cmd_buffer_dynamic.cpp
stateless/sl_cmd_buffer.cpp
stateless/sl_descriptor.cpp
stateless/sl_device_memory.cpp
stateless/sl_external_object.cpp
stateless/sl_framebuffer.cpp
stateless/sl_image.cpp
stateless/sl_instance_device.cpp
stateless/sl_pipeline.cpp
stateless/sl_ray_tracing.cpp
stateless/sl_render_pass.cpp
stateless/sl_synchronization.cpp
stateless/sl_wsi.cpp
stateless/stateless_validation.h
sync/sync_validation.cpp
sync/sync_validation.h
sync/sync_utils.cpp
sync/sync_utils.h
sync/sync_vuid_maps.cpp
sync/sync_vuid_maps.h
layer_options.cpp
vk_layer_settings_ext.h
)
get_target_property(LAYER_SOURCES vvl SOURCES)
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${LAYER_SOURCES})
set_target_properties(vvl PROPERTIES OUTPUT_NAME ${LAYER_NAME})
if(MSVC)
target_link_options(vvl PRIVATE /DEF:${CMAKE_CURRENT_SOURCE_DIR}/${LAYER_NAME}.def)
target_compile_options(vvl PRIVATE /bigobj)
elseif(MINGW)
target_sources(vvl PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/${LAYER_NAME}.def)
target_compile_options(vvl PRIVATE -Wa,-mbig-obj)
elseif(APPLE)
message(STATUS "Functions are exported via VVL_EXPORT")
set_target_properties(vvl PROPERTIES SUFFIX ".dylib")
elseif(ANDROID)
message(STATUS "Functions are exported via VVL_EXPORT")
else()
target_link_options(vvl PRIVATE LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/${LAYER_NAME}.map,-Bsymbolic,--exclude-libs,ALL)
endif()
if(${CMAKE_CXX_COMPILER_ID} MATCHES "(GNU|Clang)")
target_compile_options(vvl PRIVATE
-Wno-unused-parameter
)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(vvl PRIVATE
-Wno-sign-conversion
-Wno-implicit-int-conversion
)
endif()
endif()
# Khronos validation additional dependencies
if (USE_ROBIN_HOOD_HASHING)
target_link_libraries(vvl PRIVATE robin_hood::robin_hood)
endif()
# Order matters here. VkLayer_utils should be the last link library to ensure mimalloc overrides are picked up correctly.
# Otherwise, libraries after VkLayer_utils will not benefit from this performance improvement.
target_link_libraries(vvl PRIVATE VVL-SPIRV-LIBS VkLayer_utils)
# Using mimalloc on non-Windows OSes currently results in unit test instability with some
# OS version / driver combinations. On 32-bit systems, using mimalloc cause an increase in
# the amount of virtual address space needed, which can also cause stability problems.
if (MSVC AND CMAKE_SIZEOF_VOID_P EQUAL 8)
find_package(mimalloc CONFIG)
option(USE_MIMALLOC "Use mimalloc, a fast malloc/free replacement library" ${mimalloc_FOUND})
if (USE_MIMALLOC)
target_compile_definitions(mimalloc-static INTERFACE USE_MIMALLOC)
target_link_libraries(vvl PRIVATE mimalloc-static)
endif()
endif()
target_include_directories(vvl SYSTEM PRIVATE external)
if (ANDROID)
add_subdirectory(android)
return()
endif()
# There are 2 primary deliverables for the validation layers.
# - The actual library VkLayer_khronos_validation.(dll|so|dylib)
# - The respective json file, VkLayer_khronos_validation.json
# This code generates the appropriate json for both local testing and the installation.
# NOTE: For WIN32 the JSON and dll MUST be placed in the same location, due to Win32 using a relative path for installation.
set(INPUT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/${LAYER_NAME}.json.in")
set(INTERMEDIATE_FILE "${CMAKE_CURRENT_BINARY_DIR}/json/validation.json")
set(OUTPUT_FILE_FINAL_NAME "${LAYER_NAME}.json")
set(LAYER_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR})
if (WIN32)
set(LAYER_INSTALL_DIR ${CMAKE_INSTALL_BINDIR}) # WIN32/MINGW expect the dll in the `bin` dir, this matches our WIN32 SDK process
endif()
if (WIN32)
set(JSON_LIBRARY_PATH ".\\\\${LAYER_NAME}.dll")
elseif(APPLE)
set(JSON_LIBRARY_PATH "./lib${LAYER_NAME}.dylib")
else()
set(JSON_LIBRARY_PATH "./lib${LAYER_NAME}.so")
endif()
configure_file(${INPUT_FILE} ${INTERMEDIATE_FILE} @ONLY)
# To support both multi/single configuration generators just copy the json to the correct directory
add_custom_command(TARGET vvl POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${INTERMEDIATE_FILE} $<TARGET_FILE_DIR:vvl>/${OUTPUT_FILE_FINAL_NAME}
)
# For UNIX-based systems, `library_path` should not contain a relative path (indicated by "./") before installing to system directories
# This json isn't used for regular local development, it's used for installation
if (UNIX)
set(UNIX_INTERMEDIATE_FILE "${CMAKE_CURRENT_BINARY_DIR}/json/unix_install_validation.json")
if(APPLE)
set(JSON_LIBRARY_PATH "lib${LAYER_NAME}.dylib")
else()
set(JSON_LIBRARY_PATH "lib${LAYER_NAME}.so")
endif()
configure_file(${INPUT_FILE} ${UNIX_INTERMEDIATE_FILE} @ONLY)
install(FILES ${UNIX_INTERMEDIATE_FILE} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/vulkan/explicit_layer.d RENAME ${OUTPUT_FILE_FINAL_NAME})
endif()
if (WIN32)
install(FILES ${INTERMEDIATE_FILE} DESTINATION ${LAYER_INSTALL_DIR} RENAME ${OUTPUT_FILE_FINAL_NAME})
endif()
if (MSVC)
install(FILES $<TARGET_PDB_FILE:vvl> DESTINATION ${LAYER_INSTALL_DIR})
endif()
install(TARGETS vvl DESTINATION ${LAYER_INSTALL_DIR})
|