void etna_compile_rs_state(struct compiled_rs_state *cs, const struct rs_state *rs) { /* TILED and SUPERTILED layout have their strides multiplied with 4 in RS */ unsigned source_stride_shift = (rs->source_tiling != ETNA_LAYOUT_LINEAR) ? 2 : 0; unsigned dest_stride_shift = (rs->dest_tiling != ETNA_LAYOUT_LINEAR) ? 2 : 0; /* TODO could just pre-generate command buffer, would simply submit to one memcpy */ SET_STATE(RS_CONFIG, VIVS_RS_CONFIG_SOURCE_FORMAT(rs->source_format) | (rs->downsample_x?VIVS_RS_CONFIG_DOWNSAMPLE_X:0) | (rs->downsample_y?VIVS_RS_CONFIG_DOWNSAMPLE_Y:0) | ((rs->source_tiling&1)?VIVS_RS_CONFIG_SOURCE_TILED:0) | VIVS_RS_CONFIG_DEST_FORMAT(rs->dest_format) | ((rs->dest_tiling&1)?VIVS_RS_CONFIG_DEST_TILED:0) | ((rs->swap_rb)?VIVS_RS_CONFIG_SWAP_RB:0) | ((rs->flip)?VIVS_RS_CONFIG_FLIP:0)); SET_STATE(RS_SOURCE_ADDR, rs->source_addr); SET_STATE(RS_PIPE_SOURCE_ADDR[0], rs->source_addr); SET_STATE(RS_PIPE_SOURCE_ADDR[1], rs->source_addr); /* TODO */ SET_STATE(RS_SOURCE_STRIDE, (rs->source_stride << source_stride_shift) | ((rs->source_tiling&2)?VIVS_RS_SOURCE_STRIDE_TILING:0)); SET_STATE(RS_DEST_ADDR, rs->dest_addr); SET_STATE(RS_PIPE_DEST_ADDR[0], rs->dest_addr); SET_STATE(RS_PIPE_DEST_ADDR[1], rs->dest_addr); /* TODO */ SET_STATE(RS_DEST_STRIDE, (rs->dest_stride << dest_stride_shift) | ((rs->dest_tiling&2)?VIVS_RS_DEST_STRIDE_TILING:0)); SET_STATE(RS_WINDOW_SIZE, VIVS_RS_WINDOW_SIZE_WIDTH(rs->width) | VIVS_RS_WINDOW_SIZE_HEIGHT(rs->height)); SET_STATE(RS_DITHER[0], rs->dither[0]); SET_STATE(RS_DITHER[1], rs->dither[1]); SET_STATE(RS_CLEAR_CONTROL, VIVS_RS_CLEAR_CONTROL_BITS(rs->clear_bits) | rs->clear_mode); SET_STATE(RS_FILL_VALUE[0], rs->clear_value[0]); SET_STATE(RS_FILL_VALUE[1], rs->clear_value[1]); SET_STATE(RS_FILL_VALUE[2], rs->clear_value[2]); SET_STATE(RS_FILL_VALUE[3], rs->clear_value[3]); SET_STATE(RS_EXTRA_CONFIG, VIVS_RS_EXTRA_CONFIG_AA(rs->aa) | VIVS_RS_EXTRA_CONFIG_ENDIAN(rs->endian_mode)); }
void etna_compile_rs_state(struct etna_context *ctx, struct compiled_rs_state *cs, const struct rs_state *rs) { memset(cs, 0, sizeof(*cs)); /* TILED and SUPERTILED layout have their strides multiplied with 4 in RS */ unsigned source_stride_shift = COND(rs->source_tiling != ETNA_LAYOUT_LINEAR, 2); unsigned dest_stride_shift = COND(rs->dest_tiling != ETNA_LAYOUT_LINEAR, 2); /* tiling == ETNA_LAYOUT_MULTI_TILED or ETNA_LAYOUT_MULTI_SUPERTILED? */ int source_multi = COND(rs->source_tiling & ETNA_LAYOUT_BIT_MULTI, 1); int dest_multi = COND(rs->dest_tiling & ETNA_LAYOUT_BIT_MULTI, 1); /* Vivante RS needs widths to be a multiple of 16 or bad things * happen, such as scribbing over memory, or the GPU hanging, * even for non-tiled formats. As this is serious, use abort(). */ if (rs->width & ETNA_RS_WIDTH_MASK) abort(); /* TODO could just pre-generate command buffer, would simply submit to one memcpy */ cs->RS_CONFIG = VIVS_RS_CONFIG_SOURCE_FORMAT(rs->source_format) | COND(rs->downsample_x, VIVS_RS_CONFIG_DOWNSAMPLE_X) | COND(rs->downsample_y, VIVS_RS_CONFIG_DOWNSAMPLE_Y) | COND(rs->source_tiling & 1, VIVS_RS_CONFIG_SOURCE_TILED) | VIVS_RS_CONFIG_DEST_FORMAT(rs->dest_format) | COND(rs->dest_tiling & 1, VIVS_RS_CONFIG_DEST_TILED) | COND(rs->swap_rb, VIVS_RS_CONFIG_SWAP_RB) | COND(rs->flip, VIVS_RS_CONFIG_FLIP); cs->RS_SOURCE_STRIDE = (rs->source_stride << source_stride_shift) | COND(rs->source_tiling & 2, VIVS_RS_SOURCE_STRIDE_TILING) | COND(source_multi, VIVS_RS_SOURCE_STRIDE_MULTI); /* Initially all pipes are set to the base address of the source and * destination buffer respectively. This will be overridden below as * necessary for the multi-pipe, multi-tiled case. */ for (unsigned pipe = 0; pipe < ctx->specs.pixel_pipes; ++pipe) { cs->source[pipe].bo = rs->source; cs->source[pipe].offset = rs->source_offset; cs->source[pipe].flags = ETNA_RELOC_READ; cs->dest[pipe].bo = rs->dest; cs->dest[pipe].offset = rs->dest_offset; cs->dest[pipe].flags = ETNA_RELOC_WRITE; cs->RS_PIPE_OFFSET[pipe] = VIVS_RS_PIPE_OFFSET_X(0) | VIVS_RS_PIPE_OFFSET_Y(0); } cs->RS_DEST_STRIDE = (rs->dest_stride << dest_stride_shift) | COND(rs->dest_tiling & 2, VIVS_RS_DEST_STRIDE_TILING) | COND(dest_multi, VIVS_RS_DEST_STRIDE_MULTI); if (ctx->specs.pixel_pipes == 1 || ctx->specs.single_buffer) { cs->RS_WINDOW_SIZE = VIVS_RS_WINDOW_SIZE_WIDTH(rs->width) | VIVS_RS_WINDOW_SIZE_HEIGHT(rs->height); } else if (ctx->specs.pixel_pipes == 2) { assert((rs->height & 7) == 0); /* GPU hangs happen if height not 8-aligned */ if (source_multi) cs->source[1].offset = rs->source_offset + rs->source_stride * rs->source_padded_height / 2; if (dest_multi) cs->dest[1].offset = rs->dest_offset + rs->dest_stride * rs->dest_padded_height / 2; cs->RS_WINDOW_SIZE = VIVS_RS_WINDOW_SIZE_WIDTH(rs->width) | VIVS_RS_WINDOW_SIZE_HEIGHT(rs->height / 2); cs->RS_PIPE_OFFSET[1] = VIVS_RS_PIPE_OFFSET_X(0) | VIVS_RS_PIPE_OFFSET_Y(rs->height / 2); } else { abort(); } cs->RS_DITHER[0] = rs->dither[0]; cs->RS_DITHER[1] = rs->dither[1]; cs->RS_CLEAR_CONTROL = VIVS_RS_CLEAR_CONTROL_BITS(rs->clear_bits) | rs->clear_mode; cs->RS_FILL_VALUE[0] = rs->clear_value[0]; cs->RS_FILL_VALUE[1] = rs->clear_value[1]; cs->RS_FILL_VALUE[2] = rs->clear_value[2]; cs->RS_FILL_VALUE[3] = rs->clear_value[3]; cs->RS_EXTRA_CONFIG = VIVS_RS_EXTRA_CONFIG_AA(rs->aa) | VIVS_RS_EXTRA_CONFIG_ENDIAN(rs->endian_mode); /* TODO: cs->RS_UNK016B0 = s->size / 64 ? * The blob does this consistently but there seems to be no currently supported * model that needs it. */ }