From patchwork Tue Jan 31 08:23:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wladimir J. van der Laan" X-Patchwork-Id: 9546709 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7219F604A0 for ; Tue, 31 Jan 2017 08:23:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 63EFE280DE for ; Tue, 31 Jan 2017 08:23:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 58889281A7; Tue, 31 Jan 2017 08:23:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B8AFE28210 for ; Tue, 31 Jan 2017 08:23:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A1BE26E5E6; Tue, 31 Jan 2017 08:23:56 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 796D26E5E6; Tue, 31 Jan 2017 08:23:55 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id v77so21238779wmv.0; Tue, 31 Jan 2017 00:23:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mime-version:content-disposition; bh=cy9MBdPtuaCTg7HRmx2Xxw1D6n3RMCJqLo3IsHSj+4M=; b=Jjp1mAmM8XqX4eg2Mv3vO/7atQ7co15bkHU8ah1ISyFUXnMVClW/tzUnoSn7y2wXXv 2MMkcok1rMReSHRHbC9KK4pXgkmyxY/xtBt0gEUABPRFNce00AAB3jhxLybSb5rMBif5 MNPt6CAYcqv1rRkR0SBWpRz3N+gscUHoFnfNvqyECMb8dxjvcYb2R1afz/ATG5EjY6Om QEIExDwLniMEUnfo/uf5q6CT4gTpt4lzMC1sNh/Z6YZC4qt6qnzWajFFv/sBeggG44Bp +U4pdCrZqcJJ+4gY2NY5R/cJddF0cQiQLxod0t5oa2qcadSxQIH1qKrsFv5socm5q8T4 C/uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition; bh=cy9MBdPtuaCTg7HRmx2Xxw1D6n3RMCJqLo3IsHSj+4M=; b=Dn89JXsjpmFvSukb/1DCTjdCoU7hZcfdVGL2LPDIi6H0TE+hXNK9LEIbyYvtb6MnVF 6cMBer1rW8klrfuaPh3L8JpKproXV7L6jYrFxRqVbXYBoGMoVxcFwc4Eae1YI9d1vSJH kDfUGOhlaGBOs8GC2n12csKP8apZJ7GJNYZvziTIJeSaZG4aqyVoOEd442w2dKEnFoKE NmuVgYikBMa139KJLN6x88nn5ZCrZ5YkwaezovDOIjb/1h75d62fAyGiqlHw76B0sH+d LF35Gqm2ogVXVI5fArhAvPT2e6ZDWi93xp1fRWuFfbRtdx8TDRLP9abZM0QOq7swLZ9n ya7w== X-Gm-Message-State: AIkVDXLO/eZyrusW9G5CJvte1JNhe7/m5r7aRjuXYUIReN7vuxH9qT/Gh2iesqox7TtH8g== X-Received: by 10.223.142.111 with SMTP id n102mr21512930wrb.11.1485851034055; Tue, 31 Jan 2017 00:23:54 -0800 (PST) Received: from amethyst.visucore.com (d222031.upc-d.chello.nl. [213.46.222.31]) by smtp.gmail.com with ESMTPSA id c202sm22374689wmd.10.2017.01.31.00.23.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Jan 2017 00:23:53 -0800 (PST) Date: Tue, 31 Jan 2017 09:23:51 +0100 From: "Wladimir J. van der Laan" To: dri-devel@lists.freedesktop.org, etnaviv@lists.freedesktop.org, Christian Gmeiner , Chris Healy Subject: [PATCH v2] etnaviv: Generate new sin/cos instructions on GC3000 Message-ID: <20170131082351.GA27316@amethyst.visucore.com> MIME-Version: 1.0 Content-Disposition: inline X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Shaders using sin/cos instructions were not working on GC3000. The reason for this turns out to be that these chips implement sin/cos in a different way (but using the same opcodes): - Need their input scaled by 1/pi instead of 2/pi. - Output an x and y component, which need to be multiplied to get the result. - tex_amode needs to be set to 1. Add a new bit to the compiler specs and generate these instructions as necessary. Signed-Off-By: Wladimir J. van der Laan Acked-by: Christian Gmeiner --- src/gallium/drivers/etnaviv/etnaviv_compiler.c | 37 +++++++++++++++++++++++++- src/gallium/drivers/etnaviv/etnaviv_internal.h | 2 ++ src/gallium/drivers/etnaviv/etnaviv_screen.c | 2 ++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/gallium/drivers/etnaviv/etnaviv_compiler.c b/src/gallium/drivers/etnaviv/etnaviv_compiler.c index 59e1452..c4519e7 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_compiler.c +++ b/src/gallium/drivers/etnaviv/etnaviv_compiler.c @@ -1444,7 +1444,42 @@ static void trans_trig(const struct instr_translater *t, struct etna_compile *c, const struct tgsi_full_instruction *inst, struct etna_inst_src *src) { - if (c->specs->has_sin_cos_sqrt) { + if (c->specs->has_new_sin_cos) { /* Alternative SIN/COS */ + /* On newer chips alternative SIN/COS instructions are implemented, + * which: + * - Need their input scaled by 1/pi instead of 2/pi + * - Output an x and y component, which need to be multiplied to + * get the result + */ + /* TGSI lowering should deal with SCS */ + assert(inst->Instruction.Opcode != TGSI_OPCODE_SCS); + + struct etna_native_reg temp = etna_compile_get_inner_temp(c); /* only using .xyz */ + emit_inst(c, &(struct etna_inst) { + .opcode = INST_OPCODE_MUL, + .sat = 0, + .dst = etna_native_to_dst(temp, INST_COMPS_Z), + .src[0] = src[0], /* any swizzling happens here */ + .src[1] = alloc_imm_f32(c, 1.0f / M_PI), + }); + emit_inst(c, &(struct etna_inst) { + .opcode = inst->Instruction.Opcode == TGSI_OPCODE_COS + ? INST_OPCODE_COS + : INST_OPCODE_SIN, + .sat = 0, + .dst = etna_native_to_dst(temp, INST_COMPS_X | INST_COMPS_Y), + .src[2] = etna_native_to_src(temp, SWIZZLE(Z, Z, Z, Z)), + .tex = { .amode=1 }, /* Unknown bit needs to be set */ + }); + emit_inst(c, &(struct etna_inst) { + .opcode = INST_OPCODE_MUL, + .sat = inst->Instruction.Saturate, + .dst = convert_dst(c, &inst->Dst[0]), + .src[0] = etna_native_to_src(temp, SWIZZLE(X, X, X, X)), + .src[1] = etna_native_to_src(temp, SWIZZLE(Y, Y, Y, Y)), + }); + + } else if (c->specs->has_sin_cos_sqrt) { /* TGSI lowering should deal with SCS */ assert(inst->Instruction.Opcode != TGSI_OPCODE_SCS); diff --git a/src/gallium/drivers/etnaviv/etnaviv_internal.h b/src/gallium/drivers/etnaviv/etnaviv_internal.h index f340116..2f09d55 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_internal.h +++ b/src/gallium/drivers/etnaviv/etnaviv_internal.h @@ -70,6 +70,8 @@ struct etna_specs { unsigned has_sign_floor_ceil : 1; /* can use VS_RANGE, PS_RANGE registers*/ unsigned has_shader_range_registers : 1; + /* has the new sin/cos functions */ + unsigned has_new_sin_cos : 1; /* can use any kind of wrapping mode on npot textures */ unsigned npot_tex_any_wrap; /* number of bits per TS tile */ diff --git a/src/gallium/drivers/etnaviv/etnaviv_screen.c b/src/gallium/drivers/etnaviv/etnaviv_screen.c index 53a31c5..0af7078 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_screen.c +++ b/src/gallium/drivers/etnaviv/etnaviv_screen.c @@ -620,6 +620,8 @@ etna_get_specs(struct etna_screen *screen) screen->model >= 0x1000 || screen->model == 0x880; screen->specs.npot_tex_any_wrap = VIV_FEATURE(screen, chipMinorFeatures1, NON_POWER_OF_TWO); + screen->specs.has_new_sin_cos = + VIV_FEATURE(screen, chipMinorFeatures3, HAS_FAST_TRANSCENDENTALS); if (instruction_count > 256) { /* unified instruction memory? */ screen->specs.vs_offset = 0xC000;