Skip to content
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
111 changes: 111 additions & 0 deletions framework/core/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: AfterColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: true
IndentPPDirectives: AfterHash
IndentWidth: 4
IndentWrappedFunctionNames: true
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: false
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 8
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: ForIndentation
---
Language: ObjC
DisableFormat: true
...
154 changes: 81 additions & 73 deletions framework/core/acceleration_structure.cpp

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions framework/core/acceleration_structure.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2021-2025, Sascha Willems
/* Copyright (c) 2021-2026, Sascha Willems
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -40,8 +40,7 @@ class AccelerationStructure
* @param device A valid Vulkan device
* @param type The type of the acceleration structure (top- or bottom-level)
*/
AccelerationStructure(vkb::core::DeviceC &device,
VkAccelerationStructureTypeKHR type);
AccelerationStructure(vkb::core::DeviceC &device, VkAccelerationStructureTypeKHR type);

~AccelerationStructure();

Expand Down Expand Up @@ -76,15 +75,16 @@ class AccelerationStructure
uint64_t index_buffer_data_address = 0,
uint64_t transform_buffer_data_address = 0);

void update_triangle_geometry(uint64_t triangleUUID, std::unique_ptr<vkb::core::BufferC> &vertex_buffer,
void update_triangle_geometry(uint64_t triangleUUID,
std::unique_ptr<vkb::core::BufferC> &vertex_buffer,
std::unique_ptr<vkb::core::BufferC> &index_buffer,
std::unique_ptr<vkb::core::BufferC> &transform_buffer,
uint32_t triangle_count,
uint32_t max_vertex,
VkDeviceSize vertex_stride,
uint32_t transform_offset = 0,
VkFormat vertex_format = VK_FORMAT_R32G32B32_SFLOAT,
VkGeometryFlagsKHR flags = VK_GEOMETRY_OPAQUE_BIT_KHR,
uint32_t transform_offset = 0,
VkFormat vertex_format = VK_FORMAT_R32G32B32_SFLOAT,
VkGeometryFlagsKHR flags = VK_GEOMETRY_OPAQUE_BIT_KHR,
uint64_t vertex_buffer_data_address = 0,
uint64_t index_buffer_data_address = 0,
uint64_t transform_buffer_data_address = 0);
Expand All @@ -102,10 +102,11 @@ class AccelerationStructure
uint32_t transform_offset = 0,
VkGeometryFlagsKHR flags = VK_GEOMETRY_OPAQUE_BIT_KHR);

void update_instance_geometry(uint64_t instance_UID, std::unique_ptr<vkb::core::BufferC> &instance_buffer,
uint32_t instance_count,
uint32_t transform_offset = 0,
VkGeometryFlagsKHR flags = VK_GEOMETRY_OPAQUE_BIT_KHR);
void update_instance_geometry(uint64_t instance_UID,
std::unique_ptr<vkb::core::BufferC> &instance_buffer,
uint32_t instance_count,
uint32_t transform_offset = 0,
VkGeometryFlagsKHR flags = VK_GEOMETRY_OPAQUE_BIT_KHR);

