2 * Copyright (C) 2009 Francisco Jerez.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include "nouveau_driver.h"
28 #include "nouveau_context.h"
31 nouveau_bo_marker_emit(struct gl_context *ctx, struct nouveau_bo_marker *m,
34 struct nouveau_channel *chan = context_chan(ctx);
37 if (m->gr->bound == NOUVEAU_GROBJ_UNBOUND)
38 nouveau_grobj_autobind(m->gr);
40 if (MARK_RING(chan, 2, 2))
43 packet = (m->gr->subc << 13) | (1 << 18) | m->mthd;
46 if (nouveau_pushbuf_emit_reloc(chan, chan->cur++, m->bo,
48 (m->flags & (NOUVEAU_BO_VRAM |
54 *(chan->cur++) = packet;
57 if (nouveau_pushbuf_emit_reloc(chan, chan->cur++, m->bo, m->data,
58 m->data2, flags | m->flags,
70 nouveau_bo_context_grow(struct nouveau_bo_context *bctx)
72 struct nouveau_bo_marker *marker = bctx->marker;
73 int allocated = bctx->allocated + 1;
75 marker = realloc(marker, allocated * sizeof(struct nouveau_bo_marker));
79 bctx->marker = marker;
80 bctx->allocated = allocated;
86 nouveau_bo_mark(struct nouveau_bo_context *bctx, struct nouveau_grobj *gr,
87 uint32_t mthd, struct nouveau_bo *bo,
88 uint32_t data, uint32_t data2, uint32_t vor, uint32_t tor,
91 struct nouveau_bo_state *s = &to_nouveau_context(bctx->ctx)->bo;
92 struct nouveau_bo_marker *m;
94 if (bctx->count == bctx->allocated) {
95 if (!nouveau_bo_context_grow(bctx))
99 m = &bctx->marker[bctx->count];
101 *m = (struct nouveau_bo_marker) {
110 nouveau_bo_ref(bo, &m->bo);
115 if (!nouveau_bo_marker_emit(bctx->ctx, m, 0))
121 nouveau_bo_context_reset(bctx);
126 nouveau_bo_context_reset(struct nouveau_bo_context *bctx)
128 struct nouveau_bo_state *s = &to_nouveau_context(bctx->ctx)->bo;
129 int i, n = bctx->count;
134 for (i = 0; i < n; i++)
135 nouveau_bo_ref(NULL, &bctx->marker[i].bo);
139 nouveau_bo_state_emit(struct gl_context *ctx)
141 struct nouveau_bo_state *s = &to_nouveau_context(ctx)->bo;
144 for (i = 0; i < NUM_NOUVEAU_BO_CONTEXT; i++) {
145 struct nouveau_bo_context *bctx = &s->context[i];
147 for (j = 0; j < bctx->count; j++) {
148 if (!nouveau_bo_marker_emit(ctx, &bctx->marker[j],
158 nouveau_bo_state_init(struct gl_context *ctx)
160 struct nouveau_bo_state *s = &to_nouveau_context(ctx)->bo;
163 for (i = 0; i < NUM_NOUVEAU_BO_CONTEXT; i++)
164 s->context[i].ctx = ctx;
168 nouveau_bo_state_destroy(struct gl_context *ctx)
170 struct nouveau_bo_state *s = &to_nouveau_context(ctx)->bo;
173 for (i = 0; i < NUM_NOUVEAU_BO_CONTEXT; i++) {
174 struct nouveau_bo_context *bctx = &s->context[i];
176 for (j = 0; j < bctx->count; j++)
177 nouveau_bo_ref(NULL, &bctx->marker[j].bo);