Archived
1
Fork 0

Fix some more image transition bugs related to vulkan dispatch

This commit is contained in:
redstrate 2021-06-01 11:49:27 -04:00
parent f69d7c18fd
commit e63caf1a83
2 changed files with 24 additions and 8 deletions

View file

@ -676,7 +676,7 @@ GFXRenderPass* GFXVulkan::create_render_pass(const GFXRenderPassCreateInfo& info
VkAttachmentDescription depthAttachment; VkAttachmentDescription depthAttachment;
VkAttachmentReference depthAttachmentRef; VkAttachmentReference depthAttachmentRef;
for (int i = 0; i < info.attachments.size(); i++) { for (int i = 0; i < info.attachments.size(); i++) {
bool isDepthAttachment = false; bool isDepthAttachment = false;
if (info.attachments[i] == GFXPixelFormat::DEPTH_32F) if (info.attachments[i] == GFXPixelFormat::DEPTH_32F)
isDepthAttachment = true; isDepthAttachment = true;
@ -691,10 +691,14 @@ GFXRenderPass* GFXVulkan::create_render_pass(const GFXRenderPassCreateInfo& info
attachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; attachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
if(info.will_use_in_shader) { if(info.will_use_in_shader) {
attachment.finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; if(isDepthAttachment) {
attachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
} else {
attachment.finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
}
} else { } else {
if (isDepthAttachment) if (isDepthAttachment)
attachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL; attachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
else else
attachment.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; attachment.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
} }
@ -717,7 +721,7 @@ GFXRenderPass* GFXVulkan::create_render_pass(const GFXRenderPassCreateInfo& info
descriptions.push_back(attachment); descriptions.push_back(attachment);
references.push_back(attachmentRef); references.push_back(attachmentRef);
} }
} }
VkSubpassDescription subpass = {}; VkSubpassDescription subpass = {};
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
@ -730,7 +734,9 @@ GFXRenderPass* GFXVulkan::create_render_pass(const GFXRenderPassCreateInfo& info
descriptions.push_back(depthAttachment); descriptions.push_back(depthAttachment);
} }
VkRenderPassCreateInfo renderPassInfo = {}; // dependency to next renderpass
VkRenderPassCreateInfo renderPassInfo = {};
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
renderPassInfo.attachmentCount = static_cast<uint32_t>(descriptions.size()); renderPassInfo.attachmentCount = static_cast<uint32_t>(descriptions.size());
renderPassInfo.pAttachments = descriptions.data(); renderPassInfo.pAttachments = descriptions.data();
@ -1489,8 +1495,12 @@ void GFXVulkan::submit(GFXCommandBuffer* command_buffer, const int identifier) {
for(auto binding : currentPipeline->bindings_marked_as_storage_images) { for(auto binding : currentPipeline->bindings_marked_as_storage_images) {
auto tex = (GFXVulkanTexture*)boundTextures[binding]; auto tex = (GFXVulkanTexture*)boundTextures[binding];
const auto check_flag = [](const GFXTextureUsage usage, const GFXTextureUsage flag) {
return (usage & flag) == flag;
};
VkImageLayout next_layout = tex->layout; VkImageLayout next_layout = tex->layout;
if((tex->usage & GFXTextureUsage::Sampled) == GFXTextureUsage::Sampled) if(check_flag(tex->usage, GFXTextureUsage::Sampled) && !check_flag(tex->usage, GFXTextureUsage::Attachment))
next_layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; next_layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
inlineTransitionImageLayout(cmd, tex->handle, tex->format, tex->aspect, tex->range, VK_IMAGE_LAYOUT_GENERAL, next_layout); inlineTransitionImageLayout(cmd, tex->handle, tex->format, tex->aspect, tex->range, VK_IMAGE_LAYOUT_GENERAL, next_layout);
@ -2093,6 +2103,12 @@ void GFXVulkan::cacheDescriptorState(GFXVulkanPipeline* pipeline, VkDescriptorSe
imageInfo.imageView = vulkanTexture->view; imageInfo.imageView = vulkanTexture->view;
imageInfo.sampler = vulkanTexture->sampler; imageInfo.sampler = vulkanTexture->sampler;
if((vulkanTexture->usage & GFXTextureUsage::Attachment) == GFXTextureUsage::Attachment) {
if(vulkanTexture->format == VK_FORMAT_D32_SFLOAT) {
imageInfo.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
}
}
VkWriteDescriptorSet descriptorWrite = {}; VkWriteDescriptorSet descriptorWrite = {};
descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descriptorWrite.dstSet = descriptorSet; descriptorWrite.dstSet = descriptorSet;

View file

@ -79,7 +79,7 @@ void ShadowPass::create_scene_resources(Scene& scene) {
spotTextureInfo.width = render_options.shadow_resolution; spotTextureInfo.width = render_options.shadow_resolution;
spotTextureInfo.height = render_options.shadow_resolution; spotTextureInfo.height = render_options.shadow_resolution;
spotTextureInfo.format = GFXPixelFormat::DEPTH_32F; spotTextureInfo.format = GFXPixelFormat::DEPTH_32F;
spotTextureInfo.usage = GFXTextureUsage::Sampled | GFXTextureUsage::Attachment; spotTextureInfo.usage = GFXTextureUsage::Sampled;
spotTextureInfo.array_length = max_spot_shadows; spotTextureInfo.array_length = max_spot_shadows;
spotTextureInfo.samplingMode = SamplingMode::ClampToBorder; spotTextureInfo.samplingMode = SamplingMode::ClampToBorder;
spotTextureInfo.border_color = GFXBorderColor::OpaqueWhite; spotTextureInfo.border_color = GFXBorderColor::OpaqueWhite;