1#ifndef NNGN_GRAPHICS_VULKAN_UTILS_H
2#define NNGN_GRAPHICS_VULKAN_UTILS_H
18#define LOG_RESULT(f, ...) nngn::vk_check_result(#f, f(__VA_ARGS__))
19#define CHECK_RESULT(f, ...) \
20 do { if(!LOG_RESULT(f, __VA_ARGS__)) [[unlikely]] return false; } while(0);
25const char *
vk_enum_str(VkDebugUtilsMessageSeverityFlagBitsEXT
f);
26const char *
vk_enum_str(VkDebugUtilsMessageTypeFlagsEXT
f);
39 {
return {
e.width,
e.height}; }
41 {
return {.width =
v.
x, .height =
v.y}; }
54template<c_function_po
inter auto f>
59 std::span<const VkExtensionProperties>
s);
64template<
typename T,
auto ...Ps>
66 std::span<const VkVertexInputBindingDescription> bindings);
70 requires std::ranges::sized_range<T>;
71 {std::declval<std::ranges::range_value_t<T>>().
name.data()}
72 -> std::same_as<char*>;
86 if(
r == VK_SUCCESS) [[likely]]
92template<c_function_po
inter auto f>
95 f(args..., &
n,
nullptr);
96 std::vector<std::remove_pointer_t<types_last_t<fn_args<f>>>> ret(
n);
97 f(args..., &
n, ret.data());
102 std::vector<const char*> ret = {};
103 ret.reserve(
r.size());
104 for(
const auto &x :
r)
105 ret.push_back(x.name.data());
109template<standard_layout
T,
auto ...Ps>
111 constexpr auto n =
sizeof...(Ps);
113 std::array<VkVertexInputAttributeDescription, n> ret = {};
114 for(std::size_t
i = 0;
i <
n; ++
i)
116 .location =
static_cast<u32>(
i),
118 .format = VK_FORMAT_R32G32B32_SFLOAT,
125 std::span<const VkVertexInputBindingDescription> bindings,
126 std::span<const VkVertexInputAttributeDescription> attrs
129 .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
130 .vertexBindingDescriptionCount =
131 static_cast<std::uint32_t
>(bindings.size()),
132 .pVertexBindingDescriptions = bindings.data(),
133 .vertexAttributeDescriptionCount =
134 static_cast<std::uint32_t
>(attrs.size()),
135 .pVertexAttributeDescriptions = attrs.data(),
name
Definition cathedral.lua:11
static std::ostream & l()
Definition log.cpp:56
for i
Definition font.lua:5
local n
Definition dump_lights.lua:5
local r
Definition gamma.lua:7
const char * vk_enum_str(VkDebugUtilsMessageSeverityFlagBitsEXT f)
Definition utils.cpp:108
std::string vk_version_str(Graphics::Version v)
Definition utils.cpp:119
std::vector< Graphics::Extension > vk_parse_extensions(std::span< const VkExtensionProperties > s)
Populates Graphics::Extension objects from their Vulkan equivalents.
Definition utils.cpp:158
Graphics::Version vk_parse_version(std::uint32_t v)
Unpacks a Vulkan version number.
Definition utils.cpp:144
std::uint32_t u32
Definition def.h:14
Graphics::PresentMode vk_present_mode(VkPresentModeKHR m)
Populates a Graphics::PresentMode from its Vulkan equivalent.
Definition utils.cpp:175
vk_create_info_type< T > vk_create_info(vk_create_info_type< T > info)
Definition utils.h:79
auto vk_enumerate(const auto &...args)
Creates a vector from the result of calling f with args.
Definition utils.h:93
nngn::uvec2 vk_extent_to_vec(VkExtent2D e)
Definition utils.h:38
bool vk_check_result(const char *func, VkResult r)
Checks that r is VK_SUCCESS or emits a log message.
Definition utils.h:85
typename detail::vk_create_info_type_impl< T >::type vk_create_info_type
Maps types to *CretaeInfo structures.
Definition types.h:47
VkExtent2D vk_vec_to_extent(nngn::uvec2 v)
Definition utils.h:40
std::vector< const char * > vk_names(const VkNamedRange auto &r)
Extracts the name character array from common objects.
Definition utils.h:101
auto vk_vertex_attrs()
Definition utils.h:110
const char * vk_strerror(VkResult result)
Definition utils.cpp:13
std::size_t offsetof_ptr(auto T::*p)
Similar to the stdlib's offsetof, but using member data pointers.
Definition utils.h:153
constexpr empty vk_struct_type
Maps types to VkStructureType values.
Definition types.h:51
constexpr auto vk_vertex_input(std::span< const VkVertexInputBindingDescription > bindings)
func
Definition plot.lua:8
v[1]
Definition math.lua:22
PresentMode
Definition graphics.h:148
local e
Definition math.lua:4
std::chrono::seconds s
Definition timing.cpp:6