xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/d3d12/d3d12_video_proc.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_PROC_H
25 #define D3D12_VIDEO_PROC_H
26 #include "d3d12_video_types.h"
27 
28 
29 ///
30 /// Pipe video interface starts
31 ///
32 
33 /**
34  * creates a video processor
35  */
36 struct pipe_video_codec *
37 d3d12_video_create_processor(struct pipe_context *context, const struct pipe_video_codec *templ);
38 
39 /**
40  * destroy this video processor
41  */
42 void
43 d3d12_video_processor_destroy(struct pipe_video_codec *codec);
44 
45 /**
46  * start processing of a new frame
47  */
48 void
49 d3d12_video_processor_begin_frame(struct pipe_video_codec * codec,
50                                 struct pipe_video_buffer *target,
51                                 struct pipe_picture_desc *picture);
52 
53 /**
54  * Perform post-process effect
55  */
56 void
57 d3d12_video_processor_process_frame(struct pipe_video_codec *codec,
58                         struct pipe_video_buffer *input_texture,
59                         const struct pipe_vpp_desc *process_properties);
60 /**
61  * end processing of the current frame
62  */
63 int
64 d3d12_video_processor_end_frame(struct pipe_video_codec * codec,
65                               struct pipe_video_buffer *target,
66                               struct pipe_picture_desc *picture);
67 /**
68 
69  * flush any outstanding command buffers to the hardware
70  * should be called before a video_buffer is acessed by the gallium frontend again
71  */
72 void
73 d3d12_video_processor_flush(struct pipe_video_codec *codec);
74 
75 ///
76 /// Pipe video interface ends
77 ///
78 
79 ///
80 /// d3d12_video_processor functions starts
81 ///
82 
83 struct d3d12_video_processor_output_context
84 {
85    struct D3D12_VIDEO_PROCESS_OUTPUT_STREAM_ARGUMENTS args;
86    struct d3d12_video_buffer* buffer;
87 };
88 
89 struct d3d12_video_processor
90 {
91    struct pipe_video_codec base;
92    struct d3d12_screen  *m_pD3D12Screen;
93    struct d3d12_context *m_pD3D12Context;
94 
95    ///
96    /// D3D12 objects and context info
97    ///
98 
99    const uint m_NodeMask  = 0u;
100    const uint m_NodeIndex = 0u;
101 
102    ComPtr<ID3D12Fence> m_spFence;
103    uint                m_fenceValue = 1u;
104 
105    ComPtr<ID3D12VideoDevice>             m_spD3D12VideoDevice;
106 
107    D3D12_FEATURE_DATA_VIDEO_PROCESS_SUPPORT           m_SupportCaps;
108    D3D12_VIDEO_PROCESS_OUTPUT_STREAM_DESC             m_outputStreamDesc;
109    std::vector<D3D12_VIDEO_PROCESS_INPUT_STREAM_DESC> m_inputStreamDescs;
110    ComPtr<ID3D12VideoProcessor1>                      m_spVideoProcessor;
111    ComPtr<ID3D12CommandQueue>                         m_spCommandQueue;
112    std::vector<ComPtr<ID3D12CommandAllocator>>        m_spCommandAllocators;
113    std::vector<struct d3d12_fence>                    m_PendingFences;
114    ComPtr<ID3D12VideoProcessCommandList1>             m_spCommandList;
115 
116    std::vector<D3D12_RESOURCE_BARRIER> m_transitionsBeforeCloseCmdList;
117 
118    // Current state between begin and end frame
119    d3d12_video_processor_output_context m_OutputArguments;
120    std::vector<D3D12_VIDEO_PROCESS_INPUT_STREAM_ARGUMENTS1> m_ProcessInputs;
121    std::vector<struct d3d12_video_buffer*> m_InputBuffers;
122 
123    // Indicates if GPU commands have not been flushed and are pending.
124    bool m_needsGPUFlush = false;
125 
126    D3D12_FEATURE_DATA_VIDEO_PROCESS_MAX_INPUT_STREAMS m_vpMaxInputStreams = { };
127 
128    struct d3d12_fence* input_surface_fence = NULL;
129 };
130 
131 struct pipe_video_codec *
132 d3d12_video_processor_create(struct pipe_context *context, const struct pipe_video_codec *codec);
133 
134 bool
135 d3d12_video_processor_check_caps_and_create_processor(struct d3d12_video_processor *pD3D12Proc,
136                                                         std::vector<DXGI_FORMAT> InputFormats,
137                                                         DXGI_COLOR_SPACE_TYPE InputColorSpace,
138                                                         DXGI_FORMAT OutputFormat,
139                                                         DXGI_COLOR_SPACE_TYPE OutputColorSpace);
140 
141 bool
142 d3d12_video_processor_create_command_objects(struct d3d12_video_processor *pD3D12Proc);
143 
144 D3D12_VIDEO_PROCESS_ORIENTATION
145 d3d12_video_processor_convert_pipe_rotation(enum pipe_video_vpp_orientation orientation);
146 
147 bool
148 d3d12_video_processor_ensure_fence_finished(struct pipe_video_codec *codec, uint64_t fenceValueToWaitOn, uint64_t timeout_ns);
149 
150 bool
151 d3d12_video_processor_sync_completion(struct pipe_video_codec *codec, uint64_t fenceValueToWaitOn, uint64_t timeout_ns);
152 
153 uint64_t
154 d3d12_video_processor_pool_current_index(struct d3d12_video_processor *codec);
155 
156 int d3d12_video_processor_get_processor_fence(struct pipe_video_codec *codec,
157                                               struct pipe_fence_handle *fence,
158                                               uint64_t timeout);
159 
160 // We need enough to so next item in pipeline doesn't ask for a fence value we lost
161 const uint64_t D3D12_VIDEO_PROC_ASYNC_DEPTH = 36;
162 
163 ///
164 /// d3d12_video_processor functions ends
165 ///
166 
167 #endif
168