X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fdrivers%2Fsoftpipe%2Fsp_setup.c;h=ffe49260b9a8f7ba32606b05eb8f5e5011ba26b0;hb=081a958bcddd37131bd67d0ac26a0785ecbd5fa6;hp=35ef9e698d58e3d2648c5b14d409539f930166af;hpb=cb136a93aba4dc64db7e446b0fbc36c9172e4017;p=mesa.git diff --git a/src/gallium/drivers/softpipe/sp_setup.c b/src/gallium/drivers/softpipe/sp_setup.c index 35ef9e698d5..ffe49260b9a 100644 --- a/src/gallium/drivers/softpipe/sp_setup.c +++ b/src/gallium/drivers/softpipe/sp_setup.c @@ -1,6 +1,6 @@ /************************************************************************** * - * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. + * Copyright 2007 VMware, Inc. * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -18,7 +18,7 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -28,7 +28,7 @@ /** * \brief Primitive rasterization/rendering (points, lines, triangles) * - * \author Keith Whitwell + * \author Keith Whitwell * \author Brian Paul */ @@ -38,7 +38,6 @@ #include "sp_setup.h" #include "sp_state.h" #include "draw/draw_context.h" -#include "draw/draw_vertex.h" #include "pipe/p_shader_tokens.h" #include "util/u_math.h" #include "util/u_memory.h" @@ -92,6 +91,7 @@ struct setup_context { int facing; float pixel_offset; + unsigned max_layer; struct quad_header quad[MAX_QUADS]; struct quad_header *quad_ptrs[MAX_QUADS]; @@ -111,44 +111,24 @@ struct setup_context { uint numFragsWritten; /**< per primitive */ #endif - unsigned winding; /* which winding to cull */ + unsigned cull_face; /* which faces cull */ unsigned nr_vertex_attrs; }; -/** - * Do triangle cull test using tri determinant (sign indicates orientation) - * \return true if triangle is to be culled. - */ -static INLINE boolean -cull_tri(const struct setup_context *setup, float det) -{ - if (det != 0) { - /* if (det < 0 then Z points toward camera and triangle is - * counter-clockwise winding. - */ - unsigned winding = (det < 0) ? PIPE_WINDING_CCW : PIPE_WINDING_CW; - - if ((winding & setup->winding) == 0) - return FALSE; - } - - /* Culled: - */ - return TRUE; -} /** * Clip setup->quad against the scissor/surface bounds. */ -static INLINE void +static inline void quad_clip(struct setup_context *setup, struct quad_header *quad) { - const struct pipe_scissor_state *cliprect = &setup->softpipe->cliprect; + unsigned viewport_index = quad[0].input.viewport_index; + const struct pipe_scissor_state *cliprect = &setup->softpipe->cliprect[viewport_index]; const int minx = (int) cliprect->minx; const int maxx = (int) cliprect->maxx; const int miny = (int) cliprect->miny; @@ -176,14 +156,18 @@ quad_clip(struct setup_context *setup, struct quad_header *quad) /** * Emit a quad (pass to next stage) with clipping. */ -static INLINE void +static inline void clip_emit_quad(struct setup_context *setup, struct quad_header *quad) { - quad_clip( setup, quad ); + quad_clip(setup, quad); if (quad->inout.mask) { struct softpipe_context *sp = setup->softpipe; +#if DEBUG_FRAGS + setup->numFragsEmitted += util_bitcount(quad->inout.mask); +#endif + sp->quad.first->run( sp->quad.first, &quad, 1 ); } } @@ -194,14 +178,14 @@ clip_emit_quad(struct setup_context *setup, struct quad_header *quad) * Given an X or Y coordinate, return the block/quad coordinate that it * belongs to. */ -static INLINE int +static inline int block(int x) { return x & ~(2-1); } -static INLINE int +static inline int block_x(int x) { return x & ~(16-1); @@ -255,6 +239,9 @@ flush_spans(struct setup_context *setup) setup->quad[q].inout.mask = quadmask; setup->quad_ptrs[q] = &setup->quad[q]; q++; +#if DEBUG_FRAGS + setup->numFragsEmitted += util_bitcount(quadmask); +#endif } mask0 >>= 2; mask1 >>= 2; @@ -393,14 +380,22 @@ setup_sort_vertices(struct setup_context *setup, * 0 = front-facing, 1 = back-facing */ setup->facing = - ((det > 0.0) ^ - (setup->softpipe->rasterizer->front_winding == PIPE_WINDING_CW)); + ((det < 0.0) ^ + (setup->softpipe->rasterizer->front_ccw)); + + { + unsigned face = setup->facing == 0 ? PIPE_FACE_FRONT : PIPE_FACE_BACK; + + if (face & setup->cull_face) + return FALSE; + } + /* Prepare pixel offset for rasterisation: * - pixel center (0.5, 0.5) for GL, or * - assume (0.0, 0.0) for other APIs. */ - if (setup->softpipe->rasterizer->gl_rasterization_rules) { + if (setup->softpipe->rasterizer->half_pixel_center) { setup->pixel_offset = 0.5f; } else { setup->pixel_offset = 0.0f; @@ -517,14 +512,6 @@ tri_linear_coeff(struct setup_context *setup, coef->a0[i] = (v[0] - (dadx * (setup->vmin[0][0] - setup->pixel_offset) + dady * (setup->vmin[0][1] - setup->pixel_offset))); - - /* - debug_printf("attr[%d].%c: %f dx:%f dy:%f\n", - slot, "xyzw"[i], - setup->coef[slot].a0[i], - setup->coef[slot].dadx[i], - setup->coef[slot].dady[i]); - */ } @@ -555,13 +542,6 @@ tri_persp_coeff(struct setup_context *setup, float dadx = a * setup->oneoverarea; float dady = b * setup->oneoverarea; - /* - debug_printf("tri persp %d,%d: %f %f %f\n", vertSlot, i, - setup->vmin[vertSlot][i], - setup->vmid[vertSlot][i], - setup->vmax[vertSlot][i] - ); - */ assert(i <= 3); coef->dadx[i] = dadx; @@ -581,17 +561,22 @@ tri_persp_coeff(struct setup_context *setup, static void setup_fragcoord_coeff(struct setup_context *setup, uint slot) { - struct sp_fragment_shader* spfs = setup->softpipe->fs; + const struct tgsi_shader_info *fsInfo = &setup->softpipe->fs_variant->info; + boolean origin_lower_left = + fsInfo->properties[TGSI_PROPERTY_FS_COORD_ORIGIN]; + boolean pixel_center_integer = + fsInfo->properties[TGSI_PROPERTY_FS_COORD_PIXEL_CENTER]; + /*X*/ - setup->coef[slot].a0[0] = spfs->pixel_center_integer ? 0.0 : 0.5; - setup->coef[slot].dadx[0] = 1.0; - setup->coef[slot].dady[0] = 0.0; + setup->coef[slot].a0[0] = pixel_center_integer ? 0.0f : 0.5f; + setup->coef[slot].dadx[0] = 1.0f; + setup->coef[slot].dady[0] = 0.0f; /*Y*/ setup->coef[slot].a0[1] = - (spfs->origin_lower_left ? setup->softpipe->framebuffer.height : 0) - + (spfs->pixel_center_integer ? 0.0 : 0.5); - setup->coef[slot].dadx[1] = 0.0; - setup->coef[slot].dady[1] = spfs->origin_lower_left ? -1.0 : 1.0; + (origin_lower_left ? setup->softpipe->framebuffer.height-1 : 0) + + (pixel_center_integer ? 0.0f : 0.5f); + setup->coef[slot].dadx[1] = 0.0f; + setup->coef[slot].dady[1] = origin_lower_left ? -1.0f : 1.0f; /*Z*/ setup->coef[slot].a0[2] = setup->posCoef.a0[2]; setup->coef[slot].dadx[2] = setup->posCoef.dadx[2]; @@ -612,11 +597,13 @@ static void setup_tri_coefficients(struct setup_context *setup) { struct softpipe_context *softpipe = setup->softpipe; - const struct sp_fragment_shader *spfs = softpipe->fs; - const struct vertex_info *vinfo = softpipe_get_vertex_info(softpipe); + const struct tgsi_shader_info *fsInfo = &setup->softpipe->fs_variant->info; + const struct sp_setup_info *sinfo = &softpipe->setup_info; uint fragSlot; float v[3]; + assert(sinfo->valid); + /* z and w are done by linear interpolation: */ v[0] = setup->vmin[0][2]; @@ -631,48 +618,59 @@ setup_tri_coefficients(struct setup_context *setup) /* setup interpolation for all the remaining attributes: */ - for (fragSlot = 0; fragSlot < spfs->info.num_inputs; fragSlot++) { - const uint vertSlot = vinfo->attrib[fragSlot].src_index; + for (fragSlot = 0; fragSlot < fsInfo->num_inputs; fragSlot++) { + const uint vertSlot = sinfo->attrib[fragSlot].src_index; uint j; - switch (vinfo->attrib[fragSlot].interp_mode) { - case INTERP_CONSTANT: - for (j = 0; j < NUM_CHANNELS; j++) + switch (sinfo->attrib[fragSlot].interp) { + case SP_INTERP_CONSTANT: + for (j = 0; j < TGSI_NUM_CHANNELS; j++) { const_coeff(setup, &setup->coef[fragSlot], vertSlot, j); + } break; - case INTERP_LINEAR: - for (j = 0; j < NUM_CHANNELS; j++) { + case SP_INTERP_LINEAR: + for (j = 0; j < TGSI_NUM_CHANNELS; j++) { tri_apply_cylindrical_wrap(setup->vmin[vertSlot][j], setup->vmid[vertSlot][j], setup->vmax[vertSlot][j], - spfs->info.input_cylindrical_wrap[fragSlot] & (1 << j), + fsInfo->input_cylindrical_wrap[fragSlot] & (1 << j), v); tri_linear_coeff(setup, &setup->coef[fragSlot], j, v); } break; - case INTERP_PERSPECTIVE: - for (j = 0; j < NUM_CHANNELS; j++) { + case SP_INTERP_PERSPECTIVE: + for (j = 0; j < TGSI_NUM_CHANNELS; j++) { tri_apply_cylindrical_wrap(setup->vmin[vertSlot][j], setup->vmid[vertSlot][j], setup->vmax[vertSlot][j], - spfs->info.input_cylindrical_wrap[fragSlot] & (1 << j), + fsInfo->input_cylindrical_wrap[fragSlot] & (1 << j), v); tri_persp_coeff(setup, &setup->coef[fragSlot], j, v); } break; - case INTERP_POS: + case SP_INTERP_POS: setup_fragcoord_coeff(setup, fragSlot); break; default: assert(0); } - if (spfs->info.input_semantic_name[fragSlot] == TGSI_SEMANTIC_FACE) { + if (fsInfo->input_semantic_name[fragSlot] == TGSI_SEMANTIC_FACE) { /* convert 0 to 1.0 and 1 to -1.0 */ setup->coef[fragSlot].a0[0] = setup->facing * -2.0f + 1.0f; setup->coef[fragSlot].dadx[0] = 0.0; setup->coef[fragSlot].dady[0] = 0.0; } + + if (0) { + for (j = 0; j < TGSI_NUM_CHANNELS; j++) { + debug_printf("attr[%d].%c: a0:%f dx:%f dy:%f\n", + fragSlot, "xyzw"[j], + setup->coef[fragSlot].a0[j], + setup->coef[fragSlot].dadx[j], + setup->coef[fragSlot].dady[j]); + } + } } } @@ -712,9 +710,10 @@ static void subtriangle(struct setup_context *setup, struct edge *eleft, struct edge *eright, - int lines) + int lines, + unsigned viewport_index) { - const struct pipe_scissor_state *cliprect = &setup->softpipe->cliprect; + const struct pipe_scissor_state *cliprect = &setup->softpipe->cliprect[viewport_index]; const int minx = (int) cliprect->minx; const int maxx = (int) cliprect->maxx; const int miny = (int) cliprect->miny; @@ -811,7 +810,8 @@ sp_setup_tri(struct setup_context *setup, const float (*v2)[4]) { float det; - + uint layer = 0; + unsigned viewport_index = 0; #if DEBUG_VERTS debug_printf("Setup triangle:\n"); print_vertex(setup, v0); @@ -819,7 +819,7 @@ sp_setup_tri(struct setup_context *setup, print_vertex(setup, v2); #endif - if (setup->softpipe->no_rast) + if (setup->softpipe->no_rast || setup->softpipe->rasterizer->rasterizer_discard) return; det = calc_det(v0, v1, v2); @@ -832,11 +832,9 @@ sp_setup_tri(struct setup_context *setup, setup->numFragsWritten = 0; #endif - if (cull_tri( setup, det )) - return; - if (!setup_sort_vertices( setup, det, v0, v1, v2 )) return; + setup_tri_coefficients( setup ); setup_tri_edges( setup ); @@ -846,24 +844,39 @@ sp_setup_tri(struct setup_context *setup, setup->span.right[0] = 0; setup->span.right[1] = 0; /* setup->span.z_mode = tri_z_mode( setup->ctx ); */ + if (setup->softpipe->layer_slot > 0) { + layer = *(unsigned *)setup->vprovoke[setup->softpipe->layer_slot]; + layer = MIN2(layer, setup->max_layer); + } + setup->quad[0].input.layer = layer; + + if (setup->softpipe->viewport_index_slot > 0) { + unsigned *udata = (unsigned*)v0[setup->softpipe->viewport_index_slot]; + viewport_index = sp_clamp_viewport_idx(*udata); + } + setup->quad[0].input.viewport_index = viewport_index; /* init_constant_attribs( setup ); */ if (setup->oneoverarea < 0.0) { /* emaj on left: */ - subtriangle( setup, &setup->emaj, &setup->ebot, setup->ebot.lines ); - subtriangle( setup, &setup->emaj, &setup->etop, setup->etop.lines ); + subtriangle(setup, &setup->emaj, &setup->ebot, setup->ebot.lines, viewport_index); + subtriangle(setup, &setup->emaj, &setup->etop, setup->etop.lines, viewport_index); } else { /* emaj on right: */ - subtriangle( setup, &setup->ebot, &setup->emaj, setup->ebot.lines ); - subtriangle( setup, &setup->etop, &setup->emaj, setup->etop.lines ); + subtriangle(setup, &setup->ebot, &setup->emaj, setup->ebot.lines, viewport_index); + subtriangle(setup, &setup->etop, &setup->emaj, setup->etop.lines, viewport_index); } flush_spans( setup ); + if (setup->softpipe->active_statistics_queries) { + setup->softpipe->pipeline_statistics.c_primitives++; + } + #if DEBUG_FRAGS printf("Tri: %u frags emitted, %u written\n", setup->numFragsEmitted, @@ -954,12 +967,14 @@ setup_line_coefficients(struct setup_context *setup, const float (*v1)[4]) { struct softpipe_context *softpipe = setup->softpipe; - const struct sp_fragment_shader *spfs = softpipe->fs; - const struct vertex_info *vinfo = softpipe_get_vertex_info(softpipe); + const struct tgsi_shader_info *fsInfo = &setup->softpipe->fs_variant->info; + const struct sp_setup_info *sinfo = &softpipe->setup_info; uint fragSlot; float area; float v[2]; + assert(sinfo->valid); + /* use setup->vmin, vmax to point to vertices */ if (softpipe->rasterizer->flatshade_first) setup->vprovoke = v0; @@ -989,41 +1004,41 @@ setup_line_coefficients(struct setup_context *setup, /* setup interpolation for all the remaining attributes: */ - for (fragSlot = 0; fragSlot < spfs->info.num_inputs; fragSlot++) { - const uint vertSlot = vinfo->attrib[fragSlot].src_index; + for (fragSlot = 0; fragSlot < fsInfo->num_inputs; fragSlot++) { + const uint vertSlot = sinfo->attrib[fragSlot].src_index; uint j; - switch (vinfo->attrib[fragSlot].interp_mode) { - case INTERP_CONSTANT: - for (j = 0; j < NUM_CHANNELS; j++) + switch (sinfo->attrib[fragSlot].interp) { + case SP_INTERP_CONSTANT: + for (j = 0; j < TGSI_NUM_CHANNELS; j++) const_coeff(setup, &setup->coef[fragSlot], vertSlot, j); break; - case INTERP_LINEAR: - for (j = 0; j < NUM_CHANNELS; j++) { + case SP_INTERP_LINEAR: + for (j = 0; j < TGSI_NUM_CHANNELS; j++) { line_apply_cylindrical_wrap(setup->vmin[vertSlot][j], setup->vmax[vertSlot][j], - spfs->info.input_cylindrical_wrap[fragSlot] & (1 << j), + fsInfo->input_cylindrical_wrap[fragSlot] & (1 << j), v); line_linear_coeff(setup, &setup->coef[fragSlot], j, v); } break; - case INTERP_PERSPECTIVE: - for (j = 0; j < NUM_CHANNELS; j++) { + case SP_INTERP_PERSPECTIVE: + for (j = 0; j < TGSI_NUM_CHANNELS; j++) { line_apply_cylindrical_wrap(setup->vmin[vertSlot][j], setup->vmax[vertSlot][j], - spfs->info.input_cylindrical_wrap[fragSlot] & (1 << j), + fsInfo->input_cylindrical_wrap[fragSlot] & (1 << j), v); line_persp_coeff(setup, &setup->coef[fragSlot], j, v); } break; - case INTERP_POS: + case SP_INTERP_POS: setup_fragcoord_coeff(setup, fragSlot); break; default: assert(0); } - if (spfs->info.input_semantic_name[fragSlot] == TGSI_SEMANTIC_FACE) { + if (fsInfo->input_semantic_name[fragSlot] == TGSI_SEMANTIC_FACE) { /* convert 0 to 1.0 and 1 to -1.0 */ setup->coef[fragSlot].a0[0] = setup->facing * -2.0f + 1.0f; setup->coef[fragSlot].dadx[0] = 0.0; @@ -1037,7 +1052,7 @@ setup_line_coefficients(struct setup_context *setup, /** * Plot a pixel in a line segment. */ -static INLINE void +static inline void plot(struct setup_context *setup, int x, int y) { const int iy = y & 1; @@ -1052,7 +1067,7 @@ plot(struct setup_context *setup, int x, int y) /* flush prev quad, start new quad */ if (setup->quad[0].input.x0 != -1) - clip_emit_quad( setup, &setup->quad[0] ); + clip_emit_quad(setup, &setup->quad[0]); setup->quad[0].input.x0 = quadX; setup->quad[0].input.y0 = quadY; @@ -1080,6 +1095,8 @@ sp_setup_line(struct setup_context *setup, int dx = x1 - x0; int dy = y1 - y0; int xstep, ystep; + uint layer = 0; + unsigned viewport_index = 0; #if DEBUG_VERTS debug_printf("Setup line:\n"); @@ -1087,7 +1104,7 @@ sp_setup_line(struct setup_context *setup, print_vertex(setup, v1); #endif - if (setup->softpipe->no_rast) + if (setup->softpipe->no_rast || setup->softpipe->rasterizer->rasterizer_discard) return; if (dx == 0 && dy == 0) @@ -1123,6 +1140,17 @@ sp_setup_line(struct setup_context *setup, setup->quad[0].input.x0 = setup->quad[0].input.y0 = -1; setup->quad[0].inout.mask = 0x0; + if (setup->softpipe->layer_slot > 0) { + layer = *(unsigned *)setup->vprovoke[setup->softpipe->layer_slot]; + layer = MIN2(layer, setup->max_layer); + } + setup->quad[0].input.layer = layer; + + if (setup->softpipe->viewport_index_slot > 0) { + unsigned *udata = (unsigned*)setup->vprovoke[setup->softpipe->viewport_index_slot]; + viewport_index = sp_clamp_viewport_idx(*udata); + } + setup->quad[0].input.viewport_index = viewport_index; /* XXX temporary: set coverage to 1.0 so the line appears * if AA mode happens to be enabled. @@ -1175,7 +1203,7 @@ sp_setup_line(struct setup_context *setup, /* draw final quad */ if (setup->quad[0].inout.mask) { - clip_emit_quad( setup, &setup->quad[0] ); + clip_emit_quad(setup, &setup->quad[0]); } } @@ -1203,7 +1231,7 @@ sp_setup_point(struct setup_context *setup, const float (*v0)[4]) { struct softpipe_context *softpipe = setup->softpipe; - const struct sp_fragment_shader *spfs = softpipe->fs; + const struct tgsi_shader_info *fsInfo = &setup->softpipe->fs_variant->info; const int sizeAttr = setup->softpipe->psize_slot; const float size = sizeAttr > 0 ? v0[sizeAttr][0] @@ -1212,19 +1240,34 @@ sp_setup_point(struct setup_context *setup, const boolean round = (boolean) setup->softpipe->rasterizer->point_smooth; const float x = v0[0][0]; /* Note: data[0] is always position */ const float y = v0[0][1]; - const struct vertex_info *vinfo = softpipe_get_vertex_info(softpipe); + const struct sp_setup_info *sinfo = &softpipe->setup_info; uint fragSlot; - + uint layer = 0; + unsigned viewport_index = 0; #if DEBUG_VERTS debug_printf("Setup point:\n"); print_vertex(setup, v0); #endif - if (softpipe->no_rast) + assert(sinfo->valid); + + if (setup->softpipe->no_rast || setup->softpipe->rasterizer->rasterizer_discard) return; assert(setup->softpipe->reduced_prim == PIPE_PRIM_POINTS); + if (setup->softpipe->layer_slot > 0) { + layer = *(unsigned *)v0[setup->softpipe->layer_slot]; + layer = MIN2(layer, setup->max_layer); + } + setup->quad[0].input.layer = layer; + + if (setup->softpipe->viewport_index_slot > 0) { + unsigned *udata = (unsigned*)v0[setup->softpipe->viewport_index_slot]; + viewport_index = sp_clamp_viewport_idx(*udata); + } + setup->quad[0].input.viewport_index = viewport_index; + /* For points, all interpolants are constant-valued. * However, for point sprites, we'll need to setup texcoords appropriately. * XXX: which coefficients are the texcoords??? @@ -1247,30 +1290,30 @@ sp_setup_point(struct setup_context *setup, const_coeff(setup, &setup->posCoef, 0, 2); const_coeff(setup, &setup->posCoef, 0, 3); - for (fragSlot = 0; fragSlot < spfs->info.num_inputs; fragSlot++) { - const uint vertSlot = vinfo->attrib[fragSlot].src_index; + for (fragSlot = 0; fragSlot < fsInfo->num_inputs; fragSlot++) { + const uint vertSlot = sinfo->attrib[fragSlot].src_index; uint j; - switch (vinfo->attrib[fragSlot].interp_mode) { - case INTERP_CONSTANT: + switch (sinfo->attrib[fragSlot].interp) { + case SP_INTERP_CONSTANT: /* fall-through */ - case INTERP_LINEAR: - for (j = 0; j < NUM_CHANNELS; j++) + case SP_INTERP_LINEAR: + for (j = 0; j < TGSI_NUM_CHANNELS; j++) const_coeff(setup, &setup->coef[fragSlot], vertSlot, j); break; - case INTERP_PERSPECTIVE: - for (j = 0; j < NUM_CHANNELS; j++) + case SP_INTERP_PERSPECTIVE: + for (j = 0; j < TGSI_NUM_CHANNELS; j++) point_persp_coeff(setup, setup->vprovoke, &setup->coef[fragSlot], vertSlot, j); break; - case INTERP_POS: + case SP_INTERP_POS: setup_fragcoord_coeff(setup, fragSlot); break; default: assert(0); } - if (spfs->info.input_semantic_name[fragSlot] == TGSI_SEMANTIC_FACE) { + if (fsInfo->input_semantic_name[fragSlot] == TGSI_SEMANTIC_FACE) { /* convert 0 to 1.0 and 1 to -1.0 */ setup->coef[fragSlot].a0[0] = setup->facing * -2.0f + 1.0f; setup->coef[fragSlot].dadx[0] = 0.0; @@ -1286,7 +1329,7 @@ sp_setup_point(struct setup_context *setup, setup->quad[0].input.x0 = (int) x - ix; setup->quad[0].input.y0 = (int) y - iy; setup->quad[0].inout.mask = (1 << ix) << (2 * iy); - clip_emit_quad( setup, &setup->quad[0] ); + clip_emit_quad(setup, &setup->quad[0]); } else { if (round) { @@ -1347,7 +1390,7 @@ sp_setup_point(struct setup_context *setup, if (setup->quad[0].inout.mask) { setup->quad[0].input.x0 = ix; setup->quad[0].input.y0 = iy; - clip_emit_quad( setup, &setup->quad[0] ); + clip_emit_quad(setup, &setup->quad[0]); } } } @@ -1394,7 +1437,7 @@ sp_setup_point(struct setup_context *setup, setup->quad[0].inout.mask = mask; setup->quad[0].input.x0 = ix; setup->quad[0].input.y0 = iy; - clip_emit_quad( setup, &setup->quad[0] ); + clip_emit_quad(setup, &setup->quad[0]); } } } @@ -1409,25 +1452,43 @@ void sp_setup_prepare(struct setup_context *setup) { struct softpipe_context *sp = setup->softpipe; - + int i; + unsigned max_layer = ~0; if (sp->dirty) { - softpipe_update_derived(sp); + softpipe_update_derived(sp, sp->reduced_api_prim); } /* Note: nr_attrs is only used for debugging (vertex printing) */ setup->nr_vertex_attrs = draw_num_shader_outputs(sp->draw); + /* + * Determine how many layers the fb has (used for clamping layer value). + * OpenGL (but not d3d10) permits different amount of layers per rt, however + * results are undefined if layer exceeds the amount of layers of ANY + * attachment hence don't need separate per cbuf and zsbuf max. + */ + for (i = 0; i < setup->softpipe->framebuffer.nr_cbufs; i++) { + struct pipe_surface *cbuf = setup->softpipe->framebuffer.cbufs[i]; + if (cbuf) { + max_layer = MIN2(max_layer, + cbuf->u.tex.last_layer - cbuf->u.tex.first_layer); + + } + } + + setup->max_layer = max_layer; + sp->quad.first->begin( sp->quad.first ); if (sp->reduced_api_prim == PIPE_PRIM_TRIANGLES && - sp->rasterizer->fill_cw == PIPE_POLYGON_MODE_FILL && - sp->rasterizer->fill_ccw == PIPE_POLYGON_MODE_FILL) { + sp->rasterizer->fill_front == PIPE_POLYGON_MODE_FILL && + sp->rasterizer->fill_back == PIPE_POLYGON_MODE_FILL) { /* we'll do culling */ - setup->winding = sp->rasterizer->cull_mode; + setup->cull_face = sp->rasterizer->cull_face; } else { /* 'draw' will do culling */ - setup->winding = PIPE_WINDING_NONE; + setup->cull_face = PIPE_FACE_NONE; } }