Compare commits
3 Commits
e3c4267fc2
...
a94f2da6b2
| Author | SHA1 | Date | |
|---|---|---|---|
| a94f2da6b2 | |||
| 9bcb8385fe | |||
| a0b3325e1d |
@@ -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
|
||||
)
|
||||
|
||||
|
||||
15
README.md
15
README.md
@@ -10,10 +10,13 @@ The maiden project is a GPU accelerated 3D rendering engine built with C++ based
|
||||
|
||||
### Clone Repository
|
||||
```bash
|
||||
$ git clone https://git.vxbard.net/homeburger/maiden.git
|
||||
# ssh recommended for contribution
|
||||
$ git clone git@github.com:Blitblank/maiden.git
|
||||
# http if you don't like ssh:
|
||||
$ git clone https://github.com/Blitblank/maiden.git
|
||||
|
||||
# If there's any necessary submodules then:
|
||||
$ git clone --recurse-submodules https://git.vxbard.net/homeburger/maiden.git
|
||||
$ git clone --recurse-submodules git@github.com:Blitblank/maiden.git
|
||||
|
||||
# If you have already cloned the repository and you need its submodules:
|
||||
$ git submodule update --init --recursive
|
||||
@@ -80,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
|
||||
|
||||
106
src/Device.cpp
Normal file
106
src/Device.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
|
||||
#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;
|
||||
|
||||
uint32_t score = 0;
|
||||
|
||||
// TODO: this is very basic and can be improved
|
||||
|
||||
// prefer discrete graphics to integrated graphics
|
||||
if(deviceProperties.deviceType == vk::PhysicalDeviceType::eDiscreteGpu) {
|
||||
score += 2;
|
||||
} else {
|
||||
std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] Warning: physical device " << deviceProperties.deviceName << " is not a discrete device!" << std::endl;
|
||||
}
|
||||
|
||||
// prefer devices that support vulkan 1.3
|
||||
if(deviceProperties.apiVersion >= vk::ApiVersion14) {
|
||||
score++;
|
||||
} else {
|
||||
std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] Warning: physical device " << deviceProperties.deviceName << " does not support Vulkan 1.3! (" << std::endl;
|
||||
}
|
||||
|
||||
// prefer devices that support graphics queues
|
||||
auto queueFamilies = device.getQueueFamilyProperties();
|
||||
if(std::ranges::any_of( queueFamilies, []( auto const & qfp ) { return !!( qfp.queueFlags & vk::QueueFlagBits::eGraphics ); } )) {
|
||||
score++;
|
||||
} else {
|
||||
std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] Warning: physical device " << deviceProperties.deviceName << " does not support graphics queue families!" << std::endl;
|
||||
}
|
||||
|
||||
// prefer devices that support all required extensions
|
||||
auto availableDeviceExtensions = device.enumerateDeviceExtensionProperties();
|
||||
bool found = false;
|
||||
uint32_t missingExtensions = 0;
|
||||
for(auto& requiredExtension : requiredDeviceExtensions_) {
|
||||
for(auto& availableExtension: availableDeviceExtensions) {
|
||||
if(strcmp(availableExtension.extensionName, requiredExtension) == 0) {
|
||||
found = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if(found == false) {
|
||||
missingExtensions++;
|
||||
}
|
||||
}
|
||||
if(missingExtensions == 0) {
|
||||
score++;
|
||||
} else {
|
||||
std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] Warning: physical device " << deviceProperties.deviceName << " is missing extensions!" << std::endl;
|
||||
}
|
||||
|
||||
// prefer devices that support all required features
|
||||
auto features = device.template getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVulkan13Features, vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT>();
|
||||
if(features.template get<vk::PhysicalDeviceVulkan13Features>().dynamicRendering && features.template get<vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT>().extendedDynamicState) {
|
||||
score++;
|
||||
} else {
|
||||
std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] Warning: physical device " << deviceProperties.deviceName << " is missing features!" << std::endl;
|
||||
}
|
||||
|
||||
return score;
|
||||
}
|
||||
27
src/Device.hpp
Normal file
27
src/Device.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
#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;
|
||||
|
||||
// required extensions for the physical device
|
||||
std::vector<const char*> requiredDeviceExtensions_ = { vk::KHRSwapchainExtensionName };
|
||||
|
||||
};
|
||||
@@ -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