diff options
| -rw-r--r-- | compute.comp | 4 | ||||
| -rw-r--r-- | include/vulkan-loader.hpp | 22 | ||||
| -rw-r--r-- | src/main.cpp | 21 | ||||
| -rw-r--r-- | src/vulkan-loader.cpp | 14 |
4 files changed, 37 insertions, 24 deletions
diff --git a/compute.comp b/compute.comp new file mode 100644 index 0000000..f0bcb49 --- /dev/null +++ b/compute.comp @@ -0,0 +1,4 @@ +#version 450 + +void main() { +} diff --git a/include/vulkan-loader.hpp b/include/vulkan-loader.hpp index f90ef4d..4586c36 100644 --- a/include/vulkan-loader.hpp +++ b/include/vulkan-loader.hpp @@ -30,13 +30,17 @@ X(vkGetPhysicalDeviceMemoryProperties) \ X(vkCreateDevice) \ X(vkEnumerateDeviceExtensionProperties) \ + X(vkCreateDebugUtilsMessengerEXT) \ + X(vkDestroyDebugUtilsMessengerEXT) + +#if defined(VK_USE_PLATFORM_WIN32_KHR) +#define VULKAN_SURFACE_FUNCTIONS \ X(vkDestroySurfaceKHR) \ X(vkGetPhysicalDeviceSurfaceSupportKHR) \ X(vkGetPhysicalDeviceSurfaceCapabilitiesKHR) \ X(vkGetPhysicalDeviceSurfaceFormatsKHR) \ - X(vkGetPhysicalDeviceSurfacePresentModesKHR) \ - X(vkCreateDebugUtilsMessengerEXT) \ - X(vkDestroyDebugUtilsMessengerEXT) + X(vkGetPhysicalDeviceSurfacePresentModesKHR) +#endif #if defined(WINDOWS) #define PLATFORM_VULKAN_INSTANCE_FUNCTIONS X(vkCreateWin32SurfaceKHR) @@ -48,12 +52,7 @@ X(vkGetDeviceQueue) \ X(vkDestroyDevice) \ X(vkDeviceWaitIdle) \ - X(vkCreateSwapchainKHR) \ - X(vkGetSwapchainImagesKHR) \ - X(vkAcquireNextImageKHR) \ - X(vkDestroySwapchainKHR) \ X(vkQueueSubmit) \ - X(vkQueuePresentKHR) \ X(vkCreateSemaphore) \ X(vkDestroySemaphore) \ X(vkCreateCommandPool) \ @@ -116,6 +115,13 @@ X(vkDestroyBuffer) \ X(vkDestroyRenderPass) +// Depends on the swapchain extension +// X(vkCreateSwapchainKHR) \ +// X(vkGetSwapchainImagesKHR) \ +// X(vkAcquireNextImageKHR) \ +// X(vkDestroySwapchainKHR) \ +// X(vkQueuePresentKHR) \ + #define X(name) extern PFN_##name name; VULKAN_EXPORTED_FUNCTIONS VULKAN_APPLICATION_FUNCTIONS diff --git a/src/main.cpp b/src/main.cpp index 692778c..ca0f7e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -203,22 +203,25 @@ void create_device() { vkGetDeviceQueue(device, compute_queue_index, 0, &compute_queue); } -VkComputePipeline compute_pipeline; +VkPipeline compute_pipeline; void create_pipeline() { - File* fd = fopen("compute.shader", "r"); + FILE* f = fopen("compute.spv", "r"); + if (f == nullptr) { + std::cerr << "Cannot open compute shader file !" << std::endl; + } - if (fseek(fd, 0, SEEK_END) != 0) { + if (fseek(f, 0, SEEK_END) != 0) { exit(1); } - long len = ftell(fd); - const uint32_t* compute_shader_code = (uint32_t*) malloc(len * sizeof(uint32_t)); + long len = ftell(f); + const uint32_t* compute_shader_code = (uint32_t*) malloc(len); - if (fseek(fd, 0, SEEK_SET) != 0) { + if (fseek(f, 0, SEEK_SET) != 0) { exit(1); } - if (fread((void*) compute_shader_code, len * sizeof(uint32_t), len, fd) != len) { + if (fread((void*) compute_shader_code, sizeof(uint32_t), len / sizeof(uint32_t), f) != len / sizeof(uint32_t)) { std::cerr << "Reading shader code failed" << std::endl; exit(1); } @@ -228,7 +231,7 @@ void create_pipeline() { shader_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; shader_create_info.pNext = nullptr; shader_create_info.flags = 0; - shader_create_info.codeSize = len * sizeof(uint32_t); + shader_create_info.codeSize = len; shader_create_info.pCode = compute_shader_code; vkCreateShaderModule(device, &shader_create_info, nullptr, &compute_shader_module); @@ -278,7 +281,7 @@ void create_pipeline() { create_info.layout = pipeline_layout; vkCreateComputePipelines( - device, + device, VK_NULL_HANDLE, 1, &create_info, diff --git a/src/vulkan-loader.cpp b/src/vulkan-loader.cpp index 32aa49b..f4d9547 100644 --- a/src/vulkan-loader.cpp +++ b/src/vulkan-loader.cpp @@ -45,10 +45,10 @@ void Load_##name() VULKAN_APPLICATION_FUNCTIONS #undef X -#define X(name) \ -void Load_##name(VkInstance _instance) \ +#define X(name) \ +void Load_##name(VkInstance instance) \ { \ - name = reinterpret_cast<PFN_##name>(vkGetInstanceProcAddr(_instance, #name)); \ + name = reinterpret_cast<PFN_##name>(vkGetInstanceProcAddr(instance, #name)); \ if (!name) { \ std::cout << "Cannot load vulkan function " << #name << std::endl; \ } \ @@ -57,10 +57,10 @@ VULKAN_INSTANCE_FUNCTIONS PLATFORM_VULKAN_INSTANCE_FUNCTIONS #undef X -#define X(name) \ -void Load_##name(VkDevice _device) \ +#define X(name) \ +void Load_##name(VkDevice device) \ { \ - name = reinterpret_cast<PFN_##name>(vkGetDeviceProcAddr(_device, #name)); \ + name = reinterpret_cast<PFN_##name>(vkGetDeviceProcAddr(device, #name)); \ if (!name) { \ std::cout << "Cannot load vulkan function " << #name << std::endl; \ } \ @@ -84,7 +84,7 @@ void load_instance_functions(VkInstance instance) { } void load_device_functions(VkDevice device) { -#define X(name) void Load_##name(VkDevice _device); +#define X(name) Load_##name(device); VULKAN_DEVICE_FUNCTIONS #undef X } |
