This adds support for NV12 and P010. More will be added later. --- libavcodec/ffv1enc.c | 2 ++ libavcodec/ffv1enc_vulkan.c | 8 ++++++-- libavcodec/vulkan/ffv1_enc.comp | 21 ++++++++++++++------- 3 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c index 6ab648fd80..e215ab20a4 100644 --- a/libavcodec/ffv1enc.c +++ b/libavcodec/ffv1enc.c @@ -813,6 +813,7 @@ av_cold int ff_ffv1_encode_setup_plane_info(AVCodecContext *avctx, if (!avctx->bits_per_raw_sample) s->bits_per_raw_sample = 9; case AV_PIX_FMT_GRAY10: + case AV_PIX_FMT_P010: case AV_PIX_FMT_YUV444P10: case AV_PIX_FMT_YUV440P10: case AV_PIX_FMT_YUV420P10: @@ -859,6 +860,7 @@ av_cold int ff_ffv1_encode_setup_plane_info(AVCodecContext *avctx, s->version = FFMAX(s->version, 1); case AV_PIX_FMT_GRAY8: case AV_PIX_FMT_YA8: + case AV_PIX_FMT_NV12: case AV_PIX_FMT_YUV444P: case AV_PIX_FMT_YUV440P: case AV_PIX_FMT_YUV422P: diff --git a/libavcodec/ffv1enc_vulkan.c b/libavcodec/ffv1enc_vulkan.c index 688c14fb81..42a98a5efa 100644 --- a/libavcodec/ffv1enc_vulkan.c +++ b/libavcodec/ffv1enc_vulkan.c @@ -141,6 +141,7 @@ typedef struct FFv1VkParameters { uint8_t micro_version; uint8_t force_pcm; uint8_t key_frame; + uint8_t components; uint8_t planes; uint8_t codec_planes; uint8_t transparency; @@ -149,7 +150,7 @@ typedef struct FFv1VkParameters { uint8_t ec; uint8_t ppi; uint8_t chunks; - uint8_t padding[2]; + uint8_t padding[1]; } FFv1VkParameters; static void add_push_data(FFVulkanShader *shd) @@ -173,6 +174,7 @@ static void add_push_data(FFVulkanShader *shd) GLSLC(1, uint8_t micro_version; ); GLSLC(1, uint8_t force_pcm; ); GLSLC(1, uint8_t key_frame; ); + GLSLC(1, uint8_t components; ); GLSLC(1, uint8_t planes; ); GLSLC(1, uint8_t codec_planes; ); GLSLC(1, uint8_t transparency; ); @@ -181,7 +183,7 @@ static void add_push_data(FFVulkanShader *shd) GLSLC(1, uint8_t ec; ); GLSLC(1, uint8_t ppi; ); GLSLC(1, uint8_t chunks; ); - GLSLC(1, uint8_t padding[2]; ); + GLSLC(1, uint8_t padding[1]; ); GLSLC(0, }; ); ff_vk_shader_add_push_const(shd, 0, sizeof(FFv1VkParameters), VK_SHADER_STAGE_COMPUTE_BIT); @@ -326,6 +328,7 @@ static int vulkan_encode_ffv1_submit_frame(AVCodecContext *avctx, int has_inter = avctx->gop_size > 1; uint32_t context_count = f->context_count[f->context_model]; + const AVPixFmtDescriptor *fmt_desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt); VkImageView in_views[AV_NUM_DATA_POINTERS]; VkImageView intermediate_views[AV_NUM_DATA_POINTERS]; @@ -498,6 +501,7 @@ static int vulkan_encode_ffv1_submit_frame(AVCodecContext *avctx, .micro_version = f->micro_version, .force_pcm = fv->force_pcm, .key_frame = f->key_frame, + .components = fmt_desc->nb_components, .planes = av_pix_fmt_count_planes(avctx->sw_pix_fmt), .codec_planes = f->plane_count, .transparency = f->transparency, diff --git a/libavcodec/vulkan/ffv1_enc.comp b/libavcodec/vulkan/ffv1_enc.comp index 880d3a37f0..4b851fd711 100644 --- a/libavcodec/vulkan/ffv1_enc.comp +++ b/libavcodec/vulkan/ffv1_enc.comp @@ -26,14 +26,18 @@ void encode_slice(inout SliceContext sc, const uint slice_idx) #ifndef GOLOMB if (sc.slice_coding_mode == 1) { - for (int p = 0; p < planes; p++) { + for (int c = 0; c < components; c++) { int h = sc.slice_dim.y; - if (p > 0 && p < 3) + if (c > 0 && c < 3) h >>= chroma_shift.y; + /* Takes into account dual-plane YUV formats */ + int p = min(c, planes - 1); + int comp = c - p; + for (int y = 0; y < h; y++) - encode_line_pcm(sc, y, p, 0, bits); + encode_line_pcm(sc, y, p, comp, bits); } } else #endif @@ -41,18 +45,21 @@ void encode_slice(inout SliceContext sc, const uint slice_idx) uint64_t slice_state_off = uint64_t(slice_state) + slice_idx*plane_state_size*codec_planes; - for (int p = 0; p < planes; p++) { + for (int c = 0; c < components; c++) { int run_index = 0; int h = sc.slice_dim.y; - if (p > 0 && p < 3) + if (c > 0 && c < 3) h >>= chroma_shift.y; + int p = min(c, planes - 1); + int comp = c - p; + for (int y = 0; y < h; y++) - encode_line(sc, slice_state_off, y, p, 0, bits, run_index); + encode_line(sc, slice_state_off, y, p, comp, bits, run_index); /* For the second chroma plane, reuse the first plane's state */ - if (p != 1) + if (c != 1) slice_state_off += plane_state_size; } } -- 2.49.0.395.g12beb8f557c _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".