vulkan h265 /w 10-bit + fix encoder hang (#565)
This commit is contained in:
@@ -468,9 +468,16 @@ QList<Settings::video_codec> Settings::allowedCodecs() const
|
||||
video_codec::H265,
|
||||
video_codec::Av1,
|
||||
};
|
||||
case encoder_name::X264:
|
||||
case encoder_name::Vulkan:
|
||||
return {video_codec::H264};
|
||||
return {
|
||||
video_codec::CodecAuto,
|
||||
video_codec::H264,
|
||||
video_codec::H265,
|
||||
};
|
||||
case encoder_name::X264:
|
||||
return {
|
||||
video_codec::H264,
|
||||
};
|
||||
}
|
||||
return {video_codec::CodecAuto};
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ It also requires at least one encoder:
|
||||
|
||||
* For nvenc (Nvidia), it requires cuda and nvidia driver
|
||||
* For vaapi (AMD/Intel), it requires ffmpeg with vaapi and libdrm support, as well as vaapi drivers for the GPU
|
||||
* For vulkan (Any modern GPU), it requires vulkan headers of 1.3.283 or later, as well as vulkan drivers for the GPU
|
||||
* For x264 (software encoding), it requires libx264
|
||||
|
||||
Some distributions such as Fedora don't ship h264 and h265 encoders and need specific repositories.
|
||||
|
||||
@@ -64,7 +64,12 @@ Identifier of the encoder, one of
|
||||
Default value: first supported by both headset and encoder of `av1`, `h264`, `h265`.
|
||||
|
||||
One of `h264`, `h265`, `av1`, `raw`.
|
||||
Not all encoders support every codec, `x264` and `vulkan` only support `h264`. For `raw` codec, only `raw` encoder can be used.
|
||||
|
||||
Not all encoders support every codec:
|
||||
- `x264` encoder only supports `h264` codec
|
||||
- `vulkan` encoder supports `h264` and `h265` codecs
|
||||
- `raw` encoder only supports `raw` codec
|
||||
- `nvenc` and `vaapi` support all codecs, except `raw`
|
||||
|
||||
If `nvenc` encoder is in use, you can refer to [nvidia website](https://developer.nvidia.com/video-encode-decode-support-matrix) to make sure that your GPU supports encoding with the desired codec.
|
||||
|
||||
|
||||
@@ -152,7 +152,7 @@ if (WIVRN_BUILD_SERVER)
|
||||
target_sources(wivrn-server PRIVATE
|
||||
encoder/video_encoder_vulkan.cpp
|
||||
encoder/video_encoder_vulkan_h264.cpp
|
||||
#encoder/video_encoder_vulkan_h265.cpp
|
||||
encoder/video_encoder_vulkan_h265.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "encoder_settings.h"
|
||||
|
||||
#include "driver/configuration.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "utils/wivrn_vk_bundle.h"
|
||||
@@ -289,7 +289,12 @@ static void fill_defaults(wivrn_vk_bundle & bundle, const std::vector<wivrn::vid
|
||||
#endif
|
||||
|
||||
if (config.name == encoder_vulkan and not config.codec)
|
||||
config.codec = h264; // this will fail if 10-bit is enabled
|
||||
{
|
||||
if (bit_depth == 10)
|
||||
config.codec = h265;
|
||||
else
|
||||
config.codec = h264;
|
||||
}
|
||||
|
||||
#if WIVRN_USE_X264
|
||||
if (config.name == encoder_x264)
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
*/
|
||||
|
||||
#include "video_encoder_ffmpeg.h"
|
||||
|
||||
#include "util/u_logging.h"
|
||||
#include <stdexcept>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
#endif
|
||||
#if WIVRN_USE_VULKAN_ENCODE
|
||||
#include "video_encoder_vulkan_h264.h"
|
||||
// #include "video_encoder_vulkan_h265.h"
|
||||
#include "video_encoder_vulkan_h265.h"
|
||||
#endif
|
||||
#include "video_encoder_raw.h"
|
||||
|
||||
@@ -122,9 +122,8 @@ std::unique_ptr<video_encoder> video_encoder::create(
|
||||
res = video_encoder_vulkan_h264::create(wivrn_vk, settings, fps, stream_idx);
|
||||
break;
|
||||
case video_codec::h265:
|
||||
throw std::runtime_error("h265 not supported for vulkan video encode");
|
||||
// res = video_encoder_vulkan_h265::create(wivrn_vk, settings, fps);
|
||||
// break;
|
||||
res = video_encoder_vulkan_h265::create(wivrn_vk, settings, fps, stream_idx);
|
||||
break;
|
||||
case video_codec::av1:
|
||||
throw std::runtime_error("av1 not supported for vulkan video encode");
|
||||
case video_codec::raw:
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
// TODO: verify
|
||||
static uint32_t align(uint32_t value, uint32_t alignment)
|
||||
{
|
||||
if (alignment == 0)
|
||||
@@ -115,6 +116,18 @@ wivrn::video_encoder_vulkan::video_encoder_vulkan(
|
||||
U_LOG_W("No suitable rate control available, reverting to default");
|
||||
rate_control.reset();
|
||||
}
|
||||
|
||||
constexpr uint32_t cb_min_size = 8;
|
||||
uint32_t granWidth =
|
||||
std::max(video_caps.pictureAccessGranularity.width, encode_caps.encodeInputPictureGranularity.width);
|
||||
uint32_t granHeight =
|
||||
std::max(video_caps.pictureAccessGranularity.height, encode_caps.encodeInputPictureGranularity.height);
|
||||
|
||||
aligned_extent = vk::Extent3D{
|
||||
.width = align(rect.extent.width, std::max(cb_min_size, granWidth)),
|
||||
.height = align(rect.extent.height, std::max(cb_min_size, granHeight)),
|
||||
.depth = 1,
|
||||
};
|
||||
}
|
||||
|
||||
void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_caps,
|
||||
@@ -135,7 +148,7 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca
|
||||
.imageUsage = vk::ImageUsageFlagBits::eVideoEncodeSrcKHR,
|
||||
});
|
||||
|
||||
if (picture_format.format != vk::Format::eG8B8R82Plane420Unorm)
|
||||
if (picture_format.format != vk::Format::eG8B8R82Plane420Unorm && picture_format.format != vk::Format::eG10X6B10X6R10X62Plane420Unorm3Pack16)
|
||||
throw std::runtime_error("Unsupported format " +
|
||||
vk::to_string(picture_format.format) +
|
||||
" for encoder input image");
|
||||
@@ -151,12 +164,6 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca
|
||||
// TODO: check format capabilities
|
||||
// TODO: use multiple images if array levels are not supported
|
||||
|
||||
vk::Extent3D aligned_extent{
|
||||
.width = align(rect.extent.width, video_caps.pictureAccessGranularity.width),
|
||||
.height = align(rect.extent.height, video_caps.pictureAccessGranularity.height),
|
||||
.depth = 1,
|
||||
};
|
||||
|
||||
vk::ImageCreateInfo img_create_info{
|
||||
.pNext = &video_profile_list,
|
||||
.flags = reference_picture_format.imageCreateFlags,
|
||||
@@ -224,10 +231,10 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca
|
||||
//.flags = vk::VideoSessionCreateFlagBitsKHR::eAllowEncodeParameterOptimizations,
|
||||
.pVideoProfile = &video_profile,
|
||||
.pictureFormat = picture_format.format,
|
||||
.maxCodedExtent = rect.extent,
|
||||
.maxCodedExtent = {aligned_extent.width, aligned_extent.height},
|
||||
.referencePictureFormat = reference_picture_format.format,
|
||||
.maxDpbSlots = num_dpb_slots,
|
||||
.maxActiveReferencePictures = 2,
|
||||
.maxActiveReferencePictures = 1, // h265 code assumes only 1 reference
|
||||
.pStdHeaderVersion = &std_header_version,
|
||||
});
|
||||
|
||||
@@ -343,7 +350,8 @@ void wivrn::video_encoder_vulkan::init(const vk::VideoCapabilitiesKHR & video_ca
|
||||
for (auto & item: dpb)
|
||||
{
|
||||
item.resource = vk::VideoPictureResourceInfoKHR{
|
||||
.codedExtent = rect.extent,
|
||||
.codedOffset = {0, 0},
|
||||
.codedExtent = {aligned_extent.width, aligned_extent.height},
|
||||
.imageViewBinding = *item.image_view,
|
||||
};
|
||||
}
|
||||
@@ -644,7 +652,7 @@ std::pair<bool, vk::Semaphore> wivrn::video_encoder_vulkan::present_image(vk::Im
|
||||
dpb_item * ref_slot = nullptr;
|
||||
for (auto & i: dpb)
|
||||
{
|
||||
if (i.frame_index == last_ack and i.info.slotIndex != -1)
|
||||
if (i.frame_index == last_ack and i.info.slotIndex != -1 and i.info.slotIndex != (int32_t)slot_index)
|
||||
{
|
||||
ref_slot = &i;
|
||||
break;
|
||||
@@ -667,15 +675,37 @@ std::pair<bool, vk::Semaphore> wivrn::video_encoder_vulkan::present_image(vk::Im
|
||||
{
|
||||
slot_item.idr = false;
|
||||
}
|
||||
|
||||
slot->frame_index = frame_index;
|
||||
slot->info.pPictureResource = &slot->resource;
|
||||
|
||||
vk::VideoReferenceSlotInfoKHR init_refs[2] = {};
|
||||
init_refs[0] = dpb_info[slot_index];
|
||||
init_refs[0].slotIndex = -1;
|
||||
init_refs[0].pPictureResource = &dpb[slot_index].resource;
|
||||
|
||||
if (ref_slot)
|
||||
{
|
||||
const int32_t ref_idx = ref_slot->info.slotIndex;
|
||||
if (ref_idx >= 0 && ref_idx < dpb.size())
|
||||
{
|
||||
init_refs[1] = dpb[size_t(ref_idx)].info;
|
||||
init_refs[1].slotIndex = ref_idx;
|
||||
init_refs[1].pPictureResource = &dpb[size_t(ref_idx)].resource;
|
||||
}
|
||||
else
|
||||
{
|
||||
U_LOG_I("ref_idx out of range: %d", ref_idx);
|
||||
ref_slot = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
video_cmd_buf.beginVideoCodingKHR({
|
||||
.pNext = (session_initialized and rate_control) ? &rate_control.value() : nullptr,
|
||||
.videoSession = *video_session,
|
||||
.videoSessionParameters = *video_session_parameters,
|
||||
.referenceSlotCount = uint32_t(dpb_info.size()),
|
||||
.pReferenceSlots = dpb_info.data(),
|
||||
.referenceSlotCount = ref_slot ? 2u : 1u,
|
||||
.pReferenceSlots = init_refs,
|
||||
});
|
||||
|
||||
slot->info.slotIndex = slot_index;
|
||||
@@ -751,12 +781,14 @@ std::pair<bool, vk::Semaphore> wivrn::video_encoder_vulkan::present_image(vk::Im
|
||||
.dstBufferOffset = 0,
|
||||
.dstBufferRange = slot_item.output_buffer.info().size,
|
||||
.srcPictureResource = {
|
||||
.codedExtent = rect.extent,
|
||||
.codedOffset = {0, 0},
|
||||
.codedExtent = {aligned_extent.width, aligned_extent.height},
|
||||
.baseArrayLayer = 0,
|
||||
.imageViewBinding = image_view,
|
||||
},
|
||||
.pSetupReferenceSlot = &slot->info,
|
||||
};
|
||||
|
||||
if (ref_slot)
|
||||
encode_info.setReferenceSlots(ref_slot->info);
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
#include <vulkan/vulkan_structs.hpp>
|
||||
|
||||
#include "video_encoder.h"
|
||||
#include "vk/allocation.h"
|
||||
@@ -82,6 +83,7 @@ class video_encoder_vulkan : public video_encoder
|
||||
|
||||
protected:
|
||||
const uint8_t num_dpb_slots;
|
||||
vk::Extent3D aligned_extent;
|
||||
vk::VideoEncodeRateControlLayerInfoKHR rate_control_layer;
|
||||
std::optional<vk::VideoEncodeRateControlInfoKHR> rate_control;
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "video_encoder_vulkan_h264.h"
|
||||
|
||||
#include "encoder/encoder_settings.h"
|
||||
#include "utils/wivrn_vk_bundle.h"
|
||||
|
||||
@@ -337,7 +338,7 @@ void * wivrn::video_encoder_vulkan_h264::encode_info_next(uint32_t frame_num, si
|
||||
std_picture_info = {
|
||||
.flags =
|
||||
{
|
||||
.IdrPicFlag = uint32_t(ref_slot ? 0 : 1),
|
||||
.IdrPicFlag = ref_slot ? 0u : 1u,
|
||||
.is_reference = 1,
|
||||
.no_output_of_prior_pics_flag = 0,
|
||||
.long_term_reference_flag = 0,
|
||||
|
||||
@@ -17,15 +17,90 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "video_encoder_vulkan_h265.h"
|
||||
#include "encoder/encoder_settings.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "utils/wivrn_vk_bundle.h"
|
||||
|
||||
wivrn::video_encoder_vulkan_h265::video_encoder_vulkan_h265(wivrn_vk_bundle & vk, vk::Rect2D rect, vk::VideoEncodeCapabilitiesKHR encode_caps, float fps, uint64_t bitrate) :
|
||||
video_encoder_vulkan(vk, rect, encode_caps, fps, bitrate),
|
||||
#include "encoder/encoder_settings.h"
|
||||
#include "utils/wivrn_vk_bundle.h"
|
||||
#include <cstdint>
|
||||
#include <vulkan/vulkan_core.h>
|
||||
#include <vulkan/vulkan_enums.hpp>
|
||||
|
||||
static StdVideoH265LevelIdc choose_level(uint32_t w, uint32_t h, float fps)
|
||||
{
|
||||
const uint64_t pixrate = uint64_t(w) * uint64_t(h) * uint64_t(fps + 0.5f);
|
||||
|
||||
// only consider >=5_0 due to general_tier_flag on ptl
|
||||
|
||||
if (pixrate < 267'386'880)
|
||||
return STD_VIDEO_H265_LEVEL_IDC_5_0;
|
||||
if (pixrate < 534'773'760)
|
||||
return STD_VIDEO_H265_LEVEL_IDC_5_1;
|
||||
if (pixrate < 1'069'547'520)
|
||||
return STD_VIDEO_H265_LEVEL_IDC_6_0;
|
||||
if (pixrate < 2'139'095'040)
|
||||
return STD_VIDEO_H265_LEVEL_IDC_6_1;
|
||||
return STD_VIDEO_H265_LEVEL_IDC_6_2;
|
||||
}
|
||||
|
||||
static uint32_t find_lsb(uint32_t v)
|
||||
{
|
||||
for (int i = 0; i < 32; i++)
|
||||
if (v & (1u << i))
|
||||
return i;
|
||||
|
||||
throw std::runtime_error(std::string("invalid value in encode capabilities reported by gpu driver"));
|
||||
}
|
||||
|
||||
static uint32_t find_msb(uint32_t v)
|
||||
{
|
||||
for (int i = 31; i >= 0; i--)
|
||||
if (v & (1u << i))
|
||||
return i;
|
||||
|
||||
throw std::runtime_error(std::string("invalid value in encode capabilities reported by gpu driver"));
|
||||
}
|
||||
|
||||
wivrn::video_encoder_vulkan_h265::video_encoder_vulkan_h265(
|
||||
wivrn_vk_bundle & vk,
|
||||
vk::Rect2D rect,
|
||||
const vk::VideoCapabilitiesKHR & video_caps,
|
||||
const vk::VideoEncodeCapabilitiesKHR & encode_caps,
|
||||
float fps,
|
||||
uint8_t stream_idx,
|
||||
const encoder_settings & settings) :
|
||||
video_encoder_vulkan(vk, rect, video_caps, encode_caps, fps, stream_idx, settings),
|
||||
vui{
|
||||
.flags = {
|
||||
.aspect_ratio_info_present_flag = 1,
|
||||
.video_signal_type_present_flag = 1,
|
||||
.video_full_range_flag = 1,
|
||||
.colour_description_present_flag = 1,
|
||||
.chroma_loc_info_present_flag = 1,
|
||||
.vui_timing_info_present_flag = 0, // no fixed framerate
|
||||
.motion_vectors_over_pic_boundaries_flag = 1, // allow motion vectors that exceed picture boundaries
|
||||
.restricted_ref_pic_lists_flag = 1, // all slices in a single picture use the same referene
|
||||
},
|
||||
.aspect_ratio_idc = STD_VIDEO_H265_ASPECT_RATIO_IDC_SQUARE, // _pixels_ are square
|
||||
.video_format = 5, // unspecified video format
|
||||
.colour_primaries = 1, // BT.709
|
||||
.transfer_characteristics = 1, // BT.709
|
||||
.matrix_coeffs = 1, // BT.709
|
||||
.chroma_sample_loc_type_top_field = 0,
|
||||
.chroma_sample_loc_type_bottom_field = 0,
|
||||
|
||||
},
|
||||
dpb{.max_latency_increase_plus1 = {1}, .max_dec_pic_buffering_minus1 = {uint8_t(num_dpb_slots > 0 ? num_dpb_slots - 1 : 0)}, .max_num_reorder_pics = {0}},
|
||||
ptl{.flags = {
|
||||
.general_tier_flag = 1, // 1 if >=STD_VIDEO_H265_LEVEL_IDC_5_0 and we only do 5 and above
|
||||
.general_progressive_source_flag = 1,
|
||||
.general_interlaced_source_flag = 0,
|
||||
.general_non_packed_constraint_flag = 0,
|
||||
.general_frame_only_constraint_flag = 1,
|
||||
},
|
||||
.general_profile_idc = (settings.bit_depth == 10) ? STD_VIDEO_H265_PROFILE_IDC_MAIN_10 : STD_VIDEO_H265_PROFILE_IDC_MAIN,
|
||||
.general_level_idc = choose_level(rect.extent.width, rect.extent.height, fps)},
|
||||
vps{
|
||||
.flags{
|
||||
.vps_temporal_id_nesting_flag = 0,
|
||||
.flags = {
|
||||
.vps_temporal_id_nesting_flag = 1, // radv breaks without
|
||||
.vps_sub_layer_ordering_info_present_flag = 0,
|
||||
.vps_timing_info_present_flag = 0,
|
||||
.vps_poc_proportional_to_timing_flag = 0,
|
||||
@@ -37,55 +112,31 @@ wivrn::video_encoder_vulkan_h265::video_encoder_vulkan_h265(wivrn_vk_bundle & vk
|
||||
.vps_num_units_in_tick = 0,
|
||||
.vps_time_scale = 0,
|
||||
.vps_num_ticks_poc_diff_one_minus1 = 0,
|
||||
.reserved3 = 0,
|
||||
.pDecPicBufMgr = &dpb,
|
||||
.pHrdParameters = nullptr,
|
||||
.pProfileTierLevel = &ptl,
|
||||
},
|
||||
sps{
|
||||
.flags{
|
||||
.sps_temporal_id_nesting_flag = 0,
|
||||
.separate_colour_plane_flag = 0,
|
||||
.conformance_window_flag = 0,
|
||||
.sps_sub_layer_ordering_info_present_flag = 0,
|
||||
.scaling_list_enabled_flag = 0,
|
||||
.sps_scaling_list_data_present_flag = 0,
|
||||
.amp_enabled_flag = 0,
|
||||
.sample_adaptive_offset_enabled_flag = 0,
|
||||
.pcm_enabled_flag = 0,
|
||||
.pcm_loop_filter_disabled_flag = 0,
|
||||
.long_term_ref_pics_present_flag = 0,
|
||||
.sps_temporal_mvp_enabled_flag = 0,
|
||||
.strong_intra_smoothing_enabled_flag = 0,
|
||||
.vui_parameters_present_flag = 0,
|
||||
.sps_extension_present_flag = 0,
|
||||
.sps_range_extension_flag = 0,
|
||||
.transform_skip_rotation_enabled_flag = 0,
|
||||
.transform_skip_context_enabled_flag = 0,
|
||||
.implicit_rdpcm_enabled_flag = 0,
|
||||
.explicit_rdpcm_enabled_flag = 0,
|
||||
.extended_precision_processing_flag = 0,
|
||||
.intra_smoothing_disabled_flag = 0,
|
||||
.high_precision_offsets_enabled_flag = 0,
|
||||
.persistent_rice_adaptation_enabled_flag = 0,
|
||||
.cabac_bypass_alignment_enabled_flag = 0,
|
||||
.sps_scc_extension_flag = 0,
|
||||
.sps_curr_pic_ref_enabled_flag = 0,
|
||||
.palette_mode_enabled_flag = 0,
|
||||
.sps_palette_predictor_initializers_present_flag = 0,
|
||||
.intra_boundary_filtering_disabled_flag = 0,
|
||||
.flags = {
|
||||
.sps_temporal_id_nesting_flag = 1, // radv breaks without
|
||||
.conformance_window_flag = 1, // conf_win_* are set
|
||||
.amp_enabled_flag = 1, // confirmed ok
|
||||
.sample_adaptive_offset_enabled_flag = 0, // off for (ultra) low-latency
|
||||
.strong_intra_smoothing_enabled_flag = 1, // confirmed ok
|
||||
.vui_parameters_present_flag = 1,
|
||||
.sps_range_extension_flag = (settings.bit_depth == 10) ? 1u : 0u,
|
||||
},
|
||||
.chroma_format_idc = STD_VIDEO_H265_CHROMA_FORMAT_IDC_420,
|
||||
.pic_width_in_luma_samples = 0,
|
||||
.pic_height_in_luma_samples = 0,
|
||||
.pic_width_in_luma_samples = aligned_extent.width, // confirmed
|
||||
.pic_height_in_luma_samples = aligned_extent.height, // confirmed
|
||||
.sps_video_parameter_set_id = 0,
|
||||
.sps_max_sub_layers_minus1 = 0,
|
||||
.sps_seq_parameter_set_id = 0,
|
||||
.bit_depth_luma_minus8 = 0,
|
||||
.bit_depth_chroma_minus8 = 0,
|
||||
.log2_max_pic_order_cnt_lsb_minus4 = 0,
|
||||
.log2_min_luma_coding_block_size_minus3 = 0,
|
||||
.log2_diff_max_min_luma_coding_block_size = 0,
|
||||
.log2_min_luma_transform_block_size_minus2 = 0,
|
||||
.log2_diff_max_min_luma_transform_block_size = 0,
|
||||
.max_transform_hierarchy_depth_inter = 0,
|
||||
.max_transform_hierarchy_depth_intra = 0,
|
||||
.bit_depth_luma_minus8 = static_cast<uint8_t>(settings.bit_depth - 8),
|
||||
.bit_depth_chroma_minus8 = static_cast<uint8_t>(settings.bit_depth - 8),
|
||||
.log2_max_pic_order_cnt_lsb_minus4 = 4, // arbitrary
|
||||
.log2_min_luma_coding_block_size_minus3 = 0, // keep it 0, related values are filled in create()
|
||||
.num_short_term_ref_pic_sets = 0,
|
||||
.num_long_term_ref_pics_sps = 0,
|
||||
.pcm_sample_bit_depth_luma_minus1 = 0,
|
||||
@@ -98,46 +149,26 @@ wivrn::video_encoder_vulkan_h265::video_encoder_vulkan_h265(wivrn_vk_bundle & vk
|
||||
.delta_palette_max_predictor_size = 0,
|
||||
.motion_vector_resolution_control_idc = 0,
|
||||
.sps_num_palette_predictor_initializers_minus1 = 0,
|
||||
.conf_win_left_offset = 0,
|
||||
.conf_win_right_offset = 0,
|
||||
.conf_win_top_offset = 0,
|
||||
.conf_win_bottom_offset = 0,
|
||||
.conf_win_left_offset = 0u,
|
||||
.conf_win_right_offset = (aligned_extent.width - rect.extent.width) >> 1, // 4:2:0
|
||||
.conf_win_top_offset = 0u,
|
||||
.conf_win_bottom_offset = (aligned_extent.height - rect.extent.height) >> 1, // 4:2:0
|
||||
.pProfileTierLevel = &ptl,
|
||||
.pDecPicBufMgr = &dpb,
|
||||
.pScalingLists = nullptr,
|
||||
.pShortTermRefPicSet = nullptr,
|
||||
.pLongTermRefPicsSps = nullptr,
|
||||
.pSequenceParameterSetVui = &vui,
|
||||
.pPredictorPaletteEntries = nullptr,
|
||||
},
|
||||
pps{
|
||||
.flags =
|
||||
{
|
||||
.dependent_slice_segments_enabled_flag = 0,
|
||||
.output_flag_present_flag = 0,
|
||||
.sign_data_hiding_enabled_flag = 0,
|
||||
.cabac_init_present_flag = 0,
|
||||
.constrained_intra_pred_flag = 0,
|
||||
.transform_skip_enabled_flag = 0,
|
||||
.cu_qp_delta_enabled_flag = 0,
|
||||
.pps_slice_chroma_qp_offsets_present_flag = 0,
|
||||
.weighted_pred_flag = 0,
|
||||
.weighted_bipred_flag = 0,
|
||||
.transquant_bypass_enabled_flag = 0,
|
||||
.tiles_enabled_flag = 0,
|
||||
.entropy_coding_sync_enabled_flag = 0,
|
||||
.uniform_spacing_flag = 0,
|
||||
.loop_filter_across_tiles_enabled_flag = 0,
|
||||
.pps_loop_filter_across_slices_enabled_flag = 0,
|
||||
.deblocking_filter_control_present_flag = 0,
|
||||
.deblocking_filter_override_enabled_flag = 0,
|
||||
.pps_deblocking_filter_disabled_flag = 0,
|
||||
.pps_scaling_list_data_present_flag = 0,
|
||||
.lists_modification_present_flag = 0,
|
||||
.slice_segment_header_extension_present_flag = 0,
|
||||
.pps_extension_present_flag = 0,
|
||||
.cross_component_prediction_enabled_flag = 0,
|
||||
.chroma_qp_offset_list_enabled_flag = 0,
|
||||
.pps_curr_pic_ref_enabled_flag = 0,
|
||||
.residual_adaptive_colour_transform_enabled_flag = 0,
|
||||
.pps_slice_act_qp_offsets_present_flag = 0,
|
||||
.pps_palette_predictor_initializers_present_flag = 0,
|
||||
.monochrome_palette_flag = 0,
|
||||
.pps_range_extension_flag = 0,
|
||||
},
|
||||
.flags = {
|
||||
.cu_qp_delta_enabled_flag = 1, // must be 1 or nvidia breaks
|
||||
.transquant_bypass_enabled_flag = 0, // only 1 when tuned for lossless
|
||||
.deblocking_filter_control_present_flag = 1,
|
||||
.pps_range_extension_flag = (settings.bit_depth == 10) ? 1u : 0u,
|
||||
},
|
||||
|
||||
.pps_pic_parameter_set_id = 0,
|
||||
.pps_seq_parameter_set_id = 0,
|
||||
.sps_video_parameter_set_id = 0,
|
||||
@@ -151,7 +182,6 @@ wivrn::video_encoder_vulkan_h265::video_encoder_vulkan_h265(wivrn_vk_bundle & vk
|
||||
.pps_beta_offset_div2 = 0,
|
||||
.pps_tc_offset_div2 = 0,
|
||||
.log2_parallel_merge_level_minus2 = 0,
|
||||
.log2_max_transform_skip_block_size_minus2 = 0,
|
||||
.diff_cu_chroma_qp_offset_depth = 0,
|
||||
.chroma_qp_offset_list_len_minus1 = 0,
|
||||
.cb_qp_offset_list = {},
|
||||
@@ -162,8 +192,8 @@ wivrn::video_encoder_vulkan_h265::video_encoder_vulkan_h265(wivrn_vk_bundle & vk
|
||||
.pps_act_cb_qp_offset_plus5 = 0,
|
||||
.pps_act_cr_qp_offset_plus3 = 0,
|
||||
.pps_num_palette_predictor_initializers = 0,
|
||||
.luma_bit_depth_entry_minus8 = 0,
|
||||
.chroma_bit_depth_entry_minus8 = 0,
|
||||
.luma_bit_depth_entry_minus8 = static_cast<uint8_t>(settings.bit_depth - 8),
|
||||
.chroma_bit_depth_entry_minus8 = static_cast<uint8_t>(settings.bit_depth - 8),
|
||||
.num_tile_columns_minus1 = 0,
|
||||
.num_tile_rows_minus1 = 0,
|
||||
.reserved1 = 0,
|
||||
@@ -171,6 +201,8 @@ wivrn::video_encoder_vulkan_h265::video_encoder_vulkan_h265(wivrn_vk_bundle & vk
|
||||
.column_width_minus1 = {},
|
||||
.row_height_minus1 = {},
|
||||
.reserved3 = 0,
|
||||
.pScalingLists = nullptr,
|
||||
.pPredictorPaletteEntries = nullptr,
|
||||
}
|
||||
{
|
||||
if (not std::ranges::any_of(vk.device_extensions, [](std::string_view ext) { return ext == VK_KHR_VIDEO_ENCODE_H265_EXTENSION_NAME; }))
|
||||
@@ -195,44 +227,79 @@ std::vector<void *> wivrn::video_encoder_vulkan_h265::setup_slot_info(size_t dpb
|
||||
return res;
|
||||
}
|
||||
|
||||
std::unique_ptr<wivrn::video_encoder_vulkan_h265> wivrn::video_encoder_vulkan_h265::create(
|
||||
wivrn_vk_bundle & vk,
|
||||
encoder_settings & settings,
|
||||
float fps)
|
||||
static auto get_video_caps(vk::raii::PhysicalDevice & phys_dev, int bit_depth)
|
||||
{
|
||||
vk::Rect2D rect{
|
||||
.offset = {
|
||||
.x = settings.offset_x,
|
||||
.y = settings.offset_y,
|
||||
if (!(bit_depth == 8 || bit_depth == 10))
|
||||
throw std::runtime_error("h265 encoder supports 8-bit or 10-bit only");
|
||||
|
||||
vk::StructureChain video_profile_info{
|
||||
vk::VideoProfileInfoKHR{
|
||||
.videoCodecOperation = vk::VideoCodecOperationFlagBitsKHR::eEncodeH265,
|
||||
.chromaSubsampling = vk::VideoChromaSubsamplingFlagBitsKHR::e420,
|
||||
.lumaBitDepth = bit_depth == 10 ? vk::VideoComponentBitDepthFlagBitsKHR::e10 : vk::VideoComponentBitDepthFlagBitsKHR::e8,
|
||||
.chromaBitDepth = bit_depth == 10 ? vk::VideoComponentBitDepthFlagBitsKHR::e10 : vk::VideoComponentBitDepthFlagBitsKHR::e8,
|
||||
},
|
||||
.extent = {
|
||||
.width = settings.width,
|
||||
.height = settings.height,
|
||||
vk::VideoEncodeH265ProfileInfoKHR{
|
||||
.stdProfileIdc = bit_depth == 10 ? STD_VIDEO_H265_PROFILE_IDC_MAIN_10 : STD_VIDEO_H265_PROFILE_IDC_MAIN,
|
||||
},
|
||||
};
|
||||
vk::VideoEncodeUsageInfoKHR{
|
||||
.videoUsageHints = vk::VideoEncodeUsageFlagBitsKHR::eStreaming,
|
||||
.videoContentHints = vk::VideoEncodeContentFlagBitsKHR::eRendered,
|
||||
.tuningMode = vk::VideoEncodeTuningModeKHR::eUltraLowLatency,
|
||||
}};
|
||||
|
||||
try
|
||||
{
|
||||
auto [video_caps, encode_caps, encode_h265_caps] =
|
||||
phys_dev.getVideoCapabilitiesKHR<
|
||||
vk::VideoCapabilitiesKHR,
|
||||
vk::VideoEncodeCapabilitiesKHR,
|
||||
vk::VideoEncodeH265CapabilitiesKHR>(video_profile_info.get());
|
||||
return std::make_tuple(video_caps, encode_caps, encode_h265_caps, video_profile_info);
|
||||
}
|
||||
catch (...)
|
||||
{}
|
||||
// NVIDIA fails if the structure is there
|
||||
video_profile_info.unlink<vk::VideoEncodeUsageInfoKHR>();
|
||||
|
||||
auto [video_caps, encode_caps, encode_h265_caps] =
|
||||
vk.physical_device.getVideoCapabilitiesKHR<
|
||||
phys_dev.getVideoCapabilitiesKHR<
|
||||
vk::VideoCapabilitiesKHR,
|
||||
vk::VideoEncodeCapabilitiesKHR,
|
||||
vk::VideoEncodeH265CapabilitiesKHR>(video_profile_info.get());
|
||||
return std::make_tuple(video_caps, encode_caps, encode_h265_caps, video_profile_info);
|
||||
}
|
||||
|
||||
std::unique_ptr<video_encoder_vulkan_h265> self(new video_encoder_vulkan_h265(vk, rect, encode_caps, fps, settings.bitrate));
|
||||
std::unique_ptr<wivrn::video_encoder_vulkan_h265> wivrn::video_encoder_vulkan_h265::create(
|
||||
wivrn_vk_bundle & vk,
|
||||
encoder_settings & settings,
|
||||
float fps,
|
||||
uint8_t stream_idx)
|
||||
{
|
||||
vk::Rect2D rect{
|
||||
.offset = {.x = settings.offset_x, .y = settings.offset_y},
|
||||
.extent = {.width = settings.width, .height = settings.height},
|
||||
};
|
||||
|
||||
vk::VideoEncodeH265SessionParametersAddInfoKHR h265_add_info{};
|
||||
h265_add_info.setStdVPSs(self->vps);
|
||||
h265_add_info.setStdSPSs(self->sps);
|
||||
h265_add_info.setStdPPSs(self->pps);
|
||||
auto [video_caps, encode_caps, encode_h265_caps, video_profile_info] = get_video_caps(vk.physical_device, settings.bit_depth);
|
||||
|
||||
vk::VideoEncodeH265SessionParametersCreateInfoKHR h265_session_params{
|
||||
std::unique_ptr<video_encoder_vulkan_h265> self(
|
||||
new video_encoder_vulkan_h265(vk, rect, video_caps, encode_caps, fps, stream_idx, settings));
|
||||
|
||||
vk::VideoEncodeH265SessionParametersAddInfoKHR add_info{};
|
||||
add_info.setStdVPSs(self->vps);
|
||||
add_info.setStdSPSs(self->sps);
|
||||
add_info.setStdPPSs(self->pps);
|
||||
|
||||
vk::VideoEncodeH265SessionParametersCreateInfoKHR session_params_info{
|
||||
.maxStdVPSCount = 1,
|
||||
.maxStdSPSCount = 1,
|
||||
.maxStdPPSCount = 1,
|
||||
.pParametersAddInfo = &h265_add_info,
|
||||
.pParametersAddInfo = &add_info,
|
||||
};
|
||||
|
||||
vk::VideoEncodeH265SessionCreateInfoKHR session_create_info{
|
||||
.useMaxLevelIdc = false,
|
||||
.useMaxLevelIdc = false, // let driver clamp if needed
|
||||
};
|
||||
|
||||
if (encode_h265_caps.requiresGopRemainingFrames)
|
||||
@@ -243,16 +310,39 @@ std::unique_ptr<wivrn::video_encoder_vulkan_h265> wivrn::video_encoder_vulkan_h2
|
||||
.gopRemainingP = std::numeric_limits<uint32_t>::max(),
|
||||
.gopRemainingB = 0,
|
||||
};
|
||||
self->rate_control_h265 = vk::VideoEncodeH265RateControlInfoKHR{
|
||||
self->rc_h265 = vk::VideoEncodeH265RateControlInfoKHR{
|
||||
.pNext = &self->gop_info,
|
||||
.gopFrameCount = std::numeric_limits<uint32_t>::max(),
|
||||
.idrPeriod = std::numeric_limits<uint32_t>::max(),
|
||||
.flags = {},
|
||||
};
|
||||
self->rate_control->pNext = &self->rate_control_h265;
|
||||
self->rate_control->pNext = &self->rc_h265;
|
||||
}
|
||||
|
||||
self->init(video_caps, video_profile_info.get(), &session_create_info, &h265_session_params);
|
||||
self->sps.log2_diff_max_min_luma_coding_block_size = find_msb((uint32_t)encode_h265_caps.ctbSizes) + 1; // First bit is 16x16.
|
||||
self->sps.log2_min_luma_transform_block_size_minus2 = find_lsb((uint32_t)encode_h265_caps.transformBlockSizes);
|
||||
self->sps.log2_diff_max_min_luma_transform_block_size =
|
||||
find_msb((uint32_t)encode_h265_caps.transformBlockSizes) - find_lsb((uint32_t)encode_h265_caps.transformBlockSizes);
|
||||
|
||||
uint32_t max_transform_hierarchy = (find_msb((uint32_t)encode_h265_caps.ctbSizes) + 4) - (find_lsb((uint32_t)encode_h265_caps.transformBlockSizes) + 2);
|
||||
self->sps.max_transform_hierarchy_depth_inter = max_transform_hierarchy;
|
||||
self->sps.max_transform_hierarchy_depth_intra = max_transform_hierarchy;
|
||||
|
||||
uint32_t syntax_flags = (uint32_t)encode_h265_caps.stdSyntaxFlags;
|
||||
|
||||
if ((syntax_flags & VK_VIDEO_ENCODE_H265_STD_TRANSFORM_SKIP_ENABLED_FLAG_SET_BIT_KHR) != 0 ||
|
||||
(syntax_flags & VK_VIDEO_ENCODE_H265_STD_TRANSFORM_SKIP_ENABLED_FLAG_UNSET_BIT_KHR) == 0)
|
||||
{
|
||||
self->pps.flags.transform_skip_enabled_flag = 1;
|
||||
self->pps.log2_max_transform_skip_block_size_minus2 = find_msb((uint32_t)encode_h265_caps.transformBlockSizes);
|
||||
}
|
||||
|
||||
if ((syntax_flags & VK_VIDEO_ENCODE_H265_STD_CONSTRAINED_INTRA_PRED_FLAG_SET_BIT_KHR) != 0)
|
||||
self->pps.flags.constrained_intra_pred_flag = 1;
|
||||
|
||||
if ((syntax_flags & VK_VIDEO_ENCODE_H265_STD_SAMPLE_ADAPTIVE_OFFSET_ENABLED_FLAG_SET_BIT_KHR) != 0)
|
||||
self->sample_adaptive_offset_enabled = true;
|
||||
|
||||
self->rate_control_layer.pNext = &self->rc_layer_h265;
|
||||
self->init(video_caps, video_profile_info.get(), &session_create_info, &session_params_info);
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -262,6 +352,9 @@ std::vector<uint8_t> wivrn::video_encoder_vulkan_h265::get_vps_sps_pps()
|
||||
.writeStdVPS = true,
|
||||
.writeStdSPS = true,
|
||||
.writeStdPPS = true,
|
||||
.stdVPSId = 0,
|
||||
.stdSPSId = 0,
|
||||
.stdPPSId = 0,
|
||||
};
|
||||
return get_encoded_parameters(&next);
|
||||
}
|
||||
@@ -269,50 +362,28 @@ std::vector<uint8_t> wivrn::video_encoder_vulkan_h265::get_vps_sps_pps()
|
||||
void wivrn::video_encoder_vulkan_h265::send_idr_data()
|
||||
{
|
||||
auto data = get_vps_sps_pps();
|
||||
SendData(data, false);
|
||||
SendData(data, false, true);
|
||||
}
|
||||
|
||||
void * wivrn::video_encoder_vulkan_h265::encode_info_next(uint32_t frame_num, size_t slot, std::optional<size_t> ref)
|
||||
void * wivrn::video_encoder_vulkan_h265::encode_info_next(uint32_t frame_num, size_t slot, std::optional<int32_t> ref_slot)
|
||||
{
|
||||
slice_header = {
|
||||
.flags =
|
||||
{
|
||||
.first_slice_segment_in_pic_flag = 0,
|
||||
.dependent_slice_segment_flag = 0,
|
||||
.slice_sao_luma_flag = 0,
|
||||
.slice_sao_chroma_flag = 0,
|
||||
.num_ref_idx_active_override_flag = 0,
|
||||
.mvd_l1_zero_flag = 0,
|
||||
.cabac_init_flag = 0,
|
||||
.cu_chroma_qp_offset_enabled_flag = 0,
|
||||
.deblocking_filter_override_flag = 0,
|
||||
.slice_deblocking_filter_disabled_flag = 0,
|
||||
.collocated_from_l0_flag = 0,
|
||||
.slice_loop_filter_across_slices_enabled_flag = 0,
|
||||
},
|
||||
.slice_type = ref ? STD_VIDEO_H265_SLICE_TYPE_P
|
||||
: STD_VIDEO_H265_SLICE_TYPE_I,
|
||||
.slice_segment_address = 0,
|
||||
.collocated_ref_idx = 0,
|
||||
.MaxNumMergeCand = 0,
|
||||
.slice_cb_qp_offset = 0,
|
||||
.slice_cr_qp_offset = 0,
|
||||
.slice_beta_offset_div2 = 0,
|
||||
.slice_tc_offset_div2 = 0,
|
||||
.slice_act_y_qp_offset = 0,
|
||||
.slice_act_cb_qp_offset = 0,
|
||||
.slice_act_cr_qp_offset = 0,
|
||||
.slice_qp_delta = 0,
|
||||
.flags = {
|
||||
.first_slice_segment_in_pic_flag = 1,
|
||||
.slice_sao_luma_flag = sample_adaptive_offset_enabled,
|
||||
.slice_sao_chroma_flag = sample_adaptive_offset_enabled,
|
||||
.num_ref_idx_active_override_flag = ref_slot ? 1u : 0u,
|
||||
.collocated_from_l0_flag = 1,
|
||||
},
|
||||
.slice_type = ref_slot ? STD_VIDEO_H265_SLICE_TYPE_P : STD_VIDEO_H265_SLICE_TYPE_I,
|
||||
.MaxNumMergeCand = 5,
|
||||
};
|
||||
nalu_slice_info = vk::VideoEncodeH265NaluSliceSegmentInfoKHR{
|
||||
.constantQp = 0,
|
||||
.pStdSliceSegmentHeader = &slice_header,
|
||||
};
|
||||
reference_lists_info = {
|
||||
.flags =
|
||||
{
|
||||
.ref_pic_list_modification_flag_l0 = 0,
|
||||
.ref_pic_list_modification_flag_l1 = 0,
|
||||
},
|
||||
.flags = {.ref_pic_list_modification_flag_l0 = 0, .ref_pic_list_modification_flag_l1 = 0},
|
||||
.num_ref_idx_l0_active_minus1 = 0,
|
||||
.num_ref_idx_l1_active_minus1 = 0,
|
||||
.RefPicList0 = {},
|
||||
@@ -320,92 +391,99 @@ void * wivrn::video_encoder_vulkan_h265::encode_info_next(uint32_t frame_num, si
|
||||
.list_entry_l0 = {},
|
||||
.list_entry_l1 = {},
|
||||
};
|
||||
std::fill(reference_lists_info.RefPicList0,
|
||||
reference_lists_info.RefPicList0 + sizeof(reference_lists_info.RefPicList0),
|
||||
STD_VIDEO_H265_NO_REFERENCE_PICTURE);
|
||||
std::fill(reference_lists_info.RefPicList1,
|
||||
reference_lists_info.RefPicList1 + sizeof(reference_lists_info.RefPicList1),
|
||||
STD_VIDEO_H265_NO_REFERENCE_PICTURE);
|
||||
if (ref)
|
||||
std::ranges::fill(reference_lists_info.RefPicList0, STD_VIDEO_H265_NO_REFERENCE_PICTURE);
|
||||
std::ranges::fill(reference_lists_info.RefPicList1, STD_VIDEO_H265_NO_REFERENCE_PICTURE);
|
||||
|
||||
const int32_t poc = int32_t(frame_num);
|
||||
|
||||
if (ref_slot)
|
||||
{
|
||||
reference_lists_info.RefPicList0[0] = *ref;
|
||||
const int32_t refPoc = dpb_std_info[*ref_slot].PicOrderCntVal;
|
||||
|
||||
st_rps = {};
|
||||
|
||||
for (uint32_t i = 0; i < poc_history.size(); ++i)
|
||||
{
|
||||
const uint32_t delta = uint32_t(poc - poc_history[i]) - i; // deltas are accumulative!
|
||||
st_rps.delta_poc_s0_minus1[i] = uint16_t(delta - 1);
|
||||
if (poc_history[i] == refPoc)
|
||||
{
|
||||
st_rps.used_by_curr_pic_s0_flag |= (1u << i);
|
||||
st_rps.num_negative_pics = uint8_t(i + 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
st_rps.num_positive_pics = 0;
|
||||
st_rps.used_by_curr_pic_flag = 0;
|
||||
|
||||
reference_lists_info.num_ref_idx_l0_active_minus1 = 0;
|
||||
reference_lists_info.RefPicList0[0] = static_cast<uint8_t>(*ref_slot);
|
||||
|
||||
if (st_rps.used_by_curr_pic_s0_flag == 0)
|
||||
{
|
||||
// ref_slot is too old → encode an IDR instead
|
||||
ref_slot.reset();
|
||||
poc_history.clear();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
poc_history.clear();
|
||||
}
|
||||
|
||||
std_picture_info = {
|
||||
.flags =
|
||||
{
|
||||
.is_reference = 1,
|
||||
.IrapPicFlag = uint32_t(ref ? 0 : 1),
|
||||
.used_for_long_term_reference = 0,
|
||||
.discardable_flag = 0,
|
||||
.cross_layer_bla_flag = 0,
|
||||
.pic_output_flag = 0,
|
||||
.no_output_of_prior_pics_flag = 0,
|
||||
.short_term_ref_pic_set_sps_flag = 0,
|
||||
.slice_temporal_mvp_enabled_flag = 0,
|
||||
},
|
||||
.pic_type = ref ? STD_VIDEO_H265_PICTURE_TYPE_P
|
||||
: STD_VIDEO_H265_PICTURE_TYPE_IDR,
|
||||
.flags = {
|
||||
.is_reference = 1,
|
||||
.IrapPicFlag = ref_slot ? 0u : 1u,
|
||||
.used_for_long_term_reference = 0,
|
||||
.discardable_flag = 0,
|
||||
.cross_layer_bla_flag = 0,
|
||||
.pic_output_flag = 1,
|
||||
.no_output_of_prior_pics_flag = ref_slot ? 0u : 1u,
|
||||
.short_term_ref_pic_set_sps_flag = 0u,
|
||||
.slice_temporal_mvp_enabled_flag = 1,
|
||||
},
|
||||
.pic_type = ref_slot ? STD_VIDEO_H265_PICTURE_TYPE_P : STD_VIDEO_H265_PICTURE_TYPE_IDR,
|
||||
.sps_video_parameter_set_id = 0,
|
||||
.pps_seq_parameter_set_id = 0,
|
||||
.pps_pic_parameter_set_id = 0,
|
||||
.pps_seq_parameter_set_id = sps.sps_seq_parameter_set_id,
|
||||
.pps_pic_parameter_set_id = pps.pps_pic_parameter_set_id,
|
||||
.short_term_ref_pic_set_idx = 0,
|
||||
.PicOrderCntVal = 0,
|
||||
.PicOrderCntVal = int32_t(poc),
|
||||
.TemporalId = 0,
|
||||
.reserved1 = {},
|
||||
.pRefLists = ref_slot ? &reference_lists_info : nullptr,
|
||||
.pShortTermRefPicSet = ref_slot ? &st_rps : nullptr,
|
||||
.pLongTermRefPics = nullptr,
|
||||
};
|
||||
|
||||
picture_info = vk::VideoEncodeH265PictureInfoKHR{
|
||||
.naluSliceSegmentEntryCount = 1,
|
||||
.pNaluSliceSegmentEntries = &nalu_slice_info,
|
||||
.pStdPictureInfo = &std_picture_info,
|
||||
};
|
||||
|
||||
dpb_std_info[slot].pic_type = std_picture_info.pic_type;
|
||||
auto & i = dpb_std_info[slot];
|
||||
i.flags = {.used_for_long_term_reference = 0, .unused_for_reference = 0};
|
||||
i.pic_type = std_picture_info.pic_type;
|
||||
i.PicOrderCntVal = std_picture_info.PicOrderCntVal;
|
||||
i.TemporalId = std_picture_info.TemporalId;
|
||||
|
||||
if (not ref)
|
||||
++idr_id;
|
||||
const uint32_t history_limit = std::min<uint32_t>(16u, dpb.max_dec_pic_buffering_minus1[0]);
|
||||
|
||||
if (poc_history.size() < 1 || poc_history.front() != poc)
|
||||
poc_history.push_front(poc);
|
||||
if (poc_history.size() > history_limit)
|
||||
poc_history.pop_back();
|
||||
|
||||
return &picture_info;
|
||||
}
|
||||
|
||||
vk::ExtensionProperties wivrn::video_encoder_vulkan_h265::std_header_version()
|
||||
{
|
||||
// FIXME: update to version 1.0
|
||||
vk::ExtensionProperties std_header_version{
|
||||
.specVersion = 0x0000900b, // VK_MAKE_VIDEO_STD_VERSION(1, 0, 0),
|
||||
.specVersion = VK_MAKE_VIDEO_STD_VERSION(1, 0, 0),
|
||||
};
|
||||
strcpy(std_header_version.extensionName,
|
||||
VK_STD_VULKAN_VIDEO_CODEC_H265_ENCODE_EXTENSION_NAME);
|
||||
return std_header_version;
|
||||
}
|
||||
|
||||
decltype(wivrn::video_encoder_vulkan_h265::video_profile_info) wivrn::video_encoder_vulkan_h265::video_profile_info = vk::StructureChain{
|
||||
vk::VideoProfileInfoKHR{
|
||||
.videoCodecOperation =
|
||||
vk::VideoCodecOperationFlagBitsKHR::eEncodeH265,
|
||||
.chromaSubsampling = vk::VideoChromaSubsamplingFlagBitsKHR::e420,
|
||||
.lumaBitDepth = vk::VideoComponentBitDepthFlagBitsKHR::e8,
|
||||
.chromaBitDepth = vk::VideoComponentBitDepthFlagBitsKHR::e8,
|
||||
},
|
||||
vk::VideoEncodeH265ProfileInfoKHR{
|
||||
.stdProfileIdc = STD_VIDEO_H265_PROFILE_IDC_MAIN,
|
||||
},
|
||||
vk::VideoEncodeUsageInfoKHR{
|
||||
.videoUsageHints = vk::VideoEncodeUsageFlagBitsKHR::eStreaming,
|
||||
.videoContentHints = vk::VideoEncodeContentFlagBitsKHR::eRendered,
|
||||
.tuningMode = vk::VideoEncodeTuningModeKHR::eUltraLowLatency,
|
||||
}};
|
||||
vk::StructureChain video_profile_info{
|
||||
vk::VideoProfileInfoKHR{
|
||||
.videoCodecOperation =
|
||||
vk::VideoCodecOperationFlagBitsKHR::eEncodeH265,
|
||||
.chromaSubsampling = vk::VideoChromaSubsamplingFlagBitsKHR::e420,
|
||||
.lumaBitDepth = vk::VideoComponentBitDepthFlagBitsKHR::e8,
|
||||
.chromaBitDepth = vk::VideoComponentBitDepthFlagBitsKHR::e8,
|
||||
},
|
||||
vk::VideoEncodeH265ProfileInfoKHR{
|
||||
.stdProfileIdc = STD_VIDEO_H265_PROFILE_IDC_MAIN,
|
||||
},
|
||||
vk::VideoEncodeUsageInfoKHR{
|
||||
.videoUsageHints = vk::VideoEncodeUsageFlagBitsKHR::eStreaming,
|
||||
.videoContentHints = vk::VideoEncodeContentFlagBitsKHR::eRendered,
|
||||
.tuningMode = vk::VideoEncodeTuningModeKHR::eUltraLowLatency,
|
||||
}};
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "video_encoder_vulkan.h"
|
||||
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
@@ -26,33 +27,50 @@
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
|
||||
class video_encoder_vulkan_h265 : public video_encoder_vulkan
|
||||
{
|
||||
uint16_t idr_id = 0;
|
||||
StdVideoH265VideoParameterSet vps;
|
||||
StdVideoH265SequenceParameterSet sps;
|
||||
StdVideoH265PictureParameterSet pps;
|
||||
std::deque<int32_t> poc_history;
|
||||
bool sample_adaptive_offset_enabled = false;
|
||||
|
||||
StdVideoEncodeH265SliceSegmentHeader slice_header;
|
||||
vk::VideoEncodeH265NaluSliceSegmentInfoKHR nalu_slice_info;
|
||||
StdVideoH265SequenceParameterSetVui vui{};
|
||||
StdVideoH265DecPicBufMgr dpb{};
|
||||
|
||||
StdVideoEncodeH265PictureInfo std_picture_info;
|
||||
vk::VideoEncodeH265PictureInfoKHR picture_info;
|
||||
StdVideoH265ProfileTierLevel ptl{};
|
||||
StdVideoH265VideoParameterSet vps{};
|
||||
|
||||
StdVideoEncodeH265ReferenceListsInfo reference_lists_info;
|
||||
StdVideoH265SequenceParameterSet sps{};
|
||||
|
||||
StdVideoH265PictureParameterSet pps{};
|
||||
|
||||
StdVideoH265ShortTermRefPicSet st_rps{};
|
||||
|
||||
StdVideoEncodeH265SliceSegmentHeader slice_header{};
|
||||
vk::VideoEncodeH265NaluSliceSegmentInfoKHR nalu_slice_info{};
|
||||
|
||||
StdVideoEncodeH265ReferenceListsInfo reference_lists_info{};
|
||||
StdVideoEncodeH265PictureInfo std_picture_info{};
|
||||
vk::VideoEncodeH265PictureInfoKHR picture_info{};
|
||||
|
||||
std::vector<StdVideoEncodeH265ReferenceInfo> dpb_std_info;
|
||||
std::vector<vk::VideoEncodeH265DpbSlotInfoKHR> dpb_std_slots;
|
||||
|
||||
vk::VideoEncodeH265GopRemainingFrameInfoKHR gop_info;
|
||||
vk::VideoEncodeH265RateControlInfoKHR rate_control_h265;
|
||||
vk::VideoEncodeH265GopRemainingFrameInfoKHR gop_info{};
|
||||
vk::VideoEncodeH265RateControlInfoKHR rc_h265{};
|
||||
vk::VideoEncodeH265RateControlLayerInfoKHR rc_layer_h265{};
|
||||
|
||||
video_encoder_vulkan_h265(wivrn_vk_bundle & vk, vk::Rect2D rect, vk::VideoEncodeCapabilitiesKHR encode_caps, float fps, uint64_t bitrate);
|
||||
video_encoder_vulkan_h265(wivrn_vk_bundle & vk,
|
||||
vk::Rect2D rect,
|
||||
const vk::VideoCapabilitiesKHR & video_caps,
|
||||
const vk::VideoEncodeCapabilitiesKHR & encode_caps,
|
||||
float fps,
|
||||
uint8_t stream_idx,
|
||||
const encoder_settings & settings);
|
||||
|
||||
protected:
|
||||
std::vector<void *> setup_slot_info(size_t dpb_size) override;
|
||||
|
||||
void * encode_info_next(uint32_t frame_num, size_t slot, std::optional<size_t> ref) override;
|
||||
void * encode_info_next(uint32_t frame_num, size_t slot, std::optional<int32_t> ref_slot) override;
|
||||
virtual vk::ExtensionProperties std_header_version() override;
|
||||
|
||||
void send_idr_data() override;
|
||||
@@ -60,7 +78,8 @@ protected:
|
||||
public:
|
||||
static std::unique_ptr<video_encoder_vulkan_h265> create(wivrn_vk_bundle & vk,
|
||||
encoder_settings & settings,
|
||||
float fps);
|
||||
float fps,
|
||||
uint8_t stream_idx);
|
||||
|
||||
std::vector<uint8_t> get_vps_sps_pps();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user