Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
echo Building with minimal Vulkan...
FLAGS+=('-DVMA_HPP_VULKAN_REVISION=${{matrix.env.modules && 'min-modules' || 'min-headers'}}')

cmake "${FLAGS[@]}" -DCMAKE_CXX_FLAGS="$CXX_FLAGS"
cmake "${FLAGS[@]}" -DCMAKE_CXX_FLAGS="$CXX_FLAGS -DVULKAN_HPP_NO_SMART_HANDLE"
cmake --build build --clean-first

cmake "${FLAGS[@]}" -DCMAKE_CXX_FLAGS="$CXX_FLAGS -DVULKAN_HPP_NO_EXCEPTIONS -DVULKAN_HPP_USE_REFLECT"
Expand All @@ -102,7 +102,7 @@ jobs:
unset 'FLAGS[${#FLAGS[@]}-1]'
FLAGS+=('-DVMA_HPP_VULKAN_REVISION=main')

cmake "${FLAGS[@]}" -DCMAKE_CXX_FLAGS="$CXX_FLAGS"
cmake "${FLAGS[@]}" -DCMAKE_CXX_FLAGS="$CXX_FLAGS -DVULKAN_HPP_NO_SMART_HANDLE"
cmake --build build --clean-first

cmake "${FLAGS[@]}" -DCMAKE_CXX_FLAGS="$CXX_FLAGS -DVULKAN_HPP_NO_EXCEPTIONS -DVULKAN_HPP_USE_REFLECT"
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.8...3.30 FATAL_ERROR)
project(VulkanMemoryAllocator-Hpp-Generator VERSION 3.3.0 LANGUAGES CXX)

set(VMA_HPP_VULKAN_MIN_HEADERS "1.4.327" CACHE INTERNAL "Minimal Vulkan-Headers revision (headers)")
set(VMA_HPP_VULKAN_MIN_MODULES "1.4.336" CACHE INTERNAL "Minimal Vulkan-Headers revision (modules)")
set(VMA_HPP_VULKAN_MIN_MODULES "1.4.337" CACHE INTERNAL "Minimal Vulkan-Headers revision (modules)")

