anv/pipeline: Convert YCbCr lowering to deref instructiosn
Acked-by: Rob Clark <robdclark@gmail.com> Acked-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl> Acked-by: Dave Airlie <airlied@redhat.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
This commit is contained in:
@@ -30,6 +30,7 @@ struct ycbcr_state {
|
|||||||
nir_builder *builder;
|
nir_builder *builder;
|
||||||
nir_ssa_def *image_size;
|
nir_ssa_def *image_size;
|
||||||
nir_tex_instr *origin_tex;
|
nir_tex_instr *origin_tex;
|
||||||
|
nir_deref_instr *tex_deref;
|
||||||
struct anv_ycbcr_conversion *conversion;
|
struct anv_ycbcr_conversion *conversion;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -152,22 +153,24 @@ convert_ycbcr(struct ycbcr_state *state,
|
|||||||
|
|
||||||
/* TODO: we should probably replace this with a push constant/uniform. */
|
/* TODO: we should probably replace this with a push constant/uniform. */
|
||||||
static nir_ssa_def *
|
static nir_ssa_def *
|
||||||
get_texture_size(struct ycbcr_state *state, nir_deref_var *texture)
|
get_texture_size(struct ycbcr_state *state, nir_deref_instr *texture)
|
||||||
{
|
{
|
||||||
if (state->image_size)
|
if (state->image_size)
|
||||||
return state->image_size;
|
return state->image_size;
|
||||||
|
|
||||||
nir_builder *b = state->builder;
|
nir_builder *b = state->builder;
|
||||||
const struct glsl_type *type = nir_deref_tail(&texture->deref)->type;
|
const struct glsl_type *type = texture->type;
|
||||||
nir_tex_instr *tex = nir_tex_instr_create(b->shader, 0);
|
nir_tex_instr *tex = nir_tex_instr_create(b->shader, 1);
|
||||||
|
|
||||||
tex->op = nir_texop_txs;
|
tex->op = nir_texop_txs;
|
||||||
tex->sampler_dim = glsl_get_sampler_dim(type);
|
tex->sampler_dim = glsl_get_sampler_dim(type);
|
||||||
tex->is_array = glsl_sampler_type_is_array(type);
|
tex->is_array = glsl_sampler_type_is_array(type);
|
||||||
tex->is_shadow = glsl_sampler_type_is_shadow(type);
|
tex->is_shadow = glsl_sampler_type_is_shadow(type);
|
||||||
tex->texture = nir_deref_var_clone(texture, tex);
|
|
||||||
tex->dest_type = nir_type_int;
|
tex->dest_type = nir_type_int;
|
||||||
|
|
||||||
|
tex->src[0].src_type = nir_tex_src_texture_deref;
|
||||||
|
tex->src[0].src = nir_src_for_ssa(&texture->dest.ssa);
|
||||||
|
|
||||||
nir_ssa_dest_init(&tex->instr, &tex->dest,
|
nir_ssa_dest_init(&tex->instr, &tex->dest,
|
||||||
nir_tex_instr_dest_size(tex), 32, NULL);
|
nir_tex_instr_dest_size(tex), 32, NULL);
|
||||||
nir_builder_instr_insert(b, &tex->instr);
|
nir_builder_instr_insert(b, &tex->instr);
|
||||||
@@ -199,8 +202,7 @@ implicit_downsampled_coords(struct ycbcr_state *state,
|
|||||||
{
|
{
|
||||||
nir_builder *b = state->builder;
|
nir_builder *b = state->builder;
|
||||||
struct anv_ycbcr_conversion *conversion = state->conversion;
|
struct anv_ycbcr_conversion *conversion = state->conversion;
|
||||||
nir_ssa_def *image_size = get_texture_size(state,
|
nir_ssa_def *image_size = get_texture_size(state, state->tex_deref);
|
||||||
state->origin_tex->texture);
|
|
||||||
nir_ssa_def *comp[4] = { NULL, };
|
nir_ssa_def *comp[4] = { NULL, };
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
@@ -266,10 +268,7 @@ create_plane_tex_instr_implicit(struct ycbcr_state *state,
|
|||||||
|
|
||||||
tex->texture_index = old_tex->texture_index;
|
tex->texture_index = old_tex->texture_index;
|
||||||
tex->texture_array_size = old_tex->texture_array_size;
|
tex->texture_array_size = old_tex->texture_array_size;
|
||||||
tex->texture = nir_deref_var_clone(old_tex->texture, tex);
|
|
||||||
|
|
||||||
tex->sampler_index = old_tex->sampler_index;
|
tex->sampler_index = old_tex->sampler_index;
|
||||||
tex->sampler = nir_deref_var_clone(old_tex->sampler, tex);
|
|
||||||
|
|
||||||
nir_ssa_dest_init(&tex->instr, &tex->dest,
|
nir_ssa_dest_init(&tex->instr, &tex->dest,
|
||||||
old_tex->dest.ssa.num_components,
|
old_tex->dest.ssa.num_components,
|
||||||
@@ -320,7 +319,11 @@ try_lower_tex_ycbcr(struct anv_pipeline_layout *layout,
|
|||||||
nir_builder *builder,
|
nir_builder *builder,
|
||||||
nir_tex_instr *tex)
|
nir_tex_instr *tex)
|
||||||
{
|
{
|
||||||
nir_variable *var = tex->texture->var;
|
int deref_src_idx = nir_tex_instr_src_index(tex, nir_tex_src_texture_deref);
|
||||||
|
assert(deref_src_idx >= 0);
|
||||||
|
nir_deref_instr *deref = nir_src_as_deref(tex->src[deref_src_idx].src);
|
||||||
|
|
||||||
|
nir_variable *var = nir_deref_instr_get_variable(deref);
|
||||||
const struct anv_descriptor_set_layout *set_layout =
|
const struct anv_descriptor_set_layout *set_layout =
|
||||||
layout->set[var->data.descriptor_set].layout;
|
layout->set[var->data.descriptor_set].layout;
|
||||||
const struct anv_descriptor_set_binding_layout *binding =
|
const struct anv_descriptor_set_binding_layout *binding =
|
||||||
@@ -338,14 +341,14 @@ try_lower_tex_ycbcr(struct anv_pipeline_layout *layout,
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
unsigned texture_index = tex->texture_index;
|
unsigned texture_index = tex->texture_index;
|
||||||
if (tex->texture->deref.child) {
|
if (deref->deref_type != nir_deref_type_var) {
|
||||||
assert(tex->texture->deref.child->deref_type == nir_deref_type_array);
|
assert(deref->deref_type == nir_deref_type_array);
|
||||||
nir_deref_array *deref_array = nir_deref_as_array(tex->texture->deref.child);
|
nir_const_value *const_index = nir_src_as_const_value(deref->arr.index);
|
||||||
if (deref_array->deref_array_type != nir_deref_array_type_direct)
|
if (!const_index)
|
||||||
return false;
|
return false;
|
||||||
size_t hw_binding_size =
|
size_t hw_binding_size =
|
||||||
anv_descriptor_set_binding_layout_get_hw_size(binding);
|
anv_descriptor_set_binding_layout_get_hw_size(binding);
|
||||||
texture_index += MIN2(deref_array->base_offset, hw_binding_size - 1);
|
texture_index += MIN2(const_index->u32[0], hw_binding_size - 1);
|
||||||
}
|
}
|
||||||
const struct anv_sampler *sampler =
|
const struct anv_sampler *sampler =
|
||||||
binding->immutable_samplers[texture_index];
|
binding->immutable_samplers[texture_index];
|
||||||
@@ -356,6 +359,7 @@ try_lower_tex_ycbcr(struct anv_pipeline_layout *layout,
|
|||||||
struct ycbcr_state state = {
|
struct ycbcr_state state = {
|
||||||
.builder = builder,
|
.builder = builder,
|
||||||
.origin_tex = tex,
|
.origin_tex = tex,
|
||||||
|
.tex_deref = deref,
|
||||||
.conversion = sampler->conversion,
|
.conversion = sampler->conversion,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -221,9 +221,6 @@ anv_shader_compile_to_nir(struct anv_pipeline *pipeline,
|
|||||||
if (stage == MESA_SHADER_FRAGMENT)
|
if (stage == MESA_SHADER_FRAGMENT)
|
||||||
NIR_PASS_V(nir, anv_nir_lower_input_attachments);
|
NIR_PASS_V(nir, anv_nir_lower_input_attachments);
|
||||||
|
|
||||||
NIR_PASS_V(nir, nir_lower_deref_instrs,
|
|
||||||
nir_lower_texture_derefs | nir_lower_image_derefs);
|
|
||||||
|
|
||||||
return nir;
|
return nir;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -423,6 +420,9 @@ anv_pipeline_compile(struct anv_pipeline *pipeline,
|
|||||||
|
|
||||||
NIR_PASS_V(nir, anv_nir_lower_ycbcr_textures, layout);
|
NIR_PASS_V(nir, anv_nir_lower_ycbcr_textures, layout);
|
||||||
|
|
||||||
|
NIR_PASS_V(nir, nir_lower_deref_instrs,
|
||||||
|
nir_lower_texture_derefs | nir_lower_image_derefs);
|
||||||
|
|
||||||
NIR_PASS_V(nir, anv_nir_lower_push_constants);
|
NIR_PASS_V(nir, anv_nir_lower_push_constants);
|
||||||
|
|
||||||
if (stage != MESA_SHADER_COMPUTE)
|
if (stage != MESA_SHADER_COMPUTE)
|
||||||
|
Reference in New Issue
Block a user