Skip to content

Commit

Permalink
Make Vulkan initialization work
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Feb 4, 2025
1 parent bae003a commit ce148d2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,15 +436,18 @@ static void initWindow(struct dx_window *window, int windowIndex) {
void kinc_g5_internal_destroy_window(int window) {}

void kinc_g5_internal_destroy() {
#ifndef KOPE
#ifdef KINC_WINDOWS
if (device) {
device->Release();
device = NULL;
}
#endif
#endif
}

void kinc_g5_internal_init() {
#ifndef KOPE
#ifdef KINC_WINDOWS
#ifdef _DEBUG
ID3D12Debug *debugController = NULL;
Expand Down Expand Up @@ -483,6 +486,7 @@ void kinc_g5_internal_init() {

CloseHandle(waitEvent);
#endif
#endif
}

void kinc_g5_internal_init_window(int windowIndex, int depthBufferBits, int stencilBufferBits, bool verticalSync) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ static bool find_layer(VkLayerProperties *layers, int layer_count, const char *w
}

void kinc_g5_internal_init() {
#ifndef KOPE
VkResult err;
uint32_t instance_layer_count = 0;

Expand Down Expand Up @@ -1036,6 +1037,7 @@ void kinc_g5_internal_init() {

err = vkCreateSemaphore(vk_ctx.device, &semInfo, NULL, &relay_semaphore);
assert(!err);
#endif
}

void kinc_g5_internal_destroy() {}
Expand Down
40 changes: 22 additions & 18 deletions Backends/Graphics5/Vulkan/Sources/kope/vulkan/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ void kope_vulkan_device_create(kope_g5_device *device, const kope_g5_device_wish

if (check_instance_layers(instance_layers, instance_layers_count)) {
kinc_log(KINC_LOG_LEVEL_INFO, "Running with Vulkan validation layers enabled.");
validation = true;
}
else {
--instance_layers_count; // Remove VK_LAYER_KHRONOS_validation
Expand All @@ -299,6 +300,7 @@ void kope_vulkan_device_create(kope_g5_device *device, const kope_g5_device_wish

instance_extensions[instance_extensions_count++] = VK_KHR_SURFACE_EXTENSION_NAME;
instance_extensions[instance_extensions_count++] = VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME;
instance_extensions[instance_extensions_count++] = VK_EXT_DEBUG_REPORT_EXTENSION_NAME;
#ifdef KINC_WINDOWS
instance_extensions[instance_extensions_count++] = VK_KHR_WIN32_SURFACE_EXTENSION_NAME;
#endif
Expand Down Expand Up @@ -372,37 +374,39 @@ void kope_vulkan_device_create(kope_g5_device *device, const kope_g5_device_wish
#endif

const char *device_extensions[64];
int device_extension_count = 0;
int device_extensions_count = 0;

device_extensions[device_extension_count++] = VK_EXT_DEBUG_MARKER_EXTENSION_NAME;
device_extensions[device_extension_count++] = VK_KHR_SWAPCHAIN_EXTENSION_NAME;
device_extensions[device_extensions_count++] = VK_EXT_DEBUG_MARKER_EXTENSION_NAME;
device_extensions[device_extensions_count++] = VK_KHR_SWAPCHAIN_EXTENSION_NAME;
// Allows negative viewport height to flip viewport
device_extensions[device_extension_count++] = VK_KHR_MAINTENANCE1_EXTENSION_NAME;
device_extensions[device_extensions_count++] = VK_KHR_MAINTENANCE1_EXTENSION_NAME;

#ifdef KINC_VKRT
device_extensions[device_extension_count++] = VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME;
device_extensions[device_extension_count++] = VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME;
device_extensions[device_extension_count++] = VK_KHR_DEFERRED_HOST_OPERATIONS_EXTENSION_NAME;
device_extensions[device_extension_count++] = VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME;
device_extensions[device_extension_count++] = VK_KHR_RAY_TRACING_PIPELINE_EXTENSION_NAME;
device_extensions[device_extension_count++] = VK_KHR_SPIRV_1_4_EXTENSION_NAME;
device_extensions[device_extension_count++] = VK_KHR_SHADER_FLOAT_CONTROLS_EXTENSION_NAME;
device_extensions[device_extensions_count++] = VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME;
device_extensions[device_extensions_count++] = VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME;
device_extensions[device_extensions_count++] = VK_KHR_DEFERRED_HOST_OPERATIONS_EXTENSION_NAME;
device_extensions[device_extensions_count++] = VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME;
device_extensions[device_extensions_count++] = VK_KHR_RAY_TRACING_PIPELINE_EXTENSION_NAME;
device_extensions[device_extensions_count++] = VK_KHR_SPIRV_1_4_EXTENSION_NAME;
device_extensions[device_extensions_count++] = VK_KHR_SHADER_FLOAT_CONTROLS_EXTENSION_NAME;
#endif

#ifndef VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME // For Dave's Debian
#define VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME "VK_KHR_format_feature_flags2"
#endif

device_extensions[device_extension_count++] = VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME;
device_extensions[device_extensions_count++] = VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME;

if (!check_device_extensions(device_extensions, device_extension_count)) {
device_extension_count -= 1; // remove VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME
}
if (!check_device_extensions(device_extensions, device_extensions_count)) {
device_extensions_count -= 1; // remove VK_KHR_FORMAT_FEATURE_FLAGS_2_EXTENSION_NAME

if (!check_device_extensions(device_extensions, device_extension_count)) {
kinc_error_message("Missing device extensions");
if (!check_device_extensions(device_extensions, device_extensions_count)) {
kinc_error_message("Missing device extensions");
}
}

load_extension_functions();

if (validation) {
const VkDebugUtilsMessengerCreateInfoEXT create_info = {
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT,
Expand Down Expand Up @@ -459,7 +463,7 @@ void kope_vulkan_device_create(kope_g5_device *device, const kope_g5_device_wish
.enabledLayerCount = device_layers_count,
.ppEnabledLayerNames = (const char *const *)device_layers,

.enabledExtensionCount = device_extension_count,
.enabledExtensionCount = device_extensions_count,
.ppEnabledExtensionNames = (const char *const *)device_extensions,

#ifdef KINC_VKRT
Expand Down

0 comments on commit ce148d2

Please sign in to comment.