void (*gfx_cull_face)(Gfx_cull_face cf);
void (*gfx_reshape)(int width, int height);
void (*gfx_wireframe)(bool enable);
+void (*gfx_swapbuffers)();
+void (*gfx_begin_drawing)();
+void (*gfx_end_drawing)();
bool gfx_init(Gfx_API api)
{
extern void (*gfx_cull_face)(Gfx_cull_face cf);
extern void (*gfx_reshape)(int width, int height);
extern void (*gfx_wireframe)(bool enable);
+extern void (*gfx_swapbuffers)();
+extern void (*gfx_begin_drawing)();
+extern void (*gfx_end_drawing)();
bool gfx_init(Gfx_API api);
void gfx_cleanup();
while(!glfwWindowShouldClose(win)) {
display();
- glfwSwapBuffers(win);
+ gfx_swapbuffers();
glfwPollEvents();
}
camera->set_orbit_params(cam_theta, cam_phi, cam_dist);
camera->set_position(cam_pos.x, cam_pos.y, cam_pos.z);
+ gfx_begin_drawing();
+
gfx_clear(0.1, 0.1, 0.1);
terrain_rend->draw();
cow_rend->draw();
+
+ gfx_end_drawing();
}
static bool gen_poisson(std::vector<Vec2> &points, float min_dist, float radius)
static void cull_face(Gfx_cull_face cf);
static void reshape(int width, int height) {}
static void wireframe(bool enable);
+static void swapbuffers();
+static void begin_drawing();
+static void end_drawing();
bool init_opengl()
{
gfx_cull_face = cull_face;
gfx_reshape = reshape;
gfx_wireframe = wireframe;
+ gfx_swapbuffers = swapbuffers;
+ gfx_begin_drawing = begin_drawing;
+ gfx_end_drawing = end_drawing;
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
return true;
else
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
+
+static void swapbuffers()
+{
+ glfwSwapBuffers(win);
+}
+
+static void begin_drawing()
+{
+}
+
+static void end_drawing()
+{
+}
#include <string>
#include "shader.h"
+/* each shader program will correspond to a pipeline. The pipeline
+ * must have the cull, zbuffer etc since they can't be dynamic states */
+
+struct Pipeline {
+
+};
+
class ShaderVK : public Shader
{
protected:
class ShaderProgramVK : public ShaderProgram
{
protected:
+ Pipeline pipeline;
/*ubo*/
public:
virtual void set_uniform_matrix(int location, const Mat4 &mat) override;
};
-#endif // SHADER_VK_H_
\ No newline at end of file
+#endif // SHADER_VK_H_
#include <string>
#include <vector>
+#include <gmath/gmath.h>
+
#include "gfxapi.h"
#include "vkutil.h"
extern int win_w;
extern int win_h;
+VkCommandBuffer *swapchain_cmd_bufs;
+
/* static functions */
static void error_callback(int error, const char *descr);
static void clear(float r, float g, float b);
static void zbuffer(bool enable);
static void cull_face(Gfx_cull_face cf);
static void reshape(int width, int height);
+static void swapbuffers();
+static void begin_drawing();
+static void end_drawing();
+
+static bool create_swapchain_cmd_bufs(VkCommandPool vkcmdpool);
+static bool record_cmd_clear(float r, float g, float b);
bool init_vulkan()
{
+ gfx_clear = clear;
+ gfx_viewport = viewport;
+ gfx_zbuffer = zbuffer;
+ gfx_cull_face = cull_face;
+ gfx_reshape = reshape;
+ gfx_swapbuffers = swapbuffers;
+ gfx_begin_drawing = begin_drawing;
+ gfx_end_drawing = end_drawing;
+
if(!glfwInit()) {
fprintf(stderr, "Failed to initialize GLFW.\n");
return false;
return false;
}
+ if(!vku_create_semaphores())
+ return false;
+
if(!(vkswapchain = vku_create_swapchain(vksurface, win_w, win_h, 2,
VK_PRESENT_MODE_FIFO_KHR, 0))) {
fprintf(stderr, "Failed to create swapchain.\n");
return false;
}
- vkswapchain_views = vku_create_image_views(vkswapchain_images, vknum_swapchain_images);
- if(!vkswapchain_views) {
- fprintf(stderr, "Failed to create swapchain image views.\n");
- delete [] vkswapchain_images;
- return false;
- }
-
- if(!vku_create_renderpass()) {
- fprintf(stderr, "Failed to create renderpass'\n");
+ /* vkswapchain_views = vku_create_image_views(vkswapchain_images, vknum_swapchain_images);
+ if(!vkswapchain_views) {
+ fprintf(stderr, "Failed to create swapchain image views.\n");
+ delete [] vkswapchain_images;
+ return false;
+ }
+ */
+ if(!create_swapchain_cmd_bufs(vkcmdpool)) {
return false;
}
- if(!vku_create_framebuffers(vkswapchain_views, vknum_swapchain_images, win_w, win_h)) {
- fprintf(stderr, "Failed to create framebuffers.\n");
+ if(!record_cmd_clear(1.0, 0.1, 0.1))
return false;
- }
-
- gfx_clear = clear;
- gfx_viewport = viewport;
- gfx_zbuffer = zbuffer;
- gfx_cull_face = cull_face;
- gfx_reshape = reshape;
return true;
}
void cleanup_vulkan()
{
+ vkFreeCommandBuffers(vkdev, vkcmdpool, vknum_swapchain_images, swapchain_cmd_bufs);
if(win) {
glfwDestroyWindow(win);
}
//TODOs according to the book:
// 1- make sure all threads have been terminated (when I add threads)
-
- // 2- destroy objects in *reverse* order
- vkDestroyRenderPass(vkdev, vkrpass, 0);
- vkDestroySurfaceKHR(vkinst, vksurface, 0);
-
vku_cleanup();
}
delete [] vkswapchain_images;
vkswapchain_images = vku_get_swapchain_images(sc, 0);
- vknext_swapchain_image = vku_get_next_image(vkswapchain);
+ vk_curr_swapchain_image = vku_get_next_image(vkswapchain);
}
static void clear(float r, float g, float b)
static void cull_face(Gfx_cull_face cf)
{
}
+
+static void swapbuffers()
+{
+}
+
+static void begin_drawing()
+{
+ if((vk_curr_swapchain_image = vku_get_next_image(vkswapchain)) == -1) {
+ fprintf(stderr, "Failed to get swapchain image. Exiting.\n");
+ exit(1);
+ }
+}
+
+static void end_drawing()
+{
+ /* submit queue */
+
+ VkSubmitInfo sinf;
+ memset(&sinf, 0, sizeof sinf);
+ sinf.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
+ sinf.waitSemaphoreCount = 1;
+ sinf.pWaitSemaphores = &vk_img_avail_sema;
+ sinf.signalSemaphoreCount = 1;
+ sinf.pSignalSemaphores = &vk_rend_done_sema;
+
+ // the queue should wait on the semaphore
+
+ VkPipelineStageFlags wait_flags = VK_PIPELINE_STAGE_TRANSFER_BIT;
+ sinf.pWaitDstStageMask = &wait_flags;
+ sinf.commandBufferCount = 1;
+ sinf.pCommandBuffers = &swapchain_cmd_bufs[vk_curr_swapchain_image];
+
+ if(vkQueueSubmit(vkq, 1, &sinf, VK_NULL_HANDLE) != VK_SUCCESS) {
+ fprintf(stderr, "Failed to submit drawing command buffer\n");
+ exit(1);
+ }
+
+ /* present drawn image */
+ VkPresentInfoKHR pinf;
+ memset(&pinf, 0, sizeof pinf);
+ pinf.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
+ pinf.waitSemaphoreCount = 1;
+ pinf.pWaitSemaphores = &vk_rend_done_sema;
+ pinf.swapchainCount = 1;
+ pinf.pSwapchains = &vkswapchain;
+ pinf.pImageIndices = (uint32_t *)&vk_curr_swapchain_image;
+
+ if(vkQueuePresentKHR(vkq, &pinf) != VK_SUCCESS) {
+ fprintf(stderr, "Failed to submit presentation command buffer.\n");
+ exit(1);
+ }
+}
+
+static bool record_cmd_clear(float r, float g, float b)
+{
+ VkCommandBufferBeginInfo binf;
+ binf.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
+ binf.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
+
+ /* this function must be called outside a renderpass instance */
+ const VkClearColorValue pcolor[4] = {r, g, b, 1.0};
+
+ VkImageSubresourceRange range;
+ memset(&range, 0, sizeof range);
+ range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+ range.baseMipLevel = 0;
+ range.baseArrayLayer = 0;
+ range.layerCount = 1;
+
+ for(int i=0; i<vknum_swapchain_images; i++) {
+ /* layout for clearing */
+ VkImageMemoryBarrier cb;
+ memset(&cb, 0, sizeof cb);
+ cb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
+ cb.srcAccessMask = VK_ACCESS_MEMORY_READ_BIT;
+ cb.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
+ cb.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
+ cb.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
+ cb.srcQueueFamilyIndex = vkqfamily;
+ cb.dstQueueFamilyIndex = vkqfamily;
+ cb.image = vkswapchain_images[i];
+ cb.subresourceRange = range;
+
+ /* layout for presenting */
+ VkImageMemoryBarrier pb;
+ memset(&pb, 0, sizeof pb);
+ pb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
+ pb.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
+ pb.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
+ pb.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
+ pb.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
+ pb.srcQueueFamilyIndex = vkqfamily;
+ pb.dstQueueFamilyIndex = vkqfamily;
+ pb.image = vkswapchain_images[i];
+ pb.subresourceRange = range;
+
+ vkBeginCommandBuffer(swapchain_cmd_bufs[i], &binf);
+ vkCmdPipelineBarrier(swapchain_cmd_bufs[i], VK_PIPELINE_STAGE_TRANSFER_BIT,
+ VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, 0, 0, 0, 1, &pb);
+
+ vkCmdClearColorImage(swapchain_cmd_bufs[i], vkswapchain_images[vk_curr_swapchain_image], VK_IMAGE_LAYOUT_GENERAL,
+ pcolor, 1, &range);
+
+ vkCmdPipelineBarrier(swapchain_cmd_bufs[i], VK_PIPELINE_STAGE_TRANSFER_BIT,
+ VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, 0, 0, 0, 0, 0, 1, &cb);
+
+ if(vkEndCommandBuffer(swapchain_cmd_bufs[i]) != VK_SUCCESS) {
+ fprintf(stderr, "Failed to record command buffer.\n");
+ return false;
+ }
+ }
+ return true;
+}
+
+static bool create_swapchain_cmd_bufs(VkCommandPool cpool)
+{
+ swapchain_cmd_bufs = new VkCommandBuffer[vknum_swapchain_images];
+
+ VkCommandBufferAllocateInfo ainf;
+ memset(&ainf, 0, sizeof ainf);
+
+ ainf.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
+ ainf.commandPool = cpool;
+ ainf.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
+ ainf.commandBufferCount = (uint32_t)vknum_swapchain_images;
+
+ if(vkAllocateCommandBuffers(vkdev, &ainf, swapchain_cmd_bufs) != VK_SUCCESS) {
+ fprintf(stderr, "Failed to allocate the swapchain command buffers.\n");
+ return false;
+ }
+
+ return true;
+}
+#include <gmath/gmath.h>
#include <vulkan/vulkan.h>
#include <stdio.h>
#include <stdint.h>
/* global variables */
-VkPipeline *vkgraphics_pipeline;
+VkPipeline *vkgparent_pipeline;
VkFramebuffer *vkfbufs;
VkRenderPass vkrpass;
-VkSwapchainKHR vkswapchain;
-VkImage *vkswapchain_images;
-VkImageView *vkswapchain_views;
-int vknum_swapchain_images;
-int vknext_swapchain_image;
VkSurfaceKHR vksurface;
VkInstance vkinst;
VkPhysicalDevice vkpdev;
VkCommandBuffer vkcmdbuf; /* primary command buffer */
int vkqfamily;
+VkSemaphore vk_img_avail_sema;
+VkSemaphore vk_rend_done_sema;
+VkSwapchainKHR vkswapchain;
+VkImage *vkswapchain_images;
+VkImageView *vkswapchain_views;
+int vknum_swapchain_images;
+int vk_curr_swapchain_image;
+
/* static functions */
static const char *get_device_name_str(VkPhysicalDeviceType type);
static const char *get_memtype_flags_str(VkMemoryPropertyFlags flags);
if(vkinst) {
vkDeviceWaitIdle(vkdev);
vkDestroyCommandPool(vkdev, vkcmdpool, 0);
+
+ vkDestroySemaphore(vkdev, vk_img_avail_sema, 0);
+ vkDestroySemaphore(vkdev, vk_rend_done_sema, 0);
+
vkDestroyDevice(vkdev, 0);
vkDestroyInstance(vkinst, 0);
vkinst = 0;
phys_devices = 0;
}
+bool vku_create_semaphores()
+{
+ VkSemaphoreCreateInfo sinf;
+ memset(&sinf, 0, sizeof sinf);
+
+ sinf.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
+ if(vkCreateSemaphore(vkdev, &sinf, 0, &vk_img_avail_sema) != VK_SUCCESS) {
+ fprintf(stderr, "Failed to create semaphore\n");
+ return false;
+ }
+
+ if(vkCreateSemaphore(vkdev, &sinf, 0, &vk_rend_done_sema) != VK_SUCCESS) {
+ fprintf(stderr, "Failed to create semaphore\n");
+ return false;
+ }
+
+ return true;
+}
+
VkCommandBuffer vku_alloc_cmdbuf(VkCommandPool pool, VkCommandBufferLevel level)
{
VkCommandBuffer cmdbuf;
vkCmdCopyBuffer(cmdbuf, src, dest, 1, ©);
}
-/* paste
-
-static bool create_instance()
-{
- uint32_t layer_count = 0;
- std::vector<const char *> enabled_layers;
-
- if(vkEnumerateInstanceLayerProperties(&layer_count, 0) != VK_SUCCESS) {
- fprintf(stderr, "Failed to query layer properties.\n");
- return false;
- }
-
- if(layer_count > 0) {
- VkLayerProperties *layers = (VkLayerProperties *)alloca(layer_count * sizeof *layers);
- vkEnumerateInstanceLayerProperties(&layer_count, layers);
- for(uint32_t i=0; i<layer_count; i++) {
- if(strcmp(layers[i].layerName, "VK_LAYER_LUNARG_standard_validation")) {
- enabled_layers.push_back(layers[i].layerName);
- }
- }
- }
-
- uint32_t extensions_count = 0;
- std::vector<const char *> enabled_extensions;
-
- if(vkEnumerateInstanceExtensionProperties(0, &extensions_count, 0) != VK_SUCCESS) {
- fprintf(stderr, "Failed to enumerate instance extension properties\n");
- return false;
- }
-
- if(extensions_count > 0) {
- VkExtensionProperties *extensions = (VkExtensionProperties *)alloca(extensions_count * sizeof *extensions);
- vkEnumerateInstanceExtensionProperties(0, &extensions_count, extensions);
-
- for(uint32_t i=0; i<extensions_count; i++) {
- printf("Extension %u: %s %u.\n", i, extensions[i].extensionName, extensions[i].specVersion);
- //enable all the available extensions
- enabled_extensions.push_back(extensions[i].extensionName);
- enabled_extension_names.push_back(std::string(extensions[i].extensionName));
- }
- }
-
- VkInstanceCreateInfo create_info;
- memset(&create_info, 0, sizeof create_info);
- create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
-
- if(!enabled_layers.empty()) {
- create_info.enabledLayerCount = enabled_layers.size();
- create_info.ppEnabledLayerNames = enabled_layers.data();
- }
-
- if(!enabled_extensions.empty()) {
- create_info.enabledExtensionCount = enabled_extensions.size();
- create_info.ppEnabledExtensionNames = enabled_extensions.data();
- }
-
- if(vkCreateInstance(&create_info, 0, &inst) != VK_SUCCESS) {
- fprintf(stderr, "Failed to create instance.\n");
- return false;
- }
-
- if(!create_device())
- return false;
-
- return true;
-}
-
-static bool create_device()
-{
- int qfam_idx = -1;
- int pdev_idx = -1;
-
- uint32_t dev_count;
- if(vkEnumeratePhysicalDevices(inst, &dev_count, 0) != VK_SUCCESS) {
- fprintf(stderr, "Failed to enumerate physical devices.\n");
- return false;
- }
- printf("%u devices found.\n", (unsigned int)dev_count);
-
- VkPhysicalDevice *phys_dev = (VkPhysicalDevice *)alloca(dev_count * sizeof *phys_dev);
- vkEnumeratePhysicalDevices(inst, &dev_count, phys_dev);
- VkPhysicalDeviceMemoryProperties memprop;
-
- for(uint32_t i=0; i<dev_count; i++) {
- VkPhysicalDeviceProperties dev_props;
- vkGetPhysicalDeviceProperties(phys_dev[i], &dev_props);
-
- //memory heaps:
- vkGetPhysicalDeviceMemoryProperties(phys_dev[i], &memprop);
- printf("\tNumber of heaps: %u\n", memprop.memoryHeapCount);
- for(uint32_t j=0; j<memprop.memoryHeapCount; j++) {
- printf("\t\tHeap %u size: %lu\n", j, (unsigned long)memprop.memoryHeaps[j].size);
- printf("\t\tHeap %u flags: %s\n", j, heap_flags_str(memprop.memoryHeaps[j].flags));
- }
- //memory types
- printf("\tMemory types: %u\n", memprop.memoryTypeCount);
- for(uint32_t j=0; j<memprop.memoryTypeCount; j++) {
- printf("\t\tType %u heap index: %u\n", j, memprop.memoryTypes[j].heapIndex);
- printf("\t\tType %u flags: %s\n", j, memtype_flags_str(memprop.memoryTypes[j].propertyFlags));
- }
-
- //supported features
- VkPhysicalDeviceFeatures features;
- vkGetPhysicalDeviceFeatures(phys_dev[i], &features);
-
- //queue families
- uint32_t qfam_count;
- vkGetPhysicalDeviceQueueFamilyProperties(phys_dev[i], &qfam_count, 0);
- printf("\tQueue Families: %u\n", qfam_count);
- VkQueueFamilyProperties *qfam_props = new VkQueueFamilyProperties[qfam_count];
- vkGetPhysicalDeviceQueueFamilyProperties(phys_dev[i], &qfam_count, qfam_props);
- for(uint32_t j=0; j<qfam_count; j++) {
- printf("\t\tFamily %u flags: %s\n", j, queue_flags_str(qfam_props[j].queueFlags));
- printf("\t\tFamily %u number of queues: %u\n", j, qfam_props[j].queueCount);
-
- if((qfam_props[j].queueFlags & VK_QUEUE_GRAPHICS_BIT) && (pdev_idx == -1)) {
- pdev_idx = i;
- qfam_idx = j;
- num_queues = qfam_props[j].queueCount;
- }
- }
- delete [] qfam_props;
- }
-
- if(pdev_idx == -1) {
- fprintf(stderr, "No suitable devices found.\n");
- return false;
- }
-
- pdev = *(phys_dev + pdev_idx);
- qfamily_idx = qfam_idx;
-
- uint32_t layer_count;
- if(vkEnumerateDeviceLayerProperties(pdev, &layer_count, 0) != VK_SUCCESS) {
- fprintf(stderr, "Failed to enumerate device layers.\n");
- return false;
- }
- if(layer_count > 0) {
- VkLayerProperties *layers = (VkLayerProperties*)alloca(layer_count * sizeof *layers);
- vkEnumerateDeviceLayerProperties(pdev, &layer_count, layers);
- printf("%u layers found.\n", layer_count);
- for(uint32_t i=0; i<layer_count; i++) {
- printf("Layer %u: %s (%u, %u)\n", i, layers[i].layerName,
- layers[i].specVersion, layers[i].implementationVersion);
- printf("\tDesc: %s\n", layers[i].description);
- }
- }
-
- VkDeviceCreateInfo dev_info;
- memset(&dev_info, 0, sizeof dev_info);
- dev_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
-
- VkDeviceQueueCreateInfo dev_qinfo;
- memset(&dev_qinfo, 0, sizeof dev_qinfo);
- dev_qinfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
- dev_qinfo.queueFamilyIndex = qfam_idx;
- dev_qinfo.queueCount = 1;
-
- dev_info.queueCreateInfoCount = 1;
- dev_info.pQueueCreateInfos = &dev_qinfo;
-
- if(vkCreateDevice(pdev, &dev_info, 0, &device) != VK_SUCCESS) {
- fprintf(stderr, "Failed to create logical device.\n");
- return false;
- }
-
- vkGetPhysicalDeviceMemoryProperties(pdev, &memprop);
- for(uint32_t j=0; j<memprop.memoryTypeCount; j++) {
- if(memprop.memoryTypes[j].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) {
- device_mem_idx = j;
- printf("Selected device memory index: %u\n", device_mem_idx);
- break;
- }
- }
-
- return true;
-}
-
-static const char *dev_type_str(VkPhysicalDeviceType type)
-{
- switch(type) {
- case VK_PHYSICAL_DEVICE_TYPE_OTHER:
- return "other";
- case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
- return "integrated GPU";
- case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
- return "discrete GPU";
- case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU:
- return "virtual GPU";
- case VK_PHYSICAL_DEVICE_TYPE_CPU:
- return "CPU";
- default:
- break;
- }
- return "unknown";
-}
-
-static const char *heap_flags_str(VkMemoryHeapFlags flags)
-{
- static std::string str;
- str.clear();
- if(flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) {
- str += "device-local ";
- }
- if(!str.empty())
- str.pop_back();
- return str.c_str();
-}
-
-static const char *memtype_flags_str(VkMemoryPropertyFlags flags)
-{
- static std::string str;
- str.clear();
- if(flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) {
- str += "device-local ";
- }
- if(flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) {
- str += "host-visible ";
- }
- if(flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) {
- str += "host-coherent ";
- }
- if(flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) {
- str += "host-cached ";
- }
- if(flags & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) {
- str += "lazily-allocated ";
- }
- if(!str.empty())
- str.pop_back();
- return str.c_str();
-}
-
-static const char *queue_flags_str(VkQueueFlags flags)
-{
- static std::string str;
- str.clear();
- if(flags & VK_QUEUE_GRAPHICS_BIT)
- str += "graphics ";
- if(flags & VK_QUEUE_COMPUTE_BIT)
- str += "compute ";
- if(flags & VK_QUEUE_TRANSFER_BIT)
- str += "transfer ";
- if(flags & VK_QUEUE_SPARSE_BINDING_BIT)
- str += "sparse-binding ";
- if(!str.empty())
- str.pop_back();
- return str.c_str();
-}
-*/
-
const char *vku_get_vulkan_error_str(VkResult error)
{
std::string errmsg;
break;
case VK_ERROR_FEATURE_NOT_PRESENT:
errmsg = std::string("VK_ERROR_FEATURE_NOT_PRESENT");
- break;
case VK_ERROR_INCOMPATIBLE_DRIVER:
errmsg = std::string("VK_ERROR_INCOMPATIBLE_DRIVER");
break;
msi.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
msi.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
- //TODO in progress
+ /* vertex input descriptions */
+ VkVertexInputBindingDescription vib;
+ memset(&vib, 0, sizeof vib);
+ vib.stride = sizeof(Vec3);
+ vib.inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
+
+ /* input attr bindings */
+ VkVertexInputAttributeDescription via[2];
+ memset(&via, 0, sizeof via);
+ via[0].format = VK_FORMAT_R32G32B32A32_SFLOAT;
+
return true;
}
#include <vulkan/vulkan.h>
#include <vector>
-extern VkPipeline *vkgraphics_pipeline;
+extern VkPipeline *vkgparent_pipeline;
extern VkDescriptorSet *vkdescset;
extern VkFramebuffer *vkfbufs;
extern VkRenderPass vkrpass;
-extern VkSwapchainKHR vkswapchain;
-extern VkImage *vkswapchain_images;
-extern VkImageView *vkswapchain_views;
-extern int vknum_swapchain_images;
-extern VkSurfaceKHR vksurface;
extern VkInstance vkinst;
extern VkPhysicalDevice vkpdev;
extern VkDevice vkdev;
extern VkCommandPool vkcmdpool;
extern VkCommandBuffer vkcmdbuf; /* primary command buffer */
extern int vkqfamily;
-extern int vknext_swapchain_image;
+
+/* presentation */
+extern VkSurfaceKHR vksurface;
+extern VkSwapchainKHR vkswapchain;
+extern int vknum_swapchain_images;
+extern VkImage *vkswapchain_images;
+extern VkImageView *vkswapchain_views;
+extern int vk_curr_swapchain_image;
+extern VkSemaphore vk_img_avail_sema;
+extern VkSemaphore vk_rend_done_sema;
struct vku_buffer {
VkBuffer buf;
bool vku_create_device();
void vku_cleanup();
+/* semaphores */
+bool vku_create_semaphores();
+
/* command buffers */
VkCommandBuffer vku_alloc_cmdbuf(VkCommandPool pool, VkCommandBufferLevel level);
void vku_free_cmdbuf(VkCommandPool pool, VkCommandBuffer buf);