radv: use nir constant helpers
authorKarol Herbst <kherbst@redhat.com>
Thu, 28 Mar 2019 15:53:47 +0000 (16:53 +0100)
committerKarol Herbst <kherbst@redhat.com>
Sun, 14 Apr 2019 20:25:56 +0000 (22:25 +0200)
Signed-off-by: Karol Herbst <kherbst@redhat.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/amd/vulkan/radv_meta_resolve_cs.c
src/amd/vulkan/radv_shader_info.c

index e56df7f8a59e248501d272520bd63732ecb315df..1b786526cf25972318ee7a0090b11aad98171d79 100644 (file)
 static nir_ssa_def *radv_meta_build_resolve_srgb_conversion(nir_builder *b,
                                                            nir_ssa_def *input)
 {
-       nir_const_value v;
        unsigned i;
-       v.u32[0] = 0x3b4d2e1c; // 0.00313080009
 
        nir_ssa_def *cmp[3];
        for (i = 0; i < 3; i++)
                cmp[i] = nir_flt(b, nir_channel(b, input, i),
-                                nir_build_imm(b, 1, 32, v));
+                                nir_imm_int(b, 0x3b4d2e1c));
 
        nir_ssa_def *ltvals[3];
-       v.f32[0] = 12.92;
        for (i = 0; i < 3; i++)
                ltvals[i] = nir_fmul(b, nir_channel(b, input, i),
-                                    nir_build_imm(b, 1, 32, v));
+                                    nir_imm_float(b, 12.92));
 
        nir_ssa_def *gtvals[3];
 
        for (i = 0; i < 3; i++) {
-               v.f32[0] = 1.0/2.4;
                gtvals[i] = nir_fpow(b, nir_channel(b, input, i),
-                                    nir_build_imm(b, 1, 32, v));
-               v.f32[0] = 1.055;
+                                    nir_imm_float(b, 1.0/2.4));
                gtvals[i] = nir_fmul(b, gtvals[i],
-                                    nir_build_imm(b, 1, 32, v));
-               v.f32[0] = 0.055;
+                                    nir_imm_float(b, 1.055));
                gtvals[i] = nir_fsub(b, gtvals[i],
-                                    nir_build_imm(b, 1, 32, v));
+                                    nir_imm_float(b, 0.055));
        }
 
        nir_ssa_def *comp[4];
index 002475953d96d39766efe7843c56f3272514fe40..932a18522666da5a6afbab613ce61879dcd5f45b 100644 (file)
@@ -59,9 +59,7 @@ get_deref_offset(nir_deref_instr *instr,
 
        if (var->data.compact) {
                assert(instr->deref_type == nir_deref_type_array);
-               nir_const_value *v = nir_src_as_const_value(instr->arr.index);
-               assert(v);
-               *const_out = v->u32[0];
+               *const_out = nir_src_as_uint(instr->arr.index);
                return;
        }
 
@@ -80,9 +78,8 @@ get_deref_offset(nir_deref_instr *instr,
                        }
                } else if(path.path[idx_lvl]->deref_type == nir_deref_type_array) {
                        unsigned size = glsl_count_attribute_slots(path.path[idx_lvl]->type, false);
-                       nir_const_value *v = nir_src_as_const_value(path.path[idx_lvl]->arr.index);
-                       if (v)
-                               const_offset += v->u32[0] * size;
+                       if (nir_src_is_const(path.path[idx_lvl]->arr.index))
+                               const_offset += nir_src_as_uint(path.path[idx_lvl]->arr.index) * size;
                } else
                        unreachable("Uhandled deref type in get_deref_instr_offset");
        }
@@ -189,13 +186,12 @@ gather_push_constant_info(const nir_shader *nir,
                          const nir_intrinsic_instr *instr,
                          struct radv_shader_info *info)
 {
-       nir_const_value *cval = nir_src_as_const_value(instr->src[0]);
        int base = nir_intrinsic_base(instr);
 
-       if (!cval) {
+       if (!nir_src_is_const(instr->src[0])) {
                info->has_indirect_push_constants = true;
        } else {
-               uint32_t min = base + cval->u32[0];
+               uint32_t min = base + nir_src_as_uint(instr->src[0]);
                uint32_t max = min + instr->num_components * 4;
 
                info->max_push_constant_used =