* Simple pass-through fragment shader to use when we don't have
* a real shader (or it fails to compile for some reason).
*/
-static unsigned passthrough_decl[] = {
- _3DSTATE_PIXEL_SHADER_PROGRAM | ((1 * 3) - 1),
-};
-
static unsigned passthrough_program[] = {
+ _3DSTATE_PIXEL_SHADER_PROGRAM | ((1 * 3) - 1),
/* move to output color:
*/
(A0_MOV | (REG_TYPE_OC << A0_DEST_TYPE_SHIFT) | A0_DEST_CHANNEL_ALL |
i915_use_passthrough_shader(struct i915_fragment_shader *fs)
{
fs->program = (uint *)MALLOC(sizeof(passthrough_program));
- fs->decl = (uint *)MALLOC(sizeof(passthrough_decl));
if (fs->program) {
memcpy(fs->program, passthrough_program, sizeof(passthrough_program));
- memcpy(fs->decl, passthrough_decl, sizeof(passthrough_decl));
fs->program_len = ARRAY_SIZE(passthrough_program);
- fs->decl_len = ARRAY_SIZE(passthrough_decl);
}
fs->num_constants = 0;
}
/* Copy compilation results to fragment program struct:
*/
- assert(!ifs->decl);
assert(!ifs->program);
- ifs->decl = (uint *)MALLOC(decl_size * sizeof(uint));
- ifs->program = (uint *)MALLOC(program_size * sizeof(uint));
-
- if (ifs->decl) {
- ifs->decl_len = decl_size;
-
- memcpy(ifs->decl, p->declarations, decl_size * sizeof(uint));
- }
-
- if (ifs->program) {
- ifs->program_len = program_size;
-
- memcpy(ifs->program, p->program, program_size * sizeof(uint));
- }
+ ifs->program_len = decl_size + program_size;
+ ifs->program = (uint *)MALLOC(ifs->program_len * sizeof(uint));
+ memcpy(ifs->program, p->declarations, decl_size * sizeof(uint));
+ memcpy(&ifs->program[decl_size], p->program, program_size * sizeof(uint));
}
/* Release the compilation struct:
static void
validate_program(struct i915_context *i915, unsigned *batch_space)
{
- uint additional_size = 0;
-
- additional_size += i915->current.fixup_swizzle ? 3 : 0;
-
/* we need more batch space if we want to emulate rgba framebuffers */
- *batch_space = i915->fs->decl_len + i915->fs->program_len + additional_size;
+ *batch_space = i915->fs->program_len + (i915->current.fixup_swizzle ? 3 : 0);
}
static void
emit_program(struct i915_context *i915)
{
- uint additional_size = 0;
- uint i;
-
- /* count how much additional space we'll need */
- validate_program(i915, &additional_size);
- additional_size -= i915->fs->decl_len + i915->fs->program_len;
-
/* we should always have, at least, a pass-through program */
assert(i915->fs->program_len > 0);
- /* output the declarations */
- {
- /* first word has the size, we have to adjust that */
- uint size = (i915->fs->decl[0]);
- size += additional_size;
- OUT_BATCH(size);
- }
+ /* If we're doing a fixup swizzle, that's 3 more dwords to add. */
+ uint32_t additional_size = 0;
+ if (i915->current.fixup_swizzle)
+ additional_size = 3;
+
+ /* output the program: 1 dword of header, then 3 dwords per decl/instruction */
+ assert(i915->fs->program_len % 3 == 1);
- for (i = 1; i < i915->fs->decl_len; i++)
- OUT_BATCH(i915->fs->decl[i]);
+ /* first word has the size, adjust it for fixup swizzle */
+ OUT_BATCH(i915->fs->program[0] + additional_size);
- /* output the program */
- assert(i915->fs->program_len % 3 == 0);
- for (i = 0; i < i915->fs->program_len; i += 3) {
+ for (int i = 1; i < i915->fs->program_len; i++)
OUT_BATCH(i915->fs->program[i]);
- OUT_BATCH(i915->fs->program[i + 1]);
- OUT_BATCH(i915->fs->program[i + 2]);
- }
/* we emit an additional mov with swizzle to fake RGBA framebuffers */
if (i915->current.fixup_swizzle) {