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
I now get the following error when reading the cubemap:
UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout(ERROR / SPEC): msgNum: 1303270965 - Validation Error: [ UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout ] Object 0: handle = 0x259694faf30, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0x4dae5635 | vkQueueSubmit(): pSubmits[0].pCommandBuffers[0] command buffer VkCommandBuffer 0x259694faf30[] expects VkImage 0x44695a0000000071[] (subresource: aspectMask 0x2 array layer 0, mip level 0) to be in layout VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL--instead, current layout is VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL. Objects: 1 [0] 0x259694faf30, type: 6, name: NULL
I have just realised that the following render pass that is reading the cubemap is expecting a colored texture instead of a depth map. However, I don't expect this would be the cause of the error since the transition to a shader read layout should enable the render pass to read it.
- Assistant
- User
Please read the previous messages. I am attempting to transition the image layout through the use of subpass dependencies instead of the barrier functions.
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.