From 1b293d9a4eacacc1f69906a1572dccc0deb66dd3 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sun, 10 Sep 2017 13:54:27 +1000 Subject: [PATCH] object: add more wrapper types --- CMakeLists.txt | 3 + buffer.hpp | 2 +- command_pool.hpp | 2 + device_memory.hpp | 2 + framebuffer.hpp | 1 + fwd.hpp | 14 +++- image_view.hpp | 6 +- object.hpp | 73 +++++++++++--------- pipeline.hpp | 2 +- pipeline_layout.cpp | 21 ++++++ pipeline_layout.hpp | 29 ++++++++ render_pass.hpp | 2 +- shader_module.cpp | 40 ++++++++++- shader_module.hpp | 14 +++- swapchain.hpp | 29 ++++++++ tools/hello.cpp | 119 ++++++++++++++------------------- traits.hpp | 157 ++++++++++++++++++++++++++------------------ 17 files changed, 341 insertions(+), 175 deletions(-) create mode 100644 pipeline_layout.cpp create mode 100644 pipeline_layout.hpp create mode 100644 swapchain.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index eb9da85..da458ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,6 +75,8 @@ list (APPEND sources pipeline.hpp pipeline_cache.cpp pipeline_cache.hpp + pipeline_layout.cpp + pipeline_layout.hpp queue.cpp queue.hpp render_pass.cpp @@ -85,6 +87,7 @@ list (APPEND sources shader_module.hpp surface.cpp surface.hpp + swapchain.hpp traits.cpp traits.hpp ) diff --git a/buffer.hpp b/buffer.hpp index bae25b4..a971060 100644 --- a/buffer.hpp +++ b/buffer.hpp @@ -23,7 +23,7 @@ namespace cruft::vk { struct buffer : public owned { - + using owned::owned; }; } diff --git a/command_pool.hpp b/command_pool.hpp index 43a43b4..fa459ae 100644 --- a/command_pool.hpp +++ b/command_pool.hpp @@ -22,6 +22,8 @@ namespace cruft::vk { struct command_pool : public owned { + using owned::owned; + void reset (const device&, VkCommandPoolResetFlags); }; } diff --git a/device_memory.hpp b/device_memory.hpp index d1ad831..367f932 100644 --- a/device_memory.hpp +++ b/device_memory.hpp @@ -23,6 +23,8 @@ namespace cruft::vk { struct device_memory : public owned { + using owned::owned; + void* map (const device&, VkDeviceSize offset, VkDeviceSize size, diff --git a/framebuffer.hpp b/framebuffer.hpp index 5367fdc..07e6a16 100644 --- a/framebuffer.hpp +++ b/framebuffer.hpp @@ -22,6 +22,7 @@ namespace cruft::vk { struct framebuffer : public owned { + using owned::owned; }; } diff --git a/fwd.hpp b/fwd.hpp index 2d6577e..1e9b3ad 100644 --- a/fwd.hpp +++ b/fwd.hpp @@ -43,11 +43,13 @@ namespace cruft::vk { struct physical_device; struct pipeline; struct pipeline_cache; + struct pipeline_layout; struct queue; struct render_pass; struct semaphore; struct shader_module; struct surface; + struct swapchain; class error; template class error_code; @@ -62,10 +64,18 @@ namespace cruft::vk { #define VK_OWNED_TYPE_MAP(FUNC) \ MAP(FUNC, \ + buffer, \ + command_pool, \ + device_memory, \ + framebuffer, \ + image_view, \ + pipeline_layout, \ queue, \ - surface, \ + render_pass, \ semaphore, \ - image_view) + shader_module, \ + surface, \ + swapchain) #define VK_TYPE_MAP(FUNC) \ MAP(FUNC,instance) \ diff --git a/image_view.hpp b/image_view.hpp index 085b3be..8f6a1b9 100644 --- a/image_view.hpp +++ b/image_view.hpp @@ -12,11 +12,11 @@ * limitations under the License. * * Copyright: - * 2016, Danny Robson + * 2017, Danny Robson */ -#ifndef CRUFT_VK_SEMAPHORE_HPP -#define CRUFT_VK_SEMAPHORE_HPP +#ifndef CRUFT_VK_IMAGE_VIEW_HPP +#define CRUFT_VK_IMAGE_VIEW_HPP #include "./object.hpp" #include "./fwd.hpp" diff --git a/object.hpp b/object.hpp index 011419b..769b34e 100644 --- a/object.hpp +++ b/object.hpp @@ -29,6 +29,8 @@ namespace cruft::vk { /// management. template struct object { + using native_type = native_t; + object (native_t _native): m_native (_native) { @@ -159,42 +161,49 @@ namespace cruft::vk { /////////////////////////////////////////////////////////////////////////// + template + class owned_ptr { + public: + owned_ptr (T &&_self, owner_t &_owner): + m_self (std::move (_self)), + m_owner (_owner) + { ; } + + owned_ptr (owned_ptr &&rhs): + m_self (std::move (rhs.m_self)), + m_owner (rhs.m_owner) + { ; } + + ~owned_ptr () + { + m_self.destroy (m_owner); + } + + // it's unclear whether we want to work around reseating m_owner, + // or if this operation just isn't sufficiently prevalent to + // justify the work. + owned_ptr& operator= (owned_ptr &&rhs) = delete; + + T& operator* ()& + { return m_self; } + + T* + operator-> ()& + { return &m_self; } + + private: + T m_self; + owner_t &m_owner; + }; + + + + //------------------------------------------------------------------------- template auto make_owned (OwnerT &owner, Args &&...args) { - class destroyer { - public: - destroyer (SelfT &&_self, OwnerT &_owner): - m_self (std::move (_self)), - m_owner (_owner) - { ; } - - destroyer (destroyer &&rhs): - m_self (std::move (rhs.m_self)), - m_owner (rhs.m_owner) - { ; } - - ~destroyer () - { - m_self.destroy (m_owner); - } - - // it's unclear whether we want to work around reseating m_owner, - // or if this operation just isn't sufficiently prevalent to - // justify the work. - destroyer& operator= (destroyer &&rhs) = delete; - - SelfT* - operator-> ()& - { return &m_self; } - - private: - SelfT m_self; - OwnerT &m_owner; - }; - - return destroyer { + return owned_ptr { SelfT { owner, std::forward (args)... }, owner }; diff --git a/pipeline.hpp b/pipeline.hpp index fbeb8a3..7eb03d9 100644 --- a/pipeline.hpp +++ b/pipeline.hpp @@ -23,7 +23,7 @@ namespace cruft::vk { struct pipeline : public owned { - + using owned::owned; }; } diff --git a/pipeline_layout.cpp b/pipeline_layout.cpp new file mode 100644 index 0000000..cbcc6d7 --- /dev/null +++ b/pipeline_layout.cpp @@ -0,0 +1,21 @@ +/* + * 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: + * 2016, Danny Robson + */ + +#include "./pipeline_layout.hpp" + + +/////////////////////////////////////////////////////////////////////////////// diff --git a/pipeline_layout.hpp b/pipeline_layout.hpp new file mode 100644 index 0000000..d4f8268 --- /dev/null +++ b/pipeline_layout.hpp @@ -0,0 +1,29 @@ +/* + * 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, Danny Robson + */ + +#ifndef CRUFT_VK_PIPELINE_LAYOUT_HPP +#define CRUFT_VK_PIPELINE_LAYOUT_HPP + +#include "./object.hpp" + +namespace cruft::vk { + struct pipeline_layout : public owned { + using owned::owned; + }; +}; + +#endif diff --git a/render_pass.hpp b/render_pass.hpp index f10b5ea..c842351 100644 --- a/render_pass.hpp +++ b/render_pass.hpp @@ -22,7 +22,7 @@ namespace cruft::vk { struct render_pass : public owned { - + using owned::owned; }; } diff --git a/shader_module.cpp b/shader_module.cpp index c47ccc9..7e8dff2 100644 --- a/shader_module.cpp +++ b/shader_module.cpp @@ -12,7 +12,45 @@ * limitations under the License. * * Copyright: - * 2016, Danny Robson + * 2016-2017, Danny Robson */ #include "./shader_module.hpp" + +#include "./device.hpp" + +#include + +using cruft::vk::shader_module; + + +/////////////////////////////////////////////////////////////////////////////// +struct cruft::vk::shader_module::cookie : public create_t { +public: + cookie (const std::experimental::filesystem::path &src): + create_t {}, + m_bytes (util::slurp (src)) + { + CHECK_MOD (m_bytes.size (), 4); + + sType = cruft::vk::structure_type_v; + codeSize = m_bytes.size (); + pCode = reinterpret_cast (m_bytes.data ()); + } + +private: + std::vector m_bytes; +}; + + +/////////////////////////////////////////////////////////////////////////////// +shader_module::shader_module (device &owner, + const std::experimental::filesystem::path &src): + shader_module (owner, cookie (src)) +{ ; } + + +//----------------------------------------------------------------------------- +shader_module::shader_module (device &owner, const cookie &info): + owned (owner, &info, nullptr) +{ ; } diff --git a/shader_module.hpp b/shader_module.hpp index c34ceb1..d36d403 100644 --- a/shader_module.hpp +++ b/shader_module.hpp @@ -12,7 +12,7 @@ * limitations under the License. * * Copyright: - * 2016, Danny Robson + * 2016-2017, Danny Robson */ #ifndef CRUFT_VK_SHADER_MODULE_HPP @@ -21,9 +21,21 @@ #include "./object.hpp" #include "./fwd.hpp" +#include + + namespace cruft::vk { struct shader_module : public owned { + using create_t = create_info_t; + shader_module (device&, const std::experimental::filesystem::path &src); + + private: + // used as a convenience to allow taking address of a temporary + // create_info_t in the filesystem::path constructor. + struct cookie; + + shader_module (device&, const cookie&); }; } diff --git a/swapchain.hpp b/swapchain.hpp new file mode 100644 index 0000000..8d78611 --- /dev/null +++ b/swapchain.hpp @@ -0,0 +1,29 @@ +/* + * 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, Danny Robson + */ + +#ifndef CRUFT_VK_SWAPCHAIN_HPP +#define CRUFT_VK_SWAPCHAIN_HPP + +#include "./object.hpp" + +namespace cruft::vk { + struct swapchain : public owned { + using owned::owned; + }; +}; + +#endif diff --git a/tools/hello.cpp b/tools/hello.cpp index 3905f6f..808505b 100644 --- a/tools/hello.cpp +++ b/tools/hello.cpp @@ -5,6 +5,14 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -44,26 +52,6 @@ vk_debug_callback (VkDebugReportFlagsEXT flags, } -VkShaderModule -create_shader (cruft::vk::device &dev, const std::experimental::filesystem::path &src) -{ - auto bytes = util::slurp (src); - assert (bytes.size () % 4 == 0); - - VkShaderModuleCreateInfo create_info {}; - create_info.sType = cruft::vk::structure_type_v; - create_info.codeSize = bytes.size (); - create_info.pCode = reinterpret_cast (bytes.data ()); - - VkShaderModule value; - cruft::vk::error::try_code ( - vkCreateShaderModule (dev.native (), &create_info, nullptr, &value) - ); - - return value; -} - - /////////////////////////////////////////////////////////////////////////////// struct vertex_t { util::point2f position; @@ -247,23 +235,22 @@ main (void) .oldSwapchain = VK_NULL_HANDLE, }; - VkSwapchainKHR swapchain; - cruft::vk::error::try_code ( - vkCreateSwapchainKHR (ldevice.native (), &swap_create_info, nullptr, &swapchain) - ); + auto swapchain = cruft::vk::make_owned (ldevice, &swap_create_info, nullptr); uint32_t swap_image_count = 0; cruft::vk::error::try_code ( - vkGetSwapchainImagesKHR (ldevice.native (), swapchain, &swap_image_count, nullptr) + vkGetSwapchainImagesKHR (ldevice.native (), swapchain->native (), &swap_image_count, nullptr) ); std::vector swap_images = cruft::vk::error::try_values ( - vkGetSwapchainImagesKHR, ldevice.native (), swapchain + vkGetSwapchainImagesKHR, ldevice.native (), swapchain->native () ); - std::vector swap_image_views (swap_image_count); + using image_view_ptr = cruft::vk::owned_ptr; + std::vector swap_image_views; + swap_image_views.reserve (swap_image_count); std::transform ( std::cbegin (swap_images), std::cend (swap_images), - std::begin (swap_image_views), + std::back_inserter (swap_image_views), [&] (auto i) { VkImageViewCreateInfo create_info {}; create_info.sType = cruft::vk::structure_type_v, @@ -285,19 +272,14 @@ main (void) .layerCount = 1 }; - VkImageView v; - cruft::vk::error::try_code ( - vkCreateImageView (ldevice.native (), &create_info, nullptr, &v) - ); - - return v; + return cruft::vk::make_owned (ldevice, &create_info, nullptr); }); auto graphics_queue = cruft::vk::make_owned (ldevice, graphics_queue_id, 0); auto present_queue = cruft::vk::make_owned (ldevice, present_queue_id, 0); - auto vert_module = create_shader (ldevice, "./hello.vert.spv"); - auto frag_module = create_shader (ldevice, "./hello.frag.spv"); + auto vert_module = cruft::vk::make_owned (ldevice, "./hello.vert.spv"); + auto frag_module = cruft::vk::make_owned (ldevice, "./hello.frag.spv"); VkBufferCreateInfo buffer_info {}; buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; @@ -305,12 +287,10 @@ main (void) buffer_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - VkBuffer vertex_buffer = cruft::vk::error::try_query ( - vkCreateBuffer, ldevice.native (), &buffer_info, nullptr - ); + auto vertex_buffer = cruft::vk::make_owned (ldevice, &buffer_info, nullptr); auto memory_requirements = cruft::vk::error::try_query ( - vkGetBufferMemoryRequirements, ldevice.native (), vertex_buffer + vkGetBufferMemoryRequirements, ldevice.native (), vertex_buffer->native () ); auto memory_properties = pdevice.memory_properties (); @@ -327,29 +307,30 @@ main (void) throw std::runtime_error ("no suitable memory type"); } (); - auto vertex_memory = cruft::vk::error::try_query ( - vkAllocateMemory, ldevice.native (), &allocate_info, nullptr + + auto vertex_memory = cruft::vk::make_owned ( + ldevice, &allocate_info, nullptr ); cruft::vk::error::try_code ( - vkBindBufferMemory (ldevice.native (), vertex_buffer, vertex_memory, 0) + vkBindBufferMemory (ldevice.native (), vertex_buffer->native (), vertex_memory->native (), 0) ); auto data = cruft::vk::error::try_query ( - vkMapMemory, ldevice.native (), vertex_memory, 0, buffer_info.size, 0 + vkMapMemory, ldevice.native (), vertex_memory->native (), 0, buffer_info.size, 0 ); memcpy (data, std::data (VERTICES), sizeof (VERTICES)); - vkUnmapMemory (ldevice.native (), vertex_memory); + vkUnmapMemory (ldevice.native (), vertex_memory->native ()); VkPipelineShaderStageCreateInfo vert_stage_info {}; vert_stage_info.sType = cruft::vk::structure_type_v; vert_stage_info.stage = VK_SHADER_STAGE_VERTEX_BIT; - vert_stage_info.module = vert_module; + vert_stage_info.module = vert_module->native (); vert_stage_info.pName = "main"; VkPipelineShaderStageCreateInfo frag_stage_info = vert_stage_info; frag_stage_info.stage = VK_SHADER_STAGE_FRAGMENT_BIT; - frag_stage_info.module = frag_module; + frag_stage_info.module = frag_module->native (); VkPipelineShaderStageCreateInfo stages[] = { vert_stage_info, frag_stage_info @@ -454,9 +435,8 @@ main (void) pipeline_layout_info.pushConstantRangeCount = 0; // Optional pipeline_layout_info.pPushConstantRanges = 0; // Optional - VkPipelineLayout pipeline_layout; - cruft::vk::error::try_code ( - vkCreatePipelineLayout (ldevice.native (), &pipeline_layout_info, nullptr, &pipeline_layout) + auto pipeline_layout = cruft::vk::make_owned ( + ldevice, &pipeline_layout_info, nullptr ); VkAttachmentDescription color_attachment {}; @@ -485,9 +465,8 @@ main (void) render_pass_info.subpassCount = 1; render_pass_info.pSubpasses = &subpass; - VkRenderPass render_pass; - cruft::vk::error::try_code ( - vkCreateRenderPass (ldevice.native (), &render_pass_info, nullptr, &render_pass) + auto render_pass = cruft::vk::make_owned ( + ldevice, &render_pass_info, nullptr ); VkGraphicsPipelineCreateInfo pipeline_info {}; @@ -501,8 +480,8 @@ main (void) pipeline_info.pMultisampleState = &multisampling; pipeline_info.pDepthStencilState = nullptr; pipeline_info.pColorBlendState = &colour_blend; - pipeline_info.layout = pipeline_layout; - pipeline_info.renderPass = render_pass; + pipeline_info.layout = pipeline_layout->native (); + pipeline_info.renderPass = render_pass->native (); pipeline_info.subpass = 0; pipeline_info.basePipelineHandle = VK_NULL_HANDLE; pipeline_info.basePipelineIndex = -1; @@ -515,23 +494,26 @@ main (void) ); - std::vector swapchain_framebuffers (swap_image_views.size ()); + using framebuffer_ptr = cruft::vk::owned_ptr; + std::vector swapchain_framebuffers; + swapchain_framebuffers.reserve (swap_image_views.size ()); + for (size_t i = 0; i < swap_image_views.size (); ++i) { VkImageView attachments[] = { - swap_image_views[i] + swap_image_views[i]->native () }; VkFramebufferCreateInfo framebuffer_info {}; framebuffer_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; - framebuffer_info.renderPass = render_pass; + framebuffer_info.renderPass = render_pass->native (); framebuffer_info.attachmentCount = 1; framebuffer_info.pAttachments = attachments; framebuffer_info.width = present_extent.width; framebuffer_info.height = present_extent.height; framebuffer_info.layers = 1; - cruft::vk::error::try_code ( - vkCreateFramebuffer (ldevice.native (), &framebuffer_info, nullptr, &swapchain_framebuffers[i]) + swapchain_framebuffers.push_back ( + cruft::vk::make_owned (ldevice, &framebuffer_info, nullptr) ); }; @@ -539,15 +521,14 @@ main (void) pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; pool_info.queueFamilyIndex = device_queues[0].queueFamilyIndex; - VkCommandPool command_pool; - cruft::vk::error::try_code ( - vkCreateCommandPool (ldevice.native (), &pool_info, nullptr, &command_pool) + auto command_pool = cruft::vk::make_owned ( + ldevice, &pool_info, nullptr ); std::vector command_buffers (swapchain_framebuffers.size ()); VkCommandBufferAllocateInfo alloc_info = {}; alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; - alloc_info.commandPool = command_pool; + alloc_info.commandPool = command_pool->native (); alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; alloc_info.commandBufferCount = (uint32_t) command_buffers.size(); cruft::vk::error::try_code ( @@ -565,8 +546,8 @@ main (void) VkRenderPassBeginInfo render_begin {}; render_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; - render_begin.renderPass = render_pass; - render_begin.framebuffer = swapchain_framebuffers[i]; + render_begin.renderPass = render_pass->native (); + render_begin.framebuffer = swapchain_framebuffers[i]->native (); render_begin.renderArea.extent = present_extent; VkClearValue clear_color { 0.f, 0.f, 0.f, 1.f }; @@ -577,7 +558,7 @@ main (void) vkCmdBindPipeline (command_buffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, graphics_pipeline); - VkBuffer buffers[] = {vertex_buffer}; + VkBuffer buffers[] = {vertex_buffer->native ()}; VkDeviceSize offsets[] = {0}; vkCmdBindVertexBuffers (command_buffers[i], 0, 1, buffers, offsets); @@ -597,7 +578,7 @@ main (void) uint32_t image_index; cruft::vk::error::try_code ( vkAcquireNextImageKHR ( - ldevice.native (), swapchain, + ldevice.native (), swapchain->native (), std::numeric_limits::max (), image_semaphore->native (), VK_NULL_HANDLE, &image_index @@ -636,7 +617,7 @@ main (void) present_info.waitSemaphoreCount = 1; present_info.pWaitSemaphores = signal_semaphores; - VkSwapchainKHR swapchains[] = { swapchain }; + VkSwapchainKHR swapchains[] = { swapchain->native () }; present_info.swapchainCount = 1; present_info.pSwapchains = swapchains; present_info.pImageIndices = &image_index; diff --git a/traits.hpp b/traits.hpp index 5bfd844..6328bd4 100644 --- a/traits.hpp +++ b/traits.hpp @@ -27,66 +27,6 @@ namespace cruft::vk { - /////////////////////////////////////////////////////////////////////////// - /// describes the corresponding value for sType in native structures - template - struct structure_type {}; - - - //------------------------------------------------------------------------- - #define DEFINE_STRUCTURE_TYPE(KLASS,VALUE) \ - template <> \ - struct structure_type : \ - public std::integral_constant< \ - VkStructureType, \ - PASTE(VK_STRUCTURE_TYPE_,VALUE) \ - > \ - { } - - 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); - DEFINE_STRUCTURE_TYPE (VkDebugReportCallbackCreateInfoEXT, - DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT); - - #undef DEFINE_STRUCTURE_TYPE - - - //------------------------------------------------------------------------- - template - constexpr auto structure_type_v = structure_type::value; - - - /////////////////////////////////////////////////////////////////////////// - /// describes the parameter struct used to create a given vulkan type. - /// - /// explicitly does not operate on vk-cruft types, only native types. - template - struct create_info { }; - - - //------------------------------------------------------------------------- - #define DEFINE_CREATE_INFO(TARGET,INFO) \ - template <> \ - struct create_info \ - { using type = INFO; } - - DEFINE_CREATE_INFO (VkImageViewCreateInfo, VkImageViewCreateInfo); - DEFINE_CREATE_INFO (VkShaderModule, VkShaderModuleCreateInfo); - - #undef DEFINE_CREATE_INFO - - - //------------------------------------------------------------------------- - template - using create_info_t = typename create_info::type; - - /////////////////////////////////////////////////////////////////////////// /// describes the native type that corresponds to a given vk-cruft type. template struct native_traits { }; @@ -106,12 +46,14 @@ namespace cruft::vk { template <> struct native_traits { using type = VkInstance; }; template <> struct native_traits { using type = VkPhysicalDevice; }; template <> struct native_traits { using type = VkPipelineCache; }; + template <> struct native_traits { using type = VkPipelineLayout; }; template <> struct native_traits { using type = VkPipeline; }; template <> struct native_traits { using type = VkQueue; }; template <> struct native_traits { using type = VkRenderPass; }; template <> struct native_traits { using type = VkSemaphore; }; template <> struct native_traits { using type = VkShaderModule; }; template <> struct native_traits { using type = VkSurfaceKHR; }; + template <> struct native_traits { using type = VkSwapchainKHR; }; //------------------------------------------------------------------------- @@ -151,10 +93,10 @@ namespace cruft::vk { //------------------------------------------------------------------------- #define IS_WRAPPER(KLASS) \ - template <> \ - struct is_wrapper : \ - public std::true_type \ - { }; + template <> \ + struct is_wrapper : \ + public std::true_type \ + { }; VK_TYPE_MAP(IS_WRAPPER) #undef IS_WRAPPER @@ -165,6 +107,41 @@ namespace cruft::vk { static constexpr auto is_wrapper_v = is_wrapper::value; + /////////////////////////////////////////////////////////////////////////// + /// describes the corresponding value for sType in native structures + template + struct structure_type {}; + + + //------------------------------------------------------------------------- + #define DEFINE_STRUCTURE_TYPE(KLASS,VALUE) \ + template <> \ + struct structure_type : \ + public std::integral_constant< \ + VkStructureType, \ + PASTE(VK_STRUCTURE_TYPE_,VALUE) \ + > \ + { } + + 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); + DEFINE_STRUCTURE_TYPE (VkDebugReportCallbackCreateInfoEXT, + DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT); + + #undef DEFINE_STRUCTURE_TYPE + + + //------------------------------------------------------------------------- + template + constexpr auto structure_type_v = structure_type::value; + + /////////////////////////////////////////////////////////////////////////// /// describes the native type that owns a given native type, and hence /// forms part of the create/destroy process. @@ -172,13 +149,49 @@ namespace cruft::vk { /// undefined for types that aren't `owned' types. template struct owner_traits {}; + template <> struct owner_traits { using type = device; }; + template <> struct owner_traits { using type = device; }; + template <> struct owner_traits { using type = device; }; + template <> struct owner_traits { using type = device; }; + template <> struct owner_traits { using type = device; }; + template <> struct owner_traits { using type = device; }; template <> struct owner_traits { using type = device; }; + template <> struct owner_traits { using type = device; }; + template <> struct owner_traits { using type = device; }; + template <> struct owner_traits { using type = device; }; template <> struct owner_traits { using type = instance; }; + template <> struct owner_traits { using type = device; }; template using owner_t = typename owner_traits::type; + /////////////////////////////////////////////////////////////////////////// + /// describes the parameter struct used to create a given vulkan type. + /// + /// explicitly does not operate on vk-cruft types, only native types. + template + struct create_info { }; + + + //------------------------------------------------------------------------- + #define DEFINE_CREATE_INFO(TARGET,INFO) \ + template <> \ + struct create_info \ + { using type = INFO; } + + DEFINE_CREATE_INFO (VkImageViewCreateInfo, VkImageViewCreateInfo); + DEFINE_CREATE_INFO (VkShaderModule, VkShaderModuleCreateInfo); + DEFINE_CREATE_INFO (VkPipelineLayout, VkPipelineLayoutCreateInfo); + + #undef DEFINE_CREATE_INFO + + + //------------------------------------------------------------------------- + template + using create_info_t = typename create_info::type; + + /////////////////////////////////////////////////////////////////////////// /// lists the `create' and `destroy' methods for a given native type. /// @@ -206,6 +219,11 @@ namespace cruft::vk { static constexpr auto& destroy = vkDestroyDevice; }; + template <> struct life_traits { + static constexpr auto& create = vkCreateImageView; + static constexpr auto& destroy = vkDestroyImageView; + }; + template <> struct life_traits { static constexpr auto& create = vkCreateCommandPool; static constexpr auto& destroy = vkDestroyCommandPool; @@ -273,6 +291,11 @@ namespace cruft::vk { // static constexpr auto destroy = vkDestroyPipeline; //}; + template <> struct life_traits { + static constexpr auto& create = vkCreatePipelineLayout; + static constexpr auto& destroy = vkDestroyPipelineLayout; + }; + template <> struct life_traits { static constexpr auto& create = vkCreatePipelineCache; static constexpr auto& destroy = vkDestroyPipelineCache; @@ -293,6 +316,12 @@ namespace cruft::vk { }; + template <> struct life_traits { + static constexpr auto& create = vkCreateSwapchainKHR; + static constexpr auto& destroy = vkDestroySwapchainKHR; + }; + + /////////////////////////////////////////////////////////////////////////// /// describes the functions required to enumerate native types template struct enum_traits { };