Re: [Mesa-dev] [PATCH 25/43] intel/blorp/blit: Add support for normalized coordinates
On Wed, May 17, 2017 at 5:42 AM, Pohjolainen, Topi < topi.pohjolai...@gmail.com> wrote: > On Tue, May 16, 2017 at 03:45:19PM -0700, Jason Ekstrand wrote: > > Gen5 and earlier can't do non-normalized coordinates so we need to > > compensate in the shader. Fortunately, it's pretty easy plumb through. > > --- > > src/intel/blorp/blorp_blit.c | 27 ++- > > src/intel/blorp/blorp_priv.h | 6 ++ > > 2 files changed, 28 insertions(+), 5 deletions(-) > > > > diff --git a/src/intel/blorp/blorp_blit.c b/src/intel/blorp/blorp_blit.c > > index 144bfb3..23e33de 100644 > > --- a/src/intel/blorp/blorp_blit.c > > +++ b/src/intel/blorp/blorp_blit.c > > @@ -55,6 +55,7 @@ struct brw_blorp_blit_vars { > > nir_variable *v_src_z; > > nir_variable *v_src_offset; > > nir_variable *v_dst_offset; > > + nir_variable *v_src_inv_size; > > > > /* gl_FragCoord */ > > nir_variable *frag_coord; > > @@ -79,6 +80,7 @@ brw_blorp_blit_vars_init(nir_builder *b, struct > brw_blorp_blit_vars *v, > > LOAD_INPUT(src_z, glsl_uint_type()) > > LOAD_INPUT(src_offset, glsl_vector_type(GLSL_TYPE_UINT, 2)) > > LOAD_INPUT(dst_offset, glsl_vector_type(GLSL_TYPE_UINT, 2)) > > + LOAD_INPUT(src_inv_size, glsl_vector_type(GLSL_TYPE_FLOAT, 2)) > > > > #undef LOAD_INPUT > > > > @@ -198,10 +200,15 @@ blorp_create_nir_tex_instr(nir_builder *b, struct > brw_blorp_blit_vars *v, > > > > static nir_ssa_def * > > blorp_nir_tex(nir_builder *b, struct brw_blorp_blit_vars *v, > > - nir_ssa_def *pos, nir_alu_type dst_type) > > + const struct brw_blorp_blit_prog_key *key, nir_ssa_def > *pos) > > { > > + /* If the sampler requires normalized coordinates, we need to > compensate. */ > > + if (key->src_coords_normalized) > > + pos = nir_fmul(b, pos, nir_load_var(b, v->v_src_inv_size)); > > + > > nir_tex_instr *tex = > > - blorp_create_nir_tex_instr(b, v, nir_texop_tex, pos, 2, dst_type); > > + blorp_create_nir_tex_instr(b, v, nir_texop_tex, pos, 2, > > + key->texture_data_type); > > > > assert(pos->num_components == 2); > > tex->sampler_dim = GLSL_SAMPLER_DIM_2D; > > @@ -1188,7 +1195,7 @@ brw_blorp_build_nir_shader(struct blorp_context > *blorp, void *mem_ctx, > > src_pos = nir_ishl(, src_pos, nir_imm_int(, 1)); > > src_pos = nir_iadd(, src_pos, nir_imm_int(, 1)); > > src_pos = nir_i2f32(, src_pos); > > - color = blorp_nir_tex(, , src_pos, key->texture_data_type); > > + color = blorp_nir_tex(, , key, src_pos); > >} else { > > /* Gen7+ hardware doesn't automaticaly blend. */ > > color = blorp_nir_manual_blend_average(, , src_pos, > key->src_samples, > > @@ -1200,7 +1207,7 @@ brw_blorp_build_nir_shader(struct blorp_context > *blorp, void *mem_ctx, > >color = blorp_nir_manual_blend_bilinear(, src_pos, > key->src_samples, key, ); > > } else { > >if (key->bilinear_filter) { > > - color = blorp_nir_tex(, , src_pos, key->texture_data_type); > > + color = blorp_nir_tex(, , key, src_pos); > >} else { > > /* We're going to use texelFetch, so we need integers */ > > if (src_pos->num_components == 2) { > > @@ -2056,9 +2063,19 @@ blorp_blit(struct blorp_batch *batch, > > wm_prog_key.y_scale = params.src.surf.samples / wm_prog_key.x_scale; > > > > if (filter == GL_LINEAR && > > - params.src.surf.samples <= 1 && params.dst.surf.samples <= 1) > > + params.src.surf.samples <= 1 && params.dst.surf.samples <= 1) { > >wm_prog_key.bilinear_filter = true; > > > > + if (batch->blorp->isl_dev->info->gen < 6) { > > + /* Gen4-5 don't support non-normalized texture coordinates */ > > + wm_prog_key.src_coords_normalized = true; > > + params.wm_inputs.src_inv_size[0] = > > +1.0f / minify(params.src.surf.logical_level0_px.width, > src_level); > > + params.wm_inputs.src_inv_size[1] = > > +1.0f / minify(params.src.surf.logical_level0_px.height, > src_level); > > + } > > + } > > + > > if ((params.src.surf.usage & ISL_SURF_USAGE_DEPTH_BIT) == 0 && > > (params.src.surf.usage & ISL_SURF_USAGE_STENCIL_BIT) == 0 && > > !isl_format_has_int_channel(params.src.surf.format) && > > diff --git a/src/intel/blorp/blorp_priv.h b/src/intel/blorp/blorp_priv.h > > index c61ab08..39da5af 100644 > > --- a/src/intel/blorp/blorp_priv.h > > +++ b/src/intel/blorp/blorp_priv.h > > @@ -124,6 +124,9 @@ struct brw_blorp_wm_inputs > > struct blorp_surf_offset src_offset; > > struct blorp_surf_offset dst_offset; > > > > + /* (1/width, 1/height) for the source surface */ > > + float src_inv_size[2]; > > + > > There is still the "pad[1]" in the end which I think is now correct, before > it should have been "pad[3]", right? It aligns to vec4. Yes > Do we really need > that anymore... > Maybe? The real requirement is
Re: [Mesa-dev] [PATCH 25/43] intel/blorp/blit: Add support for normalized coordinates
On Tue, May 16, 2017 at 03:45:19PM -0700, Jason Ekstrand wrote: > Gen5 and earlier can't do non-normalized coordinates so we need to > compensate in the shader. Fortunately, it's pretty easy plumb through. > --- > src/intel/blorp/blorp_blit.c | 27 ++- > src/intel/blorp/blorp_priv.h | 6 ++ > 2 files changed, 28 insertions(+), 5 deletions(-) > > diff --git a/src/intel/blorp/blorp_blit.c b/src/intel/blorp/blorp_blit.c > index 144bfb3..23e33de 100644 > --- a/src/intel/blorp/blorp_blit.c > +++ b/src/intel/blorp/blorp_blit.c > @@ -55,6 +55,7 @@ struct brw_blorp_blit_vars { > nir_variable *v_src_z; > nir_variable *v_src_offset; > nir_variable *v_dst_offset; > + nir_variable *v_src_inv_size; > > /* gl_FragCoord */ > nir_variable *frag_coord; > @@ -79,6 +80,7 @@ brw_blorp_blit_vars_init(nir_builder *b, struct > brw_blorp_blit_vars *v, > LOAD_INPUT(src_z, glsl_uint_type()) > LOAD_INPUT(src_offset, glsl_vector_type(GLSL_TYPE_UINT, 2)) > LOAD_INPUT(dst_offset, glsl_vector_type(GLSL_TYPE_UINT, 2)) > + LOAD_INPUT(src_inv_size, glsl_vector_type(GLSL_TYPE_FLOAT, 2)) > > #undef LOAD_INPUT > > @@ -198,10 +200,15 @@ blorp_create_nir_tex_instr(nir_builder *b, struct > brw_blorp_blit_vars *v, > > static nir_ssa_def * > blorp_nir_tex(nir_builder *b, struct brw_blorp_blit_vars *v, > - nir_ssa_def *pos, nir_alu_type dst_type) > + const struct brw_blorp_blit_prog_key *key, nir_ssa_def *pos) > { > + /* If the sampler requires normalized coordinates, we need to compensate. > */ > + if (key->src_coords_normalized) > + pos = nir_fmul(b, pos, nir_load_var(b, v->v_src_inv_size)); > + > nir_tex_instr *tex = > - blorp_create_nir_tex_instr(b, v, nir_texop_tex, pos, 2, dst_type); > + blorp_create_nir_tex_instr(b, v, nir_texop_tex, pos, 2, > + key->texture_data_type); > > assert(pos->num_components == 2); > tex->sampler_dim = GLSL_SAMPLER_DIM_2D; > @@ -1188,7 +1195,7 @@ brw_blorp_build_nir_shader(struct blorp_context *blorp, > void *mem_ctx, > src_pos = nir_ishl(, src_pos, nir_imm_int(, 1)); > src_pos = nir_iadd(, src_pos, nir_imm_int(, 1)); > src_pos = nir_i2f32(, src_pos); > - color = blorp_nir_tex(, , src_pos, key->texture_data_type); > + color = blorp_nir_tex(, , key, src_pos); >} else { > /* Gen7+ hardware doesn't automaticaly blend. */ > color = blorp_nir_manual_blend_average(, , src_pos, > key->src_samples, > @@ -1200,7 +1207,7 @@ brw_blorp_build_nir_shader(struct blorp_context *blorp, > void *mem_ctx, >color = blorp_nir_manual_blend_bilinear(, src_pos, key->src_samples, > key, ); > } else { >if (key->bilinear_filter) { > - color = blorp_nir_tex(, , src_pos, key->texture_data_type); > + color = blorp_nir_tex(, , key, src_pos); >} else { > /* We're going to use texelFetch, so we need integers */ > if (src_pos->num_components == 2) { > @@ -2056,9 +2063,19 @@ blorp_blit(struct blorp_batch *batch, > wm_prog_key.y_scale = params.src.surf.samples / wm_prog_key.x_scale; > > if (filter == GL_LINEAR && > - params.src.surf.samples <= 1 && params.dst.surf.samples <= 1) > + params.src.surf.samples <= 1 && params.dst.surf.samples <= 1) { >wm_prog_key.bilinear_filter = true; > > + if (batch->blorp->isl_dev->info->gen < 6) { > + /* Gen4-5 don't support non-normalized texture coordinates */ > + wm_prog_key.src_coords_normalized = true; > + params.wm_inputs.src_inv_size[0] = > +1.0f / minify(params.src.surf.logical_level0_px.width, > src_level); > + params.wm_inputs.src_inv_size[1] = > +1.0f / minify(params.src.surf.logical_level0_px.height, > src_level); > + } > + } > + > if ((params.src.surf.usage & ISL_SURF_USAGE_DEPTH_BIT) == 0 && > (params.src.surf.usage & ISL_SURF_USAGE_STENCIL_BIT) == 0 && > !isl_format_has_int_channel(params.src.surf.format) && > diff --git a/src/intel/blorp/blorp_priv.h b/src/intel/blorp/blorp_priv.h > index c61ab08..39da5af 100644 > --- a/src/intel/blorp/blorp_priv.h > +++ b/src/intel/blorp/blorp_priv.h > @@ -124,6 +124,9 @@ struct brw_blorp_wm_inputs > struct blorp_surf_offset src_offset; > struct blorp_surf_offset dst_offset; > > + /* (1/width, 1/height) for the source surface */ > + float src_inv_size[2]; > + There is still the "pad[1]" in the end which I think is now correct, before it should have been "pad[3]", right? It aligns to vec4. Do we really need that anymore... > /* Minimum layer setting works for all the textures types but texture_3d > * for which the setting has no effect. Use the z-coordinate instead. > */ > @@ -228,6 +231,9 @@ struct brw_blorp_blit_prog_key > /* Number of bits per channel in the source image. */ > uint8_t src_bpc; > >
[Mesa-dev] [PATCH 25/43] intel/blorp/blit: Add support for normalized coordinates
Gen5 and earlier can't do non-normalized coordinates so we need to compensate in the shader. Fortunately, it's pretty easy plumb through. --- src/intel/blorp/blorp_blit.c | 27 ++- src/intel/blorp/blorp_priv.h | 6 ++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/intel/blorp/blorp_blit.c b/src/intel/blorp/blorp_blit.c index 144bfb3..23e33de 100644 --- a/src/intel/blorp/blorp_blit.c +++ b/src/intel/blorp/blorp_blit.c @@ -55,6 +55,7 @@ struct brw_blorp_blit_vars { nir_variable *v_src_z; nir_variable *v_src_offset; nir_variable *v_dst_offset; + nir_variable *v_src_inv_size; /* gl_FragCoord */ nir_variable *frag_coord; @@ -79,6 +80,7 @@ brw_blorp_blit_vars_init(nir_builder *b, struct brw_blorp_blit_vars *v, LOAD_INPUT(src_z, glsl_uint_type()) LOAD_INPUT(src_offset, glsl_vector_type(GLSL_TYPE_UINT, 2)) LOAD_INPUT(dst_offset, glsl_vector_type(GLSL_TYPE_UINT, 2)) + LOAD_INPUT(src_inv_size, glsl_vector_type(GLSL_TYPE_FLOAT, 2)) #undef LOAD_INPUT @@ -198,10 +200,15 @@ blorp_create_nir_tex_instr(nir_builder *b, struct brw_blorp_blit_vars *v, static nir_ssa_def * blorp_nir_tex(nir_builder *b, struct brw_blorp_blit_vars *v, - nir_ssa_def *pos, nir_alu_type dst_type) + const struct brw_blorp_blit_prog_key *key, nir_ssa_def *pos) { + /* If the sampler requires normalized coordinates, we need to compensate. */ + if (key->src_coords_normalized) + pos = nir_fmul(b, pos, nir_load_var(b, v->v_src_inv_size)); + nir_tex_instr *tex = - blorp_create_nir_tex_instr(b, v, nir_texop_tex, pos, 2, dst_type); + blorp_create_nir_tex_instr(b, v, nir_texop_tex, pos, 2, + key->texture_data_type); assert(pos->num_components == 2); tex->sampler_dim = GLSL_SAMPLER_DIM_2D; @@ -1188,7 +1195,7 @@ brw_blorp_build_nir_shader(struct blorp_context *blorp, void *mem_ctx, src_pos = nir_ishl(, src_pos, nir_imm_int(, 1)); src_pos = nir_iadd(, src_pos, nir_imm_int(, 1)); src_pos = nir_i2f32(, src_pos); - color = blorp_nir_tex(, , src_pos, key->texture_data_type); + color = blorp_nir_tex(, , key, src_pos); } else { /* Gen7+ hardware doesn't automaticaly blend. */ color = blorp_nir_manual_blend_average(, , src_pos, key->src_samples, @@ -1200,7 +1207,7 @@ brw_blorp_build_nir_shader(struct blorp_context *blorp, void *mem_ctx, color = blorp_nir_manual_blend_bilinear(, src_pos, key->src_samples, key, ); } else { if (key->bilinear_filter) { - color = blorp_nir_tex(, , src_pos, key->texture_data_type); + color = blorp_nir_tex(, , key, src_pos); } else { /* We're going to use texelFetch, so we need integers */ if (src_pos->num_components == 2) { @@ -2056,9 +2063,19 @@ blorp_blit(struct blorp_batch *batch, wm_prog_key.y_scale = params.src.surf.samples / wm_prog_key.x_scale; if (filter == GL_LINEAR && - params.src.surf.samples <= 1 && params.dst.surf.samples <= 1) + params.src.surf.samples <= 1 && params.dst.surf.samples <= 1) { wm_prog_key.bilinear_filter = true; + if (batch->blorp->isl_dev->info->gen < 6) { + /* Gen4-5 don't support non-normalized texture coordinates */ + wm_prog_key.src_coords_normalized = true; + params.wm_inputs.src_inv_size[0] = +1.0f / minify(params.src.surf.logical_level0_px.width, src_level); + params.wm_inputs.src_inv_size[1] = +1.0f / minify(params.src.surf.logical_level0_px.height, src_level); + } + } + if ((params.src.surf.usage & ISL_SURF_USAGE_DEPTH_BIT) == 0 && (params.src.surf.usage & ISL_SURF_USAGE_STENCIL_BIT) == 0 && !isl_format_has_int_channel(params.src.surf.format) && diff --git a/src/intel/blorp/blorp_priv.h b/src/intel/blorp/blorp_priv.h index c61ab08..39da5af 100644 --- a/src/intel/blorp/blorp_priv.h +++ b/src/intel/blorp/blorp_priv.h @@ -124,6 +124,9 @@ struct brw_blorp_wm_inputs struct blorp_surf_offset src_offset; struct blorp_surf_offset dst_offset; + /* (1/width, 1/height) for the source surface */ + float src_inv_size[2]; + /* Minimum layer setting works for all the textures types but texture_3d * for which the setting has no effect. Use the z-coordinate instead. */ @@ -228,6 +231,9 @@ struct brw_blorp_blit_prog_key /* Number of bits per channel in the source image. */ uint8_t src_bpc; + /* True if the source requires normalized coordinates */ + bool src_coords_normalized; + /* Number of samples per pixel that have been configured in the render * target. */ -- 2.5.0.400.gff86faf ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev