1 /*
2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics to
4 develop this 3D driver.
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
13
14 The above copyright notice and this permission notice (including the
15 next paragraph) shall be included in all copies or substantial
16 portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **********************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keithw@vmware.com>
30 */
31
32 #pragma once
33
34 #include "elk_compiler.h"
35 #include "elk_eu.h"
36
37 /* Initial 3 verts, plus at most 6 additional verts from intersections
38 * with fixed planes, plus at most 8 additional verts from intersections
39 * with user clip planes
40 */
41 #define MAX_VERTS (3+6+8)
42
43 #define PRIM_MASK (0x1f)
44
45 struct elk_clip_compile {
46 struct elk_codegen func;
47 struct elk_clip_prog_key key;
48 struct elk_clip_prog_data prog_data;
49
50 struct {
51 struct elk_reg R0;
52 struct elk_reg vertex[MAX_VERTS];
53
54 struct elk_reg t;
55 struct elk_reg t0, t1;
56 struct elk_reg dp0, dp1;
57
58 struct elk_reg dpPrev;
59 struct elk_reg dp;
60 struct elk_reg loopcount;
61 struct elk_reg nr_verts;
62 struct elk_reg planemask;
63
64 struct elk_reg inlist;
65 struct elk_reg outlist;
66 struct elk_reg freelist;
67
68 struct elk_reg dir;
69 struct elk_reg tmp0, tmp1;
70 struct elk_reg offset;
71
72 struct elk_reg fixed_planes;
73 struct elk_reg plane_equation;
74
75 struct elk_reg ff_sync;
76
77 /* Bitmask indicating which coordinate attribute should be used for
78 * comparison to each clipping plane. A 0 indicates that VARYING_SLOT_POS
79 * should be used, because it's one of the fixed +/- x/y/z planes that
80 * constitute the bounds of the view volume. A 1 indicates that
81 * VARYING_SLOT_CLIP_VERTEX should be used (if available) since it's a user-
82 * defined clipping plane.
83 */
84 struct elk_reg vertex_src_mask;
85
86 /* Offset into the vertex of the current plane's clipdistance value */
87 struct elk_reg clipdistance_offset;
88 } reg;
89
90 /* Number of registers storing VUE data */
91 GLuint nr_regs;
92
93 GLuint first_tmp;
94 GLuint last_tmp;
95
96 bool need_direction;
97
98 struct intel_vue_map vue_map;
99 };
100
101 /**
102 * True if the given varying is one of the outputs of the vertex shader.
103 */
elk_clip_have_varying(struct elk_clip_compile * c,GLuint varying)104 static inline bool elk_clip_have_varying(struct elk_clip_compile *c,
105 GLuint varying)
106 {
107 return (c->key.attrs & BITFIELD64_BIT(varying)) ? 1 : 0;
108 }
109
110 /* Points are only culled, so no need for a clip routine, however it
111 * works out easier to have a dummy one.
112 */
113 void elk_emit_unfilled_clip( struct elk_clip_compile *c );
114 void elk_emit_tri_clip( struct elk_clip_compile *c );
115 void elk_emit_line_clip( struct elk_clip_compile *c );
116 void elk_emit_point_clip( struct elk_clip_compile *c );
117
118 /* elk_clip_tri.c, for use by the unfilled clip routine:
119 */
120 void elk_clip_tri_init_vertices( struct elk_clip_compile *c );
121 void elk_clip_tri_flat_shade( struct elk_clip_compile *c );
122 void elk_clip_tri( struct elk_clip_compile *c );
123 void elk_clip_tri_emit_polygon( struct elk_clip_compile *c );
124 void elk_clip_tri_alloc_regs( struct elk_clip_compile *c,
125 GLuint nr_verts );
126
127
128 /* Utils:
129 */
130
131 void elk_clip_interp_vertex( struct elk_clip_compile *c,
132 struct elk_indirect dest_ptr,
133 struct elk_indirect v0_ptr, /* from */
134 struct elk_indirect v1_ptr, /* to */
135 struct elk_reg t0,
136 bool force_edgeflag );
137
138 void elk_clip_init_planes( struct elk_clip_compile *c );
139
140 void elk_clip_emit_vue(struct elk_clip_compile *c,
141 struct elk_indirect vert,
142 enum elk_urb_write_flags flags,
143 GLuint header);
144
145 void elk_clip_kill_thread(struct elk_clip_compile *c);
146
147 struct elk_reg elk_clip_plane_stride( struct elk_clip_compile *c );
148 struct elk_reg elk_clip_plane0_address( struct elk_clip_compile *c );
149
150 void elk_clip_copy_flatshaded_attributes( struct elk_clip_compile *c,
151 GLuint to, GLuint from );
152
153 void elk_clip_init_clipmask( struct elk_clip_compile *c );
154
155 struct elk_reg get_tmp( struct elk_clip_compile *c );
156
157 void elk_clip_project_position(struct elk_clip_compile *c,
158 struct elk_reg pos );
159 void elk_clip_ff_sync(struct elk_clip_compile *c);
160 void elk_clip_init_ff_sync(struct elk_clip_compile *c);
161