softpipe: support all TGSI fragment coord conventions (v4)

Changes in v4:
- Rebase and modify for changes in previous patches

Changes in v3:
- Use positive caps instead of negative caps

Changes in v2:
- Now takes the fragment convention directly from the fragment shader

Adds internal support for all fragment coord conventions to softpipe.

This patch is not required for use with the current state trackers, but it
allows softpipe to run any TGSI program and enhances performance.
This commit is contained in:
Luca Barbieri 2010-01-21 05:38:45 +01:00
parent 62c673b6ac
commit b2299d80b4
4 changed files with 20 additions and 7 deletions

View File

@ -100,11 +100,10 @@ softpipe_get_param(struct pipe_screen *screen, int param)
case PIPE_CAP_INDEP_BLEND_FUNC:
return 1;
case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
return 1;
case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
return 0;
case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
return 1;
default:
return 0;
}

View File

@ -504,21 +504,24 @@ static void tri_persp_coeff( struct setup_context *setup,
/**
* Special coefficient setup for gl_FragCoord.
* X and Y are trivial, though Y has to be inverted for OpenGL.
* X and Y are trivial, though Y may have to be inverted for OpenGL.
* Z and W are copied from posCoef which should have already been computed.
* We could do a bit less work if we'd examine gl_FragCoord's swizzle mask.
*/
static void
setup_fragcoord_coeff(struct setup_context *setup, uint slot)
{
struct sp_fragment_shader* spfs = setup->softpipe->fs;
/*X*/
setup->coef[slot].a0[0] = 0;
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;
/*Y*/
setup->coef[slot].a0[1] = 0.0;
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] = 1.0;
setup->coef[slot].dady[1] = spfs->origin_lower_left ? -1.0 : 1.0;
/*Z*/
setup->coef[slot].a0[2] = setup->posCoef.a0[2];
setup->coef[slot].dadx[2] = setup->posCoef.dadx[2];

View File

@ -68,6 +68,9 @@ struct sp_fragment_shader {
struct tgsi_shader_info info;
boolean origin_lower_left; /**< fragment shader uses lower left position origin? */
boolean pixel_center_integer; /**< fragment shader uses integer pixel center? */
void (*prepare)( const struct sp_fragment_shader *shader,
struct tgsi_exec_machine *machine,
struct tgsi_sampler **samplers);

View File

@ -44,6 +44,7 @@ softpipe_create_fs_state(struct pipe_context *pipe,
{
struct softpipe_context *softpipe = softpipe_context(pipe);
struct sp_fragment_shader *state;
unsigned i;
/* debug */
if (softpipe->dump_fs)
@ -60,6 +61,13 @@ softpipe_create_fs_state(struct pipe_context *pipe,
/* get/save the summary info for this shader */
tgsi_scan_shader(templ->tokens, &state->info);
for (i = 0; i < state->info.num_properties; ++i) {
if (state->info.properties[i].name == TGSI_PROPERTY_FS_COORD_ORIGIN)
state->origin_lower_left = state->info.properties[i].data[0];
else if (state->info.properties[i].name == TGSI_PROPERTY_FS_COORD_PIXEL_CENTER)
state->pixel_center_integer = state->info.properties[i].data[0];
}
return state;
}