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
21 changes: 21 additions & 0 deletions .github/workflows/generate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Generate Headers
on:
pull_request:
push:
branches:
- master
jobs:
generate:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
with:
submodules: true
fetch-tags: true
- name: Generate Headers
run: |
git fetch --unshallow --tags
cmake -B build -DVMA_HPP_GENERATOR_BUILD=ON -DVMA_HPP_RUN_GENERATOR=ON -DVMA_HPP_DO_UPDATE=ON -DVMA_HPP_SAMPLES_BUILD=OFF
cmake --build build
git diff --exit-code
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ option(VMA_HPP_RUN_GENERATOR "Run the HPP generator" ${PROJECT_IS_TOP_LEVE
option(VMA_HPP_SAMPLES_BUILD "Build samples" ${PROJECT_IS_TOP_LEVEL})
option(VMA_HPP_DO_UPDATE "Update VMA submodule" OFF)
set(VMA_HPP_INPUT_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/VulkanMemoryAllocator/include/vk_mem_alloc.h" CACHE FILEPATH "Input vk_mem_alloc.h file")
set(VMA_HPP_VULKAN_MIN_REVISION "1.4.334" CACHE INTERNAL "Minimal Vulkan-Headers revision")
set(VMA_HPP_VULKAN_REVISION "v${VMA_HPP_VULKAN_MIN_REVISION}" CACHE STRING "Vulkan-Headers revision")
set(VMA_HPP_VMA_REVISION "v${PROJECT_VERSION}" CACHE STRING "VulkanMemoryAllocator revision" FORCE)
set(VMA_HPP_VULKAN_MIN_VERSION "1.4.335" CACHE INTERNAL "Minimal Vulkan-Headers revision")
set(VMA_HPP_VULKAN_REVISION "v${VMA_HPP_VULKAN_MIN_VERSION}" CACHE STRING "Vulkan-Headers revision")
set(VMA_HPP_VMA_REVISION "v${PROJECT_VERSION}" CACHE STRING "VulkanMemoryAllocator revision" FORCE)

if (VMA_HPP_DO_UPDATE)
# Find Git.
Expand Down Expand Up @@ -65,11 +65,11 @@ if (VMA_HPP_DO_UPDATE)
string(STRIP ${CMAKE_MATCH_1} VMA_HPP_VMA_VERSION)

# Update versions in the README.
message(STATUS "Updating README with VMA ${VMA_HPP_VMA_VERSION} and Vulkan ${VMA_HPP_VULKAN_MIN_REVISION}")
message(STATUS "Updating README with VMA ${VMA_HPP_VMA_VERSION} and Vulkan ${VMA_HPP_VULKAN_MIN_VERSION}")
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/README.md" VMA_HPP_README)
string(REPLACE ";" "\\;" VMA_HPP_README "${VMA_HPP_README}") # Do not mess up semicolons in the README
string(REGEX REPLACE "<!--VER-->[^<]*<!--/VER-->" "<!--VER-->${VMA_HPP_VMA_VERSION}<!--/VER-->" VMA_HPP_README "${VMA_HPP_README}")
string(REGEX REPLACE "<!--VK-->[^<]*<!--/VK-->" "<!--VK-->${VMA_HPP_VULKAN_MIN_REVISION}<!--/VK-->" VMA_HPP_README "${VMA_HPP_README}")
string(REGEX REPLACE "<!--VK-->[^<]*<!--/VK-->" "<!--VK-->${VMA_HPP_VULKAN_MIN_VERSION}<!--/VK-->" VMA_HPP_README "${VMA_HPP_README}")
file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/README.md" ${VMA_HPP_README})

# Generate "imported" utility header.
Expand Down Expand Up @@ -116,7 +116,7 @@ if (VMA_HPP_RUN_GENERATOR)
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Running VmaHppGenerator"
DEPENDS VmaHppGenerator "${VMA_HPP_INPUT_HEADER}")
add_custom_target(GenerateVmaHpp DEPENDS ${VMA_HPP_GENERATED_FILES})
add_custom_target(GenerateVmaHpp ALL DEPENDS ${VMA_HPP_GENERATED_FILES})
add_dependencies(VulkanMemoryAllocator-Hpp GenerateVmaHpp)
endif ()

Expand Down
4 changes: 2 additions & 2 deletions 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 headers](https://github.com/KhronosGroup/Vulkan-Headers) **<!--VK-->1.4.334<!--/VK-->** or newer
- [Vulkan headers](https://github.com/KhronosGroup/Vulkan-Headers) **<!--VK-->1.4.335<!--/VK-->** 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 Expand Up @@ -70,7 +70,7 @@ target_sources(<target> PRIVATE

```c++
// Do not define VMA_IMPLEMENTATION
import vk_mem_alloc_hpp; // Also imports vulkan_hpp and std
import vk_mem_alloc; // Also imports vulkan and std
```


Expand Down
13 changes: 8 additions & 5 deletions VmaHppGenerator.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include <algorithm>
#include <array>
#include <cstdint>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <optional>
#include <regex>
#include <string>
Expand Down Expand Up @@ -2130,7 +2133,7 @@ void generateModule(const ConditionalTree& tree, const Symbols& symbols) {
if (endsWith(*t.name, "FlagBits"))
specializations << n << navigate(t) << "template<> struct FlagTraits<VMA_HPP_NAMESPACE::" << t.name << ">;";

// fatal error C1116: unrecoverable error importing module 'vk_mem_alloc_hpp'. Specialization of 'vma::operator ==' with arguments 'vma::Pool, 0'
// fatal error C1116: unrecoverable error importing module 'vk_mem_alloc'. Specialization of 'vma::operator ==' with arguments 'vma::Pool, 0'
for (const Symbol& t : symbols.handles)
specializations << n << navigate(t) << "template<> struct isVulkanHandleType<VMA_HPP_NAMESPACE::" << t.name << ">;";

Expand All @@ -2156,8 +2159,8 @@ void generateModule(const ConditionalTree& tree, const Symbols& symbols) {
#define VMA_IMPLEMENTATION
#include "vk_mem_alloc.hpp"
#include "vk_mem_alloc_raii.hpp"
export module vk_mem_alloc_hpp;
export import vulkan_hpp;
export module vk_mem_alloc;
export import vulkan;

export namespace VMA_HPP_NAMESPACE {
#ifndef VULKAN_HPP_NO_TO_STRING
Expand Down Expand Up @@ -2195,7 +2198,7 @@ void generateModule(const ConditionalTree& tree, const Symbols& symbols) {

module : private;
namespace VULKAN_HPP_NAMESPACE {
// This is needed for template specializations to be visible outside the module when importing vulkan_hpp (is this a MSVC bug?).
// This is needed for template specializations to be visible outside the module when importing vulkan (is this a MSVC bug?).
$3
#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE
namespace VULKAN_HPP_RAII_NAMESPACE {
Expand All @@ -2214,9 +2217,9 @@ std::string readSource() {
in.seekg(0, std::ios::beg);
text.assign(std::istreambuf_iterator(in), {});

text = text.substr(0, text.find("#ifdef VMA_IMPLEMENTATION")); // Strip implementation part
text = std::regex_replace(text, std::regex(R"(/\*[\s\S]*?\*/)"), ""); // Delete multi-line comments
text = std::regex_replace(text, std::regex("//.*"), ""); // Delete single-line comments
text = text.substr(0, text.find("#ifdef VMA_IMPLEMENTATION")); // Strip implementation part
return text;
}

Expand Down
6 changes: 3 additions & 3 deletions include/vk_mem_alloc.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ module;
#define VMA_IMPLEMENTATION
#include "vk_mem_alloc.hpp"
#include "vk_mem_alloc_raii.hpp"
export module vk_mem_alloc_hpp;
export import vulkan_hpp;
export module vk_mem_alloc;
export import vulkan;

export namespace VMA_HPP_NAMESPACE {
#ifndef VULKAN_HPP_NO_TO_STRING
Expand Down Expand Up @@ -104,7 +104,7 @@ export namespace VMA_HPP_NAMESPACE {

module : private;
namespace VULKAN_HPP_NAMESPACE {
// This is needed for template specializations to be visible outside the module when importing vulkan_hpp (is this a MSVC bug?).
// This is needed for template specializations to be visible outside the module when importing vulkan (is this a MSVC bug?).
template<> struct FlagTraits<VMA_HPP_NAMESPACE::AllocatorCreateFlagBits>;
template<> struct FlagTraits<VMA_HPP_NAMESPACE::AllocationCreateFlagBits>;
template<> struct FlagTraits<VMA_HPP_NAMESPACE::PoolCreateFlagBits>;
Expand Down
2 changes: 1 addition & 1 deletion include/vk_mem_alloc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#define VULKAN_MEMORY_ALLOCATOR_HPP

#ifdef VMA_HPP_CXX_MODULE
import vulkan_hpp;
import vulkan;
#else
#include <vulkan/vulkan.hpp>
#endif
Expand Down
2 changes: 1 addition & 1 deletion samples/common.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifdef USE_MODULES
import vk_mem_alloc_hpp;
import vk_mem_alloc;
#else
#define VMA_IMPLEMENTATION
#include <vk_mem_alloc.hpp>
Expand Down
Loading