Vulkan: Fix compute test cases

Compute tests were failing due to recent changes.
* Incorrect image layout was used for writable image bindings.
* Incorrect pipeline stage was used for indirect command buffers.

Pull Request: https://projects.blender.org/blender/blender/pulls/121744
This commit is contained in:
Jeroen Bakker
2024-05-14 08:22:18 +02:00
parent 29dc4a85f7
commit f625c4e63d
6 changed files with 53 additions and 25 deletions

View File

@@ -31,11 +31,16 @@ struct VKDispatchIndirectCreateInfo : NonCopyable {
VKDispatchIndirectCreateInfo(const VKResourceAccessInfo &resources) : resources(resources) {}
};
class VKDispatchIndirectNode : public VKNodeInfo<VKNodeType::DISPATCH_INDIRECT,
VKDispatchIndirectCreateInfo,
VKDispatchIndirectData,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
VKResourceType::IMAGE | VKResourceType::BUFFER> {
/* Although confusing the spec mentions that VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT should also be
* used for dispatches.
* (https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkPipelineStageFlagBits.html)
*/
class VKDispatchIndirectNode
: public VKNodeInfo<VKNodeType::DISPATCH_INDIRECT,
VKDispatchIndirectCreateInfo,
VKDispatchIndirectData,
VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
VKResourceType::IMAGE | VKResourceType::BUFFER> {
public:
/**
* Update the node data with the data inside create_info.

View File

@@ -328,7 +328,7 @@ TEST(vk_render_graph, dispatch_indirect_read_back)
EXPECT_EQ(4, log.size());
EXPECT_EQ(
"pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "
"dst_stage_mask=VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT" +
"dst_stage_mask=VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT" +
endl() +
" - buffer_barrier(src_access_mask=, "
"dst_access_mask=VK_ACCESS_INDIRECT_COMMAND_READ_BIT, buffer=0x2, offset=0, "
@@ -387,7 +387,7 @@ TEST(vk_render_graph, dispatch_indirect_dispatch_indirect_read_back)
EXPECT_EQ(
"pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "
"dst_stage_mask=VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT" +
"dst_stage_mask=VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT" +
endl() +
" - buffer_barrier(src_access_mask=, "
"dst_access_mask=VK_ACCESS_INDIRECT_COMMAND_READ_BIT, buffer=0x2, offset=0, "
@@ -402,8 +402,9 @@ TEST(vk_render_graph, dispatch_indirect_dispatch_indirect_read_back)
log[2]);
EXPECT_EQ("dispatch_indirect(buffer=0x2, offset=0)", log[3]);
EXPECT_EQ(
"pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, "
"dst_stage_mask=VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT" +
"pipeline_barrier(src_stage_mask=VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT, "
"VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, "
"dst_stage_mask=VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT" +
endl() +
" - buffer_barrier(src_access_mask=VK_ACCESS_SHADER_WRITE_BIT, "
"dst_access_mask=VK_ACCESS_SHADER_WRITE_BIT, buffer=0x1, offset=0, "

View File

@@ -15,7 +15,8 @@ namespace blender::gpu::render_graph {
VkImageLayout VKImageAccess::to_vk_image_layout() const
{
if (vk_access_flags & (VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT)) {
return VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
/* TODO: when read only use VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL */
return VK_IMAGE_LAYOUT_GENERAL;
}
if (vk_access_flags &

View File

@@ -181,14 +181,26 @@ void VKDescriptorSetTracker::update(VKContext &context)
if (!binding.is_image()) {
continue;
}
/* TODO: Based on the actual usage we should use
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL/VK_IMAGE_LAYOUT_GENERAL. */
binding.texture->layout_ensure(context, VK_IMAGE_LAYOUT_GENERAL);
VkDescriptorImageInfo image_info = {};
image_info.sampler = binding.vk_sampler;
image_info.imageView = binding.texture->image_view_get().vk_handle();
image_info.imageLayout = binding.texture->current_layout_get();
image_infos.append(image_info);
if (use_render_graph) {
/* TODO: Based on the actual usage we should use
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL. */
VkDescriptorImageInfo image_info = {};
image_info.sampler = binding.vk_sampler;
image_info.imageView = binding.texture->image_view_get().vk_handle();
image_info.imageLayout = VK_IMAGE_LAYOUT_GENERAL;
image_infos.append(image_info);
}
else {
/* TODO: Based on the actual usage we should use
* VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL/VK_IMAGE_LAYOUT_GENERAL. */
binding.texture->layout_ensure(context, VK_IMAGE_LAYOUT_GENERAL);
VkDescriptorImageInfo image_info = {};
image_info.sampler = binding.vk_sampler;
image_info.imageView = binding.texture->image_view_get().vk_handle();
image_info.imageLayout = binding.texture->current_layout_get();
image_infos.append(image_info);
}
VkWriteDescriptorSet write_descriptor = {};
write_descriptor.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;

View File

@@ -227,8 +227,8 @@ void VKShaderInterface::descriptor_set_location_update(
case shader::ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER:
vk_access_flags |= VK_ACCESS_UNIFORM_READ_BIT;
break;
case shader::ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER:
case shader::ShaderCreateInfo::Resource::BindType::IMAGE:
if (bool(resource->storagebuf.qualifiers & shader::Qualifier::READ) == true) {
vk_access_flags |= VK_ACCESS_SHADER_READ_BIT;
}
@@ -236,6 +236,16 @@ void VKShaderInterface::descriptor_set_location_update(
vk_access_flags |= VK_ACCESS_SHADER_WRITE_BIT;
}
break;
case shader::ShaderCreateInfo::Resource::BindType::IMAGE:
if (bool(resource->image.qualifiers & shader::Qualifier::READ) == true) {
vk_access_flags |= VK_ACCESS_SHADER_READ_BIT;
}
if (bool(resource->image.qualifiers & shader::Qualifier::WRITE) == true) {
vk_access_flags |= VK_ACCESS_SHADER_WRITE_BIT;
}
break;
case shader::ShaderCreateInfo::Resource::BindType::SAMPLER:
vk_access_flags |= VK_ACCESS_SHADER_READ_BIT;
break;

View File

@@ -458,8 +458,8 @@ bool VKTexture::init_internal(VertBuf *vbo)
copy_buffer_to_image.region.imageExtent.width = w_;
copy_buffer_to_image.region.imageExtent.height = 1;
copy_buffer_to_image.region.imageExtent.depth = 1;
copy_buffer_to_image.region.imageSubresource.aspectMask = to_vk_image_aspect_flag_bits(
device_format_);
copy_buffer_to_image.region.imageSubresource.aspectMask = to_vk_image_aspect_single_bit(
to_vk_image_aspect_flag_bits(device_format_), false);
copy_buffer_to_image.region.imageSubresource.mipLevel = 0;
copy_buffer_to_image.region.imageSubresource.layerCount = 1;
@@ -643,10 +643,9 @@ void VKTexture::add_to_descriptor_set(AddToDescriptorSetContext &data,
const VKSampler &sampler = device.samplers().get(sampler_state);
data.descriptor_set.bind(*this, *location, sampler);
}
render_graph::VKImageAccess image_access = {};
image_access.vk_image = vk_image_handle();
image_access.vk_access_flags = data.shader_interface.access_mask(bind_type, *location);
data.resource_access_info.images.append(image_access);
data.resource_access_info.images.append({vk_image_handle(),
data.shader_interface.access_mask(bind_type, binding),
to_vk_image_aspect_flag_bits(device_format_)});
}
}