2 * Copyright 2008 Ben Skeggs
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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
23 #include "draw/draw_context.h"
24 #include "pipe/p_defines.h"
25 #include "pipe/internal/p_winsys_screen.h"
27 #include "nv50_context.h"
28 #include "nv50_screen.h"
31 nv50_flush(struct pipe_context
*pipe
, unsigned flags
,
32 struct pipe_fence_handle
**fence
)
34 struct nv50_context
*nv50
= nv50_context(pipe
);
35 struct nouveau_channel
*chan
= nv50
->screen
->base
.channel
;
37 if (flags
& PIPE_FLUSH_TEXTURE_CACHE
) {
38 BEGIN_RING(chan
, nv50
->screen
->tesla
, 0x1338, 1);
39 OUT_RING (chan
, 0x20);
42 if (flags
& PIPE_FLUSH_FRAME
)
47 nv50_destroy(struct pipe_context
*pipe
)
49 struct nv50_context
*nv50
= nv50_context(pipe
);
52 so_ref(NULL
, &nv50
->state
.fb
);
53 if (nv50
->state
.blend
)
54 so_ref(NULL
, &nv50
->state
.blend
);
55 if (nv50
->state
.blend_colour
)
56 so_ref(NULL
, &nv50
->state
.blend_colour
);
58 so_ref(NULL
, &nv50
->state
.zsa
);
60 so_ref(NULL
, &nv50
->state
.rast
);
61 if (nv50
->state
.stipple
)
62 so_ref(NULL
, &nv50
->state
.stipple
);
63 if (nv50
->state
.scissor
)
64 so_ref(NULL
, &nv50
->state
.scissor
);
65 if (nv50
->state
.viewport
)
66 so_ref(NULL
, &nv50
->state
.viewport
);
67 if (nv50
->state
.tsc_upload
)
68 so_ref(NULL
, &nv50
->state
.tsc_upload
);
69 if (nv50
->state
.tic_upload
)
70 so_ref(NULL
, &nv50
->state
.tic_upload
);
71 if (nv50
->state
.vertprog
)
72 so_ref(NULL
, &nv50
->state
.vertprog
);
73 if (nv50
->state
.fragprog
)
74 so_ref(NULL
, &nv50
->state
.fragprog
);
75 if (nv50
->state
.geomprog
)
76 so_ref(NULL
, &nv50
->state
.geomprog
);
77 if (nv50
->state
.fp_linkage
)
78 so_ref(NULL
, &nv50
->state
.fp_linkage
);
79 if (nv50
->state
.gp_linkage
)
80 so_ref(NULL
, &nv50
->state
.gp_linkage
);
81 if (nv50
->state
.vtxfmt
)
82 so_ref(NULL
, &nv50
->state
.vtxfmt
);
83 if (nv50
->state
.vtxbuf
)
84 so_ref(NULL
, &nv50
->state
.vtxbuf
);
85 if (nv50
->state
.vtxattr
)
86 so_ref(NULL
, &nv50
->state
.vtxattr
);
88 draw_destroy(nv50
->draw
);
90 if (nv50
->screen
->cur_ctx
== nv50
)
91 nv50
->screen
->cur_ctx
= NULL
;
98 nv50_create(struct pipe_screen
*pscreen
, unsigned pctx_id
)
100 struct pipe_winsys
*pipe_winsys
= pscreen
->winsys
;
101 struct nv50_screen
*screen
= nv50_screen(pscreen
);
102 struct nv50_context
*nv50
;
104 nv50
= CALLOC_STRUCT(nv50_context
);
107 nv50
->screen
= screen
;
108 nv50
->pctx_id
= pctx_id
;
110 nv50
->pipe
.winsys
= pipe_winsys
;
111 nv50
->pipe
.screen
= pscreen
;
113 nv50
->pipe
.destroy
= nv50_destroy
;
115 nv50
->pipe
.draw_arrays
= nv50_draw_arrays
;
116 nv50
->pipe
.draw_arrays_instanced
= nv50_draw_arrays_instanced
;
117 nv50
->pipe
.draw_elements
= nv50_draw_elements
;
118 nv50
->pipe
.draw_elements_instanced
= nv50_draw_elements_instanced
;
119 nv50
->pipe
.clear
= nv50_clear
;
121 nv50
->pipe
.flush
= nv50_flush
;
123 nv50
->pipe
.is_texture_referenced
= nouveau_is_texture_referenced
;
124 nv50
->pipe
.is_buffer_referenced
= nouveau_is_buffer_referenced
;
126 screen
->base
.channel
->user_private
= nv50
;
127 screen
->base
.channel
->flush_notify
= nv50_state_flush_notify
;
129 nv50_init_surface_functions(nv50
);
130 nv50_init_state_functions(nv50
);
131 nv50_init_query_functions(nv50
);
133 nv50
->draw
= draw_create();
135 draw_set_rasterize_stage(nv50
->draw
, nv50_draw_render_stage(nv50
));