mesa: merge gallium-0.2 into gallium-master-merge
[mesa.git] / src / gallium / drivers / i965simple / brw_winsys.h
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /**
29 * \file
30 * This is the interface that i965simple requires any window system
31 * hosting it to implement. This is the only include file in i965simple
32 * which is public.
33 *
34 */
35
36 #ifndef BRW_WINSYS_H
37 #define BRW_WINSYS_H
38
39
40 #include "pipe/p_defines.h"
41
42
43 /* Pipe drivers are (meant to be!) independent of both GL and the
44 * window system. The window system provides a buffer manager and a
45 * set of additional hooks for things like command buffer submission,
46 * etc.
47 *
48 * There clearly has to be some agreement between the window system
49 * driver and the hardware driver about the format of command buffers,
50 * etc.
51 */
52
53 struct pipe_buffer;
54 struct pipe_fence_handle;
55 struct pipe_winsys;
56 struct pipe_screen;
57
58
59 /* The pipe driver currently understands the following chipsets:
60 */
61 #define PCI_CHIP_I965_G 0x29A2
62 #define PCI_CHIP_I965_Q 0x2992
63 #define PCI_CHIP_I965_G_1 0x2982
64 #define PCI_CHIP_I965_GM 0x2A02
65 #define PCI_CHIP_I965_GME 0x2A12
66
67
68 /* These are the names of all the state caches managed by the driver.
69 *
70 * When data is uploaded to a buffer with buffer_subdata, we use the
71 * special version of that function below so that information about
72 * what type of data this is can be passed to the winsys backend.
73 * That in turn allows the correct flags to be set in the aub file
74 * dump to allow human-readable file dumps later on.
75 */
76
77 enum brw_cache_id {
78 BRW_CC_VP,
79 BRW_CC_UNIT,
80 BRW_WM_PROG,
81 BRW_SAMPLER_DEFAULT_COLOR,
82 BRW_SAMPLER,
83 BRW_WM_UNIT,
84 BRW_SF_PROG,
85 BRW_SF_VP,
86 BRW_SF_UNIT,
87 BRW_VS_UNIT,
88 BRW_VS_PROG,
89 BRW_GS_UNIT,
90 BRW_GS_PROG,
91 BRW_CLIP_VP,
92 BRW_CLIP_UNIT,
93 BRW_CLIP_PROG,
94 BRW_SS_SURFACE,
95 BRW_SS_SURF_BIND,
96
97 BRW_MAX_CACHE
98 };
99
100 #define BRW_CONSTANT_BUFFER BRW_MAX_CACHE
101
102 /**
103 * Additional winsys interface for i965simple.
104 *
105 * It is an over-simple batchbuffer mechanism. Will want to improve the
106 * performance of this, perhaps based on the cmdstream stuff. It
107 * would be pretty impossible to implement swz on top of this
108 * interface.
109 *
110 * Will also need additions/changes to implement static/dynamic
111 * indirect state.
112 */
113 struct brw_winsys {
114
115 void (*destroy)(struct brw_winsys *);
116
117 /**
118 * Reserve space on batch buffer.
119 *
120 * Returns a null pointer if there is insufficient space in the batch buffer
121 * to hold the requested number of dwords and relocations.
122 *
123 * The number of dwords should also include the number of relocations.
124 */
125 unsigned *(*batch_start)(struct brw_winsys *sws,
126 unsigned dwords,
127 unsigned relocs);
128
129 void (*batch_dword)(struct brw_winsys *sws,
130 unsigned dword);
131
132 /**
133 * Emit a relocation to a buffer.
134 *
135 * Used not only when the buffer addresses are not pinned, but also to
136 * ensure refered buffers will not be destroyed until the current batch
137 * buffer execution is finished.
138 *
139 * The access flags is a combination of I915_BUFFER_ACCESS_WRITE and
140 * I915_BUFFER_ACCESS_READ macros.
141 */
142 void (*batch_reloc)(struct brw_winsys *sws,
143 struct pipe_buffer *buf,
144 unsigned access_flags,
145 unsigned delta);
146
147
148 /* Not used yet, but really want this:
149 */
150 void (*batch_end)( struct brw_winsys *sws );
151
152 /**
153 * Flush the batch buffer.
154 *
155 * Fence argument must point to NULL or to a previous fence, and the caller
156 * must call fence_reference when done with the fence.
157 */
158 void (*batch_flush)(struct brw_winsys *sws,
159 struct pipe_fence_handle **fence);
160
161
162 /* A version of buffer_subdata that includes information for the
163 * simulator:
164 */
165 void (*buffer_subdata_typed)(struct brw_winsys *sws,
166 struct pipe_buffer *buf,
167 unsigned long offset,
168 unsigned long size,
169 const void *data,
170 unsigned data_type);
171
172
173 /* A cheat so we don't have to think about relocations in a couple
174 * of places yet:
175 */
176 unsigned (*get_buffer_offset)( struct brw_winsys *sws,
177 struct pipe_buffer *buf,
178 unsigned flags );
179
180 };
181
182 #define BRW_BUFFER_ACCESS_WRITE 0x1
183 #define BRW_BUFFER_ACCESS_READ 0x2
184
185 #define BRW_BUFFER_USAGE_LIT_VERTEX (PIPE_BUFFER_USAGE_CUSTOM << 0)
186
187
188 struct pipe_context *brw_create(struct pipe_screen *,
189 struct brw_winsys *,
190 unsigned pci_id);
191
192 static inline boolean brw_batchbuffer_data(struct brw_winsys *winsys,
193 const void *data,
194 unsigned bytes)
195 {
196 static const unsigned incr = sizeof(unsigned);
197 uint i;
198 const unsigned *udata = (const unsigned*)(data);
199 unsigned size = bytes/incr;
200
201 winsys->batch_start(winsys, size, 0);
202 for (i = 0; i < size; ++i) {
203 winsys->batch_dword(winsys, udata[i]);
204 }
205 winsys->batch_end(winsys);
206
207 return (i == size);
208 }
209 #endif