34adac5226c8c477a615e7069762d8587538f290
1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
32 #include "sp_context.h"
37 #include "pipe/p_state.h"
38 #include "pipe/p_defines.h"
39 #include "util/u_memory.h"
40 #include "pipe/p_inlines.h"
41 #include "tgsi/tgsi_sse2.h"
45 struct sp_llvm_fragment_shader
{
46 struct sp_fragment_shader base
;
47 struct gallivm_prog
*llvm_prog
;
51 shade_quad_llvm(struct quad_stage
*qs
,
52 struct quad_header
*quad
)
54 struct quad_shade_stage
*qss
= quad_shade_stage(qs
);
55 struct softpipe_context
*softpipe
= qs
->softpipe
;
56 float dests
[4][16][4] ALIGN16_ATTRIB
;
57 float inputs
[4][16][4] ALIGN16_ATTRIB
;
58 const float fx
= (float) quad
->x0
;
59 const float fy
= (float) quad
->y0
;
60 struct gallivm_prog
*llvm
= qss
->llvm_prog
;
63 inputs
[1][0][0] = fx
+ 1.0f
;
65 inputs
[3][0][0] = fx
+ 1.0f
;
69 inputs
[2][0][1] = fy
+ 1.0f
;
70 inputs
[3][0][1] = fy
+ 1.0f
;
73 gallivm_prog_inputs_interpolate(llvm
, inputs
, quad
->coef
);
76 debug_printf("MASK = %d\n", quad
->mask
);
77 for (int i
= 0; i
< 4; ++i
) {
78 for (int j
= 0; j
< 2; ++j
) {
79 debug_printf("IN(%d,%d) [%f %f %f %f]\n", i
, j
,
80 inputs
[i
][j
][0], inputs
[i
][j
][1], inputs
[i
][j
][2], inputs
[i
][j
][3]);
86 gallivm_fragment_shader_exec(llvm
, fx
, fy
, dests
, inputs
,
87 softpipe
->mapped_constants
[PIPE_SHADER_FRAGMENT
],
90 debug_printf("OUT LLVM = 1[%f %f %f %f], 2[%f %f %f %f]\n",
91 dests
[0][0][0], dests
[0][0][1], dests
[0][0][2], dests
[0][0][3],
92 dests
[0][1][0], dests
[0][1][1], dests
[0][1][2], dests
[0][1][3]);
95 /* store result color */
96 if (qss
->colorOutSlot
>= 0) {
98 /* XXX need to handle multiple color outputs someday */
99 allvmrt(qss
->stage
.softpipe
->fs
->info
.output_semantic_name
[qss
->colorOutSlot
]
100 == TGSI_SEMANTIC_COLOR
);
101 for (i
= 0; i
< QUAD_SIZE
; ++i
) {
102 quad
->outputs
.color
[0][0][i
] = dests
[i
][qss
->colorOutSlot
][0];
103 quad
->outputs
.color
[0][1][i
] = dests
[i
][qss
->colorOutSlot
][1];
104 quad
->outputs
.color
[0][2][i
] = dests
[i
][qss
->colorOutSlot
][2];
105 quad
->outputs
.color
[0][3][i
] = dests
[i
][qss
->colorOutSlot
][3];
109 for (int i
= 0; i
< QUAD_SIZE
; ++i
) {
110 debug_printf("QLLVM%d(%d) [%f, %f, %f, %f]\n", i
, qss
->colorOutSlot
,
111 quad
->outputs
.color
[0][0][i
],
112 quad
->outputs
.color
[0][1][i
],
113 quad
->outputs
.color
[0][2][i
],
114 quad
->outputs
.color
[0][3][i
]);
119 if (qss
->depthOutSlot
>= 0) {
120 /* output[slot] is new Z */
122 for (i
= 0; i
< 4; i
++) {
123 quad
->outputs
.depth
[i
] = dests
[i
][0][2];
127 /* copy input Z (which was interpolated by the executor) to output Z */
129 for (i
= 0; i
< 4; i
++) {
130 quad
->outputs
.depth
[i
] = inputs
[i
][0][2];
134 debug_printf("D [%f, %f, %f, %f] mask = %d\n",
135 quad
->outputs
.depth
[0],
136 quad
->outputs
.depth
[1],
137 quad
->outputs
.depth
[2],
138 quad
->outputs
.depth
[3], quad
->mask
);
141 /* shader may cull fragments */
143 qs
->next
->run( qs
->next
, quad
);
149 run_llvm_fs( const struct sp_fragment_shader
*base
,
150 struct foo
*machine
)
156 delete_llvm_fs( struct sp_fragment_shader
*base
)
162 struct sp_fragment_shader
*
163 softpipe_create_fs_llvm(struct softpipe_context
*softpipe
,
164 const struct pipe_shader_state
*templ
)
166 struct sp_llvm_fragment_shader
*shader
= NULL
;
168 /* LLVM fragment shaders currently disabled:
170 state
= CALLOC_STRUCT(sp_llvm_shader_state
);
174 state
->llvm_prog
= 0;
176 if (!gallivm_global_cpu_engine()) {
177 gallivm_cpu_engine_create(state
->llvm_prog
);
180 gallivm_cpu_jit_compile(gallivm_global_cpu_engine(), state
->llvm_prog
);
183 shader
->base
.run
= run_llvm_fs
;
184 shader
->base
.delete = delete_llvm_fs
;
193 struct sp_fragment_shader
*
194 softpipe_create_fs_llvm(struct softpipe_context
*softpipe
,
195 const struct pipe_shader_state
*templ
)