anv: Fix up spirv for new texture/sampler split stuff

This commit is contained in:
Jason Ekstrand 2016-02-09 12:13:32 -08:00
parent b14f4c1fd3
commit 09b3e30dc6
4 changed files with 42 additions and 22 deletions

View file

@ -1389,12 +1389,32 @@ vtn_handle_texture(struct vtn_builder *b, SpvOp opcode,
}
nir_deref_var *sampler = vtn_access_chain_to_deref(b, sampled.sampler);
instr->sampler = nir_deref_as_var(nir_copy_deref(instr, &sampler->deref));
if (sampled.image) {
nir_deref_var *image = vtn_access_chain_to_deref(b, sampled.image);
instr->texture = nir_deref_as_var(nir_copy_deref(instr, &image->deref));
} else {
instr->texture = NULL;
instr->texture = nir_deref_as_var(nir_copy_deref(instr, &sampler->deref));
}
switch (instr->op) {
case nir_texop_tex:
case nir_texop_txb:
case nir_texop_txl:
case nir_texop_txd:
/* These operations require a sampler */
instr->sampler = nir_deref_as_var(nir_copy_deref(instr, &sampler->deref));
break;
case nir_texop_txf:
case nir_texop_txf_ms:
case nir_texop_txs:
case nir_texop_lod:
case nir_texop_tg4:
case nir_texop_query_levels:
case nir_texop_texture_samples:
case nir_texop_samples_identical:
/* These don't */
instr->sampler = NULL;
break;
}
nir_ssa_dest_init(&instr->instr, &instr->dest,

View file

@ -106,6 +106,7 @@ build_nir_copy_fragment_shader(enum glsl_sampler_dim tex_dim)
tex->dest_type = nir_type_float; /* TODO */
tex->is_array = glsl_sampler_type_is_array(sampler_type);
tex->coord_components = tex_pos->num_components;
tex->texture = nir_deref_var_create(tex, sampler);
tex->sampler = nir_deref_var_create(tex, sampler);
nir_ssa_dest_init(&tex->instr, &tex->dest, 4, "tex");

View file

@ -152,6 +152,7 @@ build_nir_fs(uint32_t num_samples)
nir_tex_instr *tex;
tex = nir_tex_instr_create(b.shader, /*num_srcs*/ 2);
tex->texture = nir_deref_var_create(tex, u_tex);
tex->sampler = nir_deref_var_create(tex, u_tex);
tex->sampler_dim = GLSL_SAMPLER_DIM_MS;
tex->op = nir_texop_txf_ms;

View file

@ -58,21 +58,18 @@ get_surface_index(unsigned set, unsigned binding,
}
static uint32_t
get_sampler_index(unsigned set, unsigned binding, nir_texop tex_op,
get_sampler_index(unsigned set, unsigned binding,
struct apply_pipeline_layout_state *state)
{
assert(set < state->layout->num_sets);
struct anv_descriptor_set_layout *set_layout =
state->layout->set[set].layout;
assert(binding < set_layout->binding_count);
gl_shader_stage stage = state->shader->stage;
if (set_layout->binding[binding].stage[stage].sampler_index < 0) {
assert(tex_op == nir_texop_txf);
return 0;
}
assert(binding < set_layout->binding_count);
assert(set_layout->binding[binding].stage[stage].sampler_index >= 0);
uint32_t sampler_index =
state->layout->set[set].stage[stage].sampler_start +
@ -188,29 +185,30 @@ static void
lower_tex(nir_tex_instr *tex, struct apply_pipeline_layout_state *state)
{
/* No one should have come by and lowered it already */
assert(tex->sampler);
assert(tex->texture);
nir_deref_var *tex_deref = tex->texture ? tex->texture : tex->sampler;
tex->texture_index =
get_surface_index(tex_deref->var->data.descriptor_set,
tex_deref->var->data.binding, state);
lower_tex_deref(tex, tex_deref, &tex->texture_index,
get_surface_index(tex->texture->var->data.descriptor_set,
tex->texture->var->data.binding, state);
lower_tex_deref(tex, tex->texture, &tex->texture_index,
nir_tex_src_texture_offset, state);
tex->sampler_index =
get_sampler_index(tex->sampler->var->data.descriptor_set,
tex->sampler->var->data.binding, tex->op, state);
lower_tex_deref(tex, tex->sampler, &tex->sampler_index,
nir_tex_src_sampler_offset, state);
if (tex->sampler) {
tex->sampler_index =
get_sampler_index(tex->sampler->var->data.descriptor_set,
tex->sampler->var->data.binding, state);
lower_tex_deref(tex, tex->sampler, &tex->sampler_index,
nir_tex_src_sampler_offset, state);
}
/* The backend only ever uses this to mark used surfaces. We don't care
* about that little optimization so it just needs to be non-zero.
*/
tex->texture_array_size = 1;
if (tex->texture)
cleanup_tex_deref(tex, tex->texture);
cleanup_tex_deref(tex, tex->sampler);
cleanup_tex_deref(tex, tex->texture);
if (tex->sampler)
cleanup_tex_deref(tex, tex->sampler);
tex->texture = NULL;
tex->sampler = NULL;
}