xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/d3d12/d3d12_video_buffer.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 
25 #ifndef D3D12_VIDEO_BUFFER_H
26 #define D3D12_VIDEO_BUFFER_H
27 
28 #include "pipe/p_context.h"
29 #include "pipe/p_video_codec.h"
30 #include <vector>
31 #include "d3d12_video_types.h"
32 
33 ///
34 /// Pipe video buffer interface starts
35 ///
36 
37 /**
38  * creates a video buffer
39  */
40 struct pipe_video_buffer *
41 d3d12_video_buffer_create(struct pipe_context *pipe, const struct pipe_video_buffer *tmpl);
42 
43 /**
44  * creates a video buffer from a handle
45  */
46 struct pipe_video_buffer *
47 d3d12_video_buffer_from_handle( struct pipe_context *pipe,
48                            const struct pipe_video_buffer *tmpl,
49                            struct winsys_handle *handle,
50                            unsigned usage);
51 /**
52  * destroy this video buffer
53  */
54 void
55 d3d12_video_buffer_destroy(struct pipe_video_buffer *buffer);
56 
57 /**
58  * get an individual resource for each plane,
59  * only returns existing resources by reference
60  */
61 void
62 d3d12_video_buffer_resources(struct pipe_video_buffer *buffer,
63                              struct pipe_resource **resources);
64 
65 /**
66  * get an individual sampler view for each plane
67  */
68 struct pipe_sampler_view **
69 d3d12_video_buffer_get_sampler_view_planes(struct pipe_video_buffer *buffer);
70 
71 /**
72  * get an individual sampler view for each component
73  */
74 struct pipe_sampler_view **
75 d3d12_video_buffer_get_sampler_view_components(struct pipe_video_buffer *buffer);
76 
77 /**
78  * get an individual surfaces for each plane
79  */
80 struct pipe_surface **
81 d3d12_video_buffer_get_surfaces(struct pipe_video_buffer *buffer);
82 
83 /*
84  * destroy the associated data
85  */
86 void
87 d3d12_video_buffer_destroy_associated_data(void *associated_data);
88 
89 /**
90  * output for decoding / input for displaying
91  */
92 struct d3d12_video_buffer
93 {
94    pipe_video_buffer                       base;
95    struct d3d12_resource *                 texture;
96    uint                                    num_planes;
97    std::vector<pipe_surface *>      surfaces;
98    std::vector<pipe_sampler_view *> sampler_view_planes;
99    std::vector<pipe_sampler_view *> sampler_view_components;
100 
101    // Indicates the subresource index into the texture.array_size
102    // that corresponds to this video buffer object
103    uint                             idx_texarray_slots;
104 
105    // Used by d3d12_video_buffer_destroy() when using texture array mode
106    // in the function d3d12_video_enc::d3d12_video_create_dpb_buffer()
107    // Points to the same address as d3d12_video_encoder::m_spVideoTexArrayDPBPoolInUse
108    std::shared_ptr<uint32_t> m_spVideoTexArrayDPBPoolInUse;
109 };
110 
111 ///
112 /// Pipe video buffer interface ends
113 ///
114 
115 /**
116  * creates a video dpb buffer
117  */
118 
119 enum class d3d12_video_buffer_creation_mode
120 {
121    create_resource = 0,
122    place_on_resource = 1,
123    open_shared_resource = 2,
124 };
125 
126 struct pipe_video_buffer*
127 d3d12_video_create_dpb_buffer(struct pipe_video_codec *codec,
128                               struct pipe_picture_desc *picture,
129                               const struct pipe_video_buffer *templat);
130 
131 struct pipe_video_buffer*
132 d3d12_video_create_dpb_buffer_aot(struct pipe_video_codec *codec,
133                                   struct pipe_picture_desc *picture,
134                                   const struct pipe_video_buffer *templat);
135 
136 struct pipe_video_buffer*
137 d3d12_video_create_dpb_buffer_texarray(struct pipe_video_codec *codec,
138                                        struct pipe_picture_desc *picture,
139                                        const struct pipe_video_buffer *templat);
140 
141 #endif
142