diff options
Diffstat (limited to 'src/gallium/state_trackers/xorg/xorg_exa_tgsi.c')
-rw-r--r-- | src/gallium/state_trackers/xorg/xorg_exa_tgsi.c | 294 |
1 files changed, 262 insertions, 32 deletions
diff --git a/src/gallium/state_trackers/xorg/xorg_exa_tgsi.c b/src/gallium/state_trackers/xorg/xorg_exa_tgsi.c index b5288bde4f..cfee10c3b3 100644 --- a/src/gallium/state_trackers/xorg/xorg_exa_tgsi.c +++ b/src/gallium/state_trackers/xorg/xorg_exa_tgsi.c @@ -18,22 +18,24 @@ #include "cso_cache/cso_hash.h" /* Vertex shader: - * IN[0] = src_pos - * IN[1] = mask_pos - * IN[2] = dst_pos + * IN[0] = vertex pos + * IN[1] = src tex coord | solid fill color + * IN[2] = mask tex coord + * IN[3] = dst tex coord * CONST[0] = (2/dst_width, 2/dst_height, 1, 1) * CONST[1] = (-1, -1, 0, 0) * - * OUT[0] = src_pos - * OUT[1] = mask_pos - * OUT[2] = dst_pos + * OUT[0] = vertex pos + * OUT[1] = src tex coord | solid fill color + * OUT[2] = mask tex coord + * OUT[3] = dst tex coord */ /* Fragment shader: * SAMP[0] = src * SAMP[1] = mask * SAMP[2] = dst - * IN[0] = pos src + * IN[0] = pos src | solid fill color * IN[1] = pos mask * IN[2] = pos dst * CONST[0] = (0, 0, 0, 1) @@ -84,6 +86,150 @@ vs_normalize_coords(struct ureg_program *ureg, struct ureg_src coords, return ret; } +static void +linear_gradient(struct ureg_program *ureg, + struct ureg_dst out, + struct ureg_src pos, + struct ureg_src sampler, + struct ureg_src coords, + struct ureg_src const0124, + struct ureg_src matrow0, + struct ureg_src matrow1, + struct ureg_src matrow2) +{ + struct ureg_dst temp0 = ureg_DECL_temporary(ureg); + struct ureg_dst temp1 = ureg_DECL_temporary(ureg); + struct ureg_dst temp2 = ureg_DECL_temporary(ureg); + struct ureg_dst temp3 = ureg_DECL_temporary(ureg); + struct ureg_dst temp4 = ureg_DECL_temporary(ureg); + struct ureg_dst temp5 = ureg_DECL_temporary(ureg); + + ureg_MOV(ureg, + ureg_writemask(temp0, TGSI_WRITEMASK_XY), pos); + ureg_MOV(ureg, + ureg_writemask(temp0, TGSI_WRITEMASK_Z), + ureg_scalar(const0124, TGSI_SWIZZLE_Y)); + + ureg_DP3(ureg, temp1, matrow0, ureg_src(temp0)); + ureg_DP3(ureg, temp2, matrow1, ureg_src(temp0)); + ureg_DP3(ureg, temp3, matrow2, ureg_src(temp0)); + ureg_RCP(ureg, temp3, ureg_src(temp3)); + ureg_MUL(ureg, temp1, ureg_src(temp1), ureg_src(temp3)); + ureg_MUL(ureg, temp2, ureg_src(temp2), ureg_src(temp3)); + + ureg_MOV(ureg, ureg_writemask(temp4, TGSI_WRITEMASK_X), + ureg_src(temp1)); + ureg_MOV(ureg, ureg_writemask(temp4, TGSI_WRITEMASK_Y), + ureg_src(temp2)); + + ureg_MUL(ureg, temp0, + ureg_scalar(coords, TGSI_SWIZZLE_Y), + ureg_scalar(ureg_src(temp4), TGSI_SWIZZLE_Y)); + ureg_MAD(ureg, temp1, + ureg_scalar(coords, TGSI_SWIZZLE_X), + ureg_scalar(ureg_src(temp4), TGSI_SWIZZLE_X), + ureg_src(temp0)); + + ureg_MUL(ureg, temp2, + ureg_src(temp1), + ureg_scalar(coords, TGSI_SWIZZLE_Z)); + + ureg_TEX(ureg, out, + TGSI_TEXTURE_1D, ureg_src(temp2), sampler); + + ureg_release_temporary(ureg, temp0); + ureg_release_temporary(ureg, temp1); + ureg_release_temporary(ureg, temp2); + ureg_release_temporary(ureg, temp3); + ureg_release_temporary(ureg, temp4); + ureg_release_temporary(ureg, temp5); +} + + +static void +radial_gradient(struct ureg_program *ureg, + struct ureg_dst out, + struct ureg_src pos, + struct ureg_src sampler, + struct ureg_src coords, + struct ureg_src const0124, + struct ureg_src matrow0, + struct ureg_src matrow1, + struct ureg_src matrow2) +{ + struct ureg_dst temp0 = ureg_DECL_temporary(ureg); + struct ureg_dst temp1 = ureg_DECL_temporary(ureg); + struct ureg_dst temp2 = ureg_DECL_temporary(ureg); + struct ureg_dst temp3 = ureg_DECL_temporary(ureg); + struct ureg_dst temp4 = ureg_DECL_temporary(ureg); + struct ureg_dst temp5 = ureg_DECL_temporary(ureg); + + ureg_MOV(ureg, + ureg_writemask(temp0, TGSI_WRITEMASK_XY), + pos); + ureg_MOV(ureg, + ureg_writemask(temp0, TGSI_WRITEMASK_Z), + ureg_scalar(const0124, TGSI_SWIZZLE_Y)); + + ureg_DP3(ureg, temp1, matrow0, ureg_src(temp0)); + ureg_DP3(ureg, temp2, matrow1, ureg_src(temp0)); + ureg_DP3(ureg, temp3, matrow2, ureg_src(temp0)); + ureg_RCP(ureg, temp3, ureg_src(temp3)); + ureg_MUL(ureg, temp1, ureg_src(temp1), ureg_src(temp3)); + ureg_MUL(ureg, temp2, ureg_src(temp2), ureg_src(temp3)); + + ureg_MOV(ureg, ureg_writemask(temp5, TGSI_WRITEMASK_X), + ureg_src(temp1)); + ureg_MOV(ureg, ureg_writemask(temp5, TGSI_WRITEMASK_Y), + ureg_src(temp2)); + + ureg_MUL(ureg, temp0, ureg_scalar(coords, TGSI_SWIZZLE_Y), + ureg_scalar(ureg_src(temp5), TGSI_SWIZZLE_Y)); + ureg_MAD(ureg, temp1, + ureg_scalar(coords, TGSI_SWIZZLE_X), + ureg_scalar(ureg_src(temp5), TGSI_SWIZZLE_X), + ureg_src(temp0)); + ureg_ADD(ureg, temp1, + ureg_src(temp1), ureg_src(temp1)); + ureg_MUL(ureg, temp3, + ureg_scalar(ureg_src(temp5), TGSI_SWIZZLE_Y), + ureg_scalar(ureg_src(temp5), TGSI_SWIZZLE_Y)); + ureg_MAD(ureg, temp4, + ureg_scalar(ureg_src(temp5), TGSI_SWIZZLE_X), + ureg_scalar(ureg_src(temp5), TGSI_SWIZZLE_X), + ureg_src(temp3)); + ureg_MOV(ureg, temp4, ureg_negate(ureg_src(temp4))); + ureg_MUL(ureg, temp2, + ureg_scalar(coords, TGSI_SWIZZLE_Z), + ureg_src(temp4)); + ureg_MUL(ureg, temp0, + ureg_scalar(const0124, TGSI_SWIZZLE_W), + ureg_src(temp2)); + ureg_MUL(ureg, temp3, + ureg_src(temp1), ureg_src(temp1)); + ureg_SUB(ureg, temp2, + ureg_src(temp3), ureg_src(temp0)); + ureg_RSQ(ureg, temp2, ureg_abs(ureg_src(temp2))); + ureg_RCP(ureg, temp2, ureg_src(temp2)); + ureg_SUB(ureg, temp1, + ureg_src(temp2), ureg_src(temp1)); + ureg_ADD(ureg, temp0, + ureg_scalar(coords, TGSI_SWIZZLE_Z), + ureg_scalar(coords, TGSI_SWIZZLE_Z)); + ureg_RCP(ureg, temp0, ureg_src(temp0)); + ureg_MUL(ureg, temp2, + ureg_src(temp1), ureg_src(temp0)); + ureg_TEX(ureg, out, TGSI_TEXTURE_1D, + ureg_src(temp2), sampler); + + ureg_release_temporary(ureg, temp0); + ureg_release_temporary(ureg, temp1); + ureg_release_temporary(ureg, temp2); + ureg_release_temporary(ureg, temp3); + ureg_release_temporary(ureg, temp4); + ureg_release_temporary(ureg, temp5); +} + static void * create_vs(struct pipe_context *pipe, unsigned vs_traits) @@ -92,6 +238,9 @@ create_vs(struct pipe_context *pipe, struct ureg_src src; struct ureg_dst dst; struct ureg_src const0, const1; + boolean is_fill = vs_traits & VS_FILL; + boolean is_composite = vs_traits & VS_COMPOSITE; + boolean has_mask = vs_traits & VS_MASK; ureg = ureg_create(TGSI_PROCESSOR_VERTEX); if (ureg == NULL) @@ -100,18 +249,34 @@ create_vs(struct pipe_context *pipe, const0 = ureg_DECL_constant(ureg); const1 = ureg_DECL_constant(ureg); - if ((vs_traits & VS_COMPOSITE)) { + /* it has to be either a fill or a composite op */ + debug_assert(is_fill ^ is_composite); + + src = ureg_DECL_vs_input(ureg, + TGSI_SEMANTIC_POSITION, 0); + dst = ureg_DECL_output(ureg, TGSI_SEMANTIC_POSITION, 0); + src = vs_normalize_coords(ureg, src, + const0, const1); + ureg_MOV(ureg, dst, src); + + + if (is_composite) { src = ureg_DECL_vs_input(ureg, - TGSI_SEMANTIC_POSITION, 0); - dst = ureg_DECL_output(ureg, TGSI_SEMANTIC_POSITION, 0); - src = vs_normalize_coords(ureg, src, - const0, const1); + TGSI_SEMANTIC_GENERIC, 1); + dst = ureg_DECL_output(ureg, TGSI_SEMANTIC_GENERIC, 1); ureg_MOV(ureg, dst, src); } - if ((vs_traits & VS_MASK)) { + if (is_fill) { src = ureg_DECL_vs_input(ureg, - TGSI_SEMANTIC_POSITION, 1); - dst = ureg_DECL_output(ureg, TGSI_SEMANTIC_POSITION, 1); + TGSI_SEMANTIC_COLOR, 1); + dst = ureg_DECL_output(ureg, TGSI_SEMANTIC_COLOR, 1); + ureg_MOV(ureg, dst, src); + } + + if (has_mask) { + src = ureg_DECL_vs_input(ureg, + TGSI_SEMANTIC_GENERIC, 2); + dst = ureg_DECL_output(ureg, TGSI_SEMANTIC_POSITION, 2); ureg_MOV(ureg, dst, src); } @@ -125,27 +290,50 @@ create_fs(struct pipe_context *pipe, unsigned fs_traits) { struct ureg_program *ureg; - struct ureg_src dst_sampler, src_sampler, mask_sampler; - struct ureg_src dst_pos, src_pos, mask_pos; - struct ureg_src src, mask; + struct ureg_src /*dst_sampler,*/ src_sampler, mask_sampler; + struct ureg_src /*dst_pos,*/ src_input, mask_pos; + struct ureg_dst src, mask; struct ureg_dst out; + boolean has_mask = fs_traits & FS_MASK; + boolean is_fill = fs_traits & FS_FILL; + boolean is_composite = fs_traits & FS_COMPOSITE; + boolean is_solid = fs_traits & FS_SOLID_FILL; + boolean is_lingrad = fs_traits & FS_LINGRAD_FILL; + boolean is_radgrad = fs_traits & FS_RADGRAD_FILL; ureg = ureg_create(TGSI_PROCESSOR_FRAGMENT); if (ureg == NULL) return 0; + /* it has to be either a fill or a composite op */ + debug_assert(is_fill ^ is_composite); + out = ureg_DECL_output(ureg, TGSI_SEMANTIC_COLOR, 0); - src_sampler = ureg_DECL_sampler(ureg); - src_pos = ureg_DECL_fs_input(ureg, - TGSI_SEMANTIC_POSITION, - 0, - TGSI_INTERPOLATE_PERSPECTIVE); + if (is_composite) { + src_sampler = ureg_DECL_sampler(ureg, 0); + src_input = ureg_DECL_fs_input(ureg, + TGSI_SEMANTIC_POSITION, + 0, + TGSI_INTERPOLATE_PERSPECTIVE); + } + if (is_fill) { + if (is_solid) + src_input = ureg_DECL_fs_input(ureg, + TGSI_SEMANTIC_COLOR, + 0, + TGSI_INTERPOLATE_PERSPECTIVE); + else + src_input = ureg_DECL_fs_input(ureg, + TGSI_SEMANTIC_POSITION, + 0, + TGSI_INTERPOLATE_PERSPECTIVE); + } - if ((fs_traits & FS_MASK)) { - mask_sampler = ureg_DECL_sampler(ureg); + if (has_mask) { + mask_sampler = ureg_DECL_sampler(ureg, 1); mask_pos = ureg_DECL_fs_input(ureg, TGSI_SEMANTIC_POSITION, 1, @@ -153,21 +341,63 @@ create_fs(struct pipe_context *pipe, } #if 0 /* unused right now */ - dst_sampler = ureg_DECL_sampler(ureg); + dst_sampler = ureg_DECL_sampler(ureg, 2); dst_pos = ureg_DECL_fs_input(ureg, TGSI_SEMANTIC_POSITION, 2, TGSI_INTERPOLATE_PERSPECTIVE); #endif - if ((fs_traits & FS_MASK)) { - ureg_TEX(ureg, ureg_dst(mask), + if (is_composite) { + if (has_mask) + src = ureg_DECL_temporary(ureg); + else + src = out; + ureg_TEX(ureg, src, + TGSI_TEXTURE_2D, src_input, src_sampler); + } else if (is_fill) { + if (is_solid) { + if (has_mask) + src = ureg_dst(src_input); + else + ureg_MOV(ureg, out, src_input); + } else if (is_lingrad || is_radgrad) { + struct ureg_src coords, const0124, + matrow0, matrow1, matrow2; + + if (has_mask) + src = ureg_DECL_temporary(ureg); + else + src = out; + + coords = ureg_DECL_constant(ureg); + const0124 = ureg_DECL_constant(ureg); + matrow0 = ureg_DECL_constant(ureg); + matrow1 = ureg_DECL_constant(ureg); + matrow2 = ureg_DECL_constant(ureg); + + if (is_lingrad) { + linear_gradient(ureg, src, + src_input, src_sampler, + coords, const0124, + matrow0, matrow1, matrow2); + } else if (is_radgrad) { + radial_gradient(ureg, src, + src_input, src_sampler, + coords, const0124, + matrow0, matrow1, matrow2); + } + } else + debug_assert(!"Unknown fill type!"); + } + + if (has_mask) { + mask = ureg_DECL_temporary(ureg); + ureg_TEX(ureg, mask, TGSI_TEXTURE_2D, mask_pos, mask_sampler); /* src IN mask */ - src_in_mask(ureg, out, src, mask); - } else { - ureg_TEX(ureg, out, - TGSI_TEXTURE_2D, src_pos, src_sampler); + src_in_mask(ureg, out, ureg_src(src), ureg_src(mask)); + ureg_release_temporary(ureg, mask); } ureg_END(ureg); |