• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**********************************************************
2  * Copyright 2008-2009 VMware, Inc.  All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person
5  * obtaining a copy of this software and associated documentation
6  * files (the "Software"), to deal in the Software without
7  * restriction, including without limitation the rights to use, copy,
8  * modify, merge, publish, distribute, sublicense, and/or sell copies
9  * of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  *
24  **********************************************************/
25 
26 #include "draw/draw_context.h"
27 #include "draw/draw_vbuf.h"
28 #include "util/u_inlines.h"
29 #include "pipe/p_state.h"
30 
31 #include "svga_context.h"
32 #include "svga_screen.h"
33 #include "svga_swtnl.h"
34 #include "svga_state.h"
35 #include "svga_swtnl_private.h"
36 
37 
38 
39 enum pipe_error
svga_swtnl_draw_vbo(struct svga_context * svga,const struct pipe_draw_info * info)40 svga_swtnl_draw_vbo(struct svga_context *svga,
41                     const struct pipe_draw_info *info)
42 {
43    struct pipe_transfer *vb_transfer[PIPE_MAX_ATTRIBS] = { 0 };
44    struct pipe_transfer *ib_transfer = NULL;
45    struct pipe_transfer *cb_transfer[SVGA_MAX_CONST_BUFS] = { 0 };
46    struct draw_context *draw = svga->swtnl.draw;
47    MAYBE_UNUSED unsigned old_num_vertex_buffers;
48    unsigned i;
49    const void *map;
50    enum pipe_error ret;
51 
52    SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_SWTNLDRAWVBO);
53 
54    assert(!svga->dirty);
55    assert(svga->state.sw.need_swtnl);
56    assert(draw);
57 
58    /* Make sure that the need_swtnl flag does not go away */
59    svga->state.sw.in_swtnl_draw = TRUE;
60 
61    ret = svga_update_state(svga, SVGA_STATE_SWTNL_DRAW);
62    if (ret != PIPE_OK) {
63       svga_context_flush(svga, NULL);
64       ret = svga_update_state(svga, SVGA_STATE_SWTNL_DRAW);
65       svga->swtnl.new_vbuf = TRUE;
66       assert(ret == PIPE_OK);
67    }
68 
69    /*
70     * Map vertex buffers
71     */
72    for (i = 0; i < svga->curr.num_vertex_buffers; i++) {
73       if (svga->curr.vb[i].buffer) {
74          map = pipe_buffer_map(&svga->pipe,
75                                svga->curr.vb[i].buffer,
76                                PIPE_TRANSFER_READ,
77                                &vb_transfer[i]);
78 
79          draw_set_mapped_vertex_buffer(draw, i, map, ~0);
80       }
81    }
82    old_num_vertex_buffers = svga->curr.num_vertex_buffers;
83 
84    /* Map index buffer, if present */
85    map = NULL;
86    if (info->indexed && svga->curr.ib.buffer) {
87       map = pipe_buffer_map(&svga->pipe, svga->curr.ib.buffer,
88                             PIPE_TRANSFER_READ,
89                             &ib_transfer);
90       draw_set_indexes(draw,
91                        (const ubyte *) map + svga->curr.ib.offset,
92                        svga->curr.ib.index_size, ~0);
93    }
94 
95    /* Map constant buffers */
96    for (i = 0; i < ARRAY_SIZE(svga->curr.constbufs[PIPE_SHADER_VERTEX]); ++i) {
97       if (svga->curr.constbufs[PIPE_SHADER_VERTEX][i].buffer == NULL) {
98          continue;
99       }
100 
101       map = pipe_buffer_map(&svga->pipe,
102                             svga->curr.constbufs[PIPE_SHADER_VERTEX][i].buffer,
103                             PIPE_TRANSFER_READ,
104                             &cb_transfer[i]);
105       assert(map);
106       draw_set_mapped_constant_buffer(
107          draw, PIPE_SHADER_VERTEX, i,
108          map,
109          svga->curr.constbufs[PIPE_SHADER_VERTEX][i].buffer->width0);
110    }
111 
112    draw_vbo(draw, info);
113 
114    draw_flush(svga->swtnl.draw);
115 
116    /* Ensure the draw module didn't touch this */
117    assert(old_num_vertex_buffers == svga->curr.num_vertex_buffers);
118 
119    /*
120     * unmap vertex/index buffers
121     */
122    for (i = 0; i < svga->curr.num_vertex_buffers; i++) {
123       if (svga->curr.vb[i].buffer) {
124          pipe_buffer_unmap(&svga->pipe, vb_transfer[i]);
125          draw_set_mapped_vertex_buffer(draw, i, NULL, 0);
126       }
127    }
128 
129    if (ib_transfer) {
130       pipe_buffer_unmap(&svga->pipe, ib_transfer);
131       draw_set_indexes(draw, NULL, 0, 0);
132    }
133 
134    for (i = 0; i < ARRAY_SIZE(svga->curr.constbufs[PIPE_SHADER_VERTEX]); ++i) {
135       if (svga->curr.constbufs[PIPE_SHADER_VERTEX][i].buffer) {
136          pipe_buffer_unmap(&svga->pipe, cb_transfer[i]);
137       }
138    }
139 
140    /* Now safe to remove the need_swtnl flag in any update_state call */
141    svga->state.sw.in_swtnl_draw = FALSE;
142    svga->dirty |= SVGA_NEW_NEED_PIPELINE | SVGA_NEW_NEED_SWVFETCH;
143 
144    SVGA_STATS_TIME_POP(svga_sws(svga));
145    return ret;
146 }
147 
148 
149 
150 
svga_init_swtnl(struct svga_context * svga)151 boolean svga_init_swtnl( struct svga_context *svga )
152 {
153    struct svga_screen *screen = svga_screen(svga->pipe.screen);
154 
155    svga->swtnl.backend = svga_vbuf_render_create(svga);
156    if(!svga->swtnl.backend)
157       goto fail;
158 
159    /*
160     * Create drawing context and plug our rendering stage into it.
161     */
162    svga->swtnl.draw = draw_create(&svga->pipe);
163    if (svga->swtnl.draw == NULL)
164       goto fail;
165 
166 
167    draw_set_rasterize_stage(svga->swtnl.draw,
168                             draw_vbuf_stage( svga->swtnl.draw, svga->swtnl.backend ));
169 
170    draw_set_render(svga->swtnl.draw, svga->swtnl.backend);
171 
172    svga->blitter = util_blitter_create(&svga->pipe);
173    if (!svga->blitter)
174       goto fail;
175 
176    /* must be done before installing Draw stages */
177    util_blitter_cache_all_shaders(svga->blitter);
178 
179    if (!screen->haveLineSmooth)
180       draw_install_aaline_stage(svga->swtnl.draw, &svga->pipe);
181 
182    /* enable/disable line stipple stage depending on device caps */
183    draw_enable_line_stipple(svga->swtnl.draw, !screen->haveLineStipple);
184 
185    /* always install AA point stage */
186    draw_install_aapoint_stage(svga->swtnl.draw, &svga->pipe);
187 
188    /* Set wide line threshold above device limit (so we'll never really use it)
189     */
190    draw_wide_line_threshold(svga->swtnl.draw,
191                             MAX2(screen->maxLineWidth,
192                                  screen->maxLineWidthAA));
193 
194    if (debug_get_bool_option("SVGA_SWTNL_FSE", FALSE))
195       draw_set_driver_clipping(svga->swtnl.draw, TRUE, TRUE, TRUE, FALSE);
196 
197    return TRUE;
198 
199 fail:
200    if (svga->blitter)
201       util_blitter_destroy(svga->blitter);
202 
203    if (svga->swtnl.backend)
204       svga->swtnl.backend->destroy( svga->swtnl.backend );
205 
206    if (svga->swtnl.draw)
207       draw_destroy( svga->swtnl.draw );
208 
209    return FALSE;
210 }
211 
212 
svga_destroy_swtnl(struct svga_context * svga)213 void svga_destroy_swtnl( struct svga_context *svga )
214 {
215    draw_destroy( svga->swtnl.draw );
216 }
217