xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/i915/i915_winsys.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /**************************************************************************
2  *
3  * Copyright © 2009 Jakob Bornecrantz
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
22  * DEALINGS IN THE SOFTWARE.
23  *
24  **************************************************************************/
25 
26 #ifndef I915_WINSYS_H
27 #define I915_WINSYS_H
28 
29 #include "util/compiler.h"
30 
31 struct i915_winsys;
32 struct i915_winsys_buffer;
33 struct i915_winsys_batchbuffer;
34 struct pipe_resource;
35 struct pipe_fence_handle;
36 struct winsys_handle;
37 
38 enum i915_winsys_buffer_usage {
39    /* use on textures */
40    I915_USAGE_RENDER = 0x01,
41    I915_USAGE_SAMPLER = 0x02,
42    I915_USAGE_2D_TARGET = 0x04,
43    I915_USAGE_2D_SOURCE = 0x08,
44    /* use on vertex */
45    I915_USAGE_VERTEX = 0x10
46 };
47 
48 enum i915_winsys_buffer_type {
49    I915_NEW_TEXTURE,
50    I915_NEW_SCANOUT, /**< a texture used for scanning out from */
51    I915_NEW_VERTEX
52 };
53 
54 /* These need to be in sync with the definitions of libdrm-intel! */
55 enum i915_winsys_buffer_tile { I915_TILE_NONE, I915_TILE_X, I915_TILE_Y };
56 
57 enum i915_winsys_flush_flags {
58    I915_FLUSH_ASYNC = 0,
59    I915_FLUSH_END_OF_FRAME = 1
60 };
61 
62 struct i915_winsys_batchbuffer {
63 
64    struct i915_winsys *iws;
65 
66    /**
67     * Values exported to speed up the writing the batchbuffer,
68     * instead of having to go trough a accesor function for
69     * each dword written.
70     */
71    /*{@*/
72    uint8_t *map;
73    uint8_t *ptr;
74    size_t size;
75 
76    size_t relocs;
77 
78    uint8_t *ptr_start;
79    int reloc_count_start;
80    /*@}*/
81 };
82 
83 struct i915_winsys {
84 
85    unsigned pci_id; /**< PCI ID for the device */
86 
87    /**
88     * Batchbuffer functions.
89     */
90    /*@{*/
91    /**
92     * Create a new batchbuffer.
93     */
94    struct i915_winsys_batchbuffer *(*batchbuffer_create)(
95       struct i915_winsys *iws);
96 
97    /**
98     * Validate buffers for usage in this batchbuffer.
99     * Does space-checking and asorted other book-keeping.
100     *
101     * @batch
102     * @buffers array to buffers to validate
103     * @num_of_buffers size of the passed array
104     */
105    bool (*validate_buffers)(struct i915_winsys_batchbuffer *batch,
106                             struct i915_winsys_buffer **buffers,
107                             int num_of_buffers);
108 
109    /**
110     * Emit a relocation to a buffer.
111     * Target position in batchbuffer is the same as ptr.
112     *
113     * @batch
114     * @reloc buffer address to be inserted into target.
115     * @usage how is the hardware going to use the buffer.
116     * @offset add this to the reloc buffers address
117     * @target buffer where to write the address, null for batchbuffer.
118     * @fenced relocation needs a fence.
119     */
120    int (*batchbuffer_reloc)(struct i915_winsys_batchbuffer *batch,
121                             struct i915_winsys_buffer *reloc,
122                             enum i915_winsys_buffer_usage usage,
123                             unsigned offset, bool fenced);
124 
125    /**
126     * Flush a bufferbatch.
127     */
128    void (*batchbuffer_flush)(struct i915_winsys_batchbuffer *batch,
129                              struct pipe_fence_handle **fence,
130                              enum i915_winsys_flush_flags flags);
131 
132    /**
133     * Destroy a batchbuffer.
134     */
135    void (*batchbuffer_destroy)(struct i915_winsys_batchbuffer *batch);
136 
137    /**
138     * Store start values of emit
139     */
140    void (*emit_start)(struct i915_winsys_batchbuffer *batch);
141 
142    /**
143     * Go back to start values
144     */
145    void (*emit_restart)(struct i915_winsys_batchbuffer *batch);
146    /*@}*/
147 
148    /**
149     * Buffer functions.
150     */
151    /*@{*/
152    /**
153     * Create a buffer.
154     */
155    struct i915_winsys_buffer *(*buffer_create)(
156       struct i915_winsys *iws, unsigned size,
157       enum i915_winsys_buffer_type type);
158 
159    /**
160     * Create a tiled buffer.
161     *
162     * *stride, height are in bytes. The winsys tries to allocate the buffer with
163     * the tiling mode provide in *tiling. If tiling is no possible, *tiling will
164     * be set to I915_TILE_NONE. The calculated stride (incorporateing hw/kernel
165     * requirements) is always returned in *stride.
166     */
167    struct i915_winsys_buffer *(*buffer_create_tiled)(
168       struct i915_winsys *iws, unsigned *stride, unsigned height,
169       enum i915_winsys_buffer_tile *tiling, enum i915_winsys_buffer_type type);
170 
171    /**
172     * Creates a buffer from a handle.
173     * Used to implement pipe_screen::resource_from_handle.
174     * Also provides the stride information needed for the
175     * texture via the stride argument.
176     */
177    struct i915_winsys_buffer *(*buffer_from_handle)(
178       struct i915_winsys *iws, struct winsys_handle *whandle, unsigned height,
179       enum i915_winsys_buffer_tile *tiling, unsigned *stride);
180 
181    /**
182     * Used to implement pipe_screen::resource_get_handle.
183     * The winsys might need the stride information.
184     */
185    bool (*buffer_get_handle)(struct i915_winsys *iws,
186                              struct i915_winsys_buffer *buffer,
187                              struct winsys_handle *whandle, unsigned stride);
188 
189    /**
190     * Map a buffer.
191     */
192    void *(*buffer_map)(struct i915_winsys *iws,
193                        struct i915_winsys_buffer *buffer, bool write);
194 
195    /**
196     * Unmap a buffer.
197     */
198    void (*buffer_unmap)(struct i915_winsys *iws,
199                         struct i915_winsys_buffer *buffer);
200 
201    /**
202     * Write to a buffer.
203     *
204     * Arguments follows pipe_buffer_write.
205     */
206    int (*buffer_write)(struct i915_winsys *iws, struct i915_winsys_buffer *dst,
207                        size_t offset, size_t size, const void *data);
208 
209    void (*buffer_destroy)(struct i915_winsys *iws,
210                           struct i915_winsys_buffer *buffer);
211 
212    /**
213     * Check if a buffer is busy.
214     */
215    bool (*buffer_is_busy)(struct i915_winsys *iws,
216                           struct i915_winsys_buffer *buffer);
217    /*@}*/
218 
219    /**
220     * Fence functions.
221     */
222    /*@{*/
223    /**
224     * Reference fence and set ptr to fence.
225     */
226    void (*fence_reference)(struct i915_winsys *iws,
227                            struct pipe_fence_handle **ptr,
228                            struct pipe_fence_handle *fence);
229 
230    /**
231     * Check if a fence has finished.
232     */
233    int (*fence_signalled)(struct i915_winsys *iws,
234                           struct pipe_fence_handle *fence);
235 
236    /**
237     * Wait on a fence to finish.
238     */
239    int (*fence_finish)(struct i915_winsys *iws,
240                        struct pipe_fence_handle *fence);
241    /*@}*/
242 
243    /**
244     * Retrieve the aperture size (in MiB) of the device.
245     */
246    int (*aperture_size)(struct i915_winsys *iws);
247 
248    /**
249     * Destroy the winsys.
250     */
251    void (*destroy)(struct i915_winsys *iws);
252 
253    /**
254     * Get FD if the winsys provides one
255     */
256    int (*get_fd)(struct i915_winsys *iws);
257 };
258 
259 #endif
260