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 **************************************************************************/
29 #include "sp_context.h"
32 #include "sp_headers.h"
35 #include "pipe/p_state.h"
36 #include "pipe/p_defines.h"
37 #include "pipe/p_util.h"
38 #include "pipe/p_inlines.h"
39 #include "tgsi/exec/tgsi_exec.h"
40 #include "tgsi/exec/tgsi_sse2.h"
43 #if defined(__i386__) || defined(__386__)
45 #include "rtasm/rtasm_x86sse.h"
47 /* Surely this should be defined somewhere in a tgsi header:
49 typedef void (XSTDCALL
*codegen_function
)(
50 const struct tgsi_exec_vector
*input
,
51 struct tgsi_exec_vector
*output
,
53 struct tgsi_exec_vector
*temporary
,
54 const struct tgsi_interp_coef
*coef
55 //, const struct tgsi_exec_vector *quadPos
59 struct sp_sse_fragment_shader
{
60 struct sp_fragment_shader base
;
61 struct x86_function sse2_program
;
62 codegen_function func
;
68 fs_sse_prepare( struct sp_fragment_shader
*base
,
69 struct tgsi_exec_machine
*machine
,
70 struct tgsi_sampler
*samplers
)
75 /* TODO: codegenerate the whole run function, skip this wrapper.
76 * TODO: break dependency on tgsi_exec_machine struct
77 * TODO: push Position calculation into the generated shader
78 * TODO: process >1 quad at a time
81 fs_sse_run( struct sp_fragment_shader
*base
,
82 struct tgsi_exec_machine
*machine
,
83 struct quad_header
*quad
)
85 struct sp_sse_fragment_shader
*shader
= (struct sp_sse_fragment_shader
*) base
;
87 /* Compute X, Y, Z, W vals for this quad -- place in temp[0] for now */
88 sp_setup_pos_vector(quad
->posCoef
,
89 (float)quad
->x0
, (float)quad
->y0
,
93 machine
->Temps
[TGSI_EXEC_TEMP_KILMASK_I
].xyzw
[TGSI_EXEC_TEMP_KILMASK_C
].u
[0] = 0x0;
95 shader
->func( machine
->Inputs
,
100 // , &machine->QuadPos
103 return ~(machine
->Temps
[TGSI_EXEC_TEMP_KILMASK_I
].xyzw
[TGSI_EXEC_TEMP_KILMASK_C
].u
[0]);
108 fs_sse_delete( struct sp_fragment_shader
*base
)
110 struct sp_sse_fragment_shader
*shader
= (struct sp_sse_fragment_shader
*) base
;
112 x86_release_func( &shader
->sse2_program
);
117 struct sp_fragment_shader
*
118 softpipe_create_fs_sse(struct softpipe_context
*softpipe
,
119 const struct pipe_shader_state
*templ
)
121 struct sp_sse_fragment_shader
*shader
;
123 if (!softpipe
->use_sse
)
126 shader
= CALLOC_STRUCT(sp_sse_fragment_shader
);
130 x86_init_func( &shader
->sse2_program
);
132 if (!tgsi_emit_sse2_fs( templ
->tokens
, &shader
->sse2_program
)) {
137 shader
->func
= (codegen_function
) x86_get_func( &shader
->sse2_program
);
138 assert(shader
->func
);
140 shader
->base
.shader
= *templ
;
141 shader
->base
.prepare
= fs_sse_prepare
;
142 shader
->base
.run
= fs_sse_run
;
143 shader
->base
.delete = fs_sse_delete
;
145 return &shader
->base
;
151 /* Maybe put this varient in the header file.
153 struct sp_fragment_shader
*
154 softpipe_create_fs_sse(struct softpipe_context
*softpipe
,
155 const struct pipe_shader_state
*templ
)