diff mbox

[FFmpeg-devel,00/72] Implement support for Vulkan multiplane images and video decoding

Message ID NOST85t--3-9@lynne.ee
State New
Headers show

Commit Message

Lynne Feb. 17, 2023, 3:43 a.m. UTC
This small patchset mostly rewrites Vulkan to enable using multiplane images,
and implements video decode support. Also, many numerous bugs and issues
were fixed, as well as having quite a lot of performance improvements.

The patchset can be viewed here as well:
https://github.com/cyanreg/FFmpeg/tree/vulkan_staging

Patches attached.

Comments

Jean-Baptiste Kempf Feb. 17, 2023, 9:08 a.m. UTC | #1
Hello,

On Fri, 17 Feb 2023, at 04:43, Lynne wrote:
> This small patchset mostly rewrites Vulkan to enable using multiplane images,

This is not small. We're talking about thousands of lines of code;

And this changes numerous h264 and hevc headers, and adds callback to the make AVHWAccel.

And that is besides the full rewrite of some Vulkan files...

This will take a long time to review.
Hendrik Leppkes Feb. 17, 2023, 9:45 a.m. UTC | #2
On Fri, Feb 17, 2023 at 10:09 AM Jean-Baptiste Kempf <jb@videolan.org> wrote:
>
> Hello,
>
> On Fri, 17 Feb 2023, at 04:43, Lynne wrote:
> > This small patchset mostly rewrites Vulkan to enable using multiplane images,
>
> This is not small. We're talking about thousands of lines of code;
>
> And this changes numerous h264 and hevc headers, and adds callback to the make AVHWAccel.
>
> And that is besides the full rewrite of some Vulkan files...
>
> This will take a long time to review.
>

I would agree, this set is too large to try to skirt it in just under
the deadline of a new release, with the potential of needing to fix
stuff later.
Just have it land on master after the branch, and there is no time
pressure to review it, or make numerous fixes on the release branch.

PS:
Can you please send it as a proper patchset? Reviewing 72 patches off
of one mail is not really fitting the workflow at all.

- Hendrik
Lynne Feb. 17, 2023, 10:45 a.m. UTC | #3
Feb 17, 2023, 10:45 by h.leppkes@gmail.com:

> On Fri, Feb 17, 2023 at 10:09 AM Jean-Baptiste Kempf <jb@videolan.org> wrote:
>
>>
>> Hello,
>>
>> On Fri, 17 Feb 2023, at 04:43, Lynne wrote:
>> > This small patchset mostly rewrites Vulkan to enable using multiplane images,
>>
>> This is not small. We're talking about thousands of lines of code;
>>
>> And this changes numerous h264 and hevc headers, and adds callback to the make AVHWAccel.
>>
>> And that is besides the full rewrite of some Vulkan files...
>>
>> This will take a long time to review.
>>
>
> I would agree, this set is too large to try to skirt it in just under
> the deadline of a new release, with the potential of needing to fix
> stuff later.
> Just have it land on master after the branch, and there is no time
> pressure to review it, or make numerous fixes on the release branch.
>

The code's been tested by a lot of folks already, and importantly,
passes the validation layers (with some warnings due to spec issues
that the workgroup agreed to fix).
The output is also conformant on all implementations.
All the code needs is some looking over to make sure I haven't done
something silly. Valgrind output is clean too.
It is a lot of code in terms of diff, but rather than reviewing each patch
individually, you should just try looking at the final files directly, that way,
you only have a few thousand lines to look at, rather than a few
thousand times twenty.
I've abstracted all the low-level Vulkan stuff from the decoding patchset,
so the output is high-level enough that anyone who's written hwaccels can
understand it.


> PS:
> Can you please send it as a proper patchset? Reviewing 72 patches off
> of one mail is not really fitting the workflow at all.
>

I'll do that.
Kieran Kunhya Feb. 17, 2023, 11:04 a.m. UTC | #4
On Fri, 17 Feb 2023 at 09:09, Jean-Baptiste Kempf <jb@videolan.org> wrote:

> Hello,
>
> On Fri, 17 Feb 2023, at 04:43, Lynne wrote:
> > This small patchset mostly rewrites Vulkan to enable using multiplane
> images,
>
> This is not small. We're talking about thousands of lines of code;
>
> And this changes numerous h264 and hevc headers, and adds callback to the
> make AVHWAccel.
>
> And that is besides the full rewrite of some Vulkan files...
>
> This will take a long time to review.
>

I agree.

Kieran
Lynne Feb. 17, 2023, 11:52 a.m. UTC | #5
Feb 17, 2023, 12:05 by kierank@obe.tv:

> On Fri, 17 Feb 2023 at 09:09, Jean-Baptiste Kempf <jb@videolan.org> wrote:
>
>> Hello,
>>
>> On Fri, 17 Feb 2023, at 04:43, Lynne wrote:
>> > This small patchset mostly rewrites Vulkan to enable using multiplane
>> images,
>>
>> This is not small. We're talking about thousands of lines of code;
>>
>> And this changes numerous h264 and hevc headers, and adds callback to the
>> make AVHWAccel.
>>
>> And that is besides the full rewrite of some Vulkan files...
>>
>> This will take a long time to review.
>>
>
> I agree.
>

The codec changes are simple and separate, so it's not that bad to read.
There's no more than a 100 lines or so added to the H264 parser.
The 72 patch figure may be scary, but that's because I didn't want to
squash my vulkan changes behind large rewrite commits. Otherwise,
this would be a 30-commit patchset.
Michael Niedermayer Feb. 17, 2023, 3:45 p.m. UTC | #6
On Fri, Feb 17, 2023 at 12:52:21PM +0100, Lynne wrote:
> Feb 17, 2023, 12:05 by kierank@obe.tv:
> 
> > On Fri, 17 Feb 2023 at 09:09, Jean-Baptiste Kempf <jb@videolan.org> wrote:
> >
> >> Hello,
> >>
> >> On Fri, 17 Feb 2023, at 04:43, Lynne wrote:
> >> > This small patchset mostly rewrites Vulkan to enable using multiplane
> >> images,
> >>
> >> This is not small. We're talking about thousands of lines of code;
> >>
> >> And this changes numerous h264 and hevc headers, and adds callback to the
> >> make AVHWAccel.
> >>
> >> And that is besides the full rewrite of some Vulkan files...
> >>
> >> This will take a long time to review.
> >>
> >
> > I agree.
> >
> 
> The codec changes are simple and separate, so it's not that bad to read.
> There's no more than a 100 lines or so added to the H264 parser.
> The 72 patch figure may be scary, but that's because I didn't want to
> squash my vulkan changes behind large rewrite commits. Otherwise,
> this would be a 30-commit patchset.

some of these patches are very simple, yes. Others probably not (i only looked at
the first few)
That said i was never a friend of large last minute patch-sets before releases.
I think the real deciding factor is the communities opinion and
3 Developers already are against this going in before the branching. So
unless theres a shift in oppinion i think there are more people for applying
this after branching release/6.0 than before.

Is it an issue if its only in 6.1 in 6months ?

thx

[...]
Lynne Feb. 17, 2023, 4:35 p.m. UTC | #7
Feb 17, 2023, 16:45 by michael@niedermayer.cc:

> On Fri, Feb 17, 2023 at 12:52:21PM +0100, Lynne wrote:
>
>> Feb 17, 2023, 12:05 by kierank@obe.tv:
>>
>> > On Fri, 17 Feb 2023 at 09:09, Jean-Baptiste Kempf <jb@videolan.org> wrote:
>> >
>> >> Hello,
>> >>
>> >> On Fri, 17 Feb 2023, at 04:43, Lynne wrote:
>> >> > This small patchset mostly rewrites Vulkan to enable using multiplane
>> >> images,
>> >>
>> >> This is not small. We're talking about thousands of lines of code;
>> >>
>> >> And this changes numerous h264 and hevc headers, and adds callback to the
>> >> make AVHWAccel.
>> >>
>> >> And that is besides the full rewrite of some Vulkan files...
>> >>
>> >> This will take a long time to review.
>> >>
>> >
>> > I agree.
>> >
>>
>> The codec changes are simple and separate, so it's not that bad to read.
>> There's no more than a 100 lines or so added to the H264 parser.
>> The 72 patch figure may be scary, but that's because I didn't want to
>> squash my vulkan changes behind large rewrite commits. Otherwise,
>> this would be a 30-commit patchset.
>>
>
> some of these patches are very simple, yes. Others probably not (i only looked at
> the first few)
> That said i was never a friend of large last minute patch-sets before releases.
> I think the real deciding factor is the communities opinion and
> 3 Developers already are against this going in before the branching. So
> unless theres a shift in oppinion i think there are more people for applying
> this after branching release/6.0 than before.
>
> Is it an issue if its only in 6.1 in 6months ?
>

It's quite a long ways away, and this is by far the most complete
implementation of the spec which everyone is testing against.
This is the first vendor-independent, OS-independent and
hardware-independent video decoding API, and a lot of important
users like browsers and media players want to use it.
Not having it in this release would mean that all those users will
use Gstreamer instead, or nothing at all, instead choosing
proprietary libraries.

6.0 will still have at least a few days of testing after tagging, which
is enough to discover and fix major issues, if they're found.
A single dev so far has really suggested leaving it out of 6.0,
with a few others just saying that it'll take time to review,
but I think reviews are done by looking at code rather than
speculating, and at least one person has said they'll be able to
look at it tomorrow.
Michael Niedermayer Feb. 18, 2023, 7:02 p.m. UTC | #8
On Fri, Feb 17, 2023 at 04:43:50AM +0100, Lynne wrote:
> This small patchset mostly rewrites Vulkan to enable using multiplane images,
> and implements video decode support. Also, many numerous bugs and issues
> were fixed, as well as having quite a lot of performance improvements.
> 
> The patchset can be viewed here as well:
> https://github.com/cyanreg/FFmpeg/tree/vulkan_staging
> 
> Patches attached.
> 

[...]
  
>  av1dec.c  |    3 +++
>  avcodec.h |    5 +++++
>  h264dec.c |    3 +++
>  hevcdec.c |    3 +++
>  vp8.c     |    3 +++
>  vp9.c     |    3 +++
>  6 files changed, 20 insertions(+)
> 122f9df511e4680d0027afae5d4f9f2f1880874e  0065-avcodec-add-AVHWAccel.flush-callback.patch
> From 93223fa95389c60c015cfcee22784a1bf0fdb05b Mon Sep 17 00:00:00 2001
> From: Lynne <dev@lynne.ee>
> Date: Fri, 6 Jan 2023 03:32:56 +0100
> Subject: [PATCH 65/72] avcodec: add AVHWAccel.flush callback

this patch seems to break fate-vp8-size-change

==5117== Invalid read of size 8
==5117==    at 0xD50598: vp8_decode_flush_impl (vp8.c:171)
==5117==    by 0xD5ACB3: ff_vp8_decode_free (vp8.c:2869)
==5117==    by 0x84CA73: avcodec_close (avcodec.c:448)
==5117==    by 0x644BB5: avformat_find_stream_info (demux.c:2969)
==5117==    by 0x243F70: ifile_open (ffmpeg_demux.c:985)
==5117==    by 0x25F60D: open_files (ffmpeg_opt.c:1244)
==5117==    by 0x25F7C4: ffmpeg_parse_options (ffmpeg_opt.c:1283)
==5117==    by 0x278003: main (ffmpeg.c:4160)
==5117==  Address 0x70 is not stack'd, malloc'd or (recently) free'd
==5117== 
==5117== 
==5117== Process terminating with default action of signal 11 (SIGSEGV)
==5117==  Access not within mapped region at address 0x70
==5117==    at 0xD50598: vp8_decode_flush_impl (vp8.c:171)
==5117==    by 0xD5ACB3: ff_vp8_decode_free (vp8.c:2869)
==5117==    by 0x84CA73: avcodec_close (avcodec.c:448)
==5117==    by 0x644BB5: avformat_find_stream_info (demux.c:2969)
==5117==    by 0x243F70: ifile_open (ffmpeg_demux.c:985)
==5117==    by 0x25F60D: open_files (ffmpeg_opt.c:1244)
==5117==    by 0x25F7C4: ffmpeg_parse_options (ffmpeg_opt.c:1283)
==5117==    by 0x278003: main (ffmpeg.c:4160)
==5117==  If you believe this happened as a result of a stack
==5117==  overflow in your program's main thread (unlikely but
==5117==  possible), you can try to increase the size of the
==5117==  main thread stack using the --main-stacksize= flag.
==5117==  The main thread stack size used in this run was 8388608.


[...]
Lynne Feb. 19, 2023, 12:08 a.m. UTC | #9
Feb 18, 2023, 20:03 by michael@niedermayer.cc:

> On Fri, Feb 17, 2023 at 04:43:50AM +0100, Lynne wrote:
>
>> This small patchset mostly rewrites Vulkan to enable using multiplane images,
>> and implements video decode support. Also, many numerous bugs and issues
>> were fixed, as well as having quite a lot of performance improvements.
>>
>> The patchset can be viewed here as well:
>> https://github.com/cyanreg/FFmpeg/tree/vulkan_staging
>>
>> Patches attached.
>>
>
> [...]
>  
>
>> av1dec.c  |    3 +++
>>  avcodec.h |    5 +++++
>>  h264dec.c |    3 +++
>>  hevcdec.c |    3 +++
>>  vp8.c     |    3 +++
>>  vp9.c     |    3 +++
>>  6 files changed, 20 insertions(+)
>> 122f9df511e4680d0027afae5d4f9f2f1880874e  0065-avcodec-add-AVHWAccel.flush-callback.patch
>> From 93223fa95389c60c015cfcee22784a1bf0fdb05b Mon Sep 17 00:00:00 2001
>> From: Lynne <dev@lynne.ee>
>> Date: Fri, 6 Jan 2023 03:32:56 +0100
>> Subject: [PATCH 65/72] avcodec: add AVHWAccel.flush callback
>>
>
> this patch seems to break fate-vp8-size-change
>

Thanks, philipl also reported this, fixed in my branch
https://github.com/cyanreg/FFmpeg/tree/vulkan_staging
Michael Niedermayer Feb. 19, 2023, 3:40 p.m. UTC | #10
Hi


