+/*
+ * Copyright 2012 Red Hat Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Authors: Ben Skeggs
+ *
+ */
+
#include "draw/draw_context.h"
-#include "pipe/p_defines.h"
+#include "nouveau/nv_object.xml.h"
+#include "nv30-40_3d.xml.h"
+
+#include "nouveau/nouveau_fence.h"
#include "nv30_context.h"
-#include "nvfx_screen.h"
+#include "nv30_transfer.h"
+#include "nv30_state.h"
+
+static void
+nv30_context_kick_notify(struct nouveau_pushbuf *push)
+{
+ struct nouveau_screen *screen;
+ struct nv30_context *nv30;
+
+ if (!push->user_priv)
+ return;
+ nv30 = container_of(push->user_priv, nv30, bufctx);
+ screen = &nv30->screen->base;
+
+ nouveau_fence_next(screen);
+ nouveau_fence_update(screen, TRUE);
+
+ if (push->bufctx) {
+ struct nouveau_bufref *bref;
+ LIST_FOR_EACH_ENTRY(bref, &push->bufctx->current, thead) {
+ struct nv04_resource *res = bref->priv;
+ if (res && res->mm) {
+ nouveau_fence_ref(screen->fence.current, &res->fence);
+
+ if (bref->flags & NOUVEAU_BO_RD)
+ res->status |= NOUVEAU_BUFFER_STATUS_GPU_READING;
+
+ if (bref->flags & NOUVEAU_BO_WR) {
+ nouveau_fence_ref(screen->fence.current, &res->fence_wr);
+ res->status |= NOUVEAU_BUFFER_STATUS_GPU_WRITING;
+ }
+ }
+ }
+ }
+}
static void
-nv30_flush(struct pipe_context *pipe, unsigned flags,
- struct pipe_fence_handle **fence)
+nv30_context_flush(struct pipe_context *pipe, struct pipe_fence_handle **fence)
{
- struct nvfx_context *nvfx = nvfx_context(pipe);
- struct nvfx_screen *screen = nvfx->screen;
- struct nouveau_channel *chan = screen->base.channel;
- struct nouveau_grobj *eng3d = screen->eng3d;
-
- if (flags & PIPE_FLUSH_TEXTURE_CACHE) {
- BEGIN_RING(chan, eng3d, 0x1fd8, 1);
- OUT_RING (chan, 2);
- BEGIN_RING(chan, eng3d, 0x1fd8, 1);
- OUT_RING (chan, 1);
- }
-
- FIRE_RING(chan);
- if (fence)
- *fence = NULL;
+ struct nv30_context *nv30 = nv30_context(pipe);
+ struct nouveau_pushbuf *push = nv30->base.pushbuf;
+
+ if (fence)
+ nouveau_fence_ref(nv30->screen->base.fence.current,
+ (struct nouveau_fence **)fence);
+
+ PUSH_KICK(push);
}
static void
-nv30_destroy(struct pipe_context *pipe)
+nv30_context_destroy(struct pipe_context *pipe)
{
- struct nvfx_context *nvfx = nvfx_context(pipe);
- unsigned i;
+ struct nv30_context *nv30 = nv30_context(pipe);
+
+ if (nv30->blitter)
+ util_blitter_destroy(nv30->blitter);
- for (i = 0; i < NVFX_STATE_MAX; i++) {
- if (nvfx->state.hw[i])
- so_ref(NULL, &nvfx->state.hw[i]);
- }
+ if (nv30->draw)
+ draw_destroy(nv30->draw);
- if (nvfx->draw)
- draw_destroy(nvfx->draw);
- FREE(nvfx);
+ nouveau_bufctx_del(&nv30->bufctx);
+
+ if (nv30->screen->cur_ctx == nv30)
+ nv30->screen->cur_ctx = NULL;
+
+ nouveau_context_destroy(&nv30->base);
}
+#define FAIL_CONTEXT_INIT(str, err) \
+ do { \
+ NOUVEAU_ERR(str, err); \
+ nv30_context_destroy(pipe); \
+ return NULL; \
+ } while(0)
+
struct pipe_context *
-nv30_create(struct pipe_screen *pscreen, void *priv)
+nv30_context_create(struct pipe_screen *pscreen, void *priv)
{
- struct nvfx_screen *screen = nvfx_screen(pscreen);
- struct pipe_winsys *ws = pscreen->winsys;
- struct nvfx_context *nvfx;
- struct nouveau_winsys *nvws = screen->nvws;
-
- nvfx = CALLOC(1, sizeof(struct nvfx_context));
- if (!nvfx)
- return NULL;
- nvfx->screen = screen;
-
- nvfx->nvws = nvws;
-
- nvfx->pipe.winsys = ws;
- nvfx->pipe.screen = pscreen;
- nvfx->pipe.priv = priv;
- nvfx->pipe.destroy = nv30_destroy;
- nvfx->pipe.draw_arrays = nv30_draw_arrays;
- nvfx->pipe.draw_elements = nv30_draw_elements;
- nvfx->pipe.clear = nvfx_clear;
- nvfx->pipe.flush = nv30_flush;
-
- nvfx->pipe.is_texture_referenced = nouveau_is_texture_referenced;
- nvfx->pipe.is_buffer_referenced = nouveau_is_buffer_referenced;
-
- screen->base.channel->user_private = nvfx;
- screen->base.channel->flush_notify = nvfx_state_flush_notify;
-
- nvfx->is_nv4x = screen->is_nv4x;
-
- nvfx_init_query_functions(nvfx);
- nvfx_init_surface_functions(nvfx);
- nv30_init_state_functions(nvfx);
- nvfx_init_transfer_functions(nvfx);
-
- /* Create, configure, and install fallback swtnl path */
- nvfx->draw = draw_create();
- draw_wide_point_threshold(nvfx->draw, 9999999.0);
- draw_wide_line_threshold(nvfx->draw, 9999999.0);
- draw_enable_line_stipple(nvfx->draw, FALSE);
- draw_enable_point_sprites(nvfx->draw, FALSE);
- draw_set_rasterize_stage(nvfx->draw, nv30_draw_render_stage(nvfx));
-
- return &nvfx->pipe;
+ struct nv30_screen *screen = nv30_screen(pscreen);
+ struct nv30_context *nv30 = CALLOC_STRUCT(nv30_context);
+ struct nouveau_pushbuf *push;
+ struct pipe_context *pipe;
+ int ret;
+
+ if (!nv30)
+ return NULL;
+
+ nv30->screen = screen;
+ nv30->base.screen = &screen->base;
+ nv30->base.copy_data = nv30_transfer_copy_data;
+
+ pipe = &nv30->base.pipe;
+ pipe->screen = pscreen;
+ pipe->priv = priv;
+ pipe->destroy = nv30_context_destroy;
+ pipe->flush = nv30_context_flush;
+
+ /*XXX: *cough* per-context client */
+ nv30->base.client = screen->base.client;
+
+ /*XXX: *cough* per-context pushbufs */
+ push = screen->base.pushbuf;
+ nv30->base.pushbuf = push;
+ nv30->base.pushbuf->user_priv = push->user_priv; /* hack at validate time */
+ nv30->base.pushbuf->rsvd_kick = 16; /* hack in screen before first space */
+ nv30->base.pushbuf->kick_notify = nv30_context_kick_notify;
+
+ ret = nouveau_bufctx_new(nv30->base.client, 64, &nv30->bufctx);
+ if (ret) {
+ nv30_context_destroy(pipe);
+ return NULL;
+ }
+
+ /*XXX: make configurable with performance vs quality, these defaults
+ * match the binary driver's defaults
+ */
+ if (screen->eng3d->oclass < NV40_3D_CLASS)
+ nv30->config.filter = 0x00000004;
+ else
+ nv30->config.filter = 0x00002dc4;
+
+ nv30->config.aniso = NV40_3D_TEX_WRAP_ANISO_MIP_FILTER_OPTIMIZATION_OFF;
+
+ if (debug_get_bool_option("NV30_SWTNL", FALSE))
+ nv30->draw_flags |= NV30_NEW_SWTNL;
+
+ /*XXX: nvfx... */
+ nv30->is_nv4x = (screen->eng3d->oclass >= NV40_3D_CLASS) ? ~0 : 0;
+ nv30->use_nv4x = (screen->eng3d->oclass >= NV40_3D_CLASS) ? ~0 : 0;
+ nv30->render_mode = HW;
+
+ nv30->sample_mask = 0xffff;
+ nv30_vbo_init(pipe);
+ nv30_query_init(pipe);
+ nv30_state_init(pipe);
+ nv30_resource_init(pipe);
+ nv30_clear_init(pipe);
+ nv30_fragprog_init(pipe);
+ nv30_vertprog_init(pipe);
+ nv30_texture_init(pipe);
+ nv30_fragtex_init(pipe);
+ nv40_verttex_init(pipe);
+ nv30_draw_init(pipe);
+
+ nv30->blitter = util_blitter_create(pipe);
+ if (!nv30->blitter) {
+ nv30_context_destroy(pipe);
+ return NULL;
+ }
+
+ return pipe;
}