1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2007 VMware, Inc.
4bf215546Sopenharmony_ci * All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the
8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
12bf215546Sopenharmony_ci * the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the
15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
16bf215546Sopenharmony_ci * of the Software.
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25bf215546Sopenharmony_ci *
26bf215546Sopenharmony_ci **************************************************************************/
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci/* Authors:  Keith Whitwell <keithw@vmware.com>
29bf215546Sopenharmony_ci */
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci#ifndef LP_CONTEXT_H
32bf215546Sopenharmony_ci#define LP_CONTEXT_H
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci#include "pipe/p_context.h"
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_ci#include "draw/draw_vertex.h"
37bf215546Sopenharmony_ci#include "util/u_blitter.h"
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci#include "lp_tex_sample.h"
40bf215546Sopenharmony_ci#include "lp_jit.h"
41bf215546Sopenharmony_ci#include "lp_setup.h"
42bf215546Sopenharmony_ci#include "lp_state_fs.h"
43bf215546Sopenharmony_ci#include "lp_state_cs.h"
44bf215546Sopenharmony_ci#include "lp_state_setup.h"
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_cistruct llvmpipe_vbuf_render;
48bf215546Sopenharmony_cistruct draw_context;
49bf215546Sopenharmony_cistruct draw_stage;
50bf215546Sopenharmony_cistruct draw_vertex_shader;
51bf215546Sopenharmony_cistruct lp_fragment_shader;
52bf215546Sopenharmony_cistruct lp_compute_shader;
53bf215546Sopenharmony_cistruct lp_blend_state;
54bf215546Sopenharmony_cistruct lp_setup_context;
55bf215546Sopenharmony_cistruct lp_setup_variant;
56bf215546Sopenharmony_cistruct lp_velems_state;
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_cistruct llvmpipe_context {
59bf215546Sopenharmony_ci   struct pipe_context pipe;  /**< base class */
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_ci   struct list_head list;
62bf215546Sopenharmony_ci   /** Constant state objects */
63bf215546Sopenharmony_ci   const struct pipe_blend_state *blend;
64bf215546Sopenharmony_ci   struct pipe_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
65bf215546Sopenharmony_ci
66bf215546Sopenharmony_ci   const struct pipe_depth_stencil_alpha_state *depth_stencil;
67bf215546Sopenharmony_ci   const struct pipe_rasterizer_state *rasterizer;
68bf215546Sopenharmony_ci   struct lp_fragment_shader *fs;
69bf215546Sopenharmony_ci   struct draw_vertex_shader *vs;
70bf215546Sopenharmony_ci   const struct lp_geometry_shader *gs;
71bf215546Sopenharmony_ci   const struct lp_tess_ctrl_shader *tcs;
72bf215546Sopenharmony_ci   const struct lp_tess_eval_shader *tes;
73bf215546Sopenharmony_ci   struct lp_compute_shader *cs;
74bf215546Sopenharmony_ci   const struct lp_velems_state *velems;
75bf215546Sopenharmony_ci   const struct lp_so_state *so;
76bf215546Sopenharmony_ci
77bf215546Sopenharmony_ci   /** Other rendering state */
78bf215546Sopenharmony_ci   unsigned sample_mask;
79bf215546Sopenharmony_ci   unsigned min_samples;
80bf215546Sopenharmony_ci   struct pipe_blend_color blend_color;
81bf215546Sopenharmony_ci   struct pipe_stencil_ref stencil_ref;
82bf215546Sopenharmony_ci   struct pipe_clip_state clip;
83bf215546Sopenharmony_ci   struct pipe_constant_buffer constants[PIPE_SHADER_TYPES][LP_MAX_TGSI_CONST_BUFFERS];
84bf215546Sopenharmony_ci   struct pipe_framebuffer_state framebuffer;
85bf215546Sopenharmony_ci   struct pipe_poly_stipple poly_stipple;
86bf215546Sopenharmony_ci   struct pipe_scissor_state scissors[PIPE_MAX_VIEWPORTS];
87bf215546Sopenharmony_ci   struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
88bf215546Sopenharmony_ci
89bf215546Sopenharmony_ci   struct pipe_viewport_state viewports[PIPE_MAX_VIEWPORTS];
90bf215546Sopenharmony_ci   struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_ci   struct pipe_shader_buffer ssbos[PIPE_SHADER_TYPES][LP_MAX_TGSI_SHADER_BUFFERS];
93bf215546Sopenharmony_ci   struct pipe_image_view images[PIPE_SHADER_TYPES][LP_MAX_TGSI_SHADER_IMAGES];
94bf215546Sopenharmony_ci   uint32_t fs_ssbo_write_mask;
95bf215546Sopenharmony_ci   unsigned num_samplers[PIPE_SHADER_TYPES];
96bf215546Sopenharmony_ci   unsigned num_sampler_views[PIPE_SHADER_TYPES];
97bf215546Sopenharmony_ci   unsigned num_images[PIPE_SHADER_TYPES];
98bf215546Sopenharmony_ci
99bf215546Sopenharmony_ci   unsigned num_vertex_buffers;
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_ci   struct draw_so_target *so_targets[PIPE_MAX_SO_BUFFERS];
102bf215546Sopenharmony_ci   int num_so_targets;
103bf215546Sopenharmony_ci   struct pipe_query_data_so_statistics so_stats[PIPE_MAX_VERTEX_STREAMS];
104bf215546Sopenharmony_ci
105bf215546Sopenharmony_ci   struct pipe_query_data_pipeline_statistics pipeline_statistics;
106bf215546Sopenharmony_ci   unsigned active_statistics_queries;
107bf215546Sopenharmony_ci
108bf215546Sopenharmony_ci   unsigned active_occlusion_queries;
109bf215546Sopenharmony_ci
110bf215546Sopenharmony_ci   unsigned active_primgen_queries;
111bf215546Sopenharmony_ci
112bf215546Sopenharmony_ci   bool queries_disabled;
113bf215546Sopenharmony_ci
114bf215546Sopenharmony_ci   unsigned dirty; /**< Mask of LP_NEW_x flags */
115bf215546Sopenharmony_ci   unsigned cs_dirty; /**< Mask of LP_CSNEW_x flags */
116bf215546Sopenharmony_ci   /** Mapped vertex buffers */
117bf215546Sopenharmony_ci   ubyte *mapped_vbuffer[PIPE_MAX_ATTRIBS];
118bf215546Sopenharmony_ci
119bf215546Sopenharmony_ci   /** Vertex format */
120bf215546Sopenharmony_ci   struct vertex_info vertex_info;
121bf215546Sopenharmony_ci
122bf215546Sopenharmony_ci   uint8_t patch_vertices;
123bf215546Sopenharmony_ci
124bf215546Sopenharmony_ci   /** Which vertex shader output slot contains color */
125bf215546Sopenharmony_ci   int8_t color_slot[2];
126bf215546Sopenharmony_ci
127bf215546Sopenharmony_ci   /** Which vertex shader output slot contains bcolor */
128bf215546Sopenharmony_ci   int8_t bcolor_slot[2];
129bf215546Sopenharmony_ci
130bf215546Sopenharmony_ci   /** Which vertex shader output slot contains point size */
131bf215546Sopenharmony_ci   int8_t psize_slot;
132bf215546Sopenharmony_ci
133bf215546Sopenharmony_ci   /** Which vertex shader output slot contains viewport index */
134bf215546Sopenharmony_ci   int8_t viewport_index_slot;
135bf215546Sopenharmony_ci
136bf215546Sopenharmony_ci   /** Which geometry shader output slot contains layer */
137bf215546Sopenharmony_ci   int8_t layer_slot;
138bf215546Sopenharmony_ci
139bf215546Sopenharmony_ci   /** A fake frontface output for unfilled primitives */
140bf215546Sopenharmony_ci   int8_t face_slot;
141bf215546Sopenharmony_ci
142bf215546Sopenharmony_ci   /** Depth format and bias settings. */
143bf215546Sopenharmony_ci   boolean floating_point_depth;
144bf215546Sopenharmony_ci   double mrd;   /**< minimum resolvable depth value, for polygon offset */
145bf215546Sopenharmony_ci
146bf215546Sopenharmony_ci   /** The tiling engine */
147bf215546Sopenharmony_ci   struct lp_setup_context *setup;
148bf215546Sopenharmony_ci   struct lp_setup_variant setup_variant;
149bf215546Sopenharmony_ci
150bf215546Sopenharmony_ci   /** The primitive drawing context */
151bf215546Sopenharmony_ci   struct draw_context *draw;
152bf215546Sopenharmony_ci
153bf215546Sopenharmony_ci   struct blitter_context *blitter;
154bf215546Sopenharmony_ci
155bf215546Sopenharmony_ci   unsigned tex_timestamp;
156bf215546Sopenharmony_ci
157bf215546Sopenharmony_ci   /** List of all fragment shader variants */
158bf215546Sopenharmony_ci   struct lp_fs_variant_list_item fs_variants_list;
159bf215546Sopenharmony_ci   unsigned nr_fs_variants;
160bf215546Sopenharmony_ci   unsigned nr_fs_instrs;
161bf215546Sopenharmony_ci
162bf215546Sopenharmony_ci   boolean permit_linear_rasterizer;
163bf215546Sopenharmony_ci   boolean single_vp;
164bf215546Sopenharmony_ci
165bf215546Sopenharmony_ci   struct lp_setup_variant_list_item setup_variants_list;
166bf215546Sopenharmony_ci   unsigned nr_setup_variants;
167bf215546Sopenharmony_ci
168bf215546Sopenharmony_ci   /** List of all compute shader variants */
169bf215546Sopenharmony_ci   struct lp_cs_variant_list_item cs_variants_list;
170bf215546Sopenharmony_ci   unsigned nr_cs_variants;
171bf215546Sopenharmony_ci   unsigned nr_cs_instrs;
172bf215546Sopenharmony_ci   struct lp_cs_context *csctx;
173bf215546Sopenharmony_ci
174bf215546Sopenharmony_ci   /** Conditional query object and mode */
175bf215546Sopenharmony_ci   struct pipe_query *render_cond_query;
176bf215546Sopenharmony_ci   enum pipe_render_cond_flag render_cond_mode;
177bf215546Sopenharmony_ci   boolean render_cond_cond;
178bf215546Sopenharmony_ci
179bf215546Sopenharmony_ci   /** VK render cond */
180bf215546Sopenharmony_ci   struct llvmpipe_resource *render_cond_buffer;
181bf215546Sopenharmony_ci   unsigned render_cond_offset;
182bf215546Sopenharmony_ci
183bf215546Sopenharmony_ci   /** The LLVMContext to use for LLVM related work */
184bf215546Sopenharmony_ci   LLVMContextRef context;
185bf215546Sopenharmony_ci
186bf215546Sopenharmony_ci   int max_global_buffers;
187bf215546Sopenharmony_ci   struct pipe_resource **global_buffers;
188bf215546Sopenharmony_ci
189bf215546Sopenharmony_ci};
190bf215546Sopenharmony_ci
191bf215546Sopenharmony_ci
192bf215546Sopenharmony_cistruct pipe_context *
193bf215546Sopenharmony_cillvmpipe_create_context(struct pipe_screen *screen, void *priv,
194bf215546Sopenharmony_ci                        unsigned flags);
195bf215546Sopenharmony_ci
196bf215546Sopenharmony_cistruct pipe_resource *
197bf215546Sopenharmony_cillvmpipe_user_buffer_create(struct pipe_screen *screen,
198bf215546Sopenharmony_ci                            void *ptr,
199bf215546Sopenharmony_ci                            unsigned bytes,
200bf215546Sopenharmony_ci                            unsigned bind_flags);
201bf215546Sopenharmony_ci
202bf215546Sopenharmony_ci
203bf215546Sopenharmony_cistatic inline struct llvmpipe_context *
204bf215546Sopenharmony_cillvmpipe_context( struct pipe_context *pipe )
205bf215546Sopenharmony_ci{
206bf215546Sopenharmony_ci   return (struct llvmpipe_context *)pipe;
207bf215546Sopenharmony_ci}
208bf215546Sopenharmony_ci
209bf215546Sopenharmony_ci#endif /* LP_CONTEXT_H */
210bf215546Sopenharmony_ci
211