2 * Copyright © 2015 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
21 * DEALINGS IN THE SOFTWARE.
24 #include "util/ralloc.h"
25 #include "brw_context.h"
26 #include "brw_defines.h"
29 #include "intel_mipmap_tree.h"
30 #include "intel_batchbuffer.h"
31 #include "brw_state.h"
32 #include "program/prog_statevars.h"
33 #include "compiler/glsl/ir_uniform.h"
34 #include "main/shaderapi.h"
37 * Creates a region containing the push constants for the CS on gen7+.
39 * Push constants are constant values (such as GLSL uniforms) that are
40 * pre-loaded into a shader stage's register space at thread spawn time.
42 * For other stages, see brw_curbe.c:brw_upload_constant_buffer for the
43 * equivalent gen4/5 code and gen6_vs_state.c:gen6_upload_push_constants for
47 brw_upload_cs_push_constants(struct brw_context
*brw
,
48 const struct gl_program
*prog
,
49 const struct brw_cs_prog_data
*cs_prog_data
,
50 struct brw_stage_state
*stage_state
)
52 struct gl_context
*ctx
= &brw
->ctx
;
53 const struct brw_stage_prog_data
*prog_data
=
54 (struct brw_stage_prog_data
*) cs_prog_data
;
56 /* Updates the ParamaterValues[i] pointers for all parameters of the
57 * basic type of PROGRAM_STATE_VAR.
59 /* XXX: Should this happen somewhere before to get our state flag set? */
60 _mesa_load_state_parameters(ctx
, prog
->Parameters
);
62 if (cs_prog_data
->push
.total
.size
== 0) {
63 stage_state
->push_const_size
= 0;
68 gl_constant_value
*param
= (gl_constant_value
*)
69 brw_state_batch(brw
, ALIGN(cs_prog_data
->push
.total
.size
, 64),
70 64, &stage_state
->push_const_offset
);
73 STATIC_ASSERT(sizeof(gl_constant_value
) == sizeof(float));
75 if (cs_prog_data
->push
.cross_thread
.size
> 0) {
76 gl_constant_value
*param_copy
= param
;
77 assert(cs_prog_data
->thread_local_id_index
< 0 ||
78 cs_prog_data
->thread_local_id_index
>=
79 cs_prog_data
->push
.cross_thread
.dwords
);
81 i
< cs_prog_data
->push
.cross_thread
.dwords
;
83 param_copy
[i
] = *prog_data
->param
[i
];
87 gl_constant_value thread_id
;
88 if (cs_prog_data
->push
.per_thread
.size
> 0) {
89 for (unsigned t
= 0; t
< cs_prog_data
->threads
; t
++) {
91 8 * (cs_prog_data
->push
.per_thread
.regs
* t
+
92 cs_prog_data
->push
.cross_thread
.regs
);
93 unsigned src
= cs_prog_data
->push
.cross_thread
.dwords
;
94 for ( ; src
< prog_data
->nr_params
; src
++, dst
++) {
95 if (src
!= cs_prog_data
->thread_local_id_index
)
96 param
[dst
] = *prog_data
->param
[src
];
98 thread_id
.u
= t
* cs_prog_data
->simd_size
;
99 param
[dst
] = thread_id
;
105 stage_state
->push_const_size
=
106 cs_prog_data
->push
.cross_thread
.regs
+
107 cs_prog_data
->push
.per_thread
.regs
;
112 gen7_upload_cs_push_constants(struct brw_context
*brw
)
114 struct brw_stage_state
*stage_state
= &brw
->cs
.base
;
116 /* BRW_NEW_COMPUTE_PROGRAM */
117 const struct brw_program
*cp
= (struct brw_program
*) brw
->compute_program
;
120 /* BRW_NEW_CS_PROG_DATA */
121 struct brw_cs_prog_data
*cs_prog_data
=
122 brw_cs_prog_data(brw
->cs
.base
.prog_data
);
124 _mesa_shader_write_subroutine_indices(&brw
->ctx
, MESA_SHADER_COMPUTE
);
125 brw_upload_cs_push_constants(brw
, &cp
->program
, cs_prog_data
,
130 const struct brw_tracked_state gen7_cs_push_constants
= {
132 .mesa
= _NEW_PROGRAM_CONSTANTS
,
133 .brw
= BRW_NEW_BATCH
|
135 BRW_NEW_COMPUTE_PROGRAM
|
136 BRW_NEW_CS_PROG_DATA
|
137 BRW_NEW_PUSH_CONSTANT_ALLOCATION
,
139 .emit
= gen7_upload_cs_push_constants
,
143 * Creates a new CS constant buffer reflecting the current CS program's
144 * constants, if needed by the CS program.
147 brw_upload_cs_pull_constants(struct brw_context
*brw
)
149 struct brw_stage_state
*stage_state
= &brw
->cs
.base
;
151 /* BRW_NEW_COMPUTE_PROGRAM */
152 struct brw_program
*cp
= (struct brw_program
*) brw
->compute_program
;
154 /* BRW_NEW_CS_PROG_DATA */
155 const struct brw_stage_prog_data
*prog_data
= brw
->cs
.base
.prog_data
;
157 _mesa_shader_write_subroutine_indices(&brw
->ctx
, MESA_SHADER_COMPUTE
);
158 /* _NEW_PROGRAM_CONSTANTS */
159 brw_upload_pull_constants(brw
, BRW_NEW_SURFACES
, &cp
->program
,
160 stage_state
, prog_data
);
163 const struct brw_tracked_state brw_cs_pull_constants
= {
165 .mesa
= _NEW_PROGRAM_CONSTANTS
,
166 .brw
= BRW_NEW_BATCH
|
168 BRW_NEW_COMPUTE_PROGRAM
|
169 BRW_NEW_CS_PROG_DATA
,
171 .emit
= brw_upload_cs_pull_constants
,