Fix vulkan encode QFOT layouts (NVIDIA green frame)
Compositor release left layouts as eUndefined while encoder acquire transitioned to eVideoEncodeSrcKHR (or eTransferSrcOptimal on the NVIDIA tmp_image path); the spec forbids that layout mismatch for exclusive-mode QFOT. NVIDIA honoured it by treating encode-queue contents as undefined (solid green frame). Encoders now publish target_layout. The compositor's release and the encoder's acquire both transition eGeneral -> target_layout in a single barrier; per VkImageMemoryBarrier2 the layout transition is performed exactly once between the queues, so no second non-QFOT barrier is needed. target_layout is eVideoEncodeSrcKHR on the direct vulkan encode path and eGeneral elsewhere. Also fix optimal_transfer(): the inner `auto to = ...` shadowed the parameter, so the maintenance9 check was effectively always false.
This commit is contained in:
committed by
Patrick Nicolas
parent
f54be85c26
commit
e79621d377
@@ -442,6 +442,16 @@ xrt_result_t compositor::layer_commit(xrt_graphics_sync_handle_t sync_handle)
|
|||||||
.srcAccessMask = vk::AccessFlagBits2::eShaderStorageWrite,
|
.srcAccessMask = vk::AccessFlagBits2::eShaderStorageWrite,
|
||||||
.dstStageMask = vk::PipelineStageFlagBits2::eAllCommands,
|
.dstStageMask = vk::PipelineStageFlagBits2::eAllCommands,
|
||||||
.dstAccessMask = vk::AccessFlagBits2::eMemoryRead,
|
.dstAccessMask = vk::AccessFlagBits2::eMemoryRead,
|
||||||
|
// For a queue-family ownership transfer in EXCLUSIVE
|
||||||
|
// sharing mode, the release barrier's old/new layout
|
||||||
|
// must match the encoder-side acquire. newLayout is
|
||||||
|
// the encoder's target_layout; per the VkImageMemoryBarrier2
|
||||||
|
// spec the layout transition is executed exactly once
|
||||||
|
// between the queues, so this single QFOT barrier covers
|
||||||
|
// both the queue-family transfer and the layout
|
||||||
|
// transition the encoder needs.
|
||||||
|
.oldLayout = vk::ImageLayout::eGeneral,
|
||||||
|
.newLayout = encoder->target_layout,
|
||||||
.srcQueueFamilyIndex = vk.queue_family_index,
|
.srcQueueFamilyIndex = vk.queue_family_index,
|
||||||
.dstQueueFamilyIndex = encoder->target_queue,
|
.dstQueueFamilyIndex = encoder->target_queue,
|
||||||
.image = images[i].image,
|
.image = images[i].image,
|
||||||
|
|||||||
@@ -78,6 +78,10 @@ public:
|
|||||||
const uint8_t stream_idx;
|
const uint8_t stream_idx;
|
||||||
const uint32_t target_queue;
|
const uint32_t target_queue;
|
||||||
const bool need_transfer;
|
const bool need_transfer;
|
||||||
|
// Layout the encoder needs y_cbcr to arrive in. Set during construction
|
||||||
|
// or init() and read by the compositor on every layer_commit — must not
|
||||||
|
// change after the first frame.
|
||||||
|
vk::ImageLayout target_layout = vk::ImageLayout::eGeneral;
|
||||||
static const uint8_t num_slots = 2;
|
static const uint8_t num_slots = 2;
|
||||||
const double bitrate_multiplier;
|
const double bitrate_multiplier;
|
||||||
|
|
||||||
|
|||||||
@@ -317,6 +317,13 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tmp_image path: copyImage source accepts eGeneral, so no transition needed.
|
||||||
|
// Direct path: vkCmdEncodeVideoKHR requires eVideoEncodeSrcKHR — folding it
|
||||||
|
// into target_layout lets the QFOT barrier perform the transition in one step.
|
||||||
|
target_layout = tmp_image
|
||||||
|
? vk::ImageLayout::eGeneral
|
||||||
|
: vk::ImageLayout::eVideoEncodeSrcKHR;
|
||||||
|
|
||||||
// Decode picture buffer (DPB) images
|
// Decode picture buffer (DPB) images
|
||||||
vk::VideoFormatPropertiesKHR reference_picture_format = select_video_format(
|
vk::VideoFormatPropertiesKHR reference_picture_format = select_video_format(
|
||||||
vk.physical_device,
|
vk.physical_device,
|
||||||
@@ -638,14 +645,13 @@ void wivrn::video_encoder_vulkan::present_image(vk::Image y_cbcr, vk::SemaphoreS
|
|||||||
compositor_sem.stageMask = vk::PipelineStageFlagBits2::eCopy;
|
compositor_sem.stageMask = vk::PipelineStageFlagBits2::eCopy;
|
||||||
|
|
||||||
beman::inplace_vector::inplace_vector<vk::ImageMemoryBarrier2, 2> im_barriers;
|
beman::inplace_vector::inplace_vector<vk::ImageMemoryBarrier2, 2> im_barriers;
|
||||||
vk::ImageLayout y_cbcr_layout{vk::ImageLayout::eGeneral};
|
|
||||||
if (need_transfer)
|
if (need_transfer)
|
||||||
{
|
{
|
||||||
im_barriers.push_back(vk::ImageMemoryBarrier2{
|
im_barriers.push_back(vk::ImageMemoryBarrier2{
|
||||||
.dstStageMask = vk::PipelineStageFlagBits2KHR::eCopy,
|
.dstStageMask = vk::PipelineStageFlagBits2KHR::eCopy,
|
||||||
.dstAccessMask = vk::AccessFlagBits2::eTransferRead,
|
.dstAccessMask = vk::AccessFlagBits2::eTransferRead,
|
||||||
.oldLayout = y_cbcr_layout,
|
.oldLayout = vk::ImageLayout::eGeneral,
|
||||||
.newLayout = vk::ImageLayout::eTransferSrcOptimal,
|
.newLayout = target_layout,
|
||||||
.srcQueueFamilyIndex = vk.queue_family_index,
|
.srcQueueFamilyIndex = vk.queue_family_index,
|
||||||
.dstQueueFamilyIndex = target_queue,
|
.dstQueueFamilyIndex = target_queue,
|
||||||
.image = y_cbcr,
|
.image = y_cbcr,
|
||||||
@@ -655,7 +661,6 @@ void wivrn::video_encoder_vulkan::present_image(vk::Image y_cbcr, vk::SemaphoreS
|
|||||||
.baseArrayLayer = stream_idx,
|
.baseArrayLayer = stream_idx,
|
||||||
.layerCount = 1},
|
.layerCount = 1},
|
||||||
});
|
});
|
||||||
y_cbcr_layout = vk::ImageLayout::eTransferSrcOptimal;
|
|
||||||
}
|
}
|
||||||
im_barriers.push_back(vk::ImageMemoryBarrier2{
|
im_barriers.push_back(vk::ImageMemoryBarrier2{
|
||||||
.dstStageMask = vk::PipelineStageFlagBits2KHR::eCopy,
|
.dstStageMask = vk::PipelineStageFlagBits2KHR::eCopy,
|
||||||
@@ -677,7 +682,7 @@ void wivrn::video_encoder_vulkan::present_image(vk::Image y_cbcr, vk::SemaphoreS
|
|||||||
|
|
||||||
video_cmd_buf.copyImage(
|
video_cmd_buf.copyImage(
|
||||||
y_cbcr,
|
y_cbcr,
|
||||||
y_cbcr_layout,
|
target_layout,
|
||||||
tmp_image,
|
tmp_image,
|
||||||
vk::ImageLayout::eTransferDstOptimal,
|
vk::ImageLayout::eTransferDstOptimal,
|
||||||
std::array{
|
std::array{
|
||||||
@@ -739,27 +744,29 @@ void wivrn::video_encoder_vulkan::present_image(vk::Image y_cbcr, vk::SemaphoreS
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
compositor_sem.stageMask = vk::PipelineStageFlagBits2::eVideoEncodeKHR;
|
compositor_sem.stageMask = vk::PipelineStageFlagBits2::eVideoEncodeKHR;
|
||||||
if (need_transfer)
|
// Single barrier: when need_transfer, this is the QFOT acquire and
|
||||||
{
|
// carries the layout transition (eGeneral → target_layout) per the
|
||||||
vk::ImageMemoryBarrier2 video_barrier{
|
// VkImageMemoryBarrier2 spec (executed once between the queues).
|
||||||
.dstStageMask = vk::PipelineStageFlagBits2KHR::eVideoEncodeKHR,
|
// When need_transfer is false (optimal cross-queue transfer, no QFOT)
|
||||||
.dstAccessMask = vk::AccessFlagBits2::eVideoEncodeReadKHR,
|
// the same barrier degenerates to a plain layout transition.
|
||||||
.oldLayout = vk::ImageLayout::eGeneral,
|
vk::ImageMemoryBarrier2 barrier{
|
||||||
.newLayout = vk::ImageLayout::eVideoEncodeSrcKHR,
|
.dstStageMask = vk::PipelineStageFlagBits2KHR::eVideoEncodeKHR,
|
||||||
.srcQueueFamilyIndex = vk.queue_family_index,
|
.dstAccessMask = vk::AccessFlagBits2::eVideoEncodeReadKHR,
|
||||||
.dstQueueFamilyIndex = target_queue,
|
.oldLayout = vk::ImageLayout::eGeneral,
|
||||||
.image = y_cbcr,
|
.newLayout = target_layout,
|
||||||
.subresourceRange = {.aspectMask = vk::ImageAspectFlagBits::eColor,
|
.srcQueueFamilyIndex = need_transfer ? vk.queue_family_index : vk::QueueFamilyIgnored,
|
||||||
.baseMipLevel = 0,
|
.dstQueueFamilyIndex = need_transfer ? target_queue : vk::QueueFamilyIgnored,
|
||||||
.levelCount = 1,
|
.image = y_cbcr,
|
||||||
.baseArrayLayer = stream_idx,
|
.subresourceRange = {.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||||
.layerCount = 1},
|
.baseMipLevel = 0,
|
||||||
};
|
.levelCount = 1,
|
||||||
video_cmd_buf.pipelineBarrier2({
|
.baseArrayLayer = stream_idx,
|
||||||
.imageMemoryBarrierCount = 1,
|
.layerCount = 1},
|
||||||
.pImageMemoryBarriers = &video_barrier,
|
};
|
||||||
});
|
video_cmd_buf.pipelineBarrier2({
|
||||||
}
|
.imageMemoryBarrierCount = 1,
|
||||||
|
.pImageMemoryBarriers = &barrier,
|
||||||
|
});
|
||||||
|
|
||||||
auto it = image_views.find(VkImage(y_cbcr));
|
auto it = image_views.find(VkImage(y_cbcr));
|
||||||
if (it != image_views.end())
|
if (it != image_views.end())
|
||||||
|
|||||||
@@ -419,8 +419,8 @@ bool wivrn::vk_bundle::optimal_transfer(uint32_t from, uint32_t to) const
|
|||||||
{
|
{
|
||||||
auto props = physical_device.getQueueFamilyProperties2<vk::StructureChain<vk::QueueFamilyProperties2, vk::QueueFamilyOwnershipTransferPropertiesKHR>>();
|
auto props = physical_device.getQueueFamilyProperties2<vk::StructureChain<vk::QueueFamilyProperties2, vk::QueueFamilyOwnershipTransferPropertiesKHR>>();
|
||||||
|
|
||||||
auto to = std::get<1>(props[from]).optimalImageTransferToQueueFamilies;
|
auto mask = std::get<1>(props[from]).optimalImageTransferToQueueFamilies;
|
||||||
return to & (1 << to);
|
return (mask & (1u << to)) != 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user