1 /**************************************************************************
3 * Copyright 2003 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 #include "i915_context.h"
29 #include "i915_state.h"
30 #include "i915_screen.h"
31 #include "i915_surface.h"
32 #include "i915_query.h"
33 #include "i915_batch.h"
34 #include "i915_resource.h"
36 #include "draw/draw_context.h"
37 #include "pipe/p_defines.h"
38 #include "util/u_inlines.h"
39 #include "util/u_memory.h"
40 #include "util/u_prim.h"
41 #include "util/u_upload_mgr.h"
42 #include "pipe/p_screen.h"
45 DEBUG_GET_ONCE_BOOL_OPTION(i915_no_vbuf
, "I915_NO_VBUF", FALSE
)
54 i915_draw_vbo(struct pipe_context
*pipe
, const struct pipe_draw_info
*info
)
56 struct i915_context
*i915
= i915_context(pipe
);
57 struct draw_context
*draw
= i915
->draw
;
58 const void *mapped_indices
= NULL
;
61 if (!u_trim_pipe_prim(info
->mode
, (unsigned*)&info
->count
))
65 * Ack vs contants here, helps ipers a lot.
67 i915
->dirty
&= ~I915_NEW_VS_CONSTANTS
;
70 i915_update_derived(i915
);
75 for (i
= 0; i
< i915
->nr_vertex_buffers
; i
++) {
76 const void *buf
= i915
->vertex_buffers
[i
].is_user_buffer
?
77 i915
->vertex_buffers
[i
].buffer
.user
: NULL
;
79 buf
= i915_buffer(i915
->vertex_buffers
[i
].buffer
.resource
)->data
;
80 draw_set_mapped_vertex_buffer(draw
, i
, buf
, ~0);
84 * Map index buffer, if present
86 if (info
->index_size
) {
87 mapped_indices
= info
->has_user_indices
? info
->index
.user
: NULL
;
89 mapped_indices
= i915_buffer(info
->index
.resource
)->data
;
90 draw_set_indexes(draw
,
91 (ubyte
*) mapped_indices
,
92 info
->index_size
, ~0);
95 if (i915
->constants
[PIPE_SHADER_VERTEX
])
96 draw_set_mapped_constant_buffer(draw
, PIPE_SHADER_VERTEX
, 0,
97 i915_buffer(i915
->constants
[PIPE_SHADER_VERTEX
])->data
,
98 (i915
->current
.num_user_constants
[PIPE_SHADER_VERTEX
] *
101 draw_set_mapped_constant_buffer(draw
, PIPE_SHADER_VERTEX
, 0, NULL
, 0);
103 if (i915
->num_vertex_sampler_views
> 0)
104 i915_prepare_vertex_sampling(i915
);
109 draw_vbo(i915
->draw
, info
);
112 * unmap vertex/index buffers
114 for (i
= 0; i
< i915
->nr_vertex_buffers
; i
++) {
115 draw_set_mapped_vertex_buffer(i915
->draw
, i
, NULL
, 0);
118 draw_set_indexes(draw
, NULL
, 0, 0);
120 if (i915
->num_vertex_sampler_views
> 0)
121 i915_cleanup_vertex_sampling(i915
);
124 * Instead of flushing on every state change, we flush once here
125 * when we fire the vbo.
127 draw_flush(i915
->draw
);
132 * Generic context functions
136 static void i915_destroy(struct pipe_context
*pipe
)
138 struct i915_context
*i915
= i915_context(pipe
);
142 util_blitter_destroy(i915
->blitter
);
144 draw_destroy(i915
->draw
);
146 if (i915
->base
.stream_uploader
)
147 u_upload_destroy(i915
->base
.stream_uploader
);
150 i915
->iws
->batchbuffer_destroy(i915
->batch
);
152 /* unbind framebuffer */
153 for (i
= 0; i
< PIPE_MAX_COLOR_BUFS
; i
++) {
154 pipe_surface_reference(&i915
->framebuffer
.cbufs
[i
], NULL
);
156 pipe_surface_reference(&i915
->framebuffer
.zsbuf
, NULL
);
158 /* unbind constant buffers */
159 for (i
= 0; i
< PIPE_SHADER_TYPES
; i
++) {
160 pipe_resource_reference(&i915
->constants
[i
], NULL
);
166 struct pipe_context
*
167 i915_create_context(struct pipe_screen
*screen
, void *priv
, unsigned flags
)
169 struct i915_context
*i915
;
171 i915
= CALLOC_STRUCT(i915_context
);
175 i915
->iws
= i915_screen(screen
)->iws
;
176 i915
->base
.screen
= screen
;
177 i915
->base
.priv
= priv
;
178 i915
->base
.stream_uploader
= u_upload_create_default(&i915
->base
);
179 i915
->base
.const_uploader
= i915
->base
.stream_uploader
;
181 i915
->base
.destroy
= i915_destroy
;
183 if (i915_screen(screen
)->debug
.use_blitter
)
184 i915
->base
.clear
= i915_clear_blitter
;
186 i915
->base
.clear
= i915_clear_render
;
188 i915
->base
.draw_vbo
= i915_draw_vbo
;
190 /* init this before draw */
191 slab_create(&i915
->transfer_pool
, sizeof(struct pipe_transfer
),
193 slab_create(&i915
->texture_transfer_pool
, sizeof(struct i915_transfer
),
196 /* Batch stream debugging is a bit hacked up at the moment:
198 i915
->batch
= i915
->iws
->batchbuffer_create(i915
->iws
);
201 * Create drawing context and plug our rendering stage into it.
203 i915
->draw
= draw_create(&i915
->base
);
205 if (!debug_get_option_i915_no_vbuf()) {
206 draw_set_rasterize_stage(i915
->draw
, i915_draw_vbuf_stage(i915
));
208 draw_set_rasterize_stage(i915
->draw
, i915_draw_render_stage(i915
));
211 i915_init_surface_functions(i915
);
212 i915_init_state_functions(i915
);
213 i915_init_flush_functions(i915
);
214 i915_init_resource_functions(i915
);
215 i915_init_query_functions(i915
);
217 /* Create blitter. */
218 i915
->blitter
= util_blitter_create(&i915
->base
);
219 assert(i915
->blitter
);
221 /* must be done before installing Draw stages */
222 util_blitter_cache_all_shaders(i915
->blitter
);
224 draw_install_aaline_stage(i915
->draw
, &i915
->base
);
225 draw_install_aapoint_stage(i915
->draw
, &i915
->base
);
226 draw_enable_point_sprites(i915
->draw
, TRUE
);
229 i915
->hardware_dirty
= ~0;
230 i915
->immediate_dirty
= ~0;
231 i915
->dynamic_dirty
= ~0;
232 i915
->static_dirty
= ~0;
233 i915
->flush_dirty
= 0;