Path: blob/21.2-virgl/src/gallium/drivers/nouveau/codegen/nv50_ir_driver.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#ifndef __NV50_IR_DRIVER_H__23#define __NV50_IR_DRIVER_H__2425#include "pipe/p_shader_tokens.h"2627#include "util/blob.h"28#include "tgsi/tgsi_util.h"29#include "tgsi/tgsi_parse.h"30#include "tgsi/tgsi_scan.h"3132struct nir_shader_compiler_options;3334/*35* This struct constitutes linkage information in TGSI terminology.36*37* It is created by the code generator and handed to the pipe driver38* for input/output slot assignment.39*/40struct nv50_ir_varying41{42uint8_t slot[4]; /* native slots for xyzw (addresses in 32-bit words) */4344unsigned mask : 4; /* vec4 mask */45unsigned linear : 1; /* linearly interpolated if true (and not flat) */46unsigned flat : 1;47unsigned sc : 1; /* special colour interpolation mode (SHADE_MODEL) */48unsigned centroid : 1;49unsigned patch : 1; /* patch constant value */50unsigned regular : 1; /* driver-specific meaning (e.g. input in sreg) */51unsigned input : 1; /* indicates direction of system values */52unsigned oread : 1; /* true if output is read from parallel TCP */5354ubyte id; /* TGSI register index */55ubyte sn; /* TGSI semantic name */56ubyte si; /* TGSI semantic index */57};5859#ifndef NDEBUG60# define NV50_IR_DEBUG_BASIC (1 << 0)61# define NV50_IR_DEBUG_VERBOSE (2 << 0)62# define NV50_IR_DEBUG_REG_ALLOC (1 << 2)63#else64# define NV50_IR_DEBUG_BASIC 065# define NV50_IR_DEBUG_VERBOSE 066# define NV50_IR_DEBUG_REG_ALLOC 067#endif6869struct nv50_ir_prog_symbol70{71uint32_t label;72uint32_t offset;73};7475#define NVISA_GF100_CHIPSET 0xc076#define NVISA_GK104_CHIPSET 0xe077#define NVISA_GK20A_CHIPSET 0xea78#define NVISA_GM107_CHIPSET 0x11079#define NVISA_GM200_CHIPSET 0x12080#define NVISA_GV100_CHIPSET 0x1408182struct nv50_ir_prog_info_out;8384/* used for the input data and assignSlot interface */85struct nv50_ir_prog_info86{87uint16_t target; /* chipset (0x50, 0x84, 0xc0, ...) */8889uint8_t type; /* PIPE_SHADER */9091uint8_t optLevel; /* optimization level (0 to 3) */92uint8_t dbgFlags;93bool omitLineNum; /* only used for printing the prog when dbgFlags is set */9495struct {96uint32_t smemSize; /* required shared memory per block */97uint8_t sourceRep; /* PIPE_SHADER_IR_* */98const void *source;99} bin;100101union {102struct {103uint32_t inputOffset; /* base address for user args */104uint32_t gridInfoBase; /* base address for NTID,NCTAID */105uint16_t numThreads[3]; /* max number of threads */106} cp;107} prop;108109struct {110int8_t genUserClip; /* request user clip planes for ClipVertex */111uint8_t auxCBSlot; /* driver constant buffer slot */112uint16_t ucpBase; /* base address for UCPs */113uint16_t drawInfoBase; /* base address for draw parameters */114uint16_t alphaRefBase; /* base address for alpha test values */115int8_t viewportId; /* output index of ViewportIndex */116bool mul_zero_wins; /* program wants for x*0 = 0 */117bool nv50styleSurfaces; /* generate gX[] access for raw buffers */118uint16_t texBindBase; /* base address for tex handles (nve4) */119uint16_t fbtexBindBase; /* base address for fbtex handle (nve4) */120uint16_t suInfoBase; /* base address for surface info (nve4) */121uint16_t bindlessBase; /* base address for bindless image info (nve4) */122uint16_t bufInfoBase; /* base address for buffer info */123uint16_t sampleInfoBase; /* base address for sample positions */124uint8_t msInfoCBSlot; /* cX[] used for multisample info */125uint16_t msInfoBase; /* base address for multisample info */126uint16_t uboInfoBase; /* base address for compute UBOs (gk104+) */127128uint16_t membarOffset; /* base address for membar reads (nv50) */129uint8_t gmemMembar; /* gX[] on which to perform membar reads (nv50) */130} io;131132/* driver callback to assign input/output locations */133int (*assignSlots)(struct nv50_ir_prog_info_out *);134};135136/* the produced binary with metadata */137struct nv50_ir_prog_info_out138{139uint16_t target; /* chipset (0x50, 0x84, 0xc0, ...) */140141uint8_t type; /* PIPE_SHADER */142143struct {144int16_t maxGPR; /* may be -1 if none used */145uint32_t tlsSpace; /* required local memory per thread */146uint32_t smemSize; /* required shared memory per block */147uint32_t *code;148uint32_t codeSize;149uint32_t instructions;150void *relocData;151void *fixupData;152} bin;153154struct nv50_ir_varying sv[PIPE_MAX_SHADER_INPUTS];155struct nv50_ir_varying in[PIPE_MAX_SHADER_INPUTS];156struct nv50_ir_varying out[PIPE_MAX_SHADER_OUTPUTS];157uint8_t numInputs;158uint8_t numOutputs;159uint8_t numPatchConstants; /* also included in numInputs/numOutputs */160uint8_t numSysVals;161162union {163struct {164bool usesDrawParameters;165} vp;166struct {167uint8_t outputPatchSize;168uint8_t partitioning; /* PIPE_TESS_PART */169int8_t winding; /* +1 (clockwise) / -1 (counter-clockwise) */170uint8_t domain; /* PIPE_PRIM_{QUADS,TRIANGLES,LINES} */171uint8_t outputPrim; /* PIPE_PRIM_{TRIANGLES,LINES,POINTS} */172} tp;173struct {174uint8_t outputPrim;175unsigned instanceCount;176unsigned maxVertices;177} gp;178struct {179unsigned numColourResults;180bool writesDepth : 1;181bool earlyFragTests : 1;182bool postDepthCoverage : 1;183bool usesDiscard : 1;184bool usesSampleMaskIn : 1;185bool readsFramebuffer : 1;186bool readsSampleLocations : 1;187bool separateFragData : 1;188} fp;189struct {190struct {191unsigned valid : 1;192unsigned image : 1;193unsigned slot : 6;194} gmem[16]; /* nv50 only */195} cp;196} prop;197198struct {199uint8_t clipDistances; /* number of clip distance outputs */200uint8_t cullDistances; /* number of cull distance outputs */201int8_t genUserClip; /* request user clip planes for ClipVertex */202uint8_t instanceId; /* system value index of InstanceID */203uint8_t vertexId; /* system value index of VertexID */204uint8_t edgeFlagIn;205uint8_t edgeFlagOut;206uint8_t fragDepth; /* output index of FragDepth */207uint8_t sampleMask; /* output index of SampleMask */208uint8_t globalAccess; /* 1 for read, 2 for wr, 3 for rw */209bool fp64; /* program uses fp64 math */210bool layer_viewport_relative;211} io;212213uint8_t numBarriers;214215void *driverPriv;216};217218#ifdef __cplusplus219extern "C" {220#endif221222const struct nir_shader_compiler_options *223nv50_ir_nir_shader_compiler_options(int chipset);224225extern int nv50_ir_generate_code(struct nv50_ir_prog_info *,226struct nv50_ir_prog_info_out *);227228extern void nv50_ir_relocate_code(void *relocData, uint32_t *code,229uint32_t codePos,230uint32_t libPos,231uint32_t dataPos);232233extern void234nv50_ir_apply_fixups(void *fixupData, uint32_t *code,235bool force_per_sample, bool flatshade,236uint8_t alphatest, bool msaa);237238/* obtain code that will be shared among programs */239extern void nv50_ir_get_target_library(uint32_t chipset,240const uint32_t **code, uint32_t *size);241242243#ifdef __cplusplus244namespace nv50_ir245{246class FixupEntry;247class FixupData;248249void250gk110_interpApply(const nv50_ir::FixupEntry *entry, uint32_t *code,251const nv50_ir::FixupData& data);252void253gm107_interpApply(const nv50_ir::FixupEntry *entry, uint32_t *code,254const nv50_ir::FixupData& data);255void256nv50_interpApply(const nv50_ir::FixupEntry *entry, uint32_t *code,257const nv50_ir::FixupData& data);258void259nvc0_interpApply(const nv50_ir::FixupEntry *entry, uint32_t *code,260const nv50_ir::FixupData& data);261void262gv100_interpApply(const nv50_ir::FixupEntry *entry, uint32_t *code,263const nv50_ir::FixupData& data);264void265gk110_selpFlip(const nv50_ir::FixupEntry *entry, uint32_t *code,266const nv50_ir::FixupData& data);267void268gm107_selpFlip(const nv50_ir::FixupEntry *entry, uint32_t *code,269const nv50_ir::FixupData& data);270void271nvc0_selpFlip(const nv50_ir::FixupEntry *entry, uint32_t *code,272const nv50_ir::FixupData& data);273void274gv100_selpFlip(const nv50_ir::FixupEntry *entry, uint32_t *code,275const nv50_ir::FixupData& data);276}277#endif278279extern void280nv50_ir_prog_info_out_print(struct nv50_ir_prog_info_out *);281282/* Serialize a nv50_ir_prog_info structure and save it into blob */283extern bool284nv50_ir_prog_info_serialize(struct blob *, struct nv50_ir_prog_info *);285286/* Serialize a nv50_ir_prog_info_out structure and save it into blob */287extern bool MUST_CHECK288nv50_ir_prog_info_out_serialize(struct blob *, struct nv50_ir_prog_info_out *);289290/* Deserialize from data and save into a nv50_ir_prog_info_out structure291* using a pointer. Size is a total size of the serialized data.292* Offset points to where info_out in data is located. */293extern bool MUST_CHECK294nv50_ir_prog_info_out_deserialize(void *data, size_t size, size_t offset,295struct nv50_ir_prog_info_out *);296297#ifdef __cplusplus298}299#endif300301#endif // __NV50_IR_DRIVER_H__302303304