Skip to content

Commit c452af2

Browse files
authored
Common code cleanup (#12)
Consistent Doxygen style (must use @ everywhere). Consistent include path style (must include prefix directory for common code). Moves CMake compiler helper to common .cmake file. Allows layer code to write over existing layer code to facilitate updates.
1 parent 5a99c11 commit c452af2

33 files changed

+500
-533
lines changed

.github/workflows/build_test.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ jobs:
8282
- name: Generate layer_test
8383
run: |
8484
python3 ./generator/generate_vulkan_common.py
85+
mkdir layer_example/build_rel
86+
cd layer_example/build_rel
87+
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release ..
88+
make -j4
8589
8690
build-ubuntu-x64-clang-new-project:
8791
name: Ubuntu x64 generate new layer
@@ -94,6 +98,7 @@ jobs:
9498

9599
- name: Generate layer_test
96100
run: |
101+
python3 ./generator/generate_vulkan_common.py
97102
python3 ./generator/generate_vulkan_layer.py --project-name Test --layer-name VkLayerTest --output layer_test
98103
mkdir layer_test/build_rel
99104
cd layer_test/build_rel

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ set(CMAKE_CXX_STANDARD 20)
2727

2828
project(libGPULayers_UnitTests VERSION 1.0.0)
2929

30+
# Standard CMake components
31+
include(source_common/compiler_helper.cmake)
32+
3033
# Build steps
3134
set(LGL_UNITTEST ON)
3235

generator/generate_vulkan_layer.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,17 +429,13 @@ def main():
429429
print(f'ERROR: Layer name "{args.layer_name}" is invalid')
430430
return 1
431431

432-
# If overwrite is set, remove output directory if it exists
433-
if args.overwrite:
434-
shutil.rmtree(args.output, ignore_errors=True)
435-
436-
# Check that output directory is either empty or non-existent
432+
# Check that output directory is either empty or over-writable
437433
outdir = args.output
438434
if os.path.exists(outdir):
439435
if not os.path.isdir(outdir):
440436
print(f'ERROR: Output location "{outdir}" is not a directory')
441437
return 1
442-
if len(os.listdir(outdir)) != 0:
438+
if len(os.listdir(outdir)) != 0 and not args.overwrite:
443439
print(f'ERROR: Output directory "{outdir}" is not empty')
444440
return 1
445441

generator/vk_codegen/device_dispatch_table.txt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,33 @@
22

33
#include <vulkan/vulkan.h>
44

5-
#include "device_functions.hpp"
5+
#include "framework/device_functions.hpp"
6+
#include "utils/misc.hpp"
7+
68
#if __has_include ("layer_device_functions.hpp")
79
#include "layer_device_functions.hpp"
810
#endif
911

1012
/**
11-
* \brief Interception table lookup entry.
13+
* @brief Interception table lookup entry.
1214
*/
1315
struct DeviceInterceptTableEntry
1416
{
1517
/**
16-
* \brief The function entrypoint name.
18+
* @brief The function entrypoint name.
1719
*/
1820
const char* name;
1921

2022
/**
21-
* \brief The layer function pointer.
23+
* @brief The layer function pointer.
2224
*/
2325
PFN_vkVoidFunction function;
2426
};
2527

2628
#define ENTRY(fnc) { STR(fnc), reinterpret_cast<PFN_vkVoidFunction>(layer_##fnc<user_tag>) }
2729

2830
/**
29-
* \brief The device dispatch table used to call the driver.
31+
* @brief The device dispatch table used to call the driver.
3032
*/
3133
static const struct DeviceInterceptTableEntry deviceIntercepts[] = {
3234
{ITABLE_MEMBERS}
@@ -44,11 +46,11 @@ struct DeviceDispatchTable {
4446
#define ENTRY(fnc) table.fnc = (PFN_##fnc)getProcAddr(device, STR(fnc))
4547

4648
/**
47-
* \brief Initialize the device dispatch table with driver function pointers.
49+
* @brief Initialize the device dispatch table with driver function pointers.
4850
*
49-
* \param device The device handle.
50-
* \param getProcAddr The function getter for the driver/next layer down.
51-
* \param table The table to populate.
51+
* @param device The device handle.
52+
* @param getProcAddr The function getter for the driver/next layer down.
53+
* @param table The table to populate.
5254
*/
5355
static inline void initDriverDeviceDispatchTable(
5456
VkDevice device,

generator/vk_codegen/instance_dispatch_table.txt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,33 @@
22

33
#include <vulkan/vulkan.h>
44

5-
#include "instance_functions.hpp"
5+
#include "framework/instance_functions.hpp"
6+
#include "utils/misc.hpp"
7+
68
#if __has_include ("layer_instance_functions.hpp")
79
#include "layer_instance_functions.hpp"
810
#endif
911

1012
/**
11-
* \brief Interception table lookup entry.
13+
* @brief Interception table lookup entry.
1214
*/
1315
struct InstanceInterceptTableEntry
1416
{
1517
/**
16-
* \brief The function entrypoint name.
18+
* @brief The function entrypoint name.
1719
*/
1820
const char* name;
1921

2022
/**
21-
* \brief The layer function pointer.
23+
* @brief The layer function pointer.
2224
*/
2325
PFN_vkVoidFunction function;
2426
};
2527

2628
#define ENTRY(fnc) { STR(fnc), reinterpret_cast<PFN_vkVoidFunction>(layer_##fnc<user_tag>) }
2729

2830
/**
29-
* \brief The instance dispatch table used to call the driver.
31+
* @brief The instance dispatch table used to call the driver.
3032
*/
3133
static const struct InstanceInterceptTableEntry instanceIntercepts[] = {
3234
{ITABLE_MEMBERS}
@@ -35,7 +37,7 @@ static const struct InstanceInterceptTableEntry instanceIntercepts[] = {
3537
#undef ENTRY
3638

3739
/**
38-
* \brief The instance dispatch table used to call the driver.
40+
* @brief The instance dispatch table used to call the driver.
3941
*/
4042
struct InstanceDispatchTable {
4143
PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
@@ -46,11 +48,11 @@ struct InstanceDispatchTable {
4648
#define ENTRY(fnc) table.fnc = (PFN_##fnc)getProcAddr(instance, STR(fnc))
4749

4850
/**
49-
* \brief Initialize the instance dispatch table with driver function pointers.
51+
* @brief Initialize the instance dispatch table with driver function pointers.
5052
*
51-
* \param instance The instance handle.
52-
* \param getProcAddr The function getter for the driver/next layer down.
53-
* \param table The table to populate.
53+
* @param instance The instance handle.
54+
* @param getProcAddr The function getter for the driver/next layer down.
55+
* @param table The table to populate.
5456
*/
5557
static inline void initDriverInstanceDispatchTable(
5658
VkInstance instance,

generator/vk_codegen/root_CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ project({PROJECT_NAME} VERSION 1.0.0)
2929

3030
# Common configuration
3131
set(LGL_LOG_TAG, "{LAYER_NAME}")
32+
include(../source_common/compiler_helper.cmake)
3233

3334
# Build steps
3435
add_subdirectory(source)

generator/vk_codegen/source_CMakeLists.txt

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,6 @@
2121
# SOFTWARE.
2222
# -----------------------------------------------------------------------------
2323

24-
# Compiler accepts GNU-style command line options
25-
set(is_gnu_fe1 "$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},GNU>")
26-
27-
# Compiler accepts AppleClang-style command line options, which is also GNU-style
28-
set(is_gnu_fe2 "$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},AppleClang>")
29-
30-
# Compiler accepts GNU-style command line options
31-
set(is_gnu_fe "$<OR:${is_gnu_fe1},${is_gnu_fe2}>")
32-
33-
# Compiler is upstream clang with the standard frontend
34-
set(is_clang "$<AND:${is_gnu_fe},$<CXX_COMPILER_ID:Clang,AppleClang>>")
35-
3624
# Set output file names
3725
if (CMAKE_BUILD_TYPE STREQUAL "Release")
3826
set(VK_LAYER {LAYER_NAME}_sym)
@@ -59,24 +47,15 @@ add_library(
5947

6048
target_include_directories(
6149
${VK_LAYER} PRIVATE
62-
${PROJECT_SOURCE_DIR}/../source_common/framework
50+
${PROJECT_SOURCE_DIR}/../source_common
6351
${CMAKE_CURRENT_BINARY_DIR}
6452
.)
6553

6654
target_include_directories(
6755
${VK_LAYER} SYSTEM PRIVATE
6856
../../khronos/vulkan/include)
6957

70-
target_compile_options(
71-
${VK_LAYER} PRIVATE
72-
-fvisibility=hidden
73-
-fvisibility-inlines-hidden
74-
-fno-exceptions
75-
-fno-rtti
76-
-Wall
77-
-Wextra
78-
-Wno-missing-field-initializers
79-
$<${is_clang}:-Wdocumentation>)
58+
lgl_set_build_options(${VK_LAYER})
8059

8160
target_compile_definitions(
8261
${VK_LAYER} PRIVATE
@@ -85,7 +64,7 @@ target_compile_definitions(
8564

8665
target_link_libraries(
8766
${VK_LAYER}
88-
layer_common
67+
lib_layer_framework
8968
$<$<PLATFORM_ID:Android>:log>)
9069

9170
if (CMAKE_BUILD_TYPE STREQUAL "Release")

generator/vk_common/CMakeLists.txt

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,54 +21,32 @@
2121
# SOFTWARE.
2222
# -----------------------------------------------------------------------------
2323

24-
# Compiler accepts GNU-style command line options
25-
set(is_gnu_fe1 "$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},GNU>")
26-
27-
# Compiler accepts AppleClang-style command line options, which is also GNU-style
28-
set(is_gnu_fe2 "$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},AppleClang>")
29-
30-
# Compiler accepts GNU-style command line options
31-
set(is_gnu_fe "$<OR:${is_gnu_fe1},${is_gnu_fe2}>")
32-
33-
# Compiler is upstream clang with the standard frontend
34-
set(is_clang "$<AND:${is_gnu_fe},$<CXX_COMPILER_ID:Clang,AppleClang>>")
35-
36-
set(DIR_TARGET layer_common)
24+
set(BUILD_TARGET lib_layer_framework)
3725

3826
add_library(
39-
${DIR_TARGET} STATIC
27+
${BUILD_TARGET} STATIC
4028
device_functions.cpp
4129
instance_functions.cpp)
4230

4331
target_include_directories(
44-
${DIR_TARGET} PRIVATE
32+
${BUILD_TARGET} PRIVATE
4533
# Note, this includes from the layer-specific tree
4634
${PROJECT_SOURCE_DIR}/source
47-
.)
35+
../)
4836

4937
target_include_directories(
50-
${DIR_TARGET} SYSTEM PRIVATE
38+
${BUILD_TARGET} SYSTEM PRIVATE
5139
../../khronos/vulkan/include)
5240

53-
target_compile_options(
54-
${DIR_TARGET} PRIVATE
55-
-fvisibility=hidden
56-
-fvisibility-inlines-hidden
57-
-fno-exceptions
58-
-fno-rtti
59-
-fpic
60-
-Wall
61-
-Wextra
62-
-Wno-missing-field-initializers
63-
$<${is_clang}:-Wdocumentation>)
41+
lgl_set_build_options(${BUILD_TARGET})
6442

6543
# TODO: Log tag needs to come from child project
6644
target_compile_definitions(
67-
${DIR_TARGET} PRIVATE
45+
${BUILD_TARGET} PRIVATE
6846
$<$<PLATFORM_ID:Android>:VK_USE_PLATFORM_ANDROID_KHR=1>
6947
$<$<PLATFORM_ID:Android>:LGL_LOG_TAG="${LGL_LOG_TAG}">)
7048

7149
# TODO: Remove this?
7250
target_link_libraries(
73-
${DIR_TARGET}
51+
${BUILD_TARGET}
7452
$<$<PLATFORM_ID:Android>:log>)

generator/vk_common/entry_utils.hpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "device_dispatch_table.hpp"
4444
#include "device_functions.hpp"
4545

46+
extern std::mutex g_vulkanLock;
4647

4748
#define VK_LAYER_EXPORT __attribute__((visibility("default")))
4849

@@ -53,7 +54,7 @@
5354
#endif
5455

5556
/**
56-
* \brief The layer configuration.
57+
* @brief The layer configuration.
5758
*/
5859
#define LGL_VERSION VK_MAKE_VERSION(LGL_VER_MAJOR, LGL_VER_MINOR, LGL_VER_PATCH)
5960

@@ -62,37 +63,37 @@ static const std::array<VkLayerProperties, 1> layerProps = {
6263
};
6364

6465
/**
65-
* \brief Dispatch table lookup entry.
66+
* @brief Dispatch table lookup entry.
6667
*/
6768
struct DispatchTableEntry
6869
{
6970
/**
70-
* \brief The function entrypoint name.
71+
* @brief The function entrypoint name.
7172
*/
7273
const char* name;
7374

7475
/**
75-
* \brief The function pointer.
76+
* @brief The function pointer.
7677
*/
7778
PFN_vkVoidFunction function;
7879
};
7980

8081
/**
81-
* \brief Utility macro to define a lookup for a core function.
82+
* @brief Utility macro to define a lookup for a core function.
8283
*/
8384
#define VK_TABLE_ENTRY(func) \
8485
{ STR(func), reinterpret_cast<PFN_vkVoidFunction>(func) }
8586

8687
/**
87-
* \brief Utility macro to define a lookup for a layer-dispatch-only function.
88+
* @brief Utility macro to define a lookup for a layer-dispatch-only function.
8889
*/
8990
#define VK_TABLE_ENTRYL(func) \
9091
{ STR(func), reinterpret_cast<PFN_vkVoidFunction>(layer_##func) }
9192

9293
/**
93-
* \brief Fetch the layer function for a given instance entrypoint name.
94+
* @brief Fetch the layer function for a given instance entrypoint name.
9495
*
95-
* \param name The layer entry point name.
96+
* @param name The layer entry point name.
9697
*
9798
* \return The layer function pointer, or \c nullptr if the layer doesn't
9899
* intercept the function.
@@ -126,9 +127,9 @@ static PFN_vkVoidFunction get_instance_layer_function(
126127
}
127128

128129
/**
129-
* \brief Fetch the layer function for a given device entrypoint name.
130+
* @brief Fetch the layer function for a given device entrypoint name.
130131
*
131-
* \param name The layer entry point name.
132+
* @param name The layer entry point name.
132133
*
133134
* \return The layer function pointer, or \c nullptr if the layer doesn't intercept the function.
134135
*/

0 commit comments

Comments
 (0)