1bf215546Sopenharmony_ci/**************************************************************************
2bf215546Sopenharmony_ci *
3bf215546Sopenharmony_ci * Copyright 2009 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#ifndef DRAW_GS_H
29bf215546Sopenharmony_ci#define DRAW_GS_H
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci#include "draw_context.h"
32bf215546Sopenharmony_ci#include "tgsi/tgsi_exec.h"
33bf215546Sopenharmony_ci#include "draw_private.h"
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ci#define MAX_TGSI_PRIMITIVES 4
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_cistruct draw_context;
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci#ifdef DRAW_LLVM_AVAILABLE
40bf215546Sopenharmony_cistruct draw_gs_jit_context;
41bf215546Sopenharmony_cistruct draw_gs_llvm_variant;
42bf215546Sopenharmony_ci
43bf215546Sopenharmony_ci/**
44bf215546Sopenharmony_ci * Structure holding the inputs to the geometry shader. It uses SOA layout.
45bf215546Sopenharmony_ci * The dimensions are as follows:
46bf215546Sopenharmony_ci * - maximum number of vertices for a geometry shader input primitive
47bf215546Sopenharmony_ci *   (6 for triangle_adjacency)
48bf215546Sopenharmony_ci * - maximum number of attributes for each vertex
49bf215546Sopenharmony_ci * - four channels per each attribute (x,y,z,w)
50bf215546Sopenharmony_ci * - number of input primitives equal to the SOA vector length
51bf215546Sopenharmony_ci */
52bf215546Sopenharmony_cistruct draw_gs_inputs {
53bf215546Sopenharmony_ci   float data[6][PIPE_MAX_SHADER_INPUTS][TGSI_NUM_CHANNELS][TGSI_NUM_CHANNELS];
54bf215546Sopenharmony_ci};
55bf215546Sopenharmony_ci#endif
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_ci/**
58bf215546Sopenharmony_ci * Private version of the compiled geometry shader
59bf215546Sopenharmony_ci */
60bf215546Sopenharmony_cistruct draw_vertex_stream {
61bf215546Sopenharmony_ci   unsigned *primitive_lengths;
62bf215546Sopenharmony_ci   unsigned emitted_vertices;
63bf215546Sopenharmony_ci   unsigned emitted_primitives;
64bf215546Sopenharmony_ci   float (*tmp_output)[4];
65bf215546Sopenharmony_ci};
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_cistruct draw_geometry_shader {
68bf215546Sopenharmony_ci   struct draw_context *draw;
69bf215546Sopenharmony_ci
70bf215546Sopenharmony_ci   struct tgsi_exec_machine *machine;
71bf215546Sopenharmony_ci
72bf215546Sopenharmony_ci   /* This member will disappear shortly:*/
73bf215546Sopenharmony_ci   struct pipe_shader_state state;
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_ci   struct tgsi_shader_info info;
76bf215546Sopenharmony_ci   unsigned position_output;
77bf215546Sopenharmony_ci   unsigned viewport_index_output;
78bf215546Sopenharmony_ci   unsigned clipvertex_output;
79bf215546Sopenharmony_ci   unsigned ccdistance_output[PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT];
80bf215546Sopenharmony_ci
81bf215546Sopenharmony_ci   unsigned max_output_vertices;
82bf215546Sopenharmony_ci   unsigned primitive_boundary;
83bf215546Sopenharmony_ci   unsigned input_primitive;
84bf215546Sopenharmony_ci   unsigned output_primitive;
85bf215546Sopenharmony_ci   unsigned vertex_size;
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_ci   struct draw_vertex_stream stream[TGSI_MAX_VERTEX_STREAMS];
88bf215546Sopenharmony_ci   unsigned num_vertex_streams;
89bf215546Sopenharmony_ci
90bf215546Sopenharmony_ci   unsigned in_prim_idx;
91bf215546Sopenharmony_ci   unsigned input_vertex_stride;
92bf215546Sopenharmony_ci   unsigned fetched_prim_count;
93bf215546Sopenharmony_ci   const float (*input)[4];
94bf215546Sopenharmony_ci   const struct tgsi_shader_info *input_info;
95bf215546Sopenharmony_ci   unsigned vector_length;
96bf215546Sopenharmony_ci   unsigned max_out_prims;
97bf215546Sopenharmony_ci
98bf215546Sopenharmony_ci   unsigned num_invocations;
99bf215546Sopenharmony_ci   unsigned invocation_id;
100bf215546Sopenharmony_ci#ifdef DRAW_LLVM_AVAILABLE
101bf215546Sopenharmony_ci   struct draw_gs_inputs *gs_input;
102bf215546Sopenharmony_ci   struct draw_gs_jit_context *jit_context;
103bf215546Sopenharmony_ci   struct draw_gs_llvm_variant *current_variant;
104bf215546Sopenharmony_ci   struct vertex_header *gs_output[PIPE_MAX_VERTEX_STREAMS];
105bf215546Sopenharmony_ci
106bf215546Sopenharmony_ci   int **llvm_prim_lengths;
107bf215546Sopenharmony_ci   int *llvm_emitted_primitives;
108bf215546Sopenharmony_ci   int *llvm_emitted_vertices;
109bf215546Sopenharmony_ci   int *llvm_prim_ids;
110bf215546Sopenharmony_ci#endif
111bf215546Sopenharmony_ci
112bf215546Sopenharmony_ci   void (*fetch_inputs)(struct draw_geometry_shader *shader,
113bf215546Sopenharmony_ci                        unsigned *indices,
114bf215546Sopenharmony_ci                        unsigned num_vertices,
115bf215546Sopenharmony_ci                        unsigned prim_idx);
116bf215546Sopenharmony_ci   void (*fetch_outputs)(struct draw_geometry_shader *shader,
117bf215546Sopenharmony_ci                         unsigned vertex_stream,
118bf215546Sopenharmony_ci                         unsigned num_primitives,
119bf215546Sopenharmony_ci                         float (**p_output)[4]);
120bf215546Sopenharmony_ci
121bf215546Sopenharmony_ci   void     (*prepare)(struct draw_geometry_shader *shader,
122bf215546Sopenharmony_ci                       const void *constants[PIPE_MAX_CONSTANT_BUFFERS],
123bf215546Sopenharmony_ci                       const unsigned constants_size[PIPE_MAX_CONSTANT_BUFFERS]);
124bf215546Sopenharmony_ci   void (*run)(struct draw_geometry_shader *shader,
125bf215546Sopenharmony_ci               unsigned input_primitives, unsigned *out_prims);
126bf215546Sopenharmony_ci};
127bf215546Sopenharmony_ci
128bf215546Sopenharmony_civoid draw_geometry_shader_new_instance(struct draw_geometry_shader *gs);
129bf215546Sopenharmony_ci
130bf215546Sopenharmony_ci/*
131bf215546Sopenharmony_ci * Returns the number of vertices emitted.
132bf215546Sopenharmony_ci * The vertex shader can emit any number of vertices as long as it's
133bf215546Sopenharmony_ci * smaller than the GS_MAX_OUTPUT_VERTICES shader property.
134bf215546Sopenharmony_ci */
135bf215546Sopenharmony_ciint draw_geometry_shader_run(struct draw_geometry_shader *shader,
136bf215546Sopenharmony_ci                             const void *constants[PIPE_MAX_CONSTANT_BUFFERS],
137bf215546Sopenharmony_ci                             const unsigned constants_size[PIPE_MAX_CONSTANT_BUFFERS],
138bf215546Sopenharmony_ci                             const struct draw_vertex_info *input_verts,
139bf215546Sopenharmony_ci                             const struct draw_prim_info *input_prim,
140bf215546Sopenharmony_ci                             const struct tgsi_shader_info *input_info,
141bf215546Sopenharmony_ci                             struct draw_vertex_info *output_verts,
142bf215546Sopenharmony_ci                             struct draw_prim_info *output_prims );
143bf215546Sopenharmony_ci
144bf215546Sopenharmony_civoid draw_geometry_shader_prepare(struct draw_geometry_shader *shader,
145bf215546Sopenharmony_ci                                  struct draw_context *draw);
146bf215546Sopenharmony_ci
147bf215546Sopenharmony_ciint draw_gs_max_output_vertices(struct draw_geometry_shader *shader,
148bf215546Sopenharmony_ci                                unsigned pipe_prim);
149bf215546Sopenharmony_ci
150bf215546Sopenharmony_ci#ifdef DRAW_LLVM_AVAILABLE
151bf215546Sopenharmony_civoid draw_gs_set_current_variant(struct draw_geometry_shader *shader,
152bf215546Sopenharmony_ci                                 struct draw_gs_llvm_variant *variant);
153bf215546Sopenharmony_ci#endif
154bf215546Sopenharmony_ci
155bf215546Sopenharmony_ci#endif
156