assert(instr->op != nir_texop_lod || c->devinfo->ver >= 42);
unsigned texture_idx = instr->texture_index;
- unsigned sampler_idx = instr->sampler_index;
+
+ /* For instructions that don't have a sampler (i.e. txf) we bind
+ * default sampler state via the backend_flags to handle precision.
+ */
+ unsigned sampler_idx = nir_tex_instr_need_sampler(instr) ?
+ instr->sampler_index : instr->backend_flags;
/* Even if the texture operation doesn't need a sampler by
* itself, we still need to add the sampler configuration
* parameter if the output is 32 bit
*/
+ assert(sampler_idx < c->key->num_samplers_used);
bool output_type_32_bit =
c->key->sampler[sampler_idx].return_size == 32;
return glsl_count_attribute_slots(type, false);
}
+static enum nir_lower_tex_packing
+lower_tex_packing_cb(const nir_tex_instr *tex, const void *data)
+{
+ struct v3d_compile *c = (struct v3d_compile *) data;
+
+ int sampler_index = nir_tex_instr_need_sampler(tex) ?
+ tex->sampler_index : tex->backend_flags;
+
+ assert(sampler_index < c->key->num_samplers_used);
+ return c->key->sampler[sampler_index].return_size == 16 ?
+ nir_lower_tex_packing_16 : nir_lower_tex_packing_none;
+}
+
static void
v3d_lower_nir(struct v3d_compile *c)
{
tex_options.swizzles[i][j] = c->key->tex[i].swizzle[j];
}
- assert(c->key->num_samplers_used <= ARRAY_SIZE(c->key->sampler));
- for (int i = 0; i < c->key->num_samplers_used; i++) {
- if (c->key->sampler[i].return_size == 16) {
- tex_options.lower_tex_packing[i] =
- nir_lower_tex_packing_16;
- }
- }
+ tex_options.lower_tex_packing_cb = lower_tex_packing_cb;
+ tex_options.lower_tex_packing_data = c;
NIR_PASS(_, c->s, nir_lower_tex, &tex_options);
NIR_PASS(_, c->s, nir_lower_system_values);
nir_ssa_def *tex_pos,
nir_ssa_def *sample_idx)
{
- nir_tex_instr *tex = nir_tex_instr_create(b->shader, 4);
+ nir_tex_instr *tex = nir_tex_instr_create(b->shader, 3);
tex->sampler_dim = GLSL_SAMPLER_DIM_MS;
tex->op = nir_texop_txf_ms;
tex->src[0] = nir_tex_src_for_ssa(nir_tex_src_coord, tex_pos);
tex->src[1] = nir_tex_src_for_ssa(nir_tex_src_texture_deref, tex_deref);
- tex->src[2] = nir_tex_src_for_ssa(nir_tex_src_sampler_deref, tex_deref);
- tex->src[3] = nir_tex_src_for_ssa(nir_tex_src_ms_index, sample_idx);
+ tex->src[2] = nir_tex_src_for_ssa(nir_tex_src_ms_index, sample_idx);
tex->dest_type = nir_get_nir_type_for_glsl_base_type(tex_type);
tex->is_array = false;
tex->coord_components = tex_pos->num_components;
if (texture_idx < 0 && sampler_idx < 0)
return false;
- /* If we don't have a sampler, we assign it the idx we reserve for this
- * case, and we ensure that it is using the correct return size.
+ /* If the instruction doesn't have a sampler (i.e. txf) we use backend_flags
+ * to bind a default sampler state to configure precission.
*/
if (sampler_idx < 0) {
state->needs_default_sampler_state = true;
- instr->sampler_index = return_size == 16 ?
+ instr->backend_flags = return_size == 16 ?
V3DV_NO_SAMPLER_16BIT_IDX : V3DV_NO_SAMPLER_32BIT_IDX;
}