diff options
Diffstat (limited to 'source/base/base_render_vulkan.cpp')
| -rw-r--r-- | source/base/base_render_vulkan.cpp | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/source/base/base_render_vulkan.cpp b/source/base/base_render_vulkan.cpp new file mode 100644 index 0000000..9295d00 --- /dev/null +++ b/source/base/base_render_vulkan.cpp | |||
| @@ -0,0 +1,129 @@ | |||
| 1 | #if 0 | ||
| 2 | #define VK_NO_PROTOTYPES | ||
| 3 | |||
| 4 | internal void | ||
| 5 | vk_render_entrypoint(MemArena *arena, WinParams *window, Params *params) | ||
| 6 | { | ||
| 7 | |||
| 8 | // NOTE: requires #define VK_NO_PROTOTYPES | ||
| 9 | // NOTE: dlopen searches for a path starting with a '/' afterwards it starts searching other directories | ||
| 10 | // thats why the param is called path here. but we pass the name in stead | ||
| 11 | // https://tldp.org/HOWTO/Program-Library-HOWTO/dl-libraries.html | ||
| 12 | |||
| 13 | |||
| 14 | |||
| 15 | VkApplicationInfo app_info{}; // used for creating a vkInstance | ||
| 16 | VkInstanceCreateInfo create_info{}; | ||
| 17 | |||
| 18 | // fill in app info | ||
| 19 | { | ||
| 20 | app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; | ||
| 21 | app_info.pApplicationName = params->name; | ||
| 22 | app_info.applicationVersion = VK_MAKE_VERSION(1, 0, 0); | ||
| 23 | app_info.pEngineName = window->name; | ||
| 24 | app_info.engineVersion = VK_MAKE_VERSION(1, 0, 0); | ||
| 25 | app_info.apiVersion = VK_API_VERSION_1_0; | ||
| 26 | } | ||
| 27 | |||
| 28 | // fill in create info | ||
| 29 | { | ||
| 30 | create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; | ||
| 31 | create_info.pApplicationInfo = &app_info; | ||
| 32 | |||
| 33 | #if 0 | ||
| 34 | // TODO: fill in the extenions for windows. | ||
| 35 | // where do we find these? | ||
| 36 | create_info.enabledExtensionCount = ...; | ||
| 37 | create_info.ppEnabledExtensionNames = ...; | ||
| 38 | #endif | ||
| 39 | } | ||
| 40 | |||
| 41 | #ifdef BASE_DEBUG | ||
| 42 | bool enable_validation_layer = true; | ||
| 43 | #else | ||
| 44 | bool enable_validation_layer = false; | ||
| 45 | #endif | ||
| 46 | |||
| 47 | |||
| 48 | bool layer_found = false; | ||
| 49 | // check validation support | ||
| 50 | ScratchArena scratch = scratch_start(arena); | ||
| 51 | |||
| 52 | |||
| 53 | // gather the validation layers and available layers | ||
| 54 | u32 layer_count; | ||
| 55 | vkEnumerateInstanceLayerProperties(&layer_count, NULL); | ||
| 56 | VkLayerProperties *available_layers; | ||
| 57 | String8List *validation_layers = PushStructZero(arena, String8List); | ||
| 58 | String8Node vk_layer_khronos_validation_node = ToString8Node(str8("VK_LAYER_KHRONOS_validation")); | ||
| 59 | str8_list_push_node(validation_layers, &vk_layer_khronos_validation_node); | ||
| 60 | available_layers = PushArrayZero(arena, VkLayerProperties, layer_count); | ||
| 61 | vkEnumerateInstanceLayerProperties(&layer_count, available_layers); | ||
| 62 | |||
| 63 | for(String8Node *current_node = validation_layers->first; !is_nil_str8_node(current_node); current_node = current_node->next) { | ||
| 64 | for(u32 index = 0; index < layer_count; ++index) { | ||
| 65 | VkLayerProperties *current_layer = &available_layers[index]; | ||
| 66 | String8 current_layer_name = str8(current_layer->layerName); | ||
| 67 | if(str8_is_match(current_node->value, current_layer_name)) { | ||
| 68 | layer_found = true; | ||
| 69 | break; | ||
| 70 | } | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | // check if we found that specific layer and we can continue | ||
| 75 | |||
| 76 | if(enable_validation_layer) { // check the avalaiobe layers after creating the instance | ||
| 77 | if(!layer_found) { | ||
| 78 | Log("requested validation layer not found!"); | ||
| 79 | } | ||
| 80 | |||
| 81 | |||
| 82 | // extract names, null terminated | ||
| 83 | String8 *names_in_one_str8_lit = PushStructZero(arena, String8); | ||
| 84 | for(u32 index = 0; index < layer_count; ++index) { | ||
| 85 | VkLayerProperties *current_layer = &available_layers[index]; | ||
| 86 | String8 current_layer_name; | ||
| 87 | if(current_layer != NULL) { | ||
| 88 | current_layer_name = str8(current_layer->layerName); | ||
| 89 | } else { | ||
| 90 | breakpoint(); | ||
| 91 | } | ||
| 92 | str8_append(names_in_one_str8_lit, ¤t_layer_name); | ||
| 93 | } | ||
| 94 | |||
| 95 | create_info.enabledLayerCount = layer_count; | ||
| 96 | create_info.ppEnabledLayerNames = (const char *)names_in_one_str8_lit->data; // TODO: is this fixed??? | ||
| 97 | } | ||
| 98 | |||
| 99 | VkInstance instance = VK_NULL_HANDLE; | ||
| 100 | VkResult result = vkCreateInstance(&create_info, NULL, &instance); | ||
| 101 | |||
| 102 | if(result != VK_SUCCESS) { // check the return code of the instance creation | ||
| 103 | Log("Failed to create a VkInstance"); | ||
| 104 | } else { | ||
| 105 | scratch_end(&scratch); | ||
| 106 | |||
| 107 | { | ||
| 108 | // TODO: window polling untill it closes | ||
| 109 | } | ||
| 110 | } | ||
| 111 | |||
| 112 | if(instance != VK_NULL_HANDLE) { | ||
| 113 | vkDestroyInstance(instance, nullptr); | ||
| 114 | } | ||
| 115 | } | ||
| 116 | |||
| 117 | |||
| 118 | internal void | ||
| 119 | render_loop() | ||
| 120 | { | ||
| 121 | |||
| 122 | |||
| 123 | |||
| 124 | |||
| 125 | } | ||
| 126 | |||
| 127 | |||
| 128 | |||
| 129 | #endif \ No newline at end of file | ||
