nir,ac/nir: fix cube_face_coord
[mesa.git] / src / amd / common / ac_nir_to_llvm.c
index 61b33c74e6c4f1921379b41ef5849a5096b3e055..421b7f478b531c8b071d031b4a49feb574e5977f 100644 (file)
@@ -1032,10 +1032,17 @@ static void visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr)
                LLVMValueRef in[3];
                for (unsigned chan = 0; chan < 3; chan++)
                        in[chan] = ac_llvm_extract_elem(&ctx->ac, src[0], chan);
-               results[0] = ac_build_intrinsic(&ctx->ac, "llvm.amdgcn.cubetc",
+               results[0] = ac_build_intrinsic(&ctx->ac, "llvm.amdgcn.cubesc",
                                                ctx->ac.f32, in, 3, AC_FUNC_ATTR_READNONE);
-               results[1] = ac_build_intrinsic(&ctx->ac, "llvm.amdgcn.cubesc",
+               results[1] = ac_build_intrinsic(&ctx->ac, "llvm.amdgcn.cubetc",
                                                ctx->ac.f32, in, 3, AC_FUNC_ATTR_READNONE);
+               LLVMValueRef ma = ac_build_intrinsic(&ctx->ac, "llvm.amdgcn.cubema",
+                                                    ctx->ac.f32, in, 3, AC_FUNC_ATTR_READNONE);
+               results[0] = ac_build_fdiv(&ctx->ac, results[0], ma);
+               results[1] = ac_build_fdiv(&ctx->ac, results[1], ma);
+               LLVMValueRef offset = LLVMConstReal(ctx->ac.f32, 0.5);
+               results[0] = LLVMBuildFAdd(ctx->ac.builder, results[0], offset, "");
+               results[1] = LLVMBuildFAdd(ctx->ac.builder, results[1], offset, "");
                result = ac_build_gather_values(&ctx->ac, results, 2);
                break;
        }