ac/nir: use ac_build_buffer_load_format for image buffer loads
authorMarek Olšák <marek.olsak@amd.com>
Tue, 30 Jan 2018 18:40:43 +0000 (19:40 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Thu, 1 Feb 2018 15:20:19 +0000 (16:20 +0100)
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
src/amd/common/ac_nir_to_llvm.c

index 75d7b12995746c3161a5fdc459c857370b0c8112..05b937803f0946c9277514eb775723fef4c46fb7 100644 (file)
@@ -3611,14 +3611,19 @@ static LLVMValueRef visit_image_load(struct ac_nir_context *ctx,
 
        const enum glsl_sampler_dim dim = glsl_get_sampler_dim(type);
        if (dim == GLSL_SAMPLER_DIM_BUF) {
-               params[0] = get_sampler_desc(ctx, instr->variables[0], AC_DESC_BUFFER, NULL, true, false);
-               params[1] = LLVMBuildExtractElement(ctx->ac.builder, get_src(ctx, instr->src[0]),
-                                                   ctx->ac.i32_0, ""); /* vindex */
-               params[2] = ctx->ac.i32_0; /* voffset */
-               params[3] = ctx->ac.i1false;  /* glc */
-               params[4] = ctx->ac.i1false;  /* slc */
-               res = ac_build_intrinsic(&ctx->ac, "llvm.amdgcn.buffer.load.format.v4f32", ctx->ac.v4f32,
-                                        params, 5, 0);
+               unsigned mask = nir_ssa_def_components_read(&instr->dest.ssa);
+               unsigned num_channels = util_last_bit(mask);
+               LLVMValueRef rsrc, vindex;
+
+               rsrc = get_sampler_desc(ctx, instr->variables[0], AC_DESC_BUFFER, NULL, true, false);
+               vindex = LLVMBuildExtractElement(ctx->ac.builder, get_src(ctx, instr->src[0]),
+                                                ctx->ac.i32_0, "");
+
+               /* TODO: set "glc" and "can_speculate" when OpenGL needs it. */
+               res = ac_build_buffer_load_format(&ctx->ac, rsrc, vindex,
+                                                 ctx->ac.i32_0, num_channels,
+                                                 false, false);
+               res = ac_build_expand_to_vec4(&ctx->ac, res, num_channels);
 
                res = trim_vector(&ctx->ac, res, instr->dest.ssa.num_components);
                res = ac_to_integer(&ctx->ac, res);