Skip to content

Use VUL safe_struct #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
[submodule "khronos/vulkan"]
path = source_third_party/khronos/vulkan
url = https://github.com/KhronosGroup/Vulkan-Headers
[submodule "khronos/opengles"]
path = source_third_party/khronos/opengles
url = https://github.com/KhronosGroup/OpenGL-Registry
[submodule "khronos/egl"]
path = source_third_party/khronos/egl
url = https://github.com/KhronosGroup/EGL-Registry
[submodule "source_third_party/gtest"]
path = source_third_party/gtest
url = https://github.com/google/googletest
[submodule "source_third_party/protopuf"]
path = source_third_party/protopuf
url = https://github.com/PragmaTwice/protopuf.git
[submodule "source_third_party/khronos/vulkan-utilities"]
path = source_third_party/khronos/vulkan-utilities
url = https://github.com/KhronosGroup/Vulkan-Utility-Libraries/
3 changes: 2 additions & 1 deletion generator/vk_codegen/source_CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ target_include_directories(

target_include_directories(
${VK_LAYER} SYSTEM PRIVATE
../../source_third_party/khronos/vulkan/include/)
../../source_third_party/khronos/vulkan/include/
../../source_third_party/khronos/vulkan-utilities/include/)

lgl_set_build_options(${VK_LAYER})

Expand Down
3 changes: 2 additions & 1 deletion layer_example/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ target_include_directories(

target_include_directories(
${VK_LAYER} SYSTEM PRIVATE
../../source_third_party/khronos/vulkan/include/)
../../source_third_party/khronos/vulkan/include/
../../source_third_party/khronos/vulkan-utilities/include/)

lgl_set_build_options(${VK_LAYER})

Expand Down
3 changes: 2 additions & 1 deletion layer_gpu_support/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ target_include_directories(
target_include_directories(
${VK_LAYER} SYSTEM PRIVATE
../../source_third_party/
../../source_third_party/khronos/vulkan/include/)
../../source_third_party/khronos/vulkan/include/
../../source_third_party/khronos/vulkan-utilities/include/)

lgl_set_build_options(${VK_LAYER})

Expand Down
29 changes: 13 additions & 16 deletions layer_gpu_support/source/layer_device_functions_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* IN THE SOFTWARE.
* ----------------------------------------------------------------------------
*/
#include <vulkan/utility/vk_safe_struct.hpp>
#include <vulkan/utility/vk_struct_helper.hpp>

#include "device.hpp"
#include "framework/device_dispatch_table.hpp"
Expand Down Expand Up @@ -119,40 +121,36 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateImage<user_tag>(VkDevice device,
}
}

VkImageCreateInfo newCreateInfo = *pCreateInfo;

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<VkImageCompressionControlEXT>(VK_STRUCTURE_TYPE_IMAGE_COMPRESSION_CONTROL_EXT,
pCreateInfo->pNext);
// Create modifiable structures we can patch
vku::safe_VkImageCreateInfo newCreateInfoSafe(pCreateInfo);
auto* newCreateInfo = reinterpret_cast<VkImageCreateInfo*>(&newCreateInfoSafe);
void* pNextBase = const_cast<void*>(newCreateInfoSafe.pNext);

// Create extra structures we allocate here, but populate elsewhere
VkImageCompressionControlEXT newCompressionControl = vku::InitStructHelper();
VkImageCompressionControlEXT* compressionControl = &newCompressionControl;

auto* userCompressionControl = vku::FindStructInPNextChain<VkImageCompressionControlEXT>(pNextBase);
if (userCompressionControl)
{
compressionControl = userCompressionControl;
}

bool patchNeeded = compressionControl != userCompressionControl;

