Compare commits
1 commit
refactor-c
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
883f683ce4 |
6 changed files with 177 additions and 77 deletions
34
json_mods.hpp
Normal file
34
json_mods.hpp
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
#pragma once
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <nlohmann/json_fwd.hpp>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
#define ENROLL_COMPONENT(COMPONENT, ...) \
|
||||||
|
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(COMPONENT, __VA_ARGS__); \
|
||||||
|
template <> struct NameOf<COMPONENT> { \
|
||||||
|
static constexpr const char *name = #COMPONENT; \
|
||||||
|
};
|
||||||
|
|
||||||
|
// partial specialization (full specialization works too)
|
||||||
|
namespace nlohmann {
|
||||||
|
template <typename T>
|
||||||
|
struct adl_serializer<std::optional<T>> {
|
||||||
|
static void to_json(json& j, const std::optional<T>& opt) {
|
||||||
|
if (opt == std::nullopt) {
|
||||||
|
j = nullptr;
|
||||||
|
} else {
|
||||||
|
j = *opt; // this will call adl_serializer<T>::to_json which will
|
||||||
|
// find the free function to_json in T's namespace!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void from_json(const json& j, std::optional<T>& opt) {
|
||||||
|
if (j.is_null() || j == false) {
|
||||||
|
opt = std::nullopt;
|
||||||
|
} else {
|
||||||
|
opt = std::make_optional<T>(j.template get<T>());
|
||||||
|
// same as above, but with adl_serializer<T>::from_json
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -104,6 +104,7 @@ else
|
||||||
})
|
})
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
json = subproject('nlohmann_json').get_variable('nlohmann_json_dep')
|
||||||
vkbootstrap_proj = cmake.subproject('vk-bootstrap', options: vk_opts)
|
vkbootstrap_proj = cmake.subproject('vk-bootstrap', options: vk_opts)
|
||||||
vkbootstrap = vkbootstrap_proj.get_variable('vk_bootstrap_dep')
|
vkbootstrap = vkbootstrap_proj.get_variable('vk_bootstrap_dep')
|
||||||
|
|
||||||
|
|
@ -113,6 +114,7 @@ dependencies += [
|
||||||
glm,
|
glm,
|
||||||
imgui,
|
imgui,
|
||||||
sdl2,
|
sdl2,
|
||||||
|
json,
|
||||||
]
|
]
|
||||||
|
|
||||||
sources = [
|
sources = [
|
||||||
|
|
|
||||||
8
trash_test.hpp
Normal file
8
trash_test.hpp
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
#include "vk_types.h"
|
||||||
|
#include "json_mods.hpp"
|
||||||
|
|
||||||
|
template <typename T> struct NameOf;
|
||||||
|
|
||||||
|
ENROLL_COMPONENT(VkSemaphoreCreateInfo, sType);
|
||||||
|
ENROLL_COMPONENT(VkFenceCreateInfo, sType);
|
||||||
|
ENROLL_COMPONENT(VkImageViewCreateInfo, sType, viewType, subresourceRange.baseMipLevel, subresourceRange.levelCount, subresourceRange.baseArrayLayer, subresourceRange.layerCount);
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
#define VMA_IMPLEMENTATION
|
#define VMA_IMPLEMENTATION
|
||||||
#include "vk_mem_alloc.h"
|
#include "vk_mem_alloc.h"
|
||||||
|
|
||||||
constexpr bool bUseValidationLayers = true;
|
constexpr bool bUseValidationLayers = false;
|
||||||
|
|
||||||
VulkanEngine* loadedEngine = nullptr;
|
VulkanEngine* loadedEngine = nullptr;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,76 +1,126 @@
|
||||||
#include <vk_initializers.h>
|
#include <vk_initializers.h>
|
||||||
|
#include <vulkan/vk_enum_string_helper.h>
|
||||||
|
#include "trash_test.hpp"
|
||||||
|
|
||||||
|
nlohmann::json DATA = nlohmann::json::parse(R"(
|
||||||
|
{
|
||||||
|
"VkSemaphoreCreateInfo": {
|
||||||
|
"draw": {
|
||||||
|
"sType": 9
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"VkFenceCreateInfo": {
|
||||||
|
"draw": {
|
||||||
|
"sType": 8
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"VkImageViewCreateInfo": {
|
||||||
|
"draw": {
|
||||||
|
"sType": 15,
|
||||||
|
"viewType": 1,
|
||||||
|
"subresourceRange.baseMipLevel": 0,
|
||||||
|
"subresourceRange.levelCount": 1,
|
||||||
|
"subresourceRange.baseArrayLayer": 0,
|
||||||
|
"subresourceRange.layerCount": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)");
|
||||||
|
|
||||||
|
template<typename COMPONENT> COMPONENT load(nlohmann::json &data, const std::string& profile) {
|
||||||
|
COMPONENT result{};
|
||||||
|
auto& type_stuff = data[NameOf<COMPONENT>::name];
|
||||||
|
auto& profile_data = type_stuff[profile];
|
||||||
|
nlohmann::from_json(profile_data, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// #if !defined( VULKAN_HPP_NO_CONSTRUCTORS ) && !defined( VULKAN_HPP_NO_STRUCT_CONSTRUCTORS )
|
|
||||||
//
|
|
||||||
#define VULKAN_HPP_NO_STRUCT_CONSTRUCTORS 1
|
|
||||||
#define VULKAN_HPP_NO_CONSTRUCTORS 1
|
|
||||||
#include <vulkan/vulkan.hpp>
|
|
||||||
|
|
||||||
VkCommandPoolCreateInfo vkinit::command_pool_create_info(uint32_t queueFamilyIndex,
|
VkCommandPoolCreateInfo vkinit::command_pool_create_info(uint32_t queueFamilyIndex,
|
||||||
VkCommandPoolCreateFlags flags /*= 0*/)
|
VkCommandPoolCreateFlags flags /*= 0*/)
|
||||||
{
|
{
|
||||||
return vk::CommandPoolCreateInfo{
|
VkCommandPoolCreateInfo info = {};
|
||||||
.flags=vk::CommandPoolCreateFlags(flags),
|
info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
|
||||||
.queueFamilyIndex=queueFamilyIndex
|
info.pNext = nullptr;
|
||||||
};
|
info.queueFamilyIndex = queueFamilyIndex;
|
||||||
|
info.flags = flags;
|
||||||
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VkCommandBufferAllocateInfo vkinit::command_buffer_allocate_info(
|
VkCommandBufferAllocateInfo vkinit::command_buffer_allocate_info(
|
||||||
VkCommandPool pool, uint32_t count /*= 1*/)
|
VkCommandPool pool, uint32_t count /*= 1*/)
|
||||||
{
|
{
|
||||||
return vk::CommandBufferAllocateInfo{
|
VkCommandBufferAllocateInfo info = {};
|
||||||
.commandPool=pool,
|
info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
||||||
.level=vk::CommandBufferLevel::ePrimary,
|
info.pNext = nullptr;
|
||||||
.commandBufferCount=count
|
|
||||||
};
|
info.commandPool = pool;
|
||||||
|
info.commandBufferCount = count;
|
||||||
|
info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||||
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkFenceCreateInfo vkinit::fence_create_info(VkFenceCreateFlags flags /*=0*/)
|
VkFenceCreateInfo vkinit::fence_create_info(VkFenceCreateFlags flags /*=0*/)
|
||||||
{
|
{
|
||||||
return vk::FenceCreateInfo{
|
auto info = load<VkFenceCreateInfo>(DATA, "draw");
|
||||||
.flags=vk::FenceCreateFlags(flags)
|
info.flags = flags;
|
||||||
};
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkSemaphoreCreateInfo vkinit::semaphore_create_info(VkSemaphoreCreateFlags flags/*=0*/)
|
VkSemaphoreCreateInfo vkinit::semaphore_create_info(VkSemaphoreCreateFlags flags/*=0*/)
|
||||||
{
|
{
|
||||||
return vk::SemaphoreCreateInfo{
|
auto info = load<VkSemaphoreCreateInfo>(DATA, "draw");
|
||||||
.flags=vk::SemaphoreCreateFlags(flags)
|
info.flags = flags;
|
||||||
};
|
|
||||||
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkCommandBufferBeginInfo vkinit::command_buffer_begin_info(VkCommandBufferUsageFlags flags /*= 0*/)
|
VkCommandBufferBeginInfo vkinit::command_buffer_begin_info(VkCommandBufferUsageFlags flags /*= 0*/)
|
||||||
{
|
{
|
||||||
return vk::CommandBufferBeginInfo{
|
VkCommandBufferBeginInfo info = {};
|
||||||
.flags=vk::CommandBufferUsageFlags(flags)
|
info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||||
};
|
info.pNext = nullptr;
|
||||||
|
|
||||||
|
info.pInheritanceInfo = nullptr;
|
||||||
|
info.flags = flags;
|
||||||
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkImageSubresourceRange vkinit::image_subresource_range(VkImageAspectFlags aspectMask)
|
VkImageSubresourceRange vkinit::image_subresource_range(VkImageAspectFlags aspectMask)
|
||||||
{
|
{
|
||||||
return vk::ImageSubresourceRange{
|
VkImageSubresourceRange subImage {};
|
||||||
vk::ImageAspectFlags(aspectMask),
|
subImage.aspectMask = aspectMask;
|
||||||
0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_ARRAY_LAYERS
|
subImage.baseMipLevel = 0;
|
||||||
};
|
subImage.levelCount = VK_REMAINING_MIP_LEVELS;
|
||||||
|
subImage.baseArrayLayer = 0;
|
||||||
|
subImage.layerCount = VK_REMAINING_ARRAY_LAYERS;
|
||||||
|
|
||||||
|
return subImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkSemaphoreSubmitInfo vkinit::semaphore_submit_info(VkPipelineStageFlags2 stageMask, VkSemaphore semaphore)
|
VkSemaphoreSubmitInfo vkinit::semaphore_submit_info(VkPipelineStageFlags2 stageMask, VkSemaphore semaphore)
|
||||||
{
|
{
|
||||||
return vk::SemaphoreSubmitInfo{
|
VkSemaphoreSubmitInfo submitInfo{};
|
||||||
.semaphore=vk::Semaphore{semaphore},
|
submitInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO;
|
||||||
.value=1,
|
submitInfo.pNext = nullptr;
|
||||||
.stageMask=vk::PipelineStageFlags2{stageMask},
|
submitInfo.semaphore = semaphore;
|
||||||
.deviceIndex=0,
|
submitInfo.stageMask = stageMask;
|
||||||
};
|
submitInfo.deviceIndex = 0;
|
||||||
|
submitInfo.value = 1;
|
||||||
|
|
||||||
|
return submitInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkCommandBufferSubmitInfo vkinit::command_buffer_submit_info(VkCommandBuffer cmd)
|
VkCommandBufferSubmitInfo vkinit::command_buffer_submit_info(VkCommandBuffer cmd)
|
||||||
{
|
{
|
||||||
return vk::CommandBufferSubmitInfo{
|
VkCommandBufferSubmitInfo info{};
|
||||||
.commandBuffer=cmd, // commandBuffer
|
info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_SUBMIT_INFO;
|
||||||
.deviceMask=0, // deviceMask
|
info.pNext = nullptr;
|
||||||
};
|
info.commandBuffer = cmd;
|
||||||
|
info.deviceMask = 0;
|
||||||
|
|
||||||
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkSubmitInfo2 vkinit::submit_info(VkCommandBufferSubmitInfo* cmd, VkSemaphoreSubmitInfo* signalSemaphoreInfo,
|
VkSubmitInfo2 vkinit::submit_info(VkCommandBufferSubmitInfo* cmd, VkSemaphoreSubmitInfo* signalSemaphoreInfo,
|
||||||
|
|
@ -94,56 +144,51 @@ VkSubmitInfo2 vkinit::submit_info(VkCommandBufferSubmitInfo* cmd, VkSemaphoreSub
|
||||||
|
|
||||||
VkImageCreateInfo vkinit::image_create_info(VkFormat format, VkImageUsageFlags usageFlags, VkExtent3D extent)
|
VkImageCreateInfo vkinit::image_create_info(VkFormat format, VkImageUsageFlags usageFlags, VkExtent3D extent)
|
||||||
{
|
{
|
||||||
return vk::ImageCreateInfo{
|
VkImageCreateInfo info{};
|
||||||
.flags=vk::ImageCreateFlags(0),
|
info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||||
.imageType=vk::ImageType::e2D,
|
info.pNext = nullptr;
|
||||||
.format=vk::Format{format},
|
|
||||||
.extent=vk::Extent3D{extent.width, extent.height, extent.depth},
|
info.imageType = VK_IMAGE_TYPE_2D;
|
||||||
.mipLevels=1,
|
|
||||||
.arrayLayers=1,
|
info.format = format;
|
||||||
.samples=vk::SampleCountFlagBits::e1,
|
info.extent = extent;
|
||||||
.tiling=vk::ImageTiling::eOptimal,
|
|
||||||
.usage=vk::ImageUsageFlags{usageFlags},
|
info.mipLevels = 1;
|
||||||
};
|
info.arrayLayers = 1;
|
||||||
|
|
||||||
|
info.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
|
||||||
|
info.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||||
|
info.usage = usageFlags;
|
||||||
|
|
||||||
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkImageViewCreateInfo vkinit::imageview_create_info(VkFormat format, VkImage image, VkImageAspectFlags aspectFlags)
|
VkImageViewCreateInfo vkinit::imageview_create_info(VkFormat format, VkImage image, VkImageAspectFlags aspectFlags)
|
||||||
{
|
{
|
||||||
return vk::ImageViewCreateInfo{
|
auto info = load<VkImageViewCreateInfo>(DATA, "draw");
|
||||||
.image=image,
|
|
||||||
.viewType=vk::ImageViewType::e2D,
|
info.image = image;
|
||||||
.format=vk::Format{format},
|
info.format = format;
|
||||||
.subresourceRange{
|
info.subresourceRange.aspectMask = aspectFlags;
|
||||||
.aspectMask=vk::ImageAspectFlags{aspectFlags},
|
|
||||||
.baseMipLevel=0,
|
return info;
|
||||||
.levelCount=1,
|
|
||||||
.baseArrayLayer=0,
|
|
||||||
.layerCount=1,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VkRenderingAttachmentInfo vkinit::attachment_info(
|
VkRenderingAttachmentInfo vkinit::attachment_info(
|
||||||
VkImageView view, VkClearValue* clear ,VkImageLayout layout /*= VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL*/)
|
VkImageView view, VkClearValue* clear ,VkImageLayout layout /*= VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL*/)
|
||||||
{
|
{
|
||||||
vk::RenderingAttachmentInfo colorAttachment{
|
VkRenderingAttachmentInfo colorAttachment {};
|
||||||
.imageView=view,
|
colorAttachment.sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO;
|
||||||
.imageLayout=vk::ImageLayout(layout),
|
colorAttachment.pNext = nullptr;
|
||||||
.loadOp=vk::AttachmentLoadOp(clear ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD),
|
|
||||||
.storeOp=vk::AttachmentStoreOp(VK_ATTACHMENT_STORE_OP_STORE),
|
colorAttachment.imageView = view;
|
||||||
};
|
colorAttachment.imageLayout = layout;
|
||||||
|
colorAttachment.loadOp = clear ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_LOAD;
|
||||||
|
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||||
|
|
||||||
if (clear) {
|
if (clear) {
|
||||||
vk::ArrayWrapper1D<float, 4> thefuckingcolor{{
|
colorAttachment.clearValue = *clear;
|
||||||
clear->color.float32[0],
|
|
||||||
clear->color.float32[1],
|
|
||||||
clear->color.float32[2],
|
|
||||||
clear->color.float32[3],
|
|
||||||
}};
|
|
||||||
|
|
||||||
colorAttachment.clearValue = vk::ClearValue{
|
|
||||||
.color = thefuckingcolor
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return colorAttachment;
|
return colorAttachment;
|
||||||
|
|
|
||||||
11
wraps/nlohmann_json.wrap
Normal file
11
wraps/nlohmann_json.wrap
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
[wrap-file]
|
||||||
|
directory = nlohmann_json-3.11.3
|
||||||
|
lead_directory_missing = true
|
||||||
|
source_url = https://github.com/nlohmann/json/releases/download/v3.11.3/include.zip
|
||||||
|
source_filename = nlohmann_json-3.11.3.zip
|
||||||
|
source_hash = a22461d13119ac5c78f205d3df1db13403e58ce1bb1794edc9313677313f4a9d
|
||||||
|
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/nlohmann_json_3.11.3-1/nlohmann_json-3.11.3.zip
|
||||||
|
wrapdb_version = 3.11.3-1
|
||||||
|
|
||||||
|
[provide]
|
||||||
|
nlohmann_json = nlohmann_json_dep
|
||||||
Loading…
Add table
Add a link
Reference in a new issue