diff options
Diffstat (limited to 'src/mesa/state_tracker')
-rw-r--r-- | src/mesa/state_tracker/st_atom.c | 4 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_atom.h | 2 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_atom_constbuf.c | 24 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_atom_shader.c | 42 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_program.c | 48 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_context.h | 4 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_extensions.c | 4 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_mesa_to_tgsi.c | 18 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_program.c | 246 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_program.h | 48 |
10 files changed, 435 insertions, 5 deletions
diff --git a/src/mesa/state_tracker/st_atom.c b/src/mesa/state_tracker/st_atom.c index 6f293128d3a..e389e57346b 100644 --- a/src/mesa/state_tracker/st_atom.c +++ b/src/mesa/state_tracker/st_atom.c @@ -47,6 +47,7 @@ static const struct st_tracked_state *atoms[] = &st_finalize_textures, &st_update_fp, + &st_update_gp, &st_update_vp, &st_update_rasterizer, @@ -59,6 +60,7 @@ static const struct st_tracked_state *atoms[] = &st_update_framebuffer, &st_update_msaa, &st_update_vs_constants, + &st_update_gs_constants, &st_update_fs_constants, &st_update_pixel_transfer }; @@ -115,6 +117,8 @@ static void check_program_state( struct st_context *st ) if (ctx->FragmentProgram._Current != &st->fp->Base) st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; + if (ctx->GeometryProgram._Current != &st->gp->Base) + st->dirty.st |= ST_NEW_GEOMETRY_PROGRAM; } diff --git a/src/mesa/state_tracker/st_atom.h b/src/mesa/state_tracker/st_atom.h index 0c25269e0a4..1f0fef63df5 100644 --- a/src/mesa/state_tracker/st_atom.h +++ b/src/mesa/state_tracker/st_atom.h @@ -48,6 +48,7 @@ extern const struct st_tracked_state st_update_framebuffer; extern const struct st_tracked_state st_update_clip; extern const struct st_tracked_state st_update_depth_stencil_alpha; extern const struct st_tracked_state st_update_fp; +extern const struct st_tracked_state st_update_gp; extern const struct st_tracked_state st_update_vp; extern const struct st_tracked_state st_update_rasterizer; extern const struct st_tracked_state st_update_polygon_stipple; @@ -59,6 +60,7 @@ extern const struct st_tracked_state st_update_sampler; extern const struct st_tracked_state st_update_texture; extern const struct st_tracked_state st_finalize_textures; extern const struct st_tracked_state st_update_fs_constants; +extern const struct st_tracked_state st_update_gs_constants; extern const struct st_tracked_state st_update_vs_constants; extern const struct st_tracked_state st_update_pixel_transfer; diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c index 38fadb20163..6f9d71e845b 100644 --- a/src/mesa/state_tracker/st_atom_constbuf.c +++ b/src/mesa/state_tracker/st_atom_constbuf.c @@ -59,7 +59,8 @@ void st_upload_constants( struct st_context *st, struct pipe_resource **cbuf = &st->state.constants[shader_type]; assert(shader_type == PIPE_SHADER_VERTEX || - shader_type == PIPE_SHADER_FRAGMENT); + shader_type == PIPE_SHADER_FRAGMENT || + shader_type == PIPE_SHADER_GEOMETRY); /* update constants */ if (params && params->NumParameters) { @@ -139,3 +140,24 @@ const struct st_tracked_state st_update_fs_constants = { update_fs_constants /* update */ }; +/* Geometry shader: + */ +static void update_gs_constants(struct st_context *st ) +{ + struct st_geometry_program *gp = st->gp; + struct gl_program_parameter_list *params; + + if (gp) { + params = gp->Base.Base.Parameters; + st_upload_constants( st, params, PIPE_SHADER_GEOMETRY ); + } +} + +const struct st_tracked_state st_update_gs_constants = { + "st_update_gs_constants", /* name */ + { /* dirty */ + (_NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS), /* mesa */ + ST_NEW_GEOMETRY_PROGRAM, /* st */ + }, + update_gs_constants /* update */ +}; diff --git a/src/mesa/state_tracker/st_atom_shader.c b/src/mesa/state_tracker/st_atom_shader.c index dcaad83a3c3..cebaad5f000 100644 --- a/src/mesa/state_tracker/st_atom_shader.c +++ b/src/mesa/state_tracker/st_atom_shader.c @@ -66,7 +66,19 @@ translate_fp(struct st_context *st, } } +/* + * Translate geometry program if needed. + */ +static void +translate_gp(struct st_context *st, + struct st_geometry_program *stgp) +{ + if (!stgp->tgsi.tokens) { + assert(stgp->Base.Base.NumInstructions > 1); + st_translate_geometry_program(st, stgp); + } +} /** * Find a translated vertex program that corresponds to stvp and @@ -222,3 +234,33 @@ const struct st_tracked_state st_update_vp = { }, update_vp /* update */ }; + +static void +update_gp( struct st_context *st ) +{ + + struct st_geometry_program *stgp; + + if (!st->ctx->GeometryProgram._Current) { + cso_set_geometry_shader_handle(st->cso_context, NULL); + return; + } + + stgp = st_geometry_program(st->ctx->GeometryProgram._Current); + assert(stgp->Base.Base.Target == MESA_GEOMETRY_PROGRAM); + + translate_gp(st, stgp); + + st_reference_geomprog(st, &st->gp, stgp); + + cso_set_geometry_shader_handle(st->cso_context, stgp->driver_shader); +} + +const struct st_tracked_state st_update_gp = { + "st_update_gp", /* name */ + { /* dirty */ + 0, /* mesa */ + ST_NEW_GEOMETRY_PROGRAM /* st */ + }, + update_gp /* update */ +}; diff --git a/src/mesa/state_tracker/st_cb_program.c b/src/mesa/state_tracker/st_cb_program.c index c8e4b9d56dd..6aa7e79af95 100644 --- a/src/mesa/state_tracker/st_cb_program.c +++ b/src/mesa/state_tracker/st_cb_program.c @@ -66,6 +66,9 @@ static void st_bind_program( GLcontext *ctx, case GL_FRAGMENT_PROGRAM_ARB: st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; break; + case MESA_GEOMETRY_PROGRAM: + st->dirty.st |= ST_NEW_GEOMETRY_PROGRAM; + break; } } @@ -80,6 +83,7 @@ static void st_use_program( GLcontext *ctx, struct gl_shader_program *shProg) st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; st->dirty.st |= ST_NEW_VERTEX_PROGRAM; + st->dirty.st |= ST_NEW_GEOMETRY_PROGRAM; } @@ -116,6 +120,17 @@ static struct gl_program *st_new_program( GLcontext *ctx, id ); } + case MESA_GEOMETRY_PROGRAM: { + struct st_geometry_program *prog = ST_CALLOC_STRUCT(st_geometry_program); + + prog->serialNo = SerialNo++; + + return _mesa_init_geometry_program( ctx, + &prog->Base, + target, + id ); + } + default: assert(0); return NULL; @@ -135,6 +150,21 @@ st_delete_program(GLcontext *ctx, struct gl_program *prog) st_vp_release_varients( st, stvp ); } break; + case MESA_GEOMETRY_PROGRAM: + { + struct st_geometry_program *stgp = (struct st_geometry_program *) prog; + + if (stgp->driver_shader) { + cso_delete_geometry_shader(st->cso_context, stgp->driver_shader); + stgp->driver_shader = NULL; + } + + if (stgp->tgsi.tokens) { + st_free_tokens((void *) stgp->tgsi.tokens); + stgp->tgsi.tokens = NULL; + } + } + break; case GL_FRAGMENT_PROGRAM_ARB: { struct st_fragment_program *stfp = (struct st_fragment_program *) prog; @@ -197,6 +227,24 @@ static GLboolean st_program_string_notify( GLcontext *ctx, if (st->fp == stfp) st->dirty.st |= ST_NEW_FRAGMENT_PROGRAM; } + else if (target == MESA_GEOMETRY_PROGRAM) { + struct st_geometry_program *stgp = (struct st_geometry_program *) prog; + + stgp->serialNo++; + + if (stgp->driver_shader) { + cso_delete_geometry_shader(st->cso_context, stgp->driver_shader); + stgp->driver_shader = NULL; + } + + if (stgp->tgsi.tokens) { + st_free_tokens((void *) stgp->tgsi.tokens); + stgp->tgsi.tokens = NULL; + } + + if (st->gp == stgp) + st->dirty.st |= ST_NEW_GEOMETRY_PROGRAM; + } else if (target == GL_VERTEX_PROGRAM_ARB) { struct st_vertex_program *stvp = (struct st_vertex_program *) prog; diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 4edfb2ae856..7f7088e2fd2 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -51,6 +51,7 @@ struct bitmap_cache; #define ST_NEW_VERTEX_PROGRAM 0x4 #define ST_NEW_FRAMEBUFFER 0x8 #define ST_NEW_EDGEFLAGS_DATA 0x10 +#define ST_NEW_GEOMETRY_PROGRAM 0x20 struct st_state_flags { @@ -95,7 +96,7 @@ struct st_context struct pipe_sampler_state samplers[PIPE_MAX_SAMPLERS]; struct pipe_sampler_state *sampler_list[PIPE_MAX_SAMPLERS]; struct pipe_clip_state clip; - struct pipe_resource *constants[2]; + struct pipe_resource *constants[PIPE_SHADER_TYPES]; struct pipe_framebuffer_state framebuffer; struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; struct pipe_scissor_state scissor; @@ -130,6 +131,7 @@ struct st_context struct st_vertex_program *vp; /**< Currently bound vertex program */ struct st_fragment_program *fp; /**< Currently bound fragment program */ + struct st_geometry_program *gp; /**< Currently bound geometry program */ struct st_vp_varient *vp_varient; diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c index d0ea89f4f4f..c5326fe0db0 100644 --- a/src/mesa/state_tracker/st_extensions.c +++ b/src/mesa/state_tracker/st_extensions.c @@ -392,4 +392,8 @@ void st_init_extensions(struct st_context *st) ctx->Extensions.ARB_draw_buffers_blend = GL_TRUE; } #endif + + if (screen->get_param(screen, PIPE_CAP_GEOMETRY_SHADER4)) { + ctx->Extensions.ARB_geometry_shader4 = GL_TRUE; + } } diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c b/src/mesa/state_tracker/st_mesa_to_tgsi.c index 49b7b5d1c10..f5c9c4d5c1a 100644 --- a/src/mesa/state_tracker/st_mesa_to_tgsi.c +++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c @@ -522,6 +522,10 @@ translate_opcode( unsigned op ) return TGSI_OPCODE_DST; case OPCODE_ELSE: return TGSI_OPCODE_ELSE; + case OPCODE_EMIT_VERTEX: + return TGSI_OPCODE_EMIT; + case OPCODE_END_PRIMITIVE: + return TGSI_OPCODE_ENDPRIM; case OPCODE_ENDIF: return TGSI_OPCODE_ENDIF; case OPCODE_ENDLOOP: @@ -985,6 +989,20 @@ st_translate_mesa_program( } } } + else if (procType == TGSI_PROCESSOR_GEOMETRY) { + for (i = 0; i < numInputs; i++) { + t->inputs[i] = ureg_DECL_gs_input(ureg, + i, + inputSemanticName[i], + inputSemanticIndex[i]); + } + + for (i = 0; i < numOutputs; i++) { + t->outputs[i] = ureg_DECL_output( ureg, + outputSemanticName[i], + outputSemanticIndex[i] ); + } + } else { for (i = 0; i < numInputs; i++) { t->inputs[i] = ureg_DECL_vs_input(ureg, i); diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c index 3ea325bb42a..1b8612d570b 100644 --- a/src/mesa/state_tracker/st_program.c +++ b/src/mesa/state_tracker/st_program.c @@ -459,6 +459,252 @@ st_translate_fragment_program(struct st_context *st, } } +void +st_translate_geometry_program(struct st_context *st, + struct st_geometry_program *stgp) +{ + GLuint inputMapping[GEOM_ATTRIB_MAX]; + GLuint outputMapping[GEOM_RESULT_MAX]; + struct pipe_context *pipe = st->pipe; + enum pipe_error error; + GLuint attr; + const GLbitfield inputsRead = stgp->Base.Base.InputsRead; + GLuint vslot = 0; + GLuint num_generic = 0; + + uint gs_num_inputs = 0; + uint gs_builtin_inputs = 0; + uint gs_array_offset = 0; + + ubyte gs_output_semantic_name[PIPE_MAX_SHADER_OUTPUTS]; + ubyte gs_output_semantic_index[PIPE_MAX_SHADER_OUTPUTS]; + uint gs_num_outputs = 0; + + GLint i; + GLuint maxSlot = 0; + struct ureg_program *ureg; + + ureg = ureg_create( TGSI_PROCESSOR_GEOMETRY ); + if (ureg == NULL) { + return; + } + + assert(0); + /* which vertex output goes to the first geometry input */ + if (inputsRead & GEOM_BIT_VERTICES) + vslot = 0; + else + vslot = 1; + + /* + * Convert Mesa program inputs to TGSI input register semantics. + */ + for (attr = 0; attr < GEOM_ATTRIB_MAX; attr++) { + if (inputsRead & (1 << attr)) { + const GLuint slot = gs_num_inputs; + + gs_num_inputs++; + + inputMapping[attr] = slot; + + stgp->input_map[slot + gs_array_offset] = vslot - gs_builtin_inputs; + stgp->input_to_index[attr] = vslot; + stgp->index_to_input[vslot] = attr; + ++vslot; + + if (attr != GEOM_ATTRIB_VERTICES && + attr != GEOM_ATTRIB_PRIMITIVE_ID) { + gs_array_offset += 2; + } else + ++gs_builtin_inputs; + +#if 1 + debug_printf("input map at %d = %d\n", + slot + gs_array_offset, stgp->input_map[slot + gs_array_offset]); +#endif + + switch (attr) { + case GEOM_ATTRIB_VERTICES: + debug_assert(0); + break; + case GEOM_ATTRIB_PRIMITIVE_ID: + stgp->input_semantic_name[slot] = TGSI_SEMANTIC_PRIMID; + stgp->input_semantic_index[slot] = 0; + break; + case GEOM_ATTRIB_POSITION: + stgp->input_semantic_name[slot] = TGSI_SEMANTIC_POSITION; + stgp->input_semantic_index[slot] = 0; + break; + case GEOM_ATTRIB_COLOR0: + stgp->input_semantic_name[slot] = TGSI_SEMANTIC_COLOR; + stgp->input_semantic_index[slot] = 0; + break; + case GEOM_ATTRIB_COLOR1: + stgp->input_semantic_name[slot] = TGSI_SEMANTIC_COLOR; + stgp->input_semantic_index[slot] = 1; + break; + case GEOM_ATTRIB_FOG_FRAG_COORD: + stgp->input_semantic_name[slot] = TGSI_SEMANTIC_FOG; + stgp->input_semantic_index[slot] = 0; + break; + case GEOM_ATTRIB_TEX_COORD: + stgp->input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC; + stgp->input_semantic_index[slot] = num_generic++; + break; + case GEOM_ATTRIB_VAR0: + /* fall-through */ + default: + stgp->input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC; + stgp->input_semantic_index[slot] = num_generic++; + } + } + } + + /* initialize output semantics to defaults */ + for (i = 0; i < PIPE_MAX_SHADER_OUTPUTS; i++) { + gs_output_semantic_name[i] = TGSI_SEMANTIC_GENERIC; + gs_output_semantic_index[i] = 0; + } + + num_generic = 0; + /* + * Determine number of outputs, the (default) output register + * mapping and the semantic information for each output. + */ + for (attr = 0; attr < GEOM_RESULT_MAX; attr++) { + if (stgp->Base.Base.OutputsWritten & (1 << attr)) { + GLuint slot; + + slot = gs_num_outputs; + gs_num_outputs++; + outputMapping[attr] = slot; + + switch (attr) { + case GEOM_RESULT_POS: + assert(slot == 0); + gs_output_semantic_name[slot] = TGSI_SEMANTIC_POSITION; + gs_output_semantic_index[slot] = 0; + break; + case GEOM_RESULT_COL0: + gs_output_semantic_name[slot] = TGSI_SEMANTIC_COLOR; + gs_output_semantic_index[slot] = 0; + break; + case GEOM_RESULT_COL1: + gs_output_semantic_name[slot] = TGSI_SEMANTIC_COLOR; + gs_output_semantic_index[slot] = 1; + break; + case GEOM_RESULT_SCOL0: + gs_output_semantic_name[slot] = TGSI_SEMANTIC_BCOLOR; + gs_output_semantic_index[slot] = 0; + break; + case GEOM_RESULT_SCOL1: + gs_output_semantic_name[slot] = TGSI_SEMANTIC_BCOLOR; + gs_output_semantic_index[slot] = 1; + break; + case GEOM_RESULT_FOGC: + gs_output_semantic_name[slot] = TGSI_SEMANTIC_FOG; + gs_output_semantic_index[slot] = 0; + break; + case GEOM_RESULT_PSIZ: + gs_output_semantic_name[slot] = TGSI_SEMANTIC_PSIZE; + gs_output_semantic_index[slot] = 0; + break; + case GEOM_RESULT_TEX0: + case GEOM_RESULT_TEX1: + case GEOM_RESULT_TEX2: + case GEOM_RESULT_TEX3: + case GEOM_RESULT_TEX4: + case GEOM_RESULT_TEX5: + case GEOM_RESULT_TEX6: + case GEOM_RESULT_TEX7: + /* fall-through */ + case GEOM_RESULT_VAR0: + /* fall-through */ + default: + assert(slot < Elements(gs_output_semantic_name)); + /* use default semantic info */ + gs_output_semantic_name[slot] = TGSI_SEMANTIC_GENERIC; + gs_output_semantic_index[slot] = num_generic++; + } + } + } + + assert(gs_output_semantic_name[0] == TGSI_SEMANTIC_POSITION); + + /* find max output slot referenced to compute gs_num_outputs */ + for (attr = 0; attr < GEOM_RESULT_MAX; attr++) { + if (outputMapping[attr] != ~0 && outputMapping[attr] > maxSlot) + maxSlot = outputMapping[attr]; + } + gs_num_outputs = maxSlot + 1; + +#if 0 /* debug */ + { + GLuint i; + printf("outputMapping? %d\n", outputMapping ? 1 : 0); + if (outputMapping) { + printf("attr -> slot\n"); + for (i = 0; i < 16; i++) { + printf(" %2d %3d\n", i, outputMapping[i]); + } + } + printf("slot sem_name sem_index\n"); + for (i = 0; i < gs_num_outputs; i++) { + printf(" %2d %d %d\n", + i, + gs_output_semantic_name[i], + gs_output_semantic_index[i]); + } + } +#endif + + /* free old shader state, if any */ + if (stgp->tgsi.tokens) { + st_free_tokens(stgp->tgsi.tokens); + stgp->tgsi.tokens = NULL; + } + if (stgp->driver_shader) { + cso_delete_geometry_shader(st->cso_context, stgp->driver_shader); + stgp->driver_shader = NULL; + } + + ureg_property_gs_input_prim(ureg, stgp->Base.InputType); + ureg_property_gs_output_prim(ureg, stgp->Base.OutputType); + ureg_property_gs_max_vertices(ureg, stgp->Base.VerticesOut); + + error = st_translate_mesa_program(st->ctx, + TGSI_PROCESSOR_GEOMETRY, + ureg, + &stgp->Base.Base, + /* inputs */ + gs_num_inputs, + inputMapping, + stgp->input_semantic_name, + stgp->input_semantic_index, + NULL, + /* outputs */ + gs_num_outputs, + outputMapping, + gs_output_semantic_name, + gs_output_semantic_index, + FALSE); + + + stgp->num_inputs = gs_num_inputs; + stgp->tgsi.tokens = ureg_get_tokens( ureg, NULL ); + ureg_destroy( ureg ); + stgp->driver_shader = pipe->create_gs_state(pipe, &stgp->tgsi); + + if ((ST_DEBUG & DEBUG_TGSI) && (ST_DEBUG & DEBUG_MESA)) { + _mesa_print_program(&stgp->Base.Base); + debug_printf("\n"); + } + + if (ST_DEBUG & DEBUG_TGSI) { + tgsi_dump(stgp->tgsi.tokens, 0); + debug_printf("\n"); + } +} /** * Debug- print current shader text diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index d4b7151e929..d779d5a6dde 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -41,7 +41,6 @@ struct cso_fragment_shader; struct cso_vertex_shader; -struct translated_vertex_program; /** @@ -99,8 +98,6 @@ struct st_vp_varient }; - - /** * Derived from Mesa gl_fragment_program: */ @@ -126,6 +123,33 @@ struct st_vertex_program struct st_vp_varient *varients; }; +/** + * Derived from Mesa gl_geometry_program: + */ +struct st_geometry_program +{ + struct gl_geometry_program Base; /**< The Mesa geometry program */ + GLuint serialNo; + + /** map GP input back to VP output */ + GLuint input_map[PIPE_MAX_SHADER_INPUTS]; + + /** maps a Mesa GEOM_ATTRIB_x to a packed TGSI input index */ + GLuint input_to_index[GEOM_ATTRIB_MAX]; + /** maps a TGSI input index back to a Mesa GEOM_ATTRIB_x */ + GLuint index_to_input[PIPE_MAX_SHADER_INPUTS]; + + GLuint num_inputs; + + GLuint input_to_slot[GEOM_ATTRIB_MAX]; /**< Maps GEOM_ATTRIB_x to slot */ + GLuint num_input_slots; + + ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS]; + ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS]; + + struct pipe_shader_state tgsi; + void *driver_shader; +}; static INLINE struct st_fragment_program * st_fragment_program( struct gl_fragment_program *fp ) @@ -140,6 +164,11 @@ st_vertex_program( struct gl_vertex_program *vp ) return (struct st_vertex_program *)vp; } +static INLINE struct st_geometry_program * +st_geometry_program( struct gl_geometry_program *vp ) +{ + return (struct st_geometry_program *)vp; +} static INLINE void st_reference_vertprog(struct st_context *st, @@ -152,6 +181,16 @@ st_reference_vertprog(struct st_context *st, } static INLINE void +st_reference_geomprog(struct st_context *st, + struct st_geometry_program **ptr, + struct st_geometry_program *prog) +{ + _mesa_reference_program(st->ctx, + (struct gl_program **) ptr, + (struct gl_program *) prog); +} + +static INLINE void st_reference_fragprog(struct st_context *st, struct st_fragment_program **ptr, struct st_fragment_program *prog) @@ -166,6 +205,9 @@ extern void st_translate_fragment_program(struct st_context *st, struct st_fragment_program *fp); +extern void +st_translate_geometry_program(struct st_context *st, + struct st_geometry_program *stgp); /* Called after program string change, discard all previous * compilation results. |