2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
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:
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.
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.
26 **********************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
33 #include "main/compiler.h"
34 #include "brw_context.h"
37 #include "brw_state.h"
38 #include "program/prog_print.h"
39 #include "program/prog_parameter.h"
41 #include "../glsl/ralloc.h"
43 static void do_vs_prog( struct brw_context
*brw
,
44 struct brw_vertex_program
*vp
,
45 struct brw_vs_prog_key
*key
)
47 struct gl_context
*ctx
= &brw
->intel
.ctx
;
48 struct intel_context
*intel
= &brw
->intel
;
50 const GLuint
*program
;
51 struct brw_vs_compile c
;
55 static int new_vs
= -1;
57 memset(&c
, 0, sizeof(c
));
58 memcpy(&c
.key
, key
, sizeof(*key
));
60 mem_ctx
= ralloc_context(NULL
);
62 brw_init_compile(brw
, &c
.func
, mem_ctx
);
65 c
.prog_data
.outputs_written
= vp
->program
.Base
.OutputsWritten
;
66 c
.prog_data
.inputs_read
= vp
->program
.Base
.InputsRead
;
68 if (c
.key
.copy_edgeflag
) {
69 c
.prog_data
.outputs_written
|= BITFIELD64_BIT(VERT_RESULT_EDGE
);
70 c
.prog_data
.inputs_read
|= 1<<VERT_ATTRIB_EDGEFLAG
;
73 /* Put dummy slots into the VUE for the SF to put the replaced
74 * point sprite coords in. We shouldn't need these dummy slots,
75 * which take up precious URB space, but it would mean that the SF
76 * doesn't get nice aligned pairs of input coords into output
77 * coords, which would be a pain to handle.
79 for (i
= 0; i
< 8; i
++) {
80 if (c
.key
.point_coord_replace
& (1 << i
))
81 c
.prog_data
.outputs_written
|= BITFIELD64_BIT(VERT_RESULT_TEX0
+ i
);
85 _mesa_fprint_program_opt(stdout
, &c
.vp
->program
.Base
, PROG_PRINT_DEBUG
,
92 new_vs
= getenv("INTEL_NEW_VS") != NULL
;
101 /* Scratch space is used for register spilling */
102 if (c
.last_scratch
) {
103 c
.prog_data
.total_scratch
= brw_get_scratch_size(c
.last_scratch
);
105 brw_get_scratch_bo(intel
, &brw
->vs
.scratch_bo
,
106 c
.prog_data
.total_scratch
* brw
->vs_max_threads
);
111 program
= brw_get_program(&c
.func
, &program_size
);
113 /* We upload from &c.prog_data including the constant_map assuming
114 * they're packed together. It would be nice to have a
115 * compile-time assert macro here.
117 assert(c
.constant_map
== (int8_t *)&c
.prog_data
+
118 sizeof(c
.prog_data
));
119 assert(ctx
->Const
.VertexProgram
.MaxNativeParameters
==
120 ARRAY_SIZE(c
.constant_map
));
123 aux_size
= sizeof(c
.prog_data
);
125 aux_size
+= c
.vp
->program
.Base
.Parameters
->NumParameters
;
127 brw_upload_cache(&brw
->cache
, BRW_VS_PROG
,
128 &c
.key
, sizeof(c
.key
),
129 program
, program_size
,
130 &c
.prog_data
, aux_size
,
131 &brw
->vs
.prog_offset
, &brw
->vs
.prog_data
);
132 ralloc_free(mem_ctx
);
136 static void brw_upload_vs_prog(struct brw_context
*brw
)
138 struct gl_context
*ctx
= &brw
->intel
.ctx
;
139 struct brw_vs_prog_key key
;
140 struct brw_vertex_program
*vp
=
141 (struct brw_vertex_program
*)brw
->vertex_program
;
144 memset(&key
, 0, sizeof(key
));
146 /* Just upload the program verbatim for now. Always send it all
147 * the inputs it asks for, whether they are varying or not.
149 key
.program_string_id
= vp
->id
;
150 key
.nr_userclip
= brw_count_bits(ctx
->Transform
.ClipPlanesEnabled
);
151 key
.copy_edgeflag
= (ctx
->Polygon
.FrontMode
!= GL_FILL
||
152 ctx
->Polygon
.BackMode
!= GL_FILL
);
153 key
.two_side_color
= (ctx
->Light
.Enabled
&& ctx
->Light
.Model
.TwoSide
);
155 /* _NEW_LIGHT | _NEW_BUFFERS */
156 key
.clamp_vertex_color
= ctx
->Light
._ClampVertexColor
;
159 if (ctx
->Point
.PointSprite
) {
160 for (i
= 0; i
< 8; i
++) {
161 if (ctx
->Point
.CoordReplace
[i
])
162 key
.point_coord_replace
|= (1 << i
);
166 /* BRW_NEW_VERTICES */
167 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
168 if (vp
->program
.Base
.InputsRead
& (1 << i
) &&
169 brw
->vb
.inputs
[i
].glarray
->Type
== GL_FIXED
) {
170 key
.gl_fixed_input_size
[i
] = brw
->vb
.inputs
[i
].glarray
->Size
;
174 if (!brw_search_cache(&brw
->cache
, BRW_VS_PROG
,
176 &brw
->vs
.prog_offset
, &brw
->vs
.prog_data
)) {
177 do_vs_prog(brw
, vp
, &key
);
179 brw
->vs
.constant_map
= ((int8_t *)brw
->vs
.prog_data
+
180 sizeof(*brw
->vs
.prog_data
));
186 const struct brw_tracked_state brw_vs_prog
= {
188 .mesa
= (_NEW_TRANSFORM
| _NEW_POLYGON
| _NEW_POINT
| _NEW_LIGHT
|
190 .brw
= (BRW_NEW_VERTEX_PROGRAM
|
194 .prepare
= brw_upload_vs_prog