1 /* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
4 * Copyright (C) 2012 Rob Clark <robclark@freedesktop.org>
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 (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * Rob Clark <robclark@freedesktop.org>
29 #include "freedreno_context.h"
30 #include "freedreno_draw.h"
31 #include "freedreno_fence.h"
32 #include "freedreno_program.h"
33 #include "freedreno_resource.h"
34 #include "freedreno_texture.h"
35 #include "freedreno_state.h"
36 #include "freedreno_gmem.h"
37 #include "freedreno_query.h"
38 #include "freedreno_query_hw.h"
39 #include "freedreno_util.h"
42 fd_context_flush(struct pipe_context
*pctx
, struct pipe_fence_handle
**fence
,
45 struct fd_context
*ctx
= fd_context(pctx
);
48 if (!ctx
->screen
->reorder
) {
49 struct fd_batch
*batch
= NULL
;
50 fd_batch_reference(&batch
, ctx
->batch
);
51 fd_batch_flush(batch
, true);
52 timestamp
= fd_ringbuffer_timestamp(batch
->gmem
);
53 fd_batch_reference(&batch
, NULL
);
55 timestamp
= fd_bc_flush(&ctx
->screen
->batch_cache
, ctx
);
59 fd_screen_fence_ref(pctx
->screen
, fence
, NULL
);
60 *fence
= fd_fence_create(pctx
, timestamp
);
65 * emit marker string as payload of a no-op packet, which can be
69 fd_emit_string_marker(struct pipe_context
*pctx
, const char *string
, int len
)
71 struct fd_context
*ctx
= fd_context(pctx
);
72 struct fd_ringbuffer
*ring
;
73 const uint32_t *buf
= (const void *)string
;
78 ring
= ctx
->batch
->draw
;
80 /* max packet size is 0x3fff dwords: */
81 len
= MIN2(len
, 0x3fff * 4);
83 OUT_PKT3(ring
, CP_NOP
, align(len
, 4) / 4);
90 /* copy remainder bytes without reading past end of input string: */
99 fd_context_destroy(struct pipe_context
*pctx
)
101 struct fd_context
*ctx
= fd_context(pctx
);
106 if (ctx
->screen
->reorder
)
107 util_queue_destroy(&ctx
->flush_queue
);
109 fd_batch_reference(&ctx
->batch
, NULL
); /* unref current batch */
110 fd_bc_invalidate_context(ctx
);
113 fd_hw_query_fini(pctx
);
116 util_blitter_destroy(ctx
->blitter
);
118 if (ctx
->primconvert
)
119 util_primconvert_destroy(ctx
->primconvert
);
121 util_slab_destroy(&ctx
->transfer_pool
);
123 for (i
= 0; i
< ARRAY_SIZE(ctx
->pipe
); i
++) {
124 struct fd_vsc_pipe
*pipe
= &ctx
->pipe
[i
];
130 fd_device_del(ctx
->dev
);
132 if (fd_mesa_debug
& (FD_DBG_BSTAT
| FD_DBG_MSGS
)) {
133 printf("batch_total=%u, batch_sysmem=%u, batch_gmem=%u, batch_restore=%u\n",
134 (uint32_t)ctx
->stats
.batch_total
, (uint32_t)ctx
->stats
.batch_sysmem
,
135 (uint32_t)ctx
->stats
.batch_gmem
, (uint32_t)ctx
->stats
.batch_restore
);
142 fd_set_debug_callback(struct pipe_context
*pctx
,
143 const struct pipe_debug_callback
*cb
)
145 struct fd_context
*ctx
= fd_context(pctx
);
150 memset(&ctx
->debug
, 0, sizeof(ctx
->debug
));
153 struct pipe_context
*
154 fd_context_init(struct fd_context
*ctx
, struct pipe_screen
*pscreen
,
155 const uint8_t *primtypes
, void *priv
)
157 struct fd_screen
*screen
= fd_screen(pscreen
);
158 struct pipe_context
*pctx
;
161 ctx
->screen
= screen
;
163 ctx
->primtypes
= primtypes
;
164 ctx
->primtype_mask
= 0;
165 for (i
= 0; i
< PIPE_PRIM_MAX
; i
++)
167 ctx
->primtype_mask
|= (1 << i
);
169 /* need some sane default in case state tracker doesn't
172 ctx
->sample_mask
= 0xffff;
175 pctx
->screen
= pscreen
;
177 pctx
->flush
= fd_context_flush
;
178 pctx
->emit_string_marker
= fd_emit_string_marker
;
179 pctx
->set_debug_callback
= fd_set_debug_callback
;
181 /* TODO what about compute? Ideally it creates it's own independent
182 * batches per compute job (since it isn't using tiling, so no point
183 * in getting involved with the re-ordering madness)..
185 if (!screen
->reorder
) {
186 ctx
->batch
= fd_bc_alloc_batch(&screen
->batch_cache
, ctx
);
189 util_slab_create(&ctx
->transfer_pool
, sizeof(struct fd_transfer
),
190 16, UTIL_SLAB_SINGLETHREADED
);
193 fd_resource_context_init(pctx
);
194 fd_query_context_init(pctx
);
195 fd_texture_init(pctx
);
197 fd_hw_query_init(pctx
);
199 ctx
->blitter
= util_blitter_create(pctx
);
203 ctx
->primconvert
= util_primconvert_create(pctx
, ctx
->primtype_mask
);
204 if (!ctx
->primconvert
)