diff options
author | Corbin Simpson <MostAwesomeDude@gmail.com> | 2010-06-22 21:58:56 -0700 |
---|---|---|
committer | Corbin Simpson <MostAwesomeDude@gmail.com> | 2010-06-22 22:49:13 -0700 |
commit | d3ad6fa579d89d8c3ee27882d5baf8f8d2ecb3ea (patch) | |
tree | ca26907c6433d7519077e51989c7201c538b5407 | |
parent | 61ec20581696004acad516b14ca4a8a5ae9e6f1d (diff) |
gallium/drivers: Create Galahad from identity.
Galahad is a sanity-checking layer meant to replace the crufty and
scattered sanity checks inside drivers with a robust, non-silenceable,
useful set of warnings and errors that can be used to keep misbehaving
state trackers from going unnoticed.
-rw-r--r-- | src/gallium/drivers/galahad/Makefile | 12 | ||||
-rw-r--r-- | src/gallium/drivers/galahad/SConscript | 14 | ||||
-rw-r--r-- | src/gallium/drivers/galahad/glhd_context.c | 952 | ||||
-rw-r--r-- | src/gallium/drivers/galahad/glhd_context.h | 52 | ||||
-rw-r--r-- | src/gallium/drivers/galahad/glhd_drm.c | 93 | ||||
-rw-r--r-- | src/gallium/drivers/galahad/glhd_drm.h | 35 | ||||
-rw-r--r-- | src/gallium/drivers/galahad/glhd_objects.c | 186 | ||||
-rw-r--r-- | src/gallium/drivers/galahad/glhd_objects.h | 176 | ||||
-rw-r--r-- | src/gallium/drivers/galahad/glhd_public.h | 37 | ||||
-rw-r--r-- | src/gallium/drivers/galahad/glhd_screen.c | 325 | ||||
-rw-r--r-- | src/gallium/drivers/galahad/glhd_screen.h | 48 |
11 files changed, 1930 insertions, 0 deletions
diff --git a/src/gallium/drivers/galahad/Makefile b/src/gallium/drivers/galahad/Makefile new file mode 100644 index 00000000000..d5df84b71b8 --- /dev/null +++ b/src/gallium/drivers/galahad/Makefile | |||
@@ -0,0 +1,12 @@ | |||
1 | TOP = ../../../.. | ||
2 | include $(TOP)/configs/current | ||
3 | |||
4 | LIBNAME = identity | ||
5 | |||
6 | C_SOURCES = \ | ||
7 | glhd_objects.c \ | ||
8 | glhd_context.c \ | ||
9 | glhd_screen.c \ | ||
10 | glhd_drm.c | ||
11 | |||
12 | include ../../Makefile.template | ||
diff --git a/src/gallium/drivers/galahad/SConscript b/src/gallium/drivers/galahad/SConscript new file mode 100644 index 00000000000..fc668facaf5 --- /dev/null +++ b/src/gallium/drivers/galahad/SConscript | |||
@@ -0,0 +1,14 @@ | |||
1 | Import('*') | ||
2 | |||
3 | env = env.Clone() | ||
4 | |||
5 | identity = env.ConvenienceLibrary( | ||
6 | target = 'identity', | ||
7 | source = [ | ||
8 | 'glhd_context.c', | ||
9 | 'glhd_drm.c', | ||
10 | 'glhd_objects.c', | ||
11 | 'glhd_screen.c', | ||
12 | ]) | ||
13 | |||
14 | Export('identity') | ||
diff --git a/src/gallium/drivers/galahad/glhd_context.c b/src/gallium/drivers/galahad/glhd_context.c new file mode 100644 index 00000000000..ae4fc923e42 --- /dev/null +++ b/src/gallium/drivers/galahad/glhd_context.c | |||
@@ -0,0 +1,952 @@ | |||
1 | /************************************************************************** | ||
2 | * | ||
3 | * Copyright 2009 VMware, Inc. | ||
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 VMWARE 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 | #include "pipe/p_context.h" | ||
30 | #include "util/u_memory.h" | ||
31 | #include "util/u_inlines.h" | ||
32 | |||
33 | #include "glhd_context.h" | ||
34 | #include "glhd_objects.h" | ||
35 | |||
36 | |||
37 | static void | ||
38 | galahad_destroy(struct pipe_context *_pipe) | ||
39 | { | ||
40 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
41 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
42 | |||
43 | pipe->destroy(pipe); | ||
44 | |||
45 | FREE(glhd_pipe); | ||
46 | } | ||
47 | |||
48 | static void | ||
49 | galahad_draw_arrays(struct pipe_context *_pipe, | ||
50 | unsigned prim, | ||
51 | unsigned start, | ||
52 | unsigned count) | ||
53 | { | ||
54 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
55 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
56 | |||
57 | pipe->draw_arrays(pipe, | ||
58 | prim, | ||
59 | start, | ||
60 | count); | ||
61 | } | ||
62 | |||
63 | static void | ||
64 | galahad_draw_elements(struct pipe_context *_pipe, | ||
65 | struct pipe_resource *_indexResource, | ||
66 | unsigned indexSize, | ||
67 | int indexBias, | ||
68 | unsigned prim, | ||
69 | unsigned start, | ||
70 | unsigned count) | ||
71 | { | ||
72 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
73 | struct galahad_resource *glhd_resource = galahad_resource(_indexResource); | ||
74 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
75 | struct pipe_resource *indexResource = glhd_resource->resource; | ||
76 | |||
77 | pipe->draw_elements(pipe, | ||
78 | indexResource, | ||
79 | indexSize, | ||
80 | indexBias, | ||
81 | prim, | ||
82 | start, | ||
83 | count); | ||
84 | } | ||
85 | |||
86 | static void | ||
87 | galahad_draw_range_elements(struct pipe_context *_pipe, | ||
88 | struct pipe_resource *_indexResource, | ||
89 | unsigned indexSize, | ||
90 | int indexBias, | ||
91 | unsigned minIndex, | ||
92 | unsigned maxIndex, | ||
93 | unsigned mode, | ||
94 | unsigned start, | ||
95 | unsigned count) | ||
96 | { | ||
97 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
98 | struct galahad_resource *glhd_resource = galahad_resource(_indexResource); | ||
99 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
100 | struct pipe_resource *indexResource = glhd_resource->resource; | ||
101 | |||
102 | pipe->draw_range_elements(pipe, | ||
103 | indexResource, | ||
104 | indexSize, | ||
105 | indexBias, | ||
106 | minIndex, | ||
107 | maxIndex, | ||
108 | mode, | ||
109 | start, | ||
110 | count); | ||
111 | } | ||
112 | |||
113 | static struct pipe_query * | ||
114 | galahad_create_query(struct pipe_context *_pipe, | ||
115 | unsigned query_type) | ||
116 | { | ||
117 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
118 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
119 | |||
120 | return pipe->create_query(pipe, | ||
121 | query_type); | ||
122 | } | ||
123 | |||
124 | static void | ||
125 | galahad_destroy_query(struct pipe_context *_pipe, | ||
126 | struct pipe_query *query) | ||
127 | { | ||
128 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
129 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
130 | |||
131 | pipe->destroy_query(pipe, | ||
132 | query); | ||
133 | } | ||
134 | |||
135 | static void | ||
136 | galahad_begin_query(struct pipe_context *_pipe, | ||
137 | struct pipe_query *query) | ||
138 | { | ||
139 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
140 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
141 | |||
142 | pipe->begin_query(pipe, | ||
143 | query); | ||
144 | } | ||
145 | |||
146 | static void | ||
147 | galahad_end_query(struct pipe_context *_pipe, | ||
148 | struct pipe_query *query) | ||
149 | { | ||
150 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
151 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
152 | |||
153 | pipe->end_query(pipe, | ||
154 | query); | ||
155 | } | ||
156 | |||
157 | static boolean | ||
158 | galahad_get_query_result(struct pipe_context *_pipe, | ||
159 | struct pipe_query *query, | ||
160 | boolean wait, | ||
161 | void *result) | ||
162 | { | ||
163 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
164 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
165 | |||
166 | return pipe->get_query_result(pipe, | ||
167 | query, | ||
168 | wait, | ||
169 | result); | ||
170 | } | ||
171 | |||
172 | static void * | ||
173 | galahad_create_blend_state(struct pipe_context *_pipe, | ||
174 | const struct pipe_blend_state *blend) | ||
175 | { | ||
176 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
177 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
178 | |||
179 | return pipe->create_blend_state(pipe, | ||
180 | blend); | ||
181 | } | ||
182 | |||
183 | static void | ||
184 | galahad_bind_blend_state(struct pipe_context *_pipe, | ||
185 | void *blend) | ||
186 | { | ||
187 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
188 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
189 | |||
190 | pipe->bind_blend_state(pipe, | ||
191 | blend); | ||
192 | } | ||
193 | |||
194 | static void | ||
195 | galahad_delete_blend_state(struct pipe_context *_pipe, | ||
196 | void *blend) | ||
197 | { | ||
198 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
199 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
200 | |||
201 | pipe->delete_blend_state(pipe, | ||
202 | blend); | ||
203 | } | ||
204 | |||
205 | static void * | ||
206 | galahad_create_sampler_state(struct pipe_context *_pipe, | ||
207 | const struct pipe_sampler_state *sampler) | ||
208 | { | ||
209 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
210 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
211 | |||
212 | return pipe->create_sampler_state(pipe, | ||
213 | sampler); | ||
214 | } | ||
215 | |||
216 | static void | ||
217 | galahad_bind_fragment_sampler_states(struct pipe_context *_pipe, | ||
218 | unsigned num_samplers, | ||
219 | void **samplers) | ||
220 | { | ||
221 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
222 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
223 | |||
224 | pipe->bind_fragment_sampler_states(pipe, | ||
225 | num_samplers, | ||
226 | samplers); | ||
227 | } | ||
228 | |||
229 | static void | ||
230 | galahad_bind_vertex_sampler_states(struct pipe_context *_pipe, | ||
231 | unsigned num_samplers, | ||
232 | void **samplers) | ||
233 | { | ||
234 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
235 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
236 | |||
237 | pipe->bind_vertex_sampler_states(pipe, | ||
238 | num_samplers, | ||
239 | samplers); | ||
240 | } | ||
241 | |||
242 | static void | ||
243 | galahad_delete_sampler_state(struct pipe_context *_pipe, | ||
244 | void *sampler) | ||
245 | { | ||
246 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
247 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
248 | |||
249 | pipe->delete_sampler_state(pipe, | ||
250 | sampler); | ||
251 | } | ||
252 | |||
253 | static void * | ||
254 | galahad_create_rasterizer_state(struct pipe_context *_pipe, | ||
255 | const struct pipe_rasterizer_state *rasterizer) | ||
256 | { | ||
257 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
258 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
259 | |||
260 | return pipe->create_rasterizer_state(pipe, | ||
261 | rasterizer); | ||
262 | } | ||
263 | |||
264 | static void | ||
265 | galahad_bind_rasterizer_state(struct pipe_context *_pipe, | ||
266 | void *rasterizer) | ||
267 | { | ||
268 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
269 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
270 | |||
271 | pipe->bind_rasterizer_state(pipe, | ||
272 | rasterizer); | ||
273 | } | ||
274 | |||
275 | static void | ||
276 | galahad_delete_rasterizer_state(struct pipe_context *_pipe, | ||
277 | void *rasterizer) | ||
278 | { | ||
279 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
280 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
281 | |||
282 | pipe->delete_rasterizer_state(pipe, | ||
283 | rasterizer); | ||
284 | } | ||
285 | |||
286 | static void * | ||
287 | galahad_create_depth_stencil_alpha_state(struct pipe_context *_pipe, | ||
288 | const struct pipe_depth_stencil_alpha_state *depth_stencil_alpha) | ||
289 | { | ||
290 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
291 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
292 | |||
293 | return pipe->create_depth_stencil_alpha_state(pipe, | ||
294 | depth_stencil_alpha); | ||
295 | } | ||
296 | |||
297 | static void | ||
298 | galahad_bind_depth_stencil_alpha_state(struct pipe_context *_pipe, | ||
299 | void *depth_stencil_alpha) | ||
300 | { | ||
301 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
302 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
303 | |||
304 | pipe->bind_depth_stencil_alpha_state(pipe, | ||
305 | depth_stencil_alpha); | ||
306 | } | ||
307 | |||
308 | static void | ||
309 | galahad_delete_depth_stencil_alpha_state(struct pipe_context *_pipe, | ||
310 | void *depth_stencil_alpha) | ||
311 | { | ||
312 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
313 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
314 | |||
315 | pipe->delete_depth_stencil_alpha_state(pipe, | ||
316 | depth_stencil_alpha); | ||
317 | } | ||
318 | |||
319 | static void * | ||
320 | galahad_create_fs_state(struct pipe_context *_pipe, | ||
321 | const struct pipe_shader_state *fs) | ||
322 | { | ||
323 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
324 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
325 | |||
326 | return pipe->create_fs_state(pipe, | ||
327 | fs); | ||
328 | } | ||
329 | |||
330 | static void | ||
331 | galahad_bind_fs_state(struct pipe_context *_pipe, | ||
332 | void *fs) | ||
333 | { | ||
334 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
335 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
336 | |||
337 | pipe->bind_fs_state(pipe, | ||
338 | fs); | ||
339 | } | ||
340 | |||
341 | static void | ||
342 | galahad_delete_fs_state(struct pipe_context *_pipe, | ||
343 | void *fs) | ||
344 | { | ||
345 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
346 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
347 | |||
348 | pipe->delete_fs_state(pipe, | ||
349 | fs); | ||
350 | } | ||
351 | |||
352 | static void * | ||
353 | galahad_create_vs_state(struct pipe_context *_pipe, | ||
354 | const struct pipe_shader_state *vs) | ||
355 | { | ||
356 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
357 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
358 | |||
359 | return pipe->create_vs_state(pipe, | ||
360 | vs); | ||
361 | } | ||
362 | |||
363 | static void | ||
364 | galahad_bind_vs_state(struct pipe_context *_pipe, | ||
365 | void *vs) | ||
366 | { | ||
367 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
368 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
369 | |||
370 | pipe->bind_vs_state(pipe, | ||
371 | vs); | ||
372 | } | ||
373 | |||
374 | static void | ||
375 | galahad_delete_vs_state(struct pipe_context *_pipe, | ||
376 | void *vs) | ||
377 | { | ||
378 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
379 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
380 | |||
381 | pipe->delete_vs_state(pipe, | ||
382 | vs); | ||
383 | } | ||
384 | |||
385 | |||
386 | static void * | ||
387 | galahad_create_vertex_elements_state(struct pipe_context *_pipe, | ||
388 | unsigned num_elements, | ||
389 | const struct pipe_vertex_element *vertex_elements) | ||
390 | { | ||
391 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
392 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
393 | |||
394 | return pipe->create_vertex_elements_state(pipe, | ||
395 | num_elements, | ||
396 | vertex_elements); | ||
397 | } | ||
398 | |||
399 | static void | ||
400 | galahad_bind_vertex_elements_state(struct pipe_context *_pipe, | ||
401 | void *velems) | ||
402 | { | ||
403 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
404 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
405 | |||
406 | pipe->bind_vertex_elements_state(pipe, | ||
407 | velems); | ||
408 | } | ||
409 | |||
410 | static void | ||
411 | galahad_delete_vertex_elements_state(struct pipe_context *_pipe, | ||
412 | void *velems) | ||
413 | { | ||
414 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
415 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
416 | |||
417 | pipe->delete_vertex_elements_state(pipe, | ||
418 | velems); | ||
419 | } | ||
420 | |||
421 | static void | ||
422 | galahad_set_blend_color(struct pipe_context *_pipe, | ||
423 | const struct pipe_blend_color *blend_color) | ||
424 | { | ||
425 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
426 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
427 | |||
428 | pipe->set_blend_color(pipe, | ||
429 | blend_color); | ||
430 | } | ||
431 | |||
432 | static void | ||
433 | galahad_set_stencil_ref(struct pipe_context *_pipe, | ||
434 | const struct pipe_stencil_ref *stencil_ref) | ||
435 | { | ||
436 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
437 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
438 | |||
439 | pipe->set_stencil_ref(pipe, | ||
440 | stencil_ref); | ||
441 | } | ||
442 | |||
443 | static void | ||
444 | galahad_set_clip_state(struct pipe_context *_pipe, | ||
445 | const struct pipe_clip_state *clip) | ||
446 | { | ||
447 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
448 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
449 | |||
450 | pipe->set_clip_state(pipe, | ||
451 | clip); | ||
452 | } | ||
453 | |||
454 | static void | ||
455 | galahad_set_sample_mask(struct pipe_context *_pipe, | ||
456 | unsigned sample_mask) | ||
457 | { | ||
458 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
459 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
460 | |||
461 | pipe->set_sample_mask(pipe, | ||
462 | sample_mask); | ||
463 | } | ||
464 | |||
465 | static void | ||
466 | galahad_set_constant_buffer(struct pipe_context *_pipe, | ||
467 | uint shader, | ||
468 | uint index, | ||
469 | struct pipe_resource *_resource) | ||
470 | { | ||
471 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
472 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
473 | struct pipe_resource *unwrapped_resource; | ||
474 | struct pipe_resource *resource = NULL; | ||
475 | |||
476 | /* XXX hmm? unwrap the input state */ | ||
477 | if (_resource) { | ||
478 | unwrapped_resource = galahad_resource_unwrap(_resource); | ||
479 | resource = unwrapped_resource; | ||
480 | } | ||
481 | |||
482 | pipe->set_constant_buffer(pipe, | ||
483 | shader, | ||
484 | index, | ||
485 | resource); | ||
486 | } | ||
487 | |||
488 | static void | ||
489 | galahad_set_framebuffer_state(struct pipe_context *_pipe, | ||
490 | const struct pipe_framebuffer_state *_state) | ||
491 | { | ||
492 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
493 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
494 | struct pipe_framebuffer_state unwrapped_state; | ||
495 | struct pipe_framebuffer_state *state = NULL; | ||
496 | unsigned i; | ||
497 | |||
498 | /* unwrap the input state */ | ||
499 | if (_state) { | ||
500 | memcpy(&unwrapped_state, _state, sizeof(unwrapped_state)); | ||
501 | for(i = 0; i < _state->nr_cbufs; i++) | ||
502 | unwrapped_state.cbufs[i] = galahad_surface_unwrap(_state->cbufs[i]); | ||
503 | for (; i < PIPE_MAX_COLOR_BUFS; i++) | ||
504 | unwrapped_state.cbufs[i] = NULL; | ||
505 | unwrapped_state.zsbuf = galahad_surface_unwrap(_state->zsbuf); | ||
506 | state = &unwrapped_state; | ||
507 | } | ||
508 | |||
509 | pipe->set_framebuffer_state(pipe, | ||
510 | state); | ||
511 | } | ||
512 | |||
513 | static void | ||
514 | galahad_set_polygon_stipple(struct pipe_context *_pipe, | ||
515 | const struct pipe_poly_stipple *poly_stipple) | ||
516 | { | ||
517 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
518 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
519 | |||
520 | pipe->set_polygon_stipple(pipe, | ||
521 | poly_stipple); | ||
522 | } | ||
523 | |||
524 | static void | ||
525 | galahad_set_scissor_state(struct pipe_context *_pipe, | ||
526 | const struct pipe_scissor_state *scissor) | ||
527 | { | ||
528 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
529 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
530 | |||
531 | pipe->set_scissor_state(pipe, | ||
532 | scissor); | ||
533 | } | ||
534 | |||
535 | static void | ||
536 | galahad_set_viewport_state(struct pipe_context *_pipe, | ||
537 | const struct pipe_viewport_state *viewport) | ||
538 | { | ||
539 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
540 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
541 | |||
542 | pipe->set_viewport_state(pipe, | ||
543 | viewport); | ||
544 | } | ||
545 | |||
546 | static void | ||
547 | galahad_set_fragment_sampler_views(struct pipe_context *_pipe, | ||
548 | unsigned num, | ||
549 | struct pipe_sampler_view **_views) | ||
550 | { | ||
551 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
552 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
553 | struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SAMPLERS]; | ||
554 | struct pipe_sampler_view **views = NULL; | ||
555 | unsigned i; | ||
556 | |||
557 | if (_views) { | ||
558 | for (i = 0; i < num; i++) | ||
559 | unwrapped_views[i] = galahad_sampler_view_unwrap(_views[i]); | ||
560 | for (; i < PIPE_MAX_SAMPLERS; i++) | ||
561 | unwrapped_views[i] = NULL; | ||
562 | |||
563 | views = unwrapped_views; | ||
564 | } | ||
565 | |||
566 | pipe->set_fragment_sampler_views(pipe, num, views); | ||
567 | } | ||
568 | |||
569 | static void | ||
570 | galahad_set_vertex_sampler_views(struct pipe_context *_pipe, | ||
571 | unsigned num, | ||
572 | struct pipe_sampler_view **_views) | ||
573 | { | ||
574 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
575 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
576 | struct pipe_sampler_view *unwrapped_views[PIPE_MAX_VERTEX_SAMPLERS]; | ||
577 | struct pipe_sampler_view **views = NULL; | ||
578 | unsigned i; | ||
579 | |||
580 | if (_views) { | ||
581 | for (i = 0; i < num; i++) | ||
582 | unwrapped_views[i] = galahad_sampler_view_unwrap(_views[i]); | ||
583 | for (; i < PIPE_MAX_VERTEX_SAMPLERS; i++) | ||
584 | unwrapped_views[i] = NULL; | ||
585 | |||
586 | views = unwrapped_views; | ||
587 | } | ||
588 | |||
589 | pipe->set_vertex_sampler_views(pipe, num, views); | ||
590 | } | ||
591 | |||
592 | static void | ||
593 | galahad_set_vertex_buffers(struct pipe_context *_pipe, | ||
594 | unsigned num_buffers, | ||
595 | const struct pipe_vertex_buffer *_buffers) | ||
596 | { | ||
597 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
598 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
599 | struct pipe_vertex_buffer unwrapped_buffers[PIPE_MAX_SHADER_INPUTS]; | ||
600 | struct pipe_vertex_buffer *buffers = NULL; | ||
601 | unsigned i; | ||
602 | |||
603 | if (num_buffers) { | ||
604 | memcpy(unwrapped_buffers, _buffers, num_buffers * sizeof(*_buffers)); | ||
605 | for (i = 0; i < num_buffers; i++) | ||
606 | unwrapped_buffers[i].buffer = galahad_resource_unwrap(_buffers[i].buffer); | ||
607 | buffers = unwrapped_buffers; | ||
608 | } | ||
609 | |||
610 | pipe->set_vertex_buffers(pipe, | ||
611 | num_buffers, | ||
612 | buffers); | ||
613 | } | ||
614 | static void | ||
615 | galahad_resource_copy_region(struct pipe_context *_pipe, | ||
616 | struct pipe_resource *_dst, | ||
617 | struct pipe_subresource subdst, | ||
618 | unsigned dstx, | ||
619 | unsigned dsty, | ||
620 | unsigned dstz, | ||
621 | struct pipe_resource *_src, | ||
622 | struct pipe_subresource subsrc, | ||
623 | unsigned srcx, | ||
624 | unsigned srcy, | ||
625 | unsigned srcz, | ||
626 | unsigned width, | ||
627 | unsigned height) | ||
628 | { | ||
629 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
630 | struct galahad_resource *glhd_resource_dst = galahad_resource(_dst); | ||
631 | struct galahad_resource *glhd_resource_src = galahad_resource(_src); | ||
632 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
633 | struct pipe_resource *dst = glhd_resource_dst->resource; | ||
634 | struct pipe_resource *src = glhd_resource_src->resource; | ||
635 | |||
636 | pipe->resource_copy_region(pipe, | ||
637 | dst, | ||
638 | subdst, | ||
639 | dstx, | ||
640 | dsty, | ||
641 | dstz, | ||
642 | src, | ||
643 | subsrc, | ||
644 | srcx, | ||
645 | srcy, | ||
646 | srcz, | ||
647 | width, | ||
648 | height); | ||
649 | } | ||
650 | |||
651 | static void | ||
652 | galahad_clear(struct pipe_context *_pipe, | ||
653 | unsigned buffers, | ||
654 | const float *rgba, | ||
655 | double depth, | ||
656 | unsigned stencil) | ||
657 | { | ||
658 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
659 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
660 | |||
661 | pipe->clear(pipe, | ||
662 | buffers, | ||
663 | rgba, | ||
664 | depth, | ||
665 | stencil); | ||
666 | } | ||
667 | |||
668 | static void | ||
669 | galahad_clear_render_target(struct pipe_context *_pipe, | ||
670 | struct pipe_surface *_dst, | ||
671 | const float *rgba, | ||
672 | unsigned dstx, unsigned dsty, | ||
673 | unsigned width, unsigned height) | ||
674 | { | ||
675 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
676 | struct galahad_surface *glhd_surface_dst = galahad_surface(_dst); | ||
677 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
678 | struct pipe_surface *dst = glhd_surface_dst->surface; | ||
679 | |||
680 | pipe->clear_render_target(pipe, | ||
681 | dst, | ||
682 | rgba, | ||
683 | dstx, | ||
684 | dsty, | ||
685 | width, | ||
686 | height); | ||
687 | } | ||
688 | static void | ||
689 | galahad_clear_depth_stencil(struct pipe_context *_pipe, | ||
690 | struct pipe_surface *_dst, | ||
691 | unsigned clear_flags, | ||
692 | double depth, | ||
693 | unsigned stencil, | ||
694 | unsigned dstx, unsigned dsty, | ||
695 | unsigned width, unsigned height) | ||
696 | { | ||
697 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
698 | struct galahad_surface *glhd_surface_dst = galahad_surface(_dst); | ||
699 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
700 | struct pipe_surface *dst = glhd_surface_dst->surface; | ||
701 | |||
702 | pipe->clear_depth_stencil(pipe, | ||
703 | dst, | ||
704 | clear_flags, | ||
705 | depth, | ||
706 | stencil, | ||
707 | dstx, | ||
708 | dsty, | ||
709 | width, | ||
710 | height); | ||
711 | |||
712 | } | ||
713 | |||
714 | static void | ||
715 | galahad_flush(struct pipe_context *_pipe, | ||
716 | unsigned flags, | ||
717 | struct pipe_fence_handle **fence) | ||
718 | { | ||
719 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
720 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
721 | |||
722 | pipe->flush(pipe, | ||
723 | flags, | ||
724 | fence); | ||
725 | } | ||
726 | |||
727 | static unsigned int | ||
728 | galahad_is_resource_referenced(struct pipe_context *_pipe, | ||
729 | struct pipe_resource *_resource, | ||
730 | unsigned face, | ||
731 | unsigned level) | ||
732 | { | ||
733 | struct galahad_context *glhd_pipe = galahad_context(_pipe); | ||
734 | struct galahad_resource *glhd_resource = galahad_resource(_resource); | ||
735 | struct pipe_context *pipe = glhd_pipe->pipe; | ||
736 | struct pipe_resource *resource = glhd_resource->resource; | ||
737 | |||
738 | return pipe->is_resource_referenced(pipe, | ||
739 | resource, | ||
740 | face, | ||
741 | level); | ||
742 | } | ||
743 | |||
744 | static struct pipe_sampler_view * | ||
745 | galahad_context_create_sampler_view(struct pipe_context *_pipe, | ||
746 | struct pipe_resource *_resource, | ||
747 | const struct pipe_sampler_view *templ) | ||
748 | { | ||
749 | struct galahad_context *glhd_context = galahad_context(_pipe); | ||
750 | struct galahad_resource *glhd_resource = galahad_resource(_resource); | ||
751 | struct pipe_context *pipe = glhd_context->pipe; | ||
752 | struct pipe_resource *resource = glhd_resource->resource; | ||
753 | struct pipe_sampler_view *result; | ||
754 | |||
755 | result = pipe->create_sampler_view(pipe, | ||
756 | resource, | ||
757 | templ); | ||
758 | |||
759 | if (result) | ||
760 | return galahad_sampler_view_create(glhd_context, glhd_resource, result); | ||
761 | return NULL; | ||
762 | } | ||
763 | |||
764 | static void | ||
765 | galahad_context_sampler_view_destroy(struct pipe_context *_pipe, | ||
766 | struct pipe_sampler_view *_view) | ||
767 | { | ||
768 | galahad_sampler_view_destroy(galahad_context(_pipe), | ||
769 | galahad_sampler_view(_view)); | ||
770 | } | ||
771 | |||
772 | static struct pipe_transfer * | ||
773 | galahad_context_get_transfer(struct pipe_context *_context, | ||
774 | struct pipe_resource *_resource, | ||
775 | struct pipe_subresource sr, | ||
776 | unsigned usage, | ||
777 | const struct pipe_box *box) | ||
778 | { | ||
779 | struct galahad_context *glhd_context = galahad_context(_context); | ||
780 | struct galahad_resource *glhd_resource = galahad_resource(_resource); | ||
781 | struct pipe_context *context = glhd_context->pipe; | ||
782 | struct pipe_resource *resource = glhd_resource->resource; | ||
783 | struct pipe_transfer *result; | ||
784 | |||
785 | result = context->get_transfer(context, | ||
786 | resource, | ||
787 | sr, | ||
788 | usage, | ||
789 | box); | ||
790 | |||
791 | if (result) | ||
792 | return galahad_transfer_create(glhd_context, glhd_resource, result); | ||
793 | return NULL; | ||
794 | } | ||
795 | |||
796 | static void | ||
797 | galahad_context_transfer_destroy(struct pipe_context *_pipe, | ||
798 | struct pipe_transfer *_transfer) | ||
799 | { | ||
800 | galahad_transfer_destroy(galahad_context(_pipe), | ||
801 | galahad_transfer(_transfer)); | ||
802 | } | ||
803 | |||
804 | static void * | ||
805 | galahad_context_transfer_map(struct pipe_context *_context, | ||
806 | struct pipe_transfer *_transfer) | ||
807 | { | ||
808 | struct galahad_context *glhd_context = galahad_context(_context); | ||
809 | struct galahad_transfer *glhd_transfer = galahad_transfer(_transfer); | ||
810 | struct pipe_context *context = glhd_context->pipe; | ||
811 | struct pipe_transfer *transfer = glhd_transfer->transfer; | ||
812 | |||
813 | return context->transfer_map(context, | ||
814 | transfer); | ||
815 | } | ||
816 | |||
817 | |||
818 | |||
819 | static void | ||
820 | galahad_context_transfer_flush_region(struct pipe_context *_context, | ||
821 | struct pipe_transfer *_transfer, | ||
822 | const struct pipe_box *box) | ||
823 | { | ||
824 | struct galahad_context *glhd_context = galahad_context(_context); | ||
825 | struct galahad_transfer *glhd_transfer = galahad_transfer(_transfer); | ||
826 | struct pipe_context *context = glhd_context->pipe; | ||
827 | struct pipe_transfer *transfer = glhd_transfer->transfer; | ||
828 | |||
829 | context->transfer_flush_region(context, | ||
830 | transfer, | ||
831 | box); | ||
832 | } | ||
833 | |||
834 | |||
835 | static void | ||
836 | galahad_context_transfer_unmap(struct pipe_context *_context, | ||
837 | struct pipe_transfer *_transfer) | ||
838 | { | ||
839 | struct galahad_context *glhd_context = galahad_context(_context); | ||
840 | struct galahad_transfer *glhd_transfer = galahad_transfer(_transfer); | ||
841 | struct pipe_context *context = glhd_context->pipe; | ||
842 | struct pipe_transfer *transfer = glhd_transfer->transfer; | ||
843 | |||
844 | context->transfer_unmap(context, | ||
845 | transfer); | ||
846 | } | ||
847 | |||
848 | |||
849 | static void | ||
850 | galahad_context_transfer_inline_write(struct pipe_context *_context, | ||
851 | struct pipe_resource *_resource, | ||
852 | struct pipe_subresource sr, | ||
853 | unsigned usage, | ||
854 | const struct pipe_box *box, | ||
855 | const void *data, | ||
856 | unsigned stride, | ||
857 | unsigned slice_stride) | ||
858 | { | ||
859 | struct galahad_context *glhd_context = galahad_context(_context); | ||
860 | struct galahad_resource *glhd_resource = galahad_resource(_resource); | ||
861 | struct pipe_context *context = glhd_context->pipe; | ||
862 | struct pipe_resource *resource = glhd_resource->resource; | ||
863 | |||
864 | context->transfer_inline_write(context, | ||
865 | resource, | ||
866 | sr, | ||
867 | usage, | ||
868 | box, | ||
869 | data, | ||
870 | stride, | ||
871 | slice_stride); | ||
872 | } | ||
873 | |||
874 | |||
875 | struct pipe_context * | ||
876 | galahad_context_create(struct pipe_screen *_screen, struct pipe_context *pipe) | ||
877 | { | ||
878 | struct galahad_context *glhd_pipe; | ||
879 | (void)galahad_screen(_screen); | ||
880 | |||
881 | glhd_pipe = CALLOC_STRUCT(galahad_context); | ||
882 | if (!glhd_pipe) { | ||
883 | return NULL; | ||
884 | } | ||
885 | |||
886 | glhd_pipe->base.winsys = NULL; | ||
887 | glhd_pipe->base.screen = _screen; | ||
888 | glhd_pipe->base.priv = pipe->priv; /* expose wrapped data */ | ||
889 | glhd_pipe->base.draw = NULL; | ||
890 | |||
891 | glhd_pipe->base.destroy = galahad_destroy; | ||
892 | glhd_pipe->base.draw_arrays = galahad_draw_arrays; | ||
893 | glhd_pipe->base.draw_elements = galahad_draw_elements; | ||
894 | glhd_pipe->base.draw_range_elements = galahad_draw_range_elements; | ||
895 | glhd_pipe->base.create_query = galahad_create_query; | ||
896 | glhd_pipe->base.destroy_query = galahad_destroy_query; | ||
897 | glhd_pipe->base.begin_query = galahad_begin_query; | ||
898 | glhd_pipe->base.end_query = galahad_end_query; | ||
899 | glhd_pipe->base.get_query_result = galahad_get_query_result; | ||
900 | glhd_pipe->base.create_blend_state = galahad_create_blend_state; | ||
901 | glhd_pipe->base.bind_blend_state = galahad_bind_blend_state; | ||
902 | glhd_pipe->base.delete_blend_state = galahad_delete_blend_state; | ||
903 | glhd_pipe->base.create_sampler_state = galahad_create_sampler_state; | ||
904 | glhd_pipe->base.bind_fragment_sampler_states = galahad_bind_fragment_sampler_states; | ||
905 | glhd_pipe->base.bind_vertex_sampler_states = galahad_bind_vertex_sampler_states; | ||
906 | glhd_pipe->base.delete_sampler_state = galahad_delete_sampler_state; | ||
907 | glhd_pipe->base.create_rasterizer_state = galahad_create_rasterizer_state; | ||
908 | glhd_pipe->base.bind_rasterizer_state = galahad_bind_rasterizer_state; | ||
909 | glhd_pipe->base.delete_rasterizer_state = galahad_delete_rasterizer_state; | ||
910 | glhd_pipe->base.create_depth_stencil_alpha_state = galahad_create_depth_stencil_alpha_state; | ||
911 | glhd_pipe->base.bind_depth_stencil_alpha_state = galahad_bind_depth_stencil_alpha_state; | ||
912 | glhd_pipe->base.delete_depth_stencil_alpha_state = galahad_delete_depth_stencil_alpha_state; | ||
913 | glhd_pipe->base.create_fs_state = galahad_create_fs_state; | ||
914 | glhd_pipe->base.bind_fs_state = galahad_bind_fs_state; | ||
915 | glhd_pipe->base.delete_fs_state = galahad_delete_fs_state; | ||
916 | glhd_pipe->base.create_vs_state = galahad_create_vs_state; | ||
917 | glhd_pipe->base.bind_vs_state = galahad_bind_vs_state; | ||
918 | glhd_pipe->base.delete_vs_state = galahad_delete_vs_state; | ||
919 | glhd_pipe->base.create_vertex_elements_state = galahad_create_vertex_elements_state; | ||
920 | glhd_pipe->base.bind_vertex_elements_state = galahad_bind_vertex_elements_state; | ||
921 | glhd_pipe->base.delete_vertex_elements_state = galahad_delete_vertex_elements_state; | ||
922 | glhd_pipe->base.set_blend_color = galahad_set_blend_color; | ||
923 | glhd_pipe->base.set_stencil_ref = galahad_set_stencil_ref; | ||
924 | glhd_pipe->base.set_clip_state = galahad_set_clip_state; | ||
925 | glhd_pipe->base.set_sample_mask = galahad_set_sample_mask; | ||
926 | glhd_pipe->base.set_constant_buffer = galahad_set_constant_buffer; | ||
927 | glhd_pipe->base.set_framebuffer_state = galahad_set_framebuffer_state; | ||
928 | glhd_pipe->base.set_polygon_stipple = galahad_set_polygon_stipple; | ||
929 | glhd_pipe->base.set_scissor_state = galahad_set_scissor_state; | ||
930 | glhd_pipe->base.set_viewport_state = galahad_set_viewport_state; | ||
931 | glhd_pipe->base.set_fragment_sampler_views = galahad_set_fragment_sampler_views; | ||
932 | glhd_pipe->base.set_vertex_sampler_views = galahad_set_vertex_sampler_views; | ||
933 | glhd_pipe->base.set_vertex_buffers = galahad_set_vertex_buffers; | ||
934 | glhd_pipe->base.resource_copy_region = galahad_resource_copy_region; | ||
935 | glhd_pipe->base.clear = galahad_clear; | ||
936 | glhd_pipe->base.clear_render_target = galahad_clear_render_target; | ||
937 | glhd_pipe->base.clear_depth_stencil = galahad_clear_depth_stencil; | ||
938 | glhd_pipe->base.flush = galahad_flush; | ||
939 | glhd_pipe->base.is_resource_referenced = galahad_is_resource_referenced; | ||
940 | glhd_pipe->base.create_sampler_view = galahad_context_create_sampler_view; | ||
941 | glhd_pipe->base.sampler_view_destroy = galahad_context_sampler_view_destroy; | ||
942 | glhd_pipe->base.get_transfer = galahad_context_get_transfer; | ||
943 | glhd_pipe->base.transfer_destroy = galahad_context_transfer_destroy; | ||
944 | glhd_pipe->base.transfer_map = galahad_context_transfer_map; | ||
945 | glhd_pipe->base.transfer_unmap = galahad_context_transfer_unmap; | ||
946 | glhd_pipe->base.transfer_flush_region = galahad_context_transfer_flush_region; | ||
947 | glhd_pipe->base.transfer_inline_write = galahad_context_transfer_inline_write; | ||
948 | |||
949 | glhd_pipe->pipe = pipe; | ||
950 | |||
951 | return &glhd_pipe->base; | ||
952 | } | ||
diff --git a/src/gallium/drivers/galahad/glhd_context.h b/src/gallium/drivers/galahad/glhd_context.h new file mode 100644 index 00000000000..b316ec32b16 --- /dev/null +++ b/src/gallium/drivers/galahad/glhd_context.h | |||
@@ -0,0 +1,52 @@ | |||
1 | /************************************************************************** | ||
2 | * | ||
3 | * Copyright 2009 VMware, Inc. | ||
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 VMWARE 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 | #ifndef GLHD_CONTEXT_H | ||
29 | #define GLHD_CONTEXT_H | ||
30 | |||
31 | #include "pipe/p_state.h" | ||
32 | #include "pipe/p_context.h" | ||
33 | |||
34 | |||
35 | struct galahad_context { | ||
36 | struct pipe_context base; /**< base class */ | ||
37 | |||
38 | struct pipe_context *pipe; | ||
39 | }; | ||
40 | |||
41 | |||
42 | struct pipe_context * | ||
43 | galahad_context_create(struct pipe_screen *screen, struct pipe_context *pipe); | ||
44 | |||
45 | |||
46 | static INLINE struct galahad_context * | ||
47 | galahad_context(struct pipe_context *pipe) | ||
48 | { | ||
49 | return (struct galahad_context *)pipe; | ||
50 | } | ||
51 | |||
52 | #endif /* GLHD_CONTEXT_H */ | ||
diff --git a/src/gallium/drivers/galahad/glhd_drm.c b/src/gallium/drivers/galahad/glhd_drm.c new file mode 100644 index 00000000000..78e290c9a84 --- /dev/null +++ b/src/gallium/drivers/galahad/glhd_drm.c | |||
@@ -0,0 +1,93 @@ | |||
1 | /************************************************************************** | ||
2 | * | ||
3 | * Copyright 2009 VMware, Inc. | ||
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 VMWARE 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 | #include "state_tracker/drm_api.h" | ||
29 | |||
30 | #include "util/u_memory.h" | ||
31 | #include "glhd_drm.h" | ||
32 | #include "glhd_screen.h" | ||
33 | #include "glhd_public.h" | ||
34 | |||
35 | struct galahad_drm_api | ||
36 | { | ||
37 | struct drm_api base; | ||
38 | |||
39 | struct drm_api *api; | ||
40 | }; | ||
41 | |||
42 | static INLINE struct galahad_drm_api * | ||
43 | galahad_drm_api(struct drm_api *_api) | ||
44 | { | ||
45 | return (struct galahad_drm_api *)_api; | ||
46 | } | ||
47 | |||
48 | static struct pipe_screen * | ||
49 | galahad_drm_create_screen(struct drm_api *_api, int fd) | ||
50 | { | ||
51 | struct galahad_drm_api *glhd_api = galahad_drm_api(_api); | ||
52 | struct drm_api *api = glhd_api->api; | ||
53 | struct pipe_screen *screen; | ||
54 | |||
55 | screen = api->create_screen(api, fd); | ||
56 | |||
57 | return galahad_screen_create(screen); | ||
58 | } | ||
59 | |||
60 | static void | ||
61 | galahad_drm_destroy(struct drm_api *_api) | ||
62 | { | ||
63 | struct galahad_drm_api *glhd_api = galahad_drm_api(_api); | ||
64 | struct drm_api *api = glhd_api->api; | ||
65 | api->destroy(api); | ||
66 | |||
67 | FREE(glhd_api); | ||
68 | } | ||
69 | |||
70 | struct drm_api * | ||
71 | galahad_drm_create(struct drm_api *api) | ||
72 | { | ||
73 | struct galahad_drm_api *glhd_api; | ||
74 | |||
75 | if (!api) | ||
76 | goto error; | ||
77 | |||
78 | glhd_api = CALLOC_STRUCT(galahad_drm_api); | ||
79 | |||
80 | if (!glhd_api) | ||
81 | goto error; | ||
82 | |||
83 | glhd_api->base.name = api->name; | ||
84 | glhd_api->base.driver_name = api->driver_name; | ||
85 | glhd_api->base.create_screen = galahad_drm_create_screen; | ||
86 | glhd_api->base.destroy = galahad_drm_destroy; | ||
87 | glhd_api->api = api; | ||
88 | |||
89 | return &glhd_api->base; | ||
90 | |||
91 | error: | ||
92 | return api; | ||
93 | } | ||
diff --git a/src/gallium/drivers/galahad/glhd_drm.h b/src/gallium/drivers/galahad/glhd_drm.h new file mode 100644 index 00000000000..613ac24946d --- /dev/null +++ b/src/gallium/drivers/galahad/glhd_drm.h | |||
@@ -0,0 +1,35 @@ | |||
1 | /************************************************************************** | ||
2 | * | ||
3 | * Copyright 2009 VMware, Inc. | ||
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 VMWARE 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 | #ifndef GLHD_DRM_H | ||
29 | #define GLHD_DRM_H | ||
30 | |||
31 | struct drm_api; | ||
32 | |||
33 | struct drm_api* galahad_drm_create(struct drm_api *api); | ||
34 | |||
35 | #endif /* GLHD_DRM_H */ | ||
diff --git a/src/gallium/drivers/galahad/glhd_objects.c b/src/gallium/drivers/galahad/glhd_objects.c new file mode 100644 index 00000000000..cea32d7ffec --- /dev/null +++ b/src/gallium/drivers/galahad/glhd_objects.c | |||
@@ -0,0 +1,186 @@ | |||
1 | /************************************************************************** | ||
2 | * | ||
3 | * Copyright 2009 VMware, Inc. | ||
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 VMWARE 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 | #include "util/u_inlines.h" | ||
29 | #include "util/u_memory.h" | ||
30 | |||
31 | #include "glhd_screen.h" | ||
32 | #include "glhd_objects.h" | ||
33 | #include "glhd_context.h" | ||
34 | |||
35 | |||
36 | |||
37 | struct pipe_resource * | ||
38 | galahad_resource_create(struct galahad_screen *glhd_screen, | ||
39 | struct pipe_resource *resource) | ||
40 | { | ||
41 | struct galahad_resource *glhd_resource; | ||
42 | |||
43 | if(!resource) | ||
44 | goto error; | ||
45 | |||
46 | assert(resource->screen == glhd_screen->screen); | ||
47 | |||
48 | glhd_resource = CALLOC_STRUCT(galahad_resource); | ||
49 | if(!glhd_resource) | ||
50 | goto error; | ||
51 | |||
52 | memcpy(&glhd_resource->base, resource, sizeof(struct pipe_resource)); | ||
53 | |||
54 | pipe_reference_init(&glhd_resource->base.reference, 1); | ||
55 | glhd_resource->base.screen = &glhd_screen->base; | ||
56 | glhd_resource->resource = resource; | ||
57 | |||
58 | return &glhd_resource->base; | ||
59 | |||
60 | error: | ||
61 | pipe_resource_reference(&resource, NULL); | ||
62 | return NULL; | ||
63 | } | ||
64 | |||
65 | void | ||
66 | galahad_resource_destroy(struct galahad_resource *glhd_resource) | ||
67 | { | ||
68 | pipe_resource_reference(&glhd_resource->resource, NULL); | ||
69 | FREE(glhd_resource); | ||
70 | } | ||
71 | |||
72 | |||
73 | struct pipe_surface * | ||
74 | galahad_surface_create(struct galahad_resource *glhd_resource, | ||
75 | struct pipe_surface *surface) | ||
76 | { | ||
77 | struct galahad_surface *glhd_surface; | ||
78 | |||
79 | if(!surface) | ||
80 | goto error; | ||
81 | |||
82 | assert(surface->texture == glhd_resource->resource); | ||
83 | |||
84 | glhd_surface = CALLOC_STRUCT(galahad_surface); | ||
85 | if(!glhd_surface) | ||
86 | goto error; | ||
87 | |||
88 | memcpy(&glhd_surface->base, surface, sizeof(struct pipe_surface)); | ||
89 | |||
90 | pipe_reference_init(&glhd_surface->base.reference, 1); | ||
91 | glhd_surface->base.texture = NULL; | ||
92 | pipe_resource_reference(&glhd_surface->base.texture, &glhd_resource->base); | ||
93 | glhd_surface->surface = surface; | ||
94 | |||
95 | return &glhd_surface->base; | ||
96 | |||
97 | error: | ||
98 | pipe_surface_reference(&surface, NULL); | ||
99 | return NULL; | ||
100 | } | ||
101 | |||
102 | void | ||
103 | galahad_surface_destroy(struct galahad_surface *glhd_surface) | ||
104 | { | ||
105 | pipe_resource_reference(&glhd_surface->base.texture, NULL); | ||
106 | pipe_surface_reference(&glhd_surface->surface, NULL); | ||
107 | FREE(glhd_surface); | ||
108 | } | ||
109 | |||
110 | |||
111 | struct pipe_sampler_view * | ||
112 | galahad_sampler_view_create(struct galahad_context *glhd_context, | ||
113 | struct galahad_resource *glhd_resource, | ||
114 | struct pipe_sampler_view *view) | ||
115 | { | ||
116 | struct galahad_sampler_view *glhd_view; | ||
117 | |||
118 | if (!view) | ||
119 | goto error; | ||
120 | |||
121 | assert(view->texture == glhd_resource->resource); | ||
122 | |||
123 | glhd_view = MALLOC(sizeof(struct galahad_sampler_view)); | ||
124 | |||
125 | glhd_view->base = *view; | ||
126 | glhd_view->base.reference.count = 1; | ||
127 | glhd_view->base.texture = NULL; | ||
128 | pipe_resource_reference(&glhd_view->base.texture, glhd_resource->resource); | ||
129 | glhd_view->base.context = glhd_context->pipe; | ||
130 | |||
131 | return &glhd_view->base; | ||
132 | error: | ||
133 | return NULL; | ||
134 | } | ||
135 | |||
136 | void | ||
137 | galahad_sampler_view_destroy(struct galahad_context *glhd_context, | ||
138 | struct galahad_sampler_view *glhd_view) | ||
139 | { | ||
140 | pipe_resource_reference(&glhd_view->base.texture, NULL); | ||
141 | glhd_context->pipe->sampler_view_destroy(glhd_context->pipe, | ||
142 | glhd_view->sampler_view); | ||
143 | FREE(glhd_view); | ||
144 | } | ||
145 | |||
146 | |||
147 | struct pipe_transfer * | ||
148 | galahad_transfer_create(struct galahad_context *glhd_context, | ||
149 | struct galahad_resource *glhd_resource, | ||
150 | struct pipe_transfer *transfer) | ||
151 | { | ||
152 | struct galahad_transfer *glhd_transfer; | ||
153 | |||
154 | if(!transfer) | ||
155 | goto error; | ||
156 | |||
157 | assert(transfer->resource == glhd_resource->resource); | ||
158 | |||
159 | glhd_transfer = CALLOC_STRUCT(galahad_transfer); | ||
160 | if(!glhd_transfer) | ||
161 | goto error; | ||
162 | |||
163 | memcpy(&glhd_transfer->base, transfer, sizeof(struct pipe_transfer)); | ||
164 | |||
165 | glhd_transfer->base.resource = NULL; | ||
166 | glhd_transfer->transfer = transfer; | ||
167 | |||
168 | pipe_resource_reference(&glhd_transfer->base.resource, &glhd_resource->base); | ||
169 | assert(glhd_transfer->base.resource == &glhd_resource->base); | ||
170 | |||
171 | return &glhd_transfer->base; | ||
172 | |||
173 | error: | ||
174 | glhd_context->pipe->transfer_destroy(glhd_context->pipe, transfer); | ||
175 | return NULL; | ||
176 | } | ||
177 | |||
178 | void | ||
179 | galahad_transfer_destroy(struct galahad_context *glhd_context, | ||
180 | struct galahad_transfer *glhd_transfer) | ||
181 | { | ||
182 | pipe_resource_reference(&glhd_transfer->base.resource, NULL); | ||
183 | glhd_transfer->pipe->transfer_destroy(glhd_context->pipe, | ||
184 | glhd_transfer->transfer); | ||
185 | FREE(glhd_transfer); | ||
186 | } | ||
diff --git a/src/gallium/drivers/galahad/glhd_objects.h b/src/gallium/drivers/galahad/glhd_objects.h new file mode 100644 index 00000000000..16e1d94469c --- /dev/null +++ b/src/gallium/drivers/galahad/glhd_objects.h | |||
@@ -0,0 +1,176 @@ | |||
1 | /************************************************************************** | ||
2 | * | ||
3 | * Copyright 2009 VMware, Inc. | ||
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 VMWARE 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 | #ifndef GLHD_OBJECTS_H | ||
29 | #define GLHD_OBJECTS_H | ||
30 | |||
31 | |||
32 | #include "pipe/p_compiler.h" | ||
33 | #include "pipe/p_state.h" | ||
34 | |||
35 | #include "glhd_screen.h" | ||
36 | |||
37 | struct galahad_context; | ||
38 | |||
39 | |||
40 | struct galahad_resource | ||
41 | { | ||
42 | struct pipe_resource base; | ||
43 | |||
44 | struct pipe_resource *resource; | ||
45 | }; | ||
46 | |||
47 | |||
48 | struct galahad_sampler_view | ||
49 | { | ||
50 | struct pipe_sampler_view base; | ||
51 | |||
52 | struct pipe_sampler_view *sampler_view; | ||
53 | }; | ||
54 | |||
55 | |||
56 | struct galahad_surface | ||
57 | { | ||
58 | struct pipe_surface base; | ||
59 | |||
60 | struct pipe_surface *surface; | ||
61 | }; | ||
62 | |||
63 | |||
64 | struct galahad_transfer | ||
65 | { | ||
66 | struct pipe_transfer base; | ||
67 | |||
68 | struct pipe_context *pipe; | ||
69 | struct pipe_transfer *transfer; | ||
70 | }; | ||
71 | |||
72 | |||
73 | static INLINE struct galahad_resource * | ||
74 | galahad_resource(struct pipe_resource *_resource) | ||
75 | { | ||
76 | if(!_resource) | ||
77 | return NULL; | ||
78 | (void)galahad_screen(_resource->screen); | ||
79 | return (struct galahad_resource *)_resource; | ||
80 | } | ||
81 | |||
82 | static INLINE struct galahad_sampler_view * | ||
83 | galahad_sampler_view(struct pipe_sampler_view *_sampler_view) | ||
84 | { | ||
85 | if (!_sampler_view) { | ||
86 | return NULL; | ||
87 | } | ||
88 | return (struct galahad_sampler_view *)_sampler_view; | ||
89 | } | ||
90 | |||
91 | static INLINE struct galahad_surface * | ||
92 | galahad_surface(struct pipe_surface *_surface) | ||
93 | { | ||
94 | if(!_surface) | ||
95 | return NULL; | ||
96 | (void)galahad_resource(_surface->texture); | ||
97 | return (struct galahad_surface *)_surface; | ||
98 | } | ||
99 | |||
100 | static INLINE struct galahad_transfer * | ||
101 | galahad_transfer(struct pipe_transfer *_transfer) | ||
102 | { | ||
103 | if(!_transfer) | ||
104 | return NULL; | ||
105 | (void)galahad_resource(_transfer->resource); | ||
106 | return (struct galahad_transfer *)_transfer; | ||
107 | } | ||
108 | |||
109 | static INLINE struct pipe_resource * | ||
110 | galahad_resource_unwrap(struct pipe_resource *_resource) | ||
111 | { | ||
112 | if(!_resource) | ||
113 | return NULL; | ||
114 | return galahad_resource(_resource)->resource; | ||
115 | } | ||
116 | |||
117 | static INLINE struct pipe_sampler_view * | ||
118 | galahad_sampler_view_unwrap(struct pipe_sampler_view *_sampler_view) | ||
119 | { | ||
120 | if (!_sampler_view) { | ||
121 | return NULL; | ||
122 | } | ||
123 | return galahad_sampler_view(_sampler_view)->sampler_view; | ||
124 | } | ||
125 | |||
126 | static INLINE struct pipe_surface * | ||
127 | galahad_surface_unwrap(struct pipe_surface *_surface) | ||
128 | { | ||
129 | if(!_surface) | ||
130 | return NULL; | ||
131 | return galahad_surface(_surface)->surface; | ||
132 | } | ||
133 | |||
134 | static INLINE struct pipe_transfer * | ||
135 | galahad_transfer_unwrap(struct pipe_transfer *_transfer) | ||
136 | { | ||
137 | if(!_transfer) | ||
138 | return NULL; | ||
139 | return galahad_transfer(_transfer)->transfer; | ||
140 | } | ||
141 | |||
142 | |||
143 | struct pipe_resource * | ||
144 | galahad_resource_create(struct galahad_screen *glhd_screen, | ||
145 | struct pipe_resource *resource); | ||
146 | |||
147 | void | ||
148 | galahad_resource_destroy(struct galahad_resource *glhd_resource); | ||
149 | |||
150 | struct pipe_surface * | ||
151 | galahad_surface_create(struct galahad_resource *glhd_resource, | ||
152 | struct pipe_surface *surface); | ||
153 | |||
154 | void | ||
155 | galahad_surface_destroy(struct galahad_surface *glhd_surface); | ||
156 | |||
157 | struct pipe_sampler_view * | ||
158 | galahad_sampler_view_create(struct galahad_context *glhd_context, | ||
159 | struct galahad_resource *glhd_resource, | ||
160 | struct pipe_sampler_view *view); | ||
161 | |||
162 | void | ||
163 | galahad_sampler_view_destroy(struct galahad_context *glhd_context, | ||
164 | struct galahad_sampler_view *glhd_sampler_view); | ||
165 | |||
166 | struct pipe_transfer * | ||
167 | galahad_transfer_create(struct galahad_context *glhd_context, | ||
168 | struct galahad_resource *glhd_resource, | ||
169 | struct pipe_transfer *transfer); | ||
170 | |||
171 | void | ||
172 | galahad_transfer_destroy(struct galahad_context *glhd_context, | ||
173 | struct galahad_transfer *glhd_transfer); | ||
174 | |||
175 | |||
176 | #endif /* GLHD_OBJECTS_H */ | ||
diff --git a/src/gallium/drivers/galahad/glhd_public.h b/src/gallium/drivers/galahad/glhd_public.h new file mode 100644 index 00000000000..77a380196a1 --- /dev/null +++ b/src/gallium/drivers/galahad/glhd_public.h | |||
@@ -0,0 +1,37 @@ | |||
1 | /************************************************************************** | ||
2 | * | ||
3 | * Copyright 2009 VMware, Inc. | ||
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 VMWARE 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 | #ifndef GLHD_PUBLIC_H | ||
29 | #define GLHD_PUBLIC_H | ||
30 | |||
31 | struct pipe_screen; | ||
32 | struct pipe_context; | ||
33 | |||
34 | struct pipe_screen * | ||
35 | galahad_screen_create(struct pipe_screen *screen); | ||
36 | |||
37 | #endif /* GLHD_PUBLIC_H */ | ||
diff --git a/src/gallium/drivers/galahad/glhd_screen.c b/src/gallium/drivers/galahad/glhd_screen.c new file mode 100644 index 00000000000..3f56c3bafdf --- /dev/null +++ b/src/gallium/drivers/galahad/glhd_screen.c | |||
@@ -0,0 +1,325 @@ | |||
1 | /************************************************************************** | ||
2 | * | ||
3 | * Copyright 2009 VMware, Inc. | ||
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 VMWARE 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 | #include "pipe/p_screen.h" | ||
30 | #include "pipe/p_state.h" | ||
31 | #include "util/u_memory.h" | ||
32 | |||
33 | #include "glhd_public.h" | ||
34 | #include "glhd_screen.h" | ||
35 | #include "glhd_context.h" | ||
36 | #include "glhd_objects.h" | ||
37 | |||
38 | |||
39 | static void | ||
40 | galahad_screen_destroy(struct pipe_screen *_screen) | ||
41 | { | ||
42 | struct galahad_screen *glhd_screen = galahad_screen(_screen); | ||
43 | struct pipe_screen *screen = glhd_screen->screen; | ||
44 | |||
45 | screen->destroy(screen); | ||
46 | |||
47 | FREE(glhd_screen); | ||
48 | } | ||
49 | |||
50 | static const char * | ||
51 | galahad_screen_get_name(struct pipe_screen *_screen) | ||
52 | { | ||
53 | struct galahad_screen *glhd_screen = galahad_screen(_screen); | ||
54 | struct pipe_screen *screen = glhd_screen->screen; | ||
55 | |||
56 | return screen->get_name(screen); | ||
57 | } | ||
58 | |||
59 | static const char * | ||
60 | galahad_screen_get_vendor(struct pipe_screen *_screen) | ||
61 | { | ||
62 | struct galahad_screen *glhd_screen = galahad_screen(_screen); | ||
63 | struct pipe_screen *screen = glhd_screen->screen; | ||
64 | |||
65 | return screen->get_vendor(screen); | ||
66 | } | ||
67 | |||
68 | static int | ||
69 | galahad_screen_get_param(struct pipe_screen *_screen, | ||
70 | enum pipe_cap param) | ||
71 | { | ||
72 | struct galahad_screen *glhd_screen = galahad_screen(_screen); | ||
73 | struct pipe_screen *screen = glhd_screen->screen; | ||
74 | |||
75 | return screen->get_param(screen, | ||
76 | param); | ||
77 | } | ||
78 | |||
79 | static float | ||
80 | galahad_screen_get_paramf(struct pipe_screen *_screen, | ||
81 | enum pipe_cap param) | ||
82 | { | ||
83 | struct galahad_screen *glhd_screen = galahad_screen(_screen); | ||
84 | struct pipe_screen *screen = glhd_screen->screen; | ||
85 | |||
86 | return screen->get_paramf(screen, | ||
87 | param); | ||
88 | } | ||
89 | |||
90 | static boolean | ||
91 | galahad_screen_is_format_supported(struct pipe_screen *_screen, | ||
92 | enum pipe_format format, | ||
93 | enum pipe_texture_target target, | ||
94 | unsigned sample_count, | ||
95 | unsigned tex_usage, | ||
96 | unsigned geom_flags) | ||
97 | { | ||
98 | struct galahad_screen *glhd_screen = galahad_screen(_screen); | ||
99 | struct pipe_screen *screen = glhd_screen->screen; | ||
100 | |||
101 | return screen->is_format_supported(screen, | ||
102 | format, | ||
103 | target, | ||
104 | sample_count, | ||
105 | tex_usage, | ||
106 | geom_flags); | ||
107 | } | ||
108 | |||
109 | static struct pipe_context * | ||
110 | galahad_screen_context_create(struct pipe_screen *_screen, | ||
111 | void *priv) | ||
112 | { | ||
113 | struct galahad_screen *glhd_screen = galahad_screen(_screen); | ||
114 | struct pipe_screen *screen = glhd_screen->screen; | ||
115 | struct pipe_context *result; | ||
116 | |||
117 | result = screen->context_create(screen, priv); | ||
118 | if (result) | ||
119 | return galahad_context_create(_screen, result); | ||
120 | return NULL; | ||
121 | } | ||
122 | |||
123 | static struct pipe_resource * | ||
124 | galahad_screen_resource_create(struct pipe_screen *_screen, | ||
125 | const struct pipe_resource *templat) | ||
126 | { | ||
127 | struct galahad_screen *glhd_screen = galahad_screen(_screen); | ||
128 | struct pipe_screen *screen = glhd_screen->screen; | ||
129 | struct pipe_resource *result; | ||
130 | |||
131 | result = screen->resource_create(screen, | ||
132 | templat); | ||
133 | |||
134 | if (result) | ||
135 | return galahad_resource_create(glhd_screen, result); | ||
136 | return NULL; | ||
137 | } | ||
138 | |||
139 | static struct pipe_resource * | ||
140 | galahad_screen_resource_from_handle(struct pipe_screen *_screen, | ||
141 | const struct pipe_resource *templ, | ||
142 | struct winsys_handle *handle) | ||
143 | { | ||
144 | struct galahad_screen *glhd_screen = galahad_screen(_screen); | ||
145 | struct pipe_screen *screen = glhd_screen->screen; | ||
146 | struct pipe_resource *result; | ||
147 | |||
148 | /* TODO trace call */ | ||
149 | |||
150 | result = screen->resource_from_handle(screen, templ, handle); | ||
151 | |||
152 | result = galahad_resource_create(galahad_screen(_screen), result); | ||
153 | |||
154 | return result; | ||
155 | } | ||
156 | |||
157 | static boolean | ||
158 | galahad_screen_resource_get_handle(struct pipe_screen *_screen, | ||
159 | struct pipe_resource *_resource, | ||
160 | struct winsys_handle *handle) | ||
161 | { | ||
162 | struct galahad_screen *glhd_screen = galahad_screen(_screen); | ||
163 | struct galahad_resource *glhd_resource = galahad_resource(_resource); | ||
164 | struct pipe_screen *screen = glhd_screen->screen; | ||
165 | struct pipe_resource *resource = glhd_resource->resource; | ||
166 | |||
167 | /* TODO trace call */ | ||
168 | |||
169 | return screen->resource_get_handle(screen, resource, handle); | ||
170 | } | ||
171 | |||
172 | |||
173 | |||
174 | static void | ||
175 | galahad_screen_resource_destroy(struct pipe_screen *screen, | ||
176 | struct pipe_resource *_resource) | ||
177 | { | ||
178 | galahad_resource_destroy(galahad_resource(_resource)); | ||
179 | } | ||
180 | |||
181 | static struct pipe_surface * | ||
182 | galahad_screen_get_tex_surface(struct pipe_screen *_screen, | ||
183 | struct pipe_resource *_resource, | ||
184 | unsigned face, | ||
185 | unsigned level, | ||
186 | unsigned zslice, | ||
187 | unsigned usage) | ||
188 | { | ||
189 | struct galahad_screen *glhd_screen = galahad_screen(_screen); | ||
190 | struct galahad_resource *glhd_resource = galahad_resource(_resource); | ||
191 | struct pipe_screen *screen = glhd_screen->screen; | ||
192 | struct pipe_resource *resource = glhd_resource->resource; | ||
193 | struct pipe_surface *result; | ||
194 | |||
195 | result = screen->get_tex_surface(screen, | ||
196 | resource, | ||
197 | face, | ||
198 | level, | ||
199 | zslice, | ||
200 | usage); | ||
201 | |||
202 | if (result) | ||
203 | return galahad_surface_create(glhd_resource, result); | ||
204 | return NULL; | ||
205 | } | ||
206 | |||
207 | static void | ||
208 | galahad_screen_tex_surface_destroy(struct pipe_surface *_surface) | ||
209 | { | ||
210 | galahad_surface_destroy(galahad_surface(_surface)); | ||
211 | } | ||
212 | |||
213 | |||
214 | |||
215 | static struct pipe_resource * | ||
216 | galahad_screen_user_buffer_create(struct pipe_screen *_screen, | ||
217 | void *ptr, | ||
218 | unsigned bytes, | ||
219 | unsigned usage) | ||
220 | { | ||
221 | struct galahad_screen *glhd_screen = galahad_screen(_screen); | ||
222 | struct pipe_screen *screen = glhd_screen->screen; | ||
223 | struct pipe_resource *result; | ||
224 | |||
225 | result = screen->user_buffer_create(screen, | ||
226 | ptr, | ||
227 | bytes, | ||
228 | usage); | ||
229 | |||
230 | if (result) | ||
231 | return galahad_resource_create(glhd_screen, result); | ||
232 | return NULL; | ||
233 | } | ||
234 | |||
235 | |||
236 | |||
237 | static void | ||
238 | galahad_screen_flush_frontbuffer(struct pipe_screen *_screen, | ||
239 | struct pipe_surface *_surface, | ||
240 | void *context_private) | ||
241 | { | ||
242 | struct galahad_screen *glhd_screen = galahad_screen(_screen); | ||
243 | struct galahad_surface *glhd_surface = galahad_surface(_surface); | ||
244 | struct pipe_screen *screen = glhd_screen->screen; | ||
245 | struct pipe_surface *surface = glhd_surface->surface; | ||
246 | |||
247 | screen->flush_frontbuffer(screen, | ||
248 | surface, | ||
249 | context_private); | ||
250 | } | ||
251 | |||
252 | static void | ||
253 | galahad_screen_fence_reference(struct pipe_screen *_screen, | ||
254 | struct pipe_fence_handle **ptr, | ||
255 | struct pipe_fence_handle *fence) | ||
256 | { | ||
257 | struct galahad_screen *glhd_screen = galahad_screen(_screen); | ||
258 | struct pipe_screen *screen = glhd_screen->screen; | ||
259 | |||
260 | screen->fence_reference(screen, | ||
261 | ptr, | ||
262 | fence); | ||
263 | } | ||
264 | |||
265 | static int | ||
266 | galahad_screen_fence_signalled(struct pipe_screen *_screen, | ||
267 | struct pipe_fence_handle *fence, | ||
268 | unsigned flags) | ||
269 | { | ||
270 | struct galahad_screen *glhd_screen = galahad_screen(_screen); | ||
271 | struct pipe_screen *screen = glhd_screen->screen; | ||
272 | |||
273 | return screen->fence_signalled(screen, | ||
274 | fence, | ||
275 | flags); | ||
276 | } | ||
277 | |||
278 | static int | ||
279 | galahad_screen_fence_finish(struct pipe_screen *_screen, | ||
280 | struct pipe_fence_handle *fence, | ||
281 | unsigned flags) | ||
282 | { | ||
283 | struct galahad_screen *glhd_screen = galahad_screen(_screen); | ||
284 | struct pipe_screen *screen = glhd_screen->screen; | ||
285 | |||
286 | return screen->fence_finish(screen, | ||
287 | fence, | ||
288 | flags); | ||
289 | } | ||
290 | |||
291 | struct pipe_screen * | ||
292 | galahad_screen_create(struct pipe_screen *screen) | ||
293 | { | ||
294 | struct galahad_screen *glhd_screen; | ||
295 | |||
296 | glhd_screen = CALLOC_STRUCT(galahad_screen); | ||
297 | if (!glhd_screen) { | ||
298 | return NULL; | ||
299 | } | ||
300 | |||
301 | glhd_screen->base.winsys = NULL; | ||
302 | |||
303 | glhd_screen->base.destroy = galahad_screen_destroy; | ||
304 | glhd_screen->base.get_name = galahad_screen_get_name; | ||
305 | glhd_screen->base.get_vendor = galahad_screen_get_vendor; | ||
306 | glhd_screen->base.get_param = galahad_screen_get_param; | ||
307 | glhd_screen->base.get_paramf = galahad_screen_get_paramf; | ||
308 | glhd_screen->base.is_format_supported = galahad_screen_is_format_supported; | ||
309 | glhd_screen->base.context_create = galahad_screen_context_create; | ||
310 | glhd_screen->base.resource_create = galahad_screen_resource_create; | ||
311 | glhd_screen->base.resource_from_handle = galahad_screen_resource_from_handle; | ||
312 | glhd_screen->base.resource_get_handle = galahad_screen_resource_get_handle; | ||
313 | glhd_screen->base.resource_destroy = galahad_screen_resource_destroy; | ||
314 | glhd_screen->base.get_tex_surface = galahad_screen_get_tex_surface; | ||
315 | glhd_screen->base.tex_surface_destroy = galahad_screen_tex_surface_destroy; | ||
316 | glhd_screen->base.user_buffer_create = galahad_screen_user_buffer_create; | ||
317 | glhd_screen->base.flush_frontbuffer = galahad_screen_flush_frontbuffer; | ||
318 | glhd_screen->base.fence_reference = galahad_screen_fence_reference; | ||
319 | glhd_screen->base.fence_signalled = galahad_screen_fence_signalled; | ||
320 | glhd_screen->base.fence_finish = galahad_screen_fence_finish; | ||
321 | |||
322 | glhd_screen->screen = screen; | ||
323 | |||
324 | return &glhd_screen->base; | ||
325 | } | ||
diff --git a/src/gallium/drivers/galahad/glhd_screen.h b/src/gallium/drivers/galahad/glhd_screen.h new file mode 100644 index 00000000000..7862f4af2b3 --- /dev/null +++ b/src/gallium/drivers/galahad/glhd_screen.h | |||
@@ -0,0 +1,48 @@ | |||
1 | /************************************************************************** | ||
2 | * | ||
3 | * Copyright 2009 VMware, Inc. | ||
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 VMWARE 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 | #ifndef GLHD_SCREEN_H | ||
29 | #define GLHD_SCREEN_H | ||
30 | |||
31 | #include "pipe/p_screen.h" | ||
32 | #include "pipe/p_defines.h" | ||
33 | |||
34 | |||
35 | struct galahad_screen { | ||
36 | struct pipe_screen base; | ||
37 | |||
38 | struct pipe_screen *screen; | ||
39 | }; | ||
40 | |||
41 | |||
42 | static INLINE struct galahad_screen * | ||
43 | galahad_screen(struct pipe_screen *screen) | ||
44 | { | ||
45 | return (struct galahad_screen *)screen; | ||
46 | } | ||
47 | |||
48 | #endif /* GLHD_SCREEN_H */ | ||