Rev 2352 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2351 | Serge | 1 | #include |
2 | #include |
||
3 | #include "i915_drm.h" |
||
4 | #include "i915_drv.h" |
||
5 | #include "intel_drv.h" |
||
6 | |||
7 | #include |
||
8 | #include |
||
9 | #include |
||
10 | #include |
||
11 | |||
12 | #include |
||
13 | |||
14 | #include "../bitmap.h" |
||
15 | |||
16 | #include "sna.h" |
||
17 | |||
18 | struct kgem_bo *create_bo(bitmap_t *bitmap); |
||
19 | |||
20 | static Bool sna_solid_cache_init(struct sna *sna); |
||
21 | |||
22 | struct sna *sna_device; |
||
23 | |||
24 | void no_render_init(struct sna *sna) |
||
25 | { |
||
26 | struct sna_render *render = &sna->render; |
||
27 | |||
28 | memset (render,0, sizeof (*render)); |
||
29 | |||
30 | render->vertices = render->vertex_data; |
||
31 | render->vertex_size = ARRAY_SIZE(render->vertex_data); |
||
32 | |||
33 | // render->composite = no_render_composite; |
||
34 | |||
35 | // render->copy_boxes = no_render_copy_boxes; |
||
36 | // render->copy = no_render_copy; |
||
37 | |||
38 | // render->fill_boxes = no_render_fill_boxes; |
||
39 | // render->fill = no_render_fill; |
||
40 | // render->fill_one = no_render_fill_one; |
||
41 | // render->clear = no_render_clear; |
||
42 | |||
43 | // render->reset = no_render_reset; |
||
44 | // render->flush = no_render_flush; |
||
45 | // render->fini = no_render_fini; |
||
46 | |||
47 | // sna->kgem.context_switch = no_render_context_switch; |
||
48 | // sna->kgem.retire = no_render_retire; |
||
49 | |||
50 | // if (sna->kgem.gen >= 60) |
||
51 | sna->kgem.ring = KGEM_RENDER; |
||
52 | } |
||
53 | |||
54 | |||
55 | Bool sna_accel_init(struct sna *sna) |
||
56 | { |
||
57 | const char *backend; |
||
58 | |||
59 | // list_init(&sna->deferred_free); |
||
60 | // list_init(&sna->dirty_pixmaps); |
||
61 | // list_init(&sna->active_pixmaps); |
||
62 | // list_init(&sna->inactive_clock[0]); |
||
63 | // list_init(&sna->inactive_clock[1]); |
||
64 | |||
65 | // sna_accel_install_timers(sna); |
||
66 | |||
67 | |||
68 | backend = "no"; |
||
69 | sna->have_render = false; |
||
70 | sna->default_tiling = 0; //I915_TILING_X; |
||
71 | no_render_init(sna); |
||
72 | |||
73 | if ((sna->have_render = gen6_render_init(sna))) |
||
74 | backend = "SandyBridge"; |
||
75 | |||
76 | /* |
||
77 | if (sna->chipset.info->gen >= 80) { |
||
78 | } else if (sna->chipset.info->gen >= 70) { |
||
79 | if ((sna->have_render = gen7_render_init(sna))) |
||
80 | backend = "IvyBridge"; |
||
81 | } else if (sna->chipset.info->gen >= 60) { |
||
82 | if ((sna->have_render = gen6_render_init(sna))) |
||
83 | backend = "SandyBridge"; |
||
84 | } else if (sna->chipset.info->gen >= 50) { |
||
85 | if ((sna->have_render = gen5_render_init(sna))) |
||
86 | backend = "Ironlake"; |
||
87 | } else if (sna->chipset.info->gen >= 40) { |
||
88 | if ((sna->have_render = gen4_render_init(sna))) |
||
89 | backend = "Broadwater"; |
||
90 | } else if (sna->chipset.info->gen >= 30) { |
||
91 | if ((sna->have_render = gen3_render_init(sna))) |
||
92 | backend = "gen3"; |
||
93 | } else if (sna->chipset.info->gen >= 20) { |
||
94 | if ((sna->have_render = gen2_render_init(sna))) |
||
95 | backend = "gen2"; |
||
96 | } |
||
97 | */ |
||
98 | DBG(("%s(backend=%s, have_render=%d)\n", |
||
99 | __FUNCTION__, backend, sna->have_render)); |
||
100 | |||
101 | kgem_reset(&sna->kgem); |
||
102 | |||
103 | if (!sna_solid_cache_init(sna)) |
||
104 | return FALSE; |
||
105 | |||
106 | sna_device = sna; |
||
107 | #if 0 |
||
108 | { |
||
109 | struct kgem_bo *screen_bo; |
||
110 | bitmap_t screen; |
||
111 | |||
112 | screen.pitch = 1024*4; |
||
113 | screen.gaddr = 0; |
||
114 | screen.width = 1024; |
||
115 | screen.height = 768; |
||
116 | screen.obj = (void*)-1; |
||
117 | |||
118 | screen_bo = create_bo(&screen); |
||
119 | |||
120 | sna->render.clear(sna, &screen, screen_bo); |
||
121 | } |
||
122 | #endif |
||
123 | |||
124 | return TRUE; |
||
125 | } |
||
126 | |||
127 | int sna_init() |
||
128 | { |
||
129 | struct sna *sna; |
||
130 | |||
131 | DBG(("%s\n", __FUNCTION__)); |
||
132 | |||
133 | sna = kzalloc(sizeof(struct sna), 0); |
||
134 | if (sna == NULL) |
||
135 | return FALSE; |
||
136 | |||
137 | // sna->mode.cpp = 4; |
||
138 | |||
139 | kgem_init(&sna->kgem, 60); |
||
140 | /* |
||
141 | if (!xf86ReturnOptValBool(sna->Options, |
||
142 | OPTION_RELAXED_FENCING, |
||
143 | sna->kgem.has_relaxed_fencing)) { |
||
144 | xf86DrvMsg(scrn->scrnIndex, |
||
145 | sna->kgem.has_relaxed_fencing ? X_CONFIG : X_PROBED, |
||
146 | "Disabling use of relaxed fencing\n"); |
||
147 | sna->kgem.has_relaxed_fencing = 0; |
||
148 | } |
||
149 | if (!xf86ReturnOptValBool(sna->Options, |
||
150 | OPTION_VMAP, |
||
151 | sna->kgem.has_vmap)) { |
||
152 | xf86DrvMsg(scrn->scrnIndex, |
||
153 | sna->kgem.has_vmap ? X_CONFIG : X_PROBED, |
||
154 | "Disabling use of vmap\n"); |
||
155 | sna->kgem.has_vmap = 0; |
||
156 | } |
||
157 | */ |
||
158 | |||
159 | /* Disable tiling by default */ |
||
160 | sna->tiling = SNA_TILING_DISABLE; |
||
161 | |||
162 | /* Default fail-safe value of 75 Hz */ |
||
163 | // sna->vblank_interval = 1000 * 1000 * 1000 / 75; |
||
164 | |||
165 | sna->flags = 0; |
||
166 | sna->flags |= SNA_NO_THROTTLE; |
||
167 | sna->flags |= SNA_NO_DELAYED_FLUSH; |
||
168 | |||
169 | return sna_accel_init(sna); |
||
170 | } |
||
171 | |||
172 | |||
173 | static Bool sna_solid_cache_init(struct sna *sna) |
||
174 | { |
||
175 | struct sna_solid_cache *cache = &sna->render.solid_cache; |
||
176 | |||
177 | DBG(("%s\n", __FUNCTION__)); |
||
178 | |||
179 | cache->cache_bo = |
||
180 | kgem_create_linear(&sna->kgem, sizeof(cache->color)); |
||
181 | if (!cache->cache_bo) |
||
182 | return FALSE; |
||
183 | |||
184 | /* |
||
185 | * Initialise [0] with white since it is very common and filling the |
||
186 | * zeroth slot simplifies some of the checks. |
||
187 | */ |
||
188 | cache->color[0] = 0xffffffff; |
||
189 | cache->bo[0] = kgem_create_proxy(cache->cache_bo, 0, sizeof(uint32_t)); |
||
190 | cache->bo[0]->pitch = 4; |
||
191 | cache->dirty = 1; |
||
192 | cache->size = 1; |
||
193 | cache->last = 0; |
||
194 | |||
195 | return TRUE; |
||
196 | } |
||
197 | |||
198 | void |
||
199 | sna_render_flush_solid(struct sna *sna) |
||
200 | { |
||
201 | struct sna_solid_cache *cache = &sna->render.solid_cache; |
||
202 | |||
203 | DBG(("sna_render_flush_solid(size=%d)\n", cache->size)); |
||
204 | assert(cache->dirty); |
||
205 | assert(cache->size); |
||
206 | |||
207 | kgem_bo_write(&sna->kgem, cache->cache_bo, |
||
208 | cache->color, cache->size*sizeof(uint32_t)); |
||
209 | cache->dirty = 0; |
||
210 | cache->last = 0; |
||
211 | } |
||
212 | |||
213 | static void |
||
214 | sna_render_finish_solid(struct sna *sna, bool force) |
||
215 | { |
||
216 | struct sna_solid_cache *cache = &sna->render.solid_cache; |
||
217 | int i; |
||
218 | |||
219 | DBG(("sna_render_finish_solid(force=%d, domain=%d, busy=%d, dirty=%d)\n", |
||
220 | force, cache->cache_bo->domain, cache->cache_bo->rq != NULL, cache->dirty)); |
||
221 | |||
222 | if (!force && cache->cache_bo->domain != DOMAIN_GPU) |
||
223 | return; |
||
224 | |||
225 | if (cache->dirty) |
||
226 | sna_render_flush_solid(sna); |
||
227 | |||
228 | for (i = 0; i < cache->size; i++) { |
||
229 | if (cache->bo[i] == NULL) |
||
230 | continue; |
||
231 | |||
232 | kgem_bo_destroy(&sna->kgem, cache->bo[i]); |
||
233 | cache->bo[i] = NULL; |
||
234 | } |
||
235 | kgem_bo_destroy(&sna->kgem, cache->cache_bo); |
||
236 | |||
237 | DBG(("sna_render_finish_solid reset\n")); |
||
238 | |||
239 | cache->cache_bo = kgem_create_linear(&sna->kgem, sizeof(cache->color)); |
||
240 | cache->bo[0] = kgem_create_proxy(cache->cache_bo, 0, sizeof(uint32_t)); |
||
241 | cache->bo[0]->pitch = 4; |
||
242 | if (force) |
||
243 | cache->size = 1; |
||
244 | } |
||
245 | |||
246 | |||
247 | struct kgem_bo * |
||
248 | sna_render_get_solid(struct sna *sna, uint32_t color) |
||
249 | { |
||
250 | struct sna_solid_cache *cache = &sna->render.solid_cache; |
||
251 | int i; |
||
252 | |||
253 | DBG(("%s: %08x\n", __FUNCTION__, color)); |
||
254 | |||
255 | // if ((color & 0xffffff) == 0) /* alpha only */ |
||
256 | // return kgem_bo_reference(sna->render.alpha_cache.bo[color>>24]); |
||
257 | |||
258 | if (color == 0xffffffff) { |
||
259 | DBG(("%s(white)\n", __FUNCTION__)); |
||
260 | return kgem_bo_reference(cache->bo[0]); |
||
261 | } |
||
262 | |||
263 | if (cache->color[cache->last] == color) { |
||
264 | DBG(("sna_render_get_solid(%d) = %x (last)\n", |
||
265 | cache->last, color)); |
||
266 | return kgem_bo_reference(cache->bo[cache->last]); |
||
267 | } |
||
268 | |||
269 | for (i = 1; i < cache->size; i++) { |
||
270 | if (cache->color[i] == color) { |
||
271 | if (cache->bo[i] == NULL) { |
||
272 | DBG(("sna_render_get_solid(%d) = %x (recreate)\n", |
||
273 | i, color)); |
||
274 | goto create; |
||
275 | } else { |
||
276 | DBG(("sna_render_get_solid(%d) = %x (old)\n", |
||
277 | i, color)); |
||
278 | goto done; |
||
279 | } |
||
280 | } |
||
281 | } |
||
282 | |||
283 | sna_render_finish_solid(sna, i == ARRAY_SIZE(cache->color)); |
||
284 | |||
285 | i = cache->size++; |
||
286 | cache->color[i] = color; |
||
287 | cache->dirty = 1; |
||
288 | DBG(("sna_render_get_solid(%d) = %x (new)\n", i, color)); |
||
289 | |||
290 | create: |
||
291 | cache->bo[i] = kgem_create_proxy(cache->cache_bo, |
||
292 | i*sizeof(uint32_t), sizeof(uint32_t)); |
||
293 | cache->bo[i]->pitch = 4; |
||
294 | |||
295 | done: |
||
296 | cache->last = i; |
||
297 | return kgem_bo_reference(cache->bo[i]); |
||
298 | } |
||
299 | |||
300 | int sna_blit_copy(bitmap_t *dst_bitmap, int dst_x, int dst_y, |
||
301 | int w, int h, bitmap_t *src_bitmap, int src_x, int src_y) |
||
302 | |||
303 | { |
||
2352 | Serge | 304 | batchbuffer_t execbuffer; |
305 | |||
2351 | Serge | 306 | struct kgem_bo src_bo, dst_bo; |
307 | |||
2352 | Serge | 308 | memset(&execbuffer, 0, sizeof(execbuffer)); |
2351 | Serge | 309 | memset(&src_bo, 0, sizeof(src_bo)); |
310 | memset(&dst_bo, 0, sizeof(dst_bo)); |
||
311 | |||
2352 | Serge | 312 | INIT_LIST_HEAD(&execbuffer.objects); |
313 | |||
2351 | Serge | 314 | src_bo.gaddr = src_bitmap->gaddr; |
315 | src_bo.pitch = src_bitmap->pitch; |
||
316 | src_bo.tiling = 0; |
||
317 | |||
318 | dst_bo.gaddr = dst_bitmap->gaddr; |
||
319 | dst_bo.pitch = dst_bitmap->pitch; |
||
320 | dst_bo.tiling = 0; |
||
321 | |||
322 | sna_device->render.copy(sna_device, 0, src_bitmap, &src_bo, |
||
323 | dst_bitmap, &dst_bo, dst_x, dst_y, |
||
324 | src_x, src_y, w, h); |
||
2352 | Serge | 325 | |
326 | INIT_LIST_HEAD(&execbuffer.objects); |
||
327 | list_add_tail(&src_bitmap->obj->exec_list, &execbuffer.objects); |
||
328 | |||
329 | _kgem_submit(&sna_device->kgem, &execbuffer); |
||
330 | |||
2351 | Serge | 331 | }; |
332 | |||
333 | |||
2361 | Serge | 334 | int sna_blit_tex(bitmap_t *dst_bitmap, int dst_x, int dst_y, |
335 | int w, int h, bitmap_t *src_bitmap, int src_x, int src_y, |
||
336 | bitmap_t *mask_bitmap) |
||
337 | |||
338 | { |
||
339 | struct sna_composite_op cop; |
||
340 | batchbuffer_t execbuffer; |
||
341 | BoxRec box; |
||
342 | |||
343 | struct kgem_bo src_bo, mask_bo, dst_bo; |
||
344 | |||
345 | memset(&cop, 0, sizeof(cop)); |
||
346 | memset(&execbuffer, 0, sizeof(execbuffer)); |
||
347 | memset(&src_bo, 0, sizeof(src_bo)); |
||
348 | memset(&dst_bo, 0, sizeof(dst_bo)); |
||
349 | memset(&mask_bo, 0, sizeof(mask_bo)); |
||
350 | |||
351 | src_bo.gaddr = src_bitmap->gaddr; |
||
352 | src_bo.pitch = src_bitmap->pitch; |
||
353 | src_bo.tiling = 0; |
||
354 | |||
355 | dst_bo.gaddr = dst_bitmap->gaddr; |
||
356 | dst_bo.pitch = dst_bitmap->pitch; |
||
357 | dst_bo.tiling = 0; |
||
358 | |||
359 | mask_bo.gaddr = mask_bitmap->gaddr; |
||
360 | mask_bo.pitch = mask_bitmap->pitch; |
||
361 | mask_bo.tiling = 0; |
||
362 | |||
363 | box.x1 = dst_x; |
||
364 | box.y1 = dst_y; |
||
365 | box.x2 = dst_x+w; |
||
366 | box.y2 = dst_y+h; |
||
367 | |||
368 | sna_device->render.composite(sna_device, 0, |
||
369 | src_bitmap, &src_bo, |
||
370 | mask_bitmap, &mask_bo, |
||
371 | dst_bitmap, &dst_bo, |
||
372 | src_x, src_y, |
||
373 | src_x, src_y, |
||
374 | dst_x, dst_y, |
||
375 | w, h, &cop); |
||
376 | |||
377 | cop.box(sna_device, &cop, &box); |
||
378 | cop.done(sna_device, &cop); |
||
379 | |||
380 | INIT_LIST_HEAD(&execbuffer.objects); |
||
381 | list_add_tail(&src_bitmap->obj->exec_list, &execbuffer.objects); |
||
382 | list_add_tail(&mask_bitmap->obj->exec_list, &execbuffer.objects); |
||
383 | |||
384 | _kgem_submit(&sna_device->kgem, &execbuffer); |
||
385 | |||
386 | };>> |
||
387 |