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 "program/prog_parameter.h"
35 #include "brw_context.h"
36 #include "brw_state.h"
40 brw_upload_vec4_pull_constants(struct brw_context
*brw
,
41 GLbitfield brw_new_constbuf
,
42 const struct gl_program
*prog
,
43 struct brw_stage_state
*stage_state
,
44 const struct brw_vec4_prog_data
*prog_data
)
48 /* Updates the ParamaterValues[i] pointers for all parameters of the
49 * basic type of PROGRAM_STATE_VAR.
51 _mesa_load_state_parameters(&brw
->ctx
, prog
->Parameters
);
53 if (!prog_data
->nr_pull_params
) {
54 if (stage_state
->const_bo
) {
55 drm_intel_bo_unreference(stage_state
->const_bo
);
56 stage_state
->const_bo
= NULL
;
57 stage_state
->surf_offset
[SURF_INDEX_VEC4_CONST_BUFFER
] = 0;
58 brw
->state
.dirty
.brw
|= brw_new_constbuf
;
63 /* _NEW_PROGRAM_CONSTANTS */
64 drm_intel_bo_unreference(stage_state
->const_bo
);
65 uint32_t size
= prog_data
->nr_pull_params
* 4;
66 stage_state
->const_bo
= drm_intel_bo_alloc(brw
->bufmgr
, "vec4_const_buffer",
69 drm_intel_gem_bo_map_gtt(stage_state
->const_bo
);
71 for (i
= 0; i
< prog_data
->nr_pull_params
; i
++) {
72 memcpy(stage_state
->const_bo
->virtual + i
* 4,
73 prog_data
->pull_param
[i
],
78 for (i
= 0; i
< ALIGN(prog_data
->nr_pull_params
, 4) / 4; i
++) {
79 float *row
= (float *)stage_state
->const_bo
->virtual + i
* 4;
80 printf("const surface %3d: %4.3f %4.3f %4.3f %4.3f\n",
81 i
, row
[0], row
[1], row
[2], row
[3]);
85 drm_intel_gem_bo_unmap_gtt(stage_state
->const_bo
);
87 const int surf
= SURF_INDEX_VEC4_CONST_BUFFER
;
88 brw
->vtbl
.create_constant_surface(brw
, stage_state
->const_bo
, 0, size
,
89 &stage_state
->surf_offset
[surf
], false);
91 brw
->state
.dirty
.brw
|= brw_new_constbuf
;
95 /* Creates a new VS constant buffer reflecting the current VS program's
96 * constants, if needed by the VS program.
98 * Otherwise, constants go through the CURBEs using the brw_constant_buffer
102 brw_upload_vs_pull_constants(struct brw_context
*brw
)
104 struct brw_stage_state
*stage_state
= &brw
->vs
.base
;
106 /* BRW_NEW_VERTEX_PROGRAM */
107 struct brw_vertex_program
*vp
=
108 (struct brw_vertex_program
*) brw
->vertex_program
;
110 /* CACHE_NEW_VS_PROG */
111 const struct brw_vec4_prog_data
*prog_data
= &brw
->vs
.prog_data
->base
;
113 /* _NEW_PROGRAM_CONSTANTS */
114 brw_upload_vec4_pull_constants(brw
, BRW_NEW_VS_CONSTBUF
, &vp
->program
.Base
,
115 stage_state
, prog_data
);
118 const struct brw_tracked_state brw_vs_pull_constants
= {
120 .mesa
= (_NEW_PROGRAM_CONSTANTS
),
121 .brw
= (BRW_NEW_BATCH
| BRW_NEW_VERTEX_PROGRAM
),
122 .cache
= CACHE_NEW_VS_PROG
,
124 .emit
= brw_upload_vs_pull_constants
,
128 brw_upload_vs_ubo_surfaces(struct brw_context
*brw
)
130 struct brw_stage_state
*stage_state
= &brw
->vs
.base
;
132 struct gl_context
*ctx
= &brw
->ctx
;
134 struct gl_shader_program
*prog
= ctx
->Shader
.CurrentVertexProgram
;
139 brw_upload_ubo_surfaces(brw
, prog
->_LinkedShaders
[MESA_SHADER_VERTEX
],
140 &stage_state
->surf_offset
[SURF_INDEX_VEC4_UBO(0)]);
143 const struct brw_tracked_state brw_vs_ubo_surfaces
= {
145 .mesa
= _NEW_PROGRAM
,
146 .brw
= BRW_NEW_BATCH
| BRW_NEW_UNIFORM_BUFFER
,
149 .emit
= brw_upload_vs_ubo_surfaces
,
154 brw_vec4_upload_binding_table(struct brw_context
*brw
,
155 GLbitfield brw_new_binding_table
,
156 struct brw_stage_state
*stage_state
,
157 const struct brw_vec4_prog_data
*prog_data
)
162 if (INTEL_DEBUG
& DEBUG_SHADER_TIME
) {
163 gen7_create_shader_time_surface(brw
, &stage_state
->surf_offset
[SURF_INDEX_VEC4_SHADER_TIME
]);
166 /* If there are no surfaces, skip making the binding table altogether. */
167 const unsigned entries
= prog_data
->binding_table_size
;
169 if (stage_state
->bind_bo_offset
!= 0) {
170 brw
->state
.dirty
.brw
|= brw_new_binding_table
;
171 stage_state
->bind_bo_offset
= 0;
176 bind
= brw_state_batch(brw
, AUB_TRACE_BINDING_TABLE
,
177 sizeof(uint32_t) * entries
,
178 32, &stage_state
->bind_bo_offset
);
180 /* BRW_NEW_SURFACES and BRW_NEW_*_CONSTBUF */
181 for (i
= 0; i
< entries
; i
++) {
182 bind
[i
] = stage_state
->surf_offset
[i
];
185 brw
->state
.dirty
.brw
|= brw_new_binding_table
;
190 * Constructs the binding table for the WM surface state, which maps unit
191 * numbers to surface state objects.
194 brw_vs_upload_binding_table(struct brw_context
*brw
)
196 struct brw_stage_state
*stage_state
= &brw
->vs
.base
;
197 /* CACHE_NEW_VS_PROG */
198 const struct brw_vec4_prog_data
*prog_data
= &brw
->vs
.prog_data
->base
;
200 /* BRW_NEW_SURFACES and BRW_NEW_VS_CONSTBUF */
201 brw_vec4_upload_binding_table(brw
, BRW_NEW_VS_BINDING_TABLE
, stage_state
,
205 const struct brw_tracked_state brw_vs_binding_table
= {
208 .brw
= (BRW_NEW_BATCH
|
209 BRW_NEW_VS_CONSTBUF
|
211 .cache
= CACHE_NEW_VS_PROG
213 .emit
= brw_vs_upload_binding_table
,