void * util_make_geometry_passthrough_shader(struct pipe_context *pipe, uint num_attribs, const ubyte *semantic_names, const ubyte *semantic_indexes) { static const unsigned zero[4] = {0, 0, 0, 0}; struct ureg_program *ureg; struct ureg_dst dst[PIPE_MAX_SHADER_OUTPUTS]; struct ureg_src src[PIPE_MAX_SHADER_INPUTS]; struct ureg_src imm; unsigned i; ureg = ureg_create(PIPE_SHADER_GEOMETRY); if (!ureg) return NULL; ureg_property(ureg, TGSI_PROPERTY_GS_INPUT_PRIM, PIPE_PRIM_POINTS); ureg_property(ureg, TGSI_PROPERTY_GS_OUTPUT_PRIM, PIPE_PRIM_POINTS); ureg_property(ureg, TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES, 1); ureg_property(ureg, TGSI_PROPERTY_GS_INVOCATIONS, 1); imm = ureg_DECL_immediate_uint(ureg, zero, 4); /** * Loop over all the attribs and declare the corresponding * declarations in the geometry shader */ for (i = 0; i < num_attribs; i++) { src[i] = ureg_DECL_input(ureg, semantic_names[i], semantic_indexes[i], 0, 1); src[i] = ureg_src_dimension(src[i], 0); dst[i] = ureg_DECL_output(ureg, semantic_names[i], semantic_indexes[i]); } /* MOV dst[i] src[i] */ for (i = 0; i < num_attribs; i++) { ureg_MOV(ureg, dst[i], src[i]); } /* EMIT IMM[0] */ ureg_insn(ureg, TGSI_OPCODE_EMIT, NULL, 0, &imm, 1, 0); /* END */ ureg_END(ureg); return ureg_create_shader_and_destroy(ureg, pipe); }
void * st_pbo_create_gs(struct st_context *st) { static const int zero = 0; struct ureg_program *ureg; struct ureg_dst out_pos; struct ureg_dst out_layer; struct ureg_src in_pos; struct ureg_src imm; unsigned i; ureg = ureg_create(PIPE_SHADER_GEOMETRY); if (!ureg) return NULL; ureg_property(ureg, TGSI_PROPERTY_GS_INPUT_PRIM, PIPE_PRIM_TRIANGLES); ureg_property(ureg, TGSI_PROPERTY_GS_OUTPUT_PRIM, PIPE_PRIM_TRIANGLE_STRIP); ureg_property(ureg, TGSI_PROPERTY_GS_MAX_OUTPUT_VERTICES, 3); out_pos = ureg_DECL_output(ureg, TGSI_SEMANTIC_POSITION, 0); out_layer = ureg_DECL_output(ureg, TGSI_SEMANTIC_LAYER, 0); in_pos = ureg_DECL_input(ureg, TGSI_SEMANTIC_POSITION, 0, 0, 1); imm = ureg_DECL_immediate_int(ureg, &zero, 1); for (i = 0; i < 3; ++i) { struct ureg_src in_pos_vertex = ureg_src_dimension(in_pos, i); /* out_pos = in_pos[i] */ ureg_MOV(ureg, out_pos, in_pos_vertex); /* out_layer.x = f2i(in_pos[i].z) */ ureg_F2I(ureg, ureg_writemask(out_layer, TGSI_WRITEMASK_X), ureg_scalar(in_pos_vertex, TGSI_SWIZZLE_Z)); ureg_EMIT(ureg, ureg_scalar(imm, TGSI_SWIZZLE_X)); } ureg_END(ureg); return ureg_create_shader_and_destroy(ureg, st->pipe); }
/** * Create a TGSI ureg_src register from a Mesa src register. */ static struct ureg_src translate_src( struct st_translate *t, const struct prog_src_register *SrcReg ) { struct ureg_src src = src_register( t, SrcReg->File, SrcReg->Index ); if (t->procType == TGSI_PROCESSOR_GEOMETRY && SrcReg->HasIndex2) { src = src_register( t, SrcReg->File, SrcReg->Index2 ); if (SrcReg->RelAddr2) src = ureg_src_dimension_indirect( src, ureg_src(t->address[0]), SrcReg->Index); else src = ureg_src_dimension( src, SrcReg->Index); } src = ureg_swizzle( src, GET_SWZ( SrcReg->Swizzle, 0 ) & 0x3, GET_SWZ( SrcReg->Swizzle, 1 ) & 0x3, GET_SWZ( SrcReg->Swizzle, 2 ) & 0x3, GET_SWZ( SrcReg->Swizzle, 3 ) & 0x3); if (SrcReg->Negate == NEGATE_XYZW) src = ureg_negate(src); if (SrcReg->Abs) src = ureg_abs(src); if (SrcReg->RelAddr) { src = ureg_src_indirect( src, ureg_src(t->address[0])); if (SrcReg->File != PROGRAM_INPUT && SrcReg->File != PROGRAM_OUTPUT) { /* If SrcReg->Index was negative, it was set to zero in * src_register(). Reassign it now. But don't do this * for input/output regs since they get remapped while * const buffers don't. */ src.Index = SrcReg->Index; } } return src; }