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_resource.h"
32 #include "freedreno_texture.h"
33 #include "freedreno_state.h"
34 #include "freedreno_gmem.h"
35 #include "freedreno_util.h"
38 fd_context_next_rb(struct pipe_context
*pctx
)
40 struct fd_context
*ctx
= fd_context(pctx
);
41 struct fd_ringbuffer
*ring
;
44 fd_ringmarker_del(ctx
->draw_start
);
45 fd_ringmarker_del(ctx
->draw_end
);
47 /* grab next ringbuffer: */
48 ring
= ctx
->rings
[(ctx
->rings_idx
++) % ARRAY_SIZE(ctx
->rings
)];
50 /* wait for new rb to be idle: */
51 ts
= fd_ringbuffer_timestamp(ring
);
54 fd_pipe_wait(ctx
->screen
->pipe
, ts
);
57 fd_ringbuffer_reset(ring
);
59 ctx
->draw_start
= fd_ringmarker_new(ring
);
60 ctx
->draw_end
= fd_ringmarker_new(ring
);
65 /* emit accumulated render cmds, needed for example if render target has
66 * changed, or for flush()
69 fd_context_render(struct pipe_context
*pctx
)
71 struct fd_context
*ctx
= fd_context(pctx
);
72 struct pipe_framebuffer_state
*pfb
= &ctx
->framebuffer
;
74 DBG("needs_flush: %d", ctx
->needs_flush
);
76 if (!ctx
->needs_flush
)
79 fd_gmem_render_tiles(pctx
);
81 DBG("%p/%p/%p", ctx
->ring
->start
, ctx
->ring
->cur
, ctx
->ring
->end
);
83 /* if size in dwords is more than half the buffer size, then wait and
86 if ((ctx
->ring
->cur
- ctx
->ring
->start
) > ctx
->ring
->size
/8)
87 fd_context_next_rb(pctx
);
89 ctx
->needs_flush
= false;
90 ctx
->cleared
= ctx
->restore
= ctx
->resolve
= 0;
95 fd_resource(pfb
->cbufs
[0]->texture
)->dirty
= false;
97 fd_resource(pfb
->zsbuf
->texture
)->dirty
= false;
101 fd_context_flush(struct pipe_context
*pctx
, struct pipe_fence_handle
**fence
,
104 DBG("fence=%p", fence
);
108 fd_fence_ref(ctx
->screen
->fence
.current
,
109 (struct fd_fence
**)fence
);
113 fd_context_render(pctx
);
117 fd_context_destroy(struct pipe_context
*pctx
)
119 struct fd_context
*ctx
= fd_context(pctx
);
125 util_blitter_destroy(ctx
->blitter
);
127 if (ctx
->primconvert
)
128 util_primconvert_destroy(ctx
->primconvert
);
130 fd_ringmarker_del(ctx
->draw_start
);
131 fd_ringmarker_del(ctx
->draw_end
);
132 fd_ringbuffer_del(ctx
->ring
);
134 for (i
= 0; i
< ARRAY_SIZE(ctx
->pipe
); i
++) {
135 struct fd_vsc_pipe
*pipe
= &ctx
->pipe
[i
];
144 struct pipe_context
*
145 fd_context_init(struct fd_context
*ctx
, struct pipe_screen
*pscreen
,
146 const uint8_t *primtypes
, void *priv
)
148 struct fd_screen
*screen
= fd_screen(pscreen
);
149 struct pipe_context
*pctx
;
152 ctx
->screen
= screen
;
154 ctx
->primtypes
= primtypes
;
155 ctx
->primtype_mask
= 0;
156 for (i
= 0; i
< PIPE_PRIM_MAX
; i
++)
158 ctx
->primtype_mask
|= (1 << i
);
160 /* need some sane default in case state tracker doesn't
163 ctx
->sample_mask
= 0xffff;
166 pctx
->screen
= pscreen
;
168 pctx
->flush
= fd_context_flush
;
170 for (i
= 0; i
< ARRAY_SIZE(ctx
->rings
); i
++) {
171 ctx
->rings
[i
] = fd_ringbuffer_new(screen
->pipe
, 0x400000);
176 fd_context_next_rb(pctx
);
178 util_slab_create(&ctx
->transfer_pool
, sizeof(struct pipe_transfer
),
179 16, UTIL_SLAB_SINGLETHREADED
);
182 fd_resource_context_init(pctx
);
183 fd_texture_init(pctx
);
186 ctx
->blitter
= util_blitter_create(pctx
);
190 ctx
->primconvert
= util_primconvert_create(pctx
, ctx
->primtype_mask
);
191 if (!ctx
->primconvert
)