etnaviv: Rework locking
[mesa.git] / src / gallium / drivers / etnaviv / etnaviv_context.c
1 /*
2 * Copyright (c) 2012-2015 Etnaviv Project
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sub license,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
13 * of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Wladimir J. van der Laan <laanwj@gmail.com>
25 * Christian Gmeiner <christian.gmeiner@gmail.com>
26 */
27
28 #include "etnaviv_context.h"
29
30 #include "etnaviv_blend.h"
31 #include "etnaviv_clear_blit.h"
32 #include "etnaviv_compiler.h"
33 #include "etnaviv_debug.h"
34 #include "etnaviv_emit.h"
35 #include "etnaviv_fence.h"
36 #include "etnaviv_query.h"
37 #include "etnaviv_query_hw.h"
38 #include "etnaviv_rasterizer.h"
39 #include "etnaviv_resource.h"
40 #include "etnaviv_screen.h"
41 #include "etnaviv_shader.h"
42 #include "etnaviv_state.h"
43 #include "etnaviv_surface.h"
44 #include "etnaviv_texture.h"
45 #include "etnaviv_transfer.h"
46 #include "etnaviv_translate.h"
47 #include "etnaviv_zsa.h"
48
49 #include "pipe/p_context.h"
50 #include "pipe/p_state.h"
51 #include "util/hash_table.h"
52 #include "util/u_blitter.h"
53 #include "util/u_helpers.h"
54 #include "util/u_memory.h"
55 #include "util/u_prim.h"
56 #include "util/u_upload_mgr.h"
57
58 #include "hw/common.xml.h"
59
60 static void
61 etna_context_destroy(struct pipe_context *pctx)
62 {
63 struct etna_context *ctx = etna_context(pctx);
64 struct etna_screen *screen = ctx->screen;
65
66 mtx_lock(&ctx->lock);
67 if (ctx->used_resources_read) {
68
69 /*
70 * There should be no resources tracked in the context when it's being
71 * destroyed. Be sure there are none to avoid memory leaks on buggy
72 * programs.
73 */
74 set_foreach(ctx->used_resources_read, entry) {
75 struct etna_resource *rsc = (struct etna_resource *)entry->key;
76
77 _mesa_set_remove_key(rsc->pending_ctx, ctx);
78 }
79 _mesa_set_destroy(ctx->used_resources_read, NULL);
80
81 }
82 if (ctx->used_resources_write) {
83
84 /*
85 * There should be no resources tracked in the context when it's being
86 * destroyed. Be sure there are none to avoid memory leaks on buggy
87 * programs.
88 */
89 set_foreach(ctx->used_resources_write, entry) {
90 struct etna_resource *rsc = (struct etna_resource *)entry->key;
91
92 _mesa_set_remove_key(rsc->pending_ctx, ctx);
93 }
94 _mesa_set_destroy(ctx->used_resources_write, NULL);
95
96 }
97 mtx_unlock(&ctx->lock);
98
99 if (ctx->dummy_rt)
100 etna_bo_del(ctx->dummy_rt);
101
102 util_copy_framebuffer_state(&ctx->framebuffer_s, NULL);
103
104 if (ctx->primconvert)
105 util_primconvert_destroy(ctx->primconvert);
106
107 if (ctx->blitter)
108 util_blitter_destroy(ctx->blitter);
109
110 if (pctx->stream_uploader)
111 u_upload_destroy(pctx->stream_uploader);
112
113 if (ctx->stream)
114 etna_cmd_stream_del(ctx->stream);
115
116 slab_destroy_child(&ctx->transfer_pool);
117
118 if (ctx->in_fence_fd != -1)
119 close(ctx->in_fence_fd);
120
121 mtx_destroy(&ctx->lock);
122
123 FREE(pctx);
124 }
125
126 /* Update render state where needed based on draw operation */
127 static void
128 etna_update_state_for_draw(struct etna_context *ctx, const struct pipe_draw_info *info)
129 {
130 /* Handle primitive restart:
131 * - If not an indexed draw, we don't care about the state of the primitive restart bit.
132 * - Otherwise, set the bit in INDEX_STREAM_CONTROL in the index buffer state
133 * accordingly
134 * - If the value of the INDEX_STREAM_CONTROL register changed due to this, or
135 * primitive restart is enabled and the restart index changed, mark the index
136 * buffer state as dirty
137 */
138
139 if (info->index_size) {
140 uint32_t new_control = ctx->index_buffer.FE_INDEX_STREAM_CONTROL;
141
142 if (info->primitive_restart)
143 new_control |= VIVS_FE_INDEX_STREAM_CONTROL_PRIMITIVE_RESTART;
144 else
145 new_control &= ~VIVS_FE_INDEX_STREAM_CONTROL_PRIMITIVE_RESTART;
146
147 if (ctx->index_buffer.FE_INDEX_STREAM_CONTROL != new_control ||
148 (info->primitive_restart && ctx->index_buffer.FE_PRIMITIVE_RESTART_INDEX != info->restart_index)) {
149 ctx->index_buffer.FE_INDEX_STREAM_CONTROL = new_control;
150 ctx->index_buffer.FE_PRIMITIVE_RESTART_INDEX = info->restart_index;
151 ctx->dirty |= ETNA_DIRTY_INDEX_BUFFER;
152 }
153 }
154 }
155
156 static bool
157 etna_get_vs(struct etna_context *ctx, struct etna_shader_key key)
158 {
159 const struct etna_shader_variant *old = ctx->shader.vs;
160
161 ctx->shader.vs = etna_shader_variant(ctx->shader.bind_vs, key, &ctx->debug);
162
163 if (!ctx->shader.vs)
164 return false;
165
166 if (old != ctx->shader.vs)
167 ctx->dirty |= ETNA_DIRTY_SHADER;
168
169 return true;
170 }
171
172 static bool
173 etna_get_fs(struct etna_context *ctx, struct etna_shader_key key)
174 {
175 const struct etna_shader_variant *old = ctx->shader.fs;
176
177 ctx->shader.fs = etna_shader_variant(ctx->shader.bind_fs, key, &ctx->debug);
178
179 if (!ctx->shader.fs)
180 return false;
181
182 if (old != ctx->shader.fs)
183 ctx->dirty |= ETNA_DIRTY_SHADER;
184
185 return true;
186 }
187
188 static void
189 etna_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
190 {
191 struct etna_context *ctx = etna_context(pctx);
192 struct pipe_framebuffer_state *pfb = &ctx->framebuffer_s;
193 uint32_t draw_mode;
194 unsigned i;
195
196 if (!info->count_from_stream_output && !info->indirect &&
197 !info->primitive_restart &&
198 !u_trim_pipe_prim(info->mode, (unsigned*)&info->count))
199 return;
200
201 if (ctx->vertex_elements == NULL || ctx->vertex_elements->num_elements == 0)
202 return; /* Nothing to do */
203
204 if (!(ctx->prim_hwsupport & (1 << info->mode))) {
205 struct primconvert_context *primconvert = ctx->primconvert;
206 util_primconvert_save_rasterizer_state(primconvert, ctx->rasterizer);
207 util_primconvert_draw_vbo(primconvert, info);
208 return;
209 }
210
211 int prims = u_decomposed_prims_for_vertices(info->mode, info->count);
212 if (unlikely(prims <= 0)) {
213 DBG("Invalid draw primitive mode=%i or no primitives to be drawn", info->mode);
214 return;
215 }
216
217 draw_mode = translate_draw_mode(info->mode);
218 if (draw_mode == ETNA_NO_MATCH) {
219 BUG("Unsupported draw mode");
220 return;
221 }
222
223 /* Upload a user index buffer. */
224 unsigned index_offset = 0;
225 struct pipe_resource *indexbuf = NULL;
226
227 if (info->index_size) {
228 indexbuf = info->has_user_indices ? NULL : info->index.resource;
229 if (info->has_user_indices &&
230 !util_upload_index_buffer(pctx, info, &indexbuf, &index_offset)) {
231 BUG("Index buffer upload failed.");
232 return;
233 }
234 /* Add start to index offset, when rendering indexed */
235 index_offset += info->start * info->index_size;
236
237 ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.bo = etna_resource(indexbuf)->bo;
238 ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.offset = index_offset;
239 ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.flags = ETNA_RELOC_READ;
240 ctx->index_buffer.FE_INDEX_STREAM_CONTROL = translate_index_size(info->index_size);
241
242 if (!ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.bo) {
243 BUG("Unsupported or no index buffer");
244 return;
245 }
246 } else {
247 ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.bo = 0;
248 ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.offset = 0;
249 ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.flags = 0;
250 ctx->index_buffer.FE_INDEX_STREAM_CONTROL = 0;
251 }
252 ctx->dirty |= ETNA_DIRTY_INDEX_BUFFER;
253
254 struct etna_shader_key key = {
255 .front_ccw = ctx->rasterizer->front_ccw,
256 };
257
258 if (pfb->cbufs[0])
259 key.frag_rb_swap = !!translate_rs_format_rb_swap(pfb->cbufs[0]->format);
260
261 if (!etna_get_vs(ctx, key) || !etna_get_fs(ctx, key)) {
262 BUG("compiled shaders are not okay");
263 return;
264 }
265
266 /* Update any derived state */
267 if (!etna_state_update(ctx))
268 return;
269
270 mtx_lock(&ctx->lock);
271
272 /*
273 * Figure out the buffers/features we need:
274 */
275 if (etna_depth_enabled(ctx))
276 resource_written(ctx, pfb->zsbuf->texture);
277
278 if (etna_stencil_enabled(ctx))
279 resource_written(ctx, pfb->zsbuf->texture);
280
281 for (i = 0; i < pfb->nr_cbufs; i++) {
282 struct pipe_resource *surf;
283
284 if (!pfb->cbufs[i])
285 continue;
286
287 surf = pfb->cbufs[i]->texture;
288 resource_written(ctx, surf);
289 }
290
291 /* Mark constant buffers as being read */
292 resource_read(ctx, ctx->constant_buffer[PIPE_SHADER_VERTEX].buffer);
293 resource_read(ctx, ctx->constant_buffer[PIPE_SHADER_FRAGMENT].buffer);
294
295 /* Mark VBOs as being read */
296 foreach_bit(i, ctx->vertex_buffer.enabled_mask) {
297 assert(!ctx->vertex_buffer.vb[i].is_user_buffer);
298 resource_read(ctx, ctx->vertex_buffer.vb[i].buffer.resource);
299 }
300
301 /* Mark index buffer as being read */
302 resource_read(ctx, indexbuf);
303
304 /* Mark textures as being read */
305 for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
306 if (ctx->sampler_view[i]) {
307 resource_read(ctx, ctx->sampler_view[i]->texture);
308
309 /* if texture was modified since the last update,
310 * we need to clear the texture cache and possibly
311 * resolve/update ts
312 */
313 etna_update_sampler_source(ctx->sampler_view[i], i);
314 }
315 }
316
317 list_for_each_entry(struct etna_hw_query, hq, &ctx->active_hw_queries, node)
318 resource_written(ctx, hq->prsc);
319
320 ctx->stats.prims_emitted += u_reduced_prims_for_vertices(info->mode, info->count);
321 ctx->stats.draw_calls++;
322
323 /* Update state for this draw operation */
324 etna_update_state_for_draw(ctx, info);
325
326 /* First, sync state, then emit DRAW_PRIMITIVES or DRAW_INDEXED_PRIMITIVES */
327 etna_emit_state(ctx);
328
329 if (ctx->specs.halti >= 2) {
330 /* On HALTI2+ (GC3000 and higher) only use instanced drawing commands, as the blob does */
331 etna_draw_instanced(ctx->stream, info->index_size, draw_mode, 1,
332 info->count, info->index_size ? info->index_bias : info->start);
333 } else {
334 if (info->index_size)
335 etna_draw_indexed_primitives(ctx->stream, draw_mode, 0, prims, info->index_bias);
336 else
337 etna_draw_primitives(ctx->stream, draw_mode, info->start, prims);
338 }
339
340 if (DBG_ENABLED(ETNA_DBG_DRAW_STALL)) {
341 /* Stall the FE after every draw operation. This allows better
342 * debug of GPU hang conditions, as the FE will indicate which
343 * draw op has caused the hang. */
344 etna_stall(ctx->stream, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE);
345 }
346 mtx_unlock(&ctx->lock);
347
348 if (DBG_ENABLED(ETNA_DBG_FLUSH_ALL))
349 pctx->flush(pctx, NULL, 0);
350
351 if (ctx->framebuffer_s.cbufs[0])
352 etna_resource(ctx->framebuffer_s.cbufs[0]->texture)->seqno++;
353 if (ctx->framebuffer_s.zsbuf)
354 etna_resource(ctx->framebuffer_s.zsbuf->texture)->seqno++;
355 if (info->index_size && indexbuf != info->index.resource)
356 pipe_resource_reference(&indexbuf, NULL);
357 }
358
359 static void etna_reset_gpu_state(struct etna_context *ctx)
360 {
361 struct etna_cmd_stream *stream = ctx->stream;
362
363 etna_set_state(stream, VIVS_GL_API_MODE, VIVS_GL_API_MODE_OPENGL);
364 etna_set_state(stream, VIVS_GL_VERTEX_ELEMENT_CONFIG, 0x00000001);
365 /* blob sets this to 0x40000031 on GC7000, seems to make no difference,
366 * but keep it in mind if depth behaves strangely. */
367 etna_set_state(stream, VIVS_RA_EARLY_DEPTH, 0x00000031);
368 etna_set_state(stream, VIVS_PA_W_CLIP_LIMIT, 0x34000001);
369 etna_set_state(stream, VIVS_PA_FLAGS, 0x00000000); /* blob sets ZCONVERT_BYPASS on GC3000+, this messes up z for us */
370 etna_set_state(stream, VIVS_PA_VIEWPORT_UNK00A80, 0x38a01404);
371 etna_set_state(stream, VIVS_PA_VIEWPORT_UNK00A84, fui(8192.0));
372 etna_set_state(stream, VIVS_PA_ZFARCLIPPING, 0x00000000);
373 etna_set_state(stream, VIVS_RA_HDEPTH_CONTROL, 0x00007000);
374 etna_set_state(stream, VIVS_PE_STENCIL_CONFIG_EXT2, 0x00000000);
375 etna_set_state(stream, VIVS_PS_CONTROL_EXT, 0x00000000);
376
377 /* There is no HALTI0 specific state */
378 if (ctx->specs.halti >= 1) { /* Only on HALTI1+ */
379 etna_set_state(stream, VIVS_VS_HALTI1_UNK00884, 0x00000808);
380 }
381 if (ctx->specs.halti >= 2) { /* Only on HALTI2+ */
382 etna_set_state(stream, VIVS_RA_UNK00E0C, 0x00000000);
383 }
384 if (ctx->specs.halti >= 3) { /* Only on HALTI3+ */
385 etna_set_state(stream, VIVS_PS_HALTI3_UNK0103C, 0x76543210);
386 }
387 if (ctx->specs.halti >= 4) { /* Only on HALTI4+ */
388 etna_set_state(stream, VIVS_PS_MSAA_CONFIG, 0x6fffffff & 0xf70fffff & 0xfff6ffff &
389 0xffff6fff & 0xfffff6ff & 0xffffff7f);
390 etna_set_state(stream, VIVS_PE_HALTI4_UNK014C0, 0x00000000);
391 }
392 if (ctx->specs.halti >= 5) { /* Only on HALTI5+ */
393 etna_set_state(stream, VIVS_NTE_DESCRIPTOR_UNK14C40, 0x00000001);
394 etna_set_state(stream, VIVS_FE_HALTI5_UNK007D8, 0x00000002);
395 etna_set_state(stream, VIVS_FE_HALTI5_ID_CONFIG, 0x00000000);
396 etna_set_state(stream, VIVS_PS_SAMPLER_BASE, 0x00000000);
397 etna_set_state(stream, VIVS_VS_SAMPLER_BASE, 0x00000020);
398 etna_set_state(stream, VIVS_SH_CONFIG, VIVS_SH_CONFIG_RTNE_ROUNDING);
399 } else { /* Only on pre-HALTI5 */
400 etna_set_state(stream, VIVS_GL_UNK03834, 0x00000000);
401 etna_set_state(stream, VIVS_GL_UNK03838, 0x00000000);
402 etna_set_state(stream, VIVS_GL_UNK03854, 0x00000000);
403 }
404
405 if (!ctx->specs.use_blt) {
406 /* Enable SINGLE_BUFFER for resolve, if supported */
407 etna_set_state(stream, VIVS_RS_SINGLE_BUFFER, COND(ctx->specs.single_buffer, VIVS_RS_SINGLE_BUFFER_ENABLE));
408 }
409
410 ctx->dirty = ~0L;
411 ctx->dirty_sampler_views = ~0L;
412 }
413
414 static void
415 etna_flush(struct pipe_context *pctx, struct pipe_fence_handle **fence,
416 enum pipe_flush_flags flags)
417 {
418 struct etna_context *ctx = etna_context(pctx);
419 struct etna_screen *screen = ctx->screen;
420 int out_fence_fd = -1;
421
422 mtx_lock(&ctx->lock);
423
424 list_for_each_entry(struct etna_hw_query, hq, &ctx->active_hw_queries, node)
425 etna_hw_query_suspend(hq, ctx);
426
427 etna_cmd_stream_flush(ctx->stream, ctx->in_fence_fd,
428 (flags & PIPE_FLUSH_FENCE_FD) ? &out_fence_fd : NULL);
429
430 list_for_each_entry(struct etna_hw_query, hq, &ctx->active_hw_queries, node)
431 etna_hw_query_resume(hq, ctx);
432
433 if (fence)
434 *fence = etna_fence_create(pctx, out_fence_fd);
435
436 /*
437 * Go through all _resources_ pending in this _context_ and mark them as
438 * not pending in this _context_ anymore, since they were just flushed.
439 */
440 set_foreach(ctx->used_resources_read, entry) {
441 struct etna_resource *rsc = (struct etna_resource *)entry->key;
442 struct pipe_resource *referenced = &rsc->base;
443
444 _mesa_set_remove_key(rsc->pending_ctx, ctx);
445
446 pipe_resource_reference(&referenced, NULL);
447 }
448 _mesa_set_clear(ctx->used_resources_read, NULL);
449
450 set_foreach(ctx->used_resources_write, entry) {
451 struct etna_resource *rsc = (struct etna_resource *)entry->key;
452 struct pipe_resource *referenced = &rsc->base;
453
454 _mesa_set_remove_key(rsc->pending_ctx, ctx);
455
456 pipe_resource_reference(&referenced, NULL);
457 }
458 _mesa_set_clear(ctx->used_resources_write, NULL);
459
460 etna_reset_gpu_state(ctx);
461 mtx_unlock(&ctx->lock);
462 }
463
464 static void
465 etna_context_force_flush(struct etna_cmd_stream *stream, void *priv)
466 {
467 struct pipe_context *pctx = priv;
468
469 pctx->flush(pctx, NULL, 0);
470
471 }
472
473 static void
474 etna_set_debug_callback(struct pipe_context *pctx,
475 const struct pipe_debug_callback *cb)
476 {
477 struct etna_context *ctx = etna_context(pctx);
478
479 if (cb)
480 ctx->debug = *cb;
481 else
482 memset(&ctx->debug, 0, sizeof(ctx->debug));
483 }
484
485 struct pipe_context *
486 etna_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
487 {
488 struct etna_context *ctx = CALLOC_STRUCT(etna_context);
489 struct etna_screen *screen;
490 struct pipe_context *pctx;
491
492 if (ctx == NULL)
493 return NULL;
494
495 pctx = &ctx->base;
496 pctx->priv = ctx;
497 pctx->screen = pscreen;
498 pctx->stream_uploader = u_upload_create_default(pctx);
499 if (!pctx->stream_uploader)
500 goto fail;
501 pctx->const_uploader = pctx->stream_uploader;
502
503 screen = etna_screen(pscreen);
504 ctx->stream = etna_cmd_stream_new(screen->pipe, 0x2000,
505 &etna_context_force_flush, pctx);
506 if (ctx->stream == NULL)
507 goto fail;
508
509 ctx->used_resources_read = _mesa_set_create(NULL, _mesa_hash_pointer,
510 _mesa_key_pointer_equal);
511 if (!ctx->used_resources_read)
512 goto fail;
513
514 ctx->used_resources_write = _mesa_set_create(NULL, _mesa_hash_pointer,
515 _mesa_key_pointer_equal);
516 if (!ctx->used_resources_write)
517 goto fail;
518
519 mtx_init(&ctx->lock, mtx_recursive);
520
521 /* context ctxate setup */
522 ctx->specs = screen->specs;
523 ctx->screen = screen;
524 /* need some sane default in case state tracker doesn't set some state: */
525 ctx->sample_mask = 0xffff;
526
527 /* Set sensible defaults for state */
528 etna_reset_gpu_state(ctx);
529
530 ctx->in_fence_fd = -1;
531
532 pctx->destroy = etna_context_destroy;
533 pctx->draw_vbo = etna_draw_vbo;
534 pctx->flush = etna_flush;
535 pctx->set_debug_callback = etna_set_debug_callback;
536 pctx->create_fence_fd = etna_create_fence_fd;
537 pctx->fence_server_sync = etna_fence_server_sync;
538
539 /* creation of compile states */
540 pctx->create_blend_state = etna_blend_state_create;
541 pctx->create_rasterizer_state = etna_rasterizer_state_create;
542 pctx->create_depth_stencil_alpha_state = etna_zsa_state_create;
543
544 etna_clear_blit_init(pctx);
545 etna_query_context_init(pctx);
546 etna_state_init(pctx);
547 etna_surface_init(pctx);
548 etna_shader_init(pctx);
549 etna_texture_init(pctx);
550 etna_transfer_init(pctx);
551
552 ctx->blitter = util_blitter_create(pctx);
553 if (!ctx->blitter)
554 goto fail;
555
556 /* Generate the bitmask of supported draw primitives. */
557 ctx->prim_hwsupport = 1 << PIPE_PRIM_POINTS |
558 1 << PIPE_PRIM_LINES |
559 1 << PIPE_PRIM_LINE_STRIP |
560 1 << PIPE_PRIM_TRIANGLES |
561 1 << PIPE_PRIM_TRIANGLE_FAN;
562
563 /* TODO: The bug relates only to indexed draws, but here we signal
564 * that there is no support for triangle strips at all. This should
565 * be refined.
566 */
567 if (VIV_FEATURE(ctx->screen, chipMinorFeatures2, BUG_FIXES8))
568 ctx->prim_hwsupport |= 1 << PIPE_PRIM_TRIANGLE_STRIP;
569
570 if (VIV_FEATURE(ctx->screen, chipMinorFeatures2, LINE_LOOP))
571 ctx->prim_hwsupport |= 1 << PIPE_PRIM_LINE_LOOP;
572
573 ctx->primconvert = util_primconvert_create(pctx, ctx->prim_hwsupport);
574 if (!ctx->primconvert)
575 goto fail;
576
577 slab_create_child(&ctx->transfer_pool, &screen->transfer_pool);
578 list_inithead(&ctx->active_hw_queries);
579
580 /* create dummy RT buffer, used when rendering with no color buffer */
581 ctx->dummy_rt = etna_bo_new(ctx->screen->dev, 64 * 64 * 4,
582 DRM_ETNA_GEM_CACHE_WC);
583 if (!ctx->dummy_rt)
584 goto fail;
585
586 ctx->dummy_rt_reloc.bo = ctx->dummy_rt;
587 ctx->dummy_rt_reloc.offset = 0;
588 ctx->dummy_rt_reloc.flags = ETNA_RELOC_READ | ETNA_RELOC_WRITE;
589
590 return pctx;
591
592 fail:
593 pctx->destroy(pctx);
594
595 return NULL;
596 }