350
350
} fixup_formats[] = {
351
351
{ PIPE_FORMAT_R8G8B8A8_UNORM, 0x21030000 /* BGRA */},
352
{ PIPE_FORMAT_L8_UNORM, 0x00000000 /* RRRR */},
353
{ PIPE_FORMAT_I8_UNORM, 0x00000000 /* RRRR */},
352
{ PIPE_FORMAT_L8_UNORM, 0x00030000 /* RRRA */},
353
{ PIPE_FORMAT_I8_UNORM, 0x00030000 /* RRRA */},
354
354
{ PIPE_FORMAT_A8_UNORM, 0x33330000 /* AAAA */},
355
355
{ PIPE_FORMAT_NONE, 0x00000000},
358
static boolean need_fixup(struct pipe_surface* p)
358
static uint need_target_fixup(struct pipe_surface* p)
360
360
enum pipe_format f;
361
361
/* if we don't have a surface bound yet, we don't need to fixup the shader */
366
366
for(int i=0; fixup_formats[i].format != PIPE_FORMAT_NONE; i++)
367
367
if (fixup_formats[i].format == f)
373
373
static uint fixup_swizzle(enum pipe_format f)
383
383
validate_program(struct i915_context *i915, unsigned *batch_space)
385
385
struct pipe_surface *cbuf_surface = i915->framebuffer.cbufs[0];
386
uint additional_size = need_target_fixup(cbuf_surface);
387
388
/* we need more batch space if we want to emulate rgba framebuffers */
388
*batch_space = i915->fs->program_len + (need_fixup(cbuf_surface) ? 3 : 0);
389
*batch_space = i915->fs->program_len + 3 * additional_size;
392
393
emit_program(struct i915_context *i915)
394
395
struct pipe_surface *cbuf_surface = i915->framebuffer.cbufs[0];
395
boolean need_format_fixup = need_fixup(cbuf_surface);
396
uint target_fixup = need_target_fixup(cbuf_surface);
398
399
/* we should always have, at least, a pass-through program */
399
400
assert(i915->fs->program_len > 0);
400
for (i = 0; i < i915->fs->program_len; i++) {
401
if ((i == 0) && need_format_fixup)
402
OUT_BATCH(i915->fs->program[i] + 3);
404
OUT_BATCH(i915->fs->program[i]);
403
/* first word has the size, we have to adjust that */
404
uint size = (i915->fs->program[0]);
405
size += target_fixup * 3;
409
/* output the declarations of the program */
410
for (i=1 ; i < i915->fs->program_len; i++)
411
OUT_BATCH(i915->fs->program[i]);
407
413
/* we emit an additional mov with swizzle to fake RGBA framebuffers */
408
if (need_format_fixup) {
409
415
/* mov out_color, out_color.zyxw */
410
416
OUT_BATCH(A0_MOV |
411
417
(REG_TYPE_OC << A0_DEST_TYPE_SHIFT) |