Go to the source code of this file.
Defines | |
#define | MAX_VERTEX_SIZE ((2 + PIPE_MAX_SHADER_OUTPUTS) * 4 * sizeof(float)) |
#define | CLIP_RIGHT_BIT 0x01 |
#define | CLIP_LEFT_BIT 0x02 |
#define | CLIP_TOP_BIT 0x04 |
#define | CLIP_BOTTOM_BIT 0x08 |
#define | CLIP_FAR_BIT 0x10 |
#define | CLIP_NEAR_BIT 0x20 |
Functions | |
static float | dot4 (const float *a, const float *b) |
static unsigned | compute_clipmask (const float *clip, float plane[][4], unsigned nr) |
static void | run_vertex_program (struct spu_vs_context *draw, unsigned elts[4], unsigned count, const uint64_t *vOut) |
Transform vertices with the current vertex program/shader Up to four vertices can be shaded at a time. | |
void | spu_bind_vertex_shader (struct spu_vs_context *draw, struct cell_shader_info *vs) |
void | spu_execute_vertex_shader (struct spu_vs_context *draw, const struct cell_command_vs *vs) |
Variables | |
unsigned char immediates[(sizeof(float)*4 *TGSI_EXEC_NUM_IMMEDIATES)+32] | ALIGN16_ATTRIB |
#define CLIP_BOTTOM_BIT 0x08 |
Definition at line 54 of file spu_vertex_shader.c.
#define CLIP_FAR_BIT 0x10 |
Definition at line 55 of file spu_vertex_shader.c.
#define CLIP_LEFT_BIT 0x02 |
Definition at line 52 of file spu_vertex_shader.c.
#define CLIP_NEAR_BIT 0x20 |
Definition at line 56 of file spu_vertex_shader.c.
#define CLIP_RIGHT_BIT 0x01 |
Definition at line 51 of file spu_vertex_shader.c.
#define CLIP_TOP_BIT 0x04 |
Definition at line 53 of file spu_vertex_shader.c.
#define MAX_VERTEX_SIZE ((2 + PIPE_MAX_SHADER_OUTPUTS) * 4 * sizeof(float)) |
Definition at line 48 of file spu_vertex_shader.c.
static unsigned compute_clipmask | ( | const float * | clip, | |
float | plane[][4], | |||
unsigned | nr | |||
) | [static] |
Definition at line 69 of file spu_vertex_shader.c.
References CLIP_BOTTOM_BIT, CLIP_FAR_BIT, CLIP_LEFT_BIT, CLIP_NEAR_BIT, CLIP_RIGHT_BIT, CLIP_TOP_BIT, and dot4().
00070 { 00071 unsigned mask = 0; 00072 unsigned i; 00073 00074 /* Do the hardwired planes first: 00075 */ 00076 if (-clip[0] + clip[3] < 0) mask |= CLIP_RIGHT_BIT; 00077 if ( clip[0] + clip[3] < 0) mask |= CLIP_LEFT_BIT; 00078 if (-clip[1] + clip[3] < 0) mask |= CLIP_TOP_BIT; 00079 if ( clip[1] + clip[3] < 0) mask |= CLIP_BOTTOM_BIT; 00080 if (-clip[2] + clip[3] < 0) mask |= CLIP_FAR_BIT; 00081 if ( clip[2] + clip[3] < 0) mask |= CLIP_NEAR_BIT; 00082 00083 /* Followed by any remaining ones: 00084 */ 00085 for (i = 6; i < nr; i++) { 00086 if (dot4(clip, plane[i]) < 0) 00087 mask |= (1<<i); 00088 } 00089 00090 return mask; 00091 }
static float dot4 | ( | const float * | a, | |
const float * | b | |||
) | [static] |
static void run_vertex_program | ( | struct spu_vs_context * | draw, | |
unsigned | elts[4], | |||
unsigned | count, | |||
const uint64_t * | vOut | |||
) | [static] |
Transform vertices with the current vertex program/shader Up to four vertices can be shaded at a time.
vbuffer | the input vertex data | |
elts | indexes of four input vertices | |
count | number of vertices to shade [1..4] | |
vOut | array of pointers to four output vertices |
Definition at line 103 of file spu_vertex_shader.c.
References ALIGN16_ASSIGN, ALIGN16_DECL, ASSERT, ASSERT_ALIGN16, vertex_header::clip, vertex_header::clipmask, compute_clipmask(), spu_vs_context::constants, spu_exec_machine::Consts, vertex_header::data, vertex_header::edgeflag, spu_exec_channel::f, spu_exec_machine::Inputs, spu_vs_context::machine, spu_vs_context::nr_planes, spu_vs_context::num_vs_outputs, spu_exec_machine::Outputs, PIPE_MAX_ATTRIBS, spu_vs_context::plane, spu_exec_machine::Processor, ROUNDUP16, pipe_viewport_state::scale, spu_exec_machine_run(), spu_vertex_fetch(), TAG_VERTEX_BUFFER, TGSI_PROCESSOR_VERTEX, pipe_viewport_state::translate, spu_vs_context::viewport, wait_on_mask(), and spu_exec_vector::xyzw.
00106 { 00107 struct spu_exec_machine *machine = &draw->machine; 00108 unsigned int j; 00109 00110 ALIGN16_DECL(struct spu_exec_vector, inputs, PIPE_MAX_ATTRIBS); 00111 ALIGN16_DECL(struct spu_exec_vector, outputs, PIPE_MAX_ATTRIBS); 00112 const float *scale = draw->viewport.scale; 00113 const float *trans = draw->viewport.translate; 00114 00115 ASSERT(count <= 4); 00116 00117 machine->Processor = TGSI_PROCESSOR_VERTEX; 00118 00119 ASSERT_ALIGN16(draw->constants); 00120 machine->Consts = (float (*)[4]) draw->constants; 00121 00122 machine->Inputs = ALIGN16_ASSIGN(inputs); 00123 machine->Outputs = ALIGN16_ASSIGN(outputs); 00124 00125 spu_vertex_fetch( draw, machine, elts, count ); 00126 00127 /* run shader */ 00128 spu_exec_machine_run( machine ); 00129 00130 00131 /* store machine results */ 00132 for (j = 0; j < count; j++) { 00133 unsigned slot; 00134 float x, y, z, w; 00135 unsigned char buffer[sizeof(struct vertex_header) 00136 + MAX_VERTEX_SIZE] ALIGN16_ATTRIB; 00137 struct vertex_header *const tmpOut = 00138 (struct vertex_header *) buffer; 00139 const unsigned vert_size = ROUNDUP16(sizeof(struct vertex_header) 00140 + (sizeof(float) * 4 00141 * draw->num_vs_outputs)); 00142 00143 mfc_get(tmpOut, vOut[j], vert_size, TAG_VERTEX_BUFFER, 0, 0); 00144 wait_on_mask(1 << TAG_VERTEX_BUFFER); 00145 00146 00147 /* Handle attr[0] (position) specially: 00148 * 00149 * XXX: Computing the clipmask should be done in the vertex 00150 * program as a set of DP4 instructions appended to the 00151 * user-provided code. 00152 */ 00153 x = tmpOut->clip[0] = machine->Outputs[0].xyzw[0].f[j]; 00154 y = tmpOut->clip[1] = machine->Outputs[0].xyzw[1].f[j]; 00155 z = tmpOut->clip[2] = machine->Outputs[0].xyzw[2].f[j]; 00156 w = tmpOut->clip[3] = machine->Outputs[0].xyzw[3].f[j]; 00157 00158 tmpOut->clipmask = compute_clipmask(tmpOut->clip, draw->plane, 00159 draw->nr_planes); 00160 tmpOut->edgeflag = 1; 00161 00162 /* divide by w */ 00163 w = 1.0f / w; 00164 x *= w; 00165 y *= w; 00166 z *= w; 00167 00168 /* Viewport mapping */ 00169 tmpOut->data[0][0] = x * scale[0] + trans[0]; 00170 tmpOut->data[0][1] = y * scale[1] + trans[1]; 00171 tmpOut->data[0][2] = z * scale[2] + trans[2]; 00172 tmpOut->data[0][3] = w; 00173 00174 /* Remaining attributes are packed into sequential post-transform 00175 * vertex attrib slots. 00176 */ 00177 for (slot = 1; slot < draw->num_vs_outputs; slot++) { 00178 tmpOut->data[slot][0] = machine->Outputs[slot].xyzw[0].f[j]; 00179 tmpOut->data[slot][1] = machine->Outputs[slot].xyzw[1].f[j]; 00180 tmpOut->data[slot][2] = machine->Outputs[slot].xyzw[2].f[j]; 00181 tmpOut->data[slot][3] = machine->Outputs[slot].xyzw[3].f[j]; 00182 } 00183 00184 mfc_put(tmpOut, vOut[j], vert_size, TAG_VERTEX_BUFFER, 0, 0); 00185 } /* loop over vertices */ 00186 }
void spu_bind_vertex_shader | ( | struct spu_vs_context * | draw, | |
struct cell_shader_info * | vs | |||
) |
Definition at line 194 of file spu_vertex_shader.c.
References cell_shader_info::declarations, spu_exec_machine::Declarations, cell_shader_info::immediates, spu_exec_machine::Imms, cell_shader_info::instructions, spu_exec_machine::Instructions, spu_vs_context::machine, cell_shader_info::num_declarations, cell_shader_info::num_immediates, cell_shader_info::num_instructions, cell_shader_info::num_outputs, spu_vs_context::num_vs_outputs, spu_exec_machine::NumDeclarations, spu_exec_machine::NumInstructions, PIPE_MAX_SAMPLERS, PIPE_SHADER_VERTEX, ROUNDUP16, spu_exec_machine_init(), TAG_VERTEX_BUFFER, and wait_on_mask().
00196 { 00197 const unsigned immediate_addr = vs->immediates; 00198 const unsigned immediate_size = 00199 ROUNDUP16((sizeof(float) * 4 * vs->num_immediates) 00200 + (immediate_addr & 0x0f)); 00201 00202 00203 mfc_get(immediates, immediate_addr & ~0x0f, immediate_size, 00204 TAG_VERTEX_BUFFER, 0, 0); 00205 00206 draw->machine.Instructions = (struct tgsi_full_instruction *) 00207 vs->instructions; 00208 draw->machine.NumInstructions = vs->num_instructions; 00209 00210 draw->machine.Declarations = (struct tgsi_full_declaration *) 00211 vs->declarations; 00212 draw->machine.NumDeclarations = vs->num_declarations; 00213 00214 draw->num_vs_outputs = vs->num_outputs; 00215 00216 /* specify the shader to interpret/execute */ 00217 spu_exec_machine_init(&draw->machine, 00218 PIPE_MAX_SAMPLERS, 00219 NULL /*samplers*/, 00220 PIPE_SHADER_VERTEX); 00221 00222 wait_on_mask(1 << TAG_VERTEX_BUFFER); 00223 00224 (void) memcpy(& draw->machine.Imms, &immediates[immediate_addr & 0x0f], 00225 sizeof(float) * 4 * vs->num_immediates); 00226 }
void spu_execute_vertex_shader | ( | struct spu_vs_context * | draw, | |
const struct cell_command_vs * | vs | |||
) |
Definition at line 230 of file spu_vertex_shader.c.
References cell_command_vs::elts, MIN2, cell_command_vs::nr_attrs, spu_vs_context::nr_attrs, spu_vs_context::nr_planes, cell_command_vs::nr_planes, cell_command_vs::num_elts, cell_command_vs::plane, spu_vs_context::plane, run_vertex_program(), spu_vs_context::vertex_fetch, and cell_command_vs::vOut.
00232 { 00233 unsigned i; 00234 00235 (void) memcpy(draw->plane, vs->plane, sizeof(float) * 4 * vs->nr_planes); 00236 draw->nr_planes = vs->nr_planes; 00237 draw->vertex_fetch.nr_attrs = vs->nr_attrs; 00238 00239 for (i = 0; i < vs->num_elts; i += 4) { 00240 const unsigned batch_size = MIN2(vs->num_elts - i, 4); 00241 00242 run_vertex_program(draw, & vs->elts[i], batch_size, &vs->vOut[i]); 00243 } 00244 }
unsigned char immediates [(sizeof(float) * 4 * TGSI_EXEC_NUM_IMMEDIATES) + 32] ALIGN16_ATTRIB |
Definition at line 190 of file spu_vertex_shader.c.