summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/llvm/gallivm_p.h
blob: cfe7b1901b371085811c2afc2cb76cf4aada5f78 (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
#ifndef GALLIVM_P_H
#define GALLIVM_P_H

#ifdef MESA_LLVM

#include "gallivm.h"
#include "pipe/p_shader_tokens.h"
#include "pipe/p_compiler.h"

namespace llvm {
   class Module;
}

#if defined __cplusplus
extern "C" {
#endif

enum gallivm_shader_type;
enum gallivm_vector_layout;

struct gallivm_interpolate {
   int attrib;
   int chan;
   int type;
};

struct gallivm_ir {
   llvm::Module *module;
   int id;
   enum gallivm_shader_type type;
   enum gallivm_vector_layout layout;
   int num_components;
   int   num_consts;

   //FIXME: this might not be enough for some shaders
   struct gallivm_interpolate interpolators[32*4];
   int   num_interp;
};

struct gallivm_prog {
   llvm::Module *module;
   void *function;

   int   id;
   enum gallivm_shader_type type;

   int   num_consts;

   //FIXME: this might not be enough for some shaders
   struct gallivm_interpolate interpolators[32*4];
   int   num_interp;
};

static INLINE void gallivm_swizzle_components(int swizzle,
                                              int *xc, int *yc,
                                              int *zc, int *wc)
{
   int x = swizzle / 1000; swizzle -= x * 1000;
   int y = swizzle / 100;  swizzle -= y * 100;
   int z = swizzle / 10;   swizzle -= z * 10;
   int w = swizzle;

   if (xc) *xc = x;
   if (yc) *yc = y;
   if (zc) *zc = z;
   if (wc) *wc = w;
}

static INLINE boolean gallivm_is_swizzle(int swizzle)
{
   const int NO_SWIZZLE = TGSI_SWIZZLE_X * 1000 + TGSI_SWIZZLE_Y * 100 +
                          TGSI_SWIZZLE_Z * 10 + TGSI_SWIZZLE_W;
   return swizzle != NO_SWIZZLE;
}

static INLINE int gallivm_x_swizzle(int swizzle)
{
   int x;
   gallivm_swizzle_components(swizzle, &x, 0, 0, 0);
   return x;
}

static INLINE int gallivm_y_swizzle(int swizzle)
{
   int y;
   gallivm_swizzle_components(swizzle, 0, &y, 0, 0);
   return y;
}

static INLINE int gallivm_z_swizzle(int swizzle)
{
   int z;
   gallivm_swizzle_components(swizzle, 0, 0, &z, 0);
   return z;
}

static INLINE int gallivm_w_swizzle(int swizzle)
{
   int w;
   gallivm_swizzle_components(swizzle, 0, 0, 0, &w);
   return w;
}

#endif /* MESA_LLVM */

#if defined __cplusplus
} // extern "C"
#endif

#endif