Render views using quads with barrel distortion (instead of directly blitting result to swapchain)
This commit is contained in:
parent
671cebdc63
commit
a122c2380a
5 changed files with 394 additions and 328 deletions
20
data/shaders/multiview/viewdisplay.frag
Normal file
20
data/shaders/multiview/viewdisplay.frag
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
layout (binding = 1) uniform sampler2DArray samplerView;
|
||||||
|
|
||||||
|
layout (location = 0) in vec2 inUV;
|
||||||
|
layout (location = 0) out vec4 outColor;
|
||||||
|
|
||||||
|
layout (constant_id = 0) const float VIEW_LAYER = 0.0f;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
const float alpha = 0.2;
|
||||||
|
|
||||||
|
vec2 p1 = vec2(2.0 * inUV - 1.0);
|
||||||
|
vec2 p2 = p1 / (1.0 - alpha * length(p1));
|
||||||
|
p2 = (p2 + 1.0) * 0.5;
|
||||||
|
|
||||||
|
bool inside = ((p2.x >= 0.0) && (p2.x <= 1.0) && (p2.y >= 0.0 ) && (p2.y <= 1.0));
|
||||||
|
outColor = inside ? texture(samplerView, vec3(p2, VIEW_LAYER)) : vec4(0.0);
|
||||||
|
}
|
||||||
BIN
data/shaders/multiview/viewdisplay.frag.spv
Normal file
BIN
data/shaders/multiview/viewdisplay.frag.spv
Normal file
Binary file not shown.
14
data/shaders/multiview/viewdisplay.vert
Normal file
14
data/shaders/multiview/viewdisplay.vert
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
layout (location = 0) out vec2 outUV;
|
||||||
|
|
||||||
|
out gl_PerVertex
|
||||||
|
{
|
||||||
|
vec4 gl_Position;
|
||||||
|
};
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
|
||||||
|
gl_Position = vec4(outUV * 2.0f - 1.0f, 0.0f, 1.0f);
|
||||||
|
}
|
||||||
BIN
data/shaders/multiview/viewdisplay.vert.spv
Normal file
BIN
data/shaders/multiview/viewdisplay.vert.spv
Normal file
Binary file not shown.
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Vulkan Example - Multiview (VK_KHR_multiview)
|
* Vulkan Example - Multiview (VK_KHR_multiview)
|
||||||
*
|
*
|
||||||
* VK_KHR_multiview allows rendering to multiple views of a single renderpass
|
* Uses VK_KHR_multiview for simultaneously rendering to multiple views and displays these with barrel distortion using a fragment shader
|
||||||
*
|
*
|
||||||
* Copyright (C) 2018 by Sascha Willems - www.saschawillems.de
|
* Copyright (C) 2018 by Sascha Willems - www.saschawillems.de
|
||||||
*
|
*
|
||||||
|
|
@ -35,11 +35,20 @@ public:
|
||||||
vks::VERTEX_COMPONENT_COLOR,
|
vks::VERTEX_COMPONENT_COLOR,
|
||||||
});
|
});
|
||||||
|
|
||||||
struct ColorAttachment {
|
struct MultiviewPass {
|
||||||
|
struct FrameBufferAttachment {
|
||||||
VkImage image;
|
VkImage image;
|
||||||
VkImageView view;
|
|
||||||
VkDeviceMemory memory;
|
VkDeviceMemory memory;
|
||||||
} colorAttachment;
|
VkImageView view;
|
||||||
|
} color, depth;
|
||||||
|
VkFramebuffer frameBuffer;
|
||||||
|
VkRenderPass renderPass;
|
||||||
|
VkDescriptorImageInfo descriptor;
|
||||||
|
VkSampler sampler;
|
||||||
|
VkSemaphore semaphore;
|
||||||
|
std::vector<VkCommandBuffer> commandBuffers;
|
||||||
|
std::vector<VkFence> waitFences;
|
||||||
|
} multiviewPass;
|
||||||
|
|
||||||
vks::Model scene;
|
vks::Model scene;
|
||||||
|
|
||||||
|
|
@ -56,10 +65,7 @@ public:
|
||||||
VkDescriptorSet descriptorSet;
|
VkDescriptorSet descriptorSet;
|
||||||
VkDescriptorSetLayout descriptorSetLayout;
|
VkDescriptorSetLayout descriptorSetLayout;
|
||||||
|
|
||||||
// Semaphore used to synchronize blit to swapchain
|
VkPipeline viewDisplayPipelines[2];
|
||||||
VkSemaphore blitCompleteSemaphore;
|
|
||||||
std::vector<VkCommandBuffer> blitCommandBuffers;
|
|
||||||
std::vector<VkFence> blitWaitFences;
|
|
||||||
|
|
||||||
// Camera and view properties
|
// Camera and view properties
|
||||||
float eyeSeparation = 0.08f;
|
float eyeSeparation = 0.08f;
|
||||||
|
|
@ -70,14 +76,17 @@ public:
|
||||||
|
|
||||||
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
|
||||||
{
|
{
|
||||||
title = "Multiview";
|
title = "Multiview rendering";
|
||||||
camera.type = Camera::CameraType::firstperson;
|
camera.type = Camera::CameraType::firstperson;
|
||||||
camera.setRotation(glm::vec3(0.0f, 90.0f, 0.0f));
|
camera.setRotation(glm::vec3(0.0f, 90.0f, 0.0f));
|
||||||
camera.setTranslation(glm::vec3(7.0f, 3.2f, 0.0f));
|
camera.setTranslation(glm::vec3(7.0f, 3.2f, 0.0f));
|
||||||
camera.movementSpeed = 5.0f;
|
camera.movementSpeed = 5.0f;
|
||||||
settings.overlay = false;
|
settings.overlay = true;
|
||||||
|
|
||||||
|
// Enable extension required for multiview
|
||||||
enabledDeviceExtensions.push_back(VK_KHR_MULTIVIEW_EXTENSION_NAME);
|
enabledDeviceExtensions.push_back(VK_KHR_MULTIVIEW_EXTENSION_NAME);
|
||||||
|
|
||||||
|
// Reading device properties and features for multiview requires VK_KHR_get_physical_device_properties2 to be enabled
|
||||||
enabledInstanceExtensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
|
enabledInstanceExtensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,44 +97,65 @@ public:
|
||||||
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
|
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
|
||||||
vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr);
|
vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr);
|
||||||
|
|
||||||
vkDestroyImageView(device, colorAttachment.view, nullptr);
|
// Multiview pass
|
||||||
vkDestroyImage(device, colorAttachment.image, nullptr);
|
|
||||||
vkFreeMemory(device, colorAttachment.memory, nullptr);
|
|
||||||
|
|
||||||
vkDestroySemaphore(device, blitCompleteSemaphore, nullptr);
|
vkDestroyImageView(device, multiviewPass.color.view, nullptr);
|
||||||
for (auto& fence : blitWaitFences) {
|
vkDestroyImage(device, multiviewPass.color.image, nullptr);
|
||||||
|
vkFreeMemory(device, multiviewPass.color.memory, nullptr);
|
||||||
|
vkDestroyImageView(device, multiviewPass.depth.view, nullptr);
|
||||||
|
vkDestroyImage(device, multiviewPass.depth.image, nullptr);
|
||||||
|
vkFreeMemory(device, multiviewPass.depth.memory, nullptr);
|
||||||
|
|
||||||
|
vkDestroyRenderPass(device, multiviewPass.renderPass, nullptr);
|
||||||
|
vkDestroySampler(device, multiviewPass.sampler, nullptr);
|
||||||
|
vkDestroyFramebuffer(device, multiviewPass.frameBuffer, nullptr);
|
||||||
|
|
||||||
|
vkDestroySemaphore(device, multiviewPass.semaphore, nullptr);
|
||||||
|
for (auto& fence : multiviewPass.waitFences) {
|
||||||
vkDestroyFence(device, fence, nullptr);
|
vkDestroyFence(device, fence, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto& pipeline : viewDisplayPipelines) {
|
||||||
|
vkDestroyPipeline(device, pipeline, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
scene.destroy();
|
scene.destroy();
|
||||||
|
|
||||||
uniformBuffer.destroy();
|
uniformBuffer.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Custom depth/stencil setup
|
Prepares all resources required for the multiview attachment
|
||||||
Creates a depth/stencil framebuffer with multiple layers rendered to in a single pass
|
Images, views, attachments, renderpass, framebuffer, etc.
|
||||||
*/
|
*/
|
||||||
void setupDepthStencil()
|
void prepareMultiview()
|
||||||
{
|
{
|
||||||
VkImageCreateInfo image = {};
|
// Example renders to two views (left/right)
|
||||||
image.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
const uint32_t multiviewLayerCount = 2;
|
||||||
image.pNext = NULL;
|
|
||||||
image.imageType = VK_IMAGE_TYPE_2D;
|
|
||||||
image.format = depthFormat;
|
|
||||||
image.extent = { width, height, 1 };
|
|
||||||
image.mipLevels = 1;
|
|
||||||
image.arrayLayers = 2; // Two layers for two viewports
|
|
||||||
image.samples = VK_SAMPLE_COUNT_1_BIT;
|
|
||||||
image.tiling = VK_IMAGE_TILING_OPTIMAL;
|
|
||||||
image.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
|
|
||||||
image.flags = 0;
|
|
||||||
|
|
||||||
VkMemoryAllocateInfo mem_alloc = {};
|
/*
|
||||||
mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
Layered depth/stencil framebuffer
|
||||||
mem_alloc.pNext = NULL;
|
*/
|
||||||
mem_alloc.allocationSize = 0;
|
{
|
||||||
mem_alloc.memoryTypeIndex = 0;
|
VkImageCreateInfo imageCI= vks::initializers::imageCreateInfo();
|
||||||
|
imageCI.imageType = VK_IMAGE_TYPE_2D;
|
||||||
|
imageCI.format = depthFormat;
|
||||||
|
imageCI.extent = { width, height, 1 };
|
||||||
|
imageCI.mipLevels = 1;
|
||||||
|
imageCI.arrayLayers = multiviewLayerCount;
|
||||||
|
imageCI.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
imageCI.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||||
|
imageCI.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
|
||||||
|
imageCI.flags = 0;
|
||||||
|
VK_CHECK_RESULT(vkCreateImage(device, &imageCI, nullptr, &multiviewPass.depth.image));
|
||||||
|
|
||||||
|
VkMemoryRequirements memReqs;
|
||||||
|
vkGetImageMemoryRequirements(device, multiviewPass.depth.image, &memReqs);
|
||||||
|
|
||||||
|
VkMemoryAllocateInfo memAllocInfo{};
|
||||||
|
memAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
||||||
|
memAllocInfo.allocationSize = 0;
|
||||||
|
memAllocInfo.memoryTypeIndex = 0;
|
||||||
|
|
||||||
VkImageViewCreateInfo depthStencilView = {};
|
VkImageViewCreateInfo depthStencilView = {};
|
||||||
depthStencilView.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
depthStencilView.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
||||||
|
|
@ -138,25 +168,77 @@ public:
|
||||||
depthStencilView.subresourceRange.baseMipLevel = 0;
|
depthStencilView.subresourceRange.baseMipLevel = 0;
|
||||||
depthStencilView.subresourceRange.levelCount = 1;
|
depthStencilView.subresourceRange.levelCount = 1;
|
||||||
depthStencilView.subresourceRange.baseArrayLayer = 0;
|
depthStencilView.subresourceRange.baseArrayLayer = 0;
|
||||||
depthStencilView.subresourceRange.layerCount = 1;
|
depthStencilView.subresourceRange.layerCount = multiviewLayerCount;
|
||||||
|
depthStencilView.image = multiviewPass.depth.image;
|
||||||
|
|
||||||
VkMemoryRequirements memReqs;
|
memAllocInfo.allocationSize = memReqs.size;
|
||||||
|
memAllocInfo.memoryTypeIndex = vulkanDevice->getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
||||||
VK_CHECK_RESULT(vkCreateImage(device, &image, nullptr, &depthStencil.image));
|
VK_CHECK_RESULT(vkAllocateMemory(device, &memAllocInfo, nullptr, &multiviewPass.depth.memory));
|
||||||
vkGetImageMemoryRequirements(device, depthStencil.image, &memReqs);
|
VK_CHECK_RESULT(vkBindImageMemory(device, multiviewPass.depth.image, multiviewPass.depth.memory, 0));
|
||||||
mem_alloc.allocationSize = memReqs.size;
|
VK_CHECK_RESULT(vkCreateImageView(device, &depthStencilView, nullptr, &multiviewPass.depth.view));
|
||||||
mem_alloc.memoryTypeIndex = vulkanDevice->getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
|
||||||
VK_CHECK_RESULT(vkAllocateMemory(device, &mem_alloc, nullptr, &depthStencil.mem));
|
|
||||||
VK_CHECK_RESULT(vkBindImageMemory(device, depthStencil.image, depthStencil.mem, 0));
|
|
||||||
|
|
||||||
depthStencilView.image = depthStencil.image;
|
|
||||||
VK_CHECK_RESULT(vkCreateImageView(device, &depthStencilView, nullptr, &depthStencil.view));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Custom renderpass setup
|
Layered color attachment
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
VkImageCreateInfo imageCI = vks::initializers::imageCreateInfo();
|
||||||
|
imageCI.imageType = VK_IMAGE_TYPE_2D;
|
||||||
|
imageCI.format = swapChain.colorFormat;
|
||||||
|
imageCI.extent = { width, height, 1 };
|
||||||
|
imageCI.mipLevels = 1;
|
||||||
|
imageCI.arrayLayers = multiviewLayerCount;
|
||||||
|
imageCI.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||||
|
imageCI.tiling = VK_IMAGE_TILING_OPTIMAL;
|
||||||
|
imageCI.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
|
||||||
|
VK_CHECK_RESULT(vkCreateImage(device, &imageCI, nullptr, &multiviewPass.color.image));
|
||||||
|
|
||||||
|
VkMemoryRequirements memReqs;
|
||||||
|
vkGetImageMemoryRequirements(device, multiviewPass.color.image, &memReqs);
|
||||||
|
|
||||||
|
VkMemoryAllocateInfo memoryAllocInfo = vks::initializers::memoryAllocateInfo();
|
||||||
|
memoryAllocInfo.allocationSize = memReqs.size;
|
||||||
|
memoryAllocInfo.memoryTypeIndex = vulkanDevice->getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
||||||
|
VK_CHECK_RESULT(vkAllocateMemory(device, &memoryAllocInfo, nullptr, &multiviewPass.color.memory));
|
||||||
|
VK_CHECK_RESULT(vkBindImageMemory(device, multiviewPass.color.image, multiviewPass.color.memory, 0));
|
||||||
|
|
||||||
|
VkImageViewCreateInfo imageViewCI = vks::initializers::imageViewCreateInfo();
|
||||||
|
imageViewCI.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
|
||||||
|
imageViewCI.format = swapChain.colorFormat;
|
||||||
|
imageViewCI.flags = 0;
|
||||||
|
imageViewCI.subresourceRange = {};
|
||||||
|
imageViewCI.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
|
imageViewCI.subresourceRange.baseMipLevel = 0;
|
||||||
|
imageViewCI.subresourceRange.levelCount = 1;
|
||||||
|
imageViewCI.subresourceRange.baseArrayLayer = 0;
|
||||||
|
imageViewCI.subresourceRange.layerCount = multiviewLayerCount;
|
||||||
|
imageViewCI.image = multiviewPass.color.image;
|
||||||
|
VK_CHECK_RESULT(vkCreateImageView(device, &imageViewCI, nullptr, &multiviewPass.color.view));
|
||||||
|
|
||||||
|
// Create sampler to sample from the attachment in the fragment shader
|
||||||
|
VkSamplerCreateInfo samplerCI = vks::initializers::samplerCreateInfo();
|
||||||
|
samplerCI.magFilter = VK_FILTER_NEAREST;
|
||||||
|
samplerCI.minFilter = VK_FILTER_NEAREST;
|
||||||
|
samplerCI.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
|
||||||
|
samplerCI.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
||||||
|
samplerCI.addressModeV = samplerCI.addressModeU;
|
||||||
|
samplerCI.addressModeW = samplerCI.addressModeU;
|
||||||
|
samplerCI.mipLodBias = 0.0f;
|
||||||
|
samplerCI.maxAnisotropy = 1.0f;
|
||||||
|
samplerCI.minLod = 0.0f;
|
||||||
|
samplerCI.maxLod = 1.0f;
|
||||||
|
samplerCI.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
|
||||||
|
VK_CHECK_RESULT(vkCreateSampler(device, &samplerCI, nullptr, &multiviewPass.sampler));
|
||||||
|
|
||||||
|
// Fill a descriptor for later use in a descriptor set
|
||||||
|
multiviewPass.descriptor.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||||
|
multiviewPass.descriptor.imageView = multiviewPass.color.view;
|
||||||
|
multiviewPass.descriptor.sampler = multiviewPass.sampler;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Renderpass
|
||||||
*/
|
*/
|
||||||
void setupRenderPass()
|
|
||||||
{
|
{
|
||||||
std::array<VkAttachmentDescription, 2> attachments = {};
|
std::array<VkAttachmentDescription, 2> attachments = {};
|
||||||
// Color attachment
|
// Color attachment
|
||||||
|
|
@ -191,11 +273,6 @@ public:
|
||||||
subpassDescription.colorAttachmentCount = 1;
|
subpassDescription.colorAttachmentCount = 1;
|
||||||
subpassDescription.pColorAttachments = &colorReference;
|
subpassDescription.pColorAttachments = &colorReference;
|
||||||
subpassDescription.pDepthStencilAttachment = &depthReference;
|
subpassDescription.pDepthStencilAttachment = &depthReference;
|
||||||
subpassDescription.inputAttachmentCount = 0;
|
|
||||||
subpassDescription.pInputAttachments = nullptr;
|
|
||||||
subpassDescription.preserveAttachmentCount = 0;
|
|
||||||
subpassDescription.pPreserveAttachments = nullptr;
|
|
||||||
subpassDescription.pResolveAttachments = nullptr;
|
|
||||||
|
|
||||||
// Subpass dependencies for layout transitions
|
// Subpass dependencies for layout transitions
|
||||||
std::array<VkSubpassDependency, 2> dependencies;
|
std::array<VkSubpassDependency, 2> dependencies;
|
||||||
|
|
@ -250,90 +327,34 @@ public:
|
||||||
|
|
||||||
renderPassCI.pNext = &renderPassMultiviewCI;
|
renderPassCI.pNext = &renderPassMultiviewCI;
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkCreateRenderPass(device, &renderPassCI, nullptr, &renderPass));
|
VK_CHECK_RESULT(vkCreateRenderPass(device, &renderPassCI, nullptr, &multiviewPass.renderPass));
|
||||||
|
|
||||||
// The custom render pass does not include the swapchain images, so we need to do an initial layout transition
|
|
||||||
|
|
||||||
VkCommandBuffer layoutCmd = vulkanDevice->createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
|
|
||||||
VkImageSubresourceRange subresourceRange { VK_IMAGE_ASPECT_COLOR_BIT, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_MIP_LEVELS };
|
|
||||||
for (uint32_t i = 0; i < swapChain.imageCount; i++) {
|
|
||||||
vks::tools::setImageLayout(
|
|
||||||
layoutCmd,
|
|
||||||
swapChain.images[i],
|
|
||||||
VK_IMAGE_LAYOUT_UNDEFINED,
|
|
||||||
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
|
|
||||||
subresourceRange);
|
|
||||||
}
|
|
||||||
vulkanDevice->flushCommandBuffer(layoutCmd, queue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Custom framebuffer setup
|
Framebuffer
|
||||||
Creates a color framebuffer with multiple layers rendered to in a single pass
|
|
||||||
*/
|
*/
|
||||||
void setupFrameBuffer()
|
|
||||||
{
|
{
|
||||||
VkImageCreateInfo imageCI = vks::initializers::imageCreateInfo();
|
VkImageView attachments[2];
|
||||||
imageCI.imageType = VK_IMAGE_TYPE_2D;
|
attachments[0] = multiviewPass.color.view;
|
||||||
imageCI.format = swapChain.colorFormat;
|
attachments[1] = multiviewPass.depth.view;
|
||||||
imageCI.extent = { width, height, 1 };
|
|
||||||
imageCI.mipLevels = 1;
|
|
||||||
// Two layers for two views
|
|
||||||
imageCI.arrayLayers = 2;
|
|
||||||
imageCI.samples = VK_SAMPLE_COUNT_1_BIT;
|
|
||||||
imageCI.tiling = VK_IMAGE_TILING_OPTIMAL;
|
|
||||||
imageCI.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
|
|
||||||
|
|
||||||
VkMemoryRequirements memReqs;
|
VkFramebufferCreateInfo framebufferCI = vks::initializers::framebufferCreateInfo();
|
||||||
VK_CHECK_RESULT(vkCreateImage(device, &imageCI, nullptr, &colorAttachment.image));
|
framebufferCI.renderPass = multiviewPass.renderPass;
|
||||||
vkGetImageMemoryRequirements(device, colorAttachment.image, &memReqs);
|
framebufferCI.attachmentCount = 2;
|
||||||
|
framebufferCI.pAttachments = attachments;
|
||||||
VkMemoryAllocateInfo memoryAllocInfo = vks::initializers::memoryAllocateInfo();
|
framebufferCI.width = width;
|
||||||
memoryAllocInfo.allocationSize = memReqs.size;
|
framebufferCI.height = height;
|
||||||
memoryAllocInfo.memoryTypeIndex = vulkanDevice->getMemoryType(memReqs.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
framebufferCI.layers = 1;
|
||||||
VK_CHECK_RESULT(vkAllocateMemory(device, &memoryAllocInfo, nullptr, &colorAttachment.memory));
|
VK_CHECK_RESULT(vkCreateFramebuffer(device, &framebufferCI, nullptr, &multiviewPass.frameBuffer));
|
||||||
VK_CHECK_RESULT(vkBindImageMemory(device, colorAttachment.image, colorAttachment.memory, 0));
|
|
||||||
|
|
||||||
VkImageViewCreateInfo imageViewCI = vks::initializers::imageViewCreateInfo();
|
|
||||||
imageViewCI.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
|
|
||||||
imageViewCI.format = swapChain.colorFormat;
|
|
||||||
imageViewCI.flags = 0;
|
|
||||||
imageViewCI.subresourceRange = {};
|
|
||||||
imageViewCI.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
|
||||||
imageViewCI.subresourceRange.baseMipLevel = 0;
|
|
||||||
imageViewCI.subresourceRange.levelCount = 1;
|
|
||||||
imageViewCI.subresourceRange.baseArrayLayer = 0;
|
|
||||||
// Two layers for two views
|
|
||||||
imageViewCI.subresourceRange.layerCount = 2;
|
|
||||||
imageViewCI.image = colorAttachment.image;
|
|
||||||
VK_CHECK_RESULT(vkCreateImageView(device, &imageViewCI, nullptr, &colorAttachment.view));
|
|
||||||
|
|
||||||
// Depth/Stencil attachment is the same for all frame buffers
|
|
||||||
std::vector<VkImageView> attachments = { colorAttachment.view, depthStencil.view };
|
|
||||||
|
|
||||||
VkFramebufferCreateInfo frameBufferCreateInfo = {};
|
|
||||||
frameBufferCreateInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
|
|
||||||
frameBufferCreateInfo.pNext = NULL;
|
|
||||||
frameBufferCreateInfo.renderPass = renderPass;
|
|
||||||
frameBufferCreateInfo.attachmentCount = 2;
|
|
||||||
frameBufferCreateInfo.pAttachments = attachments.data();
|
|
||||||
frameBufferCreateInfo.width = width;
|
|
||||||
frameBufferCreateInfo.height = height;
|
|
||||||
frameBufferCreateInfo.layers = 1;
|
|
||||||
|
|
||||||
// Create frame buffers for every swap chain image
|
|
||||||
frameBuffers.resize(swapChain.imageCount);
|
|
||||||
for (uint32_t i = 0; i < frameBuffers.size(); i++) {
|
|
||||||
VK_CHECK_RESULT(vkCreateFramebuffer(device, &frameBufferCreateInfo, nullptr, &frameBuffers[i]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void buildCommandBuffers()
|
void buildCommandBuffers()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Scene rendering
|
View display
|
||||||
*/
|
*/
|
||||||
|
{
|
||||||
VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo();
|
VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo();
|
||||||
|
|
||||||
VkClearValue clearValues[2];
|
VkClearValue clearValues[2];
|
||||||
|
|
@ -353,98 +374,79 @@ public:
|
||||||
renderPassBeginInfo.framebuffer = frameBuffers[i];
|
renderPassBeginInfo.framebuffer = frameBuffers[i];
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo));
|
VK_CHECK_RESULT(vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo));
|
||||||
|
|
||||||
vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
|
vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
|
||||||
|
VkViewport viewport = vks::initializers::viewport((float)width / 2.0f, (float)height, 0.0f, 1.0f);
|
||||||
VkViewport viewport = vks::initializers::viewport((float)width, (float)height, 0.0f, 1.0f);
|
VkRect2D scissor = vks::initializers::rect2D(width / 2, height, 0, 0);
|
||||||
vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport);
|
vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport);
|
||||||
|
|
||||||
VkRect2D scissor = vks::initializers::rect2D(width, height, 0, 0);
|
|
||||||
vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor);
|
vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor);
|
||||||
|
|
||||||
vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSet, 0, nullptr);
|
vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSet, 0, nullptr);
|
||||||
|
|
||||||
VkDeviceSize offsets[1] = { 0 };
|
// Left eye
|
||||||
vkCmdBindVertexBuffers(drawCmdBuffers[i], 0, 1, &scene.vertices.buffer, offsets);
|
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, viewDisplayPipelines[0]);
|
||||||
vkCmdBindIndexBuffer(drawCmdBuffers[i], scene.indices.buffer, 0, VK_INDEX_TYPE_UINT32);
|
vkCmdDraw(drawCmdBuffers[i], 3, 1, 0, 0);
|
||||||
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
|
|
||||||
vkCmdDrawIndexed(drawCmdBuffers[i], scene.indexCount, 1, 0, 0, 0);
|
// Right eye
|
||||||
|
viewport.x = (float)width / 2;
|
||||||
|
scissor.offset.x = width / 2;
|
||||||
|
vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport);
|
||||||
|
vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor);
|
||||||
|
|
||||||
|
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, viewDisplayPipelines[1]);
|
||||||
|
vkCmdDraw(drawCmdBuffers[i], 3, 1, 0, 0);
|
||||||
|
|
||||||
vkCmdEndRenderPass(drawCmdBuffers[i]);
|
vkCmdEndRenderPass(drawCmdBuffers[i]);
|
||||||
|
|
||||||
VkImageSubresourceRange subresourceRange{};
|
|
||||||
subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
|
||||||
subresourceRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
|
|
||||||
subresourceRange.levelCount = VK_REMAINING_MIP_LEVELS;
|
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkEndCommandBuffer(drawCmdBuffers[i]));
|
VK_CHECK_RESULT(vkEndCommandBuffer(drawCmdBuffers[i]));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Layered color attachment to swapchain blit
|
Multiview layered attachment scene rendering
|
||||||
*/
|
*/
|
||||||
blitCommandBuffers.resize(drawCmdBuffers.size());
|
|
||||||
|
multiviewPass.commandBuffers.resize(drawCmdBuffers.size());
|
||||||
|
|
||||||
VkCommandBufferAllocateInfo cmdBufAllocateInfo = vks::initializers::commandBufferAllocateInfo(cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, static_cast<uint32_t>(drawCmdBuffers.size()));
|
VkCommandBufferAllocateInfo cmdBufAllocateInfo = vks::initializers::commandBufferAllocateInfo(cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, static_cast<uint32_t>(drawCmdBuffers.size()));
|
||||||
VK_CHECK_RESULT(vkAllocateCommandBuffers(device, &cmdBufAllocateInfo, blitCommandBuffers.data()));
|
VK_CHECK_RESULT(vkAllocateCommandBuffers(device, &cmdBufAllocateInfo, multiviewPass.commandBuffers.data()));
|
||||||
|
|
||||||
for (int32_t i = 0; i < blitCommandBuffers.size(); ++i) {
|
{
|
||||||
VK_CHECK_RESULT(vkBeginCommandBuffer(blitCommandBuffers[i], &cmdBufInfo));
|
VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo();
|
||||||
|
|
||||||
VkImageSubresourceRange subresourceRange { VK_IMAGE_ASPECT_COLOR_BIT, 0, VK_REMAINING_MIP_LEVELS, 0, VK_REMAINING_MIP_LEVELS };
|
VkClearValue clearValues[2];
|
||||||
|
clearValues[0].color = defaultClearColor;
|
||||||
|
clearValues[1].depthStencil = { 1.0f, 0 };
|
||||||
|
|
||||||
vks::tools::setImageLayout(
|
VkRenderPassBeginInfo renderPassBeginInfo = vks::initializers::renderPassBeginInfo();
|
||||||
blitCommandBuffers[i],
|
renderPassBeginInfo.renderPass = multiviewPass.renderPass;
|
||||||
swapChain.images[i],
|
renderPassBeginInfo.renderArea.offset.x = 0;
|
||||||
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
|
renderPassBeginInfo.renderArea.offset.y = 0;
|
||||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
renderPassBeginInfo.renderArea.extent.width = width;
|
||||||
subresourceRange);
|
renderPassBeginInfo.renderArea.extent.height = height;
|
||||||
|
renderPassBeginInfo.clearValueCount = 2;
|
||||||
|
renderPassBeginInfo.pClearValues = clearValues;
|
||||||
|
|
||||||
VkImageBlit imageBlit{};
|
for (int32_t i = 0; i < multiviewPass.commandBuffers.size(); ++i) {
|
||||||
imageBlit.srcOffsets[0] = { 0, 0, 0 };
|
renderPassBeginInfo.framebuffer = multiviewPass.frameBuffer;
|
||||||
imageBlit.srcOffsets[1] = { static_cast<int32_t>(width), static_cast<int32_t>(height), 1 };
|
|
||||||
imageBlit.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
|
||||||
imageBlit.srcSubresource.layerCount = 1;
|
|
||||||
imageBlit.dstSubresource = imageBlit.srcSubresource;
|
|
||||||
|
|
||||||
// Blit first color attachment layer to the left of the swapchain image
|
VK_CHECK_RESULT(vkBeginCommandBuffer(multiviewPass.commandBuffers[i], &cmdBufInfo));
|
||||||
imageBlit.dstOffsets[0] = { 0, 0, 0 };
|
vkCmdBeginRenderPass(multiviewPass.commandBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
|
||||||
imageBlit.dstOffsets[1] = { static_cast<int32_t>(width) / 2, static_cast<int32_t>(height), 1 };
|
VkViewport viewport = vks::initializers::viewport((float)width, (float)height, 0.0f, 1.0f);
|
||||||
imageBlit.srcSubresource.baseArrayLayer = 0;
|
vkCmdSetViewport(multiviewPass.commandBuffers[i], 0, 1, &viewport);
|
||||||
vkCmdBlitImage(
|
VkRect2D scissor = vks::initializers::rect2D(width, height, 0, 0);
|
||||||
blitCommandBuffers[i],
|
vkCmdSetScissor(multiviewPass.commandBuffers[i], 0, 1, &scissor);
|
||||||
colorAttachment.image,
|
|
||||||
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
|
||||||
swapChain.images[i],
|
|
||||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
|
||||||
1,
|
|
||||||
&imageBlit,
|
|
||||||
VK_FILTER_NEAREST);
|
|
||||||
|
|
||||||
// Blit second color attachment layer to the left of the swapchain image
|
vkCmdBindDescriptorSets(multiviewPass.commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSet, 0, nullptr);
|
||||||
imageBlit.dstOffsets[0] = { static_cast<int32_t>(width) / 2, 0, 0 };
|
|
||||||
imageBlit.dstOffsets[1] = { static_cast<int32_t>(width), static_cast<int32_t>(height), 1 };
|
|
||||||
imageBlit.srcSubresource.baseArrayLayer = 1;
|
|
||||||
vkCmdBlitImage(
|
|
||||||
blitCommandBuffers[i],
|
|
||||||
colorAttachment.image,
|
|
||||||
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
|
|
||||||
swapChain.images[i],
|
|
||||||
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
|
|
||||||
1,
|
|
||||||
&imageBlit,
|
|
||||||
VK_FILTER_NEAREST);
|
|
||||||
|
|
||||||
vks::tools::setImageLayout(
|
VkDeviceSize offsets[1] = { 0 };
|
||||||
blitCommandBuffers[i],
|
vkCmdBindVertexBuffers(multiviewPass.commandBuffers[i], 0, 1, &scene.vertices.buffer, offsets);
|
||||||
swapChain.images[i],
|
vkCmdBindIndexBuffer(multiviewPass.commandBuffers[i], scene.indices.buffer, 0, VK_INDEX_TYPE_UINT32);
|
||||||
VK_IMAGE_LAYOUT_UNDEFINED,
|
vkCmdBindPipeline(multiviewPass.commandBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
|
||||||
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
|
vkCmdDrawIndexed(multiviewPass.commandBuffers[i], scene.indexCount, 1, 0, 0, 0);
|
||||||
subresourceRange);
|
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkEndCommandBuffer(blitCommandBuffers[i]));
|
vkCmdEndRenderPass(multiviewPass.commandBuffers[i]);
|
||||||
|
VK_CHECK_RESULT(vkEndCommandBuffer(multiviewPass.commandBuffers[i]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadAssets()
|
void loadAssets()
|
||||||
|
|
@ -484,6 +486,7 @@ public:
|
||||||
std::vector<VkWriteDescriptorSet> writeDescriptorSets = {
|
std::vector<VkWriteDescriptorSet> writeDescriptorSets = {
|
||||||
// Binding 0: Vertex shader UBO
|
// Binding 0: Vertex shader UBO
|
||||||
vks::initializers::writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBuffer.descriptor),
|
vks::initializers::writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBuffer.descriptor),
|
||||||
|
vks::initializers::writeDescriptorSet(descriptorSet, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, &multiviewPass.descriptor),
|
||||||
};
|
};
|
||||||
vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, nullptr);
|
vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, nullptr);
|
||||||
}
|
}
|
||||||
|
|
@ -492,7 +495,7 @@ public:
|
||||||
{
|
{
|
||||||
|
|
||||||
VkSemaphoreCreateInfo semaphoreCI = vks::initializers::semaphoreCreateInfo();
|
VkSemaphoreCreateInfo semaphoreCI = vks::initializers::semaphoreCreateInfo();
|
||||||
VK_CHECK_RESULT(vkCreateSemaphore(device, &semaphoreCI, nullptr, &blitCompleteSemaphore));
|
VK_CHECK_RESULT(vkCreateSemaphore(device, &semaphoreCI, nullptr, &multiviewPass.semaphore));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Display multi view features and properties
|
Display multi view features and properties
|
||||||
|
|
@ -571,8 +574,36 @@ public:
|
||||||
shaderStages[1] = loadShader(getAssetPath() + "shaders/multiview/multiview.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
shaderStages[1] = loadShader(getAssetPath() + "shaders/multiview/multiview.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||||
pipelineCI.stageCount = 2;
|
pipelineCI.stageCount = 2;
|
||||||
pipelineCI.pStages = shaderStages.data();
|
pipelineCI.pStages = shaderStages.data();
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipeline));
|
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &pipeline));
|
||||||
|
|
||||||
|
/*
|
||||||
|
Full screen pass
|
||||||
|
*/
|
||||||
|
|
||||||
|
float multiviewArrayLayer = 0.0f;
|
||||||
|
|
||||||
|
VkSpecializationMapEntry specializationMapEntry{ 0, 0, sizeof(float) };
|
||||||
|
|
||||||
|
VkSpecializationInfo specializationInfo{};
|
||||||
|
specializationInfo.dataSize = sizeof(float);
|
||||||
|
specializationInfo.mapEntryCount = 1;
|
||||||
|
specializationInfo.pMapEntries = &specializationMapEntry;
|
||||||
|
specializationInfo.pData = &multiviewArrayLayer;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Separate pipelines per eye (view) using specialization constants to set view array layer to sample from
|
||||||
|
*/
|
||||||
|
for (uint32_t i = 0; i < 2; i++) {
|
||||||
|
shaderStages[0] = loadShader(getAssetPath() + "shaders/multiview/viewdisplay.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
|
||||||
|
shaderStages[1] = loadShader(getAssetPath() + "shaders/multiview/viewdisplay.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||||
|
shaderStages[1].pSpecializationInfo = &specializationInfo;
|
||||||
|
multiviewArrayLayer = (float)i;
|
||||||
|
VkPipelineVertexInputStateCreateInfo emptyInputState = vks::initializers::pipelineVertexInputStateCreateInfo();
|
||||||
|
pipelineCI.pVertexInputState = &emptyInputState;
|
||||||
|
pipelineCI.layout = pipelineLayout;
|
||||||
|
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCI, nullptr, &viewDisplayPipelines[i]));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare and initialize uniform buffer containing shader uniforms
|
// Prepare and initialize uniform buffer containing shader uniforms
|
||||||
|
|
@ -639,39 +670,40 @@ public:
|
||||||
{
|
{
|
||||||
VulkanExampleBase::prepareFrame();
|
VulkanExampleBase::prepareFrame();
|
||||||
|
|
||||||
// Render
|
// Multiview offscreen render
|
||||||
|
VK_CHECK_RESULT(vkWaitForFences(device, 1, &multiviewPass.waitFences[currentBuffer], VK_TRUE, UINT64_MAX));
|
||||||
|
VK_CHECK_RESULT(vkResetFences(device, 1, &multiviewPass.waitFences[currentBuffer]));
|
||||||
|
submitInfo.pWaitSemaphores = &semaphores.presentComplete;
|
||||||
|
submitInfo.pSignalSemaphores = &multiviewPass.semaphore;
|
||||||
|
submitInfo.commandBufferCount = 1;
|
||||||
|
submitInfo.pCommandBuffers = &multiviewPass.commandBuffers[currentBuffer];
|
||||||
|
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, multiviewPass.waitFences[currentBuffer]));
|
||||||
|
|
||||||
|
// View display
|
||||||
VK_CHECK_RESULT(vkWaitForFences(device, 1, &waitFences[currentBuffer], VK_TRUE, UINT64_MAX));
|
VK_CHECK_RESULT(vkWaitForFences(device, 1, &waitFences[currentBuffer], VK_TRUE, UINT64_MAX));
|
||||||
VK_CHECK_RESULT(vkResetFences(device, 1, &waitFences[currentBuffer]));
|
VK_CHECK_RESULT(vkResetFences(device, 1, &waitFences[currentBuffer]));
|
||||||
submitInfo.pWaitSemaphores = &semaphores.presentComplete;
|
submitInfo.pWaitSemaphores = &multiviewPass.semaphore;
|
||||||
submitInfo.pSignalSemaphores = &semaphores.renderComplete;
|
submitInfo.pSignalSemaphores = &semaphores.renderComplete;
|
||||||
submitInfo.commandBufferCount = 1;
|
submitInfo.commandBufferCount = 1;
|
||||||
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
|
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
|
||||||
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, waitFences[currentBuffer]));
|
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, waitFences[currentBuffer]));
|
||||||
|
|
||||||
// Blit
|
VulkanExampleBase::submitFrame();
|
||||||
VK_CHECK_RESULT(vkWaitForFences(device, 1, &blitWaitFences[currentBuffer], VK_TRUE, UINT64_MAX));
|
|
||||||
VK_CHECK_RESULT(vkResetFences(device, 1, &blitWaitFences[currentBuffer]));
|
|
||||||
submitInfo.pWaitSemaphores = &semaphores.renderComplete;
|
|
||||||
submitInfo.pSignalSemaphores = &blitCompleteSemaphore;
|
|
||||||
submitInfo.commandBufferCount = 1;
|
|
||||||
submitInfo.pCommandBuffers = &blitCommandBuffers[currentBuffer];
|
|
||||||
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, blitWaitFences[currentBuffer]));
|
|
||||||
|
|
||||||
VK_CHECK_RESULT(swapChain.queuePresent(queue, currentBuffer, blitCompleteSemaphore));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void prepare()
|
void prepare()
|
||||||
{
|
{
|
||||||
VulkanExampleBase::prepare();
|
VulkanExampleBase::prepare();
|
||||||
loadAssets();
|
loadAssets();
|
||||||
|
prepareMultiview();
|
||||||
prepareUniformBuffers();
|
prepareUniformBuffers();
|
||||||
prepareDescriptors();
|
prepareDescriptors();
|
||||||
preparePipelines();
|
preparePipelines();
|
||||||
buildCommandBuffers();
|
buildCommandBuffers();
|
||||||
|
|
||||||
VkFenceCreateInfo fenceCreateInfo = vks::initializers::fenceCreateInfo(VK_FENCE_CREATE_SIGNALED_BIT);
|
VkFenceCreateInfo fenceCreateInfo = vks::initializers::fenceCreateInfo(VK_FENCE_CREATE_SIGNALED_BIT);
|
||||||
blitWaitFences.resize(blitCommandBuffers.size());
|
multiviewPass.waitFences.resize(multiviewPass.commandBuffers.size());
|
||||||
for (auto& fence : blitWaitFences) {
|
for (auto& fence : multiviewPass.waitFences) {
|
||||||
VK_CHECK_RESULT(vkCreateFence(device, &fenceCreateInfo, nullptr, &fence));
|
VK_CHECK_RESULT(vkCreateFence(device, &fenceCreateInfo, nullptr, &fence));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue