/*
Copyright (C) Intel Corp. 2006. All Rights Reserved.
- Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
+ Intel funded Tungsten Graphics to
develop this 3D driver.
-
+
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
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.
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.
-
+
**********************************************************************/
/*
* Authors:
- * Keith Whitwell <keith@tungstengraphics.com>
+ * Keith Whitwell <keithw@vmware.com>
*/
-
+
#include "main/compiler.h"
#include "brw_context.h"
#include "program/prog_print.h"
#include "program/prog_parameter.h"
-#include "glsl/ralloc.h"
+#include "util/ralloc.h"
static inline void assign_vue_slot(struct brw_vue_map *vue_map,
int varying)
vue_map->slots_valid = slots_valid;
int i;
- /* gl_Layer doesn't get its own varying slot--it's stored in the virst VUE
- * slot (VARYING_SLOT_PSIZ).
+ /* gl_Layer and gl_ViewportIndex don't get their own varying slots -- they
+ * are stored in the first VUE slot (VARYING_SLOT_PSIZ).
*/
- slots_valid &= ~VARYING_BIT_LAYER;
+ slots_valid &= ~(VARYING_BIT_LAYER | VARYING_BIT_VIEWPORT);
/* Make sure that the values we store in vue_map->varying_to_slot and
* vue_map->slot_to_varying won't overflow the signed chars that are used
/* VUE header: format depends on chip generation and whether clipping is
* enabled.
*/
- switch (brw->gen) {
- case 4:
- case 5:
+ if (brw->gen < 6) {
/* There are 8 dwords in VUE header pre-Ironlake:
* dword 0-3 is indices, point width, clip flags.
* dword 4-7 is ndc position
assign_vue_slot(vue_map, VARYING_SLOT_PSIZ);
assign_vue_slot(vue_map, BRW_VARYING_SLOT_NDC);
assign_vue_slot(vue_map, VARYING_SLOT_POS);
- break;
- case 6:
- case 7:
+ } else {
/* There are 8 or 16 DWs (D0-D15) in VUE header on Sandybridge:
* dword 0-3 of the header is indices, point width, clip flags.
* dword 4-7 is the 4D space position
assign_vue_slot(vue_map, VARYING_SLOT_COL1);
if (slots_valid & BITFIELD64_BIT(VARYING_SLOT_BFC1))
assign_vue_slot(vue_map, VARYING_SLOT_BFC1);
- break;
- default:
- assert (!"VUE map not known for this chip generation");
- break;
}
/* The hardware doesn't care about the rest of the vertex outputs, so just
*/
gl_clip_plane *brw_select_clip_planes(struct gl_context *ctx)
{
- if (ctx->Shader.CurrentVertexProgram) {
+ if (ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX]) {
/* There is currently a GLSL vertex shader, so clip according to GLSL
* rules, which means compare gl_ClipVertex (or gl_Position, if
* gl_ClipVertex wasn't assigned) against the eye-coordinate clip planes
const struct brw_vs_prog_data *a = in_a;
const struct brw_vs_prog_data *b = in_b;
- /* Compare the base vec4 structure. */
- if (!brw_vec4_prog_data_compare(&a->base, &b->base))
+ /* Compare the base structure. */
+ if (!brw_stage_prog_data_compare(&a->base.base, &b->base.base))
return false;
/* Compare the rest of the struct. */
- const unsigned offset = sizeof(struct brw_vec4_prog_data);
+ const unsigned offset = sizeof(struct brw_stage_prog_data);
if (memcmp(((char *) a) + offset, ((char *) b) + offset,
sizeof(struct brw_vs_prog_data) - offset)) {
return false;
const GLuint *program;
struct brw_vs_compile c;
struct brw_vs_prog_data prog_data;
+ struct brw_stage_prog_data *stage_prog_data = &prog_data.base.base;
void *mem_ctx;
int i;
struct gl_shader *vs = NULL;
*/
param_count += c.key.base.nr_userclip_plane_consts * 4;
- prog_data.base.param = rzalloc_array(NULL, const float *, param_count);
- prog_data.base.pull_param = rzalloc_array(NULL, const float *, param_count);
+ stage_prog_data->param =
+ rzalloc_array(NULL, const gl_constant_value *, param_count);
+ stage_prog_data->pull_param =
+ rzalloc_array(NULL, const gl_constant_value *, param_count);
+
+ /* Setting nr_params here NOT to the size of the param and pull_param
+ * arrays, but to the number of uniform components vec4_visitor
+ * needs. vec4_visitor::setup_uniforms() will set it back to a proper value.
+ */
+ stage_prog_data->nr_params = ALIGN(param_count, 4) / 4;
+ if (vs) {
+ stage_prog_data->nr_params += vs->num_samplers;
+ }
GLbitfield64 outputs_written = vp->program.Base.OutputsWritten;
prog_data.inputs_read = vp->program.Base.InputsRead;
brw_compute_vue_map(brw, &prog_data.base.vue_map, outputs_written);
if (0) {
- _mesa_fprint_program_opt(stdout, &c.vp->program.Base, PROG_PRINT_DEBUG,
+ _mesa_fprint_program_opt(stderr, &c.vp->program.Base, PROG_PRINT_DEBUG,
true);
}
"Try reducing the number of live vec4 values to "
"improve performance.\n");
- prog_data.base.total_scratch
+ prog_data.base.base.total_scratch
= brw_get_scratch_size(c.base.last_scratch*REG_SIZE);
brw_get_scratch_bo(brw, &brw->vs.base.scratch_bo,
- prog_data.base.total_scratch * brw->max_vs_threads);
+ prog_data.base.base.total_scratch *
+ brw->max_vs_threads);
}
- brw_upload_cache(&brw->cache, BRW_VS_PROG,
+ brw_upload_cache(&brw->cache, BRW_CACHE_VS_PROG,
&c.key, sizeof(c.key),
program, program_size,
&prog_data, sizeof(prog_data),
for (unsigned int i = 0; i < brw->cache.size; i++) {
for (c = brw->cache.items[i]; c; c = c->next) {
- if (c->cache_id == BRW_VS_PROG) {
+ if (c->cache_id == BRW_CACHE_VS_PROG) {
old_key = c->key;
if (old_key->base.program_string_id == key->base.program_string_id)
old_key->base.nr_userclip_plane_consts,
key->base.nr_userclip_plane_consts);
- found |= key_debug(brw, "clip distance enable",
- old_key->base.uses_clip_distance, key->base.uses_clip_distance);
found |= key_debug(brw, "copy edgeflag",
old_key->copy_edgeflag, key->copy_edgeflag);
found |= key_debug(brw, "PointCoord replace",
struct gl_context *ctx = &brw->ctx;
key->userclip_active = (ctx->Transform.ClipPlanesEnabled != 0);
- key->uses_clip_distance = program_uses_clip_distance;
- if (key->userclip_active && !key->uses_clip_distance) {
+ if (key->userclip_active && !program_uses_clip_distance) {
key->nr_userclip_plane_consts
= _mesa_logbase2(ctx->Transform.ClipPlanesEnabled) + 1;
}
struct gl_context *ctx = &brw->ctx;
struct brw_vs_prog_key key;
/* BRW_NEW_VERTEX_PROGRAM */
- struct brw_vertex_program *vp =
+ struct brw_vertex_program *vp =
(struct brw_vertex_program *)brw->vertex_program;
struct gl_program *prog = (struct gl_program *) brw->vertex_program;
int i;
* the inputs it asks for, whether they are varying or not.
*/
key.base.program_string_id = vp->id;
- brw_setup_vec4_key_clip_info(brw, &key.base, vp->program.UsesClipDistance);
+ brw_setup_vec4_key_clip_info(brw, &key.base,
+ vp->program.Base.UsesClipDistanceOut);
/* _NEW_POLYGON */
if (brw->gen < 6) {
}
}
- if (!brw_search_cache(&brw->cache, BRW_VS_PROG,
+ if (!brw_search_cache(&brw->cache, BRW_CACHE_VS_PROG,
&key, sizeof(key),
&brw->vs.base.prog_offset, &brw->vs.prog_data)) {
- bool success = do_vs_prog(brw, ctx->Shader.CurrentVertexProgram,
- vp, &key);
+ bool success =
+ do_vs_prog(brw, ctx->_Shader->CurrentProgram[MESA_SHADER_VERTEX], vp,
+ &key);
(void) success;
assert(success);
}
+ brw->vs.base.prog_data = &brw->vs.prog_data->base.base;
+
if (memcmp(&brw->vs.prog_data->base.vue_map, &brw->vue_map_geom_out,
sizeof(brw->vue_map_geom_out)) != 0) {
brw->vue_map_vs = brw->vs.prog_data->base.vue_map;
brw->state.dirty.brw |= BRW_NEW_VUE_MAP_VS;
- if (brw->gen < 7) {
+ if (brw->gen < 6) {
/* No geometry shader support, so the VS VUE map is the VUE map for
* the output of the "geometry" portion of the pipeline.
*/
*/
const struct brw_tracked_state brw_vs_prog = {
.dirty = {
- .mesa = (_NEW_TRANSFORM | _NEW_POLYGON | _NEW_POINT | _NEW_LIGHT |
- _NEW_TEXTURE |
- _NEW_BUFFERS),
- .brw = (BRW_NEW_VERTEX_PROGRAM |
- BRW_NEW_VERTICES),
+ .mesa = _NEW_BUFFERS |
+ _NEW_LIGHT |
+ _NEW_POINT |
+ _NEW_POLYGON |
+ _NEW_TEXTURE |
+ _NEW_TRANSFORM,
+ .brw = BRW_NEW_VERTEX_PROGRAM |
+ BRW_NEW_VERTICES,
.cache = 0
},
.emit = brw_upload_vs_prog
};
bool
-brw_vs_precompile(struct gl_context *ctx, struct gl_shader_program *prog)
+brw_vs_precompile(struct gl_context *ctx,
+ struct gl_shader_program *shader_prog,
+ struct gl_program *prog)
{
struct brw_context *brw = brw_context(ctx);
struct brw_vs_prog_key key;
struct brw_vs_prog_data *old_prog_data = brw->vs.prog_data;
bool success;
- if (!prog->_LinkedShaders[MESA_SHADER_VERTEX])
- return true;
-
- struct gl_vertex_program *vp = (struct gl_vertex_program *)
- prog->_LinkedShaders[MESA_SHADER_VERTEX]->Program;
+ struct gl_vertex_program *vp = (struct gl_vertex_program *) prog;
struct brw_vertex_program *bvp = brw_vertex_program(vp);
memset(&key, 0, sizeof(key));
- key.base.program_string_id = bvp->id;
- key.base.clamp_vertex_color = ctx->API == API_OPENGL_COMPAT;
-
- unsigned sampler_count = _mesa_fls(vp->Base.SamplersUsed);
- for (unsigned i = 0; i < sampler_count; i++) {
- if (vp->Base.ShadowSamplers & (1 << i)) {
- /* Assume DEPTH_TEXTURE_MODE is the default: X, X, X, 1 */
- key.base.tex.swizzles[i] =
- MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_ONE);
- } else {
- /* Color sampler: assume no swizzling. */
- key.base.tex.swizzles[i] = SWIZZLE_XYZW;
- }
- }
+ brw_vec4_setup_prog_key_for_precompile(ctx, &key.base, bvp->id, &vp->Base);
- success = do_vs_prog(brw, prog, bvp, &key);
+ success = do_vs_prog(brw, shader_prog, bvp, &key);
brw->vs.base.prog_offset = old_prog_offset;
brw->vs.prog_data = old_prog_data;
return success;
}
-
-
-void
-brw_vs_prog_data_free(const void *in_prog_data)
-{
- const struct brw_vs_prog_data *prog_data = in_prog_data;
-
- brw_vec4_prog_data_free(&prog_data->base);
-}