Path: blob/21.2-virgl/src/gallium/drivers/nouveau/codegen/nv50_ir_lowering_nvc0.h
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.h"23#include "codegen/nv50_ir_build_util.h"2425/* On nvc0, surface info is obtained via the surface binding points passed26* to the SULD/SUST instructions.27* On nve4, surface info is stored in c[] and is used by various special28* instructions, e.g. for clamping coordinates or generating an address.29* They couldn't just have added an equivalent to TIC now, couldn't they ?30*/31#define NVC0_SU_INFO_ADDR 0x0032#define NVC0_SU_INFO_FMT 0x0433#define NVC0_SU_INFO_DIM_X 0x0834#define NVC0_SU_INFO_PITCH 0x0c35#define NVC0_SU_INFO_DIM_Y 0x1036#define NVC0_SU_INFO_ARRAY 0x1437#define NVC0_SU_INFO_DIM_Z 0x1838#define NVC0_SU_INFO_UNK1C 0x1c39#define NVC0_SU_INFO_WIDTH 0x2040#define NVC0_SU_INFO_HEIGHT 0x2441#define NVC0_SU_INFO_DEPTH 0x2842#define NVC0_SU_INFO_TARGET 0x2c43#define NVC0_SU_INFO_BSIZE 0x3044#define NVC0_SU_INFO_RAW_X 0x3445#define NVC0_SU_INFO_MS_X 0x3846#define NVC0_SU_INFO_MS_Y 0x3c4748#define NVC0_SU_INFO__STRIDE 0x404950#define NVC0_SU_INFO_DIM(i) (0x08 + (i) * 8)51#define NVC0_SU_INFO_SIZE(i) (0x20 + (i) * 4)52#define NVC0_SU_INFO_MS(i) (0x38 + (i) * 4)5354namespace nv50_ir {5556class NVC0LegalizeSSA : public Pass57{58private:59virtual bool visit(BasicBlock *);60virtual bool visit(Function *);6162// we want to insert calls to the builtin library only after optimization63void handleDIV(Instruction *); // integer division, modulus64void handleRCPRSQLib(Instruction *, Value *[]);65void handleRCPRSQ(Instruction *); // double precision float recip/rsqrt66void handleSET(CmpInstruction *);67void handleTEXLOD(TexInstruction *);68void handleShift(Instruction *);69void handleBREV(Instruction *);7071protected:72void handleFTZ(Instruction *);7374BuildUtil bld;75};7677class NVC0LegalizePostRA : public Pass78{79public:80NVC0LegalizePostRA(const Program *);8182private:83virtual bool visit(Function *);84virtual bool visit(BasicBlock *);8586void replaceCvt(Instruction *);87void replaceZero(Instruction *);88bool tryReplaceContWithBra(BasicBlock *);89void propagateJoin(BasicBlock *);9091struct TexUse92{93TexUse(Instruction *use, const Instruction *tex, bool after)94: insn(use), tex(tex), after(after), level(-1) { }95Instruction *insn;96const Instruction *tex; // or split / mov97bool after;98int level;99};100struct Limits101{102Limits() : min(0), max(0) { }103Limits(int min, int max) : min(min), max(max) { }104int min, max;105};106bool insertTextureBarriers(Function *);107inline bool insnDominatedBy(const Instruction *, const Instruction *) const;108void findFirstUses(Instruction *texi, std::list<TexUse> &uses);109void findFirstUsesBB(int minGPR, int maxGPR, Instruction *start,110const Instruction *texi, std::list<TexUse> &uses,111unordered_set<const BasicBlock *> &visited);112void addTexUse(std::list<TexUse>&, Instruction *, const Instruction *);113const Instruction *recurseDef(const Instruction *);114115private:116LValue *rZero;117LValue *carry;118LValue *pOne;119const bool needTexBar;120};121122class NVC0LoweringPass : public Pass123{124public:125NVC0LoweringPass(Program *);126127protected:128bool handleRDSV(Instruction *);129bool handleWRSV(Instruction *);130bool handleEXPORT(Instruction *);131bool handleOUT(Instruction *);132bool handleDIV(Instruction *);133bool handleMOD(Instruction *);134bool handleSQRT(Instruction *);135bool handlePOW(Instruction *);136bool handleTEX(TexInstruction *);137bool handleTXD(TexInstruction *);138bool handleTXQ(TexInstruction *);139virtual bool handleManualTXD(TexInstruction *);140bool handleTXLQ(TexInstruction *);141bool handleSUQ(TexInstruction *);142bool handleATOM(Instruction *);143bool handleCasExch(Instruction *, bool needCctl);144void handleSurfaceOpGM107(TexInstruction *);145void handleSurfaceOpNVE4(TexInstruction *);146void handleSurfaceOpNVC0(TexInstruction *);147void handleSharedATOM(Instruction *);148void handleSharedATOMNVE4(Instruction *);149void handleLDST(Instruction *);150bool handleBUFQ(Instruction *);151void handlePIXLD(Instruction *);152153void checkPredicate(Instruction *);154Value *loadMsAdjInfo32(TexInstruction::Target targ, uint32_t index, int slot, Value *ind, bool bindless);155156virtual bool visit(Instruction *);157158private:159virtual bool visit(Function *);160virtual bool visit(BasicBlock *);161162void readTessCoord(LValue *dst, int c);163164Value *loadResInfo32(Value *ptr, uint32_t off, uint16_t base);165Value *loadResInfo64(Value *ptr, uint32_t off, uint16_t base);166Value *loadResLength32(Value *ptr, uint32_t off, uint16_t base);167Value *loadSuInfo32(Value *ptr, int slot, uint32_t off, bool bindless);168Value *loadBufInfo64(Value *ptr, uint32_t off);169Value *loadBufLength32(Value *ptr, uint32_t off);170Value *loadUboInfo64(Value *ptr, uint32_t off);171Value *loadUboLength32(Value *ptr, uint32_t off);172Value *loadMsInfo32(Value *ptr, uint32_t off);173174void adjustCoordinatesMS(TexInstruction *);175TexInstruction *processSurfaceCoordsGM107(TexInstruction *, Instruction *[4]);176void processSurfaceCoordsNVE4(TexInstruction *);177void processSurfaceCoordsNVC0(TexInstruction *);178void convertSurfaceFormat(TexInstruction *, Instruction **);179void insertOOBSurfaceOpResult(TexInstruction *);180Value *calculateSampleOffset(Value *sampleID);181182protected:183Value *loadTexHandle(Value *ptr, unsigned int slot);184185BuildUtil bld;186187private:188const Target *const targ;189190LValue *gpEmitAddress;191};192193} // namespace nv50_ir194195196