xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/d3d12/d3d12_video_encoder_references_manager_av1.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright © Microsoft Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 #ifndef D3D12_VIDEO_ENCODE_FIFO_REFERENCES_MANAGER_AV1_H
25 #define D3D12_VIDEO_ENCODE_FIFO_REFERENCES_MANAGER_AV1_H
26 
27 #include "d3d12_video_types.h"
28 #include "d3d12_video_encoder_references_manager.h"
29 #include "d3d12_video_dpb_storage_manager.h"
30 
31 class d3d12_video_encoder_references_manager_av1 : public d3d12_video_encoder_references_manager_interface
32 {
33  public:
34    void end_frame();
35    void begin_frame(D3D12_VIDEO_ENCODER_PICTURE_CONTROL_CODEC_DATA curFrameData,
36                     bool bUsedAsReference,
37                     struct pipe_picture_desc *picture);
38    D3D12_VIDEO_ENCODER_RECONSTRUCTED_PICTURE get_current_frame_recon_pic_output_allocation();
39    bool get_current_frame_picture_control_data(D3D12_VIDEO_ENCODER_PICTURE_CONTROL_CODEC_DATA &codecAllocation);
40    bool is_current_frame_used_as_reference();
41    D3D12_VIDEO_ENCODE_REFERENCE_FRAMES get_current_reference_frames();
42 
43    d3d12_video_encoder_references_manager_av1(bool gopHasInterCodedFrames,
44                                               d3d12_video_dpb_storage_manager_interface &rDpbStorageManager);
45 
~d3d12_video_encoder_references_manager_av1()46    ~d3d12_video_encoder_references_manager_av1()
47    { }
48 
49  private:
50    // Class helpers
51 
52    void clear_dpb();
53    void refresh_dpb_slots_with_current_frame_reconpic();
54 
55    uint32_t get_dpb_virtual_slot_refcount_from_ref_frame_idx(uint32_t dpbSlotIndex);
56    uint32_t get_dpb_physical_slot_refcount_from_virtual_dpb(uint32_t ReconstructedPictureResourceIndex);
57 
58    void print_virtual_dpb_entries();
59    void print_physical_resource_references();
60    void print_ref_frame_idx();
61 
62    // Class members
63 
64    struct current_frame_references_data
65    {
66       std::vector<D3D12_VIDEO_ENCODER_AV1_REFERENCE_PICTURE_DESCRIPTOR> pVirtualDPBEntries;
67       D3D12_VIDEO_ENCODER_RECONSTRUCTED_PICTURE ReconstructedPicTexture;
68    } m_CurrentFrameReferencesData = {};
69    d3d12_video_dpb_storage_manager_interface &m_PhysicalAllocationsStorage;
70    bool m_gopHasInterFrames = false;
71    bool m_isCurrentFrameUsedAsReference = false;
72    D3D12_VIDEO_ENCODER_AV1_PICTURE_CONTROL_CODEC_DATA m_CurrentFramePicParams = {};
73 
74    // Constants
75    const uint32_t NUM_REF_FRAMES = 8;
76    const uint32_t REFS_PER_FRAME = 7;
77 };
78 
79 #endif
80