102
103
++vsctx->num_outputs;
105
static void insert_output(struct tgsi_transform_context *ctx,
106
struct tgsi_full_declaration *before,
107
unsigned name, unsigned index, unsigned interp)
106
static void insert_output_before(struct tgsi_transform_context *ctx,
107
struct tgsi_full_declaration *before,
108
unsigned name, unsigned index, unsigned interp)
109
110
struct vs_transform_context *vsctx = (struct vs_transform_context *)ctx;
117
118
/* Insert the new output. */
118
emit_output(ctx, name, index, interp, before->Range.First);
119
emit_output(ctx, name, index, interp,
120
before->Range.First + vsctx->decl_shift);
120
122
++vsctx->decl_shift;
123
static void insert_trailing_bcolor(struct tgsi_transform_context *ctx,
124
struct tgsi_full_declaration *before)
125
static void insert_output_after(struct tgsi_transform_context *ctx,
126
struct tgsi_full_declaration *after,
127
unsigned name, unsigned index, unsigned interp)
126
129
struct vs_transform_context *vsctx = (struct vs_transform_context *)ctx;
128
/* If BCOLOR0 is used, make sure BCOLOR1 is present too. Otherwise
129
* the rasterizer doesn't do the color selection correctly. */
130
if (vsctx->bcolor_used[0] && !vsctx->bcolor_used[1]) {
132
insert_output(ctx, before, TGSI_SEMANTIC_BCOLOR, 1,
133
TGSI_INTERPOLATE_LINEAR);
135
emit_output(ctx, TGSI_SEMANTIC_BCOLOR, 1,
136
TGSI_INTERPOLATE_LINEAR, vsctx->num_outputs);
138
vsctx->bcolor_used[1] = TRUE;
132
/* Make a place for the new output. */
133
for (i = after->Range.First+1; i < Elements(vsctx->out_remap); i++) {
134
++vsctx->out_remap[i];
137
/* Insert the new output. */
138
emit_output(ctx, name, index, interp,
139
after->Range.First + 1);
142
144
static void transform_decl(struct tgsi_transform_context *ctx,
154
156
case TGSI_SEMANTIC_COLOR:
155
157
assert(decl->Semantic.Index < 2);
156
vsctx->color_used[decl->Semantic.Index] = TRUE;
158
159
/* We must rasterize the first color if the second one is
159
160
* used, otherwise the rasterizer doesn't do the color
160
161
* selection correctly. Declare it, but don't write to it. */
161
162
if (decl->Semantic.Index == 1 && !vsctx->color_used[0]) {
162
insert_output(ctx, decl, TGSI_SEMANTIC_COLOR, 0,
163
TGSI_INTERPOLATE_LINEAR);
163
insert_output_before(ctx, decl, TGSI_SEMANTIC_COLOR, 0,
164
TGSI_INTERPOLATE_LINEAR);
164
165
vsctx->color_used[0] = TRUE;
168
169
case TGSI_SEMANTIC_BCOLOR:
169
170
assert(decl->Semantic.Index < 2);
170
vsctx->bcolor_used[decl->Semantic.Index] = TRUE;
172
172
/* We must rasterize all 4 colors if back-face colors are
173
173
* used, otherwise the rasterizer doesn't do the color
174
174
* selection correctly. Declare it, but don't write to it. */
175
175
if (!vsctx->color_used[0]) {
176
insert_output(ctx, decl, TGSI_SEMANTIC_COLOR, 0,
177
TGSI_INTERPOLATE_LINEAR);
176
insert_output_before(ctx, decl, TGSI_SEMANTIC_COLOR, 0,
177
TGSI_INTERPOLATE_LINEAR);
178
178
vsctx->color_used[0] = TRUE;
180
180
if (!vsctx->color_used[1]) {
181
insert_output(ctx, decl, TGSI_SEMANTIC_COLOR, 1,
182
TGSI_INTERPOLATE_LINEAR);
181
insert_output_before(ctx, decl, TGSI_SEMANTIC_COLOR, 1,
182
TGSI_INTERPOLATE_LINEAR);
183
183
vsctx->color_used[1] = TRUE;
185
185
if (decl->Semantic.Index == 1 && !vsctx->bcolor_used[0]) {
186
insert_output(ctx, decl, TGSI_SEMANTIC_BCOLOR, 0,
187
TGSI_INTERPOLATE_LINEAR);
186
insert_output_before(ctx, decl, TGSI_SEMANTIC_BCOLOR, 0,
187
TGSI_INTERPOLATE_LINEAR);
188
188
vsctx->bcolor_used[0] = TRUE;
190
/* One more case is handled in insert_trailing_bcolor. */
193
192
case TGSI_SEMANTIC_GENERIC:
216
210
ctx->emit_declaration(ctx, decl);
212
/* Insert BCOLOR1 if needed. */
213
if (decl->Declaration.File == TGSI_FILE_OUTPUT &&
214
decl->Semantic.Name == TGSI_SEMANTIC_BCOLOR &&
215
!vsctx->bcolor_used[1]) {
216
insert_output_after(ctx, decl, TGSI_SEMANTIC_BCOLOR, 1,
217
TGSI_INTERPOLATE_LINEAR);
219
221
static void transform_inst(struct tgsi_transform_context *ctx,
226
228
if (!vsctx->first_instruction) {
227
229
vsctx->first_instruction = TRUE;
229
/* The trailing BCOLOR should be inserted before the code
230
* if it hasn't already been done so. */
231
insert_trailing_bcolor(ctx, NULL);
233
231
/* Insert the generic output for WPOS. */
234
232
emit_output(ctx, TGSI_SEMANTIC_GENERIC, vsctx->last_generic + 1,
235
233
TGSI_INTERPOLATE_PERSPECTIVE, vsctx->num_outputs);
309
307
ctx->emit_instruction(ctx, inst);
312
void r300_draw_init_vertex_shader(struct draw_context *draw,
310
void r300_draw_init_vertex_shader(struct r300_context *r300,
313
311
struct r300_vertex_shader *vs)
313
struct draw_context *draw = r300->draw;
315
314
struct pipe_shader_state new_vs;
315
struct tgsi_shader_info info;
316
316
struct vs_transform_context transform;
317
317
const uint newLen = tgsi_num_tokens(vs->state.tokens) + 100 /* XXX */;
320
tgsi_scan_shader(vs->state.tokens, &info);
320
322
new_vs.tokens = tgsi_alloc_tokens(newLen);
321
323
if (new_vs.tokens == NULL)
329
331
transform.base.transform_instruction = transform_inst;
330
332
transform.base.transform_declaration = transform_decl;
334
for (i = 0; i < info.num_outputs; i++) {
335
unsigned index = info.output_semantic_index[i];
337
switch (info.output_semantic_name[i]) {
338
case TGSI_SEMANTIC_COLOR:
340
transform.color_used[index] = TRUE;
343
case TGSI_SEMANTIC_BCOLOR:
345
transform.bcolor_used[index] = TRUE;
332
350
tgsi_transform_shader(vs->state.tokens,
333
351
(struct tgsi_token*)new_vs.tokens,
334
352
newLen, &transform.base);