Re: [Mesa-dev] [PATCH v3 10/12] anv: add nir lowering pass for ycrcb textures
Quoting Lionel Landwerlin (2017-10-05 09:37:39) > On 05/10/17 17:36, Dylan Baker wrote: > > Quoting Lionel Landwerlin (2017-10-04 10:34:55) > > This pass implements all the implicit conversions required by the > VK_KHR_sampler_ycbcr_conversion specification. > > It also inserts plane sources onto sampling instructions that we then > let the pipeline layout pass deal with, when mapping things correctly > to descriptors. > > v2: Add new file to meson build (Lionel) > Use nir_frcp() rather than (1.0f / x) (Jason) > Reuse nir_tex_instr_dest_size() rather than handwritten one > (Jason) > Return progress (Jason) > Account for array of samplers (Jason) > > Signed-off-by: Lionel Landwerlin> --- > src/intel/Makefile.sources | 1 + > src/intel/vulkan/anv_nir.h | 3 + > src/intel/vulkan/anv_nir_apply_pipeline_layout.c | 61 ++- > src/intel/vulkan/anv_nir_lower_ycbcr_textures.c | 469 > +++ > src/intel/vulkan/anv_pipeline.c | 2 + > src/intel/vulkan/anv_private.h | 16 +- > src/intel/vulkan/meson.build | 1 + > 7 files changed, 547 insertions(+), 6 deletions(-) > create mode 100644 src/intel/vulkan/anv_nir_lower_ycbcr_textures.c > > diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources > index bca7a132b26..9672dcc252d 100644 > --- a/src/intel/Makefile.sources > +++ b/src/intel/Makefile.sources > @@ -219,6 +219,7 @@ VULKAN_FILES := \ > vulkan/anv_nir_lower_input_attachments.c \ > vulkan/anv_nir_lower_multiview.c \ > vulkan/anv_nir_lower_push_constants.c \ > + vulkan/anv_nir_lower_ycbcr_textures.c \ > > This needs to be added to meson too in src/intel/vulkan/meson.build > > > It is! :) I am blind apparently :) > > > > > vulkan/anv_pass.c \ > vulkan/anv_pipeline.c \ > vulkan/anv_pipeline_cache.c \ > diff --git a/src/intel/vulkan/anv_nir.h b/src/intel/vulkan/anv_nir.h > index 5b450b45cdf..8ac0a119dac 100644 > --- a/src/intel/vulkan/anv_nir.h > +++ b/src/intel/vulkan/anv_nir.h > @@ -37,6 +37,9 @@ void anv_nir_lower_push_constants(nir_shader > *shader); > > bool anv_nir_lower_multiview(nir_shader *shader, uint32_t view_mask); > > +bool anv_nir_lower_ycbcr_textures(nir_shader *shader, > + struct anv_pipeline *pipeline); > + > void anv_nir_apply_pipeline_layout(struct anv_pipeline *pipeline, > nir_shader *shader, > struct brw_stage_prog_data > *prog_data, > diff --git a/src/intel/vulkan/anv_nir_apply_pipeline_layout.c > b/src/intel/vulkan/anv_nir_apply_pipeline_layout.c > index 428cfdf42d1..28cbb98c563 100644 > --- a/src/intel/vulkan/anv_nir_apply_pipeline_layout.c > +++ b/src/intel/vulkan/anv_nir_apply_pipeline_layout.c > @@ -131,7 +131,7 @@ lower_res_index_intrinsic(nir_intrinsic_instr > *intrin, > static void > lower_tex_deref(nir_tex_instr *tex, nir_deref_var *deref, > unsigned *const_index, unsigned hw_binding_size, > -nir_tex_src_type src_type, > +nir_tex_src_type src_type, bool allow_indirect, > struct apply_pipeline_layout_state *state) > { > nir_builder *b = >builder; > @@ -141,6 +141,15 @@ lower_tex_deref(nir_tex_instr *tex, > nir_deref_var *deref, >nir_deref_array *deref_array = > nir_deref_as_array(deref->deref.child); > >if (deref_array->deref_array_type == > nir_deref_array_type_indirect) { > + /* From VK_KHR_sampler_ycbcr_conversion: > + * > + * If sampler Y’CBCR conversion is enabled, the combined > image > + * sampler must be indexed only by constant integral > expressions when > + * aggregated into arrays in shader code, irrespective of > the > + * shaderSampledImageArrayDynamicIndexing feature. > + */ > + assert(allow_indirect); > + > nir_ssa_def *index = > nir_iadd(b, nir_imm_int(b, deref_array->base_offset), > nir_ssa_for_src(b, deref_array->indirect, > 1)); > @@ -186,6 +195,46 @@ cleanup_tex_deref(nir_tex_instr *tex, > nir_deref_var *deref) > nir_instr_rewrite_src(>instr, _array->indirect, > NIR_SRC_INIT); >
Re: [Mesa-dev] [PATCH v3 10/12] anv: add nir lowering pass for ycrcb textures
On 05/10/17 17:36, Dylan Baker wrote: Quoting Lionel Landwerlin (2017-10-04 10:34:55) This pass implements all the implicit conversions required by the VK_KHR_sampler_ycbcr_conversion specification. It also inserts plane sources onto sampling instructions that we then let the pipeline layout pass deal with, when mapping things correctly to descriptors. v2: Add new file to meson build (Lionel) Use nir_frcp() rather than (1.0f / x) (Jason) Reuse nir_tex_instr_dest_size() rather than handwritten one (Jason) Return progress (Jason) Account for array of samplers (Jason) Signed-off-by: Lionel Landwerlin--- src/intel/Makefile.sources | 1 + src/intel/vulkan/anv_nir.h | 3 + src/intel/vulkan/anv_nir_apply_pipeline_layout.c | 61 ++- src/intel/vulkan/anv_nir_lower_ycbcr_textures.c | 469 +++ src/intel/vulkan/anv_pipeline.c | 2 + src/intel/vulkan/anv_private.h | 16 +- src/intel/vulkan/meson.build | 1 + 7 files changed, 547 insertions(+), 6 deletions(-) create mode 100644 src/intel/vulkan/anv_nir_lower_ycbcr_textures.c diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources index bca7a132b26..9672dcc252d 100644 --- a/src/intel/Makefile.sources +++ b/src/intel/Makefile.sources @@ -219,6 +219,7 @@ VULKAN_FILES := \ vulkan/anv_nir_lower_input_attachments.c \ vulkan/anv_nir_lower_multiview.c \ vulkan/anv_nir_lower_push_constants.c \ + vulkan/anv_nir_lower_ycbcr_textures.c \ This needs to be added to meson too in src/intel/vulkan/meson.build It is! :) vulkan/anv_pass.c \ vulkan/anv_pipeline.c \ vulkan/anv_pipeline_cache.c \ diff --git a/src/intel/vulkan/anv_nir.h b/src/intel/vulkan/anv_nir.h index 5b450b45cdf..8ac0a119dac 100644 --- a/src/intel/vulkan/anv_nir.h +++ b/src/intel/vulkan/anv_nir.h @@ -37,6 +37,9 @@ void anv_nir_lower_push_constants(nir_shader *shader); bool anv_nir_lower_multiview(nir_shader *shader, uint32_t view_mask); +bool anv_nir_lower_ycbcr_textures(nir_shader *shader, + struct anv_pipeline *pipeline); + void anv_nir_apply_pipeline_layout(struct anv_pipeline *pipeline, nir_shader *shader, struct brw_stage_prog_data *prog_data, diff --git a/src/intel/vulkan/anv_nir_apply_pipeline_layout.c b/src/intel/vulkan/anv_nir_apply_pipeline_layout.c index 428cfdf42d1..28cbb98c563 100644 --- a/src/intel/vulkan/anv_nir_apply_pipeline_layout.c +++ b/src/intel/vulkan/anv_nir_apply_pipeline_layout.c @@ -131,7 +131,7 @@ lower_res_index_intrinsic(nir_intrinsic_instr *intrin, static void lower_tex_deref(nir_tex_instr *tex, nir_deref_var *deref, unsigned *const_index, unsigned hw_binding_size, -nir_tex_src_type src_type, +nir_tex_src_type src_type, bool allow_indirect, struct apply_pipeline_layout_state *state) { nir_builder *b = >builder; @@ -141,6 +141,15 @@ lower_tex_deref(nir_tex_instr *tex, nir_deref_var *deref, nir_deref_array *deref_array = nir_deref_as_array(deref->deref.child); if (deref_array->deref_array_type == nir_deref_array_type_indirect) { + /* From VK_KHR_sampler_ycbcr_conversion: + * + * If sampler Y’CBCR conversion is enabled, the combined image + * sampler must be indexed only by constant integral expressions when + * aggregated into arrays in shader code, irrespective of the + * shaderSampledImageArrayDynamicIndexing feature. + */ + assert(allow_indirect); + nir_ssa_def *index = nir_iadd(b, nir_imm_int(b, deref_array->base_offset), nir_ssa_for_src(b, deref_array->indirect, 1)); @@ -186,6 +195,46 @@ cleanup_tex_deref(nir_tex_instr *tex, nir_deref_var *deref) nir_instr_rewrite_src(>instr, _array->indirect, NIR_SRC_INIT); } +static bool +has_tex_src_plane(nir_tex_instr *tex) +{ + for (unsigned i = 0; i < tex->num_srcs; i++) { + if (tex->src[i].src_type == nir_tex_src_plane) + return true; + } + + return false; +} + +static uint32_t +extract_tex_src_plane(nir_tex_instr *tex) +{ + nir_tex_src *new_srcs = rzalloc_array(tex, nir_tex_src, tex->num_srcs - 1); + unsigned plane = 0; + + for (unsigned i = 0, w = 0; i < tex->num_srcs; i++) { + if (tex->src[i].src_type == nir_tex_src_plane) { + nir_const_value *const_plane = +nir_src_as_const_value(tex->src[i].src); + + /* Our color conversion lowering pass should only ever insert + * constants. */ + assert(const_plane); + plane = const_plane->u32[0]; + } else { + new_srcs[w].src_type = tex->src[i].src_type; + nir_instr_move_src(>instr,
Re: [Mesa-dev] [PATCH v3 10/12] anv: add nir lowering pass for ycrcb textures
Quoting Lionel Landwerlin (2017-10-04 10:34:55) > This pass implements all the implicit conversions required by the > VK_KHR_sampler_ycbcr_conversion specification. > > It also inserts plane sources onto sampling instructions that we then > let the pipeline layout pass deal with, when mapping things correctly > to descriptors. > > v2: Add new file to meson build (Lionel) > Use nir_frcp() rather than (1.0f / x) (Jason) > Reuse nir_tex_instr_dest_size() rather than handwritten one (Jason) > Return progress (Jason) > Account for array of samplers (Jason) > > Signed-off-by: Lionel Landwerlin> --- > src/intel/Makefile.sources | 1 + > src/intel/vulkan/anv_nir.h | 3 + > src/intel/vulkan/anv_nir_apply_pipeline_layout.c | 61 ++- > src/intel/vulkan/anv_nir_lower_ycbcr_textures.c | 469 > +++ > src/intel/vulkan/anv_pipeline.c | 2 + > src/intel/vulkan/anv_private.h | 16 +- > src/intel/vulkan/meson.build | 1 + > 7 files changed, 547 insertions(+), 6 deletions(-) > create mode 100644 src/intel/vulkan/anv_nir_lower_ycbcr_textures.c > > diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources > index bca7a132b26..9672dcc252d 100644 > --- a/src/intel/Makefile.sources > +++ b/src/intel/Makefile.sources > @@ -219,6 +219,7 @@ VULKAN_FILES := \ > vulkan/anv_nir_lower_input_attachments.c \ > vulkan/anv_nir_lower_multiview.c \ > vulkan/anv_nir_lower_push_constants.c \ > + vulkan/anv_nir_lower_ycbcr_textures.c \ This needs to be added to meson too in src/intel/vulkan/meson.build > vulkan/anv_pass.c \ > vulkan/anv_pipeline.c \ > vulkan/anv_pipeline_cache.c \ > diff --git a/src/intel/vulkan/anv_nir.h b/src/intel/vulkan/anv_nir.h > index 5b450b45cdf..8ac0a119dac 100644 > --- a/src/intel/vulkan/anv_nir.h > +++ b/src/intel/vulkan/anv_nir.h > @@ -37,6 +37,9 @@ void anv_nir_lower_push_constants(nir_shader *shader); > > bool anv_nir_lower_multiview(nir_shader *shader, uint32_t view_mask); > > +bool anv_nir_lower_ycbcr_textures(nir_shader *shader, > + struct anv_pipeline *pipeline); > + > void anv_nir_apply_pipeline_layout(struct anv_pipeline *pipeline, > nir_shader *shader, > struct brw_stage_prog_data *prog_data, > diff --git a/src/intel/vulkan/anv_nir_apply_pipeline_layout.c > b/src/intel/vulkan/anv_nir_apply_pipeline_layout.c > index 428cfdf42d1..28cbb98c563 100644 > --- a/src/intel/vulkan/anv_nir_apply_pipeline_layout.c > +++ b/src/intel/vulkan/anv_nir_apply_pipeline_layout.c > @@ -131,7 +131,7 @@ lower_res_index_intrinsic(nir_intrinsic_instr *intrin, > static void > lower_tex_deref(nir_tex_instr *tex, nir_deref_var *deref, > unsigned *const_index, unsigned hw_binding_size, > -nir_tex_src_type src_type, > +nir_tex_src_type src_type, bool allow_indirect, > struct apply_pipeline_layout_state *state) > { > nir_builder *b = >builder; > @@ -141,6 +141,15 @@ lower_tex_deref(nir_tex_instr *tex, nir_deref_var *deref, >nir_deref_array *deref_array = nir_deref_as_array(deref->deref.child); > >if (deref_array->deref_array_type == nir_deref_array_type_indirect) { > + /* From VK_KHR_sampler_ycbcr_conversion: > + * > + * If sampler Y’CBCR conversion is enabled, the combined image > + * sampler must be indexed only by constant integral expressions > when > + * aggregated into arrays in shader code, irrespective of the > + * shaderSampledImageArrayDynamicIndexing feature. > + */ > + assert(allow_indirect); > + > nir_ssa_def *index = > nir_iadd(b, nir_imm_int(b, deref_array->base_offset), > nir_ssa_for_src(b, deref_array->indirect, 1)); > @@ -186,6 +195,46 @@ cleanup_tex_deref(nir_tex_instr *tex, nir_deref_var > *deref) > nir_instr_rewrite_src(>instr, _array->indirect, NIR_SRC_INIT); > } > > +static bool > +has_tex_src_plane(nir_tex_instr *tex) > +{ > + for (unsigned i = 0; i < tex->num_srcs; i++) { > + if (tex->src[i].src_type == nir_tex_src_plane) > + return true; > + } > + > + return false; > +} > + > +static uint32_t > +extract_tex_src_plane(nir_tex_instr *tex) > +{ > + nir_tex_src *new_srcs = rzalloc_array(tex, nir_tex_src, tex->num_srcs - > 1); > + unsigned plane = 0; > + > + for (unsigned i = 0, w = 0; i < tex->num_srcs; i++) { > + if (tex->src[i].src_type == nir_tex_src_plane) { > + nir_const_value *const_plane = > +nir_src_as_const_value(tex->src[i].src); > + > + /* Our color conversion lowering pass should only ever insert > + * constants. */ > + assert(const_plane); > + plane =
Re: [Mesa-dev] [PATCH v3 10/12] anv: add nir lowering pass for ycrcb textures
All of these changed were made :) On 04/10/17 22:32, Jason Ekstrand wrote: On Wed, Oct 4, 2017 at 10:34 AM, Lionel Landwerlin> wrote: This pass implements all the implicit conversions required by the VK_KHR_sampler_ycbcr_conversion specification. It also inserts plane sources onto sampling instructions that we then let the pipeline layout pass deal with, when mapping things correctly to descriptors. v2: Add new file to meson build (Lionel) Use nir_frcp() rather than (1.0f / x) (Jason) Reuse nir_tex_instr_dest_size() rather than handwritten one (Jason) Return progress (Jason) Account for array of samplers (Jason) Signed-off-by: Lionel Landwerlin > --- src/intel/Makefile.sources | 1 + src/intel/vulkan/anv_nir.h | 3 + src/intel/vulkan/anv_nir_apply_pipeline_layout.c | 61 ++- src/intel/vulkan/anv_nir_lower_ycbcr_textures.c | 469 +++ src/intel/vulkan/anv_pipeline.c | 2 + src/intel/vulkan/anv_private.h | 16 +- src/intel/vulkan/meson.build | 1 + 7 files changed, 547 insertions(+), 6 deletions(-) create mode 100644 src/intel/vulkan/anv_nir_lower_ycbcr_textures.c diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources index bca7a132b26..9672dcc252d 100644 --- a/src/intel/Makefile.sources +++ b/src/intel/Makefile.sources @@ -219,6 +219,7 @@ VULKAN_FILES := \ vulkan/anv_nir_lower_input_attachments.c \ vulkan/anv_nir_lower_multiview.c \ vulkan/anv_nir_lower_push_constants.c \ + vulkan/anv_nir_lower_ycbcr_textures.c \ vulkan/anv_pass.c \ vulkan/anv_pipeline.c \ vulkan/anv_pipeline_cache.c \ diff --git a/src/intel/vulkan/anv_nir.h b/src/intel/vulkan/anv_nir.h index 5b450b45cdf..8ac0a119dac 100644 --- a/src/intel/vulkan/anv_nir.h +++ b/src/intel/vulkan/anv_nir.h @@ -37,6 +37,9 @@ void anv_nir_lower_push_constants(nir_shader *shader); bool anv_nir_lower_multiview(nir_shader *shader, uint32_t view_mask); +bool anv_nir_lower_ycbcr_textures(nir_shader *shader, + struct anv_pipeline *pipeline); + void anv_nir_apply_pipeline_layout(struct anv_pipeline *pipeline, nir_shader *shader, struct brw_stage_prog_data *prog_data, diff --git a/src/intel/vulkan/anv_nir_apply_pipeline_layout.c b/src/intel/vulkan/anv_nir_apply_pipeline_layout.c index 428cfdf42d1..28cbb98c563 100644 --- a/src/intel/vulkan/anv_nir_apply_pipeline_layout.c +++ b/src/intel/vulkan/anv_nir_apply_pipeline_layout.c @@ -131,7 +131,7 @@ lower_res_index_intrinsic(nir_intrinsic_instr *intrin, static void lower_tex_deref(nir_tex_instr *tex, nir_deref_var *deref, unsigned *const_index, unsigned hw_binding_size, - nir_tex_src_type src_type, + nir_tex_src_type src_type, bool allow_indirect, struct apply_pipeline_layout_state *state) { nir_builder *b = >builder; @@ -141,6 +141,15 @@ lower_tex_deref(nir_tex_instr *tex, nir_deref_var *deref, nir_deref_array *deref_array = nir_deref_as_array(deref->deref.child); if (deref_array->deref_array_type == nir_deref_array_type_indirect) { + /* From VK_KHR_sampler_ycbcr_conversion: + * + * If sampler Y’CBCR conversion is enabled, the combined image + * sampler must be indexed only by constant integral expressions when + * aggregated into arrays in shader code, irrespective of the + * shaderSampledImageArrayDynamicIndexing feature. + */ + assert(allow_indirect); + nir_ssa_def *index = nir_iadd(b, nir_imm_int(b, deref_array->base_offset), nir_ssa_for_src(b, deref_array->indirect, 1)); @@ -186,6 +195,46 @@ cleanup_tex_deref(nir_tex_instr *tex, nir_deref_var *deref) nir_instr_rewrite_src(>instr, _array->indirect, NIR_SRC_INIT); } +static bool +has_tex_src_plane(nir_tex_instr *tex) +{ + for (unsigned i = 0; i < tex->num_srcs; i++) { + if (tex->src[i].src_type == nir_tex_src_plane) + return true; + } + + return false; +} + +static uint32_t +extract_tex_src_plane(nir_tex_instr *tex) +{ + nir_tex_src *new_srcs = rzalloc_array(tex, nir_tex_src, tex->num_srcs - 1); + unsigned plane = 0; + + for (unsigned i = 0, w = 0; i <
Re: [Mesa-dev] [PATCH v3 10/12] anv: add nir lowering pass for ycrcb textures
On Wed, Oct 4, 2017 at 10:34 AM, Lionel Landwerlin < lionel.g.landwer...@intel.com> wrote: > This pass implements all the implicit conversions required by the > VK_KHR_sampler_ycbcr_conversion specification. > > It also inserts plane sources onto sampling instructions that we then > let the pipeline layout pass deal with, when mapping things correctly > to descriptors. > > v2: Add new file to meson build (Lionel) > Use nir_frcp() rather than (1.0f / x) (Jason) > Reuse nir_tex_instr_dest_size() rather than handwritten one (Jason) > Return progress (Jason) > Account for array of samplers (Jason) > > Signed-off-by: Lionel Landwerlin> --- > src/intel/Makefile.sources | 1 + > src/intel/vulkan/anv_nir.h | 3 + > src/intel/vulkan/anv_nir_apply_pipeline_layout.c | 61 ++- > src/intel/vulkan/anv_nir_lower_ycbcr_textures.c | 469 > +++ > src/intel/vulkan/anv_pipeline.c | 2 + > src/intel/vulkan/anv_private.h | 16 +- > src/intel/vulkan/meson.build | 1 + > 7 files changed, 547 insertions(+), 6 deletions(-) > create mode 100644 src/intel/vulkan/anv_nir_lower_ycbcr_textures.c > > diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources > index bca7a132b26..9672dcc252d 100644 > --- a/src/intel/Makefile.sources > +++ b/src/intel/Makefile.sources > @@ -219,6 +219,7 @@ VULKAN_FILES := \ > vulkan/anv_nir_lower_input_attachments.c \ > vulkan/anv_nir_lower_multiview.c \ > vulkan/anv_nir_lower_push_constants.c \ > + vulkan/anv_nir_lower_ycbcr_textures.c \ > vulkan/anv_pass.c \ > vulkan/anv_pipeline.c \ > vulkan/anv_pipeline_cache.c \ > diff --git a/src/intel/vulkan/anv_nir.h b/src/intel/vulkan/anv_nir.h > index 5b450b45cdf..8ac0a119dac 100644 > --- a/src/intel/vulkan/anv_nir.h > +++ b/src/intel/vulkan/anv_nir.h > @@ -37,6 +37,9 @@ void anv_nir_lower_push_constants(nir_shader *shader); > > bool anv_nir_lower_multiview(nir_shader *shader, uint32_t view_mask); > > +bool anv_nir_lower_ycbcr_textures(nir_shader *shader, > + struct anv_pipeline *pipeline); > + > void anv_nir_apply_pipeline_layout(struct anv_pipeline *pipeline, > nir_shader *shader, > struct brw_stage_prog_data *prog_data, > diff --git a/src/intel/vulkan/anv_nir_apply_pipeline_layout.c > b/src/intel/vulkan/anv_nir_apply_pipeline_layout.c > index 428cfdf42d1..28cbb98c563 100644 > --- a/src/intel/vulkan/anv_nir_apply_pipeline_layout.c > +++ b/src/intel/vulkan/anv_nir_apply_pipeline_layout.c > @@ -131,7 +131,7 @@ lower_res_index_intrinsic(nir_intrinsic_instr *intrin, > static void > lower_tex_deref(nir_tex_instr *tex, nir_deref_var *deref, > unsigned *const_index, unsigned hw_binding_size, > -nir_tex_src_type src_type, > +nir_tex_src_type src_type, bool allow_indirect, > struct apply_pipeline_layout_state *state) > { > nir_builder *b = >builder; > @@ -141,6 +141,15 @@ lower_tex_deref(nir_tex_instr *tex, nir_deref_var > *deref, >nir_deref_array *deref_array = nir_deref_as_array(deref-> > deref.child); > >if (deref_array->deref_array_type == nir_deref_array_type_indirect) > { > + /* From VK_KHR_sampler_ycbcr_conversion: > + * > + * If sampler Y’CBCR conversion is enabled, the combined image > + * sampler must be indexed only by constant integral expressions > when > + * aggregated into arrays in shader code, irrespective of the > + * shaderSampledImageArrayDynamicIndexing feature. > + */ > + assert(allow_indirect); > + > nir_ssa_def *index = > nir_iadd(b, nir_imm_int(b, deref_array->base_offset), > nir_ssa_for_src(b, deref_array->indirect, 1)); > @@ -186,6 +195,46 @@ cleanup_tex_deref(nir_tex_instr *tex, nir_deref_var > *deref) > nir_instr_rewrite_src(>instr, _array->indirect, > NIR_SRC_INIT); > } > > +static bool > +has_tex_src_plane(nir_tex_instr *tex) > +{ > + for (unsigned i = 0; i < tex->num_srcs; i++) { > + if (tex->src[i].src_type == nir_tex_src_plane) > + return true; > + } > + > + return false; > +} > + > +static uint32_t > +extract_tex_src_plane(nir_tex_instr *tex) > +{ > + nir_tex_src *new_srcs = rzalloc_array(tex, nir_tex_src, tex->num_srcs > - 1); > + unsigned plane = 0; > + > + for (unsigned i = 0, w = 0; i < tex->num_srcs; i++) { > + if (tex->src[i].src_type == nir_tex_src_plane) { > + nir_const_value *const_plane = > +nir_src_as_const_value(tex->src[i].src); > + > + /* Our color conversion lowering pass should only ever insert > + * constants. */ > + assert(const_plane); > + plane = const_plane->u32[0]; > + }
[Mesa-dev] [PATCH v3 10/12] anv: add nir lowering pass for ycrcb textures
This pass implements all the implicit conversions required by the VK_KHR_sampler_ycbcr_conversion specification. It also inserts plane sources onto sampling instructions that we then let the pipeline layout pass deal with, when mapping things correctly to descriptors. v2: Add new file to meson build (Lionel) Use nir_frcp() rather than (1.0f / x) (Jason) Reuse nir_tex_instr_dest_size() rather than handwritten one (Jason) Return progress (Jason) Account for array of samplers (Jason) Signed-off-by: Lionel Landwerlin--- src/intel/Makefile.sources | 1 + src/intel/vulkan/anv_nir.h | 3 + src/intel/vulkan/anv_nir_apply_pipeline_layout.c | 61 ++- src/intel/vulkan/anv_nir_lower_ycbcr_textures.c | 469 +++ src/intel/vulkan/anv_pipeline.c | 2 + src/intel/vulkan/anv_private.h | 16 +- src/intel/vulkan/meson.build | 1 + 7 files changed, 547 insertions(+), 6 deletions(-) create mode 100644 src/intel/vulkan/anv_nir_lower_ycbcr_textures.c diff --git a/src/intel/Makefile.sources b/src/intel/Makefile.sources index bca7a132b26..9672dcc252d 100644 --- a/src/intel/Makefile.sources +++ b/src/intel/Makefile.sources @@ -219,6 +219,7 @@ VULKAN_FILES := \ vulkan/anv_nir_lower_input_attachments.c \ vulkan/anv_nir_lower_multiview.c \ vulkan/anv_nir_lower_push_constants.c \ + vulkan/anv_nir_lower_ycbcr_textures.c \ vulkan/anv_pass.c \ vulkan/anv_pipeline.c \ vulkan/anv_pipeline_cache.c \ diff --git a/src/intel/vulkan/anv_nir.h b/src/intel/vulkan/anv_nir.h index 5b450b45cdf..8ac0a119dac 100644 --- a/src/intel/vulkan/anv_nir.h +++ b/src/intel/vulkan/anv_nir.h @@ -37,6 +37,9 @@ void anv_nir_lower_push_constants(nir_shader *shader); bool anv_nir_lower_multiview(nir_shader *shader, uint32_t view_mask); +bool anv_nir_lower_ycbcr_textures(nir_shader *shader, + struct anv_pipeline *pipeline); + void anv_nir_apply_pipeline_layout(struct anv_pipeline *pipeline, nir_shader *shader, struct brw_stage_prog_data *prog_data, diff --git a/src/intel/vulkan/anv_nir_apply_pipeline_layout.c b/src/intel/vulkan/anv_nir_apply_pipeline_layout.c index 428cfdf42d1..28cbb98c563 100644 --- a/src/intel/vulkan/anv_nir_apply_pipeline_layout.c +++ b/src/intel/vulkan/anv_nir_apply_pipeline_layout.c @@ -131,7 +131,7 @@ lower_res_index_intrinsic(nir_intrinsic_instr *intrin, static void lower_tex_deref(nir_tex_instr *tex, nir_deref_var *deref, unsigned *const_index, unsigned hw_binding_size, -nir_tex_src_type src_type, +nir_tex_src_type src_type, bool allow_indirect, struct apply_pipeline_layout_state *state) { nir_builder *b = >builder; @@ -141,6 +141,15 @@ lower_tex_deref(nir_tex_instr *tex, nir_deref_var *deref, nir_deref_array *deref_array = nir_deref_as_array(deref->deref.child); if (deref_array->deref_array_type == nir_deref_array_type_indirect) { + /* From VK_KHR_sampler_ycbcr_conversion: + * + * If sampler Y’CBCR conversion is enabled, the combined image + * sampler must be indexed only by constant integral expressions when + * aggregated into arrays in shader code, irrespective of the + * shaderSampledImageArrayDynamicIndexing feature. + */ + assert(allow_indirect); + nir_ssa_def *index = nir_iadd(b, nir_imm_int(b, deref_array->base_offset), nir_ssa_for_src(b, deref_array->indirect, 1)); @@ -186,6 +195,46 @@ cleanup_tex_deref(nir_tex_instr *tex, nir_deref_var *deref) nir_instr_rewrite_src(>instr, _array->indirect, NIR_SRC_INIT); } +static bool +has_tex_src_plane(nir_tex_instr *tex) +{ + for (unsigned i = 0; i < tex->num_srcs; i++) { + if (tex->src[i].src_type == nir_tex_src_plane) + return true; + } + + return false; +} + +static uint32_t +extract_tex_src_plane(nir_tex_instr *tex) +{ + nir_tex_src *new_srcs = rzalloc_array(tex, nir_tex_src, tex->num_srcs - 1); + unsigned plane = 0; + + for (unsigned i = 0, w = 0; i < tex->num_srcs; i++) { + if (tex->src[i].src_type == nir_tex_src_plane) { + nir_const_value *const_plane = +nir_src_as_const_value(tex->src[i].src); + + /* Our color conversion lowering pass should only ever insert + * constants. */ + assert(const_plane); + plane = const_plane->u32[0]; + } else { + new_srcs[w].src_type = tex->src[i].src_type; + nir_instr_move_src(>instr, _srcs[w].src, >src[i].src); + w++; + } + } + + ralloc_free(tex->src); + tex->src = new_srcs; + tex->num_srcs--; + + return plane; +} + static void lower_tex(nir_tex_instr *tex, struct