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_blitter.h"
29 #include "intel_chipset.h"
34 #include "ilo_gpgpu.h"
35 #include "ilo_query.h"
36 #include "ilo_resource.h"
37 #include "ilo_screen.h"
38 #include "ilo_shader.h"
39 #include "ilo_state.h"
40 #include "ilo_video.h"
41 #include "ilo_context.h"
44 ilo_context_new_cp_batch(struct ilo_cp
*cp
, void *data
)
46 struct ilo_context
*ilo
= ilo_context(data
);
48 if (cp
->ring
== ILO_CP_RING_RENDER
)
49 ilo_3d_new_cp_batch(ilo
->hw3d
);
53 ilo_context_pre_cp_flush(struct ilo_cp
*cp
, void *data
)
55 struct ilo_context
*ilo
= ilo_context(data
);
57 if (cp
->ring
== ILO_CP_RING_RENDER
)
58 ilo_3d_pre_cp_flush(ilo
->hw3d
);
62 ilo_context_post_cp_flush(struct ilo_cp
*cp
, void *data
)
64 struct ilo_context
*ilo
= ilo_context(data
);
67 ilo
->last_cp_bo
->unreference(ilo
->last_cp_bo
);
69 /* remember the just flushed bo, on which fences could wait */
70 ilo
->last_cp_bo
= cp
->bo
;
71 ilo
->last_cp_bo
->reference(ilo
->last_cp_bo
);
73 if (cp
->ring
== ILO_CP_RING_RENDER
)
74 ilo_3d_post_cp_flush(ilo
->hw3d
);
78 ilo_flush(struct pipe_context
*pipe
,
79 struct pipe_fence_handle
**f
,
80 enum pipe_flush_flags flags
)
82 struct ilo_context
*ilo
= ilo_context(pipe
);
85 struct ilo_fence
*fence
;
87 fence
= CALLOC_STRUCT(ilo_fence
);
89 pipe_reference_init(&fence
->reference
, 1);
91 /* reference the batch bo that we want to wait on */
92 if (ilo_cp_empty(ilo
->cp
))
93 fence
->bo
= ilo
->last_cp_bo
;
95 fence
->bo
= ilo
->cp
->bo
;
98 fence
->bo
->reference(fence
->bo
);
101 *f
= (struct pipe_fence_handle
*) fence
;
104 ilo_cp_flush(ilo
->cp
);
108 ilo_context_destroy(struct pipe_context
*pipe
)
110 struct ilo_context
*ilo
= ilo_context(pipe
);
113 ilo
->last_cp_bo
->unreference(ilo
->last_cp_bo
);
116 util_blitter_destroy(ilo
->blitter
);
118 ilo_3d_destroy(ilo
->hw3d
);
119 if (ilo
->shader_cache
)
120 ilo_shader_cache_destroy(ilo
->shader_cache
);
122 ilo_cp_destroy(ilo
->cp
);
127 static struct pipe_context
*
128 ilo_context_create(struct pipe_screen
*screen
, void *priv
)
130 struct ilo_screen
*is
= ilo_screen(screen
);
131 struct ilo_context
*ilo
;
133 ilo
= CALLOC_STRUCT(ilo_context
);
137 ilo
->winsys
= is
->winsys
;
140 ilo
->cp
= ilo_cp_create(ilo
->winsys
, is
->dev
.has_llc
);
141 ilo
->shader_cache
= ilo_shader_cache_create(ilo
->winsys
);
143 ilo
->hw3d
= ilo_3d_create(ilo
->cp
, ilo
->dev
);
145 if (!ilo
->cp
|| !ilo
->shader_cache
|| !ilo
->hw3d
) {
146 ilo_context_destroy(&ilo
->base
);
150 ilo_cp_set_hook(ilo
->cp
, ILO_CP_HOOK_NEW_BATCH
,
151 ilo_context_new_cp_batch
, (void *) ilo
);
152 ilo_cp_set_hook(ilo
->cp
, ILO_CP_HOOK_PRE_FLUSH
,
153 ilo_context_pre_cp_flush
, (void *) ilo
);
154 ilo_cp_set_hook(ilo
->cp
, ILO_CP_HOOK_POST_FLUSH
,
155 ilo_context_post_cp_flush
, (void *) ilo
);
157 ilo
->dirty
= ILO_DIRTY_ALL
;
159 ilo
->base
.screen
= screen
;
160 ilo
->base
.priv
= priv
;
162 ilo
->base
.destroy
= ilo_context_destroy
;
163 ilo
->base
.flush
= ilo_flush
;
165 ilo_init_3d_functions(ilo
);
166 ilo_init_query_functions(ilo
);
167 ilo_init_state_functions(ilo
);
168 ilo_init_blit_functions(ilo
);
169 ilo_init_transfer_functions(ilo
);
170 ilo_init_video_functions(ilo
);
171 ilo_init_gpgpu_functions(ilo
);
173 /* this must be called last as u_blitter is a client of the pipe context */
174 ilo
->blitter
= util_blitter_create(&ilo
->base
);
176 ilo_context_destroy(&ilo
->base
);
184 * Initialize context-related functions.
187 ilo_init_context_functions(struct ilo_screen
*is
)
189 is
->base
.context_create
= ilo_context_create
;