1848b8605Smrg/************************************************************************** 2848b8605Smrg * 3848b8605Smrg * Copyright 2007 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 /* 29848b8605Smrg * Authors: 30848b8605Smrg * Keith Whitwell <keithw@vmware.com> 31848b8605Smrg */ 32848b8605Smrg 33848b8605Smrg#ifndef DRAW_PT_H 34848b8605Smrg#define DRAW_PT_H 35848b8605Smrg 36848b8605Smrg#include "pipe/p_compiler.h" 37848b8605Smrg 38848b8605Smrgstruct draw_pt_middle_end; 39848b8605Smrgstruct draw_context; 40848b8605Smrgstruct draw_prim_info; 41848b8605Smrgstruct draw_vertex_info; 42848b8605Smrg 43848b8605Smrg 44848b8605Smrg#define PT_SHADE 0x1 45848b8605Smrg#define PT_CLIPTEST 0x2 46848b8605Smrg#define PT_PIPELINE 0x4 47848b8605Smrg#define PT_MAX_MIDDLE 0x8 48848b8605Smrg 49848b8605Smrg 50848b8605Smrg/* The "front end" - prepare sets of fetch, draw elements for the 51848b8605Smrg * middle end. 52848b8605Smrg * 53848b8605Smrg * The fetch elements are indices to the vertices. The draw elements are 54848b8605Smrg * indices to the fetched vertices. When both arrays of elements are both 55848b8605Smrg * linear, middle->run_linear is called; When only the fetch elements are 56848b8605Smrg * linear, middle->run_linear_elts is called; Otherwise, middle->run is 57848b8605Smrg * called. 58848b8605Smrg * 59848b8605Smrg * When the number of the draw elements exceeds max_vertex of the middle end, 60848b8605Smrg * the draw elements (as well as the fetch elements) are splitted and the 61848b8605Smrg * middle end is called multiple times. 62848b8605Smrg * 63848b8605Smrg * Currenly there is: 64848b8605Smrg * - vsplit - catchall implementation, splits big prims 65848b8605Smrg */ 66848b8605Smrgstruct draw_pt_front_end { 67848b8605Smrg void (*prepare)( struct draw_pt_front_end *, 68848b8605Smrg unsigned prim, 69848b8605Smrg struct draw_pt_middle_end *, 70848b8605Smrg unsigned opt ); 71848b8605Smrg 72848b8605Smrg void (*run)( struct draw_pt_front_end *, 73848b8605Smrg unsigned start, 74848b8605Smrg unsigned count ); 75848b8605Smrg 76848b8605Smrg void (*flush)( struct draw_pt_front_end *, unsigned flags ); 77848b8605Smrg void (*destroy)( struct draw_pt_front_end * ); 78848b8605Smrg}; 79848b8605Smrg 80848b8605Smrg 81848b8605Smrg/* The "middle end" - prepares actual hardware vertices for the 82848b8605Smrg * hardware backend. 83848b8605Smrg * 84848b8605Smrg * prim_flags is as defined by pipe_draw_info::flags. 85848b8605Smrg * 86848b8605Smrg * Currently two versions of this: 87848b8605Smrg * - fetch, vertex shade, cliptest, prim-pipeline 88848b8605Smrg * - fetch, emit (ie passthrough) 89848b8605Smrg */ 90848b8605Smrgstruct draw_pt_middle_end { 91848b8605Smrg void (*prepare)( struct draw_pt_middle_end *, 92848b8605Smrg unsigned prim, 93848b8605Smrg unsigned opt, 94848b8605Smrg unsigned *max_vertices ); 95848b8605Smrg 96848b8605Smrg /** 97848b8605Smrg * Bind/update parameter state such as constants, viewport dims 98848b8605Smrg * and clip planes. Basically, stuff which isn't "baked" into the 99848b8605Smrg * shader or pipeline state. 100848b8605Smrg */ 101848b8605Smrg void (*bind_parameters)(struct draw_pt_middle_end *); 102848b8605Smrg 103848b8605Smrg void (*run)( struct draw_pt_middle_end *, 104848b8605Smrg const unsigned *fetch_elts, 105848b8605Smrg unsigned fetch_count, 106848b8605Smrg const ushort *draw_elts, 107848b8605Smrg unsigned draw_count, 108848b8605Smrg unsigned prim_flags ); 109848b8605Smrg 110848b8605Smrg void (*run_linear)(struct draw_pt_middle_end *, 111848b8605Smrg unsigned start, 112848b8605Smrg unsigned count, 113848b8605Smrg unsigned prim_flags ); 114848b8605Smrg 115848b8605Smrg /* Transform all vertices in a linear range and then draw them with 116848b8605Smrg * the supplied element list. May fail and return FALSE. 117848b8605Smrg */ 118848b8605Smrg boolean (*run_linear_elts)( struct draw_pt_middle_end *, 119848b8605Smrg unsigned fetch_start, 120848b8605Smrg unsigned fetch_count, 121848b8605Smrg const ushort *draw_elts, 122848b8605Smrg unsigned draw_count, 123848b8605Smrg unsigned prim_flags ); 124848b8605Smrg 125848b8605Smrg int (*get_max_vertex_count)( struct draw_pt_middle_end * ); 126848b8605Smrg 127848b8605Smrg void (*finish)( struct draw_pt_middle_end * ); 128848b8605Smrg void (*destroy)( struct draw_pt_middle_end * ); 129848b8605Smrg}; 130848b8605Smrg 131848b8605Smrg 132848b8605Smrg/* The "back end" - supplied by the driver, defined in draw_vbuf.h. 133848b8605Smrg */ 134848b8605Smrgstruct vbuf_render; 135848b8605Smrgstruct vertex_header; 136848b8605Smrg 137848b8605Smrg 138848b8605Smrg/* Frontends: 139848b8605Smrg * 140848b8605Smrg * Currently only the general-purpose vsplit implementation. 141848b8605Smrg */ 142848b8605Smrgstruct draw_pt_front_end *draw_pt_vsplit(struct draw_context *draw); 143848b8605Smrg 144848b8605Smrg 145848b8605Smrg/* Middle-ends: 146848b8605Smrg * 147848b8605Smrg * Currently one general-purpose case which can do all possibilities, 148848b8605Smrg * at the slight expense of creating a vertex_header in some cases 149848b8605Smrg * unecessarily. 150848b8605Smrg * 151848b8605Smrg * The special case fetch_emit code avoids pipeline vertices 152848b8605Smrg * altogether and builds hardware vertices directly from API 153848b8605Smrg * vertex_elements. 154848b8605Smrg */ 155848b8605Smrgstruct draw_pt_middle_end *draw_pt_fetch_emit( struct draw_context *draw ); 156848b8605Smrgstruct draw_pt_middle_end *draw_pt_middle_fse( struct draw_context *draw ); 157848b8605Smrgstruct draw_pt_middle_end *draw_pt_fetch_pipeline_or_emit(struct draw_context *draw); 158848b8605Smrgstruct draw_pt_middle_end *draw_pt_fetch_pipeline_or_emit_llvm(struct draw_context *draw); 159848b8605Smrg 160848b8605Smrg 161848b8605Smrg 162848b8605Smrg/******************************************************************************* 163848b8605Smrg * HW vertex emit: 164848b8605Smrg */ 165848b8605Smrgstruct pt_emit; 166848b8605Smrg 167848b8605Smrgvoid draw_pt_emit_prepare( struct pt_emit *emit, 168848b8605Smrg unsigned prim, 169848b8605Smrg unsigned *max_vertices ); 170848b8605Smrg 171848b8605Smrgvoid draw_pt_emit( struct pt_emit *emit, 172848b8605Smrg const struct draw_vertex_info *vert_info, 173848b8605Smrg const struct draw_prim_info *prim_info); 174848b8605Smrg 175848b8605Smrgvoid draw_pt_emit_linear( struct pt_emit *emit, 176848b8605Smrg const struct draw_vertex_info *vert_info, 177848b8605Smrg const struct draw_prim_info *prim_info); 178848b8605Smrg 179848b8605Smrgvoid draw_pt_emit_destroy( struct pt_emit *emit ); 180848b8605Smrg 181848b8605Smrgstruct pt_emit *draw_pt_emit_create( struct draw_context *draw ); 182848b8605Smrg 183848b8605Smrg/******************************************************************************* 184848b8605Smrg * HW stream output emit: 185848b8605Smrg */ 186848b8605Smrgstruct pt_so_emit; 187848b8605Smrg 188848b8605Smrgvoid draw_pt_so_emit_prepare(struct pt_so_emit *emit, boolean use_pre_clip_pos); 189848b8605Smrg 190848b8605Smrgvoid draw_pt_so_emit( struct pt_so_emit *emit, 191b8e80941Smrg int num_vertex_streams, 192848b8605Smrg const struct draw_vertex_info *vert_info, 193848b8605Smrg const struct draw_prim_info *prim_info ); 194848b8605Smrg 195848b8605Smrgvoid draw_pt_so_emit_destroy( struct pt_so_emit *emit ); 196848b8605Smrg 197848b8605Smrgstruct pt_so_emit *draw_pt_so_emit_create( struct draw_context *draw ); 198848b8605Smrg 199848b8605Smrg/******************************************************************************* 200848b8605Smrg * API vertex fetch: 201848b8605Smrg */ 202848b8605Smrg 203848b8605Smrgstruct pt_fetch; 204848b8605Smrgvoid draw_pt_fetch_prepare( struct pt_fetch *fetch, 205848b8605Smrg unsigned vertex_input_count, 206848b8605Smrg unsigned vertex_size, 207848b8605Smrg unsigned instance_id_index ); 208848b8605Smrg 209848b8605Smrgvoid draw_pt_fetch_run( struct pt_fetch *fetch, 210848b8605Smrg const unsigned *elts, 211848b8605Smrg unsigned count, 212848b8605Smrg char *verts ); 213848b8605Smrg 214848b8605Smrgvoid draw_pt_fetch_run_linear( struct pt_fetch *fetch, 215848b8605Smrg unsigned start, 216848b8605Smrg unsigned count, 217848b8605Smrg char *verts ); 218848b8605Smrg 219848b8605Smrgvoid draw_pt_fetch_destroy( struct pt_fetch *fetch ); 220848b8605Smrg 221848b8605Smrgstruct pt_fetch *draw_pt_fetch_create( struct draw_context *draw ); 222848b8605Smrg 223848b8605Smrg/******************************************************************************* 224848b8605Smrg * Post-VS: cliptest, rhw, viewport 225848b8605Smrg */ 226848b8605Smrgstruct pt_post_vs; 227848b8605Smrg 228848b8605Smrgboolean draw_pt_post_vs_run( struct pt_post_vs *pvs, 229848b8605Smrg struct draw_vertex_info *info, 230848b8605Smrg const struct draw_prim_info *prim_info ); 231848b8605Smrg 232848b8605Smrgvoid draw_pt_post_vs_prepare( struct pt_post_vs *pvs, 233848b8605Smrg boolean clip_xy, 234848b8605Smrg boolean clip_z, 235848b8605Smrg boolean clip_user, 236848b8605Smrg boolean guard_band, 237848b8605Smrg boolean bypass_viewport, 238848b8605Smrg boolean clip_halfz, 239848b8605Smrg boolean need_edgeflags ); 240848b8605Smrg 241848b8605Smrgstruct pt_post_vs *draw_pt_post_vs_create( struct draw_context *draw ); 242848b8605Smrg 243848b8605Smrgvoid draw_pt_post_vs_destroy( struct pt_post_vs *pvs ); 244848b8605Smrg 245848b8605Smrg 246848b8605Smrg/******************************************************************************* 247848b8605Smrg * Utils: 248848b8605Smrg */ 249848b8605Smrgvoid draw_pt_split_prim(unsigned prim, unsigned *first, unsigned *incr); 250848b8605Smrgunsigned draw_pt_trim_count(unsigned count, unsigned first, unsigned incr); 251848b8605Smrg 252848b8605Smrg 253848b8605Smrg#endif 254