2
* Copyright (c) 2012-2015 Etnaviv Project
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:
11
* The above copyright notice and this permission notice (including the
12
* next paragraph) shall be included in all copies or substantial portions
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.
24
* Wladimir J. van der Laan <laanwj@gmail.com>
25
* Christian Gmeiner <christian.gmeiner@gmail.com>
28
#include "etnaviv_context.h"
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_acc.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"
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_draw.h"
54
#include "util/u_helpers.h"
55
#include "util/u_memory.h"
56
#include "util/u_prim.h"
57
#include "util/u_upload_mgr.h"
59
#include "hw/common.xml.h"
62
etna_emit_nop_with_data(struct etna_cmd_stream *stream, uint32_t value)
64
etna_cmd_stream_emit(stream, VIV_FE_NOP_HEADER_OP_NOP);
65
etna_cmd_stream_emit(stream, value);
69
etna_emit_string_marker(struct pipe_context *pctx, const char *string, int len)
71
struct etna_context *ctx = etna_context(pctx);
72
struct etna_cmd_stream *stream = ctx->stream;
73
const uint32_t *buf = (const void *)string;
75
etna_cmd_stream_reserve(stream, len * 2);
78
etna_emit_nop_with_data(stream, *buf);
83
/* copy remainder bytes without reading past end of input string */
87
etna_emit_nop_with_data(stream, w);
92
etna_set_frontend_noop(struct pipe_context *pctx, bool enable)
94
struct etna_context *ctx = etna_context(pctx);
96
pctx->flush(pctx, NULL, 0);
97
ctx->is_noop = enable;
101
etna_context_destroy(struct pipe_context *pctx)
103
struct etna_context *ctx = etna_context(pctx);
105
mtx_lock(&ctx->lock);
107
if (ctx->used_resources_read) {
110
* There should be no resources tracked in the context when it's being
111
* destroyed. Be sure there are none to avoid memory leaks on buggy
114
set_foreach(ctx->used_resources_read, entry) {
115
struct etna_resource *rsc = (struct etna_resource *)entry->key;
117
mtx_lock(&rsc->lock);
118
_mesa_set_remove_key(rsc->pending_ctx, ctx);
119
mtx_unlock(&rsc->lock);
121
_mesa_set_destroy(ctx->used_resources_read, NULL);
124
if (ctx->used_resources_write) {
127
* There should be no resources tracked in the context when it's being
128
* destroyed. Be sure there are none to avoid memory leaks on buggy
131
set_foreach(ctx->used_resources_write, entry) {
132
struct etna_resource *rsc = (struct etna_resource *)entry->key;
134
mtx_lock(&rsc->lock);
135
_mesa_set_remove_key(rsc->pending_ctx, ctx);
136
mtx_unlock(&rsc->lock);
138
_mesa_set_destroy(ctx->used_resources_write, NULL);
141
if (ctx->flush_resources)
142
_mesa_set_destroy(ctx->flush_resources, NULL);
144
mtx_unlock(&ctx->lock);
146
if (ctx->dummy_desc_bo)
147
etna_bo_del(ctx->dummy_desc_bo);
150
etna_bo_del(ctx->dummy_rt);
152
util_copy_framebuffer_state(&ctx->framebuffer_s, NULL);
155
util_blitter_destroy(ctx->blitter);
157
if (pctx->stream_uploader)
158
u_upload_destroy(pctx->stream_uploader);
161
etna_cmd_stream_del(ctx->stream);
163
slab_destroy_child(&ctx->transfer_pool);
165
if (ctx->in_fence_fd != -1)
166
close(ctx->in_fence_fd);
168
mtx_destroy(&ctx->lock);
173
/* Update render state where needed based on draw operation */
175
etna_update_state_for_draw(struct etna_context *ctx, const struct pipe_draw_info *info)
177
/* Handle primitive restart:
178
* - If not an indexed draw, we don't care about the state of the primitive restart bit.
179
* - Otherwise, set the bit in INDEX_STREAM_CONTROL in the index buffer state
181
* - If the value of the INDEX_STREAM_CONTROL register changed due to this, or
182
* primitive restart is enabled and the restart index changed, mark the index
183
* buffer state as dirty
186
if (info->index_size) {
187
uint32_t new_control = ctx->index_buffer.FE_INDEX_STREAM_CONTROL;
189
if (info->primitive_restart)
190
new_control |= VIVS_FE_INDEX_STREAM_CONTROL_PRIMITIVE_RESTART;
192
new_control &= ~VIVS_FE_INDEX_STREAM_CONTROL_PRIMITIVE_RESTART;
194
if (ctx->index_buffer.FE_INDEX_STREAM_CONTROL != new_control ||
195
(info->primitive_restart && ctx->index_buffer.FE_PRIMITIVE_RESTART_INDEX != info->restart_index)) {
196
ctx->index_buffer.FE_INDEX_STREAM_CONTROL = new_control;
197
ctx->index_buffer.FE_PRIMITIVE_RESTART_INDEX = info->restart_index;
198
ctx->dirty |= ETNA_DIRTY_INDEX_BUFFER;
204
etna_get_vs(struct etna_context *ctx, struct etna_shader_key key)
206
const struct etna_shader_variant *old = ctx->shader.vs;
208
ctx->shader.vs = etna_shader_variant(ctx->shader.bind_vs, key, &ctx->debug);
213
if (old != ctx->shader.vs)
214
ctx->dirty |= ETNA_DIRTY_SHADER;
220
etna_get_fs(struct etna_context *ctx, struct etna_shader_key key)
222
const struct etna_shader_variant *old = ctx->shader.fs;
224
/* update the key if we need to run nir_lower_sample_tex_compare(..). */
225
if (ctx->screen->specs.halti < 2 &&
226
(ctx->dirty & (ETNA_DIRTY_SAMPLERS | ETNA_DIRTY_SAMPLER_VIEWS))) {
228
for (unsigned int i = 0; i < ctx->num_fragment_sampler_views; i++) {
229
if (ctx->sampler[i]->compare_mode == PIPE_TEX_COMPARE_NONE)
232
key.has_sample_tex_compare = 1;
233
key.num_texture_states = ctx->num_fragment_sampler_views;
235
key.tex_swizzle[i].swizzle_r = ctx->sampler_view[i]->swizzle_r;
236
key.tex_swizzle[i].swizzle_g = ctx->sampler_view[i]->swizzle_g;
237
key.tex_swizzle[i].swizzle_b = ctx->sampler_view[i]->swizzle_b;
238
key.tex_swizzle[i].swizzle_a = ctx->sampler_view[i]->swizzle_a;
240
key.tex_compare_func[i] = ctx->sampler[i]->compare_func;
244
ctx->shader.fs = etna_shader_variant(ctx->shader.bind_fs, key, &ctx->debug);
249
if (old != ctx->shader.fs)
250
ctx->dirty |= ETNA_DIRTY_SHADER;
256
etna_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info,
257
unsigned drawid_offset,
258
const struct pipe_draw_indirect_info *indirect,
259
const struct pipe_draw_start_count_bias *draws,
263
util_draw_multi(pctx, info, drawid_offset, indirect, draws, num_draws);
267
if (!indirect && (!draws[0].count || !info->instance_count))
270
struct etna_context *ctx = etna_context(pctx);
271
struct etna_screen *screen = ctx->screen;
272
struct pipe_framebuffer_state *pfb = &ctx->framebuffer_s;
277
!info->primitive_restart &&
278
!u_trim_pipe_prim(info->mode, (unsigned*)&draws[0].count))
281
if (ctx->vertex_elements == NULL || ctx->vertex_elements->num_elements == 0)
282
return; /* Nothing to do */
284
if (unlikely(ctx->rasterizer->cull_face == PIPE_FACE_FRONT_AND_BACK &&
285
u_decomposed_prim(info->mode) == PIPE_PRIM_TRIANGLES))
288
int prims = u_decomposed_prims_for_vertices(info->mode, draws[0].count);
289
if (unlikely(prims <= 0)) {
290
DBG("Invalid draw primitive mode=%i or no primitives to be drawn", info->mode);
294
draw_mode = translate_draw_mode(info->mode);
295
if (draw_mode == ETNA_NO_MATCH) {
296
BUG("Unsupported draw mode");
300
/* Upload a user index buffer. */
301
unsigned index_offset = 0;
302
struct pipe_resource *indexbuf = NULL;
304
if (info->index_size) {
305
indexbuf = info->has_user_indices ? NULL : info->index.resource;
306
if (info->has_user_indices &&
307
!util_upload_index_buffer(pctx, info, &draws[0], &indexbuf, &index_offset, 4)) {
308
BUG("Index buffer upload failed.");
311
/* Add start to index offset, when rendering indexed */
312
index_offset += draws[0].start * info->index_size;
314
ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.bo = etna_resource(indexbuf)->bo;
315
ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.offset = index_offset;
316
ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.flags = ETNA_RELOC_READ;
317
ctx->index_buffer.FE_INDEX_STREAM_CONTROL = translate_index_size(info->index_size);
319
if (!ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.bo) {
320
BUG("Unsupported or no index buffer");
324
ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.bo = 0;
325
ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.offset = 0;
326
ctx->index_buffer.FE_INDEX_STREAM_BASE_ADDR.flags = 0;
327
ctx->index_buffer.FE_INDEX_STREAM_CONTROL = 0;
329
ctx->dirty |= ETNA_DIRTY_INDEX_BUFFER;
331
struct etna_shader_key key = {
332
.front_ccw = ctx->rasterizer->front_ccw,
333
.sprite_coord_enable = ctx->rasterizer->sprite_coord_enable,
334
.sprite_coord_yinvert = !!ctx->rasterizer->sprite_coord_mode,
338
key.frag_rb_swap = !!translate_pe_format_rb_swap(pfb->cbufs[0]->format);
340
if (!etna_get_vs(ctx, key) || !etna_get_fs(ctx, key)) {
341
BUG("compiled shaders are not okay");
345
/* Update any derived state */
346
if (!etna_state_update(ctx))
349
mtx_lock(&ctx->lock);
352
* Figure out the buffers/features we need:
354
if (ctx->dirty & ETNA_DIRTY_ZSA) {
355
if (etna_depth_enabled(ctx))
356
resource_written(ctx, pfb->zsbuf->texture);
358
if (etna_stencil_enabled(ctx))
359
resource_written(ctx, pfb->zsbuf->texture);
362
if (ctx->dirty & ETNA_DIRTY_FRAMEBUFFER) {
363
for (i = 0; i < pfb->nr_cbufs; i++) {
364
struct pipe_resource *surf;
369
surf = pfb->cbufs[i]->texture;
370
resource_written(ctx, surf);
374
if (ctx->dirty & ETNA_DIRTY_SHADER) {
375
/* Mark constant buffers as being read */
376
u_foreach_bit(i, ctx->constant_buffer[PIPE_SHADER_VERTEX].enabled_mask)
377
resource_read(ctx, ctx->constant_buffer[PIPE_SHADER_VERTEX].cb[i].buffer);
379
u_foreach_bit(i, ctx->constant_buffer[PIPE_SHADER_FRAGMENT].enabled_mask)
380
resource_read(ctx, ctx->constant_buffer[PIPE_SHADER_FRAGMENT].cb[i].buffer);
383
if (ctx->dirty & ETNA_DIRTY_VERTEX_BUFFERS) {
384
/* Mark VBOs as being read */
385
u_foreach_bit(i, ctx->vertex_buffer.enabled_mask) {
386
assert(!ctx->vertex_buffer.vb[i].is_user_buffer);
387
resource_read(ctx, ctx->vertex_buffer.vb[i].buffer.resource);
391
if (ctx->dirty & ETNA_DIRTY_INDEX_BUFFER) {
392
/* Mark index buffer as being read */
393
resource_read(ctx, indexbuf);
396
/* Mark textures as being read */
397
for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
398
if (ctx->sampler_view[i]) {
399
if (ctx->dirty & ETNA_DIRTY_SAMPLER_VIEWS)
400
resource_read(ctx, ctx->sampler_view[i]->texture);
402
/* if texture was modified since the last update,
403
* we need to clear the texture cache and possibly
406
etna_update_sampler_source(ctx->sampler_view[i], i);
410
ctx->stats.prims_generated += u_reduced_prims_for_vertices(info->mode, draws[0].count);
411
ctx->stats.draw_calls++;
413
/* Update state for this draw operation */
414
etna_update_state_for_draw(ctx, info);
416
/* First, sync state, then emit DRAW_PRIMITIVES or DRAW_INDEXED_PRIMITIVES */
417
etna_emit_state(ctx);
419
if (screen->specs.halti >= 2) {
420
/* On HALTI2+ (GC3000 and higher) only use instanced drawing commands, as the blob does */
421
etna_draw_instanced(ctx->stream, info->index_size, draw_mode, info->instance_count,
422
draws[0].count, info->index_size ? draws->index_bias : draws[0].start);
424
if (info->index_size)
425
etna_draw_indexed_primitives(ctx->stream, draw_mode, 0, prims, draws->index_bias);
427
etna_draw_primitives(ctx->stream, draw_mode, draws[0].start, prims);
430
if (DBG_ENABLED(ETNA_DBG_DRAW_STALL)) {
431
/* Stall the FE after every draw operation. This allows better
432
* debug of GPU hang conditions, as the FE will indicate which
433
* draw op has caused the hang. */
434
etna_stall(ctx->stream, SYNC_RECIPIENT_FE, SYNC_RECIPIENT_PE);
436
mtx_unlock(&ctx->lock);
438
if (DBG_ENABLED(ETNA_DBG_FLUSH_ALL))
439
pctx->flush(pctx, NULL, 0);
441
if (ctx->framebuffer_s.cbufs[0])
442
etna_resource(ctx->framebuffer_s.cbufs[0]->texture)->seqno++;
443
if (ctx->framebuffer_s.zsbuf)
444
etna_resource(ctx->framebuffer_s.zsbuf->texture)->seqno++;
445
if (info->index_size && indexbuf != info->index.resource)
446
pipe_resource_reference(&indexbuf, NULL);
450
etna_reset_gpu_state(struct etna_context *ctx)
452
struct etna_cmd_stream *stream = ctx->stream;
453
struct etna_screen *screen = ctx->screen;
454
uint32_t dummy_attribs[VIVS_NFE_GENERIC_ATTRIB__LEN] = { 0 };
456
etna_set_state(stream, VIVS_GL_API_MODE, VIVS_GL_API_MODE_OPENGL);
457
etna_set_state(stream, VIVS_GL_VERTEX_ELEMENT_CONFIG, 0x00000001);
458
etna_set_state(stream, VIVS_PA_W_CLIP_LIMIT, 0x34000001);
459
etna_set_state(stream, VIVS_PA_FLAGS, 0x00000000); /* blob sets ZCONVERT_BYPASS on GC3000+, this messes up z for us */
460
etna_set_state(stream, VIVS_PA_VIEWPORT_UNK00A80, 0x38a01404);
461
etna_set_state(stream, VIVS_PA_VIEWPORT_UNK00A84, fui(8192.0));
462
etna_set_state(stream, VIVS_PA_ZFARCLIPPING, 0x00000000);
463
etna_set_state(stream, VIVS_RA_HDEPTH_CONTROL, 0x00007000);
464
etna_set_state(stream, VIVS_PS_CONTROL_EXT, 0x00000000);
466
/* There is no HALTI0 specific state */
467
if (screen->specs.halti >= 1) { /* Only on HALTI1+ */
468
etna_set_state(stream, VIVS_VS_HALTI1_UNK00884, 0x00000808);
470
if (screen->specs.halti >= 2) { /* Only on HALTI2+ */
471
etna_set_state(stream, VIVS_RA_UNK00E0C, 0x00000000);
473
if (screen->specs.halti >= 3) { /* Only on HALTI3+ */
474
etna_set_state(stream, VIVS_PS_HALTI3_UNK0103C, 0x76543210);
476
if (screen->specs.halti >= 4) { /* Only on HALTI4+ */
477
etna_set_state(stream, VIVS_PS_MSAA_CONFIG, 0x6fffffff & 0xf70fffff & 0xfff6ffff &
478
0xffff6fff & 0xfffff6ff & 0xffffff7f);
479
etna_set_state(stream, VIVS_PE_HALTI4_UNK014C0, 0x00000000);
481
if (screen->specs.halti >= 5) { /* Only on HALTI5+ */
482
etna_set_state(stream, VIVS_NTE_DESCRIPTOR_UNK14C40, 0x00000001);
483
etna_set_state(stream, VIVS_FE_HALTI5_UNK007D8, 0x00000002);
484
etna_set_state(stream, VIVS_PS_SAMPLER_BASE, 0x00000000);
485
etna_set_state(stream, VIVS_VS_SAMPLER_BASE, 0x00000020);
486
etna_set_state(stream, VIVS_SH_CONFIG, VIVS_SH_CONFIG_RTNE_ROUNDING);
487
} else { /* Only on pre-HALTI5 */
488
etna_set_state(stream, VIVS_GL_UNK03838, 0x00000000);
489
etna_set_state(stream, VIVS_GL_UNK03854, 0x00000000);
492
if (!screen->specs.use_blt) {
493
/* Enable SINGLE_BUFFER for resolve, if supported */
494
etna_set_state(stream, VIVS_RS_SINGLE_BUFFER, COND(screen->specs.single_buffer, VIVS_RS_SINGLE_BUFFER_ENABLE));
497
if (screen->specs.halti >= 5) {
498
/* TXDESC cache flush - do this once at the beginning, as texture
499
* descriptors are only written by the CPU once, then patched by the kernel
500
* before command stream submission. It does not need flushing if the
501
* referenced image data changes.
503
etna_set_state(stream, VIVS_NTE_DESCRIPTOR_FLUSH, 0);
504
etna_set_state(stream, VIVS_GL_FLUSH_CACHE,
505
VIVS_GL_FLUSH_CACHE_DESCRIPTOR_UNK12 |
506
VIVS_GL_FLUSH_CACHE_DESCRIPTOR_UNK13);
508
/* Icache invalidate (should do this on shader change?) */
509
etna_set_state(stream, VIVS_VS_ICACHE_INVALIDATE,
510
VIVS_VS_ICACHE_INVALIDATE_UNK0 | VIVS_VS_ICACHE_INVALIDATE_UNK1 |
511
VIVS_VS_ICACHE_INVALIDATE_UNK2 | VIVS_VS_ICACHE_INVALIDATE_UNK3 |
512
VIVS_VS_ICACHE_INVALIDATE_UNK4);
515
/* It seems that some GPUs (at least some GC400 have shown this behavior)
516
* come out of reset with random vertex attributes enabled and also don't
517
* disable them on the write to the first config register as normal. Enabling
518
* all attributes seems to provide the GPU with the required edge to actually
519
* disable the unused attributes on the next draw.
521
if (screen->specs.halti >= 5) {
522
etna_set_state_multi(stream, VIVS_NFE_GENERIC_ATTRIB_CONFIG0(0),
523
VIVS_NFE_GENERIC_ATTRIB__LEN, dummy_attribs);
525
etna_set_state_multi(stream, VIVS_FE_VERTEX_ELEMENT_CONFIG(0),
526
screen->specs.halti >= 0 ? 16 : 12, dummy_attribs);
530
ctx->dirty_sampler_views = ~0L;
534
etna_flush(struct pipe_context *pctx, struct pipe_fence_handle **fence,
535
enum pipe_flush_flags flags)
537
struct etna_context *ctx = etna_context(pctx);
538
int out_fence_fd = -1;
540
mtx_lock(&ctx->lock);
542
list_for_each_entry(struct etna_acc_query, aq, &ctx->active_acc_queries, node)
543
etna_acc_query_suspend(aq, ctx);
545
/* flush all resources that need an implicit flush */
546
set_foreach(ctx->flush_resources, entry) {
547
struct pipe_resource *prsc = (struct pipe_resource *)entry->key;
549
pctx->flush_resource(pctx, prsc);
551
_mesa_set_clear(ctx->flush_resources, NULL);
553
etna_cmd_stream_flush(ctx->stream, ctx->in_fence_fd,
554
(flags & PIPE_FLUSH_FENCE_FD) ? &out_fence_fd : NULL,
557
list_for_each_entry(struct etna_acc_query, aq, &ctx->active_acc_queries, node)
558
etna_acc_query_resume(aq, ctx);
561
*fence = etna_fence_create(pctx, out_fence_fd);
564
* Go through all _resources_ pending in this _context_ and mark them as
565
* not pending in this _context_ anymore, since they were just flushed.
567
set_foreach(ctx->used_resources_read, entry) {
568
struct etna_resource *rsc = (struct etna_resource *)entry->key;
569
struct pipe_resource *referenced = &rsc->base;
571
mtx_lock(&rsc->lock);
573
_mesa_set_remove_key(rsc->pending_ctx, ctx);
575
/* if resource has no pending ctx's reset its status */
576
if (_mesa_set_next_entry(rsc->pending_ctx, NULL) == NULL)
577
rsc->status &= ~ETNA_PENDING_READ;
579
mtx_unlock(&rsc->lock);
581
pipe_resource_reference(&referenced, NULL);
583
_mesa_set_clear(ctx->used_resources_read, NULL);
585
set_foreach(ctx->used_resources_write, entry) {
586
struct etna_resource *rsc = (struct etna_resource *)entry->key;
587
struct pipe_resource *referenced = &rsc->base;
589
mtx_lock(&rsc->lock);
590
_mesa_set_remove_key(rsc->pending_ctx, ctx);
592
/* if resource has no pending ctx's reset its status */
593
if (_mesa_set_next_entry(rsc->pending_ctx, NULL) == NULL)
594
rsc->status &= ~ETNA_PENDING_WRITE;
595
mtx_unlock(&rsc->lock);
597
pipe_resource_reference(&referenced, NULL);
599
_mesa_set_clear(ctx->used_resources_write, NULL);
601
etna_reset_gpu_state(ctx);
602
mtx_unlock(&ctx->lock);
606
etna_context_force_flush(struct etna_cmd_stream *stream, void *priv)
608
struct pipe_context *pctx = priv;
610
pctx->flush(pctx, NULL, 0);
615
etna_set_debug_callback(struct pipe_context *pctx,
616
const struct util_debug_callback *cb)
618
struct etna_context *ctx = etna_context(pctx);
623
memset(&ctx->debug, 0, sizeof(ctx->debug));
626
struct pipe_context *
627
etna_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
629
struct etna_context *ctx = CALLOC_STRUCT(etna_context);
630
struct etna_screen *screen;
631
struct pipe_context *pctx;
638
pctx->screen = pscreen;
639
pctx->stream_uploader = u_upload_create_default(pctx);
640
if (!pctx->stream_uploader)
642
pctx->const_uploader = pctx->stream_uploader;
644
screen = etna_screen(pscreen);
645
ctx->stream = etna_cmd_stream_new(screen->pipe, 0x2000,
646
&etna_context_force_flush, pctx);
647
if (ctx->stream == NULL)
650
ctx->used_resources_read = _mesa_set_create(NULL, _mesa_hash_pointer,
651
_mesa_key_pointer_equal);
652
if (!ctx->used_resources_read)
655
ctx->used_resources_write = _mesa_set_create(NULL, _mesa_hash_pointer,
656
_mesa_key_pointer_equal);
657
if (!ctx->used_resources_write)
660
ctx->flush_resources = _mesa_set_create(NULL, _mesa_hash_pointer,
661
_mesa_key_pointer_equal);
662
if (!ctx->flush_resources)
665
mtx_init(&ctx->lock, mtx_recursive);
667
/* context ctxate setup */
668
ctx->screen = screen;
669
/* need some sane default in case gallium frontends don't set some state: */
670
ctx->sample_mask = 0xffff;
672
/* Set sensible defaults for state */
673
etna_reset_gpu_state(ctx);
675
ctx->in_fence_fd = -1;
677
pctx->destroy = etna_context_destroy;
678
pctx->draw_vbo = etna_draw_vbo;
679
pctx->flush = etna_flush;
680
pctx->set_debug_callback = etna_set_debug_callback;
681
pctx->create_fence_fd = etna_create_fence_fd;
682
pctx->fence_server_sync = etna_fence_server_sync;
683
pctx->emit_string_marker = etna_emit_string_marker;
684
pctx->set_frontend_noop = etna_set_frontend_noop;
686
/* creation of compile states */
687
pctx->create_blend_state = etna_blend_state_create;
688
pctx->create_rasterizer_state = etna_rasterizer_state_create;
689
pctx->create_depth_stencil_alpha_state = etna_zsa_state_create;
691
etna_clear_blit_init(pctx);
692
etna_query_context_init(pctx);
693
etna_state_init(pctx);
694
etna_surface_init(pctx);
695
etna_shader_init(pctx);
696
etna_texture_init(pctx);
697
etna_transfer_init(pctx);
699
ctx->blitter = util_blitter_create(pctx);
703
slab_create_child(&ctx->transfer_pool, &screen->transfer_pool);
704
list_inithead(&ctx->active_acc_queries);
706
/* create dummy RT buffer, used when rendering with no color buffer */
707
ctx->dummy_rt = etna_bo_new(ctx->screen->dev, 64 * 64 * 4,
708
DRM_ETNA_GEM_CACHE_WC);
712
ctx->dummy_rt_reloc.bo = ctx->dummy_rt;
713
ctx->dummy_rt_reloc.offset = 0;
714
ctx->dummy_rt_reloc.flags = ETNA_RELOC_READ | ETNA_RELOC_WRITE;
716
if (screen->specs.halti >= 5) {
717
/* Create an empty dummy texture descriptor */
718
ctx->dummy_desc_bo = etna_bo_new(ctx->screen->dev, 0x100, DRM_ETNA_GEM_CACHE_WC);
719
if (!ctx->dummy_desc_bo)
721
uint32_t *buf = etna_bo_map(ctx->dummy_desc_bo);
722
etna_bo_cpu_prep(ctx->dummy_desc_bo, DRM_ETNA_PREP_WRITE);
723
memset(buf, 0, 0x100);
724
etna_bo_cpu_fini(ctx->dummy_desc_bo);
725
ctx->DUMMY_DESC_ADDR.bo = ctx->dummy_desc_bo;
726
ctx->DUMMY_DESC_ADDR.offset = 0;
727
ctx->DUMMY_DESC_ADDR.flags = ETNA_RELOC_READ;