blob: d2c5852bdf780f7e7db2351742c6ff4796a5632f [file] [log] [blame]
Zack Rusin7d690902008-02-04 10:07:02 -05001#ifndef GALLIVM_P_H
2#define GALLIVM_P_H
3
4#ifdef MESA_LLVM
5
Zack Rusin3c3c1ff2008-02-12 23:08:42 -05006#include "gallivm.h"
7#include "pipe/p_shader_tokens.h"
8#include "pipe/p_compiler.h"
9
Zack Rusin7d690902008-02-04 10:07:02 -050010namespace llvm {
11 class Module;
12}
13
14#if defined __cplusplus
15extern "C" {
16#endif
17
18enum gallivm_shader_type;
19enum gallivm_vector_layout;
20
21struct gallivm_interpolate {
22 int attrib;
23 int chan;
24 int type;
25};
26
27struct gallivm_ir {
28 llvm::Module *module;
29 int id;
30 enum gallivm_shader_type type;
31 enum gallivm_vector_layout layout;
32 int num_components;
33 int num_consts;
34
José Fonseca9a8a5d72008-02-27 16:42:15 +090035 /* FIXME: this might not be enough for some shaders */
Zack Rusin7d690902008-02-04 10:07:02 -050036 struct gallivm_interpolate interpolators[32*4];
37 int num_interp;
38};
39
40struct gallivm_prog {
41 llvm::Module *module;
42 void *function;
43
44 int id;
45 enum gallivm_shader_type type;
46
47 int num_consts;
48
José Fonseca9a8a5d72008-02-27 16:42:15 +090049 /* FIXME: this might not be enough for some shaders */
Zack Rusin7d690902008-02-04 10:07:02 -050050 struct gallivm_interpolate interpolators[32*4];
51 int num_interp;
52};
53
Zack Rusin3c3c1ff2008-02-12 23:08:42 -050054static INLINE void gallivm_swizzle_components(int swizzle,
55 int *xc, int *yc,
56 int *zc, int *wc)
57{
58 int x = swizzle / 1000; swizzle -= x * 1000;
59 int y = swizzle / 100; swizzle -= y * 100;
60 int z = swizzle / 10; swizzle -= z * 10;
61 int w = swizzle;
62
63 if (xc) *xc = x;
64 if (yc) *yc = y;
65 if (zc) *zc = z;
66 if (wc) *wc = w;
67}
68
69static INLINE boolean gallivm_is_swizzle(int swizzle)
70{
71 const int NO_SWIZZLE = TGSI_SWIZZLE_X * 1000 + TGSI_SWIZZLE_Y * 100 +
72 TGSI_SWIZZLE_Z * 10 + TGSI_SWIZZLE_W;
73 return swizzle != NO_SWIZZLE;
74}
75
76static INLINE int gallivm_x_swizzle(int swizzle)
77{
78 int x;
79 gallivm_swizzle_components(swizzle, &x, 0, 0, 0);
80 return x;
81}
82
83static INLINE int gallivm_y_swizzle(int swizzle)
84{
85 int y;
86 gallivm_swizzle_components(swizzle, 0, &y, 0, 0);
87 return y;
88}
89
90static INLINE int gallivm_z_swizzle(int swizzle)
91{
92 int z;
93 gallivm_swizzle_components(swizzle, 0, 0, &z, 0);
94 return z;
95}
96
97static INLINE int gallivm_w_swizzle(int swizzle)
98{
99 int w;
100 gallivm_swizzle_components(swizzle, 0, 0, 0, &w);
101 return w;
102}
103
Zack Rusin7d690902008-02-04 10:07:02 -0500104#if defined __cplusplus
José Fonseca9a8a5d72008-02-27 16:42:15 +0900105}
Zack Rusin7d690902008-02-04 10:07:02 -0500106#endif
107
Stephane Marchesin7b0e0e12008-11-16 20:32:05 +0100108#endif /* MESA_LLVM */
109
Zack Rusin7d690902008-02-04 10:07:02 -0500110#endif