1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
/**************************************************************************
*
* Copyright 2007 VMware, Inc.
* All Rights Reserved.
* Copyright 2008 VMware, Inc. All rights reserved.
*
* 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, sub license, 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 (including the
* next paragraph) 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 NON-INFRINGEMENT.
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
*
**************************************************************************/
/* Author:
* Keith Whitwell <keithw@vmware.com>
*/
#include "draw/draw_context.h"
#include "draw/draw_vbuf.h"
#include "pipe/p_defines.h"
#include "util/u_inlines.h"
#include "util/u_math.h"
#include "util/u_memory.h"
#include "util/simple_list.h"
#include "util/u_upload_mgr.h"
#include "lp_clear.h"
#include "lp_context.h"
#include "lp_flush.h"
#include "lp_perf.h"
#include "lp_state.h"
#include "lp_surface.h"
#include "lp_query.h"
#include "lp_setup.h"
/* This is only safe if there's just one concurrent context */
#ifdef PIPE_SUBSYSTEM_EMBEDDED
#define USE_GLOBAL_LLVM_CONTEXT
#endif
static void llvmpipe_destroy( struct pipe_context *pipe )
{
struct llvmpipe_context *llvmpipe = llvmpipe_context( pipe );
uint i, j;
lp_print_counters();
if (llvmpipe->blitter) {
util_blitter_destroy(llvmpipe->blitter);
}
if (llvmpipe->pipe.stream_uploader)
u_upload_destroy(llvmpipe->pipe.stream_uploader);
/* This will also destroy llvmpipe->setup:
*/
if (llvmpipe->draw)
draw_destroy( llvmpipe->draw );
for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
pipe_surface_reference(&llvmpipe->framebuffer.cbufs[i], NULL);
}
pipe_surface_reference(&llvmpipe->framebuffer.zsbuf, NULL);
for (i = 0; i < ARRAY_SIZE(llvmpipe->sampler_views[0]); i++) {
pipe_sampler_view_reference(&llvmpipe->sampler_views[PIPE_SHADER_FRAGMENT][i], NULL);
}
for (i = 0; i < ARRAY_SIZE(llvmpipe->sampler_views[0]); i++) {
pipe_sampler_view_reference(&llvmpipe->sampler_views[PIPE_SHADER_VERTEX][i], NULL);
}
for (i = 0; i < ARRAY_SIZE(llvmpipe->sampler_views[0]); i++) {
pipe_sampler_view_reference(&llvmpipe->sampler_views[PIPE_SHADER_GEOMETRY][i], NULL);
}
for (i = 0; i < ARRAY_SIZE(llvmpipe->constants); i++) {
for (j = 0; j < ARRAY_SIZE(llvmpipe->constants[i]); j++) {
pipe_resource_reference(&llvmpipe->constants[i][j].buffer, NULL);
}
}
for (i = 0; i < llvmpipe->num_vertex_buffers; i++) {
pipe_vertex_buffer_unreference(&llvmpipe->vertex_buffer[i]);
}
lp_delete_setup_variants(llvmpipe);
#ifndef USE_GLOBAL_LLVM_CONTEXT
LLVMContextDispose(llvmpipe->context);
#endif
llvmpipe->context = NULL;
align_free( llvmpipe );
}
static void
do_flush( struct pipe_context *pipe,
struct pipe_fence_handle **fence,
unsigned flags)
{
llvmpipe_flush(pipe, fence, __FUNCTION__);
}
static void
llvmpipe_render_condition(struct pipe_context *pipe,
struct pipe_query *query,
boolean condition,
enum pipe_render_cond_flag mode)
{
struct llvmpipe_context *llvmpipe = llvmpipe_context( pipe );
llvmpipe->render_cond_query = query;
llvmpipe->render_cond_mode = mode;
llvmpipe->render_cond_cond = condition;
}
struct pipe_context *
llvmpipe_create_context(struct pipe_screen *screen, void *priv,
unsigned flags)
{
struct llvmpipe_context *llvmpipe;
llvmpipe = align_malloc(sizeof(struct llvmpipe_context), 16);
if (!llvmpipe)
return NULL;
util_init_math();
memset(llvmpipe, 0, sizeof *llvmpipe);
make_empty_list(&llvmpipe->fs_variants_list);
make_empty_list(&llvmpipe->setup_variants_list);
llvmpipe->pipe.screen = screen;
llvmpipe->pipe.priv = priv;
/* Init the pipe context methods */
llvmpipe->pipe.destroy = llvmpipe_destroy;
llvmpipe->pipe.set_framebuffer_state = llvmpipe_set_framebuffer_state;
llvmpipe->pipe.clear = llvmpipe_clear;
llvmpipe->pipe.flush = do_flush;
llvmpipe->pipe.render_condition = llvmpipe_render_condition;
llvmpipe_init_blend_funcs(llvmpipe);
llvmpipe_init_clip_funcs(llvmpipe);
llvmpipe_init_draw_funcs(llvmpipe);
llvmpipe_init_sampler_funcs(llvmpipe);
llvmpipe_init_query_funcs( llvmpipe );
llvmpipe_init_vertex_funcs(llvmpipe);
llvmpipe_init_so_funcs(llvmpipe);
llvmpipe_init_fs_funcs(llvmpipe);
llvmpipe_init_vs_funcs(llvmpipe);
llvmpipe_init_gs_funcs(llvmpipe);
llvmpipe_init_rasterizer_funcs(llvmpipe);
llvmpipe_init_context_resource_funcs( &llvmpipe->pipe );
llvmpipe_init_surface_functions(llvmpipe);
#ifdef USE_GLOBAL_LLVM_CONTEXT
llvmpipe->context = LLVMGetGlobalContext();
#else
llvmpipe->context = LLVMContextCreate();
#endif
if (!llvmpipe->context)
goto fail;
/*
* Create drawing context and plug our rendering stage into it.
*/
llvmpipe->draw = draw_create_with_llvm_context(&llvmpipe->pipe,
llvmpipe->context);
if (!llvmpipe->draw)
goto fail;
/* FIXME: devise alternative to draw_texture_samplers */
llvmpipe->setup = lp_setup_create( &llvmpipe->pipe,
llvmpipe->draw );
if (!llvmpipe->setup)
goto fail;
llvmpipe->pipe.stream_uploader = u_upload_create_default(&llvmpipe->pipe);
if (!llvmpipe->pipe.stream_uploader)
goto fail;
llvmpipe->pipe.const_uploader = llvmpipe->pipe.stream_uploader;
llvmpipe->blitter = util_blitter_create(&llvmpipe->pipe);
if (!llvmpipe->blitter) {
goto fail;
}
/* must be done before installing Draw stages */
util_blitter_cache_all_shaders(llvmpipe->blitter);
/* plug in AA line/point stages */
draw_install_aaline_stage(llvmpipe->draw, &llvmpipe->pipe);
draw_install_aapoint_stage(llvmpipe->draw, &llvmpipe->pipe);
draw_install_pstipple_stage(llvmpipe->draw, &llvmpipe->pipe);
/* convert points and lines into triangles:
* (otherwise, draw points and lines natively)
*/
draw_wide_point_sprites(llvmpipe->draw, FALSE);
draw_enable_point_sprites(llvmpipe->draw, FALSE);
draw_wide_point_threshold(llvmpipe->draw, 10000.0);
draw_wide_line_threshold(llvmpipe->draw, 10000.0);
lp_reset_counters();
return &llvmpipe->pipe;
fail:
llvmpipe_destroy(&llvmpipe->pipe);
return NULL;
}
|