diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..091ff8d --- /dev/null +++ b/.clang-format @@ -0,0 +1,165 @@ +--- +Language: Cpp +BasedOnStyle: Mozilla + +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: None +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: Consecutive +AlignConsecutiveDeclarations: None +AlignConsecutiveMacros: Consecutive +AlignEscapedNewlines: Right +AlignOperands: AlignAfterOperator +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: InlineOnly +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: Yes +AttributeMacros: +BinPackArguments: false +BinPackParameters: false +BitFieldColonSpacing: Both +BraceWrapping: + AfterCaseLabel: true + AfterClass: true + AfterControlStatement: Always + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterStruct: true + AfterUnion: true + AfterExternBlock: true + BeforeCatch: true + BeforeElse: true + BeforeLambdaBody: true + BeforeWhile: true + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Custom +BreakBeforeConceptDeclarations: true +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +BreakStringLiterals: false +ColumnLimit: 120 +CommentPragmas: '\(no-format\) $' +CompactNamespaces: true +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: false +DerivePointerAlignment: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: Always +FixNamespaceComments: false +ForEachMacros: +IfMacros: +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^"[^"]+"$' + Priority: 2 + SortPriority: 2 + - Regex: '^<[0-9A-Za-z_/]+>$' + Priority: 3 + SortPriority: 3 + - Regex: '^<[Ww]indows.h>$' + Priority: 4 + SortPriority: 4 + - Regex: '^<(gtest|gmock)/[^>]+\.(h|hh|hpp)>$' + Priority: 7 + SortPriority: 7 + - Regex: '^<[^>]+\.(h|hh|hpp)>$' + Priority: 8 + SortPriority: 8 +IncludeIsMainRegex: '$' +IncludeIsMainSourceRegex: '(_impl\.hpp)$' +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: false +IndentExternBlock: false +IndentGotoLabels: false +IndentPPDirectives: AfterHash +IndentRequiresClause: false +IndentWidth: 4 # +IndentWrappedFunctionNames: true +InsertBraces: true +InsertNewlineAtEOF: true +InsertTrailingCommas: Wrapped +KeepEmptyLinesAtTheStartOfBlocks: false +KeepEmptyLinesAtEOF: true +LambdaBodyIndentation: Signature +#MacroBlockBegin: +#MacroBlockEnd: +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: Inner +NamespaceMacros: +PackConstructorInitializers: Never +PenaltyBreakOpenParenthesis: 0 +PPIndentWidth: 2 # +PointerAlignment: Left +QualifierAlignment: Custom +QualifierOrder: + - inline + - static + - constexpr + - friend + - const + - restrict + - volatile + - type +RawStringFormats: +ReferenceAlignment: Pointer +ReflowComments: true +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +ShortNamespaceLines: 1 +SortIncludes: CaseSensitive +SortUsingDeclarations: true +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeParens: ControlStatementsExceptControlMacros +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: c++20 +StatementAttributeLikeMacros: +StatementMacros: + - UNUSED +TabWidth: 4 +TypenameMacros: +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: +... diff --git a/cmake/clang-tools.cmake b/cmake/clang-tools.cmake new file mode 100644 index 0000000..db06f41 --- /dev/null +++ b/cmake/clang-tools.cmake @@ -0,0 +1,73 @@ +# Copyright (C) 2025 by Arm Limited (or its affiliates). All rights reserved. +include_guard(GLOBAL) + +# ### +# Find various optional tools +# ### +find_file(CLANG_FORMAT NAMES "clang-format${CMAKE_EXECUTABLE_SUFFIX}" + NO_CMAKE_FIND_ROOT_PATH) + +if(EXISTS ${CLANG_FORMAT}) + execute_process( + COMMAND "${CLANG_FORMAT}" --version + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + RESULT_VARIABLE _cf_res + OUTPUT_VARIABLE _cf_out + ERROR_QUIET) + string(REGEX REPLACE "[\n\r\t]" " " _cf_out "${_cf_out}") + string(STRIP "${_cf_out}" _cf_out) + + if(NOT "${_cf_res}" EQUAL 0) + message(STATUS "Failed to execute '${CLANG_FORMAT} --version'") + unset(CLANG_FORMAT) + elseif(NOT "${_cf_out}" MATCHES ".*clang-format version ([^ ]+).*") + message(STATUS "Failed to understand '${CLANG_FORMAT} --version' output") + unset(CLANG_FORMAT) + else() + string(REGEX REPLACE ".*clang-format version ([^ ]+).*" "\\1" _cf_ver "${_cf_out}") + message(STATUS "Detected clang-format version '${_cf_ver}'") + + if("${_cf_ver}" VERSION_LESS "18.0.0") + message(STATUS "The version of clang-format is too old") + unset(CLANG_FORMAT) + endif() + endif() + + unset(_cf_res) + unset(_cf_out) + unset(_cf_ver) +endif() + +# ### +# Add a custom targets for running clang-format +# ### +if(EXISTS ${CLANG_FORMAT}) + add_custom_target(clang-format + COMMENT "Run clang-format on all targets") +endif() + +# used to get the root project directory +file(REAL_PATH "${CMAKE_CURRENT_LIST_DIR}/.." _cf_root) + +function(add_clang_tools) + if(EXISTS ${CLANG_FORMAT}) + # Determine the name to give the custom target; base it on the folder path relative to the repo root + file(RELATIVE_PATH _cf_relpath "${_cf_root}" "${CMAKE_CURRENT_SOURCE_DIR}") + string(REGEX REPLACE "[^0-9A-Za-z_\-]" "-" _cf_name "${_cf_relpath}") + + # find the sources + file( + GLOB_RECURSE _cf_srcs + LIST_DIRECTORIES false + RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" + CONFIGURE_DEPENDS "*.cpp" "*.hpp") + + # add the task + add_custom_target(clang-format-${_cf_name} + COMMAND ${CLANG_FORMAT} -i ${_cf_srcs} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + SOURCES ${_cf_srcs} + COMMENT "Run clang-format on the sources in ${CMAKE_CURRENT_SOURCE_DIR} for ${_cf_name}") + add_dependencies(clang-format clang-format-${_cf_name}) + endif() +endfunction() diff --git a/generator/generate_vulkan_common.py b/generator/generate_vulkan_common.py index 9900f1e..ce273bb 100755 --- a/generator/generate_vulkan_common.py +++ b/generator/generate_vulkan_common.py @@ -502,6 +502,9 @@ def generate_instance_decls( file.write('#pragma once\n') file.write('\n') + file.write('// clang-format off\n') + file.write('\n') + file.write('#include \n') file.write('\n') @@ -558,6 +561,8 @@ def generate_instance_decls( file.write('\n'.join(lines)) file.write('\n') + file.write('// clang-format on\n') + def generate_instance_defs( file: TextIO, mapping: VersionInfo, commands: list[Command]) -> None: @@ -695,6 +700,9 @@ def generate_device_decls( file.write('#pragma once\n') file.write('\n') + file.write('// clang-format off\n') + file.write('\n') + file.write('#include \n') file.write('\n') @@ -750,6 +758,8 @@ def generate_device_decls( file.write('\n'.join(lines)) file.write('\n') + file.write('// clang-format on\n') + def generate_device_defs( file: TextIO, mapping: VersionInfo, commands: list[Command]) -> None: diff --git a/generator/vk_codegen/device_defs.txt b/generator/vk_codegen/device_defs.txt index b217a1d..1a9c6bd 100644 --- a/generator/vk_codegen/device_defs.txt +++ b/generator/vk_codegen/device_defs.txt @@ -1,3 +1,5 @@ +// clang-format off + #include // Include from per-layer code @@ -10,3 +12,4 @@ extern std::mutex g_vulkanLock; {FUNCTION_DEFS} +// clang-format on diff --git a/generator/vk_codegen/device_dispatch_table.txt b/generator/vk_codegen/device_dispatch_table.txt index 4ff4bd5..8550328 100644 --- a/generator/vk_codegen/device_dispatch_table.txt +++ b/generator/vk_codegen/device_dispatch_table.txt @@ -1,5 +1,7 @@ #pragma once +// clang-format off + #include #include "framework/device_functions.hpp" @@ -64,3 +66,5 @@ static inline void initDriverDeviceDispatchTable( } #undef ENTRY + +// clang-format on diff --git a/generator/vk_codegen/instance_defs.txt b/generator/vk_codegen/instance_defs.txt index 400263c..e2bfa50 100644 --- a/generator/vk_codegen/instance_defs.txt +++ b/generator/vk_codegen/instance_defs.txt @@ -1,3 +1,5 @@ +// clang-format off + #include // Include from per-layer code @@ -12,3 +14,4 @@ extern std::mutex g_vulkanLock; {FUNCTION_DEFS} +// clang-format on diff --git a/generator/vk_codegen/instance_dispatch_table.txt b/generator/vk_codegen/instance_dispatch_table.txt index ad73df3..96c3b82 100644 --- a/generator/vk_codegen/instance_dispatch_table.txt +++ b/generator/vk_codegen/instance_dispatch_table.txt @@ -1,5 +1,7 @@ #pragma once +// clang-format off + #include #include "framework/device_functions.hpp" @@ -67,3 +69,5 @@ static inline void initDriverInstanceDispatchTable( } #undef ENTRY + +// clang-format on diff --git a/generator/vk_codegen/root_CMakeLists.txt b/generator/vk_codegen/root_CMakeLists.txt index ffa4b2f..00ed305 100644 --- a/generator/vk_codegen/root_CMakeLists.txt +++ b/generator/vk_codegen/root_CMakeLists.txt @@ -33,6 +33,7 @@ set(LGL_CONFIG_TRACE 0) set(LGL_CONFIG_LOG 1) include(../source_common/compiler_helper.cmake) +include(../cmake/clang-tools.cmake) # Build steps add_subdirectory(source) diff --git a/generator/vk_codegen/source_CMakeLists.txt b/generator/vk_codegen/source_CMakeLists.txt index dcb3f42..1de8d53 100644 --- a/generator/vk_codegen/source_CMakeLists.txt +++ b/generator/vk_codegen/source_CMakeLists.txt @@ -70,3 +70,5 @@ if (CMAKE_BUILD_TYPE STREQUAL "Release") ARGS --strip-all -o ${VK_LAYER_STRIP} $ COMMENT "Stripped lib${VK_LAYER}.so to ${VK_LAYER_STRIP}") endif() + +add_clang_tools() \ No newline at end of file diff --git a/layer_example/CMakeLists.txt b/layer_example/CMakeLists.txt index 3b8f48e..6a9f441 100644 --- a/layer_example/CMakeLists.txt +++ b/layer_example/CMakeLists.txt @@ -33,6 +33,7 @@ set(LGL_CONFIG_TRACE 0) set(LGL_CONFIG_LOG 1) include(../source_common/compiler_helper.cmake) +include(../cmake/clang-tools.cmake) # Build steps add_subdirectory(source) diff --git a/layer_example/source/CMakeLists.txt b/layer_example/source/CMakeLists.txt index 8456f98..294cb72 100644 --- a/layer_example/source/CMakeLists.txt +++ b/layer_example/source/CMakeLists.txt @@ -71,3 +71,5 @@ if (CMAKE_BUILD_TYPE STREQUAL "Release") ARGS --strip-all -o ${VK_LAYER_STRIP} $ COMMENT "Stripped lib${VK_LAYER}.so to ${VK_LAYER_STRIP}") endif() + +add_clang_tools() \ No newline at end of file diff --git a/layer_example/source/device.cpp b/layer_example/source/device.cpp index 711a9c0..11bd1dd 100644 --- a/layer_example/source/device.cpp +++ b/layer_example/source/device.cpp @@ -23,16 +23,17 @@ * ---------------------------------------------------------------------------- */ +#include "device.hpp" + +#include "framework/utils.hpp" +#include "instance.hpp" + #include -#include #include -#include +#include #include -#include "framework/utils.hpp" - -#include "device.hpp" -#include "instance.hpp" +#include /** * @brief The dispatch lookup for all of the created Vulkan instances. @@ -40,62 +41,54 @@ static std::unordered_map> g_devices; /* See header for documentation. */ -const std::vector Device::extraExtensions { }; +const std::vector Device::extraExtensions {}; /* See header for documentation. */ -void Device::store( - VkDevice handle, - std::unique_ptr device -) { +void Device::store(VkDevice handle, std::unique_ptr device) +{ void* key = getDispatchKey(handle); - g_devices.insert({ key, std::move(device) }); + g_devices.insert({key, std::move(device)}); } /* See header for documentation. */ -Device* Device::retrieve( - VkDevice handle -) { +Device* Device::retrieve(VkDevice handle) +{ void* key = getDispatchKey(handle); assert(isInMap(key, g_devices)); return g_devices.at(key).get(); } /* See header for documentation. */ -Device* Device::retrieve( - VkQueue handle -) { +Device* Device::retrieve(VkQueue handle) +{ void* key = getDispatchKey(handle); assert(isInMap(key, g_devices)); return g_devices.at(key).get(); } /* See header for documentation. */ -Device* Device::retrieve( - VkCommandBuffer handle -) { +Device* Device::retrieve(VkCommandBuffer handle) +{ void* key = getDispatchKey(handle); assert(isInMap(key, g_devices)); return g_devices.at(key).get(); } /* See header for documentation. */ -void Device::destroy( - Device* device -) { +void Device::destroy(Device* device) +{ g_devices.erase(getDispatchKey(device)); } /* See header for documentation. */ -Device::Device( - Instance* _instance, - VkPhysicalDevice _physicalDevice, - VkDevice _device, - PFN_vkGetDeviceProcAddr nlayerGetProcAddress, - const VkDeviceCreateInfo& createInfo -): - instance(_instance), - physicalDevice(_physicalDevice), - device(_device) +Device::Device(Instance* _instance, + VkPhysicalDevice _physicalDevice, + VkDevice _device, + PFN_vkGetDeviceProcAddr nlayerGetProcAddress, + const VkDeviceCreateInfo& createInfo) + : instance(_instance), + physicalDevice(_physicalDevice), + device(_device) { UNUSED(createInfo); diff --git a/layer_example/source/device.hpp b/layer_example/source/device.hpp index 29325c2..6e85ba2 100644 --- a/layer_example/source/device.hpp +++ b/layer_example/source/device.hpp @@ -52,12 +52,11 @@ #pragma once -#include - #include "framework/device_dispatch_table.hpp" - #include "instance.hpp" +#include + /** * @brief This class implements the layer state tracker for a single device. */ @@ -70,9 +69,7 @@ class Device * @param handle The dispatchable device handle to use as an indirect key. * @param device The @c Device object to store. */ - static void store( - VkDevice handle, - std::unique_ptr device); + static void store(VkDevice handle, std::unique_ptr device); /** * @brief Fetch a device from the global store of dispatchable devices. @@ -81,8 +78,7 @@ class Device * * @return The layer device context. */ - static Device* retrieve( - VkDevice handle); + static Device* retrieve(VkDevice handle); /** * @brief Fetch a device from the global store of dispatchable devices. @@ -91,8 +87,7 @@ class Device * * @return The layer device context. */ - static Device* retrieve( - VkQueue handle); + static Device* retrieve(VkQueue handle); /** * @brief Fetch a device from the global store of dispatchable devices. @@ -101,16 +96,14 @@ class Device * * @return The layer device context. */ - static Device* retrieve( - VkCommandBuffer handle); + static Device* retrieve(VkCommandBuffer handle); /** * @brief Drop a device from the global store of dispatchable devices. * * @param device The device to drop. */ - static void destroy( - Device* device); + static void destroy(Device* device); /** * @brief Create a new layer device object. @@ -123,12 +116,11 @@ class Device * @param nlayerGetProcAddress The vkGetProcAddress function in the driver/next layer down. * @param createInfo The create info used to create the device. */ - Device( - Instance* instance, - VkPhysicalDevice physicalDevice, - VkDevice device, - PFN_vkGetDeviceProcAddr nlayerGetProcAddress, - const VkDeviceCreateInfo& createInfo); + Device(Instance* instance, + VkPhysicalDevice physicalDevice, + VkDevice device, + PFN_vkGetDeviceProcAddr nlayerGetProcAddress, + const VkDeviceCreateInfo& createInfo); /** * @brief Destroy this layer device object. diff --git a/layer_example/source/instance.cpp b/layer_example/source/instance.cpp index 8c1adb4..42db622 100644 --- a/layer_example/source/instance.cpp +++ b/layer_example/source/instance.cpp @@ -23,11 +23,11 @@ * ---------------------------------------------------------------------------- */ -#include +#include "instance.hpp" #include "framework/utils.hpp" -#include "instance.hpp" +#include /** * @brief The dispatch lookup for all of the created Vulkan instances. @@ -35,54 +35,44 @@ static std::unordered_map> g_instances; /* See header for documentation. */ -const APIVersion Instance::minAPIVersion { 1, 1 }; +const APIVersion Instance::minAPIVersion {1, 1}; /* See header for documentation. */ -const std::vector Instance::extraExtensions { - VK_EXT_DEBUG_UTILS_EXTENSION_NAME -}; +const std::vector Instance::extraExtensions {VK_EXT_DEBUG_UTILS_EXTENSION_NAME}; /* See header for documentation. */ -void Instance::store( - VkInstance handle, - std::unique_ptr& instance -) { +void Instance::store(VkInstance handle, std::unique_ptr& instance) +{ void* key = getDispatchKey(handle); - g_instances.insert({ key, std::move(instance) }); + g_instances.insert({key, std::move(instance)}); } /* See header for documentation. */ -Instance* Instance::retrieve( - VkInstance handle -) { +Instance* Instance::retrieve(VkInstance handle) +{ void* key = getDispatchKey(handle); assert(isInMap(key, g_instances)); return g_instances.at(key).get(); } /* See header for documentation. */ -Instance* Instance::retrieve( - VkPhysicalDevice handle -) { +Instance* Instance::retrieve(VkPhysicalDevice handle) +{ void* key = getDispatchKey(handle); assert(isInMap(key, g_instances)); return g_instances.at(key).get(); } /* See header for documentation. */ -void Instance::destroy( - Instance* instance -) { +void Instance::destroy(Instance* instance) +{ g_instances.erase(getDispatchKey(instance->instance)); } /* See header for documentation. */ -Instance::Instance( - VkInstance _instance, - PFN_vkGetInstanceProcAddr _nlayerGetProcAddress -) : - instance(_instance), - nlayerGetProcAddress(_nlayerGetProcAddress) +Instance::Instance(VkInstance _instance, PFN_vkGetInstanceProcAddr _nlayerGetProcAddress) + : instance(_instance), + nlayerGetProcAddress(_nlayerGetProcAddress) { initDriverInstanceDispatchTable(instance, nlayerGetProcAddress, driver); } diff --git a/layer_example/source/instance.hpp b/layer_example/source/instance.hpp index b6bdea1..f3ffc7a 100644 --- a/layer_example/source/instance.hpp +++ b/layer_example/source/instance.hpp @@ -54,14 +54,14 @@ #pragma once +#include "framework/instance_dispatch_table.hpp" + #include #include #include #include -#include "framework/instance_dispatch_table.hpp" - /** * @brief This class implements the layer state tracker for a single instance. */ @@ -74,9 +74,7 @@ class Instance * @param handle The dispatchable instance handle to use as an indirect key. * @param instance The @c Instance object to store. */ - static void store( - VkInstance handle, - std::unique_ptr& instance); + static void store(VkInstance handle, std::unique_ptr& instance); /** * @brief Fetch an instance from the global store of dispatchable instances. @@ -85,8 +83,7 @@ class Instance * * @return The layer instance context. */ - static Instance* retrieve( - VkInstance handle); + static Instance* retrieve(VkInstance handle); /** * @brief Fetch an instance from the global store of dispatchable instances. @@ -95,16 +92,14 @@ class Instance * * @return The layer instance context. */ - static Instance* retrieve( - VkPhysicalDevice handle); + static Instance* retrieve(VkPhysicalDevice handle); /** * @brief Drop an instance from the global store of dispatchable instances. * * @param instance The instance to drop. */ - static void destroy( - Instance* instance); + static void destroy(Instance* instance); /** * @brief Create a new layer instance object. @@ -112,9 +107,7 @@ class Instance * @param instance The instance handle this instance is created with. * @param nlayerGetProcAddress The vkGetProcAddress function in the driver/next layer down. */ - Instance( - VkInstance instance, - PFN_vkGetInstanceProcAddr nlayerGetProcAddress); + Instance(VkInstance instance, PFN_vkGetInstanceProcAddr nlayerGetProcAddress); public: /** diff --git a/layer_example/source/layer_device_functions.cpp b/layer_example/source/layer_device_functions.cpp index e097f0e..9073fb2 100644 --- a/layer_example/source/layer_device_functions.cpp +++ b/layer_example/source/layer_device_functions.cpp @@ -23,28 +23,27 @@ * ---------------------------------------------------------------------------- */ +#include "device.hpp" +#include "framework/device_dispatch_table.hpp" + #include #include #include -#include "device.hpp" -#include "layer_device_functions.hpp" - extern std::mutex g_vulkanLock; /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass( - VkCommandBuffer commandBuffer, - const VkRenderPassBeginInfo* pRenderPassBegin, - VkSubpassContents contents -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, + const VkRenderPassBeginInfo* pRenderPassBegin, + VkSubpassContents contents) +{ #if CONFIG_TRACE == 1 LAYER_LOG("API Trace: Layer: %s ", __func__); #endif // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver @@ -53,18 +52,17 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2( - VkCommandBuffer commandBuffer, - const VkRenderPassBeginInfo* pRenderPassBegin, - const VkSubpassBeginInfo* pSubpassBeginInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2(VkCommandBuffer commandBuffer, + const VkRenderPassBeginInfo* pRenderPassBegin, + const VkSubpassBeginInfo* pSubpassBeginInfo) +{ #if CONFIG_TRACE == 1 LAYER_LOG("API Trace: Layer: %s ", __func__); #endif // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver @@ -73,18 +71,17 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2KHR( - VkCommandBuffer commandBuffer, - const VkRenderPassBeginInfo* pRenderPassBegin, - const VkSubpassBeginInfo* pSubpassBeginInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, + const VkRenderPassBeginInfo* pRenderPassBegin, + const VkSubpassBeginInfo* pSubpassBeginInfo) +{ #if CONFIG_TRACE == 1 LAYER_LOG("API Trace: Layer: %s ", __func__); #endif // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver @@ -93,17 +90,16 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2KHR( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRendering( - VkCommandBuffer commandBuffer, - const VkRenderingInfo* pRenderingInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRendering(VkCommandBuffer commandBuffer, + const VkRenderingInfo* pRenderingInfo) +{ #if CONFIG_TRACE == 1 LAYER_LOG("API Trace: Layer: %s ", __func__); #endif // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver @@ -112,17 +108,16 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRendering( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderingKHR( - VkCommandBuffer commandBuffer, - const VkRenderingInfo* pRenderingInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderingKHR(VkCommandBuffer commandBuffer, + const VkRenderingInfo* pRenderingInfo) +{ #if CONFIG_TRACE == 1 LAYER_LOG("API Trace: Layer: %s ", __func__); #endif // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver diff --git a/layer_example/source/layer_device_functions.hpp b/layer_example/source/layer_device_functions.hpp index df321c2..e39b83b 100644 --- a/layer_example/source/layer_device_functions.hpp +++ b/layer_example/source/layer_device_functions.hpp @@ -23,37 +23,34 @@ * ---------------------------------------------------------------------------- */ -#include "framework/utils.hpp" +#pragma once + +#include /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass( - VkCommandBuffer commandBuffer, - const VkRenderPassBeginInfo* pRenderPassBegin, - VkSubpassContents contents); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, + const VkRenderPassBeginInfo* pRenderPassBegin, + VkSubpassContents contents); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2( - VkCommandBuffer commandBuffer, - const VkRenderPassBeginInfo* pRenderPassBegin, - const VkSubpassBeginInfo* pSubpassBeginInfo); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2(VkCommandBuffer commandBuffer, + const VkRenderPassBeginInfo* pRenderPassBegin, + const VkSubpassBeginInfo* pSubpassBeginInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2KHR( - VkCommandBuffer commandBuffer, - const VkRenderPassBeginInfo* pRenderPassBegin, - const VkSubpassBeginInfo* pSubpassBeginInfo); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, + const VkRenderPassBeginInfo* pRenderPassBegin, + const VkSubpassBeginInfo* pSubpassBeginInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRendering( - VkCommandBuffer commandBuffer, - const VkRenderingInfo* pRenderingInfo); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRendering(VkCommandBuffer commandBuffer, + const VkRenderingInfo* pRenderingInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderingKHR( - VkCommandBuffer commandBuffer, - const VkRenderingInfo* pRenderingInfo); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderingKHR(VkCommandBuffer commandBuffer, + const VkRenderingInfo* pRenderingInfo); diff --git a/layer_gpu_support/CMakeLists.txt b/layer_gpu_support/CMakeLists.txt index 7ec9c07..436065e 100644 --- a/layer_gpu_support/CMakeLists.txt +++ b/layer_gpu_support/CMakeLists.txt @@ -33,6 +33,7 @@ set(LGL_CONFIG_TRACE 0) set(LGL_CONFIG_LOG 1) include(../source_common/compiler_helper.cmake) +include(../cmake/clang-tools.cmake) # Build steps add_subdirectory(source) diff --git a/layer_gpu_support/source/CMakeLists.txt b/layer_gpu_support/source/CMakeLists.txt index 2c4b384..28fe048 100644 --- a/layer_gpu_support/source/CMakeLists.txt +++ b/layer_gpu_support/source/CMakeLists.txt @@ -79,3 +79,5 @@ if (CMAKE_BUILD_TYPE STREQUAL "Release") ARGS --strip-all -o ${VK_LAYER_STRIP} $ COMMENT "Stripped lib${VK_LAYER}.so to ${VK_LAYER_STRIP}") endif() + +add_clang_tools() \ No newline at end of file diff --git a/layer_gpu_support/source/device.cpp b/layer_gpu_support/source/device.cpp index 94bb521..663d86f 100644 --- a/layer_gpu_support/source/device.cpp +++ b/layer_gpu_support/source/device.cpp @@ -23,9 +23,9 @@ * ---------------------------------------------------------------------------- */ -#include "framework/utils.hpp" - #include "device.hpp" + +#include "framework/utils.hpp" #include "instance.hpp" /** @@ -36,63 +36,55 @@ static std::unordered_map> g_devices; /* See header for documentation. */ const std::vector Device::extraExtensions { VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME, - VK_EXT_IMAGE_COMPRESSION_CONTROL_EXTENSION_NAME + VK_EXT_IMAGE_COMPRESSION_CONTROL_EXTENSION_NAME, }; /* See header for documentation. */ -void Device::store( - VkDevice handle, - std::unique_ptr device -) { +void Device::store(VkDevice handle, std::unique_ptr device) +{ void* key = getDispatchKey(handle); - g_devices.insert({ key, std::move(device) }); + g_devices.insert({key, std::move(device)}); } /* See header for documentation. */ -Device* Device::retrieve( - VkDevice handle -) { +Device* Device::retrieve(VkDevice handle) +{ void* key = getDispatchKey(handle); assert(isInMap(key, g_devices)); return g_devices.at(key).get(); } /* See header for documentation. */ -Device* Device::retrieve( - VkQueue handle -) { +Device* Device::retrieve(VkQueue handle) +{ void* key = getDispatchKey(handle); assert(isInMap(key, g_devices)); return g_devices.at(key).get(); } /* See header for documentation. */ -Device* Device::retrieve( - VkCommandBuffer handle -) { +Device* Device::retrieve(VkCommandBuffer handle) +{ void* key = getDispatchKey(handle); assert(isInMap(key, g_devices)); return g_devices.at(key).get(); } /* See header for documentation. */ -void Device::destroy( - Device* device -) { +void Device::destroy(Device* device) +{ g_devices.erase(getDispatchKey(device)); } /* See header for documentation. */ -Device::Device( - Instance* _instance, - VkPhysicalDevice _physicalDevice, - VkDevice _device, - PFN_vkGetDeviceProcAddr nlayerGetProcAddress, - const VkDeviceCreateInfo& createInfo -): - instance(_instance), - physicalDevice(_physicalDevice), - device(_device) +Device::Device(Instance* _instance, + VkPhysicalDevice _physicalDevice, + VkDevice _device, + PFN_vkGetDeviceProcAddr nlayerGetProcAddress, + const VkDeviceCreateInfo& createInfo) + : instance(_instance), + physicalDevice(_physicalDevice), + device(_device) { UNUSED(createInfo); @@ -102,17 +94,16 @@ Device::Device( .sType = VK_STRUCTURE_TYPE_SEMAPHORE_TYPE_CREATE_INFO, .pNext = nullptr, .semaphoreType = VK_SEMAPHORE_TYPE_TIMELINE, - .initialValue = queueSerializationTimelineSemCount + .initialValue = queueSerializationTimelineSemCount, }; VkSemaphoreCreateInfo semCreateInfo { .sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, .pNext = &timelineCreateInfo, - .flags = 0 + .flags = 0, }; - auto result = driver.vkCreateSemaphore( - device, &semCreateInfo, nullptr, &queueSerializationTimelineSem); + auto result = driver.vkCreateSemaphore(device, &semCreateInfo, nullptr, &queueSerializationTimelineSem); if (result != VK_SUCCESS) { LAYER_ERR("Failed vkCreateSemaphore() for queue serialization"); diff --git a/layer_gpu_support/source/device.hpp b/layer_gpu_support/source/device.hpp index d95fae5..16799c2 100644 --- a/layer_gpu_support/source/device.hpp +++ b/layer_gpu_support/source/device.hpp @@ -52,12 +52,11 @@ #pragma once -#include - #include "framework/device_dispatch_table.hpp" - #include "instance.hpp" +#include + /** * @brief This class implements the layer state tracker for a single device. */ @@ -70,9 +69,7 @@ class Device * @param handle The dispatchable device handle to use as an indirect key. * @param device The @c Device object to store. */ - static void store( - VkDevice handle, - std::unique_ptr device); + static void store(VkDevice handle, std::unique_ptr device); /** * @brief Fetch a device from the global store of dispatchable devices. @@ -81,8 +78,7 @@ class Device * * @return The layer device context. */ - static Device* retrieve( - VkDevice handle); + static Device* retrieve(VkDevice handle); /** * @brief Fetch a device from the global store of dispatchable devices. @@ -91,8 +87,7 @@ class Device * * @return The layer device context. */ - static Device* retrieve( - VkQueue handle); + static Device* retrieve(VkQueue handle); /** * @brief Fetch a device from the global store of dispatchable devices. @@ -101,16 +96,14 @@ class Device * * @return The layer device context. */ - static Device* retrieve( - VkCommandBuffer handle); + static Device* retrieve(VkCommandBuffer handle); /** * @brief Drop a device from the global store of dispatchable devices. * * @param device The device to drop. */ - static void destroy( - Device* device); + static void destroy(Device* device); /** * @brief Create a new layer device object. @@ -123,12 +116,11 @@ class Device * @param nlayerGetProcAddress The vkGetProcAddress function in the driver/next layer down. * @param createInfo The create info used to create the device. */ - Device( - Instance* instance, - VkPhysicalDevice physicalDevice, - VkDevice device, - PFN_vkGetDeviceProcAddr nlayerGetProcAddress, - const VkDeviceCreateInfo& createInfo); + Device(Instance* instance, + VkPhysicalDevice physicalDevice, + VkDevice device, + PFN_vkGetDeviceProcAddr nlayerGetProcAddress, + const VkDeviceCreateInfo& createInfo); /** * @brief Destroy this layer device object. @@ -164,10 +156,10 @@ class Device /** * @brief The timeline sem use for queue serialization. */ - VkSemaphore queueSerializationTimelineSem { nullptr }; + VkSemaphore queueSerializationTimelineSem {nullptr}; /** * @brief The current timeline sem target value the next use waits for. */ - uint64_t queueSerializationTimelineSemCount { 0 }; + uint64_t queueSerializationTimelineSemCount {0}; }; diff --git a/layer_gpu_support/source/instance.cpp b/layer_gpu_support/source/instance.cpp index 8c1adb4..d567bbb 100644 --- a/layer_gpu_support/source/instance.cpp +++ b/layer_gpu_support/source/instance.cpp @@ -23,11 +23,11 @@ * ---------------------------------------------------------------------------- */ -#include +#include "instance.hpp" #include "framework/utils.hpp" -#include "instance.hpp" +#include /** * @brief The dispatch lookup for all of the created Vulkan instances. @@ -35,54 +35,46 @@ static std::unordered_map> g_instances; /* See header for documentation. */ -const APIVersion Instance::minAPIVersion { 1, 1 }; +const APIVersion Instance::minAPIVersion {1, 1}; /* See header for documentation. */ const std::vector Instance::extraExtensions { - VK_EXT_DEBUG_UTILS_EXTENSION_NAME + VK_EXT_DEBUG_UTILS_EXTENSION_NAME, }; /* See header for documentation. */ -void Instance::store( - VkInstance handle, - std::unique_ptr& instance -) { +void Instance::store(VkInstance handle, std::unique_ptr& instance) +{ void* key = getDispatchKey(handle); - g_instances.insert({ key, std::move(instance) }); + g_instances.insert({key, std::move(instance)}); } /* See header for documentation. */ -Instance* Instance::retrieve( - VkInstance handle -) { +Instance* Instance::retrieve(VkInstance handle) +{ void* key = getDispatchKey(handle); assert(isInMap(key, g_instances)); return g_instances.at(key).get(); } /* See header for documentation. */ -Instance* Instance::retrieve( - VkPhysicalDevice handle -) { +Instance* Instance::retrieve(VkPhysicalDevice handle) +{ void* key = getDispatchKey(handle); assert(isInMap(key, g_instances)); return g_instances.at(key).get(); } /* See header for documentation. */ -void Instance::destroy( - Instance* instance -) { +void Instance::destroy(Instance* instance) +{ g_instances.erase(getDispatchKey(instance->instance)); } /* See header for documentation. */ -Instance::Instance( - VkInstance _instance, - PFN_vkGetInstanceProcAddr _nlayerGetProcAddress -) : - instance(_instance), - nlayerGetProcAddress(_nlayerGetProcAddress) +Instance::Instance(VkInstance _instance, PFN_vkGetInstanceProcAddr _nlayerGetProcAddress) + : instance(_instance), + nlayerGetProcAddress(_nlayerGetProcAddress) { initDriverInstanceDispatchTable(instance, nlayerGetProcAddress, driver); } diff --git a/layer_gpu_support/source/instance.hpp b/layer_gpu_support/source/instance.hpp index 081b26d..b38f2bd 100644 --- a/layer_gpu_support/source/instance.hpp +++ b/layer_gpu_support/source/instance.hpp @@ -54,15 +54,14 @@ #pragma once +#include "framework/instance_dispatch_table.hpp" +#include "layer_config.hpp" + #include #include #include -#include "framework/instance_dispatch_table.hpp" - -#include "layer_config.hpp" - /** * @brief This class implements the layer state tracker for a single instance. */ @@ -75,9 +74,7 @@ class Instance * @param handle The dispatchable instance handle to use as an indirect key. * @param instance The @c Instance object to store. */ - static void store( - VkInstance handle, - std::unique_ptr& instance); + static void store(VkInstance handle, std::unique_ptr& instance); /** * @brief Fetch an instance from the global store of dispatchable instances. @@ -86,8 +83,7 @@ class Instance * * @return The layer instance context. */ - static Instance* retrieve( - VkInstance handle); + static Instance* retrieve(VkInstance handle); /** * @brief Fetch an instance from the global store of dispatchable instances. @@ -96,16 +92,14 @@ class Instance * * @return The layer instance context. */ - static Instance* retrieve( - VkPhysicalDevice handle); + static Instance* retrieve(VkPhysicalDevice handle); /** * @brief Drop an instance from the global store of dispatchable instances. * * @param instance The instance to drop. */ - static void destroy( - Instance* instance); + static void destroy(Instance* instance); /** * @brief Create a new layer instance object. @@ -113,9 +107,7 @@ class Instance * @param instance The instance handle this instance is created with. * @param nlayerGetProcAddress The vkGetProcAddress function in the driver/next layer down. */ - Instance( - VkInstance instance, - PFN_vkGetInstanceProcAddr nlayerGetProcAddress); + Instance(VkInstance instance, PFN_vkGetInstanceProcAddr nlayerGetProcAddress); public: /** diff --git a/layer_gpu_support/source/layer_config.cpp b/layer_gpu_support/source/layer_config.cpp index 7491d63..4df39dd 100644 --- a/layer_gpu_support/source/layer_config.cpp +++ b/layer_gpu_support/source/layer_config.cpp @@ -28,20 +28,18 @@ * Defines the a config file to parameterize the layer. */ -#include - -#include +#include "layer_config.hpp" #include "framework/utils.hpp" - -#include "layer_config.hpp" #include "version.hpp" +#include + +#include /* See header for documentation. */ -void LayerConfig::parse_serialization_options( - const json& config -) { +void LayerConfig::parse_serialization_options(const json& config) +{ // Decode serialization state json serialize = config.at("serialize"); @@ -90,9 +88,8 @@ void LayerConfig::parse_serialization_options( } /* See header for documentation. */ -void LayerConfig::parse_shader_options( - const json& config -) { +void LayerConfig::parse_shader_options(const json& config) +{ // Decode serialization state json shader = config.at("shader"); @@ -113,9 +110,8 @@ void LayerConfig::parse_shader_options( } /* See header for documentation. */ -void LayerConfig::parse_framebuffer_options( - const json& config -) { +void LayerConfig::parse_framebuffer_options(const json& config) +{ // Decode serialization state json framebuffer = config.at("framebuffer"); @@ -135,7 +131,7 @@ void LayerConfig::parse_framebuffer_options( } // Convert fixed_rate_compression into a bit mask - uint32_t fixed_rate_mask { 0 }; + uint32_t fixed_rate_mask {0}; if (force_fixed_rate_compression > 0) { if (force_fixed_rate_compression <= 1) @@ -202,7 +198,6 @@ LayerConfig::LayerConfig() std::string file_name(LGL_LAYER_CONFIG); #endif - LAYER_LOG("Trying to read config: %s", file_name.c_str()); std::ifstream stream(file_name); @@ -218,7 +213,7 @@ LayerConfig::LayerConfig() { data = json::parse(stream); } - catch(const json::parse_error& e) + catch (const json::parse_error& e) { LAYER_ERR("Failed to load layer config, using defaults"); LAYER_ERR("Error: %s", e.what()); @@ -229,7 +224,7 @@ LayerConfig::LayerConfig() { parse_serialization_options(data); } - catch(const json::out_of_range& e) + catch (const json::out_of_range& e) { LAYER_ERR("Failed to read serialization config, using defaults"); LAYER_ERR("Error: %s", e.what()); @@ -239,7 +234,7 @@ LayerConfig::LayerConfig() { parse_shader_options(data); } - catch(const json::out_of_range& e) + catch (const json::out_of_range& e) { LAYER_ERR("Failed to read shader config, using defaults"); LAYER_ERR("Error: %s", e.what()); @@ -249,7 +244,7 @@ LayerConfig::LayerConfig() { parse_framebuffer_options(data); } - catch(const json::out_of_range& e) + catch (const json::out_of_range& e) { LAYER_ERR("Failed to read framebuffer config, using defaults"); LAYER_ERR("Error: %s", e.what()); diff --git a/layer_gpu_support/source/layer_config.hpp b/layer_gpu_support/source/layer_config.hpp index d68a3bf..a065341 100644 --- a/layer_gpu_support/source/layer_config.hpp +++ b/layer_gpu_support/source/layer_config.hpp @@ -44,7 +44,7 @@ using json = nlohmann::json; class LayerConfig { public: - /** + /** * @brief Create a new layer config. */ LayerConfig(); @@ -138,7 +138,6 @@ class LayerConfig */ uint32_t framebuffer_force_fixed_rate_compression() const; - private: /** * @brief Parse the configuration options for the serializer. @@ -171,62 +170,62 @@ class LayerConfig /** * @brief True if we force serialize across queues. */ - bool conf_serialize_queues { false }; + bool conf_serialize_queues {false}; /** * @brief True if we force serialize before compute dispatches. */ - bool conf_serialize_dispatch_pre { false }; + bool conf_serialize_dispatch_pre {false}; /** * @brief True if we force serialize after compute dispatches. */ - bool conf_serialize_dispatch_post { false }; + bool conf_serialize_dispatch_post {false}; /** * @brief True if we force serialize before render pass workloads. */ - bool conf_serialize_render_pass_pre { false }; + bool conf_serialize_render_pass_pre {false}; /** * @brief True if we force serialize after render pass workloads. */ - bool conf_serialize_render_pass_post { false }; + bool conf_serialize_render_pass_post {false}; /** * @brief True if we force serialize before trace rays workloads. */ - bool conf_serialize_trace_rays_pre { false }; + bool conf_serialize_trace_rays_pre {false}; /** * @brief True if we force serialize after trace rays workloads. */ - bool conf_serialize_trace_rays_post { false }; + bool conf_serialize_trace_rays_post {false}; /** * @brief True if we force serialize before transfer workloads. */ - bool conf_serialize_transfer_pre { false }; + bool conf_serialize_transfer_pre {false}; /** * @brief True if we force serialize after transfer workloads. */ - bool conf_serialize_transfer_post { false }; + bool conf_serialize_transfer_post {false}; /** * @brief True if we force disable executable binary caching. */ - bool conf_shader_disable_program_cache { false }; + bool conf_shader_disable_program_cache {false}; /** * @brief True if we force remove use of relaxed precision decoration. */ - bool conf_shader_disable_relaxed_precision { false }; + bool conf_shader_disable_relaxed_precision {false}; /** * @brief True if we change SPIR-V to change the program hash. */ - bool conf_shader_enable_fuzz_spirv_hash { false }; + bool conf_shader_enable_fuzz_spirv_hash {false}; /** * @brief True if we disable all framebuffer compression. @@ -234,14 +233,14 @@ class LayerConfig * This has precedence over default compression and forcing fixed rate * compression. */ - bool conf_framebuffer_disable_compression { false }; + bool conf_framebuffer_disable_compression {false}; /** * @brief True if we for all compression to default framebuffer compression. * * This has precedence over forcing fixed rate compression. */ - bool conf_framebuffer_force_default_compression { false }; + bool conf_framebuffer_force_default_compression {false}; /** * @brief True if we force fixed rate compression. @@ -254,5 +253,5 @@ class LayerConfig * * If zero, then no force is set and default compression will be used. */ - uint32_t conf_framebuffer_force_fixed_rate_compression { 0 }; + uint32_t conf_framebuffer_force_fixed_rate_compression {0}; }; diff --git a/layer_gpu_support/source/layer_device_functions.hpp b/layer_gpu_support/source/layer_device_functions.hpp index 36c5aa5..a4ac236 100644 --- a/layer_gpu_support/source/layer_device_functions.hpp +++ b/layer_gpu_support/source/layer_device_functions.hpp @@ -27,337 +27,297 @@ #include -#include "framework/utils.hpp" - // Functions for render passes /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass( - VkCommandBuffer commandBuffer, - const VkRenderPassBeginInfo* pRenderPassBegin, - VkSubpassContents contents); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, + const VkRenderPassBeginInfo* pRenderPassBegin, + VkSubpassContents contents); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2( - VkCommandBuffer commandBuffer, - const VkRenderPassBeginInfo* pRenderPassBegin, - const VkSubpassBeginInfo* pSubpassBeginInfo); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2(VkCommandBuffer commandBuffer, + const VkRenderPassBeginInfo* pRenderPassBegin, + const VkSubpassBeginInfo* pSubpassBeginInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2KHR( - VkCommandBuffer commandBuffer, - const VkRenderPassBeginInfo* pRenderPassBegin, - const VkSubpassBeginInfo* pSubpassBeginInfo); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, + const VkRenderPassBeginInfo* pRenderPassBegin, + const VkSubpassBeginInfo* pSubpassBeginInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRendering( - VkCommandBuffer commandBuffer, - const VkRenderingInfo* pRenderingInfo); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRendering(VkCommandBuffer commandBuffer, + const VkRenderingInfo* pRenderingInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderingKHR( - VkCommandBuffer commandBuffer, - const VkRenderingInfo* pRenderingInfo); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderingKHR(VkCommandBuffer commandBuffer, + const VkRenderingInfo* pRenderingInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRenderPass( - VkCommandBuffer commandBuffer); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRenderPass(VkCommandBuffer commandBuffer); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRendering( - VkCommandBuffer commandBuffer); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRendering(VkCommandBuffer commandBuffer); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRenderingKHR( - VkCommandBuffer commandBuffer); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRenderingKHR(VkCommandBuffer commandBuffer); // Functions for compute dispatches /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatch( - VkCommandBuffer commandBuffer, - uint32_t groupCountX, - uint32_t groupCountY, - uint32_t groupCountZ); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatch(VkCommandBuffer commandBuffer, + uint32_t groupCountX, + uint32_t groupCountY, + uint32_t groupCountZ); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchBase( - VkCommandBuffer commandBuffer, - uint32_t baseGroupX, - uint32_t baseGroupY, - uint32_t baseGroupZ, - uint32_t groupCountX, - uint32_t groupCountY, - uint32_t groupCountZ); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchBase(VkCommandBuffer commandBuffer, + uint32_t baseGroupX, + uint32_t baseGroupY, + uint32_t baseGroupZ, + uint32_t groupCountX, + uint32_t groupCountY, + uint32_t groupCountZ); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchBaseKHR( - VkCommandBuffer commandBuffer, - uint32_t baseGroupX, - uint32_t baseGroupY, - uint32_t baseGroupZ, - uint32_t groupCountX, - uint32_t groupCountY, - uint32_t groupCountZ); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, + uint32_t baseGroupX, + uint32_t baseGroupY, + uint32_t baseGroupZ, + uint32_t groupCountX, + uint32_t groupCountY, + uint32_t groupCountZ); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchIndirect( - VkCommandBuffer commandBuffer, - VkBuffer buffer, - VkDeviceSize offset); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset); // Commands for trace rays /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysIndirect2KHR( - VkCommandBuffer commandBuffer, - VkDeviceAddress indirectDeviceAddress); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysIndirect2KHR(VkCommandBuffer commandBuffer, + VkDeviceAddress indirectDeviceAddress); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysIndirectKHR( - VkCommandBuffer commandBuffer, - const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable, - VkDeviceAddress indirectDeviceAddress); +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer, + const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable, + VkDeviceAddress indirectDeviceAddress); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysKHR( - VkCommandBuffer commandBuffer, - const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable, - uint32_t width, - uint32_t height, - uint32_t depth); - +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdTraceRaysKHR(VkCommandBuffer commandBuffer, + const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable, + uint32_t width, + uint32_t height, + uint32_t depth); // Commands for transfers /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdFillBuffer( - VkCommandBuffer commandBuffer, - VkBuffer dstBuffer, - VkDeviceSize dstOffset, - VkDeviceSize size, - uint32_t data); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdFillBuffer(VkCommandBuffer commandBuffer, + VkBuffer dstBuffer, + VkDeviceSize dstOffset, + VkDeviceSize size, + uint32_t data); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdClearColorImage( - VkCommandBuffer commandBuffer, - VkImage image, - VkImageLayout imageLayout, - const VkClearColorValue* pColor, - uint32_t rangeCount, - const VkImageSubresourceRange* pRanges); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdClearColorImage(VkCommandBuffer commandBuffer, + VkImage image, + VkImageLayout imageLayout, + const VkClearColorValue* pColor, + uint32_t rangeCount, + const VkImageSubresourceRange* pRanges); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdClearDepthStencilImage( - VkCommandBuffer commandBuffer, - VkImage image, - VkImageLayout imageLayout, - const VkClearDepthStencilValue* pDepthStencil, - uint32_t rangeCount, - const VkImageSubresourceRange* pRanges); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, + VkImage image, + VkImageLayout imageLayout, + const VkClearDepthStencilValue* pDepthStencil, + uint32_t rangeCount, + const VkImageSubresourceRange* pRanges); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer( - VkCommandBuffer commandBuffer, - VkBuffer srcBuffer, - VkBuffer dstBuffer, - uint32_t regionCount, - const VkBufferCopy* pRegions); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer(VkCommandBuffer commandBuffer, + VkBuffer srcBuffer, + VkBuffer dstBuffer, + uint32_t regionCount, + const VkBufferCopy* pRegions); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2( - VkCommandBuffer commandBuffer, - const VkCopyBufferInfo2* pCopyBufferInfo); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2(VkCommandBuffer commandBuffer, + const VkCopyBufferInfo2* pCopyBufferInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2KHR( - VkCommandBuffer commandBuffer, - const VkCopyBufferInfo2* pCopyBufferInfo); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, + const VkCopyBufferInfo2* pCopyBufferInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage( - VkCommandBuffer commandBuffer, - VkBuffer srcBuffer, - VkImage dstImage, - VkImageLayout dstImageLayout, - uint32_t regionCount, - const VkBufferImageCopy* pRegions); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer, + VkBuffer srcBuffer, + VkImage dstImage, + VkImageLayout dstImageLayout, + uint32_t regionCount, + const VkBufferImageCopy* pRegions); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage2( - VkCommandBuffer commandBuffer, - const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo); +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdCopyBufferToImage2(VkCommandBuffer commandBuffer, + const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage2KHR( - VkCommandBuffer commandBuffer, - const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo); +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, + const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage( - VkCommandBuffer commandBuffer, - VkImage srcImage, - VkImageLayout srcImageLayout, - VkImage dstImage, - VkImageLayout dstImageLayout, - uint32_t regionCount, - const VkImageCopy* pRegions); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage(VkCommandBuffer commandBuffer, + VkImage srcImage, + VkImageLayout srcImageLayout, + VkImage dstImage, + VkImageLayout dstImageLayout, + uint32_t regionCount, + const VkImageCopy* pRegions); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2( - VkCommandBuffer commandBuffer, - const VkCopyImageInfo2* pCopyImageInfo); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2(VkCommandBuffer commandBuffer, + const VkCopyImageInfo2* pCopyImageInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2KHR( - VkCommandBuffer commandBuffer, - const VkCopyImageInfo2* pCopyImageInfo); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2KHR(VkCommandBuffer commandBuffer, + const VkCopyImageInfo2* pCopyImageInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer( - VkCommandBuffer commandBuffer, - VkImage srcImage, - VkImageLayout srcImageLayout, - VkBuffer dstBuffer, - uint32_t regionCount, - const VkBufferImageCopy* pRegions); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, + VkImage srcImage, + VkImageLayout srcImageLayout, + VkBuffer dstBuffer, + uint32_t regionCount, + const VkBufferImageCopy* pRegions); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer2( - VkCommandBuffer commandBuffer, - const VkCopyImageToBufferInfo2* pCopyImageToBufferInfo); +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer, + const VkCopyImageToBufferInfo2* pCopyImageToBufferInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer2KHR( - VkCommandBuffer commandBuffer, - const VkCopyImageToBufferInfo2* pCopyImageToBufferInfo); +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, + const VkCopyImageToBufferInfo2* pCopyImageToBufferInfo); // Functions for queues /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit( - VkQueue queue, - uint32_t submitCount, - const VkSubmitInfo* pSubmits, - VkFence fence); +VKAPI_ATTR VkResult VKAPI_CALL + layer_vkQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence); /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit2( - VkQueue queue, - uint32_t submitCount, - const VkSubmitInfo2* pSubmits, - VkFence fence); +VKAPI_ATTR VkResult VKAPI_CALL + layer_vkQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2* pSubmits, VkFence fence); /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit2KHR( - VkQueue queue, - uint32_t submitCount, - const VkSubmitInfo2* pSubmits, - VkFence fence); +VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit2KHR(VkQueue queue, + uint32_t submitCount, + const VkSubmitInfo2* pSubmits, + VkFence fence); // Functions for pipelines /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateShaderModule( - VkDevice device, - const VkShaderModuleCreateInfo* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkShaderModule* pShaderModule); +VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateShaderModule(VkDevice device, + const VkShaderModuleCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkShaderModule* pShaderModule); /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateShadersEXT( - VkDevice device, - uint32_t createInfoCount, - const VkShaderCreateInfoEXT* pCreateInfos, - const VkAllocationCallbacks* pAllocator, - VkShaderEXT* pShaders); - +VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateShadersEXT(VkDevice device, + uint32_t createInfoCount, + const VkShaderCreateInfoEXT* pCreateInfos, + const VkAllocationCallbacks* pAllocator, + VkShaderEXT* pShaders); /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkGetPipelineKeyKHR( - VkDevice device, - const VkPipelineCreateInfoKHR* pPipelineCreateInfo, - VkPipelineBinaryKeyKHR* pPipelineKey); +VKAPI_ATTR VkResult VKAPI_CALL layer_vkGetPipelineKeyKHR(VkDevice device, + const VkPipelineCreateInfoKHR* pPipelineCreateInfo, + VkPipelineBinaryKeyKHR* pPipelineKey); /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateComputePipelines( - VkDevice device, - VkPipelineCache pipelineCache, - uint32_t createInfoCount, - const VkComputePipelineCreateInfo* pCreateInfos, - const VkAllocationCallbacks* pAllocator, - VkPipeline* pPipelines); +VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateComputePipelines(VkDevice device, + VkPipelineCache pipelineCache, + uint32_t createInfoCount, + const VkComputePipelineCreateInfo* pCreateInfos, + const VkAllocationCallbacks* pAllocator, + VkPipeline* pPipelines); /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateGraphicsPipelines( - VkDevice device, - VkPipelineCache pipelineCache, - uint32_t createInfoCount, - const VkGraphicsPipelineCreateInfo* pCreateInfos, - const VkAllocationCallbacks* pAllocator, - VkPipeline* pPipelines); +VKAPI_ATTR VkResult VKAPI_CALL + layer_vkCreateGraphicsPipelines(VkDevice device, + VkPipelineCache pipelineCache, + uint32_t createInfoCount, + const VkGraphicsPipelineCreateInfo* pCreateInfos, + const VkAllocationCallbacks* pAllocator, + VkPipeline* pPipelines); /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateRayTracingPipelinesKHR( - VkDevice device, - VkDeferredOperationKHR deferredOperation, - VkPipelineCache pipelineCache, - uint32_t createInfoCount, - const VkRayTracingPipelineCreateInfoKHR* pCreateInfos, - const VkAllocationCallbacks* pAllocator, - VkPipeline* pPipelines); +VKAPI_ATTR VkResult VKAPI_CALL + layer_vkCreateRayTracingPipelinesKHR(VkDevice device, + VkDeferredOperationKHR deferredOperation, + VkPipelineCache pipelineCache, + uint32_t createInfoCount, + const VkRayTracingPipelineCreateInfoKHR* pCreateInfos, + const VkAllocationCallbacks* pAllocator, + VkPipeline* pPipelines); // Functions for images /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateImage( - VkDevice device, - const VkImageCreateInfo* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkImage* pImage); +template<> +VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateImage(VkDevice device, + const VkImageCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkImage* pImage); diff --git a/layer_gpu_support/source/layer_device_functions_dispatch.cpp b/layer_gpu_support/source/layer_device_functions_dispatch.cpp index 4f3d393..9b9a3bc 100644 --- a/layer_gpu_support/source/layer_device_functions_dispatch.cpp +++ b/layer_gpu_support/source/layer_device_functions_dispatch.cpp @@ -23,10 +23,10 @@ * ---------------------------------------------------------------------------- */ -#include - #include "device.hpp" -#include "layer_device_functions.hpp" +#include "framework/device_dispatch_table.hpp" + +#include extern std::mutex g_vulkanLock; @@ -36,24 +36,24 @@ extern std::mutex g_vulkanLock; * @param layer The layer context for the device. * @param commandBuffer The command buffer we are recording. */ -static void preDispatch( - Device* layer, - VkCommandBuffer commandBuffer -) { +static void preDispatch(Device* layer, VkCommandBuffer commandBuffer) +{ if (!layer->instance->config.serialize_cmdstream_compute_dispatch_pre()) { return; } // Execution dependency - layer->driver.vkCmdPipelineBarrier( - commandBuffer, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - 0, - 0, nullptr, - 0, nullptr, - 0, nullptr); + layer->driver.vkCmdPipelineBarrier(commandBuffer, + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + 0, + 0, + nullptr, + 0, + nullptr, + 0, + nullptr); } /** @@ -62,38 +62,37 @@ static void preDispatch( * @param layer The layer context for the device. * @param commandBuffer The command buffer we are recording. */ -static void postDispatch( - Device* layer, - VkCommandBuffer commandBuffer -) { +static void postDispatch(Device* layer, VkCommandBuffer commandBuffer) +{ if (!layer->instance->config.serialize_cmdstream_compute_dispatch_post()) { return; } // Execution dependency - layer->driver.vkCmdPipelineBarrier( - commandBuffer, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - 0, - 0, nullptr, - 0, nullptr, - 0, nullptr); + layer->driver.vkCmdPipelineBarrier(commandBuffer, + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + 0, + 0, + nullptr, + 0, + nullptr, + 0, + nullptr); } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatch( - VkCommandBuffer commandBuffer, - uint32_t groupCountX, - uint32_t groupCountY, - uint32_t groupCountZ -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatch(VkCommandBuffer commandBuffer, + uint32_t groupCountX, + uint32_t groupCountY, + uint32_t groupCountZ) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver @@ -105,66 +104,65 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatch( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchBase( - VkCommandBuffer commandBuffer, - uint32_t baseGroupX, - uint32_t baseGroupY, - uint32_t baseGroupZ, - uint32_t groupCountX, - uint32_t groupCountY, - uint32_t groupCountZ -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchBase(VkCommandBuffer commandBuffer, + uint32_t baseGroupX, + uint32_t baseGroupY, + uint32_t baseGroupZ, + uint32_t groupCountX, + uint32_t groupCountY, + uint32_t groupCountZ) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver lock.unlock(); preDispatch(layer, commandBuffer); - layer->driver.vkCmdDispatchBase(commandBuffer, baseGroupX, baseGroupY, baseGroupZ, groupCountX, groupCountY, groupCountZ); + layer->driver + .vkCmdDispatchBase(commandBuffer, baseGroupX, baseGroupY, baseGroupZ, groupCountX, groupCountY, groupCountZ); postDispatch(layer, commandBuffer); } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchBaseKHR( - VkCommandBuffer commandBuffer, - uint32_t baseGroupX, - uint32_t baseGroupY, - uint32_t baseGroupZ, - uint32_t groupCountX, - uint32_t groupCountY, - uint32_t groupCountZ -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, + uint32_t baseGroupX, + uint32_t baseGroupY, + uint32_t baseGroupZ, + uint32_t groupCountX, + uint32_t groupCountY, + uint32_t groupCountZ) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver lock.unlock(); preDispatch(layer, commandBuffer); - layer->driver.vkCmdDispatchBaseKHR(commandBuffer, baseGroupX, baseGroupY, baseGroupZ, groupCountX, groupCountY, groupCountZ); + layer->driver + .vkCmdDispatchBaseKHR(commandBuffer, baseGroupX, baseGroupY, baseGroupZ, groupCountX, groupCountY, groupCountZ); postDispatch(layer, commandBuffer); } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchIndirect( - VkCommandBuffer commandBuffer, - VkBuffer buffer, - VkDeviceSize offset -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver diff --git a/layer_gpu_support/source/layer_device_functions_image.cpp b/layer_gpu_support/source/layer_device_functions_image.cpp index 59d0553..f29851c 100644 --- a/layer_gpu_support/source/layer_device_functions_image.cpp +++ b/layer_gpu_support/source/layer_device_functions_image.cpp @@ -23,12 +23,12 @@ * ---------------------------------------------------------------------------- */ +#include "device.hpp" +#include "framework/device_dispatch_table.hpp" + #include #include -#include "device.hpp" -#include "layer_device_functions.hpp" - extern std::mutex g_vulkanLock; /** @@ -39,62 +39,59 @@ extern std::mutex g_vulkanLock; * * @return Bitmask of supported VkImageCompressionFixedRateFlagBitsEXT bits. */ -static VkImageCompressionFixedRateFlagsEXT getSupportedCompressionLevels( - Device* layer, - const VkImageCreateInfo* pCreateInfo -) { +static VkImageCompressionFixedRateFlagsEXT getSupportedCompressionLevels(Device* layer, + const VkImageCreateInfo* pCreateInfo) +{ VkImageCompressionControlEXT compressionInfo { .sType = VK_STRUCTURE_TYPE_IMAGE_COMPRESSION_CONTROL_EXT, .pNext = nullptr, .flags = VK_IMAGE_COMPRESSION_FIXED_RATE_DEFAULT_EXT, .compressionControlPlaneCount = 0, - .pFixedRateFlags = 0 + .pFixedRateFlags = 0, }; VkImageCompressionPropertiesEXT compressionProperties { .sType = VK_STRUCTURE_TYPE_IMAGE_COMPRESSION_PROPERTIES_EXT, .pNext = nullptr, .imageCompressionFlags = 0, - .imageCompressionFixedRateFlags = 0 + .imageCompressionFixedRateFlags = 0, }; VkPhysicalDeviceImageFormatInfo2 formatInfo { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2, .pNext = reinterpret_cast(&compressionInfo), .format = pCreateInfo->format, - .type = pCreateInfo->imageType, + .type = pCreateInfo->imageType, .tiling = pCreateInfo->tiling, - .usage = pCreateInfo->usage, - .flags = pCreateInfo->flags + .usage = pCreateInfo->usage, + .flags = pCreateInfo->flags, }; VkImageFormatProperties2 formatProperties { .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2, - .pNext = reinterpret_cast(&compressionProperties), - .imageFormatProperties = {} + .pNext = reinterpret_cast(&compressionProperties), + .imageFormatProperties = {}, }; auto instance = layer->instance; auto physicalDevice = layer->physicalDevice; - instance->driver.vkGetPhysicalDeviceImageFormatProperties2( - physicalDevice, &formatInfo, &formatProperties); + instance->driver.vkGetPhysicalDeviceImageFormatProperties2(physicalDevice, &formatInfo, &formatProperties); return compressionProperties.imageCompressionFixedRateFlags; } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateImage( - VkDevice device, - const VkImageCreateInfo* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkImage* pImage -) { +template<> +VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateImage(VkDevice device, + const VkImageCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkImage* pImage) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(device); const auto& config = layer->instance->config; @@ -127,9 +124,9 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateImage( VkImageCompressionControlEXT newCompressionControl; // TODO: This currently relies on const_cast to make user struct writable // We should replace this with a generic clone (issue #56) - auto* userCompressionControl = searchNextList( - VK_STRUCTURE_TYPE_IMAGE_COMPRESSION_CONTROL_EXT, - pCreateInfo->pNext); + auto* userCompressionControl = + searchNextList(VK_STRUCTURE_TYPE_IMAGE_COMPRESSION_CONTROL_EXT, + pCreateInfo->pNext); VkImageCompressionControlEXT* compressionControl = &newCompressionControl; if (userCompressionControl) @@ -174,4 +171,3 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateImage( return layer->driver.vkCreateImage(device, &newCreateInfo, pAllocator, pImage); } - diff --git a/layer_gpu_support/source/layer_device_functions_pipelines.cpp b/layer_gpu_support/source/layer_device_functions_pipelines.cpp index 6001dd3..86fd806 100644 --- a/layer_gpu_support/source/layer_device_functions_pipelines.cpp +++ b/layer_gpu_support/source/layer_device_functions_pipelines.cpp @@ -23,20 +23,20 @@ * ---------------------------------------------------------------------------- */ +#include "device.hpp" +#include "framework/device_dispatch_table.hpp" + #include #include -#include "device.hpp" -#include "layer_device_functions.hpp" - extern std::mutex g_vulkanLock; // Opcode IDs for interesting SPIR-V opcodes -static const uint32_t SPIRV_OPCODE_OPDECORATE { 71 }; -static const uint32_t SPIRV_OPCODE_OPMEMBERDECORATE { 72 }; -static const uint32_t SPIRV_OPCODE_OPDECORATEID { 332 }; -static const uint32_t SPIRV_OPCODE_OPDECORATESTRING { 5632 }; -static const uint32_t SPIRV_OPCODE_OPMEMBERDECORATESTRING { 5633 }; +static const uint32_t SPIRV_OPCODE_OPDECORATE {71}; +static const uint32_t SPIRV_OPCODE_OPMEMBERDECORATE {72}; +static const uint32_t SPIRV_OPCODE_OPDECORATEID {332}; +static const uint32_t SPIRV_OPCODE_OPDECORATESTRING {5632}; +static const uint32_t SPIRV_OPCODE_OPMEMBERDECORATESTRING {5633}; // Map of decorate opcodes and the word offset of the decoration ID static const std::map SPIRV_DECORATE_OPCODES { @@ -44,11 +44,11 @@ static const std::map SPIRV_DECORATE_OPCODES { {SPIRV_OPCODE_OPMEMBERDECORATE, 3}, {SPIRV_OPCODE_OPDECORATEID, 2}, {SPIRV_OPCODE_OPDECORATESTRING, 2}, - {SPIRV_OPCODE_OPMEMBERDECORATESTRING, 3} + {SPIRV_OPCODE_OPMEMBERDECORATESTRING, 3}, }; // Decoration IDs for interesting SPIR-V decorations -static const uint32_t SPIRV_DECORATE_RELAXED_PRECISION { 0 }; +static const uint32_t SPIRV_DECORATE_RELAXED_PRECISION {0}; /** * @brief Modify a SPIR-V module to remove all use of relaxed precision. @@ -57,26 +57,24 @@ static const uint32_t SPIRV_DECORATE_RELAXED_PRECISION { 0 }; * * @return The modified binary. */ -static std::vector remove_relaxed_precision( - const std::vector& originalCode -) { +static std::vector remove_relaxed_precision(const std::vector& originalCode) +{ // This module assumes the input SPIR-V is valid std::vector code; // Process SPIR-V header - for (size_t i = 0 ; i < 5; i++) + for (size_t i = 0; i < 5; i++) { - code.push_back(originalCode[i]); - + code.push_back(originalCode[i]); } // Process SPIR-V opcode payload - for (size_t i = 5 ; i < originalCode.size(); /* Increment in loop. */) + for (size_t i = 5; i < originalCode.size(); /* Increment in loop. */) { uint32_t opWord0 = originalCode[i]; - uint32_t opCode { opWord0 & 0xFFFF }; - uint32_t opWordCount { opWord0 >> 16 }; + uint32_t opCode {opWord0 & 0xFFFF}; + uint32_t opWordCount {opWord0 >> 16}; // This should never happen, but avoids infinite loop on bad input if (opWordCount == 0) @@ -85,7 +83,7 @@ static std::vector remove_relaxed_precision( break; } - bool keep { true }; + bool keep {true}; if (isInMap(opCode, SPIRV_DECORATE_OPCODES)) { size_t offset = SPIRV_DECORATE_OPCODES.at(opCode); @@ -118,9 +116,8 @@ static std::vector remove_relaxed_precision( * * @return The modified binary. */ -static std::vector fuzz_spirv( - const std::vector& originalCode -) { +static std::vector fuzz_spirv(const std::vector& originalCode) +{ // This module assumes the input SPIR-V is valid std::vector code = originalCode; @@ -133,16 +130,15 @@ static std::vector fuzz_spirv( /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateShaderModule( - VkDevice device, - const VkShaderModuleCreateInfo* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkShaderModule* pShaderModule -) { +VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateShaderModule(VkDevice device, + const VkShaderModuleCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkShaderModule* pShaderModule) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(device); // Release the lock to call into the driver @@ -171,17 +167,16 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateShaderModule( /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateShadersEXT( - VkDevice device, - uint32_t createInfoCount, - const VkShaderCreateInfoEXT* pCreateInfos, - const VkAllocationCallbacks* pAllocator, - VkShaderEXT* pShaders -) { +VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateShadersEXT(VkDevice device, + uint32_t createInfoCount, + const VkShaderCreateInfoEXT* pCreateInfos, + const VkAllocationCallbacks* pAllocator, + VkShaderEXT* pShaders) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(device); // Create copies we can modify @@ -264,21 +259,19 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateShadersEXT( /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkGetPipelineKeyKHR( - VkDevice device, - const VkPipelineCreateInfoKHR* pPipelineCreateInfo, - VkPipelineBinaryKeyKHR* pPipelineKey -) { +VKAPI_ATTR VkResult VKAPI_CALL layer_vkGetPipelineKeyKHR(VkDevice device, + const VkPipelineCreateInfoKHR* pPipelineCreateInfo, + VkPipelineBinaryKeyKHR* pPipelineKey) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(device); // If caching is disabled then return a scrambled global key if (layer->instance->config.shader_disable_cache() && !pPipelineCreateInfo) { - for (size_t i = 0; i < VK_MAX_PIPELINE_BINARY_KEY_SIZE_KHR; i++) { pPipelineKey->key[i] = static_cast(i); @@ -295,18 +288,17 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkGetPipelineKeyKHR( /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateComputePipelines( - VkDevice device, - VkPipelineCache pipelineCache, - uint32_t createInfoCount, - const VkComputePipelineCreateInfo* pCreateInfos, - const VkAllocationCallbacks* pAllocator, - VkPipeline* pPipelines -) { +VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateComputePipelines(VkDevice device, + VkPipelineCache pipelineCache, + uint32_t createInfoCount, + const VkComputePipelineCreateInfo* pCreateInfos, + const VkAllocationCallbacks* pAllocator, + VkPipeline* pPipelines) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(device); if (layer->instance->config.shader_disable_cache()) @@ -316,23 +308,24 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateComputePipelines( // Release the lock to call into the driver lock.unlock(); - return layer->driver.vkCreateComputePipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines); + return layer->driver + .vkCreateComputePipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines); } /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateGraphicsPipelines( - VkDevice device, - VkPipelineCache pipelineCache, - uint32_t createInfoCount, - const VkGraphicsPipelineCreateInfo* pCreateInfos, - const VkAllocationCallbacks* pAllocator, - VkPipeline* pPipelines -) { +VKAPI_ATTR VkResult VKAPI_CALL + layer_vkCreateGraphicsPipelines(VkDevice device, + VkPipelineCache pipelineCache, + uint32_t createInfoCount, + const VkGraphicsPipelineCreateInfo* pCreateInfos, + const VkAllocationCallbacks* pAllocator, + VkPipeline* pPipelines) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(device); if (layer->instance->config.shader_disable_cache()) @@ -342,24 +335,25 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateGraphicsPipelines( // Release the lock to call into the driver lock.unlock(); - return layer->driver.vkCreateGraphicsPipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines); + return layer->driver + .vkCreateGraphicsPipelines(device, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines); } /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateRayTracingPipelinesKHR( - VkDevice device, - VkDeferredOperationKHR deferredOperation, - VkPipelineCache pipelineCache, - uint32_t createInfoCount, - const VkRayTracingPipelineCreateInfoKHR* pCreateInfos, - const VkAllocationCallbacks* pAllocator, - VkPipeline* pPipelines -) { +VKAPI_ATTR VkResult VKAPI_CALL + layer_vkCreateRayTracingPipelinesKHR(VkDevice device, + VkDeferredOperationKHR deferredOperation, + VkPipelineCache pipelineCache, + uint32_t createInfoCount, + const VkRayTracingPipelineCreateInfoKHR* pCreateInfos, + const VkAllocationCallbacks* pAllocator, + VkPipeline* pPipelines) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(device); if (layer->instance->config.shader_disable_cache()) @@ -369,5 +363,11 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateRayTracingPipelinesKHR( // Release the lock to call into the driver lock.unlock(); - return layer->driver.vkCreateRayTracingPipelinesKHR(device, deferredOperation, pipelineCache, createInfoCount, pCreateInfos, pAllocator, pPipelines); + return layer->driver.vkCreateRayTracingPipelinesKHR(device, + deferredOperation, + pipelineCache, + createInfoCount, + pCreateInfos, + pAllocator, + pPipelines); } diff --git a/layer_gpu_support/source/layer_device_functions_queue.cpp b/layer_gpu_support/source/layer_device_functions_queue.cpp index 2a99868..f8b9618 100644 --- a/layer_gpu_support/source/layer_device_functions_queue.cpp +++ b/layer_gpu_support/source/layer_device_functions_queue.cpp @@ -23,25 +23,22 @@ * ---------------------------------------------------------------------------- */ -#include - #include "device.hpp" -#include "layer_device_functions.hpp" +#include "framework/device_dispatch_table.hpp" + +#include extern std::mutex g_vulkanLock; /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit( - VkQueue queue, - uint32_t submitCount, - const VkSubmitInfo* pSubmits, - VkFence fence -) { +VKAPI_ATTR VkResult VKAPI_CALL + layer_vkQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(queue); // Serialize in the order submits are called @@ -60,7 +57,7 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit( .waitSemaphoreValueCount = 1, .pWaitSemaphoreValues = &waitValue, .signalSemaphoreValueCount = 1, - .pSignalSemaphoreValues = &signalValue + .pSignalSemaphoreValues = &signalValue, }; VkSubmitInfo submitInfoPre { @@ -72,7 +69,7 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit( .commandBufferCount = 0, .pCommandBuffers = 0, .signalSemaphoreCount = 0, - .pSignalSemaphores = nullptr + .pSignalSemaphores = nullptr, }; VkSubmitInfo submitInfoPost { @@ -84,7 +81,7 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit( .commandBufferCount = 0, .pCommandBuffers = 0, .signalSemaphoreCount = 1, - .pSignalSemaphores = &(layer->queueSerializationTimelineSem) + .pSignalSemaphores = &(layer->queueSerializationTimelineSem), }; // Release the lock to call into the driver @@ -107,16 +104,13 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit( /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit2( - VkQueue queue, - uint32_t submitCount, - const VkSubmitInfo2* pSubmits, - VkFence fence -) { +VKAPI_ATTR VkResult VKAPI_CALL + layer_vkQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2* pSubmits, VkFence fence) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(queue); // Serialize in the order submits are called @@ -133,7 +127,7 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit2( .semaphore = layer->queueSerializationTimelineSem, .value = waitValue, .stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - .deviceIndex = 0 + .deviceIndex = 0, }; VkSemaphoreSubmitInfo timelineInfoPost { @@ -142,7 +136,7 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit2( .semaphore = layer->queueSerializationTimelineSem, .value = signalValue, .stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - .deviceIndex = 0 + .deviceIndex = 0, }; VkSubmitInfo2 submitInfoPre { @@ -154,7 +148,7 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit2( .commandBufferInfoCount = 0, .pCommandBufferInfos = nullptr, .signalSemaphoreInfoCount = 0, - .pSignalSemaphoreInfos = nullptr + .pSignalSemaphoreInfos = nullptr, }; VkSubmitInfo2 submitInfoPost { @@ -166,7 +160,7 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit2( .commandBufferInfoCount = 0, .pCommandBufferInfos = nullptr, .signalSemaphoreInfoCount = 1, - .pSignalSemaphoreInfos = &timelineInfoPost + .pSignalSemaphoreInfos = &timelineInfoPost, }; // Release the lock to call into the driver @@ -185,21 +179,17 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit2( } return result; - } /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit2KHR( - VkQueue queue, - uint32_t submitCount, - const VkSubmitInfo2* pSubmits, - VkFence fence -) { +VKAPI_ATTR VkResult VKAPI_CALL + layer_vkQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2* pSubmits, VkFence fence) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(queue); // Serialize in the order submits are called @@ -216,7 +206,7 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit2KHR( .semaphore = layer->queueSerializationTimelineSem, .value = waitValue, .stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - .deviceIndex = 0 + .deviceIndex = 0, }; VkSemaphoreSubmitInfo timelineInfoPost { @@ -225,7 +215,7 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit2KHR( .semaphore = layer->queueSerializationTimelineSem, .value = signalValue, .stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - .deviceIndex = 0 + .deviceIndex = 0, }; VkSubmitInfo2 submitInfoPre { @@ -237,7 +227,7 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit2KHR( .commandBufferInfoCount = 0, .pCommandBufferInfos = nullptr, .signalSemaphoreInfoCount = 0, - .pSignalSemaphoreInfos = nullptr + .pSignalSemaphoreInfos = nullptr, }; VkSubmitInfo2 submitInfoPost { @@ -249,7 +239,7 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit2KHR( .commandBufferInfoCount = 0, .pCommandBufferInfos = nullptr, .signalSemaphoreInfoCount = 1, - .pSignalSemaphoreInfos = &timelineInfoPost + .pSignalSemaphoreInfos = &timelineInfoPost, }; // Release the lock to call into the driver diff --git a/layer_gpu_support/source/layer_device_functions_render_pass.cpp b/layer_gpu_support/source/layer_device_functions_render_pass.cpp index 80ec85e..03a2bf1 100644 --- a/layer_gpu_support/source/layer_device_functions_render_pass.cpp +++ b/layer_gpu_support/source/layer_device_functions_render_pass.cpp @@ -23,10 +23,10 @@ * ---------------------------------------------------------------------------- */ -#include - #include "device.hpp" -#include "layer_device_functions.hpp" +#include "framework/device_dispatch_table.hpp" + +#include extern std::mutex g_vulkanLock; @@ -42,24 +42,24 @@ static std::unordered_map dynamic_suspend_state; * @param layer The layer context for the device. * @param commandBuffer The command buffer we are recording. */ -static void preRenderPass( - Device* layer, - VkCommandBuffer commandBuffer -) { +static void preRenderPass(Device* layer, VkCommandBuffer commandBuffer) +{ if (!layer->instance->config.serialize_cmdstream_render_pass_pre()) { return; } // Execution dependency - layer->driver.vkCmdPipelineBarrier( - commandBuffer, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - 0, - 0, nullptr, - 0, nullptr, - 0, nullptr); + layer->driver.vkCmdPipelineBarrier(commandBuffer, + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + 0, + 0, + nullptr, + 0, + nullptr, + 0, + nullptr); } /** @@ -68,37 +68,36 @@ static void preRenderPass( * @param layer The layer context for the device. * @param commandBuffer The command buffer we are recording. */ -static void postRenderPass( - Device* layer, - VkCommandBuffer commandBuffer -) { +static void postRenderPass(Device* layer, VkCommandBuffer commandBuffer) +{ if (!layer->instance->config.serialize_cmdstream_render_pass_post()) { return; } // Execution dependency - layer->driver.vkCmdPipelineBarrier( - commandBuffer, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - 0, - 0, nullptr, - 0, nullptr, - 0, nullptr); + layer->driver.vkCmdPipelineBarrier(commandBuffer, + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + 0, + 0, + nullptr, + 0, + nullptr, + 0, + nullptr); } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass( - VkCommandBuffer commandBuffer, - const VkRenderPassBeginInfo* pRenderPassBegin, - VkSubpassContents contents -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, + const VkRenderPassBeginInfo* pRenderPassBegin, + VkSubpassContents contents) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver @@ -109,16 +108,15 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2( - VkCommandBuffer commandBuffer, - const VkRenderPassBeginInfo* pRenderPassBegin, - const VkSubpassBeginInfo* pSubpassBeginInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2(VkCommandBuffer commandBuffer, + const VkRenderPassBeginInfo* pRenderPassBegin, + const VkSubpassBeginInfo* pSubpassBeginInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver @@ -129,16 +127,15 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2KHR( - VkCommandBuffer commandBuffer, - const VkRenderPassBeginInfo* pRenderPassBegin, - const VkSubpassBeginInfo* pSubpassBeginInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, + const VkRenderPassBeginInfo* pRenderPassBegin, + const VkSubpassBeginInfo* pSubpassBeginInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver @@ -149,15 +146,14 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2KHR( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRendering( - VkCommandBuffer commandBuffer, - const VkRenderingInfo* pRenderingInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRendering(VkCommandBuffer commandBuffer, + const VkRenderingInfo* pRenderingInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); bool resuming = pRenderingInfo->flags & VK_RENDERING_RESUMING_BIT; @@ -176,15 +172,14 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRendering( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderingKHR( - VkCommandBuffer commandBuffer, - const VkRenderingInfo* pRenderingInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderingKHR(VkCommandBuffer commandBuffer, + const VkRenderingInfo* pRenderingInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); bool resuming = pRenderingInfo->flags & VK_RENDERING_RESUMING_BIT_KHR; @@ -203,14 +198,13 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderingKHR( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRenderPass( - VkCommandBuffer commandBuffer -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRenderPass(VkCommandBuffer commandBuffer) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver @@ -221,14 +215,13 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRenderPass( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRendering( - VkCommandBuffer commandBuffer -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRendering(VkCommandBuffer commandBuffer) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Retrieve the begin rendering suspend state @@ -248,14 +241,13 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRendering( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRenderingKHR( - VkCommandBuffer commandBuffer -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRenderingKHR(VkCommandBuffer commandBuffer) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Retrieve the begin rendering suspend state diff --git a/layer_gpu_support/source/layer_device_functions_trace_rays.cpp b/layer_gpu_support/source/layer_device_functions_trace_rays.cpp index e841a1a..ef76d2d 100644 --- a/layer_gpu_support/source/layer_device_functions_trace_rays.cpp +++ b/layer_gpu_support/source/layer_device_functions_trace_rays.cpp @@ -23,10 +23,10 @@ * ---------------------------------------------------------------------------- */ -#include - #include "device.hpp" -#include "layer_device_functions.hpp" +#include "framework/device_dispatch_table.hpp" + +#include extern std::mutex g_vulkanLock; @@ -36,24 +36,24 @@ extern std::mutex g_vulkanLock; * @param layer The layer context for the device. * @param commandBuffer The command buffer we are recording. */ -static void preTraceRays( - Device* layer, - VkCommandBuffer commandBuffer -) { +static void preTraceRays(Device* layer, VkCommandBuffer commandBuffer) +{ if (!layer->instance->config.serialize_cmdstream_trace_rays_pre()) { return; } // Execution dependency - layer->driver.vkCmdPipelineBarrier( - commandBuffer, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - 0, - 0, nullptr, - 0, nullptr, - 0, nullptr); + layer->driver.vkCmdPipelineBarrier(commandBuffer, + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + 0, + 0, + nullptr, + 0, + nullptr, + 0, + nullptr); } /** @@ -62,36 +62,35 @@ static void preTraceRays( * @param layer The layer context for the device. * @param commandBuffer The command buffer we are recording. */ -static void postTraceRays( - Device* layer, - VkCommandBuffer commandBuffer -) { +static void postTraceRays(Device* layer, VkCommandBuffer commandBuffer) +{ if (!layer->instance->config.serialize_cmdstream_trace_rays_post()) { return; } // Execution dependency - layer->driver.vkCmdPipelineBarrier( - commandBuffer, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - 0, - 0, nullptr, - 0, nullptr, - 0, nullptr); + layer->driver.vkCmdPipelineBarrier(commandBuffer, + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + 0, + 0, + nullptr, + 0, + nullptr, + 0, + nullptr); } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysIndirect2KHR( - VkCommandBuffer commandBuffer, - VkDeviceAddress indirectDeviceAddress -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysIndirect2KHR(VkCommandBuffer commandBuffer, + VkDeviceAddress indirectDeviceAddress) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver @@ -103,51 +102,63 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysIndirect2KHR( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysIndirectKHR( - VkCommandBuffer commandBuffer, - const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable, - VkDeviceAddress indirectDeviceAddress -) { +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer, + const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable, + VkDeviceAddress indirectDeviceAddress) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver lock.unlock(); preTraceRays(layer, commandBuffer); - layer->driver.vkCmdTraceRaysIndirectKHR(commandBuffer, pRaygenShaderBindingTable, pMissShaderBindingTable, pHitShaderBindingTable, pCallableShaderBindingTable, indirectDeviceAddress); + layer->driver.vkCmdTraceRaysIndirectKHR(commandBuffer, + pRaygenShaderBindingTable, + pMissShaderBindingTable, + pHitShaderBindingTable, + pCallableShaderBindingTable, + indirectDeviceAddress); postTraceRays(layer, commandBuffer); } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysKHR( - VkCommandBuffer commandBuffer, - const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable, - uint32_t width, - uint32_t height, - uint32_t depth -) { +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdTraceRaysKHR(VkCommandBuffer commandBuffer, + const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable, + uint32_t width, + uint32_t height, + uint32_t depth) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver lock.unlock(); preTraceRays(layer, commandBuffer); - layer->driver.vkCmdTraceRaysKHR(commandBuffer, pRaygenShaderBindingTable, pMissShaderBindingTable, pHitShaderBindingTable, pCallableShaderBindingTable, width, height, depth); + layer->driver.vkCmdTraceRaysKHR(commandBuffer, + pRaygenShaderBindingTable, + pMissShaderBindingTable, + pHitShaderBindingTable, + pCallableShaderBindingTable, + width, + height, + depth); postTraceRays(layer, commandBuffer); -} \ No newline at end of file +} diff --git a/layer_gpu_support/source/layer_device_functions_transfer.cpp b/layer_gpu_support/source/layer_device_functions_transfer.cpp index 94373f2..d442e96 100644 --- a/layer_gpu_support/source/layer_device_functions_transfer.cpp +++ b/layer_gpu_support/source/layer_device_functions_transfer.cpp @@ -23,10 +23,10 @@ * ---------------------------------------------------------------------------- */ -#include - #include "device.hpp" -#include "layer_device_functions.hpp" +#include "framework/device_dispatch_table.hpp" + +#include extern std::mutex g_vulkanLock; @@ -36,24 +36,24 @@ extern std::mutex g_vulkanLock; * @param layer The layer context for the device. * @param commandBuffer The command buffer we are recording. */ -static void preTransfer( - Device* layer, - VkCommandBuffer commandBuffer -) { +static void preTransfer(Device* layer, VkCommandBuffer commandBuffer) +{ if (!layer->instance->config.serialize_cmdstream_transfer_pre()) { return; } // Execution dependency - layer->driver.vkCmdPipelineBarrier( - commandBuffer, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - 0, - 0, nullptr, - 0, nullptr, - 0, nullptr); + layer->driver.vkCmdPipelineBarrier(commandBuffer, + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + 0, + 0, + nullptr, + 0, + nullptr, + 0, + nullptr); } /** @@ -62,41 +62,40 @@ static void preTransfer( * @param layer The layer context for the device. * @param commandBuffer The command buffer we are recording. */ -static void postTransfer( - Device* layer, - VkCommandBuffer commandBuffer -) { +static void postTransfer(Device* layer, VkCommandBuffer commandBuffer) +{ if (!layer->instance->config.serialize_cmdstream_transfer_post()) { return; } // Execution dependency - layer->driver.vkCmdPipelineBarrier( - commandBuffer, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - 0, - 0, nullptr, - 0, nullptr, - 0, nullptr); + layer->driver.vkCmdPipelineBarrier(commandBuffer, + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + 0, + 0, + nullptr, + 0, + nullptr, + 0, + nullptr); } // Commands for transfers /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdFillBuffer( - VkCommandBuffer commandBuffer, - VkBuffer dstBuffer, - VkDeviceSize dstOffset, - VkDeviceSize size, - uint32_t data -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdFillBuffer(VkCommandBuffer commandBuffer, + VkBuffer dstBuffer, + VkDeviceSize dstOffset, + VkDeviceSize size, + uint32_t data) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver @@ -108,19 +107,18 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdFillBuffer( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdClearColorImage( - VkCommandBuffer commandBuffer, - VkImage image, - VkImageLayout imageLayout, - const VkClearColorValue* pColor, - uint32_t rangeCount, - const VkImageSubresourceRange* pRanges -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdClearColorImage(VkCommandBuffer commandBuffer, + VkImage image, + VkImageLayout imageLayout, + const VkClearColorValue* pColor, + uint32_t rangeCount, + const VkImageSubresourceRange* pRanges) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver @@ -132,19 +130,18 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdClearColorImage( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdClearDepthStencilImage( - VkCommandBuffer commandBuffer, - VkImage image, - VkImageLayout imageLayout, - const VkClearDepthStencilValue* pDepthStencil, - uint32_t rangeCount, - const VkImageSubresourceRange* pRanges -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, + VkImage image, + VkImageLayout imageLayout, + const VkClearDepthStencilValue* pDepthStencil, + uint32_t rangeCount, + const VkImageSubresourceRange* pRanges) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver @@ -156,18 +153,17 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdClearDepthStencilImage( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer( - VkCommandBuffer commandBuffer, - VkBuffer srcBuffer, - VkBuffer dstBuffer, - uint32_t regionCount, - const VkBufferCopy* pRegions -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer(VkCommandBuffer commandBuffer, + VkBuffer srcBuffer, + VkBuffer dstBuffer, + uint32_t regionCount, + const VkBufferCopy* pRegions) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver @@ -179,15 +175,14 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2( - VkCommandBuffer commandBuffer, - const VkCopyBufferInfo2* pCopyBufferInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2(VkCommandBuffer commandBuffer, + const VkCopyBufferInfo2* pCopyBufferInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver @@ -199,15 +194,14 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2KHR( - VkCommandBuffer commandBuffer, - const VkCopyBufferInfo2* pCopyBufferInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, + const VkCopyBufferInfo2* pCopyBufferInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver @@ -219,19 +213,18 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2KHR( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage( - VkCommandBuffer commandBuffer, - VkBuffer srcBuffer, - VkImage dstImage, - VkImageLayout dstImageLayout, - uint32_t regionCount, - const VkBufferImageCopy* pRegions -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer, + VkBuffer srcBuffer, + VkImage dstImage, + VkImageLayout dstImageLayout, + uint32_t regionCount, + const VkBufferImageCopy* pRegions) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver @@ -243,15 +236,15 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage2( - VkCommandBuffer commandBuffer, - const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdCopyBufferToImage2(VkCommandBuffer commandBuffer, + const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver @@ -263,15 +256,15 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage2( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage2KHR( - VkCommandBuffer commandBuffer, - const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, + const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver @@ -283,40 +276,39 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage2KHR( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage( - VkCommandBuffer commandBuffer, - VkImage srcImage, - VkImageLayout srcImageLayout, - VkImage dstImage, - VkImageLayout dstImageLayout, - uint32_t regionCount, - const VkImageCopy* pRegions -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage(VkCommandBuffer commandBuffer, + VkImage srcImage, + VkImageLayout srcImageLayout, + VkImage dstImage, + VkImageLayout dstImageLayout, + uint32_t regionCount, + const VkImageCopy* pRegions) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver lock.unlock(); preTransfer(layer, commandBuffer); - layer->driver.vkCmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions); + layer->driver + .vkCmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions); postTransfer(layer, commandBuffer); } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2( - VkCommandBuffer commandBuffer, - const VkCopyImageInfo2* pCopyImageInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2(VkCommandBuffer commandBuffer, + const VkCopyImageInfo2* pCopyImageInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver @@ -328,15 +320,14 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2KHR( - VkCommandBuffer commandBuffer, - const VkCopyImageInfo2* pCopyImageInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2KHR(VkCommandBuffer commandBuffer, + const VkCopyImageInfo2* pCopyImageInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver @@ -348,19 +339,18 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2KHR( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer( - VkCommandBuffer commandBuffer, - VkImage srcImage, - VkImageLayout srcImageLayout, - VkBuffer dstBuffer, - uint32_t regionCount, - const VkBufferImageCopy* pRegions -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, + VkImage srcImage, + VkImageLayout srcImageLayout, + VkBuffer dstBuffer, + uint32_t regionCount, + const VkBufferImageCopy* pRegions) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver @@ -372,15 +362,15 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer2( - VkCommandBuffer commandBuffer, - const VkCopyImageToBufferInfo2* pCopyImageToBufferInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer, + const VkCopyImageToBufferInfo2* pCopyImageToBufferInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver @@ -392,15 +382,15 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer2( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer2KHR( - VkCommandBuffer commandBuffer, - const VkCopyImageToBufferInfo2* pCopyImageToBufferInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, + const VkCopyImageToBufferInfo2* pCopyImageToBufferInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Release the lock to call into the driver diff --git a/layer_gpu_timeline/CMakeLists.txt b/layer_gpu_timeline/CMakeLists.txt index f3d8cd2..eef8fef 100644 --- a/layer_gpu_timeline/CMakeLists.txt +++ b/layer_gpu_timeline/CMakeLists.txt @@ -33,6 +33,7 @@ set(LGL_CONFIG_TRACE 0) set(LGL_CONFIG_LOG 1) include(../source_common/compiler_helper.cmake) +include(../cmake/clang-tools.cmake) # Build steps add_subdirectory(../source_common/comms source_common/comms) diff --git a/layer_gpu_timeline/source/CMakeLists.txt b/layer_gpu_timeline/source/CMakeLists.txt index 2b52fe8..4c302e7 100644 --- a/layer_gpu_timeline/source/CMakeLists.txt +++ b/layer_gpu_timeline/source/CMakeLists.txt @@ -83,3 +83,5 @@ if (CMAKE_BUILD_TYPE STREQUAL "Release") ARGS --strip-all -o ${VK_LAYER_STRIP} $ COMMENT "Stripped lib${VK_LAYER}.so to ${VK_LAYER_STRIP}") endif() + +add_clang_tools() \ No newline at end of file diff --git a/layer_gpu_timeline/source/device.cpp b/layer_gpu_timeline/source/device.cpp index 92ff9a6..e721ca5 100644 --- a/layer_gpu_timeline/source/device.cpp +++ b/layer_gpu_timeline/source/device.cpp @@ -23,19 +23,20 @@ * ---------------------------------------------------------------------------- */ +#include "device.hpp" + +#include "comms/comms_module.hpp" +#include "framework/utils.hpp" +#include "instance.hpp" + #include -#include #include +#include +#include + #include #include #include -#include - -#include "comms/comms_module.hpp" -#include "framework/utils.hpp" - -#include "device.hpp" -#include "instance.hpp" using json = nlohmann::json; @@ -45,7 +46,7 @@ using json = nlohmann::json; static std::unordered_map> g_devices; /* See header for documentation. */ -const std::vector Device::extraExtensions { }; +const std::vector Device::extraExtensions {}; /* See header for documentation. */ std::unique_ptr Device::commsModule; @@ -54,59 +55,51 @@ std::unique_ptr Device::commsModule; std::unique_ptr Device::commsWrapper; /* See header for documentation. */ -void Device::store( - VkDevice handle, - std::unique_ptr device -) { +void Device::store(VkDevice handle, std::unique_ptr device) +{ void* key = getDispatchKey(handle); - g_devices.insert({ key, std::move(device) }); + g_devices.insert({key, std::move(device)}); } /* See header for documentation. */ -Device* Device::retrieve( - VkDevice handle -) { +Device* Device::retrieve(VkDevice handle) +{ void* key = getDispatchKey(handle); assert(isInMap(key, g_devices)); return g_devices.at(key).get(); } /* See header for documentation. */ -Device* Device::retrieve( - VkQueue handle -) { +Device* Device::retrieve(VkQueue handle) +{ void* key = getDispatchKey(handle); assert(isInMap(key, g_devices)); return g_devices.at(key).get(); } /* See header for documentation. */ -Device* Device::retrieve( - VkCommandBuffer handle -) { +Device* Device::retrieve(VkCommandBuffer handle) +{ void* key = getDispatchKey(handle); assert(isInMap(key, g_devices)); return g_devices.at(key).get(); } /* See header for documentation. */ -void Device::destroy( - Device* device -) { +void Device::destroy(Device* device) +{ g_devices.erase(getDispatchKey(device)); } /* See header for documentation. */ -Device::Device( - Instance* _instance, - VkPhysicalDevice _physicalDevice, - VkDevice _device, - PFN_vkGetDeviceProcAddr nlayerGetProcAddress, - const VkDeviceCreateInfo& createInfo -): - instance(_instance), - physicalDevice(_physicalDevice), - device(_device) +Device::Device(Instance* _instance, + VkPhysicalDevice _physicalDevice, + VkDevice _device, + PFN_vkGetDeviceProcAddr nlayerGetProcAddress, + const VkDeviceCreateInfo& createInfo) + : instance(_instance), + physicalDevice(_physicalDevice), + device(_device) { UNUSED(createInfo); @@ -123,7 +116,7 @@ Device::Device( VkPhysicalDeviceProperties deviceProperties; instance->driver.vkGetPhysicalDeviceProperties(physicalDevice, &deviceProperties); - std::string name { deviceProperties.deviceName }; + std::string name {deviceProperties.deviceName}; uint32_t driverVersion = deviceProperties.driverVersion; uint32_t major = VK_VERSION_MAJOR(driverVersion); @@ -133,13 +126,13 @@ Device::Device( pid_t processPID = getpid(); json deviceMetadata { - { "type", "device" }, - { "pid", static_cast(processPID) }, - { "device", reinterpret_cast(device) }, - { "deviceName", name }, - { "driverMajor", major }, - { "driverMinor", minor }, - { "driverPatch", patch } + {"type", "device"}, + {"pid", static_cast(processPID)}, + {"device", reinterpret_cast(device)}, + {"deviceName", name}, + {"driverMajor", major}, + {"driverMinor", minor}, + {"driverPatch", patch}, }; commsWrapper->txMessage(deviceMetadata.dump()); diff --git a/layer_gpu_timeline/source/device.hpp b/layer_gpu_timeline/source/device.hpp index 38b2680..9253db0 100644 --- a/layer_gpu_timeline/source/device.hpp +++ b/layer_gpu_timeline/source/device.hpp @@ -52,14 +52,13 @@ #pragma once -#include - #include "comms/comms_module.hpp" #include "framework/device_dispatch_table.hpp" -#include "trackers/device.hpp" - #include "instance.hpp" #include "timeline_comms.hpp" +#include "trackers/device.hpp" + +#include /** * @brief This class implements the layer state tracker for a single device. @@ -73,9 +72,7 @@ class Device * @param handle The dispatchable device handle to use as an indirect key. * @param device The @c Device object to store. */ - static void store( - VkDevice handle, - std::unique_ptr device); + static void store(VkDevice handle, std::unique_ptr device); /** * @brief Fetch a device from the global store of dispatchable devices. @@ -84,8 +81,7 @@ class Device * * @return The layer device context. */ - static Device* retrieve( - VkDevice handle); + static Device* retrieve(VkDevice handle); /** * @brief Fetch a device from the global store of dispatchable devices. @@ -94,8 +90,7 @@ class Device * * @return The layer device context. */ - static Device* retrieve( - VkQueue handle); + static Device* retrieve(VkQueue handle); /** * @brief Fetch a device from the global store of dispatchable devices. @@ -104,16 +99,14 @@ class Device * * @return The layer device context. */ - static Device* retrieve( - VkCommandBuffer handle); + static Device* retrieve(VkCommandBuffer handle); /** * @brief Drop a device from the global store of dispatchable devices. * * @param device The device to drop. */ - static void destroy( - Device* device); + static void destroy(Device* device); /** * @brief Create a new layer device object. @@ -126,12 +119,11 @@ class Device * @param nlayerGetProcAddress The vkGetDeviceProcAddress function for the driver. * @param createInfo The create info used to create the device. */ - Device( - Instance* instance, - VkPhysicalDevice physicalDevice, - VkDevice device, - PFN_vkGetDeviceProcAddr nlayerGetProcAddress, - const VkDeviceCreateInfo& createInfo); + Device(Instance* instance, + VkPhysicalDevice physicalDevice, + VkDevice device, + PFN_vkGetDeviceProcAddr nlayerGetProcAddress, + const VkDeviceCreateInfo& createInfo); /** * @brief Destroy this layer device object. @@ -143,30 +135,19 @@ class Device * * @param message The message to send. */ - void onFrame( - const std::string& message - ) { - commsWrapper->txMessage(message); - } + void onFrame(const std::string& message) { commsWrapper->txMessage(message); } /** * @brief Callback for sending messages on workload submit to a queue. * * @param message The message to send. */ - void onWorkloadSubmit( - const std::string& message - ) { - commsWrapper->txMessage(message); - } + void onWorkloadSubmit(const std::string& message) { commsWrapper->txMessage(message); } /** * @brief Get the cumulative stats for this device. */ - Tracker::Device& getStateTracker() - { - return stateTracker; - } + Tracker::Device& getStateTracker() { return stateTracker; } public: /** diff --git a/layer_gpu_timeline/source/device_utils.hpp b/layer_gpu_timeline/source/device_utils.hpp index eddf193..6456355 100644 --- a/layer_gpu_timeline/source/device_utils.hpp +++ b/layer_gpu_timeline/source/device_utils.hpp @@ -25,11 +25,10 @@ #pragma once -#include - +#include "device.hpp" #include "framework/utils.hpp" -#include "device.hpp" +#include /** * @brief Emit a start tag via a driver debug utils label. @@ -38,18 +37,15 @@ * @param commandBuffer The command buffer we are recording. * @param tagID The tagID to emit into the label. */ -[[maybe_unused]] static void emitStartTag( - Device* layer, - VkCommandBuffer commandBuffer, - uint64_t tagID -) { +[[maybe_unused]] static void emitStartTag(Device* layer, VkCommandBuffer commandBuffer, uint64_t tagID) +{ // Emit the unique workload tag into the command stream std::string tagLabel = formatString("t%" PRIu64, tagID); VkDebugUtilsLabelEXT tagInfo { .sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT, .pNext = nullptr, .pLabelName = tagLabel.c_str(), - .color = { 0.0f, 0.0f, 0.0f, 0.0f } + .color = {0.0f, 0.0f, 0.0f, 0.0f}, }; layer->driver.vkCmdBeginDebugUtilsLabelEXT(commandBuffer, &tagInfo); diff --git a/layer_gpu_timeline/source/instance.cpp b/layer_gpu_timeline/source/instance.cpp index 8c1adb4..d567bbb 100644 --- a/layer_gpu_timeline/source/instance.cpp +++ b/layer_gpu_timeline/source/instance.cpp @@ -23,11 +23,11 @@ * ---------------------------------------------------------------------------- */ -#include +#include "instance.hpp" #include "framework/utils.hpp" -#include "instance.hpp" +#include /** * @brief The dispatch lookup for all of the created Vulkan instances. @@ -35,54 +35,46 @@ static std::unordered_map> g_instances; /* See header for documentation. */ -const APIVersion Instance::minAPIVersion { 1, 1 }; +const APIVersion Instance::minAPIVersion {1, 1}; /* See header for documentation. */ const std::vector Instance::extraExtensions { - VK_EXT_DEBUG_UTILS_EXTENSION_NAME + VK_EXT_DEBUG_UTILS_EXTENSION_NAME, }; /* See header for documentation. */ -void Instance::store( - VkInstance handle, - std::unique_ptr& instance -) { +void Instance::store(VkInstance handle, std::unique_ptr& instance) +{ void* key = getDispatchKey(handle); - g_instances.insert({ key, std::move(instance) }); + g_instances.insert({key, std::move(instance)}); } /* See header for documentation. */ -Instance* Instance::retrieve( - VkInstance handle -) { +Instance* Instance::retrieve(VkInstance handle) +{ void* key = getDispatchKey(handle); assert(isInMap(key, g_instances)); return g_instances.at(key).get(); } /* See header for documentation. */ -Instance* Instance::retrieve( - VkPhysicalDevice handle -) { +Instance* Instance::retrieve(VkPhysicalDevice handle) +{ void* key = getDispatchKey(handle); assert(isInMap(key, g_instances)); return g_instances.at(key).get(); } /* See header for documentation. */ -void Instance::destroy( - Instance* instance -) { +void Instance::destroy(Instance* instance) +{ g_instances.erase(getDispatchKey(instance->instance)); } /* See header for documentation. */ -Instance::Instance( - VkInstance _instance, - PFN_vkGetInstanceProcAddr _nlayerGetProcAddress -) : - instance(_instance), - nlayerGetProcAddress(_nlayerGetProcAddress) +Instance::Instance(VkInstance _instance, PFN_vkGetInstanceProcAddr _nlayerGetProcAddress) + : instance(_instance), + nlayerGetProcAddress(_nlayerGetProcAddress) { initDriverInstanceDispatchTable(instance, nlayerGetProcAddress, driver); } diff --git a/layer_gpu_timeline/source/instance.hpp b/layer_gpu_timeline/source/instance.hpp index b6bdea1..f3ffc7a 100644 --- a/layer_gpu_timeline/source/instance.hpp +++ b/layer_gpu_timeline/source/instance.hpp @@ -54,14 +54,14 @@ #pragma once +#include "framework/instance_dispatch_table.hpp" + #include #include #include #include -#include "framework/instance_dispatch_table.hpp" - /** * @brief This class implements the layer state tracker for a single instance. */ @@ -74,9 +74,7 @@ class Instance * @param handle The dispatchable instance handle to use as an indirect key. * @param instance The @c Instance object to store. */ - static void store( - VkInstance handle, - std::unique_ptr& instance); + static void store(VkInstance handle, std::unique_ptr& instance); /** * @brief Fetch an instance from the global store of dispatchable instances. @@ -85,8 +83,7 @@ class Instance * * @return The layer instance context. */ - static Instance* retrieve( - VkInstance handle); + static Instance* retrieve(VkInstance handle); /** * @brief Fetch an instance from the global store of dispatchable instances. @@ -95,16 +92,14 @@ class Instance * * @return The layer instance context. */ - static Instance* retrieve( - VkPhysicalDevice handle); + static Instance* retrieve(VkPhysicalDevice handle); /** * @brief Drop an instance from the global store of dispatchable instances. * * @param instance The instance to drop. */ - static void destroy( - Instance* instance); + static void destroy(Instance* instance); /** * @brief Create a new layer instance object. @@ -112,9 +107,7 @@ class Instance * @param instance The instance handle this instance is created with. * @param nlayerGetProcAddress The vkGetProcAddress function in the driver/next layer down. */ - Instance( - VkInstance instance, - PFN_vkGetInstanceProcAddr nlayerGetProcAddress); + Instance(VkInstance instance, PFN_vkGetInstanceProcAddr nlayerGetProcAddress); public: /** diff --git a/layer_gpu_timeline/source/layer_device_functions.hpp b/layer_gpu_timeline/source/layer_device_functions.hpp index 8c2f8b5..2fc8460 100644 --- a/layer_gpu_timeline/source/layer_device_functions.hpp +++ b/layer_gpu_timeline/source/layer_device_functions.hpp @@ -27,484 +27,424 @@ #include -#include "framework/utils.hpp" - // Functions for command pools /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateCommandPool( - VkDevice device, - const VkCommandPoolCreateInfo* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkCommandPool* pCommandPool); +template<> +VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateCommandPool(VkDevice device, + const VkCommandPoolCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkCommandPool* pCommandPool); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkResetCommandPool( - VkDevice device, - VkCommandPool commandPool, - VkCommandPoolResetFlags flags); +template<> +VKAPI_ATTR VkResult VKAPI_CALL layer_vkResetCommandPool(VkDevice device, + VkCommandPool commandPool, + VkCommandPoolResetFlags flags); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkDestroyCommandPool( - VkDevice device, - VkCommandPool commandPool, - const VkAllocationCallbacks* pAllocator); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkDestroyCommandPool(VkDevice device, + VkCommandPool commandPool, + const VkAllocationCallbacks* pAllocator); // Functions for command buffers /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkAllocateCommandBuffers( - VkDevice device, - const VkCommandBufferAllocateInfo* pAllocateInfo, - VkCommandBuffer* pCommandBuffers); +template<> +VKAPI_ATTR VkResult VKAPI_CALL + layer_vkAllocateCommandBuffers(VkDevice device, + const VkCommandBufferAllocateInfo* pAllocateInfo, + VkCommandBuffer* pCommandBuffers); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR VkResult layer_vkBeginCommandBuffer( - VkCommandBuffer commandBuffer, - const VkCommandBufferBeginInfo* pBeginInfo); +template<> +VKAPI_ATTR VkResult layer_vkBeginCommandBuffer(VkCommandBuffer commandBuffer, + const VkCommandBufferBeginInfo* pBeginInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdExecuteCommands( - VkCommandBuffer commandBuffer, - uint32_t commandBufferCount, - const VkCommandBuffer* pCommandBuffers); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdExecuteCommands(VkCommandBuffer commandBuffer, + uint32_t commandBufferCount, + const VkCommandBuffer* pCommandBuffers); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkResetCommandBuffer( - VkCommandBuffer commandBuffer, - VkCommandBufferResetFlags flags); +template<> +VKAPI_ATTR VkResult VKAPI_CALL layer_vkResetCommandBuffer(VkCommandBuffer commandBuffer, + VkCommandBufferResetFlags flags); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkFreeCommandBuffers( - VkDevice device, - VkCommandPool commandPool, - uint32_t commandBufferCount, - const VkCommandBuffer* pCommandBuffers); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkFreeCommandBuffers(VkDevice device, + VkCommandPool commandPool, + uint32_t commandBufferCount, + const VkCommandBuffer* pCommandBuffers); // Functions for render passes /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateRenderPass( - VkDevice device, - const VkRenderPassCreateInfo* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkRenderPass* pRenderPass); +template<> +VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateRenderPass(VkDevice device, + const VkRenderPassCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkRenderPass* pRenderPass); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateRenderPass2( - VkDevice device, - const VkRenderPassCreateInfo2* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkRenderPass* pRenderPass); +template<> +VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateRenderPass2(VkDevice device, + const VkRenderPassCreateInfo2* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkRenderPass* pRenderPass); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateRenderPass2KHR( - VkDevice device, - const VkRenderPassCreateInfo2* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkRenderPass* pRenderPass); +template<> +VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateRenderPass2KHR(VkDevice device, + const VkRenderPassCreateInfo2* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkRenderPass* pRenderPass); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkDestroyRenderPass( - VkDevice device, - VkRenderPass renderPass, - const VkAllocationCallbacks* pAllocator); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkDestroyRenderPass(VkDevice device, + VkRenderPass renderPass, + const VkAllocationCallbacks* pAllocator); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass( - VkCommandBuffer commandBuffer, - const VkRenderPassBeginInfo* pRenderPassBegin, - VkSubpassContents contents); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, + const VkRenderPassBeginInfo* pRenderPassBegin, + VkSubpassContents contents); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2( - VkCommandBuffer commandBuffer, - const VkRenderPassBeginInfo* pRenderPassBegin, - const VkSubpassBeginInfo* pSubpassBeginInfo); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2(VkCommandBuffer commandBuffer, + const VkRenderPassBeginInfo* pRenderPassBegin, + const VkSubpassBeginInfo* pSubpassBeginInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2KHR( - VkCommandBuffer commandBuffer, - const VkRenderPassBeginInfo* pRenderPassBegin, - const VkSubpassBeginInfo* pSubpassBeginInfo); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, + const VkRenderPassBeginInfo* pRenderPassBegin, + const VkSubpassBeginInfo* pSubpassBeginInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRendering( - VkCommandBuffer commandBuffer, - const VkRenderingInfo* pRenderingInfo); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRendering(VkCommandBuffer commandBuffer, + const VkRenderingInfo* pRenderingInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderingKHR( - VkCommandBuffer commandBuffer, - const VkRenderingInfo* pRenderingInfo); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderingKHR(VkCommandBuffer commandBuffer, + const VkRenderingInfo* pRenderingInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRenderPass( - VkCommandBuffer commandBuffer); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRenderPass(VkCommandBuffer commandBuffer); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRendering( - VkCommandBuffer commandBuffer); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRendering(VkCommandBuffer commandBuffer); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRenderingKHR( - VkCommandBuffer commandBuffer); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRenderingKHR(VkCommandBuffer commandBuffer); // Functions for draw calls /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDraw( - VkCommandBuffer commandBuffer, - uint32_t vertexCount, - uint32_t instanceCount, - uint32_t firstVertex, - uint32_t firstInstance); - -/* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndexed( - VkCommandBuffer commandBuffer, - uint32_t indexCount, - uint32_t instanceCount, - uint32_t firstIndex, - int32_t vertexOffset, - uint32_t firstInstance); - -/* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndexedIndirect( - VkCommandBuffer commandBuffer, - VkBuffer buffer, - VkDeviceSize offset, - uint32_t drawCount, - uint32_t stride); - -/* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndexedIndirectCount( - VkCommandBuffer commandBuffer, - VkBuffer buffer, - VkDeviceSize offset, - VkBuffer countBuffer, - VkDeviceSize countBufferOffset, - uint32_t maxDrawCount, - uint32_t stride); - -/* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndexedIndirectCountKHR( - VkCommandBuffer commandBuffer, - VkBuffer buffer, - VkDeviceSize offset, - VkBuffer countBuffer, - VkDeviceSize countBufferOffset, - uint32_t maxDrawCount, - uint32_t stride); - -/* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndirect( - VkCommandBuffer commandBuffer, - VkBuffer buffer, - VkDeviceSize offset, - uint32_t drawCount, - uint32_t stride); - -/* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndirectByteCountEXT( - VkCommandBuffer commandBuffer, - uint32_t instanceCount, - uint32_t firstInstance, - VkBuffer counterBuffer, - VkDeviceSize counterBufferOffset, - uint32_t counterOffset, - uint32_t vertexStride); - -/* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndirectCount( - VkCommandBuffer commandBuffer, - VkBuffer buffer, - VkDeviceSize offset, - VkBuffer countBuffer, - VkDeviceSize countBufferOffset, - uint32_t maxDrawCount, - uint32_t stride); - -/* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndirectCountKHR( - VkCommandBuffer commandBuffer, - VkBuffer buffer, - VkDeviceSize offset, - VkBuffer countBuffer, - VkDeviceSize countBufferOffset, - uint32_t maxDrawCount, - uint32_t stride); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDraw(VkCommandBuffer commandBuffer, + uint32_t vertexCount, + uint32_t instanceCount, + uint32_t firstVertex, + uint32_t firstInstance); + +/* See Vulkan API for documentation. */ +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndexed(VkCommandBuffer commandBuffer, + uint32_t indexCount, + uint32_t instanceCount, + uint32_t firstIndex, + int32_t vertexOffset, + uint32_t firstInstance); + +/* See Vulkan API for documentation. */ +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset, + uint32_t drawCount, + uint32_t stride); + +/* See Vulkan API for documentation. */ +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset, + VkBuffer countBuffer, + VkDeviceSize countBufferOffset, + uint32_t maxDrawCount, + uint32_t stride); + +/* See Vulkan API for documentation. */ +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset, + VkBuffer countBuffer, + VkDeviceSize countBufferOffset, + uint32_t maxDrawCount, + uint32_t stride); + +/* See Vulkan API for documentation. */ +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndirect(VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset, + uint32_t drawCount, + uint32_t stride); + +/* See Vulkan API for documentation. */ +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndirectByteCountEXT(VkCommandBuffer commandBuffer, + uint32_t instanceCount, + uint32_t firstInstance, + VkBuffer counterBuffer, + VkDeviceSize counterBufferOffset, + uint32_t counterOffset, + uint32_t vertexStride); + +/* See Vulkan API for documentation. */ +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndirectCount(VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset, + VkBuffer countBuffer, + VkDeviceSize countBufferOffset, + uint32_t maxDrawCount, + uint32_t stride); + +/* See Vulkan API for documentation. */ +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset, + VkBuffer countBuffer, + VkDeviceSize countBufferOffset, + uint32_t maxDrawCount, + uint32_t stride); // Functions for compute dispatches /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatch( - VkCommandBuffer commandBuffer, - uint32_t groupCountX, - uint32_t groupCountY, - uint32_t groupCountZ); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatch(VkCommandBuffer commandBuffer, + uint32_t groupCountX, + uint32_t groupCountY, + uint32_t groupCountZ); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchBase( - VkCommandBuffer commandBuffer, - uint32_t baseGroupX, - uint32_t baseGroupY, - uint32_t baseGroupZ, - uint32_t groupCountX, - uint32_t groupCountY, - uint32_t groupCountZ); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchBase(VkCommandBuffer commandBuffer, + uint32_t baseGroupX, + uint32_t baseGroupY, + uint32_t baseGroupZ, + uint32_t groupCountX, + uint32_t groupCountY, + uint32_t groupCountZ); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchBaseKHR( - VkCommandBuffer commandBuffer, - uint32_t baseGroupX, - uint32_t baseGroupY, - uint32_t baseGroupZ, - uint32_t groupCountX, - uint32_t groupCountY, - uint32_t groupCountZ); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, + uint32_t baseGroupX, + uint32_t baseGroupY, + uint32_t baseGroupZ, + uint32_t groupCountX, + uint32_t groupCountY, + uint32_t groupCountZ); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchIndirect( - VkCommandBuffer commandBuffer, - VkBuffer buffer, - VkDeviceSize offset); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset); // Commands for trace rays /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysIndirect2KHR( - VkCommandBuffer commandBuffer, - VkDeviceAddress indirectDeviceAddress); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysIndirect2KHR(VkCommandBuffer commandBuffer, + VkDeviceAddress indirectDeviceAddress); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysIndirectKHR( - VkCommandBuffer commandBuffer, - const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable, - VkDeviceAddress indirectDeviceAddress); +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer, + const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable, + VkDeviceAddress indirectDeviceAddress); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysKHR( - VkCommandBuffer commandBuffer, - const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable, - uint32_t width, - uint32_t height, - uint32_t depth); - +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdTraceRaysKHR(VkCommandBuffer commandBuffer, + const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable, + uint32_t width, + uint32_t height, + uint32_t depth); // Commands for transfers /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdFillBuffer( - VkCommandBuffer commandBuffer, - VkBuffer dstBuffer, - VkDeviceSize dstOffset, - VkDeviceSize size, - uint32_t data); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdFillBuffer(VkCommandBuffer commandBuffer, + VkBuffer dstBuffer, + VkDeviceSize dstOffset, + VkDeviceSize size, + uint32_t data); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdClearColorImage( - VkCommandBuffer commandBuffer, - VkImage image, - VkImageLayout imageLayout, - const VkClearColorValue* pColor, - uint32_t rangeCount, - const VkImageSubresourceRange* pRanges); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdClearColorImage(VkCommandBuffer commandBuffer, + VkImage image, + VkImageLayout imageLayout, + const VkClearColorValue* pColor, + uint32_t rangeCount, + const VkImageSubresourceRange* pRanges); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdClearDepthStencilImage( - VkCommandBuffer commandBuffer, - VkImage image, - VkImageLayout imageLayout, - const VkClearDepthStencilValue* pDepthStencil, - uint32_t rangeCount, - const VkImageSubresourceRange* pRanges); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, + VkImage image, + VkImageLayout imageLayout, + const VkClearDepthStencilValue* pDepthStencil, + uint32_t rangeCount, + const VkImageSubresourceRange* pRanges); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer( - VkCommandBuffer commandBuffer, - VkBuffer srcBuffer, - VkBuffer dstBuffer, - uint32_t regionCount, - const VkBufferCopy* pRegions); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer(VkCommandBuffer commandBuffer, + VkBuffer srcBuffer, + VkBuffer dstBuffer, + uint32_t regionCount, + const VkBufferCopy* pRegions); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2( - VkCommandBuffer commandBuffer, - const VkCopyBufferInfo2* pCopyBufferInfo); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2(VkCommandBuffer commandBuffer, + const VkCopyBufferInfo2* pCopyBufferInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2KHR( - VkCommandBuffer commandBuffer, - const VkCopyBufferInfo2* pCopyBufferInfo); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, + const VkCopyBufferInfo2* pCopyBufferInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage( - VkCommandBuffer commandBuffer, - VkBuffer srcBuffer, - VkImage dstImage, - VkImageLayout dstImageLayout, - uint32_t regionCount, - const VkBufferImageCopy* pRegions); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer, + VkBuffer srcBuffer, + VkImage dstImage, + VkImageLayout dstImageLayout, + uint32_t regionCount, + const VkBufferImageCopy* pRegions); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage2( - VkCommandBuffer commandBuffer, - const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo); +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdCopyBufferToImage2(VkCommandBuffer commandBuffer, + const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage2KHR( - VkCommandBuffer commandBuffer, - const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo); +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, + const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage( - VkCommandBuffer commandBuffer, - VkImage srcImage, - VkImageLayout srcImageLayout, - VkImage dstImage, - VkImageLayout dstImageLayout, - uint32_t regionCount, - const VkImageCopy* pRegions); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage(VkCommandBuffer commandBuffer, + VkImage srcImage, + VkImageLayout srcImageLayout, + VkImage dstImage, + VkImageLayout dstImageLayout, + uint32_t regionCount, + const VkImageCopy* pRegions); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2( - VkCommandBuffer commandBuffer, - const VkCopyImageInfo2* pCopyImageInfo); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2(VkCommandBuffer commandBuffer, + const VkCopyImageInfo2* pCopyImageInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2KHR( - VkCommandBuffer commandBuffer, - const VkCopyImageInfo2* pCopyImageInfo); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2KHR(VkCommandBuffer commandBuffer, + const VkCopyImageInfo2* pCopyImageInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer( - VkCommandBuffer commandBuffer, - VkImage srcImage, - VkImageLayout srcImageLayout, - VkBuffer dstBuffer, - uint32_t regionCount, - const VkBufferImageCopy* pRegions); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, + VkImage srcImage, + VkImageLayout srcImageLayout, + VkBuffer dstBuffer, + uint32_t regionCount, + const VkBufferImageCopy* pRegions); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer2( - VkCommandBuffer commandBuffer, - const VkCopyImageToBufferInfo2* pCopyImageToBufferInfo); +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer, + const VkCopyImageToBufferInfo2* pCopyImageToBufferInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer2KHR( - VkCommandBuffer commandBuffer, - const VkCopyImageToBufferInfo2* pCopyImageToBufferInfo); +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, + const VkCopyImageToBufferInfo2* pCopyImageToBufferInfo); // Functions for debug /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDebugMarkerBeginEXT( - VkCommandBuffer commandBuffer, - const VkDebugMarkerMarkerInfoEXT* pMarkerInfo); +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDebugMarkerBeginEXT(VkCommandBuffer commandBuffer, + const VkDebugMarkerMarkerInfoEXT* pMarkerInfo); /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDebugMarkerEndEXT( - VkCommandBuffer commandBuffer); +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDebugMarkerEndEXT(VkCommandBuffer commandBuffer); /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginDebugUtilsLabelEXT( - VkCommandBuffer commandBuffer, - const VkDebugUtilsLabelEXT* pLabelInfo); +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer, + const VkDebugUtilsLabelEXT* pLabelInfo); /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndDebugUtilsLabelEXT( - VkCommandBuffer commandBuffer); +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer); // Functions for queues /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueuePresentKHR( - VkQueue queue, - const VkPresentInfoKHR* pPresentInfo); +VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo); /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit( - VkQueue queue, - uint32_t submitCount, - const VkSubmitInfo* pSubmits, - VkFence fence); +VKAPI_ATTR VkResult VKAPI_CALL + layer_vkQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence); /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit2( - VkQueue queue, - uint32_t submitCount, - const VkSubmitInfo2* pSubmits, - VkFence fence); +VKAPI_ATTR VkResult VKAPI_CALL + layer_vkQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2* pSubmits, VkFence fence); /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit2KHR( - VkQueue queue, - uint32_t submitCount, - const VkSubmitInfo2* pSubmits, - VkFence fence); +VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit2KHR(VkQueue queue, + uint32_t submitCount, + const VkSubmitInfo2* pSubmits, + VkFence fence); diff --git a/layer_gpu_timeline/source/layer_device_functions_command_buffer.cpp b/layer_gpu_timeline/source/layer_device_functions_command_buffer.cpp index ef8e920..de0f4f4 100644 --- a/layer_gpu_timeline/source/layer_device_functions_command_buffer.cpp +++ b/layer_gpu_timeline/source/layer_device_functions_command_buffer.cpp @@ -23,30 +23,29 @@ * ---------------------------------------------------------------------------- */ -#include - #include "device.hpp" -#include "layer_device_functions.hpp" +#include "framework/device_dispatch_table.hpp" + +#include extern std::mutex g_vulkanLock; /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkAllocateCommandBuffers( - VkDevice device, - const VkCommandBufferAllocateInfo* pAllocateInfo, - VkCommandBuffer* pCommandBuffers -) { +template<> +VKAPI_ATTR VkResult VKAPI_CALL + layer_vkAllocateCommandBuffers(VkDevice device, + const VkCommandBufferAllocateInfo* pAllocateInfo, + VkCommandBuffer* pCommandBuffers) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(device); // Release the lock to call into the driver lock.unlock(); - VkResult result = layer->driver.vkAllocateCommandBuffers( - device, pAllocateInfo, pCommandBuffers); + VkResult result = layer->driver.vkAllocateCommandBuffers(device, pAllocateInfo, pCommandBuffers); if (result != VK_SUCCESS) { return result; @@ -57,21 +56,19 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkAllocateCommandBuffers( auto& tracker = layer->getStateTracker(); for (uint32_t i = 0; i < pAllocateInfo->commandBufferCount; i++) { - tracker.allocateCommandBuffer( - pAllocateInfo->commandPool, pCommandBuffers[i]); + tracker.allocateCommandBuffer(pAllocateInfo->commandPool, pCommandBuffers[i]); } return result; } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR VkResult layer_vkBeginCommandBuffer( - VkCommandBuffer commandBuffer, - const VkCommandBufferBeginInfo* pBeginInfo -) { +template<> +VKAPI_ATTR VkResult layer_vkBeginCommandBuffer(VkCommandBuffer commandBuffer, + const VkCommandBufferBeginInfo* pBeginInfo) +{ // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); auto& tracker = layer->getStateTracker(); @@ -85,15 +82,14 @@ VKAPI_ATTR VkResult layer_vkBeginCommandBuffer( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkResetCommandBuffer( - VkCommandBuffer commandBuffer, - VkCommandBufferResetFlags flags -) { +template<> +VKAPI_ATTR VkResult VKAPI_CALL layer_vkResetCommandBuffer(VkCommandBuffer commandBuffer, + VkCommandBufferResetFlags flags) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); auto& tracker = layer->getStateTracker(); @@ -106,17 +102,16 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkResetCommandBuffer( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkFreeCommandBuffers( - VkDevice device, - VkCommandPool commandPool, - uint32_t commandBufferCount, - const VkCommandBuffer* pCommandBuffers -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkFreeCommandBuffers(VkDevice device, + VkCommandPool commandPool, + uint32_t commandBufferCount, + const VkCommandBuffer* pCommandBuffers) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(device); auto& tracker = layer->getStateTracker(); @@ -127,21 +122,19 @@ VKAPI_ATTR void VKAPI_CALL layer_vkFreeCommandBuffers( // Release the lock to call into the driver lock.unlock(); - layer->driver.vkFreeCommandBuffers( - device, commandPool, commandBufferCount, pCommandBuffers); + layer->driver.vkFreeCommandBuffers(device, commandPool, commandBufferCount, pCommandBuffers); } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdExecuteCommands( - VkCommandBuffer commandBuffer, - uint32_t commandBufferCount, - const VkCommandBuffer* pCommandBuffers -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdExecuteCommands(VkCommandBuffer commandBuffer, + uint32_t commandBufferCount, + const VkCommandBuffer* pCommandBuffers) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store and device-wide data - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); auto& tracker = layer->getStateTracker(); @@ -155,6 +148,5 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdExecuteCommands( // Release the lock to call into the main driver lock.unlock(); - layer->driver.vkCmdExecuteCommands( - commandBuffer, commandBufferCount, pCommandBuffers); + layer->driver.vkCmdExecuteCommands(commandBuffer, commandBufferCount, pCommandBuffers); } diff --git a/layer_gpu_timeline/source/layer_device_functions_command_pool.cpp b/layer_gpu_timeline/source/layer_device_functions_command_pool.cpp index a640a90..4beb9c7 100644 --- a/layer_gpu_timeline/source/layer_device_functions_command_pool.cpp +++ b/layer_gpu_timeline/source/layer_device_functions_command_pool.cpp @@ -23,31 +23,29 @@ * ---------------------------------------------------------------------------- */ -#include - #include "device.hpp" -#include "layer_device_functions.hpp" +#include "framework/device_dispatch_table.hpp" + +#include extern std::mutex g_vulkanLock; /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateCommandPool( - VkDevice device, - const VkCommandPoolCreateInfo* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkCommandPool* pCommandPool -) { +template<> +VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateCommandPool(VkDevice device, + const VkCommandPoolCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkCommandPool* pCommandPool) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(device); // Release the lock to call into the driver lock.unlock(); - VkResult result = layer->driver.vkCreateCommandPool( - device, pCreateInfo, pAllocator, pCommandPool); + VkResult result = layer->driver.vkCreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool); if (result != VK_SUCCESS) { return result; @@ -61,16 +59,15 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateCommandPool( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkResetCommandPool( - VkDevice device, - VkCommandPool commandPool, - VkCommandPoolResetFlags flags -) { +template<> +VKAPI_ATTR VkResult VKAPI_CALL layer_vkResetCommandPool(VkDevice device, + VkCommandPool commandPool, + VkCommandPoolResetFlags flags) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(device); auto& tracker = layer->getStateTracker(); @@ -82,16 +79,15 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkResetCommandPool( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkDestroyCommandPool( - VkDevice device, - VkCommandPool commandPool, - const VkAllocationCallbacks* pAllocator -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkDestroyCommandPool(VkDevice device, + VkCommandPool commandPool, + const VkAllocationCallbacks* pAllocator) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(device); auto& tracker = layer->getStateTracker(); diff --git a/layer_gpu_timeline/source/layer_device_functions_debug.cpp b/layer_gpu_timeline/source/layer_device_functions_debug.cpp index 1905193..7795598 100644 --- a/layer_gpu_timeline/source/layer_device_functions_debug.cpp +++ b/layer_gpu_timeline/source/layer_device_functions_debug.cpp @@ -23,23 +23,22 @@ * ---------------------------------------------------------------------------- */ -#include - #include "device.hpp" -#include "layer_device_functions.hpp" +#include "framework/device_dispatch_table.hpp" + +#include extern std::mutex g_vulkanLock; /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDebugMarkerBeginEXT( - VkCommandBuffer commandBuffer, - const VkDebugMarkerMarkerInfoEXT* pMarkerInfo -) { +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDebugMarkerBeginEXT(VkCommandBuffer commandBuffer, + const VkDebugMarkerMarkerInfoEXT* pMarkerInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); auto& tracker = layer->getStateTracker(); @@ -55,13 +54,12 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdDebugMarkerBeginEXT( /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDebugMarkerEndEXT( - VkCommandBuffer commandBuffer -) { +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDebugMarkerEndEXT(VkCommandBuffer commandBuffer) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); auto& tracker = layer->getStateTracker(); @@ -77,14 +75,13 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdDebugMarkerEndEXT( /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginDebugUtilsLabelEXT( - VkCommandBuffer commandBuffer, - const VkDebugUtilsLabelEXT* pLabelInfo -) { +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer, + const VkDebugUtilsLabelEXT* pLabelInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); auto& tracker = layer->getStateTracker(); @@ -100,13 +97,12 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginDebugUtilsLabelEXT( /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndDebugUtilsLabelEXT( - VkCommandBuffer commandBuffer -) { +VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); auto& tracker = layer->getStateTracker(); diff --git a/layer_gpu_timeline/source/layer_device_functions_dispatch.cpp b/layer_gpu_timeline/source/layer_device_functions_dispatch.cpp index de5ee10..094de22 100644 --- a/layer_gpu_timeline/source/layer_device_functions_dispatch.cpp +++ b/layer_gpu_timeline/source/layer_device_functions_dispatch.cpp @@ -23,11 +23,11 @@ * ---------------------------------------------------------------------------- */ -#include - #include "device.hpp" #include "device_utils.hpp" -#include "layer_device_functions.hpp" +#include "framework/device_dispatch_table.hpp" + +#include extern std::mutex g_vulkanLock; @@ -42,38 +42,35 @@ extern std::mutex g_vulkanLock; * * @return The assigned tagID for the workload. */ -static uint64_t registerDispatch( - Device* layer, - VkCommandBuffer commandBuffer, - int64_t groupX, - int64_t groupY, - int64_t groupZ -) { +static uint64_t registerDispatch(Device* layer, + VkCommandBuffer commandBuffer, + int64_t groupX, + int64_t groupY, + int64_t groupZ) +{ auto& tracker = layer->getStateTracker(); auto& cb = tracker.getCommandBuffer(commandBuffer); return cb.dispatch(groupX, groupY, groupZ); } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatch( - VkCommandBuffer commandBuffer, - uint32_t groupCountX, - uint32_t groupCountY, - uint32_t groupCountZ -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatch(VkCommandBuffer commandBuffer, + uint32_t groupCountX, + uint32_t groupCountY, + uint32_t groupCountZ) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); - uint64_t tagID = registerDispatch( - layer, - commandBuffer, - static_cast(groupCountX), - static_cast(groupCountY), - static_cast(groupCountZ)); + uint64_t tagID = registerDispatch(layer, + commandBuffer, + static_cast(groupCountX), + static_cast(groupCountY), + static_cast(groupCountZ)); // Release the lock to call into the driver lock.unlock(); @@ -83,78 +80,75 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatch( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchBase( - VkCommandBuffer commandBuffer, - uint32_t baseGroupX, - uint32_t baseGroupY, - uint32_t baseGroupZ, - uint32_t groupCountX, - uint32_t groupCountY, - uint32_t groupCountZ -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchBase(VkCommandBuffer commandBuffer, + uint32_t baseGroupX, + uint32_t baseGroupY, + uint32_t baseGroupZ, + uint32_t groupCountX, + uint32_t groupCountY, + uint32_t groupCountZ) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); - uint64_t tagID = registerDispatch( - layer, - commandBuffer, - static_cast(groupCountX), - static_cast(groupCountY), - static_cast(groupCountZ)); + uint64_t tagID = registerDispatch(layer, + commandBuffer, + static_cast(groupCountX), + static_cast(groupCountY), + static_cast(groupCountZ)); // Release the lock to call into the driver lock.unlock(); emitStartTag(layer, commandBuffer, tagID); - layer->driver.vkCmdDispatchBase(commandBuffer, baseGroupX, baseGroupY, baseGroupZ, groupCountX, groupCountY, groupCountZ); + layer->driver + .vkCmdDispatchBase(commandBuffer, baseGroupX, baseGroupY, baseGroupZ, groupCountX, groupCountY, groupCountZ); layer->driver.vkCmdEndDebugUtilsLabelEXT(commandBuffer); } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchBaseKHR( - VkCommandBuffer commandBuffer, - uint32_t baseGroupX, - uint32_t baseGroupY, - uint32_t baseGroupZ, - uint32_t groupCountX, - uint32_t groupCountY, - uint32_t groupCountZ -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchBaseKHR(VkCommandBuffer commandBuffer, + uint32_t baseGroupX, + uint32_t baseGroupY, + uint32_t baseGroupZ, + uint32_t groupCountX, + uint32_t groupCountY, + uint32_t groupCountZ) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); - uint64_t tagID = registerDispatch( - layer, - commandBuffer, - static_cast(groupCountX), - static_cast(groupCountY), - static_cast(groupCountZ)); + uint64_t tagID = registerDispatch(layer, + commandBuffer, + static_cast(groupCountX), + static_cast(groupCountY), + static_cast(groupCountZ)); // Release the lock to call into the driver lock.unlock(); emitStartTag(layer, commandBuffer, tagID); - layer->driver.vkCmdDispatchBaseKHR(commandBuffer, baseGroupX, baseGroupY, baseGroupZ, groupCountX, groupCountY, groupCountZ); + layer->driver + .vkCmdDispatchBaseKHR(commandBuffer, baseGroupX, baseGroupY, baseGroupZ, groupCountX, groupCountY, groupCountZ); layer->driver.vkCmdEndDebugUtilsLabelEXT(commandBuffer); } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchIndirect( - VkCommandBuffer commandBuffer, - VkBuffer buffer, - VkDeviceSize offset -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchIndirect(VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); uint64_t tagID = registerDispatch(layer, commandBuffer, -1, -1, -1); diff --git a/layer_gpu_timeline/source/layer_device_functions_draw_call.cpp b/layer_gpu_timeline/source/layer_device_functions_draw_call.cpp index 42350d0..b1ab208 100644 --- a/layer_gpu_timeline/source/layer_device_functions_draw_call.cpp +++ b/layer_gpu_timeline/source/layer_device_functions_draw_call.cpp @@ -23,13 +23,13 @@ * ---------------------------------------------------------------------------- */ +#include "device.hpp" +#include "framework/device_dispatch_table.hpp" + #include #include #include -#include "device.hpp" -#include "layer_device_functions.hpp" - extern std::mutex g_vulkanLock; /** @@ -38,28 +38,25 @@ extern std::mutex g_vulkanLock; * @param layer The layer context for the device. * @param commandBuffer The command buffer we are recording. */ -static void registerDrawCall( - Device* layer, - VkCommandBuffer commandBuffer -) { +static void registerDrawCall(Device* layer, VkCommandBuffer commandBuffer) +{ auto& state = layer->getStateTracker(); auto& stats = state.getCommandBuffer(commandBuffer).getStats(); stats.incDrawCallCount(); } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDraw( - VkCommandBuffer commandBuffer, - uint32_t vertexCount, - uint32_t instanceCount, - uint32_t firstVertex, - uint32_t firstInstance -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDraw(VkCommandBuffer commandBuffer, + uint32_t vertexCount, + uint32_t instanceCount, + uint32_t firstVertex, + uint32_t firstInstance) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); registerDrawCall(layer, commandBuffer); @@ -70,19 +67,18 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdDraw( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndexed( - VkCommandBuffer commandBuffer, - uint32_t indexCount, - uint32_t instanceCount, - uint32_t firstIndex, - int32_t vertexOffset, - uint32_t firstInstance -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndexed(VkCommandBuffer commandBuffer, + uint32_t indexCount, + uint32_t instanceCount, + uint32_t firstIndex, + int32_t vertexOffset, + uint32_t firstInstance) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); registerDrawCall(layer, commandBuffer); @@ -93,18 +89,17 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndexed( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndexedIndirect( - VkCommandBuffer commandBuffer, - VkBuffer buffer, - VkDeviceSize offset, - uint32_t drawCount, - uint32_t stride -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset, + uint32_t drawCount, + uint32_t stride) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); registerDrawCall(layer, commandBuffer); @@ -115,66 +110,75 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndexedIndirect( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndexedIndirectCount( - VkCommandBuffer commandBuffer, - VkBuffer buffer, - VkDeviceSize offset, - VkBuffer countBuffer, - VkDeviceSize countBufferOffset, - uint32_t maxDrawCount, - uint32_t stride -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndexedIndirectCount(VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset, + VkBuffer countBuffer, + VkDeviceSize countBufferOffset, + uint32_t maxDrawCount, + uint32_t stride) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); registerDrawCall(layer, commandBuffer); // Release the lock to call into the driver lock.unlock(); - layer->driver.vkCmdDrawIndexedIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); + layer->driver.vkCmdDrawIndexedIndirectCount(commandBuffer, + buffer, + offset, + countBuffer, + countBufferOffset, + maxDrawCount, + stride); } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndexedIndirectCountKHR( - VkCommandBuffer commandBuffer, - VkBuffer buffer, - VkDeviceSize offset, - VkBuffer countBuffer, - VkDeviceSize countBufferOffset, - uint32_t maxDrawCount, - uint32_t stride -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndexedIndirectCountKHR(VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset, + VkBuffer countBuffer, + VkDeviceSize countBufferOffset, + uint32_t maxDrawCount, + uint32_t stride) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); registerDrawCall(layer, commandBuffer); // Release the lock to call into the driver lock.unlock(); - layer->driver.vkCmdDrawIndexedIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); + layer->driver.vkCmdDrawIndexedIndirectCountKHR(commandBuffer, + buffer, + offset, + countBuffer, + countBufferOffset, + maxDrawCount, + stride); } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndirect( - VkCommandBuffer commandBuffer, - VkBuffer buffer, - VkDeviceSize offset, - uint32_t drawCount, - uint32_t stride -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndirect(VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset, + uint32_t drawCount, + uint32_t stride) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); registerDrawCall(layer, commandBuffer); @@ -185,73 +189,78 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndirect( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndirectByteCountEXT( - VkCommandBuffer commandBuffer, - uint32_t instanceCount, - uint32_t firstInstance, - VkBuffer counterBuffer, - VkDeviceSize counterBufferOffset, - uint32_t counterOffset, - uint32_t vertexStride -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndirectByteCountEXT(VkCommandBuffer commandBuffer, + uint32_t instanceCount, + uint32_t firstInstance, + VkBuffer counterBuffer, + VkDeviceSize counterBufferOffset, + uint32_t counterOffset, + uint32_t vertexStride) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); registerDrawCall(layer, commandBuffer); // Release the lock to call into the driver lock.unlock(); - layer->driver.vkCmdDrawIndirectByteCountEXT(commandBuffer, instanceCount, firstInstance, counterBuffer, counterBufferOffset, counterOffset, vertexStride); + layer->driver.vkCmdDrawIndirectByteCountEXT(commandBuffer, + instanceCount, + firstInstance, + counterBuffer, + counterBufferOffset, + counterOffset, + vertexStride); } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndirectCount( - VkCommandBuffer commandBuffer, - VkBuffer buffer, - VkDeviceSize offset, - VkBuffer countBuffer, - VkDeviceSize countBufferOffset, - uint32_t maxDrawCount, - uint32_t stride -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndirectCount(VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset, + VkBuffer countBuffer, + VkDeviceSize countBufferOffset, + uint32_t maxDrawCount, + uint32_t stride) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); registerDrawCall(layer, commandBuffer); // Release the lock to call into the driver lock.unlock(); - layer->driver.vkCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); + layer->driver + .vkCmdDrawIndirectCount(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndirectCountKHR( - VkCommandBuffer commandBuffer, - VkBuffer buffer, - VkDeviceSize offset, - VkBuffer countBuffer, - VkDeviceSize countBufferOffset, - uint32_t maxDrawCount, - uint32_t stride -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdDrawIndirectCountKHR(VkCommandBuffer commandBuffer, + VkBuffer buffer, + VkDeviceSize offset, + VkBuffer countBuffer, + VkDeviceSize countBufferOffset, + uint32_t maxDrawCount, + uint32_t stride) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); registerDrawCall(layer, commandBuffer); // Release the lock to call into the driver lock.unlock(); - layer->driver.vkCmdDrawIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); + layer->driver + .vkCmdDrawIndirectCountKHR(commandBuffer, buffer, offset, countBuffer, countBufferOffset, maxDrawCount, stride); } diff --git a/layer_gpu_timeline/source/layer_device_functions_queue.cpp b/layer_gpu_timeline/source/layer_device_functions_queue.cpp index 972a9f8..a1ed3f1 100644 --- a/layer_gpu_timeline/source/layer_device_functions_queue.cpp +++ b/layer_gpu_timeline/source/layer_device_functions_queue.cpp @@ -23,15 +23,15 @@ * ---------------------------------------------------------------------------- */ +#include "device.hpp" +#include "framework/device_dispatch_table.hpp" +#include "utils/misc.hpp" + #include + #include #include -#include "utils/misc.hpp" - -#include "device.hpp" -#include "layer_device_functions.hpp" - using json = nlohmann::json; using namespace std::placeholders; @@ -50,7 +50,8 @@ static uint64_t getClockMonotonicRaw() struct timespec ts; auto error = clock_gettime(CLOCK_MONOTONIC_RAW, &ts); - if (error) { + if (error) + { return 0; } @@ -68,17 +69,14 @@ static uint64_t getClockMonotonicRaw() * @param queue The queue being submitted to. * @param callback The data emit callback. */ -static void emitQueueMetadata( - VkDevice device, - VkQueue queue, - std::function callback -) { +static void emitQueueMetadata(VkDevice device, VkQueue queue, std::function callback) +{ // Write the queue submit metadata json submitMetadata { - { "type", "submit" }, - { "device", reinterpret_cast(device) }, - { "queue", reinterpret_cast(queue) }, - { "timestamp", getClockMonotonicRaw() } + {"type", "submit"}, + {"device", reinterpret_cast(device)}, + {"queue", reinterpret_cast(queue)}, + {"timestamp", getClockMonotonicRaw()}, }; callback(submitMetadata.dump()); @@ -92,12 +90,11 @@ static void emitQueueMetadata( * @param commandBuffer The command buffer being submitted. * @param callback The data emit callback. */ -static void emitCommandBufferMetadata( - Device& layer, - VkQueue queue, - VkCommandBuffer commandBuffer, - std::function callback -) { +static void emitCommandBufferMetadata(Device& layer, + VkQueue queue, + VkCommandBuffer commandBuffer, + std::function callback) +{ // Fetch layer proxies for this workload auto& tracker = layer.getStateTracker(); auto& trackQueue = tracker.getQueue(queue); @@ -110,14 +107,12 @@ static void emitCommandBufferMetadata( /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueuePresentKHR( - VkQueue queue, - const VkPresentInfoKHR* pPresentInfo -) { +VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR* pPresentInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(queue); auto& tracker = layer->getStateTracker(); @@ -126,10 +121,10 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueuePresentKHR( // This is run with the lock held to ensure that all queue submit // messages are sent sequentially to the host tool json frame { - { "type", "frame" }, - { "device", reinterpret_cast(layer->device) }, - { "fid", tracker.totalStats.getFrameCount() }, - { "timestamp", getClockMonotonicRaw() } + {"type", "frame"}, + {"device", reinterpret_cast(layer->device)}, + {"fid", tracker.totalStats.getFrameCount()}, + {"timestamp", getClockMonotonicRaw()}, }; layer->onFrame(frame.dump()); @@ -141,16 +136,13 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueuePresentKHR( /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit( - VkQueue queue, - uint32_t submitCount, - const VkSubmitInfo* pSubmits, - VkFence fence -) { +VKAPI_ATTR VkResult VKAPI_CALL + layer_vkQueueSubmit(VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(queue); auto onSubmit = std::bind(&Device::onWorkloadSubmit, layer, _1); @@ -179,16 +171,13 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit( /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit2( - VkQueue queue, - uint32_t submitCount, - const VkSubmitInfo2* pSubmits, - VkFence fence -) { +VKAPI_ATTR VkResult VKAPI_CALL + layer_vkQueueSubmit2(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2* pSubmits, VkFence fence) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(queue); auto onSubmit = std::bind(&Device::onWorkloadSubmit, layer, _1); @@ -217,16 +206,13 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit2( /* See Vulkan API for documentation. */ template<> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkQueueSubmit2KHR( - VkQueue queue, - uint32_t submitCount, - const VkSubmitInfo2* pSubmits, - VkFence fence -) { +VKAPI_ATTR VkResult VKAPI_CALL + layer_vkQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2* pSubmits, VkFence fence) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(queue); auto onSubmit = std::bind(&Device::onWorkloadSubmit, layer, _1); diff --git a/layer_gpu_timeline/source/layer_device_functions_render_pass.cpp b/layer_gpu_timeline/source/layer_device_functions_render_pass.cpp index 5d16880..5595583 100644 --- a/layer_gpu_timeline/source/layer_device_functions_render_pass.cpp +++ b/layer_gpu_timeline/source/layer_device_functions_render_pass.cpp @@ -23,29 +23,27 @@ * ---------------------------------------------------------------------------- */ -#include - +#include "device.hpp" +#include "device_utils.hpp" +#include "framework/device_dispatch_table.hpp" #include "framework/utils.hpp" #include "trackers/render_pass.hpp" -#include "device.hpp" -#include "device_utils.hpp" -#include "layer_device_functions.hpp" +#include extern std::mutex g_vulkanLock; /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateRenderPass( - VkDevice device, - const VkRenderPassCreateInfo* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkRenderPass* pRenderPass -) { +template<> +VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateRenderPass(VkDevice device, + const VkRenderPassCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkRenderPass* pRenderPass) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(device); // Release the lock to call into the driver @@ -64,17 +62,16 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateRenderPass( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateRenderPass2( - VkDevice device, - const VkRenderPassCreateInfo2* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkRenderPass* pRenderPass -) { +template<> +VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateRenderPass2(VkDevice device, + const VkRenderPassCreateInfo2* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkRenderPass* pRenderPass) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(device); // Release the lock to call into the driver @@ -93,17 +90,16 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateRenderPass2( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateRenderPass2KHR( - VkDevice device, - const VkRenderPassCreateInfo2* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkRenderPass* pRenderPass -) { +template<> +VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateRenderPass2KHR(VkDevice device, + const VkRenderPassCreateInfo2* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkRenderPass* pRenderPass) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(device); // Release the lock to call into the driver @@ -122,16 +118,15 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateRenderPass2KHR( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkDestroyRenderPass( - VkDevice device, - VkRenderPass renderPass, - const VkAllocationCallbacks* pAllocator -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkDestroyRenderPass(VkDevice device, + VkRenderPass renderPass, + const VkAllocationCallbacks* pAllocator) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(device); auto& tracker = layer->getStateTracker(); @@ -143,16 +138,15 @@ VKAPI_ATTR void VKAPI_CALL layer_vkDestroyRenderPass( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass( - VkCommandBuffer commandBuffer, - const VkRenderPassBeginInfo* pRenderPassBegin, - VkSubpassContents contents -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass(VkCommandBuffer commandBuffer, + const VkRenderPassBeginInfo* pRenderPassBegin, + VkSubpassContents contents) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); auto& tracker = layer->getStateTracker(); @@ -172,16 +166,15 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2( - VkCommandBuffer commandBuffer, - const VkRenderPassBeginInfo* pRenderPassBegin, - const VkSubpassBeginInfo* pSubpassBeginInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2(VkCommandBuffer commandBuffer, + const VkRenderPassBeginInfo* pRenderPassBegin, + const VkSubpassBeginInfo* pSubpassBeginInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); auto& tracker = layer->getStateTracker(); @@ -201,16 +194,15 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2KHR( - VkCommandBuffer commandBuffer, - const VkRenderPassBeginInfo* pRenderPassBegin, - const VkSubpassBeginInfo* pSubpassBeginInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2KHR(VkCommandBuffer commandBuffer, + const VkRenderPassBeginInfo* pRenderPassBegin, + const VkSubpassBeginInfo* pSubpassBeginInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); auto& tracker = layer->getStateTracker(); @@ -230,15 +222,14 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderPass2KHR( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRendering( - VkCommandBuffer commandBuffer, - const VkRenderingInfo* pRenderingInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRendering(VkCommandBuffer commandBuffer, + const VkRenderingInfo* pRenderingInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); auto& tracker = layer->getStateTracker(); @@ -253,8 +244,7 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRendering( uint32_t height = pRenderingInfo->renderArea.extent.height; // Notify the command buffer we are starting a new render pass - uint64_t tagID = cb.renderPassBegin( - rp, width, height, resuming, suspending); + uint64_t tagID = cb.renderPassBegin(rp, width, height, resuming, suspending); // Release the lock to call into the driver lock.unlock(); @@ -267,15 +257,14 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRendering( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderingKHR( - VkCommandBuffer commandBuffer, - const VkRenderingInfo* pRenderingInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderingKHR(VkCommandBuffer commandBuffer, + const VkRenderingInfo* pRenderingInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); auto& tracker = layer->getStateTracker(); @@ -290,8 +279,7 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderingKHR( uint32_t height = pRenderingInfo->renderArea.extent.height; // Notify the command buffer we are starting a new render pass - uint64_t tagID = cb.renderPassBegin( - rp, width, height, resuming, suspending); + uint64_t tagID = cb.renderPassBegin(rp, width, height, resuming, suspending); // Release the lock to call into the driver lock.unlock(); @@ -304,14 +292,13 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdBeginRenderingKHR( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRenderPass( - VkCommandBuffer commandBuffer -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRenderPass(VkCommandBuffer commandBuffer) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Update the layer command stream in the tracker @@ -326,14 +313,13 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRenderPass( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRendering( - VkCommandBuffer commandBuffer -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRendering(VkCommandBuffer commandBuffer) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Update the layer command stream in the tracker @@ -351,14 +337,13 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRendering( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRenderingKHR( - VkCommandBuffer commandBuffer -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdEndRenderingKHR(VkCommandBuffer commandBuffer) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Update the layer command stream in the tracker diff --git a/layer_gpu_timeline/source/layer_device_functions_trace_rays.cpp b/layer_gpu_timeline/source/layer_device_functions_trace_rays.cpp index e6df5e3..b37e4de 100644 --- a/layer_gpu_timeline/source/layer_device_functions_trace_rays.cpp +++ b/layer_gpu_timeline/source/layer_device_functions_trace_rays.cpp @@ -23,14 +23,14 @@ * ---------------------------------------------------------------------------- */ +#include "device.hpp" +#include "device_utils.hpp" +#include "framework/device_dispatch_table.hpp" + #include #include #include -#include "device.hpp" -#include "device_utils.hpp" -#include "layer_device_functions.hpp" - extern std::mutex g_vulkanLock; /** @@ -44,28 +44,26 @@ extern std::mutex g_vulkanLock; * * @return The assigned tagID for the workload. */ -static uint64_t registerTraceRays( - Device* layer, - VkCommandBuffer commandBuffer, - int64_t itemsX, - int64_t itemsY, - int64_t itemsZ -) { +static uint64_t registerTraceRays(Device* layer, + VkCommandBuffer commandBuffer, + int64_t itemsX, + int64_t itemsY, + int64_t itemsZ) +{ auto& tracker = layer->getStateTracker(); auto& cb = tracker.getCommandBuffer(commandBuffer); return cb.traceRays(itemsX, itemsY, itemsZ); } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysIndirect2KHR( - VkCommandBuffer commandBuffer, - VkDeviceAddress indirectDeviceAddress -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysIndirect2KHR(VkCommandBuffer commandBuffer, + VkDeviceAddress indirectDeviceAddress) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); uint64_t tagID = registerTraceRays(layer, commandBuffer, -1, -1, -1); @@ -78,19 +76,19 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysIndirect2KHR( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysIndirectKHR( - VkCommandBuffer commandBuffer, - const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable, - VkDeviceAddress indirectDeviceAddress -) { +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdTraceRaysIndirectKHR(VkCommandBuffer commandBuffer, + const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable, + VkDeviceAddress indirectDeviceAddress) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); uint64_t tagID = registerTraceRays(layer, commandBuffer, -1, -1, -1); @@ -98,26 +96,31 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysIndirectKHR( // Release the lock to call into the driver lock.unlock(); emitStartTag(layer, commandBuffer, tagID); - layer->driver.vkCmdTraceRaysIndirectKHR(commandBuffer, pRaygenShaderBindingTable, pMissShaderBindingTable, pHitShaderBindingTable, pCallableShaderBindingTable, indirectDeviceAddress); + layer->driver.vkCmdTraceRaysIndirectKHR(commandBuffer, + pRaygenShaderBindingTable, + pMissShaderBindingTable, + pHitShaderBindingTable, + pCallableShaderBindingTable, + indirectDeviceAddress); layer->driver.vkCmdEndDebugUtilsLabelEXT(commandBuffer); } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysKHR( - VkCommandBuffer commandBuffer, - const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable, - const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable, - uint32_t width, - uint32_t height, - uint32_t depth -) { +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdTraceRaysKHR(VkCommandBuffer commandBuffer, + const VkStridedDeviceAddressRegionKHR* pRaygenShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pMissShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pHitShaderBindingTable, + const VkStridedDeviceAddressRegionKHR* pCallableShaderBindingTable, + uint32_t width, + uint32_t height, + uint32_t depth) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); uint64_t tagID = registerTraceRays(layer, commandBuffer, width, height, depth); @@ -125,6 +128,13 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdTraceRaysKHR( // Release the lock to call into the driver lock.unlock(); emitStartTag(layer, commandBuffer, tagID); - layer->driver.vkCmdTraceRaysKHR(commandBuffer, pRaygenShaderBindingTable, pMissShaderBindingTable, pHitShaderBindingTable, pCallableShaderBindingTable, width, height, depth); + layer->driver.vkCmdTraceRaysKHR(commandBuffer, + pRaygenShaderBindingTable, + pMissShaderBindingTable, + pHitShaderBindingTable, + pCallableShaderBindingTable, + width, + height, + depth); layer->driver.vkCmdEndDebugUtilsLabelEXT(commandBuffer); -} \ No newline at end of file +} diff --git a/layer_gpu_timeline/source/layer_device_functions_transfer.cpp b/layer_gpu_timeline/source/layer_device_functions_transfer.cpp index ecfaa65..791a1f1 100644 --- a/layer_gpu_timeline/source/layer_device_functions_transfer.cpp +++ b/layer_gpu_timeline/source/layer_device_functions_transfer.cpp @@ -23,14 +23,14 @@ * ---------------------------------------------------------------------------- */ +#include "device.hpp" +#include "device_utils.hpp" +#include "framework/device_dispatch_table.hpp" + #include #include #include -#include "device.hpp" -#include "device_utils.hpp" -#include "layer_device_functions.hpp" - extern std::mutex g_vulkanLock; /** @@ -43,12 +43,11 @@ extern std::mutex g_vulkanLock; * * @return The assigned tagID for the workload. */ -static uint64_t registerBufferTransfer( - Device* layer, - VkCommandBuffer commandBuffer, - const std::string& transferType, - int64_t byteCount -) { +static uint64_t registerBufferTransfer(Device* layer, + VkCommandBuffer commandBuffer, + const std::string& transferType, + int64_t byteCount) +{ auto& tracker = layer->getStateTracker(); auto& cb = tracker.getCommandBuffer(commandBuffer); return cb.bufferTransfer(transferType, byteCount); @@ -64,12 +63,11 @@ static uint64_t registerBufferTransfer( * * @return The assigned tagID for the workload. */ -static uint64_t registerImageTransfer( - Device* layer, - VkCommandBuffer commandBuffer, - const std::string& transferType, - int64_t pixelCount -) { +static uint64_t registerImageTransfer(Device* layer, + VkCommandBuffer commandBuffer, + const std::string& transferType, + int64_t pixelCount) +{ auto& tracker = layer->getStateTracker(); auto& cb = tracker.getCommandBuffer(commandBuffer); return cb.imageTransfer(transferType, pixelCount); @@ -78,18 +76,17 @@ static uint64_t registerImageTransfer( // Commands for transfers /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdFillBuffer( - VkCommandBuffer commandBuffer, - VkBuffer dstBuffer, - VkDeviceSize dstOffset, - VkDeviceSize size, - uint32_t data -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdFillBuffer(VkCommandBuffer commandBuffer, + VkBuffer dstBuffer, + VkDeviceSize dstOffset, + VkDeviceSize size, + uint32_t data) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Compute the size of the transfer @@ -100,11 +97,7 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdFillBuffer( byteCount = -2; } - uint64_t tagID = registerBufferTransfer( - layer, - commandBuffer, - "Fill buffer", - byteCount); + uint64_t tagID = registerBufferTransfer(layer, commandBuffer, "Fill buffer", byteCount); // Release the lock to call into the driver lock.unlock(); @@ -114,30 +107,25 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdFillBuffer( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdClearColorImage( - VkCommandBuffer commandBuffer, - VkImage image, - VkImageLayout imageLayout, - const VkClearColorValue* pColor, - uint32_t rangeCount, - const VkImageSubresourceRange* pRanges -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdClearColorImage(VkCommandBuffer commandBuffer, + VkImage image, + VkImageLayout imageLayout, + const VkClearColorValue* pColor, + uint32_t rangeCount, + const VkImageSubresourceRange* pRanges) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Compute the size of the transfer // TODO: Add image tracking so we can turn image and pRanges into pixels int64_t pixelCount = -1; - uint64_t tagID = registerImageTransfer( - layer, - commandBuffer, - "Clear image", - pixelCount); + uint64_t tagID = registerImageTransfer(layer, commandBuffer, "Clear image", pixelCount); // Release the lock to call into the driver lock.unlock(); @@ -147,30 +135,25 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdClearColorImage( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdClearDepthStencilImage( - VkCommandBuffer commandBuffer, - VkImage image, - VkImageLayout imageLayout, - const VkClearDepthStencilValue* pDepthStencil, - uint32_t rangeCount, - const VkImageSubresourceRange* pRanges -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdClearDepthStencilImage(VkCommandBuffer commandBuffer, + VkImage image, + VkImageLayout imageLayout, + const VkClearDepthStencilValue* pDepthStencil, + uint32_t rangeCount, + const VkImageSubresourceRange* pRanges) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Compute the size of the transfer // TODO: Add image tracking so we can turn image and pRanges into pixels int64_t pixelCount = -1; - uint64_t tagID = registerImageTransfer( - layer, - commandBuffer, - "Clear image", - pixelCount); + uint64_t tagID = registerImageTransfer(layer, commandBuffer, "Clear image", pixelCount); // Release the lock to call into the driver lock.unlock(); @@ -180,18 +163,17 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdClearDepthStencilImage( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer( - VkCommandBuffer commandBuffer, - VkBuffer srcBuffer, - VkBuffer dstBuffer, - uint32_t regionCount, - const VkBufferCopy* pRegions -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer(VkCommandBuffer commandBuffer, + VkBuffer srcBuffer, + VkBuffer dstBuffer, + uint32_t regionCount, + const VkBufferCopy* pRegions) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Compute the size of the transfer @@ -201,11 +183,7 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer( byteCount += static_cast(pRegions[i].size); } - uint64_t tagID = registerBufferTransfer( - layer, - commandBuffer, - "Copy buffer", - byteCount); + uint64_t tagID = registerBufferTransfer(layer, commandBuffer, "Copy buffer", byteCount); // Release the lock to call into the driver lock.unlock(); @@ -215,15 +193,14 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2( - VkCommandBuffer commandBuffer, - const VkCopyBufferInfo2* pCopyBufferInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2(VkCommandBuffer commandBuffer, + const VkCopyBufferInfo2* pCopyBufferInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Compute the size of the transfer @@ -233,11 +210,7 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2( byteCount += static_cast(pCopyBufferInfo->pRegions[i].size); } - uint64_t tagID = registerBufferTransfer( - layer, - commandBuffer, - "Copy buffer", - byteCount); + uint64_t tagID = registerBufferTransfer(layer, commandBuffer, "Copy buffer", byteCount); // Release the lock to call into the driver lock.unlock(); @@ -247,15 +220,14 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2KHR( - VkCommandBuffer commandBuffer, - const VkCopyBufferInfo2* pCopyBufferInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2KHR(VkCommandBuffer commandBuffer, + const VkCopyBufferInfo2* pCopyBufferInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Compute the size of the transfer @@ -265,11 +237,7 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2KHR( byteCount += static_cast(pCopyBufferInfo->pRegions[i].size); } - uint64_t tagID = registerBufferTransfer( - layer, - commandBuffer, - "Copy buffer", - byteCount); + uint64_t tagID = registerBufferTransfer(layer, commandBuffer, "Copy buffer", byteCount); // Release the lock to call into the driver lock.unlock(); @@ -279,19 +247,18 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBuffer2KHR( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage( - VkCommandBuffer commandBuffer, - VkBuffer srcBuffer, - VkImage dstImage, - VkImageLayout dstImageLayout, - uint32_t regionCount, - const VkBufferImageCopy* pRegions -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer, + VkBuffer srcBuffer, + VkImage dstImage, + VkImageLayout dstImageLayout, + uint32_t regionCount, + const VkBufferImageCopy* pRegions) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Compute the size of the transfer @@ -304,11 +271,7 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage( pixelCount += rPixelCount; } - uint64_t tagID = registerImageTransfer( - layer, - commandBuffer, - "Copy buffer to image", - pixelCount); + uint64_t tagID = registerImageTransfer(layer, commandBuffer, "Copy buffer to image", pixelCount); // Release the lock to call into the driver lock.unlock(); @@ -318,15 +281,15 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage2( - VkCommandBuffer commandBuffer, - const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdCopyBufferToImage2(VkCommandBuffer commandBuffer, + const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Compute the size of the transfer @@ -339,11 +302,7 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage2( pixelCount += rPixelCount; } - uint64_t tagID = registerImageTransfer( - layer, - commandBuffer, - "Copy buffer to image", - pixelCount); + uint64_t tagID = registerImageTransfer(layer, commandBuffer, "Copy buffer to image", pixelCount); // Release the lock to call into the driver lock.unlock(); @@ -353,15 +312,15 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage2( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage2KHR( - VkCommandBuffer commandBuffer, - const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdCopyBufferToImage2KHR(VkCommandBuffer commandBuffer, + const VkCopyBufferToImageInfo2* pCopyBufferToImageInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Compute the size of the transfer @@ -374,11 +333,7 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage2KHR( pixelCount += rPixelCount; } - uint64_t tagID = registerImageTransfer( - layer, - commandBuffer, - "Copy buffer to image", - pixelCount); + uint64_t tagID = registerImageTransfer(layer, commandBuffer, "Copy buffer to image", pixelCount); // Release the lock to call into the driver lock.unlock(); @@ -388,20 +343,19 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyBufferToImage2KHR( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage( - VkCommandBuffer commandBuffer, - VkImage srcImage, - VkImageLayout srcImageLayout, - VkImage dstImage, - VkImageLayout dstImageLayout, - uint32_t regionCount, - const VkImageCopy* pRegions -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage(VkCommandBuffer commandBuffer, + VkImage srcImage, + VkImageLayout srcImageLayout, + VkImage dstImage, + VkImageLayout dstImageLayout, + uint32_t regionCount, + const VkImageCopy* pRegions) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Compute the size of the transfer @@ -414,29 +368,25 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage( pixelCount += rPixelCount; } - uint64_t tagID = registerImageTransfer( - layer, - commandBuffer, - "Copy image", - pixelCount); + uint64_t tagID = registerImageTransfer(layer, commandBuffer, "Copy image", pixelCount); // Release the lock to call into the driver lock.unlock(); emitStartTag(layer, commandBuffer, tagID); - layer->driver.vkCmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions); + layer->driver + .vkCmdCopyImage(commandBuffer, srcImage, srcImageLayout, dstImage, dstImageLayout, regionCount, pRegions); layer->driver.vkCmdEndDebugUtilsLabelEXT(commandBuffer); } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2( - VkCommandBuffer commandBuffer, - const VkCopyImageInfo2* pCopyImageInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2(VkCommandBuffer commandBuffer, + const VkCopyImageInfo2* pCopyImageInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Compute the size of the transfer @@ -449,11 +399,7 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2( pixelCount += rPixelCount; } - uint64_t tagID = registerImageTransfer( - layer, - commandBuffer, - "Copy image", - pixelCount); + uint64_t tagID = registerImageTransfer(layer, commandBuffer, "Copy image", pixelCount); // Release the lock to call into the driver lock.unlock(); @@ -463,15 +409,14 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2KHR( - VkCommandBuffer commandBuffer, - const VkCopyImageInfo2* pCopyImageInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2KHR(VkCommandBuffer commandBuffer, + const VkCopyImageInfo2* pCopyImageInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Compute the size of the transfer @@ -484,11 +429,7 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2KHR( pixelCount += rPixelCount; } - uint64_t tagID = registerImageTransfer( - layer, - commandBuffer, - "Copy image", - pixelCount); + uint64_t tagID = registerImageTransfer(layer, commandBuffer, "Copy image", pixelCount); // Release the lock to call into the driver lock.unlock(); @@ -498,19 +439,18 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImage2KHR( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer( - VkCommandBuffer commandBuffer, - VkImage srcImage, - VkImageLayout srcImageLayout, - VkBuffer dstBuffer, - uint32_t regionCount, - const VkBufferImageCopy* pRegions -) { +template<> +VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, + VkImage srcImage, + VkImageLayout srcImageLayout, + VkBuffer dstBuffer, + uint32_t regionCount, + const VkBufferImageCopy* pRegions) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Compute the size of the transfer @@ -527,11 +467,7 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer( // type, which means this should be a bufferTransfer reporting size in // bytes. Without image tracking we only have pixels, so for now we report // as "Copy image" and report size in pixels. - uint64_t tagID = registerImageTransfer( - layer, - commandBuffer, - "Copy image to buffer", - pixelCount); + uint64_t tagID = registerImageTransfer(layer, commandBuffer, "Copy image to buffer", pixelCount); // Release the lock to call into the driver lock.unlock(); @@ -541,15 +477,15 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer2( - VkCommandBuffer commandBuffer, - const VkCopyImageToBufferInfo2* pCopyImageToBufferInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdCopyImageToBuffer2(VkCommandBuffer commandBuffer, + const VkCopyImageToBufferInfo2* pCopyImageToBufferInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Compute the size of the transfer @@ -566,11 +502,7 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer2( // type, which means this should be a bufferTransfer reporting size in // bytes. Without image tracking we only have pixels, so for now we report // as "Copy image" and report size in pixels. - uint64_t tagID = registerImageTransfer( - layer, - commandBuffer, - "Copy image to buffer", - pixelCount); + uint64_t tagID = registerImageTransfer(layer, commandBuffer, "Copy image to buffer", pixelCount); // Release the lock to call into the driver lock.unlock(); @@ -580,15 +512,15 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer2( } /* See Vulkan API for documentation. */ -template <> -VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer2KHR( - VkCommandBuffer commandBuffer, - const VkCopyImageToBufferInfo2* pCopyImageToBufferInfo -) { +template<> +VKAPI_ATTR void VKAPI_CALL + layer_vkCmdCopyImageToBuffer2KHR(VkCommandBuffer commandBuffer, + const VkCopyImageToBufferInfo2* pCopyImageToBufferInfo) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(commandBuffer); // Compute the size of the transfer @@ -605,11 +537,7 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdCopyImageToBuffer2KHR( // type, which means this should be a bufferTransfer reporting size in // bytes. Without image tracking we only have pixels, so for now we report // as "Copy image" and report size in pixels. - uint64_t tagID = registerImageTransfer( - layer, - commandBuffer, - "Copy image to buffer", - pixelCount); + uint64_t tagID = registerImageTransfer(layer, commandBuffer, "Copy image to buffer", pixelCount); // Release the lock to call into the driver lock.unlock(); diff --git a/layer_gpu_timeline/source/timeline_comms.cpp b/layer_gpu_timeline/source/timeline_comms.cpp index 125acef..6ad1e40 100644 --- a/layer_gpu_timeline/source/timeline_comms.cpp +++ b/layer_gpu_timeline/source/timeline_comms.cpp @@ -23,15 +23,13 @@ * ---------------------------------------------------------------------------- */ -#include - #include "timeline_comms.hpp" +#include + /* See header for documentation. */ -TimelineComms::TimelineComms( - Comms::CommsInterface& _comms -): - comms(_comms) +TimelineComms::TimelineComms(Comms::CommsInterface& _comms) + : comms(_comms) { if (comms.isConnected()) { @@ -40,8 +38,7 @@ TimelineComms::TimelineComms( } /* See header for documentation. */ -void TimelineComms::txMessage( - const std::string& message) +void TimelineComms::txMessage(const std::string& message) { // Message endpoint is not available if (endpoint == 0) diff --git a/layer_gpu_timeline/source/timeline_comms.hpp b/layer_gpu_timeline/source/timeline_comms.hpp index 84a3c8a..c06537b 100644 --- a/layer_gpu_timeline/source/timeline_comms.hpp +++ b/layer_gpu_timeline/source/timeline_comms.hpp @@ -47,22 +47,20 @@ class TimelineComms * * @param comms The common comms module used by all services. */ - TimelineComms( - Comms::CommsInterface& comms); + TimelineComms(Comms::CommsInterface& comms); /** * @brief Send a message to the GPU timeline endpoint service. * * @param message The message to send. */ - void txMessage( - const std::string& message); + void txMessage(const std::string& message); private: /** * @brief The endpoint ID of the service, or 0 if not found. */ - Comms::EndpointID endpoint { 0 }; + Comms::EndpointID endpoint {0}; /** * @brief The common module for network messaging. diff --git a/source_common/CMakeLists.txt b/source_common/CMakeLists.txt index a408717..a9f0672 100644 --- a/source_common/CMakeLists.txt +++ b/source_common/CMakeLists.txt @@ -25,5 +25,7 @@ # depends on per-layer implementations of the root intercept Instance and # Device classes which get specialized for each use case. +include(../cmake/clang-tools.cmake) + add_subdirectory(comms) add_subdirectory(trackers) diff --git a/source_common/comms/CMakeLists.txt b/source_common/comms/CMakeLists.txt index 4a95390..6bccecb 100644 --- a/source_common/comms/CMakeLists.txt +++ b/source_common/comms/CMakeLists.txt @@ -40,3 +40,5 @@ lgl_set_build_options(${LIB_BINARY}) if(${LGL_UNITTEST}) add_subdirectory(test) endif() + +add_clang_tools() \ No newline at end of file diff --git a/source_common/comms/comms_interface.hpp b/source_common/comms/comms_interface.hpp index 187bf31..20a237b 100644 --- a/source_common/comms/comms_interface.hpp +++ b/source_common/comms/comms_interface.hpp @@ -55,7 +55,7 @@ using MessageData = std::vector; * Note that this hides the built-in registry service, which uses endpoint * zero, because a normaluser should not be calling it. */ -static const EndpointID NO_ENDPOINT { 0 }; +static const EndpointID NO_ENDPOINT {0}; /** * @brief Abstract base class defining the public interface for comms. @@ -79,8 +79,7 @@ class CommsInterface * * @return The service address, or @c NO_ENDPOINT if service is not found. */ - virtual EndpointID getEndpointID( - const std::string& name) = 0; + virtual EndpointID getEndpointID(const std::string& name) = 0; /** * @brief Asynchronously transmit message to the host. @@ -91,9 +90,7 @@ class CommsInterface * @param endpoint The address of the destination service. * @param data The data to transmit. */ - virtual void txAsync( - EndpointID endpoint, - std::unique_ptr data) = 0; + virtual void txAsync(EndpointID endpoint, std::unique_ptr data) = 0; /** * @brief Synchronously transmit message to the host. @@ -105,9 +102,7 @@ class CommsInterface * @param endpoint The address of the destination service. * @param data The data to transmit. */ - virtual void tx( - EndpointID endpoint, - std::unique_ptr data) = 0; + virtual void tx(EndpointID endpoint, std::unique_ptr data) = 0; /** * @brief Synchronously transmit message to the host and wait for response. @@ -122,9 +117,7 @@ class CommsInterface * * @return The response message data payload. */ - virtual std::unique_ptr txRx( - EndpointID endpoint, - std::unique_ptr data) = 0; + virtual std::unique_ptr txRx(EndpointID endpoint, std::unique_ptr data) = 0; }; -} \ No newline at end of file +} diff --git a/source_common/comms/comms_message.cpp b/source_common/comms/comms_message.cpp index 03f0e9f..e6f1f9e 100644 --- a/source_common/comms/comms_message.cpp +++ b/source_common/comms/comms_message.cpp @@ -33,18 +33,15 @@ namespace Comms { -Message::Message( - EndpointID _endpointID, - MessageType _messageType, - MessageID _messageID, - std::unique_ptr _transmitData -) : - endpointID(_endpointID), - messageType(_messageType), - messageID(_messageID), - transmitData(std::move(_transmitData)) +Message::Message(EndpointID _endpointID, + MessageType _messageType, + MessageID _messageID, + std::unique_ptr _transmitData) + : endpointID(_endpointID), + messageType(_messageType), + messageID(_messageID), + transmitData(std::move(_transmitData)) { - } } diff --git a/source_common/comms/comms_message.hpp b/source_common/comms/comms_message.hpp index 22ef212..b9cd36d 100644 --- a/source_common/comms/comms_message.hpp +++ b/source_common/comms/comms_message.hpp @@ -29,8 +29,8 @@ */ #pragma once -#include "comms/comms_interface.hpp" #include "../utils/queue.hpp" +#include "comms/comms_interface.hpp" namespace Comms { @@ -43,7 +43,8 @@ using MessageID = uint64_t; /** * @brief A type used for message types in the protocol. */ -enum class MessageType: uint8_t { +enum class MessageType : uint8_t +{ /** Message is an asynchronous transmit. */ TX_ASYNC = 0, /** Message is a synchronous transmit. */ @@ -59,16 +60,16 @@ enum class MessageType: uint8_t { */ typedef struct __attribute__((packed)) { - uint8_t messageType; // Is this tx_async (0), tx (1), or tx_rx (2)? - uint8_t endpointID; // The endpoint service address. - uint64_t messageID; // The unique message ID for a tx_rx pair. - uint32_t payloadSize; // The size of the payload in bytes. + uint8_t messageType; // Is this tx_async (0), tx (1), or tx_rx (2)? + uint8_t endpointID; // The endpoint service address. + uint64_t messageID; // The unique message ID for a tx_rx pair. + uint32_t payloadSize; // The size of the payload in bytes. } MessageHeader; /** * @brief Class representing a task in the protocol. */ -class Message: public Task +class Message : public Task { public: /** @@ -79,11 +80,10 @@ class Message: public Task * @param messageID The sequence ID of the message. * @param transmitData The data to transmit. */ - Message( - EndpointID endpointID, - MessageType messageType, - MessageID messageID, - std::unique_ptr transmitData); + Message(EndpointID endpointID, + MessageType messageType, + MessageID messageID, + std::unique_ptr transmitData); /** * @brief The type of the message. diff --git a/source_common/comms/comms_module.cpp b/source_common/comms/comms_module.cpp index 335b79f..85e12f6 100644 --- a/source_common/comms/comms_module.cpp +++ b/source_common/comms/comms_module.cpp @@ -28,24 +28,24 @@ * The implementation of the main communications module. */ -#include +#include "comms_module.hpp" + +#include "framework/utils.hpp" + +#include #include + +#include #include #include #include -#include - -#include "framework/utils.hpp" -#include "comms_module.hpp" - namespace Comms { /* See header for documentation. */ -CommsModule::CommsModule( - const std::string& domainAddress -) { +CommsModule::CommsModule(const std::string& domainAddress) +{ sockfd = socket(AF_UNIX, SOCK_STREAM, 0); if (sockfd < 0) { @@ -53,17 +53,18 @@ CommsModule::CommsModule( return; } - struct sockaddr_un servAddr {}; + struct sockaddr_un servAddr + { + }; servAddr.sun_family = AF_UNIX; // Copy the domain address, inserting leading NUL needed for abstract UDS std::strcpy(servAddr.sun_path + 1, domainAddress.c_str()); servAddr.sun_path[0] = '\0'; - int conn = connect( - sockfd, - reinterpret_cast(&servAddr), - offsetof(struct sockaddr_un, sun_path) + domainAddress.size() + 1); + int conn = connect(sockfd, + reinterpret_cast(&servAddr), + offsetof(struct sockaddr_un, sun_path) + domainAddress.size() + 1); if (conn != 0) { LAYER_LOG(" - ERROR: Client UDS connection failed"); @@ -77,10 +78,8 @@ CommsModule::CommsModule( } /* See header for documentation. */ -CommsModule::CommsModule( - const std::string& hostAddress, - int port -) { +CommsModule::CommsModule(const std::string& hostAddress, int port) +{ sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) { @@ -88,15 +87,14 @@ CommsModule::CommsModule( return; } - struct sockaddr_in servAddr {}; + struct sockaddr_in servAddr + { + }; servAddr.sin_family = AF_INET; servAddr.sin_port = htons(port); servAddr.sin_addr.s_addr = inet_addr(hostAddress.c_str()); - int conn = connect( - sockfd, - reinterpret_cast(&servAddr), - sizeof(servAddr)); + int conn = connect(sockfd, reinterpret_cast(&servAddr), sizeof(servAddr)); if (conn != 0) { LAYER_LOG(" - ERROR: Client TCP connection failed"); @@ -139,9 +137,8 @@ bool CommsModule::isConnected() } /* See header for documentation. */ -EndpointID CommsModule::getEndpointID( - const std::string& name -) { +EndpointID CommsModule::getEndpointID(const std::string& name) +{ std::lock_guard lock(registryLock); if (registry.empty()) { @@ -159,10 +156,8 @@ EndpointID CommsModule::getEndpointID( } uint8_t svcId = (*resp)[0]; - size_t size = static_cast((*resp)[4] << 24) - | static_cast((*resp)[3] << 16) - | static_cast((*resp)[2] << 8) - | static_cast((*resp)[1] << 0); + size_t size = static_cast((*resp)[4] << 24) | static_cast((*resp)[3] << 16) + | static_cast((*resp)[2] << 8) | static_cast((*resp)[1] << 0); // If not enough bytes to read the service name then stop if (resp->size() < 5 + size) @@ -186,51 +181,33 @@ EndpointID CommsModule::getEndpointID( return registry[name]; } // Service not found - catch(std::out_of_range const&) + catch (const std::out_of_range&) { return NO_ENDPOINT; } } /* See header for documentation. */ -void CommsModule::txAsync( - EndpointID endpoint, - std::unique_ptr data -) { - auto message = std::make_shared( - endpoint, - MessageType::TX_ASYNC, - 0, - std::move(data)); +void CommsModule::txAsync(EndpointID endpoint, std::unique_ptr data) +{ + auto message = std::make_shared(endpoint, MessageType::TX_ASYNC, 0, std::move(data)); enqueueMessage(std::move(message)); } /* See header for documentation. */ -void CommsModule::tx( - EndpointID endpoint, - std::unique_ptr data -) { - auto message = std::make_shared( - endpoint, - MessageType::TX, - 0, - std::move(data)); +void CommsModule::tx(EndpointID endpoint, std::unique_ptr data) +{ + auto message = std::make_shared(endpoint, MessageType::TX, 0, std::move(data)); enqueueMessage(message); message->wait(); } /* See header for documentation. */ -std::unique_ptr CommsModule::txRx( - EndpointID endpoint, - std::unique_ptr data -) { - auto message = std::make_shared( - endpoint, - MessageType::TX_RX, - assignMessageID(), - std::move(data)); +std::unique_ptr CommsModule::txRx(EndpointID endpoint, std::unique_ptr data) +{ + auto message = std::make_shared(endpoint, MessageType::TX_RX, assignMessageID(), std::move(data)); enqueueMessage(message); message->wait(); @@ -245,9 +222,8 @@ MessageID CommsModule::assignMessageID() } /* See header for documentation. */ -void CommsModule::enqueueMessage( - std::shared_ptr message -) { +void CommsModule::enqueueMessage(std::shared_ptr message) +{ messageQueue.put(std::move(message)); } diff --git a/source_common/comms/comms_module.hpp b/source_common/comms/comms_module.hpp index 7cb86a4..68c7aab 100644 --- a/source_common/comms/comms_module.hpp +++ b/source_common/comms/comms_module.hpp @@ -77,8 +77,8 @@ #include "comms/comms_interface.hpp" #include "comms/comms_message.hpp" -#include "comms/comms_transmitter.hpp" #include "comms/comms_receiver.hpp" +#include "comms/comms_transmitter.hpp" #include "utils/queue.hpp" namespace Comms @@ -89,7 +89,7 @@ namespace Comms * * Exposes the CommsInterface to calling code. */ -class CommsModule: public CommsInterface +class CommsModule : public CommsInterface { public: /** @@ -101,8 +101,7 @@ class CommsModule: public CommsInterface * * @param domainAddress The unix domain address to use. */ - CommsModule( - const std::string& domainAddress); + CommsModule(const std::string& domainAddress); /** * @brief Construct a new instance using a TCP/IP socket. @@ -110,9 +109,7 @@ class CommsModule: public CommsInterface * @param hostAddress The host name or IP address to use. * @param port The port number to use. */ - CommsModule( - const std::string& hostAddress, - int port); + CommsModule(const std::string& hostAddress, int port); /** * @brief Close the host connection and stop all worker threads. @@ -127,23 +124,16 @@ class CommsModule: public CommsInterface virtual bool isConnected(); /** See @c comms_interface.hpp for documentation. */ - virtual EndpointID getEndpointID( - const std::string& name); + virtual EndpointID getEndpointID(const std::string& name); /** See @c comms_interface.hpp for documentation. */ - virtual void txAsync( - EndpointID endpoint, - std::unique_ptr data); + virtual void txAsync(EndpointID endpoint, std::unique_ptr data); /** See @c comms_interface.hpp for documentation. */ - virtual void tx( - EndpointID endpoint, - std::unique_ptr data); + virtual void tx(EndpointID endpoint, std::unique_ptr data); /** See @c comms_interface.hpp for documentation. */ - virtual std::unique_ptr txRx( - EndpointID endpoint, - std::unique_ptr data); + virtual std::unique_ptr txRx(EndpointID endpoint, std::unique_ptr data); // Allow module internal classes to access private members friend class Transmitter; @@ -162,8 +152,7 @@ class CommsModule: public CommsInterface * * @param message The message to queue. */ - void enqueueMessage( - std::shared_ptr message); + void enqueueMessage(std::shared_ptr message); /** * @brief Get the oldest message from the outbound message task queue. @@ -176,12 +165,12 @@ class CommsModule: public CommsInterface /** * @brief The socket for communications. */ - int sockfd { -1 }; + int sockfd {-1}; /** * @brief The next message ID nonce to use. */ - std::atomic nextMessageID { 1 }; + std::atomic nextMessageID {1}; /** * @brief The FIFO queue of messages to send. diff --git a/source_common/comms/comms_receiver.cpp b/source_common/comms/comms_receiver.cpp index d27b868..2b18d27 100644 --- a/source_common/comms/comms_receiver.cpp +++ b/source_common/comms/comms_receiver.cpp @@ -28,24 +28,24 @@ * The implementation of the communications module receiver worker. */ -#include -#include -#include -#include -#include - #include "comms/comms_receiver.hpp" + #include "comms/comms_module.hpp" #include "framework/utils.hpp" #include "utils/misc.hpp" +#include +#include +#include + +#include +#include + namespace Comms { /* See header for documentation. */ -Receiver::Receiver( - CommsModule& _parent -) : - parent(_parent) +Receiver::Receiver(CommsModule& _parent) + : parent(_parent) { int pipe_err = pipe(stopRequestPipe); if (pipe_err) @@ -87,11 +87,10 @@ void Receiver::stop() } /* See header for documentation. */ -void Receiver::parkMessage( - std::shared_ptr message -) { +void Receiver::parkMessage(std::shared_ptr message) +{ std::lock_guard lock(parkingLock); - parkingBuffer.insert({ message->messageID, std::move(message) }); + parkingBuffer.insert({message->messageID, std::move(message)}); } /* See header for documentation. */ @@ -123,10 +122,8 @@ void Receiver::runReceiver() } /* See header for documentation. */ -void Receiver::wakeMessage( - MessageID messageID, - std::unique_ptr data -) { +void Receiver::wakeMessage(MessageID messageID, std::unique_ptr data) +{ std::lock_guard lock(parkingLock); // Handle message not found ... @@ -146,10 +143,8 @@ void Receiver::wakeMessage( } /* See header for documentation. */ -bool Receiver::receiveData( - uint8_t* data, - size_t dataSize -) { +bool Receiver::receiveData(uint8_t* data, size_t dataSize) +{ int sockfd = parent.sockfd; int pipefd = stopRequestPipe[0]; int maxfd = std::max(sockfd, pipefd); diff --git a/source_common/comms/comms_receiver.hpp b/source_common/comms/comms_receiver.hpp index 5a84702..f2e3663 100644 --- a/source_common/comms/comms_receiver.hpp +++ b/source_common/comms/comms_receiver.hpp @@ -29,12 +29,12 @@ */ #pragma once +#include "comms/comms_message.hpp" + #include #include #include -#include "comms/comms_message.hpp" - namespace Comms { @@ -52,8 +52,7 @@ class Receiver * * @param parent The parent comms module. */ - Receiver( - CommsModule& parent); + Receiver(CommsModule& parent); /** * @brief Destroy this receiver. @@ -72,8 +71,7 @@ class Receiver * * @param message The message waiting for a response. */ - void parkMessage( - std::shared_ptr message); + void parkMessage(std::shared_ptr message); private: /** @@ -87,9 +85,7 @@ class Receiver * @param messageID The message to wake. * @param data The response data payload from the host. */ - void wakeMessage( - MessageID messageID, - std::unique_ptr data); + void wakeMessage(MessageID messageID, std::unique_ptr data); /** * @brief Receive N bytes of data from the socket. @@ -99,9 +95,7 @@ class Receiver * * @return @c true if we received a message, @c false otherwise. */ - bool receiveData( - uint8_t* data, - size_t dataSize); + bool receiveData(uint8_t* data, size_t dataSize); private: /** @@ -137,4 +131,4 @@ class Receiver std::unordered_map> parkingBuffer; }; -} \ No newline at end of file +} diff --git a/source_common/comms/comms_transmitter.cpp b/source_common/comms/comms_transmitter.cpp index 3088754..e7924c1 100644 --- a/source_common/comms/comms_transmitter.cpp +++ b/source_common/comms/comms_transmitter.cpp @@ -27,21 +27,21 @@ * @file * The implementation of the communications module transmitter worker. */ -#include -#include - #include "comms/comms_transmitter.hpp" + #include "comms/comms_module.hpp" #include "framework/utils.hpp" +#include + +#include + namespace Comms { /* See header for documentation. */ -Transmitter::Transmitter( - CommsModule& _parent -) : - parent(_parent) +Transmitter::Transmitter(CommsModule& _parent) + : parent(_parent) { // Create and start a worker thread worker = std::thread(&Transmitter::runTransmitter, this); @@ -96,8 +96,7 @@ void Transmitter::stop() // Use a dummy message to wake worker thread if blocked on the queue auto stopData = std::make_unique(); - auto message = std::make_shared( - 0, MessageType::STOP, 0, std::move(stopData)); + auto message = std::make_shared(0, MessageType::STOP, 0, std::move(stopData)); parent.enqueueMessage(message); // Join on the worker thread @@ -105,9 +104,8 @@ void Transmitter::stop() } /* See header for documentation. */ -void Transmitter::sendMessage( - const Message& message -) { +void Transmitter::sendMessage(const Message& message) +{ uint8_t* data = message.transmitData->data(); size_t dataSize = message.transmitData->size(); @@ -126,11 +124,9 @@ void Transmitter::sendMessage( } /* See header for documentation. */ -void Transmitter::sendData( - uint8_t* data, - size_t dataSize -) { - while(dataSize) +void Transmitter::sendData(uint8_t* data, size_t dataSize) +{ + while (dataSize) { ssize_t sentSize = send(parent.sockfd, data, dataSize, 0); // An error occurred or server disconnected diff --git a/source_common/comms/comms_transmitter.hpp b/source_common/comms/comms_transmitter.hpp index 13af90b..a594759 100644 --- a/source_common/comms/comms_transmitter.hpp +++ b/source_common/comms/comms_transmitter.hpp @@ -29,12 +29,12 @@ */ #pragma once +#include "comms/comms_message.hpp" + #include #include #include -#include "comms/comms_message.hpp" - namespace Comms { @@ -52,8 +52,7 @@ class Transmitter * * @param parent The parent comms module. */ - Transmitter( - CommsModule& parent); + Transmitter(CommsModule& parent); /** * @brief Destroy this transmitter. @@ -78,8 +77,7 @@ class Transmitter * * @param message The message to send. */ - void sendMessage( - const Message& message); + void sendMessage(const Message& message); /** * @brief Send N bytes of data to the socket. @@ -87,9 +85,7 @@ class Transmitter * @param data The data to send. * @param dataSize The number of bytes in the data. */ - void sendData( - uint8_t* data, - size_t dataSize); + void sendData(uint8_t* data, size_t dataSize); private: /** diff --git a/source_common/comms/test/CMakeLists.txt b/source_common/comms/test/CMakeLists.txt index d15218c..8c77684 100644 --- a/source_common/comms/test/CMakeLists.txt +++ b/source_common/comms/test/CMakeLists.txt @@ -76,3 +76,4 @@ install( TARGETS ${TEST_BINARY} DESTINATION bin) +add_clang_tools() \ No newline at end of file diff --git a/source_common/comms/test/comms_test_server.cpp b/source_common/comms/test/comms_test_server.cpp index 116cfb2..56c11e9 100644 --- a/source_common/comms/test/comms_test_server.cpp +++ b/source_common/comms/test/comms_test_server.cpp @@ -30,9 +30,10 @@ #include "comms/test/comms_test_server.hpp" -#include #include #include + +#include #include #include #include @@ -41,9 +42,8 @@ namespace CommsTest { /* See header for documentation. */ -CommsTestServer::CommsTestServer( - const std::string& domainAddress -) { +CommsTestServer::CommsTestServer(const std::string& domainAddress) +{ int pipeErr = pipe(stopRequestPipe); if (pipeErr) { @@ -59,7 +59,9 @@ CommsTestServer::CommsTestServer( } // Build the address to listen on - struct sockaddr_un servAddr {}; + struct sockaddr_un servAddr + { + }; servAddr.sun_family = AF_UNIX; // Copy the domain address, inserting leading NUL needed for abstract UDS @@ -67,10 +69,9 @@ CommsTestServer::CommsTestServer( servAddr.sun_path[0] = '\0'; // Bind the socket to the address - int bindErr = bind( - listenSockfd, - reinterpret_cast(&servAddr), - offsetof(struct sockaddr_un, sun_path) + domainAddress.size() + 1); + int bindErr = bind(listenSockfd, + reinterpret_cast(&servAddr), + offsetof(struct sockaddr_un, sun_path) + domainAddress.size() + 1); if (bindErr) { std::cout << " - ERROR: Svr socket bind failed" << std::endl; @@ -80,8 +81,8 @@ CommsTestServer::CommsTestServer( } // Listen on the socket - int listenErr = listen(listenSockfd, 5); - if(listenErr) + int listenErr = listen(listenSockfd, 5); + if (listenErr) { std::cout << " - ERROR: Svr socket listen failed" << std::endl; close(listenSockfd); @@ -95,9 +96,8 @@ CommsTestServer::CommsTestServer( } /* See header for documentation. */ -CommsTestServer::CommsTestServer( - int port -) { +CommsTestServer::CommsTestServer(int port) +{ int pipeErr = pipe(stopRequestPipe); if (pipeErr) { @@ -119,16 +119,15 @@ CommsTestServer::CommsTestServer( std::cout << " - WARN: Svr socket setsockopt failed" << std::endl; } - struct sockaddr_in servAddr {}; + struct sockaddr_in servAddr + { + }; servAddr.sin_family = AF_INET; servAddr.sin_port = htons(port); servAddr.sin_addr.s_addr = INADDR_ANY; // Bind the socket to the address - int bindErr = bind( - listenSockfd, - reinterpret_cast(&servAddr), - sizeof(struct sockaddr_in)); + int bindErr = bind(listenSockfd, reinterpret_cast(&servAddr), sizeof(struct sockaddr_in)); if (bindErr) { std::cout << " - ERROR: Svr socket bind failed " << std::endl; @@ -138,8 +137,8 @@ CommsTestServer::CommsTestServer( } // Listen on the socket - int listenErr = listen(listenSockfd, 5); - if(listenErr) + int listenErr = listen(listenSockfd, 5); + if (listenErr) { std::cout << " - ERROR: Svr socket listen failed" << std::endl; close(listenSockfd); @@ -190,7 +189,7 @@ void CommsTestServer::stop() void CommsTestServer::runServer() { int dataSockfd = accept(listenSockfd, NULL, NULL); - if(dataSockfd < 0) + if (dataSockfd < 0) { std::cout << " - ERROR: Svr socket accept failed" << std::endl; close(listenSockfd); @@ -220,10 +219,9 @@ void CommsTestServer::runServer() // Store the message for later checking std::string decodedPayload(payload->begin(), payload->end()); - received.emplace_back( - static_cast(header.endpointID), - static_cast(header.messageType), - std::move(payload)); + received.emplace_back(static_cast(header.endpointID), + static_cast(header.messageType), + std::move(payload)); // If this is a tx_rx message reverse payload and send it back ... if (header.messageType == static_cast(Comms::MessageType::TX_RX)) @@ -252,11 +250,8 @@ void CommsTestServer::runServer() } /* See header for documentation. */ -bool CommsTestServer::receiveData( - int sockfd, - uint8_t* data, - size_t dataSize -) { +bool CommsTestServer::receiveData(int sockfd, uint8_t* data, size_t dataSize) +{ int pipefd = stopRequestPipe[0]; int maxfd = std::max(sockfd, pipefd); @@ -298,12 +293,9 @@ bool CommsTestServer::receiveData( } /* See header for documentation. */ -void CommsTestServer::send_data( - int sockfd, - uint8_t* data, - size_t dataSize -) { - while(dataSize) +void CommsTestServer::send_data(int sockfd, uint8_t* data, size_t dataSize) +{ + while (dataSize) { ssize_t sentSize = send(sockfd, data, dataSize, 0); // An error occurred diff --git a/source_common/comms/test/comms_test_server.hpp b/source_common/comms/test/comms_test_server.hpp index 4cc779d..c55a2a9 100644 --- a/source_common/comms/test/comms_test_server.hpp +++ b/source_common/comms/test/comms_test_server.hpp @@ -30,12 +30,12 @@ #pragma once +#include "comms/comms_message.hpp" + #include #include #include -#include "comms/comms_message.hpp" - namespace CommsTest { @@ -52,13 +52,12 @@ class TestMessage * @param messageType The type of the message. * @param data The received data. */ - TestMessage( - Comms::EndpointID endpointID, - Comms::MessageType messageType, - std::unique_ptr data) : - endpointID(endpointID), - messageType(messageType), - data(std::move(data)) { } + TestMessage(Comms::EndpointID endpointID, Comms::MessageType messageType, std::unique_ptr data) + : endpointID(endpointID), + messageType(messageType), + data(std::move(data)) + { + } /** * @brief The endpoint of the message. @@ -76,7 +75,6 @@ class TestMessage std::unique_ptr data; }; - class CommsTestServer { public: @@ -88,16 +86,14 @@ class CommsTestServer * * @param domainAddress The unix domain address to use. */ - CommsTestServer( - const std::string& domainAddress); + CommsTestServer(const std::string& domainAddress); /** * @brief Construct a new server listening on TCP/IP socket. * * @param port The port number to use. */ - CommsTestServer( - int port); + CommsTestServer(int port); /** * @brief Close the host connection and stop all worker threads. @@ -128,10 +124,7 @@ class CommsTestServer * * @return @c true if we received a message, @c false otherwise. */ - bool receiveData( - int sockfd, - uint8_t* data, - size_t dataSize); + bool receiveData(int sockfd, uint8_t* data, size_t dataSize); /** * @brief Send N bytes of data to the socket. @@ -140,10 +133,7 @@ class CommsTestServer * @param data The data to send. * @param dataSize The number of bytes in the data. */ - void send_data( - int sockfd, - uint8_t* data, - size_t dataSize); + void send_data(int sockfd, uint8_t* data, size_t dataSize); public: /** @@ -155,7 +145,7 @@ class CommsTestServer /** * @brief The socket for listening for connections. */ - int listenSockfd { -1 }; + int listenSockfd {-1}; /** * @brief Pipe used to unblock the read socket rather than use timeouts. diff --git a/source_common/comms/test/unittest_comms.cpp b/source_common/comms/test/unittest_comms.cpp index a37ace7..af310e8 100644 --- a/source_common/comms/test/unittest_comms.cpp +++ b/source_common/comms/test/unittest_comms.cpp @@ -32,31 +32,28 @@ * A normal tx message guarantees that the messages is sent before returning, * but does not guarantee that the server has received and processed it. */ -#include - #include "comms/comms_interface.hpp" #include "comms/comms_module.hpp" #include "comms/test/comms_test_server.hpp" +#include + using namespace CommsTest; -std::unique_ptr makeTestPayload( - const std::string& str -) { +std::unique_ptr makeTestPayload(const std::string& str) +{ auto data = std::make_unique(str.begin(), str.end()); return data; } -std::string decodeTestPayload( - std::unique_ptr data -) { +std::string decodeTestPayload(std::unique_ptr data) +{ std::string str(data->begin(), data->end()); return str; } -std::string decodeTestPayload( - TestMessage& msg -) { +std::string decodeTestPayload(TestMessage& msg) +{ std::string str(msg.data->begin(), msg.data->end()); return str; } @@ -111,7 +108,7 @@ TEST(Comms, test_uds_tx_nb) EXPECT_EQ(server.received[0].endpointID, 2); EXPECT_EQ(server.received[0].data->size(), 4); - EXPECT_EQ(decodeTestPayload(server.received[0]),"abcd"); + EXPECT_EQ(decodeTestPayload(server.received[0]), "abcd"); } /** @brief Test lifecycle with a TX_ASYNC sent message. */ @@ -136,7 +133,7 @@ TEST(Comms, test_uds_tx_async_0b) EXPECT_EQ(server.received[1].endpointID, 2); EXPECT_EQ(server.received[1].data->size(), 4); - EXPECT_EQ(decodeTestPayload(server.received[1]),"abcd"); + EXPECT_EQ(decodeTestPayload(server.received[1]), "abcd"); } /** @brief Test lifecycle with a TX_ASYNC sent message. */ @@ -158,11 +155,11 @@ TEST(Comms, test_uds_tx_async_nb) EXPECT_EQ(server.received[0].endpointID, 1); EXPECT_EQ(server.received[0].data->size(), 4); - EXPECT_EQ(decodeTestPayload(server.received[0]),"abcd"); + EXPECT_EQ(decodeTestPayload(server.received[0]), "abcd"); EXPECT_EQ(server.received[1].endpointID, 2); EXPECT_EQ(server.received[1].data->size(), 3); - EXPECT_EQ(decodeTestPayload(server.received[1]),"efg"); + EXPECT_EQ(decodeTestPayload(server.received[1]), "efg"); } /** @brief Test lifecycle with a TX_RX sent message. */ @@ -202,11 +199,11 @@ TEST(Comms, test_uds_tx_rx_nb) EXPECT_EQ(server.received[0].endpointID, 1); EXPECT_EQ(server.received[0].data->size(), 4); - EXPECT_EQ(decodeTestPayload(server.received[0]),"abcd"); + EXPECT_EQ(decodeTestPayload(server.received[0]), "abcd"); // Validate it was responded to correctly EXPECT_EQ(resps.size(), 4); - EXPECT_EQ(resps,"dcba"); + EXPECT_EQ(resps, "dcba"); } // ---------------------------------------------------------------------------- @@ -258,7 +255,7 @@ TEST(Comms, test_tcp_tx_nb) EXPECT_EQ(server.received[0].endpointID, 2); EXPECT_EQ(server.received[0].data->size(), 4); - EXPECT_EQ(decodeTestPayload(server.received[0]),"abcd"); + EXPECT_EQ(decodeTestPayload(server.received[0]), "abcd"); } /** @brief Test lifecycle with a TX_ASYNC sent message. */ @@ -283,7 +280,7 @@ TEST(Comms, test_tcp_tx_async_0b) EXPECT_EQ(server.received[1].endpointID, 2); EXPECT_EQ(server.received[1].data->size(), 4); - EXPECT_EQ(decodeTestPayload(server.received[1]),"abcd"); + EXPECT_EQ(decodeTestPayload(server.received[1]), "abcd"); } /** @brief Test lifecycle with a TX_ASYNC sent message. */ @@ -305,11 +302,11 @@ TEST(Comms, test_tcp_tx_async_nb) EXPECT_EQ(server.received[0].endpointID, 1); EXPECT_EQ(server.received[0].data->size(), 4); - EXPECT_EQ(decodeTestPayload(server.received[0]),"abcd"); + EXPECT_EQ(decodeTestPayload(server.received[0]), "abcd"); EXPECT_EQ(server.received[1].endpointID, 2); EXPECT_EQ(server.received[1].data->size(), 3); - EXPECT_EQ(decodeTestPayload(server.received[1]),"efg"); + EXPECT_EQ(decodeTestPayload(server.received[1]), "efg"); } /** @brief Test lifecycle with a TX_RX sent message. */ @@ -349,9 +346,9 @@ TEST(Comms, test_tcp_tx_rx_nb) EXPECT_EQ(server.received[0].endpointID, 1); EXPECT_EQ(server.received[0].data->size(), 4); - EXPECT_EQ(decodeTestPayload(server.received[0]),"abcd"); + EXPECT_EQ(decodeTestPayload(server.received[0]), "abcd"); // Validate it was responded to correctly EXPECT_EQ(resps.size(), 4); - EXPECT_EQ(resps,"dcba"); + EXPECT_EQ(resps, "dcba"); } diff --git a/source_common/comms/test/unittest_comms_client.cpp b/source_common/comms/test/unittest_comms_client.cpp index 4675172..41369a2 100644 --- a/source_common/comms/test/unittest_comms_client.cpp +++ b/source_common/comms/test/unittest_comms_client.cpp @@ -35,21 +35,19 @@ * TODO: Get the test server to echo back tx and tx_async messages in a * subsequent tx_rx message. */ -#include - #include "comms/comms_interface.hpp" #include "comms/comms_module.hpp" -std::unique_ptr makeTestPayload( - const std::string& str -) { +#include + +std::unique_ptr makeTestPayload(const std::string& str) +{ auto data = std::make_unique(str.begin(), str.end()); return data; } -std::string decodeTestPayload( - std::unique_ptr data -) { +std::string decodeTestPayload(std::unique_ptr data) +{ std::string str(data->begin(), data->end()); return str; } @@ -135,4 +133,4 @@ TEST(CommsClient, test_tcp_tx_rx_nb) // Validate it was responded to correctly EXPECT_EQ(resps.size(), 4); EXPECT_EQ(resps, "dcba"); -} \ No newline at end of file +} diff --git a/source_common/framework/CMakeLists.txt b/source_common/framework/CMakeLists.txt index 6e2269a..a6de453 100644 --- a/source_common/framework/CMakeLists.txt +++ b/source_common/framework/CMakeLists.txt @@ -44,3 +44,5 @@ target_include_directories( ../../source_third_party/khronos/vulkan/include/) lgl_set_build_options(${LIB_BINARY}) + +add_clang_tools() \ No newline at end of file diff --git a/source_common/framework/device_dispatch_table.hpp b/source_common/framework/device_dispatch_table.hpp index 6ea6eaa..d5ea701 100644 --- a/source_common/framework/device_dispatch_table.hpp +++ b/source_common/framework/device_dispatch_table.hpp @@ -25,6 +25,8 @@ #pragma once +// clang-format off + #include #include "framework/device_functions.hpp" @@ -1427,3 +1429,5 @@ static inline void initDriverDeviceDispatchTable( } #undef ENTRY + +// clang-format on diff --git a/source_common/framework/device_functions.cpp b/source_common/framework/device_functions.cpp index 29276bf..ce1f3a2 100644 --- a/source_common/framework/device_functions.cpp +++ b/source_common/framework/device_functions.cpp @@ -23,6 +23,8 @@ * ---------------------------------------------------------------------------- */ +// clang-format off + #include // Include from per-layer code @@ -7773,3 +7775,4 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkWriteMicromapsPropertiesEXT_default( return layer->driver.vkWriteMicromapsPropertiesEXT(device, micromapCount, pMicromaps, queryType, dataSize, pData, stride); } +// clang-format on diff --git a/source_common/framework/device_functions.hpp b/source_common/framework/device_functions.hpp index a564535..ecd16c6 100644 --- a/source_common/framework/device_functions.hpp +++ b/source_common/framework/device_functions.hpp @@ -25,6 +25,8 @@ #pragma once +// clang-format off + #include /* See Vulkan API for documentation. */ @@ -7987,3 +7989,4 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkWriteMicromapsPropertiesEXT( return layer_vkWriteMicromapsPropertiesEXT_default(device, micromapCount, pMicromaps, queryType, dataSize, pData, stride); } +// clang-format on diff --git a/source_common/framework/device_query.cpp b/source_common/framework/device_query.cpp index 8d0443d..974f48c 100644 --- a/source_common/framework/device_query.cpp +++ b/source_common/framework/device_query.cpp @@ -23,28 +23,26 @@ * ---------------------------------------------------------------------------- */ -#include - #include "utils/misc.hpp" +#include + /** See header for documentation. */ -bool isEnabledVkKhrTimelineSemaphore( - const VkDeviceCreateInfo& createInfo -) { +bool isEnabledVkKhrTimelineSemaphore(const VkDeviceCreateInfo& createInfo) +{ // Check Vulkan 1.2 core feature first - auto* coreFeature = searchNextList( - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES, - createInfo.pNext); + auto* coreFeature = + searchNextList(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES, + createInfo.pNext); if (coreFeature) { return coreFeature->timelineSemaphore; } // Check the extension second - bool extEnabled = isInExtensionList( - VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME, - createInfo.enabledExtensionCount, - createInfo.ppEnabledExtensionNames); + bool extEnabled = isInExtensionList(VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME, + createInfo.enabledExtensionCount, + createInfo.ppEnabledExtensionNames); if (!extEnabled) { return false; diff --git a/source_common/framework/device_query.hpp b/source_common/framework/device_query.hpp index b48ee82..d939016 100644 --- a/source_common/framework/device_query.hpp +++ b/source_common/framework/device_query.hpp @@ -30,10 +30,10 @@ #pragma once -#include - #include "utils/misc.hpp" +#include + /** * Test if VK_KHR_timeline_semaphore (or equivalent core feature) is enabled. * @@ -41,5 +41,4 @@ * * @return @c true if enabled, @c false otherwise. */ -bool isEnabledVkKhrTimelineSemaphore( - const VkDeviceCreateInfo& createInfo0); +bool isEnabledVkKhrTimelineSemaphore(const VkDeviceCreateInfo& createInfo0); diff --git a/source_common/framework/entry.cpp b/source_common/framework/entry.cpp index d1090e6..5718822 100644 --- a/source_common/framework/entry.cpp +++ b/source_common/framework/entry.cpp @@ -30,74 +30,67 @@ * Note that the Android loader requires more functions to be exposed as * library symbols than other Vulkan loaders. */ -#include - #include "framework/device_functions.hpp" #include "framework/instance_functions.hpp" #include "framework/utils.hpp" -#if __has_include ("layer_device_functions.hpp") - #include "layer_device_functions.hpp" +#include + +#if __has_include("layer_device_functions.hpp") +# include "layer_device_functions.hpp" #endif -#if __has_include ("layer_instance_functions.hpp") - #include "layer_instance_functions.hpp" +#if __has_include("layer_instance_functions.hpp") +# include "layer_instance_functions.hpp" #endif std::mutex g_vulkanLock; -extern "C" { - +extern "C" +{ /** See Vulkan API for documentation. */ -VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr( - VkDevice device, - const char* pName -) { +VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char* pName) +{ return layer_vkGetDeviceProcAddr(device, pName); } /** See Vulkan API for documentation. */ -VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr( - VkInstance instance, - const char* pName -) { +VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char* pName) +{ return layer_vkGetInstanceProcAddr(instance, pName); } /** See Vulkan API for documentation. */ -VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties( - const char* pLayerName, - uint32_t* pPropertyCount, - VkExtensionProperties* pProperties -) { +VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL + vkEnumerateInstanceExtensionProperties(const char* pLayerName, + uint32_t* pPropertyCount, + VkExtensionProperties* pProperties) +{ return layer_vkEnumerateInstanceExtensionProperties(pLayerName, pPropertyCount, pProperties); } /** See Vulkan API for documentation. */ -VK_LAYER_EXPORT_ANDROID VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties( - VkPhysicalDevice gpu, - const char* pLayerName, - uint32_t* pPropertyCount, - VkExtensionProperties* pProperties -) { +VK_LAYER_EXPORT_ANDROID VKAPI_ATTR VkResult VKAPI_CALL + vkEnumerateDeviceExtensionProperties(VkPhysicalDevice gpu, + const char* pLayerName, + uint32_t* pPropertyCount, + VkExtensionProperties* pProperties) +{ return layer_vkEnumerateDeviceExtensionProperties(gpu, pLayerName, pPropertyCount, pProperties); } /** See Vulkan API for documentation. */ -VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties( - uint32_t* pPropertyCount, - VkLayerProperties* pProperties -) { +VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t* pPropertyCount, + VkLayerProperties* pProperties) +{ return layer_vkEnumerateInstanceLayerProperties(pPropertyCount, pProperties); } /** See Vulkan API for documentation. */ -VK_LAYER_EXPORT_ANDROID VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties( - VkPhysicalDevice gpu, - uint32_t* pPropertyCount, - VkLayerProperties* pProperties -) { +VK_LAYER_EXPORT_ANDROID VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice gpu, + uint32_t* pPropertyCount, + VkLayerProperties* pProperties) +{ return layer_vkEnumerateDeviceLayerProperties(gpu, pPropertyCount, pProperties); } - } diff --git a/source_common/framework/instance_dispatch_table.hpp b/source_common/framework/instance_dispatch_table.hpp index 92d0292..8114645 100644 --- a/source_common/framework/instance_dispatch_table.hpp +++ b/source_common/framework/instance_dispatch_table.hpp @@ -25,6 +25,8 @@ #pragma once +// clang-format off + #include #include "framework/device_functions.hpp" @@ -758,3 +760,5 @@ static inline void initDriverInstanceDispatchTable( } #undef ENTRY + +// clang-format on diff --git a/source_common/framework/instance_functions.cpp b/source_common/framework/instance_functions.cpp index ac9d970..545c0be 100644 --- a/source_common/framework/instance_functions.cpp +++ b/source_common/framework/instance_functions.cpp @@ -23,6 +23,8 @@ * ---------------------------------------------------------------------------- */ +// clang-format off + #include // Include from per-layer code @@ -1203,3 +1205,4 @@ VKAPI_ATTR void VKAPI_CALL layer_vkSubmitDebugUtilsMessageEXT_default( layer->driver.vkSubmitDebugUtilsMessageEXT(instance, messageSeverity, messageTypes, pCallbackData); } +// clang-format on diff --git a/source_common/framework/instance_functions.hpp b/source_common/framework/instance_functions.hpp index bad8fc2..cd423a6 100644 --- a/source_common/framework/instance_functions.hpp +++ b/source_common/framework/instance_functions.hpp @@ -25,6 +25,8 @@ #pragma once +// clang-format off + #include #if defined(VK_USE_PLATFORM_ANDROID_KHR) @@ -1352,3 +1354,4 @@ VKAPI_ATTR void VKAPI_CALL layer_vkSubmitDebugUtilsMessageEXT( layer_vkSubmitDebugUtilsMessageEXT_default(instance, messageSeverity, messageTypes, pCallbackData); } +// clang-format on diff --git a/source_common/framework/manual_functions.cpp b/source_common/framework/manual_functions.cpp index b8c7585..b9b3389 100644 --- a/source_common/framework/manual_functions.cpp +++ b/source_common/framework/manual_functions.cpp @@ -31,6 +31,7 @@ */ #include "framework/manual_functions.hpp" + #include "utils/misc.hpp" /** @@ -44,7 +45,7 @@ extern std::mutex g_vulkanLock; #define LGL_VERSION VK_MAKE_VERSION(LGL_VER_MAJOR, LGL_VER_MINOR, LGL_VER_PATCH) static const std::array layerProps = { - {{ LGL_LAYER_NAME, LGL_VERSION, 1, LGL_LAYER_DESC }}, + {{LGL_LAYER_NAME, LGL_VERSION, 1, LGL_LAYER_DESC}}, }; /** @@ -66,19 +67,22 @@ struct DispatchTableEntry /** * @brief Utility macro to define a lookup for a core function. */ -#define VK_TABLE_ENTRY(func) \ - { STR(func), reinterpret_cast(func) } +#define VK_TABLE_ENTRY(func) \ + { \ + STR(func), reinterpret_cast(func) \ + } /** * @brief Utility macro to define a lookup for a layer-dispatch-only function. */ -#define VK_TABLE_ENTRYL(func) \ - { STR(func), reinterpret_cast(layer_##func) } +#define VK_TABLE_ENTRYL(func) \ + { \ + STR(func), reinterpret_cast(layer_##func) \ + } /* See header for documentation. */ -VkLayerInstanceCreateInfo* getChainInfo( - const VkInstanceCreateInfo* pCreateInfo -) { +VkLayerInstanceCreateInfo* getChainInfo(const VkInstanceCreateInfo* pCreateInfo) +{ auto* info = static_cast(pCreateInfo->pNext); while (info) { @@ -96,9 +100,8 @@ VkLayerInstanceCreateInfo* getChainInfo( } /* See header for documentation. */ -VkLayerDeviceCreateInfo* getChainInfo( - const VkDeviceCreateInfo* pCreateInfo -) { +VkLayerDeviceCreateInfo* getChainInfo(const VkDeviceCreateInfo* pCreateInfo) +{ auto* info = static_cast(pCreateInfo->pNext); while (info) { @@ -116,9 +119,8 @@ VkLayerDeviceCreateInfo* getChainInfo( } /* See header for documentation. */ -PFN_vkVoidFunction getFixedInstanceLayerFunction( - const char* name -) { +PFN_vkVoidFunction getFixedInstanceLayerFunction(const char* name) +{ static const DispatchTableEntry layerFunctions[] = { VK_TABLE_ENTRY(vkGetInstanceProcAddr), VK_TABLE_ENTRY(vkEnumerateDeviceLayerProperties), @@ -127,7 +129,7 @@ PFN_vkVoidFunction getFixedInstanceLayerFunction( VK_TABLE_ENTRY(vkEnumerateInstanceExtensionProperties), }; - for (auto &function : layerFunctions) + for (auto& function : layerFunctions) { if (!strcmp(function.name, name)) { @@ -139,10 +141,9 @@ PFN_vkVoidFunction getFixedInstanceLayerFunction( } /* See header for documentation. */ -PFN_vkVoidFunction getInstanceLayerFunction( - const char* name -) { - for (auto &function : instanceIntercepts) +PFN_vkVoidFunction getInstanceLayerFunction(const char* name) +{ + for (auto& function : instanceIntercepts) { if (!strcmp(function.name, name)) { @@ -154,16 +155,15 @@ PFN_vkVoidFunction getInstanceLayerFunction( } /* See header for documentation. */ -PFN_vkVoidFunction getDeviceLayerFunction( - const char* name -) { +PFN_vkVoidFunction getDeviceLayerFunction(const char* name) +{ static const DispatchTableEntry layerFunctions[] = { VK_TABLE_ENTRY(vkGetDeviceProcAddr), VK_TABLE_ENTRY(vkEnumerateDeviceExtensionProperties), VK_TABLE_ENTRY(vkEnumerateDeviceLayerProperties), }; - for (auto &function : layerFunctions) + for (auto& function : layerFunctions) { if (!strcmp(function.name, name)) { @@ -171,7 +171,7 @@ PFN_vkVoidFunction getDeviceLayerFunction( } } - for (auto &function : deviceIntercepts) + for (auto& function : deviceIntercepts) { if (!strcmp(function.name, name)) { @@ -183,9 +183,8 @@ PFN_vkVoidFunction getDeviceLayerFunction( } /* See header for documentation. */ -APIVersion getInstanceAPIVersion( - PFN_vkGetInstanceProcAddr fpGetProcAddr -) { +APIVersion getInstanceAPIVersion(PFN_vkGetInstanceProcAddr fpGetProcAddr) +{ // TODO: This will crash in Khronos validation if we try to use this // with the validation layer beneath us due to Android loader v0 protocol. #if 0 @@ -197,7 +196,7 @@ APIVersion getInstanceAPIVersion( if (!fpFunction) { LAYER_ERR("Failed to get vkEnumerateInstanceVersion()"); - return { 0 , 0 }; + return {0, 0}; } uint32_t apiVersion = 0; @@ -205,36 +204,34 @@ APIVersion getInstanceAPIVersion( if (result != VK_SUCCESS) { LAYER_ERR("Failed to call vkEnumerateInstanceVersion()"); - return { 0 , 0 }; + return {0, 0}; } uint32_t major = VK_API_VERSION_MAJOR(apiVersion); uint32_t minor = VK_API_VERSION_MINOR(apiVersion); - return { major, minor }; + return {major, minor}; } /* See header for documentation. */ -APIVersion getApplicationAPIVersion( - const VkInstanceCreateInfo* pCreateInfo -) { +APIVersion getApplicationAPIVersion(const VkInstanceCreateInfo* pCreateInfo) +{ uint32_t apiVersion = pCreateInfo->pApplicationInfo->apiVersion; uint32_t major = VK_API_VERSION_MAJOR(apiVersion); uint32_t minor = VK_API_VERSION_MINOR(apiVersion); - return { major, minor }; + return {major, minor}; } /* See header for documentation. */ -APIVersion getDeviceAPIVersion( - PFN_vkGetInstanceProcAddr fpGetProcAddr, - VkInstance instance, - VkPhysicalDevice physicalDevice -) { +APIVersion getDeviceAPIVersion(PFN_vkGetInstanceProcAddr fpGetProcAddr, + VkInstance instance, + VkPhysicalDevice physicalDevice) +{ auto fpFunctionRaw = fpGetProcAddr(instance, "vkGetPhysicalDeviceProperties"); auto fpFunction = reinterpret_cast(fpFunctionRaw); if (!fpFunction) { LAYER_ERR("Failed to get vkGetPhysicalDeviceProperties()"); - return { 0 , 0 }; + return {0, 0}; } VkPhysicalDeviceProperties properties {}; @@ -242,18 +239,16 @@ APIVersion getDeviceAPIVersion( uint32_t major = VK_API_VERSION_MAJOR(properties.apiVersion); uint32_t minor = VK_API_VERSION_MINOR(properties.apiVersion); - return { major, minor }; + return {major, minor}; } /** * @brief Is version A >= version B. */ -static bool isVersionGreaterEqual( - const APIVersion& a, - const APIVersion& b -) { +static bool isVersionGreaterEqual(const APIVersion& a, const APIVersion& b) +{ // Different major version - if(a.first != b.first) + if (a.first != b.first) { return a.first > b.first; } @@ -265,12 +260,10 @@ static bool isVersionGreaterEqual( /** * @brief Is version A > version B. */ -static bool isVersionGreater( - const APIVersion& a, - const APIVersion& b -) { +static bool isVersionGreater(const APIVersion& a, const APIVersion& b) +{ // Different major version - if(a.first != b.first) + if (a.first != b.first) { return a.first > b.first; } @@ -280,43 +273,37 @@ static bool isVersionGreater( } /* See header for documentation. */ -APIVersion increaseAPIVersion( - const APIVersion& userVersion, - const APIVersion& maxVersion, - const APIVersion& requiredVersion -) { +APIVersion increaseAPIVersion(const APIVersion& userVersion, + const APIVersion& maxVersion, + const APIVersion& requiredVersion) +{ // User version is good enough to support the layer, so stick with that - if(isVersionGreaterEqual(userVersion, requiredVersion)) + if (isVersionGreaterEqual(userVersion, requiredVersion)) { - LAYER_LOG( - "Instance API version %u.%u (user setting meets layer minimum)", - userVersion.first, userVersion.second); + LAYER_LOG("Instance API version %u.%u (user setting meets layer minimum)", + userVersion.first, + userVersion.second); return userVersion; } // Required version is higher than the max version so log a warning // and try to continue using maxVersion but it may fail ... - if(isVersionGreater(requiredVersion, maxVersion)) + if (isVersionGreater(requiredVersion, maxVersion)) { - LAYER_ERR( - "Instance API version %u.%u (lower than layer minimum)", - maxVersion.first, maxVersion.second); + LAYER_ERR("Instance API version %u.%u (lower than layer minimum)", maxVersion.first, maxVersion.second); return maxVersion; } - LAYER_LOG( - "Instance API version %u.%u (increased to layer minimum)", - requiredVersion.first, requiredVersion.second); + LAYER_LOG("Instance API version %u.%u (increased to layer minimum)", requiredVersion.first, requiredVersion.second); return requiredVersion; } /* See header for documentation. */ -std::vector getInstanceExtensionList( - const VkInstanceCreateInfo* pCreateInfo -) { +std::vector getInstanceExtensionList(const VkInstanceCreateInfo* pCreateInfo) +{ std::vector foundExtensions; // Fetch the functions needed to query extensions availability @@ -348,11 +335,10 @@ std::vector getInstanceExtensionList( } /* See header for documentation. */ -std::vector getDeviceExtensionList( - VkInstance instance, - VkPhysicalDevice physicalDevice, - const VkDeviceCreateInfo* pCreateInfo -) { +std::vector getDeviceExtensionList(VkInstance instance, + VkPhysicalDevice physicalDevice, + const VkDeviceCreateInfo* pCreateInfo) +{ std::vector foundExtensions; // Fetch the functions needed to query extensions availability @@ -384,12 +370,10 @@ std::vector getDeviceExtensionList( } /* See header for documentation. */ -std::vector cloneExtensionList( - uint32_t extensionCount, - const char* const* extensionList -) { +std::vector cloneExtensionList(uint32_t extensionCount, const char* const* extensionList) +{ std::vector data; - for(uint32_t i = 0; i < extensionCount; i++) + for (uint32_t i = 0; i < extensionCount; i++) { data.emplace_back(extensionList[i]); } @@ -405,11 +389,9 @@ std::vector cloneExtensionList( * @param supported The list of supported extension, or empty if unknown. * @param active The list of active extensions. */ -static void enableInstanceVkExtDebugUtils( - const std::vector& supported, - std::vector& active -) { - static const std::string target { VK_EXT_DEBUG_UTILS_EXTENSION_NAME }; +static void enableInstanceVkExtDebugUtils(const std::vector& supported, std::vector& active) +{ + static const std::string target {VK_EXT_DEBUG_UTILS_EXTENSION_NAME}; // Test if the desired extension is supported. If supported list is // empty then we didn't query and assume extension is supported. @@ -446,13 +428,12 @@ static void enableInstanceVkExtDebugUtils( * @param active The list of active extensions. * @param newFeatures Pre-allocated struct we can use if we need to add it. */ -static void enableDeviceVkKhrTimelineSemaphore( - VkDeviceCreateInfo& createInfo, - std::vector& supported, - std::vector& active, - VkPhysicalDeviceTimelineSemaphoreFeatures newFeatures -) { - static const std::string target { VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME }; +static void enableDeviceVkKhrTimelineSemaphore(VkDeviceCreateInfo& createInfo, + std::vector& supported, + std::vector& active, + VkPhysicalDeviceTimelineSemaphoreFeatures newFeatures) +{ + static const std::string target {VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME}; // Test if the desired extension is supported if (!isIn(target, supported)) @@ -491,9 +472,9 @@ static void enableDeviceVkKhrTimelineSemaphore( // Check if user provided a VkPhysicalDeviceVulkan12Features // TODO: This currently relies on const_cast to make user struct writable // We should replace this with a generic clone (issue #56) - auto* config2 = searchNextList( - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES, - createInfo.pNext); + auto* config2 = + searchNextList(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES, + createInfo.pNext); if (config2) { @@ -533,13 +514,12 @@ static void enableDeviceVkKhrTimelineSemaphore( * @param active The list of active extensions. * @param newFeatures Pre-allocated struct we can use if we need to add it. */ -static void enableDeviceVkExtImageCompressionControl( - VkDeviceCreateInfo& createInfo, - std::vector& supported, - std::vector& active, - VkPhysicalDeviceImageCompressionControlFeaturesEXT newFeatures -) { - static const std::string target { VK_EXT_IMAGE_COMPRESSION_CONTROL_EXTENSION_NAME }; +static void enableDeviceVkExtImageCompressionControl(VkDeviceCreateInfo& createInfo, + std::vector& supported, + std::vector& active, + VkPhysicalDeviceImageCompressionControlFeaturesEXT newFeatures) +{ + static const std::string target {VK_EXT_IMAGE_COMPRESSION_CONTROL_EXTENSION_NAME}; // Test if the desired extension is supported if (!isIn(target, supported)) @@ -588,10 +568,8 @@ static void enableDeviceVkExtImageCompressionControl( } /** See Vulkan API for documentation. */ -PFN_vkVoidFunction layer_vkGetInstanceProcAddr_default( - VkInstance instance, - const char* pName -) { +PFN_vkVoidFunction layer_vkGetInstanceProcAddr_default(VkInstance instance, const char* pName) +{ // Always expose these functions ... PFN_vkVoidFunction layerFunction = getFixedInstanceLayerFunction(pName); if (layerFunction) @@ -602,8 +580,9 @@ PFN_vkVoidFunction layer_vkGetInstanceProcAddr_default( // Otherwise, only expose functions that the driver exposes to avoid // changing queryable interface behavior seen by the application layerFunction = getInstanceLayerFunction(pName); - if (instance) { - std::unique_lock lock { g_vulkanLock }; + if (instance) + { + std::unique_lock lock {g_vulkanLock}; auto* layer = Instance::retrieve(instance); // Don't hold the lock while calling the driver @@ -624,12 +603,10 @@ PFN_vkVoidFunction layer_vkGetInstanceProcAddr_default( } /** See Vulkan API for documentation. */ -PFN_vkVoidFunction layer_vkGetDeviceProcAddr_default( - VkDevice device, - const char* pName -) { +PFN_vkVoidFunction layer_vkGetDeviceProcAddr_default(VkDevice device, const char* pName) +{ // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(device); lock.unlock(); @@ -649,11 +626,10 @@ PFN_vkVoidFunction layer_vkGetDeviceProcAddr_default( } /** See Vulkan API for documentation. */ -VkResult layer_vkEnumerateInstanceExtensionProperties_default( - const char* pLayerName, - uint32_t* pPropertyCount, - VkExtensionProperties* pProperties -) { +VkResult layer_vkEnumerateInstanceExtensionProperties_default(const char* pLayerName, + uint32_t* pPropertyCount, + VkExtensionProperties* pProperties) +{ LAYER_TRACE(__func__); UNUSED(pProperties); @@ -668,12 +644,11 @@ VkResult layer_vkEnumerateInstanceExtensionProperties_default( } /** See Vulkan API for documentation. */ -VkResult layer_vkEnumerateDeviceExtensionProperties_default( - VkPhysicalDevice gpu, - const char* pLayerName, - uint32_t* pPropertyCount, - VkExtensionProperties* pProperties -) { +VkResult layer_vkEnumerateDeviceExtensionProperties_default(VkPhysicalDevice gpu, + const char* pLayerName, + uint32_t* pPropertyCount, + VkExtensionProperties* pProperties) +{ LAYER_TRACE(__func__); UNUSED(pProperties); @@ -694,7 +669,7 @@ VkResult layer_vkEnumerateDeviceExtensionProperties_default( assert(!pLayerName); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Instance::retrieve(gpu); // Release the lock to call into the driver @@ -703,10 +678,8 @@ VkResult layer_vkEnumerateDeviceExtensionProperties_default( } /** See Vulkan API for documentation. */ -VkResult layer_vkEnumerateInstanceLayerProperties_default( - uint32_t* pPropertyCount, - VkLayerProperties* pProperties -) { +VkResult layer_vkEnumerateInstanceLayerProperties_default(uint32_t* pPropertyCount, VkLayerProperties* pProperties) +{ LAYER_TRACE(__func__); if (pProperties) @@ -727,11 +700,10 @@ VkResult layer_vkEnumerateInstanceLayerProperties_default( } /** See Vulkan API for documentation. */ -VkResult layer_vkEnumerateDeviceLayerProperties_default( - VkPhysicalDevice gpu, - uint32_t* pPropertyCount, - VkLayerProperties* pProperties -) { +VkResult layer_vkEnumerateDeviceLayerProperties_default(VkPhysicalDevice gpu, + uint32_t* pPropertyCount, + VkLayerProperties* pProperties) +{ LAYER_TRACE(__func__); UNUSED(gpu); @@ -754,11 +726,10 @@ VkResult layer_vkEnumerateDeviceLayerProperties_default( } /* See Vulkan API for documentation. */ -VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateInstance_default( - const VkInstanceCreateInfo* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkInstance* pInstance -) { +VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateInstance_default(const VkInstanceCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkInstance* pInstance) +{ LAYER_TRACE(__func__); // We cannot reliably query the available instance extensions on Android if multiple layers are @@ -806,7 +777,7 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateInstance_default( newCreateInfo.pApplicationInfo = &newAppInfo; // Create a copy of the extension list we can patch - std::vector newExtensions; + std::vector newExtensions; const auto start = pCreateInfo->ppEnabledExtensionNames; const auto end = pCreateInfo->ppEnabledExtensionNames + pCreateInfo->enabledExtensionCount; newExtensions.insert(newExtensions.end(), start, end); @@ -816,9 +787,7 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateInstance_default( { if (newExt == VK_EXT_DEBUG_UTILS_EXTENSION_NAME) { - enableInstanceVkExtDebugUtils( - supportedExtensions, - newExtensions); + enableInstanceVkExtDebugUtils(supportedExtensions, newExtensions); } else { @@ -846,12 +815,10 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateInstance_default( } // Retake the lock to access layer-wide global store - auto instance = std::make_unique( - *pInstance, - fpGetInstanceProcAddr); + auto instance = std::make_unique(*pInstance, fpGetInstanceProcAddr); { - std::lock_guard lock { g_vulkanLock }; + std::lock_guard lock {g_vulkanLock}; Instance::store(*pInstance, instance); } @@ -859,14 +826,12 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateInstance_default( } /* See Vulkan API for documentation. */ -VKAPI_ATTR void VKAPI_CALL layer_vkDestroyInstance_default( - VkInstance instance, - const VkAllocationCallbacks* pAllocator -) { +VKAPI_ATTR void VKAPI_CALL layer_vkDestroyInstance_default(VkInstance instance, const VkAllocationCallbacks* pAllocator) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Instance::retrieve(instance); // Layer proxy must be destroyed before the driver version @@ -876,20 +841,18 @@ VKAPI_ATTR void VKAPI_CALL layer_vkDestroyInstance_default( // Release the lock to call into the driver lock.unlock(); layer->driver.vkDestroyInstance(instance, pAllocator); - } /* See Vulkan API for documentation. */ -VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateDevice_default( - VkPhysicalDevice physicalDevice, - const VkDeviceCreateInfo* pCreateInfo, - const VkAllocationCallbacks* pAllocator, - VkDevice* pDevice -) { +VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateDevice_default(VkPhysicalDevice physicalDevice, + const VkDeviceCreateInfo* pCreateInfo, + const VkAllocationCallbacks* pAllocator, + VkDevice* pDevice) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Instance::retrieve(physicalDevice); // Release the lock to call into the driver @@ -904,8 +867,7 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateDevice_default( auto fpGetDeviceProcAddr = chainInfo->u.pLayerInfo->pfnNextGetDeviceProcAddr; // Log this for support purposes ... - APIVersion apiVersion = getDeviceAPIVersion( - fpGetInstanceProcAddr, layer->instance, physicalDevice); + APIVersion apiVersion = getDeviceAPIVersion(fpGetInstanceProcAddr, layer->instance, physicalDevice); LAYER_LOG("Device API version %u.%u", apiVersion.first, apiVersion.second); @@ -917,7 +879,7 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateDevice_default( VkPhysicalDeviceImageCompressionControlFeaturesEXT newCompressionControlFeatures; // Create a copy of the extension list we can patch - std::vector newExtensions; + std::vector newExtensions; const auto start = pCreateInfo->ppEnabledExtensionNames; const auto end = pCreateInfo->ppEnabledExtensionNames + pCreateInfo->enabledExtensionCount; newExtensions.insert(newExtensions.end(), start, end); @@ -927,19 +889,14 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateDevice_default( { if (newExt == VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME) { - enableDeviceVkKhrTimelineSemaphore( - newCreateInfo, - supportedExtensions, - newExtensions, - newTimelineFeatures); + enableDeviceVkKhrTimelineSemaphore(newCreateInfo, supportedExtensions, newExtensions, newTimelineFeatures); } else if (newExt == VK_EXT_IMAGE_COMPRESSION_CONTROL_EXTENSION_NAME) { - enableDeviceVkExtImageCompressionControl( - newCreateInfo, - supportedExtensions, - newExtensions, - newCompressionControlFeatures); + enableDeviceVkExtImageCompressionControl(newCreateInfo, + supportedExtensions, + newExtensions, + newCompressionControlFeatures); } else { @@ -974,8 +931,7 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateDevice_default( return res; } - auto device = std::make_unique( - layer, physicalDevice, *pDevice, fpGetDeviceProcAddr, newCreateInfo); + auto device = std::make_unique(layer, physicalDevice, *pDevice, fpGetDeviceProcAddr, newCreateInfo); // Retake the lock to access layer-wide global store lock.lock(); @@ -985,14 +941,12 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateDevice_default( } /* See Vulkan API for documentation. */ -VKAPI_ATTR void VKAPI_CALL layer_vkDestroyDevice_default( - VkDevice device, - const VkAllocationCallbacks* pAllocator -) { +VKAPI_ATTR void VKAPI_CALL layer_vkDestroyDevice_default(VkDevice device, const VkAllocationCallbacks* pAllocator) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(device); // Layer proxy must be destroyed before the driver version @@ -1005,15 +959,15 @@ VKAPI_ATTR void VKAPI_CALL layer_vkDestroyDevice_default( } /* See Vulkan API for documentation. */ -VKAPI_ATTR void VKAPI_CALL layer_vkGetDeviceImageMemoryRequirementsKHR_default( - VkDevice device, - const VkDeviceImageMemoryRequirements* pInfo, - VkMemoryRequirements2* pMemoryRequirements -) { +VKAPI_ATTR void VKAPI_CALL + layer_vkGetDeviceImageMemoryRequirementsKHR_default(VkDevice device, + const VkDeviceImageMemoryRequirements* pInfo, + VkMemoryRequirements2* pMemoryRequirements) +{ LAYER_TRACE(__func__); // Hold the lock to access layer-wide global store - std::unique_lock lock { g_vulkanLock }; + std::unique_lock lock {g_vulkanLock}; auto* layer = Device::retrieve(device); // Workaround Unreal Engine trying to invoke this via a function pointer diff --git a/source_common/framework/manual_functions.hpp b/source_common/framework/manual_functions.hpp index 94a3e05..723294e 100644 --- a/source_common/framework/manual_functions.hpp +++ b/source_common/framework/manual_functions.hpp @@ -29,6 +29,14 @@ * implemented as library code which can be swapped for alternative * implementations on a per-layer basis if needed. */ +#include "device.hpp" +#include "framework/device_dispatch_table.hpp" +#include "framework/device_functions.hpp" +#include "framework/instance_functions.hpp" +#include "framework/utils.hpp" +#include "instance.hpp" +#include "version.hpp" + #include #include #include @@ -36,15 +44,6 @@ #include #include -#include "device.hpp" -#include "instance.hpp" -#include "version.hpp" - -#include "framework/device_dispatch_table.hpp" -#include "framework/device_functions.hpp" -#include "framework/instance_functions.hpp" -#include "framework/utils.hpp" - /** * @brief Extract the layer chain info from the instance creation info. * @@ -52,8 +51,7 @@ * * @return The instance creation info, or @c nullptr if not found. */ -VkLayerInstanceCreateInfo* getChainInfo( - const VkInstanceCreateInfo* pCreateInfo); +VkLayerInstanceCreateInfo* getChainInfo(const VkInstanceCreateInfo* pCreateInfo); /** * @brief Extract the layer chain info from the device creation info. @@ -62,8 +60,7 @@ VkLayerInstanceCreateInfo* getChainInfo( * * @return The instance creation info, or @c nullptr if not found. */ -VkLayerDeviceCreateInfo* getChainInfo( - const VkDeviceCreateInfo* pCreateInfo); +VkLayerDeviceCreateInfo* getChainInfo(const VkDeviceCreateInfo* pCreateInfo); /** * @brief Fetch the function for a given static instance entrypoint name. @@ -76,8 +73,7 @@ VkLayerDeviceCreateInfo* getChainInfo( * @return The layer function pointer, or \c nullptr if the layer doesn't * intercept the function. */ -PFN_vkVoidFunction getFixedInstanceLayerFunction( - const char* name); +PFN_vkVoidFunction getFixedInstanceLayerFunction(const char* name); /** * @brief Fetch the function for a given dynamic instance entrypoint name. @@ -90,8 +86,7 @@ PFN_vkVoidFunction getFixedInstanceLayerFunction( * @return The layer function pointer, or \c nullptr if the layer doesn't * intercept the function. */ -PFN_vkVoidFunction getInstanceLayerFunction( - const char* name); +PFN_vkVoidFunction getInstanceLayerFunction(const char* name); /** * @brief Fetch the function for a given dynamic instance entrypoint name. @@ -104,8 +99,7 @@ PFN_vkVoidFunction getInstanceLayerFunction( * @return The layer function pointer, or \c nullptr if the layer doesn't * intercept the function. */ -PFN_vkVoidFunction getDeviceLayerFunction( - const char* name); +PFN_vkVoidFunction getDeviceLayerFunction(const char* name); /** * @brief Fetch the maximum supported instance API version. @@ -114,8 +108,7 @@ PFN_vkVoidFunction getDeviceLayerFunction( * * @return The major/minor version numbers, or zeros on error. */ -APIVersion getInstanceAPIVersion( - PFN_vkGetInstanceProcAddr fpGetProcAddr); +APIVersion getInstanceAPIVersion(PFN_vkGetInstanceProcAddr fpGetProcAddr); /** * @brief Fetch the application requested instance API version. @@ -124,8 +117,7 @@ APIVersion getInstanceAPIVersion( * * @return The major/minor version numbers. */ -APIVersion getApplicationAPIVersion( - const VkInstanceCreateInfo* pCreateInfo); +APIVersion getApplicationAPIVersion(const VkInstanceCreateInfo* pCreateInfo); /** * @brief Fetch the maximum supported device API version. @@ -136,10 +128,9 @@ APIVersion getApplicationAPIVersion( * * @return The major/minor version numbers, or zeros on error. */ -APIVersion getDeviceAPIVersion( - PFN_vkGetInstanceProcAddr fpGetProcAddr, - VkInstance instance, - VkPhysicalDevice physicalDevice); +APIVersion getDeviceAPIVersion(PFN_vkGetInstanceProcAddr fpGetProcAddr, + VkInstance instance, + VkPhysicalDevice physicalDevice); /** * @brief Return an increased API version, if supported. @@ -150,10 +141,9 @@ APIVersion getDeviceAPIVersion( * * @return The major/minor version numbers, or zeros on error. */ -APIVersion increaseAPIVersion( - const APIVersion& userVersion, - const APIVersion& maxVersion, - const APIVersion& requiredVersion); +APIVersion increaseAPIVersion(const APIVersion& userVersion, + const APIVersion& maxVersion, + const APIVersion& requiredVersion); /** * @brief Fetch the list of supported extensions from the instance. @@ -167,8 +157,7 @@ APIVersion increaseAPIVersion( * * @return The list of supported extensions; empty list on failure. */ -std::vector getInstanceExtensionList( - const VkInstanceCreateInfo* pCreateInfo); +std::vector getInstanceExtensionList(const VkInstanceCreateInfo* pCreateInfo); /** * @brief Fetch the list of supported extensions from a physical device. @@ -179,10 +168,9 @@ std::vector getInstanceExtensionList( * * @return The list of supported extensions; empty list on failure. */ -std::vector getDeviceExtensionList( - VkInstance instance, - VkPhysicalDevice physicalDevice, - const VkDeviceCreateInfo* pCreateInfo); +std::vector getDeviceExtensionList(VkInstance instance, + VkPhysicalDevice physicalDevice, + const VkDeviceCreateInfo* pCreateInfo); /** * @brief Clone the target extension list. @@ -192,6 +180,4 @@ std::vector getDeviceExtensionList( * * @return the cloned list. */ -std::vector cloneExtensionList( - uint32_t extensionCount, - const char* const* extensionList); +std::vector cloneExtensionList(uint32_t extensionCount, const char* const* extensionList); diff --git a/source_common/framework/utils.hpp b/source_common/framework/utils.hpp index 0a6913b..1ed7a87 100644 --- a/source_common/framework/utils.hpp +++ b/source_common/framework/utils.hpp @@ -38,7 +38,7 @@ #include #if defined(VK_USE_PLATFORM_ANDROID_KHR) - #include +# include #endif /** @@ -50,9 +50,9 @@ * Annotation for exported symbol from shared object on Android only. */ #if defined(VK_USE_PLATFORM_ANDROID_KHR) - #define VK_LAYER_EXPORT_ANDROID VK_LAYER_EXPORT +# define VK_LAYER_EXPORT_ANDROID VK_LAYER_EXPORT #else - #define VK_LAYER_EXPORT_ANDROID +# define VK_LAYER_EXPORT_ANDROID #endif /** @@ -63,7 +63,9 @@ using APIVersion = std::pair; /** * @brief Tag type used for template function dispatch; */ -struct user_tag {}; +struct user_tag +{ +}; /** * @brief Convert a dispatchable API handle to the underlying dispatch key. @@ -72,9 +74,8 @@ struct user_tag {}; * * @return The dispatch key. */ -static inline void* getDispatchKey( - void* ptr -) { +inline static void* getDispatchKey(void* ptr) +{ return *static_cast(ptr); } @@ -82,43 +83,47 @@ static inline void* getDispatchKey( * @brief Enable to enable API entrypoint tracing to the log/logcat. */ #if !defined(CONFIG_TRACE) - #define CONFIG_TRACE 0 +# define CONFIG_TRACE 0 #endif /** * @brief Enable to enable layer logging to the log/logcat. */ #if !defined(CONFIG_LOG) - #define CONFIG_LOG 1 +# define CONFIG_LOG 1 #endif #if CONFIG_TRACE - #ifdef __ANDROID__ - #if !defined(LGL_LOG_TAG) - #error "LGL_LOG_TAG not defined" - #endif - - #define LAYER_TRACE(x) __android_log_print(ANDROID_LOG_INFO, LGL_LOG_TAG, "API Trace: %s", x) - #else - #define LAYER_TRACE(x) printf("API Trace: %s\n", x) - #endif +# ifdef __ANDROID__ +# if !defined(LGL_LOG_TAG) +# error "LGL_LOG_TAG not defined" +# endif + +# define LAYER_TRACE(x) __android_log_print(ANDROID_LOG_INFO, LGL_LOG_TAG, "API Trace: %s", x) +# else +# define LAYER_TRACE(x) printf("API Trace: %s\n", x) +# endif #else - #define LAYER_TRACE(x) +# define LAYER_TRACE(x) #endif #if CONFIG_LOG - #ifdef __ANDROID__ - #if !defined(LGL_LOG_TAG) - #error "LGL_LOG_TAG not defined" - #endif - - #define LAYER_LOG(...) __android_log_print(ANDROID_LOG_INFO, LGL_LOG_TAG, __VA_ARGS__) - #define LAYER_ERR(...) __android_log_print(ANDROID_LOG_INFO, LGL_LOG_TAG, __VA_ARGS__) - #else - #define LAYER_LOG(...) printf(__VA_ARGS__); printf("\n"); - #define LAYER_ERR(...) printf(__VA_ARGS__); printf("\n"); - #endif +# ifdef __ANDROID__ +# if !defined(LGL_LOG_TAG) +# error "LGL_LOG_TAG not defined" +# endif + +# define LAYER_LOG(...) __android_log_print(ANDROID_LOG_INFO, LGL_LOG_TAG, __VA_ARGS__) +# define LAYER_ERR(...) __android_log_print(ANDROID_LOG_INFO, LGL_LOG_TAG, __VA_ARGS__) +# else +# define LAYER_LOG(...) \ + printf(__VA_ARGS__); \ + printf("\n"); +# define LAYER_ERR(...) \ + printf(__VA_ARGS__); \ + printf("\n"); +# endif #else - #define LAYER_LOG(...) - #define LAYER_ERR(...) +# define LAYER_LOG(...) +# define LAYER_ERR(...) #endif diff --git a/source_common/trackers/CMakeLists.txt b/source_common/trackers/CMakeLists.txt index 9d1259d..868e9fd 100644 --- a/source_common/trackers/CMakeLists.txt +++ b/source_common/trackers/CMakeLists.txt @@ -44,3 +44,4 @@ lgl_set_build_options(${LIB_BINARY}) # add_subdirectory(test) #endif() +add_clang_tools() \ No newline at end of file diff --git a/source_common/trackers/command_buffer.cpp b/source_common/trackers/command_buffer.cpp index b1b5d3c..17b7084 100644 --- a/source_common/trackers/command_buffer.cpp +++ b/source_common/trackers/command_buffer.cpp @@ -23,22 +23,21 @@ * ---------------------------------------------------------------------------- */ -#include - #include "trackers/command_buffer.hpp" + #include "framework/utils.hpp" #include "utils/misc.hpp" +#include + namespace Tracker { /* See header for documentation. */ -CommandBuffer::CommandBuffer( - VkCommandBuffer _handle) : - handle(_handle) -{ +CommandBuffer::CommandBuffer(VkCommandBuffer _handle) + : handle(_handle) { -}; + }; /* See header for documentation. */ void CommandBuffer::reset() @@ -50,17 +49,14 @@ void CommandBuffer::reset() } /* See header for documentation. */ -void CommandBuffer::begin( - bool _oneTimeSubmit -) +void CommandBuffer::begin(bool _oneTimeSubmit) { oneTimeSubmit = _oneTimeSubmit; } /* See header for documentation. */ -void CommandBuffer::debugMarkerBegin( - std::string marker -) { +void CommandBuffer::debugMarkerBegin(std::string marker) +{ // Create a workload we can reference later auto workload = std::make_shared(marker); workloads.push_back(workload); @@ -80,14 +76,13 @@ void CommandBuffer::debugMarkerEnd() } /* See header for documentation. */ -uint64_t CommandBuffer::renderPassBegin( - const RenderPass& renderPass, - uint32_t width, - uint32_t height, - bool resuming, - bool suspending -) { - uint64_t tagID { 0 }; +uint64_t CommandBuffer::renderPassBegin(const RenderPass& renderPass, + uint32_t width, + uint32_t height, + bool resuming, + bool suspending) +{ + uint64_t tagID {0}; assert(!currentRenderPass); @@ -101,8 +96,7 @@ uint64_t CommandBuffer::renderPassBegin( // Populate render pass with config information renderPassStartDrawCount = stats.getDrawCallCount(); - auto workload = std::make_shared( - tagID, renderPass, width, height, suspending, oneTimeSubmit); + auto workload = std::make_shared(tagID, renderPass, width, height, suspending, oneTimeSubmit); currentRenderPass = workload; workloads.push_back(workload); @@ -132,17 +126,13 @@ bool CommandBuffer::renderPassEnd() } /* See header for documentation. */ -uint64_t CommandBuffer::dispatch( - int64_t xGroups, - int64_t yGroups, - int64_t zGroups -) { +uint64_t CommandBuffer::dispatch(int64_t xGroups, int64_t yGroups, int64_t zGroups) +{ uint64_t tagID = Tracker::LCSWorkload::assignTagID(); stats.incDispatchCount(); // Add a workload to the render pass - auto workload = std::make_shared( - tagID, xGroups, yGroups, zGroups); + auto workload = std::make_shared(tagID, xGroups, yGroups, zGroups); workloads.push_back(workload); // Add a command to the layer-side command stream @@ -153,17 +143,13 @@ uint64_t CommandBuffer::dispatch( } /* See header for documentation. */ -uint64_t CommandBuffer::traceRays( - int64_t xItems, - int64_t yItems, - int64_t zItems -) { +uint64_t CommandBuffer::traceRays(int64_t xItems, int64_t yItems, int64_t zItems) +{ uint64_t tagID = Tracker::LCSWorkload::assignTagID(); stats.incTraceRaysCount(); // Add a workload to the render pass - auto workload = std::make_shared( - tagID, xItems, yItems, zItems); + auto workload = std::make_shared(tagID, xItems, yItems, zItems); workloads.push_back(workload); // Add a command to the layer-side command stream @@ -174,16 +160,13 @@ uint64_t CommandBuffer::traceRays( } /* See header for documentation. */ -uint64_t CommandBuffer::imageTransfer( - const std::string& transferType, - int64_t pixelCount -) { +uint64_t CommandBuffer::imageTransfer(const std::string& transferType, int64_t pixelCount) +{ uint64_t tagID = Tracker::LCSWorkload::assignTagID(); stats.incImageTransferCount(); // Add a workload to the render pass - auto workload = std::make_shared( - tagID, transferType, pixelCount); + auto workload = std::make_shared(tagID, transferType, pixelCount); workloads.push_back(workload); // Add a command to the layer-side command stream @@ -194,16 +177,13 @@ uint64_t CommandBuffer::imageTransfer( } /* See header for documentation. */ -uint64_t CommandBuffer::bufferTransfer( - const std::string& transferType, - int64_t byteCount -) { +uint64_t CommandBuffer::bufferTransfer(const std::string& transferType, int64_t byteCount) +{ uint64_t tagID = Tracker::LCSWorkload::assignTagID(); stats.incBufferTransferCount(); // Add a workload to the render pass - auto workload = std::make_shared( - tagID, transferType, byteCount); + auto workload = std::make_shared(tagID, transferType, byteCount); workloads.push_back(workload); // Add a command to the layer-side command stream @@ -214,9 +194,8 @@ uint64_t CommandBuffer::bufferTransfer( } /* See header for documentation. */ -void CommandBuffer::executeCommands( - CommandBuffer& secondary -) { +void CommandBuffer::executeCommands(CommandBuffer& secondary) +{ // Integrate secondary statistics into the primary stats.mergeCounts(secondary.getStats()); @@ -226,21 +205,15 @@ void CommandBuffer::executeCommands( } /* See header for documentation. */ -CommandPool::CommandPool( - VkCommandPool _handle) : - handle(_handle) -{ +CommandPool::CommandPool(VkCommandPool _handle) + : handle(_handle) { -}; + }; /* See header for documentation. */ -CommandBuffer& CommandPool::allocateCommandBuffer( - VkCommandBuffer commandBuffer -) { - auto result = commandBuffers.insert({ - commandBuffer, - std::make_unique(commandBuffer) - }); +CommandBuffer& CommandPool::allocateCommandBuffer(VkCommandBuffer commandBuffer) +{ + auto result = commandBuffers.insert({commandBuffer, std::make_unique(commandBuffer)}); // Validate that insertion worked assert(result.second); @@ -250,9 +223,8 @@ CommandBuffer& CommandPool::allocateCommandBuffer( } /* See header for documentation. */ -void CommandPool::freeCommandBuffer( - VkCommandBuffer commandBuffer -) { +void CommandPool::freeCommandBuffer(VkCommandBuffer commandBuffer) +{ commandBuffers.erase(commandBuffer); } diff --git a/source_common/trackers/command_buffer.hpp b/source_common/trackers/command_buffer.hpp index 3962f48..029cb41 100644 --- a/source_common/trackers/command_buffer.hpp +++ b/source_common/trackers/command_buffer.hpp @@ -43,15 +43,16 @@ #pragma once +#include "trackers/layer_command_stream.hpp" +#include "trackers/stats.hpp" + #include #include #include #include #include -#include -#include "trackers/stats.hpp" -#include "trackers/layer_command_stream.hpp" +#include namespace Tracker { @@ -67,24 +68,17 @@ class CommandBuffer * * @param handle The Vulkan command buffer handle we are tracking. */ - CommandBuffer( - VkCommandBuffer handle); + CommandBuffer(VkCommandBuffer handle); /** * @brief Get the stats object for this command buffer; */ - Stats& getStats() - { - return stats; - } + Stats& getStats() { return stats; } /** * @brief Get the layer submit-time command stream for this command buffer. */ - const std::vector& getSubmitCommandStream() const - { - return workloadCommandStream; - } + const std::vector& getSubmitCommandStream() const { return workloadCommandStream; } /** * @brief Begin recording a render pass. @@ -98,12 +92,11 @@ class CommandBuffer * @return Returns the tagID assigned to this workload. Always returns 0 * if @c resuming an existing workload. */ - uint64_t renderPassBegin( - const RenderPass& renderPass, - uint32_t width, - uint32_t height, - bool resuming=false, - bool suspending=false); + uint64_t renderPassBegin(const RenderPass& renderPass, + uint32_t width, + uint32_t height, + bool resuming = false, + bool suspending = false); /** * @brief End the current render pass workload recording. @@ -122,10 +115,7 @@ class CommandBuffer * * @return Returns the tagID assigned to this workload. */ - uint64_t dispatch( - int64_t xGroups, - int64_t yGroups, - int64_t zGroups); + uint64_t dispatch(int64_t xGroups, int64_t yGroups, int64_t zGroups); /** * @brief Capture a trace rays dispatch. @@ -136,10 +126,7 @@ class CommandBuffer * * @return Returns the tagID assigned to this workload. */ - uint64_t traceRays( - int64_t xItems, - int64_t yItems, - int64_t zItems); + uint64_t traceRays(int64_t xItems, int64_t yItems, int64_t zItems); /** * @brief Capture a transfer where the destination is an image. @@ -149,9 +136,7 @@ class CommandBuffer * * @return Returns the tagID assigned to this workload. */ - uint64_t imageTransfer( - const std::string& transferType, - int64_t pixelCount); + uint64_t imageTransfer(const std::string& transferType, int64_t pixelCount); /** * @brief Capture a transfer where the destination is a buffer. @@ -161,17 +146,14 @@ class CommandBuffer * * @return Returns the tagID assigned to this workload. */ - uint64_t bufferTransfer( - const std::string& transferType, - int64_t byteCount); + uint64_t bufferTransfer(const std::string& transferType, int64_t byteCount); /** * @brief Begin a user debug marker range. * * @param marker The marker label. */ - void debugMarkerBegin( - std::string marker); + void debugMarkerBegin(std::string marker); /** * @brief End a user debug marker range. @@ -181,8 +163,7 @@ class CommandBuffer /** * @brief Execute a secondary command buffer. */ - void executeCommands( - CommandBuffer& secondary); + void executeCommands(CommandBuffer& secondary); /** * @brief Reset the command buffer back into the @a Initial state. @@ -194,8 +175,7 @@ class CommandBuffer * * @param oneTimeSubmit Is this a one-time submit recording? */ - void begin( - bool oneTimeSubmit); + void begin(bool oneTimeSubmit); private: /** @@ -206,12 +186,12 @@ class CommandBuffer /** * @brief Is this command buffer recording one-time-submit? */ - bool oneTimeSubmit { false }; + bool oneTimeSubmit {false}; /** * @brief The command buffer draw count at the start of the render pass. */ - uint64_t renderPassStartDrawCount { 0 }; + uint64_t renderPassStartDrawCount {0}; /** * @brief The cumulative stats of the commands in this command buffer. @@ -245,8 +225,7 @@ class CommandPool * * @param handle The Vulkan pool buffer handle we are wrapping. */ - CommandPool( - VkCommandPool handle); + CommandPool(VkCommandPool handle); /** * @brief Allocate a command buffer in the pool with the given handle. @@ -255,16 +234,14 @@ class CommandPool * * \return The layer wrapper object for the command buffer. */ - CommandBuffer& allocateCommandBuffer( - VkCommandBuffer commandBuffer); + CommandBuffer& allocateCommandBuffer(VkCommandBuffer commandBuffer); /** * @brief Free the command buffer in the pool with the given handle. * * @param commandBuffer The Vulkan handle of the command buffer to free. */ - void freeCommandBuffer( - VkCommandBuffer commandBuffer); + void freeCommandBuffer(VkCommandBuffer commandBuffer); /** * @brief Reset all allocated command buffers into the @a Initial state. @@ -277,7 +254,7 @@ class CommandPool */ const VkCommandPool handle; - /** + /** * @brief The command buffers currently allocated in this command pool. */ std::unordered_map> commandBuffers; diff --git a/source_common/trackers/device.cpp b/source_common/trackers/device.cpp index af5fee7..bc65eaa 100644 --- a/source_common/trackers/device.cpp +++ b/source_common/trackers/device.cpp @@ -24,57 +24,45 @@ */ #include "trackers/device.hpp" + #include "utils/misc.hpp" namespace Tracker { /* See header for documentation. */ -void Device::createCommandPool( - VkCommandPool commandPool -) { - commandPools.insert({ - commandPool, - std::make_unique(commandPool) - }); +void Device::createCommandPool(VkCommandPool commandPool) +{ + commandPools.insert({commandPool, std::make_unique(commandPool)}); } /* See header for documentation. */ -CommandPool& Device::getCommandPool( - VkCommandPool commandPool -) { +CommandPool& Device::getCommandPool(VkCommandPool commandPool) +{ assert(isInMap(commandPool, commandPools)); return *commandPools.at(commandPool); } /* See header for documentation. */ -void Device::destroyCommandPool( - VkCommandPool commandPool -) { +void Device::destroyCommandPool(VkCommandPool commandPool) +{ commandPools.erase(commandPool); } /* See header for documentation. */ -void Device::allocateCommandBuffer( - VkCommandPool commandPool, - VkCommandBuffer commandBuffer -) { +void Device::allocateCommandBuffer(VkCommandPool commandPool, VkCommandBuffer commandBuffer) +{ // Allocate in the pool auto& pool = getCommandPool(commandPool); auto& buffer = pool.allocateCommandBuffer(commandBuffer); // Insert into the tracker lookup map - commandBuffers.insert({ - commandBuffer, - buffer - }); + commandBuffers.insert({commandBuffer, buffer}); } /* See header for documentation. */ -void Device::freeCommandBuffer( - VkCommandPool commandPool, - VkCommandBuffer commandBuffer -) { +void Device::freeCommandBuffer(VkCommandPool commandPool, VkCommandBuffer commandBuffer) +{ // Remove from the tracker lookup map commandBuffers.erase(commandBuffer); @@ -84,75 +72,56 @@ void Device::freeCommandBuffer( } /* See header for documentation. */ -CommandBuffer& Device::getCommandBuffer( - VkCommandBuffer commandBuffer -) { +CommandBuffer& Device::getCommandBuffer(VkCommandBuffer commandBuffer) +{ assert(isInMap(commandBuffer, commandBuffers)); return commandBuffers.at(commandBuffer); } /* See header for documentation. */ -void Device::createRenderPass( - VkRenderPass renderPass, - const VkRenderPassCreateInfo& createInfo -) { - renderPasses.insert({ - renderPass, - std::make_unique(renderPass, createInfo) - }); +void Device::createRenderPass(VkRenderPass renderPass, const VkRenderPassCreateInfo& createInfo) +{ + renderPasses.insert({renderPass, std::make_unique(renderPass, createInfo)}); } /* See header for documentation. */ -void Device::createRenderPass( - VkRenderPass renderPass, - const VkRenderPassCreateInfo2& createInfo -) { - renderPasses.insert({ - renderPass, - std::make_unique(renderPass, createInfo) - }); +void Device::createRenderPass(VkRenderPass renderPass, const VkRenderPassCreateInfo2& createInfo) +{ + renderPasses.insert({renderPass, std::make_unique(renderPass, createInfo)}); } /* See header for documentation. */ -RenderPass& Device::getRenderPass( - VkRenderPass renderPass -) { +RenderPass& Device::getRenderPass(VkRenderPass renderPass) +{ assert(isInMap(renderPass, renderPasses)); return *renderPasses.at(renderPass); } /* See header for documentation. */ -void Device::destroyRenderPass( - VkRenderPass renderPass -) { +void Device::destroyRenderPass(VkRenderPass renderPass) +{ renderPasses.erase(renderPass); } /* See header for documentation. */ -Queue& Device::getQueue( - VkQueue queue -) { +Queue& Device::getQueue(VkQueue queue) +{ // Create a tracker for a queue on first use if (!isInMap(queue, queues)) { - queues.insert({ - queue, - std::make_unique(queue) - }); + queues.insert({queue, std::make_unique(queue)}); } return *queues.at(queue); } /* See header for documentation. */ -void Device::queueSubmit( - VkCommandBuffer commandBuffer -) { +void Device::queueSubmit(VkCommandBuffer commandBuffer) +{ auto& cbStats = getCommandBuffer(commandBuffer).getStats(); frameStats.mergeCounts(cbStats); } - /* See header for documentation. */ void Device::queuePresent() { diff --git a/source_common/trackers/device.hpp b/source_common/trackers/device.hpp index 4507707..316ae6c 100644 --- a/source_common/trackers/device.hpp +++ b/source_common/trackers/device.hpp @@ -38,13 +38,14 @@ #pragma once -#include -#include - #include "trackers/command_buffer.hpp" #include "trackers/queue.hpp" #include "trackers/render_pass.hpp" +#include + +#include + namespace Tracker { @@ -59,16 +60,14 @@ class Device * * @param commandPool The native handle to track. */ - void createCommandPool( - VkCommandPool commandPool); + void createCommandPool(VkCommandPool commandPool); /** * @brief Get the tracker for a native command pool. * * @param commandPool The native handle we are tracking. */ - CommandPool& getCommandPool( - VkCommandPool commandPool); + CommandPool& getCommandPool(VkCommandPool commandPool); /** * @brief Create a new command buffer in a pool within this device. @@ -76,9 +75,7 @@ class Device * @param commandPool The native parent command pool handle. * @param commandBuffer The native handle to track. */ - void allocateCommandBuffer( - VkCommandPool commandPool, - VkCommandBuffer commandBuffer); + void allocateCommandBuffer(VkCommandPool commandPool, VkCommandBuffer commandBuffer); /** * @brief Free a command buffer in a pool within this device. @@ -86,25 +83,21 @@ class Device * @param commandPool The native parent command pool handle. * @param commandBuffer The native handle to stop tracking. */ - void freeCommandBuffer( - VkCommandPool commandPool, - VkCommandBuffer commandBuffer); + void freeCommandBuffer(VkCommandPool commandPool, VkCommandBuffer commandBuffer); /** * @brief Get the tracker for native command buffer. * * @param commandBuffer The native handle we are tracking. */ - CommandBuffer& getCommandBuffer( - VkCommandBuffer commandBuffer); + CommandBuffer& getCommandBuffer(VkCommandBuffer commandBuffer); /** * @brief Destroy a command pool within this device. * * @param commandPool The native handle to stop tracking. */ - void destroyCommandPool( - VkCommandPool commandPool); + void destroyCommandPool(VkCommandPool commandPool); /** * @brief Get the tracker for a native queue. @@ -114,8 +107,7 @@ class Device * * @param queue The native handle we are tracking. */ - Queue& getQueue( - VkQueue queue); + Queue& getQueue(VkQueue queue); /** * @brief Create a new render pass tracker within this device. @@ -123,9 +115,7 @@ class Device * @param renderPass The native handle to track. * @param createInfo The render pass configuration information. */ - void createRenderPass( - VkRenderPass renderPass, - const VkRenderPassCreateInfo& createInfo); + void createRenderPass(VkRenderPass renderPass, const VkRenderPassCreateInfo& createInfo); /** * @brief Create a new render pass tracker within this device. @@ -133,33 +123,28 @@ class Device * @param renderPass The native handle to track. * @param createInfo The render pass configuration information. */ - void createRenderPass( - VkRenderPass renderPass, - const VkRenderPassCreateInfo2& createInfo); + void createRenderPass(VkRenderPass renderPass, const VkRenderPassCreateInfo2& createInfo); /** * @brief Get the tracker for a native render pass. * * @param renderPass The native handle we are tracking. */ - RenderPass& getRenderPass( - VkRenderPass renderPass); + RenderPass& getRenderPass(VkRenderPass renderPass); /** * @brief Destroy a render pass within this device. * * @param renderPass The native handle to stop tracking. */ - void destroyRenderPass( - VkRenderPass renderPass); + void destroyRenderPass(VkRenderPass renderPass); /** * @brief Submit a command buffer to a queue within this device. * * @param commandBuffer The native command buffer we are tracking. */ - void queueSubmit( - VkCommandBuffer commandBuffer); + void queueSubmit(VkCommandBuffer commandBuffer); /** * @brief Submit a display present command to a queue within this device. diff --git a/source_common/trackers/layer_command_stream.cpp b/source_common/trackers/layer_command_stream.cpp index bb54cba..9d4cfd0 100644 --- a/source_common/trackers/layer_command_stream.cpp +++ b/source_common/trackers/layer_command_stream.cpp @@ -23,50 +23,43 @@ * ---------------------------------------------------------------------------- */ +#include "trackers/layer_command_stream.hpp" + #include -#include -#include "trackers/layer_command_stream.hpp" +#include using json = nlohmann::json; namespace Tracker { /* See header for details. */ -std::atomic LCSWorkload::nextTagID { 1 }; +std::atomic LCSWorkload::nextTagID {1}; -LCSWorkload::LCSWorkload( - uint64_t _tagID -): - tagID(_tagID) +LCSWorkload::LCSWorkload(uint64_t _tagID) + : tagID(_tagID) { - } /* See header for details. */ -LCSMarker::LCSMarker( - const std::string& _label -) : - LCSWorkload(0), - label(_label) -{ +LCSMarker::LCSMarker(const std::string& _label) + : LCSWorkload(0), + label(_label) { -}; + }; /* See header for details. */ -LCSRenderPass::LCSRenderPass( - uint64_t _tagID, - const RenderPass& renderPass, - uint32_t _width, - uint32_t _height, - bool _suspending, - bool _oneTimeSubmit -) : - LCSWorkload(_tagID), - width(_width), - height(_height), - suspending(_suspending), - oneTimeSubmit(_oneTimeSubmit) +LCSRenderPass::LCSRenderPass(uint64_t _tagID, + const RenderPass& renderPass, + uint32_t _width, + uint32_t _height, + bool _suspending, + bool _oneTimeSubmit) + : LCSWorkload(_tagID), + width(_width), + height(_height), + suspending(_suspending), + oneTimeSubmit(_oneTimeSubmit) { // Copy these as the render pass object may be transient. subpassCount = renderPass.getSubpassCount(); @@ -74,8 +67,7 @@ LCSRenderPass::LCSRenderPass( } /* See header for details. */ -std::string LCSRenderPass::getBeginMetadata( - const std::vector* debugLabel) const +std::string LCSRenderPass::getBeginMetadata(const std::vector* debugLabel) const { // Draw count for a multi-submit command buffer cannot be reliably // associated with a single tagID if restartable across command buffer @@ -88,11 +80,11 @@ std::string LCSRenderPass::getBeginMetadata( } json metadata = { - { "type", "renderpass" }, - { "tid", tagID }, - { "width", width }, - { "height", height }, - { "drawCallCount", drawCount } + {"type", "renderpass"}, + {"tid", tagID}, + {"width", width}, + {"height", height}, + {"drawCallCount", drawCount}, }; if (debugLabel && debugLabel->size()) @@ -110,7 +102,7 @@ std::string LCSRenderPass::getBeginMetadata( for (const auto& attachment : attachments) { json attachPoint { - { "binding", attachment.getAttachmentStr() }, + {"binding", attachment.getAttachmentStr()}, }; // Default is false, so only serialize if we need it @@ -139,14 +131,13 @@ std::string LCSRenderPass::getBeginMetadata( } /* See header for details. */ -std::string LCSRenderPass::getContinuationMetadata( - const std::vector* debugLabel, - uint64_t tagIDContinuation) const +std::string LCSRenderPass::getContinuationMetadata(const std::vector* debugLabel, + uint64_t tagIDContinuation) const { json metadata = { - { "type", "renderpass" }, - { "tid", tagIDContinuation }, - { "drawCallCount", drawCallCount } + {"type", "renderpass"}, + {"tid", tagIDContinuation}, + {"drawCallCount", drawCallCount}, }; if (debugLabel && debugLabel->size()) @@ -158,9 +149,7 @@ std::string LCSRenderPass::getContinuationMetadata( } /* See header for details. */ -std::string LCSRenderPass::getMetadata( - const std::vector* debugLabel, - uint64_t tagIDContinuation) const +std::string LCSRenderPass::getMetadata(const std::vector* debugLabel, uint64_t tagIDContinuation) const { if (tagID) { @@ -173,33 +162,25 @@ std::string LCSRenderPass::getMetadata( } /* See header for details. */ -LCSDispatch::LCSDispatch( - uint64_t _tagID, - int64_t _xGroups, - int64_t _yGroups, - int64_t _zGroups -) : - LCSWorkload(_tagID), - xGroups(_xGroups), - yGroups(_yGroups), - zGroups(_zGroups) +LCSDispatch::LCSDispatch(uint64_t _tagID, int64_t _xGroups, int64_t _yGroups, int64_t _zGroups) + : LCSWorkload(_tagID), + xGroups(_xGroups), + yGroups(_yGroups), + zGroups(_zGroups) { - } /* See header for details. */ -std::string LCSDispatch::getMetadata( - const std::vector* debugLabel, - uint64_t tagIDContinuation -) const { +std::string LCSDispatch::getMetadata(const std::vector* debugLabel, uint64_t tagIDContinuation) const +{ UNUSED(tagIDContinuation); json metadata = { - { "type", "dispatch" }, - { "tid", tagID }, - { "xGroups", xGroups }, - { "yGroups", yGroups }, - { "zGroups", zGroups } + {"type", "dispatch"}, + {"tid", tagID}, + {"xGroups", xGroups}, + {"yGroups", yGroups}, + {"zGroups", zGroups}, }; if (debugLabel && debugLabel->size()) @@ -211,33 +192,25 @@ std::string LCSDispatch::getMetadata( } /* See header for details. */ -LCSTraceRays::LCSTraceRays( - uint64_t _tagID, - int64_t _xItems, - int64_t _yItems, - int64_t _zItems -) : - LCSWorkload(_tagID), - xItems(_xItems), - yItems(_yItems), - zItems(_zItems) +LCSTraceRays::LCSTraceRays(uint64_t _tagID, int64_t _xItems, int64_t _yItems, int64_t _zItems) + : LCSWorkload(_tagID), + xItems(_xItems), + yItems(_yItems), + zItems(_zItems) { - } /* See header for details. */ -std::string LCSTraceRays::getMetadata( - const std::vector* debugLabel, - uint64_t tagIDContinuation -) const { +std::string LCSTraceRays::getMetadata(const std::vector* debugLabel, uint64_t tagIDContinuation) const +{ UNUSED(tagIDContinuation); json metadata = { - { "type", "tracerays" }, - { "tid", tagID }, - { "xItems", xItems }, - { "yItems", yItems }, - { "zItems", zItems } + {"type", "tracerays"}, + {"tid", tagID}, + {"xItems", xItems}, + {"yItems", yItems}, + {"zItems", zItems}, }; if (debugLabel && debugLabel->size()) @@ -249,31 +222,23 @@ std::string LCSTraceRays::getMetadata( } /* See header for details. */ -LCSImageTransfer::LCSImageTransfer( - uint64_t _tagID, - const std::string& _transferType, - int64_t _pixelCount -): - LCSWorkload(_tagID), - transferType(_transferType), - pixelCount(_pixelCount) +LCSImageTransfer::LCSImageTransfer(uint64_t _tagID, const std::string& _transferType, int64_t _pixelCount) + : LCSWorkload(_tagID), + transferType(_transferType), + pixelCount(_pixelCount) { - } /* See header for details. */ -std::string LCSImageTransfer::getMetadata( - const std::vector* debugLabel, - uint64_t tagIDContinuation -) const +std::string LCSImageTransfer::getMetadata(const std::vector* debugLabel, uint64_t tagIDContinuation) const { UNUSED(tagIDContinuation); json metadata = { - { "type", "imagetransfer" }, - { "tid", tagID }, - { "subtype", transferType }, - { "pixelCount", pixelCount } + {"type", "imagetransfer"}, + {"tid", tagID}, + {"subtype", transferType}, + {"pixelCount", pixelCount}, }; if (debugLabel && debugLabel->size()) @@ -285,30 +250,23 @@ std::string LCSImageTransfer::getMetadata( } /* See header for details. */ -LCSBufferTransfer::LCSBufferTransfer( - uint64_t _tagID, - const std::string& _transferType, - int64_t _byteCount -): - LCSWorkload(_tagID), - transferType(_transferType), - byteCount(_byteCount) +LCSBufferTransfer::LCSBufferTransfer(uint64_t _tagID, const std::string& _transferType, int64_t _byteCount) + : LCSWorkload(_tagID), + transferType(_transferType), + byteCount(_byteCount) { - } /* See header for details. */ -std::string LCSBufferTransfer::getMetadata( - const std::vector* debugLabel, - uint64_t tagIDContinuation -) const { +std::string LCSBufferTransfer::getMetadata(const std::vector* debugLabel, uint64_t tagIDContinuation) const +{ UNUSED(tagIDContinuation); json metadata = { - { "type", "buffertransfer" }, - { "tid", tagID }, - { "subtype", transferType }, - { "byteCount", byteCount } + {"type", "buffertransfer"}, + {"tid", tagID}, + {"subtype", transferType}, + {"byteCount", byteCount}, }; if (debugLabel && debugLabel->size()) diff --git a/source_common/trackers/layer_command_stream.hpp b/source_common/trackers/layer_command_stream.hpp index cd5528c..87f1e29 100644 --- a/source_common/trackers/layer_command_stream.hpp +++ b/source_common/trackers/layer_command_stream.hpp @@ -38,15 +38,16 @@ #pragma once +#include "trackers/render_pass.hpp" +#include "utils/misc.hpp" + #include #include #include #include #include -#include -#include "trackers/render_pass.hpp" -#include "utils/misc.hpp" +#include namespace Tracker { @@ -76,8 +77,7 @@ class LCSWorkload * * @param tagID The assigned tagID. */ - LCSWorkload( - uint64_t tagID); + LCSWorkload(uint64_t tagID); /** * @brief Destroy a workload. @@ -90,29 +90,22 @@ class LCSWorkload * @param debugLabel The debug label stack for the VkQueue at submit time. * @param tagIDContinuation The ID of the workload if this is a continuation of it. */ - virtual std::string getMetadata( - const std::vector* debugLabel=nullptr, - uint64_t tagIDContinuation=0) const = 0; + virtual std::string getMetadata(const std::vector* debugLabel = nullptr, + uint64_t tagIDContinuation = 0) const = 0; /** * @brief Get this workload's tagID. * * @return The assigned ID. */ - uint64_t getTagID() const - { - return tagID; - } + uint64_t getTagID() const { return tagID; } /** * @brief Get a unique tagID to label a workload in a command buffer. * * @return The assigned ID. */ - static uint64_t assignTagID() - { - return nextTagID.fetch_add(1, std::memory_order_relaxed); - } + static uint64_t assignTagID() { return nextTagID.fetch_add(1, std::memory_order_relaxed); } protected: /** @@ -145,13 +138,12 @@ class LCSRenderPass : public LCSWorkload * @param suspending Is this a render pass part that suspends later? * @param oneTimeSubmit Is this recorded into a one-time-submit command buffer? */ - LCSRenderPass( - uint64_t tagID, - const RenderPass& renderPass, - uint32_t width, - uint32_t height, - bool suspending, - bool oneTimeSubmit); + LCSRenderPass(uint64_t tagID, + const RenderPass& renderPass, + uint32_t width, + uint32_t height, + bool suspending, + bool oneTimeSubmit); /** * @brief Destroy a workload. @@ -163,25 +155,18 @@ class LCSRenderPass : public LCSWorkload * * @return @c true if this instance suspends rather than ends. */ - bool isSuspending() const - { - return suspending; - }; + bool isSuspending() const { return suspending; }; /** * @brief Update this workload with the final draw count. * * @param count The number of draw calls tracked by the command buffer. */ - void setDrawCallCount(uint64_t count) - { - drawCallCount = count; - }; + void setDrawCallCount(uint64_t count) { drawCallCount = count; }; /* See base class for documentation. */ - virtual std::string getMetadata( - const std::vector* debugLabel=nullptr, - uint64_t tagIDContinuation=0) const; + virtual std::string getMetadata(const std::vector* debugLabel = nullptr, + uint64_t tagIDContinuation = 0) const; private: /** @@ -189,8 +174,7 @@ class LCSRenderPass : public LCSWorkload * * @param debugLabel The debug label stack of the VkQueue at submit time. */ - std::string getBeginMetadata( - const std::vector* debugLabel=nullptr) const; + std::string getBeginMetadata(const std::vector* debugLabel = nullptr) const; /** * @brief Get the metadata for this workload if continuing an existing render pass. @@ -198,9 +182,8 @@ class LCSRenderPass : public LCSWorkload * @param debugLabel The debug label stack of the VkQueue at submit time. * @param tagIDContinuation The ID of the workload if this is a continuation of it. */ - std::string getContinuationMetadata( - const std::vector* debugLabel=nullptr, - uint64_t tagIDContinuation=0) const; + std::string getContinuationMetadata(const std::vector* debugLabel = nullptr, + uint64_t tagIDContinuation = 0) const; /** * @brief Width of this workload, in pixels. @@ -233,7 +216,7 @@ class LCSRenderPass : public LCSWorkload * Note: This is updated by ther command buffer tracker when the render * pass is suspended or ended. */ - uint64_t drawCallCount { 0 }; + uint64_t drawCallCount {0}; /** * @brief The attachments for this render pass. @@ -257,11 +240,7 @@ class LCSDispatch : public LCSWorkload * @param yGroups The number of work groups in the Y dimension. * @param zGroups The number of work groups in the Z dimension. */ - LCSDispatch( - uint64_t tagID, - int64_t xGroups, - int64_t yGroups, - int64_t zGroups); + LCSDispatch(uint64_t tagID, int64_t xGroups, int64_t yGroups, int64_t zGroups); /** * @brief Destroy a workload. @@ -269,9 +248,8 @@ class LCSDispatch : public LCSWorkload virtual ~LCSDispatch() = default; /* See base class for documentation. */ - virtual std::string getMetadata( - const std::vector* debugLabel=nullptr, - uint64_t tagIDContinuation=0) const; + virtual std::string getMetadata(const std::vector* debugLabel = nullptr, + uint64_t tagIDContinuation = 0) const; private: /** @@ -306,11 +284,7 @@ class LCSTraceRays : public LCSWorkload * @param yItems The number of work items in the Y dimension. * @param zItems The number of work items in the Z dimension. */ - LCSTraceRays( - uint64_t tagID, - int64_t xItems, - int64_t yItems, - int64_t zItems); + LCSTraceRays(uint64_t tagID, int64_t xItems, int64_t yItems, int64_t zItems); /** * @brief Destroy a workload. @@ -318,9 +292,8 @@ class LCSTraceRays : public LCSWorkload virtual ~LCSTraceRays() = default; /* See base class for documentation. */ - virtual std::string getMetadata( - const std::vector* debugLabel=nullptr, - uint64_t tagIDContinuation=0) const; + virtual std::string getMetadata(const std::vector* debugLabel = nullptr, + uint64_t tagIDContinuation = 0) const; private: /** @@ -354,10 +327,7 @@ class LCSImageTransfer : public LCSWorkload * @param transferType The subtype of the transfer. * @param pixelCount The size of the transfer, in pixels. */ - LCSImageTransfer( - uint64_t tagID, - const std::string& transferType, - int64_t pixelCount); + LCSImageTransfer(uint64_t tagID, const std::string& transferType, int64_t pixelCount); /** * @brief Destroy a workload. @@ -365,9 +335,8 @@ class LCSImageTransfer : public LCSWorkload virtual ~LCSImageTransfer() = default; /* See base class for documentation. */ - virtual std::string getMetadata( - const std::vector* debugLabel=nullptr, - uint64_t tagIDContinuation=0) const; + virtual std::string getMetadata(const std::vector* debugLabel = nullptr, + uint64_t tagIDContinuation = 0) const; private: /** @@ -397,10 +366,7 @@ class LCSBufferTransfer : public LCSWorkload * @param transferType The subtype of the transfer. * @param byteCount The size of the transfer, in bytes. */ - LCSBufferTransfer( - uint64_t tagID, - const std::string& transferType, - int64_t byteCount); + LCSBufferTransfer(uint64_t tagID, const std::string& transferType, int64_t byteCount); /** * @brief Destroy a workload. @@ -408,9 +374,8 @@ class LCSBufferTransfer : public LCSWorkload virtual ~LCSBufferTransfer() = default; /* See base class for documentation. */ - virtual std::string getMetadata( - const std::vector* debugLabel=nullptr, - uint64_t tagIDContinuation=0) const; + virtual std::string getMetadata(const std::vector* debugLabel = nullptr, + uint64_t tagIDContinuation = 0) const; private: /** @@ -438,8 +403,7 @@ class LCSMarker : public LCSWorkload * * @param label The application debug label. */ - LCSMarker( - const std::string& label); + LCSMarker(const std::string& label); /** * @brief Destroy a workload. @@ -447,9 +411,8 @@ class LCSMarker : public LCSWorkload virtual ~LCSMarker() = default; /* See base class for documentation. */ - virtual std::string getMetadata( - const std::vector* debugLabel=nullptr, - uint64_t tagIDContinuation=0) const + virtual std::string getMetadata(const std::vector* debugLabel = nullptr, + uint64_t tagIDContinuation = 0) const { UNUSED(debugLabel); UNUSED(tagIDContinuation); diff --git a/source_common/trackers/queue.cpp b/source_common/trackers/queue.cpp index 3677096..6acd15b 100644 --- a/source_common/trackers/queue.cpp +++ b/source_common/trackers/queue.cpp @@ -23,27 +23,23 @@ * ---------------------------------------------------------------------------- */ -#include - #include "trackers/queue.hpp" +#include + namespace Tracker { /* See header for details. */ -Queue::Queue( - VkQueue _handle -): - handle(_handle) -{ +Queue::Queue(VkQueue _handle) + : handle(_handle) { -}; + }; /* See header for details. */ -void Queue::runSubmitCommandStream( - const std::vector& stream, - std::function callback -) { - for (auto& instr: stream) +void Queue::runSubmitCommandStream(const std::vector& stream, + std::function callback) +{ + for (auto& instr : stream) { LCSOpcode opCode = instr.first; const LCSWorkload* opData = instr.second.get(); @@ -84,10 +80,8 @@ void Queue::runSubmitCommandStream( } } } - else if ((opCode == LCSOpcode::DISPATCH) || - (opCode == LCSOpcode::TRACE_RAYS) || - (opCode == LCSOpcode::IMAGE_TRANSFER) || - (opCode == LCSOpcode::BUFFER_TRANSFER)) + else if ((opCode == LCSOpcode::DISPATCH) || (opCode == LCSOpcode::TRACE_RAYS) + || (opCode == LCSOpcode::IMAGE_TRANSFER) || (opCode == LCSOpcode::BUFFER_TRANSFER)) { uint64_t tagID = opData->getTagID(); std::string log = joinString(debugStack, "|"); diff --git a/source_common/trackers/queue.hpp b/source_common/trackers/queue.hpp index 7f39b05..98a5f2f 100644 --- a/source_common/trackers/queue.hpp +++ b/source_common/trackers/queue.hpp @@ -41,14 +41,15 @@ #pragma once +#include "framework/utils.hpp" +#include "trackers/layer_command_stream.hpp" + #include #include #include #include -#include -#include "framework/utils.hpp" -#include "trackers/layer_command_stream.hpp" +#include namespace Tracker { @@ -59,8 +60,7 @@ namespace Tracker class Queue { public: - Queue( - VkQueue handle); + Queue(VkQueue handle); /** * @brief Execute a layer command stream. @@ -68,9 +68,8 @@ class Queue * @param stream The layer command stream to execute. * @param callback The callback to pass submitted workloads to. */ - void runSubmitCommandStream( - const std::vector& stream, - std::function callback); + void runSubmitCommandStream(const std::vector& stream, + std::function callback); private: /** @@ -86,7 +85,7 @@ class Queue /** * @brief The last non-zero render pass tagID submitted. */ - uint64_t lastRenderPassTagID { 0 }; + uint64_t lastRenderPassTagID {0}; }; } diff --git a/source_common/trackers/render_pass.cpp b/source_common/trackers/render_pass.cpp index 8a6da5e..e110c1e 100644 --- a/source_common/trackers/render_pass.cpp +++ b/source_common/trackers/render_pass.cpp @@ -23,32 +23,29 @@ * ---------------------------------------------------------------------------- */ -#include - #include "trackers/render_pass.hpp" +#include + namespace Tracker { /* See header for details. */ -RenderPassAttachment::RenderPassAttachment( - RenderPassAttachName _name, - VkAttachmentLoadOp _loadOp, - VkAttachmentStoreOp _storeOp, - bool _resolve -) : - name(_name), - loadOp(_loadOp), - storeOp(_storeOp), - resolve(_resolve) +RenderPassAttachment::RenderPassAttachment(RenderPassAttachName _name, + VkAttachmentLoadOp _loadOp, + VkAttachmentStoreOp _storeOp, + bool _resolve) + : name(_name), + loadOp(_loadOp), + storeOp(_storeOp), + resolve(_resolve) { - } /* See header for details. */ std::string RenderPassAttachment::getAttachmentStr() const { - switch(name) + switch (name) { case RenderPassAttachName::COLOR0: return "C0"; @@ -78,18 +75,15 @@ std::string RenderPassAttachment::getAttachmentStr() const } /* See header for details. */ -RenderPass::RenderPass( - VkRenderPass _handle, - const VkRenderPassCreateInfo& createInfo -) : - handle(_handle) +RenderPass::RenderPass(VkRenderPass _handle, const VkRenderPassCreateInfo& createInfo) + : handle(_handle) { subpassCount = createInfo.subpassCount; auto& lastSubpass = createInfo.pSubpasses[subpassCount - 1]; // Color attachments - for(uint32_t i = 0; i < lastSubpass.colorAttachmentCount; i++) + for (uint32_t i = 0; i < lastSubpass.colorAttachmentCount; i++) { auto& attachRef = lastSubpass.pColorAttachments[i]; if (attachRef.attachment == VK_ATTACHMENT_UNUSED) @@ -98,15 +92,11 @@ RenderPass::RenderPass( } auto& attachDesc = createInfo.pAttachments[attachRef.attachment]; - attachments.emplace_back( - static_cast(i), - attachDesc.loadOp, - attachDesc.storeOp, - false); + attachments.emplace_back(static_cast(i), attachDesc.loadOp, attachDesc.storeOp, false); } // Color resolve attachments - for(uint32_t i = 0; i < lastSubpass.colorAttachmentCount; i++) + for (uint32_t i = 0; i < lastSubpass.colorAttachmentCount; i++) { // We may not have any resolve attachments if (!lastSubpass.pResolveAttachments) @@ -121,11 +111,7 @@ RenderPass::RenderPass( } auto& attachDesc = createInfo.pAttachments[attachRef.attachment]; - attachments.emplace_back( - static_cast(i), - attachDesc.loadOp, - attachDesc.storeOp, - true); + attachments.emplace_back(static_cast(i), attachDesc.loadOp, attachDesc.storeOp, true); } // Depth+Stencil attachments @@ -139,66 +125,55 @@ RenderPass::RenderPass( // Canonicalize read-only attachments as storeOp=NONE VkAttachmentStoreOp depthStoreOp; - switch(attachRef.layout) + switch (attachRef.layout) { - case VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL: - case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: - case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL: - if (attachDesc.storeOp == VK_ATTACHMENT_STORE_OP_STORE) - { - depthStoreOp = VK_ATTACHMENT_STORE_OP_NONE; - } - break; - default: - depthStoreOp = attachDesc.storeOp; - break; + case VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL: + case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: + case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL: + if (attachDesc.storeOp == VK_ATTACHMENT_STORE_OP_STORE) + { + depthStoreOp = VK_ATTACHMENT_STORE_OP_NONE; + } + break; + default: + depthStoreOp = attachDesc.storeOp; + break; } - attachments.emplace_back( - RenderPassAttachName::DEPTH, - attachDesc.loadOp, - depthStoreOp, - false); + attachments.emplace_back(RenderPassAttachName::DEPTH, attachDesc.loadOp, depthStoreOp, false); // Canonicalize read-only attachments as storeOp=NONE VkAttachmentStoreOp stencilStoreOp; - switch(attachRef.layout) + switch (attachRef.layout) { - case VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL: - case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: - case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL: - if (attachDesc.stencilStoreOp == VK_ATTACHMENT_STORE_OP_STORE) - { - stencilStoreOp = VK_ATTACHMENT_STORE_OP_NONE; - } - break; - default: - stencilStoreOp = attachDesc.stencilStoreOp; - break; + case VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL: + case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: + case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL: + if (attachDesc.stencilStoreOp == VK_ATTACHMENT_STORE_OP_STORE) + { + stencilStoreOp = VK_ATTACHMENT_STORE_OP_NONE; + } + break; + default: + stencilStoreOp = attachDesc.stencilStoreOp; + break; } - attachments.emplace_back( - RenderPassAttachName::STENCIL, - attachDesc.stencilLoadOp, - stencilStoreOp, - false); + attachments.emplace_back(RenderPassAttachName::STENCIL, attachDesc.stencilLoadOp, stencilStoreOp, false); } } } /* See header for details. */ -RenderPass::RenderPass( - VkRenderPass _handle, - const VkRenderPassCreateInfo2& createInfo -) : - handle(_handle) +RenderPass::RenderPass(VkRenderPass _handle, const VkRenderPassCreateInfo2& createInfo) + : handle(_handle) { subpassCount = createInfo.subpassCount; auto& lastSubpass = createInfo.pSubpasses[subpassCount - 1]; // Color attachments - for(uint32_t i = 0; i < lastSubpass.colorAttachmentCount; i++) + for (uint32_t i = 0; i < lastSubpass.colorAttachmentCount; i++) { auto& attachRef = lastSubpass.pColorAttachments[i]; if (attachRef.attachment == VK_ATTACHMENT_UNUSED) @@ -207,15 +182,11 @@ RenderPass::RenderPass( } auto& attachDesc = createInfo.pAttachments[attachRef.attachment]; - attachments.emplace_back( - static_cast(i), - attachDesc.loadOp, - attachDesc.storeOp, - false); + attachments.emplace_back(static_cast(i), attachDesc.loadOp, attachDesc.storeOp, false); } // Color resolve attachments - for(uint32_t i = 0; i < lastSubpass.colorAttachmentCount; i++) + for (uint32_t i = 0; i < lastSubpass.colorAttachmentCount; i++) { // We may not have any resolve attachments if (!lastSubpass.pResolveAttachments) @@ -230,11 +201,7 @@ RenderPass::RenderPass( } auto& attachDesc = createInfo.pAttachments[attachRef.attachment]; - attachments.emplace_back( - static_cast(i), - attachDesc.loadOp, - attachDesc.storeOp, - true); + attachments.emplace_back(static_cast(i), attachDesc.loadOp, attachDesc.storeOp, true); } // Depth+Stencil attachments @@ -248,64 +215,54 @@ RenderPass::RenderPass( // Canonicalize read-only attachments as storeOp=NONE VkAttachmentStoreOp depthStoreOp; - switch(attachRef.layout) + switch (attachRef.layout) { - case VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL: - case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: - case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL: - if (attachDesc.storeOp == VK_ATTACHMENT_STORE_OP_STORE) - { - depthStoreOp = VK_ATTACHMENT_STORE_OP_NONE; - } - break; - default: - depthStoreOp = attachDesc.storeOp; - break; + case VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL: + case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: + case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL: + if (attachDesc.storeOp == VK_ATTACHMENT_STORE_OP_STORE) + { + depthStoreOp = VK_ATTACHMENT_STORE_OP_NONE; + } + break; + default: + depthStoreOp = attachDesc.storeOp; + break; } - attachments.emplace_back( - RenderPassAttachName::DEPTH, - attachDesc.loadOp, - depthStoreOp, - false); + attachments.emplace_back(RenderPassAttachName::DEPTH, attachDesc.loadOp, depthStoreOp, false); // Canonicalize read-only attachments as storeOp=NONE VkAttachmentStoreOp stencilStoreOp; - switch(attachRef.layout) + switch (attachRef.layout) { - case VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL: - case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: - case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL: - if (attachDesc.stencilStoreOp == VK_ATTACHMENT_STORE_OP_STORE) - { - stencilStoreOp = VK_ATTACHMENT_STORE_OP_NONE; - } - break; - default: - stencilStoreOp = attachDesc.stencilStoreOp; - break; + case VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL: + case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: + case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL: + if (attachDesc.stencilStoreOp == VK_ATTACHMENT_STORE_OP_STORE) + { + stencilStoreOp = VK_ATTACHMENT_STORE_OP_NONE; + } + break; + default: + stencilStoreOp = attachDesc.stencilStoreOp; + break; } - attachments.emplace_back( - RenderPassAttachName::STENCIL, - attachDesc.stencilLoadOp, - stencilStoreOp, - false); + attachments.emplace_back(RenderPassAttachName::STENCIL, attachDesc.stencilLoadOp, stencilStoreOp, false); } } } /* See header for details. */ -RenderPass::RenderPass( - const VkRenderingInfo& createInfo -) : - handle(VK_NULL_HANDLE) +RenderPass::RenderPass(const VkRenderingInfo& createInfo) + : handle(VK_NULL_HANDLE) { // No subpasses in dynamic rendering subpassCount = 1; // Color attachments - for(uint32_t i = 0; i < createInfo.colorAttachmentCount; i++) + for (uint32_t i = 0; i < createInfo.colorAttachmentCount; i++) { auto& attachRef = createInfo.pColorAttachments[i]; if (attachRef.imageView == VK_NULL_HANDLE) @@ -313,28 +270,22 @@ RenderPass::RenderPass( continue; } - attachments.emplace_back( - static_cast(i), - attachRef.loadOp, - attachRef.storeOp, - false); + attachments.emplace_back(static_cast(i), attachRef.loadOp, attachRef.storeOp, false); } // Color resolve attachments - for(uint32_t i = 0; i < createInfo.colorAttachmentCount; i++) + for (uint32_t i = 0; i < createInfo.colorAttachmentCount; i++) { auto& attachRef = createInfo.pColorAttachments[i]; - if ((attachRef.imageView == VK_NULL_HANDLE) || - (attachRef.resolveMode == VK_RESOLVE_MODE_NONE)) + if ((attachRef.imageView == VK_NULL_HANDLE) || (attachRef.resolveMode == VK_RESOLVE_MODE_NONE)) { continue; } - attachments.emplace_back( - static_cast(i), - VK_ATTACHMENT_LOAD_OP_DONT_CARE, - VK_ATTACHMENT_STORE_OP_STORE, - true); + attachments.emplace_back(static_cast(i), + VK_ATTACHMENT_LOAD_OP_DONT_CARE, + VK_ATTACHMENT_STORE_OP_STORE, + true); } // Depth attachments @@ -344,36 +295,30 @@ RenderPass::RenderPass( // Canonicalize read-only attachments as storeOp=NONE VkAttachmentStoreOp depthStoreOp; - switch(attachRef.imageLayout) + switch (attachRef.imageLayout) { - case VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL: - case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: - case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL: - if (attachRef.storeOp == VK_ATTACHMENT_STORE_OP_STORE) - { - depthStoreOp = VK_ATTACHMENT_STORE_OP_NONE; - } - break; - default: - depthStoreOp = attachRef.storeOp; - break; + case VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL: + case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: + case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL: + if (attachRef.storeOp == VK_ATTACHMENT_STORE_OP_STORE) + { + depthStoreOp = VK_ATTACHMENT_STORE_OP_NONE; + } + break; + default: + depthStoreOp = attachRef.storeOp; + break; } - attachments.emplace_back( - RenderPassAttachName::DEPTH, - attachRef.loadOp, - depthStoreOp, - false); + attachments.emplace_back(RenderPassAttachName::DEPTH, attachRef.loadOp, depthStoreOp, false); // Depth resolve attachment - if ((attachRef.imageView != VK_NULL_HANDLE) && - (attachRef.resolveMode != VK_RESOLVE_MODE_NONE)) + if ((attachRef.imageView != VK_NULL_HANDLE) && (attachRef.resolveMode != VK_RESOLVE_MODE_NONE)) { - attachments.emplace_back( - RenderPassAttachName::DEPTH, - VK_ATTACHMENT_LOAD_OP_DONT_CARE, - VK_ATTACHMENT_STORE_OP_STORE, - true); + attachments.emplace_back(RenderPassAttachName::DEPTH, + VK_ATTACHMENT_LOAD_OP_DONT_CARE, + VK_ATTACHMENT_STORE_OP_STORE, + true); } } @@ -384,38 +329,32 @@ RenderPass::RenderPass( // Canonicalize read-only attachments as storeOp=NONE VkAttachmentStoreOp stencilStoreOp; - switch(attachRef.imageLayout) + switch (attachRef.imageLayout) { - case VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL: - case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: - case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL: - if (attachRef.storeOp == VK_ATTACHMENT_STORE_OP_STORE) - { - stencilStoreOp = VK_ATTACHMENT_STORE_OP_NONE; - } - break; - default: - stencilStoreOp = attachRef.storeOp; - break; + case VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL: + case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: + case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL: + if (attachRef.storeOp == VK_ATTACHMENT_STORE_OP_STORE) + { + stencilStoreOp = VK_ATTACHMENT_STORE_OP_NONE; + } + break; + default: + stencilStoreOp = attachRef.storeOp; + break; } - attachments.emplace_back( - RenderPassAttachName::STENCIL, - attachRef.loadOp, - stencilStoreOp, - false); + attachments.emplace_back(RenderPassAttachName::STENCIL, attachRef.loadOp, stencilStoreOp, false); // Stencil resolve attachment - if ((attachRef.imageView != VK_NULL_HANDLE) && - (attachRef.resolveMode != VK_RESOLVE_MODE_NONE)) + if ((attachRef.imageView != VK_NULL_HANDLE) && (attachRef.resolveMode != VK_RESOLVE_MODE_NONE)) { - attachments.emplace_back( - RenderPassAttachName::STENCIL, - VK_ATTACHMENT_LOAD_OP_DONT_CARE, - VK_ATTACHMENT_STORE_OP_STORE, - true); + attachments.emplace_back(RenderPassAttachName::STENCIL, + VK_ATTACHMENT_LOAD_OP_DONT_CARE, + VK_ATTACHMENT_STORE_OP_STORE, + true); } } } -} \ No newline at end of file +} diff --git a/source_common/trackers/render_pass.hpp b/source_common/trackers/render_pass.hpp index 92d964d..c45c634 100644 --- a/source_common/trackers/render_pass.hpp +++ b/source_common/trackers/render_pass.hpp @@ -38,6 +38,7 @@ #include #include #include + #include namespace Tracker @@ -74,11 +75,10 @@ class RenderPassAttachment * @param storeOp The render pass storeOp for this attachment. * @param resolve Is this a resolve attachment or the main attachment? */ - RenderPassAttachment( - RenderPassAttachName name, - VkAttachmentLoadOp loadOp, - VkAttachmentStoreOp storeOp, - bool resolve); + RenderPassAttachment(RenderPassAttachName name, + VkAttachmentLoadOp loadOp, + VkAttachmentStoreOp storeOp, + bool resolve); /** * @brief Get a string form of the attachment point name. @@ -92,21 +92,14 @@ class RenderPassAttachment * * @return @c true if loaded from memory. */ - bool isLoaded() const - { - return loadOp == VK_ATTACHMENT_LOAD_OP_LOAD; - } + bool isLoaded() const { return loadOp == VK_ATTACHMENT_LOAD_OP_LOAD; } /** * @brief Is this attachment stored at the end of the render pass? * * @return @c true if stored to memory. */ - bool isStored() const - { - return storeOp == VK_ATTACHMENT_STORE_OP_STORE; - } - + bool isStored() const { return storeOp == VK_ATTACHMENT_STORE_OP_STORE; } /** * @brief Is this attachment a resolve attachment? @@ -116,10 +109,7 @@ class RenderPassAttachment * * @return @c true if this is a resolve attachment. */ - bool isResolved() const - { - return resolve; - } + bool isResolved() const { return resolve; } private: /** @@ -155,9 +145,7 @@ class RenderPass * @param handle The driver handle of the render pass. * @param createInfo The API context creating the render pass. */ - RenderPass( - VkRenderPass handle, - const VkRenderPassCreateInfo& createInfo); + RenderPass(VkRenderPass handle, const VkRenderPassCreateInfo& createInfo); /** * @brief Construct a new render pass from Vulkan 1.0-style render passes. @@ -165,17 +153,14 @@ class RenderPass * @param handle The driver handle of the render pass. * @param createInfo The API context creating the render pass. */ - RenderPass( - VkRenderPass handle, - const VkRenderPassCreateInfo2& createInfo); + RenderPass(VkRenderPass handle, const VkRenderPassCreateInfo2& createInfo); /** * @brief Construct a new render pass from Vulkan 1.3 dynamic rendering. * * @param createInfo The API context starting the render pass. */ - RenderPass( - const VkRenderingInfo& createInfo); + RenderPass(const VkRenderingInfo& createInfo); /** * @brief Get the number of subpasses in the render pass. @@ -183,18 +168,12 @@ class RenderPass * @return The number of subpasses. Always returns 1 for dynamic render * passes which no longer use subpasses. */ - uint32_t getSubpassCount() const - { - return subpassCount; - }; + uint32_t getSubpassCount() const { return subpassCount; }; /** * @brief Get the attachment list for the render pass. */ - const std::vector& getAttachments() const - { - return attachments; - }; + const std::vector& getAttachments() const { return attachments; }; private: /** @@ -205,7 +184,7 @@ class RenderPass /** * @brief The render pass subpass count. */ - uint32_t subpassCount { 1 }; + uint32_t subpassCount {1}; /** * @brief The render pass attachments in this render pass. diff --git a/source_common/trackers/stats.hpp b/source_common/trackers/stats.hpp index 2d297ed..9f4b47b 100644 --- a/source_common/trackers/stats.hpp +++ b/source_common/trackers/stats.hpp @@ -32,6 +32,7 @@ #include #include + #include namespace Tracker @@ -50,58 +51,37 @@ class Stats /** * @brief Increment the frame counter. */ - void incFrameCount() - { - frameCount += 1; - } + void incFrameCount() { frameCount += 1; } /** * @brief Increment the render pass counter. */ - void incRenderPassCount() - { - renderPassCount += 1; - } + void incRenderPassCount() { renderPassCount += 1; } /** * @brief Increment the draw counter. */ - void incDrawCallCount() - { - drawCallCount += 1; - } + void incDrawCallCount() { drawCallCount += 1; } /** * @brief Increment the compute dispatch counter. */ - void incDispatchCount() - { - dispatchCount += 1; - } + void incDispatchCount() { dispatchCount += 1; } /** * @brief Increment the trace rays counter. */ - void incTraceRaysCount() - { - traceRaysCount += 1; - }; + void incTraceRaysCount() { traceRaysCount += 1; }; /** * @brief Increment the buffer transfer counter. */ - void incBufferTransferCount() - { - bufferTransferCount += 1; - } + void incBufferTransferCount() { bufferTransferCount += 1; } /** * @brief Increment the image transfer counter. */ - void incImageTransferCount() - { - imageTransferCount += 1; - } + void incImageTransferCount() { imageTransferCount += 1; } /** * @brief Increment all counters with values from another stats object. @@ -134,94 +114,77 @@ class Stats /** * @brief Get the frame counter. */ - uint64_t getFrameCount() const - { - return frameCount; - } + uint64_t getFrameCount() const { return frameCount; } /** * @brief Increment the render pass counter. */ - uint64_t getRenderPassCount() const - { - return renderPassCount; - } + uint64_t getRenderPassCount() const { return renderPassCount; } /** * @brief Increment the draw counter. */ - uint64_t getDrawCallCount() const - { - return drawCallCount; - } + uint64_t getDrawCallCount() const { return drawCallCount; } /** * @brief Increment the compute dispatch counter. */ - uint64_t getDispatchCount() const - { - return dispatchCount; - } + uint64_t getDispatchCount() const { return dispatchCount; } /** * @brief Increment the trace rays counter. */ - uint64_t getTraceRaysCount() const - { - return traceRaysCount; - }; + uint64_t getTraceRaysCount() const { return traceRaysCount; }; /** * @brief Increment the buffer transfer counter. */ - uint64_t getBufferTransferCount() const - { - return bufferTransferCount; - } + uint64_t getBufferTransferCount() const { return bufferTransferCount; } /** * @brief Increment the image transfer counter. */ uint64_t getImageTransferCount() const { - return imageTransferCount;; + return imageTransferCount; + ; } private: /** * @brief The number of frames tracked. */ - uint64_t frameCount { 0 }; + uint64_t frameCount {0}; /** * @brief The number of render passes tracked. */ - uint64_t renderPassCount { 0 }; + uint64_t renderPassCount {0}; /** * @brief The number of draw calls tracked. */ - uint64_t drawCallCount { 0 }; + uint64_t drawCallCount {0}; /** * @brief The number of compute dispatches tracked. */ - uint64_t dispatchCount { 0 }; + uint64_t dispatchCount {0}; /** * @brief The number of trace rays calls tracked. */ - uint64_t traceRaysCount { 0 }; + uint64_t traceRaysCount {0}; /** * @brief The number of buffer transfers tracked. */ - uint64_t bufferTransferCount { 0 }; + uint64_t bufferTransferCount {0}; /** * @brief The number of image transfers tracked. */ - uint64_t imageTransferCount { 0 }; + uint64_t imageTransferCount {0}; }; }