1848b8605Smrg/**************************************************************************
2848b8605Smrg *
3848b8605Smrg * Copyright 2009 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#ifndef DRAW_GS_H
29848b8605Smrg#define DRAW_GS_H
30848b8605Smrg
31848b8605Smrg#include "draw_context.h"
32b8e80941Smrg#include "tgsi/tgsi_exec.h"
33848b8605Smrg#include "draw_private.h"
34848b8605Smrg
35848b8605Smrg#define MAX_TGSI_PRIMITIVES 4
36848b8605Smrg
37848b8605Smrgstruct draw_context;
38848b8605Smrg
39848b8605Smrg#ifdef HAVE_LLVM
40848b8605Smrgstruct draw_gs_jit_context;
41848b8605Smrgstruct draw_gs_llvm_variant;
42848b8605Smrg
43848b8605Smrg/**
44848b8605Smrg * Structure holding the inputs to the geometry shader. It uses SOA layout.
45848b8605Smrg * The dimensions are as follows:
46848b8605Smrg * - maximum number of vertices for a geometry shader input primitive
47848b8605Smrg *   (6 for triangle_adjacency)
48848b8605Smrg * - maximum number of attributes for each vertex
49848b8605Smrg * - four channels per each attribute (x,y,z,w)
50848b8605Smrg * - number of input primitives equal to the SOA vector length
51848b8605Smrg */
52848b8605Smrgstruct draw_gs_inputs {
53848b8605Smrg   float data[6][PIPE_MAX_SHADER_INPUTS][TGSI_NUM_CHANNELS][TGSI_NUM_CHANNELS];
54848b8605Smrg};
55848b8605Smrg#endif
56848b8605Smrg
57848b8605Smrg/**
58848b8605Smrg * Private version of the compiled geometry shader
59848b8605Smrg */
60b8e80941Smrgstruct draw_vertex_stream {
61b8e80941Smrg   unsigned *primitive_lengths;
62b8e80941Smrg   unsigned emitted_vertices;
63b8e80941Smrg   unsigned emitted_primitives;
64b8e80941Smrg   float (*tmp_output)[4];
65b8e80941Smrg};
66b8e80941Smrg
67848b8605Smrgstruct draw_geometry_shader {
68848b8605Smrg   struct draw_context *draw;
69848b8605Smrg
70848b8605Smrg   struct tgsi_exec_machine *machine;
71848b8605Smrg
72848b8605Smrg   /* This member will disappear shortly:*/
73848b8605Smrg   struct pipe_shader_state state;
74848b8605Smrg
75848b8605Smrg   struct tgsi_shader_info info;
76848b8605Smrg   unsigned position_output;
77848b8605Smrg   unsigned viewport_index_output;
78b8e80941Smrg   unsigned ccdistance_output[PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT];
79848b8605Smrg
80848b8605Smrg   unsigned max_output_vertices;
81848b8605Smrg   unsigned primitive_boundary;
82848b8605Smrg   unsigned input_primitive;
83848b8605Smrg   unsigned output_primitive;
84848b8605Smrg   unsigned vertex_size;
85848b8605Smrg
86b8e80941Smrg   struct draw_vertex_stream stream[TGSI_MAX_VERTEX_STREAMS];
87b8e80941Smrg   unsigned num_vertex_streams;
88b8e80941Smrg
89848b8605Smrg   unsigned in_prim_idx;
90848b8605Smrg   unsigned input_vertex_stride;
91848b8605Smrg   unsigned fetched_prim_count;
92848b8605Smrg   const float (*input)[4];
93848b8605Smrg   const struct tgsi_shader_info *input_info;
94848b8605Smrg   unsigned vector_length;
95848b8605Smrg   unsigned max_out_prims;
96848b8605Smrg
97b8e80941Smrg   unsigned num_invocations;
98b8e80941Smrg   unsigned invocation_id;
99848b8605Smrg#ifdef HAVE_LLVM
100848b8605Smrg   struct draw_gs_inputs *gs_input;
101848b8605Smrg   struct draw_gs_jit_context *jit_context;
102848b8605Smrg   struct draw_gs_llvm_variant *current_variant;
103848b8605Smrg   struct vertex_header *gs_output;
104848b8605Smrg
105848b8605Smrg   int **llvm_prim_lengths;
106848b8605Smrg   int *llvm_emitted_primitives;
107848b8605Smrg   int *llvm_emitted_vertices;
108848b8605Smrg   int *llvm_prim_ids;
109848b8605Smrg#endif
110848b8605Smrg
111848b8605Smrg   void (*fetch_inputs)(struct draw_geometry_shader *shader,
112848b8605Smrg                        unsigned *indices,
113848b8605Smrg                        unsigned num_vertices,
114848b8605Smrg                        unsigned prim_idx);
115848b8605Smrg   void (*fetch_outputs)(struct draw_geometry_shader *shader,
116b8e80941Smrg                         unsigned vertex_stream,
117848b8605Smrg                         unsigned num_primitives,
118848b8605Smrg                         float (**p_output)[4]);
119848b8605Smrg
120848b8605Smrg   void     (*prepare)(struct draw_geometry_shader *shader,
121848b8605Smrg                       const void *constants[PIPE_MAX_CONSTANT_BUFFERS],
122848b8605Smrg                       const unsigned constants_size[PIPE_MAX_CONSTANT_BUFFERS]);
123b8e80941Smrg   void (*run)(struct draw_geometry_shader *shader,
124b8e80941Smrg               unsigned input_primitives, unsigned *out_prims);
125848b8605Smrg};
126848b8605Smrg
127848b8605Smrgvoid draw_geometry_shader_new_instance(struct draw_geometry_shader *gs);
128848b8605Smrg
129848b8605Smrg/*
130848b8605Smrg * Returns the number of vertices emitted.
131848b8605Smrg * The vertex shader can emit any number of vertices as long as it's
132848b8605Smrg * smaller than the GS_MAX_OUTPUT_VERTICES shader property.
133848b8605Smrg */
134848b8605Smrgint draw_geometry_shader_run(struct draw_geometry_shader *shader,
135848b8605Smrg                             const void *constants[PIPE_MAX_CONSTANT_BUFFERS],
136848b8605Smrg                             const unsigned constants_size[PIPE_MAX_CONSTANT_BUFFERS],
137848b8605Smrg                             const struct draw_vertex_info *input_verts,
138848b8605Smrg                             const struct draw_prim_info *input_prim,
139848b8605Smrg                             const struct tgsi_shader_info *input_info,
140848b8605Smrg                             struct draw_vertex_info *output_verts,
141848b8605Smrg                             struct draw_prim_info *output_prims );
142848b8605Smrg
143848b8605Smrgvoid draw_geometry_shader_prepare(struct draw_geometry_shader *shader,
144848b8605Smrg                                  struct draw_context *draw);
145848b8605Smrg
146848b8605Smrgint draw_gs_max_output_vertices(struct draw_geometry_shader *shader,
147848b8605Smrg                                unsigned pipe_prim);
148848b8605Smrg
149848b8605Smrg#ifdef HAVE_LLVM
150848b8605Smrgvoid draw_gs_set_current_variant(struct draw_geometry_shader *shader,
151848b8605Smrg                                 struct draw_gs_llvm_variant *variant);
152848b8605Smrg#endif
153848b8605Smrg
154848b8605Smrg#endif
155