From be4de05c1093db27b3fca12b782055ab8a1eba13 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Christian=20K=C3=B6nig?= Date: Sun, 12 Dec 2010 22:55:23 +0100 Subject: [PATCH] [g3dvl] move idct texture addr generation into vertex shader --- src/gallium/auxiliary/vl/vl_idct.c | 272 +++++++++++++++-------------- src/gallium/auxiliary/vl/vl_idct.h | 2 +- 2 files changed, 143 insertions(+), 131 deletions(-) diff --git a/src/gallium/auxiliary/vl/vl_idct.c b/src/gallium/auxiliary/vl/vl_idct.c index 1a29b91cf51..5a32573dd66 100644 --- a/src/gallium/auxiliary/vl/vl_idct.c +++ b/src/gallium/auxiliary/vl/vl_idct.c @@ -58,9 +58,10 @@ enum VS_INPUT enum VS_OUTPUT { VS_O_VPOS, - VS_O_BLOCK, - VS_O_TEX, - VS_O_START + VS_O_L_ADDR0, + VS_O_L_ADDR1, + VS_O_R_ADDR0, + VS_O_R_ADDR1 }; static const float const_matrix[8][8] = { @@ -74,28 +75,58 @@ static const float const_matrix[8][8] = { { 0.0975451f, -0.2777850f, 0.4157350f, -0.4903930f, 0.4903930f, -0.4157350f, 0.277786f, -0.0975458f } }; +static void +calc_addr(struct ureg_program *shader, struct ureg_dst addr[2], + struct ureg_src tc, struct ureg_src start, bool right_side, + bool transposed, float size) +{ + unsigned wm_start = (right_side == transposed) ? TGSI_WRITEMASK_X : TGSI_WRITEMASK_Y; + unsigned sw_start = right_side ? TGSI_SWIZZLE_Y : TGSI_SWIZZLE_X; + + unsigned wm_tc = (right_side == transposed) ? TGSI_WRITEMASK_Y : TGSI_WRITEMASK_X; + unsigned sw_tc = right_side ? TGSI_SWIZZLE_X : TGSI_SWIZZLE_Y; + + /* + * addr[0..1].(start) = right_side ? start.x : tc.x + * addr[0..1].(tc) = right_side ? tc.y : start.y + * addr[0..1].z = tc.z + * addr[1].(start) += 1.0f / scale + */ + ureg_MOV(shader, ureg_writemask(addr[0], wm_start), ureg_scalar(start, sw_start)); + ureg_MOV(shader, ureg_writemask(addr[0], wm_tc), ureg_scalar(tc, sw_tc)); + ureg_MOV(shader, ureg_writemask(addr[0], TGSI_WRITEMASK_Z), tc); + + ureg_ADD(shader, ureg_writemask(addr[1], wm_start), ureg_scalar(start, sw_start), ureg_imm1f(shader, 1.0f / size)); + ureg_MOV(shader, ureg_writemask(addr[1], wm_tc), ureg_scalar(tc, sw_tc)); + ureg_MOV(shader, ureg_writemask(addr[1], TGSI_WRITEMASK_Z), tc); +} + static void * -create_vert_shader(struct vl_idct *idct) +create_vert_shader(struct vl_idct *idct, bool matrix_stage) { struct ureg_program *shader; struct ureg_src scale; struct ureg_src vrect, vpos; - struct ureg_dst t_vpos; - struct ureg_dst o_vpos, o_block, o_tex, o_start; + struct ureg_dst t_tex, t_start; + struct ureg_dst o_vpos, o_l_addr[2], o_r_addr[2]; shader = ureg_create(TGSI_PROCESSOR_VERTEX); if (!shader) return NULL; - t_vpos = ureg_DECL_temporary(shader); + t_tex = ureg_DECL_temporary(shader); + t_start = ureg_DECL_temporary(shader); vrect = ureg_DECL_vs_input(shader, VS_I_RECT); vpos = ureg_DECL_vs_input(shader, VS_I_VPOS); o_vpos = ureg_DECL_output(shader, TGSI_SEMANTIC_POSITION, VS_O_VPOS); - o_block = ureg_DECL_output(shader, TGSI_SEMANTIC_GENERIC, VS_O_BLOCK); - o_tex = ureg_DECL_output(shader, TGSI_SEMANTIC_GENERIC, VS_O_TEX); - o_start = ureg_DECL_output(shader, TGSI_SEMANTIC_GENERIC, VS_O_START); + + o_l_addr[0] = ureg_DECL_output(shader, TGSI_SEMANTIC_GENERIC, VS_O_L_ADDR0); + o_l_addr[1] = ureg_DECL_output(shader, TGSI_SEMANTIC_GENERIC, VS_O_L_ADDR1); + + o_r_addr[0] = ureg_DECL_output(shader, TGSI_SEMANTIC_GENERIC, VS_O_R_ADDR0); + o_r_addr[1] = ureg_DECL_output(shader, TGSI_SEMANTIC_GENERIC, VS_O_R_ADDR1); /* * scale = (BLOCK_WIDTH, BLOCK_HEIGHT) / (dst.width, dst.height) @@ -104,76 +135,48 @@ create_vert_shader(struct vl_idct *idct) * o_vpos.xy = t_vpos * scale * o_vpos.zw = vpos * - * o_block = vrect - * o_tex = t_pos - * o_start = vpos * scale + * o_l_addr = calc_addr(...) + * o_r_addr = calc_addr(...) * */ scale = ureg_imm2f(shader, (float)BLOCK_WIDTH / idct->buffer_width, (float)BLOCK_HEIGHT / idct->buffer_height); - ureg_ADD(shader, ureg_writemask(t_vpos, TGSI_WRITEMASK_XY), vpos, vrect); - ureg_MUL(shader, ureg_writemask(t_vpos, TGSI_WRITEMASK_XY), ureg_src(t_vpos), scale); - ureg_MOV(shader, ureg_writemask(o_vpos, TGSI_WRITEMASK_XY), ureg_src(t_vpos)); + ureg_ADD(shader, ureg_writemask(t_tex, TGSI_WRITEMASK_XY), vpos, vrect); + ureg_MUL(shader, ureg_writemask(t_tex, TGSI_WRITEMASK_XY), ureg_src(t_tex), scale); + ureg_MOV(shader, ureg_writemask(o_vpos, TGSI_WRITEMASK_XY), ureg_src(t_tex)); ureg_MOV(shader, ureg_writemask(o_vpos, TGSI_WRITEMASK_ZW), vpos); - ureg_MOV(shader, ureg_writemask(o_block, TGSI_WRITEMASK_XY), vrect); - ureg_MOV(shader, ureg_writemask(o_block, TGSI_WRITEMASK_Z), ureg_imm1f(shader, 0.0f)); - - ureg_MOV(shader, ureg_writemask(o_tex, TGSI_WRITEMASK_XY), ureg_src(t_vpos)); -#if NR_RENDER_TARGETS == 1 - ureg_MOV(shader, ureg_writemask(o_tex, TGSI_WRITEMASK_Z), ureg_imm1f(shader, 0.0f)); -#else - ureg_MUL(shader, ureg_writemask(o_tex, TGSI_WRITEMASK_Z), + ureg_MUL(shader, ureg_writemask(t_tex, TGSI_WRITEMASK_Z), ureg_scalar(vrect, TGSI_SWIZZLE_X), ureg_imm1f(shader, BLOCK_WIDTH / NR_RENDER_TARGETS)); -#endif - ureg_MUL(shader, ureg_writemask(o_start, TGSI_WRITEMASK_XY), vpos, scale); + ureg_MUL(shader, ureg_writemask(t_start, TGSI_WRITEMASK_XY), vpos, scale); - ureg_release_temporary(shader, t_vpos); + if(matrix_stage) { + calc_addr(shader, o_l_addr, ureg_src(t_tex), ureg_src(t_start), false, false, idct->buffer_width / 4); + calc_addr(shader, o_r_addr, vrect, ureg_imm1f(shader, 0.0f), true, true, BLOCK_WIDTH / 4); + } else { + calc_addr(shader, o_l_addr, vrect, ureg_imm1f(shader, 0.0f), false, false, BLOCK_WIDTH / 4); + calc_addr(shader, o_r_addr, ureg_src(t_tex), ureg_src(t_start), true, false, idct->buffer_height / 4); + } + + ureg_release_temporary(shader, t_tex); + ureg_release_temporary(shader, t_start); ureg_END(shader); return ureg_create_shader_and_destroy(shader, idct->pipe); } -static void -calc_addr(struct ureg_program *shader, struct ureg_dst addr[2], - struct ureg_src tc, struct ureg_src start, bool right_side, - bool transposed, float size) -{ - unsigned wm_start = (right_side == transposed) ? TGSI_WRITEMASK_X : TGSI_WRITEMASK_Y; - unsigned wm_tc = (right_side == transposed) ? TGSI_WRITEMASK_Y : TGSI_WRITEMASK_X; - - addr[0] = ureg_DECL_temporary(shader); - addr[1] = ureg_DECL_temporary(shader); - - /* - * t_tc.x = right_side ? start.x : tc.x - * t_tc.y = right_side ? tc.y : start.y - * m[0..1] = tex(t_tc++, sampler) - */ - if(!right_side) { - ureg_MOV(shader, ureg_writemask(addr[0], wm_start), ureg_scalar(start, TGSI_SWIZZLE_X)); - ureg_MOV(shader, ureg_writemask(addr[0], wm_tc), ureg_scalar(tc, TGSI_SWIZZLE_Y)); - } else { - ureg_MOV(shader, ureg_writemask(addr[0], wm_start), ureg_scalar(start, TGSI_SWIZZLE_Y)); - ureg_MOV(shader, ureg_writemask(addr[0], wm_tc), ureg_scalar(tc, TGSI_SWIZZLE_X)); - } - ureg_FRC(shader, ureg_writemask(addr[0], TGSI_WRITEMASK_Z), tc); - - ureg_ADD(shader, ureg_writemask(addr[1], wm_start), ureg_src(addr[0]), ureg_imm1f(shader, 1.0f / size)); - ureg_MOV(shader, ureg_writemask(addr[1], wm_tc | TGSI_WRITEMASK_Z), ureg_src(addr[0])); -} - static void increment_addr(struct ureg_program *shader, struct ureg_dst addr[2], bool right_side, bool transposed, float size) { unsigned wm_tc = (right_side == transposed) ? TGSI_WRITEMASK_Y : TGSI_WRITEMASK_X; + /* addr[0..1]++ */ ureg_ADD(shader, ureg_writemask(addr[0], wm_tc), ureg_src(addr[0]), ureg_imm1f(shader, 1.0f / size)); ureg_ADD(shader, ureg_writemask(addr[1], wm_tc), @@ -181,13 +184,13 @@ increment_addr(struct ureg_program *shader, struct ureg_dst addr[2], } static void -fetch_four(struct ureg_program *shader, struct ureg_dst m[2], struct ureg_dst addr[2], struct ureg_src sampler) +fetch_four(struct ureg_program *shader, struct ureg_dst m[2], struct ureg_src addr[2], struct ureg_src sampler) { m[0] = ureg_DECL_temporary(shader); m[1] = ureg_DECL_temporary(shader); - ureg_TEX(shader, m[0], TGSI_TEXTURE_3D, ureg_src(addr[0]), sampler); - ureg_TEX(shader, m[1], TGSI_TEXTURE_3D, ureg_src(addr[1]), sampler); + ureg_TEX(shader, m[0], TGSI_TEXTURE_3D, addr[0], sampler); + ureg_TEX(shader, m[1], TGSI_TEXTURE_3D, addr[1], sampler); } static void @@ -210,59 +213,15 @@ matrix_mul(struct ureg_program *shader, struct ureg_dst dst, struct ureg_dst l[2 ureg_release_temporary(shader, tmp); } -static void * -create_transpose_frag_shader(struct vl_idct *idct) -{ - struct ureg_program *shader; - - struct ureg_src block, tex, start; - - struct ureg_dst laddr[2], l[2], r[2], raddr[2]; - struct ureg_dst tmp, fragment; - - shader = ureg_create(TGSI_PROCESSOR_FRAGMENT); - if (!shader) - return NULL; - - block = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, VS_O_BLOCK, TGSI_INTERPOLATE_LINEAR); - tex = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, VS_O_TEX, TGSI_INTERPOLATE_CONSTANT); - start = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, VS_O_START, TGSI_INTERPOLATE_CONSTANT); - - calc_addr(shader, laddr, block, ureg_imm1f(shader, 0.0f), false, false, BLOCK_WIDTH / 4); - calc_addr(shader, raddr, tex, start, true, false, idct->buffer_height / 4); - fetch_four(shader, l, laddr, ureg_DECL_sampler(shader, 0)); - fetch_four(shader, r, raddr, ureg_DECL_sampler(shader, 1)); - - fragment = ureg_DECL_output(shader, TGSI_SEMANTIC_COLOR, 0); - - tmp = ureg_DECL_temporary(shader); - matrix_mul(shader, ureg_writemask(tmp, TGSI_WRITEMASK_X), l, r); - ureg_MUL(shader, fragment, ureg_src(tmp), ureg_imm1f(shader, STAGE2_SCALE)); - - ureg_release_temporary(shader, tmp); - ureg_release_temporary(shader, laddr[0]); - ureg_release_temporary(shader, laddr[1]); - ureg_release_temporary(shader, l[0]); - ureg_release_temporary(shader, l[1]); - ureg_release_temporary(shader, raddr[0]); - ureg_release_temporary(shader, raddr[1]); - ureg_release_temporary(shader, r[0]); - ureg_release_temporary(shader, r[1]); - - ureg_END(shader); - - return ureg_create_shader_and_destroy(shader, idct->pipe); -} - static void * create_matrix_frag_shader(struct vl_idct *idct) { struct ureg_program *shader; - struct ureg_src tex, block, start; + struct ureg_src l_addr[2], r_addr[2], saddr[2]; - struct ureg_dst l[4][2], r[2]; - struct ureg_dst addr[2], fragment[NR_RENDER_TARGETS]; + struct ureg_dst addr[2], l[4][2], r[2]; + struct ureg_dst fragment[NR_RENDER_TARGETS]; unsigned i, j; @@ -270,31 +229,39 @@ create_matrix_frag_shader(struct vl_idct *idct) if (!shader) return NULL; - tex = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, VS_O_TEX, TGSI_INTERPOLATE_LINEAR); - block = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, VS_O_BLOCK, TGSI_INTERPOLATE_LINEAR); - start = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, VS_O_START, TGSI_INTERPOLATE_CONSTANT); + addr[0] = ureg_DECL_temporary(shader); + addr[1] = ureg_DECL_temporary(shader); + + saddr[0] = ureg_src(addr[0]); + saddr[1] = ureg_src(addr[1]); + + l_addr[0] = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, VS_O_L_ADDR0, TGSI_INTERPOLATE_LINEAR); + l_addr[1] = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, VS_O_L_ADDR1, TGSI_INTERPOLATE_LINEAR); + + r_addr[0] = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, VS_O_R_ADDR0, TGSI_INTERPOLATE_LINEAR); + r_addr[1] = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, VS_O_R_ADDR1, TGSI_INTERPOLATE_LINEAR); for (i = 0; i < NR_RENDER_TARGETS; ++i) fragment[i] = ureg_DECL_output(shader, TGSI_SEMANTIC_COLOR, i); for (i = 0; i < 4; ++i) { - if(i == 0) - calc_addr(shader, addr, tex, start, false, false, idct->buffer_width / 4); - else + if(i == 0) { + ureg_MOV(shader, addr[0], l_addr[0]); + ureg_MOV(shader, addr[1], l_addr[1]); + } else increment_addr(shader, addr, false, false, idct->buffer_height); - fetch_four(shader, l[i], addr, ureg_DECL_sampler(shader, 1)); + fetch_four(shader, l[i], saddr, ureg_DECL_sampler(shader, 1)); } - ureg_release_temporary(shader, addr[0]); - ureg_release_temporary(shader, addr[1]); for (i = 0; i < NR_RENDER_TARGETS; ++i) { - if (i == 0) - calc_addr(shader, addr, block, ureg_imm1f(shader, 0.0f), true, true, BLOCK_WIDTH / 4); - else + if(i == 0) { + ureg_MOV(shader, addr[0], r_addr[0]); + ureg_MOV(shader, addr[1], r_addr[1]); + } else increment_addr(shader, addr, true, true, BLOCK_HEIGHT); - fetch_four(shader, r, addr, ureg_DECL_sampler(shader, 0)); + fetch_four(shader, r, saddr, ureg_DECL_sampler(shader, 0)); for (j = 0; j < 4; ++j) { matrix_mul(shader, ureg_writemask(fragment[i], TGSI_WRITEMASK_X << j), l[j], r); @@ -302,13 +269,53 @@ create_matrix_frag_shader(struct vl_idct *idct) ureg_release_temporary(shader, r[0]); ureg_release_temporary(shader, r[1]); } - ureg_release_temporary(shader, addr[0]); - ureg_release_temporary(shader, addr[1]); for (i = 0; i < 4; ++i) { ureg_release_temporary(shader, l[i][0]); ureg_release_temporary(shader, l[i][1]); } + ureg_release_temporary(shader, addr[0]); + ureg_release_temporary(shader, addr[1]); + + ureg_END(shader); + + return ureg_create_shader_and_destroy(shader, idct->pipe); +} + +static void * +create_transpose_frag_shader(struct vl_idct *idct) +{ + struct ureg_program *shader; + + struct ureg_src l_addr[2], r_addr[2]; + + struct ureg_dst l[2], r[2]; + struct ureg_dst tmp, fragment; + + shader = ureg_create(TGSI_PROCESSOR_FRAGMENT); + if (!shader) + return NULL; + + l_addr[0] = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, VS_O_L_ADDR0, TGSI_INTERPOLATE_LINEAR); + l_addr[1] = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, VS_O_L_ADDR1, TGSI_INTERPOLATE_LINEAR); + + r_addr[0] = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, VS_O_R_ADDR0, TGSI_INTERPOLATE_LINEAR); + r_addr[1] = ureg_DECL_fs_input(shader, TGSI_SEMANTIC_GENERIC, VS_O_R_ADDR1, TGSI_INTERPOLATE_LINEAR); + + fetch_four(shader, l, l_addr, ureg_DECL_sampler(shader, 0)); + fetch_four(shader, r, r_addr, ureg_DECL_sampler(shader, 1)); + + fragment = ureg_DECL_output(shader, TGSI_SEMANTIC_COLOR, 0); + + tmp = ureg_DECL_temporary(shader); + matrix_mul(shader, ureg_writemask(tmp, TGSI_WRITEMASK_X), l, r); + ureg_MUL(shader, fragment, ureg_src(tmp), ureg_imm1f(shader, STAGE2_SCALE)); + + ureg_release_temporary(shader, tmp); + ureg_release_temporary(shader, l[0]); + ureg_release_temporary(shader, l[1]); + ureg_release_temporary(shader, r[0]); + ureg_release_temporary(shader, r[1]); ureg_END(shader); @@ -318,21 +325,25 @@ create_matrix_frag_shader(struct vl_idct *idct) static bool init_shaders(struct vl_idct *idct) { - idct->vs = create_vert_shader(idct); + idct->matrix_vs = create_vert_shader(idct, true); idct->matrix_fs = create_matrix_frag_shader(idct); + + idct->transpose_vs = create_vert_shader(idct, false); idct->transpose_fs = create_transpose_frag_shader(idct); return - idct->vs != NULL && - idct->transpose_fs != NULL && - idct->matrix_fs != NULL; + idct->matrix_vs != NULL && + idct->matrix_fs != NULL && + idct->transpose_vs != NULL && + idct->transpose_fs != NULL; } static void cleanup_shaders(struct vl_idct *idct) { - idct->pipe->delete_vs_state(idct->pipe, idct->vs); + idct->pipe->delete_vs_state(idct->pipe, idct->matrix_vs); idct->pipe->delete_fs_state(idct->pipe, idct->matrix_fs); + idct->pipe->delete_vs_state(idct->pipe, idct->transpose_vs); idct->pipe->delete_fs_state(idct->pipe, idct->transpose_fs); } @@ -353,9 +364,9 @@ init_state(struct vl_idct *idct) for (i = 0; i < 4; ++i) { memset(&sampler, 0, sizeof(sampler)); - sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; - sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; - sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; + sampler.wrap_s = PIPE_TEX_WRAP_REPEAT; + sampler.wrap_t = PIPE_TEX_WRAP_REPEAT; + sampler.wrap_r = PIPE_TEX_WRAP_REPEAT; sampler.min_img_filter = PIPE_TEX_FILTER_NEAREST; sampler.min_mip_filter = PIPE_TEX_MIPFILTER_NONE; sampler.mag_img_filter = PIPE_TEX_FILTER_NEAREST; @@ -730,13 +741,13 @@ vl_idct_flush(struct vl_idct *idct, struct vl_idct_buffer *buffer) idct->pipe->bind_rasterizer_state(idct->pipe, idct->rs_state); idct->pipe->set_vertex_buffers(idct->pipe, 2, buffer->vertex_bufs.all); idct->pipe->bind_vertex_elements_state(idct->pipe, idct->vertex_elems_state); - idct->pipe->bind_vs_state(idct->pipe, idct->vs); /* first stage */ idct->pipe->set_framebuffer_state(idct->pipe, &buffer->fb_state[0]); idct->pipe->set_viewport_state(idct->pipe, &buffer->viewport[0]); idct->pipe->set_fragment_sampler_views(idct->pipe, 2, buffer->sampler_views.stage[0]); idct->pipe->bind_fragment_sampler_states(idct->pipe, 2, idct->samplers.stage[0]); + idct->pipe->bind_vs_state(idct->pipe, idct->matrix_vs); idct->pipe->bind_fs_state(idct->pipe, idct->matrix_fs); util_draw_arrays(idct->pipe, PIPE_PRIM_QUADS, 0, num_verts); @@ -745,6 +756,7 @@ vl_idct_flush(struct vl_idct *idct, struct vl_idct_buffer *buffer) idct->pipe->set_viewport_state(idct->pipe, &buffer->viewport[1]); idct->pipe->set_fragment_sampler_views(idct->pipe, 2, buffer->sampler_views.stage[1]); idct->pipe->bind_fragment_sampler_states(idct->pipe, 2, idct->samplers.stage[1]); + idct->pipe->bind_vs_state(idct->pipe, idct->transpose_vs); idct->pipe->bind_fs_state(idct->pipe, idct->transpose_fs); util_draw_arrays(idct->pipe, PIPE_PRIM_QUADS, 0, num_verts); } diff --git a/src/gallium/auxiliary/vl/vl_idct.h b/src/gallium/auxiliary/vl/vl_idct.h index 6076bdec46c..fcba75a7607 100644 --- a/src/gallium/auxiliary/vl/vl_idct.h +++ b/src/gallium/auxiliary/vl/vl_idct.h @@ -53,7 +53,7 @@ struct vl_idct } individual; } samplers; - void *vs; + void *matrix_vs, *transpose_vs; void *matrix_fs, *transpose_fs; struct pipe_resource *matrix; -- 2.30.2