Merge commit 'origin/master' into gallium-0.2
[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 #include "util/u_math.h"
36
37 #include "cell_context.h"
38 #include "cell_draw_arrays.h"
39 #include "cell_flush.h"
40 #include "cell_spu.h"
41 #include "cell_batch.h"
42
43 #include "cell/common.h"
44 #include "draw/draw_context.h"
45 #include "draw/draw_private.h"
46
47 /**
48 * Run the vertex shader on all vertices in the vertex queue.
49 * Called by the draw module when the vertx cache needs to be flushed.
50 */
51 void
52 cell_vertex_shader_queue_flush(struct draw_context *draw)
53 {
54 #if 0
55 struct cell_context *const cell =
56 (struct cell_context *) draw->driver_private;
57 struct cell_command_vs *const vs = &cell_global.command[0].vs;
58 uint64_t *batch;
59 struct cell_array_info *array_info;
60 unsigned i, j;
61 struct cell_attribute_fetch_code *cf;
62
63 assert(draw->vs.queue_nr != 0);
64
65 /* XXX: do this on statechange:
66 */
67 draw_update_vertex_fetch(draw);
68 cell_update_vertex_fetch(draw);
69
70
71 batch = cell_batch_alloc(cell, sizeof(batch[0]) + sizeof(*cf));
72 batch[0] = CELL_CMD_STATE_ATTRIB_FETCH;
73 cf = (struct cell_attribute_fetch_code *) (&batch[1]);
74 cf->base = (uint64_t) cell->attrib_fetch.store;
75 cf->size = ROUNDUP16((unsigned)((void *) cell->attrib_fetch.csr
76 - (void *) cell->attrib_fetch.store));
77
78
79 for (i = 0; i < draw->vertex_fetch.nr_attrs; i++) {
80 const enum pipe_format format = draw->vertex_element[i].src_format;
81 const unsigned count = ((pf_size_x(format) != 0)
82 + (pf_size_y(format) != 0)
83 + (pf_size_z(format) != 0)
84 + (pf_size_w(format) != 0));
85 const unsigned size = pf_size_x(format) * count;
86
87 batch = cell_batch_alloc(cell, sizeof(batch[0]) + sizeof(*array_info));
88
89 batch[0] = CELL_CMD_STATE_VS_ARRAY_INFO;
90
91 array_info = (struct cell_array_info *) &batch[1];
92 assert(draw->vertex_fetch.src_ptr[i] != NULL);
93 array_info->base = (uintptr_t) draw->vertex_fetch.src_ptr[i];
94 array_info->attr = i;
95 array_info->pitch = draw->vertex_fetch.pitch[i];
96 array_info->size = size;
97 array_info->function_offset = cell->attrib_fetch_offsets[i];
98 }
99
100 batch = cell_batch_alloc(cell, sizeof(batch[0])
101 + sizeof(struct pipe_viewport_state));
102 batch[0] = CELL_CMD_STATE_VIEWPORT;
103 (void) memcpy(&batch[1], &draw->viewport,
104 sizeof(struct pipe_viewport_state));
105
106 {
107 uint64_t uniforms = (uintptr_t) draw->user.constants;
108
109 batch = cell_batch_alloc(cell, 2 *sizeof(batch[0]));
110 batch[0] = CELL_CMD_STATE_UNIFORMS;
111 batch[1] = uniforms;
112 }
113
114 cell_batch_flush(cell);
115
116 vs->opcode = CELL_CMD_VS_EXECUTE;
117 vs->nr_attrs = draw->vertex_fetch.nr_attrs;
118
119 (void) memcpy(vs->plane, draw->plane, sizeof(draw->plane));
120 vs->nr_planes = draw->nr_planes;
121
122 for (i = 0; i < draw->vs.queue_nr; i += SPU_VERTS_PER_BATCH) {
123 const unsigned n = MIN2(SPU_VERTS_PER_BATCH, draw->vs.queue_nr - i);
124
125 for (j = 0; j < n; j++) {
126 vs->elts[j] = draw->vs.queue[i + j].elt;
127 vs->vOut[j] = (uintptr_t) draw->vs.queue[i + j].vertex;
128 }
129
130 for (/* empty */; j < SPU_VERTS_PER_BATCH; j++) {
131 vs->elts[j] = vs->elts[0];
132 vs->vOut[j] = (uintptr_t) draw->vs.queue[i + j].vertex;
133 }
134
135 vs->num_elts = n;
136 send_mbox_message(cell_global.spe_contexts[0], CELL_CMD_VS_EXECUTE);
137
138 cell_flush_int(cell, CELL_FLUSH_WAIT);
139 }
140
141 draw->vs.post_nr = draw->vs.queue_nr;
142 draw->vs.queue_nr = 0;
143 #else
144 assert(0);
145 #endif
146 }