1 /**************************************************************************
3 * Copyright 2007-2009 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 **************************************************************************/
30 * The setup code is concerned with point/line/triangle setup and
31 * putting commands/data into the bins.
35 #ifndef LP_SETUP_CONTEXT_H
36 #define LP_SETUP_CONTEXT_H
41 #include "lp_bld_interp.h" /* for struct lp_shader_input */
43 #include "draw/draw_vbuf.h"
44 #include "util/u_rect.h"
45 #include "util/u_pack_color.h"
47 #define LP_SETUP_NEW_FS 0x01
48 #define LP_SETUP_NEW_CONSTANTS 0x02
49 #define LP_SETUP_NEW_BLEND_COLOR 0x04
50 #define LP_SETUP_NEW_SCISSOR 0x08
51 #define LP_SETUP_NEW_VIEWPORTS 0x10
54 struct lp_setup_variant
;
57 /** Max number of scenes */
58 /* XXX: make multiple scenes per context work, see lp_setup_rasterize_scene */
64 * Point/line/triangle setup context.
65 * Note: "stored" below indicates data which is stored in the bins,
66 * not arbitrary malloc'd memory.
69 * Subclass of vbuf_render, plugged directly into the draw module as
70 * the rendering backend.
72 struct lp_setup_context
74 struct vbuf_render base
;
76 struct pipe_context
*pipe
;
77 struct vertex_info
*vertex_info
;
81 uint sprite_coord_enable
, sprite_coord_origin
;
82 uint vertex_buffer_size
;
85 /* Final pipeline stage for draw module. Draw module should
86 * create/install this itself now.
88 struct draw_stage
*vbuf
;
91 struct lp_scene
*scenes
[MAX_SCENES
]; /**< all the scenes */
92 struct lp_scene
*scene
; /**< current scene being built */
94 struct lp_fence
*last_fence
;
95 struct llvmpipe_query
*active_queries
[LP_MAX_ACTIVE_BINNED_QUERIES
];
96 unsigned active_binned_queries
;
98 boolean flatshade_first
;
99 boolean ccw_is_frontface
;
100 boolean scissor_test
;
101 boolean point_size_per_vertex
;
102 boolean rasterizer_discard
;
104 unsigned bottom_edge_rule
;
109 int8_t viewport_index_slot
;
113 struct pipe_framebuffer_state fb
;
114 struct u_rect framebuffer
;
115 struct u_rect scissors
[PIPE_MAX_VIEWPORTS
];
116 struct u_rect draw_regions
[PIPE_MAX_VIEWPORTS
]; /* intersection of fb & scissor */
117 struct lp_jit_viewport viewports
[PIPE_MAX_VIEWPORTS
];
121 union util_color color_val
[PIPE_MAX_COLOR_BUFS
];
123 uint64_t zsvalue
; /**< lp_rast_clear_zstencil() cmd */
127 SETUP_FLUSHED
, /**< scene is null */
128 SETUP_CLEARED
, /**< scene exists but has only clears */
129 SETUP_ACTIVE
/**< scene exists and has at least one draw/query */
133 const struct lp_rast_state
*stored
; /**< what's in the scene */
134 struct lp_rast_state current
; /**< currently set state */
135 struct pipe_resource
*current_tex
[PIPE_MAX_SHADER_SAMPLER_VIEWS
];
136 unsigned current_tex_num
;
139 /** fragment shader constants */
141 struct pipe_constant_buffer current
;
142 unsigned stored_size
;
143 const void *stored_data
;
144 } constants
[LP_MAX_TGSI_CONST_BUFFERS
];
147 struct pipe_blend_color current
;
153 const struct lp_setup_variant
*variant
;
156 unsigned dirty
; /**< bitmask of LP_SETUP_NEW_x bits */
158 void (*point
)( struct lp_setup_context
*,
159 const float (*v0
)[4]);
161 void (*line
)( struct lp_setup_context
*,
162 const float (*v0
)[4],
163 const float (*v1
)[4]);
165 void (*triangle
)( struct lp_setup_context
*,
166 const float (*v0
)[4],
167 const float (*v1
)[4],
168 const float (*v2
)[4]);
172 scissor_planes_needed(boolean scis_planes
[4], const struct u_rect
*bbox
,
173 const struct u_rect
*scissor
)
176 scis_planes
[0] = (bbox
->x0
< scissor
->x0
);
178 scis_planes
[1] = (bbox
->x1
> scissor
->x1
);
180 scis_planes
[2] = (bbox
->y0
< scissor
->y0
);
182 scis_planes
[3] = (bbox
->y1
> scissor
->y1
);
186 void lp_setup_choose_triangle( struct lp_setup_context
*setup
);
187 void lp_setup_choose_line( struct lp_setup_context
*setup
);
188 void lp_setup_choose_point( struct lp_setup_context
*setup
);
190 void lp_setup_init_vbuf(struct lp_setup_context
*setup
);
192 boolean
lp_setup_update_state( struct lp_setup_context
*setup
,
193 boolean update_scene
);
195 void lp_setup_destroy( struct lp_setup_context
*setup
);
197 boolean
lp_setup_flush_and_restart(struct lp_setup_context
*setup
);
200 lp_setup_print_triangle(struct lp_setup_context
*setup
,
201 const float (*v0
)[4],
202 const float (*v1
)[4],
203 const float (*v2
)[4]);
206 lp_setup_print_vertex(struct lp_setup_context
*setup
,
208 const float (*v
)[4]);
211 struct lp_rast_triangle
*
212 lp_setup_alloc_triangle(struct lp_scene
*scene
,
218 lp_setup_bin_triangle(struct lp_setup_context
*setup
,
219 struct lp_rast_triangle
*tri
,
220 const struct u_rect
*bboxorig
,
221 const struct u_rect
*bbox
,
223 unsigned scissor_index
);