summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/nvc0/nvc0_context.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/drivers/nvc0/nvc0_context.c')
-rw-r--r--src/gallium/drivers/nvc0/nvc0_context.c147
1 files changed, 66 insertions, 81 deletions
diff --git a/src/gallium/drivers/nvc0/nvc0_context.c b/src/gallium/drivers/nvc0/nvc0_context.c
index 1b3a06dfa33..c15d0256c60 100644
--- a/src/gallium/drivers/nvc0/nvc0_context.c
+++ b/src/gallium/drivers/nvc0/nvc0_context.c
@@ -33,26 +33,22 @@ static void
nvc0_flush(struct pipe_context *pipe,
struct pipe_fence_handle **fence)
{
- struct nouveau_screen *screen = &nvc0_context(pipe)->screen->base;
+ struct nvc0_context *nvc0 = nvc0_context(pipe);
+ struct nouveau_screen *screen = &nvc0->screen->base;
if (fence)
nouveau_fence_ref(screen->fence.current, (struct nouveau_fence **)fence);
- /* Try to emit before firing to avoid having to flush again right after
- * in case we have to wait on this fence.
- */
- nouveau_fence_emit(screen->fence.current);
-
- FIRE_RING(screen->channel);
+ PUSH_KICK(nvc0->base.pushbuf); /* fencing handled in kick_notify */
}
static void
nvc0_texture_barrier(struct pipe_context *pipe)
{
- struct nouveau_channel *chan = nvc0_context(pipe)->screen->base.channel;
+ struct nouveau_pushbuf *push = nvc0_context(pipe)->base.pushbuf;
- IMMED_RING(chan, RING_3D(SERIALIZE), 0);
- IMMED_RING(chan, RING_3D(TEX_CACHE_CTL), 0);
+ IMMED_NVC0(push, NVC0_3D(SERIALIZE), 0);
+ IMMED_NVC0(push, NVC0_3D(TEX_CACHE_CTL), 0);
}
static void
@@ -60,8 +56,8 @@ nvc0_context_unreference_resources(struct nvc0_context *nvc0)
{
unsigned s, i;
- for (i = 0; i < NVC0_BUFCTX_COUNT; ++i)
- nvc0_bufctx_reset(nvc0, i);
+ nouveau_bufctx_del(&nvc0->bufctx_3d);
+ nouveau_bufctx_del(&nvc0->bufctx);
for (i = 0; i < nvc0->num_vtxbufs; ++i)
pipe_resource_reference(&nvc0->vtxbuf[i].buffer, NULL);
@@ -85,26 +81,31 @@ nvc0_destroy(struct pipe_context *pipe)
{
struct nvc0_context *nvc0 = nvc0_context(pipe);
+ if (nvc0->screen->cur_ctx == nvc0) {
+ nvc0->base.pushbuf->kick_notify = NULL;
+ nvc0->screen->cur_ctx = NULL;
+ nouveau_pushbuf_bufctx(nvc0->base.pushbuf, NULL);
+ }
+ nouveau_pushbuf_kick(nvc0->base.pushbuf, nvc0->base.pushbuf->channel);
+
nvc0_context_unreference_resources(nvc0);
draw_destroy(nvc0->draw);
- if (nvc0->screen->cur_ctx == nvc0)
- nvc0->screen->cur_ctx = NULL;
-
FREE(nvc0);
}
void
-nvc0_default_flush_notify(struct nouveau_channel *chan)
+nvc0_default_kick_notify(struct nouveau_pushbuf *push)
{
- struct nvc0_screen *screen = chan->user_private;
-
- if (!screen)
- return;
+ struct nvc0_screen *screen = push->user_priv;
- nouveau_fence_update(&screen->base, TRUE);
- nouveau_fence_next(&screen->base);
+ if (screen) {
+ nouveau_fence_next(&screen->base);
+ nouveau_fence_update(&screen->base, TRUE);
+ if (screen->cur_ctx)
+ screen->cur_ctx->state.flushed = TRUE;
+ }
}
struct pipe_context *
@@ -113,12 +114,23 @@ nvc0_create(struct pipe_screen *pscreen, void *priv)
struct nvc0_screen *screen = nvc0_screen(pscreen);
struct nvc0_context *nvc0;
struct pipe_context *pipe;
+ int ret;
+ uint32_t flags;
nvc0 = CALLOC_STRUCT(nvc0_context);
if (!nvc0)
return NULL;
pipe = &nvc0->base.pipe;
+ nvc0->base.pushbuf = screen->base.pushbuf;
+
+ ret = nouveau_bufctx_new(screen->base.client, NVC0_BIND_COUNT,
+ &nvc0->bufctx_3d);
+ if (!ret)
+ nouveau_bufctx_new(screen->base.client, 2, &nvc0->bufctx);
+ if (ret)
+ goto out_err;
+
nvc0->screen = screen;
nvc0->base.screen = &screen->base;
nvc0->base.copy_data = nvc0_m2mf_copy_linear;
@@ -136,9 +148,11 @@ nvc0_create(struct pipe_screen *pscreen, void *priv)
pipe->flush = nvc0_flush;
pipe->texture_barrier = nvc0_texture_barrier;
- if (!screen->cur_ctx)
+ if (!screen->cur_ctx) {
screen->cur_ctx = nvc0;
- screen->base.channel->flush_notify = nvc0_default_flush_notify;
+ nouveau_pushbuf_bufctx(screen->base.pushbuf, nvc0->bufctx);
+ }
+ screen->base.pushbuf->kick_notify = nvc0_default_kick_notify;
nvc0_init_query_functions(nvc0);
nvc0_init_surface_functions(nvc0);
@@ -154,72 +168,43 @@ nvc0_create(struct pipe_screen *pscreen, void *priv)
/* shader builtin library is per-screen, but we need a context for m2mf */
nvc0_program_library_upload(nvc0);
- return pipe;
-}
+ /* add permanently resident buffers to bufctxts */
-struct resident {
- struct nv04_resource *res;
- uint32_t flags;
-};
+ flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_RD;
-void
-nvc0_bufctx_add_resident(struct nvc0_context *nvc0, int ctx,
- struct nv04_resource *resource, uint32_t flags)
-{
- struct resident rsd = { resource, flags };
+ BCTX_REFN_bo(nvc0->bufctx_3d, SCREEN, flags, screen->text);
+ BCTX_REFN_bo(nvc0->bufctx_3d, SCREEN, flags, screen->uniforms);
+ BCTX_REFN_bo(nvc0->bufctx_3d, SCREEN, flags, screen->txc);
- if (!resource->bo)
- return;
- nvc0->residents_size += sizeof(struct resident);
+ flags = NOUVEAU_BO_GART | NOUVEAU_BO_WR;
- /* We don't need to reference the resource here, it will be referenced
- * in the context/state, and bufctx will be reset when state changes.
- */
- util_dynarray_append(&nvc0->residents[ctx], struct resident, rsd);
-}
+ BCTX_REFN_bo(nvc0->bufctx_3d, SCREEN, flags, screen->fence.bo);
+ BCTX_REFN_bo(nvc0->bufctx, FENCE, flags, screen->fence.bo);
-void
-nvc0_bufctx_del_resident(struct nvc0_context *nvc0, int ctx,
- struct nv04_resource *resource)
-{
- struct resident *rsd, *top;
- unsigned i;
-
- for (i = 0; i < nvc0->residents[ctx].size / sizeof(struct resident); ++i) {
- rsd = util_dynarray_element(&nvc0->residents[ctx], struct resident, i);
-
- if (rsd->res == resource) {
- top = util_dynarray_pop_ptr(&nvc0->residents[ctx], struct resident);
- if (rsd != top)
- *rsd = *top;
- nvc0->residents_size -= sizeof(struct resident);
- break;
- }
+ return pipe;
+
+out_err:
+ if (nvc0) {
+ if (nvc0->bufctx_3d)
+ nouveau_bufctx_del(&nvc0->bufctx_3d);
+ if (nvc0->bufctx)
+ nouveau_bufctx_del(&nvc0->bufctx);
+ FREE(nvc0);
}
+ return NULL;
}
void
-nvc0_bufctx_emit_relocs(struct nvc0_context *nvc0)
+nvc0_bufctx_fence(struct nvc0_context *nvc0, struct nouveau_bufctx *bufctx,
+ boolean on_flush)
{
- struct resident *rsd;
- struct util_dynarray *array;
- unsigned ctx, i, n;
-
- n = nvc0->residents_size / sizeof(struct resident);
- n += NVC0_SCREEN_RESIDENT_BO_COUNT;
-
- MARK_RING(nvc0->screen->base.channel, 0, n);
-
- for (ctx = 0; ctx < NVC0_BUFCTX_COUNT; ++ctx) {
- array = &nvc0->residents[ctx];
-
- n = array->size / sizeof(struct resident);
- for (i = 0; i < n; ++i) {
- rsd = util_dynarray_element(array, struct resident, i);
-
- nvc0_resource_validate(rsd->res, rsd->flags);
- }
+ struct nouveau_list *list = on_flush ? &bufctx->current : &bufctx->pending;
+ struct nouveau_list *it;
+
+ for (it = list->next; it != list; it = it->next) {
+ struct nouveau_bufref *ref = (struct nouveau_bufref *)it;
+ struct nv04_resource *res = ref->priv;
+ if (res)
+ nvc0_resource_validate(res, (unsigned)ref->priv_data);
}
-
- nvc0_screen_make_buffers_resident(nvc0->screen);
}