1848b8605Smrg/**************************************************************************
2848b8605Smrg *
3848b8605Smrg * Copyright 2007 VMware, Inc.
4848b8605Smrg * All Rights Reserved.
5848b8605Smrg *
6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
7848b8605Smrg * copy of this software and associated documentation files (the
8848b8605Smrg * "Software"), to deal in the Software without restriction, including
9848b8605Smrg * without limitation the rights to use, copy, modify, merge, publish,
10848b8605Smrg * distribute, sub license, and/or sell copies of the Software, and to
11848b8605Smrg * permit persons to whom the Software is furnished to do so, subject to
12848b8605Smrg * the following conditions:
13848b8605Smrg *
14848b8605Smrg * The above copyright notice and this permission notice (including the
15848b8605Smrg * next paragraph) shall be included in all copies or substantial portions
16848b8605Smrg * of the Software.
17848b8605Smrg *
18848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20848b8605Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21848b8605Smrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22848b8605Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23848b8605Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24848b8605Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25848b8605Smrg *
26848b8605Smrg **************************************************************************/
27848b8605Smrg
28848b8605Smrg/* Authors:  Keith Whitwell <keithw@vmware.com>
29848b8605Smrg */
30848b8605Smrg
31848b8605Smrg#ifndef LP_CONTEXT_H
32848b8605Smrg#define LP_CONTEXT_H
33848b8605Smrg
34848b8605Smrg#include "pipe/p_context.h"
35848b8605Smrg
36848b8605Smrg#include "draw/draw_vertex.h"
37848b8605Smrg#include "util/u_blitter.h"
38848b8605Smrg
39848b8605Smrg#include "lp_tex_sample.h"
40848b8605Smrg#include "lp_jit.h"
41848b8605Smrg#include "lp_setup.h"
42848b8605Smrg#include "lp_state_fs.h"
43848b8605Smrg#include "lp_state_setup.h"
44848b8605Smrg
45848b8605Smrg
46848b8605Smrgstruct llvmpipe_vbuf_render;
47848b8605Smrgstruct draw_context;
48848b8605Smrgstruct draw_stage;
49848b8605Smrgstruct draw_vertex_shader;
50848b8605Smrgstruct lp_fragment_shader;
51848b8605Smrgstruct lp_blend_state;
52848b8605Smrgstruct lp_setup_context;
53848b8605Smrgstruct lp_setup_variant;
54848b8605Smrgstruct lp_velems_state;
55848b8605Smrg
56848b8605Smrgstruct llvmpipe_context {
57848b8605Smrg   struct pipe_context pipe;  /**< base class */
58848b8605Smrg
59848b8605Smrg   /** Constant state objects */
60848b8605Smrg   const struct pipe_blend_state *blend;
61848b8605Smrg   struct pipe_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
62848b8605Smrg
63848b8605Smrg   const struct pipe_depth_stencil_alpha_state *depth_stencil;
64848b8605Smrg   const struct pipe_rasterizer_state *rasterizer;
65848b8605Smrg   struct lp_fragment_shader *fs;
66848b8605Smrg   struct draw_vertex_shader *vs;
67848b8605Smrg   const struct lp_geometry_shader *gs;
68848b8605Smrg   const struct lp_velems_state *velems;
69848b8605Smrg   const struct lp_so_state *so;
70848b8605Smrg
71848b8605Smrg   /** Other rendering state */
72848b8605Smrg   unsigned sample_mask;
73848b8605Smrg   struct pipe_blend_color blend_color;
74848b8605Smrg   struct pipe_stencil_ref stencil_ref;
75848b8605Smrg   struct pipe_clip_state clip;
76848b8605Smrg   struct pipe_constant_buffer constants[PIPE_SHADER_TYPES][LP_MAX_TGSI_CONST_BUFFERS];
77848b8605Smrg   struct pipe_framebuffer_state framebuffer;
78848b8605Smrg   struct pipe_poly_stipple poly_stipple;
79848b8605Smrg   struct pipe_scissor_state scissors[PIPE_MAX_VIEWPORTS];
80848b8605Smrg   struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
81848b8605Smrg
82848b8605Smrg   struct pipe_viewport_state viewports[PIPE_MAX_VIEWPORTS];
83848b8605Smrg   struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
84848b8605Smrg
85848b8605Smrg   unsigned num_samplers[PIPE_SHADER_TYPES];
86848b8605Smrg   unsigned num_sampler_views[PIPE_SHADER_TYPES];
87848b8605Smrg
88848b8605Smrg   unsigned num_vertex_buffers;
89848b8605Smrg
90848b8605Smrg   struct draw_so_target *so_targets[PIPE_MAX_SO_BUFFERS];
91848b8605Smrg   int num_so_targets;
92848b8605Smrg   struct pipe_query_data_so_statistics so_stats;
93848b8605Smrg
94848b8605Smrg   struct pipe_query_data_pipeline_statistics pipeline_statistics;
95848b8605Smrg   unsigned active_statistics_queries;
96848b8605Smrg
97848b8605Smrg   unsigned active_occlusion_queries;
98848b8605Smrg
99848b8605Smrg   unsigned dirty; /**< Mask of LP_NEW_x flags */
100848b8605Smrg
101848b8605Smrg   /** Mapped vertex buffers */
102848b8605Smrg   ubyte *mapped_vbuffer[PIPE_MAX_ATTRIBS];
103848b8605Smrg
104848b8605Smrg   /** Vertex format */
105848b8605Smrg   struct vertex_info vertex_info;
106848b8605Smrg
107848b8605Smrg   /** Which vertex shader output slot contains color */
108b8e80941Smrg   int8_t color_slot[2];
109848b8605Smrg
110848b8605Smrg   /** Which vertex shader output slot contains bcolor */
111b8e80941Smrg   int8_t bcolor_slot[2];
112848b8605Smrg
113848b8605Smrg   /** Which vertex shader output slot contains point size */
114b8e80941Smrg   int8_t psize_slot;
115848b8605Smrg
116848b8605Smrg   /** Which vertex shader output slot contains viewport index */
117b8e80941Smrg   int8_t viewport_index_slot;
118848b8605Smrg
119848b8605Smrg   /** Which geometry shader output slot contains layer */
120b8e80941Smrg   int8_t layer_slot;
121848b8605Smrg
122848b8605Smrg   /** A fake frontface output for unfilled primitives */
123b8e80941Smrg   int8_t face_slot;
124848b8605Smrg
125848b8605Smrg   /** Depth format and bias settings. */
126848b8605Smrg   boolean floating_point_depth;
127848b8605Smrg   double mrd;   /**< minimum resolvable depth value, for polygon offset */
128848b8605Smrg
129848b8605Smrg   /** The tiling engine */
130848b8605Smrg   struct lp_setup_context *setup;
131848b8605Smrg   struct lp_setup_variant setup_variant;
132848b8605Smrg
133848b8605Smrg   /** The primitive drawing context */
134848b8605Smrg   struct draw_context *draw;
135848b8605Smrg
136848b8605Smrg   struct blitter_context *blitter;
137848b8605Smrg
138848b8605Smrg   unsigned tex_timestamp;
139848b8605Smrg
140848b8605Smrg   /** List of all fragment shader variants */
141848b8605Smrg   struct lp_fs_variant_list_item fs_variants_list;
142848b8605Smrg   unsigned nr_fs_variants;
143848b8605Smrg   unsigned nr_fs_instrs;
144848b8605Smrg
145848b8605Smrg   struct lp_setup_variant_list_item setup_variants_list;
146848b8605Smrg   unsigned nr_setup_variants;
147848b8605Smrg
148848b8605Smrg   /** Conditional query object and mode */
149848b8605Smrg   struct pipe_query *render_cond_query;
150b8e80941Smrg   enum pipe_render_cond_flag render_cond_mode;
151848b8605Smrg   boolean render_cond_cond;
152b8e80941Smrg
153b8e80941Smrg   /** The LLVMContext to use for LLVM related work */
154b8e80941Smrg   LLVMContextRef context;
155848b8605Smrg};
156848b8605Smrg
157848b8605Smrg
158848b8605Smrgstruct pipe_context *
159b8e80941Smrgllvmpipe_create_context(struct pipe_screen *screen, void *priv,
160b8e80941Smrg                        unsigned flags);
161848b8605Smrg
162848b8605Smrgstruct pipe_resource *
163848b8605Smrgllvmpipe_user_buffer_create(struct pipe_screen *screen,
164848b8605Smrg                            void *ptr,
165848b8605Smrg                            unsigned bytes,
166848b8605Smrg                            unsigned bind_flags);
167848b8605Smrg
168848b8605Smrg
169b8e80941Smrgstatic inline struct llvmpipe_context *
170848b8605Smrgllvmpipe_context( struct pipe_context *pipe )
171848b8605Smrg{
172848b8605Smrg   return (struct llvmpipe_context *)pipe;
173848b8605Smrg}
174848b8605Smrg
175848b8605Smrg#endif /* LP_CONTEXT_H */
176848b8605Smrg
177