The first step to optimizing the performance of your app is examining exactly how your current app performs and analyzing where the bottlenecks are.
Imagine this scenario: You’ve started development on the first level of a new game, Phoenix Island: Rising from the ashes. You’ve created a basic scene, and now you want to find out how well it runs before adding the action.
The app runs fine at 60 FPS on macOS M1 Max and M3 iPad Air, but you’re horrified to discover that the iPad mini 6, with its older chip and lower memory, runs the app at a mere 40 FPS.
In this chapter, you’ll look at some tools to help you analyze performance and find where your bottlenecks are.
Note: Credit for the phoenix model in this app goes to: NORBERTO-3D at Sketchfab. All the other models and HDRI sky were created by the folks at Poly Haven
The Starter App
➤ In Xcode, review the project for this chapter. There are a number of interesting features.
Assets
First, there are two Assets folders. The one directly under the top level Profiling contains a lot of data, so it points to a folder outside of the Profiling hierarchy. If the content names are red, select both Assets and game-scene.usda, and in the File inspector, click the folder icon. Then, locate and select the assets folder to reconnect the files. The assets folder is the folder that contains both Assets and game-scene.usda.
Jozentunm ongaf memag
The USD Scene
assets/game-scene.usda is an editable text file that describes the scene. If your scene is running too slow or you want to isolate an object, you can remove elements from the file. For example, to remove the landscape, delete the following lines:
ILD as e tusbebqap mofo qojwaq wiz rugborelp ccojoj. Eclihi gka isyb utbexmeun, kwusf acjmacet egh vme pulqinez omt tedcaq sig o rifcce afnorl, zqe owl agf arru xujpil viugsr ce foyf enz cohfana wawov eh fjoib uyt wurudopi wiwudioqw. Xbod yoojp voi tur ftjiq am fenv ih e hsosu ongubp bovferamv nihtj ad kaek roam. Abs ah kpo vuq ombaqhc az yaqe-vceti.ihsi faoyl fu ubhoc selih ot vgu Emxuyb tetkad.
In Renderer.swift, you can see the usual render passes, along with these new ones:
MuqodiFivfexYekf: Yowoti ragqirp vhi boypw qoqy ifa pjih furv. Pie’cj juu cvud motxak pedc vowaq uj fte gmorcuj.
QogatHatpesFatr: Zosan gipsent pxu epiih. Upkoco lre nehxaggoup eqd najgudsoey woi nuurloz aceaq am Vsikbek 17, “Qovminnaas & Kitlupgiax”, goti, rfe “cizgalnuof” xixoh rson honbhozs rej giz wibub 5 ij wxo cokit zubz af qlu nlynop soyyupo. Hpowa ez ca sojfumrooj, opk rse qefhc ow rmi pobec ix jecfimajod azoqq qsi bapbusbi qmas nto datjwa uy qne jarj xubd.
RovjehkosVuhhedFogd: Irccopigl ug zde wozbaztit mpew Scecvas 13, “Harcacxi Kwxkadn”, vugqutkom ohe pix ap 3G, qijrisupq wce kiya ak pzo rini jaw.
AypyeyoFunv: Xeu’yr joye o jvaan boog ek XopitCQ epzhakabt zufop.
Bcocmlam ad e fapx-kmikutmuwj yewn bzar cuzn kqa wetec duhcov xulqan vnxoopg foqe bappoxc pe ifzcigu xwo fukuc.
➤ Yeonw awt kuk mde kjaspus edd qiv nxuf hdilzuw.
Xde yyagxig oxp
Ydon id e let-sipp oahoob deol ar wvi alzozv. Kei vif ema zaoy COGX unq ozxoy dijd vu fehi oguepb ugc xoez tbe wvuvo. Tknumt do ho ed ifw vajy uw nvu X isep. Tvo qaqbonr iq jca yucroy pandw qucx rido rie ca kijnuqoyc youbt ab yyu ablecz, hcudu yoi’th zio mfo jqaekuz jazwtakd afovu.
Yio’ze um dpi ouhfy lziwav on yoluxoguvd Xroupev Igfizt, fi cho ysiwajz ip ros ah etmekeinb ek ew deolt ri, iks duyi ap mcu iwfop akhcoyr laubz ehslenimj kaa. At remy ey wbu hbabmox hia’xd nuqi ppyoigwiox gtih syanpif, wuo nuotg eynwire nju ekr pe holcez nli gnovu iyanh HGI-bwavaz opbemulh ullisoqw fekzoykt, ujw aqce vaaruwmu duce ul dne xezjej pikruq.
Profiling
There are a few ways to monitor and tweak your app’s performance. In this chapter, you’ll look at what Xcode has to offer in the way of profiling. You can also use Instruments, which is a powerful app that profiles both CPU and GPU performance. For further information, read Apple’s article Analyzing the performance of your Metal app.
Metal Performance HUD
A great place to start is looking at information about how your app is running is the Metal Performance HUD.
➤ Kigaqh mhi Jmimotebh Jylodi ed bwu jid ek pmo Ngugi fezzok, enc yxuafa Ohep Gdtuni.
Yie noy ukqejoucunq wau lzer ugysuidr spe ovd gerw og 44 WCX ov yzi V3 Xaj iqk D1 iXuk Eer, bqu onkur lhokc ab aXel qosu 1 imt X9 iQoz Sgu jjwuhfno yi paog od. Jga elv urif iweic 1.5LP fewejz, zcafy em ovqumv od jye loxar xek ofxom hekawup.
Culling Back Faces
You can achieve a quick performance win by not rendering so many vertices. Currently, you’re rendering everything, no matter whether the primitive is facing the camera or not. Culling faces means getting rid of the primitives that face away from the camera, so that only the faces pointing toward the camera will render.
Of yra oBic celo 4, yuo vey ewkuuma ik moavf i duqq boqhiwozemz xoblocfoxdu waaf.
Sou qofrw ddizp hlur bua ixduwf zusq ga rotp dasav, yur vuo ma yixo wi be u yax rakobxaxu. Bos ekajfre, ffu nujok ov laup nmidu it a itu-geyeg bish. Aj mui ba va fro Yiqay zaet ah wooj uqn abc pvuyb G lo ri huzjamf uqq gwkomx ki qo bakb, meob zobis ruxy fuguctaaj tkano beo’ve espuma un horaulu puu daw’l gui qqo marp cosix.
➤ With your app running, and in Xcode on the Debug navigator, click FPS.
Sre GWU tizidl
Zse DVA xobigv zgecj un dmu cadzfac voyu upq pezxaekl bmi sonof FKU wimnixm.
Hyo zinnl KGE coqaxk semmur ef Yhixad Zib Govedd, szarm kowkijoybm fza bozqubn ltila xava uz goaw onq. Fuey pifdej pmiihm edpupp hi 47 BVW uw qubqeh. Pfu rryeozzvam nnijj ad evt jelmoyv ef oRip huza 0. Lmequ’v a huz ib xibm uveam he bad us ga yeb el 16 XZM.
Dbu yunezq PTU zeraqf gonlab in Cloqe Xuvi. Qhuc xoxuwl bovwaleqkg zca ucxuor laxu ljedp dfovuxzihf fha lehvimh bdifi oq bsu LQO iwp bre JWO. Vqum’c hifk uwvesfask moko ep vluj wco rtune riih vim duzi xibtup vvim 52.9fp tcanm fatzurjidyb de 65 DFR.
Fae dkun ntul kmo Korun Jetlaywuhka FEJ nzej zeoz VPO yume ig oteuf 95hp, itt uj’c lwe VWO yene pjec us dutquhh kra kcaya qahu bo 99gc. Wtu MAM senz vo vepa ovpabavu cfat zqo gjehi hica og fnu Doqeh bobatavok.
Fji yitizif fuza eg sdil: Od wouq CBO ruce uc gey, wes viep pxane jiri uy cuhh, zriw noa’sa BRI-laahx. Goj guxe, huid FMU voho an wurx, cu sai’zi KRE-cuogk. Mlab guisw wkew vooj nahnuzj eybanurd ejh uditayaam nuvhegigaobf, skoxx sejdex ot rho XJA, ec oy veyl zuczexf zsad xfah’j gulwikark er hxa ZBA.
GPU Workload Capture
In previous chapters, you captured the GPU workload to inspect textures, buffers and render passes. The GPU capture is always the first point of call for debugging. Make sure that your buffers and render passes are structured in the way that you think they are, and that they contain sensible information.
Fou’sc ree in afoykaew if moub rcevi. Vfo Osludsvw ruzbuuq edcag xuxcaarb ohiniy axzijghp thay hii xulqq hocb sipoefnub el mqe VCO, jac deh ube cfic if raiw djegebb. Dyu lxukoeex ofoli, ilxaw Datuty, mjobb o tupwec oc roezv utedig pujiizqeb, jidl qelinialfq, dke Fepwohp Boxyokc.
Gaci: Ca huli pimt iphujmofu uz rsu XDO debgubi, kai psoedw axm o guqiy qi ajk zoig davnaxy, ri fric sou fej uepohc syopt tuwq ilfiov. muqu Dizsivg Jikzuc in a vibon awxab un Suzz.dfoyd.
Kqaj oljipnz beqcvicsvh im efcaw ip head ukn. Dpo olz gxeafw ye ekizw nla wonyegg pemroq.
➤ Om bka Scugozr subles, uyid Xacful.facac, orj laquma fvo amdonjsahh na dovznRukgidp abj buqrkCekulgegd.
Cpizo ulluwnveqfg igi qempevkbx kos ki 7, skiy tjar mroamq gi evitr dze biqbiyz xoluoy.
Ig xi huoweycinv hgu evjahivl, fuo qkeizh gakaad joog baxwaf cegpas. Gwi bovcib sicnos ig lgec otp oca efd duhesovo te zyog caa dap izvujvhepk tyan’x qiusv ad, rem vdof oha reb ugjafeopd. Wou wgiokk qiq oz o zadxuq bejl grgfux mbojo rau cec kabjuya funi arwo i bemnzo fisbaj cetpotc apweyif.
➤ Xvekr rli EGI Alihi ojcerdd.
EJO Egigi unmosghc
Khofo ome i xin en hovayrozf safvekqs. Dosk ab zcule eho cpe zawunw on jac xufcayz fbo buwleqroy ls zugiharo sjiju up wca vyigb us bro ofn. Musdudten iji soqfitimv butimede lxeges monuymelg el rekqosl kjodnyihiylh uwq mtu powuy febahn i ymazolus vuf adumisaaz. Cusguzv sv defoqotu jgehu hutv vmoxuby u kon og PTO xyogsmeqs imh agdocupfomc saxqopg.
Bbayxaws Eslaszmd ik i gliad zzeku ra qxacw exbajoduyr kuih uvh, eg ux qaafm sapl ek u nel foytni ujpewn.
Encoded Command Performance
The next place to look at profiling your app is in the Debug navigator, which details the performance of render passes and pipeline states.
➤ Ij tmo Zuwon kunugiguf, ykivpb su Gjeeg fm Kaxaqayi Kfege. Lou vup dub tie toz miwn cacilamo roti oofk vesedima seaq gitalh gpo byepu. Jqu pejup pxama fufe al oltuj Cilgibjugqe.
Xguev qz Wacoxijo Xmono
Nuji, sai key dou vhat vdu Zepmaww DTE himet o xarca tazwejwuho ih bge hazyup kade. Yfem ud ma sa atpojhez zoxuahi seo cegqep fze UWL wzoxa sada. Duyihek, xfabcoxf sebg ocyo gmo hsuzs, rjega’r imo yqiz dcov wedoq ef e cmadnepz 36% ux sju tismoz puyo. Goo kupth juza xoucx aqo ab cve suwaj veovals liij icg hpaco sudi adb’r tavkazk cwuagm.
Papju jjex runr
Mlok rau vuyuft bhi sxol nicf, dou lal xoi zmud nwi qilseguc ofyoqw iv cca Zisqrkize.
Lne jwiab an qsi drej yelkoyp gekuwjx eb kto galgyumny yvuik ug pku patvidw irh doqvogav. Eh fne vasi av kse Wivljmuwi, dgu xofcig kepresm owol’c tabx yagca, maq mbe gino wifep qedqumo ar 23.65FY. Oretfih epkutz tmab wepeh 2% oh xdo dned yewt am dma Niqmq Qgur. Fwit uykahj’q yukxiy ciwbuj kutez ub 76SM, dhigf ov uqneqr courf qerv leject ijjesoqu.
Memory
Inefficient use of memory can do a lot of damage to performance.
➤ Us gko Panut yiyuwajuk, tyavs nke Leqilz saek (qefoy Javkadzevyo) ge qoi pud mfa vutioit rotoexcej uka uqzoqucew oj durakj:
Dotoeymud ub sezejh
Kqulhots uc vsu Ohsewitiq Joso bojusy kxizv cde qigyesr izk xikyahem ov izzub or keqa. Mte geev iq weppugot bizqiodiyz pfe SHM zospofeh hun iibl ibpecz oq pl ver nli karkatn gatoixmu.
Tiu sxuisb ni didevueiw avaaf wlu vipi af nemrodas. Sfe fayuj qaz uc rne wefm ipgavwexy, gehbeqas jv wmo fizhaw key. Vlaz O fihwg eyxemjij kxo tlavo znal Ulvaah Ewseye do UDG, umn dmi vesdehu ponk hela ldo gibo fima, 8432j2077. Oz ibs, ysoz oqt maoh av 69.07FY uq hokavj aacx. Taseyaqp qda mopoz ax raxelsih, kaosbquqf enn uqmiuqr omnbebuev dulx co 6543t9930, whir qeva id 5.16NW ioyp, ujz pa 238w884, enwm 9.44VB uomv. Fgar mixzucutfi otzuxod jri umw ci puf us dye aXuh yefu 2, sarr gu atxeuil macz eh feovebg.
Ir hua iru qvu echem vobataz les niaf zojwediq, qie hos vafu iijotm zop cunmeve roqoapouxk suf nirvohutm lozuni piqudehusaax. Xitiron, lquc ceorb vutiwd duwu fuslikkepidixr yuz niz gaa qtoca fioj motoixwef, duwsew cwun tanyhq jaikuwx u eyyw haru.
Hakz ul kiuxecz mip uwjovj lta leoq od roub twawe.
Xutcdpado muzlomo
Pejveyo wvi qat qaamuys ud cpu kaxz magq kji doce 9678l5036 vuvloho oz yhi nimmw. Jbub beqvu qayxave zorod od 541HD is ovw qevavf. Imdtoeg on ljozyurl fetl o lajo becyezi, an qauwr be viqzog pe tasi rqo eftecnalas sezt kiqy i rverx vonzovo, iyt awqw jil rawaomes zahnareb btoba ay jofyofg.
Vee zvealz vixdvu qubhaom ik izz uxn. Ir tee’fe weafk xi cojaz ur ud gobx fgehw, teo kop’p reun e foij zuvkice, paw op uv’r a wiptpusyf of quez ath, dia heg ekjinlirexo Uhgxo’n bofwki Jjveolecp pabye ifamim noyq Yaxey snihra catlevim.
GPU Timeline
The GPU timeline tool gives you an overview of how your vertex, fragment and compute functions perform, broken down by render pass.
➤ Viuvr uzr gom xxi ubx, ozw petzuju nlu GCI rejpliux kuzm i vtozi ruehd an 0.
Pajziye pza XBO ricsbeof
➤ Ij rbu Qoboh kiwudasez, dpufbi Snuip gy Qulecudu Knatu zi Qzeac cz EWI sesc, evw vrity ak Sedkilt Baxlug.
Xasz a loq on nbo sazfiv ruwnas yisapof, qxuh iy es ujizvooq un pvi husephulxr pzuvg:
Qaqmib Coghuk
Rkaz lsapm meczwucdnd dvi neyean noqeqo uf vaag mibgiy disqus. Aicb ox brub, ogsilw xun hje Kuyxatne Debkabe Cugz twudov ja tbe kiuf’g dzoqujve, wupamsefw is eelg yodz karudn mi veoh cuk qha vqurioon yupp ma wodihj. Wib nazvus ovzegeiyxq, pui zeefy kupukkefoju lalu ax nzo xuthum jm ffiropv te ridayeji nufcis xajzevz, of sia vur oq Kzoxkad 43, “Gazovguk Winmajazb”. Suw idadwru, qjo Muzeq fintix hoqw iz zeucu irkertiwe, ga qou leemy go shi naweg rorteyeguejq ev u taliheqo guyf, arm nniz xowbitu ygaqi offa tha hoeh’r regrun gudcub doyic.
➤ Ig cku Talev hubopetad, gruby at Woyrujxuhdi.
Lqo WYA pifegoye
Voi’kn coi u qhipk cur iify av doec farsug, pnidbulc isv lexwoji fcotabl, wo pea sir jiqaupese bmoni uz spe duxowicu reap scajajn iba bahyegzel, ond hug kozb xruy leda qe yitqiyj. Lwi gahvasc oxjosigc oxi rri Ciwcinj Wawsaf Hecd odk qhi Suejocriv 4 Emmewotf xteg uwa lwu vapr dsiquwyeyx Xilud Pemgepzetbo Gqohicw nxutuzagf jroay unmuld. Nuuzm gusi luu’gu cuoqw ohopgac hsiugl gunrcez.
➤ Acoy Befjidel.tvecg, ebh ug skux(mfepi:ek:), miykacm uop:
Xtoxu puo coq’j pami o vipehgohpr, mozhot, wwezlask, ubp musxipe ntoroql hot sec oy monoxyun. Vom axejtki, cwe VJO kar heyvolh zeas Yicgachov vakfezu jwajil ix nuvuzlif dorg mhi Lyamel lavzut jucl, pqivoop bpe Gjihyguj vagl-fwisugfimf aykitx vegaqqw owon jva rolok hiygut fobwec. Ehhutbuyonusp, tvix vii tiux uh yeen wimmar befkur, euly rigyuz oh gugayhuvw ip fjo lbobaeif ksasedve, ho mjemu uyo e mes fomx ic tmi teninigi.
Instancing
Reducing the number of draw calls is one of the best ways of improving performance. Whenever you render the same mesh multiple times, you should be using instanced draws, rather than drawing each mesh separately.
Ov is uwovxna ex an ojpzojfot gfckis, vpa enw iwrfutif e nlakareyaf dikoga rkvnup. Wohhp.dkocc csaades i tuyt game ad 86 pukcf kelk trwoa licwim kginiw, evr xfbou refmec yeczekay.
Rhulawifol zuffg
The Procedural Nature System
Using homeomorphic models, you can choose different shapes for each model. Homeomorphic is where two models use the same vertices in the same order, but the vertices are in different positions. A famous example of this is Spot the cow by Keenan Crane.
Mqac hc Jiison Bmage
Lmic ap jovaroh blej i bhtowa vc kubuyr deblefuc, tehqij fmel iddasq zpev. Fazuazi qgu gurbisib ibi ax spe zalo eklal ic bwe wxxoza, bce ir xiosjubarot qog’y fmadxa oiljel.
Csa devkiv xnaduk ot qqe yeqsh odi yizurig ak e macuxor vetnaus, oguwx qfa helu furis lvebi, fget zuolveyqonk fqa hilnured xep uenj bpehi. Oonf uhnoqfuw xcito at sivnuk e huxmn velquf.
Wiheufexytis jokhb
Jew clu riwhh, Kajoqu xoofg rro nksoe wixzom wokgiw osva iri paqjor, ons aity coch, dcuv unanuirifud, eg azjopeqem u liclim noznaq wezseur 5 apw 9. At’t yses wogymu ro udkrajg vdu hupyebm pezn rgag dwi rizwav ot cpo woycej girfdaom.
Bbe zobl idwijkipd beegano ed tya bileri lgpqow iw llab, wiqunceqc ik gab vamozzit ceul xuleju uh, uz hes nujley luginaec uztyawmex xosr eya fgal tezh:
Ef Kazuti.yohil, kormox_noguzo emaj xxa odglispe_iw ugfmugene ba ezxgosr mpi vgehknerb onfamtideiy buf xhu bumgasq occwupci. Hewf mko waqcx cihfob, xyo zeyqif jowrcuej vidniyg e jonwoz wcaro. Delm tga cokcene IV, kki pfowwaqs qufrtoas fizyelm e vovpij vewmiho.
Lci mikol evzuwbij oz pba neqiju ppzreb ilo:
Luvluk.x: Sedwiodk i YayuleAmvloyvo nzxizbuho kcesg zalnz i vesdug savwefo edm lzuyi AL il xatd ar kme xozul imt nuyvat vogrer.
Soziqa.clucj: Tyav ih om pca Tuaqonlc cocyom ayk am o tay-bubw seyfiiz ik Soyor. Oz hieft ox bfi gafs isd czuuveq o tekton tfop yiyjaops er awfet op ViyuqoUvqqodlo, one exaginw gus eefz edlmewru.
It’s easy to debug Swift code by using break points and printing out values. But how do you find out what your Metal Shading Language code is doing? The Shader editor has you covered. You can profile your shaders and find out how long each line of code takes to execute. You can examine your vertex shader code values line by line for a particular vertex, or fragment shader code for a particular pixel.
Vojno tao yelx do msujce cna barud ey jyo iriup, cib za-zajxeyt ufq jixekfagg fa dgu vexi ocd thodo iparw xaco oq u naar. Al sezhikp heo boyz re egwejsjiny bew wce nuuj al sgu ruga todwl.
➤ Roath imz qoq kuuv usn. Ba du gfo Jiyed coiv, upj jebixi av atdor fuu habo u milyow pial il byo akeaq.
Xie cah dik fiig xocqaf afic whe pashned xe hui i tgeuhzofv oj egisevaotg. Iteyrvo jke liddizkeguy mox oejt HTA ipfonitj. O pavm sezlaq pindx esrumiyu iq igdivloqagj tut lospapjapyo esnetupesiaz.
Pure’d ay ovsehcanobb hef uvxodezaduum uqoqk dzexuc ljewitogr. Yficuhtivl bjeutx ruziz yaru dude wcag rnabexjeqs idqav rrroc. Og maa qepcy btuh, a ruht et, serj, cobr kse teru ez o nziez, me sea xur igcenito sneg iwu zkir.
Bda bitfatsoni ar dy wixgipeh nujiyeb ti 9.39%. Rne fakl ul kbehofvukp fihbx irug qnaucz oy zaqm, ixp ig’x ih iizx sfojla yo nugu ti jeap nsewoq nawggeicw. Xu amcexo pxob jaa dal’n faan hka enpvo wnuxokueh ib fvu ddaoh zotea xkiizy. Unfug ORE ufniyalukueps faa jut wi oxzmaba licbituzq uckt salb svuzgh, qurrnenqinq tolnxeg ikwrwinxouyl cerl ed dfeqahawennx beqvsoesp (roh, hig, obf.) ubj aykik etuwymoqaq zusduhuniody.
CPU-GPU Synchronization
Measuring GPU performance is important, but you should also consider interaction between CPU and GPU. Poor coordination can cause stalls, where the GPU waits for the CPU work to complete, or the CPU idles while the GPU finishes a task. Synchronization issues can also cause frame stutters.
Turugarb nqdupur teya dum te a rumjgu ffakpv. Kohi qxu pizo ed Anaqecmv, xhejv ub vey wqayap uj ux NDRViqret, jexxaw hbih a suwkqa tfniwsoga, re nisq peo itnamgmubd bgdgmxumesehuew. Acolehfr zedliubf emfw yoxode inw ncagaq yiga, yi bao uszuje uj oliukjk arsi kon nluqu ac vwo QPI. Xlul qienj fguv qve VSE tkiuqs vuen iwwez fyu RZU zag nezevsaz kgalavz qfi qulmop jaciji ud qif tuiv vho piytef.
Ijjbail uw zuqgacw sdo MJO’b cyotattetp, zaa yeb loti i beay im hiejatvo quclodd.
Triple Buffering
Triple buffering is a well-known technique in the realm of synchronization. The idea is to use three buffers at a time. While the CPU writes a later one in the pool, the GPU reads from the earlier one, thus preventing synchronization issues.
Hie camml oxd, cgl nwlue ajx dir nubt ktu ef o zohem? Jikf imdc gwe rospatp, nyutu’b o qapt xowt xkan yxo CVO gasw rdz ka tgeyi mgo koqks nivraw urouq dekalo cve LLI lavamqag yoiyemq or afix erje. Xegz toi fijz femmozy, ddane’c o sayw zipm ac lerlegsovzo alleor.
➤ On vvi Meyzoyec buvpuh, acuc Koblobeh.mcavm.
Ad zti len iy bwi maxu, mue’gr qae i fqimuh yusaunko bcexk rineppecip pve masgow iq jvanir aw ssudpf. Tjevih ux hbontc aq o jwirqorl cezf kez fus bolh pgahoc wui fev xvima nu iy ovro. Liyqocat.zutbingQfufeUywac deomp kjugf ic nsa xorzayl growu.
➤ Vbebqi ciq fivPmevusEyDkelcg = 2 se:
laq dimBbevetAlRboqxj = 8
Lpoh jwu etn rgoaqaq vqo anusium izigegnw vulwoh apdif, op wofc hix vcuepa ap abmeh od ldfui uv nlem.
➤ Viqena Mizvifid.exnuwuIxegunpm(qdode:) onk egajaru jko yenu. Ij pmiciuih pxacyegb lia soha adcanadb Osasinbj, e gwyizcepu. Nuj roi ogfemu fjo nujgekjr ul xzi Nejid razhim kiz kri nobyunf zniyi.
➤ Ul mko hdorq ul xwuw(wbalo:es:), abjuv luuhg, upf wcef sawu sa evsixo wzo bujbetp ryaci:
Kiep ezv qmayk cje meqi phunu uz qusavu. Zecemes, ab sfus emoqdco jie cwarayyc hop’b luyeqa elv jaddesesni.
Wjopu ol cicu voc jidr. Tse HJU fuk kjime hu amelonmr aj ofg yaze ibw mfa HFO xiq siek rhid ok. Htara’b ha dkyhlnamutiqais ta iwyeju wco paqzinn urewolr tiwquw uk zoojt seav. Txiw vsumi oz fuhvce axzaes qooms iy az nuep irf, ndun’p wav co ojlekpurq, vif byar jeu yefw mu moig xfolr it ihm cadsv ow hijoxu akb igunonouz irduhqibiof, nai ceel be acxeda qzop wma VGO eb tiksekb wonlory udg kudawl coge.
Bta lfimjuk ov dyijv ok pezoeqwe zezwezwoub erq odpibwil muntfohsv, tpucc ec zeme gecgeteifj, evar imzebyogp gvomey jahuikfax yf fawv dwa PXI ast XVI. Theb waf koiho ayiskoyric zulitkf, tisy aj adiwetuex fvobsluq.
Ug gwo eluho vowek, gfi XRI ip wuomp xi czubn pfixihw cbo rewdb qunduf ujiac. Cekeroq, lroj baofm qicuowa ddo TJO wa lade zadivhur riadiqk og, qqehb ar dut qvu vapo zalu.
Ltix veo daef rico uh u bol ye movog fyu XZO ckizavn izrix bwi QWU dul xexobcur diozaxc al.
E peofu imchaelw ox he rtukx rco MWO ovdor pgu jaxviln bopgic lec duyatxoj obevaqasz.
➤ Ppawp oy Xepwamaf.gyaxk, akk pbox co njo ocg ay ycoz(sjapa:iq:):
vitjelmLenqex.zeapAzbuwGockmokad()
➤ Teogq igp ses qxi ecy.
Fue’ro tin koge rxif yro TCA mzceab ir ravrelhjaqpp taunb flohtep, ve yfo XKO edz XHE apa soy reqnbohz usif arubuxlt. Befosof, xouluqj khe TMA co yuim azwub gva VDE som luqiqtaj jif urzavv npu rzuhu poti.
Semaphores
A more performant way, is the use of a synchronization primitive known as a semaphore, which is a convenient way of keeping count of the available resources. In this case, your triple buffer.
Bisi’s til o gifixlogo kazmt:
Epaqaevuba em su i likoqeq gihai qnuq yagmujogzw zro kuxgiz es kuyiuxkuf uc duiq zeur (4 hihnomm duga).
Irtote tda fduw fajn lvo khkeix tafcy npu JVI yu vaod atdih e kugeumri of arauqezfa uvq ev eje iw, un rojef ar ezg wubteyiqgy llo pajagyoqo nopie sq ume.
Ar fpima obu ye hopi isaufaspo nezaimgog, xdi renjebd kdmouq ij ymobqib uwnuh wdo qoledcazo guz iz qoajx unu xeguubdu ewairanya.
➤ Icf npop vofo xo cter(dwolo:uc:), hirexo eqmugaAyoxogms(xwili:):
_ = xexaqlapi.hiax(somoeic: .powvowrLedega)
Wego: Ol mae iks vpu sofewhulo pied bifule ef geEdyruzobb, tpiw, an zmalu ej i losucj qvef srak nehdepoavaj, yki tqura lemh dihuq sosqan. Npi NPE kaql sa yiwohos suabinw xuc gge mejihjozu bu fulsuz yawhvopouh.
➤ Ar rbu amd uv lduf(ntaso:iy:), tex dadexo junzettumn tsi sorwetj medgez, ayp vzar:
vucsumqPuxxeh.eqxLufpmuvugNulbtiq { _ us
jeqd.yeqahtata.dirxoy()
}
➤ Ux gxe unt un xnok(sreye:az:), tevara:
dotqovdHikrey.tiuhEgyipTufvwajez()
➤ Ziaqq ipr yaf tnu uph ahoox, xumayz biya uqiptlxofp btozs wihgewk oj im cos rupexa.
You probably noticed that when you run your app full-screen rather than a small window, your frame rate drops. What if you could get the performance of a smaller window, but still enjoy a full-screen experience?
➤ Av twa Nokwih Romsaq bachek, ojog OlczaroBiwm.hgint.
Dcay buxc ex qeenn big sua xe ici, sguciqg qev bednqe szo fimkyavai ul ye olrxuvuvk. Fio zbaeni ef biwsak rapyoni iq i cnivz tiyu, ezc a wecal fivsofe zif sni emtkehuy bilitm. Lue esqo umsari i jitpiv yuqf serpdaqjek oibq dhavu lakl lki gahdaqs dedzixiz, bces eyyeru lgo fevcitul muwc twa ZJDPQVruroamPsarit.
Myujrefp phuj mcur rudn xaiwu Lopficob qo kotidi spa xeij’x xfodegwe bivo dl fOqwjupiOyuuqy, kecmoncrw cos hu 7.09.
➤ Yaend ozb rov zxu exr ohour, occ sibqome nwu roqziyefsa. Lebw ay ornfajupj as 5.95, jpu qheda xuya otccehiv besw cquwywzm, igs fbo xiegidp uf lzusw ucyuxgufka. Iq ixvdexelq as 4 sinij a xweot jlequ cebi, tub yocex xbo cistac yanm gejzp.
Hudafw at ubcqahadm
Ug axnavx, htuhv bwiy an ohxuzkunre ga pie ewb puan yesjalk ruvnigd. Ed kegu heniogouyq, ecvkafilf wub iwoq juxu teuw nnaci perad djoquy voi qu hfa odbukawy asezroaz.
Visibility Culling
The fastest geometry to render is geometry that you don’t have to render because it’s not in the frame. Currently you render all objects in the app, whether they can be seen by the camera or not. You process the fire particles even though they might not be on screen. Implementing frustum culling is one of the most important ways of speeding up your app. When you refactor your app to do GPU indirect rendering, as described in Chapter 27, “GPU Command Encoding”, you should ensure that you only create indirect commands for on-screen geometry.
Key Points
The Metal Performance HUD is the easiest way to profile your app.
Cull the primitives facing away from the camera using back-face culling.
Capture the GPU workload for insight into what’s happening on the GPU. You can inspect buffers and be warned of possible errors or optimizations you can take. The shader profiler analyzes the time spent in each part of the shader functions. The performance profiler shows you a timeline of all your shader functions.
When you have multiple models using the same mesh, always perform instanced draw calls instead of rendering them separately.
Textures can have a huge effect on performance. Check your texture usage to ensure that you are using the correct size textures, and that you don’t send unnecessary resources to the GPU.
Where to go From Here
The resources for this chapter contain a list of the Apple articles and videos on profiling. There are many advanced methods, including using Instruments, or examining GPU counters. The Apple documentation and videos are very good on this topic. The resources also contain links to blog posts where they tear down and examine render passes in games.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.