summaryrefslogtreecommitdiff
path: root/src/gallium/state_trackers/xorg/xorg_exa_tgsi.c
blob: 9896d067b2400ae994e48c5170eb4af456c80fa9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "xorg_exa_tgsi.h"

/*### stupidity defined in X11/extensions/XI.h */
#undef Absolute

#include "pipe/p_format.h"
#include "pipe/p_context.h"
#include "pipe/p_state.h"
#include "pipe/p_inlines.h"
#include "pipe/p_shader_tokens.h"

#include "util/u_memory.h"
#include "util/u_simple_shaders.h"

#include "tgsi/tgsi_ureg.h"

#include "cso_cache/cso_context.h"

#define UNSUPPORTED_OP 0

struct shader_id {
   int op : 8;
   int mask : 1;
   int component_alpha : 1;
   int is_fill : 1;
};

/* SAMP[0]  = dst
 * SAMP[1]  = src
 * SAMP[2]  = mask
 * IN[0]    = pos dst
 * IN[1]    = pos src
 * IN[2]    = pos mask
 * CONST[0] = (0, 0, 0, 1)
 */

static const char over_op[] =
   "SUB TEMP[3], CONST[0].wwww, TEMP[1].wwww\n"
   "MUL TEMP[3], TEMP[0], TEMP[3]\n"
   "ADD TEMP[0], TEMP[3], TEMP[0]\n";


static INLINE void
create_preamble(struct ureg_program *ureg)
{
}


static INLINE void
src_in_mask(struct ureg_program *ureg,
            struct ureg_dst dst,
            struct ureg_src src,
            struct ureg_src mask)
{
   /* MUL dst, src, mask.wwww */
   ureg_MUL(ureg, dst, src,
            ureg_scalar(mask, TGSI_SWIZZLE_W));
}

static INLINE
struct shader_id shader_state(int op,
                              PicturePtr src_picture,
                              PicturePtr mask_picture,
                              PicturePtr dst_picture)
{
   struct shader_id sid;

   sid.op = op;
   sid.mask = (mask_picture != 0);
   sid.component_alpha = (mask_picture->componentAlpha);
   sid.is_fill = (src_picture->pSourcePict != 0);
   if (sid.is_fill) {
      sid.is_fill =
         (src_picture->pSourcePict->type == SourcePictTypeSolidFill);
   }

   return sid;
}

struct xorg_shader xorg_shader_construct(struct exa_context *exa,
                                         int op,
                                         PicturePtr src_picture,
                                         PicturePtr mask_picture,
                                         PicturePtr dst_picture)
{
   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 shader_id sid = shader_state(op, src_picture,
                                       mask_picture,
                                       dst_picture);
   struct xorg_shader shader = {0};

   ureg = ureg_create(TGSI_PROCESSOR_FRAGMENT);
   if (ureg == NULL)
      return shader;

   if (sid.is_fill)
      return shader;

#if 0  /* unused right now */
   dst_sampler = ureg_DECL_sampler(ureg);
   dst_pos = ureg_DECL_fs_input(ureg,
                                TGSI_SEMANTIC_POSITION,
                                0,
                                TGSI_INTERPOLATE_PERSPECTIVE);
#endif

   src_sampler = ureg_DECL_sampler(ureg);
   src_pos = ureg_DECL_fs_input(ureg,
                                TGSI_SEMANTIC_POSITION,
                                1,
                                TGSI_INTERPOLATE_PERSPECTIVE);

   if (sid.mask) {
      mask_sampler = ureg_DECL_sampler(ureg);
      src_pos = ureg_DECL_fs_input(ureg,
                                   TGSI_SEMANTIC_POSITION,
                                   2,
                                   TGSI_INTERPOLATE_PERSPECTIVE);
   }

   ureg_TEX(ureg, ureg_dst(src),
            TGSI_TEXTURE_2D, src_pos, src_sampler);

   if (sid.mask) {
      ureg_TEX(ureg, ureg_dst(mask),
               TGSI_TEXTURE_2D, mask_pos, mask_sampler);
      /* src IN mask */
      src_in_mask(ureg, ureg_dst(src), src, mask);
   }

   ureg_END(ureg);

   return shader;
}