Commit 92d7ca4b authored by Qiang Yu's avatar Qiang Yu
Browse files

gallium: add lima driver



v2:
- use renamed util_dynarray_grow_cap
- use DEBUG_GET_ONCE_FLAGS_OPTION for debug flags
- remove DRM_FORMAT_MOD_ARM_AGTB_MODE0 usage
- compute min/max index in driver

v3:
- fix plbu framebuffer state calculation
- fix color_16pc assemble
- use nir_lower_all_source_mods for lowering neg/abs/sat
- use float arrary for static GPU data
- add disassemble comment for static shader code
- use drm_find_modifier

v4:
- use lima_nir_lower_uniform_to_scalar

v5:
- remove nir_opt_global_to_local when rebase

Cc: Rob Clark <robdclark@gmail.com>
Cc: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Acked-by: Emma Anholt's avatarEric Anholt <eric@anholt.net>
Signed-off-by: Andreas Baierl's avatarAndreas Baierl <ichgeh@imkreisrum.de>
Signed-off-by: Arno Messiaen's avatarArno Messiaen <arnomessiaen@gmail.com>
Signed-off-by: Connor Abbott's avatarConnor Abbott <cwabbott0@gmail.com>
Signed-off-by: Erico Nunes's avatarErico Nunes <nunes.erico@gmail.com>
Signed-off-by: Heiko Stuebner's avatarHeiko Stuebner <heiko@sntech.de>
Signed-off-by: Koen Kooi's avatarKoen Kooi <koen@dominion.thruhere.net>
Signed-off-by: Marek Vasut's avatarMarek Vasut <marex@denx.de>
Signed-off-by: marmeladema's avatarmarmeladema <xademax@gmail.com>
Signed-off-by: default avatarPaweł Chmiel <pawel.mikolaj.chmiel@gmail.com>
Signed-off-by: Rob Herring's avatarRob Herring <robh@kernel.org>
Signed-off-by: Rohan Garg's avatarRohan Garg <rohan@garg.io>
Signed-off-by: Vasily Khoruzhick's avatarVasily Khoruzhick <anarsoul@gmail.com>
Signed-off-by: Qiang Yu's avatarQiang Yu <yuq825@gmail.com>
parent 64eaf60c
......@@ -132,7 +132,7 @@ if _drivers.contains('auto')
elif ['arm', 'aarch64'].contains(host_machine.cpu_family())
_drivers = [
'kmsro', 'v3d', 'vc4', 'freedreno', 'etnaviv', 'nouveau',
'tegra', 'virgl', 'swrast'
'tegra', 'virgl', 'lima', 'swrast'
]
else
error('Unknown architecture @0@. Please pass -Dgallium-drivers to set driver options. Patches gladly accepted to fix this.'.format(
......@@ -162,6 +162,7 @@ with_gallium_i915 = _drivers.contains('i915')
with_gallium_svga = _drivers.contains('svga')
with_gallium_virgl = _drivers.contains('virgl')
with_gallium_swr = _drivers.contains('swr')
with_gallium_lima = _drivers.contains('lima')
if cc.get_id() == 'intel'
if meson.version().version_compare('< 0.49.0')
......
......@@ -60,7 +60,7 @@ option(
choices : [
'', 'auto', 'kmsro', 'radeonsi', 'r300', 'r600', 'nouveau', 'freedreno',
'swrast', 'v3d', 'vc4', 'etnaviv', 'tegra', 'i915', 'svga', 'virgl',
'swr', 'panfrost', 'iris'
'swr', 'panfrost', 'iris', 'lima'
],
description : 'List of gallium drivers to build. If this is set to auto all drivers applicable to the target OS/architecture will be built'
)
......
......@@ -141,6 +141,11 @@ static const struct drm_driver_descriptor driver_descriptors[] = {
.create_screen = pipe_tegra_create_screen,
.configuration = pipe_default_configuration_query,
},
{
.driver_name = "lima",
.create_screen = pipe_lima_create_screen,
.configuration = pipe_default_configuration_query,
},
};
static const struct drm_driver_descriptor default_driver_descriptor = {
......
......@@ -425,4 +425,27 @@ pipe_tegra_create_screen(int fd, const struct pipe_screen_config *config)
#endif
#ifdef GALLIUM_LIMA
#include "lima/drm/lima_drm_public.h"
struct pipe_screen *
pipe_lima_create_screen(int fd, const struct pipe_screen_config *config)
{
struct pipe_screen *screen;
screen = lima_drm_screen_create(fd);
return screen ? debug_screen_wrap(screen) : NULL;
}
#else
struct pipe_screen *
pipe_lima_create_screen(int fd, const struct pipe_screen_config *config)
{
fprintf(stderr, "lima: driver missing\n");
return NULL;
}
#endif
#endif /* DRM_HELPER_H */
......@@ -57,6 +57,9 @@ pipe_imx_drm_create_screen(int fd, const struct pipe_screen_config *config);
struct pipe_screen *
pipe_tegra_create_screen(int fd, const struct pipe_screen_config *config);
struct pipe_screen *
pipe_lima_create_screen(int fd, const struct pipe_screen_config *config);
const struct drm_conf_ret *
pipe_default_configuration_query(enum drm_conf conf);
......
/*
* Copyright (c) 2017 Lima Project
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sub license,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
#include "util/ralloc.h"
#include "gpir.h"
#include "codegen.h"
#include "lima_context.h"
static gpir_codegen_src gpir_get_alu_input(gpir_node *parent, gpir_node *child)
{
static const int slot_to_src[GPIR_INSTR_SLOT_NUM][3] = {
[GPIR_INSTR_SLOT_MUL0] = {
gpir_codegen_src_unused, gpir_codegen_src_p1_mul_0, gpir_codegen_src_p2_mul_0 },
[GPIR_INSTR_SLOT_MUL1] = {
gpir_codegen_src_unused, gpir_codegen_src_p1_mul_1, gpir_codegen_src_p2_mul_1 },
[GPIR_INSTR_SLOT_ADD0] = {
gpir_codegen_src_unused, gpir_codegen_src_p1_acc_0, gpir_codegen_src_p2_acc_0 },
[GPIR_INSTR_SLOT_ADD1] = {
gpir_codegen_src_unused, gpir_codegen_src_p1_acc_1, gpir_codegen_src_p2_acc_1 },
[GPIR_INSTR_SLOT_COMPLEX] = {
gpir_codegen_src_unused, gpir_codegen_src_p1_complex, gpir_codegen_src_unused },
[GPIR_INSTR_SLOT_PASS] = {
gpir_codegen_src_unused, gpir_codegen_src_p1_pass, gpir_codegen_src_p2_pass },
[GPIR_INSTR_SLOT_BRANCH] = {
gpir_codegen_src_unused, gpir_codegen_src_unused, gpir_codegen_src_unused },
[GPIR_INSTR_SLOT_REG0_LOAD0] = {
gpir_codegen_src_attrib_x, gpir_codegen_src_p1_attrib_x, gpir_codegen_src_unused },
[GPIR_INSTR_SLOT_REG0_LOAD1] = {
gpir_codegen_src_attrib_y, gpir_codegen_src_p1_attrib_y, gpir_codegen_src_unused },
[GPIR_INSTR_SLOT_REG0_LOAD2] = {
gpir_codegen_src_attrib_z, gpir_codegen_src_p1_attrib_z, gpir_codegen_src_unused },
[GPIR_INSTR_SLOT_REG0_LOAD3] = {
gpir_codegen_src_attrib_w, gpir_codegen_src_p1_attrib_w, gpir_codegen_src_unused },
[GPIR_INSTR_SLOT_REG1_LOAD0] = {
gpir_codegen_src_register_x, gpir_codegen_src_unused, gpir_codegen_src_unused},
[GPIR_INSTR_SLOT_REG1_LOAD1] = {
gpir_codegen_src_register_y, gpir_codegen_src_unused, gpir_codegen_src_unused},
[GPIR_INSTR_SLOT_REG1_LOAD2] = {
gpir_codegen_src_register_z, gpir_codegen_src_unused, gpir_codegen_src_unused},
[GPIR_INSTR_SLOT_REG1_LOAD3] = {
gpir_codegen_src_register_w, gpir_codegen_src_unused, gpir_codegen_src_unused},
[GPIR_INSTR_SLOT_MEM_LOAD0] = {
gpir_codegen_src_load_x, gpir_codegen_src_unused, gpir_codegen_src_unused },
[GPIR_INSTR_SLOT_MEM_LOAD1] = {
gpir_codegen_src_load_y, gpir_codegen_src_unused, gpir_codegen_src_unused },
[GPIR_INSTR_SLOT_MEM_LOAD2] = {
gpir_codegen_src_load_z, gpir_codegen_src_unused, gpir_codegen_src_unused },
[GPIR_INSTR_SLOT_MEM_LOAD3] = {
gpir_codegen_src_load_w, gpir_codegen_src_unused, gpir_codegen_src_unused },
};
assert(child->sched.instr - parent->sched.instr < 3);
return slot_to_src[child->sched.pos][child->sched.instr - parent->sched.instr];
}
static void gpir_codegen_mul0_slot(gpir_codegen_instr *code, gpir_instr *instr)
{
gpir_node *node = instr->slots[GPIR_INSTR_SLOT_MUL0];
if (!node) {
code->mul0_src0 = gpir_codegen_src_unused;
code->mul0_src1 = gpir_codegen_src_unused;
return;
}
gpir_alu_node *alu = gpir_node_to_alu(node);
switch (node->op) {
case gpir_op_mul:
code->mul0_src0 = gpir_get_alu_input(node, alu->children[0]);
code->mul0_src1 = gpir_get_alu_input(node, alu->children[1]);
if (code->mul0_src1 == gpir_codegen_src_p1_complex) {
/* Will get confused with gpir_codegen_src_ident, so need to swap inputs */
code->mul0_src1 = code->mul0_src0;
code->mul0_src0 = gpir_codegen_src_p1_complex;
}
code->mul0_neg = alu->dest_negate;
if (alu->children_negate[0])
code->mul0_neg = !code->mul0_neg;
if (alu->children_negate[1])
code->mul0_neg = !code->mul0_neg;
break;
case gpir_op_neg:
code->mul0_neg = true;
case gpir_op_mov:
code->mul0_src0 = gpir_get_alu_input(node, alu->children[0]);
code->mul0_src1 = gpir_codegen_src_ident;
break;
case gpir_op_complex1:
code->mul0_src0 = gpir_get_alu_input(node, alu->children[0]);
code->mul0_src1 = gpir_get_alu_input(node, alu->children[1]);
code->mul_op = gpir_codegen_mul_op_complex1;
break;
case gpir_op_complex2:
code->mul0_src0 = gpir_get_alu_input(node, alu->children[0]);
code->mul0_src1 = code->mul0_src0;
code->mul_op = gpir_codegen_mul_op_complex2;
break;
case gpir_op_select:
code->mul0_src0 = gpir_get_alu_input(node, alu->children[2]);
code->mul0_src1 = gpir_get_alu_input(node, alu->children[0]);
code->mul_op = gpir_codegen_mul_op_select;
break;
default:
assert(0);
}
}
static void gpir_codegen_mul1_slot(gpir_codegen_instr *code, gpir_instr *instr)
{
gpir_node *node = instr->slots[GPIR_INSTR_SLOT_MUL1];
if (!node) {
code->mul1_src0 = gpir_codegen_src_unused;
code->mul1_src1 = gpir_codegen_src_unused;
return;
}
gpir_alu_node *alu = gpir_node_to_alu(node);
switch (node->op) {
case gpir_op_mul:
code->mul1_src0 = gpir_get_alu_input(node, alu->children[0]);
code->mul1_src1 = gpir_get_alu_input(node, alu->children[1]);
if (code->mul1_src1 == gpir_codegen_src_p1_complex) {
/* Will get confused with gpir_codegen_src_ident, so need to swap inputs */
code->mul1_src1 = code->mul1_src0;
code->mul1_src0 = gpir_codegen_src_p1_complex;
}
code->mul1_neg = alu->dest_negate;
if (alu->children_negate[0])
code->mul1_neg = !code->mul1_neg;
if (alu->children_negate[1])
code->mul1_neg = !code->mul1_neg;
break;
case gpir_op_neg:
code->mul1_neg = true;
case gpir_op_mov:
code->mul1_src0 = gpir_get_alu_input(node, alu->children[0]);
code->mul1_src1 = gpir_codegen_src_ident;
break;
case gpir_op_complex1:
code->mul1_src0 = gpir_get_alu_input(node, alu->children[0]);
code->mul1_src1 = gpir_get_alu_input(node, alu->children[2]);
break;
case gpir_op_select:
code->mul1_src0 = gpir_get_alu_input(node, alu->children[1]);
code->mul1_src1 = gpir_codegen_src_unused;
break;
default:
assert(0);
}
}
static void gpir_codegen_add0_slot(gpir_codegen_instr *code, gpir_instr *instr)
{
gpir_node *node = instr->slots[GPIR_INSTR_SLOT_ADD0];
if (!node) {
code->acc0_src0 = gpir_codegen_src_unused;
code->acc0_src1 = gpir_codegen_src_unused;
return;
}
gpir_alu_node *alu = gpir_node_to_alu(node);
switch (node->op) {
case gpir_op_add:
case gpir_op_min:
case gpir_op_max:
case gpir_op_lt:
case gpir_op_ge:
code->acc0_src0 = gpir_get_alu_input(node, alu->children[0]);
code->acc0_src1 = gpir_get_alu_input(node, alu->children[1]);
code->acc0_src0_neg = alu->children_negate[0];
code->acc0_src1_neg = alu->children_negate[1];
switch (node->op) {
case gpir_op_add:
code->acc_op = gpir_codegen_acc_op_add;
if (code->acc0_src1 == gpir_codegen_src_p1_complex) {
code->acc0_src1 = code->acc0_src0;
code->acc0_src0 = gpir_codegen_src_p1_complex;
bool tmp = code->acc0_src0_neg;
code->acc0_src0_neg = code->acc0_src1_neg;
code->acc0_src1_neg = tmp;
}
break;
case gpir_op_min:
code->acc_op = gpir_codegen_acc_op_min;
break;
case gpir_op_max:
code->acc_op = gpir_codegen_acc_op_max;
break;
case gpir_op_lt:
code->acc_op = gpir_codegen_acc_op_lt;
break;
case gpir_op_ge:
code->acc_op = gpir_codegen_acc_op_ge;
break;
default:
assert(0);
}
break;
case gpir_op_floor:
case gpir_op_sign:
code->acc0_src0 = gpir_get_alu_input(node, alu->children[0]);
code->acc0_src0_neg = alu->children_negate[0];
switch (node->op) {
case gpir_op_floor:
code->acc_op = gpir_codegen_acc_op_floor;
break;
case gpir_op_sign:
code->acc_op = gpir_codegen_acc_op_sign;
break;
default:
assert(0);
}
break;
case gpir_op_neg:
code->acc0_src0_neg = true;
case gpir_op_mov:
code->acc_op = gpir_codegen_acc_op_add;
code->acc0_src0 = gpir_get_alu_input(node, alu->children[0]);
code->acc0_src1 = gpir_codegen_src_ident;
code->acc0_src1_neg = true;
break;
default:
assert(0);
}
}
static void gpir_codegen_add1_slot(gpir_codegen_instr *code, gpir_instr *instr)
{
gpir_node *node = instr->slots[GPIR_INSTR_SLOT_ADD1];
if (!node) {
code->acc1_src0 = gpir_codegen_src_unused;
code->acc1_src1 = gpir_codegen_src_unused;
return;
}
gpir_alu_node *alu = gpir_node_to_alu(node);
switch (node->op) {
case gpir_op_add:
case gpir_op_min:
case gpir_op_max:
case gpir_op_lt:
case gpir_op_ge:
code->acc1_src0 = gpir_get_alu_input(node, alu->children[0]);
code->acc1_src1 = gpir_get_alu_input(node, alu->children[1]);
code->acc1_src0_neg = alu->children_negate[0];
code->acc1_src1_neg = alu->children_negate[1];
switch (node->op) {
case gpir_op_add:
code->acc_op = gpir_codegen_acc_op_add;
if (code->acc1_src1 == gpir_codegen_src_p1_complex) {
code->acc1_src1 = code->acc1_src0;
code->acc1_src0 = gpir_codegen_src_p1_complex;
bool tmp = code->acc1_src0_neg;
code->acc1_src0_neg = code->acc1_src1_neg;
code->acc1_src1_neg = tmp;
}
break;
case gpir_op_min:
code->acc_op = gpir_codegen_acc_op_min;
break;
case gpir_op_max:
code->acc_op = gpir_codegen_acc_op_max;
break;
case gpir_op_lt:
code->acc_op = gpir_codegen_acc_op_lt;
break;
case gpir_op_ge:
code->acc_op = gpir_codegen_acc_op_ge;
break;
default:
assert(0);
}
break;
case gpir_op_floor:
case gpir_op_sign:
code->acc1_src0 = gpir_get_alu_input(node, alu->children[0]);
code->acc1_src0_neg = alu->children_negate[0];
switch (node->op) {
case gpir_op_floor:
code->acc_op = gpir_codegen_acc_op_floor;
break;
case gpir_op_sign:
code->acc_op = gpir_codegen_acc_op_sign;
break;
default:
assert(0);
}
break;
case gpir_op_neg:
code->acc1_src0_neg = true;
case gpir_op_mov:
code->acc_op = gpir_codegen_acc_op_add;
code->acc1_src0 = gpir_get_alu_input(node, alu->children[0]);
code->acc1_src1 = gpir_codegen_src_ident;
code->acc1_src1_neg = true;
break;
default:
assert(0);
}
}
static void gpir_codegen_complex_slot(gpir_codegen_instr *code, gpir_instr *instr)
{
gpir_node *node = instr->slots[GPIR_INSTR_SLOT_COMPLEX];
if (!node) {
code->complex_src = gpir_codegen_src_unused;
return;
}
switch (node->op) {
case gpir_op_mov:
case gpir_op_rcp_impl:
case gpir_op_rsqrt_impl:
{
gpir_alu_node *alu = gpir_node_to_alu(node);
code->complex_src = gpir_get_alu_input(node, alu->children[0]);
break;
}
default:
assert(0);
}
switch (node->op) {
case gpir_op_mov:
code->complex_op = gpir_codegen_complex_op_pass;
break;
case gpir_op_rcp_impl:
code->complex_op = gpir_codegen_complex_op_rcp;
break;
case gpir_op_rsqrt_impl:
code->complex_op = gpir_codegen_complex_op_rsqrt;
break;
default:
assert(0);
}
}
static void gpir_codegen_pass_slot(gpir_codegen_instr *code, gpir_instr *instr)
{
gpir_node *node = instr->slots[GPIR_INSTR_SLOT_PASS];
if (!node) {
code->pass_op = gpir_codegen_pass_op_pass;
code->pass_src = gpir_codegen_src_unused;
return;
}
switch (node->op) {
case gpir_op_mov:
{
gpir_alu_node *alu = gpir_node_to_alu(node);
code->pass_src = gpir_get_alu_input(node, alu->children[0]);
code->pass_op = gpir_codegen_pass_op_pass;
break;
}
default:
assert(0);
}
}
static void gpir_codegen_branch_slot(gpir_codegen_instr *code, gpir_instr *instr)
{
gpir_node *node = instr->slots[GPIR_INSTR_SLOT_BRANCH];
if (!node)
return;
assert(0);
}
static void gpir_codegen_reg0_slot(gpir_codegen_instr *code, gpir_instr *instr)
{
if (!instr->reg0_use_count)
return;
code->register0_attribute = instr->reg0_is_attr;
code->register0_addr = instr->reg0_index;
}
static void gpir_codegen_reg1_slot(gpir_codegen_instr *code, gpir_instr *instr)
{
if (!instr->reg1_use_count)
return;
code->register1_addr = instr->reg1_index;
}
static void gpir_codegen_mem_slot(gpir_codegen_instr *code, gpir_instr *instr)
{
if (!instr->mem_use_count) {
code->load_offset = gpir_codegen_load_off_none;
return;
}
code->load_addr = instr->mem_index;
code->load_offset = gpir_codegen_load_off_none;
}
static gpir_codegen_store_src gpir_get_store_input(gpir_node *node)
{
static int slot_to_src[GPIR_INSTR_SLOT_NUM] = {
[GPIR_INSTR_SLOT_MUL0] = gpir_codegen_store_src_mul_0,
[GPIR_INSTR_SLOT_MUL1] = gpir_codegen_store_src_mul_1,
[GPIR_INSTR_SLOT_ADD0] = gpir_codegen_store_src_acc_0,
[GPIR_INSTR_SLOT_ADD1] = gpir_codegen_store_src_acc_1,
[GPIR_INSTR_SLOT_COMPLEX] = gpir_codegen_store_src_complex,
[GPIR_INSTR_SLOT_PASS] = gpir_codegen_store_src_pass,
[GPIR_INSTR_SLOT_BRANCH...GPIR_INSTR_SLOT_STORE3] = gpir_codegen_store_src_none,
};
gpir_store_node *store = gpir_node_to_store(node);
return slot_to_src[store->child->sched.pos];
}
static void gpir_codegen_store_slot(gpir_codegen_instr *code, gpir_instr *instr)
{
gpir_node *node = instr->slots[GPIR_INSTR_SLOT_STORE0];
if (node)
code->store0_src_x = gpir_get_store_input(node);
else
code->store0_src_x = gpir_codegen_store_src_none;
node = instr->slots[GPIR_INSTR_SLOT_STORE1];
if (node)
code->store0_src_y = gpir_get_store_input(node);
else
code->store0_src_y = gpir_codegen_store_src_none;
node = instr->slots[GPIR_INSTR_SLOT_STORE2];
if (node)
code->store1_src_z = gpir_get_store_input(node);
else
code->store1_src_z = gpir_codegen_store_src_none;
node = instr->slots[GPIR_INSTR_SLOT_STORE3];
if (node)
code->store1_src_w = gpir_get_store_input(node);
else
code->store1_src_w = gpir_codegen_store_src_none;
if (instr->store_content[0] == GPIR_INSTR_STORE_TEMP) {
code->store0_temporary = true;
code->unknown_1 = 12;
}
else {
code->store0_varying = instr->store_content[0] == GPIR_INSTR_STORE_VARYING;
code->store0_addr = instr->store_index[0];
}
if (instr->store_content[1] == GPIR_INSTR_STORE_TEMP) {
code->store1_temporary = true;
code->unknown_1 = 12;