brw_vs.c revision 4176025d463e7733dac19788b45b6472b65d62d4
1/* 2 Copyright (C) Intel Corp. 2006. All Rights Reserved. 3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to 4 develop this 3D driver. 5 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: 13 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. 17 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. 25 26 **********************************************************************/ 27 /* 28 * Authors: 29 * Keith Whitwell <keith@tungstengraphics.com> 30 */ 31 32 33#include "brw_context.h" 34#include "brw_vs.h" 35#include "brw_util.h" 36#include "brw_state.h" 37#include "program/prog_print.h" 38#include "program/prog_parameter.h" 39 40#include "../glsl/ralloc.h" 41 42static void do_vs_prog( struct brw_context *brw, 43 struct brw_vertex_program *vp, 44 struct brw_vs_prog_key *key ) 45{ 46 struct gl_context *ctx = &brw->intel.ctx; 47 GLuint program_size; 48 const GLuint *program; 49 struct brw_vs_compile c; 50 void *mem_ctx; 51 int aux_size; 52 int i; 53 54 memset(&c, 0, sizeof(c)); 55 memcpy(&c.key, key, sizeof(*key)); 56 57 mem_ctx = ralloc_context(NULL); 58 59 brw_init_compile(brw, &c.func, mem_ctx); 60 c.vp = vp; 61 62 c.prog_data.outputs_written = vp->program.Base.OutputsWritten; 63 c.prog_data.inputs_read = vp->program.Base.InputsRead; 64 65 if (c.key.copy_edgeflag) { 66 c.prog_data.outputs_written |= BITFIELD64_BIT(VERT_RESULT_EDGE); 67 c.prog_data.inputs_read |= 1<<VERT_ATTRIB_EDGEFLAG; 68 } 69 70 /* Put dummy slots into the VUE for the SF to put the replaced 71 * point sprite coords in. We shouldn't need these dummy slots, 72 * which take up precious URB space, but it would mean that the SF 73 * doesn't get nice aligned pairs of input coords into output 74 * coords, which would be a pain to handle. 75 */ 76 for (i = 0; i < 8; i++) { 77 if (c.key.point_coord_replace & (1 << i)) 78 c.prog_data.outputs_written |= BITFIELD64_BIT(VERT_RESULT_TEX0 + i); 79 } 80 81 if (0) { 82 _mesa_fprint_program_opt(stdout, &c.vp->program.Base, PROG_PRINT_DEBUG, 83 GL_TRUE); 84 } 85 86 /* Emit GEN4 code. 87 */ 88 brw_vs_emit(&c); 89 90 /* get the program 91 */ 92 program = brw_get_program(&c.func, &program_size); 93 94 /* We upload from &c.prog_data including the constant_map assuming 95 * they're packed together. It would be nice to have a 96 * compile-time assert macro here. 97 */ 98 assert(c.constant_map == (int8_t *)&c.prog_data + 99 sizeof(c.prog_data)); 100 assert(ctx->Const.VertexProgram.MaxNativeParameters == 101 ARRAY_SIZE(c.constant_map)); 102 (void) ctx; 103 104 aux_size = sizeof(c.prog_data); 105 /* constant_map */ 106 aux_size += c.vp->program.Base.Parameters->NumParameters; 107 108 drm_intel_bo_unreference(brw->vs.prog_bo); 109 brw->vs.prog_bo = brw_upload_cache(&brw->cache, BRW_VS_PROG, 110 &c.key, sizeof(c.key), 111 program, program_size, 112 &c.prog_data, aux_size, 113 &brw->vs.prog_data); 114 ralloc_free(mem_ctx); 115} 116 117 118static void brw_upload_vs_prog(struct brw_context *brw) 119{ 120 struct gl_context *ctx = &brw->intel.ctx; 121 struct brw_vs_prog_key key; 122 struct brw_vertex_program *vp = 123 (struct brw_vertex_program *)brw->vertex_program; 124 int i; 125 126 memset(&key, 0, sizeof(key)); 127 128 /* Just upload the program verbatim for now. Always send it all 129 * the inputs it asks for, whether they are varying or not. 130 */ 131 key.program_string_id = vp->id; 132 key.nr_userclip = brw_count_bits(ctx->Transform.ClipPlanesEnabled); 133 key.copy_edgeflag = (ctx->Polygon.FrontMode != GL_FILL || 134 ctx->Polygon.BackMode != GL_FILL); 135 key.two_side_color = (ctx->Light.Enabled && ctx->Light.Model.TwoSide); 136 137 /* _NEW_LIGHT | _NEW_BUFFERS */ 138 key.clamp_vertex_color = ctx->Light._ClampVertexColor; 139 140 /* _NEW_POINT */ 141 if (ctx->Point.PointSprite) { 142 for (i = 0; i < 8; i++) { 143 if (ctx->Point.CoordReplace[i]) 144 key.point_coord_replace |= (1 << i); 145 } 146 } 147 148 /* BRW_NEW_VERTICES */ 149 for (i = 0; i < VERT_ATTRIB_MAX; i++) { 150 if (vp->program.Base.InputsRead & (1 << i) && 151 brw->vb.inputs[i].glarray->Type == GL_FIXED) { 152 key.gl_fixed_input_size[i] = brw->vb.inputs[i].glarray->Size; 153 } 154 } 155 156 /* Make an early check for the key. 157 */ 158 drm_intel_bo_unreference(brw->vs.prog_bo); 159 brw->vs.prog_bo = brw_search_cache(&brw->cache, BRW_VS_PROG, 160 &key, sizeof(key), 161 &brw->vs.prog_data); 162 if (brw->vs.prog_bo == NULL) 163 do_vs_prog(brw, vp, &key); 164 brw->vs.constant_map = ((int8_t *)brw->vs.prog_data + 165 sizeof(*brw->vs.prog_data)); 166} 167 168 169/* See brw_vs.c: 170 */ 171const struct brw_tracked_state brw_vs_prog = { 172 .dirty = { 173 .mesa = (_NEW_TRANSFORM | _NEW_POLYGON | _NEW_POINT | _NEW_LIGHT | 174 _NEW_BUFFERS), 175 .brw = (BRW_NEW_VERTEX_PROGRAM | 176 BRW_NEW_VERTICES), 177 .cache = 0 178 }, 179 .prepare = brw_upload_vs_prog 180}; 181