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

@ -691,10 +691,14 @@ GFXRenderPass* GFXVulkan::create_render_pass(const GFXRenderPassCreateInfo& info
attachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
if(info.will_use_in_shader) {
if(isDepthAttachment) {
attachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
} else {
attachment.finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
}
} else {
if (isDepthAttachment)
attachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
attachment.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
else
attachment.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
}
@ -730,6 +734,8 @@ GFXRenderPass* GFXVulkan::create_render_pass(const GFXRenderPassCreateInfo& info
descriptions.push_back(depthAttachment);
}
// dependency to next renderpass
VkRenderPassCreateInfo renderPassInfo = {};
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
renderPassInfo.attachmentCount = static_cast<uint32_t>(descriptions.size());
@ -1489,8 +1495,12 @@ void GFXVulkan::submit(GFXCommandBuffer* command_buffer, const int identifier) {
for(auto binding : currentPipeline->bindings_marked_as_storage_images) {
auto tex = (GFXVulkanTexture*)boundTextures[binding];
const auto check_flag = [](const GFXTextureUsage usage, const GFXTextureUsage flag) {
return (usage & flag) == flag;
};
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;
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.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 = {};
descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descriptorWrite.dstSet = descriptorSet;

View file

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