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"
37 /* there are two cases where we currently need to wait for render complete:
38 * 1) pctx->flush() .. since at the moment we have no way for DDX to sync
39 * the presentation blit with the 3d core
40 * 2) wrap-around for ringbuffer.. possibly we can do something more
41 * Intelligent here. Right now we need to ensure there is enough room
42 * at the end of the drawcmds in the cmdstream buffer for all the per-
43 * tile cmds. We do this the lamest way possible, by making the ringbuffer
44 * big, and flushing and resetting back to the beginning if we get too
48 fd_context_wait(struct pipe_context
*pctx
)
50 struct fd_context
*ctx
= fd_context(pctx
);
51 uint32_t ts
= fd_ringbuffer_timestamp(ctx
->ring
);
55 fd_pipe_wait(ctx
->screen
->pipe
, ts
);
56 fd_ringbuffer_reset(ctx
->ring
);
57 fd_ringmarker_mark(ctx
->draw_start
);
60 /* emit accumulated render cmds, needed for example if render target has
61 * changed, or for flush()
64 fd_context_render(struct pipe_context
*pctx
)
66 struct fd_context
*ctx
= fd_context(pctx
);
67 struct pipe_framebuffer_state
*pfb
= &ctx
->framebuffer
;
69 DBG("needs_flush: %d", ctx
->needs_flush
);
71 if (!ctx
->needs_flush
)
74 fd_gmem_render_tiles(pctx
);
76 DBG("%p/%p/%p", ctx
->ring
->start
, ctx
->ring
->cur
, ctx
->ring
->end
);
78 /* if size in dwords is more than half the buffer size, then wait and
81 if ((ctx
->ring
->cur
- ctx
->ring
->start
) > ctx
->ring
->size
/8)
82 fd_context_wait(pctx
);
84 ctx
->needs_flush
= false;
85 ctx
->cleared
= ctx
->restore
= ctx
->resolve
= 0;
89 fd_resource(pfb
->cbufs
[0]->texture
)->dirty
= false;
91 fd_resource(pfb
->zsbuf
->texture
)->dirty
= false;
95 fd_context_flush(struct pipe_context
*pctx
, struct pipe_fence_handle
**fence
,
98 DBG("fence=%p", fence
);
102 fd_fence_ref(ctx
->screen
->fence
.current
,
103 (struct fd_fence
**)fence
);
107 fd_context_render(pctx
);
111 fd_context_destroy(struct pipe_context
*pctx
)
113 struct fd_context
*ctx
= fd_context(pctx
);
118 util_blitter_destroy(ctx
->blitter
);
120 fd_ringmarker_del(ctx
->draw_start
);
121 fd_ringmarker_del(ctx
->draw_end
);
122 fd_ringbuffer_del(ctx
->ring
);
127 struct pipe_context
*
128 fd_context_init(struct fd_context
*ctx
,
129 struct pipe_screen
*pscreen
, void *priv
)
131 struct fd_screen
*screen
= fd_screen(pscreen
);
132 struct pipe_context
*pctx
;
134 ctx
->screen
= screen
;
136 /* need some sane default in case state tracker doesn't
139 ctx
->sample_mask
= 0xffff;
142 pctx
->screen
= pscreen
;
144 pctx
->flush
= fd_context_flush
;
146 ctx
->ring
= fd_ringbuffer_new(screen
->pipe
, 0x100000);
150 ctx
->draw_start
= fd_ringmarker_new(ctx
->ring
);
151 ctx
->draw_end
= fd_ringmarker_new(ctx
->ring
);
153 util_slab_create(&ctx
->transfer_pool
, sizeof(struct pipe_transfer
),
154 16, UTIL_SLAB_SINGLETHREADED
);
157 fd_resource_context_init(pctx
);
158 fd_texture_init(pctx
);
161 ctx
->blitter
= util_blitter_create(pctx
);