- struct nv30_screen *screen = nv30_screen(pscreen);
- struct pipe_winsys *ws = pscreen->winsys;
- struct nv30_context *nv30;
- struct nouveau_winsys *nvws = screen->nvws;
-
- nv30 = CALLOC(1, sizeof(struct nv30_context));
- if (!nv30)
- return NULL;
- nv30->screen = screen;
- nv30->pctx_id = pctx_id;
-
- nv30->nvws = nvws;
-
- nv30->pipe.winsys = ws;
- nv30->pipe.screen = pscreen;
- nv30->pipe.destroy = nv30_destroy;
- nv30->pipe.draw_arrays = nv30_draw_arrays;
- nv30->pipe.draw_elements = nv30_draw_elements;
- nv30->pipe.clear = nv30_clear;
- nv30->pipe.flush = nv30_flush;
-
- nv30->pipe.is_texture_referenced = nouveau_is_texture_referenced;
- nv30->pipe.is_buffer_referenced = nouveau_is_buffer_referenced;
-
- screen->base.channel->user_private = nv30;
- screen->base.channel->flush_notify = nv30_state_flush_notify;
-
- nv30_init_query_functions(nv30);
- nv30_init_surface_functions(nv30);
- nv30_init_state_functions(nv30);
-
- /* Create, configure, and install fallback swtnl path */
- nv30->draw = draw_create();
- draw_wide_point_threshold(nv30->draw, 9999999.0);
- draw_wide_line_threshold(nv30->draw, 9999999.0);
- draw_enable_line_stipple(nv30->draw, FALSE);
- draw_enable_point_sprites(nv30->draw, FALSE);
- draw_set_rasterize_stage(nv30->draw, nv30_draw_render_stage(nv30));
-
- return &nv30->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;