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