/** * Translate TGSI semantic info into SVGA3d semantic info. * This is called for VS outputs and PS inputs only. */ static boolean translate_vs_ps_semantic(struct svga_shader_emitter *emit, struct tgsi_declaration_semantic semantic, unsigned *usage, unsigned *idx) { switch (semantic.Name) { case TGSI_SEMANTIC_POSITION: *idx = semantic.Index; *usage = SVGA3D_DECLUSAGE_POSITION; break; case TGSI_SEMANTIC_COLOR: *idx = semantic.Index; *usage = SVGA3D_DECLUSAGE_COLOR; break; case TGSI_SEMANTIC_BCOLOR: *idx = semantic.Index + 2; /* sharing with COLOR */ *usage = SVGA3D_DECLUSAGE_COLOR; break; case TGSI_SEMANTIC_FOG: *idx = 0; assert(semantic.Index == 0); *usage = SVGA3D_DECLUSAGE_TEXCOORD; break; case TGSI_SEMANTIC_PSIZE: *idx = semantic.Index; *usage = SVGA3D_DECLUSAGE_PSIZE; break; case TGSI_SEMANTIC_GENERIC: *idx = svga_remap_generic_index(emit->key.generic_remap_table, semantic.Index); *usage = SVGA3D_DECLUSAGE_TEXCOORD; break; case TGSI_SEMANTIC_NORMAL: *idx = semantic.Index; *usage = SVGA3D_DECLUSAGE_NORMAL; break; case TGSI_SEMANTIC_CLIPDIST: case TGSI_SEMANTIC_CLIPVERTEX: /* XXX at this time we don't support clip distance or clip vertices */ debug_warn_once("unsupported clip distance/vertex attribute\n"); *usage = SVGA3D_DECLUSAGE_TEXCOORD; *idx = 0; return TRUE; default: assert(0); *usage = SVGA3D_DECLUSAGE_TEXCOORD; *idx = 0; return FALSE; } return TRUE; }
enum pipe_error svga_swtnl_update_vdecl( struct svga_context *svga ) { struct svga_vbuf_render *svga_render = svga_vbuf_render(svga->swtnl.backend); struct draw_context *draw = svga->swtnl.draw; struct vertex_info *vinfo = &svga_render->vertex_info; SVGA3dVertexDecl vdecl[PIPE_MAX_ATTRIBS]; const enum interp_mode colorInterp = svga->curr.rast->templ.flatshade ? INTERP_CONSTANT : INTERP_LINEAR; struct svga_fragment_shader *fs = svga->curr.fs; int offset = 0; int nr_decls = 0; int src; unsigned i; memset(vinfo, 0, sizeof(*vinfo)); memset(vdecl, 0, sizeof(vdecl)); /* always add position */ src = draw_find_shader_output(draw, TGSI_SEMANTIC_POSITION, 0); draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_LINEAR, src); vinfo->attrib[0].emit = EMIT_4F; vdecl[0].array.offset = offset; vdecl[0].identity.type = SVGA3D_DECLTYPE_FLOAT4; vdecl[0].identity.usage = SVGA3D_DECLUSAGE_POSITIONT; vdecl[0].identity.usageIndex = 0; offset += 16; nr_decls++; for (i = 0; i < fs->base.info.num_inputs; i++) { const unsigned sem_name = fs->base.info.input_semantic_name[i]; const unsigned sem_index = fs->base.info.input_semantic_index[i]; src = draw_find_shader_output(draw, sem_name, sem_index); vdecl[nr_decls].array.offset = offset; vdecl[nr_decls].identity.usageIndex = sem_index; switch (sem_name) { case TGSI_SEMANTIC_COLOR: draw_emit_vertex_attr(vinfo, EMIT_4F, colorInterp, src); vdecl[nr_decls].identity.usage = SVGA3D_DECLUSAGE_COLOR; vdecl[nr_decls].identity.type = SVGA3D_DECLTYPE_FLOAT4; offset += 16; nr_decls++; break; case TGSI_SEMANTIC_GENERIC: draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, src); vdecl[nr_decls].identity.usage = SVGA3D_DECLUSAGE_TEXCOORD; vdecl[nr_decls].identity.type = SVGA3D_DECLTYPE_FLOAT4; vdecl[nr_decls].identity.usageIndex = svga_remap_generic_index(fs->generic_remap_table, sem_index); offset += 16; nr_decls++; break; case TGSI_SEMANTIC_FOG: draw_emit_vertex_attr(vinfo, EMIT_1F, INTERP_PERSPECTIVE, src); vdecl[nr_decls].identity.usage = SVGA3D_DECLUSAGE_TEXCOORD; vdecl[nr_decls].identity.type = SVGA3D_DECLTYPE_FLOAT1; assert(vdecl[nr_decls].identity.usageIndex == 0); offset += 4; nr_decls++; break; case TGSI_SEMANTIC_POSITION: /* generated internally, not a vertex shader output */ break; default: assert(0); } } draw_compute_vertex_size(vinfo); svga_render->vdecl_count = nr_decls; for (i = 0; i < svga_render->vdecl_count; i++) vdecl[i].array.stride = offset; if (memcmp(svga_render->vdecl, vdecl, sizeof(vdecl)) == 0) return 0; memcpy(svga_render->vdecl, vdecl, sizeof(vdecl)); svga->swtnl.new_vdecl = TRUE; return 0; }