From 89d48b56507fa3546b06a131e0daaf2266c6f4b4 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 18 Feb 2020 01:03:36 +0900 Subject: [PATCH] Output first pixels Just clearing the screen to 0xbada55, but the validation layer is quiet. --- include/QF/Vulkan/funclist.h | 1 + libs/video/renderer/vid_render_vulkan.c | 47 +++++++++++++++++++++++++ libs/video/renderer/vulkan/swapchain.c | 1 + 3 files changed, 49 insertions(+) diff --git a/include/QF/Vulkan/funclist.h b/include/QF/Vulkan/funclist.h index 426b0fa62..8ab62852a 100644 --- a/include/QF/Vulkan/funclist.h +++ b/include/QF/Vulkan/funclist.h @@ -165,6 +165,7 @@ DEVICE_LEVEL_VULKAN_FUNCTION (vkCmdBeginRenderPass) DEVICE_LEVEL_VULKAN_FUNCTION (vkCmdNextSubpass) DEVICE_LEVEL_VULKAN_FUNCTION (vkCmdEndRenderPass) DEVICE_LEVEL_VULKAN_FUNCTION (vkCmdBindPipeline) +DEVICE_LEVEL_VULKAN_FUNCTION (vkCmdClearColorImage) #undef DEVICE_LEVEL_VULKAN_FUNCTION diff --git a/libs/video/renderer/vid_render_vulkan.c b/libs/video/renderer/vid_render_vulkan.c index 0373867de..fec8afa24 100644 --- a/libs/video/renderer/vid_render_vulkan.c +++ b/libs/video/renderer/vid_render_vulkan.c @@ -68,8 +68,55 @@ vulkan_R_Init (void) vulkan_ctx->frameset.cmdBuffers = cmdBuffers; VkCommandBufferBeginInfo beginInfo = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO }; + VkClearColorValue clearColor = { {0.7294, 0.8549, 0.3333, 1.0} }; + VkImageSubresourceRange image_subresource_range = { + VK_IMAGE_ASPECT_COLOR_BIT, + 0, 1, 0, 1, + }; + VkImageMemoryBarrier pc_barrier = { + VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, 0, + VK_ACCESS_TRANSFER_WRITE_BIT, + VK_ACCESS_MEMORY_READ_BIT, + VK_IMAGE_LAYOUT_UNDEFINED, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + device->queue.queueFamily, + device->queue.queueFamily, + 0, // filled in later + image_subresource_range + }; + VkImageMemoryBarrier cp_barrier = { + VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, 0, + VK_ACCESS_TRANSFER_WRITE_BIT, + VK_ACCESS_MEMORY_READ_BIT, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, + device->queue.queueFamily, + device->queue.queueFamily, + 0, // filled in later + image_subresource_range + }; for (size_t i = 0; i < cmdBuffers->size; i++) { + pc_barrier.image = vulkan_ctx->swapchain->images->a[i]; + cp_barrier.image = vulkan_ctx->swapchain->images->a[i]; dfunc->vkBeginCommandBuffer (cmdBuffers->a[i], &beginInfo); + dfunc->vkCmdPipelineBarrier (cmdBuffers->a[i], + VK_PIPELINE_STAGE_TRANSFER_BIT, + VK_PIPELINE_STAGE_TRANSFER_BIT, + 0, + 0, 0, // memory barriers + 0, 0, // buffer barriers + 1, &pc_barrier); + dfunc->vkCmdClearColorImage (cmdBuffers->a[i], pc_barrier.image, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, + &clearColor, 1, + &image_subresource_range); + dfunc->vkCmdPipelineBarrier (cmdBuffers->a[i], + VK_PIPELINE_STAGE_TRANSFER_BIT, + VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, + 0, + 0, 0, + 0, 0, + 1, &cp_barrier); dfunc->vkEndCommandBuffer (cmdBuffers->a[i]); } Sys_Printf ("R_Init %p %d", vulkan_ctx->swapchain->swapchain, diff --git a/libs/video/renderer/vulkan/swapchain.c b/libs/video/renderer/vulkan/swapchain.c index 4ea0a36dc..b2007953a 100644 --- a/libs/video/renderer/vulkan/swapchain.c +++ b/libs/video/renderer/vulkan/swapchain.c @@ -83,6 +83,7 @@ QFV_CreateSwapchain (vulkan_ctx_t *ctx, VkSwapchainKHR old_swapchain) imageSize.width, imageSize.height); VkImageUsageFlags imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + imageUsage |= VK_IMAGE_USAGE_TRANSFER_DST_BIT; imageUsage &= surfCaps.supportedUsageFlags; VkSurfaceTransformFlagBitsKHR surfTransform