builtin_functions.cpp 207 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692
  1. /*
  2. * Copyright © 2013 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. */
  23. /**
  24. * \file builtin_functions.cpp
  25. *
  26. * Support for GLSL built-in functions.
  27. *
  28. * This file is split into several main components:
  29. *
  30. * 1. Availability predicates
  31. *
  32. * A series of small functions that check whether the current shader
  33. * supports the version/extensions required to expose a built-in.
  34. *
  35. * 2. Core builtin_builder class functionality
  36. *
  37. * 3. Lists of built-in functions
  38. *
  39. * The builtin_builder::create_builtins() function contains lists of all
  40. * built-in function signatures, where they're available, what types they
  41. * take, and so on.
  42. *
  43. * 4. Implementations of built-in function signatures
  44. *
  45. * A series of functions which create ir_function_signatures and emit IR
  46. * via ir_builder to implement them.
  47. *
  48. * 5. External API
  49. *
  50. * A few functions the rest of the compiler can use to interact with the
  51. * built-in function module. For example, searching for a built-in by
  52. * name and parameters.
  53. */
  54. #define _USE_MATH_DEFINES
  55. #include <stdarg.h>
  56. #include <stdio.h>
  57. #include "main/core.h" /* for struct gl_shader */
  58. #include "standalone_scaffolding.h"
  59. #include "ir_builder.h"
  60. #include "glsl_parser_extras.h"
  61. #include "program/prog_instruction.h"
  62. #include <limits>
  63. #define M_PIf ((float) M_PI)
  64. #define M_PI_2f ((float) M_PI_2)
  65. #define M_PI_4f ((float) M_PI_4)
  66. using namespace ir_builder;
  67. /**
  68. * Availability predicates:
  69. * @{
  70. */
  71. static bool
  72. always_available(const _mesa_glsl_parse_state *)
  73. {
  74. return true;
  75. }
  76. static bool
  77. compatibility_vs_only(const _mesa_glsl_parse_state *state)
  78. {
  79. return state->stage == MESA_SHADER_VERTEX &&
  80. state->language_version <= 130 &&
  81. !state->es_shader;
  82. }
  83. static bool
  84. fs_only(const _mesa_glsl_parse_state *state)
  85. {
  86. return state->stage == MESA_SHADER_FRAGMENT;
  87. }
  88. static bool
  89. gs_only(const _mesa_glsl_parse_state *state)
  90. {
  91. return state->stage == MESA_SHADER_GEOMETRY;
  92. }
  93. static bool
  94. v110(const _mesa_glsl_parse_state *state)
  95. {
  96. return !state->es_shader;
  97. }
  98. static bool
  99. v110_fs_only(const _mesa_glsl_parse_state *state)
  100. {
  101. return !state->es_shader && state->stage == MESA_SHADER_FRAGMENT;
  102. }
  103. static bool
  104. v120(const _mesa_glsl_parse_state *state)
  105. {
  106. return state->is_version(120, 300);
  107. }
  108. static bool
  109. v130(const _mesa_glsl_parse_state *state)
  110. {
  111. return state->is_version(130, 300);
  112. }
  113. static bool
  114. v130_fs_only(const _mesa_glsl_parse_state *state)
  115. {
  116. return state->is_version(130, 300) &&
  117. state->stage == MESA_SHADER_FRAGMENT;
  118. }
  119. static bool
  120. v140(const _mesa_glsl_parse_state *state)
  121. {
  122. return state->is_version(140, 0);
  123. }
  124. static bool
  125. texture_rectangle(const _mesa_glsl_parse_state *state)
  126. {
  127. return state->ARB_texture_rectangle_enable;
  128. }
  129. static bool
  130. texture_external(const _mesa_glsl_parse_state *state)
  131. {
  132. return state->OES_EGL_image_external_enable;
  133. }
  134. /** True if texturing functions with explicit LOD are allowed. */
  135. static bool
  136. lod_exists_in_stage(const _mesa_glsl_parse_state *state)
  137. {
  138. /* Texturing functions with "Lod" in their name exist:
  139. * - In the vertex shader stage (for all languages)
  140. * - In any stage for GLSL 1.30+ or GLSL ES 3.00
  141. * - In any stage for desktop GLSL with ARB_shader_texture_lod enabled.
  142. *
  143. * Since ARB_shader_texture_lod can only be enabled on desktop GLSL, we
  144. * don't need to explicitly check state->es_shader.
  145. */
  146. return state->stage == MESA_SHADER_VERTEX ||
  147. state->is_version(130, 300) ||
  148. state->ARB_shader_texture_lod_enable;
  149. }
  150. static bool
  151. es_lod_exists_in_stage(const _mesa_glsl_parse_state *state)
  152. {
  153. /* Texturing functions with "LodEXT" in their name exist:
  154. * In the fragment shader, for ES1 shader, when EXT_shader_texture_lod
  155. * is enabled.
  156. */
  157. return
  158. state->stage == MESA_SHADER_FRAGMENT &&
  159. state->es_shader &&
  160. state->is_version(110, 100) &&
  161. state->EXT_shader_texture_lod_enable;
  162. }
  163. static bool
  164. v110_lod(const _mesa_glsl_parse_state *state)
  165. {
  166. return !state->es_shader && lod_exists_in_stage(state);
  167. }
  168. static bool
  169. shader_texture_lod(const _mesa_glsl_parse_state *state)
  170. {
  171. return state->ARB_shader_texture_lod_enable;
  172. }
  173. static bool
  174. es_shader_texture_lod(const _mesa_glsl_parse_state *state)
  175. {
  176. return state->EXT_shader_texture_lod_enable;
  177. }
  178. static bool
  179. es_shadow_samplers(const _mesa_glsl_parse_state *state)
  180. {
  181. return state->EXT_shadow_samplers_enable;
  182. }
  183. static bool
  184. shader_texture_lod_and_rect(const _mesa_glsl_parse_state *state)
  185. {
  186. return state->ARB_shader_texture_lod_enable &&
  187. state->ARB_texture_rectangle_enable;
  188. }
  189. static bool
  190. shader_bit_encoding(const _mesa_glsl_parse_state *state)
  191. {
  192. return state->is_version(330, 300) ||
  193. state->ARB_shader_bit_encoding_enable ||
  194. state->ARB_gpu_shader5_enable;
  195. }
  196. static bool
  197. shader_integer_mix(const _mesa_glsl_parse_state *state)
  198. {
  199. return v130(state) && state->EXT_shader_integer_mix_enable;
  200. }
  201. static bool
  202. shader_packing_or_es3(const _mesa_glsl_parse_state *state)
  203. {
  204. return state->ARB_shading_language_packing_enable ||
  205. state->is_version(400, 300);
  206. }
  207. static bool
  208. shader_packing_or_es3_or_gpu_shader5(const _mesa_glsl_parse_state *state)
  209. {
  210. return state->ARB_shading_language_packing_enable ||
  211. state->ARB_gpu_shader5_enable ||
  212. state->is_version(400, 300);
  213. }
  214. static bool
  215. gpu_shader5(const _mesa_glsl_parse_state *state)
  216. {
  217. return state->is_version(400, 0) || state->ARB_gpu_shader5_enable;
  218. }
  219. static bool
  220. shader_packing_or_gpu_shader5(const _mesa_glsl_parse_state *state)
  221. {
  222. return state->ARB_shading_language_packing_enable ||
  223. gpu_shader5(state);
  224. }
  225. static bool
  226. fs_gpu_shader5(const _mesa_glsl_parse_state *state)
  227. {
  228. return state->stage == MESA_SHADER_FRAGMENT &&
  229. (state->is_version(400, 0) || state->ARB_gpu_shader5_enable);
  230. }
  231. static bool
  232. texture_array_lod(const _mesa_glsl_parse_state *state)
  233. {
  234. return lod_exists_in_stage(state) &&
  235. state->EXT_texture_array_enable;
  236. }
  237. static bool
  238. fs_texture_array(const _mesa_glsl_parse_state *state)
  239. {
  240. return state->stage == MESA_SHADER_FRAGMENT &&
  241. state->EXT_texture_array_enable;
  242. }
  243. static bool
  244. texture_array(const _mesa_glsl_parse_state *state)
  245. {
  246. return state->EXT_texture_array_enable;
  247. }
  248. static bool
  249. texture_multisample(const _mesa_glsl_parse_state *state)
  250. {
  251. return state->is_version(150, 0) ||
  252. state->ARB_texture_multisample_enable;
  253. }
  254. static bool
  255. fs_texture_cube_map_array(const _mesa_glsl_parse_state *state)
  256. {
  257. return state->stage == MESA_SHADER_FRAGMENT &&
  258. (state->is_version(400, 0) ||
  259. state->ARB_texture_cube_map_array_enable);
  260. }
  261. static bool
  262. texture_cube_map_array(const _mesa_glsl_parse_state *state)
  263. {
  264. return state->is_version(400, 0) ||
  265. state->ARB_texture_cube_map_array_enable;
  266. }
  267. static bool
  268. texture_query_levels(const _mesa_glsl_parse_state *state)
  269. {
  270. return state->is_version(430, 0) ||
  271. state->ARB_texture_query_levels_enable;
  272. }
  273. static bool
  274. texture_query_lod(const _mesa_glsl_parse_state *state)
  275. {
  276. return state->stage == MESA_SHADER_FRAGMENT &&
  277. state->ARB_texture_query_lod_enable;
  278. }
  279. static bool
  280. texture_gather(const _mesa_glsl_parse_state *state)
  281. {
  282. return state->is_version(400, 0) ||
  283. state->ARB_texture_gather_enable ||
  284. state->ARB_gpu_shader5_enable;
  285. }
  286. /* Only ARB_texture_gather but not GLSL 4.0 or ARB_gpu_shader5.
  287. * used for relaxation of const offset requirements.
  288. */
  289. static bool
  290. texture_gather_only(const _mesa_glsl_parse_state *state)
  291. {
  292. return !state->is_version(400, 0) &&
  293. !state->ARB_gpu_shader5_enable &&
  294. state->ARB_texture_gather_enable;
  295. }
  296. /* Desktop GL or OES_standard_derivatives + fragment shader only */
  297. static bool
  298. fs_oes_derivatives(const _mesa_glsl_parse_state *state)
  299. {
  300. return state->stage == MESA_SHADER_FRAGMENT &&
  301. (state->is_version(110, 300) ||
  302. state->OES_standard_derivatives_enable);
  303. }
  304. static bool
  305. fs_derivative_control(const _mesa_glsl_parse_state *state)
  306. {
  307. return state->stage == MESA_SHADER_FRAGMENT &&
  308. (state->is_version(450, 0) ||
  309. state->ARB_derivative_control_enable);
  310. }
  311. static bool
  312. tex1d_lod(const _mesa_glsl_parse_state *state)
  313. {
  314. return !state->es_shader && lod_exists_in_stage(state);
  315. }
  316. /** True if sampler3D exists */
  317. static bool
  318. tex3d(const _mesa_glsl_parse_state *state)
  319. {
  320. /* sampler3D exists in all desktop GLSL versions, GLSL ES 1.00 with the
  321. * OES_texture_3D extension, and in GLSL ES 3.00.
  322. */
  323. return !state->es_shader ||
  324. state->OES_texture_3D_enable ||
  325. state->language_version >= 300;
  326. }
  327. static bool
  328. fs_tex3d(const _mesa_glsl_parse_state *state)
  329. {
  330. return state->stage == MESA_SHADER_FRAGMENT &&
  331. (!state->es_shader || state->OES_texture_3D_enable);
  332. }
  333. static bool
  334. tex3d_lod(const _mesa_glsl_parse_state *state)
  335. {
  336. return tex3d(state) && lod_exists_in_stage(state);
  337. }
  338. static bool
  339. shader_atomic_counters(const _mesa_glsl_parse_state *state)
  340. {
  341. return state->ARB_shader_atomic_counters_enable;
  342. }
  343. static bool
  344. shader_trinary_minmax(const _mesa_glsl_parse_state *state)
  345. {
  346. return state->AMD_shader_trinary_minmax_enable;
  347. }
  348. static bool
  349. shader_image_load_store(const _mesa_glsl_parse_state *state)
  350. {
  351. return (state->is_version(420, 0) ||
  352. state->ARB_shader_image_load_store_enable);
  353. }
  354. static bool
  355. gs_streams(const _mesa_glsl_parse_state *state)
  356. {
  357. return gpu_shader5(state) && gs_only(state);
  358. }
  359. /** @} */
  360. /******************************************************************************/
  361. namespace {
  362. /**
  363. * builtin_builder: A singleton object representing the core of the built-in
  364. * function module.
  365. *
  366. * It generates IR for every built-in function signature, and organizes them
  367. * into functions.
  368. */
  369. class builtin_builder {
  370. public:
  371. builtin_builder();
  372. ~builtin_builder();
  373. void initialize();
  374. void release();
  375. ir_function_signature *find(_mesa_glsl_parse_state *state,
  376. const char *name, exec_list *actual_parameters);
  377. /**
  378. * A shader to hold all the built-in signatures; created by this module.
  379. *
  380. * This includes signatures for every built-in, regardless of version or
  381. * enabled extensions. The availability predicate associated with each
  382. * signature allows matching_signature() to filter out the irrelevant ones.
  383. */
  384. gl_shader *shader;
  385. private:
  386. void *mem_ctx;
  387. /** Global variables used by built-in functions. */
  388. ir_variable *gl_ModelViewProjectionMatrix;
  389. ir_variable *gl_Vertex;
  390. void create_shader();
  391. void create_intrinsics();
  392. void create_builtins();
  393. /**
  394. * IR builder helpers:
  395. *
  396. * These convenience functions assist in emitting IR, but don't necessarily
  397. * fit in ir_builder itself. Many of them rely on having a mem_ctx class
  398. * member available.
  399. */
  400. ir_variable *in_var(const glsl_type *type, const char *name);
  401. ir_variable *out_var(const glsl_type *type, const char *name);
  402. ir_constant *imm(float f, unsigned vector_elements=1);
  403. ir_constant *imm(int i, unsigned vector_elements=1);
  404. ir_constant *imm(unsigned u, unsigned vector_elements=1);
  405. ir_constant *imm(const glsl_type *type, const ir_constant_data &);
  406. ir_dereference_variable *var_ref(ir_variable *var);
  407. ir_dereference_array *array_ref(ir_variable *var, int i);
  408. ir_swizzle *matrix_elt(ir_variable *var, int col, int row);
  409. ir_expression *asin_expr(ir_variable *x);
  410. void do_atan(ir_factory &body, const glsl_type *type, ir_variable *res, operand y_over_x);
  411. /**
  412. * Call function \param f with parameters specified as the linked
  413. * list \param params of \c ir_variable objects. \param ret should
  414. * point to the ir_variable that will hold the function return
  415. * value, or be \c NULL if the function has void return type.
  416. */
  417. ir_call *call(ir_function *f, ir_variable *ret, exec_list params);
  418. /** Create a new function and add the given signatures. */
  419. void add_function(const char *name, ...);
  420. enum image_function_flags {
  421. IMAGE_FUNCTION_EMIT_STUB = (1 << 0),
  422. IMAGE_FUNCTION_RETURNS_VOID = (1 << 1),
  423. IMAGE_FUNCTION_HAS_VECTOR_DATA_TYPE = (1 << 2),
  424. IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE = (1 << 3),
  425. IMAGE_FUNCTION_READ_ONLY = (1 << 4),
  426. IMAGE_FUNCTION_WRITE_ONLY = (1 << 5)
  427. };
  428. /**
  429. * Create a new image built-in function for all known image types.
  430. * \p flags is a bitfield of \c image_function_flags flags.
  431. */
  432. void add_image_function(const char *name,
  433. const char *intrinsic_name,
  434. unsigned num_arguments,
  435. unsigned flags);
  436. /**
  437. * Create new functions for all known image built-ins and types.
  438. * If \p glsl is \c true, use the GLSL built-in names and emit code
  439. * to call into the actual compiler intrinsic. If \p glsl is
  440. * false, emit a function prototype with no body for each image
  441. * intrinsic name.
  442. */
  443. void add_image_functions(bool glsl);
  444. ir_function_signature *new_sig(const glsl_type *return_type,
  445. builtin_available_predicate avail,
  446. int num_params, ...);
  447. /**
  448. * Function signature generators:
  449. * @{
  450. */
  451. ir_function_signature *unop(builtin_available_predicate avail,
  452. ir_expression_operation opcode,
  453. const glsl_type *return_type,
  454. const glsl_type *param_type);
  455. ir_function_signature *binop(ir_expression_operation opcode,
  456. builtin_available_predicate avail,
  457. const glsl_type *return_type,
  458. const glsl_type *param0_type,
  459. const glsl_type *param1_type);
  460. #define B0(X) ir_function_signature *_##X();
  461. #define B1(X) ir_function_signature *_##X(const glsl_type *);
  462. #define B2(X) ir_function_signature *_##X(const glsl_type *, const glsl_type *);
  463. #define B3(X) ir_function_signature *_##X(const glsl_type *, const glsl_type *, const glsl_type *);
  464. #define BA1(X) ir_function_signature *_##X(builtin_available_predicate, const glsl_type *);
  465. #define BA2(X) ir_function_signature *_##X(builtin_available_predicate, const glsl_type *, const glsl_type *);
  466. B1(radians)
  467. B1(degrees)
  468. B1(sin)
  469. B1(cos)
  470. B1(tan)
  471. B1(asin)
  472. B1(acos)
  473. B1(atan2)
  474. B1(atan)
  475. B1(sinh)
  476. B1(cosh)
  477. B1(tanh)
  478. B1(asinh)
  479. B1(acosh)
  480. B1(atanh)
  481. B1(pow)
  482. B1(exp)
  483. B1(log)
  484. B1(exp2)
  485. B1(log2)
  486. B1(sqrt)
  487. B1(inversesqrt)
  488. B1(abs)
  489. B1(sign)
  490. B1(floor)
  491. B1(trunc)
  492. B1(round)
  493. B1(roundEven)
  494. B1(ceil)
  495. B1(fract)
  496. B2(mod)
  497. B1(modf)
  498. BA2(min)
  499. BA2(max)
  500. BA2(clamp)
  501. B2(mix_lrp)
  502. ir_function_signature *_mix_sel(builtin_available_predicate avail,
  503. const glsl_type *val_type,
  504. const glsl_type *blend_type);
  505. B2(step)
  506. B2(smoothstep)
  507. B1(isnan)
  508. B1(isinf)
  509. B1(floatBitsToInt)
  510. B1(floatBitsToUint)
  511. B1(intBitsToFloat)
  512. B1(uintBitsToFloat)
  513. ir_function_signature *_packUnorm2x16(builtin_available_predicate avail);
  514. ir_function_signature *_packSnorm2x16(builtin_available_predicate avail);
  515. ir_function_signature *_packUnorm4x8(builtin_available_predicate avail);
  516. ir_function_signature *_packSnorm4x8(builtin_available_predicate avail);
  517. ir_function_signature *_unpackUnorm2x16(builtin_available_predicate avail);
  518. ir_function_signature *_unpackSnorm2x16(builtin_available_predicate avail);
  519. ir_function_signature *_unpackUnorm4x8(builtin_available_predicate avail);
  520. ir_function_signature *_unpackSnorm4x8(builtin_available_predicate avail);
  521. ir_function_signature *_packHalf2x16(builtin_available_predicate avail);
  522. ir_function_signature *_unpackHalf2x16(builtin_available_predicate avail);
  523. B1(length)
  524. B1(distance);
  525. B1(dot);
  526. B1(cross);
  527. B1(normalize);
  528. B0(ftransform);
  529. B1(faceforward);
  530. B1(reflect);
  531. B1(refract);
  532. B1(matrixCompMult);
  533. B1(outerProduct);
  534. B0(determinant_mat2);
  535. B0(determinant_mat3);
  536. B0(determinant_mat4);
  537. B0(inverse_mat2);
  538. B0(inverse_mat3);
  539. B0(inverse_mat4);
  540. B1(transpose);
  541. BA1(lessThan);
  542. BA1(lessThanEqual);
  543. BA1(greaterThan);
  544. BA1(greaterThanEqual);
  545. BA1(equal);
  546. BA1(notEqual);
  547. B1(any);
  548. B1(all);
  549. B1(not);
  550. B2(textureSize);
  551. ir_function_signature *_textureSize(builtin_available_predicate avail,
  552. const glsl_type *return_type,
  553. const glsl_type *sampler_type);
  554. /** Flags to _texture() */
  555. #define TEX_PROJECT 1
  556. #define TEX_OFFSET 2
  557. #define TEX_COMPONENT 4
  558. #define TEX_OFFSET_NONCONST 8
  559. #define TEX_OFFSET_ARRAY 16
  560. ir_function_signature *_texture(ir_texture_opcode opcode,
  561. builtin_available_predicate avail,
  562. const glsl_type *return_type,
  563. const glsl_type *sampler_type,
  564. const glsl_type *coord_type,
  565. int flags = 0);
  566. B0(textureCubeArrayShadow);
  567. ir_function_signature *_texelFetch(builtin_available_predicate avail,
  568. const glsl_type *return_type,
  569. const glsl_type *sampler_type,
  570. const glsl_type *coord_type,
  571. const glsl_type *offset_type = NULL);
  572. B0(EmitVertex)
  573. B0(EndPrimitive)
  574. ir_function_signature *_EmitStreamVertex(builtin_available_predicate avail,
  575. const glsl_type *stream_type);
  576. ir_function_signature *_EndStreamPrimitive(builtin_available_predicate avail,
  577. const glsl_type *stream_type);
  578. B2(textureQueryLod);
  579. B1(textureQueryLevels);
  580. B1(dFdx);
  581. B1(dFdy);
  582. B1(fwidth);
  583. B1(dFdxCoarse);
  584. B1(dFdyCoarse);
  585. B1(fwidthCoarse);
  586. B1(dFdxFine);
  587. B1(dFdyFine);
  588. B1(fwidthFine);
  589. B1(noise1);
  590. B1(noise2);
  591. B1(noise3);
  592. B1(noise4);
  593. B1(bitfieldExtract)
  594. B1(bitfieldInsert)
  595. B1(bitfieldReverse)
  596. B1(bitCount)
  597. B1(findLSB)
  598. B1(findMSB)
  599. B1(fma)
  600. B2(ldexp)
  601. B2(frexp)
  602. B1(uaddCarry)
  603. B1(usubBorrow)
  604. B1(mulExtended)
  605. B1(interpolateAtCentroid)
  606. B1(interpolateAtOffset)
  607. B1(interpolateAtSample)
  608. ir_function_signature *_atomic_intrinsic(builtin_available_predicate avail);
  609. ir_function_signature *_atomic_op(const char *intrinsic,
  610. builtin_available_predicate avail);
  611. B1(min3)
  612. B1(max3)
  613. B1(mid3)
  614. ir_function_signature *_image_prototype(const glsl_type *image_type,
  615. const char *intrinsic_name,
  616. unsigned num_arguments,
  617. unsigned flags);
  618. ir_function_signature *_image(const glsl_type *image_type,
  619. const char *intrinsic_name,
  620. unsigned num_arguments,
  621. unsigned flags);
  622. ir_function_signature *_memory_barrier_intrinsic(
  623. builtin_available_predicate avail);
  624. ir_function_signature *_memory_barrier(
  625. builtin_available_predicate avail);
  626. #undef B0
  627. #undef B1
  628. #undef B2
  629. #undef B3
  630. #undef BA1
  631. #undef BA2
  632. /** @} */
  633. };
  634. } /* anonymous namespace */
  635. /**
  636. * Core builtin_builder functionality:
  637. * @{
  638. */
  639. builtin_builder::builtin_builder()
  640. : shader(NULL),
  641. gl_ModelViewProjectionMatrix(NULL),
  642. gl_Vertex(NULL)
  643. {
  644. mem_ctx = NULL;
  645. }
  646. builtin_builder::~builtin_builder()
  647. {
  648. ralloc_free(mem_ctx);
  649. }
  650. ir_function_signature *
  651. builtin_builder::find(_mesa_glsl_parse_state *state,
  652. const char *name, exec_list *actual_parameters)
  653. {
  654. /* The shader currently being compiled requested a built-in function;
  655. * it needs to link against builtin_builder::shader in order to get them.
  656. *
  657. * Even if we don't find a matching signature, we still need to do this so
  658. * that the "no matching signature" error will list potential candidates
  659. * from the available built-ins.
  660. */
  661. state->uses_builtin_functions = true;
  662. ir_function *f = shader->symbols->get_function(name);
  663. if (f == NULL)
  664. return NULL;
  665. ir_function_signature *sig =
  666. f->matching_signature(state, actual_parameters, true);
  667. if (sig == NULL)
  668. return NULL;
  669. return sig;
  670. }
  671. void
  672. builtin_builder::initialize()
  673. {
  674. /* If already initialized, don't do it again. */
  675. if (mem_ctx != NULL)
  676. return;
  677. mem_ctx = ralloc_context(NULL);
  678. create_shader();
  679. create_intrinsics();
  680. create_builtins();
  681. }
  682. void
  683. builtin_builder::release()
  684. {
  685. ralloc_free(mem_ctx);
  686. mem_ctx = NULL;
  687. ralloc_free(shader);
  688. shader = NULL;
  689. }
  690. void
  691. builtin_builder::create_shader()
  692. {
  693. /* The target doesn't actually matter. There's no target for generic
  694. * GLSL utility code that could be linked against any stage, so just
  695. * arbitrarily pick GL_VERTEX_SHADER.
  696. */
  697. shader = _mesa_new_shader(NULL, 0, GL_VERTEX_SHADER);
  698. shader->symbols = new(mem_ctx) glsl_symbol_table;
  699. gl_ModelViewProjectionMatrix =
  700. new(mem_ctx) ir_variable(glsl_type::mat4_type,
  701. "gl_ModelViewProjectionMatrix",
  702. ir_var_uniform, glsl_precision_high);
  703. shader->symbols->add_variable(gl_ModelViewProjectionMatrix);
  704. gl_Vertex = in_var(glsl_type::vec4_type, "gl_Vertex");
  705. shader->symbols->add_variable(gl_Vertex);
  706. }
  707. /** @} */
  708. /**
  709. * Create ir_function and ir_function_signature objects for each
  710. * intrinsic.
  711. */
  712. void
  713. builtin_builder::create_intrinsics()
  714. {
  715. add_function("__intrinsic_atomic_read",
  716. _atomic_intrinsic(shader_atomic_counters),
  717. NULL);
  718. add_function("__intrinsic_atomic_increment",
  719. _atomic_intrinsic(shader_atomic_counters),
  720. NULL);
  721. add_function("__intrinsic_atomic_predecrement",
  722. _atomic_intrinsic(shader_atomic_counters),
  723. NULL);
  724. add_image_functions(false);
  725. add_function("__intrinsic_memory_barrier",
  726. _memory_barrier_intrinsic(shader_image_load_store),
  727. NULL);
  728. }
  729. /**
  730. * Create ir_function and ir_function_signature objects for each built-in.
  731. *
  732. * Contains a list of every available built-in.
  733. */
  734. void
  735. builtin_builder::create_builtins()
  736. {
  737. #define F(NAME) \
  738. add_function(#NAME, \
  739. _##NAME(glsl_type::float_type), \
  740. _##NAME(glsl_type::vec2_type), \
  741. _##NAME(glsl_type::vec3_type), \
  742. _##NAME(glsl_type::vec4_type), \
  743. NULL);
  744. #define FI(NAME) \
  745. add_function(#NAME, \
  746. _##NAME(glsl_type::float_type), \
  747. _##NAME(glsl_type::vec2_type), \
  748. _##NAME(glsl_type::vec3_type), \
  749. _##NAME(glsl_type::vec4_type), \
  750. _##NAME(glsl_type::int_type), \
  751. _##NAME(glsl_type::ivec2_type), \
  752. _##NAME(glsl_type::ivec3_type), \
  753. _##NAME(glsl_type::ivec4_type), \
  754. NULL);
  755. #define FIU(NAME) \
  756. add_function(#NAME, \
  757. _##NAME(always_available, glsl_type::float_type), \
  758. _##NAME(always_available, glsl_type::vec2_type), \
  759. _##NAME(always_available, glsl_type::vec3_type), \
  760. _##NAME(always_available, glsl_type::vec4_type), \
  761. \
  762. _##NAME(always_available, glsl_type::int_type), \
  763. _##NAME(always_available, glsl_type::ivec2_type), \
  764. _##NAME(always_available, glsl_type::ivec3_type), \
  765. _##NAME(always_available, glsl_type::ivec4_type), \
  766. \
  767. _##NAME(v130, glsl_type::uint_type), \
  768. _##NAME(v130, glsl_type::uvec2_type), \
  769. _##NAME(v130, glsl_type::uvec3_type), \
  770. _##NAME(v130, glsl_type::uvec4_type), \
  771. NULL);
  772. #define IU(NAME) \
  773. add_function(#NAME, \
  774. _##NAME(glsl_type::int_type), \
  775. _##NAME(glsl_type::ivec2_type), \
  776. _##NAME(glsl_type::ivec3_type), \
  777. _##NAME(glsl_type::ivec4_type), \
  778. \
  779. _##NAME(glsl_type::uint_type), \
  780. _##NAME(glsl_type::uvec2_type), \
  781. _##NAME(glsl_type::uvec3_type), \
  782. _##NAME(glsl_type::uvec4_type), \
  783. NULL);
  784. #define FIUB(NAME) \
  785. add_function(#NAME, \
  786. _##NAME(always_available, glsl_type::float_type), \
  787. _##NAME(always_available, glsl_type::vec2_type), \
  788. _##NAME(always_available, glsl_type::vec3_type), \
  789. _##NAME(always_available, glsl_type::vec4_type), \
  790. \
  791. _##NAME(always_available, glsl_type::int_type), \
  792. _##NAME(always_available, glsl_type::ivec2_type), \
  793. _##NAME(always_available, glsl_type::ivec3_type), \
  794. _##NAME(always_available, glsl_type::ivec4_type), \
  795. \
  796. _##NAME(v130, glsl_type::uint_type), \
  797. _##NAME(v130, glsl_type::uvec2_type), \
  798. _##NAME(v130, glsl_type::uvec3_type), \
  799. _##NAME(v130, glsl_type::uvec4_type), \
  800. \
  801. _##NAME(always_available, glsl_type::bool_type), \
  802. _##NAME(always_available, glsl_type::bvec2_type), \
  803. _##NAME(always_available, glsl_type::bvec3_type), \
  804. _##NAME(always_available, glsl_type::bvec4_type), \
  805. NULL);
  806. #define FIU2_MIXED(NAME) \
  807. add_function(#NAME, \
  808. _##NAME(always_available, glsl_type::float_type, glsl_type::float_type), \
  809. _##NAME(always_available, glsl_type::vec2_type, glsl_type::float_type), \
  810. _##NAME(always_available, glsl_type::vec3_type, glsl_type::float_type), \
  811. _##NAME(always_available, glsl_type::vec4_type, glsl_type::float_type), \
  812. \
  813. _##NAME(always_available, glsl_type::vec2_type, glsl_type::vec2_type), \
  814. _##NAME(always_available, glsl_type::vec3_type, glsl_type::vec3_type), \
  815. _##NAME(always_available, glsl_type::vec4_type, glsl_type::vec4_type), \
  816. \
  817. _##NAME(always_available, glsl_type::int_type, glsl_type::int_type), \
  818. _##NAME(always_available, glsl_type::ivec2_type, glsl_type::int_type), \
  819. _##NAME(always_available, glsl_type::ivec3_type, glsl_type::int_type), \
  820. _##NAME(always_available, glsl_type::ivec4_type, glsl_type::int_type), \
  821. \
  822. _##NAME(always_available, glsl_type::ivec2_type, glsl_type::ivec2_type), \
  823. _##NAME(always_available, glsl_type::ivec3_type, glsl_type::ivec3_type), \
  824. _##NAME(always_available, glsl_type::ivec4_type, glsl_type::ivec4_type), \
  825. \
  826. _##NAME(v130, glsl_type::uint_type, glsl_type::uint_type), \
  827. _##NAME(v130, glsl_type::uvec2_type, glsl_type::uint_type), \
  828. _##NAME(v130, glsl_type::uvec3_type, glsl_type::uint_type), \
  829. _##NAME(v130, glsl_type::uvec4_type, glsl_type::uint_type), \
  830. \
  831. _##NAME(v130, glsl_type::uvec2_type, glsl_type::uvec2_type), \
  832. _##NAME(v130, glsl_type::uvec3_type, glsl_type::uvec3_type), \
  833. _##NAME(v130, glsl_type::uvec4_type, glsl_type::uvec4_type), \
  834. NULL);
  835. F(radians)
  836. F(degrees)
  837. F(sin)
  838. F(cos)
  839. F(tan)
  840. F(asin)
  841. F(acos)
  842. add_function("atan",
  843. _atan(glsl_type::float_type),
  844. _atan(glsl_type::vec2_type),
  845. _atan(glsl_type::vec3_type),
  846. _atan(glsl_type::vec4_type),
  847. _atan2(glsl_type::float_type),
  848. _atan2(glsl_type::vec2_type),
  849. _atan2(glsl_type::vec3_type),
  850. _atan2(glsl_type::vec4_type),
  851. NULL);
  852. F(sinh)
  853. F(cosh)
  854. F(tanh)
  855. F(asinh)
  856. F(acosh)
  857. F(atanh)
  858. F(pow)
  859. F(exp)
  860. F(log)
  861. F(exp2)
  862. F(log2)
  863. F(sqrt)
  864. F(inversesqrt)
  865. FI(abs)
  866. FI(sign)
  867. F(floor)
  868. F(trunc)
  869. F(round)
  870. F(roundEven)
  871. F(ceil)
  872. F(fract)
  873. add_function("mod",
  874. _mod(glsl_type::float_type, glsl_type::float_type),
  875. _mod(glsl_type::vec2_type, glsl_type::float_type),
  876. _mod(glsl_type::vec3_type, glsl_type::float_type),
  877. _mod(glsl_type::vec4_type, glsl_type::float_type),
  878. _mod(glsl_type::vec2_type, glsl_type::vec2_type),
  879. _mod(glsl_type::vec3_type, glsl_type::vec3_type),
  880. _mod(glsl_type::vec4_type, glsl_type::vec4_type),
  881. NULL);
  882. F(modf)
  883. FIU2_MIXED(min)
  884. FIU2_MIXED(max)
  885. FIU2_MIXED(clamp)
  886. add_function("mix",
  887. _mix_lrp(glsl_type::float_type, glsl_type::float_type),
  888. _mix_lrp(glsl_type::vec2_type, glsl_type::float_type),
  889. _mix_lrp(glsl_type::vec3_type, glsl_type::float_type),
  890. _mix_lrp(glsl_type::vec4_type, glsl_type::float_type),
  891. _mix_lrp(glsl_type::vec2_type, glsl_type::vec2_type),
  892. _mix_lrp(glsl_type::vec3_type, glsl_type::vec3_type),
  893. _mix_lrp(glsl_type::vec4_type, glsl_type::vec4_type),
  894. _mix_sel(v130, glsl_type::float_type, glsl_type::bool_type),
  895. _mix_sel(v130, glsl_type::vec2_type, glsl_type::bvec2_type),
  896. _mix_sel(v130, glsl_type::vec3_type, glsl_type::bvec3_type),
  897. _mix_sel(v130, glsl_type::vec4_type, glsl_type::bvec4_type),
  898. _mix_sel(shader_integer_mix, glsl_type::int_type, glsl_type::bool_type),
  899. _mix_sel(shader_integer_mix, glsl_type::ivec2_type, glsl_type::bvec2_type),
  900. _mix_sel(shader_integer_mix, glsl_type::ivec3_type, glsl_type::bvec3_type),
  901. _mix_sel(shader_integer_mix, glsl_type::ivec4_type, glsl_type::bvec4_type),
  902. _mix_sel(shader_integer_mix, glsl_type::uint_type, glsl_type::bool_type),
  903. _mix_sel(shader_integer_mix, glsl_type::uvec2_type, glsl_type::bvec2_type),
  904. _mix_sel(shader_integer_mix, glsl_type::uvec3_type, glsl_type::bvec3_type),
  905. _mix_sel(shader_integer_mix, glsl_type::uvec4_type, glsl_type::bvec4_type),
  906. _mix_sel(shader_integer_mix, glsl_type::bool_type, glsl_type::bool_type),
  907. _mix_sel(shader_integer_mix, glsl_type::bvec2_type, glsl_type::bvec2_type),
  908. _mix_sel(shader_integer_mix, glsl_type::bvec3_type, glsl_type::bvec3_type),
  909. _mix_sel(shader_integer_mix, glsl_type::bvec4_type, glsl_type::bvec4_type),
  910. NULL);
  911. add_function("step",
  912. _step(glsl_type::float_type, glsl_type::float_type),
  913. _step(glsl_type::float_type, glsl_type::vec2_type),
  914. _step(glsl_type::float_type, glsl_type::vec3_type),
  915. _step(glsl_type::float_type, glsl_type::vec4_type),
  916. _step(glsl_type::vec2_type, glsl_type::vec2_type),
  917. _step(glsl_type::vec3_type, glsl_type::vec3_type),
  918. _step(glsl_type::vec4_type, glsl_type::vec4_type),
  919. NULL);
  920. add_function("smoothstep",
  921. _smoothstep(glsl_type::float_type, glsl_type::float_type),
  922. _smoothstep(glsl_type::float_type, glsl_type::vec2_type),
  923. _smoothstep(glsl_type::float_type, glsl_type::vec3_type),
  924. _smoothstep(glsl_type::float_type, glsl_type::vec4_type),
  925. _smoothstep(glsl_type::vec2_type, glsl_type::vec2_type),
  926. _smoothstep(glsl_type::vec3_type, glsl_type::vec3_type),
  927. _smoothstep(glsl_type::vec4_type, glsl_type::vec4_type),
  928. NULL);
  929. F(isnan)
  930. F(isinf)
  931. F(floatBitsToInt)
  932. F(floatBitsToUint)
  933. add_function("intBitsToFloat",
  934. _intBitsToFloat(glsl_type::int_type),
  935. _intBitsToFloat(glsl_type::ivec2_type),
  936. _intBitsToFloat(glsl_type::ivec3_type),
  937. _intBitsToFloat(glsl_type::ivec4_type),
  938. NULL);
  939. add_function("uintBitsToFloat",
  940. _uintBitsToFloat(glsl_type::uint_type),
  941. _uintBitsToFloat(glsl_type::uvec2_type),
  942. _uintBitsToFloat(glsl_type::uvec3_type),
  943. _uintBitsToFloat(glsl_type::uvec4_type),
  944. NULL);
  945. add_function("packUnorm2x16", _packUnorm2x16(shader_packing_or_es3_or_gpu_shader5), NULL);
  946. add_function("packSnorm2x16", _packSnorm2x16(shader_packing_or_es3), NULL);
  947. add_function("packUnorm4x8", _packUnorm4x8(shader_packing_or_gpu_shader5), NULL);
  948. add_function("packSnorm4x8", _packSnorm4x8(shader_packing_or_gpu_shader5), NULL);
  949. add_function("unpackUnorm2x16", _unpackUnorm2x16(shader_packing_or_es3_or_gpu_shader5), NULL);
  950. add_function("unpackSnorm2x16", _unpackSnorm2x16(shader_packing_or_es3), NULL);
  951. add_function("unpackUnorm4x8", _unpackUnorm4x8(shader_packing_or_gpu_shader5), NULL);
  952. add_function("unpackSnorm4x8", _unpackSnorm4x8(shader_packing_or_gpu_shader5), NULL);
  953. add_function("packHalf2x16", _packHalf2x16(shader_packing_or_es3), NULL);
  954. add_function("unpackHalf2x16", _unpackHalf2x16(shader_packing_or_es3), NULL);
  955. F(length)
  956. F(distance)
  957. F(dot)
  958. add_function("cross", _cross(glsl_type::vec3_type), NULL);
  959. F(normalize)
  960. add_function("ftransform", _ftransform(), NULL);
  961. F(faceforward)
  962. F(reflect)
  963. F(refract)
  964. // ...
  965. add_function("matrixCompMult",
  966. _matrixCompMult(glsl_type::mat2_type),
  967. _matrixCompMult(glsl_type::mat3_type),
  968. _matrixCompMult(glsl_type::mat4_type),
  969. _matrixCompMult(glsl_type::mat2x3_type),
  970. _matrixCompMult(glsl_type::mat2x4_type),
  971. _matrixCompMult(glsl_type::mat3x2_type),
  972. _matrixCompMult(glsl_type::mat3x4_type),
  973. _matrixCompMult(glsl_type::mat4x2_type),
  974. _matrixCompMult(glsl_type::mat4x3_type),
  975. NULL);
  976. add_function("outerProduct",
  977. _outerProduct(glsl_type::mat2_type),
  978. _outerProduct(glsl_type::mat3_type),
  979. _outerProduct(glsl_type::mat4_type),
  980. _outerProduct(glsl_type::mat2x3_type),
  981. _outerProduct(glsl_type::mat2x4_type),
  982. _outerProduct(glsl_type::mat3x2_type),
  983. _outerProduct(glsl_type::mat3x4_type),
  984. _outerProduct(glsl_type::mat4x2_type),
  985. _outerProduct(glsl_type::mat4x3_type),
  986. NULL);
  987. add_function("determinant",
  988. _determinant_mat2(),
  989. _determinant_mat3(),
  990. _determinant_mat4(),
  991. NULL);
  992. add_function("inverse",
  993. _inverse_mat2(),
  994. _inverse_mat3(),
  995. _inverse_mat4(),
  996. NULL);
  997. add_function("transpose",
  998. _transpose(glsl_type::mat2_type),
  999. _transpose(glsl_type::mat3_type),
  1000. _transpose(glsl_type::mat4_type),
  1001. _transpose(glsl_type::mat2x3_type),
  1002. _transpose(glsl_type::mat2x4_type),
  1003. _transpose(glsl_type::mat3x2_type),
  1004. _transpose(glsl_type::mat3x4_type),
  1005. _transpose(glsl_type::mat4x2_type),
  1006. _transpose(glsl_type::mat4x3_type),
  1007. NULL);
  1008. FIU(lessThan)
  1009. FIU(lessThanEqual)
  1010. FIU(greaterThan)
  1011. FIU(greaterThanEqual)
  1012. FIUB(notEqual)
  1013. FIUB(equal)
  1014. add_function("any",
  1015. _any(glsl_type::bvec2_type),
  1016. _any(glsl_type::bvec3_type),
  1017. _any(glsl_type::bvec4_type),
  1018. NULL);
  1019. add_function("all",
  1020. _all(glsl_type::bvec2_type),
  1021. _all(glsl_type::bvec3_type),
  1022. _all(glsl_type::bvec4_type),
  1023. NULL);
  1024. add_function("not",
  1025. _not(glsl_type::bvec2_type),
  1026. _not(glsl_type::bvec3_type),
  1027. _not(glsl_type::bvec4_type),
  1028. NULL);
  1029. add_function("textureSize",
  1030. _textureSize(v130, glsl_type::int_type, glsl_type::sampler1D_type),
  1031. _textureSize(v130, glsl_type::int_type, glsl_type::isampler1D_type),
  1032. _textureSize(v130, glsl_type::int_type, glsl_type::usampler1D_type),
  1033. _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler2D_type),
  1034. _textureSize(v130, glsl_type::ivec2_type, glsl_type::isampler2D_type),
  1035. _textureSize(v130, glsl_type::ivec2_type, glsl_type::usampler2D_type),
  1036. _textureSize(v130, glsl_type::ivec3_type, glsl_type::sampler3D_type),
  1037. _textureSize(v130, glsl_type::ivec3_type, glsl_type::isampler3D_type),
  1038. _textureSize(v130, glsl_type::ivec3_type, glsl_type::usampler3D_type),
  1039. _textureSize(v130, glsl_type::ivec2_type, glsl_type::samplerCube_type),
  1040. _textureSize(v130, glsl_type::ivec2_type, glsl_type::isamplerCube_type),
  1041. _textureSize(v130, glsl_type::ivec2_type, glsl_type::usamplerCube_type),
  1042. _textureSize(v130, glsl_type::int_type, glsl_type::sampler1DShadow_type),
  1043. _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler2DShadow_type),
  1044. _textureSize(v130, glsl_type::ivec2_type, glsl_type::samplerCubeShadow_type),
  1045. _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler1DArray_type),
  1046. _textureSize(v130, glsl_type::ivec2_type, glsl_type::isampler1DArray_type),
  1047. _textureSize(v130, glsl_type::ivec2_type, glsl_type::usampler1DArray_type),
  1048. _textureSize(v130, glsl_type::ivec3_type, glsl_type::sampler2DArray_type),
  1049. _textureSize(v130, glsl_type::ivec3_type, glsl_type::isampler2DArray_type),
  1050. _textureSize(v130, glsl_type::ivec3_type, glsl_type::usampler2DArray_type),
  1051. _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler1DArrayShadow_type),
  1052. _textureSize(v130, glsl_type::ivec3_type, glsl_type::sampler2DArrayShadow_type),
  1053. _textureSize(texture_cube_map_array, glsl_type::ivec3_type, glsl_type::samplerCubeArray_type),
  1054. _textureSize(texture_cube_map_array, glsl_type::ivec3_type, glsl_type::isamplerCubeArray_type),
  1055. _textureSize(texture_cube_map_array, glsl_type::ivec3_type, glsl_type::usamplerCubeArray_type),
  1056. _textureSize(texture_cube_map_array, glsl_type::ivec3_type, glsl_type::samplerCubeArrayShadow_type),
  1057. _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler2DRect_type),
  1058. _textureSize(v130, glsl_type::ivec2_type, glsl_type::isampler2DRect_type),
  1059. _textureSize(v130, glsl_type::ivec2_type, glsl_type::usampler2DRect_type),
  1060. _textureSize(v130, glsl_type::ivec2_type, glsl_type::sampler2DRectShadow_type),
  1061. _textureSize(v140, glsl_type::int_type, glsl_type::samplerBuffer_type),
  1062. _textureSize(v140, glsl_type::int_type, glsl_type::isamplerBuffer_type),
  1063. _textureSize(v140, glsl_type::int_type, glsl_type::usamplerBuffer_type),
  1064. _textureSize(texture_multisample, glsl_type::ivec2_type, glsl_type::sampler2DMS_type),
  1065. _textureSize(texture_multisample, glsl_type::ivec2_type, glsl_type::isampler2DMS_type),
  1066. _textureSize(texture_multisample, glsl_type::ivec2_type, glsl_type::usampler2DMS_type),
  1067. _textureSize(texture_multisample, glsl_type::ivec3_type, glsl_type::sampler2DMSArray_type),
  1068. _textureSize(texture_multisample, glsl_type::ivec3_type, glsl_type::isampler2DMSArray_type),
  1069. _textureSize(texture_multisample, glsl_type::ivec3_type, glsl_type::usampler2DMSArray_type),
  1070. NULL);
  1071. add_function("texture",
  1072. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
  1073. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
  1074. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
  1075. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
  1076. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
  1077. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
  1078. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
  1079. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
  1080. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
  1081. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
  1082. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
  1083. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
  1084. _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
  1085. _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
  1086. _texture(ir_tex, v130, glsl_type::float_type, glsl_type::samplerCubeShadow_type, glsl_type::vec4_type),
  1087. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
  1088. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
  1089. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
  1090. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
  1091. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
  1092. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
  1093. _texture(ir_tex, texture_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
  1094. _texture(ir_tex, texture_cube_map_array, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
  1095. _texture(ir_tex, texture_cube_map_array, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
  1096. _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
  1097. _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
  1098. /* samplerCubeArrayShadow is special; it has an extra parameter
  1099. * for the shadow comparitor since there is no vec5 type.
  1100. */
  1101. _textureCubeArrayShadow(),
  1102. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
  1103. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type),
  1104. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type),
  1105. _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type),
  1106. _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
  1107. _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
  1108. _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
  1109. _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
  1110. _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
  1111. _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
  1112. _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
  1113. _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
  1114. _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
  1115. _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
  1116. _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
  1117. _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
  1118. _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
  1119. _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
  1120. _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::samplerCubeShadow_type, glsl_type::vec4_type),
  1121. _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
  1122. _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
  1123. _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
  1124. _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
  1125. _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
  1126. _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
  1127. _texture(ir_txb, fs_texture_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
  1128. _texture(ir_txb, fs_texture_cube_map_array, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
  1129. _texture(ir_txb, fs_texture_cube_map_array, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
  1130. _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
  1131. NULL);
  1132. add_function("textureLod",
  1133. _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
  1134. _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
  1135. _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
  1136. _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
  1137. _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
  1138. _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
  1139. _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
  1140. _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
  1141. _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
  1142. _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
  1143. _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
  1144. _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
  1145. _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
  1146. _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
  1147. _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
  1148. _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
  1149. _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
  1150. _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
  1151. _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
  1152. _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
  1153. _texture(ir_txl, texture_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
  1154. _texture(ir_txl, texture_cube_map_array, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
  1155. _texture(ir_txl, texture_cube_map_array, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
  1156. _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
  1157. NULL);
  1158. add_function("textureOffset",
  1159. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
  1160. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
  1161. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
  1162. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
  1163. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
  1164. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
  1165. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
  1166. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
  1167. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
  1168. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
  1169. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
  1170. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
  1171. _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type, TEX_OFFSET),
  1172. _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
  1173. _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
  1174. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
  1175. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
  1176. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
  1177. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
  1178. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
  1179. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
  1180. _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
  1181. _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
  1182. _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
  1183. _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
  1184. _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
  1185. _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
  1186. _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
  1187. _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
  1188. _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
  1189. _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
  1190. _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
  1191. _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
  1192. _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
  1193. _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
  1194. _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
  1195. _texture(ir_txb, v130_fs_only, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
  1196. _texture(ir_txb, v130_fs_only, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
  1197. _texture(ir_txb, v130_fs_only, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
  1198. _texture(ir_txb, v130_fs_only, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
  1199. NULL);
  1200. add_function("textureProj",
  1201. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
  1202. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
  1203. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
  1204. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
  1205. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
  1206. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
  1207. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
  1208. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
  1209. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
  1210. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
  1211. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
  1212. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
  1213. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
  1214. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
  1215. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
  1216. _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
  1217. _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
  1218. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
  1219. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
  1220. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
  1221. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
  1222. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
  1223. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
  1224. _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT),
  1225. _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
  1226. _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
  1227. _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
  1228. _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
  1229. _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
  1230. _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
  1231. _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
  1232. _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
  1233. _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
  1234. _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
  1235. _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
  1236. _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
  1237. _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
  1238. _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
  1239. _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
  1240. _texture(ir_txb, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
  1241. _texture(ir_txb, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
  1242. NULL);
  1243. add_function("texelFetch",
  1244. _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::int_type),
  1245. _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::int_type),
  1246. _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::int_type),
  1247. _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::ivec2_type),
  1248. _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::ivec2_type),
  1249. _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::ivec2_type),
  1250. _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::ivec3_type),
  1251. _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::ivec3_type),
  1252. _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::ivec3_type),
  1253. _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::ivec2_type),
  1254. _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::ivec2_type),
  1255. _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::ivec2_type),
  1256. _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::ivec2_type),
  1257. _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::ivec2_type),
  1258. _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::ivec2_type),
  1259. _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::ivec3_type),
  1260. _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::ivec3_type),
  1261. _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::ivec3_type),
  1262. _texelFetch(v140, glsl_type::vec4_type, glsl_type::samplerBuffer_type, glsl_type::int_type),
  1263. _texelFetch(v140, glsl_type::ivec4_type, glsl_type::isamplerBuffer_type, glsl_type::int_type),
  1264. _texelFetch(v140, glsl_type::uvec4_type, glsl_type::usamplerBuffer_type, glsl_type::int_type),
  1265. _texelFetch(texture_multisample, glsl_type::vec4_type, glsl_type::sampler2DMS_type, glsl_type::ivec2_type),
  1266. _texelFetch(texture_multisample, glsl_type::ivec4_type, glsl_type::isampler2DMS_type, glsl_type::ivec2_type),
  1267. _texelFetch(texture_multisample, glsl_type::uvec4_type, glsl_type::usampler2DMS_type, glsl_type::ivec2_type),
  1268. _texelFetch(texture_multisample, glsl_type::vec4_type, glsl_type::sampler2DMSArray_type, glsl_type::ivec3_type),
  1269. _texelFetch(texture_multisample, glsl_type::ivec4_type, glsl_type::isampler2DMSArray_type, glsl_type::ivec3_type),
  1270. _texelFetch(texture_multisample, glsl_type::uvec4_type, glsl_type::usampler2DMSArray_type, glsl_type::ivec3_type),
  1271. NULL);
  1272. add_function("texelFetchOffset",
  1273. _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::int_type, glsl_type::int_type),
  1274. _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::int_type, glsl_type::int_type),
  1275. _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::int_type, glsl_type::int_type),
  1276. _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
  1277. _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
  1278. _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
  1279. _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::ivec3_type, glsl_type::ivec3_type),
  1280. _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::ivec3_type, glsl_type::ivec3_type),
  1281. _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::ivec3_type, glsl_type::ivec3_type),
  1282. _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
  1283. _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
  1284. _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
  1285. _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::ivec2_type, glsl_type::int_type),
  1286. _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::ivec2_type, glsl_type::int_type),
  1287. _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::ivec2_type, glsl_type::int_type),
  1288. _texelFetch(v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::ivec3_type, glsl_type::ivec2_type),
  1289. _texelFetch(v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::ivec3_type, glsl_type::ivec2_type),
  1290. _texelFetch(v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::ivec3_type, glsl_type::ivec2_type),
  1291. NULL);
  1292. add_function("textureProjOffset",
  1293. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
  1294. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
  1295. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
  1296. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1297. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1298. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1299. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
  1300. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
  1301. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
  1302. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1303. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1304. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1305. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1306. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1307. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1308. _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1309. _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1310. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
  1311. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
  1312. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
  1313. _texture(ir_tex, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1314. _texture(ir_tex, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1315. _texture(ir_tex, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1316. _texture(ir_tex, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1317. _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
  1318. _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
  1319. _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
  1320. _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1321. _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1322. _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1323. _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
  1324. _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
  1325. _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
  1326. _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1327. _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1328. _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1329. _texture(ir_txb, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1330. _texture(ir_txb, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1331. _texture(ir_txb, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1332. _texture(ir_txb, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1333. _texture(ir_txb, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1334. NULL);
  1335. add_function("textureLodOffset",
  1336. _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
  1337. _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
  1338. _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
  1339. _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
  1340. _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
  1341. _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
  1342. _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
  1343. _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
  1344. _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
  1345. _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
  1346. _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
  1347. _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
  1348. _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
  1349. _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
  1350. _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
  1351. _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
  1352. _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
  1353. _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
  1354. NULL);
  1355. add_function("textureProjLod",
  1356. _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
  1357. _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
  1358. _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
  1359. _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
  1360. _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
  1361. _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
  1362. _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
  1363. _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
  1364. _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
  1365. _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
  1366. _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
  1367. _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
  1368. _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
  1369. _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
  1370. _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
  1371. _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
  1372. _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
  1373. NULL);
  1374. add_function("textureProjLodOffset",
  1375. _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
  1376. _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
  1377. _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
  1378. _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1379. _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1380. _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1381. _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
  1382. _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
  1383. _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
  1384. _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1385. _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1386. _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1387. _texture(ir_txl, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1388. _texture(ir_txl, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1389. _texture(ir_txl, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1390. _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1391. _texture(ir_txl, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1392. NULL);
  1393. add_function("textureGrad",
  1394. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
  1395. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type),
  1396. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type),
  1397. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
  1398. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
  1399. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
  1400. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
  1401. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type),
  1402. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type),
  1403. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
  1404. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
  1405. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
  1406. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
  1407. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type),
  1408. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type),
  1409. _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type),
  1410. _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
  1411. _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
  1412. _texture(ir_txd, v130, glsl_type::float_type, glsl_type::samplerCubeShadow_type, glsl_type::vec4_type),
  1413. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
  1414. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type),
  1415. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type),
  1416. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
  1417. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
  1418. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
  1419. _texture(ir_txd, texture_cube_map_array, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
  1420. _texture(ir_txd, texture_cube_map_array, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
  1421. _texture(ir_txd, texture_cube_map_array, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
  1422. _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
  1423. _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
  1424. NULL);
  1425. add_function("textureGradOffset",
  1426. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type, TEX_OFFSET),
  1427. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::float_type, TEX_OFFSET),
  1428. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::float_type, TEX_OFFSET),
  1429. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
  1430. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
  1431. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
  1432. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
  1433. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
  1434. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec3_type, TEX_OFFSET),
  1435. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
  1436. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
  1437. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET),
  1438. _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type, TEX_OFFSET),
  1439. _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
  1440. _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type, TEX_OFFSET),
  1441. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
  1442. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
  1443. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1DArray_type, glsl_type::vec2_type, TEX_OFFSET),
  1444. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
  1445. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
  1446. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
  1447. _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET),
  1448. _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type, TEX_OFFSET),
  1449. NULL);
  1450. add_function("textureProjGrad",
  1451. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
  1452. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
  1453. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
  1454. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
  1455. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
  1456. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
  1457. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
  1458. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
  1459. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
  1460. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
  1461. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
  1462. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
  1463. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
  1464. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
  1465. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
  1466. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
  1467. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
  1468. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
  1469. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
  1470. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
  1471. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
  1472. _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT),
  1473. _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
  1474. _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
  1475. NULL);
  1476. add_function("textureProjGradOffset",
  1477. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
  1478. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
  1479. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec2_type, TEX_PROJECT | TEX_OFFSET),
  1480. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1481. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1482. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler1D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1483. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
  1484. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
  1485. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
  1486. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1487. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1488. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1489. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1490. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1491. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler3D_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1492. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
  1493. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
  1494. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT | TEX_OFFSET),
  1495. _texture(ir_txd, v130, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1496. _texture(ir_txd, v130, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1497. _texture(ir_txd, v130, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1498. _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1499. _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1500. _texture(ir_txd, v130, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT | TEX_OFFSET),
  1501. NULL);
  1502. add_function("EmitVertex", _EmitVertex(), NULL);
  1503. add_function("EndPrimitive", _EndPrimitive(), NULL);
  1504. add_function("EmitStreamVertex",
  1505. _EmitStreamVertex(gs_streams, glsl_type::uint_type),
  1506. _EmitStreamVertex(gs_streams, glsl_type::int_type),
  1507. NULL);
  1508. add_function("EndStreamPrimitive",
  1509. _EndStreamPrimitive(gs_streams, glsl_type::uint_type),
  1510. _EndStreamPrimitive(gs_streams, glsl_type::int_type),
  1511. NULL);
  1512. add_function("textureQueryLOD",
  1513. _textureQueryLod(glsl_type::sampler1D_type, glsl_type::float_type),
  1514. _textureQueryLod(glsl_type::isampler1D_type, glsl_type::float_type),
  1515. _textureQueryLod(glsl_type::usampler1D_type, glsl_type::float_type),
  1516. _textureQueryLod(glsl_type::sampler2D_type, glsl_type::vec2_type),
  1517. _textureQueryLod(glsl_type::isampler2D_type, glsl_type::vec2_type),
  1518. _textureQueryLod(glsl_type::usampler2D_type, glsl_type::vec2_type),
  1519. _textureQueryLod(glsl_type::sampler3D_type, glsl_type::vec3_type),
  1520. _textureQueryLod(glsl_type::isampler3D_type, glsl_type::vec3_type),
  1521. _textureQueryLod(glsl_type::usampler3D_type, glsl_type::vec3_type),
  1522. _textureQueryLod(glsl_type::samplerCube_type, glsl_type::vec3_type),
  1523. _textureQueryLod(glsl_type::isamplerCube_type, glsl_type::vec3_type),
  1524. _textureQueryLod(glsl_type::usamplerCube_type, glsl_type::vec3_type),
  1525. _textureQueryLod(glsl_type::sampler1DArray_type, glsl_type::float_type),
  1526. _textureQueryLod(glsl_type::isampler1DArray_type, glsl_type::float_type),
  1527. _textureQueryLod(glsl_type::usampler1DArray_type, glsl_type::float_type),
  1528. _textureQueryLod(glsl_type::sampler2DArray_type, glsl_type::vec2_type),
  1529. _textureQueryLod(glsl_type::isampler2DArray_type, glsl_type::vec2_type),
  1530. _textureQueryLod(glsl_type::usampler2DArray_type, glsl_type::vec2_type),
  1531. _textureQueryLod(glsl_type::samplerCubeArray_type, glsl_type::vec3_type),
  1532. _textureQueryLod(glsl_type::isamplerCubeArray_type, glsl_type::vec3_type),
  1533. _textureQueryLod(glsl_type::usamplerCubeArray_type, glsl_type::vec3_type),
  1534. _textureQueryLod(glsl_type::sampler1DShadow_type, glsl_type::float_type),
  1535. _textureQueryLod(glsl_type::sampler2DShadow_type, glsl_type::vec2_type),
  1536. _textureQueryLod(glsl_type::samplerCubeShadow_type, glsl_type::vec3_type),
  1537. _textureQueryLod(glsl_type::sampler1DArrayShadow_type, glsl_type::float_type),
  1538. _textureQueryLod(glsl_type::sampler2DArrayShadow_type, glsl_type::vec2_type),
  1539. _textureQueryLod(glsl_type::samplerCubeArrayShadow_type, glsl_type::vec3_type),
  1540. NULL);
  1541. add_function("textureQueryLevels",
  1542. _textureQueryLevels(glsl_type::sampler1D_type),
  1543. _textureQueryLevels(glsl_type::sampler2D_type),
  1544. _textureQueryLevels(glsl_type::sampler3D_type),
  1545. _textureQueryLevels(glsl_type::samplerCube_type),
  1546. _textureQueryLevels(glsl_type::sampler1DArray_type),
  1547. _textureQueryLevels(glsl_type::sampler2DArray_type),
  1548. _textureQueryLevels(glsl_type::samplerCubeArray_type),
  1549. _textureQueryLevels(glsl_type::sampler1DShadow_type),
  1550. _textureQueryLevels(glsl_type::sampler2DShadow_type),
  1551. _textureQueryLevels(glsl_type::samplerCubeShadow_type),
  1552. _textureQueryLevels(glsl_type::sampler1DArrayShadow_type),
  1553. _textureQueryLevels(glsl_type::sampler2DArrayShadow_type),
  1554. _textureQueryLevels(glsl_type::samplerCubeArrayShadow_type),
  1555. _textureQueryLevels(glsl_type::isampler1D_type),
  1556. _textureQueryLevels(glsl_type::isampler2D_type),
  1557. _textureQueryLevels(glsl_type::isampler3D_type),
  1558. _textureQueryLevels(glsl_type::isamplerCube_type),
  1559. _textureQueryLevels(glsl_type::isampler1DArray_type),
  1560. _textureQueryLevels(glsl_type::isampler2DArray_type),
  1561. _textureQueryLevels(glsl_type::isamplerCubeArray_type),
  1562. _textureQueryLevels(glsl_type::usampler1D_type),
  1563. _textureQueryLevels(glsl_type::usampler2D_type),
  1564. _textureQueryLevels(glsl_type::usampler3D_type),
  1565. _textureQueryLevels(glsl_type::usamplerCube_type),
  1566. _textureQueryLevels(glsl_type::usampler1DArray_type),
  1567. _textureQueryLevels(glsl_type::usampler2DArray_type),
  1568. _textureQueryLevels(glsl_type::usamplerCubeArray_type),
  1569. NULL);
  1570. add_function("texture1D",
  1571. _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
  1572. _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
  1573. NULL);
  1574. add_function("texture1DArray",
  1575. _texture(ir_tex, texture_array, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
  1576. _texture(ir_txb, fs_texture_array, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
  1577. NULL);
  1578. add_function("texture1DProj",
  1579. _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
  1580. _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
  1581. _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
  1582. _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
  1583. NULL);
  1584. add_function("texture1DLod",
  1585. _texture(ir_txl, tex1d_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
  1586. NULL);
  1587. add_function("texture1DArrayLod",
  1588. _texture(ir_txl, texture_array_lod, glsl_type::vec4_type, glsl_type::sampler1DArray_type, glsl_type::vec2_type),
  1589. NULL);
  1590. add_function("texture1DProjLod",
  1591. _texture(ir_txl, tex1d_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
  1592. _texture(ir_txl, tex1d_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
  1593. NULL);
  1594. add_function("texture2D",
  1595. _texture(ir_tex, always_available, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
  1596. _texture(ir_txb, fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
  1597. _texture(ir_tex, texture_external, glsl_type::vec4_type, glsl_type::samplerExternalOES_type, glsl_type::vec2_type),
  1598. NULL);
  1599. add_function("texture2DArray",
  1600. _texture(ir_tex, texture_array, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
  1601. _texture(ir_txb, fs_texture_array, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
  1602. NULL);
  1603. add_function("texture2DProj",
  1604. _texture(ir_tex, always_available, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
  1605. _texture(ir_tex, always_available, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
  1606. _texture(ir_txb, fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
  1607. _texture(ir_txb, fs_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
  1608. _texture(ir_tex, texture_external, glsl_type::vec4_type, glsl_type::samplerExternalOES_type, glsl_type::vec3_type, TEX_PROJECT),
  1609. _texture(ir_tex, texture_external, glsl_type::vec4_type, glsl_type::samplerExternalOES_type, glsl_type::vec4_type, TEX_PROJECT),
  1610. NULL);
  1611. add_function("texture2DLod",
  1612. _texture(ir_txl, lod_exists_in_stage, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
  1613. NULL);
  1614. add_function("texture2DArrayLod",
  1615. _texture(ir_txl, texture_array_lod, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
  1616. NULL);
  1617. add_function("texture2DProjLod",
  1618. _texture(ir_txl, lod_exists_in_stage, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
  1619. _texture(ir_txl, lod_exists_in_stage, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
  1620. NULL);
  1621. add_function("texture3D",
  1622. _texture(ir_tex, tex3d, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
  1623. _texture(ir_txb, fs_tex3d, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
  1624. NULL);
  1625. add_function("texture3DProj",
  1626. _texture(ir_tex, tex3d, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
  1627. _texture(ir_txb, fs_tex3d, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
  1628. NULL);
  1629. add_function("texture3DLod",
  1630. _texture(ir_txl, tex3d_lod, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
  1631. NULL);
  1632. add_function("texture3DProjLod",
  1633. _texture(ir_txl, tex3d_lod, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
  1634. NULL);
  1635. add_function("textureCube",
  1636. _texture(ir_tex, always_available, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
  1637. _texture(ir_txb, fs_only, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
  1638. NULL);
  1639. add_function("textureCubeLod",
  1640. _texture(ir_txl, lod_exists_in_stage, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
  1641. NULL);
  1642. add_function("texture2DRect",
  1643. _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
  1644. NULL);
  1645. add_function("texture2DRectProj",
  1646. _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
  1647. _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
  1648. NULL);
  1649. add_function("texture2DLodEXT",
  1650. _texture(ir_txl, es_lod_exists_in_stage, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
  1651. NULL);
  1652. add_function("texture2DProjLodEXT",
  1653. _texture(ir_txl, es_lod_exists_in_stage, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
  1654. _texture(ir_txl, es_lod_exists_in_stage, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
  1655. NULL);
  1656. add_function("textureCubeLodEXT",
  1657. _texture(ir_txl, es_lod_exists_in_stage, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
  1658. NULL);
  1659. add_function("shadow1D",
  1660. _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
  1661. _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
  1662. NULL);
  1663. add_function("shadow1DArray",
  1664. _texture(ir_tex, texture_array, glsl_type::vec4_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
  1665. _texture(ir_txb, fs_texture_array, glsl_type::vec4_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
  1666. NULL);
  1667. add_function("shadow2D",
  1668. _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
  1669. _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
  1670. NULL);
  1671. add_function("shadow2DEXT",
  1672. _texture(ir_tex, es_shadow_samplers, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
  1673. NULL);
  1674. add_function("shadow2DArray",
  1675. _texture(ir_tex, texture_array, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
  1676. _texture(ir_txb, fs_texture_array, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec4_type),
  1677. NULL);
  1678. add_function("shadow1DProj",
  1679. _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
  1680. _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
  1681. NULL);
  1682. add_function("shadow2DProj",
  1683. _texture(ir_tex, v110, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
  1684. _texture(ir_txb, v110_fs_only, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
  1685. NULL);
  1686. add_function("shadow2DProjEXT",
  1687. _texture(ir_tex, es_shadow_samplers, glsl_type::float_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
  1688. NULL);
  1689. add_function("shadow1DLod",
  1690. _texture(ir_txl, v110_lod, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
  1691. NULL);
  1692. add_function("shadow2DLod",
  1693. _texture(ir_txl, v110_lod, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
  1694. NULL);
  1695. add_function("shadow1DArrayLod",
  1696. _texture(ir_txl, texture_array_lod, glsl_type::vec4_type, glsl_type::sampler1DArrayShadow_type, glsl_type::vec3_type),
  1697. NULL);
  1698. add_function("shadow1DProjLod",
  1699. _texture(ir_txl, v110_lod, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
  1700. NULL);
  1701. add_function("shadow2DProjLod",
  1702. _texture(ir_txl, v110_lod, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
  1703. NULL);
  1704. add_function("shadow2DRect",
  1705. _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type),
  1706. NULL);
  1707. add_function("shadow2DRectProj",
  1708. _texture(ir_tex, texture_rectangle, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT),
  1709. NULL);
  1710. add_function("texture1DGradARB",
  1711. _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::float_type),
  1712. NULL);
  1713. add_function("texture1DProjGradARB",
  1714. _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec2_type, TEX_PROJECT),
  1715. _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1D_type, glsl_type::vec4_type, TEX_PROJECT),
  1716. NULL);
  1717. add_function("texture2DGradARB",
  1718. _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
  1719. NULL);
  1720. add_function("texture2DProjGradARB",
  1721. _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
  1722. _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
  1723. NULL);
  1724. add_function("texture3DGradARB",
  1725. _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec3_type),
  1726. NULL);
  1727. add_function("texture3DProjGradARB",
  1728. _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler3D_type, glsl_type::vec4_type, TEX_PROJECT),
  1729. NULL);
  1730. add_function("textureCubeGradARB",
  1731. _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
  1732. NULL);
  1733. add_function("texture2DGradEXT",
  1734. _texture(ir_txd, es_shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
  1735. NULL);
  1736. add_function("texture2DProjGradEXT",
  1737. _texture(ir_txd, es_shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec3_type, TEX_PROJECT),
  1738. _texture(ir_txd, es_shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec4_type, TEX_PROJECT),
  1739. NULL);
  1740. add_function("textureCubeGradEXT",
  1741. _texture(ir_txd, es_shader_texture_lod, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
  1742. NULL);
  1743. add_function("shadow1DGradARB",
  1744. _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec3_type),
  1745. NULL);
  1746. add_function("shadow1DProjGradARB",
  1747. _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler1DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
  1748. NULL);
  1749. add_function("shadow2DGradARB",
  1750. _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec3_type),
  1751. NULL);
  1752. add_function("shadow2DProjGradARB",
  1753. _texture(ir_txd, shader_texture_lod, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec4_type, TEX_PROJECT),
  1754. NULL);
  1755. add_function("texture2DRectGradARB",
  1756. _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
  1757. NULL);
  1758. add_function("texture2DRectProjGradARB",
  1759. _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec3_type, TEX_PROJECT),
  1760. _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec4_type, TEX_PROJECT),
  1761. NULL);
  1762. add_function("shadow2DRectGradARB",
  1763. _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec3_type),
  1764. NULL);
  1765. add_function("shadow2DRectProjGradARB",
  1766. _texture(ir_txd, shader_texture_lod_and_rect, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec4_type, TEX_PROJECT),
  1767. NULL);
  1768. add_function("textureGather",
  1769. _texture(ir_tg4, texture_gather, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type),
  1770. _texture(ir_tg4, texture_gather, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type),
  1771. _texture(ir_tg4, texture_gather, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type),
  1772. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type),
  1773. _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type),
  1774. _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type),
  1775. _texture(ir_tg4, texture_gather, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type),
  1776. _texture(ir_tg4, texture_gather, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type),
  1777. _texture(ir_tg4, texture_gather, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type),
  1778. _texture(ir_tg4, texture_gather, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type),
  1779. _texture(ir_tg4, texture_gather, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type),
  1780. _texture(ir_tg4, texture_gather, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type),
  1781. _texture(ir_tg4, texture_gather, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type),
  1782. _texture(ir_tg4, texture_gather, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type),
  1783. _texture(ir_tg4, texture_gather, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type),
  1784. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_COMPONENT),
  1785. _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_COMPONENT),
  1786. _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_COMPONENT),
  1787. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_COMPONENT),
  1788. _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_COMPONENT),
  1789. _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_COMPONENT),
  1790. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_COMPONENT),
  1791. _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_COMPONENT),
  1792. _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_COMPONENT),
  1793. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::samplerCube_type, glsl_type::vec3_type, TEX_COMPONENT),
  1794. _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isamplerCube_type, glsl_type::vec3_type, TEX_COMPONENT),
  1795. _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usamplerCube_type, glsl_type::vec3_type, TEX_COMPONENT),
  1796. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::samplerCubeArray_type, glsl_type::vec4_type, TEX_COMPONENT),
  1797. _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isamplerCubeArray_type, glsl_type::vec4_type, TEX_COMPONENT),
  1798. _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usamplerCubeArray_type, glsl_type::vec4_type, TEX_COMPONENT),
  1799. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec2_type),
  1800. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec3_type),
  1801. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::samplerCubeShadow_type, glsl_type::vec3_type),
  1802. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::samplerCubeArrayShadow_type, glsl_type::vec4_type),
  1803. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec2_type),
  1804. NULL);
  1805. add_function("textureGatherOffset",
  1806. _texture(ir_tg4, texture_gather_only, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
  1807. _texture(ir_tg4, texture_gather_only, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
  1808. _texture(ir_tg4, texture_gather_only, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET),
  1809. _texture(ir_tg4, texture_gather_only, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
  1810. _texture(ir_tg4, texture_gather_only, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
  1811. _texture(ir_tg4, texture_gather_only, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET),
  1812. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
  1813. _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
  1814. _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
  1815. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST),
  1816. _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST),
  1817. _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST),
  1818. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
  1819. _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
  1820. _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
  1821. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
  1822. _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
  1823. _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
  1824. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
  1825. _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
  1826. _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
  1827. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
  1828. _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
  1829. _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST | TEX_COMPONENT),
  1830. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
  1831. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET_NONCONST),
  1832. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec2_type, TEX_OFFSET_NONCONST),
  1833. NULL);
  1834. add_function("textureGatherOffsets",
  1835. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
  1836. _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
  1837. _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
  1838. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
  1839. _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
  1840. _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2D_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
  1841. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY),
  1842. _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY),
  1843. _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY),
  1844. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
  1845. _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
  1846. _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DArray_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
  1847. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
  1848. _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
  1849. _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
  1850. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
  1851. _texture(ir_tg4, gpu_shader5, glsl_type::ivec4_type, glsl_type::isampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
  1852. _texture(ir_tg4, gpu_shader5, glsl_type::uvec4_type, glsl_type::usampler2DRect_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY | TEX_COMPONENT),
  1853. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DShadow_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
  1854. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DArrayShadow_type, glsl_type::vec3_type, TEX_OFFSET_ARRAY),
  1855. _texture(ir_tg4, gpu_shader5, glsl_type::vec4_type, glsl_type::sampler2DRectShadow_type, glsl_type::vec2_type, TEX_OFFSET_ARRAY),
  1856. NULL);
  1857. F(dFdx)
  1858. F(dFdy)
  1859. F(fwidth)
  1860. F(dFdxCoarse)
  1861. F(dFdyCoarse)
  1862. F(fwidthCoarse)
  1863. F(dFdxFine)
  1864. F(dFdyFine)
  1865. F(fwidthFine)
  1866. F(noise1)
  1867. F(noise2)
  1868. F(noise3)
  1869. F(noise4)
  1870. IU(bitfieldExtract)
  1871. IU(bitfieldInsert)
  1872. IU(bitfieldReverse)
  1873. IU(bitCount)
  1874. IU(findLSB)
  1875. IU(findMSB)
  1876. F(fma)
  1877. add_function("ldexp",
  1878. _ldexp(glsl_type::float_type, glsl_type::int_type),
  1879. _ldexp(glsl_type::vec2_type, glsl_type::ivec2_type),
  1880. _ldexp(glsl_type::vec3_type, glsl_type::ivec3_type),
  1881. _ldexp(glsl_type::vec4_type, glsl_type::ivec4_type),
  1882. NULL);
  1883. add_function("frexp",
  1884. _frexp(glsl_type::float_type, glsl_type::int_type),
  1885. _frexp(glsl_type::vec2_type, glsl_type::ivec2_type),
  1886. _frexp(glsl_type::vec3_type, glsl_type::ivec3_type),
  1887. _frexp(glsl_type::vec4_type, glsl_type::ivec4_type),
  1888. NULL);
  1889. add_function("uaddCarry",
  1890. _uaddCarry(glsl_type::uint_type),
  1891. _uaddCarry(glsl_type::uvec2_type),
  1892. _uaddCarry(glsl_type::uvec3_type),
  1893. _uaddCarry(glsl_type::uvec4_type),
  1894. NULL);
  1895. add_function("usubBorrow",
  1896. _usubBorrow(glsl_type::uint_type),
  1897. _usubBorrow(glsl_type::uvec2_type),
  1898. _usubBorrow(glsl_type::uvec3_type),
  1899. _usubBorrow(glsl_type::uvec4_type),
  1900. NULL);
  1901. add_function("imulExtended",
  1902. _mulExtended(glsl_type::int_type),
  1903. _mulExtended(glsl_type::ivec2_type),
  1904. _mulExtended(glsl_type::ivec3_type),
  1905. _mulExtended(glsl_type::ivec4_type),
  1906. NULL);
  1907. add_function("umulExtended",
  1908. _mulExtended(glsl_type::uint_type),
  1909. _mulExtended(glsl_type::uvec2_type),
  1910. _mulExtended(glsl_type::uvec3_type),
  1911. _mulExtended(glsl_type::uvec4_type),
  1912. NULL);
  1913. add_function("interpolateAtCentroid",
  1914. _interpolateAtCentroid(glsl_type::float_type),
  1915. _interpolateAtCentroid(glsl_type::vec2_type),
  1916. _interpolateAtCentroid(glsl_type::vec3_type),
  1917. _interpolateAtCentroid(glsl_type::vec4_type),
  1918. NULL);
  1919. add_function("interpolateAtOffset",
  1920. _interpolateAtOffset(glsl_type::float_type),
  1921. _interpolateAtOffset(glsl_type::vec2_type),
  1922. _interpolateAtOffset(glsl_type::vec3_type),
  1923. _interpolateAtOffset(glsl_type::vec4_type),
  1924. NULL);
  1925. add_function("interpolateAtSample",
  1926. _interpolateAtSample(glsl_type::float_type),
  1927. _interpolateAtSample(glsl_type::vec2_type),
  1928. _interpolateAtSample(glsl_type::vec3_type),
  1929. _interpolateAtSample(glsl_type::vec4_type),
  1930. NULL);
  1931. add_function("atomicCounter",
  1932. _atomic_op("__intrinsic_atomic_read",
  1933. shader_atomic_counters),
  1934. NULL);
  1935. add_function("atomicCounterIncrement",
  1936. _atomic_op("__intrinsic_atomic_increment",
  1937. shader_atomic_counters),
  1938. NULL);
  1939. add_function("atomicCounterDecrement",
  1940. _atomic_op("__intrinsic_atomic_predecrement",
  1941. shader_atomic_counters),
  1942. NULL);
  1943. add_function("min3",
  1944. _min3(glsl_type::float_type),
  1945. _min3(glsl_type::vec2_type),
  1946. _min3(glsl_type::vec3_type),
  1947. _min3(glsl_type::vec4_type),
  1948. _min3(glsl_type::int_type),
  1949. _min3(glsl_type::ivec2_type),
  1950. _min3(glsl_type::ivec3_type),
  1951. _min3(glsl_type::ivec4_type),
  1952. _min3(glsl_type::uint_type),
  1953. _min3(glsl_type::uvec2_type),
  1954. _min3(glsl_type::uvec3_type),
  1955. _min3(glsl_type::uvec4_type),
  1956. NULL);
  1957. add_function("max3",
  1958. _max3(glsl_type::float_type),
  1959. _max3(glsl_type::vec2_type),
  1960. _max3(glsl_type::vec3_type),
  1961. _max3(glsl_type::vec4_type),
  1962. _max3(glsl_type::int_type),
  1963. _max3(glsl_type::ivec2_type),
  1964. _max3(glsl_type::ivec3_type),
  1965. _max3(glsl_type::ivec4_type),
  1966. _max3(glsl_type::uint_type),
  1967. _max3(glsl_type::uvec2_type),
  1968. _max3(glsl_type::uvec3_type),
  1969. _max3(glsl_type::uvec4_type),
  1970. NULL);
  1971. add_function("mid3",
  1972. _mid3(glsl_type::float_type),
  1973. _mid3(glsl_type::vec2_type),
  1974. _mid3(glsl_type::vec3_type),
  1975. _mid3(glsl_type::vec4_type),
  1976. _mid3(glsl_type::int_type),
  1977. _mid3(glsl_type::ivec2_type),
  1978. _mid3(glsl_type::ivec3_type),
  1979. _mid3(glsl_type::ivec4_type),
  1980. _mid3(glsl_type::uint_type),
  1981. _mid3(glsl_type::uvec2_type),
  1982. _mid3(glsl_type::uvec3_type),
  1983. _mid3(glsl_type::uvec4_type),
  1984. NULL);
  1985. add_image_functions(true);
  1986. add_function("memoryBarrier",
  1987. _memory_barrier(shader_image_load_store),
  1988. NULL);
  1989. #undef F
  1990. #undef FI
  1991. #undef FIU
  1992. #undef FIUB
  1993. #undef FIU2_MIXED
  1994. }
  1995. void
  1996. builtin_builder::add_function(const char *name, ...)
  1997. {
  1998. va_list ap;
  1999. ir_function *f = new(mem_ctx) ir_function(name);
  2000. va_start(ap, name);
  2001. while (true) {
  2002. ir_function_signature *sig = va_arg(ap, ir_function_signature *);
  2003. if (sig == NULL)
  2004. break;
  2005. if (false) {
  2006. exec_list stuff;
  2007. stuff.push_tail(sig);
  2008. validate_ir_tree(&stuff);
  2009. }
  2010. f->add_signature(sig);
  2011. }
  2012. va_end(ap);
  2013. shader->symbols->add_function(f);
  2014. }
  2015. void
  2016. builtin_builder::add_image_function(const char *name,
  2017. const char *intrinsic_name,
  2018. unsigned num_arguments,
  2019. unsigned flags)
  2020. {
  2021. static const glsl_type *const types[] = {
  2022. glsl_type::image1D_type,
  2023. glsl_type::image2D_type,
  2024. glsl_type::image3D_type,
  2025. glsl_type::image2DRect_type,
  2026. glsl_type::imageCube_type,
  2027. glsl_type::imageBuffer_type,
  2028. glsl_type::image1DArray_type,
  2029. glsl_type::image2DArray_type,
  2030. glsl_type::imageCubeArray_type,
  2031. glsl_type::image2DMS_type,
  2032. glsl_type::image2DMSArray_type,
  2033. glsl_type::iimage1D_type,
  2034. glsl_type::iimage2D_type,
  2035. glsl_type::iimage3D_type,
  2036. glsl_type::iimage2DRect_type,
  2037. glsl_type::iimageCube_type,
  2038. glsl_type::iimageBuffer_type,
  2039. glsl_type::iimage1DArray_type,
  2040. glsl_type::iimage2DArray_type,
  2041. glsl_type::iimageCubeArray_type,
  2042. glsl_type::iimage2DMS_type,
  2043. glsl_type::iimage2DMSArray_type,
  2044. glsl_type::uimage1D_type,
  2045. glsl_type::uimage2D_type,
  2046. glsl_type::uimage3D_type,
  2047. glsl_type::uimage2DRect_type,
  2048. glsl_type::uimageCube_type,
  2049. glsl_type::uimageBuffer_type,
  2050. glsl_type::uimage1DArray_type,
  2051. glsl_type::uimage2DArray_type,
  2052. glsl_type::uimageCubeArray_type,
  2053. glsl_type::uimage2DMS_type,
  2054. glsl_type::uimage2DMSArray_type
  2055. };
  2056. ir_function *f = new(mem_ctx) ir_function(name);
  2057. for (unsigned i = 0; i < Elements(types); ++i) {
  2058. if (types[i]->sampler_type != GLSL_TYPE_FLOAT ||
  2059. (flags & IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE))
  2060. f->add_signature(_image(types[i], intrinsic_name,
  2061. num_arguments, flags));
  2062. }
  2063. shader->symbols->add_function(f);
  2064. }
  2065. void
  2066. builtin_builder::add_image_functions(bool glsl)
  2067. {
  2068. const unsigned flags = (glsl ? IMAGE_FUNCTION_EMIT_STUB : 0);
  2069. add_image_function(glsl ? "imageLoad" : "__intrinsic_image_load",
  2070. "__intrinsic_image_load", 0,
  2071. (flags | IMAGE_FUNCTION_HAS_VECTOR_DATA_TYPE |
  2072. IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE |
  2073. IMAGE_FUNCTION_READ_ONLY));
  2074. add_image_function(glsl ? "imageStore" : "__intrinsic_image_store",
  2075. "__intrinsic_image_store", 1,
  2076. (flags | IMAGE_FUNCTION_RETURNS_VOID |
  2077. IMAGE_FUNCTION_HAS_VECTOR_DATA_TYPE |
  2078. IMAGE_FUNCTION_SUPPORTS_FLOAT_DATA_TYPE |
  2079. IMAGE_FUNCTION_WRITE_ONLY));
  2080. add_image_function(glsl ? "imageAtomicAdd" : "__intrinsic_image_atomic_add",
  2081. "__intrinsic_image_atomic_add", 1, flags);
  2082. add_image_function(glsl ? "imageAtomicMin" : "__intrinsic_image_atomic_min",
  2083. "__intrinsic_image_atomic_min", 1, flags);
  2084. add_image_function(glsl ? "imageAtomicMax" : "__intrinsic_image_atomic_max",
  2085. "__intrinsic_image_atomic_max", 1, flags);
  2086. add_image_function(glsl ? "imageAtomicAnd" : "__intrinsic_image_atomic_and",
  2087. "__intrinsic_image_atomic_and", 1, flags);
  2088. add_image_function(glsl ? "imageAtomicOr" : "__intrinsic_image_atomic_or",
  2089. "__intrinsic_image_atomic_or", 1, flags);
  2090. add_image_function(glsl ? "imageAtomicXor" : "__intrinsic_image_atomic_xor",
  2091. "__intrinsic_image_atomic_xor", 1, flags);
  2092. add_image_function((glsl ? "imageAtomicExchange" :
  2093. "__intrinsic_image_atomic_exchange"),
  2094. "__intrinsic_image_atomic_exchange", 1, flags);
  2095. add_image_function((glsl ? "imageAtomicCompSwap" :
  2096. "__intrinsic_image_atomic_comp_swap"),
  2097. "__intrinsic_image_atomic_comp_swap", 2, flags);
  2098. }
  2099. ir_variable *
  2100. builtin_builder::in_var(const glsl_type *type, const char *name)
  2101. {
  2102. return new(mem_ctx) ir_variable(type, name, ir_var_function_in, glsl_precision_undefined);
  2103. }
  2104. ir_variable *
  2105. builtin_builder::out_var(const glsl_type *type, const char *name)
  2106. {
  2107. return new(mem_ctx) ir_variable(type, name, ir_var_function_out, glsl_precision_undefined);
  2108. }
  2109. ir_constant *
  2110. builtin_builder::imm(float f, unsigned vector_elements)
  2111. {
  2112. return new(mem_ctx) ir_constant(f, vector_elements);
  2113. }
  2114. ir_constant *
  2115. builtin_builder::imm(int i, unsigned vector_elements)
  2116. {
  2117. return new(mem_ctx) ir_constant(i, vector_elements);
  2118. }
  2119. ir_constant *
  2120. builtin_builder::imm(unsigned u, unsigned vector_elements)
  2121. {
  2122. return new(mem_ctx) ir_constant(u, vector_elements);
  2123. }
  2124. ir_constant *
  2125. builtin_builder::imm(const glsl_type *type, const ir_constant_data &data)
  2126. {
  2127. return new(mem_ctx) ir_constant(type, &data);
  2128. }
  2129. ir_dereference_variable *
  2130. builtin_builder::var_ref(ir_variable *var)
  2131. {
  2132. return new(mem_ctx) ir_dereference_variable(var);
  2133. }
  2134. ir_dereference_array *
  2135. builtin_builder::array_ref(ir_variable *var, int idx)
  2136. {
  2137. return new(mem_ctx) ir_dereference_array(var, imm(idx));
  2138. }
  2139. /** Return an element of a matrix */
  2140. ir_swizzle *
  2141. builtin_builder::matrix_elt(ir_variable *var, int column, int row)
  2142. {
  2143. return swizzle(array_ref(var, column), row, 1);
  2144. }
  2145. /**
  2146. * Implementations of built-in functions:
  2147. * @{
  2148. */
  2149. ir_function_signature *
  2150. builtin_builder::new_sig(const glsl_type *return_type,
  2151. builtin_available_predicate avail,
  2152. int num_params,
  2153. ...)
  2154. {
  2155. va_list ap;
  2156. ir_function_signature *sig =
  2157. new(mem_ctx) ir_function_signature(return_type, glsl_precision_undefined, avail);
  2158. exec_list plist;
  2159. va_start(ap, num_params);
  2160. for (int i = 0; i < num_params; i++) {
  2161. plist.push_tail(va_arg(ap, ir_variable *));
  2162. }
  2163. va_end(ap);
  2164. sig->replace_parameters(&plist);
  2165. return sig;
  2166. }
  2167. #define MAKE_SIG(return_type, avail, ...) \
  2168. ir_function_signature *sig = \
  2169. new_sig(return_type, avail, __VA_ARGS__); \
  2170. ir_factory body(&sig->body, mem_ctx); \
  2171. sig->is_defined = true;
  2172. #define MAKE_INTRINSIC(return_type, avail, ...) \
  2173. ir_function_signature *sig = \
  2174. new_sig(return_type, avail, __VA_ARGS__); \
  2175. sig->is_intrinsic = true;
  2176. ir_function_signature *
  2177. builtin_builder::unop(builtin_available_predicate avail,
  2178. ir_expression_operation opcode,
  2179. const glsl_type *return_type,
  2180. const glsl_type *param_type)
  2181. {
  2182. ir_variable *x = in_var(param_type, "x");
  2183. MAKE_SIG(return_type, avail, 1, x);
  2184. body.emit(ret(expr(opcode, x)));
  2185. return sig;
  2186. }
  2187. #define UNOP(NAME, OPCODE, AVAIL) \
  2188. ir_function_signature * \
  2189. builtin_builder::_##NAME(const glsl_type *type) \
  2190. { \
  2191. return unop(&AVAIL, OPCODE, type, type); \
  2192. }
  2193. ir_function_signature *
  2194. builtin_builder::binop(ir_expression_operation opcode,
  2195. builtin_available_predicate avail,
  2196. const glsl_type *return_type,
  2197. const glsl_type *param0_type,
  2198. const glsl_type *param1_type)
  2199. {
  2200. ir_variable *x = in_var(param0_type, "x");
  2201. ir_variable *y = in_var(param1_type, "y");
  2202. MAKE_SIG(return_type, avail, 2, x, y);
  2203. body.emit(ret(expr(opcode, x, y)));
  2204. return sig;
  2205. }
  2206. #define BINOP(NAME, OPCODE, AVAIL) \
  2207. ir_function_signature * \
  2208. builtin_builder::_##NAME(const glsl_type *return_type, \
  2209. const glsl_type *param0_type, \
  2210. const glsl_type *param1_type) \
  2211. { \
  2212. return binop(&AVAIL, OPCODE, return_type, param0_type, param1_type); \
  2213. }
  2214. /**
  2215. * Angle and Trigonometry Functions @{
  2216. */
  2217. ir_function_signature *
  2218. builtin_builder::_radians(const glsl_type *type)
  2219. {
  2220. ir_variable *degrees = in_var(type, "degrees");
  2221. MAKE_SIG(type, always_available, 1, degrees);
  2222. body.emit(ret(mul(degrees, imm(0.0174532925f))));
  2223. return sig;
  2224. }
  2225. ir_function_signature *
  2226. builtin_builder::_degrees(const glsl_type *type)
  2227. {
  2228. ir_variable *radians = in_var(type, "radians");
  2229. MAKE_SIG(type, always_available, 1, radians);
  2230. body.emit(ret(mul(radians, imm(57.29578f))));
  2231. return sig;
  2232. }
  2233. UNOP(sin, ir_unop_sin, always_available)
  2234. UNOP(cos, ir_unop_cos, always_available)
  2235. ir_function_signature *
  2236. builtin_builder::_tan(const glsl_type *type)
  2237. {
  2238. ir_variable *theta = in_var(type, "theta");
  2239. MAKE_SIG(type, always_available, 1, theta);
  2240. body.emit(ret(div(sin(theta), cos(theta))));
  2241. return sig;
  2242. }
  2243. ir_expression *
  2244. builtin_builder::asin_expr(ir_variable *x)
  2245. {
  2246. return mul(sign(x),
  2247. sub(imm(M_PI_2f),
  2248. mul(sqrt(sub(imm(1.0f), abs(x))),
  2249. add(imm(M_PI_2f),
  2250. mul(abs(x),
  2251. add(imm(M_PI_4f - 1.0f),
  2252. mul(abs(x),
  2253. add(imm(0.086566724f),
  2254. mul(abs(x), imm(-0.03102955f))))))))));
  2255. }
  2256. ir_call *
  2257. builtin_builder::call(ir_function *f, ir_variable *ret, exec_list params)
  2258. {
  2259. exec_list actual_params;
  2260. foreach_in_list(ir_variable, var, &params) {
  2261. actual_params.push_tail(var_ref(var));
  2262. }
  2263. ir_function_signature *sig =
  2264. f->exact_matching_signature(NULL, &actual_params);
  2265. if (!sig)
  2266. return NULL;
  2267. ir_dereference_variable *deref =
  2268. (sig->return_type->is_void() ? NULL : var_ref(ret));
  2269. return new(mem_ctx) ir_call(sig, deref, &actual_params);
  2270. }
  2271. ir_function_signature *
  2272. builtin_builder::_asin(const glsl_type *type)
  2273. {
  2274. ir_variable *x = in_var(type, "x");
  2275. MAKE_SIG(type, always_available, 1, x);
  2276. body.emit(ret(asin_expr(x)));
  2277. return sig;
  2278. }
  2279. ir_function_signature *
  2280. builtin_builder::_acos(const glsl_type *type)
  2281. {
  2282. ir_variable *x = in_var(type, "x");
  2283. MAKE_SIG(type, always_available, 1, x);
  2284. body.emit(ret(sub(imm(M_PI_2f), asin_expr(x))));
  2285. return sig;
  2286. }
  2287. ir_function_signature *
  2288. builtin_builder::_atan2(const glsl_type *type)
  2289. {
  2290. ir_variable *vec_y = in_var(type, "vec_y");
  2291. ir_variable *vec_x = in_var(type, "vec_x");
  2292. MAKE_SIG(type, always_available, 2, vec_y, vec_x);
  2293. ir_variable *vec_result = body.make_temp(type, "vec_result");
  2294. ir_variable *r = body.make_temp(glsl_type::float_type, "r");
  2295. for (unsigned i = 0; i < type->vector_elements; i++) {
  2296. ir_variable *y = body.make_temp(glsl_type::float_type, "y");
  2297. ir_variable *x = body.make_temp(glsl_type::float_type, "x");
  2298. body.emit(assign(y, swizzle(vec_y, i, 1)));
  2299. body.emit(assign(x, swizzle(vec_x, i, 1)));
  2300. /* If |x| >= 1.0e-8 * |y|: */
  2301. ir_if *outer_if =
  2302. new(mem_ctx) ir_if(greater(abs(x), mul(imm(1.0e-8f), abs(y))));
  2303. ir_factory outer_then(&outer_if->then_instructions, mem_ctx);
  2304. /* Then...call atan(y/x) */
  2305. do_atan(body, glsl_type::float_type, r, div(y, x));
  2306. /* ...and fix it up: */
  2307. ir_if *inner_if = new(mem_ctx) ir_if(less(x, imm(0.0f)));
  2308. inner_if->then_instructions.push_tail(
  2309. if_tree(gequal(y, imm(0.0f)),
  2310. assign(r, add(r, imm(M_PIf))),
  2311. assign(r, sub(r, imm(M_PIf)))));
  2312. outer_then.emit(inner_if);
  2313. /* Else... */
  2314. outer_if->else_instructions.push_tail(
  2315. assign(r, mul(sign(y), imm(M_PI_2f))));
  2316. body.emit(outer_if);
  2317. body.emit(assign(vec_result, r, 1 << i));
  2318. }
  2319. body.emit(ret(vec_result));
  2320. return sig;
  2321. }
  2322. void
  2323. builtin_builder::do_atan(ir_factory &body, const glsl_type *type, ir_variable *res, operand y_over_x)
  2324. {
  2325. /*
  2326. * range-reduction, first step:
  2327. *
  2328. * / y_over_x if |y_over_x| <= 1.0;
  2329. * x = <
  2330. * \ 1.0 / y_over_x otherwise
  2331. */
  2332. ir_variable *x = body.make_temp(type, "atan_x");
  2333. body.emit(assign(x, div(min2(abs(y_over_x),
  2334. imm(1.0f)),
  2335. max2(abs(y_over_x),
  2336. imm(1.0f)))));
  2337. /*
  2338. * approximate atan by evaluating polynomial:
  2339. *
  2340. * x * 0.9999793128310355 - x^3 * 0.3326756418091246 +
  2341. * x^5 * 0.1938924977115610 - x^7 * 0.1173503194786851 +
  2342. * x^9 * 0.0536813784310406 - x^11 * 0.0121323213173444
  2343. */
  2344. ir_variable *tmp = body.make_temp(type, "atan_tmp");
  2345. body.emit(assign(tmp, mul(x, x)));
  2346. body.emit(assign(tmp, mul(add(mul(sub(mul(add(mul(sub(mul(add(mul(imm(-0.0121323213173444f),
  2347. tmp),
  2348. imm(0.0536813784310406f)),
  2349. tmp),
  2350. imm(0.1173503194786851f)),
  2351. tmp),
  2352. imm(0.1938924977115610f)),
  2353. tmp),
  2354. imm(0.3326756418091246f)),
  2355. tmp),
  2356. imm(0.9999793128310355f)),
  2357. x)));
  2358. /* range-reduction fixup */
  2359. body.emit(assign(tmp, add(tmp,
  2360. mul(b2f(greater(abs(y_over_x),
  2361. imm(1.0f, type->components()))),
  2362. add(mul(tmp,
  2363. imm(-2.0f)),
  2364. imm(M_PI_2f))))));
  2365. /* sign fixup */
  2366. body.emit(assign(res, mul(tmp, sign(y_over_x))));
  2367. }
  2368. ir_function_signature *
  2369. builtin_builder::_atan(const glsl_type *type)
  2370. {
  2371. ir_variable *y_over_x = in_var(type, "y_over_x");
  2372. MAKE_SIG(type, always_available, 1, y_over_x);
  2373. ir_variable *tmp = body.make_temp(type, "tmp");
  2374. do_atan(body, type, tmp, y_over_x);
  2375. body.emit(ret(tmp));
  2376. return sig;
  2377. }
  2378. ir_function_signature *
  2379. builtin_builder::_sinh(const glsl_type *type)
  2380. {
  2381. ir_variable *x = in_var(type, "x");
  2382. MAKE_SIG(type, v130, 1, x);
  2383. /* 0.5 * (e^x - e^(-x)) */
  2384. body.emit(ret(mul(imm(0.5f), sub(exp(x), exp(neg(x))))));
  2385. return sig;
  2386. }
  2387. ir_function_signature *
  2388. builtin_builder::_cosh(const glsl_type *type)
  2389. {
  2390. ir_variable *x = in_var(type, "x");
  2391. MAKE_SIG(type, v130, 1, x);
  2392. /* 0.5 * (e^x + e^(-x)) */
  2393. body.emit(ret(mul(imm(0.5f), add(exp(x), exp(neg(x))))));
  2394. return sig;
  2395. }
  2396. ir_function_signature *
  2397. builtin_builder::_tanh(const glsl_type *type)
  2398. {
  2399. ir_variable *x = in_var(type, "x");
  2400. MAKE_SIG(type, v130, 1, x);
  2401. /* (e^x - e^(-x)) / (e^x + e^(-x)) */
  2402. body.emit(ret(div(sub(exp(x), exp(neg(x))),
  2403. add(exp(x), exp(neg(x))))));
  2404. return sig;
  2405. }
  2406. ir_function_signature *
  2407. builtin_builder::_asinh(const glsl_type *type)
  2408. {
  2409. ir_variable *x = in_var(type, "x");
  2410. MAKE_SIG(type, v130, 1, x);
  2411. body.emit(ret(mul(sign(x), log(add(abs(x), sqrt(add(mul(x, x),
  2412. imm(1.0f))))))));
  2413. return sig;
  2414. }
  2415. ir_function_signature *
  2416. builtin_builder::_acosh(const glsl_type *type)
  2417. {
  2418. ir_variable *x = in_var(type, "x");
  2419. MAKE_SIG(type, v130, 1, x);
  2420. body.emit(ret(log(add(x, sqrt(sub(mul(x, x), imm(1.0f)))))));
  2421. return sig;
  2422. }
  2423. ir_function_signature *
  2424. builtin_builder::_atanh(const glsl_type *type)
  2425. {
  2426. ir_variable *x = in_var(type, "x");
  2427. MAKE_SIG(type, v130, 1, x);
  2428. body.emit(ret(mul(imm(0.5f), log(div(add(imm(1.0f), x),
  2429. sub(imm(1.0f), x))))));
  2430. return sig;
  2431. }
  2432. /** @} */
  2433. /**
  2434. * Exponential Functions @{
  2435. */
  2436. ir_function_signature *
  2437. builtin_builder::_pow(const glsl_type *type)
  2438. {
  2439. return binop(ir_binop_pow, always_available, type, type, type);
  2440. }
  2441. UNOP(exp, ir_unop_exp, always_available)
  2442. UNOP(log, ir_unop_log, always_available)
  2443. UNOP(exp2, ir_unop_exp2, always_available)
  2444. UNOP(log2, ir_unop_log2, always_available)
  2445. UNOP(sqrt, ir_unop_sqrt, always_available)
  2446. UNOP(inversesqrt, ir_unop_rsq, always_available)
  2447. /** @} */
  2448. UNOP(abs, ir_unop_abs, always_available)
  2449. UNOP(sign, ir_unop_sign, always_available)
  2450. UNOP(floor, ir_unop_floor, always_available)
  2451. UNOP(trunc, ir_unop_trunc, v130)
  2452. UNOP(round, ir_unop_round_even, always_available)
  2453. UNOP(roundEven, ir_unop_round_even, always_available)
  2454. UNOP(ceil, ir_unop_ceil, always_available)
  2455. UNOP(fract, ir_unop_fract, always_available)
  2456. ir_function_signature *
  2457. builtin_builder::_mod(const glsl_type *x_type, const glsl_type *y_type)
  2458. {
  2459. return binop(ir_binop_mod, always_available, x_type, x_type, y_type);
  2460. }
  2461. ir_function_signature *
  2462. builtin_builder::_modf(const glsl_type *type)
  2463. {
  2464. ir_variable *x = in_var(type, "x");
  2465. ir_variable *i = out_var(type, "i");
  2466. MAKE_SIG(type, v130, 2, x, i);
  2467. ir_variable *t = body.make_temp(type, "t");
  2468. body.emit(assign(t, expr(ir_unop_trunc, x)));
  2469. body.emit(assign(i, t));
  2470. body.emit(ret(sub(x, t)));
  2471. return sig;
  2472. }
  2473. ir_function_signature *
  2474. builtin_builder::_min(builtin_available_predicate avail,
  2475. const glsl_type *x_type, const glsl_type *y_type)
  2476. {
  2477. return binop(ir_binop_min, avail, x_type, x_type, y_type);
  2478. }
  2479. ir_function_signature *
  2480. builtin_builder::_max(builtin_available_predicate avail,
  2481. const glsl_type *x_type, const glsl_type *y_type)
  2482. {
  2483. return binop(ir_binop_max, avail, x_type, x_type, y_type);
  2484. }
  2485. ir_function_signature *
  2486. builtin_builder::_clamp(builtin_available_predicate avail,
  2487. const glsl_type *val_type, const glsl_type *bound_type)
  2488. {
  2489. ir_variable *x = in_var(val_type, "x");
  2490. ir_variable *minVal = in_var(bound_type, "minVal");
  2491. ir_variable *maxVal = in_var(bound_type, "maxVal");
  2492. MAKE_SIG(val_type, avail, 3, x, minVal, maxVal);
  2493. body.emit(ret(clamp(x, minVal, maxVal)));
  2494. return sig;
  2495. }
  2496. ir_function_signature *
  2497. builtin_builder::_mix_lrp(const glsl_type *val_type, const glsl_type *blend_type)
  2498. {
  2499. ir_variable *x = in_var(val_type, "x");
  2500. ir_variable *y = in_var(val_type, "y");
  2501. ir_variable *a = in_var(blend_type, "a");
  2502. MAKE_SIG(val_type, always_available, 3, x, y, a);
  2503. body.emit(ret(lrp(x, y, a)));
  2504. return sig;
  2505. }
  2506. ir_function_signature *
  2507. builtin_builder::_mix_sel(builtin_available_predicate avail,
  2508. const glsl_type *val_type,
  2509. const glsl_type *blend_type)
  2510. {
  2511. ir_variable *x = in_var(val_type, "x");
  2512. ir_variable *y = in_var(val_type, "y");
  2513. ir_variable *a = in_var(blend_type, "a");
  2514. MAKE_SIG(val_type, avail, 3, x, y, a);
  2515. /* csel matches the ternary operator in that a selector of true choses the
  2516. * first argument. This differs from mix(x, y, false) which choses the
  2517. * second argument (to remain consistent with the interpolating version of
  2518. * mix() which takes a blend factor from 0.0 to 1.0 where 0.0 is only x.
  2519. *
  2520. * To handle the behavior mismatch, reverse the x and y arguments.
  2521. */
  2522. body.emit(ret(csel(a, y, x)));
  2523. return sig;
  2524. }
  2525. ir_function_signature *
  2526. builtin_builder::_step(const glsl_type *edge_type, const glsl_type *x_type)
  2527. {
  2528. ir_variable *edge = in_var(edge_type, "edge");
  2529. ir_variable *x = in_var(x_type, "x");
  2530. MAKE_SIG(x_type, always_available, 2, edge, x);
  2531. ir_variable *t = body.make_temp(x_type, "t");
  2532. if (x_type->vector_elements == 1) {
  2533. /* Both are floats */
  2534. body.emit(assign(t, b2f(gequal(x, edge))));
  2535. } else if (edge_type->vector_elements == 1) {
  2536. /* x is a vector but edge is a float */
  2537. for (unsigned i = 0; i < x_type->vector_elements; i++) {
  2538. body.emit(assign(t, b2f(gequal(swizzle(x, i, 1), edge)), 1 << i));
  2539. }
  2540. } else {
  2541. /* Both are vectors */
  2542. for (unsigned i = 0; i < x_type->vector_elements; i++) {
  2543. body.emit(assign(t, b2f(gequal(swizzle(x, i, 1), swizzle(edge, i, 1))),
  2544. 1 << i));
  2545. }
  2546. }
  2547. body.emit(ret(t));
  2548. return sig;
  2549. }
  2550. ir_function_signature *
  2551. builtin_builder::_smoothstep(const glsl_type *edge_type, const glsl_type *x_type)
  2552. {
  2553. ir_variable *edge0 = in_var(edge_type, "edge0");
  2554. ir_variable *edge1 = in_var(edge_type, "edge1");
  2555. ir_variable *x = in_var(x_type, "x");
  2556. MAKE_SIG(x_type, always_available, 3, edge0, edge1, x);
  2557. /* From the GLSL 1.10 specification:
  2558. *
  2559. * genType t;
  2560. * t = clamp((x - edge0) / (edge1 - edge0), 0, 1);
  2561. * return t * t * (3 - 2 * t);
  2562. */
  2563. ir_variable *t = body.make_temp(x_type, "t");
  2564. body.emit(assign(t, clamp(div(sub(x, edge0), sub(edge1, edge0)),
  2565. imm(0.0f), imm(1.0f))));
  2566. body.emit(ret(mul(t, mul(t, sub(imm(3.0f), mul(imm(2.0f), t))))));
  2567. return sig;
  2568. }
  2569. ir_function_signature *
  2570. builtin_builder::_isnan(const glsl_type *type)
  2571. {
  2572. ir_variable *x = in_var(type, "x");
  2573. MAKE_SIG(glsl_type::bvec(type->vector_elements), v130, 1, x);
  2574. body.emit(ret(nequal(x, x)));
  2575. return sig;
  2576. }
  2577. ir_function_signature *
  2578. builtin_builder::_isinf(const glsl_type *type)
  2579. {
  2580. ir_variable *x = in_var(type, "x");
  2581. MAKE_SIG(glsl_type::bvec(type->vector_elements), v130, 1, x);
  2582. ir_constant_data infinities;
  2583. for (unsigned i = 0; i < type->vector_elements; i++) {
  2584. infinities.f[i] = std::numeric_limits<float>::infinity();
  2585. }
  2586. body.emit(ret(equal(abs(x), imm(type, infinities))));
  2587. return sig;
  2588. }
  2589. ir_function_signature *
  2590. builtin_builder::_floatBitsToInt(const glsl_type *type)
  2591. {
  2592. ir_variable *x = in_var(type, "x");
  2593. MAKE_SIG(glsl_type::ivec(type->vector_elements), shader_bit_encoding, 1, x);
  2594. body.emit(ret(bitcast_f2i(x)));
  2595. return sig;
  2596. }
  2597. ir_function_signature *
  2598. builtin_builder::_floatBitsToUint(const glsl_type *type)
  2599. {
  2600. ir_variable *x = in_var(type, "x");
  2601. MAKE_SIG(glsl_type::uvec(type->vector_elements), shader_bit_encoding, 1, x);
  2602. body.emit(ret(bitcast_f2u(x)));
  2603. return sig;
  2604. }
  2605. ir_function_signature *
  2606. builtin_builder::_intBitsToFloat(const glsl_type *type)
  2607. {
  2608. ir_variable *x = in_var(type, "x");
  2609. MAKE_SIG(glsl_type::vec(type->vector_elements), shader_bit_encoding, 1, x);
  2610. body.emit(ret(bitcast_i2f(x)));
  2611. return sig;
  2612. }
  2613. ir_function_signature *
  2614. builtin_builder::_uintBitsToFloat(const glsl_type *type)
  2615. {
  2616. ir_variable *x = in_var(type, "x");
  2617. MAKE_SIG(glsl_type::vec(type->vector_elements), shader_bit_encoding, 1, x);
  2618. body.emit(ret(bitcast_u2f(x)));
  2619. return sig;
  2620. }
  2621. ir_function_signature *
  2622. builtin_builder::_packUnorm2x16(builtin_available_predicate avail)
  2623. {
  2624. ir_variable *v = in_var(glsl_type::vec2_type, "v");
  2625. MAKE_SIG(glsl_type::uint_type, avail, 1, v);
  2626. body.emit(ret(expr(ir_unop_pack_unorm_2x16, v)));
  2627. return sig;
  2628. }
  2629. ir_function_signature *
  2630. builtin_builder::_packSnorm2x16(builtin_available_predicate avail)
  2631. {
  2632. ir_variable *v = in_var(glsl_type::vec2_type, "v");
  2633. MAKE_SIG(glsl_type::uint_type, avail, 1, v);
  2634. body.emit(ret(expr(ir_unop_pack_snorm_2x16, v)));
  2635. return sig;
  2636. }
  2637. ir_function_signature *
  2638. builtin_builder::_packUnorm4x8(builtin_available_predicate avail)
  2639. {
  2640. ir_variable *v = in_var(glsl_type::vec4_type, "v");
  2641. MAKE_SIG(glsl_type::uint_type, avail, 1, v);
  2642. body.emit(ret(expr(ir_unop_pack_unorm_4x8, v)));
  2643. return sig;
  2644. }
  2645. ir_function_signature *
  2646. builtin_builder::_packSnorm4x8(builtin_available_predicate avail)
  2647. {
  2648. ir_variable *v = in_var(glsl_type::vec4_type, "v");
  2649. MAKE_SIG(glsl_type::uint_type, avail, 1, v);
  2650. body.emit(ret(expr(ir_unop_pack_snorm_4x8, v)));
  2651. return sig;
  2652. }
  2653. ir_function_signature *
  2654. builtin_builder::_unpackUnorm2x16(builtin_available_predicate avail)
  2655. {
  2656. ir_variable *p = in_var(glsl_type::uint_type, "p");
  2657. MAKE_SIG(glsl_type::vec2_type, avail, 1, p);
  2658. body.emit(ret(expr(ir_unop_unpack_unorm_2x16, p)));
  2659. return sig;
  2660. }
  2661. ir_function_signature *
  2662. builtin_builder::_unpackSnorm2x16(builtin_available_predicate avail)
  2663. {
  2664. ir_variable *p = in_var(glsl_type::uint_type, "p");
  2665. MAKE_SIG(glsl_type::vec2_type, avail, 1, p);
  2666. body.emit(ret(expr(ir_unop_unpack_snorm_2x16, p)));
  2667. return sig;
  2668. }
  2669. ir_function_signature *
  2670. builtin_builder::_unpackUnorm4x8(builtin_available_predicate avail)
  2671. {
  2672. ir_variable *p = in_var(glsl_type::uint_type, "p");
  2673. MAKE_SIG(glsl_type::vec4_type, avail, 1, p);
  2674. body.emit(ret(expr(ir_unop_unpack_unorm_4x8, p)));
  2675. return sig;
  2676. }
  2677. ir_function_signature *
  2678. builtin_builder::_unpackSnorm4x8(builtin_available_predicate avail)
  2679. {
  2680. ir_variable *p = in_var(glsl_type::uint_type, "p");
  2681. MAKE_SIG(glsl_type::vec4_type, avail, 1, p);
  2682. body.emit(ret(expr(ir_unop_unpack_snorm_4x8, p)));
  2683. return sig;
  2684. }
  2685. ir_function_signature *
  2686. builtin_builder::_packHalf2x16(builtin_available_predicate avail)
  2687. {
  2688. ir_variable *v = in_var(glsl_type::vec2_type, "v");
  2689. MAKE_SIG(glsl_type::uint_type, avail, 1, v);
  2690. body.emit(ret(expr(ir_unop_pack_half_2x16, v)));
  2691. return sig;
  2692. }
  2693. ir_function_signature *
  2694. builtin_builder::_unpackHalf2x16(builtin_available_predicate avail)
  2695. {
  2696. ir_variable *p = in_var(glsl_type::uint_type, "p");
  2697. MAKE_SIG(glsl_type::vec2_type, avail, 1, p);
  2698. body.emit(ret(expr(ir_unop_unpack_half_2x16, p)));
  2699. return sig;
  2700. }
  2701. ir_function_signature *
  2702. builtin_builder::_length(const glsl_type *type)
  2703. {
  2704. ir_variable *x = in_var(type, "x");
  2705. MAKE_SIG(glsl_type::float_type, always_available, 1, x);
  2706. body.emit(ret(sqrt(dot(x, x))));
  2707. return sig;
  2708. }
  2709. ir_function_signature *
  2710. builtin_builder::_distance(const glsl_type *type)
  2711. {
  2712. ir_variable *p0 = in_var(type, "p0");
  2713. ir_variable *p1 = in_var(type, "p1");
  2714. MAKE_SIG(glsl_type::float_type, always_available, 2, p0, p1);
  2715. if (type->vector_elements == 1) {
  2716. body.emit(ret(abs(sub(p0, p1))));
  2717. } else {
  2718. ir_variable *p = body.make_temp(type, "p");
  2719. body.emit(assign(p, sub(p0, p1)));
  2720. body.emit(ret(sqrt(dot(p, p))));
  2721. }
  2722. return sig;
  2723. }
  2724. ir_function_signature *
  2725. builtin_builder::_dot(const glsl_type *type)
  2726. {
  2727. if (type->vector_elements == 1)
  2728. return binop(ir_binop_mul, always_available, type, type, type);
  2729. return binop(ir_binop_dot, always_available,
  2730. glsl_type::float_type, type, type);
  2731. }
  2732. ir_function_signature *
  2733. builtin_builder::_cross(const glsl_type *type)
  2734. {
  2735. ir_variable *a = in_var(type, "a");
  2736. ir_variable *b = in_var(type, "b");
  2737. MAKE_SIG(type, always_available, 2, a, b);
  2738. int yzx = MAKE_SWIZZLE4(SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_X, 0);
  2739. int zxy = MAKE_SWIZZLE4(SWIZZLE_Z, SWIZZLE_X, SWIZZLE_Y, 0);
  2740. body.emit(ret(sub(mul(swizzle(a, yzx, 3), swizzle(b, zxy, 3)),
  2741. mul(swizzle(a, zxy, 3), swizzle(b, yzx, 3)))));
  2742. return sig;
  2743. }
  2744. ir_function_signature *
  2745. builtin_builder::_normalize(const glsl_type *type)
  2746. {
  2747. ir_variable *x = in_var(type, "x");
  2748. MAKE_SIG(type, always_available, 1, x);
  2749. if (type->vector_elements == 1) {
  2750. body.emit(ret(sign(x)));
  2751. } else {
  2752. body.emit(ret(expr(ir_unop_normalize, x)));
  2753. }
  2754. return sig;
  2755. }
  2756. ir_function_signature *
  2757. builtin_builder::_ftransform()
  2758. {
  2759. MAKE_SIG(glsl_type::vec4_type, compatibility_vs_only, 0);
  2760. body.emit(ret(new(mem_ctx) ir_expression(ir_binop_mul,
  2761. glsl_type::vec4_type,
  2762. var_ref(gl_ModelViewProjectionMatrix),
  2763. var_ref(gl_Vertex))));
  2764. /* FINISHME: Once the ir_expression() constructor handles type inference
  2765. * for matrix operations, we can simplify this to:
  2766. *
  2767. * body.emit(ret(mul(gl_ModelViewProjectionMatrix, gl_Vertex)));
  2768. */
  2769. return sig;
  2770. }
  2771. ir_function_signature *
  2772. builtin_builder::_faceforward(const glsl_type *type)
  2773. {
  2774. ir_variable *N = in_var(type, "N");
  2775. ir_variable *I = in_var(type, "I");
  2776. ir_variable *Nref = in_var(type, "Nref");
  2777. MAKE_SIG(type, always_available, 3, N, I, Nref);
  2778. body.emit(if_tree(less(dot(Nref, I), imm(0.0f)),
  2779. ret(N), ret(neg(N))));
  2780. return sig;
  2781. }
  2782. ir_function_signature *
  2783. builtin_builder::_reflect(const glsl_type *type)
  2784. {
  2785. ir_variable *I = in_var(type, "I");
  2786. ir_variable *N = in_var(type, "N");
  2787. MAKE_SIG(type, always_available, 2, I, N);
  2788. /* I - 2 * dot(N, I) * N */
  2789. body.emit(ret(sub(I, mul(imm(2.0f), mul(dot(N, I), N)))));
  2790. return sig;
  2791. }
  2792. ir_function_signature *
  2793. builtin_builder::_refract(const glsl_type *type)
  2794. {
  2795. ir_variable *I = in_var(type, "I");
  2796. ir_variable *N = in_var(type, "N");
  2797. ir_variable *eta = in_var(glsl_type::float_type, "eta");
  2798. MAKE_SIG(type, always_available, 3, I, N, eta);
  2799. ir_variable *n_dot_i = body.make_temp(glsl_type::float_type, "n_dot_i");
  2800. body.emit(assign(n_dot_i, dot(N, I)));
  2801. /* From the GLSL 1.10 specification:
  2802. * k = 1.0 - eta * eta * (1.0 - dot(N, I) * dot(N, I))
  2803. * if (k < 0.0)
  2804. * return genType(0.0)
  2805. * else
  2806. * return eta * I - (eta * dot(N, I) + sqrt(k)) * N
  2807. */
  2808. ir_variable *k = body.make_temp(glsl_type::float_type, "k");
  2809. body.emit(assign(k, sub(imm(1.0f),
  2810. mul(eta, mul(eta, sub(imm(1.0f),
  2811. mul(n_dot_i, n_dot_i)))))));
  2812. body.emit(if_tree(less(k, imm(0.0f)),
  2813. ret(ir_constant::zero(mem_ctx, type)),
  2814. ret(sub(mul(eta, I),
  2815. mul(add(mul(eta, n_dot_i), sqrt(k)), N)))));
  2816. return sig;
  2817. }
  2818. ir_function_signature *
  2819. builtin_builder::_matrixCompMult(const glsl_type *type)
  2820. {
  2821. ir_variable *x = in_var(type, "x");
  2822. ir_variable *y = in_var(type, "y");
  2823. MAKE_SIG(type, always_available, 2, x, y);
  2824. ir_variable *z = body.make_temp(type, "z");
  2825. for (unsigned i = 0; i < type->matrix_columns; i++) {
  2826. body.emit(assign(array_ref(z, i), mul(array_ref(x, i), array_ref(y, i))));
  2827. }
  2828. body.emit(ret(z));
  2829. return sig;
  2830. }
  2831. ir_function_signature *
  2832. builtin_builder::_outerProduct(const glsl_type *type)
  2833. {
  2834. ir_variable *c = in_var(glsl_type::vec(type->vector_elements), "c");
  2835. ir_variable *r = in_var(glsl_type::vec(type->matrix_columns), "r");
  2836. MAKE_SIG(type, v120, 2, c, r);
  2837. ir_variable *m = body.make_temp(type, "m");
  2838. for (unsigned i = 0; i < type->matrix_columns; i++) {
  2839. body.emit(assign(array_ref(m, i), mul(c, swizzle(r, i, 1))));
  2840. }
  2841. body.emit(ret(m));
  2842. return sig;
  2843. }
  2844. ir_function_signature *
  2845. builtin_builder::_transpose(const glsl_type *orig_type)
  2846. {
  2847. const glsl_type *transpose_type =
  2848. glsl_type::get_instance(GLSL_TYPE_FLOAT,
  2849. orig_type->matrix_columns,
  2850. orig_type->vector_elements);
  2851. ir_variable *m = in_var(orig_type, "m");
  2852. MAKE_SIG(transpose_type, v120, 1, m);
  2853. ir_variable *t = body.make_temp(transpose_type, "t");
  2854. for (unsigned i = 0; i < orig_type->matrix_columns; i++) {
  2855. for (unsigned j = 0; j < orig_type->vector_elements; j++) {
  2856. body.emit(assign(array_ref(t, j),
  2857. matrix_elt(m, i, j),
  2858. 1 << i));
  2859. }
  2860. }
  2861. body.emit(ret(t));
  2862. return sig;
  2863. }
  2864. ir_function_signature *
  2865. builtin_builder::_determinant_mat2()
  2866. {
  2867. ir_variable *m = in_var(glsl_type::mat2_type, "m");
  2868. MAKE_SIG(glsl_type::float_type, v120, 1, m);
  2869. body.emit(ret(sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 1)),
  2870. mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 1)))));
  2871. return sig;
  2872. }
  2873. ir_function_signature *
  2874. builtin_builder::_determinant_mat3()
  2875. {
  2876. ir_variable *m = in_var(glsl_type::mat3_type, "m");
  2877. MAKE_SIG(glsl_type::float_type, v120, 1, m);
  2878. ir_expression *f1 =
  2879. sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 2)),
  2880. mul(matrix_elt(m, 1, 2), matrix_elt(m, 2, 1)));
  2881. ir_expression *f2 =
  2882. sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 2)),
  2883. mul(matrix_elt(m, 1, 2), matrix_elt(m, 2, 0)));
  2884. ir_expression *f3 =
  2885. sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 1)),
  2886. mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 0)));
  2887. body.emit(ret(add(sub(mul(matrix_elt(m, 0, 0), f1),
  2888. mul(matrix_elt(m, 0, 1), f2)),
  2889. mul(matrix_elt(m, 0, 2), f3))));
  2890. return sig;
  2891. }
  2892. ir_function_signature *
  2893. builtin_builder::_determinant_mat4()
  2894. {
  2895. ir_variable *m = in_var(glsl_type::mat4_type, "m");
  2896. MAKE_SIG(glsl_type::float_type, v120, 1, m);
  2897. ir_variable *SubFactor00 = body.make_temp(glsl_type::float_type, "SubFactor00");
  2898. ir_variable *SubFactor01 = body.make_temp(glsl_type::float_type, "SubFactor01");
  2899. ir_variable *SubFactor02 = body.make_temp(glsl_type::float_type, "SubFactor02");
  2900. ir_variable *SubFactor03 = body.make_temp(glsl_type::float_type, "SubFactor03");
  2901. ir_variable *SubFactor04 = body.make_temp(glsl_type::float_type, "SubFactor04");
  2902. ir_variable *SubFactor05 = body.make_temp(glsl_type::float_type, "SubFactor05");
  2903. ir_variable *SubFactor06 = body.make_temp(glsl_type::float_type, "SubFactor06");
  2904. ir_variable *SubFactor07 = body.make_temp(glsl_type::float_type, "SubFactor07");
  2905. ir_variable *SubFactor08 = body.make_temp(glsl_type::float_type, "SubFactor08");
  2906. ir_variable *SubFactor09 = body.make_temp(glsl_type::float_type, "SubFactor09");
  2907. ir_variable *SubFactor10 = body.make_temp(glsl_type::float_type, "SubFactor10");
  2908. ir_variable *SubFactor11 = body.make_temp(glsl_type::float_type, "SubFactor11");
  2909. ir_variable *SubFactor12 = body.make_temp(glsl_type::float_type, "SubFactor12");
  2910. ir_variable *SubFactor13 = body.make_temp(glsl_type::float_type, "SubFactor13");
  2911. ir_variable *SubFactor14 = body.make_temp(glsl_type::float_type, "SubFactor14");
  2912. ir_variable *SubFactor15 = body.make_temp(glsl_type::float_type, "SubFactor15");
  2913. ir_variable *SubFactor16 = body.make_temp(glsl_type::float_type, "SubFactor16");
  2914. ir_variable *SubFactor17 = body.make_temp(glsl_type::float_type, "SubFactor17");
  2915. ir_variable *SubFactor18 = body.make_temp(glsl_type::float_type, "SubFactor18");
  2916. body.emit(assign(SubFactor00, sub(mul(matrix_elt(m, 2, 2), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 2), matrix_elt(m, 2, 3)))));
  2917. body.emit(assign(SubFactor01, sub(mul(matrix_elt(m, 2, 1), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 1), matrix_elt(m, 2, 3)))));
  2918. body.emit(assign(SubFactor02, sub(mul(matrix_elt(m, 2, 1), matrix_elt(m, 3, 2)), mul(matrix_elt(m, 3, 1), matrix_elt(m, 2, 2)))));
  2919. body.emit(assign(SubFactor03, sub(mul(matrix_elt(m, 2, 0), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 2, 3)))));
  2920. body.emit(assign(SubFactor04, sub(mul(matrix_elt(m, 2, 0), matrix_elt(m, 3, 2)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 2, 2)))));
  2921. body.emit(assign(SubFactor05, sub(mul(matrix_elt(m, 2, 0), matrix_elt(m, 3, 1)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 2, 1)))));
  2922. body.emit(assign(SubFactor06, sub(mul(matrix_elt(m, 1, 2), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 2), matrix_elt(m, 1, 3)))));
  2923. body.emit(assign(SubFactor07, sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 1), matrix_elt(m, 1, 3)))));
  2924. body.emit(assign(SubFactor08, sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 3, 2)), mul(matrix_elt(m, 3, 1), matrix_elt(m, 1, 2)))));
  2925. body.emit(assign(SubFactor09, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 1, 3)))));
  2926. body.emit(assign(SubFactor10, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 3, 2)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 1, 2)))));
  2927. body.emit(assign(SubFactor11, sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 1), matrix_elt(m, 1, 3)))));
  2928. body.emit(assign(SubFactor12, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 3, 1)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 1, 1)))));
  2929. body.emit(assign(SubFactor13, sub(mul(matrix_elt(m, 1, 2), matrix_elt(m, 2, 3)), mul(matrix_elt(m, 2, 2), matrix_elt(m, 1, 3)))));
  2930. body.emit(assign(SubFactor14, sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 3)), mul(matrix_elt(m, 2, 1), matrix_elt(m, 1, 3)))));
  2931. body.emit(assign(SubFactor15, sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 2)), mul(matrix_elt(m, 2, 1), matrix_elt(m, 1, 2)))));
  2932. body.emit(assign(SubFactor16, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 3)), mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 3)))));
  2933. body.emit(assign(SubFactor17, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 2)), mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 2)))));
  2934. body.emit(assign(SubFactor18, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 1)), mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 1)))));
  2935. ir_variable *adj_0 = body.make_temp(glsl_type::vec4_type, "adj_0");
  2936. body.emit(assign(adj_0,
  2937. add(sub(mul(matrix_elt(m, 1, 1), SubFactor00),
  2938. mul(matrix_elt(m, 1, 2), SubFactor01)),
  2939. mul(matrix_elt(m, 1, 3), SubFactor02)),
  2940. WRITEMASK_X));
  2941. body.emit(assign(adj_0, neg(
  2942. add(sub(mul(matrix_elt(m, 1, 0), SubFactor00),
  2943. mul(matrix_elt(m, 1, 2), SubFactor03)),
  2944. mul(matrix_elt(m, 1, 3), SubFactor04))),
  2945. WRITEMASK_Y));
  2946. body.emit(assign(adj_0,
  2947. add(sub(mul(matrix_elt(m, 1, 0), SubFactor01),
  2948. mul(matrix_elt(m, 1, 1), SubFactor03)),
  2949. mul(matrix_elt(m, 1, 3), SubFactor05)),
  2950. WRITEMASK_Z));
  2951. body.emit(assign(adj_0, neg(
  2952. add(sub(mul(matrix_elt(m, 1, 0), SubFactor02),
  2953. mul(matrix_elt(m, 1, 1), SubFactor04)),
  2954. mul(matrix_elt(m, 1, 2), SubFactor05))),
  2955. WRITEMASK_W));
  2956. body.emit(ret(dot(array_ref(m, 0), adj_0)));
  2957. return sig;
  2958. }
  2959. ir_function_signature *
  2960. builtin_builder::_inverse_mat2()
  2961. {
  2962. ir_variable *m = in_var(glsl_type::mat2_type, "m");
  2963. MAKE_SIG(glsl_type::mat2_type, v120, 1, m);
  2964. ir_variable *adj = body.make_temp(glsl_type::mat2_type, "adj");
  2965. body.emit(assign(array_ref(adj, 0), matrix_elt(m, 1, 1), 1 << 0));
  2966. body.emit(assign(array_ref(adj, 0), neg(matrix_elt(m, 0, 1)), 1 << 1));
  2967. body.emit(assign(array_ref(adj, 1), neg(matrix_elt(m, 1, 0)), 1 << 0));
  2968. body.emit(assign(array_ref(adj, 1), matrix_elt(m, 0, 0), 1 << 1));
  2969. ir_expression *det =
  2970. sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 1)),
  2971. mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 1)));
  2972. body.emit(ret(div(adj, det)));
  2973. return sig;
  2974. }
  2975. ir_function_signature *
  2976. builtin_builder::_inverse_mat3()
  2977. {
  2978. ir_variable *m = in_var(glsl_type::mat3_type, "m");
  2979. MAKE_SIG(glsl_type::mat3_type, v120, 1, m);
  2980. ir_variable *f11_22_21_12 = body.make_temp(glsl_type::float_type, "f11_22_21_12");
  2981. ir_variable *f10_22_20_12 = body.make_temp(glsl_type::float_type, "f10_22_20_12");
  2982. ir_variable *f10_21_20_11 = body.make_temp(glsl_type::float_type, "f10_21_20_11");
  2983. body.emit(assign(f11_22_21_12,
  2984. sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 2)),
  2985. mul(matrix_elt(m, 2, 1), matrix_elt(m, 1, 2)))));
  2986. body.emit(assign(f10_22_20_12,
  2987. sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 2)),
  2988. mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 2)))));
  2989. body.emit(assign(f10_21_20_11,
  2990. sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 1)),
  2991. mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 1)))));
  2992. ir_variable *adj = body.make_temp(glsl_type::mat3_type, "adj");
  2993. body.emit(assign(array_ref(adj, 0), f11_22_21_12, WRITEMASK_X));
  2994. body.emit(assign(array_ref(adj, 1), neg(f10_22_20_12), WRITEMASK_X));
  2995. body.emit(assign(array_ref(adj, 2), f10_21_20_11, WRITEMASK_X));
  2996. body.emit(assign(array_ref(adj, 0), neg(
  2997. sub(mul(matrix_elt(m, 0, 1), matrix_elt(m, 2, 2)),
  2998. mul(matrix_elt(m, 2, 1), matrix_elt(m, 0, 2)))),
  2999. WRITEMASK_Y));
  3000. body.emit(assign(array_ref(adj, 1),
  3001. sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 2, 2)),
  3002. mul(matrix_elt(m, 2, 0), matrix_elt(m, 0, 2))),
  3003. WRITEMASK_Y));
  3004. body.emit(assign(array_ref(adj, 2), neg(
  3005. sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 2, 1)),
  3006. mul(matrix_elt(m, 2, 0), matrix_elt(m, 0, 1)))),
  3007. WRITEMASK_Y));
  3008. body.emit(assign(array_ref(adj, 0),
  3009. sub(mul(matrix_elt(m, 0, 1), matrix_elt(m, 1, 2)),
  3010. mul(matrix_elt(m, 1, 1), matrix_elt(m, 0, 2))),
  3011. WRITEMASK_Z));
  3012. body.emit(assign(array_ref(adj, 1), neg(
  3013. sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 2)),
  3014. mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 2)))),
  3015. WRITEMASK_Z));
  3016. body.emit(assign(array_ref(adj, 2),
  3017. sub(mul(matrix_elt(m, 0, 0), matrix_elt(m, 1, 1)),
  3018. mul(matrix_elt(m, 1, 0), matrix_elt(m, 0, 1))),
  3019. WRITEMASK_Z));
  3020. ir_expression *det =
  3021. add(sub(mul(matrix_elt(m, 0, 0), f11_22_21_12),
  3022. mul(matrix_elt(m, 0, 1), f10_22_20_12)),
  3023. mul(matrix_elt(m, 0, 2), f10_21_20_11));
  3024. body.emit(ret(div(adj, det)));
  3025. return sig;
  3026. }
  3027. ir_function_signature *
  3028. builtin_builder::_inverse_mat4()
  3029. {
  3030. ir_variable *m = in_var(glsl_type::mat4_type, "m");
  3031. MAKE_SIG(glsl_type::mat4_type, v120, 1, m);
  3032. ir_variable *SubFactor00 = body.make_temp(glsl_type::float_type, "SubFactor00");
  3033. ir_variable *SubFactor01 = body.make_temp(glsl_type::float_type, "SubFactor01");
  3034. ir_variable *SubFactor02 = body.make_temp(glsl_type::float_type, "SubFactor02");
  3035. ir_variable *SubFactor03 = body.make_temp(glsl_type::float_type, "SubFactor03");
  3036. ir_variable *SubFactor04 = body.make_temp(glsl_type::float_type, "SubFactor04");
  3037. ir_variable *SubFactor05 = body.make_temp(glsl_type::float_type, "SubFactor05");
  3038. ir_variable *SubFactor06 = body.make_temp(glsl_type::float_type, "SubFactor06");
  3039. ir_variable *SubFactor07 = body.make_temp(glsl_type::float_type, "SubFactor07");
  3040. ir_variable *SubFactor08 = body.make_temp(glsl_type::float_type, "SubFactor08");
  3041. ir_variable *SubFactor09 = body.make_temp(glsl_type::float_type, "SubFactor09");
  3042. ir_variable *SubFactor10 = body.make_temp(glsl_type::float_type, "SubFactor10");
  3043. ir_variable *SubFactor11 = body.make_temp(glsl_type::float_type, "SubFactor11");
  3044. ir_variable *SubFactor12 = body.make_temp(glsl_type::float_type, "SubFactor12");
  3045. ir_variable *SubFactor13 = body.make_temp(glsl_type::float_type, "SubFactor13");
  3046. ir_variable *SubFactor14 = body.make_temp(glsl_type::float_type, "SubFactor14");
  3047. ir_variable *SubFactor15 = body.make_temp(glsl_type::float_type, "SubFactor15");
  3048. ir_variable *SubFactor16 = body.make_temp(glsl_type::float_type, "SubFactor16");
  3049. ir_variable *SubFactor17 = body.make_temp(glsl_type::float_type, "SubFactor17");
  3050. ir_variable *SubFactor18 = body.make_temp(glsl_type::float_type, "SubFactor18");
  3051. body.emit(assign(SubFactor00, sub(mul(matrix_elt(m, 2, 2), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 2), matrix_elt(m, 2, 3)))));
  3052. body.emit(assign(SubFactor01, sub(mul(matrix_elt(m, 2, 1), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 1), matrix_elt(m, 2, 3)))));
  3053. body.emit(assign(SubFactor02, sub(mul(matrix_elt(m, 2, 1), matrix_elt(m, 3, 2)), mul(matrix_elt(m, 3, 1), matrix_elt(m, 2, 2)))));
  3054. body.emit(assign(SubFactor03, sub(mul(matrix_elt(m, 2, 0), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 2, 3)))));
  3055. body.emit(assign(SubFactor04, sub(mul(matrix_elt(m, 2, 0), matrix_elt(m, 3, 2)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 2, 2)))));
  3056. body.emit(assign(SubFactor05, sub(mul(matrix_elt(m, 2, 0), matrix_elt(m, 3, 1)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 2, 1)))));
  3057. body.emit(assign(SubFactor06, sub(mul(matrix_elt(m, 1, 2), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 2), matrix_elt(m, 1, 3)))));
  3058. body.emit(assign(SubFactor07, sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 1), matrix_elt(m, 1, 3)))));
  3059. body.emit(assign(SubFactor08, sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 3, 2)), mul(matrix_elt(m, 3, 1), matrix_elt(m, 1, 2)))));
  3060. body.emit(assign(SubFactor09, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 1, 3)))));
  3061. body.emit(assign(SubFactor10, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 3, 2)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 1, 2)))));
  3062. body.emit(assign(SubFactor11, sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 3, 3)), mul(matrix_elt(m, 3, 1), matrix_elt(m, 1, 3)))));
  3063. body.emit(assign(SubFactor12, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 3, 1)), mul(matrix_elt(m, 3, 0), matrix_elt(m, 1, 1)))));
  3064. body.emit(assign(SubFactor13, sub(mul(matrix_elt(m, 1, 2), matrix_elt(m, 2, 3)), mul(matrix_elt(m, 2, 2), matrix_elt(m, 1, 3)))));
  3065. body.emit(assign(SubFactor14, sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 3)), mul(matrix_elt(m, 2, 1), matrix_elt(m, 1, 3)))));
  3066. body.emit(assign(SubFactor15, sub(mul(matrix_elt(m, 1, 1), matrix_elt(m, 2, 2)), mul(matrix_elt(m, 2, 1), matrix_elt(m, 1, 2)))));
  3067. body.emit(assign(SubFactor16, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 3)), mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 3)))));
  3068. body.emit(assign(SubFactor17, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 2)), mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 2)))));
  3069. body.emit(assign(SubFactor18, sub(mul(matrix_elt(m, 1, 0), matrix_elt(m, 2, 1)), mul(matrix_elt(m, 2, 0), matrix_elt(m, 1, 1)))));
  3070. ir_variable *adj = body.make_temp(glsl_type::mat4_type, "adj");
  3071. body.emit(assign(array_ref(adj, 0),
  3072. add(sub(mul(matrix_elt(m, 1, 1), SubFactor00),
  3073. mul(matrix_elt(m, 1, 2), SubFactor01)),
  3074. mul(matrix_elt(m, 1, 3), SubFactor02)),
  3075. WRITEMASK_X));
  3076. body.emit(assign(array_ref(adj, 1), neg(
  3077. add(sub(mul(matrix_elt(m, 1, 0), SubFactor00),
  3078. mul(matrix_elt(m, 1, 2), SubFactor03)),
  3079. mul(matrix_elt(m, 1, 3), SubFactor04))),
  3080. WRITEMASK_X));
  3081. body.emit(assign(array_ref(adj, 2),
  3082. add(sub(mul(matrix_elt(m, 1, 0), SubFactor01),
  3083. mul(matrix_elt(m, 1, 1), SubFactor03)),
  3084. mul(matrix_elt(m, 1, 3), SubFactor05)),
  3085. WRITEMASK_X));
  3086. body.emit(assign(array_ref(adj, 3), neg(
  3087. add(sub(mul(matrix_elt(m, 1, 0), SubFactor02),
  3088. mul(matrix_elt(m, 1, 1), SubFactor04)),
  3089. mul(matrix_elt(m, 1, 2), SubFactor05))),
  3090. WRITEMASK_X));
  3091. body.emit(assign(array_ref(adj, 0), neg(
  3092. add(sub(mul(matrix_elt(m, 0, 1), SubFactor00),
  3093. mul(matrix_elt(m, 0, 2), SubFactor01)),
  3094. mul(matrix_elt(m, 0, 3), SubFactor02))),
  3095. WRITEMASK_Y));
  3096. body.emit(assign(array_ref(adj, 1),
  3097. add(sub(mul(matrix_elt(m, 0, 0), SubFactor00),
  3098. mul(matrix_elt(m, 0, 2), SubFactor03)),
  3099. mul(matrix_elt(m, 0, 3), SubFactor04)),
  3100. WRITEMASK_Y));
  3101. body.emit(assign(array_ref(adj, 2), neg(
  3102. add(sub(mul(matrix_elt(m, 0, 0), SubFactor01),
  3103. mul(matrix_elt(m, 0, 1), SubFactor03)),
  3104. mul(matrix_elt(m, 0, 3), SubFactor05))),
  3105. WRITEMASK_Y));
  3106. body.emit(assign(array_ref(adj, 3),
  3107. add(sub(mul(matrix_elt(m, 0, 0), SubFactor02),
  3108. mul(matrix_elt(m, 0, 1), SubFactor04)),
  3109. mul(matrix_elt(m, 0, 2), SubFactor05)),
  3110. WRITEMASK_Y));
  3111. body.emit(assign(array_ref(adj, 0),
  3112. add(sub(mul(matrix_elt(m, 0, 1), SubFactor06),
  3113. mul(matrix_elt(m, 0, 2), SubFactor07)),
  3114. mul(matrix_elt(m, 0, 3), SubFactor08)),
  3115. WRITEMASK_Z));
  3116. body.emit(assign(array_ref(adj, 1), neg(
  3117. add(sub(mul(matrix_elt(m, 0, 0), SubFactor06),
  3118. mul(matrix_elt(m, 0, 2), SubFactor09)),
  3119. mul(matrix_elt(m, 0, 3), SubFactor10))),
  3120. WRITEMASK_Z));
  3121. body.emit(assign(array_ref(adj, 2),
  3122. add(sub(mul(matrix_elt(m, 0, 0), SubFactor11),
  3123. mul(matrix_elt(m, 0, 1), SubFactor09)),
  3124. mul(matrix_elt(m, 0, 3), SubFactor12)),
  3125. WRITEMASK_Z));
  3126. body.emit(assign(array_ref(adj, 3), neg(
  3127. add(sub(mul(matrix_elt(m, 0, 0), SubFactor08),
  3128. mul(matrix_elt(m, 0, 1), SubFactor10)),
  3129. mul(matrix_elt(m, 0, 2), SubFactor12))),
  3130. WRITEMASK_Z));
  3131. body.emit(assign(array_ref(adj, 0), neg(
  3132. add(sub(mul(matrix_elt(m, 0, 1), SubFactor13),
  3133. mul(matrix_elt(m, 0, 2), SubFactor14)),
  3134. mul(matrix_elt(m, 0, 3), SubFactor15))),
  3135. WRITEMASK_W));
  3136. body.emit(assign(array_ref(adj, 1),
  3137. add(sub(mul(matrix_elt(m, 0, 0), SubFactor13),
  3138. mul(matrix_elt(m, 0, 2), SubFactor16)),
  3139. mul(matrix_elt(m, 0, 3), SubFactor17)),
  3140. WRITEMASK_W));
  3141. body.emit(assign(array_ref(adj, 2), neg(
  3142. add(sub(mul(matrix_elt(m, 0, 0), SubFactor14),
  3143. mul(matrix_elt(m, 0, 1), SubFactor16)),
  3144. mul(matrix_elt(m, 0, 3), SubFactor18))),
  3145. WRITEMASK_W));
  3146. body.emit(assign(array_ref(adj, 3),
  3147. add(sub(mul(matrix_elt(m, 0, 0), SubFactor15),
  3148. mul(matrix_elt(m, 0, 1), SubFactor17)),
  3149. mul(matrix_elt(m, 0, 2), SubFactor18)),
  3150. WRITEMASK_W));
  3151. ir_expression *det =
  3152. add(mul(matrix_elt(m, 0, 0), matrix_elt(adj, 0, 0)),
  3153. add(mul(matrix_elt(m, 0, 1), matrix_elt(adj, 1, 0)),
  3154. add(mul(matrix_elt(m, 0, 2), matrix_elt(adj, 2, 0)),
  3155. mul(matrix_elt(m, 0, 3), matrix_elt(adj, 3, 0)))));
  3156. body.emit(ret(div(adj, det)));
  3157. return sig;
  3158. }
  3159. ir_function_signature *
  3160. builtin_builder::_lessThan(builtin_available_predicate avail,
  3161. const glsl_type *type)
  3162. {
  3163. return binop(ir_binop_less, avail,
  3164. glsl_type::bvec(type->vector_elements), type, type);
  3165. }
  3166. ir_function_signature *
  3167. builtin_builder::_lessThanEqual(builtin_available_predicate avail,
  3168. const glsl_type *type)
  3169. {
  3170. return binop(ir_binop_lequal, avail,
  3171. glsl_type::bvec(type->vector_elements), type, type);
  3172. }
  3173. ir_function_signature *
  3174. builtin_builder::_greaterThan(builtin_available_predicate avail,
  3175. const glsl_type *type)
  3176. {
  3177. return binop(ir_binop_greater, avail,
  3178. glsl_type::bvec(type->vector_elements), type, type);
  3179. }
  3180. ir_function_signature *
  3181. builtin_builder::_greaterThanEqual(builtin_available_predicate avail,
  3182. const glsl_type *type)
  3183. {
  3184. return binop(ir_binop_gequal, avail,
  3185. glsl_type::bvec(type->vector_elements), type, type);
  3186. }
  3187. ir_function_signature *
  3188. builtin_builder::_equal(builtin_available_predicate avail,
  3189. const glsl_type *type)
  3190. {
  3191. return binop(ir_binop_equal, avail,
  3192. glsl_type::bvec(type->vector_elements), type, type);
  3193. }
  3194. ir_function_signature *
  3195. builtin_builder::_notEqual(builtin_available_predicate avail,
  3196. const glsl_type *type)
  3197. {
  3198. return binop(ir_binop_nequal, avail,
  3199. glsl_type::bvec(type->vector_elements), type, type);
  3200. }
  3201. ir_function_signature *
  3202. builtin_builder::_any(const glsl_type *type)
  3203. {
  3204. return unop(always_available, ir_unop_any, glsl_type::bool_type, type);
  3205. }
  3206. ir_function_signature *
  3207. builtin_builder::_all(const glsl_type *type)
  3208. {
  3209. ir_variable *v = in_var(type, "v");
  3210. MAKE_SIG(glsl_type::bool_type, always_available, 1, v);
  3211. switch (type->vector_elements) {
  3212. case 2:
  3213. body.emit(ret(logic_and(swizzle_x(v), swizzle_y(v))));
  3214. break;
  3215. case 3:
  3216. body.emit(ret(logic_and(logic_and(swizzle_x(v), swizzle_y(v)),
  3217. swizzle_z(v))));
  3218. break;
  3219. case 4:
  3220. body.emit(ret(logic_and(logic_and(logic_and(swizzle_x(v), swizzle_y(v)),
  3221. swizzle_z(v)),
  3222. swizzle_w(v))));
  3223. break;
  3224. }
  3225. return sig;
  3226. }
  3227. UNOP(not, ir_unop_logic_not, always_available)
  3228. static bool
  3229. has_lod(const glsl_type *sampler_type)
  3230. {
  3231. assert(sampler_type->is_sampler());
  3232. switch (sampler_type->sampler_dimensionality) {
  3233. case GLSL_SAMPLER_DIM_RECT:
  3234. case GLSL_SAMPLER_DIM_BUF:
  3235. case GLSL_SAMPLER_DIM_MS:
  3236. return false;
  3237. default:
  3238. return true;
  3239. }
  3240. }
  3241. ir_function_signature *
  3242. builtin_builder::_textureSize(builtin_available_predicate avail,
  3243. const glsl_type *return_type,
  3244. const glsl_type *sampler_type)
  3245. {
  3246. ir_variable *s = in_var(sampler_type, "sampler");
  3247. /* The sampler always exists; add optional lod later. */
  3248. MAKE_SIG(return_type, avail, 1, s);
  3249. ir_texture *tex = new(mem_ctx) ir_texture(ir_txs);
  3250. tex->set_sampler(new(mem_ctx) ir_dereference_variable(s), return_type);
  3251. if (has_lod(sampler_type)) {
  3252. ir_variable *lod = in_var(glsl_type::int_type, "lod");
  3253. sig->parameters.push_tail(lod);
  3254. tex->lod_info.lod = var_ref(lod);
  3255. } else {
  3256. tex->lod_info.lod = imm(0u);
  3257. }
  3258. body.emit(ret(tex));
  3259. return sig;
  3260. }
  3261. ir_function_signature *
  3262. builtin_builder::_texture(ir_texture_opcode opcode,
  3263. builtin_available_predicate avail,
  3264. const glsl_type *return_type,
  3265. const glsl_type *sampler_type,
  3266. const glsl_type *coord_type,
  3267. int flags)
  3268. {
  3269. ir_variable *s = in_var(sampler_type, "sampler");
  3270. ir_variable *P = in_var(coord_type, "P");
  3271. /* The sampler and coordinate always exist; add optional parameters later. */
  3272. MAKE_SIG(return_type, avail, 2, s, P);
  3273. ir_texture *tex = new(mem_ctx) ir_texture(opcode);
  3274. tex->set_sampler(var_ref(s), return_type);
  3275. const int coord_size = sampler_type->coordinate_components();
  3276. // removed for glsl optimizer
  3277. //if (coord_size == coord_type->vector_elements) {
  3278. tex->coordinate = var_ref(P);
  3279. //} else {
  3280. // /* The incoming coordinate also has the projector or shadow comparitor,
  3281. // * so we need to swizzle those away.
  3282. // */
  3283. // tex->coordinate = swizzle_for_size(P, coord_size);
  3284. //}
  3285. #if 0 // removed for glsl optimizer
  3286. /* The projector is always in the last component. */
  3287. if (flags & TEX_PROJECT)
  3288. tex->projector = swizzle(P, coord_type->vector_elements - 1, 1);
  3289. if (sampler_type->sampler_shadow) {
  3290. if (opcode == ir_tg4) {
  3291. /* gather has refz as a separate parameter, immediately after the
  3292. * coordinate
  3293. */
  3294. ir_variable *refz = in_var(glsl_type::float_type, "refz");
  3295. sig->parameters.push_tail(refz);
  3296. tex->shadow_comparitor = var_ref(refz);
  3297. } else {
  3298. /* The shadow comparitor is normally in the Z component, but a few types
  3299. * have sufficiently large coordinates that it's in W.
  3300. */
  3301. tex->shadow_comparitor = swizzle(P, MAX2(coord_size, SWIZZLE_Z), 1);
  3302. }
  3303. }
  3304. #endif // #if 0
  3305. if (opcode == ir_txl) {
  3306. ir_variable *lod = in_var(glsl_type::float_type, "lod");
  3307. sig->parameters.push_tail(lod);
  3308. tex->lod_info.lod = var_ref(lod);
  3309. } else if (opcode == ir_txd) {
  3310. int grad_size = coord_size - (sampler_type->sampler_array ? 1 : 0);
  3311. ir_variable *dPdx = in_var(glsl_type::vec(grad_size), "dPdx");
  3312. ir_variable *dPdy = in_var(glsl_type::vec(grad_size), "dPdy");
  3313. sig->parameters.push_tail(dPdx);
  3314. sig->parameters.push_tail(dPdy);
  3315. tex->lod_info.grad.dPdx = var_ref(dPdx);
  3316. tex->lod_info.grad.dPdy = var_ref(dPdy);
  3317. }
  3318. if (flags & (TEX_OFFSET | TEX_OFFSET_NONCONST)) {
  3319. int offset_size = coord_size - (sampler_type->sampler_array ? 1 : 0);
  3320. ir_variable *offset =
  3321. new(mem_ctx) ir_variable(glsl_type::ivec(offset_size), "offset",
  3322. (flags & TEX_OFFSET) ? ir_var_const_in : ir_var_function_in, glsl_precision_undefined);
  3323. sig->parameters.push_tail(offset);
  3324. tex->offset = var_ref(offset);
  3325. }
  3326. if (flags & TEX_OFFSET_ARRAY) {
  3327. ir_variable *offsets =
  3328. new(mem_ctx) ir_variable(glsl_type::get_array_instance(glsl_type::ivec2_type, 4),
  3329. "offsets", ir_var_const_in, glsl_precision_undefined);
  3330. sig->parameters.push_tail(offsets);
  3331. tex->offset = var_ref(offsets);
  3332. }
  3333. if (opcode == ir_tg4) {
  3334. if (flags & TEX_COMPONENT) {
  3335. ir_variable *component =
  3336. new(mem_ctx) ir_variable(glsl_type::int_type, "comp", ir_var_const_in, glsl_precision_undefined);
  3337. sig->parameters.push_tail(component);
  3338. tex->lod_info.component = var_ref(component);
  3339. }
  3340. else {
  3341. tex->lod_info.component = imm(0);
  3342. }
  3343. }
  3344. /* The "bias" parameter comes /after/ the "offset" parameter, which is
  3345. * inconsistent with both textureLodOffset and textureGradOffset.
  3346. */
  3347. if (opcode == ir_txb) {
  3348. ir_variable *bias = in_var(glsl_type::float_type, "bias");
  3349. sig->parameters.push_tail(bias);
  3350. tex->lod_info.bias = var_ref(bias);
  3351. }
  3352. body.emit(ret(tex));
  3353. return sig;
  3354. }
  3355. ir_function_signature *
  3356. builtin_builder::_textureCubeArrayShadow()
  3357. {
  3358. ir_variable *s = in_var(glsl_type::samplerCubeArrayShadow_type, "sampler");
  3359. ir_variable *P = in_var(glsl_type::vec4_type, "P");
  3360. ir_variable *compare = in_var(glsl_type::float_type, "compare");
  3361. MAKE_SIG(glsl_type::float_type, texture_cube_map_array, 3, s, P, compare);
  3362. ir_texture *tex = new(mem_ctx) ir_texture(ir_tex);
  3363. tex->set_sampler(var_ref(s), glsl_type::float_type);
  3364. tex->coordinate = var_ref(P);
  3365. //tex->shadow_comparitor = var_ref(compare); //@TODO ?
  3366. body.emit(ret(tex));
  3367. return sig;
  3368. }
  3369. ir_function_signature *
  3370. builtin_builder::_texelFetch(builtin_available_predicate avail,
  3371. const glsl_type *return_type,
  3372. const glsl_type *sampler_type,
  3373. const glsl_type *coord_type,
  3374. const glsl_type *offset_type)
  3375. {
  3376. ir_variable *s = in_var(sampler_type, "sampler");
  3377. ir_variable *P = in_var(coord_type, "P");
  3378. /* The sampler and coordinate always exist; add optional parameters later. */
  3379. MAKE_SIG(return_type, avail, 2, s, P);
  3380. ir_texture *tex = new(mem_ctx) ir_texture(ir_txf);
  3381. tex->coordinate = var_ref(P);
  3382. tex->set_sampler(var_ref(s), return_type);
  3383. if (sampler_type->sampler_dimensionality == GLSL_SAMPLER_DIM_MS) {
  3384. ir_variable *sample = in_var(glsl_type::int_type, "sample");
  3385. sig->parameters.push_tail(sample);
  3386. tex->lod_info.sample_index = var_ref(sample);
  3387. tex->op = ir_txf_ms;
  3388. } else if (has_lod(sampler_type)) {
  3389. ir_variable *lod = in_var(glsl_type::int_type, "lod");
  3390. sig->parameters.push_tail(lod);
  3391. tex->lod_info.lod = var_ref(lod);
  3392. } else {
  3393. tex->lod_info.lod = imm(0u);
  3394. }
  3395. if (offset_type != NULL) {
  3396. ir_variable *offset =
  3397. new(mem_ctx) ir_variable(offset_type, "offset", ir_var_const_in, glsl_precision_undefined);
  3398. sig->parameters.push_tail(offset);
  3399. tex->offset = var_ref(offset);
  3400. }
  3401. body.emit(ret(tex));
  3402. return sig;
  3403. }
  3404. ir_function_signature *
  3405. builtin_builder::_EmitVertex()
  3406. {
  3407. MAKE_SIG(glsl_type::void_type, gs_only, 0);
  3408. ir_rvalue *stream = new(mem_ctx) ir_constant(0, 1);
  3409. body.emit(new(mem_ctx) ir_emit_vertex(stream));
  3410. return sig;
  3411. }
  3412. ir_function_signature *
  3413. builtin_builder::_EmitStreamVertex(builtin_available_predicate avail,
  3414. const glsl_type *stream_type)
  3415. {
  3416. /* Section 8.12 (Geometry Shader Functions) of the GLSL 4.0 spec says:
  3417. *
  3418. * "Emit the current values of output variables to the current output
  3419. * primitive on stream stream. The argument to stream must be a constant
  3420. * integral expression."
  3421. */
  3422. ir_variable *stream =
  3423. new(mem_ctx) ir_variable(stream_type, "stream", ir_var_const_in, glsl_precision_undefined);
  3424. MAKE_SIG(glsl_type::void_type, avail, 1, stream);
  3425. body.emit(new(mem_ctx) ir_emit_vertex(var_ref(stream)));
  3426. return sig;
  3427. }
  3428. ir_function_signature *
  3429. builtin_builder::_EndPrimitive()
  3430. {
  3431. MAKE_SIG(glsl_type::void_type, gs_only, 0);
  3432. ir_rvalue *stream = new(mem_ctx) ir_constant(0, 1);
  3433. body.emit(new(mem_ctx) ir_end_primitive(stream));
  3434. return sig;
  3435. }
  3436. ir_function_signature *
  3437. builtin_builder::_EndStreamPrimitive(builtin_available_predicate avail,
  3438. const glsl_type *stream_type)
  3439. {
  3440. /* Section 8.12 (Geometry Shader Functions) of the GLSL 4.0 spec says:
  3441. *
  3442. * "Completes the current output primitive on stream stream and starts
  3443. * a new one. The argument to stream must be a constant integral
  3444. * expression."
  3445. */
  3446. ir_variable *stream =
  3447. new(mem_ctx) ir_variable(stream_type, "stream", ir_var_const_in, glsl_precision_undefined);
  3448. MAKE_SIG(glsl_type::void_type, avail, 1, stream);
  3449. body.emit(new(mem_ctx) ir_end_primitive(var_ref(stream)));
  3450. return sig;
  3451. }
  3452. ir_function_signature *
  3453. builtin_builder::_textureQueryLod(const glsl_type *sampler_type,
  3454. const glsl_type *coord_type)
  3455. {
  3456. ir_variable *s = in_var(sampler_type, "sampler");
  3457. ir_variable *coord = in_var(coord_type, "coord");
  3458. /* The sampler and coordinate always exist; add optional parameters later. */
  3459. MAKE_SIG(glsl_type::vec2_type, texture_query_lod, 2, s, coord);
  3460. ir_texture *tex = new(mem_ctx) ir_texture(ir_lod);
  3461. tex->coordinate = var_ref(coord);
  3462. tex->set_sampler(var_ref(s), glsl_type::vec2_type);
  3463. body.emit(ret(tex));
  3464. return sig;
  3465. }
  3466. ir_function_signature *
  3467. builtin_builder::_textureQueryLevels(const glsl_type *sampler_type)
  3468. {
  3469. ir_variable *s = in_var(sampler_type, "sampler");
  3470. const glsl_type *return_type = glsl_type::int_type;
  3471. MAKE_SIG(return_type, texture_query_levels, 1, s);
  3472. ir_texture *tex = new(mem_ctx) ir_texture(ir_query_levels);
  3473. tex->set_sampler(var_ref(s), return_type);
  3474. body.emit(ret(tex));
  3475. return sig;
  3476. }
  3477. UNOP(dFdx, ir_unop_dFdx, fs_oes_derivatives)
  3478. UNOP(dFdxCoarse, ir_unop_dFdx_coarse, fs_derivative_control)
  3479. UNOP(dFdxFine, ir_unop_dFdx_fine, fs_derivative_control)
  3480. UNOP(dFdy, ir_unop_dFdy, fs_oes_derivatives)
  3481. UNOP(dFdyCoarse, ir_unop_dFdy_coarse, fs_derivative_control)
  3482. UNOP(dFdyFine, ir_unop_dFdy_fine, fs_derivative_control)
  3483. ir_function_signature *
  3484. builtin_builder::_fwidth(const glsl_type *type)
  3485. {
  3486. ir_variable *p = in_var(type, "p");
  3487. MAKE_SIG(type, fs_oes_derivatives, 1, p);
  3488. body.emit(ret(add(abs(expr(ir_unop_dFdx, p)), abs(expr(ir_unop_dFdy, p)))));
  3489. return sig;
  3490. }
  3491. ir_function_signature *
  3492. builtin_builder::_fwidthCoarse(const glsl_type *type)
  3493. {
  3494. ir_variable *p = in_var(type, "p");
  3495. MAKE_SIG(type, fs_derivative_control, 1, p);
  3496. body.emit(ret(add(abs(expr(ir_unop_dFdx_coarse, p)),
  3497. abs(expr(ir_unop_dFdy_coarse, p)))));
  3498. return sig;
  3499. }
  3500. ir_function_signature *
  3501. builtin_builder::_fwidthFine(const glsl_type *type)
  3502. {
  3503. ir_variable *p = in_var(type, "p");
  3504. MAKE_SIG(type, fs_derivative_control, 1, p);
  3505. body.emit(ret(add(abs(expr(ir_unop_dFdx_fine, p)),
  3506. abs(expr(ir_unop_dFdy_fine, p)))));
  3507. return sig;
  3508. }
  3509. ir_function_signature *
  3510. builtin_builder::_noise1(const glsl_type *type)
  3511. {
  3512. return unop(v110, ir_unop_noise, glsl_type::float_type, type);
  3513. }
  3514. ir_function_signature *
  3515. builtin_builder::_noise2(const glsl_type *type)
  3516. {
  3517. ir_variable *p = in_var(type, "p");
  3518. MAKE_SIG(glsl_type::vec2_type, v110, 1, p);
  3519. ir_constant_data b_offset;
  3520. b_offset.f[0] = 601.0f;
  3521. b_offset.f[1] = 313.0f;
  3522. b_offset.f[2] = 29.0f;
  3523. b_offset.f[3] = 277.0f;
  3524. ir_variable *a = body.make_temp(glsl_type::float_type, "a");
  3525. ir_variable *b = body.make_temp(glsl_type::float_type, "b");
  3526. ir_variable *t = body.make_temp(glsl_type::vec2_type, "t");
  3527. body.emit(assign(a, expr(ir_unop_noise, p)));
  3528. body.emit(assign(b, expr(ir_unop_noise, add(p, imm(type, b_offset)))));
  3529. body.emit(assign(t, a, WRITEMASK_X));
  3530. body.emit(assign(t, b, WRITEMASK_Y));
  3531. body.emit(ret(t));
  3532. return sig;
  3533. }
  3534. ir_function_signature *
  3535. builtin_builder::_noise3(const glsl_type *type)
  3536. {
  3537. ir_variable *p = in_var(type, "p");
  3538. MAKE_SIG(glsl_type::vec3_type, v110, 1, p);
  3539. ir_constant_data b_offset;
  3540. b_offset.f[0] = 601.0f;
  3541. b_offset.f[1] = 313.0f;
  3542. b_offset.f[2] = 29.0f;
  3543. b_offset.f[3] = 277.0f;
  3544. ir_constant_data c_offset;
  3545. c_offset.f[0] = 1559.0f;
  3546. c_offset.f[1] = 113.0f;
  3547. c_offset.f[2] = 1861.0f;
  3548. c_offset.f[3] = 797.0f;
  3549. ir_variable *a = body.make_temp(glsl_type::float_type, "a");
  3550. ir_variable *b = body.make_temp(glsl_type::float_type, "b");
  3551. ir_variable *c = body.make_temp(glsl_type::float_type, "c");
  3552. ir_variable *t = body.make_temp(glsl_type::vec3_type, "t");
  3553. body.emit(assign(a, expr(ir_unop_noise, p)));
  3554. body.emit(assign(b, expr(ir_unop_noise, add(p, imm(type, b_offset)))));
  3555. body.emit(assign(c, expr(ir_unop_noise, add(p, imm(type, c_offset)))));
  3556. body.emit(assign(t, a, WRITEMASK_X));
  3557. body.emit(assign(t, b, WRITEMASK_Y));
  3558. body.emit(assign(t, c, WRITEMASK_Z));
  3559. body.emit(ret(t));
  3560. return sig;
  3561. }
  3562. ir_function_signature *
  3563. builtin_builder::_noise4(const glsl_type *type)
  3564. {
  3565. ir_variable *p = in_var(type, "p");
  3566. MAKE_SIG(glsl_type::vec4_type, v110, 1, p);
  3567. ir_variable *_p = body.make_temp(type, "_p");
  3568. ir_constant_data p_offset;
  3569. p_offset.f[0] = 1559.0f;
  3570. p_offset.f[1] = 113.0f;
  3571. p_offset.f[2] = 1861.0f;
  3572. p_offset.f[3] = 797.0f;
  3573. body.emit(assign(_p, add(p, imm(type, p_offset))));
  3574. ir_constant_data offset;
  3575. offset.f[0] = 601.0f;
  3576. offset.f[1] = 313.0f;
  3577. offset.f[2] = 29.0f;
  3578. offset.f[3] = 277.0f;
  3579. ir_variable *a = body.make_temp(glsl_type::float_type, "a");
  3580. ir_variable *b = body.make_temp(glsl_type::float_type, "b");
  3581. ir_variable *c = body.make_temp(glsl_type::float_type, "c");
  3582. ir_variable *d = body.make_temp(glsl_type::float_type, "d");
  3583. ir_variable *t = body.make_temp(glsl_type::vec4_type, "t");
  3584. body.emit(assign(a, expr(ir_unop_noise, p)));
  3585. body.emit(assign(b, expr(ir_unop_noise, add(p, imm(type, offset)))));
  3586. body.emit(assign(c, expr(ir_unop_noise, _p)));
  3587. body.emit(assign(d, expr(ir_unop_noise, add(_p, imm(type, offset)))));
  3588. body.emit(assign(t, a, WRITEMASK_X));
  3589. body.emit(assign(t, b, WRITEMASK_Y));
  3590. body.emit(assign(t, c, WRITEMASK_Z));
  3591. body.emit(assign(t, d, WRITEMASK_W));
  3592. body.emit(ret(t));
  3593. return sig;
  3594. }
  3595. ir_function_signature *
  3596. builtin_builder::_bitfieldExtract(const glsl_type *type)
  3597. {
  3598. ir_variable *value = in_var(type, "value");
  3599. ir_variable *offset = in_var(glsl_type::int_type, "offset");
  3600. ir_variable *bits = in_var(glsl_type::int_type, "bits");
  3601. MAKE_SIG(type, gpu_shader5, 3, value, offset, bits);
  3602. body.emit(ret(expr(ir_triop_bitfield_extract, value, offset, bits)));
  3603. return sig;
  3604. }
  3605. ir_function_signature *
  3606. builtin_builder::_bitfieldInsert(const glsl_type *type)
  3607. {
  3608. ir_variable *base = in_var(type, "base");
  3609. ir_variable *insert = in_var(type, "insert");
  3610. ir_variable *offset = in_var(glsl_type::int_type, "offset");
  3611. ir_variable *bits = in_var(glsl_type::int_type, "bits");
  3612. MAKE_SIG(type, gpu_shader5, 4, base, insert, offset, bits);
  3613. body.emit(ret(bitfield_insert(base, insert, offset, bits)));
  3614. return sig;
  3615. }
  3616. UNOP(bitfieldReverse, ir_unop_bitfield_reverse, gpu_shader5)
  3617. ir_function_signature *
  3618. builtin_builder::_bitCount(const glsl_type *type)
  3619. {
  3620. return unop(gpu_shader5, ir_unop_bit_count,
  3621. glsl_type::ivec(type->vector_elements), type);
  3622. }
  3623. ir_function_signature *
  3624. builtin_builder::_findLSB(const glsl_type *type)
  3625. {
  3626. return unop(gpu_shader5, ir_unop_find_lsb,
  3627. glsl_type::ivec(type->vector_elements), type);
  3628. }
  3629. ir_function_signature *
  3630. builtin_builder::_findMSB(const glsl_type *type)
  3631. {
  3632. return unop(gpu_shader5, ir_unop_find_msb,
  3633. glsl_type::ivec(type->vector_elements), type);
  3634. }
  3635. ir_function_signature *
  3636. builtin_builder::_fma(const glsl_type *type)
  3637. {
  3638. ir_variable *a = in_var(type, "a");
  3639. ir_variable *b = in_var(type, "b");
  3640. ir_variable *c = in_var(type, "c");
  3641. MAKE_SIG(type, gpu_shader5, 3, a, b, c);
  3642. body.emit(ret(ir_builder::fma(a, b, c)));
  3643. return sig;
  3644. }
  3645. ir_function_signature *
  3646. builtin_builder::_ldexp(const glsl_type *x_type, const glsl_type *exp_type)
  3647. {
  3648. return binop(ir_binop_ldexp, gpu_shader5, x_type, x_type, exp_type);
  3649. }
  3650. ir_function_signature *
  3651. builtin_builder::_frexp(const glsl_type *x_type, const glsl_type *exp_type)
  3652. {
  3653. ir_variable *x = in_var(x_type, "x");
  3654. ir_variable *exponent = out_var(exp_type, "exp");
  3655. MAKE_SIG(x_type, gpu_shader5, 2, x, exponent);
  3656. const unsigned vec_elem = x_type->vector_elements;
  3657. const glsl_type *bvec = glsl_type::get_instance(GLSL_TYPE_BOOL, vec_elem, 1);
  3658. const glsl_type *uvec = glsl_type::get_instance(GLSL_TYPE_UINT, vec_elem, 1);
  3659. /* Single-precision floating-point values are stored as
  3660. * 1 sign bit;
  3661. * 8 exponent bits;
  3662. * 23 mantissa bits.
  3663. *
  3664. * An exponent shift of 23 will shift the mantissa out, leaving only the
  3665. * exponent and sign bit (which itself may be zero, if the absolute value
  3666. * was taken before the bitcast and shift.
  3667. */
  3668. ir_constant *exponent_shift = imm(23);
  3669. ir_constant *exponent_bias = imm(-126, vec_elem);
  3670. ir_constant *sign_mantissa_mask = imm(0x807fffffu, vec_elem);
  3671. /* Exponent of floating-point values in the range [0.5, 1.0). */
  3672. ir_constant *exponent_value = imm(0x3f000000u, vec_elem);
  3673. ir_variable *is_not_zero = body.make_temp(bvec, "is_not_zero");
  3674. body.emit(assign(is_not_zero, nequal(abs(x), imm(0.0f, vec_elem))));
  3675. /* Since abs(x) ensures that the sign bit is zero, we don't need to bitcast
  3676. * to unsigned integers to ensure that 1 bits aren't shifted in.
  3677. */
  3678. body.emit(assign(exponent, rshift(bitcast_f2i(abs(x)), exponent_shift)));
  3679. body.emit(assign(exponent, add(exponent, csel(is_not_zero, exponent_bias,
  3680. imm(0, vec_elem)))));
  3681. ir_variable *bits = body.make_temp(uvec, "bits");
  3682. body.emit(assign(bits, bitcast_f2u(x)));
  3683. body.emit(assign(bits, bit_and(bits, sign_mantissa_mask)));
  3684. body.emit(assign(bits, bit_or(bits, csel(is_not_zero, exponent_value,
  3685. imm(0u, vec_elem)))));
  3686. body.emit(ret(bitcast_u2f(bits)));
  3687. return sig;
  3688. }
  3689. ir_function_signature *
  3690. builtin_builder::_uaddCarry(const glsl_type *type)
  3691. {
  3692. ir_variable *x = in_var(type, "x");
  3693. ir_variable *y = in_var(type, "y");
  3694. ir_variable *carry = out_var(type, "carry");
  3695. MAKE_SIG(type, gpu_shader5, 3, x, y, carry);
  3696. body.emit(assign(carry, ir_builder::carry(x, y)));
  3697. body.emit(ret(add(x, y)));
  3698. return sig;
  3699. }
  3700. ir_function_signature *
  3701. builtin_builder::_usubBorrow(const glsl_type *type)
  3702. {
  3703. ir_variable *x = in_var(type, "x");
  3704. ir_variable *y = in_var(type, "y");
  3705. ir_variable *borrow = out_var(type, "borrow");
  3706. MAKE_SIG(type, gpu_shader5, 3, x, y, borrow);
  3707. body.emit(assign(borrow, ir_builder::borrow(x, y)));
  3708. body.emit(ret(sub(x, y)));
  3709. return sig;
  3710. }
  3711. /**
  3712. * For both imulExtended() and umulExtended() built-ins.
  3713. */
  3714. ir_function_signature *
  3715. builtin_builder::_mulExtended(const glsl_type *type)
  3716. {
  3717. ir_variable *x = in_var(type, "x");
  3718. ir_variable *y = in_var(type, "y");
  3719. ir_variable *msb = out_var(type, "msb");
  3720. ir_variable *lsb = out_var(type, "lsb");
  3721. MAKE_SIG(glsl_type::void_type, gpu_shader5, 4, x, y, msb, lsb);
  3722. body.emit(assign(msb, imul_high(x, y)));
  3723. body.emit(assign(lsb, mul(x, y)));
  3724. return sig;
  3725. }
  3726. ir_function_signature *
  3727. builtin_builder::_interpolateAtCentroid(const glsl_type *type)
  3728. {
  3729. ir_variable *interpolant = in_var(type, "interpolant");
  3730. interpolant->data.must_be_shader_input = 1;
  3731. MAKE_SIG(type, fs_gpu_shader5, 1, interpolant);
  3732. body.emit(ret(interpolate_at_centroid(interpolant)));
  3733. return sig;
  3734. }
  3735. ir_function_signature *
  3736. builtin_builder::_interpolateAtOffset(const glsl_type *type)
  3737. {
  3738. ir_variable *interpolant = in_var(type, "interpolant");
  3739. interpolant->data.must_be_shader_input = 1;
  3740. ir_variable *offset = in_var(glsl_type::vec2_type, "offset");
  3741. MAKE_SIG(type, fs_gpu_shader5, 2, interpolant, offset);
  3742. body.emit(ret(interpolate_at_offset(interpolant, offset)));
  3743. return sig;
  3744. }
  3745. ir_function_signature *
  3746. builtin_builder::_interpolateAtSample(const glsl_type *type)
  3747. {
  3748. ir_variable *interpolant = in_var(type, "interpolant");
  3749. interpolant->data.must_be_shader_input = 1;
  3750. ir_variable *sample_num = in_var(glsl_type::int_type, "sample_num");
  3751. MAKE_SIG(type, fs_gpu_shader5, 2, interpolant, sample_num);
  3752. body.emit(ret(interpolate_at_sample(interpolant, sample_num)));
  3753. return sig;
  3754. }
  3755. ir_function_signature *
  3756. builtin_builder::_atomic_intrinsic(builtin_available_predicate avail)
  3757. {
  3758. ir_variable *counter = in_var(glsl_type::atomic_uint_type, "counter");
  3759. MAKE_INTRINSIC(glsl_type::uint_type, avail, 1, counter);
  3760. return sig;
  3761. }
  3762. ir_function_signature *
  3763. builtin_builder::_atomic_op(const char *intrinsic,
  3764. builtin_available_predicate avail)
  3765. {
  3766. ir_variable *counter = in_var(glsl_type::atomic_uint_type, "atomic_counter");
  3767. MAKE_SIG(glsl_type::uint_type, avail, 1, counter);
  3768. ir_variable *retval = body.make_temp(glsl_type::uint_type, "atomic_retval");
  3769. body.emit(call(shader->symbols->get_function(intrinsic), retval,
  3770. sig->parameters));
  3771. body.emit(ret(retval));
  3772. return sig;
  3773. }
  3774. ir_function_signature *
  3775. builtin_builder::_min3(const glsl_type *type)
  3776. {
  3777. ir_variable *x = in_var(type, "x");
  3778. ir_variable *y = in_var(type, "y");
  3779. ir_variable *z = in_var(type, "z");
  3780. MAKE_SIG(type, shader_trinary_minmax, 3, x, y, z);
  3781. ir_expression *min3 = min2(x, min2(y,z));
  3782. body.emit(ret(min3));
  3783. return sig;
  3784. }
  3785. ir_function_signature *
  3786. builtin_builder::_max3(const glsl_type *type)
  3787. {
  3788. ir_variable *x = in_var(type, "x");
  3789. ir_variable *y = in_var(type, "y");
  3790. ir_variable *z = in_var(type, "z");
  3791. MAKE_SIG(type, shader_trinary_minmax, 3, x, y, z);
  3792. ir_expression *max3 = max2(x, max2(y,z));
  3793. body.emit(ret(max3));
  3794. return sig;
  3795. }
  3796. ir_function_signature *
  3797. builtin_builder::_mid3(const glsl_type *type)
  3798. {
  3799. ir_variable *x = in_var(type, "x");
  3800. ir_variable *y = in_var(type, "y");
  3801. ir_variable *z = in_var(type, "z");
  3802. MAKE_SIG(type, shader_trinary_minmax, 3, x, y, z);
  3803. ir_expression *mid3 = max2(min2(x, y), max2(min2(x, z), min2(y, z)));
  3804. body.emit(ret(mid3));
  3805. return sig;
  3806. }
  3807. ir_function_signature *
  3808. builtin_builder::_image_prototype(const glsl_type *image_type,
  3809. const char *intrinsic_name,
  3810. unsigned num_arguments,
  3811. unsigned flags)
  3812. {
  3813. const glsl_type *data_type = glsl_type::get_instance(
  3814. image_type->sampler_type,
  3815. (flags & IMAGE_FUNCTION_HAS_VECTOR_DATA_TYPE ? 4 : 1),
  3816. 1);
  3817. const glsl_type *ret_type = (flags & IMAGE_FUNCTION_RETURNS_VOID ?
  3818. glsl_type::void_type : data_type);
  3819. /* Addressing arguments that are always present. */
  3820. ir_variable *image = in_var(image_type, "image");
  3821. ir_variable *coord = in_var(
  3822. glsl_type::ivec(image_type->coordinate_components()), "coord");
  3823. ir_function_signature *sig = new_sig(
  3824. ret_type, shader_image_load_store, 2, image, coord);
  3825. /* Sample index for multisample images. */
  3826. if (image_type->sampler_dimensionality == GLSL_SAMPLER_DIM_MS)
  3827. sig->parameters.push_tail(in_var(glsl_type::int_type, "sample"));
  3828. /* Data arguments. */
  3829. for (unsigned i = 0; i < num_arguments; ++i) {
  3830. char *arg_name = ralloc_asprintf(NULL, "arg%d", i);
  3831. sig->parameters.push_tail(in_var(data_type, arg_name));
  3832. ralloc_free(arg_name);
  3833. }
  3834. /* Set the maximal set of qualifiers allowed for this image
  3835. * built-in. Function calls with arguments having fewer
  3836. * qualifiers than present in the prototype are allowed by the
  3837. * spec, but not with more, i.e. this will make the compiler
  3838. * accept everything that needs to be accepted, and reject cases
  3839. * like loads from write-only or stores to read-only images.
  3840. */
  3841. image->data.image_read_only = (flags & IMAGE_FUNCTION_READ_ONLY) != 0;
  3842. image->data.image_write_only = (flags & IMAGE_FUNCTION_WRITE_ONLY) != 0;
  3843. image->data.image_coherent = true;
  3844. image->data.image_volatile = true;
  3845. image->data.image_restrict = true;
  3846. return sig;
  3847. }
  3848. ir_function_signature *
  3849. builtin_builder::_image(const glsl_type *image_type,
  3850. const char *intrinsic_name,
  3851. unsigned num_arguments,
  3852. unsigned flags)
  3853. {
  3854. ir_function_signature *sig = _image_prototype(image_type, intrinsic_name,
  3855. num_arguments, flags);
  3856. if (flags & IMAGE_FUNCTION_EMIT_STUB) {
  3857. ir_factory body(&sig->body, mem_ctx);
  3858. ir_function *f = shader->symbols->get_function(intrinsic_name);
  3859. if (flags & IMAGE_FUNCTION_RETURNS_VOID) {
  3860. body.emit(call(f, NULL, sig->parameters));
  3861. } else {
  3862. ir_variable *ret_val =
  3863. body.make_temp(sig->return_type, "_ret_val");
  3864. body.emit(call(f, ret_val, sig->parameters));
  3865. body.emit(ret(ret_val));
  3866. }
  3867. sig->is_defined = true;
  3868. } else {
  3869. sig->is_intrinsic = true;
  3870. }
  3871. return sig;
  3872. }
  3873. ir_function_signature *
  3874. builtin_builder::_memory_barrier_intrinsic(builtin_available_predicate avail)
  3875. {
  3876. MAKE_INTRINSIC(glsl_type::void_type, avail, 0);
  3877. return sig;
  3878. }
  3879. ir_function_signature *
  3880. builtin_builder::_memory_barrier(builtin_available_predicate avail)
  3881. {
  3882. MAKE_SIG(glsl_type::void_type, avail, 0);
  3883. body.emit(call(shader->symbols->get_function("__intrinsic_memory_barrier"),
  3884. NULL, sig->parameters));
  3885. return sig;
  3886. }
  3887. /** @} */
  3888. /******************************************************************************/
  3889. //@TODO: implement
  3890. typedef int mtx_t;
  3891. #define _MTX_INITIALIZER_NP 0
  3892. #define mtx_lock(name)
  3893. #define mtx_unlock(name)
  3894. /* The singleton instance of builtin_builder. */
  3895. static builtin_builder builtins;
  3896. static mtx_t builtins_lock = _MTX_INITIALIZER_NP;
  3897. /**
  3898. * External API (exposing the built-in module to the rest of the compiler):
  3899. * @{
  3900. */
  3901. void
  3902. _mesa_glsl_initialize_builtin_functions()
  3903. {
  3904. mtx_lock(&builtins_lock);
  3905. builtins.initialize();
  3906. mtx_unlock(&builtins_lock);
  3907. }
  3908. void
  3909. _mesa_glsl_release_builtin_functions()
  3910. {
  3911. mtx_lock(&builtins_lock);
  3912. builtins.release();
  3913. mtx_unlock(&builtins_lock);
  3914. }
  3915. ir_function_signature *
  3916. _mesa_glsl_find_builtin_function(_mesa_glsl_parse_state *state,
  3917. const char *name, exec_list *actual_parameters)
  3918. {
  3919. ir_function_signature * s;
  3920. mtx_lock(&builtins_lock);
  3921. s = builtins.find(state, name, actual_parameters);
  3922. mtx_unlock(&builtins_lock);
  3923. return s;
  3924. }
  3925. gl_shader *
  3926. _mesa_glsl_get_builtin_function_shader()
  3927. {
  3928. return builtins.shader;
  3929. }
  3930. /** @} */