From e22e3927b056806e9bbb089734132ad0bcb98df1 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 17 Sep 2010 18:41:30 -0600 Subject: gallium: rework handling of sprite_coord_enable state Implement the pipe_rasterizer_state::sprite_coord_enable field in the draw module (and softpipe) according to what's specified in the documentation. The draw module can now add any number of extra vertex attributes to a post-transformed vertex and generate texcoords for those attributes per sprite_coord_enable. Auto-generated texcoords for sprites only worked for one texcoord unit before. The frag shader gl_PointCoord input is now implemented like any other generic/texcoord attribute. The draw module now needs to be informed about fragment shaders since we need to look at the fragment shader's inputs to know which ones need auto-generated texcoords. Only softpipe has been updated so far. --- src/gallium/drivers/softpipe/sp_state.h | 2 ++ src/gallium/drivers/softpipe/sp_state_fs.c | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src/gallium/drivers') diff --git a/src/gallium/drivers/softpipe/sp_state.h b/src/gallium/drivers/softpipe/sp_state.h index 39d204de8a..c5d61f840f 100644 --- a/src/gallium/drivers/softpipe/sp_state.h +++ b/src/gallium/drivers/softpipe/sp_state.h @@ -70,6 +70,8 @@ struct sp_fragment_shader { struct tgsi_shader_info info; + struct draw_fragment_shader *draw_shader; + boolean origin_lower_left; /**< fragment shader uses lower left position origin? */ boolean pixel_center_integer; /**< fragment shader uses integer pixel center? */ diff --git a/src/gallium/drivers/softpipe/sp_state_fs.c b/src/gallium/drivers/softpipe/sp_state_fs.c index ded242d3dc..50bc2eea5f 100644 --- a/src/gallium/drivers/softpipe/sp_state_fs.c +++ b/src/gallium/drivers/softpipe/sp_state_fs.c @@ -60,7 +60,15 @@ softpipe_create_fs_state(struct pipe_context *pipe, state = softpipe_create_fs_exec( softpipe, templ ); } - assert(state); + if (!state) + return NULL; + + /* draw's fs state */ + state->draw_shader = draw_create_fragment_shader(softpipe->draw, templ); + if (!state->draw_shader) { + state->delete( state ); + return NULL; + } /* get/save the summary info for this shader */ tgsi_scan_shader(templ->tokens, &state->info); @@ -90,6 +98,9 @@ softpipe_bind_fs_state(struct pipe_context *pipe, void *fs) softpipe->fs = fs; + draw_bind_fragment_shader(softpipe->draw, + (softpipe->fs ? softpipe->fs->draw_shader : NULL)); + softpipe->dirty |= SP_NEW_FS; } @@ -109,6 +120,8 @@ softpipe_delete_fs_state(struct pipe_context *pipe, void *fs) tgsi_exec_machine_bind_shader(softpipe->fs_machine, NULL, 0, NULL); } + draw_delete_fragment_shader(softpipe->draw, state->draw_shader); + state->delete( state ); } -- cgit v1.2.3 From 955d76c3d2004c058c326d68eddc5a06d1611a41 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 20 Sep 2010 12:52:16 -0600 Subject: llvmpipe: maintain fragment shader state for draw module --- src/gallium/drivers/llvmpipe/lp_state_fs.c | 12 ++++++++++++ src/gallium/drivers/llvmpipe/lp_state_fs.h | 2 ++ 2 files changed, 14 insertions(+) (limited to 'src/gallium/drivers') diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index e54dd9f0a3..fb673db6d0 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -886,6 +886,7 @@ static void * llvmpipe_create_fs_state(struct pipe_context *pipe, const struct pipe_shader_state *templ) { + struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); struct lp_fragment_shader *shader; int nr_samplers; @@ -902,6 +903,12 @@ llvmpipe_create_fs_state(struct pipe_context *pipe, /* we need to keep a local copy of the tokens */ shader->base.tokens = tgsi_dup_tokens(templ->tokens); + shader->draw_data = draw_create_fragment_shader(llvmpipe->draw, templ); + if (shader->draw_data == NULL) { + FREE((void *) shader->base.tokens); + return NULL; + } + nr_samplers = shader->info.file_max[TGSI_FILE_SAMPLER] + 1; shader->variant_key_size = Offset(struct lp_fragment_shader_variant_key, @@ -938,6 +945,9 @@ llvmpipe_bind_fs_state(struct pipe_context *pipe, void *fs) draw_flush(llvmpipe->draw); + draw_bind_fragment_shader(llvmpipe->draw, + (llvmpipe->fs ? llvmpipe->fs->draw_data : NULL)); + llvmpipe->fs = fs; llvmpipe->dirty |= LP_NEW_FS; @@ -995,6 +1005,8 @@ llvmpipe_delete_fs_state(struct pipe_context *pipe, void *fs) li = next; } + draw_delete_fragment_shader(llvmpipe->draw, shader->draw_data); + assert(shader->variants_cached == 0); FREE((void *) shader->base.tokens); FREE(shader); diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.h b/src/gallium/drivers/llvmpipe/lp_state_fs.h index 2914e7d7ef..4999b8dca1 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.h +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.h @@ -100,6 +100,8 @@ struct lp_fragment_shader struct lp_fs_variant_list_item variants; + struct draw_fragment_shader *draw_data; + /* For debugging/profiling purposes */ unsigned variant_key_size; unsigned no; -- cgit v1.2.3 From ebba92875aca586b661f6547888a2ed95e70e0ff Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 20 Sep 2010 12:55:29 -0600 Subject: llvmpipe: indentation fix --- src/gallium/drivers/llvmpipe/lp_state_rasterizer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gallium/drivers') diff --git a/src/gallium/drivers/llvmpipe/lp_state_rasterizer.c b/src/gallium/drivers/llvmpipe/lp_state_rasterizer.c index 0bad7320f3..b81c2cfd15 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_rasterizer.c +++ b/src/gallium/drivers/llvmpipe/lp_state_rasterizer.c @@ -79,7 +79,7 @@ llvmpipe_bind_rasterizer_state(struct pipe_context *pipe, void *handle) llvmpipe->rasterizer->point_size, llvmpipe->rasterizer->point_size_per_vertex, llvmpipe->rasterizer->sprite_coord_enable); - } + } llvmpipe->dirty |= LP_NEW_RASTERIZER; } -- cgit v1.2.3 From 924c18da95bbc62492f8e54bd8273a4981a919dc Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 20 Sep 2010 13:07:59 -0600 Subject: llvmpipe: reformatting, remove trailing whitespace, etc --- src/gallium/drivers/llvmpipe/lp_setup_point.c | 44 ++++++++++++++------------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'src/gallium/drivers') diff --git a/src/gallium/drivers/llvmpipe/lp_setup_point.c b/src/gallium/drivers/llvmpipe/lp_setup_point.c index 5538987151..5521cbbe87 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup_point.c +++ b/src/gallium/drivers/llvmpipe/lp_setup_point.c @@ -52,26 +52,29 @@ struct point_info { /** * Compute a0 for a constant-valued coefficient (GL_FLAT shading). */ -static void constant_coef( struct lp_setup_context *setup, - struct lp_rast_triangle *point, - unsigned slot, - const float value, - unsigned i ) +static void +constant_coef(struct lp_setup_context *setup, + struct lp_rast_triangle *point, + unsigned slot, + const float value, + unsigned i) { point->inputs.a0[slot][i] = value; point->inputs.dadx[slot][i] = 0.0f; point->inputs.dady[slot][i] = 0.0f; } -static void perspective_coef( struct lp_setup_context *setup, - struct lp_rast_triangle *point, - const struct point_info *info, - unsigned slot, - unsigned vert_attr, - unsigned i) + +static void +perspective_coef(struct lp_setup_context *setup, + struct lp_rast_triangle *point, + const struct point_info *info, + unsigned slot, + unsigned vert_attr, + unsigned i) { - if (i == 0) { - float dadx = FIXED_ONE / (float)info->dx12; + if (i == 0) { + float dadx = FIXED_ONE / (float)info->dx12; float dady = 0.0f; point->inputs.dadx[slot][i] = dadx; point->inputs.dady[slot][i] = dady; @@ -79,30 +82,26 @@ static void perspective_coef( struct lp_setup_context *setup, (dadx * ((float)info->v0[0][0] - setup->pixel_offset) + dady * ((float)info->v0[0][1] - setup->pixel_offset))); } - else if (i == 1) { - float dadx = 0.0f; + float dadx = 0.0f; float dady = FIXED_ONE / (float)info->dx12; - + point->inputs.dadx[slot][i] = dadx; point->inputs.dady[slot][i] = dady; point->inputs.a0[slot][i] = (0.5 - (dadx * ((float)info->v0[0][0] - setup->pixel_offset) + dady * ((float)info->v0[0][1] - setup->pixel_offset))); } - else if (i == 2) { point->inputs.a0[slot][i] = 0.0f; point->inputs.dadx[slot][i] = 0.0f; point->inputs.dady[slot][i] = 0.0f; } - else if (i == 3) { point->inputs.a0[slot][i] = 1.0f; point->inputs.dadx[slot][i] = 0.0f; point->inputs.dady[slot][i] = 0.0f; } - } @@ -144,6 +143,7 @@ setup_point_fragcoord_coef(struct lp_setup_context *setup, } } + /** * Compute the point->coef[] array dadx, dady, a0 values. */ @@ -203,6 +203,7 @@ setup_point_coefficients( struct lp_setup_context *setup, fragcoord_usage_mask); } + static INLINE int subpixel_snap(float a) { @@ -322,8 +323,9 @@ try_setup_point( struct lp_setup_context *setup, } -static void lp_setup_point( struct lp_setup_context *setup, - const float (*v0)[4] ) +static void +lp_setup_point(struct lp_setup_context *setup, + const float (*v0)[4]) { if (!try_setup_point( setup, v0 )) { -- cgit v1.2.3 From b7a5eac1f3723a369885bad369a04c456bdf1565 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 20 Sep 2010 13:26:27 -0600 Subject: llvmpipe: clean-up, comments in setup_point_coefficient() --- src/gallium/drivers/llvmpipe/lp_setup_point.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/gallium/drivers') diff --git a/src/gallium/drivers/llvmpipe/lp_setup_point.c b/src/gallium/drivers/llvmpipe/lp_setup_point.c index 5521cbbe87..fb4fb2c436 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup_point.c +++ b/src/gallium/drivers/llvmpipe/lp_setup_point.c @@ -152,6 +152,7 @@ setup_point_coefficients( struct lp_setup_context *setup, struct lp_rast_triangle *point, const struct point_info *info) { + const struct lp_fragment_shader *shader = setup->fs.current.variant->shader; unsigned fragcoord_usage_mask = TGSI_WRITEMASK_XYZ; unsigned slot; @@ -172,12 +173,16 @@ setup_point_coefficients( struct lp_setup_context *setup, fragcoord_usage_mask |= usage_mask; break; + case LP_INTERP_LINEAR: + /* Sprite tex coords may use linear interpolation someday */ + /* fall-through */ + case LP_INTERP_PERSPECTIVE: - /* For point sprite textures */ - if (setup->fs.current.variant->shader->info.input_semantic_name[slot] - == TGSI_SEMANTIC_GENERIC) - { - int index = setup->fs.current.variant->shader->info.input_semantic_index[slot]; + /* check if the sprite coord flag is set for this attribute. + * If so, set it up so it up so x any y vary from 0 to 1. + */ + if (shader->info.input_semantic_name[slot] == TGSI_SEMANTIC_GENERIC) { + const int index = shader->info.input_semantic_index[slot]; if (setup->sprite & (1 << index)) { for (i = 0; i < NUM_CHANNELS; i++) -- cgit v1.2.3 From c3982c6bcdeb88f7fb1b20f8bd300db31cd7288d Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 20 Sep 2010 13:29:55 -0600 Subject: llvmpipe: rename sprite field, add sprite_coord_origin --- src/gallium/drivers/llvmpipe/lp_setup.c | 6 ++++-- src/gallium/drivers/llvmpipe/lp_setup.h | 3 ++- src/gallium/drivers/llvmpipe/lp_setup_context.h | 2 +- src/gallium/drivers/llvmpipe/lp_setup_point.c | 2 +- src/gallium/drivers/llvmpipe/lp_state_rasterizer.c | 3 ++- 5 files changed, 10 insertions(+), 6 deletions(-) (limited to 'src/gallium/drivers') diff --git a/src/gallium/drivers/llvmpipe/lp_setup.c b/src/gallium/drivers/llvmpipe/lp_setup.c index 6674d281d1..ea7002aafc 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup.c +++ b/src/gallium/drivers/llvmpipe/lp_setup.c @@ -490,12 +490,14 @@ void lp_setup_set_point_state( struct lp_setup_context *setup, float point_size, boolean point_size_per_vertex, - uint sprite) + uint sprite_coord_enable, + uint sprite_coord_origin) { LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); setup->point_size = point_size; - setup->sprite = sprite; + setup->sprite_coord_enable = sprite_coord_enable; + setup->sprite_coord_origin = sprite_coord_origin; setup->point_size_per_vertex = point_size_per_vertex; } diff --git a/src/gallium/drivers/llvmpipe/lp_setup.h b/src/gallium/drivers/llvmpipe/lp_setup.h index b94061b7d4..81ff43f8ad 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup.h +++ b/src/gallium/drivers/llvmpipe/lp_setup.h @@ -107,7 +107,8 @@ void lp_setup_set_point_state( struct lp_setup_context *setup, float point_size, boolean point_size_per_vertex, - uint sprite); + uint sprite_coord_enable, + uint sprite_coord_origin); void lp_setup_set_fs_inputs( struct lp_setup_context *setup, diff --git a/src/gallium/drivers/llvmpipe/lp_setup_context.h b/src/gallium/drivers/llvmpipe/lp_setup_context.h index 80b356476a..8506ed2dc9 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup_context.h +++ b/src/gallium/drivers/llvmpipe/lp_setup_context.h @@ -73,7 +73,7 @@ struct lp_setup_context uint prim; uint vertex_size; uint nr_vertices; - uint sprite; + uint sprite_coord_enable, sprite_coord_origin; uint vertex_buffer_size; void *vertex_buffer; diff --git a/src/gallium/drivers/llvmpipe/lp_setup_point.c b/src/gallium/drivers/llvmpipe/lp_setup_point.c index fb4fb2c436..f8f411f4f1 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup_point.c +++ b/src/gallium/drivers/llvmpipe/lp_setup_point.c @@ -184,7 +184,7 @@ setup_point_coefficients( struct lp_setup_context *setup, if (shader->info.input_semantic_name[slot] == TGSI_SEMANTIC_GENERIC) { const int index = shader->info.input_semantic_index[slot]; - if (setup->sprite & (1 << index)) { + if (setup->sprite_coord_enable & (1 << index)) { for (i = 0; i < NUM_CHANNELS; i++) if (usage_mask & (1 << i)) perspective_coef(setup, point, info, slot+1, vert_attr, i); diff --git a/src/gallium/drivers/llvmpipe/lp_state_rasterizer.c b/src/gallium/drivers/llvmpipe/lp_state_rasterizer.c index b81c2cfd15..dbd73812e4 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_rasterizer.c +++ b/src/gallium/drivers/llvmpipe/lp_state_rasterizer.c @@ -78,7 +78,8 @@ llvmpipe_bind_rasterizer_state(struct pipe_context *pipe, void *handle) lp_setup_set_point_state( llvmpipe->setup, llvmpipe->rasterizer->point_size, llvmpipe->rasterizer->point_size_per_vertex, - llvmpipe->rasterizer->sprite_coord_enable); + llvmpipe->rasterizer->sprite_coord_enable, + llvmpipe->rasterizer->sprite_coord_mode); } llvmpipe->dirty |= LP_NEW_RASTERIZER; -- cgit v1.2.3 From 61fcd9aaa2bf91eb400eeb4df2ab2c7e48b3bb6c Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 20 Sep 2010 13:48:02 -0600 Subject: llvmpipe: implement sprite coord origin modes --- src/gallium/drivers/llvmpipe/lp_setup_point.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/gallium/drivers') diff --git a/src/gallium/drivers/llvmpipe/lp_setup_point.c b/src/gallium/drivers/llvmpipe/lp_setup_point.c index f8f411f4f1..bb6b88069b 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup_point.c +++ b/src/gallium/drivers/llvmpipe/lp_setup_point.c @@ -71,7 +71,8 @@ perspective_coef(struct lp_setup_context *setup, const struct point_info *info, unsigned slot, unsigned vert_attr, - unsigned i) + unsigned i, + unsigned sprite_coord_origin) { if (i == 0) { float dadx = FIXED_ONE / (float)info->dx12; @@ -83,14 +84,18 @@ perspective_coef(struct lp_setup_context *setup, dady * ((float)info->v0[0][1] - setup->pixel_offset))); } else if (i == 1) { - float dadx = 0.0f; - float dady = FIXED_ONE / (float)info->dx12; + float dadx = 0.0f; + float dady = FIXED_ONE / (float)info->dx12; + + if (sprite_coord_origin == PIPE_SPRITE_COORD_LOWER_LEFT) { + dady = -dady; + } point->inputs.dadx[slot][i] = dadx; point->inputs.dady[slot][i] = dady; point->inputs.a0[slot][i] = (0.5 - - (dadx * ((float)info->v0[0][0] - setup->pixel_offset) + - dady * ((float)info->v0[0][1] - setup->pixel_offset))); + (dadx * ((float)info->v0[0][0] - setup->pixel_offset) + + dady * ((float)info->v0[0][1] - setup->pixel_offset))); } else if (i == 2) { point->inputs.a0[slot][i] = 0.0f; @@ -187,7 +192,8 @@ setup_point_coefficients( struct lp_setup_context *setup, if (setup->sprite_coord_enable & (1 << index)) { for (i = 0; i < NUM_CHANNELS; i++) if (usage_mask & (1 << i)) - perspective_coef(setup, point, info, slot+1, vert_attr, i); + perspective_coef(setup, point, info, slot+1, vert_attr, i, + setup->sprite_coord_origin); fragcoord_usage_mask |= TGSI_WRITEMASK_W; break; } -- cgit v1.2.3 From 1662c317032cf280701d7e55b028b7f0dc8afc65 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 20 Sep 2010 15:33:49 -0600 Subject: llvmpipe: check bitshift against PIPE_MAX_SHADER_OUTPUTS --- src/gallium/drivers/llvmpipe/lp_setup_point.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/gallium/drivers') diff --git a/src/gallium/drivers/llvmpipe/lp_setup_point.c b/src/gallium/drivers/llvmpipe/lp_setup_point.c index bb6b88069b..774a3c80da 100644 --- a/src/gallium/drivers/llvmpipe/lp_setup_point.c +++ b/src/gallium/drivers/llvmpipe/lp_setup_point.c @@ -188,8 +188,11 @@ setup_point_coefficients( struct lp_setup_context *setup, */ if (shader->info.input_semantic_name[slot] == TGSI_SEMANTIC_GENERIC) { const int index = shader->info.input_semantic_index[slot]; - - if (setup->sprite_coord_enable & (1 << index)) { + /* Note that sprite_coord enable is a bitfield of + * PIPE_MAX_SHADER_OUTPUTS bits. + */ + if (index < PIPE_MAX_SHADER_OUTPUTS && + (setup->sprite_coord_enable & (1 << index))) { for (i = 0; i < NUM_CHANNELS; i++) if (usage_mask & (1 << i)) perspective_coef(setup, point, info, slot+1, vert_attr, i, -- cgit v1.2.3