summaryrefslogtreecommitdiffstats
path: root/src/gallium/winsys/intel/intel_winsys.h
blob: d7104383f30378b8735a4174c8f26484c1cffc5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/*
 * Mesa 3-D graphics library
 *
 * Copyright (C) 2012-2014 LunarG, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 * Authors:
 *    Chia-I Wu <olv@lunarg.com>
 */

#ifndef INTEL_WINSYS_H
#define INTEL_WINSYS_H

#include "pipe/p_compiler.h"

/* this is compatible with i915_drm.h's definitions */
enum intel_exec_flag {
   /* bits[2:0]: ring type */
   INTEL_EXEC_DEFAULT         = 0 << 0,
   INTEL_EXEC_RENDER          = 1 << 0,
   INTEL_EXEC_BSD             = 2 << 0,
   INTEL_EXEC_BLT             = 3 << 0,

   /* bits[7:6]: constant buffer addressing mode */

   /* bits[8]: reset SO write offset register on GEN7+ */
   INTEL_EXEC_GEN7_SOL_RESET  = 1 << 8,
};

/* this is compatible with i915_drm.h's definitions */
enum intel_domain_flag {
   INTEL_DOMAIN_CPU           = 0x00000001,
   INTEL_DOMAIN_RENDER        = 0x00000002,
   INTEL_DOMAIN_SAMPLER       = 0x00000004,
   INTEL_DOMAIN_COMMAND	      = 0x00000008,
   INTEL_DOMAIN_INSTRUCTION   = 0x00000010,
   INTEL_DOMAIN_VERTEX        = 0x00000020,
   INTEL_DOMAIN_GTT           = 0x00000040,
};

/* this is compatible with i915_drm.h's definitions */
enum intel_tiling_mode {
   INTEL_TILING_NONE = 0,
   INTEL_TILING_X    = 1,
   INTEL_TILING_Y    = 2,
};

/* this is compatible with intel_bufmgr.h's definitions */
enum intel_alloc_flag {
   INTEL_ALLOC_FOR_RENDER     = 1 << 0,
};

struct winsys_handle;
struct intel_winsys;
struct intel_context;
struct intel_bo;

struct intel_winsys_info {
   int devid;
   bool has_llc;
   bool has_gen7_sol_reset;
   bool has_address_swizzling;
};

struct intel_winsys *
intel_winsys_create_for_fd(int fd);

void
intel_winsys_destroy(struct intel_winsys *winsys);

const struct intel_winsys_info *
intel_winsys_get_info(const struct intel_winsys *winsys);

/**
 * Create a logical context for use with the render ring.
 */
struct intel_context *
intel_winsys_create_context(struct intel_winsys *winsys);

/**
 * Destroy a logical context.
 */
void
intel_winsys_destroy_context(struct intel_winsys *winsys,
                             struct intel_context *ctx);

/**
 * Read a register.  Only registers that are considered safe, such as
 *
 *   TIMESTAMP (0x2358)
 *
 * can be read.
 */
int
intel_winsys_read_reg(struct intel_winsys *winsys,
                      uint32_t reg, uint64_t *val);

/**
 * Allocate a linear buffer object.
 *
 * \param name             Informative description of the bo.
 * \param size             Size of the bo.
 * \param flags            bitmask of enum intel_alloc_flag.
 */
struct intel_bo *
intel_winsys_alloc_buffer(struct intel_winsys *winsys,
                          const char *name,
                          unsigned long size,
                          unsigned long flags);

/**
 * Allocate a 2-dimentional buffer object.
 *
 * \param name             Informative description of the bo.
 * \param width            Width of the bo.
 * \param height           Height of the bo.
 * \param cpp              Bytes per texel.
 * \param tiling           Tiling mode.
 * \param flags            bitmask of enum intel_alloc_flag.
 * \param pitch            Pitch of the bo.
 */
struct intel_bo *
intel_winsys_alloc_texture(struct intel_winsys *winsys,
                           const char *name,
                           int width, int height, int cpp,
                           enum intel_tiling_mode tiling,
                           unsigned long flags,
                           unsigned long *pitch);

/**
 * Create a bo from a winsys handle.
 */
struct intel_bo *
intel_winsys_import_handle(struct intel_winsys *winsys,
                           const char *name,
                           const struct winsys_handle *handle,
                           int width, int height, int cpp,
                           enum intel_tiling_mode *tiling,
                           unsigned long *pitch);

/**
 * Export \p bo as a winsys handle for inter-process sharing.
 */
