Removed layout transitions and transition cmd buffers, replaced by subpass dependencies of framebuffer class (Refs #155)
This commit is contained in:
parent
dae07726dc
commit
5d258ce249
1 changed files with 9 additions and 66 deletions
|
|
@ -245,8 +245,6 @@ public:
|
||||||
// light sources' point of view to the layers of the depth attachment in one single pass
|
// light sources' point of view to the layers of the depth attachment in one single pass
|
||||||
void shadowSetup()
|
void shadowSetup()
|
||||||
{
|
{
|
||||||
VkCommandBuffer layoutCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
|
|
||||||
|
|
||||||
frameBuffers.shadow = new vk::Framebuffer(vulkanDevice);
|
frameBuffers.shadow = new vk::Framebuffer(vulkanDevice);
|
||||||
|
|
||||||
frameBuffers.shadow->width = SHADOWMAP_DIM;
|
frameBuffers.shadow->width = SHADOWMAP_DIM;
|
||||||
|
|
@ -262,9 +260,7 @@ public:
|
||||||
framebufferInfo.height = SHADOWMAP_DIM;
|
framebufferInfo.height = SHADOWMAP_DIM;
|
||||||
framebufferInfo.layerCount = LIGHT_COUNT;
|
framebufferInfo.layerCount = LIGHT_COUNT;
|
||||||
framebufferInfo.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
|
framebufferInfo.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
|
||||||
frameBuffers.shadow->addAttachment(framebufferInfo, layoutCmd);
|
frameBuffers.shadow->addAttachment(framebufferInfo);
|
||||||
|
|
||||||
VulkanExampleBase::flushCommandBuffer(layoutCmd, queue, true);
|
|
||||||
|
|
||||||
// Create sampler to sample from to depth attachment
|
// Create sampler to sample from to depth attachment
|
||||||
// Used to sample in the fragment shader for shadowed rendering
|
// Used to sample in the fragment shader for shadowed rendering
|
||||||
|
|
@ -277,8 +273,6 @@ public:
|
||||||
// Prepare the framebuffer for offscreen rendering with multiple attachments used as render targets inside the fragment shaders
|
// Prepare the framebuffer for offscreen rendering with multiple attachments used as render targets inside the fragment shaders
|
||||||
void deferredSetup()
|
void deferredSetup()
|
||||||
{
|
{
|
||||||
VkCommandBuffer layoutCmd = VulkanExampleBase::createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true);
|
|
||||||
|
|
||||||
frameBuffers.deferred = new vk::Framebuffer(vulkanDevice);
|
frameBuffers.deferred = new vk::Framebuffer(vulkanDevice);
|
||||||
|
|
||||||
frameBuffers.deferred->width = FB_DIM;
|
frameBuffers.deferred->width = FB_DIM;
|
||||||
|
|
@ -294,15 +288,15 @@ public:
|
||||||
// Color attachments
|
// Color attachments
|
||||||
// Attachment 0: (World space) Positions
|
// Attachment 0: (World space) Positions
|
||||||
framebufferInfo.format = VK_FORMAT_R16G16B16A16_SFLOAT;
|
framebufferInfo.format = VK_FORMAT_R16G16B16A16_SFLOAT;
|
||||||
frameBuffers.deferred->addAttachment(framebufferInfo, layoutCmd);
|
frameBuffers.deferred->addAttachment(framebufferInfo);
|
||||||
|
|
||||||
// Attachment 1: (World space) Normals
|
// Attachment 1: (World space) Normals
|
||||||
framebufferInfo.format = VK_FORMAT_R16G16B16A16_SFLOAT;
|
framebufferInfo.format = VK_FORMAT_R16G16B16A16_SFLOAT;
|
||||||
frameBuffers.deferred->addAttachment(framebufferInfo, layoutCmd);
|
frameBuffers.deferred->addAttachment(framebufferInfo);
|
||||||
|
|
||||||
// Attachment 2: Albedo (color)
|
// Attachment 2: Albedo (color)
|
||||||
framebufferInfo.format = VK_FORMAT_R8G8B8A8_UNORM;
|
framebufferInfo.format = VK_FORMAT_R8G8B8A8_UNORM;
|
||||||
frameBuffers.deferred->addAttachment(framebufferInfo, layoutCmd);
|
frameBuffers.deferred->addAttachment(framebufferInfo);
|
||||||
|
|
||||||
// Depth attachment
|
// Depth attachment
|
||||||
// Find a suitable depth format
|
// Find a suitable depth format
|
||||||
|
|
@ -312,9 +306,7 @@ public:
|
||||||
|
|
||||||
framebufferInfo.format = attDepthFormat;
|
framebufferInfo.format = attDepthFormat;
|
||||||
framebufferInfo.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
framebufferInfo.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
||||||
frameBuffers.deferred->addAttachment(framebufferInfo, layoutCmd);
|
frameBuffers.deferred->addAttachment(framebufferInfo);
|
||||||
|
|
||||||
VulkanExampleBase::flushCommandBuffer(layoutCmd, queue, true);
|
|
||||||
|
|
||||||
// Create sampler to sample from the color attachments
|
// Create sampler to sample from the color attachments
|
||||||
VK_CHECK_RESULT(frameBuffers.deferred->createSampler(VK_FILTER_LINEAR, VK_FILTER_LINEAR, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE));
|
VK_CHECK_RESULT(frameBuffers.deferred->createSampler(VK_FILTER_LINEAR, VK_FILTER_LINEAR, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE));
|
||||||
|
|
@ -360,7 +352,8 @@ public:
|
||||||
VkViewport viewport;
|
VkViewport viewport;
|
||||||
VkRect2D scissor;
|
VkRect2D scissor;
|
||||||
|
|
||||||
// Shadow map generation pass first
|
// First pass: Shadow map generation
|
||||||
|
// -------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
clearValues[0].depthStencil = { 1.0f, 0 };
|
clearValues[0].depthStencil = { 1.0f, 0 };
|
||||||
|
|
||||||
|
|
@ -373,16 +366,6 @@ public:
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkBeginCommandBuffer(commandBuffers.deferred, &cmdBufInfo));
|
VK_CHECK_RESULT(vkBeginCommandBuffer(commandBuffers.deferred, &cmdBufInfo));
|
||||||
|
|
||||||
// Change back layout of the depth attachment after sampling in the fragment shader
|
|
||||||
// todo: replace with subpass dependency
|
|
||||||
vkTools::setImageLayout(
|
|
||||||
commandBuffers.deferred,
|
|
||||||
frameBuffers.shadow->attachments[0].image,
|
|
||||||
VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT,
|
|
||||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
|
||||||
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
|
|
||||||
frameBuffers.shadow->attachments[0].subresourceRange);
|
|
||||||
|
|
||||||
viewport = vkTools::initializers::viewport((float)frameBuffers.shadow->width, (float)frameBuffers.shadow->height, 0.0f, 1.0f);
|
viewport = vkTools::initializers::viewport((float)frameBuffers.shadow->width, (float)frameBuffers.shadow->height, 0.0f, 1.0f);
|
||||||
vkCmdSetViewport(commandBuffers.deferred, 0, 1, &viewport);
|
vkCmdSetViewport(commandBuffers.deferred, 0, 1, &viewport);
|
||||||
|
|
||||||
|
|
@ -401,34 +384,9 @@ public:
|
||||||
renderScene(commandBuffers.deferred, true);
|
renderScene(commandBuffers.deferred, true);
|
||||||
vkCmdEndRenderPass(commandBuffers.deferred);
|
vkCmdEndRenderPass(commandBuffers.deferred);
|
||||||
|
|
||||||
// Change layout of the depth attachment for sampling in the fragment shader
|
// Second pass: Deferred calculations
|
||||||
// todo: replace with subpass dependency
|
|
||||||
vkTools::setImageLayout(
|
|
||||||
commandBuffers.deferred,
|
|
||||||
frameBuffers.shadow->attachments[0].image,
|
|
||||||
VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT,
|
|
||||||
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
|
|
||||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
|
||||||
frameBuffers.shadow->attachments[0].subresourceRange);
|
|
||||||
|
|
||||||
// Deferred pass second
|
|
||||||
// -------------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Change back layout of the color attachments after sampling in the fragment shader
|
|
||||||
// todo: replace with subpass dependency
|
|
||||||
for (auto attachment : frameBuffers.deferred->attachments)
|
|
||||||
{
|
|
||||||
if (!attachment.hasDepth())
|
|
||||||
{
|
|
||||||
vkTools::setImageLayout(
|
|
||||||
commandBuffers.deferred,
|
|
||||||
attachment.image,
|
|
||||||
VK_IMAGE_ASPECT_COLOR_BIT,
|
|
||||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
|
||||||
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear values for all attachments written in the fragment sahder
|
// Clear values for all attachments written in the fragment sahder
|
||||||
clearValues[0].color = { { 0.0f, 0.0f, 0.0f, 0.0f } };
|
clearValues[0].color = { { 0.0f, 0.0f, 0.0f, 0.0f } };
|
||||||
clearValues[1].color = { { 0.0f, 0.0f, 0.0f, 0.0f } };
|
clearValues[1].color = { { 0.0f, 0.0f, 0.0f, 0.0f } };
|
||||||
|
|
@ -454,21 +412,6 @@ public:
|
||||||
renderScene(commandBuffers.deferred, false);
|
renderScene(commandBuffers.deferred, false);
|
||||||
vkCmdEndRenderPass(commandBuffers.deferred);
|
vkCmdEndRenderPass(commandBuffers.deferred);
|
||||||
|
|
||||||
// Change back layout of the color attachments after sampling in the fragment shader
|
|
||||||
// todo: replace with subpass dependency
|
|
||||||
for (auto attachment : frameBuffers.deferred->attachments)
|
|
||||||
{
|
|
||||||
if (!attachment.hasDepth())
|
|
||||||
{
|
|
||||||
vkTools::setImageLayout(
|
|
||||||
commandBuffers.deferred,
|
|
||||||
attachment.image,
|
|
||||||
VK_IMAGE_ASPECT_COLOR_BIT,
|
|
||||||
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
|
||||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkEndCommandBuffer(commandBuffers.deferred));
|
VK_CHECK_RESULT(vkEndCommandBuffer(commandBuffers.deferred));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue