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_TYPES_H
25 #define D3D12_VIDEO_TYPES_H
26
27 #include <stdarg.h>
28 #include <memory>
29 #include <vector>
30 #include <functional>
31
32 #include "pipe/p_context.h"
33 #include "pipe/p_video_codec.h"
34 #include "d3d12_fence.h"
35 #include "d3d12_debug.h"
36
37 #include <directx/d3d12video.h>
38 #include <dxguids/dxguids.h>
39
40 #include <wrl/client.h>
41 using Microsoft::WRL::ComPtr;
42
43 #if !defined(_WIN32) || defined(_MSC_VER) || D3D12_SDK_VERSION < 606
44 inline D3D12_VIDEO_DECODER_HEAP_DESC
GetDesc(ID3D12VideoDecoderHeap * heap)45 GetDesc(ID3D12VideoDecoderHeap *heap)
46 {
47 return heap->GetDesc();
48 }
49 #else
50 inline D3D12_VIDEO_DECODER_HEAP_DESC
GetDesc(ID3D12VideoDecoderHeap * heap)51 GetDesc(ID3D12VideoDecoderHeap *heap)
52 {
53 D3D12_VIDEO_DECODER_HEAP_DESC ret;
54 heap->GetDesc(&ret);
55 return ret;
56 }
57 #endif
58
59 // Allow encoder to continue the encoding session when an optional
60 // rate control mode such as the following is used but not supported
61 //
62 // D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_VBV_SIZES
63 // D3D12_VIDEO_ENCODER_RATE_CONTROL_FLAG_ENABLE_MAX_FRAME_SIZE
64 //
65 // If setting this OS Env variable to true, the encoding process will continue, disregarding the settings
66 // requested for the optional RC mode
67 //
68
69 const bool D3D12_VIDEO_ENC_FALLBACK_RATE_CONTROL_CONFIG = debug_get_bool_option("D3D12_VIDEO_ENC_FALLBACK_RATE_CONTROL_CONFIG", false);
70
71 /* For CBR mode, to guarantee bitrate of generated stream complies with
72 * target bitrate (e.g. no over +/-10%), vbv_buffer_size should be same
73 * as target bitrate. Controlled by OS env var D3D12_VIDEO_ENC_CBR_FORCE_VBV_EQUAL_BITRATE
74 */
75 const bool D3D12_VIDEO_ENC_CBR_FORCE_VBV_EQUAL_BITRATE = debug_get_bool_option("D3D12_VIDEO_ENC_CBR_FORCE_VBV_EQUAL_BITRATE", false);
76
77 // Allow encoder to continue the encoding session when aa slice mode
78 // is requested but not supported.
79 //
80 // If setting this OS Env variable to true, the encoder will try to adjust to the closest slice
81 // setting available and encode using that configuration anyway
82 //
83 const bool D3D12_VIDEO_ENC_FALLBACK_SLICE_CONFIG = debug_get_bool_option("D3D12_VIDEO_ENC_FALLBACK_SLICE_CONFIG", false);
84
85 constexpr unsigned int D3D12_VIDEO_H264_MB_IN_PIXELS = 16;
86
87 enum d3d12_video_decode_config_specific_flags
88 {
89 d3d12_video_decode_config_specific_flag_none = 0,
90 d3d12_video_decode_config_specific_flag_alignment_height = 1 << 12, // set by accelerator
91 d3d12_video_decode_config_specific_flag_array_of_textures = 1 << 14, // set by accelerator
92 d3d12_video_decode_config_specific_flag_reuse_decoder =
93 1 << 15, // set by accelerator - This bit means that the decoder can be re-used with resolution change and bit
94 // depth change (including profile GUID change from 8bit to 10bit and vice versa).
95 d3d12_video_decode_config_specific_flag_reference_only_textures_required = 1 << 30, // custom created for WSL
96 };
97
98 enum d3d12_video_decode_profile_type
99 {
100 d3d12_video_decode_profile_type_none,
101 d3d12_video_decode_profile_type_h264,
102 d3d12_video_decode_profile_type_max_valid
103 };
104
105 struct d3d12_video_decode_dpb_descriptor
106 {
107 DXGI_FORMAT Format = DXGI_FORMAT_UNKNOWN;
108 uint64_t Width = 0;
109 uint32_t Height = 0;
110 bool fArrayOfTexture = false;
111 bool fReferenceOnly = false;
112 uint16_t dpbSize = 0;
113 uint32_t m_NodeMask = 0;
114 };
115
116 struct d3d12_video_decode_output_conversion_arguments
117 {
118 BOOL Enable;
119 DXGI_COLOR_SPACE_TYPE OutputColorSpace;
120 D3D12_VIDEO_SAMPLE ReferenceInfo;
121 uint32_t ReferenceFrameCount;
122 };
123
124 void
125 d3d12_video_encoder_convert_from_d3d12_level_h264(D3D12_VIDEO_ENCODER_LEVELS_H264 level12,
126 uint32_t & specLevel,
127 uint32_t & constraint_set3_flag);
128 D3D12_VIDEO_ENCODER_PROFILE_H264
129 d3d12_video_encoder_convert_profile_to_d3d12_enc_profile_h264(enum pipe_video_profile profile);
130 D3D12_VIDEO_ENCODER_CODEC
131 d3d12_video_encoder_convert_codec_to_d3d12_enc_codec(enum pipe_video_profile profile);
132 GUID
133 d3d12_video_decoder_convert_pipe_video_profile_to_d3d12_profile(enum pipe_video_profile profile);
134
135 #endif
136