if (forceDisable)
{
compressionControl->sType = VK_STRUCTURE_TYPE_IMAGE_COMPRESSION_CONTROL_EXT;
compressionControl->flags = VK_IMAGE_COMPRESSION_DISABLED_EXT;
compressionControl->compressionControlPlaneCount = 0;
compressionControl->pFixedRateFlags = nullptr;
}
else if (forceDefault)
{
compressionControl->sType = VK_STRUCTURE_TYPE_IMAGE_COMPRESSION_CONTROL_EXT;
compressionControl->flags = VK_IMAGE_COMPRESSION_DEFAULT_EXT;
compressionControl->compressionControlPlaneCount = 0;
compressionControl->pFixedRateFlags = nullptr;
}
else if (selectedLevel)
{
compressionControl->sType = VK_STRUCTURE_TYPE_IMAGE_COMPRESSION_CONTROL_EXT;
compressionControl->flags = VK_IMAGE_COMPRESSION_FIXED_RATE_EXPLICIT_EXT;
compressionControl->compressionControlPlaneCount = 1;
compressionControl->pFixedRateFlags = reinterpret_cast<VkImageCompressionFixedRateFlagsEXT*>(&selectedLevel);
Expand All @@ -162,12 +160,11 @@ VKAPI_ATTR VkResult VKAPI_CALL layer_vkCreateImage<user_tag>(VkDevice device,
patchNeeded = false;
}

// If this is new, patch it in to the pNext chain
// Add a config if not already configured by the application
if (patchNeeded)
{
compressionControl->pNext = newCreateInfo.pNext;
newCreateInfo.pNext = reinterpret_cast<const void*>(compressionControl);
vku::AddToPnext(newCreateInfoSafe, *compressionControl);
}

return layer->driver.vkCreateImage(device, &newCreateInfo, pAllocator, pImage);
return layer->driver.vkCreateImage(device, newCreateInfo, pAllocator, pImage);
}
1 change: 1 addition & 0 deletions layer_gpu_timeline/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ target_include_directories(
${VK_LAYER} SYSTEM PRIVATE
../../source_third_party/
../../source_third_party/khronos/vulkan/include/
../../source_third_party/khronos/vulkan-utilities/include/
../../source_third_party/protopuf/include/)

lgl_set_build_options(${VK_LAYER})
Expand Down
7 changes: 4 additions & 3 deletions source_common/comms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: MIT
# -----------------------------------------------------------------------------
# Copyright (c) 2024 Arm Limited
# Copyright (c) 2024-2025 Arm Limited
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -33,12 +33,13 @@ add_library(
target_include_directories(
${LIB_BINARY} PRIVATE
../
../../source_third_party/khronos/vulkan/include/)
../../source_third_party/khronos/vulkan/include/
../../source_third_party/khronos/vulkan-utilities/include/)

lgl_set_build_options(${LIB_BINARY})

if(${LGL_UNITTEST})
add_subdirectory(test)
endif()

add_clang_tools()
add_clang_tools()
5 changes: 3 additions & 2 deletions source_common/comms/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: MIT
# -----------------------------------------------------------------------------
# Copyright (c) 2024 Arm Limited
# Copyright (c) 2024-2025 Arm Limited
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -34,6 +34,7 @@ target_include_directories(
../../
../../../source_third_party/
../../../source_third_party/khronos/vulkan/include
../../source_third_party/khronos/vulkan-utilities/include/
${gtest_SOURCE_DIR}/include)

target_link_libraries(
Expand Down Expand Up @@ -76,4 +77,4 @@ install(
TARGETS ${TEST_BINARY}
DESTINATION bin)

add_clang_tools()
add_clang_tools()
14 changes: 10 additions & 4 deletions source_common/framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ set(LIB_BINARY lib_layer_framework)
add_library(
${LIB_BINARY} STATIC
device_functions.cpp
device_query.cpp
instance_functions.cpp
manual_functions.cpp)
manual_functions.cpp
../../source_third_party/khronos/vulkan-utilities/src/vulkan/vk_safe_struct_core.cpp
../../source_third_party/khronos/vulkan-utilities/src/vulkan/vk_safe_struct_ext.cpp
../../source_third_party/khronos/vulkan-utilities/src/vulkan/vk_safe_struct_khr.cpp
../../source_third_party/khronos/vulkan-utilities/src/vulkan/vk_safe_struct_manual.cpp
../../source_third_party/khronos/vulkan-utilities/src/vulkan/vk_safe_struct_utils.cpp
../../source_third_party/khronos/vulkan-utilities/src/vulkan/vk_safe_struct_vendor.cpp)

target_include_directories(
${LIB_BINARY} PRIVATE
Expand All @@ -41,8 +46,9 @@ target_include_directories(
${LIB_BINARY} SYSTEM PRIVATE
../
../../source_third_party/
../../source_third_party/khronos/vulkan/include/)
../../source_third_party/khronos/vulkan/include/
../../source_third_party/khronos/vulkan-utilities/include/)

lgl_set_build_options(${LIB_BINARY})

add_clang_tools()
add_clang_tools()
60 changes: 0 additions & 60 deletions source_common/framework/device_query.cpp

This file was deleted.

44 changes: 0 additions & 44 deletions source_common/framework/device_query.hpp

This file was deleted.

Loading