Fold layout transitions into subpass (Refs #155)
This commit is contained in:
parent
e6b3753873
commit
a12ff64736
1 changed files with 29 additions and 101 deletions
|
|
@ -232,7 +232,7 @@ public:
|
||||||
attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
attachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
attachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||||
attachments[0].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
attachments[0].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
attachments[0].initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
attachments[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
attachments[0].finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
attachments[0].finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||||
|
|
||||||
// This is the frame buffer attachment to where the multisampled image
|
// This is the frame buffer attachment to where the multisampled image
|
||||||
|
|
@ -243,8 +243,8 @@ public:
|
||||||
attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||||
attachments[1].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
attachments[1].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||||
attachments[1].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
attachments[1].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
attachments[1].initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
attachments[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
attachments[1].finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
attachments[1].finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||||
|
|
||||||
// Multisampled depth attachment we render to
|
// Multisampled depth attachment we render to
|
||||||
attachments[2].format = depthFormat;
|
attachments[2].format = depthFormat;
|
||||||
|
|
@ -253,7 +253,7 @@ public:
|
||||||
attachments[2].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
attachments[2].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
attachments[2].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
attachments[2].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||||
attachments[2].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
attachments[2].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
attachments[2].initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
attachments[2].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
attachments[2].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
attachments[2].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||||
|
|
||||||
// Depth resolve attachment
|
// Depth resolve attachment
|
||||||
|
|
@ -263,7 +263,7 @@ public:
|
||||||
attachments[3].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
attachments[3].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||||
attachments[3].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
attachments[3].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
|
||||||
attachments[3].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
attachments[3].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
|
||||||
attachments[3].initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
attachments[3].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||||
attachments[3].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
attachments[3].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
|
||||||
|
|
||||||
VkAttachmentReference colorReference = {};
|
VkAttachmentReference colorReference = {};
|
||||||
|
|
@ -289,11 +289,31 @@ public:
|
||||||
subpass.pResolveAttachments = resolveReferences.data();
|
subpass.pResolveAttachments = resolveReferences.data();
|
||||||
subpass.pDepthStencilAttachment = &depthReference;
|
subpass.pDepthStencilAttachment = &depthReference;
|
||||||
|
|
||||||
|
std::array<VkSubpassDependency, 2> dependencies;
|
||||||
|
|
||||||
|
dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL;
|
||||||
|
dependencies[0].dstSubpass = 0;
|
||||||
|
dependencies[0].srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
||||||
|
dependencies[0].dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||||
|
dependencies[0].srcAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
||||||
|
dependencies[0].dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
||||||
|
dependencies[0].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
|
||||||
|
|
||||||
|
dependencies[1].srcSubpass = 0;
|
||||||
|
dependencies[1].dstSubpass = VK_SUBPASS_EXTERNAL;
|
||||||
|
dependencies[1].srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||||
|
dependencies[1].dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
||||||
|
dependencies[1].srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
||||||
|
dependencies[1].dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
||||||
|
dependencies[1].dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
|
||||||
|
|
||||||
VkRenderPassCreateInfo renderPassInfo = vkTools::initializers::renderPassCreateInfo();
|
VkRenderPassCreateInfo renderPassInfo = vkTools::initializers::renderPassCreateInfo();
|
||||||
renderPassInfo.attachmentCount = attachments.size();
|
renderPassInfo.attachmentCount = attachments.size();
|
||||||
renderPassInfo.pAttachments = attachments.data();
|
renderPassInfo.pAttachments = attachments.data();
|
||||||
renderPassInfo.subpassCount = 1;
|
renderPassInfo.subpassCount = 1;
|
||||||
renderPassInfo.pSubpasses = &subpass;
|
renderPassInfo.pSubpasses = &subpass;
|
||||||
|
renderPassInfo.dependencyCount = 2;
|
||||||
|
renderPassInfo.pDependencies = dependencies.data();
|
||||||
|
|
||||||
VK_CHECK_RESULT(vkCreateRenderPass(device, &renderPassInfo, nullptr, &renderPass));
|
VK_CHECK_RESULT(vkCreateRenderPass(device, &renderPassInfo, nullptr, &renderPass));
|
||||||
}
|
}
|
||||||
|
|
@ -335,30 +355,6 @@ public:
|
||||||
|
|
||||||
void buildCommandBuffers()
|
void buildCommandBuffers()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Initial image layout transitions
|
|
||||||
// We need to transform the MSAA target layouts before using them
|
|
||||||
|
|
||||||
createSetupCommandBuffer();
|
|
||||||
|
|
||||||
// Tansform MSAA color target
|
|
||||||
vkTools::setImageLayout(
|
|
||||||
setupCmdBuffer,
|
|
||||||
multisampleTarget.color.image,
|
|
||||||
VK_IMAGE_ASPECT_COLOR_BIT,
|
|
||||||
VK_IMAGE_LAYOUT_UNDEFINED,
|
|
||||||
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
|
||||||
|
|
||||||
// Tansform MSAA depth target
|
|
||||||
vkTools::setImageLayout(
|
|
||||||
setupCmdBuffer,
|
|
||||||
multisampleTarget.depth.image,
|
|
||||||
VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT,
|
|
||||||
VK_IMAGE_LAYOUT_UNDEFINED,
|
|
||||||
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
|
||||||
|
|
||||||
flushSetupCommandBuffer();
|
|
||||||
|
|
||||||
VkCommandBufferBeginInfo cmdBufInfo = vkTools::initializers::commandBufferBeginInfo();
|
VkCommandBufferBeginInfo cmdBufInfo = vkTools::initializers::commandBufferBeginInfo();
|
||||||
|
|
||||||
VkClearValue clearValues[3];
|
VkClearValue clearValues[3];
|
||||||
|
|
@ -403,17 +399,10 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadTextures()
|
void loadMeshesAssets()
|
||||||
{
|
|
||||||
textureLoader->loadTexture(
|
|
||||||
getAssetPath() + "models/voyager/voyager.ktx",
|
|
||||||
VK_FORMAT_BC3_UNORM_BLOCK,
|
|
||||||
&textures.colorMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loadMeshes()
|
|
||||||
{
|
{
|
||||||
loadMesh(getAssetPath() + "models/voyager/voyager.dae", &meshes.example, vertexLayout, 1.0f);
|
loadMesh(getAssetPath() + "models/voyager/voyager.dae", &meshes.example, vertexLayout, 1.0f);
|
||||||
|
textureLoader->loadTexture(getAssetPath() + "models/voyager/voyager.ktx", VK_FORMAT_BC3_UNORM_BLOCK, &textures.colorMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupVertexDescriptions()
|
void setupVertexDescriptions()
|
||||||
|
|
@ -678,8 +667,7 @@ public:
|
||||||
void prepare()
|
void prepare()
|
||||||
{
|
{
|
||||||
VulkanExampleBase::prepare();
|
VulkanExampleBase::prepare();
|
||||||
loadTextures();
|
loadMeshesAssets();
|
||||||
loadMeshes();
|
|
||||||
setupVertexDescriptions();
|
setupVertexDescriptions();
|
||||||
prepareUniformBuffers();
|
prepareUniformBuffers();
|
||||||
setupDescriptorSetLayout();
|
setupDescriptorSetLayout();
|
||||||
|
|
@ -695,7 +683,6 @@ public:
|
||||||
if (!prepared)
|
if (!prepared)
|
||||||
return;
|
return;
|
||||||
draw();
|
draw();
|
||||||
updateUniformBuffers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void viewChanged()
|
virtual void viewChanged()
|
||||||
|
|
@ -704,63 +691,4 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
VulkanExample *vulkanExample;
|
VULKAN_EXAMPLE_MAIN()
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
||||||
{
|
|
||||||
if (vulkanExample != NULL)
|
|
||||||
{
|
|
||||||
vulkanExample->handleMessages(hWnd, uMsg, wParam, lParam);
|
|
||||||
}
|
|
||||||
return (DefWindowProc(hWnd, uMsg, wParam, lParam));
|
|
||||||
}
|
|
||||||
#elif defined(__linux__) && !defined(__ANDROID__)
|
|
||||||
static void handleEvent(const xcb_generic_event_t *event)
|
|
||||||
{
|
|
||||||
if (vulkanExample != NULL)
|
|
||||||
{
|
|
||||||
vulkanExample->handleEvent(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Main entry point
|
|
||||||
#if defined(_WIN32)
|
|
||||||
// Windows entry point
|
|
||||||
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow)
|
|
||||||
#elif defined(__ANDROID__)
|
|
||||||
// Android entry point
|
|
||||||
void android_main(android_app* state)
|
|
||||||
#elif defined(__linux__)
|
|
||||||
// Linux entry point
|
|
||||||
int main(const int argc, const char *argv[])
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
#if defined(__ANDROID__)
|
|
||||||
// Removing this may cause the compiler to omit the main entry point
|
|
||||||
// which would make the application crash at start
|
|
||||||
app_dummy();
|
|
||||||
#endif
|
|
||||||
vulkanExample = new VulkanExample();
|
|
||||||
#if defined(_WIN32)
|
|
||||||
vulkanExample->setupWindow(hInstance, WndProc);
|
|
||||||
#elif defined(__ANDROID__)
|
|
||||||
// Attach vulkan example to global android application state
|
|
||||||
state->userData = vulkanExample;
|
|
||||||
state->onAppCmd = VulkanExample::handleAppCommand;
|
|
||||||
state->onInputEvent = VulkanExample::handleAppInput;
|
|
||||||
vulkanExample->androidApp = state;
|
|
||||||
#elif defined(__linux__)
|
|
||||||
vulkanExample->setupWindow();
|
|
||||||
#endif
|
|
||||||
#if !defined(__ANDROID__)
|
|
||||||
vulkanExample->initSwapchain();
|
|
||||||
vulkanExample->prepare();
|
|
||||||
#endif
|
|
||||||
vulkanExample->renderLoop();
|
|
||||||
delete(vulkanExample);
|
|
||||||
#if !defined(__ANDROID__)
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue