1 /**************************************************************************
3 * Copyright 2003 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 **************************************************************************/
28 #include "util/u_math.h"
29 #include "util/u_memory.h"
30 #include "pipe/p_shader_tokens.h"
31 #include "draw/draw_context.h"
32 #include "draw/draw_vertex.h"
33 #include "draw/draw_private.h"
34 #include "lp_context.h"
35 #include "lp_screen.h"
42 * The vertex info describes how to convert the post-transformed vertices
43 * (simple float[][4]) used by the 'draw' module into vertices for
46 * This function validates the vertex layout.
49 compute_vertex_info(struct llvmpipe_context
*llvmpipe
)
51 const struct lp_fragment_shader
*lpfs
= llvmpipe
->fs
;
52 struct vertex_info
*vinfo
= &llvmpipe
->vertex_info
;
53 const uint num
= draw_num_shader_outputs(llvmpipe
->draw
);
56 /* Tell setup to tell the draw module to simply emit the whole
57 * post-xform vertex as-is.
59 * Not really sure if this is the best approach.
61 vinfo
->num_attribs
= 0;
62 for (i
= 0; i
< num
; i
++) {
63 draw_emit_vertex_attr(vinfo
, EMIT_4F
, INTERP_PERSPECTIVE
, i
);
65 draw_compute_vertex_size(vinfo
);
68 lp_setup_set_vertex_info(llvmpipe
->setup
, vinfo
);
71 llvmpipe->psize_slot = draw_find_vs_output(llvmpipe->draw,
72 TGSI_SEMANTIC_PSIZE, 0);
75 /* Now match FS inputs against emitted vertex data. It's also
76 * entirely possible to just have a fixed layout for FS input,
77 * determined by the fragment shader itself, and adjust the draw
78 * outputs to match that.
81 struct lp_shader_input inputs
[PIPE_MAX_SHADER_INPUTS
];
83 for (i
= 0; i
< lpfs
->info
.num_inputs
; i
++) {
85 /* This can be precomputed, except for flatshade:
87 switch (lpfs
->info
.input_semantic_name
[i
]) {
88 case TGSI_SEMANTIC_FACE
:
89 inputs
[i
].interp
= LP_INTERP_FACING
;
91 case TGSI_SEMANTIC_POSITION
:
92 inputs
[i
].interp
= LP_INTERP_POSITION
;
94 case TGSI_SEMANTIC_COLOR
:
95 /* Colors are linearly interpolated in the fragment shader
96 * even when flatshading is active. This just tells the
97 * setup module to use coefficients with ddx==0 and
100 if (llvmpipe
->rasterizer
->flatshade
)
101 inputs
[i
].interp
= LP_INTERP_CONSTANT
;
103 inputs
[i
].interp
= LP_INTERP_LINEAR
;
107 switch (lpfs
->info
.input_interpolate
[i
]) {
108 case TGSI_INTERPOLATE_CONSTANT
:
109 inputs
[i
].interp
= LP_INTERP_CONSTANT
;
111 case TGSI_INTERPOLATE_LINEAR
:
112 inputs
[i
].interp
= LP_INTERP_LINEAR
;
114 case TGSI_INTERPOLATE_PERSPECTIVE
:
115 inputs
[i
].interp
= LP_INTERP_PERSPECTIVE
;
123 /* Search for each input in current vs output:
125 inputs
[i
].src_index
=
126 draw_find_shader_output(llvmpipe
->draw
,
127 lpfs
->info
.input_semantic_name
[i
],
128 lpfs
->info
.input_semantic_index
[i
]);
131 lp_setup_set_fs_inputs(llvmpipe
->setup
,
133 lpfs
->info
.num_inputs
);
139 * Handle state changes.
140 * Called just prior to drawing anything (pipe::draw_arrays(), etc).
142 * Hopefully this will remain quite simple, otherwise need to pull in
143 * something like the state tracker mechanism.
145 void llvmpipe_update_derived( struct llvmpipe_context
*llvmpipe
)
147 struct llvmpipe_screen
*lp_screen
= llvmpipe_screen(llvmpipe
->pipe
.screen
);
149 /* Check for updated textures.
151 if (llvmpipe
->tex_timestamp
!= lp_screen
->timestamp
) {
152 llvmpipe
->tex_timestamp
= lp_screen
->timestamp
;
153 llvmpipe
->dirty
|= LP_NEW_SAMPLER_VIEW
;
156 if (llvmpipe
->dirty
& (LP_NEW_RASTERIZER
|
159 compute_vertex_info( llvmpipe
);
161 if (llvmpipe
->dirty
& (LP_NEW_FS
|
164 LP_NEW_DEPTH_STENCIL_ALPHA
|
167 LP_NEW_SAMPLER_VIEW
))
168 llvmpipe_update_fs( llvmpipe
);
170 if (llvmpipe
->dirty
& LP_NEW_BLEND_COLOR
)
171 lp_setup_set_blend_color(llvmpipe
->setup
,
172 &llvmpipe
->blend_color
);
174 if (llvmpipe
->dirty
& LP_NEW_SCISSOR
)
175 lp_setup_set_scissor(llvmpipe
->setup
, &llvmpipe
->scissor
);
177 if (llvmpipe
->dirty
& LP_NEW_DEPTH_STENCIL_ALPHA
)
178 lp_setup_set_alpha_ref_value(llvmpipe
->setup
,
179 llvmpipe
->depth_stencil
->alpha
.ref_value
);
181 if (llvmpipe
->dirty
& LP_NEW_CONSTANTS
)
182 lp_setup_set_fs_constants(llvmpipe
->setup
,
183 llvmpipe
->constants
[PIPE_SHADER_FRAGMENT
]);
185 if (llvmpipe
->dirty
& LP_NEW_SAMPLER_VIEW
)
186 lp_setup_set_fragment_sampler_views(llvmpipe
->setup
,
187 llvmpipe
->num_fragment_sampler_views
,
188 llvmpipe
->fragment_sampler_views
);