Skip to content

Commit

Permalink
Refactor: Vulkan instance check available layers
Browse files Browse the repository at this point in the history
  • Loading branch information
brenocq committed Nov 30, 2023
1 parent 8247258 commit 30356e8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
28 changes: 18 additions & 10 deletions src/atta/graphics/apis/vulkan/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Instance::Instance() {
// Create instance
VkResult result = vkCreateInstance(&createInfo, nullptr, &_instance);
if (result != VK_SUCCESS)
LOG_ERROR("gfx::vk::Instance", "Failed to create vulkan instance! Code:$0", common::toString(result));
LOG_ERROR("gfx::vk::Instance", "Failed to create vulkan instance! Code: $0", common::toString(result));
}

Instance::~Instance() {
Expand All @@ -59,25 +59,30 @@ VkInstance Instance::getHandle() const { return _instance; }

void Instance::printAvailableExtensions() {
LOG_INFO("gfx::vk::Instance", "Available instance extensions:");
for (const auto& extension : getAvailableExtensions())
LOG_INFO("gfx::vk::Instance", " - $0", extension.extensionName);
}

void Instance::printAvailableLayers() {
LOG_INFO("gfx::vk::Instance", "Available instance layers:");
for (const auto& property : getAvailableLayers())
LOG_INFO("gfx::vk::Instance", " - $0 ($1)", property.layerName, property.description);
}

std::vector<VkExtensionProperties> Instance::getAvailableExtensions() const {
uint32_t extensionCount = 0;
vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);
std::vector<VkExtensionProperties> extensions(extensionCount);
vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, extensions.data());

for (const auto& extension : extensions)
LOG_INFO("gfx::vk::Instance", " - $0", extension.extensionName);
return extensions;
}

void Instance::printAvailableLayers() {
std::vector<VkLayerProperties> Instance::getAvailableLayers() const {
uint32_t propertyCount = 0;
vkEnumerateInstanceLayerProperties(&propertyCount, nullptr);
std::vector<VkLayerProperties> properties(propertyCount);
vkEnumerateInstanceLayerProperties(&propertyCount, properties.data());

LOG_INFO("gfx::vk::Instance", "Available instance layers:");
for (const auto& property : properties)
LOG_INFO("gfx::vk::Instance", " - $0 ($1)", property.layerName, property.description);
return properties;
}

std::vector<const char*> Instance::getEnabledExtensions() {
Expand All @@ -98,9 +103,12 @@ std::vector<const char*> Instance::getEnabledExtensions() {
std::vector<const char*> Instance::getEnabledLayers() {
std::vector<const char*> layers;

for (const auto& layer : getAvailableLayers()) {
#ifdef ATTA_DEBUG_BUILD
layers.push_back("VK_LAYER_KHRONOS_validation");
if (layer.layerName == std::string("VK_LAYER_KHRONOS_validation"))
layers.push_back(layer.layerName);
#endif
}

return layers;
}
Expand Down
3 changes: 3 additions & 0 deletions src/atta/graphics/apis/vulkan/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class Instance {
void printAvailableExtensions();
void printAvailableLayers();

std::vector<VkExtensionProperties> getAvailableExtensions() const;
std::vector<VkLayerProperties> getAvailableLayers() const;

std::vector<const char*> getEnabledExtensions();
std::vector<const char*> getEnabledLayers();

Expand Down
4 changes: 2 additions & 2 deletions src/atta/graphics/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ void Manager::startUpImpl() {
_window = std::static_pointer_cast<Window>(std::make_shared<GlfwWindow>(windowInfo));

//----- Renderer API -----//
_graphicsAPI = std::static_pointer_cast<GraphicsAPI>(std::make_shared<OpenGLAPI>(_window));
//_graphicsAPI = std::static_pointer_cast<GraphicsAPI>(std::make_shared<VulkanAPI>(_window));
//_graphicsAPI = std::static_pointer_cast<GraphicsAPI>(std::make_shared<OpenGLAPI>(_window));
_graphicsAPI = std::static_pointer_cast<GraphicsAPI>(std::make_shared<VulkanAPI>(_window));
_graphicsAPI->startUp();

//----- Compute Shaders -----//
Expand Down
13 changes: 7 additions & 6 deletions src/atta/graphics/windows/glfwWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ GlfwWindow::GlfwWindow(const CreateInfo& info) : Window(info) {
if (_glfwWindowCounter++ == 0) // XXX
glfwInit();

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
// glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
// glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
// glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);// Needed for apple?

// glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
// glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
// glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);// <--- XXX OPENGL

glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);

_window = glfwCreateWindow(_width, _height, _title.c_str(), nullptr, nullptr);
glfwSetWindowUserPointer(_window, (void*)this);
Expand Down Expand Up @@ -98,7 +99,7 @@ GlfwWindow::GlfwWindow(const CreateInfo& info) : Window(info) {

glfwSetErrorCallback([](int error, const char* description) { LOG_ERROR("gfx::Window", "GLFW error($0): $1", error, std::string(description)); });

glfwMakeContextCurrent(_window);
// glfwMakeContextCurrent(_window);// <--- XXX OPENGL

#ifdef ATTA_OS_WEB
int w = canvas_get_width();
Expand Down

0 comments on commit 30356e8

Please sign in to comment.