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"
44 do_vs_prog(struct brw_context
*brw
,
45 struct gl_shader_program
*prog
,
46 struct brw_vertex_program
*vp
,
47 struct brw_vs_prog_key
*key
)
49 struct gl_context
*ctx
= &brw
->intel
.ctx
;
50 struct intel_context
*intel
= &brw
->intel
;
52 const GLuint
*program
;
53 struct brw_vs_compile c
;
57 static int new_vs
= -1;
59 memset(&c
, 0, sizeof(c
));
60 memcpy(&c
.key
, key
, sizeof(*key
));
62 mem_ctx
= ralloc_context(NULL
);
64 brw_init_compile(brw
, &c
.func
, mem_ctx
);
67 c
.prog_data
.outputs_written
= vp
->program
.Base
.OutputsWritten
;
68 c
.prog_data
.inputs_read
= vp
->program
.Base
.InputsRead
;
70 if (c
.key
.copy_edgeflag
) {
71 c
.prog_data
.outputs_written
|= BITFIELD64_BIT(VERT_RESULT_EDGE
);
72 c
.prog_data
.inputs_read
|= 1<<VERT_ATTRIB_EDGEFLAG
;
75 /* Put dummy slots into the VUE for the SF to put the replaced
76 * point sprite coords in. We shouldn't need these dummy slots,
77 * which take up precious URB space, but it would mean that the SF
78 * doesn't get nice aligned pairs of input coords into output
79 * coords, which would be a pain to handle.
81 for (i
= 0; i
< 8; i
++) {
82 if (c
.key
.point_coord_replace
& (1 << i
))
83 c
.prog_data
.outputs_written
|= BITFIELD64_BIT(VERT_RESULT_TEX0
+ i
);
87 _mesa_fprint_program_opt(stdout
, &c
.vp
->program
.Base
, PROG_PRINT_DEBUG
,
94 new_vs
= getenv("INTEL_NEW_VS") != NULL
;
97 if (!brw_vs_emit(prog
, &c
)) {
105 /* Scratch space is used for register spilling */
106 if (c
.last_scratch
) {
107 c
.prog_data
.total_scratch
= brw_get_scratch_size(c
.last_scratch
);
109 brw_get_scratch_bo(intel
, &brw
->vs
.scratch_bo
,
110 c
.prog_data
.total_scratch
* brw
->vs_max_threads
);
115 program
= brw_get_program(&c
.func
, &program_size
);
117 /* We upload from &c.prog_data including the constant_map assuming
118 * they're packed together. It would be nice to have a
119 * compile-time assert macro here.
121 assert(c
.constant_map
== (int8_t *)&c
.prog_data
+
122 sizeof(c
.prog_data
));
123 assert(ctx
->Const
.VertexProgram
.MaxNativeParameters
==
124 ARRAY_SIZE(c
.constant_map
));
127 aux_size
= sizeof(c
.prog_data
);
129 aux_size
+= c
.vp
->program
.Base
.Parameters
->NumParameters
;
131 brw_upload_cache(&brw
->cache
, BRW_VS_PROG
,
132 &c
.key
, sizeof(c
.key
),
133 program
, program_size
,
134 &c
.prog_data
, aux_size
,
135 &brw
->vs
.prog_offset
, &brw
->vs
.prog_data
);
136 ralloc_free(mem_ctx
);
142 static void brw_upload_vs_prog(struct brw_context
*brw
)
144 struct gl_context
*ctx
= &brw
->intel
.ctx
;
145 struct brw_vs_prog_key key
;
146 struct brw_vertex_program
*vp
=
147 (struct brw_vertex_program
*)brw
->vertex_program
;
150 memset(&key
, 0, sizeof(key
));
152 /* Just upload the program verbatim for now. Always send it all
153 * the inputs it asks for, whether they are varying or not.
155 key
.program_string_id
= vp
->id
;
156 key
.nr_userclip
= brw_count_bits(ctx
->Transform
.ClipPlanesEnabled
);
157 key
.copy_edgeflag
= (ctx
->Polygon
.FrontMode
!= GL_FILL
||
158 ctx
->Polygon
.BackMode
!= GL_FILL
);
159 key
.two_side_color
= (ctx
->Light
.Enabled
&& ctx
->Light
.Model
.TwoSide
);
161 /* _NEW_LIGHT | _NEW_BUFFERS */
162 key
.clamp_vertex_color
= ctx
->Light
._ClampVertexColor
;
165 if (ctx
->Point
.PointSprite
) {
166 for (i
= 0; i
< 8; i
++) {
167 if (ctx
->Point
.CoordReplace
[i
])
168 key
.point_coord_replace
|= (1 << i
);
172 /* BRW_NEW_VERTICES */
173 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
174 if (vp
->program
.Base
.InputsRead
& (1 << i
) &&
175 brw
->vb
.inputs
[i
].glarray
->Type
== GL_FIXED
) {
176 key
.gl_fixed_input_size
[i
] = brw
->vb
.inputs
[i
].glarray
->Size
;
180 if (!brw_search_cache(&brw
->cache
, BRW_VS_PROG
,
182 &brw
->vs
.prog_offset
, &brw
->vs
.prog_data
)) {
183 bool success
= do_vs_prog(brw
, ctx
->Shader
.CurrentVertexProgram
,
188 brw
->vs
.constant_map
= ((int8_t *)brw
->vs
.prog_data
+
189 sizeof(*brw
->vs
.prog_data
));
194 const struct brw_tracked_state brw_vs_prog
= {
196 .mesa
= (_NEW_TRANSFORM
| _NEW_POLYGON
| _NEW_POINT
| _NEW_LIGHT
|
198 .brw
= (BRW_NEW_VERTEX_PROGRAM
|
202 .prepare
= brw_upload_vs_prog
206 brw_vs_precompile(struct gl_context
*ctx
, struct gl_shader_program
*prog
)
208 struct brw_context
*brw
= brw_context(ctx
);
209 struct brw_vs_prog_key key
;
210 struct gl_vertex_program
*vp
= prog
->VertexProgram
;
211 struct brw_vertex_program
*bvp
= brw_vertex_program(vp
);
212 uint32_t old_prog_offset
= brw
->vs
.prog_offset
;
213 struct brw_vs_prog_data
*old_prog_data
= brw
->vs
.prog_data
;
219 memset(&key
, 0, sizeof(key
));
221 key
.program_string_id
= bvp
->id
;
222 key
.clamp_vertex_color
= true;
224 success
= do_vs_prog(brw
, prog
, bvp
, &key
);
226 brw
->vs
.prog_offset
= old_prog_offset
;
227 brw
->vs
.prog_data
= old_prog_data
;