118 lines
3.6 KiB
C++
118 lines
3.6 KiB
C++
#include <asl/print.hpp>
|
|
#include <asl/buffer.hpp>
|
|
#include <asl/log/log.hpp>
|
|
|
|
#include <SDL3/SDL.h>
|
|
#include <SDL3/SDL_main.h>
|
|
#include <SDL3/SDL_vulkan.h>
|
|
|
|
#include "hk21/vulkan_loader/api.hpp"
|
|
|
|
#define VK_ALLOCATOR nullptr
|
|
|
|
int SDL_main(int /* argc */, char* /* argv */[])
|
|
{
|
|
SDL_Init(SDL_INIT_VIDEO);
|
|
SDL_Window* window = SDL_CreateWindow("HK-21 - 460nm", 1280, 720, SDL_WINDOW_VULKAN);
|
|
|
|
SDL_ShowWindow(window);
|
|
|
|
asl::buffer<const char*> instance_extensions;
|
|
asl::buffer<const char*> device_extensions;
|
|
asl::buffer<const char*> layers;
|
|
|
|
{
|
|
uint32_t count = 0;
|
|
const char* const* extensions = SDL_Vulkan_GetInstanceExtensions(&count);
|
|
for (uint32_t i = 0; i < count; ++i)
|
|
{
|
|
instance_extensions.push(extensions[i]); // NOLINT(*-pointer-arithmetic)
|
|
}
|
|
}
|
|
|
|
layers.push("VK_LAYER_KHRONOS_validation");
|
|
layers.push("VK_LAYER_LUNARG_monitor");
|
|
|
|
instance_extensions.push(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
|
|
|
|
device_extensions.push(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
|
|
|
|
auto vkGetInstanceProcAddr = asl::bit_cast<PFN_vkGetInstanceProcAddr>(SDL_Vulkan_GetVkGetInstanceProcAddr());
|
|
auto status = vulkan_loader::load_global(vkGetInstanceProcAddr);
|
|
if (!status.ok())
|
|
{
|
|
ASL_LOG_ERROR("Couldn't load global Vulkan functions: {}", status);
|
|
return 1;
|
|
}
|
|
|
|
uint32_t version{};
|
|
vkEnumerateInstanceVersion(&version);
|
|
|
|
uint32_t vk_major = VK_API_VERSION_MAJOR(version); // NOLINT
|
|
uint32_t vk_minor = VK_API_VERSION_MINOR(version); // NOLINT
|
|
|
|
if (vk_major != 1 || vk_minor < 3)
|
|
{
|
|
ASL_LOG_ERROR("Incompatible Vulkan version: {}.{}", vk_major, vk_minor);
|
|
return 1;
|
|
}
|
|
|
|
VkApplicationInfo app_info{
|
|
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
|
.pNext = nullptr,
|
|
.pApplicationName = "HK-21",
|
|
.applicationVersion = 0,
|
|
.pEngineName = "Custom",
|
|
.engineVersion = 0,
|
|
.apiVersion = VK_MAKE_API_VERSION(0, 1, 3, 0), // NOLINT
|
|
};
|
|
|
|
VkInstanceCreateInfo instance_create_info{
|
|
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
|
|
.pNext = nullptr,
|
|
.flags = 0,
|
|
.pApplicationInfo = &app_info,
|
|
.enabledLayerCount = static_cast<uint32_t>(layers.size()),
|
|
.ppEnabledLayerNames = layers.data(),
|
|
.enabledExtensionCount = static_cast<uint32_t>(instance_extensions.size()),
|
|
.ppEnabledExtensionNames = instance_extensions.data(),
|
|
};
|
|
|
|
VkInstance instance{};
|
|
VkResult res = vkCreateInstance(&instance_create_info, VK_ALLOCATOR, &instance);
|
|
if (res != VK_SUCCESS)
|
|
{
|
|
ASL_LOG_ERROR("Couldn't create Vulkan instance: {}", res);
|
|
return 1;
|
|
}
|
|
|
|
status = vulkan_loader::load_instance(vkGetInstanceProcAddr, instance);
|
|
if (!status.ok())
|
|
{
|
|
ASL_LOG_ERROR("Couldn't load instance Vulkan functions: {}", status);
|
|
return 1;
|
|
}
|
|
|
|
bool running = true;
|
|
while (running)
|
|
{
|
|
SDL_Event e;
|
|
while (SDL_PollEvent(&e))
|
|
{
|
|
if (e.type == SDL_EVENT_QUIT || (e.type == SDL_EVENT_KEY_DOWN && e.key.key == SDLK_ESCAPE))
|
|
{
|
|
running = false;
|
|
}
|
|
}
|
|
|
|
SDL_Delay(16);
|
|
}
|
|
|
|
vkDestroyInstance(instance, VK_ALLOCATOR);
|
|
SDL_DestroyWindow(window);
|
|
SDL_Quit();
|
|
|
|
return 0;
|
|
}
|
|
|