Path: blob/21.2-virgl/src/gallium/drivers/nouveau/codegen/nv50_ir_from_common.cpp
4574 views
/*1* Copyright 2011 Christoph Bumiller2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice shall be included in11* all copies or substantial portions of the Software.12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL16* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR17* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,18* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR19* OTHER DEALINGS IN THE SOFTWARE.20*/2122#include "codegen/nv50_ir_from_common.h"2324namespace nv50_ir {2526ConverterCommon::ConverterCommon(Program *prog, nv50_ir_prog_info *info,27nv50_ir_prog_info_out *info_out)28: BuildUtil(prog),29info(info),30info_out(info_out) {}3132ConverterCommon::Subroutine *33ConverterCommon::getSubroutine(unsigned ip)34{35std::map<unsigned, Subroutine>::iterator it = sub.map.find(ip);3637if (it == sub.map.end())38it = sub.map.insert(std::make_pair(39ip, Subroutine(new Function(prog, "SUB", ip)))).first;4041return &it->second;42}4344ConverterCommon::Subroutine *45ConverterCommon::getSubroutine(Function *f)46{47unsigned ip = f->getLabel();48std::map<unsigned, Subroutine>::iterator it = sub.map.find(ip);4950if (it == sub.map.end())51it = sub.map.insert(std::make_pair(ip, Subroutine(f))).first;5253return &it->second;54}5556uint8_t57ConverterCommon::translateInterpMode(const struct nv50_ir_varying *var, operation& op)58{59uint8_t mode = NV50_IR_INTERP_PERSPECTIVE;6061if (var->flat)62mode = NV50_IR_INTERP_FLAT;63else64if (var->linear)65mode = NV50_IR_INTERP_LINEAR;66else67if (var->sc)68mode = NV50_IR_INTERP_SC;6970op = (mode == NV50_IR_INTERP_PERSPECTIVE || mode == NV50_IR_INTERP_SC)71? OP_PINTERP : OP_LINTERP;7273if (var->centroid)74mode |= NV50_IR_INTERP_CENTROID;7576return mode;77}7879void80ConverterCommon::handleUserClipPlanes()81{82Value *res[8];83int n, i, c;8485for (c = 0; c < 4; ++c) {86for (i = 0; i < info_out->io.genUserClip; ++i) {87Symbol *sym = mkSymbol(FILE_MEMORY_CONST, info->io.auxCBSlot,88TYPE_F32, info->io.ucpBase + i * 16 + c * 4);89Value *ucp = mkLoadv(TYPE_F32, sym, NULL);90if (c == 0)91res[i] = mkOp2v(OP_MUL, TYPE_F32, getScratch(), clipVtx[c], ucp);92else93mkOp3(OP_MAD, TYPE_F32, res[i], clipVtx[c], ucp, res[i]);94}95}9697const int first = info_out->numOutputs - (info_out->io.genUserClip + 3) / 4;9899for (i = 0; i < info_out->io.genUserClip; ++i) {100n = i / 4 + first;101c = i % 4;102Symbol *sym =103mkSymbol(FILE_SHADER_OUTPUT, 0, TYPE_F32, info_out->out[n].slot[c] * 4);104mkStore(OP_EXPORT, TYPE_F32, sym, NULL, res[i]);105}106}107108} // namespace nv50_ir109110111