f61c541ad1517ef50e9210f0b2d0108ea9709710
[mesa.git] / src / gallium / drivers / i965 / brw_winsys.h
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 BRW_WINSYS_H
27 #define BRW_WINSYS_H
28
29 #include "pipe/p_compiler.h"
30 #include "pipe/p_error.h"
31 #include "pipe/p_refcnt.h"
32
33 struct brw_winsys;
34 struct pipe_fence_handle;
35
36 /* Not sure why the winsys needs this:
37 */
38 #define BRW_BATCH_SIZE (32*1024)
39
40 struct brw_winsys_screen;
41
42 /* Need a tiny bit of information inside the abstract buffer struct:
43 */
44 struct brw_winsys_buffer {
45 struct pipe_reference reference;
46 struct brw_winsys_screen *sws;
47 unsigned *offset;
48 unsigned size;
49 };
50
51
52 /* Should be possible to validate usages above against buffer creation
53 * types, below:
54 */
55 enum brw_buffer_type
56 {
57 BRW_BUFFER_TYPE_TEXTURE,
58 BRW_BUFFER_TYPE_SCANOUT, /**< a texture used for scanning out from */
59 BRW_BUFFER_TYPE_VERTEX,
60 BRW_BUFFER_TYPE_CURBE,
61 BRW_BUFFER_TYPE_QUERY,
62 BRW_BUFFER_TYPE_SHADER_CONSTANTS,
63 BRW_BUFFER_TYPE_SHADER_SCRATCH,
64 BRW_BUFFER_TYPE_BATCH,
65 BRW_BUFFER_TYPE_GENERAL_STATE,
66 BRW_BUFFER_TYPE_SURFACE_STATE,
67 BRW_BUFFER_TYPE_PIXEL, /* image uploads, pbo's, etc */
68 BRW_BUFFER_TYPE_GENERIC, /* unknown */
69 BRW_BUFFER_TYPE_MAX /* Count of possible values */
70 };
71
72
73 /* Describe the usage of a particular buffer in a relocation. The DRM
74 * winsys will translate these back to GEM read/write domain flags.
75 */
76 enum brw_buffer_usage {
77 BRW_USAGE_STATE, /* INSTRUCTION, 0 */
78 BRW_USAGE_QUERY_RESULT, /* INSTRUCTION, INSTRUCTION */
79 BRW_USAGE_RENDER_TARGET, /* RENDER, 0 */
80 BRW_USAGE_DEPTH_BUFFER, /* RENDER, RENDER */
81 BRW_USAGE_BLIT_SOURCE, /* RENDER, 0 */
82 BRW_USAGE_BLIT_DEST, /* RENDER, RENDER */
83 BRW_USAGE_SAMPLER, /* SAMPLER, 0 */
84 BRW_USAGE_VERTEX, /* VERTEX, 0 */
85 BRW_USAGE_SCRATCH, /* 0, 0 */
86 BRW_USAGE_MAX
87 };
88
89 enum brw_buffer_data_type {
90 BRW_DATA_GS_CC_VP,
91 BRW_DATA_GS_CC_UNIT,
92 BRW_DATA_GS_WM_PROG,
93 BRW_DATA_GS_SAMPLER_DEFAULT_COLOR,
94 BRW_DATA_GS_SAMPLER,
95 BRW_DATA_GS_WM_UNIT,
96 BRW_DATA_GS_SF_PROG,
97 BRW_DATA_GS_SF_VP,
98 BRW_DATA_GS_SF_UNIT,
99 BRW_DATA_GS_VS_UNIT,
100 BRW_DATA_GS_VS_PROG,
101 BRW_DATA_GS_GS_UNIT,
102 BRW_DATA_GS_GS_PROG,
103 BRW_DATA_GS_CLIP_VP,
104 BRW_DATA_GS_CLIP_UNIT,
105 BRW_DATA_GS_CLIP_PROG,
106 BRW_DATA_SS_SURFACE,
107 BRW_DATA_SS_SURF_BIND,
108 BRW_DATA_OTHER,
109 BRW_DATA_MAX
110 };
111
112
113
114
115
116 struct brw_winsys_screen {
117
118
119 /**
120 * Buffer functions.
121 */
122
123 /*@{*/
124 /**
125 * Create a buffer.
126 */
127 enum pipe_error (*bo_alloc)( struct brw_winsys_screen *sws,
128 enum brw_buffer_type type,
129 unsigned size,
130 unsigned alignment,
131 struct brw_winsys_buffer **bo_out );
132
133 /* Destroy a buffer when our refcount goes to zero:
134 */
135 void (*bo_destroy)( struct brw_winsys_buffer *buffer );
136
137 /* delta -- added to b2->offset, and written into buffer
138 * offset -- location above value is written to within buffer
139 */
140 enum pipe_error (*bo_emit_reloc)( struct brw_winsys_buffer *buffer,
141 enum brw_buffer_usage usage,
142 unsigned delta,
143 unsigned offset,
144 struct brw_winsys_buffer *b2);
145
146 enum pipe_error (*bo_exec)( struct brw_winsys_buffer *buffer,
147 unsigned bytes_used );
148
149 enum pipe_error (*bo_subdata)(struct brw_winsys_buffer *buffer,
150 enum brw_buffer_data_type data_type,
151 size_t offset,
152 size_t size,
153 const void *data);
154
155 boolean (*bo_is_busy)(struct brw_winsys_buffer *buffer);
156 boolean (*bo_references)(struct brw_winsys_buffer *a,
157 struct brw_winsys_buffer *b);
158
159 /* XXX: couldn't this be handled by returning true/false on
160 * bo_emit_reloc?
161 */
162 enum pipe_error (*check_aperture_space)( struct brw_winsys_screen *iws,
163 struct brw_winsys_buffer **buffers,
164 unsigned count );
165
166 /**
167 * Map a buffer.
168 */
169 void *(*bo_map)(struct brw_winsys_buffer *buffer,
170 enum brw_buffer_data_type data_type,
171 boolean write);
172
173 /**
174 * Unmap a buffer.
175 */
176 void (*bo_unmap)(struct brw_winsys_buffer *buffer);
177 /*@}*/
178
179 /**
180 * Destroy the winsys.
181 */
182 void (*destroy)(struct brw_winsys_screen *iws);
183 };
184
185
186 static INLINE void
187 bo_reference(struct brw_winsys_buffer **ptr, struct brw_winsys_buffer *buf)
188 {
189 struct brw_winsys_buffer *old_buf = *ptr;
190
191 if (pipe_reference((struct pipe_reference **)ptr, &buf->reference))
192 old_buf->sws->bo_destroy(old_buf);
193 }
194
195
196 /**
197 * Create brw pipe_screen.
198 */
199 struct pipe_screen *brw_create_screen(struct brw_winsys_screen *iws, unsigned pci_id);
200
201 /**
202 * Create a brw pipe_context.
203 */
204 struct pipe_context *brw_create_context(struct pipe_screen *screen);
205
206 /**
207 * Get the brw_winsys buffer backing the texture.
208 *
209 * TODO UGLY
210 */
211 struct pipe_texture;
212 boolean brw_texture_get_winsys_buffer(struct pipe_texture *texture,
213 struct brw_winsys_buffer **buffer,
214 unsigned *stride);
215
216 /**
217 * Wrap a brw_winsys buffer with a texture blanket.
218 *
219 * TODO UGLY
220 */
221 struct pipe_texture *
222 brw_texture_blanket_winsys_buffer(struct pipe_screen *screen,
223 const struct pipe_texture *template,
224 const unsigned pitch,
225 struct brw_winsys_buffer *buffer);
226
227
228
229
230 #endif