So far, you’ve created an engine where you can load complex models with textures and materials, animate or update them per frame and render them. Your scenes will start to get more and more complicated as you develop your game, and you’ll want to find more performant ways of doing things.
In this chapter, you’ll take a simple scene and instead of organizing the render command codes on the CPU on each frame, you’ll set up a list of all the commands before you even start the rendering loop. Along the way, you’ll learn about argument buffers, resource heaps and indirect command buffers. Finally you’ll move the command list creation to the GPU, and have a fully GPU-driven pipeline.
As you progress through the chapter, you may not see the immediate gains. However, once you’ve centralized your rendering at the end of the chapter, your app will have more complex initial loading, but much simpler rendering.
If you feel that you haven’t spent enough time so far digging around inside buffers and examining memory, then this is the chapter for you.
Note: Indirect command buffers are supported by: iOS - Apple A9 devices and up; iMacs - models from 2015; and MacBook and MacBook Pro - models from 2016. As you’re going to be delving deep into using the hardware directly, much of this chapter won’t work on the iOS simulator.
Argument buffers
In previous chapters, you sent up to five textures to the fragment shader - the base color, normals, roughness, metalness and ambient occlusion textures. During the frame render loop, each of these incurs a renderEncoder.setFragmentTexture(texture:at:) command. Using argument buffers, you can group five pointers to these five textures into one buffer, and set this buffer on the render command encoder with just one command. This argument buffer doesn’t only have to contain textures, it can contain any other data necessary to render the frame.
When you come to draw time, instead of setting the five fragment textures on the render command encoder, you set the single argument buffer. You then perform renderEncoder.useResource(_:usage:) for each texture, which places all five textures onto the GPU as indirect resources.
Once you’ve set up an argument buffer, you can refer to it in a shader, using a struct as a parameter to the shader function.
The starter project
With the concepts under your belt, open up the starter project for this chapter and examine the project. The project is minimal and it’s not the most exciting scene, but the two models have very few vertices, and you can examine the loaded model buffers more easily. The barn has a color texture, and the grass has color and normal textures.
Wawub meonagb pidiv qcipo, ak axoum, el Tukos. Kol zorwtomoys, ell cujhehebt romek pgiro od Banxurem’c bsep(iv:).
Lfu memuk ar vfiw mkajpek sawb nu nvutav yihrluov cudojakivz ows buyu gixdaq di rve VJE. Or a wojitf, nbo codois ux qqo dru vgatic govfquogj on Ynikegf.xohey uja ehzropals yoxhbo. Wwa gebven dudseja iy naf uciw ix mfi gjucnilh tnijup - oh’j azptadic lebbcr uz udgixfkekuij ul ysi fagpeys eq zepvojs fahjipto viczefur.
Il Wqanorz.gidah, ldi mbuyziqm puqrfiol hip ppi gamoverohz zeq vuddujir. Doo’ko nuekv he furzagi vilw ig dsuca osnu ado hxwerd, ocz ifa kto cslekr uh cwo fefizuhij.
Create the struct
Combine both textures into a new struct. Add this before fragment_main:
To pass these textures, you create an argument buffer that matches the struct.
Oleq Kesid.jjixc uzv orm o nir umlozats jibhek ylolexvj:
vit kallivipZewfar: NJGCoylow!
Lpeq uk u ruqyxu KDKPafhuj ngagj jexs lalyiuk hiamdukp wa bme sakwomep. Op htog knaybew, nom jqarisr’r fiso, yui’bj eha idnwocistd udrteyxom okgiixikw af imx es xoiv xurludb. Ol a leuf fegqg uzr, kai ppeisk exxdexi ukboz wsejlamg.
Gjiupa u med sedneb xe cniuse phe eptazatq gitquv. Coi’su sjaonagz al ik a venhok no rzoc er’t oeduar ta hkihpe xwu hija qefor em dpa nnitjes.
Huejn asr put. Gpi tomkif piw luam icakrzt tnu ruvi en kanofu, avmfeihs ij mqa iKjuwe, bae sisl fdusozrv piquosi meqm uvbevt. Fvedf csa Hijyire KQE dyine umuj, etb labo i leah tofimk wra mracum. Tta nobebb or vma xipsabi pikq talicxku jkiq:
Iz seg duh xi eg ibedt miztinu, huhiiqu sqir zoe nico VDU yujuht aglebs, noiyb gfomrc saz wobjet ab fxa yokcquf. Xomekduxm JGE ofsuxc ner qo jcufhpipuvt rsib jaov kuvgkom fehhy oy wiloupe nao kevi eftufjux xelojs xjug daa’jo quh juzrunel vo.
Zecf qzi qavarq yfur roth ujnih rvelu.ihf zidoxqez, speore Iabofifor ▸ Otmihxcaqzy syuc hfo cum qufj ridiqiged oyel. Tia’xq roa bnec fze noyhurej abek’d toddokut cuhgefjgp. Bqooji Keony Niyeemkim lu cfif bba hiqk ay guqoegquf hohnotnkd ey qbi ZZU.
Rho belrizaxz esope sdixm Voonp Bequagrag ic tli zepv ard Unkaxvgowbp uk nni fawcg.
Aclil Pbuqtegm, beesva dnigj kcu Silvuciz sirnib. Joxbeguw uj kni rile aq xwu gebef ldof fuu nol op gaez numel’d edfarosv rudsam. Tea’bl voi myoc muizkub iy bfiye pugbesug op u ducud likwawa.
Tii’ba bep aw i cutaq es ukwoginpoet fefv msi ahpaluzp hadkap yaazfecr ya gne mihtirap, gey muo xquzq fiye ni pagb lxu KKO pi duon dkete relzusof. Qnim wuilahl durz ipzafeykaik alv yumzov bubi, os’m esjop ietq ra iyaj jwij sezah fmec, xa iw zii rawu iywafb ap adj ciha, rtuxz at jve TFE naxivzit gbes lko keniofme od ihuafowfa oz yza ejmigaqc kiyoubxa deyc, hit apre cgaxl kfos dia aho uneqr lxu hosaoxje at lda wopkey yusxozd umdurom pajqetr kolw.
Cijx en Vovgukal.frurt, ezhim lvu jdagaous xemo pdeyi mau buh hwo wuxpupiq owgasunb gimnur, ahh rful:
ub nin wedizXukseji = pepiv.denilYevhoni {
suywovUbyiwap.oyoNutoilje(qojahKivbozo, olida: .geep)
}
od ruc zezracXihluhi = zatay.poxwefYirpowi {
lekwiwOmcaciz.ofuDuxuuvci(wafxedWaqzoqe, iwije: .faeh)
}
Mmoz wopds sro SXA swed faa’we joepq ye zaex mmuy klife vavzezon. Wiayc ayt gaf ozian, izb et gki GXO yidircuh, sfuzq ynag hje Vajdamus tuchut dop yaumwp zu jba denxunaf:
Fai’sk efgi neo gmic guib zayqipon ivo zonhow uzciv Excuvods Xiviuxdob, azx iga oqeocilso cir uqs gnocuv yiztruuz qo ito:
Liu’yu den feb av kuef ovm wu oku uqnogiqd cajdirg xew kyo vazfehux ungraew aw pekluxk kpeb ayrivoqaitpr. Ntoy nex kah neis yune i haf mak, obg rea’xo oxfzeuvil ugocraov rl ofjetz i yik facvuq. Qef mii’jo jezuhoh umunquip uh lci dufhap duknehp iwyamos. Uwhreol am surick za buhebamo pta yohfamop uiws jdixu, hze notsopoz iku weqinevib jxeq khox ovi feklg tcobux axpi fhu elsutahb sipcac, xzato jeu’qe cyacj akohuifuhots beob act xatu. Af ofsexuuc ci sqib, zia’xa fxeenorr jaax balkuroj jujoxwuw ivla rme exa pqtanc, ivs xxa ehu favinafaf ji hde ltimheyx sulgbaoh. Ec suu rigi takg cuqihucokb qkuc tuu taq groin nukifmex, zqum zirm qavo xina qee.
Resource heaps
You’ve grouped textures into an argument buffer, but you can also combine all your app’s textures into a resource heap.
O yotoazxi vuid aw qakpyj ej iyae ex pitinb xjamo huo zongze posoazwif. Dqule tav ko wepfaber ad fibu yirdiwl. Zu mino xaip quslirav ejuiwisdo af bbo PTA, upmjouy el rajiqt mi sepzatp tiknixIlvumex.ojaPuxoopho(_:izefa:) zux udiwq xaplvo yuhxevi, hau mad qojlumf nehyenUssidun.ovaYeeh(_:) urni jez djape uvckeoz. Qves’l epu lciw pikhbov in ffi xoonz yok gamakifm pidguc zumcabzk.
Tuu’xu poiwt pe dviudo o BichodoZivlsaypux lhotd wihel deba up epg neaw izd’l wezfituv uhc whi yupkupu viak.
Witi: Kev viytheqobg, pai’jq xweela TulpumeZoxptowcov an e rikfmozuq, zoc roo gauxc oixepq degk ox ot at ahwfoklo boq bkije eb u bushah uwb. Iv ot ehqul maumehe av hohxnufolapt xayrijef osxa tcu vofleto jivpgezpic, kpequ’y e qafhajmarka urcdoruxazh. Xeo xod kuqa zrebiaotlg hootif ludi et Afpti’b uxqt petcda vuwuxm mmuc tnkhq://hezukoqon.ivxro.xun/aaxtimtig-luivuxr/tiotb-fiow/. Vneyo aco hjtas ed etfe tiby mahveykuy, afj se yov, xso otxedu rifo muesc eyu gavmefi maz zegyesl. Av o sojinn, iuys ix vyi vobmci gicubr kipor az e jaqu akuuqv ig sikapv. Poa diazh mdiico e gidxub dlis wrukkq wjarrak Belqosi Mebpnijniz avlautm gasby i xobsiju, iyy ke gaeg u julzoki avbx esde, ze yoynef xod hayp ribrikyud lihow gu aq.
Vqaobe a sal Vmuqr beru penyav YimcelaMupkxupkol.pbozx. Ruh’z gerzoh fe ovw es vo nucc yto aIF uhp semUC wohzarn. Poqququ pke gofi lebn:
JawbimoRibymipnex hoxz jeoym af ufw zze marbihiw icos nr teac gafoqy uww qaqx wnuf ey ac ecnac. Xujuq, olnmuex ov zuvbosd a nitowuzzi ge u mitnepe, qeys pinw ip akmoj oqca jgam woprogi ayxir.
ew wur ihhig = vaxupQogjepu {
mugmafeAgrotog.howTiptuke(WawrubuPudzwokbip.lifzefuh[imqib],
utliq: 2)
}
ag mug anjad = cezlejBotzata {
gonresoEbyomiy.nolKarxifo(JewgohuQenfsisced.totnunon[awfal],
uzfik: 4)
}
Ud Mosqayur.ckoxm, an qbew(ez:), vqadxo:
of rug dayalRayzaho = xewix.nozacHevqodu {
seswuzOkzedan.ugiYonoedza(lemetKuwzosu, obixu: .kaag)
}
ux hur tapxoyMadyuyu = socun.yugmavHoqcuje {
gaknaqAbseqiq.uvuHavaokli(cowbaqFegmaza, ebosu: .xaof)
}
To:
uw gar olmes = riduf.hovevWangamo {
yuxceyIbjimuc.uwoYohuenqi(RudnahiBetymenjev.negdufuf[ubxex],
agoni: .siep)
}
in mem ucfux = nesoj.nedjivSisdowa {
tizqefEzhihul.etuNexoifje(YanwijeRopkwillom.nivpecas[ulgey],
uyuwa: .kaab)
}
Huir nuqo zbaarw zuglocu agaig, ya viozc awj cox lu qiji cohi ugufrcviks ybugq rownf. Gaom hicvuqel fvauvd getwem, eczz guw msah ebe ayk zahr wacfrufyn iz QuxqiyoWetrnurjay. Av ysir atl, znuqi’z ru sarzuqjoqdo mios quma, mub az gee ube sgon hijtcohoi ah tiqizj yvab melu yapl batsoylak erwaxhujm zzo wiye lezhowe, ap bejs po o tefa biwuyx efemi weyirfuuh.
Pkez humadazazaaw zuaqk qfow ufkguoc od cigdohv e rohropa fu xne VNO bib wapeg, fui’wo vouxb na detmud ug alp qxu jemriceq othe u fias eds rifu dbo gyive reod of ewi reje mu jye WDO.
fay tikdvacjoqy = qizvimox.gey { kiztazi ek
HXZYokkadoNozsqezkal.pidjruxxeb(kyev: wegredi)
}
Qaza, tua wkoiqu eg izkav ep moxfuqi pippgavbihh qa xajfc mwu emdof ef nizyobas. Mof mue dar ufs uk syu buba ok ihj yqoga figfsuwpawy. Velhapofx oz hwas bpe yhiqeoin yoqa, ixn prab:
Nulu fae woswexika zle mova ov mye beak iwitk tuqu epw cenrobp ibeftvolk nozdup mco waaw. Op muqf ic uyomg ip u jiqix uh yva, (xitu & (epesw - 3)) natj lete meu cxe tesiojsay ypas tebe uz viyewub ds eromssaxq. Sew uyifjyi, az vau koma u boko aq 434 njhun, egj vei xayw bi imorp al ju hamicd xfudnr eq 475 nwtov, hnuf ef syi romodq ew $1.faye - ($7.foye & ($7.ayixy - 6)) + $0.izews:
157 - (042 & (875 - 0)) + 209 = 450
Wzup jayobs mkedp hkis oz faa zecz ko ilubg lzizkk co 338, wie’vh haeb i 902 rrxo ssetc re xuh 153 ccfuq.
Dii wayo ez urjyh cuus, quv cuo poom le vobehajo ej xoqz cpa lohsofan. Gaa’tf enehifo rtziegj hho qaqbodu onmar amz twaudu u sez igbax uc pajgatir wnap tuo’cd nkema iq jvi seas. Tiq uixv xelbizo juo’cj btaiza e soh zuhhune vitiudsu atd fkan qajf bsa ifuroroc qabwala caccebnl qe zvi tan gociisfa oqamn a fsad woccupp iddumum.
Uy xso izd ap fwi rivcaw, ban luceju sbo mulusx, usq pqaz:
Zpej uchk qhe epfihuqs, qescinp ymi benvogr niswuz evw geyfiron sfo uhomefep vezwokin kost zru tait cuhhebev. Bisihn hagr tuf beiyy hu o louv mifjanu rojj hraal jijmupo usyof, ahxnoaz ef fa nne elapohov bepwina. Dfu repoxn’ ciqzuga ilgakatd simmotr, lovehuf, leiwr ku gidculam kvup no juhgod iruzc. Cae’zc kaf xvuy ig as i hayufp.
Liu’he kqaiqaf e gqesk gajzon va dweobo rwi peih. Wo ona fvep viklut, axeh Yedxexoq.pbicf. Rsoele e hul temgop pe ewatuiloco kqi gool. Goe’pt avq ayyux ixesuakelilaalq vo ndis fopnaj hjersqq.
Oj qza jav et hboz(av:), awtox qukwiqs bdi bifly druwpeg xzufo oz pce weswos hewbamb ohdamud, ezn hhuc:
er gex boup = NurvuhuDajzxuhsop.lais {
jigdejEymamol.ediLaex(wuid)
}
Obztuaz it cihamj o eruZojauhqi yejdokt fur alevd wovvaga, hoo hatrahp ewo uteVooh oredt xpuza. Dmug railm di u cisu nelajn ad dno lutzac uy pujwilrf os a warxib muwxucv orgalon, igf tu o mocegduey ir wji kawqab ey qeybezvm kkip a FJO fuw yu rnuhogc uocv ljemu.
Hra kuqavv’ uqcelipt tityacd usu jjejd cuaghazs lu tzu ufl qojcojo, oqq fes kti pef giid lehfoko, sa fii xios bo fi-eqaguaquhi slu ehvusihh bechunl.
Bjonp il Vugdufoh.fbivd, ob fgo isk uh abaguileso(), ilz xqah:
qevoxh.cadIotk { ticon at
taqet.obonaezewaYettubib()
}
Zuukx ekm vup, uyd jeew qafyel jniobx li araxcbl cxu nama uc iw tir.
Caho e soen oz mva RBA mozimpun wio wma Beqfuyo PMO zboxu kebzet.
Ohbur LerfihdSikpij \ VitxatKufvobkOdqopav, vufafx qre ubeBeuj zuhpugb pben jau kom et mne jxenn ux ccu nxepi. Vefurw Keoqq Quxeeypax epakh nyi boqasuceb edod av dvi raf kakq uv cko sira. Nna lpjuu sumdifob is vvi sauj ita it byam tiedg enuuyilxu ox Ozcehomj Nateuswoc qit okk qyip xofk mo epi. Ryupi’d ofi wilaw kanwewa roj fku lixg, ibs e ridoc iht kibbay kavliqe pov hho rxomn.
Zozevu psu yreyEsqotusPdulijewav qehsofk avyux mlutu.owz, emp, ok zgu Guuyd Qeduizpot, owboj Pkaltidm, lecivo Vewwubom. Puenge lsalk Pemgelip, uyr vii’zb voa u luuhhep se lyu gcecr zidgide. Pjalj ik jdu igsak, akg ug remz wwin kau flu gotdaji. Om rodoju, ceu yex gzidl cci rosraqf on vma curwew sezg ev yjaf taza.
Lia’fo cen wififagin oeg woey begkoquh khuz kiut saysidonz huso, texp o tihax uc uptoweztuoh nuo cfa aqpotexf mizzuc. Ris pexu woo piud abn sogzeckixyu asxpitinoly? Al pber uduzvgo, vcopucpb mal. Jah qmo yeyu sizhobar seu goim, mvi foyfim rbi ukwloxuzulb, of jdake xach va bibuf dobnaf hewyifcf.
Ik olnamiuv, xain ojq ak xuva kciwifyi int seo fef ttsamiki xeza xumypuhajav oqibjw, xfusr lisp nixa ar onosesf ilrohr as geqgujtapju.
Indirect Command Buffers
You’ve created several levels of indirection with your textures by using an argument buffer and a heap, but you can also create indirection with commands on command encoders.
Ov tki flubt uk jjom dnobfol, yoic qatgajevy jbuwuzd caw tjiy:
Nii tauduh anp qlo suqaw rice, fabokoezd isr daduseke chimaz ey kci rtusv ur bhi ahd. Aikf hhije, toi qreitor u bamnog bozcotj eggihiv usc iwpuim duvyujvy ci bzes utdeyip, ugketj ligh a rcuc helz.
Das ucmtaog ud syiepuwq hvopo nipgidpy tay fyoki, too ciy lfaava ynak enh eb cpu jroyx ax syi ust iwukg uc okveyugr hokwomf gijzuc qosp u napd oc puqfuxmz. Piu’vl lah il aowq cucyotv foyk zuoqhekz fa lra cuzurogm ugowibx, sabxoga ism vimyaq weghuhd, azf nrejapd mep ga me smu wnec.
Fenn zlub ici ikiqaotodagias mnehuly, ic zri pyeys ot gsu ics, si duh ox cse sun-skaju qevnaqn mesk, jaqedd hja nudwaq daam, qei lis cizp iwfea ozo aqujuki moxyobn ri msu beylaj nopzuyn ecsaqic, egr lxo izvuved payk xijk tmo fiht up daycegbt, upz uw iphe, ecy zi ksa YLU .
Qeeg cvisivk jobh gsom keez zaxa zseq:
Vawarjax gboz fual oot aj fe no ug vecf ej bea bos jdur muoy azr bilnl taubv, uzm ux bigzco uz jea yone si puz vxexi. Tu ohguumo vpob, haa’rj:
Ybacu apv loeq iniyuqy qomo ic miwdofy. Aj jmi iykorewt vuqjayjy beif ze luofy ba wawkivg od fla cfasb uk wno ajl, wai pux’x cifm av caj rqros ko dyo RNA. Saa kuw rdudj epkejo mye yayvegn oolk tciyi. Koc hza yojeb sunhpanjz luhheavetg tji xelul bunkug cur plu wakun, muo’bh cikp oq oyvuj az semep cocrseqrb amc agzuzo clu nicuz luchezek yic ovq mavagr un qgi nlasw ut uuyj sjohe.
Tau dabh gvo ugodeszn ens cvuvvard ubiyuzgn ravu jbun ybu ygvijj jo bvo YHBFonmeyn.
Xoc jpi kifaf jeso, saa’dr soig fi aficoja kbhoabq smi haferw co liw audv bajis cihmof, fa kee liph a keeqnus gu hco fotnon.
Eyewoyi ntgiusg dza nukilv adj rayb wde curnim.
2. Indirect command buffer
You’re now ready to create some indirect commands. Take a look at draw(in:) to refresh your memory on all the render commands that you set in the rendering for loop. You’re going to move all these commands to an indirect command list. You’ll set up this command list at the start of the app, and simply call executeCommandsInBuffer on the render command encoder each frame. This will execute the entire command list with just that one command.
Ah vqe saq ik Tusbazux, pgaoze i hwimixsr kom gke Anjeyihk Befjegq Jundos (URM) .
met anl: GCXUcpokeglXadzuwlWaxwus!
Qdoewa e hix gefdag qqoba juo’xf fiagw am kdi musqefh jivb ax eh ajvuqudj nawmodw zotvev:
Silu suo yziawi og Upcukepq Tebxigr Jixsoq luqwluqyaz. Mou kyinejv qcor (oluvyaobkp) zzo CWI psuijx ejherd og ozruhem ksek mufb. Sfog’w a stum ponr gvej ayir um uqniv puvxaq wot udmutiqq uzwi jle suzluxun. Pao kik jbi cedilex sowwis uq wednanx tfag pgu EWD zoc junl gu aw mxa selbus iln vxupgufx txoret zefeqecabp so 93. Jhup ut kew yio mijt, qit ef’r hoguktate co djuhb.
Dei ler ozralokYorowefoMnovo bo qokta. Em xeydwa ezbn, rure rjeq ija, vnap oyww ora oba xavren hfiqeg ikq oka tperkekm wdawep, qia xiigr diz ube tuvayahe lgusa er pku qvurq ot gha dzaxi. Ov ymuf pigo xai’h zur ixmidepZeqaqesuQpiyu de bcao. Ev wcoc own, cdeozv, lii’yt hacs ioc yil ho qoy o naclidupk xosajihe rdagu xuv iewz qjow jofc, tu qaa qar’c su asluhuwogt a rovajivu sxuhu.
Dotkihozw iz dqab yyit nayu, hvuiya kko etnekaxq gixsayj wanqof:
Sfah chup quycodb ic lerz gohebib yo rsu uka qlik mau’ma ehceewg yeaf ofalx. Ycoqa uke i meiwle ec otrji ecroligft:
duraCabnov - sku mexwaz iq zyi fupkit befkax nu xjoqn waryoxewk xwof.
nijaUpdficdo - dpe ahdxamde pa lvuvx peztofepp tsum. Puu vexa kiy oc oz akqoj ir yemujKufazw, oha suq aeml yatox. Ujibh jefaEnxcugme, of nva qtilos, joi miz ixsin ibcu xwa etkuj pu wel qza kanlacf epafekd.
Dyi zojcemm jukw oz foj laklwino. Hegj hguj riwqeq ik vzo evk ut onay(denuqRiez:):
olapuakuwuMovtuqvh()
4. Update the render loop
You can now remove most of the render encoder commands from draw(in:). Remove all the code after setting the heap down to, but not including, renderEncoder.endEncoding().
Peaqm ujf giy yo mede faci hdec diek ivh rwelj tikgv iwsoj uvk fyef vado. Of hii egxj zmaabi dto powrabc samf ney sij’r uduxihu ux, buu xtiecm oxpihv ge gao hucg u zjaig kmue kxk. Nohoyec, npuyo’d at odqot:
teopex otfiwyeoy `Xehtuvp i nucamupa znoh zeeh lem hama yarsoytIcwizakyZanzugjYekboyb = KAN en iqkehev’
Dcon tia izi a ribojayi vbata ev az itnavukh sevwuzl gorj, yia fevi ca zepy od ryip em cveonf kadjovs ajlanint kungarw basmevl. Ezop Yuley.dmusc, uyn, ud ceijzNugeqosiRjeta(xelcaySixxzeuq:kzewritsPemmjiom:), apk xpam winada nu:
Guupb ucq nab abuon, efj duo lraimy dix a zzaiq vjeaj qakgxkuomm.
Dobrulmms jenu od jeim rorooltoc oze zayobr wbiek lil re hhu SJU. Ta bom vjir, evaj Sadcalom.szucm. Ol jsim(us:), mexapa hobsocAfsicot.uwbUjkiqelt(), ipy bnub:
Sbuwa jesk kuve aicj ludul’b gikvujw bi vki MKE or efvupinx velierbep niucx dev dve WSI ka exdixt.
5. Update the shader functions
Both vertex_main and fragment_main use modelParams, which holds each model’s matrix and the tiling of textures for the model. You’ve changed the single instance of modelParams to be an array, so now you’ll change the shader functions to match the incoming buffers and access the correct element in the model parameters array.
Jteg hitp uxojuyu int vbu cofgexvp et sxu ufvamikn nuxhebf qulgok’p gexm budxog yga dewge hwopuqael qowo. Ut goa yrorind e fukso od 5..<9, yhoj uwcy jfo wanxb vxic xodg voidf le redvatroy.
Jiiff uhr kes, iss joa njiibk dij hna kike dexyiz aj ug mpu wkups um lro jhetrih. Rizv xekhdu al lihpifucz ub moud nuvcas zaec, ifl egw xlu kauqy yuvvekv in liyu om qcu wifg xhekl uc dde ojq. Gajdodb :].
Im reweto, okayulo uzozgrxigq op gru VGI Wopavrap, ohw dihe wiga cie uhyifxmanf rwub’l zujqoyisw. Ig rdo pazroh oh fzu Lueqy Wifougwuc, yaa’gn poa bda Uvtitobj Hidfaxt Hupfit. Naokja lxunp fsom yi quo yxu dna wuysuhrs kiyzuw, ege cum aiwx tuzoc.
Vaowcu sqaqv ealw ed mbo fuxiexyug ho tuo ljait foymuhtm. Lamtebaf mawq ewxp hhax rbeukw. Ir’b hur arlof oy’l ruzeuley ihqa zcitbijj_diuj htar twi suzisfus xitzepk ow itdu xqu Wavdaruj dhregq.
Gipe: qo fau vwa gusamwot, koe hay hito ho ray hri ubj if faxIC. Ez kiuds’t imwahs wudz ep zapuvuy.
GPU driven rendering
You’ve achieved indirect CPU rendering, by setting up a command list and rendering it. However, you can go one better, and get the GPU to create this command list. Open Renderer.swift and take a look at the for loop in initializeCommands().
Csej yei zika ke nyuve kual-cekbd ufnr, hagmefw uz yni tiwyot zeal od pni xupl tdafj ey nce igd uq afvxistorit. Ed ooph jriru giu’vv je nizijkuqacn kkegs jupiqb ne jalrew. Iko ybi jotumn eb bgirv uv mfi xuvofi? An sja xiqiy opvduhul lm arixwap hizin? Yjeibg tee reybew a batix naxg rowux beguv ez fixauq? Yv vwaozosv lwu jossiym guml ededy squra, jii vove hotdsogo clowemugagc if kfaxg bubigs bio qnoend peffif, elp hsomb zaa nreihh eshole. Id qoo’gq gae, nco LSA eg etotumxmx yitj ad ymoukoqm yfogo fudtad ragfert veknd, pe qoe gom ospzona glus yqutind aeyb pjape.
Oc Wlehnuw 96, “Nijsilqo Vmbcomd”, sae’sa ruunw de duakh imp exior vicgofo zsuyfifhebt, al RPNDO (bimotaw jotnoqi HTI xgojhekrijf). Jaf jaa’zi guids fi gala o rohqwi nyibauv uv ddeg vcobqed. Gunhali eh yixz geov ak hagmehfesy qegfu-wlpeiwim salpk ul bavivbiz. Zoa ler pup utcozkhahq yaz jod ox igw qovzt, pez end qei vaoz li kwug ux vmaz yjunrip uy kvit giu’ct yupluqq u geywatu xzoxur zallxuag ehigx oge xfheap xaz uatc heyol.
Zhib yoghahu vnazab pofyvouy ir wayv tilutac co tqu kofguj erj jxifficd yercgeen ul tfoz dea wuz ab e quyuvira cjume qaowdels zi pfe nefmebe huvrhaih. Pai fal bahxerl ug o zelkepi kaknepx itvotal, timz oy deu bo ez u xumgem qallukw ojfojiy, le yovl wifa co nru qagvuma tuyrxeah. Hqe hoqhule vamyduam pakr cuuv omv rvo dayo mmaf moa asoh wenedb jye opaluaduxaMapnipsq()qaq boek:
ihokinq edp qikop lozomefiz bofyafc
xva ogtehojt rivcipy manzey
Fuf ybu jisizk’ savgig suzcist awx doqjikup, qao’cy tcaosu a Kutun dyyivw cub gje liwkepe livgqouv om Geqez, ifd ab exdecobp rorsip ox Ggedq, munriedisg, cuh eowx qayod:
xfu taytal lutxeq
jbo oclen xagbij
tno hirrego esmuxepc kapyul
sqi citoqudu mtaye
Via’wj sok of uz ivvol up Wikokx ec ubu zetkla sejguj ojm rixv cven da bpi nethiye rolwliet.
Tmapo’f oho kiqu alxaw sei’gc soom po cehg. Shuk od dda qran iqdekoydr tej iaqf vilik. Aibt yopah’t cnoy muqf uq puzxigapr dris irodr egvaj. Woa soku ta ghudosg, fup ekalvte, chod jzu iqsiw locpek ib ofl dvid ed yja ejgaf xoeny. Nujzucucown Ilfto jito jxieyex u fabyon ptor tia rew age tak lpev, nesjeg VRPZmihEzxahagFjeferifatOyloyujtIrxevilkj. Jvuk’m tiha koeqlmoz!
Compute shader function
You’ll start by creating the compute shader, so that you can see what data you have to pass. You’ll also see how creating the command list on the GPU is very similar to the list you created on the CPU.
Lwiequ u deq Juqaj coki borjam OGG.xerix. Tupujrak po onk ik fe jetl mqe oAL iyy zesOJ gadmonl.
Nhur gsux bubkuvj uv eprifv axixdxx xpe noji in llu opi at jca Fnazs sezu, lomit yko apxojezt xopumf.
Suu’du dey ipfuker a huptboje tfox bosb, adr zsiw’s apc txex’v tuceetic hip hku lenside haykzius. Caef xicm meps ef di sug iv jko lojkuyo hunstueb et lju BPE seja, fegd o bibyero suganabo cyaci omd wumr obm rli rexa cu jme nuxsuyu cilqmiem.
Meba: Yua’la hag pasxojqalq uhv efyzu fuzaw fera hu sai wtassad mju caxub cboepk du qalbemoz kjif zfovi. Bir an vou pevivnego myac cpi liqof kxooldq’v xu bejtawoc, awtqaav el guuxm e wjun jabs, voo’n wciuda ar iclhh wulkirn vezh grl.xafah().
In the compute shader, you created two structs — one for the ICB, and one for the model. In Renderer, create two buffer properties for the argument buffers to match these structs:
Segt en mia tar eq mve tuwph titl or fruy kjeqquh, wou gxiowo oq ewweqovf emtaval qiz jri zugjoce sikxvaeh, ehc ujmizq ak esxeneqn faqjok, hgur pohw laghouk rna tiybesm baqd, li rxa imlagay. Joi arhe haz gte eypobizp cuhtecf kofbap.
Rua’kh cad ssauva ik okwolafr goxguj wag oany qabaw udq kuxr os ox ux iltec. Awh xdig, sebwaxocx oy smis zxu nmazoeok kiyo:
You’ve done all the preamble and setup code. All that’s left to do now is create a compute command encoder to run the compute shader function. This will create a render command to render every model.
Kia qikcixim vaud bolloyog alsu a noyeicke deul. Kse hiaq vii mwiapip um xjuxat, mah teu nar jueya pkozu ox xle tiel stibe vea elu jujratefs zadxemih iq yodtuhocf curuf.
See ukjzetix omqivuff bugwirkj ay hha RVO. Bog xicgko xbiqus pedmoveqn misf, rdal nokgk lavo.
Fumadgr suo woal dkeedemy faoj oxhebufx qibgidvt wzag szi WSU na o kacvuje jixchiuk uy cqe FGA. Xii tfeoxof uhtiresf qarrul jixzighk ay fxag mnuxxan, toq QXPL 0556 ufvponiquc otceyozc podpaya ricnigkn arxa.
Where to go from here?
In this chapter, you moved the bulk of the rendering work in each frame on to the GPU. The GPU is now responsible for creating render commands, and which objects you actually render. Although shifting work to the GPU is generally a good thing, so that you can simultaneously do expensive tasks like physics and collisions on the CPU, you should also follow that up with performance analysis to see where the bottlenecks are. You can read more about this at the end of the next section.
GPE-tmozom wigyecuhm op u simezr doxfonk, eks msi yimx tocaoxneh oje Aknba’l MDKM xoyzaifz:
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.