if (CMAKE_VERSION VERSION_LESS "3.21")
# https://cmake.org/cmake/help/latest/variable/PROJECT_IS_TOP_LEVEL.html
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ consistent and compatible with Vulkan C++ bindings ([Vulkan-Hpp](https://github.
#### Requirements

- C++11 or newer
- [Vulkan](https://github.com/KhronosGroup/Vulkan-Headers) **<!--VK_HEADERS-->1.4.327<!--/VK_HEADERS-->** (headers) / **<!--VK_MODULES-->1.4.336<!--/VK_MODULES-->** (module) or newer
- [Vulkan](https://github.com/KhronosGroup/Vulkan-Headers) **<!--VK_HEADERS-->1.4.327<!--/VK_HEADERS-->** (headers) / **<!--VK_MODULES-->1.4.337<!--/VK_MODULES-->** (module) or newer
- [VulkanMemoryAllocator](https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator)
- *[GitHub releases](https://github.com/YaaZ/VulkanMemoryAllocator-Hpp/releases) is the recommended way to get VMA-Hpp,
they already include a compatible `vk_mem_alloc.h` header*
Expand Down
18 changes: 11 additions & 7 deletions VmaHppGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2112,7 +2112,8 @@ void generateStaticAssertions(const ConditionalTree& tree, const Symbols& symbol
}

void generateModule(const ConditionalTree& tree, const Symbols& symbols) {
Segment exports, uniqueExports, raiiExports, specializations, raiiSpecializations;
Segment::Vector<6> segments;
auto& [exports, uniqueExports, raiiExports, specializations, uniqueSpecializations, raiiSpecializations] = *segments;

// Generate export statements.
for (const auto* list : { &symbols.enums, &symbols.structs, &symbols.handles, &symbols.functions })
Expand All @@ -2139,19 +2140,19 @@ void generateModule(const ConditionalTree& tree, const Symbols& symbols) {

// error C2027: use of undefined type 'vk::UniqueHandleTraits<Type,Dispatch>'
for (const Symbol& t : symbols.handles.unique)
specializations << n << navigate(t) << "template<> class UniqueHandleTraits<VMA_HPP_NAMESPACE::" << t.name << ", VMA_HPP_NAMESPACE::detail::Dispatcher>;";
uniqueSpecializations << n << navigate(t) << "template<> class UniqueHandleTraits<VMA_HPP_NAMESPACE::" << t.name << ", VMA_HPP_NAMESPACE::detail::Dispatcher>;";

// error C2676: binary '==': 'const vma::raii::Allocator' does not define this operator or a conversion to a type acceptable to the predefined operator
for (const Symbol& t : symbols.handles.raii)
raiiSpecializations << n << navigate(t) << "template<> struct isVulkanRAIIHandleType<VMA_HPP_NAMESPACE::VMA_HPP_RAII_NAMESPACE::" << t.name << ">;";

(exports, raiiExports, specializations, raiiSpecializations) << navigate.reset;
segments << navigate.reset;

// Don't forget Buffer and Image.
uniqueExports << n << "using VMA_HPP_NAMESPACE::UniqueBuffer;" <<
n << "using VMA_HPP_NAMESPACE::UniqueImage;";
specializations << n << "template<> class UniqueHandleTraits<Buffer, VMA_HPP_NAMESPACE::detail::Dispatcher>;" <<
n << "template<> class UniqueHandleTraits<Image, VMA_HPP_NAMESPACE::detail::Dispatcher>;";
uniqueSpecializations << n << "template<> class UniqueHandleTraits<Buffer, VMA_HPP_NAMESPACE::detail::Dispatcher>;" <<
n << "template<> class UniqueHandleTraits<Image, VMA_HPP_NAMESPACE::detail::Dispatcher>;";

R"(// Generated from the Vulkan Memory Allocator (vk_mem_alloc.h).
module;
Expand Down Expand Up @@ -2200,13 +2201,16 @@ void generateModule(const ConditionalTree& tree, const Symbols& symbols) {
namespace VULKAN_HPP_NAMESPACE {
// This is needed for template specializations to be visible outside the module when importing vulkan (is this a MSVC bug?).
$3
#ifndef VULKAN_HPP_NO_SMART_HANDLE
$4
#endif
#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE
namespace VULKAN_HPP_RAII_NAMESPACE {
$4
$5
}
#endif
}
)"_seg.replace(exports, uniqueExports, raiiExports, specializations, raiiSpecializations).resolve(tree).generate("vk_mem_alloc.cppm");
)"_seg.replace(exports, uniqueExports, raiiExports, specializations, uniqueSpecializations, raiiSpecializations).resolve(tree).generate("vk_mem_alloc.cppm");
}

std::string readSource() {
Expand Down
2 changes: 2 additions & 0 deletions include/vk_mem_alloc.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,15 @@ namespace VULKAN_HPP_NAMESPACE {
template<> struct isVulkanHandleType<VMA_HPP_NAMESPACE::DefragmentationContext>;
template<> struct isVulkanHandleType<VMA_HPP_NAMESPACE::VirtualAllocation>;
template<> struct isVulkanHandleType<VMA_HPP_NAMESPACE::VirtualBlock>;
#ifndef VULKAN_HPP_NO_SMART_HANDLE
template<> class UniqueHandleTraits<VMA_HPP_NAMESPACE::Allocator, VMA_HPP_NAMESPACE::detail::Dispatcher>;
template<> class UniqueHandleTraits<VMA_HPP_NAMESPACE::Pool, VMA_HPP_NAMESPACE::detail::Dispatcher>;
template<> class UniqueHandleTraits<VMA_HPP_NAMESPACE::Allocation, VMA_HPP_NAMESPACE::detail::Dispatcher>;
template<> class UniqueHandleTraits<VMA_HPP_NAMESPACE::VirtualAllocation, VMA_HPP_NAMESPACE::detail::Dispatcher>;
template<> class UniqueHandleTraits<VMA_HPP_NAMESPACE::VirtualBlock, VMA_HPP_NAMESPACE::detail::Dispatcher>;
template<> class UniqueHandleTraits<Buffer, VMA_HPP_NAMESPACE::detail::Dispatcher>;
template<> class UniqueHandleTraits<Image, VMA_HPP_NAMESPACE::detail::Dispatcher>;
#endif
#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE
namespace VULKAN_HPP_RAII_NAMESPACE {
template<> struct isVulkanRAIIHandleType<VMA_HPP_NAMESPACE::VMA_HPP_RAII_NAMESPACE::Allocator>;
Expand Down
2 changes: 2 additions & 0 deletions samples/CompileCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ void checkHandles() {
if (al == ar) {}
if (al != ar) throw;

#ifndef VULKAN_HPP_NO_SMART_HANDLE
vma::UniqueAllocator unique;
vma::UniqueBuffer buffer;
#endif

vma::raii::Allocator raii = nullptr;
allocator = raii;
Expand Down
2 changes: 2 additions & 0 deletions samples/Init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ int main(int, char**) {
Vulkan vulkan;

auto functions = vma::functionsFromDispatchers(*vulkan.device.getDispatcher(), *vulkan.instance.getDispatcher());
#ifndef VULKAN_HPP_NO_SMART_HANDLE
auto allocator = value(vma::createAllocatorUnique(vma::AllocatorCreateInfo {
{}, vulkan.physicalDevice, vulkan.device
}.setInstance(vulkan.instance).setPVulkanFunctions(&functions)));

auto buffer = value(allocator->createBufferUnique(
vk::BufferCreateInfo { {}, 1024, vk::BufferUsageFlagBits::eTransferSrc },
vma::AllocationCreateInfo { vma::AllocationCreateFlagBits::eHostAccessSequentialWrite, vma::MemoryUsage::eAuto }));
#endif

return 0;
}