diff --git a/src/strategy/multi_view_stereo.cpp b/src/strategy/multi_view_stereo.cpp index 47ba1a35b44a5e8f1cfff7aeece646db205c9600..b76e3cac147880251e1dc4dbece269d0b49f6182 100644 --- a/src/strategy/multi_view_stereo.cpp +++ b/src/strategy/multi_view_stereo.cpp @@ -12,6 +12,7 @@ bool MultiViewStereo::on_setup_device(lava::device::create_param& parameters) { memset(&this->features, 0, sizeof(this->features)); this->features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES; + this->features.pNext = (void*)parameters.next; this->features.multiview = VK_TRUE; parameters.next = &this->features; diff --git a/src/utility/encoder.cpp b/src/utility/encoder.cpp index f4c69032a954b804147319cc8ece1a2ab272989a..d0824e1f37382b89e8cbc03cb5dc46c4a592689c 100644 --- a/src/utility/encoder.cpp +++ b/src/utility/encoder.cpp @@ -386,7 +386,7 @@ bool Encoder::encode_control(lava::renderer& renderer, EncoderCallback callback) } this->control_change = false; - + return true; } @@ -423,7 +423,7 @@ bool Encoder::encode_config(lava::renderer& renderer, EncoderCallback callback) } this->config_change = false; - + return true; } @@ -503,7 +503,7 @@ bool Encoder::submit_frame(lava::device_ptr device, EncoderFrame::Ptr frame, lav signal_info.deviceIndex = 0; VkSubmitInfo2 submit_info; - submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO_2; submit_info.pNext = nullptr; submit_info.flags = 0; submit_info.waitSemaphoreInfoCount = wait_semaphores.size(); @@ -1026,7 +1026,7 @@ bool Encoder::create_image_view(lava::device_ptr device, VkImage image, VkFormat VkImageViewCreateInfo create_info; create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; - create_info.pNext = &this->video_profile; + create_info.pNext = nullptr; create_info.flags = 0; create_info.image = image; create_info.viewType = VK_IMAGE_VIEW_TYPE_2D; @@ -1135,9 +1135,15 @@ bool Encoder::create_input_images(lava::device_ptr device, EncoderFrame::Ptr fra return false; } + VkVideoProfileListInfoKHR profile_list; + profile_list.sType = VK_STRUCTURE_TYPE_VIDEO_PROFILE_LIST_INFO_KHR; + profile_list.pNext = nullptr; + profile_list.profileCount = 1; + profile_list.pProfiles = &this->video_profile; + VkImageCreateInfo combined_create_info; combined_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; - combined_create_info.pNext = &this->video_profile; + combined_create_info.pNext = &profile_list; combined_create_info.flags = 0; combined_create_info.imageType = VK_IMAGE_TYPE_2D; combined_create_info.format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM; @@ -1247,9 +1253,15 @@ bool Encoder::create_slot_image(lava::device_ptr device, EncoderFrame::Ptr frame image_extend.height = this->setting_image_size.y; image_extend.depth = 1; + VkVideoProfileListInfoKHR profile_list; + profile_list.sType = VK_STRUCTURE_TYPE_VIDEO_PROFILE_LIST_INFO_KHR; + profile_list.pNext = nullptr; + profile_list.profileCount = 1; + profile_list.pProfiles = &this->video_profile; + VkImageCreateInfo combined_create_info; combined_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; - combined_create_info.pNext = &this->video_profile; + combined_create_info.pNext = &profile_list; combined_create_info.flags = VK_IMAGE_CREATE_DISJOINT_BIT; combined_create_info.imageType = VK_IMAGE_TYPE_2D; combined_create_info.format = VK_FORMAT_G8_B8R8_2PLANE_420_UNORM; @@ -1322,9 +1334,15 @@ bool Encoder::create_slot_image(lava::device_ptr device, EncoderFrame::Ptr frame bool Encoder::create_output_buffer(lava::device_ptr device, EncoderFrame::Ptr frame) { + VkVideoProfileListInfoKHR profile_list; + profile_list.sType = VK_STRUCTURE_TYPE_VIDEO_PROFILE_LIST_INFO_KHR; + profile_list.pNext = nullptr; + profile_list.profileCount = 1; + profile_list.pProfiles = &this->video_profile; + VkBufferCreateInfo create_info; create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; - create_info.pNext = &this->video_profile; + create_info.pNext = &profile_list; create_info.flags = 0; create_info.size = this->setting_buffer_size; create_info.usage = VK_BUFFER_USAGE_VIDEO_ENCODE_DST_BIT_KHR; @@ -1856,11 +1874,11 @@ void Encoder::encode_pass_control_command(VkCommandBuffer command_buffer, Encode codec_layer_info.useMinQp = (this->setting_mode == ENCODER_MODE_CONSTANT_BITRATE) ? VK_FALSE : VK_TRUE; codec_layer_info.minQp.qpI = (this->setting_mode == ENCODER_MODE_CONSTANT_BITRATE) ? 0 : this->setting_quality_iframe; codec_layer_info.minQp.qpP = (this->setting_mode == ENCODER_MODE_CONSTANT_BITRATE) ? 0 : this->setting_quality_pframe; - codec_layer_info.minQp.qpB = 51; + codec_layer_info.minQp.qpB = (this->setting_mode == ENCODER_MODE_CONSTANT_BITRATE) ? 0 : 51; codec_layer_info.useMaxQp = (this->setting_mode == ENCODER_MODE_CONSTANT_BITRATE) ? VK_FALSE : VK_TRUE; codec_layer_info.maxQp.qpI = (this->setting_mode == ENCODER_MODE_CONSTANT_BITRATE) ? 0 : this->setting_quality_iframe; codec_layer_info.maxQp.qpP = (this->setting_mode == ENCODER_MODE_CONSTANT_BITRATE) ? 0 : this->setting_quality_pframe; - codec_layer_info.maxQp.qpB = 51; + codec_layer_info.maxQp.qpB = (this->setting_mode == ENCODER_MODE_CONSTANT_BITRATE) ? 0 : 51; codec_layer_info.useMaxFrameSize = VK_FALSE; codec_layer_info.maxFrameSize.frameISize = 0; codec_layer_info.maxFrameSize.framePSize = 0; @@ -1870,9 +1888,9 @@ void Encoder::encode_pass_control_command(VkCommandBuffer command_buffer, Encode layer_info.sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_RATE_CONTROL_LAYER_INFO_KHR; layer_info.pNext = &codec_layer_info; layer_info.averageBitrate = (this->setting_mode == ENCODER_MODE_CONSTANT_BITRATE) ? (uint32_t)(this->setting_bit_rate * 1000000.0) : 0; - layer_info.maxBitrate = (this->setting_mode == ENCODER_MODE_CONSTANT_BITRATE) ? (uint32_t)(this->setting_bit_rate * 1000000.0) : 0; - layer_info.frameRateNumerator = (this->setting_mode == ENCODER_MODE_CONSTANT_BITRATE) ? 1 : 0; - layer_info.frameRateDenominator = (this->setting_mode == ENCODER_MODE_CONSTANT_BITRATE) ? this->setting_frame_rate : 0; + layer_info.maxBitrate = 0; + layer_info.frameRateNumerator = (this->setting_mode == ENCODER_MODE_CONSTANT_BITRATE) ? this->setting_frame_rate : 0; + layer_info.frameRateDenominator = (this->setting_mode == ENCODER_MODE_CONSTANT_BITRATE) ? 1 : 0; layer_info.virtualBufferSizeInMs = (this->setting_mode == ENCODER_MODE_CONSTANT_BITRATE) ? 10 : 0; layer_info.initialVirtualBufferSizeInMs = (this->setting_mode == ENCODER_MODE_CONSTANT_BITRATE) ? 10 : 0; @@ -1929,6 +1947,32 @@ void Encoder::encode_pass_config_setup(VkCommandBuffer command_buffer, EncoderFr end_info.flags = 0; vkCmdEndVideoCodingKHR(command_buffer, &end_info); + + VkBufferMemoryBarrier2 buffer_barrier; + buffer_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2; + buffer_barrier.pNext = nullptr; + buffer_barrier.srcStageMask = VK_PIPELINE_STAGE_2_VIDEO_ENCODE_BIT_KHR; + buffer_barrier.srcAccessMask = VK_ACCESS_2_VIDEO_ENCODE_WRITE_BIT_KHR; + buffer_barrier.dstStageMask = VK_PIPELINE_STAGE_2_HOST_BIT; + buffer_barrier.dstAccessMask = VK_ACCESS_2_HOST_READ_BIT; + buffer_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + buffer_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; + buffer_barrier.buffer = frame->output_buffer; + buffer_barrier.offset = 0; + buffer_barrier.size = VK_WHOLE_SIZE; + + VkDependencyInfo buffer_dependency; + buffer_dependency.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO; + buffer_dependency.pNext = nullptr; + buffer_dependency.dependencyFlags = 0; + buffer_dependency.memoryBarrierCount = 0; + buffer_dependency.pMemoryBarriers = nullptr; + buffer_dependency.bufferMemoryBarrierCount = 1; + buffer_dependency.pBufferMemoryBarriers = &buffer_barrier; + buffer_dependency.imageMemoryBarrierCount = 0; + buffer_dependency.pImageMemoryBarriers = nullptr; + + vkCmdPipelineBarrier2KHR(command_buffer, &buffer_dependency); } void Encoder::encode_pass_config_command(VkCommandBuffer command_buffer, EncoderFrame::Ptr frame) @@ -1941,7 +1985,7 @@ void Encoder::encode_pass_config_command(VkCommandBuffer command_buffer, Encoder input_resource.codedExtent.width = 0; input_resource.codedExtent.height = 0; input_resource.baseArrayLayer = 0; - input_resource.imageViewBinding = VK_NULL_HANDLE; + input_resource.imageViewBinding = frame->input_view_combined; VkVideoEncodeH264EmitPictureParametersInfoEXT config_info; config_info.sType = VK_STRUCTURE_TYPE_VIDEO_ENCODE_H264_EMIT_PICTURE_PARAMETERS_INFO_EXT; @@ -2002,7 +2046,7 @@ void Encoder::encode_pass_frame_setup(VkCommandBuffer command_buffer, EncoderFra read_input_barrier.subresourceRange = image_range; VkImageMemoryBarrier2& write_slot_barrier = slot_barriers[1]; - write_slot_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + write_slot_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2; write_slot_barrier.pNext = nullptr; write_slot_barrier.srcStageMask = VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT; write_slot_barrier.srcAccessMask = 0; @@ -2020,7 +2064,7 @@ void Encoder::encode_pass_frame_setup(VkCommandBuffer command_buffer, EncoderFra EncoderFrame::Ptr reference_slot = reference_slots[index]; VkImageMemoryBarrier2& slot_barrier = slot_barriers[index + 2]; - slot_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER; + slot_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2; slot_barrier.pNext = nullptr; slot_barrier.srcStageMask = VK_PIPELINE_STAGE_2_VIDEO_ENCODE_BIT_KHR; slot_barrier.srcAccessMask = VK_ACCESS_2_VIDEO_ENCODE_WRITE_BIT_KHR; diff --git a/src/utility/indirect_cache.cpp b/src/utility/indirect_cache.cpp index a62f0212495a02a4e4aa5cccad13df5127b9487a..37205c4990c55d427faccbe18acdbc2bdbc485ca 100644 --- a/src/utility/indirect_cache.cpp +++ b/src/utility/indirect_cache.cpp @@ -258,12 +258,12 @@ void IndirectCache::compute_indirect(VkCommandBuffer command_buffer, lava::index vkCmdClearColorImage(command_buffer, this->distribution_geometry_image[0], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clear_color, 1, &subresource_range); vkCmdClearColorImage(command_buffer, this->distribution_geometry_image[1], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clear_color, 1, &subresource_range); - std::vector<VkImageMemoryBarrier> clear_end_barriers = IndirectCache::build_barriers(3, VK_ACCESS_TRANSFER_WRITE_BIT, 0, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); + std::vector<VkImageMemoryBarrier> clear_end_barriers = IndirectCache::build_barriers(3, VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); clear_end_barriers[0].image = this->distribution_red_image[0]; clear_end_barriers[1].image = this->distribution_green_image[0]; clear_end_barriers[2].image = this->distribution_blue_image[0]; - vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, 0, 0, nullptr, 0, nullptr, clear_end_barriers.size(), clear_end_barriers.data()); + vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, clear_end_barriers.size(), clear_end_barriers.data()); std::vector<VkImageMemoryBarrier> geometry_begin_barriers = IndirectCache::build_barriers(2, VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL); geometry_begin_barriers[0].image = this->distribution_geometry_image[0];