mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
mem_alloc_info.pNext = is_external ? &exp_mem_info : VK_NULL_HANDLE;
mem_alloc_info.allocationSize = mem_reqs->size;
- mem_alloc_info.memoryTypeIndex =
- get_memory_type_idx(ctx->pdev, mem_reqs, prop_flags);
+ mem_alloc_info.memoryTypeIndex = get_memory_type_idx(ctx->pdev,
+ mem_reqs,
+ prop_flags);
if (mem_alloc_info.memoryTypeIndex == UINT32_MAX) {
fprintf(stderr, "No suitable memory type index found.\n");
}
static bool
-alloc_image_memory(struct vk_ctx *ctx, bool is_external, struct vk_image_obj *img_obj)
+alloc_image_memory(struct vk_ctx *ctx,
+ bool is_external,
+ struct vk_image_obj *img_obj)
{
VkMemoryDedicatedRequirements ded_reqs;
VkImageMemoryRequirementsInfo2 req_info2;
{
VkPresentModeKHR *present_modes;
uint32_t num_present_modes;
- int i;
/* find supported present modes */
if (vkGetPhysicalDeviceSurfacePresentModesKHR(ctx->pdev, surf, &num_present_modes, 0) != VK_SUCCESS || !num_present_modes) {
}
s_info->presentMode = VK_PRESENT_MODE_FIFO_KHR;
+#if 0
if (!has_vsync) {
for (i = 0; i < num_present_modes; i++) {
if (present_modes[i] == VK_PRESENT_MODE_MAILBOX_KHR) {
s_info->presentMode = present_modes[i];
- goto success;
+ break;
}
if (present_modes[i] == VK_PRESENT_MODE_IMMEDIATE_KHR) {
s_info->presentMode = present_modes[i];
- goto success;
+ break;
}
}
}
+#endif
-success:
free(present_modes);
return true;
}
return true;
fail:
- vk_cleanup_ctx(ctx, enable_layers);
+ vk_cleanup_ctx(ctx);
return false;
}
return true;
fail:
- vk_cleanup_ctx(ctx, enable_layers);
+ vk_cleanup_ctx(ctx);
return false;
}
void
-vk_destroy_cmd_bufs(struct vk_ctx *ctx,
- uint32_t num_buffers,
- VkCommandBuffer *buffers)
+vk_destroy_cmd_buffers(struct vk_ctx *ctx,
+ uint32_t num_buffers,
+ VkCommandBuffer *buffers)
{
int i;
for (i = 0; i < num_buffers; i++) {
vkResetCommandBuffer(buffers[i],
VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT);
}
- vkFreeCommandBuffers(ctx->dev, ctx->cmd_pool, num_buffers, &buffers[i]);
+ vkFreeCommandBuffers(ctx->dev, ctx->cmd_pool, num_buffers, buffers);
}
void
-vk_cleanup_ctx(struct vk_ctx *ctx,
- bool enable_layers)
+vk_cleanup_ctx(struct vk_ctx *ctx)
{
- if (enable_layers) {
- return;
- }
-
if (ctx->cmd_pool != VK_NULL_HANDLE) {
vkResetCommandPool(ctx->dev, ctx->cmd_pool,
VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT);
img_info.tiling = props->tiling;
img_info.usage = props->usage ?
props->usage : VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
- img_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
+ img_info.initialLayout = props->in_layout;
img_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
if (vkCreateImage(ctx->dev, &img_info, 0, &img->img) != VK_SUCCESS)
void
vk_destroy_buffer(struct vk_ctx *ctx,
- struct vk_buf *bo)
+ struct vk_buf *bo)
{
if (bo->buf != VK_NULL_HANDLE)
vkDestroyBuffer(ctx->dev, bo->buf, 0);
bo->mobj.mem = VK_NULL_HANDLE;
}
+bool
+vk_create_fence(struct vk_ctx *ctx,
+ VkFence *fence)
+{
+ VkFenceCreateInfo finfo;
+
+ memset(&finfo, 0, sizeof finfo);
+ finfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
+ finfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
+
+ if (vkCreateFence(ctx->dev, &finfo, 0, fence) != VK_SUCCESS) {
+ fprintf(stderr, "Failed to create fence.\n");
+ fence = 0;
+ return false;
+ }
+
+ return true;
+}
+
VkCommandBuffer
vk_create_cmd_buffer(struct vk_ctx *ctx)
{
VkDeviceSize offsets[] = {0};
int num_vertices;
struct vk_dims img_size;
+ bool create_cmd_buf = false;
assert(vk_fb_color_count == 4);
fprintf(stderr, "Failed to create command buffer.\n");
return false;
}
+ create_cmd_buf = true;
}
/* VkCommandBufferBeginInfo */
#endif
vkEndCommandBuffer(cmd_buf);
+ if (create_cmd_buf) {
+ vk_destroy_cmd_buffers(ctx, 1, &cmd_buf);
+ }
return true;
}
if (vkQueueSubmit(ctx->queue, 1, &submit_info, VK_NULL_HANDLE) != VK_SUCCESS) {
fprintf(stderr, "Failed to submit queue.\n");
+ abort();
}
- vkQueueWaitIdle(ctx->queue);
+ if (vkQueueWaitIdle(ctx->queue) != VK_SUCCESS) {
+ fprintf(stderr, "Failed to wait idle.\n");
+ abort();
+ }
}
void
vkQueueWaitIdle(ctx->queue);
}
+void
+vk_set_viewport(struct vk_ctx *ctx,
+ VkCommandBuffer cmd_buf,
+ float x, float y,
+ float w, float h,
+ float near, float far)
+{
+ VkCommandBufferBeginInfo binfo;
+ VkViewport viewport;
+
+ memset(&viewport, 0, sizeof viewport);
+ viewport.x = x;
+ viewport.y = y;
+ viewport.width = w;
+ viewport.height = h;
+ viewport.minDepth = near;
+ viewport.maxDepth = far;
+
+ memset(&binfo, 0, sizeof binfo);
+ binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
+ binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
+
+ vkBeginCommandBuffer(cmd_buf, &binfo);
+ vkCmdSetViewport(cmd_buf, 0, 1, &viewport);
+ vkEndCommandBuffer(cmd_buf);
+}
+
bool
vk_create_swapchain(struct vk_ctx *ctx,
int width, int height,
struct vk_swapchain *swapchain)
{
vkDestroySwapchainKHR(ctx->dev, swapchain->swapchain, 0);
- swapchain = 0;
}
bool
-vk_present_queue(struct vk_swapchain *swapchain,
+vk_queue_present(struct vk_swapchain *swapchain,
VkQueue queue,
uint32_t image_idx,
VkSemaphore wait_sema)
memset(&pinfo, 0, sizeof pinfo);
pinfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
pinfo.swapchainCount = 1;
+ pinfo.pSwapchains = &swapchain->swapchain;
pinfo.pImageIndices = &image_idx;
- if (wait_sema != VK_NULL_HANDLE) {
- pinfo.pWaitSemaphores = &wait_sema;
- pinfo.waitSemaphoreCount = 1;
- }
+ pinfo.pWaitSemaphores = &wait_sema;
+ pinfo.waitSemaphoreCount = 1;
if (vkQueuePresentKHR(queue, &pinfo) != VK_SUCCESS) {
fprintf(stderr, "Failed to present queue.\n");