/**
* @brief Builds the acceleration structure on the device (requires at least one geometry to be added)
Expand Down
88 changes: 50 additions & 38 deletions framework/core/allocated.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ void init(const DeviceType &device)
allocator_info.device = static_cast<VkDevice>(device.get_handle());
allocator_info.instance = static_cast<VkInstance>(device.get_gpu().get_instance().get_handle());

bool can_get_memory_requirements = device.get_gpu().is_extension_supported(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME);
bool has_dedicated_allocation = device.get_gpu().is_extension_supported(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME);
if (can_get_memory_requirements && has_dedicated_allocation && device.is_extension_enabled(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME))
bool can_get_memory_requirements =
device.get_gpu().is_extension_supported(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME);
bool has_dedicated_allocation = device.get_gpu().is_extension_supported(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME);
if (can_get_memory_requirements && has_dedicated_allocation &&
device.is_extension_enabled(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME))
{
allocator_info.flags |= VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT;
}
Expand All @@ -74,7 +76,8 @@ void init(const DeviceType &device)
allocator_info.flags |= VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT;
}

if (device.get_gpu().is_extension_supported(VK_EXT_MEMORY_BUDGET_EXTENSION_NAME) && device.is_extension_enabled(VK_EXT_MEMORY_BUDGET_EXTENSION_NAME))
if (device.get_gpu().is_extension_supported(VK_EXT_MEMORY_BUDGET_EXTENSION_NAME) &&
device.is_extension_enabled(VK_EXT_MEMORY_BUDGET_EXTENSION_NAME))
{
allocator_info.flags |= VMA_ALLOCATOR_CREATE_EXT_MEMORY_BUDGET_BIT;
}
Expand All @@ -85,7 +88,8 @@ void init(const DeviceType &device)
allocator_info.flags |= VMA_ALLOCATOR_CREATE_EXT_MEMORY_PRIORITY_BIT;
}

if (device.get_gpu().is_extension_supported(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME) && device.is_extension_enabled(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME))
if (device.get_gpu().is_extension_supported(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME) &&
device.is_extension_enabled(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME))
{
allocator_info.flags |= VMA_ALLOCATOR_CREATE_KHR_BIND_MEMORY2_BIT;
}
Expand Down Expand Up @@ -126,12 +130,16 @@ class Allocated : public vkb::core::VulkanResource<bindingType, HandleType>
public:
using ParentType = vkb::core::VulkanResource<bindingType, HandleType>;

using BufferType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::Buffer, VkBuffer>::type;
using BufferCreateInfoType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::BufferCreateInfo, VkBufferCreateInfo>::type;
using DeviceMemoryType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::DeviceMemory, VkDeviceMemory>::type;
using DeviceSizeType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::DeviceSize, VkDeviceSize>::type;
using ImageCreateInfoType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::ImageCreateInfo, VkImageCreateInfo>::type;
using ImageType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::Image, VkImage>::type;
using BufferType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::Buffer, VkBuffer>::type;
using BufferCreateInfoType =
typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::BufferCreateInfo, VkBufferCreateInfo>::type;
using DeviceMemoryType =
typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::DeviceMemory, VkDeviceMemory>::type;
using DeviceSizeType =
typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::DeviceSize, VkDeviceSize>::type;
using ImageCreateInfoType =
typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::ImageCreateInfo, VkImageCreateInfo>::type;
using ImageType = typename std::conditional<bindingType == vkb::BindingType::Cpp, vk::Image, VkImage>::type;

public:
Allocated() = delete;
Expand Down Expand Up @@ -398,14 +406,13 @@ inline Allocated<bindingType, HandleType>::Allocated(Allocated &&other) noexcept
mapped_data(std::exchange(other.mapped_data, {})),
coherent(std::exchange(other.coherent, {})),
persistent(std::exchange(other.persistent, {}))
{
}
{}

template <vkb::BindingType bindingType, typename HandleType>
template <typename... Args>
inline Allocated<bindingType, HandleType>::Allocated(const VmaAllocationCreateInfo &allocation_create_info, Args &&...args) :
ParentType{std::forward<Args>(args)...},
allocation_create_info(allocation_create_info)
inline Allocated<bindingType, HandleType>::Allocated(const VmaAllocationCreateInfo &allocation_create_info,
Args &&...args) :
ParentType{std::forward<Args>(args)...}, allocation_create_info(allocation_create_info)
{}

template <vkb::BindingType bindingType, typename HandleType>
Expand All @@ -428,45 +435,46 @@ inline void Allocated<bindingType, HandleType>::clear()
}

template <vkb::BindingType bindingType, typename HandleType>
inline typename Allocated<bindingType, HandleType>::BufferType Allocated<bindingType, HandleType>::create_buffer(BufferCreateInfoType const &create_info, DeviceSizeType alignment)
inline typename Allocated<bindingType, HandleType>::BufferType
Allocated<bindingType, HandleType>::create_buffer(BufferCreateInfoType const &create_info, DeviceSizeType alignment)
{
if constexpr (bindingType == vkb::BindingType::Cpp)
{
return create_buffer_impl(create_info, alignment);
}
else
{
return static_cast<VkBuffer>(create_buffer_impl(reinterpret_cast<vk::BufferCreateInfo const &>(create_info), alignment));
return static_cast<VkBuffer>(
create_buffer_impl(reinterpret_cast<vk::BufferCreateInfo const &>(create_info), alignment));
}
}

template <vkb::BindingType bindingType, typename HandleType>
inline vk::Buffer Allocated<bindingType, HandleType>::create_buffer_impl(vk::BufferCreateInfo const &create_info, DeviceSizeType alignment)
inline vk::Buffer Allocated<bindingType, HandleType>::create_buffer_impl(vk::BufferCreateInfo const &create_info,
DeviceSizeType alignment)
{
vk::Buffer buffer = VK_NULL_HANDLE;
VmaAllocationInfo allocation_info{};

auto result = VK_SUCCESS;
if (alignment == 0)
{
result = vmaCreateBuffer(
get_memory_allocator(),
reinterpret_cast<VkBufferCreateInfo const *>(&create_info),
&allocation_create_info,
reinterpret_cast<VkBuffer *>(&buffer),
&allocation,
&allocation_info);
result = vmaCreateBuffer(get_memory_allocator(),
reinterpret_cast<VkBufferCreateInfo const *>(&create_info),
&allocation_create_info,
reinterpret_cast<VkBuffer *>(&buffer),
&allocation,
&allocation_info);
}
else
{
result = vmaCreateBufferWithAlignment(
get_memory_allocator(),
reinterpret_cast<VkBufferCreateInfo const *>(&create_info),
&allocation_create_info,
alignment,
reinterpret_cast<VkBuffer *>(&buffer),
&allocation,
&allocation_info);
result = vmaCreateBufferWithAlignment(get_memory_allocator(),
reinterpret_cast<VkBufferCreateInfo const *>(&create_info),
&allocation_create_info,
alignment,
reinterpret_cast<VkBuffer *>(&buffer),
&allocation,
&allocation_info);
}

if (result != VK_SUCCESS)
Expand All @@ -478,7 +486,8 @@ inline vk::Buffer Allocated<bindingType, HandleType>::create_buffer_impl(vk::Buf
}

template <vkb::BindingType bindingType, typename HandleType>
inline typename Allocated<bindingType, HandleType>::ImageType Allocated<bindingType, HandleType>::create_image(ImageCreateInfoType const &create_info)
inline typename Allocated<bindingType, HandleType>::ImageType
Allocated<bindingType, HandleType>::create_image(ImageCreateInfoType const &create_info)
{
if constexpr (bindingType == vkb::BindingType::Cpp)
{
Expand Down Expand Up @@ -573,7 +582,8 @@ inline void Allocated<bindingType, HandleType>::flush(DeviceSizeType offset, Dev
{
if constexpr (bindingType == vkb::BindingType::Cpp)
{
vmaFlushAllocation(get_memory_allocator(), allocation, static_cast<VkDeviceSize>(offset), static_cast<VkDeviceSize>(size));
vmaFlushAllocation(
get_memory_allocator(), allocation, static_cast<VkDeviceSize>(offset), static_cast<VkDeviceSize>(size));
}
else
{
Expand All @@ -589,7 +599,8 @@ inline const uint8_t *Allocated<bindingType, HandleType>::get_data() const
}

template <vkb::BindingType bindingType, typename HandleType>
inline typename Allocated<bindingType, HandleType>::DeviceMemoryType Allocated<bindingType, HandleType>::get_memory() const
inline typename Allocated<bindingType, HandleType>::DeviceMemoryType
Allocated<bindingType, HandleType>::get_memory() const
{
VmaAllocationInfo alloc_info;
vmaGetAllocationInfo(get_memory_allocator(), allocation, &alloc_info);
Expand All @@ -604,7 +615,8 @@ inline typename Allocated<bindingType, HandleType>::DeviceMemoryType Allocated<b
}

template <vkb::BindingType bindingType, typename HandleType>
inline typename Allocated<bindingType, HandleType>::DeviceSizeType Allocated<bindingType, HandleType>::get_memory_offset() const
inline typename Allocated<bindingType, HandleType>::DeviceSizeType
Allocated<bindingType, HandleType>::get_memory_offset() const
{
VmaAllocationInfo alloc_info;
vmaGetAllocationInfo(get_memory_allocator(), allocation, &alloc_info);
Expand Down
Loading
Loading