在源访问掩码中包含 READ_BIT 有意义吗?
Does it make sense to have READ_BIT in source access mask?
内存屏障应该可以防止写后读和写后写的危险。读取操作后,数据未更改,因此无需使其可用。
但是规范层和验证层确实允许 srcAccessMask
中的 READ_BIT
标志。一些隐式依赖定义为:
VkSubpassDependency implicitDependency = {
.srcSubpass = lastSubpass; // Last subpass attachment is used in
.dstSubpass = VK_SUBPASS_EXTERNAL;
.srcStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
.dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
.srcAccessMask = VK_ACCESS_INPUT_ATTACHMENT_READ_BIT |
VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
.dstAccessMask = 0;
.dependencyFlags = 0;
};
我在 Khronos Vulkan 示例中生成 mipmap 后也看到了这一点:
// After the loop, all mip layers are in TRANSFER_SRC layout, so transition all to SHADER_READ
vkb::insert_image_memory_barrier(
blit_command,
texture.image,
VK_ACCESS_TRANSFER_READ_BIT, // srcAccessMask
VK_ACCESS_SHADER_READ_BIT, // dstAccessMask
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
{VK_IMAGE_ASPECT_COLOR_BIT, 0, texture.mip_levels, 0, 1});
在这种情况下 READ_BIT
是多余的,还是我遗漏了什么?
READ_BIT
确实是多余的。引用来自 VulkanDocs 的规范作者:
So we've now completely resolved that READ in srcAccessMask is
completely a no-op. If we hadn't been previously implying that you
needed it, then we'd probably make it invalid. Instead we're just
going to leave it as a no-op, and hopefully add a warning to the
validation layers that it's a no-op. This should be clear in the spec
in the next couple of weeks.
内存屏障应该可以防止写后读和写后写的危险。读取操作后,数据未更改,因此无需使其可用。
但是规范层和验证层确实允许 srcAccessMask
中的 READ_BIT
标志。一些隐式依赖定义为:
VkSubpassDependency implicitDependency = {
.srcSubpass = lastSubpass; // Last subpass attachment is used in
.dstSubpass = VK_SUBPASS_EXTERNAL;
.srcStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
.dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
.srcAccessMask = VK_ACCESS_INPUT_ATTACHMENT_READ_BIT |
VK_ACCESS_COLOR_ATTACHMENT_READ_BIT |
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
.dstAccessMask = 0;
.dependencyFlags = 0;
};
我在 Khronos Vulkan 示例中生成 mipmap 后也看到了这一点:
// After the loop, all mip layers are in TRANSFER_SRC layout, so transition all to SHADER_READ
vkb::insert_image_memory_barrier(
blit_command,
texture.image,
VK_ACCESS_TRANSFER_READ_BIT, // srcAccessMask
VK_ACCESS_SHADER_READ_BIT, // dstAccessMask
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
{VK_IMAGE_ASPECT_COLOR_BIT, 0, texture.mip_levels, 0, 1});
在这种情况下 READ_BIT
是多余的,还是我遗漏了什么?
READ_BIT
确实是多余的。引用来自 VulkanDocs 的规范作者:
So we've now completely resolved that READ in srcAccessMask is completely a no-op. If we hadn't been previously implying that you needed it, then we'd probably make it invalid. Instead we're just going to leave it as a no-op, and hopefully add a warning to the validation layers that it's a no-op. This should be clear in the spec in the next couple of weeks.