1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © Microsoft Corporation
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21bf215546Sopenharmony_ci * IN THE SOFTWARE.
22bf215546Sopenharmony_ci */
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ci#ifndef D3D12_VIDEO_PROC_H
25bf215546Sopenharmony_ci#define D3D12_VIDEO_PROC_H
26bf215546Sopenharmony_ci#include "d3d12_video_types.h"
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci///
30bf215546Sopenharmony_ci/// Pipe video interface starts
31bf215546Sopenharmony_ci///
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci/**
34bf215546Sopenharmony_ci * creates a video processor
35bf215546Sopenharmony_ci */
36bf215546Sopenharmony_cistruct pipe_video_codec *
37bf215546Sopenharmony_cid3d12_video_create_processor(struct pipe_context *context, const struct pipe_video_codec *templ);
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci/**
40bf215546Sopenharmony_ci * destroy this video processor
41bf215546Sopenharmony_ci */
42bf215546Sopenharmony_civoid
43bf215546Sopenharmony_cid3d12_video_processor_destroy(struct pipe_video_codec *codec);
44bf215546Sopenharmony_ci
45bf215546Sopenharmony_ci/**
46bf215546Sopenharmony_ci * start processing of a new frame
47bf215546Sopenharmony_ci */
48bf215546Sopenharmony_civoid
49bf215546Sopenharmony_cid3d12_video_processor_begin_frame(struct pipe_video_codec * codec,
50bf215546Sopenharmony_ci                                struct pipe_video_buffer *target,
51bf215546Sopenharmony_ci                                struct pipe_picture_desc *picture);
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_ci/**
54bf215546Sopenharmony_ci * Perform post-process effect
55bf215546Sopenharmony_ci */
56bf215546Sopenharmony_civoid
57bf215546Sopenharmony_cid3d12_video_processor_process_frame(struct pipe_video_codec *codec,
58bf215546Sopenharmony_ci                        struct pipe_video_buffer *input_texture,
59bf215546Sopenharmony_ci                        const struct pipe_vpp_desc *process_properties);
60bf215546Sopenharmony_ci/**
61bf215546Sopenharmony_ci * end processing of the current frame
62bf215546Sopenharmony_ci */
63bf215546Sopenharmony_civoid
64bf215546Sopenharmony_cid3d12_video_processor_end_frame(struct pipe_video_codec * codec,
65bf215546Sopenharmony_ci                              struct pipe_video_buffer *target,
66bf215546Sopenharmony_ci                              struct pipe_picture_desc *picture);
67bf215546Sopenharmony_ci/**
68bf215546Sopenharmony_ci
69bf215546Sopenharmony_ci * flush any outstanding command buffers to the hardware
70bf215546Sopenharmony_ci * should be called before a video_buffer is acessed by the gallium frontend again
71bf215546Sopenharmony_ci */
72bf215546Sopenharmony_civoid
73bf215546Sopenharmony_cid3d12_video_processor_flush(struct pipe_video_codec *codec);
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_ci///
76bf215546Sopenharmony_ci/// Pipe video interface ends
77bf215546Sopenharmony_ci///
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_ci///
80bf215546Sopenharmony_ci/// d3d12_video_processor functions starts
81bf215546Sopenharmony_ci///
82bf215546Sopenharmony_ci
83bf215546Sopenharmony_cistruct d3d12_video_processor
84bf215546Sopenharmony_ci{
85bf215546Sopenharmony_ci   struct pipe_video_codec base;
86bf215546Sopenharmony_ci   struct d3d12_screen  *m_pD3D12Screen;
87bf215546Sopenharmony_ci   struct d3d12_context *m_pD3D12Context;
88bf215546Sopenharmony_ci
89bf215546Sopenharmony_ci   ///
90bf215546Sopenharmony_ci   /// D3D12 objects and context info
91bf215546Sopenharmony_ci   ///
92bf215546Sopenharmony_ci
93bf215546Sopenharmony_ci   const uint m_NodeMask  = 0u;
94bf215546Sopenharmony_ci   const uint m_NodeIndex = 0u;
95bf215546Sopenharmony_ci
96bf215546Sopenharmony_ci   ComPtr<ID3D12Fence> m_spFence;
97bf215546Sopenharmony_ci   uint                m_fenceValue = 1u;
98bf215546Sopenharmony_ci
99bf215546Sopenharmony_ci   ComPtr<ID3D12VideoDevice>             m_spD3D12VideoDevice;
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_ci   D3D12_FEATURE_DATA_VIDEO_PROCESS_SUPPORT           m_SupportCaps;
102bf215546Sopenharmony_ci   D3D12_VIDEO_PROCESS_OUTPUT_STREAM_DESC             m_outputStreamDesc;
103bf215546Sopenharmony_ci   std::vector<D3D12_VIDEO_PROCESS_INPUT_STREAM_DESC> m_inputStreamDescs;
104bf215546Sopenharmony_ci   ComPtr<ID3D12VideoProcessor1>                      m_spVideoProcessor;
105bf215546Sopenharmony_ci   ComPtr<ID3D12CommandQueue>                         m_spCommandQueue;
106bf215546Sopenharmony_ci   ComPtr<ID3D12CommandAllocator>                     m_spCommandAllocator;
107bf215546Sopenharmony_ci   ComPtr<ID3D12VideoProcessCommandList1>             m_spCommandList;
108bf215546Sopenharmony_ci
109bf215546Sopenharmony_ci   std::vector<D3D12_RESOURCE_BARRIER> m_transitionsBeforeCloseCmdList;
110bf215546Sopenharmony_ci
111bf215546Sopenharmony_ci   // Current state between begin and end frame
112bf215546Sopenharmony_ci   D3D12_VIDEO_PROCESS_OUTPUT_STREAM_ARGUMENTS m_OutputArguments;
113bf215546Sopenharmony_ci   std::vector<D3D12_VIDEO_PROCESS_INPUT_STREAM_ARGUMENTS1> m_ProcessInputs;
114bf215546Sopenharmony_ci
115bf215546Sopenharmony_ci   // Indicates if GPU commands have not been flushed and are pending.
116bf215546Sopenharmony_ci   bool m_needsGPUFlush = false;
117bf215546Sopenharmony_ci};
118bf215546Sopenharmony_ci
119bf215546Sopenharmony_cistruct pipe_video_codec *
120bf215546Sopenharmony_cid3d12_video_processor_create(struct pipe_context *context, const struct pipe_video_codec *codec);
121bf215546Sopenharmony_ci
122bf215546Sopenharmony_cibool
123bf215546Sopenharmony_cid3d12_video_processor_check_caps_and_create_processor(struct d3d12_video_processor *pD3D12Proc,
124bf215546Sopenharmony_ci                                                        std::vector<DXGI_FORMAT> InputFormats,
125bf215546Sopenharmony_ci                                                        DXGI_COLOR_SPACE_TYPE InputColorSpace,
126bf215546Sopenharmony_ci                                                        DXGI_FORMAT OutputFormat,
127bf215546Sopenharmony_ci                                                        DXGI_COLOR_SPACE_TYPE OutputColorSpace);
128bf215546Sopenharmony_ci
129bf215546Sopenharmony_cibool
130bf215546Sopenharmony_cid3d12_video_processor_create_command_objects(struct d3d12_video_processor *pD3D12Proc);
131bf215546Sopenharmony_ci
132bf215546Sopenharmony_ciD3D12_VIDEO_PROCESS_ORIENTATION
133bf215546Sopenharmony_cid3d12_video_processor_convert_pipe_rotation(enum pipe_video_vpp_orientation orientation);
134bf215546Sopenharmony_ci
135bf215546Sopenharmony_ci///
136bf215546Sopenharmony_ci/// d3d12_video_processor functions ends
137bf215546Sopenharmony_ci///
138bf215546Sopenharmony_ci
139bf215546Sopenharmony_ci#endif
140