mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-05 04:40:11 +01:00
r600/sfn: Clean up some ALU lowering and move code
Signed-off-by: Gert Wollny <gert.wollny@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11348>
This commit is contained in:
parent
82c076d2c3
commit
8aaa08844f
8 changed files with 121 additions and 113 deletions
|
|
@ -49,15 +49,6 @@ $(intermediates)/egd_tables.h: $(MESA_TOP)/src/gallium/drivers/r600/egd_tables.p
|
|||
@echo "Gen Header: $(PRIVATE_MODULE) <= $(notdir $(@))"
|
||||
$(hide) $(MESA_PYTHON2) $(MESA_TOP)/src/gallium/drivers/r600/egd_tables.py $(MESA_TOP)/src/gallium/drivers/r600/evergreend.h > $@
|
||||
|
||||
sfn_nir_algebraic_gen := $(LOCAL_PATH)/sfn/sfn_nir_algebraic.py
|
||||
sfn_nir_algebraic_deps := \
|
||||
$(LOCAL_PATH)/sfn/sfn_nir_algebraic.py \
|
||||
$(MESA_TOP)/src/compiler/nir/nir_algebraic.py
|
||||
|
||||
$(intermediates)/sfn_nir_algebraic.c: $(sfn_nir_algebraic_deps)
|
||||
@mkdir -p $(dir $@)
|
||||
$(hide) $(MESA_PYTHON2) $(sfn_nir_algebraic_gen) -p $(MESA_TOP)/src/compiler/nir/ > $@
|
||||
|
||||
ifeq ($(MESA_ENABLE_LLVM),true)
|
||||
$(call mesa-build-with-llvm)
|
||||
endif
|
||||
|
|
|
|||
|
|
@ -133,6 +133,8 @@ CXX_SOURCES = \
|
|||
sfn/sfn_nir.cpp \
|
||||
sfn/sfn_nir.h \
|
||||
sfn/sfn_nir_legalize_image_load_store.cpp \
|
||||
sfn/sfn_nir_lower_alu.cpp \
|
||||
sfn/sfn_nir_lower_alu.h \
|
||||
sfn/sfn_nir_lower_64bit.cpp \
|
||||
sfn/sfn_nir_lower_fs_out_to_vector.cpp \
|
||||
sfn/sfn_nir_lower_fs_out_to_vector.h \
|
||||
|
|
|
|||
|
|
@ -151,6 +151,8 @@ files_r600 = files(
|
|||
'sfn/sfn_nir.h',
|
||||
'sfn/sfn_nir_legalize_image_load_store.cpp',
|
||||
'sfn/sfn_nir_lower_64bit.cpp',
|
||||
'sfn/sfn_nir_lower_alu.cpp',
|
||||
'sfn/sfn_nir_lower_alu.h',
|
||||
'sfn/sfn_nir_lower_fs_out_to_vector.cpp',
|
||||
'sfn/sfn_nir_lower_fs_out_to_vector.h',
|
||||
'sfn/sfn_nir_lower_tess_io.cpp',
|
||||
|
|
@ -189,19 +191,6 @@ egd_tables_h = custom_target(
|
|||
capture : true,
|
||||
)
|
||||
|
||||
sfn_nir_algebraic_c = custom_target(
|
||||
'sfn_nir_algebraic.c',
|
||||
input : 'sfn/sfn_nir_algebraic.py',
|
||||
output : 'sfn_nir_algebraic.c',
|
||||
command : [
|
||||
prog_python, '@INPUT@',
|
||||
'-p', join_paths(meson.source_root(), 'src/compiler/nir/'),
|
||||
],
|
||||
capture : true,
|
||||
depend_files : nir_algebraic_py,
|
||||
)
|
||||
|
||||
|
||||
r600_c_args = []
|
||||
if with_gallium_opencl
|
||||
r600_c_args += '-DHAVE_OPENCL'
|
||||
|
|
@ -209,7 +198,7 @@ endif
|
|||
|
||||
libr600 = static_library(
|
||||
'r600',
|
||||
[files_r600, egd_tables_h, sfn_nir_algebraic_c],
|
||||
[files_r600, egd_tables_h],
|
||||
c_args : [r600_c_args, '-Wstrict-overflow=0'],
|
||||
gnu_symbol_visibility : 'hidden',
|
||||
include_directories : [
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@
|
|||
#include "sfn_shader_tess_eval.h"
|
||||
#include "sfn_nir_lower_fs_out_to_vector.h"
|
||||
#include "sfn_ir_to_assembly.h"
|
||||
#include "sfn_nir_lower_alu.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -337,41 +338,6 @@ bool AssemblyFromShader::lower(const std::vector<InstructionBlock>& ir)
|
|||
return do_lower(ir);
|
||||
}
|
||||
|
||||
static nir_ssa_def *
|
||||
r600_nir_lower_pack_unpack_2x16_impl(nir_builder *b, nir_instr *instr, void *_options)
|
||||
{
|
||||
nir_alu_instr *alu = nir_instr_as_alu(instr);
|
||||
|
||||
switch (alu->op) {
|
||||
case nir_op_unpack_half_2x16: {
|
||||
nir_ssa_def *packed = nir_ssa_for_alu_src(b, alu, 0);
|
||||
return nir_vec2(b, nir_unpack_half_2x16_split_x(b, packed),
|
||||
nir_unpack_half_2x16_split_y(b, packed));
|
||||
|
||||
}
|
||||
case nir_op_pack_half_2x16: {
|
||||
nir_ssa_def *src_vec2 = nir_ssa_for_alu_src(b, alu, 0);
|
||||
return nir_pack_half_2x16_split(b, nir_channel(b, src_vec2, 0),
|
||||
nir_channel(b, src_vec2, 1));
|
||||
}
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool r600_nir_lower_pack_unpack_2x16_filter(const nir_instr *instr, const void *_options)
|
||||
{
|
||||
return instr->type == nir_instr_type_alu;
|
||||
}
|
||||
|
||||
bool r600_nir_lower_pack_unpack_2x16(nir_shader *shader)
|
||||
{
|
||||
return nir_shader_lower_instructions(shader,
|
||||
r600_nir_lower_pack_unpack_2x16_filter,
|
||||
r600_nir_lower_pack_unpack_2x16_impl,
|
||||
nullptr);
|
||||
};
|
||||
|
||||
static void
|
||||
r600_nir_lower_scratch_address_impl(nir_builder *b, nir_intrinsic_instr *instr)
|
||||
{
|
||||
|
|
@ -610,7 +576,6 @@ r600_nir_lower_atomics(nir_shader *shader)
|
|||
return progress;
|
||||
}
|
||||
using r600::r600_nir_lower_int_tg4;
|
||||
using r600::r600_nir_lower_pack_unpack_2x16;
|
||||
using r600::r600_lower_scratch_addresses;
|
||||
using r600::r600_lower_fs_out_to_vector;
|
||||
using r600::r600_lower_ubo_to_align16;
|
||||
|
|
@ -876,7 +841,7 @@ int r600_shader_from_nir(struct r600_context *rctx,
|
|||
idiv_options.allow_fp16 = true;
|
||||
|
||||
NIR_PASS_V(sel->nir, nir_lower_idiv, &idiv_options);
|
||||
NIR_PASS_V(sel->nir, r600_lower_alu);
|
||||
NIR_PASS_V(sel->nir, r600_nir_lower_trigen);
|
||||
NIR_PASS_V(sel->nir, nir_lower_phis_to_scalar, false);
|
||||
|
||||
if (lower_64bit)
|
||||
|
|
|
|||
|
|
@ -54,8 +54,6 @@ protected:
|
|||
nir_builder *b;
|
||||
};
|
||||
|
||||
bool r600_nir_lower_pack_unpack_2x16(nir_shader *shader);
|
||||
|
||||
bool r600_lower_scratch_addresses(nir_shader *shader);
|
||||
|
||||
bool r600_lower_ubo_to_align16(nir_shader *shader);
|
||||
|
|
@ -156,8 +154,6 @@ int r600_shader_from_nir(struct r600_context *rctx,
|
|||
struct r600_pipe_shader *pipeshader,
|
||||
union r600_shader_key *key);
|
||||
|
||||
bool r600_lower_alu(nir_shader *sh);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,49 +0,0 @@
|
|||
#
|
||||
# Copyright (C) 2021 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.
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
lower_alu = [
|
||||
# For chipfamily r600 one must do fma (2*pi ffract() - 0.5)
|
||||
(('fsin', "a@32"), ('fsin_r600', ('fadd', ('ffract', ('ffma', 'a', 0.15915494, 0.5)), -0.5))),
|
||||
(('fcos', "a@32"), ('fcos_r600', ('fadd', ('ffract', ('ffma', 'a', 0.15915494, 0.5)), -0.5))),
|
||||
]
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-p', '--import-path', required=True)
|
||||
args = parser.parse_args()
|
||||
sys.path.insert(0, args.import_path)
|
||||
run()
|
||||
|
||||
|
||||
def run():
|
||||
import nir_algebraic # pylint: disable=import-error
|
||||
|
||||
print('#include "sfn/sfn_nir.h"')
|
||||
|
||||
print(nir_algebraic.AlgebraicPass("r600_lower_alu",
|
||||
lower_alu).render())
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
103
src/gallium/drivers/r600/sfn/sfn_nir_lower_alu.cpp
Normal file
103
src/gallium/drivers/r600/sfn/sfn_nir_lower_alu.cpp
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
#include "sfn_nir_lower_alu.h"
|
||||
#include "sfn_nir.h"
|
||||
|
||||
namespace r600 {
|
||||
|
||||
class Lower2x16 : public NirLowerInstruction {
|
||||
private:
|
||||
bool filter(const nir_instr *instr) const override;
|
||||
nir_ssa_def *lower(nir_instr *instr) override;
|
||||
};
|
||||
|
||||
|
||||
bool Lower2x16::filter(const nir_instr *instr) const
|
||||
{
|
||||
if (instr->type != nir_instr_type_alu)
|
||||
return false;
|
||||
auto alu = nir_instr_as_alu(instr);
|
||||
switch (alu->op) {
|
||||
case nir_op_unpack_half_2x16:
|
||||
case nir_op_pack_half_2x16:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
nir_ssa_def *Lower2x16::lower(nir_instr *instr)
|
||||
{
|
||||
nir_alu_instr *alu = nir_instr_as_alu(instr);
|
||||
|
||||
switch (alu->op) {
|
||||
case nir_op_unpack_half_2x16: {
|
||||
nir_ssa_def *packed = nir_ssa_for_alu_src(b, alu, 0);
|
||||
return nir_vec2(b, nir_unpack_half_2x16_split_x(b, packed),
|
||||
nir_unpack_half_2x16_split_y(b, packed));
|
||||
|
||||
}
|
||||
case nir_op_pack_half_2x16: {
|
||||
nir_ssa_def *src_vec2 = nir_ssa_for_alu_src(b, alu, 0);
|
||||
return nir_pack_half_2x16_split(b, nir_channel(b, src_vec2, 0),
|
||||
nir_channel(b, src_vec2, 1));
|
||||
}
|
||||
default:
|
||||
unreachable("Lower2x16 filter doesn't filter correctly");
|
||||
}
|
||||
}
|
||||
|
||||
class LowerSinCos : public NirLowerInstruction {
|
||||
private:
|
||||
bool filter(const nir_instr *instr) const override;
|
||||
nir_ssa_def *lower(nir_instr *instr) override;
|
||||
};
|
||||
|
||||
bool LowerSinCos::filter(const nir_instr *instr) const
|
||||
{
|
||||
if (instr->type != nir_instr_type_alu)
|
||||
return false;
|
||||
|
||||
auto alu = nir_instr_as_alu(instr);
|
||||
switch (alu->op) {
|
||||
case nir_op_fsin:
|
||||
case nir_op_fcos:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
nir_ssa_def *LowerSinCos::lower(nir_instr *instr)
|
||||
{
|
||||
auto alu = nir_instr_as_alu(instr);
|
||||
|
||||
assert(alu->op == nir_op_fsin ||
|
||||
alu->op == nir_op_fcos);
|
||||
|
||||
auto normalized =
|
||||
nir_fadd(b,
|
||||
nir_ffract(b,
|
||||
nir_ffma(b,
|
||||
nir_ssa_for_alu_src(b, alu, 0),
|
||||
nir_imm_float(b, 0.15915494),
|
||||
nir_imm_float(b, 0.5))),
|
||||
nir_imm_float(b, -0.5));
|
||||
|
||||
if (alu->op == nir_op_fsin)
|
||||
return nir_fsin_r600(b, normalized);
|
||||
else
|
||||
return nir_fcos_r600(b, normalized);
|
||||
}
|
||||
|
||||
|
||||
} // namespace r600
|
||||
|
||||
|
||||
bool r600_nir_lower_pack_unpack_2x16(nir_shader *shader)
|
||||
{
|
||||
return r600::Lower2x16().run(shader);
|
||||
}
|
||||
|
||||
bool r600_nir_lower_trigen(nir_shader *shader)
|
||||
{
|
||||
return r600::LowerSinCos().run(shader);
|
||||
}
|
||||
11
src/gallium/drivers/r600/sfn/sfn_nir_lower_alu.h
Normal file
11
src/gallium/drivers/r600/sfn/sfn_nir_lower_alu.h
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef SFN_NIR_LOWER_ALU_H
|
||||
#define SFN_NIR_LOWER_ALU_H
|
||||
|
||||
#include "nir.h"
|
||||
|
||||
bool r600_nir_lower_pack_unpack_2x16(nir_shader *shader);
|
||||
|
||||
bool r600_nir_lower_trigen(nir_shader *shader);
|
||||
|
||||
|
||||
#endif // SFN_NIR_LOWER_ALU_H
|
||||
Loading…
Add table
Reference in a new issue