I am building a 3d renderer in C++ using Vulkan. I currently have a render pass that is…
- User
I am building a 3d renderer in C++ using Vulkan. I currently have a render pass that is writing the depth output to a cube map. I am trying to then read this cube map as a texture in a later render pass. However, it seems to be indicating errors with the image layout. Can you look at the following code for the depth cube map render pass and confirm that it is correctly managing the output to the right format using dependencies?
void Renderer::CreatePointShadowRenderPass() {
codevk::AttachmentDescription depthAttachment{}; depthAttachment.format = FindDepthFormat(*GetPhysicalDevice()); // High precision format depthAttachment.samples = vk::SampleCountFlagBits::e1; depthAttachment.loadOp = vk::AttachmentLoadOp::eClear; depthAttachment.storeOp = vk::AttachmentStoreOp::eStore; depthAttachment.stencilLoadOp = vk::AttachmentLoadOp::eDontCare; depthAttachment.stencilStoreOp = vk::AttachmentStoreOp::eDontCare; depthAttachment.initialLayout = vk::ImageLayout::eUndefined; depthAttachment.finalLayout = vk::ImageLayout::eDepthStencilAttachmentOptimal; vk::AttachmentReference depthAttachmentRef{}; depthAttachmentRef.attachment = 0; depthAttachmentRef.layout = vk::ImageLayout::eDepthStencilAttachmentOptimal; vk::SubpassDescription subpass{}; subpass.pipelineBindPoint = vk::PipelineBindPoint::eGraphics; subpass.colorAttachmentCount = 0; subpass.pDepthStencilAttachment = &depthAttachmentRef; // Use subpass dependencies for layout transitions std::array<vk::SubpassDependency, 2> dependencies; dependencies[0].srcSubpass = VK_SUBPASS_EXTERNAL; dependencies[0].dstSubpass = 0; dependencies[0].srcStageMask = vk::PipelineStageFlagBits::eFragmentShader; dependencies[0].dstStageMask = vk::PipelineStageFlagBits::eEarlyFragmentTests; dependencies[0].srcAccessMask = vk::AccessFlagBits::eShaderRead; dependencies[0].dstAccessMask = vk::AccessFlagBits::eDepthStencilAttachmentWrite; dependencies[0].dependencyFlags = vk::DependencyFlagBits::eByRegion; dependencies[1].srcSubpass = 0; dependencies[1].dstSubpass = VK_SUBPASS_EXTERNAL; dependencies[1].srcStageMask = vk::PipelineStageFlagBits::eLateFragmentTests; dependencies[1].dstStageMask = vk::PipelineStageFlagBits::eFragmentShader; dependencies[1].srcAccessMask = vk::AccessFlagBits::eDepthStencilAttachmentWrite; dependencies[1].dstAccessMask = vk::AccessFlagBits::eShaderRead; dependencies[1].dependencyFlags = vk::DependencyFlagBits::eByRegion; vk::RenderPassCreateInfo renderPassInfo{}; renderPassInfo.attachmentCount = 1; renderPassInfo.pAttachments = &depthAttachment; renderPassInfo.subpassCount = 1; renderPassInfo.pSubpasses = &subpass; renderPassInfo.dependencyCount = static_cast<uint32_t>(dependencies.size()); renderPassInfo.pDependencies = dependencies.data(); if (device.createRenderPass(&renderPassInfo, nullptr, &pointShadowRenderPass) != vk::Result::eSuccess) { throw std::runtime_error("Failed to create render pass."); } - Assistant
- User
- Assistant
- User
I want to be able to handle such transitions using the render pass dependencies. I have successfully been able to handle these transitions in other render passes within the rendering pipeline so believe it should be possible here. Can you take another look at the two render pass code snippets to see what modifications might need to be made? It is worth noting that the second code snippet handles a cubemap that is already supplied in the shader read format, which is functionality I want to retain.
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.