Code reorganization: move files into their places.
[mesa.git] / src / gallium / drivers / cell / ppu / cell_vertex_shader.c
1 /*
2 * (C) Copyright IBM Corporation 2008
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * AUTHORS, COPYRIGHT HOLDERS, AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /**
26 * \file cell_vertex_shader.c
27 * Vertex shader interface routines for Cell.
28 *
29 * \author Ian Romanick <idr@us.ibm.com>
30 */
31
32 #include "pipe/p_defines.h"
33 #include "pipe/p_context.h"
34 #include "pipe/p_winsys.h"
35
36 #include "cell_context.h"
37 #include "cell_draw_arrays.h"
38 #include "cell_spu.h"
39 #include "cell_batch.h"
40
41 #include "pipe/cell/common.h"
42 #include "pipe/draw/draw_context.h"
43 #include "pipe/draw/draw_private.h"
44
45 /**
46 * Run the vertex shader on all vertices in the vertex queue.
47 * Called by the draw module when the vertx cache needs to be flushed.
48 */
49 void
50 cell_vertex_shader_queue_flush(struct draw_context *draw)
51 {
52 struct cell_context *const cell =
53 (struct cell_context *) draw->driver_private;
54 struct cell_command_vs *const vs = &cell_global.command[0].vs;
55 uint64_t *batch;
56 struct cell_array_info *array_info;
57 unsigned i, j;
58
59 assert(draw->vs.queue_nr != 0);
60
61 /* XXX: do this on statechange:
62 */
63 draw_update_vertex_fetch(draw);
64
65 for (i = 0; i < draw->vertex_fetch.nr_attrs; i++) {
66 batch = cell_batch_alloc(cell, sizeof(batch[0]) + sizeof(*array_info));
67
68 batch[0] = CELL_CMD_STATE_VS_ARRAY_INFO;
69
70 array_info = (struct cell_array_info *) &batch[1];
71 assert(draw->vertex_fetch.src_ptr[i] != NULL);
72 array_info->base = (uintptr_t) draw->vertex_fetch.src_ptr[i];
73 array_info->attr = i;
74 array_info->pitch = draw->vertex_fetch.pitch[i];
75 array_info->format = draw->vertex_element[i].src_format;
76 }
77
78 batch = cell_batch_alloc(cell, sizeof(batch[0])
79 + sizeof(struct pipe_viewport_state));
80 batch[0] = CELL_CMD_STATE_VIEWPORT;
81 (void) memcpy(&batch[1], &draw->viewport,
82 sizeof(struct pipe_viewport_state));
83
84 cell_batch_flush(cell);
85
86 vs->opcode = CELL_CMD_VS_EXECUTE;
87 vs->shader.num_outputs = draw->num_vs_outputs;
88 vs->shader.declarations = (uintptr_t) draw->machine.Declarations;
89 vs->shader.num_declarations = draw->machine.NumDeclarations;
90 vs->shader.instructions = (uintptr_t) draw->machine.Instructions;
91 vs->shader.num_instructions = draw->machine.NumInstructions;
92 vs->shader.uniforms = (uintptr_t) draw->user.constants;
93 vs->shader.immediates = (uintptr_t) draw->machine.Imms;
94 vs->shader.num_immediates = draw->machine.ImmLimit / 4;
95 vs->nr_attrs = draw->vertex_fetch.nr_attrs;
96
97 (void) memcpy(vs->plane, draw->plane, sizeof(draw->plane));
98 vs->nr_planes = draw->nr_planes;
99
100 for (i = 0; i < draw->vs.queue_nr; i += SPU_VERTS_PER_BATCH) {
101 const unsigned n = MIN2(SPU_VERTS_PER_BATCH, draw->vs.queue_nr - i);
102
103 for (j = 0; j < n; j++) {
104 vs->elts[j] = draw->vs.queue[i + j].elt;
105 vs->vOut[j] = (uintptr_t) draw->vs.queue[i + j].dest;
106 }
107
108 for (/* empty */; j < SPU_VERTS_PER_BATCH; j++) {
109 vs->elts[j] = vs->elts[0];
110 vs->vOut[j] = vs->vOut[0];
111 }
112
113 vs->num_elts = n;
114 send_mbox_message(cell_global.spe_contexts[0], CELL_CMD_VS_EXECUTE);
115
116 cell_flush_int(& cell->pipe, PIPE_FLUSH_WAIT);
117 }
118
119 draw->vs.queue_nr = 0;
120 }