add device clas which enumerates availble gpu devices
This commit is contained in:
@@ -33,6 +33,7 @@ add_library(maiden_core STATIC
|
||||
src/App.cpp
|
||||
src/Window.cpp
|
||||
src/Engine.cpp
|
||||
src/Device.cpp
|
||||
# include extra source files here
|
||||
)
|
||||
|
||||
|
||||
@@ -83,10 +83,18 @@ This seems like a WSL specific error and causes real issues with relaying graphi
|
||||
$ sudo add-apt-repository ppa:kisak/kisak-mesa
|
||||
$ sudo apt-get update && sudo apt upgrade
|
||||
```
|
||||
|
||||
Note: this resulted in the following erre "WARNING: dzn is not a conformant Vulkan implementation, testing use only." Running `$ vkcube` showed that this indeed was just a warning.
|
||||
|
||||
(for those curious, dzn is a compaitibility layer between DirectX12 and Vulkan for that WSL conformity)
|
||||
|
||||
### Could not locate a Nvidia GPU
|
||||
```bash
|
||||
$ sudo add-apt-repository ppa:kisak/turtle
|
||||
$ sudo apt update
|
||||
$ sudo apt upgrade
|
||||
```
|
||||
verify with `$ vulkaninfo --summary` to ensure your GPU is shown.
|
||||
|
||||
## Development Roadmap
|
||||
### lots of todo here
|
||||
|
||||
56
src/Device.cpp
Normal file
56
src/Device.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
|
||||
#include "Device.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
Device::Device(vk::raii::Instance* instance): instance_(instance) {
|
||||
|
||||
}
|
||||
|
||||
Device::~Device() {
|
||||
|
||||
}
|
||||
|
||||
bool Device::selectPhysicalDevice() {
|
||||
|
||||
std::vector<vk::raii::PhysicalDevice> physicalDevices = instance_->enumeratePhysicalDevices();
|
||||
|
||||
if(physicalDevices.empty()) {
|
||||
std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] Error: no physical devices with Vulkan support found." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// validate found devices
|
||||
uint32_t maxScore = 0;
|
||||
for(vk::raii::PhysicalDevice& physicalDevice : physicalDevices) {
|
||||
uint32_t capabilityScore = evaluatePhysicalDevice(physicalDevice);
|
||||
if(capabilityScore > maxScore) {
|
||||
maxScore = capabilityScore;
|
||||
physicalDevice_ = physicalDevice;
|
||||
}
|
||||
}
|
||||
if(maxScore = 0) {
|
||||
std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] Error: physical devices found, but none capable for this engine." << std::endl;
|
||||
return false;
|
||||
} else {
|
||||
vk::PhysicalDeviceProperties deviceProperties = physicalDevice_.getProperties();
|
||||
std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] Physical device selected: " << deviceProperties.deviceName << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uint32_t Device::evaluatePhysicalDevice(vk::raii::PhysicalDevice& device) {
|
||||
|
||||
vk::PhysicalDeviceProperties deviceProperties = device.getProperties();
|
||||
vk::PhysicalDeviceFeatures deviceFeatures = device.getFeatures();
|
||||
|
||||
std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] Physical device found: " << deviceProperties.deviceName << std::endl;
|
||||
|
||||
if(deviceProperties.deviceType == vk::PhysicalDeviceType::eDiscreteGpu) {
|
||||
return 2;
|
||||
} else {
|
||||
return 1;
|
||||
} // i.e. a descrete gpu is preferable to an integrated gpu
|
||||
|
||||
}
|
||||
24
src/Device.hpp
Normal file
24
src/Device.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
|
||||
class Device {
|
||||
|
||||
public:
|
||||
|
||||
Device(vk::raii::Instance* instance);
|
||||
~Device();
|
||||
|
||||
// assigns a capable gpu vkdevice to physicalDevice
|
||||
bool selectPhysicalDevice();
|
||||
|
||||
private:
|
||||
|
||||
// gives a device a score to attempt to select the most capable device
|
||||
uint32_t evaluatePhysicalDevice(vk::raii::PhysicalDevice& device);
|
||||
|
||||
vk::raii::Instance* instance_ = nullptr;
|
||||
vk::raii::PhysicalDevice physicalDevice_ = nullptr;
|
||||
|
||||
};
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "Device.hpp"
|
||||
|
||||
Engine::Engine(Window* window): window_(window) {
|
||||
|
||||
// cleans up this constructor
|
||||
@@ -19,8 +21,11 @@ void Engine::init() {
|
||||
std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] Error creating Vulkan instance." << std::endl;
|
||||
}
|
||||
|
||||
// next steps:
|
||||
// device selection and setup
|
||||
Device device(&instance_);
|
||||
device.selectPhysicalDevice();
|
||||
|
||||
// next steps:
|
||||
// queue creation
|
||||
// vulkan memory allocator
|
||||
// create vulkan surface
|
||||
|
||||
Reference in New Issue
Block a user