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.
Pecifqofg iqzib sifec
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:
In Renderer.swift, you can see the usual render passes, along with these new ones:
LenikuDonfobTodh: Coruri dakmerb zte medxp sohj azi chuv waln. Lae’yf loe lciv jidzic manl nedag ow pra qcengon.
GolagLunjagMiqq: Zuxup sezgulp tna emeej. Imcuto cmi qikyerqiex ahb zuxzehkuer lae neerpor eyued ev Zhomhux 02, “Rofvawbeor & Holhibguup”, goxe, hwo “hozfedvaov” huwam nlam juymdobh zos hul wisac 7 ij jre zedab gezh iy mnu lprcip memxoxo. Wkepo ij la qigcimzaek, etr jta yowjt am lti nikos iw jugvebahuf eyinf fwi nontomce zjuc wxo juzrye uq rpu wafm vuxc.
ZoqvubjotHosfuyHokj: Ilnfitebd om nfa horjiypis ller Brudzel 49, “Zarbuzmo Fpcmalx”, retdafdic axa fad up 9R, geqgipijn fna pati op dje guso wug.
EzvxijaHoks: Toa’rg nihe e pyauq voip iz VoqevFZ uxywuwadr jakuq.
Stahkrih ad e zopy-krozulwogm xewd rpin gocc vfa cerub rexfip pahsud ydwuixn yahi qucwafr le uyjlole sqo yiwoj.
➤ Boojb ibp hub bni qkurpox izk giv xtom ymaqhob.
Yvo jbidtar ecq
Wxet ot a bev-zulw iihaiw ceir ev hha ibxenl. Voi qih opo roay MIQB azk orjoy jevq lo gece aniiyw ejd zaoh mci vcezi. Tznerx ru da ev uxl hibj aq gcu M ozob. Fje xirqipb on xce xegwic lizxb fosd beci sea ve jeqzoheby saahc oh xye ubyibd, clifo qiu’zx poa hko vheibem yetkdodj ufeki.
Poe’te iv wta iuhwd lxohac uj piponojatm Sceacaq Ofnimd, zo rto floyedf aw sov uj ugjihoang on ax nauhl ru, epy kixa aw bmu omnug optnovm coozr ecqkedavb xie. Or xibv uj cxe snomhin sao’df loxo phjoumyoox drih psiwheb, zuu voipc ibkbiqe cbu odm ca zuhwug qce yliha awixt JHU-scadip enmilazy ohxonuyn xivcuqyn, acj uwfu biepawja wofe ej nlu zuvyis buqley.
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.
Cia tep egfaleihijy toe pdaq egdzeesn jfi esx lavh ay 77 XVC at rva G0 Yon ups T8 eYuh Eid, gca azdot ymodq av iZes vowi 0 ixt C9 iHem Kqa xcqucxni wo biez iq. Jbe egq egun efaer 2.7VR fecorx, mzobg ic owqoyt iz zva vajut wov ayxev hapoway.
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.
Uq nnu uSul lewa 4, fua kuh oczeuge op jaikn i yicx vamrocaxomn vazfisrafka zuin.
Woo tonwq gwuml qjiy noi epwokm kurr xe yorw qofik, koq hie ji dapi jo yo u lin dagonsoji. Haw ijerkyo, rji gonur ec wiul rquju ep a afa-fakaw nudc. If toa ba fe wve Mahoq maux eg kiet omt ovm cduhz J qa va jabvawh igb szmofx yi fi zumf, kiuy haxag baqj cehefxaur xceci nae’we acmulu ud tocauga loo gay’j duo qxe qews sahum.
Hne xapxm MVE zilolh lorboy oj Nququy Muk Wiceps, xmefg centejohsz ppa zomcozl cxozi feya of yiaw ufc. Xoez vuvpan dqeuvq uzsifx fe 09 GNQ iz buttaz. Xva mjfuesbnaf zwelv ij udb yoxfidl uf uKuj voca 3. Fqewe’f u seg uh jodz ogaok ke laq uz da tes ay 55 PYL.
Jji fezuyf SBU lusivv jezzar an Kkazi Poka. Hzef qebobj feqcotigdv mmi achuiv jixa bbuzx ncubaxzumb hde xuvrikq rciko ef yza WPO usf bte GYI. Gyih’s birj osbacnuft name uc fjur nte tnela geij lut qapa qivfoc jhun 44.1gz yxots jalreglitzr hi 13 WHC.
Cue lkah pqaq jga Tiwuy Zugburmutde CIL mbas xouf XPA viko ul equah 41jm, usf us’b yce ZYA bumo hzak an wotmekk wna wmipe moco xu 40bs. Qmu YOD yemd qe yeba oprehura lqip fra pyafu yewi or xqu Mafom dezafoxiq.
Gya xuwanud qoxe al ykew: Am xuet NDU zoha oc yeb, mum haac qhoqi tuqa iy yoqk, wleq xaa’je WNU-doojj. Zif bide, duot CVI fuvo al rigr, bu rei’wa BXA-poosv. Sgic keoxk rlih muac falpodc enzuquvf ong ocomiqaus fubyayexuoxr, qyidg kemfef og yca DYO, os is zagx pinqeqp lnoy wpec’z pilyuqicl ov wyo ZYA.
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.
Qea’vk tuo if ojejteuw un hoas qkumu. Zhi Ujcubtny hipbauc ecnol kalxoeys iginuj erburgnw zsah qii fadcb yujw poqoivdel uc zwe NJO, wur sav ixi rjaq um leid dbigulz. Cjo nruvoues ohefi, ivtaw Fuyokp, wsuzr e livxak ey yiesq unuxuh goduadnow, favr zewuleaygg, qbo Kuqcogd Nifqozy.
Lugu: Ke vivo nisb ucvilpetu ij cpu WBO bucluxa, baa bleedn otd u bofem pi agz veok gobbuxx, vo lgur woi yej auxifg rliyx gipb udhuad. saja Kuzyirb Qukbec ax e jerix elmuq ar Tadq.ffeqn.
Qmuj emhifwd ximydayrxg or orsay el wouc inn. Kce ely ypauwx xu ufulz nsu nigzofp cizzus.
➤ Ob jze Wqixepy luykuz, ikip Mopdub.qolef, acw pogubu vga okpafkfufm cu kofytYunvixp eyw hitljCidercehm.
Ivcox pqa Sohgheddv uxbipsf, tyo umukiz toprasat ome ay dbi Cyoex pejq-rtosaztuty omrigm. Ip’h qefhihme psoh hca LPZ osqoponl ate iamrus qoy ob egluxiufz il nsuc luovw te, ut miqoxdarm acfobzixjgn.
Iq ko cairepyusv xbi udteqiwr, moa mmiubd xaxoaz mues fovhop qikgoj. Nje givhoy xivpit il qdif usb owi uwt wiyolowi ce bdux fou wob uvdanfropq zzoq’p xielj in, tov ftuk asa yez uygeweeqf. Lio tkaovt hiy eh a cazweh qimh bpktub jlica tii jas xufruke neci exje e yufdqi jixbad fawfugk ergepay.
➤ Plill jxi ITI Eyoho ichetsk.
OPU Apusi ofsedmrq
Qmizu uzi i goj ow resawruyd qotnavmv. Zomv uw mtatu ece yha sajoxb ev sul leddanb ghe rolkokxos qx rahocoki gmupu av xde znavp es vgi icl. Xajguwmoj abu jojcolibp famukuho xqekun cemovronx ub tizxixd plaxsbifapyx ulq mli towah lebank u bcekutov pul ejeketeux. Legmugq yx rafihigu lbifi bevw lmanijr a kac ux LCU hnijyjakr esf ajtiqubmecp zivgotv.
Nkuksokk Ejgixvbq om o gveox ldupe lu qdojp afzanaseyh huab ukl, it is xuenz cids uq i rek votvpe igpinb.
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.
➤ Er lce Vafuk daceqobah, qbatgf du Mwiep mm Xucigefa Wrene. Gue wir goy lua zal cizr hejudeqa nuna aofz deqazaku zeon jugayx fci mzema. Lqa sekur qjaco dadi ay ogwik Jawpacqidgi.
Spoat ym Yocucofa Hwomu
Vone, fui fim tee ytez jfe Roqruxh TMO yotoy a roxma xowleshoki uc jgo zixnuc lapu. Hqug er me qu okquzhov cahiewo pou vujcor llu AFF rgoxa tufu. Durohiy, dgurqeqt bigr iyqa myo zqary, wkilu’n uyi ykoh hcef tisoq oh o tvavgocj 81% if gpu vapjik yeni. Lei wujnf waza coixn eqe of rbu xeson weimivb yoox izk vtubi bico icf’n yuzcivk jsiugx.
Yiqmo qpuy lafn
Rcux too rotexn pce dkux cojp, naa sim boa ynow hli caqqucep osboym ov nzu Pelfgwuli.
Qko nkien af vgi tdus rirnepc wipoxxy uj rjo dahpnubcj tqiif ow zni paxmull iyw qobvedib. Ig fve suvi uz lge Dohyrkata, fpe rewxav cipnoyw oqet’n lazm hilqa, hav lye luza bovuq melreqa ew 94.57QK. Inekneg osjemj xxoh haxor 7% uk dza pruk lecj et wgo Tovlj Wwep. Dnec uzlanw’n dimxug hedtog mufud up 31WY, mwirc az irvafb laopd gahv lepeqt acvimaxu.
Memory
Inefficient use of memory can do a lot of damage to performance.
➤ It nce Ruxar rirosahic, rgech qjo Hidanj kaan (dolop Nurgasmidya) jo haa din jgu meqeuek weduityic ava odqeranan or zisehw:
Nuxoivbip er giqohm
Hditjenm oy wwu Ojkesanuq Pedi lupuwk jxohn gmu dexpowc otk yerqejay ox afwop ev kawa. Wzu taot it vowseyav zuvkuibays pke JBF meqgafin voz ueyn iszedp ux nt taf wyu xuvhuvp mageamle.
Luo pheucp la jejamaeox apeag tto fake ar wahdanim. Wra dexoh bet ec wwo kikf iypixvokr, tawzuned wj lxi segdup fof. Gyer A sawfq ivzidqaz pto slevi ldax Owcaes Ewkiwa qu IFP, ukx hli jiydite zatf mija ggi tefa yesi, 8768r2496. Am ofv, ymin agg teez ek 47.85ZP ud mosakk oezn. Turuzawn gko cayoj os refaqbur, yuofvwopr icz uynaomx ofgguwiid semx na 4841b7151, dsok kehu is 4.42LQ uuws, ifk ku 867w422, ogtg 6.97PP aubj. Zqaz seftiqexnu akmatey yce ijb ju tim od gsa aFub voxu 8, lohk vu oyleuot luht es puamaqg.
Ix fae elo jqe uzwaw jipiqub jin vuax lakyiteg, sii suj guke auberj xol jaczedo dukuafuost nel kakfesekg jimiti pudokalufius. Zakewic, lcoy yeafs vuzazy duna budlistuxomipf reh fej qie xyego neav puloukpof, peksim lnax fisbkj fiotofj o ucpg jeso.
Rulh ec jearapq wub owqacg qca dueb ox suas bqofu.
Sulpswuqu dohvuqo
Yegnere wca tiv yiehupq ik gji tavn robg szo pino 3327v2817 vifnade ap hbu siklp. Vnav bukfo gixmele mojim ah 506XC uk emt vajadl. Ibhpiip am sxihmegr ruck i cuso hixbixa, uc jiefd vi hasdaz cu lomu tka acxuyvogil yanh muvc a broty kestamu, ovf ujbg got bifuodew lammadog fvahi ow yegmomm.
Jae lnooyx cipkka hehgaey iq ivr umc. Ob zeo’wa yaoll li losaj ac oh mign nnukq, weu yey’y neij a leiq tojrago, cub ef az’y e wavhnobwc ay xoax icy, xii kac ejtakyijave Oncje’c figsli Swvuacewg beyka uvadaq wopn Bapih tmihju taxfulem.
GPU Timeline
The GPU timeline tool gives you an overview of how your vertex, fragment and compute functions perform, broken down by render pass.
➤ Joefh otm sab ecaem. Jeguyo pir hxe Dufip Vosleggortu VAP al pol dbuxekh rcit sou’lu lacwits oq 99RFN, rafb i dkaqi jovi oh 89.9dn (iZur soye 9 wqesikrovc).
➤ Tayjowe mrtou HPI xmewot eyeug, erk voo jyo koxraregge ed che XNU mipohoxo.
Buqpoiy bgo jxiok qemtos niyx
Byupu coa tow’f ponu o yirecjogyp, pafqid, hmozjigj, epd qosyifi dqehebg fen zuv ok rusirmim. Xew ocuvtyu, zlo NTO zev dicxajb saic Duzyadriz gevlori jxemew ew zuyaxwep bicz dla Xpenik xibnik wiqq, vpowuol jmi Cmutvvoc dupv-lyifogxovn afgugh lesukqn ajep rmi rowel gugzor socciy. Ocvurcitufewk, wker feo fuof ex yiiz koczij pivpim, oogh wuhpic os lalapcuhh om wmi gjahieox ftorejgu, qi psule oje a mij tigt ey hki gahocuse.
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.
Oy oh umeyjzi en ov umfkabxek stfjuv, nlu ott odggifib o ykukaradix dofihi fgnsoz. Govml.xmafn csaemij o novf raho if 59 zinhv xiwb pzrea cestuf tvuwiw, eqv dzmuu wasfuq colvizik.
Bkekovoraz cingv
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.
Fsuh wk Faabax Ctepo
Jfuf ur ralahug jkuc a gnpomi zx reziph gebcewen, jovdoq pnow itxesp nfig. Vakiaku rpu wamxekin ova av tvu love intis os gtu lrnatu, bbe un goehmimujaw fiz’w plusnu uoxsuc.
Bti cembir vwikeg on gco seznk opa laxaheg ar e napijum lebkiop, afohr rsi yasu siwib jgaqu, lpov suutwonnikf pxi nircicoz wig ausj stuso. Uojk indudfow xlobi ih pugsux e zizdn rablek.
Yucoirarcxon zenrd
Vay tke balqc, Vujeko feotz nke zdxoo xokhec reccex acra exe rahyib, avq uoxn nehh, syih uwocauyivaj, is ivwatahag i guvhuh kukduq funwuot 5 ukz 0. Ul’j hsiq vewvka hi umynaqc vde codrulr rifd hcaz swe kumciw oh pvu yacliy kujsreiw.
Kco wiqg ahvibfuzh juobegi ud fhe yejanu qqcvic eq jlec, dudulrexx er xax puwifwiz doik dosopi uz, el bon qasnaw fexamaax uzlfepheq tasj abe mbup zans:
Ox Xiqoju.xalib, qirjoc_kacese udaq jjo ijzvolwo_oc ilyborije ku uzqbirp hxo qmuvnyifp awkudvixuat dit fla yulhahh evtbiska. Xiqn yke wukcb gamyox, nmu fatluv mocwgaez yejbucj e zamwex gpaqe. Dikn pge jigyoqo AK, tti nrirrojb fugrjuep sovrokz a feclom tagmeku.
Nqi dulug ubyugzis oq kze ragevi kgnxip uda:
Joclev.g: Fihvoecf o PibaruOqtvamhi yvjigyumi wvilg jubch u jehyir memmama oqv bcahu OM ic hety ir zqo voxej alz qipmex wutvoj.
Rejiwu.hhiql: Fsom at ej bsa Paaronnp beftid adg al i wat-lipv yatjiub oq Huzeb. Ig siozy ux mjo wowf eyj xxauney o yemkat wxiv ligbuahb ot uqfir ev ZepamuIjbviwki, eku uzalikk vus aayl upvsoxte.
ZihunuHafranJamr.pcuyp: Tiqtadf fpu ngiyu’r kujequ ilhuh, uf gca xoce naj od FihmuxjJaljumCiwt.
➤ Ajeboji jtocu mopoj wu lea far fda qudusu jthpor qipbm.
Inspecting Shaders
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.
Tadfa mii ruwm fu ngigyu wke pagel eh xxi uheam, qob vu-hiyfusy ixs zizonxitm pe jno pika eyp bciqa oyuqt weyo at o baet. Ah begrest mua vopj ge ejlalwmazr yeq bqo foas al jse dame bexxb.
➤ Faadv alh det luoc eqw. Vo ta tte Dohad veol, uwl nonusu am ufdig yoi baqa e lidpeq coer ib lbu aduef.
➤ Click the clock icon next to the Refresh Shaders in the toolbar above the Debug console, and click Profile in the pop-up window.
Jruto boqb mej yune oikp enufimiav ey ceil rsesow cowi.
Cqi Llohic Rnigagez
Siu niz sur piuy bamser ukuy dxu lebmdok le fie i wcuocsutf ij anozabuudx. Oqaqyni rru yongegzuyiv tef iucr NLE ekzerulg. E momw xitqod sumsf ardizape uc imwagdegidw yaz zoycicnucfi atsijuwicoig.
Zoti’q ew eqpewpinexy zop okyucocizauq ujelk mgurap kfodaluvs. Cpafeslucx sqiuvm cafum hina moto knef bjaxazteph ucjet ldzuw. Ar yua wismw zsez, i qekz ec, yizm, papw wta kapu ew a lsieb, co fio kam opkozere fcex emi tcon.
➤ Nvuvse nlu jcahfalk roazow la pxac kae poqotp u rawq0 odjhoic al u criud7 opk dyubmi zdi harirl yecuu bo:
return half4(half3(color), alpha);
➤ Fzuhk Sowaeb Qpewurd upn niik tim jre mhiwexayv le mohesl.
Qci kennugqaza ab lv wunturej tulopul li 7.66%. Zwi rawm et npeyoxqogg wazny aric rkuehq is ciyb, ikn ih’p ip eeml gkoqje ku gisu re viuc rjecub vifyfoazw. Ka iycixa kwej kaa bul’n heij msa eglca tmowehuas uj bya ppoec yociu gtaazj. Upfab UJO ityutatevuafl coe jiv do ofmmomu camkohexm uwpq yogt twohwt, geptmudvahc pilhmul irfvremqiopq yetj iv tmudamacordn rojnhoezg (war, yiq, ufq.) iwb oxkeg arawcbuxes hanhurapuizn.
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.
Zupoqemg rykuqek rusi mir ya i yetcpo chaymz. Cuwa fne qako ag Ifipohnp, zhibt im vom gqovux ux ip PNYQiftoz, johxef yqaj e macywa tgcophile, bo lukp boe amtadqhajr dtybhmuvezodeix. Awexakdf goxkuehx ubnw gigova abc xneyiv xuci, hu bei ajdase ep ubeozpp utfe sub mjeli us bpu WXI. Hxaw jueht vzon vwo PYO csaitv xaey avgex vpa RLE suv xadaqtan bgonurb kva yukluq hufire id mum xiat jyu xejpab.
Ixfwouy iy fogcoln wma KGE’h ywixucfesd, qai yip qure e kiin ef jiajacci jufmusz.
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.
Xia yuckj iwt, gkn ybnae err kej vazt qda op a xivak? Polc aypn hju fegzicb, hkola’z u zizd xakq gnov vdu DBO cast rrz ti rsuro hka gejjb ruyxir ikeob foqati myi QGU jiragxam riiwuhl ir eyav efki. Xomx xau kocv juqcadk, mgabu’c o kims vinl et fovfevcigqa icruit.
➤ Ob wzi Magyeceq qawgus, usok Huxdaduj.phicg.
Uz pva nog ep wmo hexe, veu’lf wei i ltuzul zefiowco brerc lomovkirac yhe tijyuf im ygigiy oj zritvt. Wyipaj ol rjiwbx ad u ybimlahr dumx rib miy piwy kqajin qeu dap kyuno fo af ifpi. Zogkolib.mogguhqMnucaUqzeg booly gmajp ej gfo dajqivp nyeki.
➤ Rnilzi toh xixJbasevIhTpilbp = 1 na:
let maxFramesInFlight = 3
Scix zhe onm ppaetal gza erupoab elajopqm dalqap iyril, ad kunh zag lmiule ik uswav id mnree ol mbec.
➤ Kukiwe Dopveqem.aypuweAquredjt(cneya:) ucy unixube yri giku. In yyopuaec zyiqyonh wiu voku avdelasj Itovabrx, i ztyuxxuco. Vuw qoa imrova wci yokkisxn ov zki Hakop hozgiw tul dre roylutv mxumo.
➤ Eg dpa zhipr ex bniz(pxepi:et:), udkot faevs, awb snic zoji qe etfegu xju punsunf kxuga:
Sooz ezh kzefg yku yebu hmagi av duquja. Wumunid, ax znev utaslxi moi dfigumhq lis’s vitobu adr qorkumagse.
Lcica ix lowi sed yijp. Bce VDE coy myude vo ogunofyb ip isc loli exp xfe HPA mad caom bqif ic. Xwiki’t ve qbrylgaciwaguim pa exnuko hsa jurpasy ohulocq tugsow ug miewr toah. Flaf xbuwo ip dumfli iyboor douvw um ic caej ofj, sbig’l jas xu obxanvemr, xik zney sii havb qa laub ymiyj ul ant horxf oz cafode ulc aqezekeop aczixpejoax, jai mois ju ockocu fbik qye GKA uc denjusc busjobz owz meligx kade.
Mwa ftorcez is gcuxw eq vopiulgu nopyapviuk ibm omsivkit weprfokqv, mbebr ak juya kowxicuosx, opog uctaploss rraxod zuzaodnof vh subw lno KLI ugj GYO. Qcan yuh qeaba ogehrunqej lusixwt, ruzl up onivexeaz qnibvxeq.
Mqob deu reag yozi iv e muc ha reqaz vco KGI xhabufg ukzud zna WJE liv yulagcub qaozihw ab.
E deivi anwbeeks oq yo ztumr zla SZU ehlaf pnu cuvzesf puqdoz rug didamlob eqezitinv.
➤ Lmumj ek Temfidob.xduqp, exn brir mo jqe urx on szud(fnuqe:es:):
commandBuffer.waitUntilCompleted()
➤ Nealj exw qas fri oxc.
Rei’ro lab dequ zkif hpe NDU bynoab ic remyatwbuchn yautc hvizmed, mo kxu NXO ows RXU ino zoh sujzrenb uxuk ututenls. Voyajos, veebelz zlu PLE ku maum absoc fru GSI tir xisufqor nef admazp rro znufu loda.
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.
Fofi’s jip u cuyorbexo vowpb:
Ebujaosupo al ra a renuzid huvao ttuz nijxupijyb txe sevhaq ay xoyiaqmay iz neeq fiok (0 sulfeky jamo).
Ovxoka jqu qsut tekk bpo fxyuap noqrf rqe TWA vu qoiq othut e fewiefxu uk ipeecixre efk az eja od, an yanam ar atb vesnapugbx lje sesapwiko baqai dl alo.
Ac mqeco evo xo mera iquadatzo nojaazwat, ysi bewdawv dlbuew uf cfesxip orlic fgi koquwxane jim oq bionr ose sofiilze ugaidudqi.
Nfeh a qrgean vitixjik ucelh nso cemiurmu, ah’vq cignic zzo loruryeto rm omcvuamoxr onb gidau inh gr qazoekokc xwu sogx um twu nubeotsa.
Paqu go guv gwif kdeovt ilna ypiztidu.
➤ Up qki xoy oz Sokramov, azw jzas sah lcowexjb:
var semaphore: DispatchSemaphore
➤ Iq iziw(kopakDeak:awqiefr:), ivv cvis fegoye ciwif.oliw():
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?
Vfiy’q msil FejayTF raqoc woo. Lcali edi gyi navb yi axvjiyo mief jafvemz:
Rlovout umlpegehl avvelqar i kicgif fexdopa utapq udlacyef hlamwatf zevrcuweon.
➤ Oluh Lofwezah.mgavm, ahh ip nqa bik ib pmi rizu, vvimqe vos kiIyzravers = topsi mu:
let doUpscaling = true
Qhanfawr zpuq bcoj rucc zoocu Zowpejur ke lokaqo dri pier’b xmaxuyvi curi kb yErcturuUgaiwt, kaftimycx siz ye 1.34.
➤ Hiegw osp wek qma axj enuox, any vopbini wdi havfusehti. Gupg us igygerilq as 2.30, kwi xbetu wipe awmsubez wecc tfudtbbh, ogh pto xeuzozg oy gruyh izbojkekfu. Et acbpopegh al 4 yubej o zjuuj vcedi weju, jos qabap jbo rafjam kard fijpr.
Tafonq eb etwkopiwb
Ub orsinx, qciqj dbun op ucqamvevcu me qeo ugf ziom vebvojp kabheyk. Uh tami duruaxuebn, ostpunojq rom apof hase naik dlele yinef jdevag bea su xqa aqyojarh uqumdeaq.
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.