1 2 /* 3 * Copyright © Microsoft Corporation 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the next 13 * paragraph) shall be included in all copies or substantial portions of the 14 * Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 * IN THE SOFTWARE. 23 */ 24 25 #ifndef D3D12_VIDEO_DEC_AV1_H 26 #define D3D12_VIDEO_DEC_AV1_H 27 28 #include "d3d12_video_types.h" 29 30 // From DXVA AV1 spec 31 // Entries that will not be used for decoding the current picture, 32 // or any subsequent pictures, are indicated by setting this value to 0xFF. 33 // Also, When DXVA_PicEntry_AV1. Index does not contain an index to a valid 34 // reference, the value shall be set to 255, to indicate that the index is invalid. 35 constexpr uint16_t DXVA_AV1_INVALID_PICTURE_INDEX = 0xFF; 36 37 // Frame Restoration types (section 6.10.15) 38 enum { 39 AV1_RESTORE_NONE = 0, 40 AV1_RESTORE_WIENER = 1, 41 AV1_RESTORE_SGRPROJ = 2, 42 AV1_RESTORE_SWITCHABLE = 3, 43 }; 44 45 #pragma pack(push, BeforeDXVApacking, 1) 46 47 #ifndef _DIRECTX_AV1_VA_ 48 #define _DIRECTX_AV1_VA_ 49 50 /* AV1 picture entry data structure */ 51 typedef struct _DXVA_PicEntry_AV1 { 52 53 uint32_t width; 54 uint32_t height; 55 56 // Global motion parameters 57 int32_t wmmat[6]; 58 union { 59 struct { 60 uint8_t wminvalid : 1; 61 uint8_t wmtype : 2; 62 uint8_t Reserved : 5; 63 }; 64 uint8_t GlobalMotionFlags; 65 }; 66 67 uint8_t Index; 68 uint16_t Reserved16Bits; 69 70 } DXVA_PicEntry_AV1, *LPDXVA_PicEntry_AV1; 71 72 /* AV1 picture parameters structure */ 73 typedef struct _DXVA_PicParams_AV1 { 74 uint32_t width; 75 uint32_t height; 76 77 uint32_t max_width; 78 uint32_t max_height; 79 80 uint8_t CurrPicTextureIndex; 81 uint8_t superres_denom; 82 uint8_t bitdepth; 83 uint8_t seq_profile; 84 85 // Tiles: 86 struct { 87 uint8_t cols; 88 uint8_t rows; 89 uint16_t context_update_id; 90 uint16_t widths[64]; 91 uint16_t heights[64]; 92 } tiles; 93 94 // Coding Tools 95 union { 96 struct { 97 uint32_t use_128x128_superblock : 1; 98 uint32_t intra_edge_filter : 1; 99 uint32_t interintra_compound : 1; 100 uint32_t masked_compound : 1; 101 uint32_t warped_motion : 1; 102 uint32_t dual_filter : 1; 103 uint32_t jnt_comp : 1; 104 uint32_t screen_content_tools : 1; 105 uint32_t integer_mv : 1; 106 uint32_t cdef : 1; 107 uint32_t restoration : 1; 108 uint32_t film_grain : 1; 109 uint32_t intrabc : 1; 110 uint32_t high_precision_mv : 1; 111 uint32_t switchable_motion_mode : 1; 112 uint32_t filter_intra : 1; 113 uint32_t disable_frame_end_update_cdf : 1; 114 uint32_t disable_cdf_update : 1; 115 uint32_t reference_mode : 1; 116 uint32_t skip_mode : 1; 117 uint32_t reduced_tx_set : 1; 118 uint32_t superres : 1; 119 uint32_t tx_mode : 2; 120 uint32_t use_ref_frame_mvs : 1; 121 uint32_t enable_ref_frame_mvs : 1; 122 uint32_t reference_frame_update : 1; 123 uint32_t Reserved : 5; 124 }; 125 uint32_t CodingParamToolFlags; 126 } coding; 127 128 // Format & Picture Info flags 129 union { 130 struct { 131 uint8_t frame_type : 2; 132 uint8_t show_frame : 1; 133 uint8_t showable_frame : 1; 134 uint8_t subsampling_x : 1; 135 uint8_t subsampling_y : 1; 136 uint8_t mono_chrome : 1; 137 uint8_t Reserved : 1; 138 }; 139 uint8_t FormatAndPictureInfoFlags; 140 } format; 141 142 // References 143 uint8_t primary_ref_frame; 144 uint8_t order_hint; 145 uint8_t order_hint_bits; 146 147 DXVA_PicEntry_AV1 frame_refs[7]; 148 uint8_t RefFrameMapTextureIndex[8]; 149 150 // Loop filter parameters 151 struct { 152 uint8_t filter_level[2]; 153 uint8_t filter_level_u; 154 uint8_t filter_level_v; 155 156 uint8_t sharpness_level; 157 union { 158 struct { 159 uint8_t mode_ref_delta_enabled : 1; 160 uint8_t mode_ref_delta_update : 1; 161 uint8_t delta_lf_multi : 1; 162 uint8_t delta_lf_present : 1; 163 uint8_t Reserved : 4; 164 }; 165 uint8_t ControlFlags; 166 }; 167 char ref_deltas[8]; 168 char mode_deltas[2]; 169 uint8_t delta_lf_res; 170 uint8_t frame_restoration_type[3]; 171 uint16_t log2_restoration_unit_size[3]; 172 uint16_t Reserved16Bits; 173 } loop_filter; 174 175 // Quantization 176 struct { 177 union { 178 struct { 179 uint8_t delta_q_present : 1; 180 uint8_t delta_q_res : 2; 181 uint8_t Reserved : 5; 182 }; 183 uint8_t ControlFlags; 184 }; 185 186 uint8_t base_qindex; 187 char y_dc_delta_q; 188 char u_dc_delta_q; 189 char v_dc_delta_q; 190 char u_ac_delta_q; 191 char v_ac_delta_q; 192 // using_qmatrix: 193 uint8_t qm_y; 194 uint8_t qm_u; 195 uint8_t qm_v; 196 uint16_t Reserved16Bits; 197 } quantization; 198 199 // Cdef parameters 200 struct { 201 union { 202 struct { 203 uint8_t damping : 2; 204 uint8_t bits : 2; 205 uint8_t Reserved : 4; 206 }; 207 uint8_t ControlFlags; 208 }; 209 210 union { 211 struct { 212 uint8_t primary : 6; 213 uint8_t secondary : 2; 214 }; 215 uint8_t combined; 216 } y_strengths[8]; 217 218 union { 219 struct { 220 uint8_t primary : 6; 221 uint8_t secondary : 2; 222 }; 223 uint8_t combined; 224 } uv_strengths[8]; 225 226 } cdef; 227 228 uint8_t interp_filter; 229 230 // Segmentation 231 struct { 232 union { 233 struct { 234 uint8_t enabled : 1; 235 uint8_t update_map : 1; 236 uint8_t update_data : 1; 237 uint8_t temporal_update : 1; 238 uint8_t Reserved : 4; 239 }; 240 uint8_t ControlFlags; 241 }; 242 uint8_t Reserved24Bits[3]; 243 244 union { 245 struct { 246 uint8_t alt_q : 1; 247 uint8_t alt_lf_y_v : 1; 248 uint8_t alt_lf_y_h : 1; 249 uint8_t alt_lf_u : 1; 250 uint8_t alt_lf_v : 1; 251 uint8_t ref_frame : 1; 252 uint8_t skip : 1; 253 uint8_t globalmv : 1; 254 }; 255 uint8_t mask; 256 } feature_mask[8]; 257 258 int16_t feature_data[8][8]; 259 260 } segmentation; 261 262 struct { 263 union { 264 struct { 265 uint16_t apply_grain : 1; 266 uint16_t scaling_shift_minus8 : 2; 267 uint16_t chroma_scaling_from_luma : 1; 268 uint16_t ar_coeff_lag : 2; 269 uint16_t ar_coeff_shift_minus6 : 2; 270 uint16_t grain_scale_shift : 2; 271 uint16_t overlap_flag : 1; 272 uint16_t clip_to_restricted_range : 1; 273 uint16_t matrix_coeff_is_identity : 1; 274 uint16_t Reserved : 3; 275 }; 276 uint16_t ControlFlags; 277 }; 278 279 uint16_t grain_seed; 280 uint8_t scaling_points_y[14][2]; 281 uint8_t num_y_points; 282 uint8_t scaling_points_cb[10][2]; 283 uint8_t num_cb_points; 284 uint8_t scaling_points_cr[10][2]; 285 uint8_t num_cr_points; 286 uint8_t ar_coeffs_y[24]; 287 uint8_t ar_coeffs_cb[25]; 288 uint8_t ar_coeffs_cr[25]; 289 uint8_t cb_mult; 290 uint8_t cb_luma_mult; 291 uint8_t cr_mult; 292 uint8_t cr_luma_mult; 293 uint8_t Reserved8Bits; 294 int16_t cb_offset; 295 int16_t cr_offset; 296 } film_grain; 297 298 uint32_t Reserved32Bits; 299 uint32_t StatusReportFeedbackNumber; 300 } DXVA_PicParams_AV1, *LPDXVA_PicParams_AV1; 301 302 /* AV1 tile structure */ 303 typedef struct _DXVA_Tile_AV1 { 304 uint32_t DataOffset; 305 uint32_t DataSize; 306 uint16_t row; 307 uint16_t column; 308 uint16_t Reserved16Bits; 309 uint8_t anchor_frame; 310 uint8_t Reserved8Bits; 311 } DXVA_Tile_AV1, *LPDXVA_Tile_AV1; 312 313 /* AV1 status reporting data structure */ 314 typedef struct _DXVA_Status_AV1 { 315 uint32_t StatusReportFeedbackNumber; 316 DXVA_PicEntry_AV1 CurrPic; 317 uint8_t BufType; 318 uint8_t Status; 319 uint8_t Reserved8Bits; 320 uint16_t NumMbsAffected; 321 } DXVA_Status_AV1, *LPDXVA_Status_AV1; 322 323 #endif // _DIRECTX_AV1_VA_ 324 325 #pragma pack(pop, BeforeDXVApacking) 326 327 void 328 d3d12_video_decoder_prepare_current_frame_references_av1(struct d3d12_video_decoder *pD3D12Dec, 329 ID3D12Resource *pTexture2D, 330 uint32_t subresourceIndex); 331 332 void 333 d3d12_video_decoder_refresh_dpb_active_references_av1(struct d3d12_video_decoder *pD3D12Dec); 334 335 void 336 d3d12_video_decoder_get_frame_info_av1( 337 struct d3d12_video_decoder *pD3D12Dec, uint32_t *pWidth, uint32_t *pHeight, uint16_t *pMaxDPB); 338 339 DXVA_PicParams_AV1 340 d3d12_video_decoder_dxva_picparams_from_pipe_picparams_av1( 341 uint32_t frameNum, 342 pipe_video_profile profile, 343 pipe_av1_picture_desc *pPipeDesc); 344 345 void 346 d3d12_video_decoder_log_pic_params_av1(DXVA_PicParams_AV1 *pPicParams); 347 348 void 349 d3d12_video_decoder_prepare_dxva_slices_control_av1(struct d3d12_video_decoder *pD3D12Dec, 350 std::vector<uint8_t> &vecOutSliceControlBuffers, 351 struct pipe_av1_picture_desc *picture_av1); 352 353 #endif 354