14a49301eSmrg/**************************************************************************
24a49301eSmrg *
3af69d88dSmrg * Copyright 2007 VMware, Inc.
44a49301eSmrg * All Rights Reserved.
54a49301eSmrg *
64a49301eSmrg * Permission is hereby granted, free of charge, to any person obtaining a
74a49301eSmrg * copy of this software and associated documentation files (the
84a49301eSmrg * "Software"), to deal in the Software without restriction, including
94a49301eSmrg * without limitation the rights to use, copy, modify, merge, publish,
104a49301eSmrg * distribute, sub license, and/or sell copies of the Software, and to
114a49301eSmrg * permit persons to whom the Software is furnished to do so, subject to
124a49301eSmrg * the following conditions:
134a49301eSmrg *
144a49301eSmrg * The above copyright notice and this permission notice (including the
154a49301eSmrg * next paragraph) shall be included in all copies or substantial portions
164a49301eSmrg * of the Software.
174a49301eSmrg *
184a49301eSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
194a49301eSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
204a49301eSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21af69d88dSmrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
224a49301eSmrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
234a49301eSmrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
244a49301eSmrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
254a49301eSmrg *
264a49301eSmrg **************************************************************************/
274a49301eSmrg
28af69d88dSmrg/* Authors:  Keith Whitwell <keithw@vmware.com>
294a49301eSmrg */
304a49301eSmrg
314a49301eSmrg#ifndef LP_CONTEXT_H
324a49301eSmrg#define LP_CONTEXT_H
334a49301eSmrg
344a49301eSmrg#include "pipe/p_context.h"
354a49301eSmrg
364a49301eSmrg#include "draw/draw_vertex.h"
37af69d88dSmrg#include "util/u_blitter.h"
384a49301eSmrg
394a49301eSmrg#include "lp_tex_sample.h"
404a49301eSmrg#include "lp_jit.h"
413464ebd5Sriastradh#include "lp_setup.h"
423464ebd5Sriastradh#include "lp_state_fs.h"
437ec681f3Smrg#include "lp_state_cs.h"
443464ebd5Sriastradh#include "lp_state_setup.h"
454a49301eSmrg
464a49301eSmrg
474a49301eSmrgstruct llvmpipe_vbuf_render;
484a49301eSmrgstruct draw_context;
494a49301eSmrgstruct draw_stage;
50af69d88dSmrgstruct draw_vertex_shader;
514a49301eSmrgstruct lp_fragment_shader;
527ec681f3Smrgstruct lp_compute_shader;
534a49301eSmrgstruct lp_blend_state;
543464ebd5Sriastradhstruct lp_setup_context;
553464ebd5Sriastradhstruct lp_setup_variant;
563464ebd5Sriastradhstruct lp_velems_state;
574a49301eSmrg
584a49301eSmrgstruct llvmpipe_context {
594a49301eSmrg   struct pipe_context pipe;  /**< base class */
604a49301eSmrg
614a49301eSmrg   /** Constant state objects */
624a49301eSmrg   const struct pipe_blend_state *blend;
63af69d88dSmrg   struct pipe_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
64af69d88dSmrg
654a49301eSmrg   const struct pipe_depth_stencil_alpha_state *depth_stencil;
664a49301eSmrg   const struct pipe_rasterizer_state *rasterizer;
674a49301eSmrg   struct lp_fragment_shader *fs;
68af69d88dSmrg   struct draw_vertex_shader *vs;
693464ebd5Sriastradh   const struct lp_geometry_shader *gs;
707ec681f3Smrg   const struct lp_tess_ctrl_shader *tcs;
717ec681f3Smrg   const struct lp_tess_eval_shader *tes;
727ec681f3Smrg   struct lp_compute_shader *cs;
733464ebd5Sriastradh   const struct lp_velems_state *velems;
743464ebd5Sriastradh   const struct lp_so_state *so;
754a49301eSmrg
764a49301eSmrg   /** Other rendering state */
77af69d88dSmrg   unsigned sample_mask;
787ec681f3Smrg   unsigned min_samples;
79cdc920a0Smrg   struct pipe_blend_color blend_color;
80cdc920a0Smrg   struct pipe_stencil_ref stencil_ref;
814a49301eSmrg   struct pipe_clip_state clip;
82af69d88dSmrg   struct pipe_constant_buffer constants[PIPE_SHADER_TYPES][LP_MAX_TGSI_CONST_BUFFERS];
834a49301eSmrg   struct pipe_framebuffer_state framebuffer;
844a49301eSmrg   struct pipe_poly_stipple poly_stipple;
85af69d88dSmrg   struct pipe_scissor_state scissors[PIPE_MAX_VIEWPORTS];
86af69d88dSmrg   struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
87af69d88dSmrg
88af69d88dSmrg   struct pipe_viewport_state viewports[PIPE_MAX_VIEWPORTS];
894a49301eSmrg   struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
90af69d88dSmrg
917ec681f3Smrg   struct pipe_shader_buffer ssbos[PIPE_SHADER_TYPES][LP_MAX_TGSI_SHADER_BUFFERS];
927ec681f3Smrg   struct pipe_image_view images[PIPE_SHADER_TYPES][LP_MAX_TGSI_SHADER_IMAGES];
937ec681f3Smrg
94af69d88dSmrg   unsigned num_samplers[PIPE_SHADER_TYPES];
95af69d88dSmrg   unsigned num_sampler_views[PIPE_SHADER_TYPES];
967ec681f3Smrg   unsigned num_images[PIPE_SHADER_TYPES];
97af69d88dSmrg
984a49301eSmrg   unsigned num_vertex_buffers;
994a49301eSmrg
100af69d88dSmrg   struct draw_so_target *so_targets[PIPE_MAX_SO_BUFFERS];
101af69d88dSmrg   int num_so_targets;
1027ec681f3Smrg   struct pipe_query_data_so_statistics so_stats[PIPE_MAX_VERTEX_STREAMS];
1034a49301eSmrg
104af69d88dSmrg   struct pipe_query_data_pipeline_statistics pipeline_statistics;
105af69d88dSmrg   unsigned active_statistics_queries;
106af69d88dSmrg
107af69d88dSmrg   unsigned active_occlusion_queries;
108af69d88dSmrg
1097ec681f3Smrg   unsigned active_primgen_queries;
1107ec681f3Smrg
1117ec681f3Smrg   bool queries_disabled;
1124a49301eSmrg
1137ec681f3Smrg   unsigned dirty; /**< Mask of LP_NEW_x flags */
1147ec681f3Smrg   unsigned cs_dirty; /**< Mask of LP_CSNEW_x flags */
1154a49301eSmrg   /** Mapped vertex buffers */
1164a49301eSmrg   ubyte *mapped_vbuffer[PIPE_MAX_ATTRIBS];
1174a49301eSmrg
1184a49301eSmrg   /** Vertex format */
1194a49301eSmrg   struct vertex_info vertex_info;
1207ec681f3Smrg
1217ec681f3Smrg   uint8_t patch_vertices;
1223464ebd5Sriastradh
1233464ebd5Sriastradh   /** Which vertex shader output slot contains color */
12401e04c3fSmrg   int8_t color_slot[2];
1253464ebd5Sriastradh
1263464ebd5Sriastradh   /** Which vertex shader output slot contains bcolor */
12701e04c3fSmrg   int8_t bcolor_slot[2];
1284a49301eSmrg
1294a49301eSmrg   /** Which vertex shader output slot contains point size */
13001e04c3fSmrg   int8_t psize_slot;
1314a49301eSmrg
132af69d88dSmrg   /** Which vertex shader output slot contains viewport index */
13301e04c3fSmrg   int8_t viewport_index_slot;
134af69d88dSmrg
135af69d88dSmrg   /** Which geometry shader output slot contains layer */
13601e04c3fSmrg   int8_t layer_slot;
137af69d88dSmrg
138af69d88dSmrg   /** A fake frontface output for unfilled primitives */
13901e04c3fSmrg   int8_t face_slot;
140af69d88dSmrg
141af69d88dSmrg   /** Depth format and bias settings. */
142af69d88dSmrg   boolean floating_point_depth;
143af69d88dSmrg   double mrd;   /**< minimum resolvable depth value, for polygon offset */
144af69d88dSmrg
145cdc920a0Smrg   /** The tiling engine */
1463464ebd5Sriastradh   struct lp_setup_context *setup;
1473464ebd5Sriastradh   struct lp_setup_variant setup_variant;
1484a49301eSmrg
1494a49301eSmrg   /** The primitive drawing context */
1504a49301eSmrg   struct draw_context *draw;
1514a49301eSmrg
152af69d88dSmrg   struct blitter_context *blitter;
153af69d88dSmrg
1544a49301eSmrg   unsigned tex_timestamp;
1554a49301eSmrg
1563464ebd5Sriastradh   /** List of all fragment shader variants */
1573464ebd5Sriastradh   struct lp_fs_variant_list_item fs_variants_list;
1583464ebd5Sriastradh   unsigned nr_fs_variants;
159af69d88dSmrg   unsigned nr_fs_instrs;
1603464ebd5Sriastradh
1617ec681f3Smrg   boolean permit_linear_rasterizer;
1627ec681f3Smrg   boolean single_vp;
1637ec681f3Smrg
1643464ebd5Sriastradh   struct lp_setup_variant_list_item setup_variants_list;
1653464ebd5Sriastradh   unsigned nr_setup_variants;
1664a49301eSmrg
1677ec681f3Smrg   /** List of all compute shader variants */
1687ec681f3Smrg   struct lp_cs_variant_list_item cs_variants_list;
1697ec681f3Smrg   unsigned nr_cs_variants;
1707ec681f3Smrg   unsigned nr_cs_instrs;
1717ec681f3Smrg   struct lp_cs_context *csctx;
1727ec681f3Smrg
173af69d88dSmrg   /** Conditional query object and mode */
174af69d88dSmrg   struct pipe_query *render_cond_query;
17501e04c3fSmrg   enum pipe_render_cond_flag render_cond_mode;
176af69d88dSmrg   boolean render_cond_cond;
17701e04c3fSmrg
1787ec681f3Smrg   /** VK render cond */
1797ec681f3Smrg   struct llvmpipe_resource *render_cond_buffer;
1807ec681f3Smrg   unsigned render_cond_offset;
1817ec681f3Smrg
18201e04c3fSmrg   /** The LLVMContext to use for LLVM related work */
18301e04c3fSmrg   LLVMContextRef context;
1847ec681f3Smrg
1857ec681f3Smrg   int max_global_buffers;
1867ec681f3Smrg   struct pipe_resource **global_buffers;
1877ec681f3Smrg
188af69d88dSmrg};
1893464ebd5Sriastradh
1903464ebd5Sriastradh
191cdc920a0Smrgstruct pipe_context *
19201e04c3fSmrgllvmpipe_create_context(struct pipe_screen *screen, void *priv,
19301e04c3fSmrg                        unsigned flags);
194cdc920a0Smrg
195af69d88dSmrgstruct pipe_resource *
196af69d88dSmrgllvmpipe_user_buffer_create(struct pipe_screen *screen,
197af69d88dSmrg                            void *ptr,
198af69d88dSmrg                            unsigned bytes,
199af69d88dSmrg                            unsigned bind_flags);
200af69d88dSmrg
201cdc920a0Smrg
20201e04c3fSmrgstatic inline struct llvmpipe_context *
2034a49301eSmrgllvmpipe_context( struct pipe_context *pipe )
2044a49301eSmrg{
2054a49301eSmrg   return (struct llvmpipe_context *)pipe;
2064a49301eSmrg}
2074a49301eSmrg
2084a49301eSmrg#endif /* LP_CONTEXT_H */
2094a49301eSmrg
210