714a9bf72c26910b264addcb02cd3604b93a6cdf
[mesa.git] / src / gallium / drivers / ilo / ilo_context.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2012-2013 LunarG, Inc.
5 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the 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 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
26 */
27
28 #include "intel_chipset.h"
29
30 #include "ilo_3d.h"
31 #include "ilo_blit.h"
32 #include "ilo_cp.h"
33 #include "ilo_gpgpu.h"
34 #include "ilo_query.h"
35 #include "ilo_resource.h"
36 #include "ilo_screen.h"
37 #include "ilo_state.h"
38 #include "ilo_video.h"
39 #include "ilo_context.h"
40
41 static void
42 ilo_context_new_cp_batch(struct ilo_cp *cp, void *data)
43 {
44 }
45
46 static void
47 ilo_context_pre_cp_flush(struct ilo_cp *cp, void *data)
48 {
49 }
50
51 static void
52 ilo_context_post_cp_flush(struct ilo_cp *cp, void *data)
53 {
54 struct ilo_context *ilo = ilo_context(data);
55
56 if (ilo->last_cp_bo)
57 ilo->last_cp_bo->unreference(ilo->last_cp_bo);
58
59 /* remember the just flushed bo, on which fences could wait */
60 ilo->last_cp_bo = cp->bo;
61 ilo->last_cp_bo->reference(ilo->last_cp_bo);
62 }
63
64 static void
65 ilo_flush(struct pipe_context *pipe,
66 struct pipe_fence_handle **f,
67 enum pipe_flush_flags flags)
68 {
69 struct ilo_context *ilo = ilo_context(pipe);
70
71 if (f) {
72 struct ilo_fence *fence;
73
74 fence = CALLOC_STRUCT(ilo_fence);
75 if (fence) {
76 pipe_reference_init(&fence->reference, 1);
77
78 /* reference the batch bo that we want to wait on */
79 if (ilo_cp_empty(ilo->cp))
80 fence->bo = ilo->last_cp_bo;
81 else
82 fence->bo = ilo->cp->bo;
83
84 if (fence->bo)
85 fence->bo->reference(fence->bo);
86 }
87
88 *f = (struct pipe_fence_handle *) fence;
89 }
90
91 ilo_cp_flush(ilo->cp);
92 }
93
94 static void
95 ilo_context_destroy(struct pipe_context *pipe)
96 {
97 struct ilo_context *ilo = ilo_context(pipe);
98
99 if (ilo->last_cp_bo)
100 ilo->last_cp_bo->unreference(ilo->last_cp_bo);
101
102 if (ilo->cp)
103 ilo_cp_destroy(ilo->cp);
104
105 FREE(ilo);
106 }
107
108 static struct pipe_context *
109 ilo_context_create(struct pipe_screen *screen, void *priv)
110 {
111 struct ilo_screen *is = ilo_screen(screen);
112 struct ilo_context *ilo;
113
114 ilo = CALLOC_STRUCT(ilo_context);
115 if (!ilo)
116 return NULL;
117
118 ilo->winsys = is->winsys;
119 ilo->devid = is->devid;
120 ilo->gen = is->gen;
121
122 if (IS_SNB_GT1(ilo->devid) ||
123 IS_IVB_GT1(ilo->devid) ||
124 IS_HSW_GT1(ilo->devid) ||
125 IS_BAYTRAIL(ilo->devid))
126 ilo->gt = 1;
127 else if (IS_SNB_GT2(ilo->devid) ||
128 IS_IVB_GT2(ilo->devid) ||
129 IS_HSW_GT2(ilo->devid))
130 ilo->gt = 2;
131 else
132 ilo->gt = 0;
133
134 /* stolen from classic i965 */
135 /* WM maximum threads is number of EUs times number of threads per EU. */
136 if (ilo->gen >= ILO_GEN(7)) {
137 if (ilo->gt == 1) {
138 ilo->max_wm_threads = 48;
139 ilo->max_vs_threads = 36;
140 ilo->max_gs_threads = 36;
141 ilo->urb.size = 128;
142 ilo->urb.max_vs_entries = 512;
143 ilo->urb.max_gs_entries = 192;
144 } else if (ilo->gt == 2) {
145 ilo->max_wm_threads = 172;
146 ilo->max_vs_threads = 128;
147 ilo->max_gs_threads = 128;
148 ilo->urb.size = 256;
149 ilo->urb.max_vs_entries = 704;
150 ilo->urb.max_gs_entries = 320;
151 } else {
152 assert(!"Unknown gen7 device.");
153 }
154 } else if (ilo->gen == ILO_GEN(6)) {
155 if (ilo->gt == 2) {
156 ilo->max_wm_threads = 80;
157 ilo->max_vs_threads = 60;
158 ilo->max_gs_threads = 60;
159 ilo->urb.size = 64; /* volume 5c.5 section 5.1 */
160 ilo->urb.max_vs_entries = 256; /* volume 2a (see 3DSTATE_URB) */
161 ilo->urb.max_gs_entries = 256;
162 } else {
163 ilo->max_wm_threads = 40;
164 ilo->max_vs_threads = 24;
165 ilo->max_gs_threads = 21; /* conservative; 24 if rendering disabled */
166 ilo->urb.size = 32; /* volume 5c.5 section 5.1 */
167 ilo->urb.max_vs_entries = 256; /* volume 2a (see 3DSTATE_URB) */
168 ilo->urb.max_gs_entries = 256;
169 }
170 }
171
172 ilo->cp = ilo_cp_create(ilo->winsys, is->has_llc);
173 if (!ilo->cp) {
174 ilo_context_destroy(&ilo->base);
175 return NULL;
176 }
177
178 ilo_cp_set_hook(ilo->cp, ILO_CP_HOOK_NEW_BATCH,
179 ilo_context_new_cp_batch, (void *) ilo);
180 ilo_cp_set_hook(ilo->cp, ILO_CP_HOOK_PRE_FLUSH,
181 ilo_context_pre_cp_flush, (void *) ilo);
182 ilo_cp_set_hook(ilo->cp, ILO_CP_HOOK_POST_FLUSH,
183 ilo_context_post_cp_flush, (void *) ilo);
184
185 ilo->base.screen = screen;
186 ilo->base.priv = priv;
187
188 ilo->base.destroy = ilo_context_destroy;
189 ilo->base.flush = ilo_flush;
190
191 ilo_init_3d_functions(ilo);
192 ilo_init_query_functions(ilo);
193 ilo_init_state_functions(ilo);
194 ilo_init_blit_functions(ilo);
195 ilo_init_transfer_functions(ilo);
196 ilo_init_video_functions(ilo);
197 ilo_init_gpgpu_functions(ilo);
198
199 return &ilo->base;
200 }
201
202 /**
203 * Initialize context-related functions.
204 */
205 void
206 ilo_init_context_functions(struct ilo_screen *is)
207 {
208 is->base.context_create = ilo_context_create;
209 }