nv50: use flush_notify to reduce number of relocs
[mesa.git] / src / gallium / drivers / nv50 / nv50_context.c
1 /*
2 * Copyright 2008 Ben Skeggs
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 #include "draw/draw_context.h"
24 #include "pipe/p_defines.h"
25 #include "pipe/internal/p_winsys_screen.h"
26
27 #include "nv50_context.h"
28 #include "nv50_screen.h"
29
30 static void
31 nv50_flush(struct pipe_context *pipe, unsigned flags,
32 struct pipe_fence_handle **fence)
33 {
34 struct nv50_context *nv50 = nv50_context(pipe);
35 struct nouveau_channel *chan = nv50->screen->base.channel;
36 struct nouveau_grobj *eng2d = nv50->screen->eng2d;
37
38 /* We need this in the ddx for reliable composite, not sure what we're
39 * actually flushing. We generate all our own flushes with flags = 0. */
40 WAIT_RING(chan, 3);
41 BEGIN_RING(chan, eng2d, 0x0110, 1);
42 OUT_RING (chan, 0);
43
44 FIRE_RING(chan);
45 }
46
47 static void
48 nv50_destroy(struct pipe_context *pipe)
49 {
50 struct nv50_context *nv50 = nv50_context(pipe);
51
52 draw_destroy(nv50->draw);
53 FREE(nv50);
54 }
55
56
57 static void
58 nv50_set_edgeflags(struct pipe_context *pipe, const unsigned *bitfield)
59 {
60 }
61
62 static unsigned int
63 nv50_is_texture_referenced( struct pipe_context *pipe,
64 struct pipe_texture *texture,
65 unsigned face, unsigned level)
66 {
67 /**
68 * FIXME: Optimize.
69 */
70
71 return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE;
72 }
73
74 static unsigned int
75 nv50_is_buffer_referenced( struct pipe_context *pipe,
76 struct pipe_buffer *buf)
77 {
78 /**
79 * FIXME: Optimize.
80 */
81
82 return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE;
83 }
84
85 struct pipe_context *
86 nv50_create(struct pipe_screen *pscreen, unsigned pctx_id)
87 {
88 struct pipe_winsys *pipe_winsys = pscreen->winsys;
89 struct nv50_screen *screen = nv50_screen(pscreen);
90 struct nv50_context *nv50;
91
92 nv50 = CALLOC_STRUCT(nv50_context);
93 if (!nv50)
94 return NULL;
95 nv50->screen = screen;
96 nv50->pctx_id = pctx_id;
97
98 nv50->pipe.winsys = pipe_winsys;
99 nv50->pipe.screen = pscreen;
100
101 nv50->pipe.destroy = nv50_destroy;
102
103 nv50->pipe.set_edgeflags = nv50_set_edgeflags;
104 nv50->pipe.draw_arrays = nv50_draw_arrays;
105 nv50->pipe.draw_elements = nv50_draw_elements;
106 nv50->pipe.clear = nv50_clear;
107
108 nv50->pipe.flush = nv50_flush;
109
110 nv50->pipe.is_texture_referenced = nv50_is_texture_referenced;
111 nv50->pipe.is_buffer_referenced = nv50_is_buffer_referenced;
112
113 screen->base.channel->user_private = nv50;
114 screen->base.channel->flush_notify = nv50_state_flush_notify;
115
116 nv50_init_surface_functions(nv50);
117 nv50_init_state_functions(nv50);
118 nv50_init_query_functions(nv50);
119
120 nv50->draw = draw_create();
121 assert(nv50->draw);
122 draw_set_rasterize_stage(nv50->draw, nv50_draw_render_stage(nv50));
123
124 return &nv50->pipe;
125 }