RAIIfy vulkan
This commit is contained in:
@@ -24,15 +24,15 @@
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <openxr/openxr_platform.h>
|
||||
|
||||
xr::session::session(xr::instance & inst, xr::system & sys, VkInstance vk_inst, VkPhysicalDevice pdev, VkDevice dev, int queue_family_index) :
|
||||
xr::session::session(xr::instance & inst, xr::system & sys, vk::raii::Instance& vk_inst, vk::raii::PhysicalDevice& pdev, vk::raii::Device& dev, int queue_family_index) :
|
||||
inst(&inst)
|
||||
{
|
||||
XrGraphicsBindingVulkan2KHR vulkan_binding{};
|
||||
vulkan_binding.type = XR_TYPE_GRAPHICS_BINDING_VULKAN2_KHR;
|
||||
|
||||
vulkan_binding.instance = vk_inst;
|
||||
vulkan_binding.physicalDevice = pdev;
|
||||
vulkan_binding.device = dev;
|
||||
vulkan_binding.instance = *vk_inst;
|
||||
vulkan_binding.physicalDevice = *pdev;
|
||||
vulkan_binding.device = *dev;
|
||||
vulkan_binding.queueFamilyIndex = queue_family_index;
|
||||
vulkan_binding.queueIndex = 0;
|
||||
|
||||
@@ -75,11 +75,11 @@ xr::space xr::session::create_action_space(XrAction action, const XrPosef & pose
|
||||
return s;
|
||||
}
|
||||
|
||||
std::vector<VkFormat> xr::session::get_swapchain_formats() const
|
||||
std::vector<vk::Format> xr::session::get_swapchain_formats() const
|
||||
{
|
||||
std::vector<VkFormat> formats;
|
||||
std::vector<vk::Format> formats;
|
||||
for (auto i: details::enumerate<int64_t>(xrEnumerateSwapchainFormats, id))
|
||||
formats.push_back(static_cast<VkFormat>(i));
|
||||
formats.push_back(static_cast<vk::Format>(i));
|
||||
return formats;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -22,7 +22,7 @@
|
||||
#include "utils/handle.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
#include "space.h"
|
||||
@@ -38,7 +38,7 @@ class session : public utils::handle<XrSession>
|
||||
|
||||
public:
|
||||
session() = default;
|
||||
session(instance &, system &, VkInstance, VkPhysicalDevice, VkDevice, int queue_family_index);
|
||||
session(instance &, system &, vk::raii::Instance&, vk::raii::PhysicalDevice&, vk::raii::Device&, int queue_family_index);
|
||||
session(session &&) = default;
|
||||
session & operator=(session &&) = default;
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
space create_reference_space(XrReferenceSpaceType ref, const XrPosef & pose = {{0, 0, 0, 1}, {0, 0, 0}});
|
||||
space create_action_space(XrAction action, const XrPosef & pose = {{0, 0, 0, 1}, {0, 0, 0}});
|
||||
|
||||
std::vector<VkFormat> get_swapchain_formats() const;
|
||||
std::vector<vk::Format> get_swapchain_formats() const;
|
||||
|
||||
XrFrameState wait_frame();
|
||||
void begin_frame();
|
||||
|
||||
+11
-19
@@ -21,11 +21,9 @@
|
||||
#include "details/enumerate.h"
|
||||
#include "error.h"
|
||||
#include "session.h"
|
||||
#include "vk/vk.h"
|
||||
#include "xr.h"
|
||||
|
||||
xr::swapchain::swapchain(xr::session & s, VkDevice device, VkFormat format, uint32_t width, uint32_t height, int sample_count) :
|
||||
device(device)
|
||||
xr::swapchain::swapchain(xr::session & s, vk::raii::Device& device, vk::Format format, uint32_t width, uint32_t height, int sample_count)
|
||||
{
|
||||
assert(sample_count == 1);
|
||||
|
||||
@@ -33,7 +31,7 @@ xr::swapchain::swapchain(xr::session & s, VkDevice device, VkFormat format, uint
|
||||
create_info.type = XR_TYPE_SWAPCHAIN_CREATE_INFO;
|
||||
create_info.createFlags = 0;
|
||||
create_info.usageFlags = XR_SWAPCHAIN_USAGE_SAMPLED_BIT | XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
create_info.format = format;
|
||||
create_info.format = static_cast<VkFormat>(format);
|
||||
create_info.sampleCount = sample_count;
|
||||
create_info.width = width;
|
||||
create_info.height = height;
|
||||
@@ -56,32 +54,26 @@ xr::swapchain::swapchain(xr::session & s, VkDevice device, VkFormat format, uint
|
||||
{
|
||||
images_[i].image = array[i].image;
|
||||
|
||||
VkImageViewCreateInfo iv_create_info{};
|
||||
iv_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
||||
vk::ImageViewCreateInfo iv_create_info;
|
||||
iv_create_info.image = array[i].image;
|
||||
iv_create_info.viewType = VkImageViewType::VK_IMAGE_VIEW_TYPE_2D;
|
||||
iv_create_info.viewType = vk::ImageViewType::e2D;
|
||||
iv_create_info.format = format;
|
||||
iv_create_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
iv_create_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
iv_create_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
iv_create_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
iv_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
iv_create_info.components.r = vk::ComponentSwizzle::eIdentity;
|
||||
iv_create_info.components.g = vk::ComponentSwizzle::eIdentity;
|
||||
iv_create_info.components.b = vk::ComponentSwizzle::eIdentity;
|
||||
iv_create_info.components.a = vk::ComponentSwizzle::eIdentity;
|
||||
iv_create_info.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor;
|
||||
iv_create_info.subresourceRange.baseMipLevel = 0;
|
||||
iv_create_info.subresourceRange.levelCount = 1;
|
||||
iv_create_info.subresourceRange.baseArrayLayer = 0;
|
||||
iv_create_info.subresourceRange.layerCount = 1;
|
||||
CHECK_VK(vkCreateImageView(device, &iv_create_info, nullptr, &images_[i].view));
|
||||
|
||||
images_[i].view = vk::raii::ImageView(device, iv_create_info);
|
||||
}
|
||||
}
|
||||
|
||||
xr::swapchain::~swapchain()
|
||||
{
|
||||
for (auto & i: images_)
|
||||
{
|
||||
if (i.view)
|
||||
vkDestroyImageView(device, i.view, nullptr);
|
||||
}
|
||||
|
||||
if (id != XR_NULL_HANDLE)
|
||||
xrDestroySwapchain(id);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#include "utils/handle.h"
|
||||
#include <vector>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
#include <openxr/openxr.h>
|
||||
#include <openxr/openxr_platform.h>
|
||||
|
||||
@@ -38,22 +38,21 @@ class swapchain : public utils::handle<XrSwapchain>
|
||||
public:
|
||||
struct image
|
||||
{
|
||||
VkImage image{};
|
||||
VkImageView view{};
|
||||
vk::Image image{};
|
||||
vk::raii::ImageView view = nullptr;
|
||||
};
|
||||
|
||||
private:
|
||||
VkDevice device;
|
||||
uint32_t width_;
|
||||
uint32_t height_;
|
||||
int sample_count_;
|
||||
VkFormat format_;
|
||||
vk::Format format_;
|
||||
|
||||
std::vector<image> images_;
|
||||
|
||||
public:
|
||||
swapchain() = default;
|
||||
swapchain(session &, VkDevice device, VkFormat format, uint32_t width, uint32_t height, int sample_count = 1);
|
||||
swapchain(session &, vk::raii::Device& device, vk::Format format, uint32_t width, uint32_t height, int sample_count = 1);
|
||||
swapchain(swapchain &&) = default;
|
||||
swapchain(const swapchain &) = delete;
|
||||
swapchain & operator=(swapchain &&) = default;
|
||||
@@ -80,7 +79,7 @@ public:
|
||||
{
|
||||
return images_;
|
||||
}
|
||||
VkFormat format() const
|
||||
vk::Format format() const
|
||||
{
|
||||
return format_;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ XrSystemProperties xr::system::properties() const
|
||||
return prop;
|
||||
}
|
||||
|
||||
VkPhysicalDevice xr::system::physical_device(VkInstance vulkan) const
|
||||
vk::raii::PhysicalDevice xr::system::physical_device(vk::raii::Instance& vulkan) const
|
||||
{
|
||||
auto xrGetVulkanGraphicsDevice2KHR =
|
||||
inst->get_proc<PFN_xrGetVulkanGraphicsDevice2KHR>("xrGetVulkanGraphicsDevice2KHR");
|
||||
@@ -70,23 +70,23 @@ VkPhysicalDevice xr::system::physical_device(VkInstance vulkan) const
|
||||
XrVulkanGraphicsDeviceGetInfoKHR get_info{};
|
||||
get_info.type = XR_TYPE_VULKAN_GRAPHICS_DEVICE_GET_INFO_KHR;
|
||||
get_info.systemId = id;
|
||||
get_info.vulkanInstance = vulkan;
|
||||
get_info.vulkanInstance = *vulkan;
|
||||
|
||||
VkPhysicalDevice dev;
|
||||
CHECK_XR(xrGetVulkanGraphicsDevice2KHR(*inst, &get_info, &dev));
|
||||
|
||||
return dev;
|
||||
return vk::raii::PhysicalDevice{vulkan, dev};
|
||||
}
|
||||
|
||||
VkDevice xr::system::create_device(VkPhysicalDevice pdev, VkDeviceCreateInfo & create_info) const
|
||||
vk::raii::Device xr::system::create_device(vk::raii::PhysicalDevice& pdev, vk::DeviceCreateInfo & create_info) const
|
||||
{
|
||||
XrVulkanDeviceCreateInfoKHR xr_create_info{};
|
||||
|
||||
xr_create_info.type = XR_TYPE_VULKAN_DEVICE_CREATE_INFO_KHR;
|
||||
xr_create_info.pfnGetInstanceProcAddr = vkGetInstanceProcAddr;
|
||||
xr_create_info.systemId = id;
|
||||
xr_create_info.vulkanPhysicalDevice = pdev;
|
||||
xr_create_info.vulkanCreateInfo = &create_info;
|
||||
xr_create_info.vulkanPhysicalDevice = *pdev;
|
||||
xr_create_info.vulkanCreateInfo = &(VkDeviceCreateInfo&)create_info;
|
||||
|
||||
VkDevice dev;
|
||||
VkResult vresult;
|
||||
@@ -95,7 +95,7 @@ VkDevice xr::system::create_device(VkPhysicalDevice pdev, VkDeviceCreateInfo & c
|
||||
CHECK_XR(xrCreateVulkanDeviceKHR(*inst, &xr_create_info, &dev, &vresult));
|
||||
CHECK_VK(vresult, "xrCreateVulkanDeviceKHR");
|
||||
|
||||
return dev;
|
||||
return vk::raii::Device{pdev, dev};
|
||||
}
|
||||
|
||||
std::vector<XrViewConfigurationType> xr::system::view_configurations() const
|
||||
|
||||
+3
-3
@@ -25,7 +25,7 @@
|
||||
|
||||
#include "xr.h"
|
||||
#include <vector>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
#include <openxr/openxr.h>
|
||||
#include <openxr/openxr_platform.h>
|
||||
|
||||
@@ -55,8 +55,8 @@ public:
|
||||
|
||||
XrSystemProperties properties() const;
|
||||
XrGraphicsRequirementsVulkan2KHR graphics_requirements() const;
|
||||
VkPhysicalDevice physical_device(VkInstance vulkan) const;
|
||||
VkDevice create_device(VkPhysicalDevice pdev, VkDeviceCreateInfo & create_info) const;
|
||||
vk::raii::PhysicalDevice physical_device(vk::raii::Instance& vulkan) const;
|
||||
vk::raii::Device create_device(vk::raii::PhysicalDevice& pdev, vk::DeviceCreateInfo & create_info) const;
|
||||
|
||||
std::vector<XrViewConfigurationType> view_configurations() const;
|
||||
XrViewConfigurationProperties view_configuration_properties(XrViewConfigurationType) const;
|
||||
|
||||
Reference in New Issue
Block a user