Signed-off-by: Karol Herbst <kher...@redhat.com> --- .../drivers/nouveau/codegen/nv50_ir_from_nir.cpp | 108 +++++++++++++++++++++ 1 file changed, 108 insertions(+)
diff --git a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp index 4833da5914..6516bd2d8f 100644 --- a/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp +++ b/src/gallium/drivers/nouveau/codegen/nv50_ir_from_nir.cpp @@ -28,6 +28,9 @@ #include "codegen/nv50_ir_from_common.h" #include "codegen/nv50_ir_util.h" +#include <unordered_map> +#include <vector> + static int type_size(const struct glsl_type *type) { @@ -41,17 +44,122 @@ using namespace nv50_ir; class Converter : public ConverterCommon { public: + typedef std::vector<LValue*> LValues; + typedef decltype(nir_ssa_def().index) NirSSADefIdx; + typedef std::unordered_map<NirSSADefIdx, LValues> NirDefMap; + Converter(Program *, nir_shader *, nv50_ir_prog_info *); + LValues& convert(nir_alu_dest *); + LValues& convert(nir_dest *); + LValues& convert(nir_register *); + LValues& convert(nir_ssa_def *); + + // nir_alu_src needs special handling due to neg and abs modifiers + Value* getSrc(nir_alu_src *, uint8_t component = 0); + Value* getSrc(nir_register *, uint8_t); + Value* getSrc(nir_src *, uint8_t); + Value* getSrc(nir_ssa_def *, uint8_t); + bool run(); private: nir_shader *nir; + + NirDefMap ssaDefs; + NirDefMap regDefs; }; Converter::Converter(Program *prog, nir_shader *nir, nv50_ir_prog_info *info) : ConverterCommon(prog, info), nir(nir) {} +Converter::LValues& +Converter::convert(nir_dest *dest) +{ + if (dest->is_ssa) + return convert(&dest->ssa); + if (dest->reg.indirect) { + ERROR("no support for indirects."); + assert(false); + } + return convert(dest->reg.reg); +} + +Converter::LValues& +Converter::convert(nir_register *reg) +{ + NirDefMap::iterator it = regDefs.find(reg->index); + if (it != regDefs.end()) + return (*it).second; + + LValues newDef(reg->num_components); + for (auto i = 0u; i < reg->num_components; i++) + newDef[i] = getScratch(reg->bit_size / 8); + return regDefs[reg->index] = newDef; +} + +Converter::LValues& +Converter::convert(nir_ssa_def *def) +{ + NirDefMap::iterator it = ssaDefs.find(def->index); + if (it != ssaDefs.end()) + return (*it).second; + + LValues newDef(def->num_components); + for (auto i = 0; i < def->num_components; i++) + newDef[i] = getScratch(def->bit_size / 8); + return ssaDefs[def->index] = newDef; +} + +Value* +Converter::getSrc(nir_alu_src *src, uint8_t component) +{ + if (src->abs || src->negate) { + ERROR("modifiers currently not supported on nir_alu_src\n"); + assert(false); + } + return getSrc(&src->src, src->swizzle[component]); +} + +Value* +Converter::getSrc(nir_register *reg, uint8_t idx) +{ + NirDefMap::iterator it = regDefs.find(reg->index); + if (it == regDefs.end()) { + ERROR("Register %u not found\n", reg->index); + assert(false); + return nullptr; + } + return (*it).second[idx]; +} + +Value* +Converter::getSrc(nir_src *src, uint8_t idx) +{ + if (src->is_ssa) + return getSrc(src->ssa, idx); + + if (src->reg.indirect) { + ERROR("no support for indirects."); + assert(false); + return nullptr; + } + + return getSrc(src->reg.reg, idx); +} + +Value* +Converter::getSrc(nir_ssa_def *src, uint8_t idx) +{ + NirDefMap::iterator it = ssaDefs.find(src->index); + if (it == ssaDefs.end()) { + ERROR("SSA value %u not found\n", src->index); + assert(false); + return nullptr; + } + return (*it).second[idx]; +} + bool Converter::run() { -- 2.14.3 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev