Compare commits
2 Commits
bd6c4523dd
...
b90c980bee
| Author | SHA1 | Date | |
|---|---|---|---|
| b90c980bee | |||
| f5c4ac0790 |
@@ -17,14 +17,19 @@ int main() {
|
||||
|
||||
GLFWwindow *window = OatmealUtils::initWindow("Oatmeal - createContext", 800, 600);
|
||||
|
||||
|
||||
OatmealUtils::getLogger("context")->info("Creating context");
|
||||
try {
|
||||
Oatmeal::ctx ctx(window);
|
||||
OatmealUtils::getLogger("context")->info("Device name: {}", ctx.getDeviceName());
|
||||
OatmealUtils::getLogger("context")->info("Device name: {}", ctx.getDeviceType());
|
||||
} catch (const std::exception &e) {
|
||||
OatmealUtils::getLogger("context")->critical("{}", e.what());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
OatmealUtils::getLogger("context")->info("Starting main loop");
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
64
oatmeal/src/ctx-device.cpp
Normal file
64
oatmeal/src/ctx-device.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
#include <stdexcept>
|
||||
#include "ctx.h"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
#include "vulkan/vulkan_raii.hpp"
|
||||
|
||||
namespace Oatmeal {
|
||||
|
||||
void ctx::createLogicalDevice() {
|
||||
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = m_physicalDevice.getQueueFamilyProperties();
|
||||
|
||||
m_queueIndex = ~0;
|
||||
for (uint32_t qfpIndex = 0; qfpIndex < queueFamilyProperties.size(); qfpIndex++) {
|
||||
if ((queueFamilyProperties[qfpIndex].queueFlags & vk::QueueFlagBits::eGraphics) &&
|
||||
m_physicalDevice.getSurfaceSupportKHR(qfpIndex, *m_surface)) {
|
||||
m_queueIndex = qfpIndex;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_queueIndex == ~0) {
|
||||
// TODO: Find a better solution then just throwing a fit
|
||||
throw std::runtime_error("Failed to find a queue that supports graphics and presentation");
|
||||
}
|
||||
|
||||
vk::PhysicalDeviceFeatures deviceFeatures;
|
||||
|
||||
vk::StructureChain<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVulkan13Features,
|
||||
vk::PhysicalDeviceExtendedDynamicStateFeaturesEXT>
|
||||
featureChain = {
|
||||
{.features = {.samplerAnisotropy = true}},
|
||||
{.synchronization2 = true, .dynamicRendering = true},
|
||||
{.extendedDynamicState = true},
|
||||
};
|
||||
|
||||
float queuePriority = 0.5f;
|
||||
vk::DeviceQueueCreateInfo deviceQueueCreateInfo = {
|
||||
.queueFamilyIndex = m_queueIndex,
|
||||
.queueCount = 1,
|
||||
.pQueuePriorities = &queuePriority,
|
||||
};
|
||||
|
||||
vk::DeviceCreateInfo deviceCreateInfo = {
|
||||
.pNext = &featureChain.get<vk::PhysicalDeviceFeatures2>(),
|
||||
.queueCreateInfoCount = 1,
|
||||
.pQueueCreateInfos = &deviceQueueCreateInfo,
|
||||
.enabledExtensionCount = static_cast<uint32_t>(requiredDeviceExtensions.size()),
|
||||
.ppEnabledExtensionNames = requiredDeviceExtensions.data(),
|
||||
};
|
||||
|
||||
m_device = vk::raii::Device(m_physicalDevice, deviceCreateInfo);
|
||||
m_queue = vk::raii::Queue(m_device, m_queueIndex, 0);
|
||||
}
|
||||
|
||||
|
||||
std::string ctx::getDeviceName() const {
|
||||
const vk::PhysicalDeviceProperties deviceProperties = m_physicalDevice.getProperties();
|
||||
return deviceProperties.deviceName;
|
||||
}
|
||||
|
||||
std::string ctx::getDeviceType() const {
|
||||
const vk::PhysicalDeviceProperties deviceProperties = m_physicalDevice.getProperties();
|
||||
return vk::to_string(deviceProperties.deviceType);
|
||||
}
|
||||
} // namespace Oatmeal
|
||||
@@ -6,6 +6,8 @@ namespace Oatmeal {
|
||||
m_window = window;
|
||||
createSurface();
|
||||
pickPhysicalDevice();
|
||||
m_msaaSamples = getMaxUsableSampleCount();
|
||||
createLogicalDevice();
|
||||
}
|
||||
|
||||
ctx::~ctx() {}
|
||||
|
||||
@@ -41,6 +41,10 @@ namespace Oatmeal {
|
||||
class ctx {
|
||||
public:
|
||||
ctx(GLFWwindow *window);
|
||||
|
||||
std::string getDeviceName() const;
|
||||
std::string getDeviceType() const;
|
||||
|
||||
~ctx();
|
||||
|
||||
private:
|
||||
@@ -83,9 +87,14 @@ namespace Oatmeal {
|
||||
void createInstance();
|
||||
std::vector<const char *> getRequiredExtensions();
|
||||
void setupDebugMessenger();
|
||||
|
||||
void createSurface();
|
||||
|
||||
void pickPhysicalDevice();
|
||||
bool isPhysicalDeviceSupported(vk::raii::PhysicalDevice device);
|
||||
uint32_t scorePhysicalDevice(vk::raii::PhysicalDevice device);
|
||||
vk::SampleCountFlagBits getMaxUsableSampleCount();
|
||||
|
||||
void createLogicalDevice();
|
||||
};
|
||||
} // namespace Oatmeal
|
||||
|
||||
27
oatmeal/src/ctx_attachments.cpp
Normal file
27
oatmeal/src/ctx_attachments.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "ctx.h"
|
||||
#include "vulkan/vulkan.hpp"
|
||||
|
||||
namespace Oatmeal {
|
||||
|
||||
vk::SampleCountFlagBits ctx::getMaxUsableSampleCount() {
|
||||
vk::PhysicalDeviceProperties physicalDeviceProperties = m_physicalDevice.getProperties();
|
||||
|
||||
vk::SampleCountFlags count = physicalDeviceProperties.limits.framebufferColorSampleCounts &
|
||||
physicalDeviceProperties.limits.framebufferDepthSampleCounts;
|
||||
|
||||
if (count & vk::SampleCountFlagBits::e16) {
|
||||
return vk::SampleCountFlagBits::e16;
|
||||
}
|
||||
if (count & vk::SampleCountFlagBits::e8) {
|
||||
return vk::SampleCountFlagBits::e8;
|
||||
}
|
||||
if (count & vk::SampleCountFlagBits::e4) {
|
||||
return vk::SampleCountFlagBits::e4;
|
||||
}
|
||||
if (count & vk::SampleCountFlagBits::e2) {
|
||||
return vk::SampleCountFlagBits::e2;
|
||||
}
|
||||
|
||||
return vk::SampleCountFlagBits::e1;
|
||||
}
|
||||
} // namespace Oatmeal
|
||||
Reference in New Issue
Block a user