2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics 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 <keithw@vmware.com>
32 #include "main/mtypes.h"
33 #include "program/prog_parameter.h"
34 #include "main/shaderapi.h"
36 #include "brw_context.h"
37 #include "brw_state.h"
38 #include "intel_buffer_objects.h"
41 * Creates a temporary BO containing the pull constant data for the shader
42 * stage, and the SURFACE_STATE struct that points at it.
44 * Pull constants are GLSL uniforms (and other constant data) beyond what we
45 * could fit as push constants, or that have variable-index array access
46 * (which is easiest to support using pull constants, and avoids filling
47 * register space with mostly-unused data).
49 * Compare this path to brw_curbe.c for gen4/5 push constants, and
50 * gen6_vs_state.c for gen6+ push constants.
53 brw_upload_pull_constants(struct brw_context
*brw
,
54 GLbitfield64 brw_new_constbuf
,
55 const struct gl_program
*prog
,
56 struct brw_stage_state
*stage_state
,
57 const struct brw_stage_prog_data
*prog_data
)
60 uint32_t surf_index
= prog_data
->binding_table
.pull_constants_start
;
62 if (!prog_data
->nr_pull_params
) {
63 if (stage_state
->surf_offset
[surf_index
]) {
64 stage_state
->surf_offset
[surf_index
] = 0;
65 brw
->ctx
.NewDriverState
|= brw_new_constbuf
;
70 /* Updates the ParamaterValues[i] pointers for all parameters of the
71 * basic type of PROGRAM_STATE_VAR.
73 _mesa_load_state_parameters(&brw
->ctx
, prog
->Parameters
);
75 /* BRW_NEW_*_PROG_DATA | _NEW_PROGRAM_CONSTANTS */
76 uint32_t size
= prog_data
->nr_pull_params
* 4;
77 drm_intel_bo
*const_bo
= NULL
;
78 uint32_t const_offset
;
79 gl_constant_value
*constants
= intel_upload_space(brw
, size
, 64,
80 &const_bo
, &const_offset
);
82 STATIC_ASSERT(sizeof(gl_constant_value
) == sizeof(float));
84 for (i
= 0; i
< prog_data
->nr_pull_params
; i
++) {
85 constants
[i
] = *prog_data
->pull_param
[i
];
89 for (i
= 0; i
< ALIGN(prog_data
->nr_pull_params
, 4) / 4; i
++) {
90 const gl_constant_value
*row
= &constants
[i
* 4];
91 fprintf(stderr
, "const surface %3d: %4.3f %4.3f %4.3f %4.3f\n",
92 i
, row
[0].f
, row
[1].f
, row
[2].f
, row
[3].f
);
96 brw_create_constant_surface(brw
, const_bo
, const_offset
, size
,
97 &stage_state
->surf_offset
[surf_index
]);
98 drm_intel_bo_unreference(const_bo
);
100 brw
->ctx
.NewDriverState
|= brw_new_constbuf
;
104 /* Creates a new VS constant buffer reflecting the current VS program's
105 * constants, if needed by the VS program.
107 * Otherwise, constants go through the CURBEs using the brw_constant_buffer
111 brw_upload_vs_pull_constants(struct brw_context
*brw
)
113 struct brw_stage_state
*stage_state
= &brw
->vs
.base
;
115 /* BRW_NEW_VERTEX_PROGRAM */
116 struct brw_program
*vp
= (struct brw_program
*) brw
->vertex_program
;
118 /* BRW_NEW_VS_PROG_DATA */
119 const struct brw_stage_prog_data
*prog_data
= brw
->vs
.base
.prog_data
;
121 _mesa_shader_write_subroutine_indices(&brw
->ctx
, MESA_SHADER_VERTEX
);
122 /* _NEW_PROGRAM_CONSTANTS */
123 brw_upload_pull_constants(brw
, BRW_NEW_VS_CONSTBUF
, &vp
->program
,
124 stage_state
, prog_data
);
127 const struct brw_tracked_state brw_vs_pull_constants
= {
129 .mesa
= _NEW_PROGRAM_CONSTANTS
,
130 .brw
= BRW_NEW_BATCH
|
132 BRW_NEW_VERTEX_PROGRAM
|
133 BRW_NEW_VS_PROG_DATA
,
135 .emit
= brw_upload_vs_pull_constants
,
139 brw_upload_vs_ubo_surfaces(struct brw_context
*brw
)
141 struct gl_context
*ctx
= &brw
->ctx
;
143 struct gl_shader_program
*prog
=
144 ctx
->_Shader
->CurrentProgram
[MESA_SHADER_VERTEX
];
149 /* BRW_NEW_VS_PROG_DATA */
150 brw_upload_ubo_surfaces(brw
, prog
->_LinkedShaders
[MESA_SHADER_VERTEX
],
151 &brw
->vs
.base
, brw
->vs
.base
.prog_data
);
154 const struct brw_tracked_state brw_vs_ubo_surfaces
= {
156 .mesa
= _NEW_PROGRAM
,
157 .brw
= BRW_NEW_BATCH
|
159 BRW_NEW_UNIFORM_BUFFER
|
160 BRW_NEW_VS_PROG_DATA
,
162 .emit
= brw_upload_vs_ubo_surfaces
,
166 brw_upload_vs_abo_surfaces(struct brw_context
*brw
)
168 struct gl_context
*ctx
= &brw
->ctx
;
170 struct gl_shader_program
*prog
=
171 ctx
->_Shader
->CurrentProgram
[MESA_SHADER_VERTEX
];
174 /* BRW_NEW_VS_PROG_DATA */
175 brw_upload_abo_surfaces(brw
, prog
->_LinkedShaders
[MESA_SHADER_VERTEX
],
176 &brw
->vs
.base
, brw
->vs
.base
.prog_data
);
180 const struct brw_tracked_state brw_vs_abo_surfaces
= {
182 .mesa
= _NEW_PROGRAM
,
183 .brw
= BRW_NEW_ATOMIC_BUFFER
|
186 BRW_NEW_VS_PROG_DATA
,
188 .emit
= brw_upload_vs_abo_surfaces
,
192 brw_upload_vs_image_surfaces(struct brw_context
*brw
)
194 struct gl_context
*ctx
= &brw
->ctx
;
195 /* BRW_NEW_VERTEX_PROGRAM */
196 struct gl_shader_program
*prog
=
197 ctx
->_Shader
->CurrentProgram
[MESA_SHADER_VERTEX
];
200 /* BRW_NEW_VS_PROG_DATA, BRW_NEW_IMAGE_UNITS, _NEW_TEXTURE */
201 brw_upload_image_surfaces(brw
, prog
->_LinkedShaders
[MESA_SHADER_VERTEX
],
202 &brw
->vs
.base
, brw
->vs
.base
.prog_data
);
206 const struct brw_tracked_state brw_vs_image_surfaces
= {
208 .mesa
= _NEW_TEXTURE
,
209 .brw
= BRW_NEW_BATCH
|
211 BRW_NEW_IMAGE_UNITS
|
212 BRW_NEW_VERTEX_PROGRAM
|
213 BRW_NEW_VS_PROG_DATA
,
215 .emit
= brw_upload_vs_image_surfaces
,