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 /* invalidate the pipeline */
51 ilo_render_invalidate(ilo
->render
,
52 ILO_RENDER_INVALIDATE_BATCH_BO
|
53 ILO_RENDER_INVALIDATE_STATE_BO
|
54 ILO_RENDER_INVALIDATE_KERNEL_BO
);
58 ilo_flush(struct pipe_context
*pipe
,
59 struct pipe_fence_handle
**f
,
62 struct ilo_context
*ilo
= ilo_context(pipe
);
64 ilo_cp_submit(ilo
->cp
,
65 (flags
& PIPE_FLUSH_END_OF_FRAME
) ? "frame end" : "user request");
68 *f
= (struct pipe_fence_handle
*)
69 ilo_fence_create(pipe
->screen
, ilo
->cp
->last_submitted_bo
);
74 ilo_render_condition(struct pipe_context
*pipe
,
75 struct pipe_query
*query
,
79 struct ilo_context
*ilo
= ilo_context(pipe
);
81 /* reference count? */
82 ilo
->render_condition
.query
= query
;
83 ilo
->render_condition
.condition
= condition
;
84 ilo
->render_condition
.mode
= mode
;
88 ilo_skip_rendering(struct ilo_context
*ilo
)
93 if (!ilo
->render_condition
.query
)
96 switch (ilo
->render_condition
.mode
) {
97 case PIPE_RENDER_COND_WAIT
:
98 case PIPE_RENDER_COND_BY_REGION_WAIT
:
101 case PIPE_RENDER_COND_NO_WAIT
:
102 case PIPE_RENDER_COND_BY_REGION_NO_WAIT
:
108 if (ilo
->base
.get_query_result(&ilo
->base
, ilo
->render_condition
.query
,
109 wait
, (union pipe_query_result
*) &result
))
110 return ((bool) result
== ilo
->render_condition
.condition
);
116 ilo_context_destroy(struct pipe_context
*pipe
)
118 struct ilo_context
*ilo
= ilo_context(pipe
);
120 ilo_state_vector_cleanup(&ilo
->state_vector
);
123 u_upload_destroy(ilo
->uploader
);
126 ilo_blitter_destroy(ilo
->blitter
);
128 ilo_render_destroy(ilo
->render
);
129 if (ilo
->shader_cache
)
130 ilo_shader_cache_destroy(ilo
->shader_cache
);
132 ilo_cp_destroy(ilo
->cp
);
134 util_slab_destroy(&ilo
->transfer_mempool
);
139 static struct pipe_context
*
140 ilo_context_create(struct pipe_screen
*screen
, void *priv
)
142 struct ilo_screen
*is
= ilo_screen(screen
);
143 struct ilo_context
*ilo
;
145 ilo
= CALLOC_STRUCT(ilo_context
);
149 ilo
->winsys
= is
->winsys
;
153 * initialize first, otherwise it may not be safe to call
154 * ilo_context_destroy() on errors
156 util_slab_create(&ilo
->transfer_mempool
,
157 sizeof(struct ilo_transfer
), 64, UTIL_SLAB_SINGLETHREADED
);
159 ilo
->shader_cache
= ilo_shader_cache_create();
160 ilo
->cp
= ilo_cp_create(ilo
->dev
, ilo
->winsys
, ilo
->shader_cache
);
162 ilo
->render
= ilo_render_create(&ilo
->cp
->builder
);
164 if (!ilo
->cp
|| !ilo
->shader_cache
|| !ilo
->render
) {
165 ilo_context_destroy(&ilo
->base
);
169 ilo_cp_set_submit_callback(ilo
->cp
,
170 ilo_context_cp_submitted
, (void *) ilo
);
172 ilo
->base
.screen
= screen
;
173 ilo
->base
.priv
= priv
;
175 ilo
->base
.destroy
= ilo_context_destroy
;
176 ilo
->base
.flush
= ilo_flush
;
177 ilo
->base
.render_condition
= ilo_render_condition
;
179 ilo_init_draw_functions(ilo
);
180 ilo_init_query_functions(ilo
);
181 ilo_init_state_functions(ilo
);
182 ilo_init_blit_functions(ilo
);
183 ilo_init_transfer_functions(ilo
);
184 ilo_init_video_functions(ilo
);
185 ilo_init_gpgpu_functions(ilo
);
188 ilo_state_vector_init(ilo
->dev
, &ilo
->state_vector
);
191 * These must be called last as u_upload/u_blitter are clients of the pipe
194 ilo
->uploader
= u_upload_create(&ilo
->base
, 1024 * 1024, 16,
195 PIPE_BIND_CONSTANT_BUFFER
| PIPE_BIND_INDEX_BUFFER
);
196 if (!ilo
->uploader
) {
197 ilo_context_destroy(&ilo
->base
);
201 ilo
->blitter
= ilo_blitter_create(ilo
);
203 ilo_context_destroy(&ilo
->base
);
211 * Initialize context-related functions.
214 ilo_init_context_functions(struct ilo_screen
*is
)
216 is
->base
.context_create
= ilo_context_create
;