int
intel_winsys_export_handle(struct intel_winsys *winsys,
                           struct intel_bo *bo,
                           enum intel_tiling_mode tiling,
                           unsigned long pitch,
                           struct winsys_handle *handle);

/**
 * Check that buffer objects directly specified in \p bo_array, and those
 * indirectly referenced by them, can fit in the aperture space.
 */
int
intel_winsys_check_aperture_space(struct intel_winsys *winsys,
                                  struct intel_bo **bo_array,
                                  int count);

/**
 * Decode the commands contained in \p bo.  For debugging.
 *
 * \param bo      Batch buffer to decode.
 * \param used    Size of the commands in bytes.
 */
void
intel_winsys_decode_commands(struct intel_winsys *winsys,
                             struct intel_bo *bo, int used);

/**
 * Increase the reference count of \p bo.
 */
void
intel_bo_reference(struct intel_bo *bo);

/**
 * Decrease the reference count of \p bo.  When the reference count reaches
 * zero, \p bo is destroyed.
 */
void
intel_bo_unreference(struct intel_bo *bo);

/**
 * Return the real size of \p bo.  It may be larger than the size specified
 * in allocation due to alignment and padding requirements.
 */
unsigned long
intel_bo_get_size(const struct intel_bo *bo);

/**
 * Map \p bo for CPU access.  Recursive mapping is allowed.
 *
 * map() maps the backing store into CPU address space, cached.  It will block
 * if the bo is busy.  This variant allows fastest random reads and writes,
 * but the caller needs to handle tiling or swizzling manually if the bo is
 * tiled or swizzled.  If write is enabled and there is no shared last-level
 * cache (LLC), the CPU cache will be flushed, which is expensive.
 *
 * map_gtt() maps the bo for MMIO access, uncached but write-combined.  It
 * will block if the bo is busy.  This variant promises a reasonable speed for
 * sequential writes, but reads would be very slow.  Callers always have a
 * linear view of the bo.
 *
 * map_unsynchronized() is similar to map_gtt(), except that it does not
 * block.
 */
void *
intel_bo_map(struct intel_bo *bo, bool write_enable);

void *
intel_bo_map_gtt(struct intel_bo *bo);

void *
intel_bo_map_unsynchronized(struct intel_bo *bo);

/**
 * Unmap \p bo.
 */
void
intel_bo_unmap(struct intel_bo *bo);

/**
 * Write data to \p bo.
 */
int
intel_bo_pwrite(struct intel_bo *bo, unsigned long offset,
                unsigned long size, const void *data);

/**
 * Read data from the bo.
 */
int
intel_bo_pread(struct intel_bo *bo, unsigned long offset,
               unsigned long size, void *data);

/**
 * Add \p target_bo to the relocation list.
 *
 * When \p bo is submitted for execution, and if \p target_bo has moved,
 * the kernel will patch \p bo at \p offset to \p target_bo->offset plus
 * \p target_offset.
 */
int
intel_bo_add_reloc(struct intel_bo *bo, uint32_t offset,
                   struct intel_bo *target_bo, uint32_t target_offset,
                   uint32_t read_domains, uint32_t write_domain,
                   uint64_t *presumed_offset);

/**
 * Return the current number of relocations.
 */
int
intel_bo_get_reloc_count(struct intel_bo *bo);

/**
 * Truncate all relocations except the first \p start ones.
 *
 * Combined with \p intel_bo_get_reloc_count(), they can be used to undo the
 * \p intel_bo_add_reloc() calls that were just made.
 */
void
intel_bo_truncate_relocs(struct intel_bo *bo, int start);

/**
 * Return true if \p target_bo is on the relocation list of \p bo, or on
 * the relocation list of some bo that is referenced by \p bo.
 */
bool
intel_bo_has_reloc(struct intel_bo *bo, struct intel_bo *target_bo);

/**
 * Submit \p bo for execution.
 *
 * \p bo and all bos referenced by \p bo will be considered busy until all
 * commands are parsed and executed.
 */
int
intel_bo_exec(struct intel_bo *bo, int used,
              struct intel_context *ctx, unsigned long flags);

/**
 * Wait until \bo is idle, or \p timeout nanoseconds have passed.  A
 * negative timeout means to wait indefinitely.
 *
 * \return 0 only when \p bo is idle
 */
int
intel_bo_wait(struct intel_bo *bo, int64_t timeout);

/**
 * Return true if \p bo is busy.
 */
static inline bool
intel_bo_is_busy(struct intel_bo *bo)
{
   return (intel_bo_wait(bo, 0) != 0);
}

#endif /* INTEL_WINSYS_H */