mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-04 20:38:06 +02:00
pan/bi: Lower swizzles
Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10065>
This commit is contained in:
parent
e3e2c5b594
commit
435800e750
5 changed files with 90 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ bifrost_FILES := \
|
|||
bifrost/bifrost_compile.h \
|
||||
bifrost/bi_layout.c \
|
||||
bifrost/bi_liveness.c \
|
||||
bifrost/bi_lower_swizzle.c \
|
||||
bifrost/bi_schedule.c \
|
||||
bifrost/bi_scoreboard.c \
|
||||
bifrost/bi_pack.c \
|
||||
|
|
|
|||
85
src/panfrost/bifrost/bi_lower_swizzle.c
Normal file
85
src/panfrost/bifrost/bi_lower_swizzle.c
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (C) 2020 Collabora Ltd.
|
||||
*
|
||||
* 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, sublicense,
|
||||
* 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 NONINFRINGEMENT. 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 "compiler.h"
|
||||
#include "bi_builder.h"
|
||||
|
||||
/* Not all 8-bit and 16-bit instructions support all swizzles on all sources.
|
||||
* These passes, intended to run after NIR->BIR but before scheduling/RA, lower
|
||||
* away swizzles that cannot be represented. In the future, we should try to
|
||||
* recombine swizzles where we can as an optimization.
|
||||
*/
|
||||
|
||||
static void
|
||||
bi_lower_swizzle_16(bi_context *ctx, bi_instr *ins, unsigned src)
|
||||
{
|
||||
/* TODO: Use the opcode table and be a lot more methodical about this... */
|
||||
switch (ins->op) {
|
||||
case BI_OPCODE_CSEL_V2F16:
|
||||
case BI_OPCODE_CSEL_V2I16:
|
||||
case BI_OPCODE_CSEL_V2S16:
|
||||
case BI_OPCODE_CSEL_V2U16:
|
||||
break;
|
||||
case BI_OPCODE_IADD_V2S16:
|
||||
case BI_OPCODE_IADD_V2U16:
|
||||
case BI_OPCODE_ISUB_V2S16:
|
||||
case BI_OPCODE_ISUB_V2U16:
|
||||
if (src == 0 && ins->src[src].swizzle != BI_SWIZZLE_H10)
|
||||
break;
|
||||
else
|
||||
return;
|
||||
case BI_OPCODE_LSHIFT_AND_V2I16:
|
||||
case BI_OPCODE_LSHIFT_OR_V2I16:
|
||||
case BI_OPCODE_LSHIFT_XOR_V2I16:
|
||||
case BI_OPCODE_RSHIFT_AND_V2I16:
|
||||
case BI_OPCODE_RSHIFT_OR_V2I16:
|
||||
case BI_OPCODE_RSHIFT_XOR_V2I16:
|
||||
if (src == 2)
|
||||
return;
|
||||
else
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
/* Identity is ok (TODO: what about replicate only?) */
|
||||
if (ins->src[src].swizzle == BI_SWIZZLE_H01)
|
||||
return;
|
||||
|
||||
/* Lower it away */
|
||||
bi_builder b = bi_init_builder(ctx, bi_before_instr(ins));
|
||||
ins->src[src] = bi_replace_index(ins->src[src],
|
||||
bi_swz_v2i16(&b, ins->src[src]));
|
||||
ins->src[src].swizzle = BI_SWIZZLE_H01;
|
||||
}
|
||||
|
||||
void
|
||||
bi_lower_swizzle(bi_context *ctx)
|
||||
{
|
||||
bi_foreach_instr_global_safe(ctx, ins) {
|
||||
bi_foreach_src(ins, s) {
|
||||
if (!bi_is_null(ins->src[s]))
|
||||
bi_lower_swizzle_16(ctx, ins, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3084,6 +3084,8 @@ bifrost_compile_shader_nir(nir_shader *nir,
|
|||
bi_lower_branch(block);
|
||||
}
|
||||
|
||||
bi_lower_swizzle(ctx);
|
||||
|
||||
if (bifrost_debug & BIFROST_DBG_SHADERS && !skip_internal)
|
||||
bi_print_shader(ctx, stdout);
|
||||
bi_schedule(ctx);
|
||||
|
|
|
|||
|
|
@ -753,6 +753,7 @@ void bi_print_shader(bi_context *ctx, FILE *fp);
|
|||
void bi_opt_copy_prop(bi_context *ctx);
|
||||
void bi_opt_dead_code_eliminate(bi_context *ctx, bool soft);
|
||||
void bi_opt_push_ubo(bi_context *ctx);
|
||||
void bi_lower_swizzle(bi_context *ctx);
|
||||
void bi_schedule(bi_context *ctx);
|
||||
void bi_assign_scoreboard(bi_context *ctx);
|
||||
void bi_register_allocate(bi_context *ctx);
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
libpanfrost_bifrost_files = files(
|
||||
'bi_layout.c',
|
||||
'bi_liveness.c',
|
||||
'bi_lower_swizzle.c',
|
||||
'bi_print.c',
|
||||
'bi_opt_copy_prop.c',
|
||||
'bi_opt_dce.c',
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue