Move VulkanRenderDriver::_pick_device to RenderDevice::choose_device
This commit is contained in:
@@ -24,6 +24,7 @@ set(ENGINE_SRC
|
|||||||
core/debug.cpp
|
core/debug.cpp
|
||||||
drivers/vulkan/render_driver.cpp
|
drivers/vulkan/render_driver.cpp
|
||||||
render/renderer.cpp
|
render/renderer.cpp
|
||||||
|
render/render_device.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
list(TRANSFORM ENGINE_SRC PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/src/)
|
list(TRANSFORM ENGINE_SRC PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/src/)
|
||||||
|
|||||||
@@ -10,9 +10,10 @@
|
|||||||
#include <nova/types.h>
|
#include <nova/types.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace Nova {
|
namespace Nova {
|
||||||
struct NOVA_API RenderDevice {
|
struct RenderDevice {
|
||||||
static constexpr u32 AUTO = static_cast<u32>(-1);
|
static constexpr u32 AUTO = static_cast<u32>(-1);
|
||||||
enum class Vendor { UNKNOWN = 0, INTEL = 0x8086, AMD = 0x1002, NVIDIA = 0x10de };
|
enum class Vendor { UNKNOWN = 0, INTEL = 0x8086, AMD = 0x1002, NVIDIA = 0x10de };
|
||||||
enum class Type { OTHER = 0, INTEGRATED = 1, DISCRETE = 2, VIRTUAL = 3, CPU = 4 };
|
enum class Type { OTHER = 0, INTEGRATED = 1, DISCRETE = 2, VIRTUAL = 3, CPU = 4 };
|
||||||
@@ -22,5 +23,7 @@ namespace Nova {
|
|||||||
Type type;
|
Type type;
|
||||||
u32 deviceID;
|
u32 deviceID;
|
||||||
void* handle;
|
void* handle;
|
||||||
|
|
||||||
|
NOVA_API static u32 choose_device(const std::vector<RenderDevice>& devices);
|
||||||
};
|
};
|
||||||
} // namespace Nova
|
} // namespace Nova
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ void VulkanRenderDriver::create_device(u32 index) {
|
|||||||
NOVA_ASSERT(!m_device);
|
NOVA_ASSERT(!m_device);
|
||||||
|
|
||||||
if (index == RenderDevice::AUTO) {
|
if (index == RenderDevice::AUTO) {
|
||||||
index = _pick_device();
|
index = RenderDevice::choose_device(m_devices);
|
||||||
} else {
|
} else {
|
||||||
NOVA_ASSERT(index < m_devices.size());
|
NOVA_ASSERT(index < m_devices.size());
|
||||||
}
|
}
|
||||||
@@ -241,39 +241,6 @@ void VulkanRenderDriver::_init_hardware() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 VulkanRenderDriver::_pick_device() const {
|
|
||||||
NOVA_AUTO_TRACE();
|
|
||||||
|
|
||||||
u32 best_index = 0;
|
|
||||||
u32 best_score = 0;
|
|
||||||
|
|
||||||
for (u32 i = 0; i < m_devices.size(); i++) {
|
|
||||||
u32 score = 0;
|
|
||||||
switch (m_devices[i].type) {
|
|
||||||
case RenderDevice::Type::DISCRETE:
|
|
||||||
score += 4;
|
|
||||||
break;
|
|
||||||
case RenderDevice::Type::INTEGRATED:
|
|
||||||
score += 3;
|
|
||||||
break;
|
|
||||||
case RenderDevice::Type::VIRTUAL:
|
|
||||||
score += 2;
|
|
||||||
break;
|
|
||||||
case RenderDevice::Type::CPU:
|
|
||||||
score += 1;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (score > best_score) {
|
|
||||||
best_index = i;
|
|
||||||
best_score = score;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return best_index;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VulkanRenderDriver::_check_device_extensions() {
|
void VulkanRenderDriver::_check_device_extensions() {
|
||||||
NOVA_AUTO_TRACE();
|
NOVA_AUTO_TRACE();
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ namespace Nova {
|
|||||||
void _init_instance();
|
void _init_instance();
|
||||||
void _init_hardware();
|
void _init_hardware();
|
||||||
|
|
||||||
u32 _pick_device() const;
|
|
||||||
void _check_device_extensions();
|
void _check_device_extensions();
|
||||||
void _check_device_features();
|
void _check_device_features();
|
||||||
void _init_queues(std::vector<VkDeviceQueueCreateInfo>& queues) const;
|
void _init_queues(std::vector<VkDeviceQueueCreateInfo>& queues) const;
|
||||||
|
|||||||
43
engine/src/render/render_device.cpp
Normal file
43
engine/src/render/render_device.cpp
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2025, Jayden Grubb <contact@jaydengrubb.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <nova/core/debug.h>
|
||||||
|
#include <nova/render/render_device.h>
|
||||||
|
|
||||||
|
using namespace Nova;
|
||||||
|
|
||||||
|
u32 RenderDevice::choose_device(const std::vector<RenderDevice>& devices) {
|
||||||
|
NOVA_AUTO_TRACE();
|
||||||
|
|
||||||
|
u32 best_index = 0;
|
||||||
|
u32 best_score = 0;
|
||||||
|
|
||||||
|
for (u32 i = 0; i < devices.size(); i++) {
|
||||||
|
u32 score = 0;
|
||||||
|
switch (devices[i].type) {
|
||||||
|
case Type::DISCRETE:
|
||||||
|
score += 4;
|
||||||
|
break;
|
||||||
|
case Type::INTEGRATED:
|
||||||
|
score += 3;
|
||||||
|
break;
|
||||||
|
case Type::VIRTUAL:
|
||||||
|
score += 2;
|
||||||
|
break;
|
||||||
|
case Type::CPU:
|
||||||
|
score += 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (score > best_score) {
|
||||||
|
best_index = i;
|
||||||
|
best_score = score;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return best_index;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user