2 * Copyright © 2009 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Eric Anholt <eric@anholt.net>
28 #include "brw_context.h"
29 #include "brw_state.h"
30 #include "brw_defines.h"
32 #include "program/prog_parameter.h"
33 #include "program/prog_statevars.h"
34 #include "intel_batchbuffer.h"
37 gen6_prepare_vs_push_constants(struct brw_context
*brw
)
39 struct intel_context
*intel
= &brw
->intel
;
40 struct gl_context
*ctx
= &intel
->ctx
;
41 /* _BRW_NEW_VERTEX_PROGRAM */
42 const struct brw_vertex_program
*vp
=
43 brw_vertex_program_const(brw
->vertex_program
);
44 unsigned int nr_params
= brw
->vs
.prog_data
->nr_params
/ 4;
46 if (brw
->vertex_program
->IsNVProgram
)
47 _mesa_load_tracked_matrices(ctx
);
49 /* Updates the ParamaterValues[i] pointers for all parameters of the
50 * basic type of PROGRAM_STATE_VAR.
52 /* XXX: Should this happen somewhere before to get our state flag set? */
53 _mesa_load_state_parameters(ctx
, vp
->program
.Base
.Parameters
);
55 /* CACHE_NEW_VS_PROG | _NEW_TRANSFORM */
56 if (brw
->vs
.prog_data
->nr_params
== 0 && !ctx
->Transform
.ClipPlanesEnabled
) {
57 brw
->vs
.push_const_size
= 0;
59 int params_uploaded
= 0;
63 param
= brw_state_batch(brw
,
64 (MAX_CLIP_PLANES
+ nr_params
) *
66 32, &brw
->vs
.push_const_offset
);
68 /* This should be loaded like any other param, but it's ad-hoc
69 * until we redo the VS backend.
71 for (i
= 0; i
< MAX_CLIP_PLANES
; i
++) {
72 if (ctx
->Transform
.ClipPlanesEnabled
& (1 << i
)) {
73 memcpy(param
, ctx
->Transform
._ClipUserPlane
[i
], 4 * sizeof(float));
78 /* Align to a reg for convenience for brw_vs_emit.c */
79 if (params_uploaded
& 1) {
84 for (i
= 0; i
< vp
->program
.Base
.Parameters
->NumParameters
; i
++) {
85 if (brw
->vs
.constant_map
[i
] != -1) {
86 memcpy(param
+ brw
->vs
.constant_map
[i
] * 4,
87 vp
->program
.Base
.Parameters
->ParameterValues
[i
],
94 printf("VS constant buffer:\n");
95 for (i
= 0; i
< params_uploaded
; i
++) {
96 float *buf
= param
+ i
* 4;
97 printf("%d: %f %f %f %f\n",
98 i
, buf
[0], buf
[1], buf
[2], buf
[3]);
102 brw
->vs
.push_const_size
= (params_uploaded
+ 1) / 2;
103 /* We can only push 32 registers of constants at a time. */
104 assert(brw
->vs
.push_const_size
<= 32);
108 const struct brw_tracked_state gen6_vs_constants
= {
110 .mesa
= _NEW_TRANSFORM
| _NEW_PROGRAM_CONSTANTS
,
111 .brw
= (BRW_NEW_BATCH
|
112 BRW_NEW_VERTEX_PROGRAM
),
115 .prepare
= gen6_prepare_vs_push_constants
,
119 upload_vs_state(struct brw_context
*brw
)
121 struct intel_context
*intel
= &brw
->intel
;
123 if (brw
->vs
.push_const_size
== 0) {
124 /* Disable the push constant buffers. */
126 OUT_BATCH(_3DSTATE_CONSTANT_VS
<< 16 | (5 - 2));
134 OUT_BATCH(_3DSTATE_CONSTANT_VS
<< 16 |
135 GEN6_CONSTANT_BUFFER_0_ENABLE
|
137 /* Pointer to the VS constant buffer. Covered by the set of
138 * state flags from gen6_prepare_wm_constants
140 OUT_BATCH(brw
->vs
.push_const_offset
+
141 brw
->vs
.push_const_size
- 1);
149 OUT_BATCH(_3DSTATE_VS
<< 16 | (6 - 2));
150 OUT_BATCH(brw
->vs
.prog_offset
);
151 OUT_BATCH((0 << GEN6_VS_SAMPLER_COUNT_SHIFT
) |
152 GEN6_VS_FLOATING_POINT_MODE_ALT
|
153 (brw
->vs
.nr_surfaces
<< GEN6_VS_BINDING_TABLE_ENTRY_COUNT_SHIFT
));
154 OUT_BATCH(0); /* scratch space base offset */
155 OUT_BATCH((1 << GEN6_VS_DISPATCH_START_GRF_SHIFT
) |
156 (brw
->vs
.prog_data
->urb_read_length
<< GEN6_VS_URB_READ_LENGTH_SHIFT
) |
157 (0 << GEN6_VS_URB_ENTRY_READ_OFFSET_SHIFT
));
159 OUT_BATCH(((brw
->vs_max_threads
- 1) << GEN6_VS_MAX_THREADS_SHIFT
) |
160 GEN6_VS_STATISTICS_ENABLE
|
165 const struct brw_tracked_state gen6_vs_state
= {
167 .mesa
= _NEW_TRANSFORM
| _NEW_PROGRAM_CONSTANTS
,
168 .brw
= (BRW_NEW_CURBE_OFFSETS
|
169 BRW_NEW_NR_VS_SURFACES
|
172 BRW_NEW_VERTEX_PROGRAM
|
174 .cache
= CACHE_NEW_VS_PROG
176 .emit
= upload_vs_state
,