00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "util/u_math.h"
00029 #include "util/u_memory.h"
00030 #include "pipe/p_shader_tokens.h"
00031 #include "draw/draw_context.h"
00032 #include "draw/draw_vertex.h"
00033 #include "draw/draw_private.h"
00034 #include "sp_context.h"
00035 #include "sp_state.h"
00036
00037
00043 static void
00044 invalidate_vertex_layout(struct softpipe_context *softpipe)
00045 {
00046 softpipe->vertex_info.num_attribs = 0;
00047 }
00048
00049
00058 struct vertex_info *
00059 softpipe_get_vertex_info(struct softpipe_context *softpipe)
00060 {
00061 struct vertex_info *vinfo = &softpipe->vertex_info;
00062
00063 if (vinfo->num_attribs == 0) {
00064
00065 const struct sp_fragment_shader *spfs = softpipe->fs;
00066 const enum interp_mode colorInterp
00067 = softpipe->rasterizer->flatshade ? INTERP_CONSTANT : INTERP_LINEAR;
00068 uint i;
00069
00070 if (softpipe->vbuf) {
00071
00072
00073
00074 struct vertex_info *vinfo_vbuf = &softpipe->vertex_info_vbuf;
00075 const uint num = draw_num_vs_outputs(softpipe->draw);
00076 uint i;
00077
00078
00079
00080 vinfo_vbuf->num_attribs = 0;
00081 for (i = 0; i < num; i++) {
00082 draw_emit_vertex_attr(vinfo_vbuf, EMIT_4F, INTERP_PERSPECTIVE, i);
00083 }
00084 draw_compute_vertex_size(vinfo_vbuf);
00085 }
00086
00087
00088
00089
00090
00091 vinfo->num_attribs = 0;
00092 for (i = 0; i < spfs->info.num_inputs; i++) {
00093 int src;
00094 switch (spfs->info.input_semantic_name[i]) {
00095 case TGSI_SEMANTIC_POSITION:
00096 src = draw_find_vs_output(softpipe->draw,
00097 TGSI_SEMANTIC_POSITION, 0);
00098 draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_POS, src);
00099 break;
00100
00101 case TGSI_SEMANTIC_COLOR:
00102 src = draw_find_vs_output(softpipe->draw, TGSI_SEMANTIC_COLOR,
00103 spfs->info.input_semantic_index[i]);
00104 draw_emit_vertex_attr(vinfo, EMIT_4F, colorInterp, src);
00105 break;
00106
00107 case TGSI_SEMANTIC_FOG:
00108 src = draw_find_vs_output(softpipe->draw, TGSI_SEMANTIC_FOG, 0);
00109 draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, src);
00110 break;
00111
00112 case TGSI_SEMANTIC_GENERIC:
00113
00114 src = draw_find_vs_output(softpipe->draw, TGSI_SEMANTIC_GENERIC,
00115 spfs->info.input_semantic_index[i]);
00116 draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, src);
00117 break;
00118
00119 default:
00120 assert(0);
00121 }
00122 }
00123
00124 softpipe->psize_slot = draw_find_vs_output(softpipe->draw,
00125 TGSI_SEMANTIC_PSIZE, 0);
00126 if (softpipe->psize_slot > 0) {
00127 draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_CONSTANT,
00128 softpipe->psize_slot);
00129 }
00130
00131 draw_compute_vertex_size(vinfo);
00132 }
00133
00134 return vinfo;
00135 }
00136
00137
00152 struct vertex_info *
00153 softpipe_get_vbuf_vertex_info(struct softpipe_context *softpipe)
00154 {
00155 (void) softpipe_get_vertex_info(softpipe);
00156 return &softpipe->vertex_info_vbuf;
00157 }
00158
00159
00163 static void
00164 compute_cliprect(struct softpipe_context *sp)
00165 {
00166 uint surfWidth = sp->framebuffer.width;
00167 uint surfHeight = sp->framebuffer.height;
00168
00169 if (sp->rasterizer->scissor) {
00170
00171 sp->cliprect.minx = MAX2(sp->scissor.minx, 0);
00172 sp->cliprect.miny = MAX2(sp->scissor.miny, 0);
00173 sp->cliprect.maxx = MIN2(sp->scissor.maxx, surfWidth);
00174 sp->cliprect.maxy = MIN2(sp->scissor.maxy, surfHeight);
00175 }
00176 else {
00177
00178 sp->cliprect.minx = 0;
00179 sp->cliprect.miny = 0;
00180 sp->cliprect.maxx = surfWidth;
00181 sp->cliprect.maxy = surfHeight;
00182 }
00183 }
00184
00185
00186
00187
00188
00189 void softpipe_update_derived( struct softpipe_context *softpipe )
00190 {
00191 if (softpipe->dirty & (SP_NEW_RASTERIZER |
00192 SP_NEW_FS |
00193 SP_NEW_VS))
00194 invalidate_vertex_layout( softpipe );
00195
00196 if (softpipe->dirty & (SP_NEW_SCISSOR |
00197 SP_NEW_DEPTH_STENCIL_ALPHA |
00198 SP_NEW_FRAMEBUFFER))
00199 compute_cliprect(softpipe);
00200
00201 if (softpipe->dirty & (SP_NEW_BLEND |
00202 SP_NEW_DEPTH_STENCIL_ALPHA |
00203 SP_NEW_FRAMEBUFFER |
00204 SP_NEW_RASTERIZER |
00205 SP_NEW_FS |
00206 SP_NEW_QUERY))
00207 sp_build_quad_pipeline(softpipe);
00208
00209 softpipe->dirty = 0;
00210 }