1cdc920a0Smrg/************************************************************************** 2cdc920a0Smrg * 33464ebd5Sriastradh * Copyright 2009 VMware, Inc. 4cdc920a0Smrg * All Rights Reserved. 5cdc920a0Smrg * 6cdc920a0Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7cdc920a0Smrg * copy of this software and associated documentation files (the 8cdc920a0Smrg * "Software"), to deal in the Software without restriction, including 9cdc920a0Smrg * without limitation the rights to use, copy, modify, merge, publish, 10cdc920a0Smrg * distribute, sub license, and/or sell copies of the Software, and to 11cdc920a0Smrg * permit persons to whom the Software is furnished to do so, subject to 12cdc920a0Smrg * the following conditions: 13cdc920a0Smrg * 14cdc920a0Smrg * The above copyright notice and this permission notice (including the 15cdc920a0Smrg * next paragraph) shall be included in all copies or substantial portions 16cdc920a0Smrg * of the Software. 17cdc920a0Smrg * 18cdc920a0Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19cdc920a0Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20cdc920a0Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21af69d88dSmrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22cdc920a0Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23cdc920a0Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24cdc920a0Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25cdc920a0Smrg * 26cdc920a0Smrg **************************************************************************/ 27cdc920a0Smrg 28cdc920a0Smrg#ifndef DRAW_GS_H 29cdc920a0Smrg#define DRAW_GS_H 30cdc920a0Smrg 31cdc920a0Smrg#include "draw_context.h" 3201e04c3fSmrg#include "tgsi/tgsi_exec.h" 33cdc920a0Smrg#include "draw_private.h" 34cdc920a0Smrg 35cdc920a0Smrg#define MAX_TGSI_PRIMITIVES 4 36cdc920a0Smrg 37cdc920a0Smrgstruct draw_context; 38cdc920a0Smrg 397ec681f3Smrg#ifdef DRAW_LLVM_AVAILABLE 40af69d88dSmrgstruct draw_gs_jit_context; 41af69d88dSmrgstruct draw_gs_llvm_variant; 42af69d88dSmrg 43af69d88dSmrg/** 44af69d88dSmrg * Structure holding the inputs to the geometry shader. It uses SOA layout. 45af69d88dSmrg * The dimensions are as follows: 46af69d88dSmrg * - maximum number of vertices for a geometry shader input primitive 47af69d88dSmrg * (6 for triangle_adjacency) 48af69d88dSmrg * - maximum number of attributes for each vertex 49af69d88dSmrg * - four channels per each attribute (x,y,z,w) 50af69d88dSmrg * - number of input primitives equal to the SOA vector length 51af69d88dSmrg */ 52af69d88dSmrgstruct draw_gs_inputs { 53af69d88dSmrg float data[6][PIPE_MAX_SHADER_INPUTS][TGSI_NUM_CHANNELS][TGSI_NUM_CHANNELS]; 54af69d88dSmrg}; 55af69d88dSmrg#endif 56af69d88dSmrg 57cdc920a0Smrg/** 58cdc920a0Smrg * Private version of the compiled geometry shader 59cdc920a0Smrg */ 60361fc4cbSmayastruct draw_vertex_stream { 61361fc4cbSmaya unsigned *primitive_lengths; 62361fc4cbSmaya unsigned emitted_vertices; 63361fc4cbSmaya unsigned emitted_primitives; 64361fc4cbSmaya float (*tmp_output)[4]; 65361fc4cbSmaya}; 66361fc4cbSmaya 67cdc920a0Smrgstruct draw_geometry_shader { 68cdc920a0Smrg struct draw_context *draw; 69cdc920a0Smrg 70cdc920a0Smrg struct tgsi_exec_machine *machine; 71cdc920a0Smrg 72cdc920a0Smrg /* This member will disappear shortly:*/ 73cdc920a0Smrg struct pipe_shader_state state; 74cdc920a0Smrg 75cdc920a0Smrg struct tgsi_shader_info info; 76cdc920a0Smrg unsigned position_output; 77af69d88dSmrg unsigned viewport_index_output; 787ec681f3Smrg unsigned clipvertex_output; 7901e04c3fSmrg unsigned ccdistance_output[PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT]; 80cdc920a0Smrg 81cdc920a0Smrg unsigned max_output_vertices; 82af69d88dSmrg unsigned primitive_boundary; 83cdc920a0Smrg unsigned input_primitive; 84cdc920a0Smrg unsigned output_primitive; 853464ebd5Sriastradh unsigned vertex_size; 863464ebd5Sriastradh 87361fc4cbSmaya struct draw_vertex_stream stream[TGSI_MAX_VERTEX_STREAMS]; 88361fc4cbSmaya unsigned num_vertex_streams; 89361fc4cbSmaya 903464ebd5Sriastradh unsigned in_prim_idx; 913464ebd5Sriastradh unsigned input_vertex_stride; 92af69d88dSmrg unsigned fetched_prim_count; 933464ebd5Sriastradh const float (*input)[4]; 94af69d88dSmrg const struct tgsi_shader_info *input_info; 95af69d88dSmrg unsigned vector_length; 96af69d88dSmrg unsigned max_out_prims; 97af69d88dSmrg 9801e04c3fSmrg unsigned num_invocations; 9901e04c3fSmrg unsigned invocation_id; 1007ec681f3Smrg#ifdef DRAW_LLVM_AVAILABLE 101af69d88dSmrg struct draw_gs_inputs *gs_input; 102af69d88dSmrg struct draw_gs_jit_context *jit_context; 103af69d88dSmrg struct draw_gs_llvm_variant *current_variant; 1047ec681f3Smrg struct vertex_header *gs_output[PIPE_MAX_VERTEX_STREAMS]; 105af69d88dSmrg 106af69d88dSmrg int **llvm_prim_lengths; 107af69d88dSmrg int *llvm_emitted_primitives; 108af69d88dSmrg int *llvm_emitted_vertices; 109af69d88dSmrg int *llvm_prim_ids; 110af69d88dSmrg#endif 111af69d88dSmrg 112af69d88dSmrg void (*fetch_inputs)(struct draw_geometry_shader *shader, 113af69d88dSmrg unsigned *indices, 114af69d88dSmrg unsigned num_vertices, 115af69d88dSmrg unsigned prim_idx); 116af69d88dSmrg void (*fetch_outputs)(struct draw_geometry_shader *shader, 117361fc4cbSmaya unsigned vertex_stream, 118af69d88dSmrg unsigned num_primitives, 119af69d88dSmrg float (**p_output)[4]); 120af69d88dSmrg 121af69d88dSmrg void (*prepare)(struct draw_geometry_shader *shader, 122af69d88dSmrg const void *constants[PIPE_MAX_CONSTANT_BUFFERS], 123af69d88dSmrg const unsigned constants_size[PIPE_MAX_CONSTANT_BUFFERS]); 124361fc4cbSmaya void (*run)(struct draw_geometry_shader *shader, 125361fc4cbSmaya unsigned input_primitives, unsigned *out_prims); 126cdc920a0Smrg}; 127cdc920a0Smrg 128af69d88dSmrgvoid draw_geometry_shader_new_instance(struct draw_geometry_shader *gs); 129af69d88dSmrg 1303464ebd5Sriastradh/* 1313464ebd5Sriastradh * Returns the number of vertices emitted. 1323464ebd5Sriastradh * The vertex shader can emit any number of vertices as long as it's 1333464ebd5Sriastradh * smaller than the GS_MAX_OUTPUT_VERTICES shader property. 1343464ebd5Sriastradh */ 1353464ebd5Sriastradhint draw_geometry_shader_run(struct draw_geometry_shader *shader, 1363464ebd5Sriastradh const void *constants[PIPE_MAX_CONSTANT_BUFFERS], 1373464ebd5Sriastradh const unsigned constants_size[PIPE_MAX_CONSTANT_BUFFERS], 1383464ebd5Sriastradh const struct draw_vertex_info *input_verts, 1393464ebd5Sriastradh const struct draw_prim_info *input_prim, 140af69d88dSmrg const struct tgsi_shader_info *input_info, 1413464ebd5Sriastradh struct draw_vertex_info *output_verts, 1423464ebd5Sriastradh struct draw_prim_info *output_prims ); 143cdc920a0Smrg 144cdc920a0Smrgvoid draw_geometry_shader_prepare(struct draw_geometry_shader *shader, 145cdc920a0Smrg struct draw_context *draw); 146cdc920a0Smrg 1473464ebd5Sriastradhint draw_gs_max_output_vertices(struct draw_geometry_shader *shader, 1483464ebd5Sriastradh unsigned pipe_prim); 149cdc920a0Smrg 1507ec681f3Smrg#ifdef DRAW_LLVM_AVAILABLE 151af69d88dSmrgvoid draw_gs_set_current_variant(struct draw_geometry_shader *shader, 152af69d88dSmrg struct draw_gs_llvm_variant *variant); 153af69d88dSmrg#endif 154af69d88dSmrg 155cdc920a0Smrg#endif 156