object: add more wrapper types
This commit is contained in:
parent
88b76357fc
commit
1b293d9a4e
@ -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
|
||||
)
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
namespace cruft::vk {
|
||||
struct buffer : public owned<buffer,device> {
|
||||
|
||||
using owned::owned;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,8 @@
|
||||
|
||||
namespace cruft::vk {
|
||||
struct command_pool : public owned<command_pool,device> {
|
||||
using owned::owned;
|
||||
|
||||
void reset (const device&, VkCommandPoolResetFlags);
|
||||
};
|
||||
}
|
||||
|
@ -23,6 +23,8 @@
|
||||
|
||||
namespace cruft::vk {
|
||||
struct device_memory : public owned<device_memory,device> {
|
||||
using owned::owned;
|
||||
|
||||
void* map (const device&,
|
||||
VkDeviceSize offset,
|
||||
VkDeviceSize size,
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
namespace cruft::vk {
|
||||
struct framebuffer : public owned<framebuffer,device> {
|
||||
using owned::owned;
|
||||
};
|
||||
}
|
||||
|
||||
|
14
fwd.hpp
14
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 <VkResult> 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) \
|
||||
|
@ -12,11 +12,11 @@
|
||||
* limitations under the License.
|
||||
*
|
||||
* Copyright:
|
||||
* 2016, Danny Robson <danny@nerdcruft.net>
|
||||
* 2017, Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#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"
|
||||
|
35
object.hpp
35
object.hpp
@ -29,6 +29,8 @@ namespace cruft::vk {
|
||||
/// management.
|
||||
template <typename SelfT>
|
||||
struct object {
|
||||
using native_type = native_t<SelfT>;
|
||||
|
||||
object (native_t<SelfT> _native):
|
||||
m_native (_native)
|
||||
{
|
||||
@ -159,23 +161,20 @@ namespace cruft::vk {
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename SelfT, typename OwnerT, typename ...Args>
|
||||
auto
|
||||
make_owned (OwnerT &owner, Args &&...args)
|
||||
{
|
||||
class destroyer {
|
||||
template <typename T>
|
||||
class owned_ptr {
|
||||
public:
|
||||
destroyer (SelfT &&_self, OwnerT &_owner):
|
||||
owned_ptr (T &&_self, owner_t<T> &_owner):
|
||||
m_self (std::move (_self)),
|
||||
m_owner (_owner)
|
||||
{ ; }
|
||||
|
||||
destroyer (destroyer &&rhs):
|
||||
owned_ptr (owned_ptr &&rhs):
|
||||
m_self (std::move (rhs.m_self)),
|
||||
m_owner (rhs.m_owner)
|
||||
{ ; }
|
||||
|
||||
~destroyer ()
|
||||
~owned_ptr ()
|
||||
{
|
||||
m_self.destroy (m_owner);
|
||||
}
|
||||
@ -183,18 +182,28 @@ namespace cruft::vk {
|
||||
// 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;
|
||||
owned_ptr& operator= (owned_ptr &&rhs) = delete;
|
||||
|
||||
SelfT*
|
||||
T& operator* ()&
|
||||
{ return m_self; }
|
||||
|
||||
T*
|
||||
operator-> ()&
|
||||
{ return &m_self; }
|
||||
|
||||
private:
|
||||
SelfT m_self;
|
||||
OwnerT &m_owner;
|
||||
T m_self;
|
||||
owner_t<T> &m_owner;
|
||||
};
|
||||
|
||||
return destroyer {
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
template <typename SelfT, typename OwnerT, typename ...Args>
|
||||
auto
|
||||
make_owned (OwnerT &owner, Args &&...args)
|
||||
{
|
||||
return owned_ptr<SelfT> {
|
||||
SelfT { owner, std::forward<Args> (args)... },
|
||||
owner
|
||||
};
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
namespace cruft::vk {
|
||||
struct pipeline : public owned<pipeline,device> {
|
||||
|
||||
using owned::owned;
|
||||
};
|
||||
}
|
||||
|
||||
|
21
pipeline_layout.cpp
Normal file
21
pipeline_layout.cpp
Normal file
@ -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 <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#include "./pipeline_layout.hpp"
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
29
pipeline_layout.hpp
Normal file
29
pipeline_layout.hpp
Normal file
@ -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 <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef CRUFT_VK_PIPELINE_LAYOUT_HPP
|
||||
#define CRUFT_VK_PIPELINE_LAYOUT_HPP
|
||||
|
||||
#include "./object.hpp"
|
||||
|
||||
namespace cruft::vk {
|
||||
struct pipeline_layout : public owned<pipeline_layout,device> {
|
||||
using owned::owned;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
@ -22,7 +22,7 @@
|
||||
|
||||
namespace cruft::vk {
|
||||
struct render_pass : public owned<render_pass,device> {
|
||||
|
||||
using owned::owned;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,45 @@
|
||||
* limitations under the License.
|
||||
*
|
||||
* Copyright:
|
||||
* 2016, Danny Robson <danny@nerdcruft.net>
|
||||
* 2016-2017, Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#include "./shader_module.hpp"
|
||||
|
||||
#include "./device.hpp"
|
||||
|
||||
#include <cruft/util/io.hpp>
|
||||
|
||||
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<VkShaderModuleCreateInfo>;
|
||||
codeSize = m_bytes.size ();
|
||||
pCode = reinterpret_cast<const uint32_t*> (m_bytes.data ());
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::byte> 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)
|
||||
{ ; }
|
||||
|
@ -12,7 +12,7 @@
|
||||
* limitations under the License.
|
||||
*
|
||||
* Copyright:
|
||||
* 2016, Danny Robson <danny@nerdcruft.net>
|
||||
* 2016-2017, Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef CRUFT_VK_SHADER_MODULE_HPP
|
||||
@ -21,9 +21,21 @@
|
||||
#include "./object.hpp"
|
||||
#include "./fwd.hpp"
|
||||
|
||||
#include <experimental/filesystem>
|
||||
|
||||
|
||||
namespace cruft::vk {
|
||||
struct shader_module : public owned<shader_module,device> {
|
||||
using create_t = create_info_t<native_type>;
|
||||
|
||||
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&);
|
||||
};
|
||||
}
|
||||
|
||||
|
29
swapchain.hpp
Normal file
29
swapchain.hpp
Normal file
@ -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 <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef CRUFT_VK_SWAPCHAIN_HPP
|
||||
#define CRUFT_VK_SWAPCHAIN_HPP
|
||||
|
||||
#include "./object.hpp"
|
||||
|
||||
namespace cruft::vk {
|
||||
struct swapchain : public owned<swapchain,device> {
|
||||
using owned::owned;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
119
tools/hello.cpp
119
tools/hello.cpp
@ -5,6 +5,14 @@
|
||||
#include <cruft/vk/surface.hpp>
|
||||
#include <cruft/vk/semaphore.hpp>
|
||||
#include <cruft/vk/image_view.hpp>
|
||||
#include <cruft/vk/buffer.hpp>
|
||||
#include <cruft/vk/render_pass.hpp>
|
||||
#include <cruft/vk/shader_module.hpp>
|
||||
#include <cruft/vk/framebuffer.hpp>
|
||||
#include <cruft/vk/pipeline_layout.hpp>
|
||||
#include <cruft/vk/command_pool.hpp>
|
||||
#include <cruft/vk/device_memory.hpp>
|
||||
#include <cruft/vk/swapchain.hpp>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <GLFW/glfw3native.h>
|
||||
@ -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<VkShaderModuleCreateInfo>;
|
||||
create_info.codeSize = bytes.size ();
|
||||
create_info.pCode = reinterpret_cast<const uint32_t*> (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<cruft::vk::swapchain> (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<VkImage> swap_images = cruft::vk::error::try_values (
|
||||
vkGetSwapchainImagesKHR, ldevice.native (), swapchain
|
||||
vkGetSwapchainImagesKHR, ldevice.native (), swapchain->native ()
|
||||
);
|
||||
|
||||
std::vector<VkImageView> swap_image_views (swap_image_count);
|
||||
using image_view_ptr = cruft::vk::owned_ptr<cruft::vk::image_view>;
|
||||
std::vector<image_view_ptr> 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<VkImageViewCreateInfo>,
|
||||
@ -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<cruft::vk::image_view> (ldevice, &create_info, nullptr);
|
||||
});
|
||||
|
||||
auto graphics_queue = cruft::vk::make_owned<cruft::vk::queue> (ldevice, graphics_queue_id, 0);
|
||||
auto present_queue = cruft::vk::make_owned<cruft::vk::queue> (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<cruft::vk::shader_module> (ldevice, "./hello.vert.spv");
|
||||
auto frag_module = cruft::vk::make_owned<cruft::vk::shader_module> (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<cruft::vk::buffer> (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<cruft::vk::device_memory> (
|
||||
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<VkPipelineShaderStageCreateInfo>;
|
||||
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<cruft::vk::pipeline_layout> (
|
||||
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<cruft::vk::render_pass> (
|
||||
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<VkFramebuffer> swapchain_framebuffers (swap_image_views.size ());
|
||||
using framebuffer_ptr = cruft::vk::owned_ptr<cruft::vk::framebuffer>;
|
||||
std::vector<framebuffer_ptr> 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<cruft::vk::framebuffer> (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<cruft::vk::command_pool> (
|
||||
ldevice, &pool_info, nullptr
|
||||
);
|
||||
|
||||
std::vector<VkCommandBuffer> 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<uint64_t>::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;
|
||||
|
149
traits.hpp
149
traits.hpp
@ -27,66 +27,6 @@
|
||||
|
||||
|
||||
namespace cruft::vk {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/// describes the corresponding value for sType in native structures
|
||||
template <typename>
|
||||
struct structure_type {};
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
#define DEFINE_STRUCTURE_TYPE(KLASS,VALUE) \
|
||||
template <> \
|
||||
struct structure_type<KLASS> : \
|
||||
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 <typename T>
|
||||
constexpr auto structure_type_v = structure_type<T>::value;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/// describes the parameter struct used to create a given vulkan type.
|
||||
///
|
||||
/// explicitly does not operate on vk-cruft types, only native types.
|
||||
template <typename>
|
||||
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;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/// describes the native type that corresponds to a given vk-cruft type.
|
||||
template <typename> struct native_traits { };
|
||||
@ -106,12 +46,14 @@ namespace cruft::vk {
|
||||
template <> struct native_traits<instance> { using type = VkInstance; };
|
||||
template <> struct native_traits<physical_device> { using type = VkPhysicalDevice; };
|
||||
template <> struct native_traits<pipeline_cache> { using type = VkPipelineCache; };
|
||||
template <> struct native_traits<pipeline_layout> { using type = VkPipelineLayout; };
|
||||
template <> struct native_traits<pipeline> { using type = VkPipeline; };
|
||||
template <> struct native_traits<queue> { using type = VkQueue; };
|
||||
template <> struct native_traits<render_pass> { using type = VkRenderPass; };
|
||||
template <> struct native_traits<semaphore> { using type = VkSemaphore; };
|
||||
template <> struct native_traits<shader_module> { using type = VkShaderModule; };
|
||||
template <> struct native_traits<surface> { using type = VkSurfaceKHR; };
|
||||
template <> struct native_traits<swapchain> { using type = VkSwapchainKHR; };
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@ -165,6 +107,41 @@ namespace cruft::vk {
|
||||
static constexpr auto is_wrapper_v = is_wrapper<T>::value;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/// describes the corresponding value for sType in native structures
|
||||
template <typename>
|
||||
struct structure_type {};
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
#define DEFINE_STRUCTURE_TYPE(KLASS,VALUE) \
|
||||
template <> \
|
||||
struct structure_type<KLASS> : \
|
||||
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 <typename T>
|
||||
constexpr auto structure_type_v = structure_type<T>::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 <typename> struct owner_traits {};
|
||||
|
||||
template <> struct owner_traits<buffer> { using type = device; };
|
||||
template <> struct owner_traits<command_pool> { using type = device; };
|
||||
template <> struct owner_traits<device_memory> { using type = device; };
|
||||
template <> struct owner_traits<framebuffer> { using type = device; };
|
||||
template <> struct owner_traits<image_view> { using type = device; };
|
||||
template <> struct owner_traits<pipeline_layout> { using type = device; };
|
||||
template <> struct owner_traits<queue> { using type = device; };
|
||||
template <> struct owner_traits<render_pass> { using type = device; };
|
||||
template <> struct owner_traits<semaphore> { using type = device; };
|
||||
template <> struct owner_traits<shader_module> { using type = device; };
|
||||
template <> struct owner_traits<surface> { using type = instance; };
|
||||
template <> struct owner_traits<swapchain> { using type = device; };
|
||||
|
||||
template <typename T>
|
||||
using owner_t = typename owner_traits<T>::type;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/// describes the parameter struct used to create a given vulkan type.
|
||||
///
|
||||
/// explicitly does not operate on vk-cruft types, only native types.
|
||||
template <typename>
|
||||
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);
|
||||
DEFINE_CREATE_INFO (VkPipelineLayout, VkPipelineLayoutCreateInfo);
|
||||
|
||||
#undef DEFINE_CREATE_INFO
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
using create_info_t = typename create_info<T>::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<VkImageView> {
|
||||
static constexpr auto& create = vkCreateImageView;
|
||||
static constexpr auto& destroy = vkDestroyImageView;
|
||||
};
|
||||
|
||||
template <> struct life_traits<VkCommandPool> {
|
||||
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<VkPipelineLayout> {
|
||||
static constexpr auto& create = vkCreatePipelineLayout;
|
||||
static constexpr auto& destroy = vkDestroyPipelineLayout;
|
||||
};
|
||||
|
||||
template <> struct life_traits<VkPipelineCache> {
|
||||
static constexpr auto& create = vkCreatePipelineCache;
|
||||
static constexpr auto& destroy = vkDestroyPipelineCache;
|
||||
@ -293,6 +316,12 @@ namespace cruft::vk {
|
||||
};
|
||||
|
||||
|
||||
template <> struct life_traits<VkSwapchainKHR> {
|
||||
static constexpr auto& create = vkCreateSwapchainKHR;
|
||||
static constexpr auto& destroy = vkDestroySwapchainKHR;
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/// describes the functions required to enumerate native types
|
||||
template <typename> struct enum_traits { };
|
||||
|
Loading…
Reference in New Issue
Block a user