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>
32 #include "main/mtypes.h"
33 #include "main/texstore.h"
34 #include "program/prog_parameter.h"
36 #include "brw_context.h"
37 #include "brw_state.h"
39 /* Creates a new VS constant buffer reflecting the current VS program's
40 * constants, if needed by the VS program.
42 * Otherwise, constants go through the CURBEs using the brw_constant_buffer
46 prepare_vs_constants(struct brw_context
*brw
)
48 struct gl_context
*ctx
= &brw
->intel
.ctx
;
49 struct intel_context
*intel
= &brw
->intel
;
50 struct brw_vertex_program
*vp
=
51 (struct brw_vertex_program
*) brw
->vertex_program
;
52 const struct gl_program_parameter_list
*params
= vp
->program
.Base
.Parameters
;
53 const int size
= params
->NumParameters
* 4 * sizeof(GLfloat
);
56 if (vp
->program
.IsNVProgram
)
57 _mesa_load_tracked_matrices(ctx
);
59 /* Updates the ParamaterValues[i] pointers for all parameters of the
60 * basic type of PROGRAM_STATE_VAR.
62 _mesa_load_state_parameters(&brw
->intel
.ctx
, vp
->program
.Base
.Parameters
);
64 /* BRW_NEW_VERTEX_PROGRAM */
65 if (!vp
->use_const_buffer
) {
66 if (brw
->vs
.const_bo
) {
67 drm_intel_bo_unreference(brw
->vs
.const_bo
);
68 brw
->vs
.const_bo
= NULL
;
69 brw
->state
.dirty
.brw
|= BRW_NEW_VS_CONSTBUF
;
74 /* _NEW_PROGRAM_CONSTANTS */
75 drm_intel_bo_unreference(brw
->vs
.const_bo
);
76 brw
->vs
.const_bo
= drm_intel_bo_alloc(intel
->bufmgr
, "vp_const_buffer",
79 drm_intel_gem_bo_map_gtt(brw
->vs
.const_bo
);
80 for (i
= 0; i
< params
->NumParameters
; i
++) {
81 memcpy(brw
->vs
.const_bo
->virtual + i
* 4 * sizeof(float),
82 params
->ParameterValues
[i
],
87 for (i
= 0; i
< params
->NumParameters
; i
++) {
88 float *row
= (float *)brw
->vs
.const_bo
->virtual + i
* 4;
89 printf("vs const surface %3d: %4.3f %4.3f %4.3f %4.3f\n",
90 i
, row
[0], row
[1], row
[2], row
[3]);
94 drm_intel_gem_bo_unmap_gtt(brw
->vs
.const_bo
);
95 brw
->state
.dirty
.brw
|= BRW_NEW_VS_CONSTBUF
;
98 const struct brw_tracked_state brw_vs_constants
= {
100 .mesa
= (_NEW_PROGRAM_CONSTANTS
),
101 .brw
= (BRW_NEW_VERTEX_PROGRAM
),
104 .prepare
= prepare_vs_constants
,
108 * Update the surface state for a VS constant buffer.
110 * Sets brw->vs.surf_bo[surf] and brw->vp->const_buffer.
113 brw_update_vs_constant_surface( struct gl_context
*ctx
,
116 struct brw_context
*brw
= brw_context(ctx
);
117 struct brw_vertex_program
*vp
=
118 (struct brw_vertex_program
*) brw
->vertex_program
;
119 const struct gl_program_parameter_list
*params
= vp
->program
.Base
.Parameters
;
123 /* If there's no constant buffer, then no surface BO is needed to point at
126 if (brw
->vs
.const_bo
== NULL
) {
127 drm_intel_bo_unreference(brw
->vs
.surf_bo
[surf
]);
128 brw
->vs
.surf_bo
[surf
] = NULL
;
132 brw_create_constant_surface(brw
, brw
->vs
.const_bo
, params
->NumParameters
,
133 &brw
->vs
.surf_bo
[surf
],
134 &brw
->vs
.surf_offset
[surf
]);
139 prepare_vs_surfaces(struct brw_context
*brw
)
143 if (brw
->vs
.const_bo
) {
144 brw_add_validated_bo(brw
, brw
->vs
.const_bo
);
148 if (brw
->vs
.nr_surfaces
!= nr_surfaces
) {
149 brw
->state
.dirty
.brw
|= BRW_NEW_NR_VS_SURFACES
;
150 brw
->vs
.nr_surfaces
= nr_surfaces
;
155 * Vertex shader surfaces (constant buffer).
157 * This consumes the state updates for the constant buffer needing
158 * to be updated, and produces BRW_NEW_NR_VS_SURFACES for the VS unit and
159 * CACHE_NEW_SURF_BIND for the binding table upload.
161 static void upload_vs_surfaces(struct brw_context
*brw
)
163 struct gl_context
*ctx
= &brw
->intel
.ctx
;
167 /* BRW_NEW_NR_VS_SURFACES */
168 if (brw
->vs
.nr_surfaces
== 0) {
169 if (brw
->vs
.bind_bo
) {
170 drm_intel_bo_unreference(brw
->vs
.bind_bo
);
171 brw
->vs
.bind_bo
= NULL
;
172 brw
->state
.dirty
.brw
|= BRW_NEW_BINDING_TABLE
;
177 brw_update_vs_constant_surface(ctx
, SURF_INDEX_VERT_CONST_BUFFER
);
179 /* Might want to calculate nr_surfaces first, to avoid taking up so much
180 * space for the binding table. (once we have vs samplers)
182 bind
= brw_state_batch(brw
, sizeof(uint32_t) * BRW_VS_MAX_SURF
,
183 32, &brw
->vs
.bind_bo
, &brw
->vs
.bind_bo_offset
);
185 for (i
= 0; i
< BRW_VS_MAX_SURF
; i
++) {
186 /* BRW_NEW_VS_CONSTBUF */
187 if (brw
->vs
.surf_bo
[i
]) {
188 bind
[i
] = brw
->vs
.surf_offset
[i
];
194 brw
->state
.dirty
.brw
|= BRW_NEW_BINDING_TABLE
;
197 const struct brw_tracked_state brw_vs_surfaces
= {
200 .brw
= (BRW_NEW_VS_CONSTBUF
|
201 BRW_NEW_NR_VS_SURFACES
|
205 .prepare
= prepare_vs_surfaces
,
206 .emit
= upload_vs_surfaces
,