| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- /*
- * Copyright © 2015 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
- #include "brw_context.h"
- #include "brw_state.h"
- #include "brw_defines.h"
- #include "intel_batchbuffer.h"
- #include "intel_buffer_objects.h"
- #include "program/prog_parameter.h"
-
- void
- brw_populate_constant_data(struct brw_context *brw,
- const struct gl_program *prog,
- const struct brw_stage_prog_data *prog_data,
- void *void_dst,
- const union gl_constant_value **param,
- unsigned nr_params)
- {
- gl_constant_value *dst = void_dst;
- for (unsigned i = 0; i < nr_params; i++)
- dst[i] = *param[i];
- }
-
-
- /**
- * Creates a streamed BO containing the push constants for the VS or GS on
- * gen6+.
- *
- * Push constants are constant values (such as GLSL uniforms) that are
- * pre-loaded into a shader stage's register space at thread spawn time.
- *
- * Not all GLSL uniforms will be uploaded as push constants: The hardware has
- * a limitation of 32 or 64 EU registers (256 or 512 floats) per stage to be
- * uploaded as push constants, while GL 4.4 requires at least 1024 components
- * to be usable for the VS. Plus, currently we always use pull constants
- * instead of push constants when doing variable-index array access.
- *
- * See brw_curbe.c for the equivalent gen4/5 code.
- */
- void
- gen6_upload_push_constants(struct brw_context *brw,
- const struct gl_program *prog,
- const struct brw_stage_prog_data *prog_data,
- struct brw_stage_state *stage_state)
- {
- const struct gen_device_info *devinfo = &brw->screen->devinfo;
- struct gl_context *ctx = &brw->ctx;
-
- if (prog_data->nr_params == 0) {
- stage_state->push_const_size = 0;
- } else {
- /* Updates the ParamaterValues[i] pointers for all parameters of the
- * basic type of PROGRAM_STATE_VAR.
- */
- /* XXX: Should this happen somewhere before to get our state flag set? */
- if (prog)
- _mesa_load_state_parameters(ctx, prog->Parameters);
-
- int i;
- const int size = prog_data->nr_params * sizeof(gl_constant_value);
- gl_constant_value *param;
- if (devinfo->gen >= 8 || devinfo->is_haswell) {
- param = intel_upload_space(brw, size, 32,
- &stage_state->push_const_bo,
- &stage_state->push_const_offset);
- } else {
- param = brw_state_batch(brw, size, 32,
- &stage_state->push_const_offset);
- }
-
- STATIC_ASSERT(sizeof(gl_constant_value) == sizeof(float));
-
- /* _NEW_PROGRAM_CONSTANTS
- *
- * Also _NEW_TRANSFORM -- we may reference clip planes other than as a
- * side effect of dereferencing uniforms, so _NEW_PROGRAM_CONSTANTS
- * wouldn't be set for them.
- */
- brw_populate_constant_data(brw, prog, prog_data, param,
- prog_data->param,
- prog_data->nr_params);
-
- if (0) {
- fprintf(stderr, "%s constants:\n",
- _mesa_shader_stage_to_string(stage_state->stage));
- for (i = 0; i < prog_data->nr_params; i++) {
- if ((i & 7) == 0)
- fprintf(stderr, "g%d: ",
- prog_data->dispatch_grf_start_reg + i / 8);
- fprintf(stderr, "%8f ", param[i].f);
- if ((i & 7) == 7)
- fprintf(stderr, "\n");
- }
- if ((i & 7) != 0)
- fprintf(stderr, "\n");
- fprintf(stderr, "\n");
- }
-
- stage_state->push_const_size = ALIGN(prog_data->nr_params, 8) / 8;
- /* We can only push 32 registers of constants at a time. */
-
- /* From the SNB PRM (vol2, part 1, section 3.2.1.4: 3DSTATE_CONSTANT_VS:
- *
- * "The sum of all four read length fields (each incremented to
- * represent the actual read length) must be less than or equal to
- * 32"
- *
- * From the IVB PRM (vol2, part 1, section 3.2.1.3: 3DSTATE_CONSTANT_VS:
- *
- * "The sum of all four read length fields must be less than or
- * equal to the size of 64"
- *
- * The other shader stages all match the VS's limits.
- */
- assert(stage_state->push_const_size <= 32);
- }
-
- stage_state->push_constants_dirty = true;
- }
-
-
- /**
- * Creates a temporary BO containing the pull constant data for the shader
- * stage, and the SURFACE_STATE struct that points at it.
- *
- * Pull constants are GLSL uniforms (and other constant data) beyond what we
- * could fit as push constants, or that have variable-index array access
- * (which is easiest to support using pull constants, and avoids filling
- * register space with mostly-unused data).
- *
- * Compare this path to brw_curbe.c for gen4/5 push constants, and
- * gen6_vs_state.c for gen6+ push constants.
- */
- void
- brw_upload_pull_constants(struct brw_context *brw,
- GLbitfield64 brw_new_constbuf,
- const struct gl_program *prog,
- struct brw_stage_state *stage_state,
- const struct brw_stage_prog_data *prog_data)
- {
- unsigned i;
- uint32_t surf_index = prog_data->binding_table.pull_constants_start;
-
- if (!prog_data->nr_pull_params) {
- if (stage_state->surf_offset[surf_index]) {
- stage_state->surf_offset[surf_index] = 0;
- brw->ctx.NewDriverState |= brw_new_constbuf;
- }
- return;
- }
-
- /* Updates the ParamaterValues[i] pointers for all parameters of the
- * basic type of PROGRAM_STATE_VAR.
- */
- _mesa_load_state_parameters(&brw->ctx, prog->Parameters);
-
- /* BRW_NEW_*_PROG_DATA | _NEW_PROGRAM_CONSTANTS */
- uint32_t size = prog_data->nr_pull_params * 4;
- struct brw_bo *const_bo = NULL;
- uint32_t const_offset;
- gl_constant_value *constants = intel_upload_space(brw, size, 64,
- &const_bo, &const_offset);
-
- STATIC_ASSERT(sizeof(gl_constant_value) == sizeof(float));
-
- brw_populate_constant_data(brw, prog, prog_data, constants,
- prog_data->pull_param,
- prog_data->nr_pull_params);
-
- if (0) {
- for (i = 0; i < ALIGN(prog_data->nr_pull_params, 4) / 4; i++) {
- const gl_constant_value *row = &constants[i * 4];
- fprintf(stderr, "const surface %3d: %4.3f %4.3f %4.3f %4.3f\n",
- i, row[0].f, row[1].f, row[2].f, row[3].f);
- }
- }
-
- brw_create_constant_surface(brw, const_bo, const_offset, size,
- &stage_state->surf_offset[surf_index]);
- brw_bo_unreference(const_bo);
-
- brw->ctx.NewDriverState |= brw_new_constbuf;
- }
-
- /**
- * Creates a region containing the push constants for the CS on gen7+.
- *
- * Push constants are constant values (such as GLSL uniforms) that are
- * pre-loaded into a shader stage's register space at thread spawn time.
- *
- * For other stages, see brw_curbe.c:brw_upload_constant_buffer for the
- * equivalent gen4/5 code and gen6_vs_state.c:gen6_upload_push_constants for
- * gen6+.
- */
- void
- brw_upload_cs_push_constants(struct brw_context *brw,
- const struct gl_program *prog,
- const struct brw_cs_prog_data *cs_prog_data,
- struct brw_stage_state *stage_state)
- {
- struct gl_context *ctx = &brw->ctx;
- const struct brw_stage_prog_data *prog_data =
- (struct brw_stage_prog_data*) cs_prog_data;
-
- /* Updates the ParamaterValues[i] pointers for all parameters of the
- * basic type of PROGRAM_STATE_VAR.
- */
- /* XXX: Should this happen somewhere before to get our state flag set? */
- _mesa_load_state_parameters(ctx, prog->Parameters);
-
- if (cs_prog_data->push.total.size == 0) {
- stage_state->push_const_size = 0;
- return;
- }
-
-
- gl_constant_value *param = (gl_constant_value*)
- brw_state_batch(brw, ALIGN(cs_prog_data->push.total.size, 64),
- 64, &stage_state->push_const_offset);
- assert(param);
-
- STATIC_ASSERT(sizeof(gl_constant_value) == sizeof(float));
-
- if (cs_prog_data->push.cross_thread.size > 0) {
- gl_constant_value *param_copy = param;
- assert(cs_prog_data->thread_local_id_index < 0 ||
- cs_prog_data->thread_local_id_index >=
- cs_prog_data->push.cross_thread.dwords);
- for (unsigned i = 0;
- i < cs_prog_data->push.cross_thread.dwords;
- i++) {
- param_copy[i] = *prog_data->param[i];
- }
- }
-
- gl_constant_value thread_id;
- if (cs_prog_data->push.per_thread.size > 0) {
- for (unsigned t = 0; t < cs_prog_data->threads; t++) {
- unsigned dst =
- 8 * (cs_prog_data->push.per_thread.regs * t +
- cs_prog_data->push.cross_thread.regs);
- unsigned src = cs_prog_data->push.cross_thread.dwords;
- for ( ; src < prog_data->nr_params; src++, dst++) {
- if (src != cs_prog_data->thread_local_id_index)
- param[dst] = *prog_data->param[src];
- else {
- thread_id.u = t * cs_prog_data->simd_size;
- param[dst] = thread_id;
- }
- }
- }
- }
-
- stage_state->push_const_size =
- cs_prog_data->push.cross_thread.regs +
- cs_prog_data->push.per_thread.regs;
- }
|