2 * Mesa 3-D graphics library
4 * Copyright (C) 2012-2013 LunarG, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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.
25 * Chia-I Wu <olv@lunarg.com>
28 #include "util/u_upload_mgr.h"
31 #include "ilo_blitter.h"
34 #include "ilo_gpgpu.h"
35 #include "ilo_query.h"
36 #include "ilo_render.h"
37 #include "ilo_resource.h"
38 #include "ilo_screen.h"
39 #include "ilo_shader.h"
40 #include "ilo_state.h"
41 #include "ilo_transfer.h"
42 #include "ilo_video.h"
43 #include "ilo_context.h"
46 ilo_context_cp_submitted(struct ilo_cp
*cp
, void *data
)
48 struct ilo_context
*ilo
= ilo_context(data
);
50 /* builder buffers are reallocated */
51 ilo_render_invalidate_builder(ilo
->render
);
55 ilo_flush(struct pipe_context
*pipe
,
56 struct pipe_fence_handle
**f
,
59 struct ilo_context
*ilo
= ilo_context(pipe
);
61 ilo_cp_submit(ilo
->cp
,
62 (flags
& PIPE_FLUSH_END_OF_FRAME
) ? "frame end" : "user request");
65 struct pipe_screen
*screen
= pipe
->screen
;
66 screen
->fence_reference(screen
, f
, NULL
);
67 *f
= ilo_screen_fence_create(pipe
->screen
, ilo
->cp
->last_submitted_bo
);
72 ilo_render_condition(struct pipe_context
*pipe
,
73 struct pipe_query
*query
,
77 struct ilo_context
*ilo
= ilo_context(pipe
);
79 /* reference count? */
80 ilo
->render_condition
.query
= query
;
81 ilo
->render_condition
.condition
= condition
;
82 ilo
->render_condition
.mode
= mode
;
86 ilo_skip_rendering(struct ilo_context
*ilo
)
91 if (!ilo
->render_condition
.query
)
94 switch (ilo
->render_condition
.mode
) {
95 case PIPE_RENDER_COND_WAIT
:
96 case PIPE_RENDER_COND_BY_REGION_WAIT
:
99 case PIPE_RENDER_COND_NO_WAIT
:
100 case PIPE_RENDER_COND_BY_REGION_NO_WAIT
:
106 if (ilo
->base
.get_query_result(&ilo
->base
, ilo
->render_condition
.query
,
107 wait
, (union pipe_query_result
*) &result
))
108 return ((bool) result
== ilo
->render_condition
.condition
);
114 ilo_context_destroy(struct pipe_context
*pipe
)
116 struct ilo_context
*ilo
= ilo_context(pipe
);
118 ilo_state_vector_cleanup(&ilo
->state_vector
);
121 u_upload_destroy(ilo
->uploader
);
124 ilo_blitter_destroy(ilo
->blitter
);
126 ilo_render_destroy(ilo
->render
);
127 if (ilo
->shader_cache
)
128 ilo_shader_cache_destroy(ilo
->shader_cache
);
130 ilo_cp_destroy(ilo
->cp
);
132 slab_destroy(&ilo
->transfer_mempool
);
137 static struct pipe_context
*
138 ilo_context_create(struct pipe_screen
*screen
, void *priv
, unsigned flags
)
140 struct ilo_screen
*is
= ilo_screen(screen
);
141 struct ilo_context
*ilo
;
143 ilo
= CALLOC_STRUCT(ilo_context
);
147 ilo
->winsys
= is
->dev
.winsys
;
151 * initialize first, otherwise it may not be safe to call
152 * ilo_context_destroy() on errors
154 slab_create(&ilo
->transfer_mempool
,
155 sizeof(struct ilo_transfer
), 64);
157 ilo
->shader_cache
= ilo_shader_cache_create();
158 ilo
->cp
= ilo_cp_create(ilo
->dev
, ilo
->winsys
, ilo
->shader_cache
);
160 ilo
->render
= ilo_render_create(&ilo
->cp
->builder
);
162 if (!ilo
->cp
|| !ilo
->shader_cache
|| !ilo
->render
) {
163 ilo_context_destroy(&ilo
->base
);
167 ilo_cp_set_submit_callback(ilo
->cp
,
168 ilo_context_cp_submitted
, (void *) ilo
);
170 ilo
->base
.screen
= screen
;
171 ilo
->base
.priv
= priv
;
173 ilo
->base
.destroy
= ilo_context_destroy
;
174 ilo
->base
.flush
= ilo_flush
;
175 ilo
->base
.render_condition
= ilo_render_condition
;
177 ilo_init_draw_functions(ilo
);
178 ilo_init_query_functions(ilo
);
179 ilo_init_state_functions(ilo
);
180 ilo_init_blit_functions(ilo
);
181 ilo_init_transfer_functions(ilo
);
182 ilo_init_video_functions(ilo
);
183 ilo_init_gpgpu_functions(ilo
);
186 ilo_state_vector_init(ilo
->dev
, &ilo
->state_vector
);
189 * These must be called last as u_upload/u_blitter are clients of the pipe
192 ilo
->uploader
= u_upload_create(&ilo
->base
, 1024 * 1024,
193 PIPE_BIND_CONSTANT_BUFFER
| PIPE_BIND_INDEX_BUFFER
,
195 if (!ilo
->uploader
) {
196 ilo_context_destroy(&ilo
->base
);
200 ilo
->blitter
= ilo_blitter_create(ilo
);
202 ilo_context_destroy(&ilo
->base
);
210 * Initialize context-related functions.
213 ilo_init_context_functions(struct ilo_screen
*is
)
215 is
->base
.context_create
= ilo_context_create
;