morefancystuff–I’mjustgoingwithequalsforsimplicity.Thisallowsustodotherender
targetsyncbeforewesubmitabatch.ItalsoallowsustobuildafullGPUflushoperation:
“Setregister0to++seqIdifallpendingjobsfinished”/“Waituntilregister0containsseqId”.
Doneanddone.GPU/GPUsynchronization:solved–anduntiltheintroductionofDX11with
ComputeShadersthathaveanothertypeofmorefine-grainedsynchronization,thiswas
usuallytheonlysynchronizationmechanismyouhadontheGPUside.Forregular
rendering,yousimplydon’tneedmore.
Bytheway,ifyoucanwritetheseregistersfromtheCPUside,youcanusethistheother
waytoo–submitapartialcommandbufferincludingawaitforaparticularvalue,andthen
changetheregisterfromtheCPUinsteadoftheGPU.Thiskindofthingcanbeusedto
implementD3D11-stylemultithreadedrenderingwhereyoucansubmitabatchthat
referencesvertex/indexbuffersthatarestilllockedontheCPUside(probablybeingwritten
tobyanotherthread).Yousimplystuffthewaitjustinfrontoftheactualrendercall,andthen
theCPUcanchangethecontentsoftheregisteroncethevertex/indexbuffersareactually
unlocked.IftheGPUnevergotthatfarinthecommandbuffer,thewaitisnowano-op;ifit
did,itspendsome(commandprocessor)timespinninguntilthedatawasactuallythere.
Prettynifty,no?Actually,youcanimplementthiskindofthingevenwithoutCPU-writeable
statusregistersifyoucanmodifythecommandbufferafteryousubmitit,aslongasthere’s
acommandbuffer“jump”instruction.Thedetailsarelefttotheinterestedreader:)
Ofcourse,youdon’tnecessarilyneedthesetregister/waitregistermodel;forGPU/GPU
synchronization,youcanjustassimplyhavea“rendertargetbarrier”instructionthatmakes
surearendertargetissafetouse,anda“flusheverything”command.ButIliketheset
register-stylemodelmorebecauseitkillstwobirds(back-reportingofin-useresourcestothe
CPU,andGPUself-synchronization)withonewell-designedstone.
Update:Here,I’vedrawnadiagramforyou.ItgotabitconvolutedsoI’mgoingtolowerthe
amountofdetailinthefuture.Thebasicideaisthis:ThecommandprocessorhasaFIFOin
front,thenthecommanddecodelogic,executionishandledbyvariousblocksthat
communicatewiththe2Dunit,3Dfront-end(regular3Drendering)orshaderunitsdirectly
(computeshaders),thenthere’sablockthatdealswithsync/waitcommands(whichhasthe
publiclyvisibleregistersItalkedabout),andoneunitthathandlescommandbuffer
jumps/calls(whichchangesthecurrentfetchaddressthatgoestotheFIFO).Andallofthe
unitswedispatchworktoneedtosendusbackcompletioneventssoweknowwhene.g.
texturesaren’tbeingusedanymoreandtheirmemorycanbereclaimed.
Closingremarks
Nextstepdownisthefirstonedoinganyactualrenderingwork.Finally,only3partsintomy
seriesonGPUs,weactuallystartlookingatsomevertexdata!(No,notrianglesbeing
rasterizedyet.Thatwilltakesomemoretime).