1 /* clang --emit-llvm llvm_entry.c |llvm-as |opt -std-compile-opts |llvm2cpp -for=Shader -gen-module -funcname=createBaseShader */
2 /**************************************************************************
4 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
31 * Zack Rusin zack@tungstengraphics.com
34 /* clang --emit-llvm llvm_builtins.c |llvm-as |opt -std-compile-opts |llvm-dis */
35 typedef __attribute__(( ocu_vector_type(4) )) float float4
;
37 void from_array(float4 (*res
)[16], float (*ainputs
)[16][4],
38 int count
, int num_attribs
)
40 for (int i
= 0; i
< count
; ++i
) {
41 for (int j
= 0; j
< num_attribs
; ++j
) {
43 vec
.x
= ainputs
[i
][j
][0];
44 vec
.y
= ainputs
[i
][j
][1];
45 vec
.z
= ainputs
[i
][j
][2];
46 vec
.w
= ainputs
[i
][j
][3];
52 void from_consts(float4
*res
, float (*ainputs
)[4],
55 for (int i
= 0; i
< count
; ++i
) {
57 vec
.x
= ainputs
[i
][0];
58 vec
.y
= ainputs
[i
][1];
59 vec
.z
= ainputs
[i
][2];
60 vec
.w
= ainputs
[i
][3];
65 void to_array(float (*dests
)[4], float4
*in
, int num_attribs
)
67 for (int i
= 0; i
< num_attribs
; ++i
) {
87 extern void execute_shader(struct ShaderInput
*input
);
89 void run_vertex_shader(void *inputs
,
98 float4 temps
[128];//MAX_PROGRAM_TEMPS
100 struct ShaderInput args
;
101 args
.dests
= results
;
102 args
.inputs
= inputs
;
104 /*printf("XXX LLVM run_vertex_shader vertices = %d, inputs = %d, attribs = %d, consts = %d\n",
105 num_vertices, num_inputs, num_attribs, num_consts);*/
106 from_consts(consts
, aconsts
, num_consts
);
107 args
.consts
= consts
;
110 execute_shader(&args
);
114 struct pipe_sampler_state
;
115 struct softpipe_tile_cache
;
117 #define NUM_CHANNELS 4 /* R,G,B,A */
118 #define QUAD_SIZE 4 /* 4 pixel/quad */
122 const struct pipe_sampler_state
*state
;
123 /** Get samples for four fragments in a quad */
124 void (*get_samples
)(struct tgsi_sampler
*sampler
,
125 const float s
[QUAD_SIZE
],
126 const float t
[QUAD_SIZE
],
127 const float p
[QUAD_SIZE
],
129 float rgba
[NUM_CHANNELS
][QUAD_SIZE
]);
130 void *pipe
; /*XXX temporary*/
131 struct softpipe_tile_cache
*cache
;
135 int run_fragment_shader(float x
, float y
,
136 float4 (*results
)[16],
137 float4 (*inputs
)[16],
141 struct tgsi_sampler
*samplers
)
144 float4 temps
[128];//MAX_PROGRAM_TEMPS
145 struct ShaderInput args
;
149 from_consts(consts
, aconsts
, num_consts
);
150 args
.consts
= consts
;
152 //printf("AAAAAAAAAAAAAAAAAAAAAAA FRAGMENT SHADER %f %f\n", x, y);
153 for (int i
= 0; i
< 4; ++i
) {
154 args
.inputs
= inputs
[i
];
155 args
.dests
= results
[i
];
158 execute_shader(&args
);
159 args
.kilmask
= mask
| (args
.kilmask
<< i
);
161 return ~args
.kilmask
;