2016-02-26 13:39:01 +11:00
|
|
|
/*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
* Copyright:
|
2017-09-01 12:33:08 +10:00
|
|
|
* 2016-2017, Danny Robson <danny@nerdcruft.net>
|
2016-02-26 13:39:01 +11:00
|
|
|
*/
|
|
|
|
|
2017-05-26 16:30:48 +10:00
|
|
|
#ifndef CRUFT_VK_TRAITS_HPP
|
|
|
|
#define CRUFT_VK_TRAITS_HPP
|
2016-02-24 11:11:41 +11:00
|
|
|
|
|
|
|
#include "./fwd.hpp"
|
|
|
|
#include "./vk.hpp"
|
|
|
|
|
2017-09-01 12:33:08 +10:00
|
|
|
#include <type_traits>
|
|
|
|
|
|
|
|
|
2017-05-26 16:30:48 +10:00
|
|
|
namespace cruft::vk {
|
2017-09-01 12:33:08 +10:00
|
|
|
/// describes the corresponding value for sType in native structures
|
|
|
|
template <typename T>
|
|
|
|
struct structure_type {};
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
2017-09-05 17:20:17 +10:00
|
|
|
#define DEFINE_STRUCTURE_TYPE(KLASS,VALUE) \
|
|
|
|
template <> \
|
|
|
|
struct structure_type<KLASS> : \
|
|
|
|
public std::integral_constant< \
|
|
|
|
VkStructureType, \
|
|
|
|
PASTE(VK_STRUCTURE_TYPE_,VALUE) \
|
|
|
|
> \
|
2017-09-01 12:33:08 +10:00
|
|
|
{ }
|
|
|
|
|
2017-09-05 17:20:17 +10:00
|
|
|
DEFINE_STRUCTURE_TYPE (VkInstanceCreateInfo, INSTANCE_CREATE_INFO);
|
|
|
|
DEFINE_STRUCTURE_TYPE (VkApplicationInfo, APPLICATION_INFO);
|
|
|
|
DEFINE_STRUCTURE_TYPE (VkDeviceQueueCreateInfo, DEVICE_QUEUE_CREATE_INFO);
|
|
|
|
DEFINE_STRUCTURE_TYPE (VkDeviceCreateInfo, DEVICE_CREATE_INFO);
|
|
|
|
DEFINE_STRUCTURE_TYPE (VkSwapchainCreateInfoKHR, SWAPCHAIN_CREATE_INFO_KHR);
|
|
|
|
DEFINE_STRUCTURE_TYPE (VkImageViewCreateInfo, IMAGE_VIEW_CREATE_INFO);
|
|
|
|
DEFINE_STRUCTURE_TYPE (VkShaderModuleCreateInfo, SHADER_MODULE_CREATE_INFO);
|
|
|
|
DEFINE_STRUCTURE_TYPE (VkPipelineShaderStageCreateInfo, PIPELINE_SHADER_STAGE_CREATE_INFO);
|
2017-09-07 15:50:49 +10:00
|
|
|
DEFINE_STRUCTURE_TYPE (VkDebugReportCallbackCreateInfoEXT,
|
|
|
|
DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT);
|
2017-09-01 12:33:08 +10:00
|
|
|
|
|
|
|
#undef DEFINE_STRUCTURE_TYPE
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
constexpr auto structure_type_v = structure_type<T>::value;
|
|
|
|
|
|
|
|
|
2017-09-05 17:20:17 +10:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename T>
|
|
|
|
struct create_info { };
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
#define DEFINE_CREATE_INFO(TARGET,INFO) \
|
|
|
|
template <> \
|
|
|
|
struct create_info<TARGET> \
|
|
|
|
{ using type = INFO; }
|
|
|
|
|
|
|
|
DEFINE_CREATE_INFO (VkImageViewCreateInfo, VkImageViewCreateInfo);
|
|
|
|
DEFINE_CREATE_INFO (VkShaderModule, VkShaderModuleCreateInfo);
|
|
|
|
|
|
|
|
#undef DEFINE_CREATE_INFO
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
using create_info_t = typename create_info<T>::type;
|
|
|
|
|
|
|
|
|
2016-02-24 11:11:41 +11:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename T> struct id_traits { };
|
|
|
|
|
|
|
|
template <> struct id_traits<instance> { using id_t = VkInstance; };
|
|
|
|
template <> struct id_traits<physical_device> { using id_t = VkPhysicalDevice; };
|
|
|
|
template <> struct id_traits<device> { using id_t = VkDevice; };
|
|
|
|
template <> struct id_traits<queue> { using id_t = VkQueue; };
|
|
|
|
template <> struct id_traits<command_pool> { using id_t = VkCommandPool; };
|
|
|
|
template <> struct id_traits<command_buffer> { using id_t = VkCommandBuffer; };
|
|
|
|
template <> struct id_traits<fence> { using id_t = VkFence; };
|
|
|
|
template <> struct id_traits<semaphore> { using id_t = VkSemaphore; };
|
|
|
|
template <> struct id_traits<event> { using id_t = VkEvent; };
|
|
|
|
template <> struct id_traits<render_pass> { using id_t = VkRenderPass; };
|
|
|
|
template <> struct id_traits<framebuffer> { using id_t = VkFramebuffer; };
|
|
|
|
template <> struct id_traits<shader_module> { using id_t = VkShaderModule; };
|
|
|
|
template <> struct id_traits<pipeline> { using id_t = VkPipeline; };
|
|
|
|
template <> struct id_traits<pipeline_cache> { using id_t = VkPipelineCache; };
|
|
|
|
template <> struct id_traits<device_memory> { using id_t = VkDeviceMemory; };
|
|
|
|
template <> struct id_traits<buffer> { using id_t = VkBuffer; };
|
|
|
|
template <> struct id_traits<buffer_view> { using id_t = VkBufferView; };
|
2017-09-07 15:51:11 +10:00
|
|
|
template <> struct id_traits<surface> { using id_t = VkSurfaceKHR; };
|
2016-02-24 11:11:41 +11:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename T> struct life_traits { };
|
|
|
|
|
|
|
|
template <> struct life_traits<instance> {
|
|
|
|
static constexpr auto create = vkCreateInstance;
|
|
|
|
static constexpr auto destroy = vkDestroyInstance;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct life_traits<device> {
|
|
|
|
static constexpr auto create = vkCreateDevice;
|
|
|
|
static constexpr auto destroy = vkDestroyDevice;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct life_traits<command_pool> {
|
|
|
|
static constexpr auto create = vkCreateCommandPool;
|
|
|
|
static constexpr auto destroy = vkDestroyCommandPool;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct life_traits<fence> {
|
|
|
|
static constexpr auto create = vkCreateFence;
|
|
|
|
static constexpr auto destroy = vkDestroyFence;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct life_traits<semaphore> {
|
|
|
|
static constexpr auto create = vkCreateSemaphore;
|
|
|
|
static constexpr auto destroy = vkDestroySemaphore;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct life_traits<event> {
|
|
|
|
static constexpr auto create = vkCreateEvent;
|
|
|
|
static constexpr auto destroy = vkDestroyEvent;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct life_traits<render_pass> {
|
|
|
|
static constexpr auto create = vkCreateRenderPass;
|
|
|
|
static constexpr auto destroy = vkDestroyRenderPass;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct life_traits<framebuffer> {
|
|
|
|
static constexpr auto create = vkCreateFramebuffer;
|
|
|
|
static constexpr auto destroy = vkDestroyFramebuffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct life_traits<shader_module> {
|
|
|
|
static constexpr auto create = vkCreateShaderModule;
|
|
|
|
static constexpr auto destroy = vkDestroyShaderModule;
|
|
|
|
};
|
|
|
|
|
2017-09-07 15:51:11 +10:00
|
|
|
template <> struct life_traits<surface> {
|
|
|
|
static constexpr auto destroy = vkDestroySurfaceKHR;
|
|
|
|
};
|
|
|
|
|
2017-09-05 17:20:17 +10:00
|
|
|
template <>
|
|
|
|
struct life_traits<queue> {
|
|
|
|
static constexpr auto get = vkGetDeviceQueue;
|
|
|
|
};
|
|
|
|
|
2016-02-24 11:11:41 +11:00
|
|
|
template <VkPipelineBindPoint> struct create_traits { };
|
|
|
|
template <> struct create_traits<VK_PIPELINE_BIND_POINT_COMPUTE> {
|
|
|
|
static constexpr auto func = vkCreateComputePipelines;
|
|
|
|
};
|
|
|
|
template <> struct create_traits<VK_PIPELINE_BIND_POINT_GRAPHICS> {
|
|
|
|
static constexpr auto func = vkCreateGraphicsPipelines;
|
|
|
|
};
|
|
|
|
|
2016-05-18 10:19:01 +10:00
|
|
|
// XXX: Currently causes a segfault under gcc-5.3.0 when stabs debgging is
|
|
|
|
// enabled. See gcc#71058
|
|
|
|
//
|
|
|
|
//template <> struct life_traits<pipeline> {
|
|
|
|
// template <VkPipelineBindPoint P>
|
|
|
|
// static constexpr auto create = create_traits<P>::func;
|
|
|
|
// static constexpr auto destroy = vkDestroyPipeline;
|
|
|
|
//};
|
2016-02-24 11:11:41 +11:00
|
|
|
|
|
|
|
template <> struct life_traits<pipeline_cache> {
|
|
|
|
static constexpr auto create = vkCreatePipelineCache;
|
|
|
|
static constexpr auto destroy = vkDestroyPipelineCache;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct life_traits<device_memory> {
|
|
|
|
static constexpr auto create = vkAllocateMemory;
|
|
|
|
static constexpr auto destroy = vkFreeMemory;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct life_traits<buffer> {
|
|
|
|
static constexpr auto create = vkCreateBuffer;
|
|
|
|
static constexpr auto destroy = vkDestroyBuffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> struct life_traits<buffer_view> {
|
|
|
|
static constexpr auto create = vkCreateBufferView;
|
2017-05-26 16:32:31 +10:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename T> struct enum_traits { };
|
2016-02-24 11:11:41 +11:00
|
|
|
|
2017-05-26 16:32:31 +10:00
|
|
|
template <> struct enum_traits<physical_device> {
|
|
|
|
static constexpr auto enumerate = vkEnumeratePhysicalDevices;
|
2016-02-24 11:11:41 +11:00
|
|
|
};
|
2017-09-05 17:20:17 +10:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename T> struct format_traits {};
|
2016-02-24 11:11:41 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|