nngn
Loading...
Searching...
No Matches
device.h
Go to the documentation of this file.
1#ifndef NNGN_GRAPHICS_VULKAN_DEVICE_H
2#define NNGN_GRAPHICS_VULKAN_DEVICE_H
3
4#include <span>
5#include <vector>
6
7#include "graphics/graphics.h"
8
9#include "vulkan.h"
10
11namespace nngn {
12
13class Instance;
14
16class Device {
17public:
19 Device(void) = default;
21 ~Device(void);
22 VkPhysicalDevice physical_dev(void) const { return this->ph; }
23 VkDevice id(void) const { return this->h; }
25 std::uint32_t graphics_family(void) const;
27 std::uint32_t present_family(void) const;
29 VkQueue graphics_queue(void) const { return this->queues.graphics; }
31 VkQueue present_queue(void) const { return this->queues.present; }
38 bool init(
39 const Instance &inst, VkPhysicalDevice physical_dev,
40 std::uint32_t graphics_family, std::uint32_t present_family,
41 std::span<const char *const> extensions,
42 std::span<const char *const> layers,
43 const VkPhysicalDeviceFeatures &features);
44 VkSampler create_sampler(
45 VkFilter filter, VkSamplerAddressMode addr_mode, VkBorderColor border,
46 VkSamplerMipmapMode mip_mode, std::uint32_t mip_levels) const;
48 VkShaderModule create_shader(
49 const Instance &inst,
50 std::string_view name, std::span<const std::uint8_t> src) const;
51private:
52 VkPhysicalDevice ph = {};
53 VkDevice h = {};
54 struct { std::uint32_t graphics, present; } families = {};
55 struct { VkQueue graphics, present; } queues = {};
56};
57
59struct DeviceInfo {
60 VkPhysicalDevice dev = {};
62 std::vector<Graphics::Extension> extensions = {};
63 std::vector<Graphics::QueueFamily> queue_families = {};
65 void init(VkSurfaceKHR s, VkPhysicalDevice d);
73 std::tuple<bool, std::uint32_t, std::uint32_t> find_queues() const;
74private:
75 bool can_present(VkSurfaceKHR surface, std::size_t queue_family) const;
76};
77
78inline std::uint32_t Device::graphics_family(void) const {
79 return this->families.graphics;
80}
81
82inline std::uint32_t Device::present_family(void) const {
83 return this->families.present;
84}
85
86}
87
88#endif
name
Definition cathedral.lua:11
Owning wrapper for a VkDevice.
Definition device.h:16
VkDevice h
Definition device.h:53
VkQueue graphics_queue(void) const
Queue used for graphics operations.
Definition device.h:29
VkSampler create_sampler(VkFilter filter, VkSamplerAddressMode addr_mode, VkBorderColor border, VkSamplerMipmapMode mip_mode, std::uint32_t mip_levels) const
Definition device.cpp:96
VkQueue graphics
Definition device.h:55
VkQueue present_queue(void) const
Queue used for presentation, may be the same as graphics_queue.
Definition device.h:31
VkShaderModule create_shader(const Instance &inst, std::string_view name, std::span< const std::uint8_t > src) const
Compiles and names a shader module from source.
Definition device.cpp:120
struct nngn::Device::@13 queues
std::uint32_t present
Definition device.h:54
std::uint32_t graphics
Definition device.h:54
struct nngn::Device::@12 families
std::uint32_t graphics_family(void) const
Family of the queue returned by graphics_queue.
Definition device.h:78
VkPhysicalDevice physical_dev(void) const
Definition device.h:22
VkDevice id(void) const
Definition device.h:23
std::uint32_t present_family(void) const
Family of the queue returned by present_queue.
Definition device.h:82
VkPhysicalDevice ph
Definition device.h:52
Owning wrapper for a Vulkan instance.
Definition instance.h:19
init
Definition img_common.lua:34
Definition audio.cpp:7
#define NNGN_MOVE_ONLY(x)
Definition utils.h:39
Aggregate type for information about a physical device.
Definition device.h:59
std::vector< Graphics::Extension > extensions
Definition device.h:62
Graphics::DeviceInfo info
Definition device.h:61
std::tuple< bool, std::uint32_t, std::uint32_t > find_queues() const
Finds queue families that support graphics and presentation.
Definition device.cpp:180
std::vector< Graphics::QueueFamily > queue_families
Definition device.h:63
bool can_present(VkSurfaceKHR surface, std::size_t queue_family) const
Definition device.cpp:204
VkPhysicalDevice dev
Definition device.h:60
Definition graphics.h:185
std::chrono::seconds s
Definition timing.cpp:6