1 /**************************************************************************
3 * Copyright © 2009 Jakob Bornecrantz
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:
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
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.
24 **************************************************************************/
29 #include "pipe/p_compiler.h"
30 #include "pipe/p_defines.h"
31 #include "util/u_inlines.h"
34 struct pipe_fence_handle;
36 /* Not sure why the winsys needs this:
38 #define BRW_BATCH_SIZE (32*1024)
40 struct brw_winsys_screen;
42 /* Need a tiny bit of information inside the abstract buffer struct:
44 struct brw_winsys_buffer {
45 struct pipe_reference reference;
46 struct brw_winsys_screen *sws;
51 /* Should be possible to validate usages above against buffer creation
56 BRW_BUFFER_TYPE_TEXTURE,
57 BRW_BUFFER_TYPE_SCANOUT, /**< a texture used for scanning out from */
58 BRW_BUFFER_TYPE_VERTEX,
59 BRW_BUFFER_TYPE_CURBE,
60 BRW_BUFFER_TYPE_QUERY,
61 BRW_BUFFER_TYPE_SHADER_CONSTANTS,
62 BRW_BUFFER_TYPE_SHADER_SCRATCH,
63 BRW_BUFFER_TYPE_BATCH,
64 BRW_BUFFER_TYPE_GENERAL_STATE,
65 BRW_BUFFER_TYPE_SURFACE_STATE,
66 BRW_BUFFER_TYPE_PIXEL, /* image uploads, pbo's, etc */
67 BRW_BUFFER_TYPE_GENERIC, /* unknown */
68 BRW_BUFFER_TYPE_MAX /* Count of possible values */
72 /* Describe the usage of a particular buffer in a relocation. The DRM
73 * winsys will translate these back to GEM read/write domain flags.
75 enum brw_buffer_usage {
76 BRW_USAGE_STATE, /* INSTRUCTION, 0 */
77 BRW_USAGE_QUERY_RESULT, /* INSTRUCTION, INSTRUCTION */
78 BRW_USAGE_RENDER_TARGET, /* RENDER, 0 */
79 BRW_USAGE_DEPTH_BUFFER, /* RENDER, RENDER */
80 BRW_USAGE_BLIT_SOURCE, /* RENDER, 0 */
81 BRW_USAGE_BLIT_DEST, /* RENDER, RENDER */
82 BRW_USAGE_SAMPLER, /* SAMPLER, 0 */
83 BRW_USAGE_VERTEX, /* VERTEX, 0 */
84 BRW_USAGE_SCRATCH, /* 0, 0 */
88 enum brw_buffer_data_type {
92 BRW_DATA_GS_SAMPLER_DEFAULT_COLOR,
103 BRW_DATA_GS_CLIP_UNIT,
104 BRW_DATA_GS_CLIP_PROG,
106 BRW_DATA_SS_SURF_BIND,
107 BRW_DATA_CONSTANT_BUFFER,
108 BRW_DATA_BATCH_BUFFER,
114 /* Matches the i915_drm definitions:
116 #define BRW_TILING_NONE 0
117 #define BRW_TILING_X 1
118 #define BRW_TILING_Y 2
121 /* Relocations to be applied with subdata in a call to sws->bo_subdata, below.
123 * Effectively this encodes:
125 * (unsigned *)(subdata + offset) = bo->offset + delta
127 struct brw_winsys_reloc {
128 enum brw_buffer_usage usage; /* debug only */
131 struct brw_winsys_buffer *bo;
134 static INLINE void make_reloc(struct brw_winsys_reloc *reloc,
135 enum brw_buffer_usage usage,
138 struct brw_winsys_buffer *bo)
140 reloc->usage = usage;
141 reloc->delta = delta;
142 reloc->offset = offset;
143 reloc->bo = bo; /* Note - note taking a reference yet */
148 struct brw_winsys_screen {
160 enum pipe_error (*bo_alloc)(struct brw_winsys_screen *sws,
161 enum brw_buffer_type type,
164 struct brw_winsys_buffer **bo_out);
166 enum pipe_error (*bo_from_handle)(struct brw_winsys_screen *sws,
167 struct winsys_handle *whandle,
170 struct brw_winsys_buffer **bo_out);
172 enum pipe_error (*bo_get_handle)(struct brw_winsys_buffer *buffer,
173 struct winsys_handle *whandle,
176 /* Destroy a buffer when our refcount goes to zero:
178 void (*bo_destroy)(struct brw_winsys_buffer *buffer);
180 /* delta -- added to b2->offset, and written into buffer
181 * offset -- location above value is written to within buffer
183 enum pipe_error (*bo_emit_reloc)(struct brw_winsys_buffer *buffer,
184 enum brw_buffer_usage usage,
187 struct brw_winsys_buffer *b2);
189 enum pipe_error (*bo_exec)(struct brw_winsys_buffer *buffer,
190 unsigned bytes_used);
192 enum pipe_error (*bo_subdata)(struct brw_winsys_buffer *buffer,
193 enum brw_buffer_data_type data_type,
197 const struct brw_winsys_reloc *reloc,
200 boolean (*bo_is_busy)(struct brw_winsys_buffer *buffer);
201 boolean (*bo_references)(struct brw_winsys_buffer *a,
202 struct brw_winsys_buffer *b);
204 /* XXX: couldn't this be handled by returning true/false on
207 enum pipe_error (*check_aperture_space)(struct brw_winsys_screen *iws,
208 struct brw_winsys_buffer **buffers,
214 void *(*bo_map)(struct brw_winsys_buffer *buffer,
215 enum brw_buffer_data_type data_type,
220 boolean flush_explicit);
222 void (*bo_flush_range)(struct brw_winsys_buffer *buffer,
229 void (*bo_unmap)(struct brw_winsys_buffer *buffer);
233 /* Wait for buffer to go idle. Similar to map+unmap, but doesn't
234 * mark buffer contents as dirty.
236 void (*bo_wait_idle)(struct brw_winsys_buffer *buffer);
239 * Destroy the winsys.
241 void (*destroy)(struct brw_winsys_screen *iws);
245 bo_map_read(struct brw_winsys_screen *sws, struct brw_winsys_buffer *buf)
247 return sws->bo_map( buf,
250 FALSE, FALSE, FALSE );
254 bo_reference(struct brw_winsys_buffer **ptr, struct brw_winsys_buffer *buf)
256 struct brw_winsys_buffer *old_buf = *ptr;
258 if (pipe_reference(&(*ptr)->reference, &buf->reference))
259 old_buf->sws->bo_destroy(old_buf);
266 /*************************************************************************
267 * Cooperative dumping between winsys and driver. TODO: make this
268 * driver-only by wrapping calls to winsys->bo_subdata().
278 #define DUMP_STATE 0x2
279 #define DUMP_BATCH 0x4
281 void brw_dump_data( unsigned pci_id,
282 enum brw_buffer_data_type data_type,
285 size_t size, int gen );