• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ENC_H
25 #define D3D12_VIDEO_ENC_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 #include "d3d12_video_encoder_bitstream_builder_h264.h"
31 #include "d3d12_video_encoder_bitstream_builder_hevc.h"
32 #include "d3d12_video_encoder_bitstream_builder_av1.h"
33 #include <list>
34 
35 ///
36 /// Pipe video interface starts
37 ///
38 
39 /**
40  * creates a video encoder
41  */
42 struct pipe_video_codec *
43 d3d12_video_encoder_create_encoder(struct pipe_context *context, const struct pipe_video_codec *templ);
44 
45 /**
46  * destroy this video encoder
47  */
48 void
49 d3d12_video_encoder_destroy(struct pipe_video_codec *codec);
50 
51 /**
52  * start encoding of a new frame
53  */
54 void
55 d3d12_video_encoder_begin_frame(struct pipe_video_codec * codec,
56                                 struct pipe_video_buffer *target,
57                                 struct pipe_picture_desc *picture);
58 
59 /**
60  * encode to a bitstream
61  */
62 void
63 d3d12_video_encoder_encode_bitstream(struct pipe_video_codec * codec,
64                                      struct pipe_video_buffer *source,
65                                      struct pipe_resource *    destination,
66                                      void **                   feedback);
67 
68 int d3d12_video_encoder_get_encode_headers(struct pipe_video_codec *codec,
69                                            struct pipe_picture_desc *picture,
70                                            void* bitstream_buf,
71                                            unsigned *bitstream_buf_size);
72 
73 /**
74  * get encoder feedback
75  */
76 void
77 d3d12_video_encoder_get_feedback(struct pipe_video_codec *codec,
78                                  void *feedback,
79                                  unsigned *size,
80                                  struct pipe_enc_feedback_metadata* pMetadata);
81 
82 /**
83  * end encoding of the current frame
84  */
85 int
86 d3d12_video_encoder_end_frame(struct pipe_video_codec * codec,
87                               struct pipe_video_buffer *target,
88                               struct pipe_picture_desc *picture);
89 
90 /**
91  * flush async any outstanding command buffers to the hardware
92  * and returns to the caller without waiting for completion
93  */
94 void
95 d3d12_video_encoder_flush(struct pipe_video_codec *codec);
96 
97 /**
98  * Waits until the async work from the fenceValue has been completed in the device
99  * and releases the in-flight resources
100  */
101 bool
102 d3d12_video_encoder_sync_completion(struct pipe_video_codec *codec, ID3D12Fence *fence, uint64_t fenceValueToWaitOn, uint64_t timeout_ns);
103 
104 /**
105  * Get feedback fence.
106  */
107 int
108 d3d12_video_encoder_fence_wait(struct pipe_video_codec *codec,
109                                struct pipe_fence_handle *fence,
110                                uint64_t timeout);
111 
112 struct pipe_video_buffer*
113 d3d12_video_create_dpb_buffer(struct pipe_video_codec *codec,
114                               struct pipe_picture_desc *picture,
115                               const struct pipe_video_buffer *templat);
116 
117 ///
118 /// Pipe video interface ends
119 ///
120 
121 enum d3d12_video_encoder_config_dirty_flags
122 {
123    d3d12_video_encoder_config_dirty_flag_none                   = 0x0,
124    d3d12_video_encoder_config_dirty_flag_codec                  = 0x1,
125    d3d12_video_encoder_config_dirty_flag_profile                = 0x2,
126    d3d12_video_encoder_config_dirty_flag_level                  = 0x4,
127    d3d12_video_encoder_config_dirty_flag_codec_config           = 0x8,
128    d3d12_video_encoder_config_dirty_flag_input_format           = 0x10,
129    d3d12_video_encoder_config_dirty_flag_resolution             = 0x20,
130    d3d12_video_encoder_config_dirty_flag_rate_control           = 0x40,
131    d3d12_video_encoder_config_dirty_flag_slices                 = 0x80,
132    d3d12_video_encoder_config_dirty_flag_gop                    = 0x100,
133    d3d12_video_encoder_config_dirty_flag_motion_precision_limit = 0x200,
134    d3d12_video_encoder_config_dirty_flag_sequence_header        = 0x400,
135    d3d12_video_encoder_config_dirty_flag_intra_refresh          = 0x800,
136    d3d12_video_encoder_config_dirty_flag_video_header           = 0x1000,
137    d3d12_video_encoder_config_dirty_flag_picture_header         = 0x2000,
138    d3d12_video_encoder_config_dirty_flag_aud_header             = 0x4000,
139    d3d12_video_encoder_config_dirty_flag_sei_header             = 0x8000,
140    d3d12_video_encoder_config_dirty_flag_svcprefix_slice_header = 0x10000,
141 };
142 DEFINE_ENUM_FLAG_OPERATORS(d3d12_video_encoder_config_dirty_flags);
143 
144 ///
145 /// d3d12_video_encoder functions starts
146 ///
147 
148 struct D3D12EncodeCapabilities
149 {
150    bool m_fArrayOfTexturesDpb = false;
151 
152    D3D12_VIDEO_ENCODER_SUPPORT_FLAGS                          m_SupportFlags = {};
153    D3D12_VIDEO_ENCODER_VALIDATION_FLAGS                       m_ValidationFlags = {};
154    D3D12_FEATURE_DATA_VIDEO_ENCODER_RESOLUTION_SUPPORT_LIMITS m_currentResolutionSupportCaps = {};
155    union
156    {
157       D3D12_VIDEO_ENCODER_PROFILE_H264 m_H264Profile;
158       D3D12_VIDEO_ENCODER_PROFILE_HEVC m_HEVCProfile;
159       D3D12_VIDEO_ENCODER_AV1_PROFILE  m_AV1Profile;
160    } m_encoderSuggestedProfileDesc = {};
161 
162    union
163    {
164       D3D12_VIDEO_ENCODER_LEVELS_H264                 m_H264LevelSetting;
165       D3D12_VIDEO_ENCODER_LEVEL_TIER_CONSTRAINTS_HEVC m_HEVCLevelSetting;
166       D3D12_VIDEO_ENCODER_AV1_LEVEL_TIER_CONSTRAINTS  m_AV1LevelSetting;
167    } m_encoderLevelSuggestedDesc = {};
168 
169    struct
170    {
171       union{
172          D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_H264 m_H264CodecCaps;
173          D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_SUPPORT_HEVC1 m_HEVCCodecCaps;
174          D3D12_VIDEO_ENCODER_AV1_CODEC_CONFIGURATION_SUPPORT  m_AV1CodecCaps;
175       };
176       D3D12_VIDEO_ENCODER_AV1_FRAME_SUBREGION_LAYOUT_CONFIG_SUPPORT m_AV1TileCaps;
177       D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAGS RequiredNotRequestedFeatureFlags;
178    } m_encoderCodecSpecificConfigCaps = {};
179 
180    // The maximum number of slices that the output of the current frame to be encoded will contain
181    uint32_t m_MaxSlicesInOutput = 0;
182 
183    D3D12_FEATURE_DATA_VIDEO_ENCODER_RESOURCE_REQUIREMENTS m_ResourceRequirementsCaps = {};
184 
185 };
186 
187 struct D3D12EncodeRateControlState
188 {
189    D3D12_VIDEO_ENCODER_RATE_CONTROL_MODE  m_Mode = {};
190    D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAGS m_Flags = {};
191    uint64_t max_frame_size = 0;
192    DXGI_RATIONAL                          m_FrameRate = {};
193    union
194    {
195       D3D12_VIDEO_ENCODER_RATE_CONTROL_CQP  m_Configuration_CQP;
196       D3D12_VIDEO_ENCODER_RATE_CONTROL_CBR  m_Configuration_CBR;
197       D3D12_VIDEO_ENCODER_RATE_CONTROL_VBR  m_Configuration_VBR;
198       D3D12_VIDEO_ENCODER_RATE_CONTROL_QVBR m_Configuration_QVBR;
199       D3D12_VIDEO_ENCODER_RATE_CONTROL_CQP1  m_Configuration_CQP1;
200       D3D12_VIDEO_ENCODER_RATE_CONTROL_CBR1  m_Configuration_CBR1;
201       D3D12_VIDEO_ENCODER_RATE_CONTROL_VBR1  m_Configuration_VBR1;
202       D3D12_VIDEO_ENCODER_RATE_CONTROL_QVBR1 m_Configuration_QVBR1;
203    } m_Config;
204 
205    // AV1 uses 16 bit integers, H26x uses 8 bit integers
206    std::vector<int8_t> m_pRateControlQPMap8Bit;
207    std::vector<int16_t> m_pRateControlQPMap16Bit;
208 };
209 
210 struct D3D12EncodeConfiguration
211 {
212    d3d12_video_encoder_config_dirty_flags m_ConfigDirtyFlags = d3d12_video_encoder_config_dirty_flag_none;
213 
214    D3D12_VIDEO_ENCODER_PICTURE_RESOLUTION_DESC m_currentResolution = {};
215    D3D12_BOX m_FrameCroppingCodecConfig = {};
216 
217    D3D12_FEATURE_DATA_FORMAT_INFO m_encodeFormatInfo = {};
218 
219    D3D12_VIDEO_ENCODER_CODEC m_encoderCodecDesc = {};
220 
221    D3D12_VIDEO_ENCODER_SEQUENCE_CONTROL_FLAGS m_seqFlags = D3D12_VIDEO_ENCODER_SEQUENCE_CONTROL_FLAG_NONE;
222 
223    /// As the following D3D12 Encode types have pointers in their structures, we need to keep a deep copy of them
224 
225    union
226    {
227       D3D12_VIDEO_ENCODER_PROFILE_H264 m_H264Profile;
228       D3D12_VIDEO_ENCODER_PROFILE_HEVC m_HEVCProfile;
229       D3D12_VIDEO_ENCODER_AV1_PROFILE  m_AV1Profile;
230    } m_encoderProfileDesc = {};
231 
232    union
233    {
234       D3D12_VIDEO_ENCODER_LEVELS_H264                 m_H264LevelSetting;
235       D3D12_VIDEO_ENCODER_LEVEL_TIER_CONSTRAINTS_HEVC m_HEVCLevelSetting;
236       D3D12_VIDEO_ENCODER_AV1_LEVEL_TIER_CONSTRAINTS  m_AV1LevelSetting;
237    } m_encoderLevelDesc = {};
238 
239    struct D3D12EncodeRateControlState m_encoderRateControlDesc[D3D12_VIDEO_ENC_MAX_RATE_CONTROL_TEMPORAL_LAYERS] = {};
240    UINT m_activeRateControlIndex = 0;
241 
242    union
243    {
244       D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_H264 m_H264Config;
245       D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_HEVC m_HEVCConfig;
246       D3D12_VIDEO_ENCODER_AV1_CODEC_CONFIGURATION  m_AV1Config;
247    } m_encoderCodecSpecificConfigDesc = {};
248 
249 
250    D3D12_VIDEO_ENCODER_FRAME_SUBREGION_LAYOUT_MODE m_encoderSliceConfigMode = {};
251    union
252    {
253       D3D12_VIDEO_ENCODER_PICTURE_CONTROL_SUBREGIONS_LAYOUT_DATA_SLICES m_SlicesPartition_H264;
254       D3D12_VIDEO_ENCODER_PICTURE_CONTROL_SUBREGIONS_LAYOUT_DATA_SLICES m_SlicesPartition_HEVC;
255       struct {
256          D3D12_VIDEO_ENCODER_AV1_PICTURE_CONTROL_SUBREGIONS_LAYOUT_DATA_TILES TilesPartition;
257          uint8_t TilesGroupsCount;
258          av1_tile_group_t TilesGroups[128];
259       } m_TilesConfig_AV1;
260    } m_encoderSliceConfigDesc = {};
261 
262    union
263    {
264       D3D12_VIDEO_ENCODER_SEQUENCE_GOP_STRUCTURE_H264 m_H264GroupOfPictures;
265       D3D12_VIDEO_ENCODER_SEQUENCE_GOP_STRUCTURE_HEVC m_HEVCGroupOfPictures;
266       D3D12_VIDEO_ENCODER_AV1_SEQUENCE_STRUCTURE m_AV1SequenceStructure;
267    } m_encoderGOPConfigDesc = {};
268 
269    union
270    {
271       D3D12_VIDEO_ENCODER_PICTURE_CONTROL_CODEC_DATA_H264 m_H264PicData;
272       D3D12_VIDEO_ENCODER_PICTURE_CONTROL_CODEC_DATA_HEVC1 m_HEVCPicData;
273       D3D12_VIDEO_ENCODER_AV1_PICTURE_CONTROL_CODEC_DATA m_AV1PicData;
274    } m_encoderPicParamsDesc = {};
275 
276    D3D12_VIDEO_ENCODER_MOTION_ESTIMATION_PRECISION_MODE m_encoderMotionPrecisionLimit =
277       D3D12_VIDEO_ENCODER_MOTION_ESTIMATION_PRECISION_MODE_MAXIMUM;
278 
279    D3D12_VIDEO_ENCODER_INTRA_REFRESH m_IntraRefresh = { D3D12_VIDEO_ENCODER_INTRA_REFRESH_MODE_NONE, 0 };
280    uint32_t                          m_IntraRefreshCurrentFrameIndex = 0;
281 
282    struct D3D12AV1CodecSpecificState
283    {
284       std::list<UINT/*PictureIndex*/> pendingShowableFrames;
285    } m_encoderCodecSpecificStateDescAV1;
286 
287    struct pipe_h264_enc_seq_param m_encoderCodecSpecificSequenceStateDescH264;
288    struct pipe_h265_enc_seq_param m_encoderCodecSpecificSequenceStateDescH265;
289    struct pipe_h265_enc_vid_param m_encoderCodecSpecificVideoStateDescH265;
290    struct pipe_h265_enc_pic_param m_encoderCodecSpecificPictureStateDescH265;
291 
292    bool m_bUsedAsReference; // Set if frame will be used as reference frame
293 };
294 
295 struct EncodedBitstreamResolvedMetadata
296 {
297    ComPtr<ID3D12Resource> spBuffer;
298    uint64_t bufferSize = 0;
299 
300    ComPtr<ID3D12Resource> m_spMetadataOutputBuffer;
301    /*
302    * We need to store a snapshot of the encoder state
303    * below as when get_feedback processes this other
304    * async queued frames might have changed it
305    */
306 
307    /*
308    * byte size of pre encode uploaded bitstream headers
309    * We need it in metadata as will be read in get_feedback
310    * to calculate the final size while other async encode
311    * operations (with potentially different headers) are being
312    * encoded in the GPU
313    */
314    uint64_t preEncodeGeneratedHeadersByteSize = 0;
315    uint64_t preEncodeGeneratedHeadersBytePadding = 0;
316    std::vector<uint64_t> pWrittenCodecUnitsSizes;
317 
318    /*
319    * Indicates if the encoded frame needs header generation after GPU execution
320    * If false, preEncodeGeneratedHeadersByteSize indicates the size of the generated
321    * headers (if any)
322    *
323    * If true, indicates the headers must be generated at get_feedback time.
324    */
325    bool postEncodeHeadersNeeded = false;
326 
327    /* Indicates if the current metadata has been read by get_feedback */
328    bool bRead = true;
329 
330    /* associated encoded frame state snapshot*/
331    struct D3D12EncodeCapabilities m_associatedEncodeCapabilities = {};
332    struct D3D12EncodeConfiguration m_associatedEncodeConfig = {};
333 
334    /*
335    * Associated frame compressed bitstream buffer
336    * If needed get_feedback will have to generate
337    * headers and re-pack the compressed bitstream
338    */
339    pipe_resource* comp_bit_destination;
340 
341    /*
342    * Staging bitstream for when headers must be
343    * packed in get_feedback, it contains the encoded
344    * stream from EncodeFrame.
345    */
346    ComPtr<ID3D12Resource> spStagingBitstream;
347 
348    /* codec specific associated configuration flags */
349    union {
350       struct {
351          bool enable_frame_obu;
352          bool obu_has_size_field;
353          bool temporal_delim_rendered;
354       } AV1HeadersInfo;
355    } m_CodecSpecificData;
356 
357    /*
358    * Scratch CPU buffer memory to generate any extra headers
359    * in between the GPU spStagingBitstream contents
360    */
361    std::vector<uint8_t> m_StagingBitstreamConstruction;
362 
363    /* Stores encode result for get_feedback readback in the D3D12_VIDEO_ENC_METADATA_BUFFERS_COUNT slots */
364    enum pipe_video_feedback_encode_result_flags encode_result = PIPE_VIDEO_FEEDBACK_METADATA_ENCODE_FLAG_OK;
365 
366    /* Expected max frame, slice sizes */
367    uint64_t expected_max_frame_size = 0;
368    uint64_t expected_max_slice_size = 0;
369 
370    /* Pending fence data for this frame */
371    struct d3d12_fence m_FenceData;
372 };
373 
374 enum d3d12_video_encoder_driver_workarounds
375 {
376    d3d12_video_encoder_driver_workaround_none = 0x0,
377    // Workaround for drivers supporting rate control reconfiguration but not reporting it
378    // and having issues with encoder state/heap objects recreation
379    d3d12_video_encoder_driver_workaround_rate_control_reconfig = 0x1,
380 };
381 DEFINE_ENUM_FLAG_OPERATORS(d3d12_video_encoder_driver_workarounds);
382 
383 struct d3d12_video_encoder
384 {
385    struct pipe_video_codec base = {};
386    struct pipe_screen *    m_screen = nullptr;
387    struct d3d12_screen *   m_pD3D12Screen = nullptr;
388    UINT max_quality_levels = 1;
389 
390    enum d3d12_video_encoder_driver_workarounds driver_workarounds = d3d12_video_encoder_driver_workaround_none;
391 
392    ///
393    /// D3D12 objects and context info
394    ///
395 
396    const uint m_NodeMask  = 0u;
397    const uint m_NodeIndex = 0u;
398 
399    ComPtr<ID3D12Fence> m_spFence;
400    uint64_t            m_fenceValue = 1u;
401    bool                m_bPendingWorkNotFlushed = false;
402 
403    ComPtr<ID3D12VideoDevice3>            m_spD3D12VideoDevice;
404    ComPtr<ID3D12VideoEncoder>            m_spVideoEncoder;
405    ComPtr<ID3D12VideoEncoderHeap>        m_spVideoEncoderHeap;
406    ComPtr<ID3D12CommandQueue>            m_spEncodeCommandQueue;
407    ComPtr<ID3D12VideoEncodeCommandList2> m_spEncodeCommandList;
408    std::vector<D3D12_RESOURCE_BARRIER>   m_transitionsBeforeCloseCmdList;
409 
410    std::unique_ptr<d3d12_video_encoder_references_manager_interface> m_upDPBManager;
411    std::shared_ptr<d3d12_video_dpb_storage_manager_interface>        m_upDPBStorageManager;
412    std::unique_ptr<d3d12_video_bitstream_builder_interface>          m_upBitstreamBuilder;
413 
414    pipe_resource* m_nalPrefixTmpBuffer = NULL;
415    std::vector<uint8_t> m_BitstreamHeadersBuffer;
416    std::vector<uint8_t> m_StagingHeadersBuffer;
417    std::vector<EncodedBitstreamResolvedMetadata> m_spEncodedFrameMetadata;
418 
419    struct D3D12EncodeCapabilities m_currentEncodeCapabilities = {};
420    struct D3D12EncodeConfiguration m_currentEncodeConfig = {};
421    struct D3D12EncodeConfiguration m_prevFrameEncodeConfig = {};
422 
423    struct InFlightEncodeResources
424    {
425       // In case of reconfigurations that trigger creation of new
426       // encoder or encoderheap or reference frames allocations
427       // we need to keep a reference alive to the ones that
428       // are currently in-flight
429       ComPtr<ID3D12VideoEncoder> m_spEncoder;
430       ComPtr<ID3D12VideoEncoderHeap> m_spEncoderHeap;
431       std::shared_ptr<d3d12_video_dpb_storage_manager_interface> m_References;
432 
433       ComPtr<ID3D12CommandAllocator> m_spCommandAllocator;
434 
435       struct d3d12_fence* m_InputSurfaceFence = NULL;
436 
437       /* Stores encode result for submission error control in the D3D12_VIDEO_ENC_ASYNC_DEPTH slots */
438       enum pipe_video_feedback_encode_result_flags encode_result = PIPE_VIDEO_FEEDBACK_METADATA_ENCODE_FLAG_OK;
439    };
440 
441    std::vector<InFlightEncodeResources> m_inflightResourcesPool;
442 
443    // Used to track texture array allocations given by d3d12_video_create_dpb_buffer
444    // The visibility of these members must be at encoder level, so multiple
445    // encoder objects use their own tracking and allocation pool
446    // Some apps will destroy the encoder before d3d12_video_buffer_destroy(),
447    // so the lifetime of these can't be tied to d3d12_video_encoder_destroy()
448    // This is how these are managed:
449    // 1. Created on demand at d3d12_video_create_dpb_buffer
450    //    and the pointer is stored on each d3d12_video_buffer
451    // 2. On d3d12_video_buffer::destroy(), when all the slots
452    //    of the allocation pool are unused, the memory is released.
453    pipe_resource *m_pVideoTexArrayDPBPool;
454    std::shared_ptr<uint32_t> m_spVideoTexArrayDPBPoolInUse;
455 };
456 
457 bool
458 d3d12_video_encoder_create_command_objects(struct d3d12_video_encoder *pD3D12Enc);
459 bool
460 d3d12_video_encoder_reconfigure_session(struct d3d12_video_encoder *pD3D12Enc,
461                                         struct pipe_video_buffer *  srcTexture,
462                                         struct pipe_picture_desc *  picture);
463 bool
464 d3d12_video_encoder_update_current_encoder_config_state(struct d3d12_video_encoder *pD3D12Enc,
465                                                         D3D12_VIDEO_SAMPLE srcTextureDesc,
466                                                         struct pipe_picture_desc *  picture);
467 bool
468 d3d12_video_encoder_reconfigure_encoder_objects(struct d3d12_video_encoder *pD3D12Enc,
469                                                 struct pipe_video_buffer *  srcTexture,
470                                                 struct pipe_picture_desc *  picture);
471 D3D12_VIDEO_ENCODER_PICTURE_CONTROL_CODEC_DATA
472 d3d12_video_encoder_get_current_picture_param_settings(struct d3d12_video_encoder *pD3D12Enc);
473 D3D12_VIDEO_ENCODER_LEVEL_SETTING
474 d3d12_video_encoder_get_current_level_desc(struct d3d12_video_encoder *pD3D12Enc);
475 D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION
476 d3d12_video_encoder_get_current_codec_config_desc(struct d3d12_video_encoder *pD3D12Enc);
477 D3D12_VIDEO_ENCODER_PROFILE_DESC
478 d3d12_video_encoder_get_current_profile_desc(struct d3d12_video_encoder *pD3D12Enc);
479 D3D12_VIDEO_ENCODER_RATE_CONTROL
480 d3d12_video_encoder_get_current_rate_control_settings(struct d3d12_video_encoder *pD3D12Enc);
481 D3D12_VIDEO_ENCODER_PICTURE_CONTROL_SUBREGIONS_LAYOUT_DATA
482 d3d12_video_encoder_get_current_slice_param_settings(struct d3d12_video_encoder *pD3D12Enc);
483 D3D12_VIDEO_ENCODER_SEQUENCE_GOP_STRUCTURE
484 d3d12_video_encoder_get_current_gop_desc(struct d3d12_video_encoder *pD3D12Enc);
485 uint32_t
486 d3d12_video_encoder_get_current_max_dpb_capacity(struct d3d12_video_encoder *pD3D12Enc);
487 void
488 d3d12_video_encoder_create_reference_picture_manager(struct d3d12_video_encoder *pD3D12Enc, struct pipe_picture_desc *  picture);
489 void
490 d3d12_video_encoder_update_picparams_tracking(struct d3d12_video_encoder *pD3D12Enc,
491                                               struct pipe_video_buffer *  srcTexture,
492                                               struct pipe_picture_desc *  picture);
493 void
494 d3d12_video_encoder_calculate_metadata_resolved_buffer_size(enum pipe_video_format codec, uint32_t maxSliceNumber, uint64_t &bufferSize);
495 uint32_t
496 d3d12_video_encoder_calculate_max_slices_count_in_output(
497    D3D12_VIDEO_ENCODER_FRAME_SUBREGION_LAYOUT_MODE                          slicesMode,
498    const D3D12_VIDEO_ENCODER_PICTURE_CONTROL_SUBREGIONS_LAYOUT_DATA_SLICES *slicesConfig,
499    uint32_t                                                                 MaxSubregionsNumberFromCaps,
500    D3D12_VIDEO_ENCODER_PICTURE_RESOLUTION_DESC                              sequenceTargetResolution,
501    uint32_t                                                                 SubregionBlockPixelsSize);
502 bool
503 d3d12_video_encoder_prepare_output_buffers(struct d3d12_video_encoder *pD3D12Enc,
504                                            struct pipe_video_buffer *  srcTexture,
505                                            struct pipe_picture_desc *  picture);
506 void
507 d3d12_video_encoder_build_pre_encode_codec_headers(struct d3d12_video_encoder *pD3D12Enc,
508                                                    bool &postEncodeHeadersNeeded,
509                                                    uint64_t &preEncodeGeneratedHeadersByteSize,
510                                                    std::vector<uint64_t> &pWrittenCodecUnitsSizes);
511 void
512 d3d12_video_encoder_extract_encode_metadata(
513    struct d3d12_video_encoder *                               pD3D12Dec,
514    ID3D12Resource *                                           pResolvedMetadataBuffer,
515    uint64_t                                                   resourceMetadataSize,
516    D3D12_VIDEO_ENCODER_OUTPUT_METADATA &                      encoderMetadata,
517    std::vector<D3D12_VIDEO_ENCODER_FRAME_SUBREGION_METADATA> &pSubregionsMetadata);
518 
519 D3D12_VIDEO_ENCODER_CODEC
520 d3d12_video_encoder_get_current_codec(struct d3d12_video_encoder *pD3D12Enc);
521 
522 bool
523 d3d12_video_encoder_negotiate_requested_features_and_d3d12_driver_caps(struct d3d12_video_encoder *pD3D12Enc,
524                                                                        D3D12_FEATURE_DATA_VIDEO_ENCODER_SUPPORT1 &capEncoderSupportData);
525 bool
526 d3d12_video_encoder_query_d3d12_driver_caps(struct d3d12_video_encoder *pD3D12Enc,
527                                             D3D12_FEATURE_DATA_VIDEO_ENCODER_SUPPORT1 &capEncoderSupportData);
528 bool
529 d3d12_video_encoder_check_subregion_mode_support(struct d3d12_video_encoder *pD3D12Enc,
530                                                  D3D12_VIDEO_ENCODER_FRAME_SUBREGION_LAYOUT_MODE requestedSlicesMode);
531 size_t
532 d3d12_video_encoder_pool_current_index(struct d3d12_video_encoder *pD3D12Enc);
533 
534 size_t
535 d3d12_video_encoder_metadata_current_index(struct d3d12_video_encoder *pD3D12Enc);
536 
537 unsigned
538 d3d12_video_encoder_build_post_encode_codec_bitstream(struct d3d12_video_encoder * pD3D12Enc,
539                                                       uint64_t associated_fence_value,
540                                                       EncodedBitstreamResolvedMetadata& associatedMetadata);
541 
542 void
543 d3d12_video_encoder_store_current_picture_references(d3d12_video_encoder *pD3D12Enc,
544                                                      uint64_t current_metadata_slot);
545 
546 
547 // Implementation here to prevent template linker issues
548 template<typename T>
549 void
550 d3d12_video_encoder_update_picparams_region_of_interest_qpmap(struct d3d12_video_encoder *pD3D12Enc,
551                                                               const struct pipe_enc_roi *roi_config,
552                                                               int32_t min_delta_qp,
553                                                               int32_t max_delta_qp,
554                                                               std::vector<T>& pQPMap);
555 bool
556 d3d12_video_encoder_uses_direct_dpb(enum pipe_video_format codec);
557 
558 ///
559 /// d3d12_video_encoder functions ends
560 ///
561 
562 #endif
563