On Sun, Feb 19, 2023 at 01:08:02AM +0100, Lynne wrote:
> 
> Feb 18, 2023, 20:03 by michael@niedermayer.cc:
> 
> > On Fri, Feb 17, 2023 at 04:43:50AM +0100, Lynne wrote:
> >
> >> This small patchset mostly rewrites Vulkan to enable using multiplane images,
> >> and implements video decode support. Also, many numerous bugs and issues
> >> were fixed, as well as having quite a lot of performance improvements.
> >>
> >> The patchset can be viewed here as well:
> >> https://github.com/cyanreg/FFmpeg/tree/vulkan_staging
> >>
> >> Patches attached.
> >>
> >
> > [...]
> >  
> >
> >> av1dec.c  |    3 +++
> >>  avcodec.h |    5 +++++
> >>  h264dec.c |    3 +++
> >>  hevcdec.c |    3 +++
> >>  vp8.c     |    3 +++
> >>  vp9.c     |    3 +++
> >>  6 files changed, 20 insertions(+)
> >> 122f9df511e4680d0027afae5d4f9f2f1880874e  0065-avcodec-add-AVHWAccel.flush-callback.patch
> >> From 93223fa95389c60c015cfcee22784a1bf0fdb05b Mon Sep 17 00:00:00 2001
> >> From: Lynne <dev@lynne.ee>
> >> Date: Fri, 6 Jan 2023 03:32:56 +0100
> >> Subject: [PATCH 65/72] avcodec: add AVHWAccel.flush callback
> >>
> >
> > this patch seems to break fate-vp8-size-change
> >
> 
> Thanks, philipl also reported this, fixed in my branch

> https://github.com/cyanreg/FFmpeg/tree/vulkan_staging

ok that works, that said
is there consensus that i should create the release branch "now"?
It seems no review is going on in public of these patches and we should do
the release "soon", i am asking as i dont want to just surprise anyone with
making the branch before giving a final call

thx


[...]
Kieran Kunhya Feb. 19, 2023, 3:44 p.m. UTC | #11
On Sun, 19 Feb 2023 at 15:40, Michael Niedermayer <michael@niedermayer.cc>
wrote:

> ok that works, that said
> is there consensus that i should create the release branch "now"?
> It seems no review is going on in public of these patches and we should do
> the release "soon", i am asking as i dont want to just surprise anyone with
> making the branch before giving a final call
>
> thx
>

Yes, Vulkan can wait for 6.1.

Kieran
Lynne Feb. 19, 2023, 4:53 p.m. UTC | #12
Feb 19, 2023, 16:40 by michael@niedermayer.cc:

> Hi
>
>
> On Sun, Feb 19, 2023 at 01:08:02AM +0100, Lynne wrote:
>
>>
>> Feb 18, 2023, 20:03 by michael@niedermayer.cc:
>>
>> > On Fri, Feb 17, 2023 at 04:43:50AM +0100, Lynne wrote:
>> >
>> >> This small patchset mostly rewrites Vulkan to enable using multiplane images,
>> >> and implements video decode support. Also, many numerous bugs and issues
>> >> were fixed, as well as having quite a lot of performance improvements.
>> >>
>> >> The patchset can be viewed here as well:
>> >> https://github.com/cyanreg/FFmpeg/tree/vulkan_staging
>> >>
>> >> Patches attached.
>> >>
>> >
>> > [...]
>> > 
>> >
>> >> av1dec.c  |    3 +++
>> >>  avcodec.h |    5 +++++
>> >>  h264dec.c |    3 +++
>> >>  hevcdec.c |    3 +++
>> >>  vp8.c     |    3 +++
>> >>  vp9.c     |    3 +++
>> >>  6 files changed, 20 insertions(+)
>> >> 122f9df511e4680d0027afae5d4f9f2f1880874e  0065-avcodec-add-AVHWAccel.flush-callback.patch
>> >> From 93223fa95389c60c015cfcee22784a1bf0fdb05b Mon Sep 17 00:00:00 2001
>> >> From: Lynne <dev@lynne.ee>
>> >> Date: Fri, 6 Jan 2023 03:32:56 +0100
>> >> Subject: [PATCH 65/72] avcodec: add AVHWAccel.flush callback
>> >>
>> >
>> > this patch seems to break fate-vp8-size-change
>> >
>>
>> Thanks, philipl also reported this, fixed in my branch
>>
>> https://github.com/cyanreg/FFmpeg/tree/vulkan_staging
>>
>
> ok that works, that said
> is there consensus that i should create the release branch "now"?
> It seems no review is going on in public of these patches and we should do
> the release "soon", i am asking as i dont want to just surprise anyone with
> making the branch before giving a final call
>

We need a few more days, folks are reviewing the patches
mainly on IRC and on github, since they're large.
Functionality is on-par with the current code, and it fixes
so much, apart from adding new features, I really don't want
anyone to use the old code.
The old code is so bad, even if this patchset is broken in
some ways, it would still be a big improvement over the old code.

Most of the code is code I maintain, and has been tested and
partially reviewed already by two developers who know Vulkan
and GPU code in general. I'd still like to have this in 6.0, so
I think what I should ask is if there are any objections to merging
this as-is, and fixing any issues during the testing period.

Otherwise, I'd like for 6.1 to be released no later than April.
Jean-Baptiste Kempf Feb. 19, 2023, 4:56 p.m. UTC | #13
On Sun, 19 Feb 2023, at 17:53, Lynne wrote:
> Otherwise, I'd like for 6.1 to be released no later than April.

Sure, that would be the best solution, instead of rushing code right now.

And prepare proper testing for this, with numerous different workstations and laptops.

Best,
Lynne Feb. 19, 2023, 4:57 p.m. UTC | #14
Feb 19, 2023, 17:54 by dev@lynne.ee:

> Feb 19, 2023, 16:40 by michael@niedermayer.cc:
>
>> Hi
>>
>>
>> On Sun, Feb 19, 2023 at 01:08:02AM +0100, Lynne wrote:
>>
>>>
>>> Feb 18, 2023, 20:03 by michael@niedermayer.cc:
>>>
>>> > On Fri, Feb 17, 2023 at 04:43:50AM +0100, Lynne wrote:
>>> >
>>> >> This small patchset mostly rewrites Vulkan to enable using multiplane images,
>>> >> and implements video decode support. Also, many numerous bugs and issues
>>> >> were fixed, as well as having quite a lot of performance improvements.
>>> >>
>>> >> The patchset can be viewed here as well:
>>> >> https://github.com/cyanreg/FFmpeg/tree/vulkan_staging
>>> >>
>>> >> Patches attached.
>>> >>
>>> >
>>> > [...]
>>> > 
>>> >
>>> >> av1dec.c  |    3 +++
>>> >>  avcodec.h |    5 +++++
>>> >>  h264dec.c |    3 +++
>>> >>  hevcdec.c |    3 +++
>>> >>  vp8.c     |    3 +++
>>> >>  vp9.c     |    3 +++
>>> >>  6 files changed, 20 insertions(+)
>>> >> 122f9df511e4680d0027afae5d4f9f2f1880874e  0065-avcodec-add-AVHWAccel.flush-callback.patch
>>> >> From 93223fa95389c60c015cfcee22784a1bf0fdb05b Mon Sep 17 00:00:00 2001
>>> >> From: Lynne <dev@lynne.ee>
>>> >> Date: Fri, 6 Jan 2023 03:32:56 +0100
>>> >> Subject: [PATCH 65/72] avcodec: add AVHWAccel.flush callback
>>> >>
>>> >
>>> > this patch seems to break fate-vp8-size-change
>>> >
>>>
>>> Thanks, philipl also reported this, fixed in my branch
>>>
>>> https://github.com/cyanreg/FFmpeg/tree/vulkan_staging
>>>
>>
>> ok that works, that said
>> is there consensus that i should create the release branch "now"?
>> It seems no review is going on in public of these patches and we should do
>> the release "soon", i am asking as i dont want to just surprise anyone with
>> making the branch before giving a final call
>>
>
> We need a few more days, folks are reviewing the patches
> mainly on IRC and on github, since they're large.
> Functionality is on-par with the current code, and it fixes
> so much, apart from adding new features, I really don't want
> anyone to use the old code.
> The old code is so bad, even if this patchset is broken in
> some ways, it would still be a big improvement over the old code.
>
> Most of the code is code I maintain, and has been tested and
> partially reviewed already by two developers who know Vulkan
> and GPU code in general. I'd still like to have this in 6.0, so
> I think what I should ask is if there are any objections to merging
> this as-is, and fixing any issues during the testing period.
>
> Otherwise, I'd like for 6.1 to be released no later than April.
>

Obviously, if we merge it now, and big enough issues are found
which we couldn't fix immediately, I'd have no problem reverting
the Vulkan patches from the 6.0 branch.
Lynne Feb. 19, 2023, 4:58 p.m. UTC | #15
Feb 19, 2023, 17:57 by jb@videolan.org:

> On Sun, 19 Feb 2023, at 17:53, Lynne wrote:
>
>> Otherwise, I'd like for 6.1 to be released no later than April.
>>
>
> Sure, that would be the best solution, instead of rushing code right now.
>
> And prepare proper testing for this, with numerous different workstations and laptops.
>

I have properly tested it, 4 different configurations no less.
My AMD desktop with RADV, my 1080Ti with NVIDIA's beta drivers,
my Intel laptop with ANV, and my Intel laptop's 960M.
Jean-Baptiste Kempf Feb. 19, 2023, 5:02 p.m. UTC | #16
On Sun, 19 Feb 2023, at 17:58, Lynne wrote:
> Feb 19, 2023, 17:57 by jb@videolan.org:
>
>> On Sun, 19 Feb 2023, at 17:53, Lynne wrote:
>>
>>> Otherwise, I'd like for 6.1 to be released no later than April.
>>>
>>
>> Sure, that would be the best solution, instead of rushing code right now.
>>
>> And prepare proper testing for this, with numerous different workstations and laptops.
>>
>
> I have properly tested it, 4 different configurations no less.
> My AMD desktop with RADV, my 1080Ti with NVIDIA's beta drivers,
> my Intel laptop with ANV, and my Intel laptop's 960M.

Not everyone has the same machines, distributions, OSes or even FFmpeg utlization.
Kieran Kunhya Feb. 19, 2023, 5:36 p.m. UTC | #17
>
> Obviously, if we merge it now, and big enough issues are found
> which we couldn't fix immediately, I'd have no problem reverting
> the Vulkan patches from the 6.0 branch.


A major LTS release is not your development sandbox.

Kieran
Kieran Kunhya Feb. 19, 2023, 5:42 p.m. UTC | #18
On Sun, 19 Feb 2023 at 17:36, Kieran Kunhya <kierank@obe.tv> wrote:

> Obviously, if we merge it now, and big enough issues are found
>> which we couldn't fix immediately, I'd have no problem reverting
>> the Vulkan patches from the 6.0 branch.
>
>
> A major LTS release is not your development sandbox.
>
> Kieran
>

Correction, 6.0 is not an LTS. Nonetheless, it's not your sandbox.

Kieran
Lynne Feb. 19, 2023, 6:46 p.m. UTC | #19
Feb 19, 2023, 18:43 by kierank@obe.tv:

> On Sun, 19 Feb 2023 at 17:36, Kieran Kunhya <kierank@obe.tv> wrote:
>
>> Obviously, if we merge it now, and big enough issues are found
>>
>>> which we couldn't fix immediately, I'd have no problem reverting
>>> the Vulkan patches from the 6.0 branch.
>>>
>>
>>
>> A major LTS release is not your development sandbox.
>>
>> Kieran
>>
>
> Correction, 6.0 is not an LTS. Nonetheless, it's not your sandbox.
>

If new features don't go in, the project dies.
Everyone but seems to dislike new features.
Michael Niedermayer Feb. 19, 2023, 6:50 p.m. UTC | #20
On Sun, Feb 19, 2023 at 05:53:45PM +0100, Lynne wrote:
[...]
> Otherwise, I'd like for 6.1 to be released no later than April.

ok
release early, release often, that makes sense
but rush things, delay things can be probelmatic. It doesnt have to be
but it can. id much rather do another release than to rush and squeeze
this betwen all the constraints

thx

[...]
Lynne Feb. 19, 2023, 7:02 p.m. UTC | #21
Feb 19, 2023, 19:51 by michael@niedermayer.cc:

> On Sun, Feb 19, 2023 at 05:53:45PM +0100, Lynne wrote:
> [...]
>
>> Otherwise, I'd like for 6.1 to be released no later than April.
>>
>
> ok
> release early, release often, that makes sense
> but rush things, delay things can be probelmatic. It doesnt have to be
> but it can. id much rather do another release than to rush and squeeze
> this betwen all the constraints
>
> thx
>

I wanted to push my dct deprecation patches, can I push them
to both 6.0 and master?
Niklas Haas Feb. 19, 2023, 7:32 p.m. UTC | #22
+1 on early 6.1 to get this in

On Sun, 19 Feb 2023 17:56:25 +0100 "Jean-Baptiste Kempf" <jb@videolan.org> wrote:
> On Sun, 19 Feb 2023, at 17:53, Lynne wrote:
> > Otherwise, I'd like for 6.1 to be released no later than April.
> 
> Sure, that would be the best solution, instead of rushing code right now.
> 
> And prepare proper testing for this, with numerous different workstations and laptops.
> 
> Best,
> 
> -- 
> Jean-Baptiste Kempf -  President
> +33 672 704 734
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Michael Niedermayer Feb. 19, 2023, 7:44 p.m. UTC | #23
On Sun, Feb 19, 2023 at 08:02:24PM +0100, Lynne wrote:
> Feb 19, 2023, 19:51 by michael@niedermayer.cc:
> 
> > On Sun, Feb 19, 2023 at 05:53:45PM +0100, Lynne wrote:
> > [...]
> >
> >> Otherwise, I'd like for 6.1 to be released no later than April.
> >>
> >
> > ok
> > release early, release often, that makes sense
> > but rush things, delay things can be probelmatic. It doesnt have to be
> > but it can. id much rather do another release than to rush and squeeze
> > this betwen all the constraints
> >
> > thx
> >
> 
> I wanted to push my dct deprecation patches, can I push them
> to both 6.0 and master?

