From: Jason Ekstrand Date: Tue, 9 Feb 2016 20:13:32 +0000 (-0800) Subject: anv: Fix up spirv for new texture/sampler split stuff X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=09b3e30dc672d38e60aac1d279eb1db94c9b048e;p=mesa.git anv: Fix up spirv for new texture/sampler split stuff --- diff --git a/src/compiler/nir/spirv/spirv_to_nir.c b/src/compiler/nir/spirv/spirv_to_nir.c index a7efa196832..979357d67c8 100644 --- a/src/compiler/nir/spirv/spirv_to_nir.c +++ b/src/compiler/nir/spirv/spirv_to_nir.c @@ -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, diff --git a/src/vulkan/anv_meta.c b/src/vulkan/anv_meta.c index 2867e471a32..46227c3407e 100644 --- a/src/vulkan/anv_meta.c +++ b/src/vulkan/anv_meta.c @@ -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"); diff --git a/src/vulkan/anv_meta_resolve.c b/src/vulkan/anv_meta_resolve.c index f1c985e04cf..5aa2fef76bd 100644 --- a/src/vulkan/anv_meta_resolve.c +++ b/src/vulkan/anv_meta_resolve.c @@ -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; diff --git a/src/vulkan/anv_nir_apply_pipeline_layout.c b/src/vulkan/anv_nir_apply_pipeline_layout.c index 61dcf1d4c1b..ee93e40e76c 100644 --- a/src/vulkan/anv_nir_apply_pipeline_layout.c +++ b/src/vulkan/anv_nir_apply_pipeline_layout.c @@ -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; }