Add RenderDevice struct and driver accessor functions
This commit is contained in:
25
engine/include/nova/render/render_device.h
Normal file
25
engine/include/nova/render/render_device.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Copyright (c) 2025, Jayden Grubb <contact@jaydengrubb.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <nova/api.h>
|
||||
#include <nova/types.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Nova {
|
||||
struct NOVA_API RenderDevice {
|
||||
enum class Vendor { UNKNOWN = 0, INTEL = 0x8086, AMD = 0x1002, NVIDIA = 0x10de };
|
||||
enum class Type { OTHER = 0, INTEGRATED = 1, DISCRETE = 2, VIRTUAL = 3, CPU = 4 };
|
||||
|
||||
std::string name;
|
||||
Vendor vendor;
|
||||
Type type;
|
||||
u32 deviceID;
|
||||
void* handle;
|
||||
};
|
||||
} // namespace Nova
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <nova/api.h>
|
||||
#include <nova/render/render_api.h>
|
||||
#include <nova/render/render_device.h>
|
||||
#include <nova/types.h>
|
||||
|
||||
namespace Nova {
|
||||
@@ -17,5 +18,8 @@ namespace Nova {
|
||||
|
||||
[[nodiscard]] virtual RenderAPI get_api() const = 0;
|
||||
[[nodiscard]] virtual u32 get_api_version() const = 0;
|
||||
|
||||
[[nodiscard]] virtual u32 get_device_count() const = 0;
|
||||
[[nodiscard]] virtual const RenderDevice& get_device(u32 index) const = 0;
|
||||
};
|
||||
} // namespace Nova
|
||||
|
||||
@@ -25,6 +25,7 @@ VulkanRenderDriver::VulkanRenderDriver() {
|
||||
_check_extensions();
|
||||
_check_layers();
|
||||
_init_instance();
|
||||
_init_devices();
|
||||
}
|
||||
|
||||
VulkanRenderDriver::~VulkanRenderDriver() {
|
||||
@@ -42,6 +43,14 @@ u32 VulkanRenderDriver::get_api_version() const {
|
||||
return version;
|
||||
}
|
||||
|
||||
u32 VulkanRenderDriver::get_device_count() const {
|
||||
return m_devices.size();
|
||||
}
|
||||
|
||||
const RenderDevice& VulkanRenderDriver::get_device(const u32 index) const {
|
||||
return m_devices[index];
|
||||
}
|
||||
|
||||
void VulkanRenderDriver::_check_version() const {
|
||||
NOVA_AUTO_TRACE();
|
||||
|
||||
@@ -160,6 +169,29 @@ void VulkanRenderDriver::_init_instance() {
|
||||
NOVA_LOG("VkInstance created");
|
||||
}
|
||||
|
||||
void VulkanRenderDriver::_init_devices() {
|
||||
NOVA_AUTO_TRACE();
|
||||
|
||||
u32 count;
|
||||
vkEnumeratePhysicalDevices(m_instance, &count, nullptr); // TODO: Check result
|
||||
std::vector<VkPhysicalDevice> devices(count);
|
||||
vkEnumeratePhysicalDevices(m_instance, &count, devices.data()); // TODO: Check result
|
||||
|
||||
m_devices.reserve(count);
|
||||
|
||||
for (const auto& device : devices) {
|
||||
VkPhysicalDeviceProperties properties;
|
||||
vkGetPhysicalDeviceProperties(device, &properties);
|
||||
|
||||
m_devices.emplace_back();
|
||||
m_devices.back().name = properties.deviceName;
|
||||
m_devices.back().vendor = static_cast<RenderDevice::Vendor>(properties.vendorID);
|
||||
m_devices.back().type = static_cast<RenderDevice::Type>(properties.deviceType);
|
||||
m_devices.back().deviceID = properties.deviceID;
|
||||
m_devices.back().handle = device;
|
||||
}
|
||||
}
|
||||
|
||||
VkAllocationCallbacks* VulkanRenderDriver::_get_allocator(const VkObjectType type) {
|
||||
// TODO: Add custom allocator
|
||||
(void)type;
|
||||
|
||||
@@ -20,16 +20,21 @@ namespace Nova {
|
||||
[[nodiscard]] RenderAPI get_api() const override;
|
||||
[[nodiscard]] u32 get_api_version() const override;
|
||||
|
||||
[[nodiscard]] u32 get_device_count() const override;
|
||||
[[nodiscard]] const RenderDevice& get_device(u32 index) const override;
|
||||
|
||||
private:
|
||||
VkInstance m_instance = VK_NULL_HANDLE;
|
||||
|
||||
std::vector<const char*> m_extensions;
|
||||
std::vector<const char*> m_layers;
|
||||
std::vector<RenderDevice> m_devices;
|
||||
|
||||
void _check_version() const;
|
||||
void _check_extensions();
|
||||
void _check_layers();
|
||||
void _init_instance();
|
||||
void _init_devices();
|
||||
|
||||
static VkAllocationCallbacks* _get_allocator(VkObjectType type);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user