i have no oppinion on this.
If the patches pass review and its before the release they could be
backported.
I think someone said it produces thoiusands of warnings though, that
may be non ideal

thx

[...]
Lynne Feb. 19, 2023, 8 p.m. UTC | #24
Feb 19, 2023, 20:44 by michael@niedermayer.cc:

> On Sun, Feb 19, 2023 at 08:02:24PM +0100, Lynne wrote:
>
>> Feb 19, 2023, 19:51 by michael@niedermayer.cc:
>>
>> > On Sun, Feb 19, 2023 at 05:53:45PM +0100, Lynne wrote:
>> > [...]
>> >
>> >> Otherwise, I'd like for 6.1 to be released no later than April.
>> >>
>> >
>> > ok
>> > release early, release often, that makes sense
>> > but rush things, delay things can be probelmatic. It doesnt have to be
>> > but it can. id much rather do another release than to rush and squeeze
>> > this betwen all the constraints
>> >
>> > thx
>> >
>>
>> I wanted to push my dct deprecation patches, can I push them
>> to both 6.0 and master?
>>
>
> i have no oppinion on this.
> If the patches pass review and its before the release they could be
> backported.
> I think someone said it produces thoiusands of warnings though, that
> may be non ideal
>

There are no new warnings at all in v3 of the patch, only API
users will get warnings.
Michael Niedermayer Feb. 19, 2023, 8:14 p.m. UTC | #25
On Sun, Feb 19, 2023 at 09:00:19PM +0100, Lynne wrote:
> Feb 19, 2023, 20:44 by michael@niedermayer.cc:
> 
> > On Sun, Feb 19, 2023 at 08:02:24PM +0100, Lynne wrote:
> >
> >> Feb 19, 2023, 19:51 by michael@niedermayer.cc:
> >>
> >> > On Sun, Feb 19, 2023 at 05:53:45PM +0100, Lynne wrote:
> >> > [...]
> >> >
> >> >> Otherwise, I'd like for 6.1 to be released no later than April.
> >> >>
> >> >
> >> > ok
> >> > release early, release often, that makes sense
> >> > but rush things, delay things can be probelmatic. It doesnt have to be
> >> > but it can. id much rather do another release than to rush and squeeze
> >> > this betwen all the constraints
> >> >
> >> > thx
> >> >
> >>
> >> I wanted to push my dct deprecation patches, can I push them
> >> to both 6.0 and master?
> >>
> >
> > i have no oppinion on this.
> > If the patches pass review and its before the release they could be
> > backported.
> > I think someone said it produces thoiusands of warnings though, that
> > may be non ideal
> >
> 
> There are no new warnings at all in v3 of the patch, only API
> users will get warnings.

then i see no problem with it

thx

[...]
Kieran Kunhya Feb. 19, 2023, 9:59 p.m. UTC | #26
On Sun, 19 Feb 2023 at 18:46, Lynne <dev@lynne.ee> wrote:

> Feb 19, 2023, 18:43 by kierank@obe.tv:
>
> > On Sun, 19 Feb 2023 at 17:36, Kieran Kunhya <kierank@obe.tv> wrote:
> >
> >> Obviously, if we merge it now, and big enough issues are found
> >>
> >>> which we couldn't fix immediately, I'd have no problem reverting
> >>> the Vulkan patches from the 6.0 branch.
> >>>
> >>
> >>
> >> A major LTS release is not your development sandbox.
> >>
> >> Kieran
> >>
> >
> > Correction, 6.0 is not an LTS. Nonetheless, it's not your sandbox.
> >
>
> If new features don't go in, the project dies.
> Everyone but seems to dislike new features.
>

Sure, then put your features in early in the dev cycle, not days before a
major release.

Kieran
Neal Gompa Feb. 19, 2023, 11:50 p.m. UTC | #27
On Sun, Feb 19, 2023 at 5:00 PM Kieran Kunhya <kierank@obe.tv> wrote:
>
> On Sun, 19 Feb 2023 at 18:46, Lynne <dev@lynne.ee> wrote:
>
> > Feb 19, 2023, 18:43 by kierank@obe.tv:
> >
> > > On Sun, 19 Feb 2023 at 17:36, Kieran Kunhya <kierank@obe.tv> wrote:
> > >
> > >> Obviously, if we merge it now, and big enough issues are found
> > >>
> > >>> which we couldn't fix immediately, I'd have no problem reverting
> > >>> the Vulkan patches from the 6.0 branch.
> > >>>
> > >>
> > >>
> > >> A major LTS release is not your development sandbox.
> > >>
> > >> Kieran
> > >>
> > >
> > > Correction, 6.0 is not an LTS. Nonetheless, it's not your sandbox.
> > >
> >
> > If new features don't go in, the project dies.
> > Everyone but seems to dislike new features.
> >
>
> Sure, then put your features in early in the dev cycle, not days before a
> major release.
>

This is not a reasonable response, especially to someone who is
volunteering their time to develop features for a project. If it
misses 6.0, it sucks.

My concern though is that major version bumps are supposed to be
ABI/API breaks, if this patchset doesn't land in 6.0, does that mean
it'd have to be pushed off to 7.0 if it makes public API changes? If
that's the case, I'd rather request 6.0 to be delayed to get this to land.



--
真実はいつも一つ!/ Always, there's only one truth!
Jean-Baptiste Kempf Feb. 20, 2023, 5:13 a.m. UTC | #28
On Mon, 20 Feb 2023, at 00:50, Neal Gompa wrote:
> This is not a reasonable response, especially to someone who is
> volunteering their time to develop features for a project. If it
> misses 6.0, it sucks.
>
> My concern though is that major version bumps are supposed to be
> ABI/API breaks, if this patchset doesn't land in 6.0, does that mean
> it'd have to be pushed off to 7.0 if it makes public API changes? If
> that's the case, I'd rather request 6.0 to be delayed to get this to land.

Adding an API call does not break the API. Adding an API can, in the large percentage of cases, be done without breaking ABI (Sure, it might means that the structures are not as beautiful as they should be, but...)

I don't see the issue here.

In general, adding big changes should be done at the beginning of a new cycle, not at the end.

jb
Hendrik Leppkes Feb. 20, 2023, 9:18 a.m. UTC | #29
On Mon, Feb 20, 2023 at 12:50 AM Neal Gompa <ngompa13@gmail.com> wrote:
>
> On Sun, Feb 19, 2023 at 5:00 PM Kieran Kunhya <kierank@obe.tv> wrote:
> >
> > On Sun, 19 Feb 2023 at 18:46, Lynne <dev@lynne.ee> wrote:
> >
> > > Feb 19, 2023, 18:43 by kierank@obe.tv:
> > >
> > > > On Sun, 19 Feb 2023 at 17:36, Kieran Kunhya <kierank@obe.tv> wrote:
> > > >
> > > >> Obviously, if we merge it now, and big enough issues are found
> > > >>
> > > >>> which we couldn't fix immediately, I'd have no problem reverting
> > > >>> the Vulkan patches from the 6.0 branch.
> > > >>>
> > > >>
> > > >>
> > > >> A major LTS release is not your development sandbox.
> > > >>
> > > >> Kieran
> > > >>
> > > >
> > > > Correction, 6.0 is not an LTS. Nonetheless, it's not your sandbox.
> > > >
> > >
> > > If new features don't go in, the project dies.
> > > Everyone but seems to dislike new features.
> > >
> >
> > Sure, then put your features in early in the dev cycle, not days before a
> > major release.
> >
>
> This is not a reasonable response, especially to someone who is
> volunteering their time to develop features for a project. If it
> misses 6.0, it sucks.
>

I think its quite reasonable to think of the stability and quality of
the release.
If a feature is rushed into a release and you get a buggy version of
it in 6.0, that also sucks - in fact it may suck more for those people
that were using those features this is going to replace.

