texenvprogram: fix for ARB_draw_buffers.
[mesa.git] / src / gallium / drivers / i915 / intel_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 INTEL_WINSYS_H
27 #define INTEL_WINSYS_H
28
29 #include "pipe/p_compiler.h"
30
31 struct intel_winsys;
32 struct intel_buffer;
33 struct intel_batchbuffer;
34 struct pipe_texture;
35 struct pipe_fence_handle;
36
37 enum intel_buffer_usage
38 {
39 /* use on textures */
40 INTEL_USAGE_RENDER = 0x01,
41 INTEL_USAGE_SAMPLER = 0x02,
42 INTEL_USAGE_2D_TARGET = 0x04,
43 INTEL_USAGE_2D_SOURCE = 0x08,
44 /* use on vertex */
45 INTEL_USAGE_VERTEX = 0x10
46 };
47
48 enum intel_buffer_type
49 {
50 INTEL_NEW_TEXTURE,
51 INTEL_NEW_SCANOUT, /**< a texture used for scanning out from */
52 INTEL_NEW_VERTEX
53 };
54
55 enum intel_buffer_tile
56 {
57 INTEL_TILE_NONE,
58 INTEL_TILE_X,
59 INTEL_TILE_Y
60 };
61
62 struct intel_batchbuffer {
63
64 struct intel_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 size_t max_relocs;
78 /*@}*/
79 };
80
81 struct intel_winsys {
82
83 /**
84 * Batchbuffer functions.
85 */
86 /*@{*/
87 /**
88 * Create a new batchbuffer.
89 */
90 struct intel_batchbuffer *(*batchbuffer_create)(struct intel_winsys *iws);
91
92 /**
93 * Emit a relocation to a buffer.
94 * Target position in batchbuffer is the same as ptr.
95 *
96 * @batch
97 * @reloc buffer address to be inserted into target.
98 * @usage how is the hardware going to use the buffer.
99 * @offset add this to the reloc buffers address
100 * @target buffer where to write the address, null for batchbuffer.
101 */
102 int (*batchbuffer_reloc)(struct intel_batchbuffer *batch,
103 struct intel_buffer *reloc,
104 enum intel_buffer_usage usage,
105 unsigned offset);
106
107 /**
108 * Flush a bufferbatch.
109 */
110 void (*batchbuffer_flush)(struct intel_batchbuffer *batch,
111 struct pipe_fence_handle **fence);
112
113 /**
114 * Destroy a batchbuffer.
115 */
116 void (*batchbuffer_destroy)(struct intel_batchbuffer *batch);
117 /*@}*/
118
119
120 /**
121 * Buffer functions.
122 */
123 /*@{*/
124 /**
125 * Create a buffer.
126 */
127 struct intel_buffer *(*buffer_create)(struct intel_winsys *iws,
128 unsigned size, unsigned alignment,
129 enum intel_buffer_type type);
130
131 /**
132 * Fence a buffer with a fence reg.
133 * Not to be confused with pipe_fence_handle.
134 */
135 int (*buffer_set_fence_reg)(struct intel_winsys *iws,
136 struct intel_buffer *buffer,
137 unsigned stride,
138 enum intel_buffer_tile tile);
139
140 /**
141 * Map a buffer.
142 */
143 void *(*buffer_map)(struct intel_winsys *iws,
144 struct intel_buffer *buffer,
145 boolean write);
146
147 /**
148 * Unmap a buffer.
149 */
150 void (*buffer_unmap)(struct intel_winsys *iws,
151 struct intel_buffer *buffer);
152
153 /**
154 * Write to a buffer.
155 *
156 * Arguments follows pipe_buffer_write.
157 */
158 int (*buffer_write)(struct intel_winsys *iws,
159 struct intel_buffer *dst,
160 size_t offset,
161 size_t size,
162 const void *data);
163
164 void (*buffer_destroy)(struct intel_winsys *iws,
165 struct intel_buffer *buffer);
166 /*@}*/
167
168
169 /**
170 * Fence functions.
171 */
172 /*@{*/
173 /**
174 * Reference fence and set ptr to fence.
175 */
176 void (*fence_reference)(struct intel_winsys *iws,
177 struct pipe_fence_handle **ptr,
178 struct pipe_fence_handle *fence);
179
180 /**
181 * Check if a fence has finished.
182 */
183 int (*fence_signalled)(struct intel_winsys *iws,
184 struct pipe_fence_handle *fence);
185
186 /**
187 * Wait on a fence to finish.
188 */
189 int (*fence_finish)(struct intel_winsys *iws,
190 struct pipe_fence_handle *fence);
191 /*@}*/
192
193
194 /**
195 * Destroy the winsys.
196 */
197 void (*destroy)(struct intel_winsys *iws);
198 };
199
200
201 /**
202 * Create i915 pipe_screen.
203 */
204 struct pipe_screen *i915_create_screen(struct intel_winsys *iws, unsigned pci_id);
205
206
207 /**
208 * Get the intel_winsys buffer backing the texture.
209 *
210 * TODO UGLY
211 */
212 boolean i915_get_texture_buffer_intel(struct pipe_texture *texture,
213 struct intel_buffer **buffer,
214 unsigned *stride);
215
216 /**
217 * Wrap a intel_winsys buffer with a texture blanket.
218 *
219 * TODO UGLY
220 */
221 struct pipe_texture * i915_texture_blanket_intel(struct pipe_screen *screen,
222 struct pipe_texture *tmplt,
223 unsigned pitch,
224 struct intel_buffer *buffer);
225
226 #endif