- Hendrik
Anton Khirnov Feb. 20, 2023, 4:51 p.m. UTC | #30
Quoting Lynne (2023-02-17 04:43:50)
> From a9ae85816dfaa8791f974348825fc8ba9209423d Mon Sep 17 00:00:00 2001
> From: Lynne <dev@lynne.ee>
> Date: Thu, 10 Mar 2022 18:08:53 +0100
> Subject: [PATCH 05/72] h264_parser: expose idr_pic_id
> 
> Vulkan needs it.
> ---
>  libavcodec/h264_parse.h  | 1 +
>  libavcodec/h264_parser.c | 2 +-
>  2 files changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/h264_parse.h b/libavcodec/h264_parse.h
> index 4ee863df66..4ba0add4f2 100644
> --- a/libavcodec/h264_parse.h
> +++ b/libavcodec/h264_parse.h
> @@ -85,6 +85,7 @@ typedef struct H264POCContext {
>      int delta_poc_bottom;
>      int delta_poc[2];
>      int frame_num;
> +    int idr_pic_id;
>      int prev_poc_msb;           ///< poc_msb of the last reference pic for POC type 0
>      int prev_poc_lsb;           ///< poc_lsb of the last reference pic for POC type 0
>      int frame_num_offset;       ///< for POC type 2
> diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
> index 46134a1c48..1c330484c1 100644
> --- a/libavcodec/h264_parser.c
> +++ b/libavcodec/h264_parser.c
> @@ -432,7 +432,7 @@ static inline int parse_nal_units(AVCodecParserContext *s,
>              }
>  
>              if (nal.type == H264_NAL_IDR_SLICE)
> -                get_ue_golomb_long(&nal.gb); /* idr_pic_id */
> +                p->poc.idr_pic_id = get_ue_golomb_long(&nal.gb); /* idr_pic_id */

I don't see how a parser change can be related to anything vulkan.
Anton Khirnov Feb. 20, 2023, 4:56 p.m. UTC | #31
Quoting Lynne (2023-02-17 04:43:50)
> From 1279c6011c610fdb054cd9eea7a6f07c94f69f29 Mon Sep 17 00:00:00 2001
> From: Lynne <dev@lynne.ee>
> Date: Wed, 14 Dec 2022 00:09:08 +0100
> Subject: [PATCH 08/72] h264_ps: expose bit rate and CPB size fields
> 
> ---
>  libavcodec/h264_ps.c | 8 ++++----
>  libavcodec/h264_ps.h | 4 ++++
>  2 files changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c
> index d9df570718..fc8715876a 100644
> --- a/libavcodec/h264_ps.c
> +++ b/libavcodec/h264_ps.c
> @@ -113,12 +113,12 @@ static inline int decode_hrd_parameters(GetBitContext *gb, void *logctx,
>          return AVERROR_INVALIDDATA;
>      }
>  
> -    get_bits(gb, 4); /* bit_rate_scale */
> +    sps->bit_rate_scale = get_bits(gb, 4);
>      get_bits(gb, 4); /* cpb_size_scale */
>      for (i = 0; i < cpb_count; i++) {
> -        get_ue_golomb_long(gb); /* bit_rate_value_minus1 */
> -        get_ue_golomb_long(gb); /* cpb_size_value_minus1 */
> -        get_bits1(gb);          /* cbr_flag */
> +        sps->bit_rate_value[i] = get_ue_golomb_long(gb) + 1; /* bit_rate_value_minus1 + 1 */
> +        sps->cpb_size_value[i] = get_ue_golomb_long(gb) + 1; /* cpb_size_value_minus1 + 1 */
> +        sps->cpr_flag[i]       = get_bits1(gb);
>      }
>      sps->initial_cpb_removal_delay_length = get_bits(gb, 5) + 1;
>      sps->cpb_removal_delay_length         = get_bits(gb, 5) + 1;
> diff --git a/libavcodec/h264_ps.h b/libavcodec/h264_ps.h
> index 906bab7214..03bd0227d6 100644
> --- a/libavcodec/h264_ps.h
> +++ b/libavcodec/h264_ps.h
> @@ -89,6 +89,10 @@ typedef struct SPS {
>      int pic_struct_present_flag;
>      int time_offset_length;
>      int cpb_cnt;                          ///< See H.264 E.1.2
> +    int bit_rate_scale;
> +    uint32_t bit_rate_value[32];          ///< bit_rate_value_minus1 + 1
> +    uint32_t cpb_size_value[32];          ///< cpb_size_value_minus1 + 1
> +    uint8_t cpr_flag[32];

If only there was a way to store 32 flags in less than 32 bytes.
Anton Khirnov Feb. 20, 2023, 5:21 p.m. UTC | #32
Quoting Lynne (2023-02-17 04:43:50)
> From 52ab3cd8d165a838be92189c87c54915efc1c7e5 Mon Sep 17 00:00:00 2001
> From: Lynne <dev@lynne.ee>
> Date: Wed, 11 Jan 2023 05:20:32 +0100
> Subject: [PATCH 10/72] h264dec: track picture_structure in H264Picture
> 
> ---
>  libavcodec/h264_picture.c | 1 +
>  libavcodec/h264_slice.c   | 1 +
>  libavcodec/h264dec.h      | 1 +
>  3 files changed, 3 insertions(+)
> 
> diff --git a/libavcodec/h264_picture.c b/libavcodec/h264_picture.c
> index 2661ff4698..0348166c43 100644
> --- a/libavcodec/h264_picture.c
> +++ b/libavcodec/h264_picture.c
> @@ -80,6 +80,7 @@ static void h264_copy_picture_params(H264Picture *dst, const H264Picture *src)
>      dst->mbaff         = src->mbaff;
>      dst->field_picture = src->field_picture;
>      dst->reference     = src->reference;
> +    dst->picture_structure = src->picture_structure;
>      dst->recovered     = src->recovered;
>      dst->invalid_gap   = src->invalid_gap;
>      dst->sei_recovery_frame_cnt = src->sei_recovery_frame_cnt;
> diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
> index 6188c74632..8ac66b343c 100644
> --- a/libavcodec/h264_slice.c
> +++ b/libavcodec/h264_slice.c
> @@ -491,6 +491,7 @@ static int h264_frame_start(H264Context *h)
>      pic->reference              = h->droppable ? 0 : h->picture_structure;
>      pic->f->coded_picture_number = h->coded_picture_number++;
>      pic->field_picture          = h->picture_structure != PICT_FRAME;
> +    pic->picture_structure       = h->picture_structure;

How does this make sense? picture_structure in slice header tells you
whether you're currently decoding a frame or a field, but a decoded
H264Picture is always a full frame (i.e. two fields).

This code marks field-coded pictures as whatever the second coded field
was.
Anton Khirnov Feb. 20, 2023, 5:40 p.m. UTC | #33
Quoting Lynne (2023-02-17 04:43:50)
> From 4645f1fb3249f8249fdebaf9b3edffc848b9af3c Mon Sep 17 00:00:00 2001
> From: Lynne <dev@lynne.ee>
> Date: Wed, 14 Dec 2022 00:18:42 +0100
> Subject: [PATCH 17/72] hevc_ps: expose and parse scc range extension fields
> 
> ---
>  libavcodec/hevc.h    |  2 ++
>  libavcodec/hevc_ps.c | 63 ++++++++++++++++++++++++++++++++++++++++----
>  libavcodec/hevc_ps.h | 26 ++++++++++++++++++
>  3 files changed, 86 insertions(+), 5 deletions(-)
> 
> diff --git a/libavcodec/hevc.h b/libavcodec/hevc.h
> index 1804755327..913c7d4e2e 100644
> --- a/libavcodec/hevc.h
> +++ b/libavcodec/hevc.h
> @@ -154,6 +154,8 @@ enum {
>      // get near that, though, so set a lower limit here with the maximum
>      // possible value for 4K video (at most 135 16x16 Ctb rows).
>      HEVC_MAX_ENTRY_POINT_OFFSETS = HEVC_MAX_TILE_COLUMNS * 135,
> +
> +    HEVC_PREDICTOR_PALETTE_COMP_ENTRIES_LIST_SIZE = 128,
>  };
>  
>  
> diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
> index a740da9f82..b03f59efef 100644
> --- a/libavcodec/hevc_ps.c
> +++ b/libavcodec/hevc_ps.c
> @@ -856,7 +856,7 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
>      int ret = 0;
>      int log2_diff_max_min_transform_block_size;
>      int bit_depth_chroma, start;
> -    int i;
> +    int i, j;
>  
>      // Coded parameters
>  
> @@ -1077,9 +1077,12 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
>      if (sps->vui_present)
>          decode_vui(gb, avctx, apply_defdispwin, sps);
>  
> -    if (get_bits1(gb)) { // sps_extension_flag
> +    sps->sps_extension_present_flag = get_bits1(gb);
> +    if (sps->sps_extension_present_flag) { // sps_extension_flag

// department of redundancy department called

>          sps->sps_range_extension_flag = get_bits1(gb);
> -        skip_bits(gb, 7); //sps_extension_7bits = get_bits(gb, 7);
> +        skip_bits(gb, 2);
> +        sps->sps_scc_extension_flag = get_bits1(gb);
> +        skip_bits(gb, 4);
>          if (sps->sps_range_extension_flag) {
>              sps->transform_skip_rotation_enabled_flag = get_bits1(gb);
>              sps->transform_skip_context_enabled_flag  = get_bits1(gb);
> @@ -1105,6 +1108,26 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
>                  av_log(avctx, AV_LOG_WARNING,
>                     "cabac_bypass_alignment_enabled_flag not yet implemented\n");
>          }
> +        if (sps->sps_scc_extension_flag) {
> +            sps->sps_curr_pic_ref_enabled_flag = get_bits1(gb);
> +            sps->palette_mode_enabled_flag = get_bits1(gb);
> +            if (sps->palette_mode_enabled_flag) {
> +                sps->palette_max_size = get_ue_golomb_long(gb);
> +                sps->delta_palette_max_predictor_size = get_ue_golomb_long(gb);
> +
> +                sps->sps_palette_predictor_initializer_present_flag = get_bits1(gb);
> +                if (sps->sps_palette_predictor_initializer_present_flag) {
> +                    sps->sps_num_palette_predictor_initializer_minus1 = get_ue_golomb_long(gb);
> +                    for (i = 0; i < (sps->chroma_format_idc ? 3 : 1); i++) {
> +                        for (j = 0; j <= sps->sps_num_palette_predictor_initializer_minus1; j++)
> +                            sps->palette_predictor_initializers[i][j] = get_ue_golomb_long(gb);
> +                    }
> +                }
> +            }
> +
> +            sps->motion_vector_resolution_control_idc = get_bits(gb, 2);
> +            sps->intra_boundary_filtering_disable_flag = get_bits1(gb);
> +        }
>      }
>      if (apply_defdispwin) {
>          sps->output_window.left_offset   += sps->vui.def_disp_win.left_offset;
> @@ -1446,7 +1469,7 @@ int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx,
>                             HEVCParamSets *ps)
>  {
>      HEVCSPS      *sps = NULL;
> -    int i, ret = 0;
> +    int i, j, ret = 0;
>      unsigned int pps_id = 0;
>      ptrdiff_t nal_size;
>      unsigned log2_parallel_merge_level_minus2;
> @@ -1664,11 +1687,41 @@ int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx,
>      pps->pps_extension_present_flag = get_bits1(gb);
>      if (pps->pps_extension_present_flag) {
>          pps->pps_range_extensions_flag = get_bits1(gb);
> -        skip_bits(gb, 7); // pps_extension_7bits
> +        skip_bits(gb, 2);
> +        pps->pps_scc_extension_flag = get_bits1(gb);
> +        skip_bits(gb, 4);
>          if (sps->ptl.general_ptl.profile_idc == FF_PROFILE_HEVC_REXT && pps->pps_range_extensions_flag) {
>              if ((ret = pps_range_extensions(gb, avctx, pps, sps)) < 0)
>                  goto err;
>          }
> +        if (pps->pps_scc_extension_flag) {
> +            pps->pps_curr_pic_ref_enabled_flag = get_bits1(gb);
> +            pps->residual_adaptive_colour_transform_enabled_flag = get_bits1(gb);
> +
> +            if (pps->residual_adaptive_colour_transform_enabled_flag) {
> +                pps->pps_slice_act_qp_offsets_present_flag = get_bits1(gb);
> +                pps->pps_act_y_qp_offset_plus5 = get_se_golomb(gb);
> +                pps->pps_act_cb_qp_offset_plus5 = get_se_golomb(gb);
> +                pps->pps_act_cr_qp_offset_plus3 = get_se_golomb(gb);
> +            }
> +
> +            pps->pps_palette_predictor_initializer_present_flag = get_bits1(gb);
> +            if (pps->pps_palette_predictor_initializer_present_flag) {
> +                pps->pps_num_palette_predictor_initializer = get_ue_golomb_long(gb);
> +                if (pps->pps_num_palette_predictor_initializer) {
> +                    pps->monochrome_palette_flag = get_bits1(gb);
> +                    pps->luma_bit_depth_entry_minus8 = get_ue_golomb_long(gb);
> +
> +                    if (!pps->monochrome_palette_flag)
> +                        pps->chroma_bit_depth_entry_minus8 = get_ue_golomb_long(gb);
> +
> +                    for (i = 0; i < (pps->monochrome_palette_flag ? 1 : 3); i++) {
> +                        for (j = 0; j < pps->pps_num_palette_predictor_initializer; j++)

You're allowed to declare loop variables inside loops now.

> +                            pps->palette_predictor_initializers[i][j] = get_ue_golomb_long(gb);
> +                    }
> +                }
> +            }
> +        }
>      }
>  
>      ret = setup_pps(avctx, gb, pps, sps);
> diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h
> index 549e0bdf57..8dddf7ef8d 100644
> --- a/libavcodec/hevc_ps.h
> +++ b/libavcodec/hevc_ps.h
> @@ -210,6 +210,18 @@ typedef struct HEVCSPS {
>      VUI vui;
>      PTL ptl;
>  
> +    int sps_extension_present_flag;
> +    int sps_scc_extension_flag;
> +    int sps_curr_pic_ref_enabled_flag;
> +    int palette_mode_enabled_flag;
> +    uint8_t palette_max_size;
> +    uint8_t delta_palette_max_predictor_size;
> +    uint8_t motion_vector_resolution_control_idc;
> +    uint8_t sps_num_palette_predictor_initializer_minus1;
> +    int sps_palette_predictor_initializer_present_flag;
> +    int intra_boundary_filtering_disable_flag;
> +    uint16_t palette_predictor_initializers[3][HEVC_PREDICTOR_PALETTE_COMP_ENTRIES_LIST_SIZE];
> +
>      uint8_t scaling_list_enable_flag;
>      int scaling_list_data_present_flag;
>      ScalingList scaling_list;
> @@ -341,6 +353,20 @@ typedef struct HEVCPPS {
>      uint8_t log2_sao_offset_scale_luma;
>      uint8_t log2_sao_offset_scale_chroma;
>  
> +    int pps_scc_extension_flag;
> +    int pps_curr_pic_ref_enabled_flag;
> +    int residual_adaptive_colour_transform_enabled_flag;
> +    int pps_slice_act_qp_offsets_present_flag;
> +    int pps_palette_predictor_initializer_present_flag;
> +    int pps_num_palette_predictor_initializer;
> +    int monochrome_palette_flag;
> +    int luma_bit_depth_entry_minus8;
> +    int chroma_bit_depth_entry_minus8;
> +    int pps_act_y_qp_offset_plus5;
> +    int pps_act_cb_qp_offset_plus5;
> +    int pps_act_cr_qp_offset_plus3;

All those pps_ and sps_ and prefices are redundant pleonasms and make the
code more cluttered.

The _plusminus100500 are quite annoying too.
diff mbox

Patch

From d47cb5940bc4808fea572b530eb1b9bf11159540 Mon Sep 17 00:00:00 2001
From: Lynne <dev@lynne.ee>
Date: Wed, 14 Dec 2022 08:27:18 +0100
Subject: [PATCH 72/72] hevcdec: add Vulkan hwaccel

Thanks to Dave Airlie for figuring out a lot of the parameters.
---
 configure                |   2 +
 libavcodec/Makefile      |   1 +
 libavcodec/hevcdec.c     |  27 +-
 libavcodec/hwaccels.h    |   1 +
 libavcodec/vulkan_hevc.c | 904 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 934 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/vulkan_hevc.c

diff --git a/configure b/configure
index 60973c38b3..8f7b918565 100755
--- a/configure
+++ b/configure
@@ -3050,6 +3050,8 @@  hevc_vdpau_hwaccel_deps="vdpau VdpPictureInfoHEVC"
 hevc_vdpau_hwaccel_select="hevc_decoder"
 hevc_videotoolbox_hwaccel_deps="videotoolbox"
 hevc_videotoolbox_hwaccel_select="hevc_decoder"
+hevc_vulkan_hwaccel_deps="vulkan"
+hevc_vulkan_hwaccel_select="hevc_decoder"
 mjpeg_nvdec_hwaccel_deps="nvdec"
 mjpeg_nvdec_hwaccel_select="mjpeg_decoder"
 mjpeg_vaapi_hwaccel_deps="vaapi"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 4c9db167a5..6aa304071a 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -999,6 +999,7 @@  OBJS-$(CONFIG_HEVC_NVDEC_HWACCEL)         += nvdec_hevc.o
 OBJS-$(CONFIG_HEVC_QSV_HWACCEL)           += qsvdec.o
 OBJS-$(CONFIG_HEVC_VAAPI_HWACCEL)         += vaapi_hevc.o h265_profile_level.o
 OBJS-$(CONFIG_HEVC_VDPAU_HWACCEL)         += vdpau_hevc.o h265_profile_level.o
+OBJS-$(CONFIG_HEVC_VULKAN_HWACCEL)        += vulkan_decode.o vulkan_hevc.o
 OBJS-$(CONFIG_MJPEG_NVDEC_HWACCEL)        += nvdec_mjpeg.o
 OBJS-$(CONFIG_MJPEG_VAAPI_HWACCEL)        += vaapi_mjpeg.o
 OBJS-$(CONFIG_MPEG1_NVDEC_HWACCEL)        += nvdec_mpeg12.o
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 5df831688c..0ad6418f8d 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -405,7 +405,8 @@  static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
                      CONFIG_HEVC_NVDEC_HWACCEL + \
                      CONFIG_HEVC_VAAPI_HWACCEL + \
                      CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL + \
-                     CONFIG_HEVC_VDPAU_HWACCEL)
+                     CONFIG_HEVC_VDPAU_HWACCEL + \
+                     CONFIG_HEVC_VULKAN_HWACCEL)
     enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts;
 
     switch (sps->pix_fmt) {
@@ -429,6 +430,9 @@  static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
 #endif
 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
         *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
+#endif
+#if CONFIG_HEVC_VULKAN_HWACCEL
+        *fmt++ = AV_PIX_FMT_VULKAN;
 #endif
         break;
     case AV_PIX_FMT_YUV420P10:
@@ -445,6 +449,9 @@  static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
         *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
 #endif
+#if CONFIG_HEVC_VULKAN_HWACCEL
+        *fmt++ = AV_PIX_FMT_VULKAN;
+#endif
 #if CONFIG_HEVC_VDPAU_HWACCEL
         *fmt++ = AV_PIX_FMT_VDPAU;
 #endif
@@ -464,6 +471,9 @@  static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
 #endif
 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
         *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
+#endif
+#if CONFIG_HEVC_VULKAN_HWACCEL
+        *fmt++ = AV_PIX_FMT_VULKAN;
 #endif
         break;
     case AV_PIX_FMT_YUV422P:
@@ -473,11 +483,17 @@  static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
 #endif
 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
         *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
+#endif
+#if CONFIG_HEVC_VULKAN_HWACCEL
+        *fmt++ = AV_PIX_FMT_VULKAN;
 #endif
         break;
     case AV_PIX_FMT_YUV444P10:
 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
         *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
+#endif
+#if CONFIG_HEVC_VULKAN_HWACCEL
+        *fmt++ = AV_PIX_FMT_VULKAN;
 #endif
     case AV_PIX_FMT_YUV420P12:
     case AV_PIX_FMT_YUV444P12:
@@ -487,6 +503,9 @@  static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
 #if CONFIG_HEVC_VDPAU_HWACCEL
         *fmt++ = AV_PIX_FMT_VDPAU;
 #endif
+#if CONFIG_HEVC_VULKAN_HWACCEL
+        *fmt++ = AV_PIX_FMT_VULKAN;
+#endif
 #if CONFIG_HEVC_NVDEC_HWACCEL
         *fmt++ = AV_PIX_FMT_CUDA;
 #endif
@@ -494,6 +513,9 @@  static enum AVPixelFormat get_format(HEVCContext *s, const HEVCSPS *sps)
     case AV_PIX_FMT_YUV422P12:
 #if CONFIG_HEVC_VAAPI_HWACCEL
        *fmt++ = AV_PIX_FMT_VAAPI;
+#endif
+#if CONFIG_HEVC_VULKAN_HWACCEL
+        *fmt++ = AV_PIX_FMT_VULKAN;
 #endif
         break;
     }
@@ -3752,6 +3774,9 @@  const FFCodec ff_hevc_decoder = {
 #endif
 #if CONFIG_HEVC_VIDEOTOOLBOX_HWACCEL
                                HWACCEL_VIDEOTOOLBOX(hevc),
+#endif
+#if CONFIG_HEVC_VULKAN_HWACCEL
+                               HWACCEL_VULKAN(hevc),
 #endif
                                NULL
                            },
diff --git a/libavcodec/hwaccels.h b/libavcodec/hwaccels.h
index 23d0843c76..a7c74d07cb 100644
--- a/libavcodec/hwaccels.h
+++ b/libavcodec/hwaccels.h
@@ -44,6 +44,7 @@  extern const AVHWAccel ff_hevc_nvdec_hwaccel;
 extern const AVHWAccel ff_hevc_vaapi_hwaccel;
 extern const AVHWAccel ff_hevc_vdpau_hwaccel;
 extern const AVHWAccel ff_hevc_videotoolbox_hwaccel;
+extern const AVHWAccel ff_hevc_vulkan_hwaccel;
 extern const AVHWAccel ff_mjpeg_nvdec_hwaccel;
 extern const AVHWAccel ff_mjpeg_vaapi_hwaccel;
 extern const AVHWAccel ff_mpeg1_nvdec_hwaccel;
diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c
new file mode 100644
index 0000000000..f4991d8f82
--- /dev/null
+++ b/libavcodec/vulkan_hevc.c
@@ -0,0 +1,904 @@ 
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "hevcdec.h"
+#include "hevc_ps.h"
+
+#include "vulkan_decode.h"
+
+const VkExtensionProperties ff_vk_dec_hevc_ext = {
+    .extensionName = VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_EXTENSION_NAME,
+    .specVersion   = VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_SPEC_VERSION,
+};
+
+typedef struct HEVCHeaderSPS {
+    StdVideoH265ScalingLists scaling;
+    StdVideoH265HrdParameters vui_header;
+    StdVideoH265SequenceParameterSetVui vui;
+    StdVideoH265ProfileTierLevel ptl;
+    StdVideoH265DecPicBufMgr dpbm;
+    StdVideoH265PredictorPaletteEntries pal;
+    StdVideoH265SubLayerHrdParameters nal_hdr[HEVC_MAX_SUB_LAYERS];
+    StdVideoH265SubLayerHrdParameters vcl_hdr[HEVC_MAX_SUB_LAYERS];
+    StdVideoH265ShortTermRefPicSet str[HEVC_MAX_SHORT_TERM_REF_PIC_SETS];
+    StdVideoH265LongTermRefPicsSps ltr[HEVC_MAX_LONG_TERM_REF_PICS];
+} HEVCHeaderSPS;
+
+typedef struct HEVCHeaderPPS {
+    StdVideoH265ScalingLists scaling;
+    StdVideoH265PredictorPaletteEntries pal;
+} HEVCHeaderPPS;
+
+typedef struct HEVCHeaderVPSSet {
+    StdVideoH265SubLayerHrdParameters nal_hdr[HEVC_MAX_SUB_LAYERS];
+    StdVideoH265SubLayerHrdParameters vcl_hdr[HEVC_MAX_SUB_LAYERS];
+} HEVCHeaderVPSSet;
+
+typedef struct HEVCHeaderVPS {
+    StdVideoH265ProfileTierLevel ptl;
+    StdVideoH265DecPicBufMgr dpbm;
+    StdVideoH265HrdParameters hdr[HEVC_MAX_LAYER_SETS];
+    HEVCHeaderVPSSet sls[];
+} HEVCHeaderVPS;
+
+typedef struct HEVCHeaderSet {
+    StdVideoH265SequenceParameterSet sps[HEVC_MAX_SPS_COUNT];
+    HEVCHeaderSPS hsps[HEVC_MAX_SPS_COUNT];
+
+    StdVideoH265PictureParameterSet pps[HEVC_MAX_PPS_COUNT];
+    HEVCHeaderPPS hpps[HEVC_MAX_PPS_COUNT];
+
+    StdVideoH265VideoParameterSet vps[HEVC_MAX_PPS_COUNT];
+    HEVCHeaderVPS hvps[];
+} HEVCHeaderSet;
+
+static int get_data_set_buf(FFVulkanDecodeContext *s, AVBufferRef **data_buf,
+                            int nb_vps, AVBufferRef * const vps_list[HEVC_MAX_VPS_COUNT])
+{
+    size_t buf_size = sizeof(HEVCHeaderSPS)*HEVC_MAX_SPS_COUNT +
+                      sizeof(HEVCHeaderPPS)*HEVC_MAX_PPS_COUNT +
+                      sizeof(StdVideoH265SequenceParameterSet)*HEVC_MAX_SPS_COUNT +
+                      sizeof(StdVideoH265PictureParameterSet)*HEVC_MAX_PPS_COUNT +
+                      sizeof(StdVideoH265VideoParameterSet)*HEVC_MAX_VPS_COUNT;
+
+    buf_size += (sizeof(StdVideoH265ProfileTierLevel) +
+                 sizeof(StdVideoH265DecPicBufMgr) +
+                 sizeof(StdVideoH265HrdParameters)*HEVC_MAX_LAYER_SETS)*nb_vps;
+
+    for (int i = 0; i < nb_vps; i++) {
+        const HEVCVPS *vps = (const HEVCVPS *)vps_list[i]->data;
+        buf_size += sizeof(HEVCHeaderVPSSet)*vps->vps_num_hrd_parameters;
+    }
+
+    if (buf_size > s->tmp_pool_ele_size) {
+        av_buffer_pool_uninit(&s->tmp_pool);
+        s->tmp_pool_ele_size = 0;
+        s->tmp_pool = av_buffer_pool_init(buf_size, NULL);
+        if (!s->tmp_pool)
+            return AVERROR(ENOMEM);
+        s->tmp_pool_ele_size = buf_size;
+    }
+
+    *data_buf = av_buffer_pool_get(s->tmp_pool);
+    if (!(*data_buf))
+        return AVERROR(ENOMEM);
+
+    return 0;
+}
+
+typedef struct HEVCVulkanDecodePicture {
+    FFVulkanDecodeContext          *ctx;
+    FFVulkanDecodePicture           vp;
+
+    /* Current picture */
+    StdVideoDecodeH265ReferenceInfo h265_ref;
+    VkVideoDecodeH265DpbSlotInfoKHR vkh265_ref;
+
+    /* Picture refs */
+    HEVCFrame                      *ref_src    [HEVC_MAX_REFS];
+    StdVideoDecodeH265ReferenceInfo h265_refs  [HEVC_MAX_REFS];
+    VkVideoDecodeH265DpbSlotInfoKHR vkh265_refs[HEVC_MAX_REFS];
+
+    /* Current picture (contd.) */
+    StdVideoDecodeH265PictureInfo   h265pic;
+    VkVideoDecodeH265PictureInfoKHR h265_pic_info;
+} HEVCVulkanDecodePicture;
+
+static int vk_hevc_fill_pict(AVCodecContext *avctx, HEVCFrame **ref_src,
+                             VkVideoReferenceSlotInfoKHR *ref_slot,       /* Main structure */
+                             VkVideoPictureResourceInfoKHR *ref,          /* Goes in ^ */
+                             VkVideoDecodeH265DpbSlotInfoKHR *vkh265_ref, /* Goes in ^ */
+                             StdVideoDecodeH265ReferenceInfo *h265_ref,   /* Goes in ^ */
+                             HEVCFrame *pic, int is_current, int pic_id)
+{
+    FFVulkanDecodeContext *ctx = avctx->internal->hwaccel_priv_data;
+    HEVCVulkanDecodePicture *hp = pic->hwaccel_picture_private;
+    FFVulkanDecodePicture *vkpic = &hp->vp;
+
+    int err = ff_vk_decode_prepare_frame(ctx, pic->frame, vkpic, is_current,
+                                         ctx->dedicated_dpb);
+    if (err < 0)
+        return err;
+
+    *h265_ref = (StdVideoDecodeH265ReferenceInfo) {
+        .flags = (StdVideoDecodeH265ReferenceInfoFlags) {
+            .used_for_long_term_reference = pic->flags & HEVC_FRAME_FLAG_LONG_REF,
+            .unused_for_reference = 0,
+        },
+        .PicOrderCntVal = pic->poc,
+    };
+
+    *vkh265_ref = (VkVideoDecodeH265DpbSlotInfoKHR) {
+        .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_H265_DPB_SLOT_INFO_KHR,
+        .pStdReferenceInfo = h265_ref,
+    };
+
+    *ref = (VkVideoPictureResourceInfoKHR) {
+        .sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,
+        .codedOffset = (VkOffset2D){ 0, 0 },
+        .codedExtent = (VkExtent2D){ pic->frame->width, pic->frame->height },
+        .baseArrayLayer = ctx->layered_dpb ? pic_id : 0,
+        .imageViewBinding = vkpic->img_view_ref,
+    };
+
+    *ref_slot = (VkVideoReferenceSlotInfoKHR) {
+        .sType = VK_STRUCTURE_TYPE_VIDEO_REFERENCE_SLOT_INFO_KHR,
+        .pNext = vkh265_ref,
+        .slotIndex = pic_id,
+        .pPictureResource = ref,
+    };
+
+    if (ref_src)
+        *ref_src = pic;
+
+    return 0;
+}
+
+static void set_sps(const HEVCSPS *sps, int sps_idx,
+                    StdVideoH265ScalingLists *vksps_scaling,
+                    StdVideoH265HrdParameters *vksps_vui_header,
+                    StdVideoH265SequenceParameterSetVui *vksps_vui,
+                    StdVideoH265SequenceParameterSet *vksps,
+                    StdVideoH265SubLayerHrdParameters *slhdrnal,
+                    StdVideoH265SubLayerHrdParameters *slhdrvcl,
+                    StdVideoH265ProfileTierLevel *ptl,
+                    StdVideoH265DecPicBufMgr *dpbm,
+                    StdVideoH265PredictorPaletteEntries *pal,
+                    StdVideoH265ShortTermRefPicSet *str,
+                    StdVideoH265LongTermRefPicsSps *ltr)
+{
+    for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_4X4_NUM_LISTS; i++)
+        memcpy(vksps_scaling->ScalingList4x4[i], sps->scaling_list.sl[0][i],
+               STD_VIDEO_H265_SCALING_LIST_4X4_NUM_ELEMENTS * sizeof(**vksps_scaling->ScalingList4x4));
+
+    for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_8X8_NUM_LISTS; i++)
+        memcpy(vksps_scaling->ScalingList8x8[i], sps->scaling_list.sl[1][i],
+               STD_VIDEO_H265_SCALING_LIST_8X8_NUM_ELEMENTS * sizeof(**vksps_scaling->ScalingList8x8));
+
+    for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_16X16_NUM_LISTS; i++)
+        memcpy(vksps_scaling->ScalingList16x16[i], sps->scaling_list.sl[2][i],
+               STD_VIDEO_H265_SCALING_LIST_4X4_NUM_ELEMENTS * sizeof(**vksps_scaling->ScalingList16x16));
+
+    for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_32X32_NUM_LISTS; i++)
+        memcpy(vksps_scaling->ScalingList32x32[i], sps->scaling_list.sl[3][i],
+               STD_VIDEO_H265_SCALING_LIST_32X32_NUM_ELEMENTS * sizeof(**vksps_scaling->ScalingList32x32));
+
+    memcpy(vksps_scaling->ScalingListDCCoef16x16, sps->scaling_list.sl_dc[0],
+           STD_VIDEO_H265_SCALING_LIST_4X4_NUM_ELEMENTS * sizeof(*vksps_scaling->ScalingListDCCoef16x16));
+
+    memcpy(vksps_scaling->ScalingListDCCoef32x32, sps->scaling_list.sl_dc[1],
+           STD_VIDEO_H265_SCALING_LIST_32X32_NUM_ELEMENTS * sizeof(*vksps_scaling->ScalingListDCCoef32x32));
+
+    *vksps_vui_header = (StdVideoH265HrdParameters) {
+        .flags = (StdVideoH265HrdFlags) {
+            .nal_hrd_parameters_present_flag = sps->hdr.flags.nal_hrd_parameters_present_flag,
+            .vcl_hrd_parameters_present_flag = sps->hdr.flags.vcl_hrd_parameters_present_flag,
+            .sub_pic_hrd_params_present_flag = sps->hdr.flags.sub_pic_hrd_params_present_flag,
+            .sub_pic_cpb_params_in_pic_timing_sei_flag = sps->hdr.flags.sub_pic_cpb_params_in_pic_timing_sei_flag,
+            .fixed_pic_rate_general_flag = sps->hdr.flags.fixed_pic_rate_general_flag,
+            .fixed_pic_rate_within_cvs_flag = sps->hdr.flags.fixed_pic_rate_within_cvs_flag,
+            .low_delay_hrd_flag = sps->hdr.flags.low_delay_hrd_flag,
+        },
+        .tick_divisor_minus2 = sps->hdr.tick_divisor_minus2,
+        .du_cpb_removal_delay_increment_length_minus1 = sps->hdr.du_cpb_removal_delay_increment_length_minus1,
+        .dpb_output_delay_du_length_minus1 = sps->hdr.dpb_output_delay_du_length_minus1,
+        .bit_rate_scale = sps->hdr.bit_rate_scale,
+        .cpb_size_scale = sps->hdr.cpb_size_scale,
+        .cpb_size_du_scale = sps->hdr.cpb_size_du_scale,
+        .initial_cpb_removal_delay_length_minus1 = sps->hdr.initial_cpb_removal_delay_length_minus1,
+        .au_cpb_removal_delay_length_minus1 = sps->hdr.au_cpb_removal_delay_length_minus1,
+        .dpb_output_delay_length_minus1 = sps->hdr.dpb_output_delay_length_minus1,
+        /* Reserved - 3*16 bits */
+        .pSubLayerHrdParametersNal = slhdrnal,
+        .pSubLayerHrdParametersNal = slhdrvcl,
+    };
+
+    memcpy(vksps_vui_header->cpb_cnt_minus1, sps->hdr.cpb_cnt_minus1,
+           STD_VIDEO_H265_SUBLAYERS_LIST_SIZE*sizeof(*vksps_vui_header->cpb_cnt_minus1));
+    memcpy(vksps_vui_header->elemental_duration_in_tc_minus1, sps->hdr.elemental_duration_in_tc_minus1,
+           STD_VIDEO_H265_SUBLAYERS_LIST_SIZE*sizeof(*vksps_vui_header->elemental_duration_in_tc_minus1));
+
+    memcpy(slhdrnal, sps->hdr.nal_params, HEVC_MAX_SUB_LAYERS*sizeof(*slhdrnal));
+    memcpy(slhdrvcl, sps->hdr.vcl_params, HEVC_MAX_SUB_LAYERS*sizeof(*slhdrvcl));
+
+    *vksps_vui = (StdVideoH265SequenceParameterSetVui) {
+        .flags = (StdVideoH265SpsVuiFlags) {
+            .aspect_ratio_info_present_flag = sps->vui.common.aspect_ratio_info_present_flag,
+            .overscan_info_present_flag = sps->vui.common.overscan_info_present_flag,
+            .overscan_appropriate_flag = sps->vui.common.overscan_appropriate_flag,
+            .video_signal_type_present_flag = sps->vui.common.video_signal_type_present_flag,
+            .video_full_range_flag = sps->vui.common.video_full_range_flag,
+            .colour_description_present_flag = sps->vui.common.colour_description_present_flag,
+            .chroma_loc_info_present_flag = sps->vui.common.chroma_loc_info_present_flag,
+            .neutral_chroma_indication_flag = sps->vui.neutra_chroma_indication_flag,
+            .field_seq_flag = sps->vui.field_seq_flag,
+            .frame_field_info_present_flag = sps->vui.frame_field_info_present_flag,
+            .default_display_window_flag = sps->vui.default_display_window_flag,
+            .vui_timing_info_present_flag = sps->vui.vui_timing_info_present_flag,
+            .vui_poc_proportional_to_timing_flag = sps->vui.vui_poc_proportional_to_timing_flag,
+            .vui_hrd_parameters_present_flag = sps->vui.vui_hrd_parameters_present_flag,
+            .bitstream_restriction_flag = sps->vui.bitstream_restriction_flag,
+            .tiles_fixed_structure_flag = sps->vui.tiles_fixed_structure_flag,
+            .motion_vectors_over_pic_boundaries_flag = sps->vui.motion_vectors_over_pic_boundaries_flag,
+            .restricted_ref_pic_lists_flag = sps->vui.restricted_ref_pic_lists_flag,
+        },
+        .aspect_ratio_idc = sps->vui.common.aspect_ratio_idc,
+        .sar_width = sps->vui.common.sar.num,
+        .sar_height = sps->vui.common.sar.den,
+        .video_format = sps->vui.common.video_format,
+        .colour_primaries = sps->vui.common.colour_primaries,
+        .transfer_characteristics = sps->vui.common.transfer_characteristics,
+        .matrix_coeffs = sps->vui.common.matrix_coeffs,
+        .chroma_sample_loc_type_top_field = sps->vui.common.chroma_sample_loc_type_top_field,
+        .chroma_sample_loc_type_bottom_field = sps->vui.common.chroma_sample_loc_type_bottom_field,
+        /* Reserved */
+        /* Reserved */
+        .def_disp_win_left_offset = sps->vui.def_disp_win.left_offset,
+        .def_disp_win_right_offset = sps->vui.def_disp_win.right_offset,
+        .def_disp_win_top_offset = sps->vui.def_disp_win.top_offset,
+        .def_disp_win_bottom_offset = sps->vui.def_disp_win.bottom_offset,
+        .vui_num_units_in_tick = sps->vui.vui_num_units_in_tick,
+        .vui_time_scale = sps->vui.vui_time_scale,
+        .vui_num_ticks_poc_diff_one_minus1 = sps->vui.vui_num_ticks_poc_diff_one_minus1,
+        .min_spatial_segmentation_idc = sps->vui.min_spatial_segmentation_idc,
+        .max_bytes_per_pic_denom = sps->vui.max_bytes_per_pic_denom,
+        .max_bits_per_min_cu_denom = sps->vui.max_bits_per_min_cu_denom,
+        .log2_max_mv_length_horizontal = sps->vui.log2_max_mv_length_horizontal,
+        .log2_max_mv_length_vertical = sps->vui.log2_max_mv_length_vertical,
+        .pHrdParameters = vksps_vui_header,
+    };
+
+    *ptl = (StdVideoH265ProfileTierLevel) {
+        .flags = (StdVideoH265ProfileTierLevelFlags) {
+            .general_tier_flag = sps->ptl.general_ptl.tier_flag,
+            .general_progressive_source_flag = sps->ptl.general_ptl.progressive_source_flag,
+            .general_interlaced_source_flag = sps->ptl.general_ptl.interlaced_source_flag,
+            .general_non_packed_constraint_flag = sps->ptl.general_ptl.non_packed_constraint_flag,
+            .general_frame_only_constraint_flag = sps->ptl.general_ptl.frame_only_constraint_flag,
+        },
+        .general_profile_idc = sps->ptl.general_ptl.profile_idc,
+        .general_level_idc = sps->ptl.general_ptl.level_idc,
+    };
+
+    for (int i = 0; i < sps->max_sub_layers; i++) {
+        dpbm->max_latency_increase_plus1[i] = sps->temporal_layer[i].max_latency_increase + 1;
+        dpbm->max_dec_pic_buffering_minus1[i] = sps->temporal_layer[i].max_dec_pic_buffering - 1;
+        dpbm->max_num_reorder_pics[i] = sps->temporal_layer[i].num_reorder_pics;
+    }
+
+    for (int i = 0; i < (sps->chroma_format_idc ? 3 : 1); i++)
+        for (int j = 0; j <= sps->sps_num_palette_predictor_initializer_minus1; j++)
+            pal->PredictorPaletteEntries[i][j] = sps->palette_predictor_initializers[i][j];
+
+    for (int i = 0; i < sps->nb_st_rps; i++) {
+        str[i] = (StdVideoH265ShortTermRefPicSet) {
+            .flags = (StdVideoH265ShortTermRefPicSetFlags) {
+                .inter_ref_pic_set_prediction_flag = sps->st_rps[i].rps_predict,
+                .delta_rps_sign = sps->st_rps[i].delta_rps_sign,
+            },
+            .delta_idx_minus1 = sps->st_rps[i].delta_idx - 1,
+            .use_delta_flag = sps->st_rps[i].use_delta_flag,
+            .abs_delta_rps_minus1 = sps->st_rps[i].abs_delta_rps - 1,
+            /* Spec fucked this up
+            .used_by_curr_pic_flag =
+            .used_by_curr_pic_s0_flag =
+            .used_by_curr_pic_s1_flag =
+            */
+            /* Reserved */
+            /* Reserved */
+            /* Reserved */
+            .num_negative_pics = sps->st_rps[i].num_negative_pics,
+            .num_positive_pics = sps->st_rps[i].num_delta_pocs - sps->st_rps[i].num_negative_pics,
+        };
+
+        for (int j = 0; j < str[i].num_negative_pics; j++)
+            str[i].delta_poc_s0_minus1[j] = sps->st_rps[i].delta_poc_s0[j] - 1;
+
+        for (int j = 0; j < str[i].num_positive_pics; j++)
+            str[i].delta_poc_s1_minus1[j] = sps->st_rps[i].delta_poc_s1[j] - 1;
+    }
+
+    for (int i = 0; i < sps->num_long_term_ref_pics_sps; i++) {
+        ltr[i] = (StdVideoH265LongTermRefPicsSps) {
+            .used_by_curr_pic_lt_sps_flag = sps->used_by_curr_pic_lt_sps_flag[i],
+            /* Spec fucked this up too*/
+            .lt_ref_pic_poc_lsb_sps[0] = sps->lt_ref_pic_poc_lsb_sps[i],
+        };
+    }
+
+    *vksps = (StdVideoH265SequenceParameterSet) {
+        .flags = (StdVideoH265SpsFlags) {
+            .sps_temporal_id_nesting_flag = sps->temporal_id_nesting_flag,
+            .separate_colour_plane_flag = sps->separate_colour_plane_flag,
+            .conformance_window_flag = sps->conformance_window_flag,
+            .sps_sub_layer_ordering_info_present_flag = sps->sublayer_ordering_info_flag,
+            .scaling_list_enabled_flag = sps->scaling_list_enable_flag,
+            .sps_scaling_list_data_present_flag = sps->scaling_list_data_present_flag,
+            .amp_enabled_flag = sps->amp_enabled_flag,
+            .sample_adaptive_offset_enabled_flag = sps->sao_enabled,
+            .pcm_enabled_flag = sps->pcm_enabled_flag,
+            .pcm_loop_filter_disabled_flag = sps->pcm.loop_filter_disable_flag,
+            .long_term_ref_pics_present_flag = sps->long_term_ref_pics_present_flag,
+            .sps_temporal_mvp_enabled_flag = sps->sps_temporal_mvp_enabled_flag,
+            .strong_intra_smoothing_enabled_flag = sps->sps_strong_intra_smoothing_enable_flag,
+            .vui_parameters_present_flag = sps->vui_present,
+            .sps_extension_present_flag = sps->sps_extension_present_flag,
+            .sps_range_extension_flag = sps->sps_range_extension_flag,
+            .transform_skip_rotation_enabled_flag = sps->transform_skip_rotation_enabled_flag,
+            .transform_skip_context_enabled_flag = sps->transform_skip_context_enabled_flag,
+            .implicit_rdpcm_enabled_flag = sps->implicit_rdpcm_enabled_flag,
+            .explicit_rdpcm_enabled_flag = sps->explicit_rdpcm_enabled_flag,
+            .extended_precision_processing_flag = sps->extended_precision_processing_flag,
+            .intra_smoothing_disabled_flag = sps->intra_smoothing_disabled_flag,
+            .high_precision_offsets_enabled_flag = sps->high_precision_offsets_enabled_flag,
+            .persistent_rice_adaptation_enabled_flag = sps->persistent_rice_adaptation_enabled_flag,
+            .cabac_bypass_alignment_enabled_flag = sps->cabac_bypass_alignment_enabled_flag,
+            .sps_scc_extension_flag = sps->sps_scc_extension_flag,
+            .sps_curr_pic_ref_enabled_flag = sps->sps_curr_pic_ref_enabled_flag,
+            .palette_mode_enabled_flag = sps->palette_mode_enabled_flag,
+            .sps_palette_predictor_initializers_present_flag = sps->sps_palette_predictor_initializer_present_flag,
+            .intra_boundary_filtering_disabled_flag = sps->intra_boundary_filtering_disable_flag,
+        },
+        .chroma_format_idc = sps->chroma_format_idc,
+        .pic_width_in_luma_samples = sps->width,
+        .pic_height_in_luma_samples = sps->height,
+        .sps_video_parameter_set_id = sps->vps_id,
+        .sps_max_sub_layers_minus1 = sps->max_sub_layers - 1,
+        .sps_seq_parameter_set_id = sps_idx,
+        .bit_depth_luma_minus8 = sps->bit_depth - 8,
+        .bit_depth_chroma_minus8 = sps->bit_depth_chroma - 8,
+        .log2_max_pic_order_cnt_lsb_minus4 = sps->log2_max_poc_lsb - 4,
+        .log2_min_luma_coding_block_size_minus3 = sps->log2_min_cb_size - 3,
+        .log2_diff_max_min_luma_coding_block_size = sps->log2_diff_max_min_coding_block_size,
+        .log2_min_luma_transform_block_size_minus2 = sps->log2_min_tb_size - 2,
+        .log2_diff_max_min_luma_transform_block_size = sps->log2_diff_max_min_transform_block_size,
+        .max_transform_hierarchy_depth_inter = sps->max_transform_hierarchy_depth_inter,
+        .max_transform_hierarchy_depth_intra = sps->max_transform_hierarchy_depth_intra,
+        .num_short_term_ref_pic_sets = sps->nb_st_rps,
+        .num_long_term_ref_pics_sps = sps->num_long_term_ref_pics_sps,
+        .pcm_sample_bit_depth_luma_minus1 = sps->pcm.bit_depth - 1,
+        .pcm_sample_bit_depth_chroma_minus1 = sps->pcm.bit_depth_chroma - 1,
+        .log2_min_pcm_luma_coding_block_size_minus3 = sps->pcm.log2_min_pcm_cb_size - 3,
+        .log2_diff_max_min_pcm_luma_coding_block_size = sps->pcm.log2_max_pcm_cb_size - sps->pcm.log2_min_pcm_cb_size,
+        /* Reserved */
+        /* Reserved */
+        .palette_max_size = sps->palette_max_size,
+        .delta_palette_max_predictor_size = sps->delta_palette_max_predictor_size,
+        .motion_vector_resolution_control_idc = sps->motion_vector_resolution_control_idc,
+        .sps_num_palette_predictor_initializers_minus1 = sps->sps_num_palette_predictor_initializer_minus1,
+        .conf_win_left_offset = sps->pic_conf_win.left_offset,
+        .conf_win_right_offset = sps->pic_conf_win.right_offset,
+        .conf_win_top_offset = sps->pic_conf_win.top_offset,
+        .conf_win_bottom_offset = sps->pic_conf_win.bottom_offset,
+        .pProfileTierLevel = ptl,
+        .pDecPicBufMgr = dpbm,
+        .pScalingLists = vksps_scaling,
+        .pShortTermRefPicSet = str,
+        .pLongTermRefPicsSps = ltr,
+        .pSequenceParameterSetVui = vksps_vui,
+        .pPredictorPaletteEntries = pal,
+    };
+}
+
+static void set_pps(const HEVCPPS *pps, const HEVCSPS *sps,
+                    StdVideoH265ScalingLists *vkpps_scaling,
+                    StdVideoH265PictureParameterSet *vkpps,
+                    StdVideoH265PredictorPaletteEntries *pal)
+{
+    for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_4X4_NUM_LISTS; i++)
+        memcpy(vkpps_scaling->ScalingList4x4[i], pps->scaling_list.sl[0][i],
+               STD_VIDEO_H265_SCALING_LIST_4X4_NUM_ELEMENTS * sizeof(**vkpps_scaling->ScalingList4x4));
+
+    for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_8X8_NUM_LISTS; i++)
+        memcpy(vkpps_scaling->ScalingList8x8[i], pps->scaling_list.sl[1][i],
+               STD_VIDEO_H265_SCALING_LIST_8X8_NUM_ELEMENTS * sizeof(**vkpps_scaling->ScalingList8x8));
+
+    for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_16X16_NUM_LISTS; i++)
+        memcpy(vkpps_scaling->ScalingList16x16[i], pps->scaling_list.sl[2][i],
+               STD_VIDEO_H265_SCALING_LIST_4X4_NUM_ELEMENTS * sizeof(**vkpps_scaling->ScalingList16x16));
+
+    for (int i = 0; i < STD_VIDEO_H265_SCALING_LIST_32X32_NUM_LISTS; i++)
+        memcpy(vkpps_scaling->ScalingList32x32[i], pps->scaling_list.sl[3][i],
+               STD_VIDEO_H265_SCALING_LIST_32X32_NUM_ELEMENTS * sizeof(**vkpps_scaling->ScalingList32x32));
+
+    memcpy(vkpps_scaling->ScalingListDCCoef16x16, pps->scaling_list.sl_dc[0],
+           STD_VIDEO_H265_SCALING_LIST_4X4_NUM_ELEMENTS * sizeof(*vkpps_scaling->ScalingListDCCoef16x16));
+
+    memcpy(vkpps_scaling->ScalingListDCCoef32x32, pps->scaling_list.sl_dc[1],
+           STD_VIDEO_H265_SCALING_LIST_32X32_NUM_ELEMENTS * sizeof(*vkpps_scaling->ScalingListDCCoef32x32));
+
+    *vkpps = (StdVideoH265PictureParameterSet) {
+        .flags = (StdVideoH265PpsFlags) {
+            .dependent_slice_segments_enabled_flag = pps->dependent_slice_segments_enabled_flag,
+            .output_flag_present_flag = pps->output_flag_present_flag,
+            .sign_data_hiding_enabled_flag = pps->sign_data_hiding_flag,
+            .cabac_init_present_flag = pps->cabac_init_present_flag,
+            .constrained_intra_pred_flag = pps->constrained_intra_pred_flag,
+            .transform_skip_enabled_flag = pps->transform_skip_enabled_flag,
+            .cu_qp_delta_enabled_flag = pps->cu_qp_delta_enabled_flag,
+            .pps_slice_chroma_qp_offsets_present_flag = pps->pic_slice_level_chroma_qp_offsets_present_flag,
+            .weighted_pred_flag = pps->weighted_pred_flag,
+            .weighted_bipred_flag = pps->weighted_bipred_flag,
+            .transquant_bypass_enabled_flag = pps->transquant_bypass_enable_flag,
+            .tiles_enabled_flag = pps->tiles_enabled_flag,
+            .entropy_coding_sync_enabled_flag = pps->entropy_coding_sync_enabled_flag,
+            .uniform_spacing_flag = pps->uniform_spacing_flag,
+            .loop_filter_across_tiles_enabled_flag = pps->loop_filter_across_tiles_enabled_flag,
+            .pps_loop_filter_across_slices_enabled_flag = pps->seq_loop_filter_across_slices_enabled_flag,
+            .deblocking_filter_control_present_flag = pps->deblocking_filter_control_present_flag,
+            .deblocking_filter_override_enabled_flag = pps->deblocking_filter_override_enabled_flag,
+            .pps_deblocking_filter_disabled_flag = pps->disable_dbf,
+            .pps_scaling_list_data_present_flag = pps->scaling_list_data_present_flag,
+            .lists_modification_present_flag = pps->lists_modification_present_flag,
+            .slice_segment_header_extension_present_flag = pps->slice_header_extension_present_flag,
+            .pps_extension_present_flag = pps->pps_extension_present_flag,
+            .cross_component_prediction_enabled_flag = pps->cross_component_prediction_enabled_flag,
+            .chroma_qp_offset_list_enabled_flag = pps->chroma_qp_offset_list_enabled_flag,
+            .pps_curr_pic_ref_enabled_flag = pps->pps_curr_pic_ref_enabled_flag,
+            .residual_adaptive_colour_transform_enabled_flag = pps->residual_adaptive_colour_transform_enabled_flag,
+            .pps_slice_act_qp_offsets_present_flag = pps->pps_slice_act_qp_offsets_present_flag,
+            .pps_palette_predictor_initializers_present_flag = pps->pps_palette_predictor_initializer_present_flag,
+            .monochrome_palette_flag = pps->monochrome_palette_flag,
+            .pps_range_extension_flag = pps->pps_range_extensions_flag,
+        },
+        .pps_pic_parameter_set_id = pps->pps_id,
+        .pps_seq_parameter_set_id = pps->sps_id,
+        .sps_video_parameter_set_id = sps->vps_id,
+        .num_extra_slice_header_bits = pps->num_extra_slice_header_bits,
+        .num_ref_idx_l0_default_active_minus1 = pps->num_ref_idx_l0_default_active - 1,
+        .num_ref_idx_l1_default_active_minus1 = pps->num_ref_idx_l1_default_active - 1,
+        .init_qp_minus26 = pps->pic_init_qp_minus26,
+        .diff_cu_qp_delta_depth = pps->diff_cu_qp_delta_depth,
+        .pps_cb_qp_offset = pps->cb_qp_offset,
+        .pps_cr_qp_offset = pps->cr_qp_offset,
+        .pps_beta_offset_div2 = pps->beta_offset >> 1,
+        .pps_tc_offset_div2 = pps->tc_offset >> 1,
+        .log2_parallel_merge_level_minus2 = pps->log2_parallel_merge_level - 2,
+        .log2_max_transform_skip_block_size_minus2 = pps->log2_max_transform_skip_block_size - 2,
+        .diff_cu_chroma_qp_offset_depth = pps->diff_cu_chroma_qp_offset_depth,
+        .chroma_qp_offset_list_len_minus1 = pps->chroma_qp_offset_list_len_minus1,
+        .log2_sao_offset_scale_luma = pps->log2_sao_offset_scale_luma,
+        .log2_sao_offset_scale_chroma = pps->log2_sao_offset_scale_chroma,
+        .pps_act_y_qp_offset_plus5 = pps->pps_act_y_qp_offset_plus5,
+        .pps_act_cb_qp_offset_plus5 = pps->pps_act_cb_qp_offset_plus5,
+        .pps_act_cr_qp_offset_plus3 = pps->pps_act_cr_qp_offset_plus3,
+        .pps_num_palette_predictor_initializers = pps->pps_num_palette_predictor_initializer,
+        .luma_bit_depth_entry_minus8 = pps->luma_bit_depth_entry_minus8,
+        .chroma_bit_depth_entry_minus8 = pps->chroma_bit_depth_entry_minus8,
+        .num_tile_columns_minus1 = pps->num_tile_columns - 1,
+        .num_tile_rows_minus1 = pps->num_tile_rows - 1,
+        .pScalingLists = vkpps_scaling,
+        .pPredictorPaletteEntries = pal,
+    };
+
+    for (int i = 0; i < (pps->monochrome_palette_flag ? 1 : 3); i++) {
+        for (int j = 0; j < pps->pps_num_palette_predictor_initializer; j++)
+            pal->PredictorPaletteEntries[i][j] = pps->palette_predictor_initializers[i][j];
+    }
+
+    for (int i = 0; i < pps->num_tile_columns - 1; i++)
+        vkpps->column_width_minus1[i] = pps->column_width[i] - 1;
+
+    for (int i = 0; i < pps->num_tile_rows - 1; i++)
+        vkpps->row_height_minus1[i] = pps->row_height[i] - 1;
+
+    for (int i = 0; i <= pps->chroma_qp_offset_list_len_minus1; i++) {
+        vkpps->cb_qp_offset_list[i] = pps->cb_qp_offset_list[i];
+        vkpps->cr_qp_offset_list[i] = pps->cr_qp_offset_list[i];
+    }
+}
+
+static void set_vps(const HEVCVPS *vps,
+                    StdVideoH265VideoParameterSet *vkvps,
+                    StdVideoH265ProfileTierLevel *ptl,
+                    StdVideoH265DecPicBufMgr *dpbm,
+                    StdVideoH265HrdParameters *sls_hdr,
+                    HEVCHeaderVPSSet sls[])
+{
+    for (int i = 0; i < vps->vps_num_hrd_parameters; i++) {
+        const HEVCHdrParams *src = &vps->hdr[i];
+
+        sls_hdr[i] = (StdVideoH265HrdParameters) {
+            .flags = (StdVideoH265HrdFlags) {
+                .nal_hrd_parameters_present_flag = src->flags.nal_hrd_parameters_present_flag,
+                .vcl_hrd_parameters_present_flag = src->flags.vcl_hrd_parameters_present_flag,
+                .sub_pic_hrd_params_present_flag = src->flags.sub_pic_hrd_params_present_flag,
+                .sub_pic_cpb_params_in_pic_timing_sei_flag = src->flags.sub_pic_cpb_params_in_pic_timing_sei_flag,
+                .fixed_pic_rate_general_flag = src->flags.fixed_pic_rate_general_flag,
+                .fixed_pic_rate_within_cvs_flag = src->flags.fixed_pic_rate_within_cvs_flag,
+                .low_delay_hrd_flag = src->flags.low_delay_hrd_flag,
+            },
+            .tick_divisor_minus2 = src->tick_divisor_minus2,
+            .du_cpb_removal_delay_increment_length_minus1 = src->du_cpb_removal_delay_increment_length_minus1,
+            .dpb_output_delay_du_length_minus1 = src->dpb_output_delay_du_length_minus1,
+            .bit_rate_scale = src->bit_rate_scale,
+            .cpb_size_scale = src->cpb_size_scale,
+            .cpb_size_du_scale = src->cpb_size_du_scale,
+            .initial_cpb_removal_delay_length_minus1 = src->initial_cpb_removal_delay_length_minus1,
+            .au_cpb_removal_delay_length_minus1 = src->au_cpb_removal_delay_length_minus1,
+            .dpb_output_delay_length_minus1 = src->dpb_output_delay_length_minus1,
+            /* Reserved - 3*16 bits */
+            .pSubLayerHrdParametersNal = sls[i].nal_hdr,
+            .pSubLayerHrdParametersNal = sls[i].vcl_hdr,
+        };
+
+        memcpy(sls_hdr[i].cpb_cnt_minus1, src->cpb_cnt_minus1,
+               STD_VIDEO_H265_SUBLAYERS_LIST_SIZE*sizeof(*sls_hdr[i].cpb_cnt_minus1));
+        memcpy(sls_hdr[i].elemental_duration_in_tc_minus1, src->elemental_duration_in_tc_minus1,
+               STD_VIDEO_H265_SUBLAYERS_LIST_SIZE*sizeof(*sls_hdr[i].elemental_duration_in_tc_minus1));
+
+        memcpy(sls[i].nal_hdr, src->nal_params, HEVC_MAX_SUB_LAYERS*sizeof(*sls[i].nal_hdr));
+        memcpy(sls[i].vcl_hdr, src->vcl_params, HEVC_MAX_SUB_LAYERS*sizeof(*sls[i].vcl_hdr));
+    }
+
+    *ptl = (StdVideoH265ProfileTierLevel) {
+        .flags = (StdVideoH265ProfileTierLevelFlags) {
+            .general_tier_flag = vps->ptl.general_ptl.tier_flag,
+            .general_progressive_source_flag = vps->ptl.general_ptl.progressive_source_flag,
+            .general_interlaced_source_flag = vps->ptl.general_ptl.interlaced_source_flag,
+            .general_non_packed_constraint_flag = vps->ptl.general_ptl.non_packed_constraint_flag,
+            .general_frame_only_constraint_flag = vps->ptl.general_ptl.frame_only_constraint_flag,
+        },
+        .general_profile_idc = vps->ptl.general_ptl.profile_idc,
+        .general_level_idc = vps->ptl.general_ptl.level_idc,
+    };
+
+    for (int i = 0; i < vps->vps_max_sub_layers; i++) {
+        dpbm->max_latency_increase_plus1[i] = vps->vps_max_latency_increase[i] + 1;
+        dpbm->max_dec_pic_buffering_minus1[i] = vps->vps_max_dec_pic_buffering[i] - 1;
+        dpbm->max_num_reorder_pics[i] = vps->vps_num_reorder_pics[i];
+    }
+
+    *vkvps = (StdVideoH265VideoParameterSet) {
+        .flags = (StdVideoH265VpsFlags) {
+            .vps_temporal_id_nesting_flag = vps->vps_temporal_id_nesting_flag,
+            .vps_sub_layer_ordering_info_present_flag = vps->vps_sub_layer_ordering_info_present_flag,
+            .vps_timing_info_present_flag = vps->vps_timing_info_present_flag,
+            .vps_poc_proportional_to_timing_flag = vps->vps_poc_proportional_to_timing_flag,
+        },
+        .vps_video_parameter_set_id = vps->vps_id,
+        .vps_max_sub_layers_minus1 = vps->vps_max_sub_layers - 1,
+        /* Reserved */
+        /* Reserved */
+        .vps_num_units_in_tick = vps->vps_num_units_in_tick,
+        .vps_time_scale = vps->vps_time_scale,
+        .vps_num_ticks_poc_diff_one_minus1 = vps->vps_num_ticks_poc_diff_one - 1,
+        /* Reserved */
+        .pDecPicBufMgr = dpbm,
+        .pHrdParameters = sls_hdr,
+        .pProfileTierLevel = ptl,
+    };
+}
+
+static int vk_hevc_create_params(AVCodecContext *avctx, AVBufferRef **buf)
+{
+    int err;
+    VkResult ret;
+    const HEVCContext *h = avctx->priv_data;
+    FFVulkanDecodeContext *ctx = avctx->internal->hwaccel_priv_data;
+    FFVulkanFunctions *vk = &ctx->s.vkfn;
+
+    VkVideoDecodeH265SessionParametersAddInfoKHR h265_params_info = {
+        .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_H265_SESSION_PARAMETERS_ADD_INFO_KHR,
+        .stdSPSCount = 0,
+        .stdPPSCount = 0,
+        .stdVPSCount = 0,
+    };
+    VkVideoDecodeH265SessionParametersCreateInfoKHR h265_params = {
+        .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_H265_SESSION_PARAMETERS_CREATE_INFO_KHR,
+        .pParametersAddInfo = &h265_params_info,
+    };
+    VkVideoSessionParametersCreateInfoKHR session_params_create = {
+        .sType = VK_STRUCTURE_TYPE_VIDEO_SESSION_PARAMETERS_CREATE_INFO_KHR,
+        .pNext = &h265_params,
+        .videoSession = ctx->common.session,
+        .videoSessionParametersTemplate = NULL,
+    };
+
+    int nb_vps = 0;
+    AVBufferRef *data_set;
+    HEVCHeaderSet *hdr;
+
+    AVBufferRef *tmp;
+    VkVideoSessionParametersKHR *par = av_malloc(sizeof(*par));
+    if (!par)
+        return AVERROR(ENOMEM);
+
+    for (int i = 0; h->ps.vps_list[i]; i++)
+        nb_vps++;
+
+    err = get_data_set_buf(ctx, &data_set, nb_vps, h->ps.vps_list);
+    if (err < 0)
+        return err;
+
+    hdr = (HEVCHeaderSet *)data_set->data;
+
+    h265_params_info.pStdSPSs = hdr->sps;
+    h265_params_info.pStdPPSs = hdr->pps;
+    h265_params_info.pStdVPSs = hdr->vps;
+
+    /* SPS list */
+    for (int i = 0; h->ps.sps_list[i]; i++) {
+        const HEVCSPS *sps_l = (const HEVCSPS *)h->ps.sps_list[i]->data;
+        set_sps(sps_l, i, &hdr->hsps[i].scaling, &hdr->hsps[i].vui_header,
+                &hdr->hsps[i].vui, &hdr->sps[i], hdr->hsps[i].nal_hdr,
+                hdr->hsps[i].vcl_hdr, &hdr->hsps[i].ptl, &hdr->hsps[i].dpbm,
+                &hdr->hsps[i].pal, hdr->hsps[i].str, hdr->hsps[i].ltr);
+        h265_params_info.stdSPSCount++;
+    }
+
+    /* PPS list */
+    for (int i = 0; h->ps.pps_list[i]; i++) {
+        const HEVCPPS *pps_l = (const HEVCPPS *)h->ps.pps_list[i]->data;
+        const HEVCSPS *sps_l = (const HEVCSPS *)h->ps.sps_list[pps_l->sps_id]->data;
+        set_pps(pps_l, sps_l, &hdr->hpps[i].scaling, &hdr->pps[i], &hdr->hpps[i].pal);
+        h265_params_info.stdPPSCount++;
+    }
+
+    /* VPS list */
+    for (int i = 0; i < nb_vps; i++) {
+        const HEVCVPS *vps_l = (const HEVCVPS *)h->ps.vps_list[i]->data;
+        set_vps(vps_l, &hdr->vps[i], &hdr->hvps[i].ptl, &hdr->hvps[i].dpbm,
+                hdr->hvps[i].hdr, hdr->hvps[i].sls);
+        h265_params_info.stdVPSCount++;
+    }
+
+    h265_params.maxStdSPSCount = h265_params_info.stdSPSCount;
+    h265_params.maxStdPPSCount = h265_params_info.stdPPSCount;
+    h265_params.maxStdVPSCount = h265_params_info.stdVPSCount;
+
+    /* Create session parameters */
+    ret = vk->CreateVideoSessionParametersKHR(ctx->s.hwctx->act_dev, &session_params_create,
+                                              ctx->s.hwctx->alloc, par);
+    av_buffer_unref(&data_set);
+    if (ret != VK_SUCCESS) {
+        av_log(avctx, AV_LOG_ERROR, "Unable to create Vulkan video session parameters: %s!\n",
+               ff_vk_ret2str(ret));
+        return AVERROR_EXTERNAL;
+    }
+
+    tmp = av_buffer_create((uint8_t *)par, sizeof(*par), ff_vk_decode_free_params,
+                           ctx, 0);
+    if (!tmp) {
+        ff_vk_decode_free_params(ctx, (uint8_t *)par);
+        return AVERROR(ENOMEM);
+    }
+
+    av_log(avctx, AV_LOG_DEBUG, "Created frame parameters: %i SPS %i PPS %i VPS\n",
+           h265_params_info.stdSPSCount, h265_params_info.stdPPSCount,
+           h265_params_info.stdVPSCount);
+
+    *buf = tmp;
+
+    return 0;
+}
+
+static int vk_hevc_start_frame(AVCodecContext          *avctx,
+                               av_unused const uint8_t *buffer,
+                               av_unused uint32_t       size)
+{
+    int err;
+    HEVCContext *h = avctx->priv_data;
+    HEVCFrame *pic = h->ref;
+    FFVulkanDecodeContext *ctx = avctx->internal->hwaccel_priv_data;
+    HEVCVulkanDecodePicture *hp = pic->hwaccel_picture_private;
+    FFVulkanDecodePicture *vp = &hp->vp;
+    const HEVCSPS *sps = h->ps.sps;
+    const HEVCPPS *pps = h->ps.pps;
+    int nb_refs = 0;
+
+    if (!h->hwaccel_params_buf) {
+        err = vk_hevc_create_params(avctx, &h->hwaccel_params_buf);
+        if (err < 0)
+            return err;
+    }
+
+    vp->session_params = av_buffer_ref(h->hwaccel_params_buf);
+    if (!vp->session_params)
+        return AVERROR(ENOMEM);
+
+    hp->h265pic = (StdVideoDecodeH265PictureInfo) {
+        .flags = (StdVideoDecodeH265PictureInfoFlags) {
+            .IrapPicFlag = IS_IRAP(h),
+            .IdrPicFlag = IS_IDR(h),
+            .IsReference = h->nal_unit_type < 16 ? h->nal_unit_type & 1 : 1,
+            .short_term_ref_pic_set_sps_flag = h->sh.short_term_ref_pic_set_sps_flag,
+        },
+        .sps_video_parameter_set_id = sps->vps_id,
+        .pps_seq_parameter_set_id = pps->sps_id,
+        .pps_pic_parameter_set_id = pps->pps_id,
+        .NumDeltaPocsOfRefRpsIdx = h->sh.short_term_rps ? h->sh.short_term_rps->rps_idx_num_delta_pocs : 0,
+        .PicOrderCntVal = h->poc,
+        .NumBitsForSTRefPicSetInSlice = !h->sh.short_term_ref_pic_set_sps_flag ?
+                                         h->sh.bits_used_for_short_term_rps : 0,
+    };
+
+    /* Fill in references */
+    for (int i = 0; i < FF_ARRAY_ELEMS(h->DPB); i++) {
+        const HEVCFrame *ref = &h->DPB[i];
+        int idx = nb_refs;
+
+        if (!(ref->flags & (HEVC_FRAME_FLAG_SHORT_REF | HEVC_FRAME_FLAG_LONG_REF)))
+            continue;
+
+        if (ref == pic) {
+            err = vk_hevc_fill_pict(avctx, NULL, &vp->ref_slot, &vp->ref,
+                                    &hp->vkh265_ref, &hp->h265_ref, pic, 1, i);
+            if (err < 0)
+                return err;
+
+            continue;
+        }
+
+        err = vk_hevc_fill_pict(avctx, &hp->ref_src[idx], &vp->ref_slots[idx],
+                                &vp->refs[idx], &hp->vkh265_refs[idx],
+                                &hp->h265_refs[idx], (HEVCFrame *)ref, 0, i);
+        if (err < 0)
+            return err;
+
+        nb_refs++;
+    }
+
+    memset(hp->h265pic.RefPicSetStCurrBefore, 0xff, 8);
+    for (int i = 0; i < h->rps[ST_CURR_BEF].nb_refs; i++) {
+        HEVCFrame *frame = h->rps[ST_CURR_BEF].ref[i];
+        for (int j = 0; j < FF_ARRAY_ELEMS(h->DPB); j++) {
+            const HEVCFrame *ref = &h->DPB[j];
+            if (ref == frame) {
+                hp->h265pic.RefPicSetStCurrBefore[i] = j;
+                break;
+            }
+        }
+    }
+    memset(hp->h265pic.RefPicSetStCurrAfter, 0xff, 8);
+    for (int i = 0; i < h->rps[ST_CURR_AFT].nb_refs; i++) {
+        HEVCFrame *frame = h->rps[ST_CURR_AFT].ref[i];
+        for (int j = 0; j < FF_ARRAY_ELEMS(h->DPB); j++) {
+            const HEVCFrame *ref = &h->DPB[j];
+            if (ref == frame) {
+                hp->h265pic.RefPicSetStCurrAfter[i] = j;
+                break;
+            }
+        }
+    }
+    memset(hp->h265pic.RefPicSetLtCurr, 0xff, 8);
+    for (int i = 0; i < h->rps[LT_CURR].nb_refs; i++) {
+        HEVCFrame *frame = h->rps[LT_CURR].ref[i];
+        for (int j = 0; j < FF_ARRAY_ELEMS(h->DPB); j++) {
+            const HEVCFrame *ref = &h->DPB[j];
+            if (ref == frame) {
+                hp->h265pic.RefPicSetLtCurr[i] = j;
+                break;
+            }
+        }
+    }
+
+    hp->h265_pic_info = (VkVideoDecodeH265PictureInfoKHR) {
+        .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_H265_PICTURE_INFO_KHR,
+        .pStdPictureInfo = &hp->h265pic,
+        .sliceSegmentCount = 0,
+        .pSliceSegmentOffsets = vp->slice_off,
+    };
+
+    vp->decode_info = (VkVideoDecodeInfoKHR) {
+        .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_INFO_KHR,
+        .pNext = &hp->h265_pic_info,
+        .flags = 0x0,
+        .pSetupReferenceSlot = &vp->ref_slot,
+        .referenceSlotCount = nb_refs,
+        .pReferenceSlots = vp->ref_slots,
+        .dstPictureResource = (VkVideoPictureResourceInfoKHR) {
+            .sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,
+            .codedOffset = (VkOffset2D){ 0, 0 },
+            .codedExtent = (VkExtent2D){ pic->frame->width, pic->frame->height },
+            .baseArrayLayer = 0,
+            .imageViewBinding = vp->img_view_out,
+        },
+    };
+
+    hp->ctx = ctx;
+
+    return 0;
+}
+
+static int vk_hevc_decode_slice(AVCodecContext *avctx,
+                                const uint8_t  *data,
+                                uint32_t        size)
+{
+    const HEVCContext *h = avctx->priv_data;
+    HEVCVulkanDecodePicture *hp = h->ref->hwaccel_picture_private;
+    FFVulkanDecodePicture *vp = &hp->vp;
+
+    int err = ff_vk_decode_add_slice(vp, data, size, 1,
+                                     &hp->h265_pic_info.sliceSegmentCount,
+                                     &hp->h265_pic_info.pSliceSegmentOffsets);
+    if (err < 0)
+        return err;
+
+    return 0;
+}
+
+static int vk_hevc_end_frame(AVCodecContext *avctx)
+{
+    const HEVCContext *h = avctx->priv_data;
+    HEVCFrame *pic = h->ref;
+    HEVCVulkanDecodePicture *hp = pic->hwaccel_picture_private;
+    FFVulkanDecodePicture *vp = &hp->vp;
+    FFVulkanDecodePicture *rvp[HEVC_MAX_REFS] = { 0 };
+    AVFrame *rav[HEVC_MAX_REFS] = { 0 };
+
+    for (int i = 0; i < vp->decode_info.referenceSlotCount; i++) {
+        HEVCVulkanDecodePicture *rfhp = hp->ref_src[i]->hwaccel_picture_private;
+        rav[i] = hp->ref_src[i]->frame;
+        rvp[i] = &rfhp->vp;
+    }
+
+    av_log(avctx, AV_LOG_VERBOSE, "Decoding frame, %lu bytes, %i slices\n",
+           vp->slices_size, hp->h265_pic_info.sliceSegmentCount);
+
+    return ff_vk_decode_frame(avctx, pic->frame, vp, rav, rvp);
+}
+
+static void vk_hevc_free_frame_priv(AVCodecContext *avctx, void *data)
+{
+    HEVCVulkanDecodePicture *hp = data;
+
+    /* Free frame resources */
+    ff_vk_decode_free_frame(hp->ctx, &hp->vp);
+
+    /* Free frame context */
+    av_free(hp);
+}
+
+const AVHWAccel ff_hevc_vulkan_hwaccel = {
+    .name                 = "hevc_vulkan",
+    .type                 = AVMEDIA_TYPE_VIDEO,
+    .id                   = AV_CODEC_ID_HEVC,
+    .pix_fmt              = AV_PIX_FMT_VULKAN,
+    .start_frame          = &vk_hevc_start_frame,
+    .decode_slice         = &vk_hevc_decode_slice,
+    .end_frame            = &vk_hevc_end_frame,
+    .free_frame_priv      = &vk_hevc_free_frame_priv,
+    .frame_priv_data_size = sizeof(HEVCVulkanDecodePicture),
+    .init                 = &ff_vk_decode_init,
+    .flush                = &ff_vk_decode_flush,
+    .uninit               = &ff_vk_decode_uninit,
+    .frame_params         = &ff_vk_frame_params,
+    .priv_data_size       = sizeof(FFVulkanDecodeContext),
+    .caps_internal        = HWACCEL_CAP_ASYNC_SAFE | HWACCEL_CAP_THREAD_SAFE,
+};
-- 
2.39.2