SDL_gpu.h 172 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /* WIKI CATEGORY: GPU */
  19. /**
  20. * # CategoryGPU
  21. *
  22. * The GPU API offers a cross-platform way for apps to talk to modern graphics
  23. * hardware. It offers both 3D graphics and compute support, in the style of
  24. * Metal, Vulkan, and Direct3D 12.
  25. *
  26. * A basic workflow might be something like this:
  27. *
  28. * The app creates a GPU device with SDL_CreateGPUDevice(), and assigns it to
  29. * a window with SDL_ClaimWindowForGPUDevice()--although strictly speaking you
  30. * can render offscreen entirely, perhaps for image processing, and not use a
  31. * window at all.
  32. *
  33. * Next, the app prepares static data (things that are created once and used
  34. * over and over). For example:
  35. *
  36. * - Shaders (programs that run on the GPU): use SDL_CreateGPUShader().
  37. * - Vertex buffers (arrays of geometry data) and other rendering data: use
  38. * SDL_CreateGPUBuffer() and SDL_UploadToGPUBuffer().
  39. * - Textures (images): use SDL_CreateGPUTexture() and
  40. * SDL_UploadToGPUTexture().
  41. * - Samplers (how textures should be read from): use SDL_CreateGPUSampler().
  42. * - Render pipelines (precalculated rendering state): use
  43. * SDL_CreateGPUGraphicsPipeline()
  44. *
  45. * To render, the app creates one or more command buffers, with
  46. * SDL_AcquireGPUCommandBuffer(). Command buffers collect rendering
  47. * instructions that will be submitted to the GPU in batch. Complex scenes can
  48. * use multiple command buffers, maybe configured across multiple threads in
  49. * parallel, as long as they are submitted in the correct order, but many apps
  50. * will just need one command buffer per frame.
  51. *
  52. * Rendering can happen to a texture (what other APIs call a "render target")
  53. * or it can happen to the swapchain texture (which is just a special texture
  54. * that represents a window's contents). The app can use
  55. * SDL_WaitAndAcquireGPUSwapchainTexture() to render to the window.
  56. *
  57. * Rendering actually happens in a Render Pass, which is encoded into a
  58. * command buffer. One can encode multiple render passes (or alternate between
  59. * render and compute passes) in a single command buffer, but many apps might
  60. * simply need a single render pass in a single command buffer. Render Passes
  61. * can render to up to four color textures and one depth texture
  62. * simultaneously. If the set of textures being rendered to needs to change,
  63. * the Render Pass must be ended and a new one must be begun.
  64. *
  65. * The app calls SDL_BeginGPURenderPass(). Then it sets states it needs for
  66. * each draw:
  67. *
  68. * - SDL_BindGPUGraphicsPipeline()
  69. * - SDL_SetGPUViewport()
  70. * - SDL_BindGPUVertexBuffers()
  71. * - SDL_BindGPUVertexSamplers()
  72. * - etc
  73. *
  74. * Then, make the actual draw commands with these states:
  75. *
  76. * - SDL_DrawGPUPrimitives()
  77. * - SDL_DrawGPUPrimitivesIndirect()
  78. * - SDL_DrawGPUIndexedPrimitivesIndirect()
  79. * - etc
  80. *
  81. * After all the drawing commands for a pass are complete, the app should call
  82. * SDL_EndGPURenderPass(). Once a render pass ends all render-related state is
  83. * reset.
  84. *
  85. * The app can begin new Render Passes and make new draws in the same command
  86. * buffer until the entire scene is rendered.
  87. *
  88. * Once all of the render commands for the scene are complete, the app calls
  89. * SDL_SubmitGPUCommandBuffer() to send it to the GPU for processing.
  90. *
  91. * If the app needs to read back data from texture or buffers, the API has an
  92. * efficient way of doing this, provided that the app is willing to tolerate
  93. * some latency. When the app uses SDL_DownloadFromGPUTexture() or
  94. * SDL_DownloadFromGPUBuffer(), submitting the command buffer with
  95. * SDL_SubmitGPUCommandBufferAndAcquireFence() will return a fence handle that
  96. * the app can poll or wait on in a thread. Once the fence indicates that the
  97. * command buffer is done processing, it is safe to read the downloaded data.
  98. * Make sure to call SDL_ReleaseGPUFence() when done with the fence.
  99. *
  100. * The API also has "compute" support. The app calls SDL_BeginGPUComputePass()
  101. * with compute-writeable textures and/or buffers, which can be written to in
  102. * a compute shader. Then it sets states it needs for the compute dispatches:
  103. *
  104. * - SDL_BindGPUComputePipeline()
  105. * - SDL_BindGPUComputeStorageBuffers()
  106. * - SDL_BindGPUComputeStorageTextures()
  107. *
  108. * Then, dispatch compute work:
  109. *
  110. * - SDL_DispatchGPUCompute()
  111. *
  112. * For advanced users, this opens up powerful GPU-driven workflows.
  113. *
  114. * Graphics and compute pipelines require the use of shaders, which as
  115. * mentioned above are small programs executed on the GPU. Each backend
  116. * (Vulkan, Metal, D3D12) requires a different shader format. When the app
  117. * creates the GPU device, the app lets the device know which shader formats
  118. * the app can provide. It will then select the appropriate backend depending
  119. * on the available shader formats and the backends available on the platform.
  120. * When creating shaders, the app must provide the correct shader format for
  121. * the selected backend. If you would like to learn more about why the API
  122. * works this way, there is a detailed
  123. * [blog post](https://moonside.games/posts/layers-all-the-way-down/)
  124. * explaining this situation.
  125. *
  126. * It is optimal for apps to pre-compile the shader formats they might use,
  127. * but for ease of use SDL provides a separate project,
  128. * [SDL_shadercross](https://github.com/libsdl-org/SDL_shadercross)
  129. * , for performing runtime shader cross-compilation. It also has a CLI
  130. * interface for offline precompilation as well.
  131. *
  132. * This is an extremely quick overview that leaves out several important
  133. * details. Already, though, one can see that GPU programming can be quite
  134. * complex! If you just need simple 2D graphics, the
  135. * [Render API](https://wiki.libsdl.org/SDL3/CategoryRender)
  136. * is much easier to use but still hardware-accelerated. That said, even for
  137. * 2D applications the performance benefits and expressiveness of the GPU API
  138. * are significant.
  139. *
  140. * The GPU API targets a feature set with a wide range of hardware support and
  141. * ease of portability. It is designed so that the app won't have to branch
  142. * itself by querying feature support. If you need cutting-edge features with
  143. * limited hardware support, this API is probably not for you.
  144. *
  145. * Examples demonstrating proper usage of this API can be found
  146. * [here](https://github.com/TheSpydog/SDL_gpu_examples)
  147. * .
  148. *
  149. * ## Performance considerations
  150. *
  151. * Here are some basic tips for maximizing your rendering performance.
  152. *
  153. * - Beginning a new render pass is relatively expensive. Use as few render
  154. * passes as you can.
  155. * - Minimize the amount of state changes. For example, binding a pipeline is
  156. * relatively cheap, but doing it hundreds of times when you don't need to
  157. * will slow the performance significantly.
  158. * - Perform your data uploads as early as possible in the frame.
  159. * - Don't churn resources. Creating and releasing resources is expensive.
  160. * It's better to create what you need up front and cache it.
  161. * - Don't use uniform buffers for large amounts of data (more than a matrix
  162. * or so). Use a storage buffer instead.
  163. * - Use cycling correctly. There is a detailed explanation of cycling further
  164. * below.
  165. * - Use culling techniques to minimize pixel writes. The less writing the GPU
  166. * has to do the better. Culling can be a very advanced topic but even
  167. * simple culling techniques can boost performance significantly.
  168. *
  169. * In general try to remember the golden rule of performance: doing things is
  170. * more expensive than not doing things. Don't Touch The Driver!
  171. *
  172. * ## FAQ
  173. *
  174. * **Question: When are you adding more advanced features, like ray tracing or
  175. * mesh shaders?**
  176. *
  177. * Answer: We don't have immediate plans to add more bleeding-edge features,
  178. * but we certainly might in the future, when these features prove worthwhile,
  179. * and reasonable to implement across several platforms and underlying APIs.
  180. * So while these things are not in the "never" category, they are definitely
  181. * not "near future" items either.
  182. *
  183. * **Question: Why is my shader not working?**
  184. *
  185. * Answer: A common oversight when using shaders is not properly laying out
  186. * the shader resources/registers correctly. The GPU API is very strict with
  187. * how it wants resources to be laid out and it's difficult for the API to
  188. * automatically validate shaders to see if they have a compatible layout. See
  189. * the documentation for SDL_CreateGPUShader() and
  190. * SDL_CreateGPUComputePipeline() for information on the expected layout.
  191. *
  192. * Another common issue is not setting the correct number of samplers,
  193. * textures, and buffers in SDL_GPUShaderCreateInfo. If possible use shader
  194. * reflection to extract the required information from the shader
  195. * automatically instead of manually filling in the struct's values.
  196. *
  197. * **Question: My application isn't performing very well. Is this the GPU
  198. * API's fault?**
  199. *
  200. * Answer: No. Long answer: The GPU API is a relatively thin layer over the
  201. * underlying graphics API. While it's possible that we have done something
  202. * inefficiently, it's very unlikely especially if you are relatively
  203. * inexperienced with GPU rendering. Please see the performance tips above and
  204. * make sure you are following them. Additionally, tools like
  205. * [RenderDoc](https://renderdoc.org/)
  206. * can be very helpful for diagnosing incorrect behavior and performance
  207. * issues.
  208. *
  209. * ## System Requirements
  210. *
  211. * ### Vulkan
  212. *
  213. * SDL driver name: "vulkan" (for use in SDL_CreateGPUDevice() and
  214. * SDL_PROP_GPU_DEVICE_CREATE_NAME_STRING)
  215. *
  216. * Supported on Windows, Linux, Nintendo Switch, and certain Android devices.
  217. * Requires Vulkan 1.0 with the following extensions and device features:
  218. *
  219. * - `VK_KHR_swapchain`
  220. * - `VK_KHR_maintenance1`
  221. * - `independentBlend`
  222. * - `imageCubeArray`
  223. * - `depthClamp`
  224. * - `shaderClipDistance`
  225. * - `drawIndirectFirstInstance`
  226. * - `sampleRateShading`
  227. *
  228. * You can remove some of these requirements to increase compatibility with
  229. * Android devices by using these properties when creating the GPU device with
  230. * SDL_CreateGPUDeviceWithProperties():
  231. *
  232. * - SDL_PROP_GPU_DEVICE_CREATE_FEATURE_CLIP_DISTANCE_BOOLEAN
  233. * - SDL_PROP_GPU_DEVICE_CREATE_FEATURE_DEPTH_CLAMPING_BOOLEAN
  234. * - SDL_PROP_GPU_DEVICE_CREATE_FEATURE_INDIRECT_DRAW_FIRST_INSTANCE_BOOLEAN
  235. * - SDL_PROP_GPU_DEVICE_CREATE_FEATURE_ANISOTROPY_BOOLEAN
  236. *
  237. * ### D3D12
  238. *
  239. * SDL driver name: "direct3d12"
  240. *
  241. * Supported on Windows 10 or newer, Xbox One (GDK), and Xbox Series X|S
  242. * (GDK). Requires a GPU that supports DirectX 12 Feature Level 11_0 and
  243. * Resource Binding Tier 2 or above.
  244. *
  245. * You can remove the Tier 2 resource binding requirement to support Intel
  246. * Haswell and Broadwell GPUs by using this property when creating the GPU
  247. * device with SDL_CreateGPUDeviceWithProperties():
  248. *
  249. * - SDL_PROP_GPU_DEVICE_CREATE_D3D12_ALLOW_FEWER_RESOURCE_SLOTS_BOOLEAN
  250. *
  251. * ### Metal
  252. *
  253. * SDL driver name: "metal"
  254. *
  255. * Supported on macOS 10.14+ and iOS/tvOS 13.0+. Hardware requirements vary by
  256. * operating system:
  257. *
  258. * - macOS requires an Apple Silicon or
  259. * [Intel Mac2 family](https://developer.apple.com/documentation/metal/mtlfeatureset/mtlfeatureset_macos_gpufamily2_v1?language=objc)
  260. * GPU
  261. * - iOS/tvOS requires an A9 GPU or newer
  262. * - iOS Simulator and tvOS Simulator are unsupported
  263. *
  264. * ## Coordinate System
  265. *
  266. * The GPU API uses a left-handed coordinate system, following the convention
  267. * of D3D12 and Metal. Specifically:
  268. *
  269. * - **Normalized Device Coordinates:** The lower-left corner has an x,y
  270. * coordinate of `(-1.0, -1.0)`. The upper-right corner is `(1.0, 1.0)`. Z
  271. * values range from `[0.0, 1.0]` where 0 is the near plane.
  272. * - **Viewport Coordinates:** The top-left corner has an x,y coordinate of
  273. * `(0, 0)` and extends to the bottom-right corner at `(viewportWidth,
  274. * viewportHeight)`. +Y is down.
  275. * - **Texture Coordinates:** The top-left corner has an x,y coordinate of
  276. * `(0, 0)` and extends to the bottom-right corner at `(1.0, 1.0)`. +Y is
  277. * down.
  278. *
  279. * If the backend driver differs from this convention (e.g. Vulkan, which has
  280. * an NDC that assumes +Y is down), SDL will automatically convert the
  281. * coordinate system behind the scenes, so you don't need to perform any
  282. * coordinate flipping logic in your shaders.
  283. *
  284. * ## Uniform Data
  285. *
  286. * Uniforms are for passing data to shaders. The uniform data will be constant
  287. * across all executions of the shader.
  288. *
  289. * There are 4 available uniform slots per shader stage (where the stages are
  290. * vertex, fragment, and compute). Uniform data pushed to a slot on a stage
  291. * keeps its value throughout the command buffer until you call the relevant
  292. * Push function on that slot again.
  293. *
  294. * For example, you could write your vertex shaders to read a camera matrix
  295. * from uniform binding slot 0, push the camera matrix at the start of the
  296. * command buffer, and that data will be used for every subsequent draw call.
  297. *
  298. * It is valid to push uniform data during a render or compute pass.
  299. *
  300. * Uniforms are best for pushing small amounts of data. If you are pushing
  301. * more than a matrix or two per call you should consider using a storage
  302. * buffer instead.
  303. *
  304. * ## A Note On Cycling
  305. *
  306. * When using a command buffer, operations do not occur immediately - they
  307. * occur some time after the command buffer is submitted.
  308. *
  309. * When a resource is used in a pending or active command buffer, it is
  310. * considered to be "bound". When a resource is no longer used in any pending
  311. * or active command buffers, it is considered to be "unbound".
  312. *
  313. * If data resources are bound, it is unspecified when that data will be
  314. * unbound unless you acquire a fence when submitting the command buffer and
  315. * wait on it. However, this doesn't mean you need to track resource usage
  316. * manually.
  317. *
  318. * All of the functions and structs that involve writing to a resource have a
  319. * "cycle" bool. SDL_GPUTransferBuffer, SDL_GPUBuffer, and SDL_GPUTexture all
  320. * effectively function as ring buffers on internal resources. When cycle is
  321. * true, if the resource is bound, the cycle rotates to the next unbound
  322. * internal resource, or if none are available, a new one is created. This
  323. * means you don't have to worry about complex state tracking and
  324. * synchronization as long as cycling is correctly employed.
  325. *
  326. * For example: you can call SDL_MapGPUTransferBuffer(), write texture data,
  327. * SDL_UnmapGPUTransferBuffer(), and then SDL_UploadToGPUTexture(). The next
  328. * time you write texture data to the transfer buffer, if you set the cycle
  329. * param to true, you don't have to worry about overwriting any data that is
  330. * not yet uploaded.
  331. *
  332. * Another example: If you are using a texture in a render pass every frame,
  333. * this can cause a data dependency between frames. If you set cycle to true
  334. * in the SDL_GPUColorTargetInfo struct, you can prevent this data dependency.
  335. *
  336. * Cycling will never undefine already bound data. When cycling, all data in
  337. * the resource is considered to be undefined for subsequent commands until
  338. * that data is written again. You must take care not to read undefined data.
  339. *
  340. * Note that when cycling a texture, the entire texture will be cycled, even
  341. * if only part of the texture is used in the call, so you must consider the
  342. * entire texture to contain undefined data after cycling.
  343. *
  344. * You must also take care not to overwrite a section of data that has been
  345. * referenced in a command without cycling first. It is OK to overwrite
  346. * unreferenced data in a bound resource without cycling, but overwriting a
  347. * section of data that has already been referenced will produce unexpected
  348. * results.
  349. *
  350. * ## Debugging
  351. *
  352. * At some point of your GPU journey, you will probably encounter issues that
  353. * are not traceable with regular debugger - for example, your code compiles
  354. * but you get an empty screen, or your shader fails in runtime.
  355. *
  356. * For debugging such cases, there are tools that allow visually inspecting
  357. * the whole GPU frame, every drawcall, every bound resource, memory buffers,
  358. * etc. They are the following, per platform:
  359. *
  360. * * For Windows/Linux, use
  361. * [RenderDoc](https://renderdoc.org/)
  362. * * For MacOS (Metal), use Xcode built-in debugger (Open XCode, go to Debug >
  363. * Debug Executable..., select your application, set "GPU Frame Capture" to
  364. * "Metal" in scheme "Options" window, run your app, and click the small
  365. * Metal icon on the bottom to capture a frame)
  366. *
  367. * Aside from that, you may want to enable additional debug layers to receive
  368. * more detailed error messages, based on your GPU backend:
  369. *
  370. * * For D3D12, the debug layer is an optional feature that can be installed
  371. * via "Windows Settings -> System -> Optional features" and adding the
  372. * "Graphics Tools" optional feature.
  373. * * For Vulkan, you will need to install Vulkan SDK on Windows, and on Linux,
  374. * you usually have some sort of `vulkan-validation-layers` system package
  375. * that should be installed.
  376. * * For Metal, it should be enough just to run the application from XCode to
  377. * receive detailed errors or warnings in the output.
  378. *
  379. * Don't hesitate to use tools as RenderDoc when encountering runtime issues
  380. * or unexpected output on screen, quick GPU frame inspection can usually help
  381. * you fix the majority of such problems.
  382. */
  383. #ifndef SDL_gpu_h_
  384. #define SDL_gpu_h_
  385. #include <SDL3/SDL_stdinc.h>
  386. #include <SDL3/SDL_pixels.h>
  387. #include <SDL3/SDL_properties.h>
  388. #include <SDL3/SDL_rect.h>
  389. #include <SDL3/SDL_surface.h>
  390. #include <SDL3/SDL_video.h>
  391. #include <SDL3/SDL_begin_code.h>
  392. #ifdef __cplusplus
  393. extern "C" {
  394. #endif /* __cplusplus */
  395. /* Type Declarations */
  396. /**
  397. * An opaque handle representing the SDL_GPU context.
  398. *
  399. * \since This struct is available since SDL 3.2.0.
  400. */
  401. typedef struct SDL_GPUDevice SDL_GPUDevice;
  402. /**
  403. * An opaque handle representing a buffer.
  404. *
  405. * Used for vertices, indices, indirect draw commands, and general compute
  406. * data.
  407. *
  408. * \since This struct is available since SDL 3.2.0.
  409. *
  410. * \sa SDL_CreateGPUBuffer
  411. * \sa SDL_UploadToGPUBuffer
  412. * \sa SDL_DownloadFromGPUBuffer
  413. * \sa SDL_CopyGPUBufferToBuffer
  414. * \sa SDL_BindGPUVertexBuffers
  415. * \sa SDL_BindGPUIndexBuffer
  416. * \sa SDL_BindGPUVertexStorageBuffers
  417. * \sa SDL_BindGPUFragmentStorageBuffers
  418. * \sa SDL_DrawGPUPrimitivesIndirect
  419. * \sa SDL_DrawGPUIndexedPrimitivesIndirect
  420. * \sa SDL_BindGPUComputeStorageBuffers
  421. * \sa SDL_DispatchGPUComputeIndirect
  422. * \sa SDL_ReleaseGPUBuffer
  423. */
  424. typedef struct SDL_GPUBuffer SDL_GPUBuffer;
  425. /**
  426. * An opaque handle representing a transfer buffer.
  427. *
  428. * Used for transferring data to and from the device.
  429. *
  430. * \since This struct is available since SDL 3.2.0.
  431. *
  432. * \sa SDL_CreateGPUTransferBuffer
  433. * \sa SDL_MapGPUTransferBuffer
  434. * \sa SDL_UnmapGPUTransferBuffer
  435. * \sa SDL_UploadToGPUBuffer
  436. * \sa SDL_UploadToGPUTexture
  437. * \sa SDL_DownloadFromGPUBuffer
  438. * \sa SDL_DownloadFromGPUTexture
  439. * \sa SDL_ReleaseGPUTransferBuffer
  440. */
  441. typedef struct SDL_GPUTransferBuffer SDL_GPUTransferBuffer;
  442. /**
  443. * An opaque handle representing a texture.
  444. *
  445. * \since This struct is available since SDL 3.2.0.
  446. *
  447. * \sa SDL_CreateGPUTexture
  448. * \sa SDL_UploadToGPUTexture
  449. * \sa SDL_DownloadFromGPUTexture
  450. * \sa SDL_CopyGPUTextureToTexture
  451. * \sa SDL_BindGPUVertexSamplers
  452. * \sa SDL_BindGPUVertexStorageTextures
  453. * \sa SDL_BindGPUFragmentSamplers
  454. * \sa SDL_BindGPUFragmentStorageTextures
  455. * \sa SDL_BindGPUComputeStorageTextures
  456. * \sa SDL_GenerateMipmapsForGPUTexture
  457. * \sa SDL_BlitGPUTexture
  458. * \sa SDL_ReleaseGPUTexture
  459. */
  460. typedef struct SDL_GPUTexture SDL_GPUTexture;
  461. /**
  462. * An opaque handle representing a sampler.
  463. *
  464. * \since This struct is available since SDL 3.2.0.
  465. *
  466. * \sa SDL_CreateGPUSampler
  467. * \sa SDL_BindGPUVertexSamplers
  468. * \sa SDL_BindGPUFragmentSamplers
  469. * \sa SDL_ReleaseGPUSampler
  470. */
  471. typedef struct SDL_GPUSampler SDL_GPUSampler;
  472. /**
  473. * An opaque handle representing a compiled shader object.
  474. *
  475. * \since This struct is available since SDL 3.2.0.
  476. *
  477. * \sa SDL_CreateGPUShader
  478. * \sa SDL_CreateGPUGraphicsPipeline
  479. * \sa SDL_ReleaseGPUShader
  480. */
  481. typedef struct SDL_GPUShader SDL_GPUShader;
  482. /**
  483. * An opaque handle representing a compute pipeline.
  484. *
  485. * Used during compute passes.
  486. *
  487. * \since This struct is available since SDL 3.2.0.
  488. *
  489. * \sa SDL_CreateGPUComputePipeline
  490. * \sa SDL_BindGPUComputePipeline
  491. * \sa SDL_ReleaseGPUComputePipeline
  492. */
  493. typedef struct SDL_GPUComputePipeline SDL_GPUComputePipeline;
  494. /**
  495. * An opaque handle representing a graphics pipeline.
  496. *
  497. * Used during render passes.
  498. *
  499. * \since This struct is available since SDL 3.2.0.
  500. *
  501. * \sa SDL_CreateGPUGraphicsPipeline
  502. * \sa SDL_BindGPUGraphicsPipeline
  503. * \sa SDL_ReleaseGPUGraphicsPipeline
  504. */
  505. typedef struct SDL_GPUGraphicsPipeline SDL_GPUGraphicsPipeline;
  506. /**
  507. * An opaque handle representing a command buffer.
  508. *
  509. * Most state is managed via command buffers. When setting state using a
  510. * command buffer, that state is local to the command buffer.
  511. *
  512. * Commands only begin execution on the GPU once SDL_SubmitGPUCommandBuffer is
  513. * called. Once the command buffer is submitted, it is no longer valid to use
  514. * it.
  515. *
  516. * Command buffers are executed in submission order. If you submit command
  517. * buffer A and then command buffer B all commands in A will begin executing
  518. * before any command in B begins executing.
  519. *
  520. * In multi-threading scenarios, you should only access a command buffer on
  521. * the thread you acquired it from.
  522. *
  523. * \since This struct is available since SDL 3.2.0.
  524. *
  525. * \sa SDL_AcquireGPUCommandBuffer
  526. * \sa SDL_SubmitGPUCommandBuffer
  527. * \sa SDL_SubmitGPUCommandBufferAndAcquireFence
  528. */
  529. typedef struct SDL_GPUCommandBuffer SDL_GPUCommandBuffer;
  530. /**
  531. * An opaque handle representing a render pass.
  532. *
  533. * This handle is transient and should not be held or referenced after
  534. * SDL_EndGPURenderPass is called.
  535. *
  536. * \since This struct is available since SDL 3.2.0.
  537. *
  538. * \sa SDL_BeginGPURenderPass
  539. * \sa SDL_EndGPURenderPass
  540. */
  541. typedef struct SDL_GPURenderPass SDL_GPURenderPass;
  542. /**
  543. * An opaque handle representing a compute pass.
  544. *
  545. * This handle is transient and should not be held or referenced after
  546. * SDL_EndGPUComputePass is called.
  547. *
  548. * \since This struct is available since SDL 3.2.0.
  549. *
  550. * \sa SDL_BeginGPUComputePass
  551. * \sa SDL_EndGPUComputePass
  552. */
  553. typedef struct SDL_GPUComputePass SDL_GPUComputePass;
  554. /**
  555. * An opaque handle representing a copy pass.
  556. *
  557. * This handle is transient and should not be held or referenced after
  558. * SDL_EndGPUCopyPass is called.
  559. *
  560. * \since This struct is available since SDL 3.2.0.
  561. *
  562. * \sa SDL_BeginGPUCopyPass
  563. * \sa SDL_EndGPUCopyPass
  564. */
  565. typedef struct SDL_GPUCopyPass SDL_GPUCopyPass;
  566. /**
  567. * An opaque handle representing a fence.
  568. *
  569. * \since This struct is available since SDL 3.2.0.
  570. *
  571. * \sa SDL_SubmitGPUCommandBufferAndAcquireFence
  572. * \sa SDL_QueryGPUFence
  573. * \sa SDL_WaitForGPUFences
  574. * \sa SDL_ReleaseGPUFence
  575. */
  576. typedef struct SDL_GPUFence SDL_GPUFence;
  577. /**
  578. * Specifies the primitive topology of a graphics pipeline.
  579. *
  580. * If you are using POINTLIST you must include a point size output in the
  581. * vertex shader.
  582. *
  583. * - For HLSL compiling to SPIRV you must decorate a float output with
  584. * [[vk::builtin("PointSize")]].
  585. * - For GLSL you must set the gl_PointSize builtin.
  586. * - For MSL you must include a float output with the [[point_size]]
  587. * decorator.
  588. *
  589. * Note that sized point topology is totally unsupported on D3D12. Any size
  590. * other than 1 will be ignored. In general, you should avoid using point
  591. * topology for both compatibility and performance reasons. You WILL regret
  592. * using it.
  593. *
  594. * \since This enum is available since SDL 3.2.0.
  595. *
  596. * \sa SDL_CreateGPUGraphicsPipeline
  597. */
  598. typedef enum SDL_GPUPrimitiveType
  599. {
  600. SDL_GPU_PRIMITIVETYPE_TRIANGLELIST, /**< A series of separate triangles. */
  601. SDL_GPU_PRIMITIVETYPE_TRIANGLESTRIP, /**< A series of connected triangles. */
  602. SDL_GPU_PRIMITIVETYPE_LINELIST, /**< A series of separate lines. */
  603. SDL_GPU_PRIMITIVETYPE_LINESTRIP, /**< A series of connected lines. */
  604. SDL_GPU_PRIMITIVETYPE_POINTLIST /**< A series of separate points. */
  605. } SDL_GPUPrimitiveType;
  606. /**
  607. * Specifies how the contents of a texture attached to a render pass are
  608. * treated at the beginning of the render pass.
  609. *
  610. * \since This enum is available since SDL 3.2.0.
  611. *
  612. * \sa SDL_BeginGPURenderPass
  613. */
  614. typedef enum SDL_GPULoadOp
  615. {
  616. SDL_GPU_LOADOP_LOAD, /**< The previous contents of the texture will be preserved. */
  617. SDL_GPU_LOADOP_CLEAR, /**< The contents of the texture will be cleared to a color. */
  618. SDL_GPU_LOADOP_DONT_CARE /**< The previous contents of the texture need not be preserved. The contents will be undefined. */
  619. } SDL_GPULoadOp;
  620. /**
  621. * Specifies how the contents of a texture attached to a render pass are
  622. * treated at the end of the render pass.
  623. *
  624. * \since This enum is available since SDL 3.2.0.
  625. *
  626. * \sa SDL_BeginGPURenderPass
  627. */
  628. typedef enum SDL_GPUStoreOp
  629. {
  630. SDL_GPU_STOREOP_STORE, /**< The contents generated during the render pass will be written to memory. */
  631. SDL_GPU_STOREOP_DONT_CARE, /**< The contents generated during the render pass are not needed and may be discarded. The contents will be undefined. */
  632. SDL_GPU_STOREOP_RESOLVE, /**< The multisample contents generated during the render pass will be resolved to a non-multisample texture. The contents in the multisample texture may then be discarded and will be undefined. */
  633. SDL_GPU_STOREOP_RESOLVE_AND_STORE /**< The multisample contents generated during the render pass will be resolved to a non-multisample texture. The contents in the multisample texture will be written to memory. */
  634. } SDL_GPUStoreOp;
  635. /**
  636. * Specifies the size of elements in an index buffer.
  637. *
  638. * \since This enum is available since SDL 3.2.0.
  639. *
  640. * \sa SDL_CreateGPUGraphicsPipeline
  641. */
  642. typedef enum SDL_GPUIndexElementSize
  643. {
  644. SDL_GPU_INDEXELEMENTSIZE_16BIT, /**< The index elements are 16-bit. */
  645. SDL_GPU_INDEXELEMENTSIZE_32BIT /**< The index elements are 32-bit. */
  646. } SDL_GPUIndexElementSize;
  647. /**
  648. * Specifies the pixel format of a texture.
  649. *
  650. * Texture format support varies depending on driver, hardware, and usage
  651. * flags. In general, you should use SDL_GPUTextureSupportsFormat to query if
  652. * a format is supported before using it. However, there are a few guaranteed
  653. * formats.
  654. *
  655. * FIXME: Check universal support for 32-bit component formats FIXME: Check
  656. * universal support for SIMULTANEOUS_READ_WRITE
  657. *
  658. * For SAMPLER usage, the following formats are universally supported:
  659. *
  660. * - R8G8B8A8_UNORM
  661. * - B8G8R8A8_UNORM
  662. * - R8_UNORM
  663. * - R8_SNORM
  664. * - R8G8_UNORM
  665. * - R8G8_SNORM
  666. * - R8G8B8A8_SNORM
  667. * - R16_FLOAT
  668. * - R16G16_FLOAT
  669. * - R16G16B16A16_FLOAT
  670. * - R32_FLOAT
  671. * - R32G32_FLOAT
  672. * - R32G32B32A32_FLOAT
  673. * - R11G11B10_UFLOAT
  674. * - R8G8B8A8_UNORM_SRGB
  675. * - B8G8R8A8_UNORM_SRGB
  676. * - D16_UNORM
  677. *
  678. * For COLOR_TARGET usage, the following formats are universally supported:
  679. *
  680. * - R8G8B8A8_UNORM
  681. * - B8G8R8A8_UNORM
  682. * - R8_UNORM
  683. * - R16_FLOAT
  684. * - R16G16_FLOAT
  685. * - R16G16B16A16_FLOAT
  686. * - R32_FLOAT
  687. * - R32G32_FLOAT
  688. * - R32G32B32A32_FLOAT
  689. * - R8_UINT
  690. * - R8G8_UINT
  691. * - R8G8B8A8_UINT
  692. * - R16_UINT
  693. * - R16G16_UINT
  694. * - R16G16B16A16_UINT
  695. * - R8_INT
  696. * - R8G8_INT
  697. * - R8G8B8A8_INT
  698. * - R16_INT
  699. * - R16G16_INT
  700. * - R16G16B16A16_INT
  701. * - R8G8B8A8_UNORM_SRGB
  702. * - B8G8R8A8_UNORM_SRGB
  703. *
  704. * For STORAGE usages, the following formats are universally supported:
  705. *
  706. * - R8G8B8A8_UNORM
  707. * - R8G8B8A8_SNORM
  708. * - R16G16B16A16_FLOAT
  709. * - R32_FLOAT
  710. * - R32G32_FLOAT
  711. * - R32G32B32A32_FLOAT
  712. * - R8G8B8A8_UINT
  713. * - R16G16B16A16_UINT
  714. * - R8G8B8A8_INT
  715. * - R16G16B16A16_INT
  716. *
  717. * For DEPTH_STENCIL_TARGET usage, the following formats are universally
  718. * supported:
  719. *
  720. * - D16_UNORM
  721. * - Either (but not necessarily both!) D24_UNORM or D32_FLOAT
  722. * - Either (but not necessarily both!) D24_UNORM_S8_UINT or D32_FLOAT_S8_UINT
  723. *
  724. * Unless D16_UNORM is sufficient for your purposes, always check which of
  725. * D24/D32 is supported before creating a depth-stencil texture!
  726. *
  727. * \since This enum is available since SDL 3.2.0.
  728. *
  729. * \sa SDL_CreateGPUTexture
  730. * \sa SDL_GPUTextureSupportsFormat
  731. */
  732. typedef enum SDL_GPUTextureFormat
  733. {
  734. SDL_GPU_TEXTUREFORMAT_INVALID,
  735. /* Unsigned Normalized Float Color Formats */
  736. SDL_GPU_TEXTUREFORMAT_A8_UNORM,
  737. SDL_GPU_TEXTUREFORMAT_R8_UNORM,
  738. SDL_GPU_TEXTUREFORMAT_R8G8_UNORM,
  739. SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM,
  740. SDL_GPU_TEXTUREFORMAT_R16_UNORM,
  741. SDL_GPU_TEXTUREFORMAT_R16G16_UNORM,
  742. SDL_GPU_TEXTUREFORMAT_R16G16B16A16_UNORM,
  743. SDL_GPU_TEXTUREFORMAT_R10G10B10A2_UNORM,
  744. SDL_GPU_TEXTUREFORMAT_B5G6R5_UNORM,
  745. SDL_GPU_TEXTUREFORMAT_B5G5R5A1_UNORM,
  746. SDL_GPU_TEXTUREFORMAT_B4G4R4A4_UNORM,
  747. SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM,
  748. /* Compressed Unsigned Normalized Float Color Formats */
  749. SDL_GPU_TEXTUREFORMAT_BC1_RGBA_UNORM,
  750. SDL_GPU_TEXTUREFORMAT_BC2_RGBA_UNORM,
  751. SDL_GPU_TEXTUREFORMAT_BC3_RGBA_UNORM,
  752. SDL_GPU_TEXTUREFORMAT_BC4_R_UNORM,
  753. SDL_GPU_TEXTUREFORMAT_BC5_RG_UNORM,
  754. SDL_GPU_TEXTUREFORMAT_BC7_RGBA_UNORM,
  755. /* Compressed Signed Float Color Formats */
  756. SDL_GPU_TEXTUREFORMAT_BC6H_RGB_FLOAT,
  757. /* Compressed Unsigned Float Color Formats */
  758. SDL_GPU_TEXTUREFORMAT_BC6H_RGB_UFLOAT,
  759. /* Signed Normalized Float Color Formats */
  760. SDL_GPU_TEXTUREFORMAT_R8_SNORM,
  761. SDL_GPU_TEXTUREFORMAT_R8G8_SNORM,
  762. SDL_GPU_TEXTUREFORMAT_R8G8B8A8_SNORM,
  763. SDL_GPU_TEXTUREFORMAT_R16_SNORM,
  764. SDL_GPU_TEXTUREFORMAT_R16G16_SNORM,
  765. SDL_GPU_TEXTUREFORMAT_R16G16B16A16_SNORM,
  766. /* Signed Float Color Formats */
  767. SDL_GPU_TEXTUREFORMAT_R16_FLOAT,
  768. SDL_GPU_TEXTUREFORMAT_R16G16_FLOAT,
  769. SDL_GPU_TEXTUREFORMAT_R16G16B16A16_FLOAT,
  770. SDL_GPU_TEXTUREFORMAT_R32_FLOAT,
  771. SDL_GPU_TEXTUREFORMAT_R32G32_FLOAT,
  772. SDL_GPU_TEXTUREFORMAT_R32G32B32A32_FLOAT,
  773. /* Unsigned Float Color Formats */
  774. SDL_GPU_TEXTUREFORMAT_R11G11B10_UFLOAT,
  775. /* Unsigned Integer Color Formats */
  776. SDL_GPU_TEXTUREFORMAT_R8_UINT,
  777. SDL_GPU_TEXTUREFORMAT_R8G8_UINT,
  778. SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UINT,
  779. SDL_GPU_TEXTUREFORMAT_R16_UINT,
  780. SDL_GPU_TEXTUREFORMAT_R16G16_UINT,
  781. SDL_GPU_TEXTUREFORMAT_R16G16B16A16_UINT,
  782. SDL_GPU_TEXTUREFORMAT_R32_UINT,
  783. SDL_GPU_TEXTUREFORMAT_R32G32_UINT,
  784. SDL_GPU_TEXTUREFORMAT_R32G32B32A32_UINT,
  785. /* Signed Integer Color Formats */
  786. SDL_GPU_TEXTUREFORMAT_R8_INT,
  787. SDL_GPU_TEXTUREFORMAT_R8G8_INT,
  788. SDL_GPU_TEXTUREFORMAT_R8G8B8A8_INT,
  789. SDL_GPU_TEXTUREFORMAT_R16_INT,
  790. SDL_GPU_TEXTUREFORMAT_R16G16_INT,
  791. SDL_GPU_TEXTUREFORMAT_R16G16B16A16_INT,
  792. SDL_GPU_TEXTUREFORMAT_R32_INT,
  793. SDL_GPU_TEXTUREFORMAT_R32G32_INT,
  794. SDL_GPU_TEXTUREFORMAT_R32G32B32A32_INT,
  795. /* SRGB Unsigned Normalized Color Formats */
  796. SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM_SRGB,
  797. SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM_SRGB,
  798. /* Compressed SRGB Unsigned Normalized Color Formats */
  799. SDL_GPU_TEXTUREFORMAT_BC1_RGBA_UNORM_SRGB,
  800. SDL_GPU_TEXTUREFORMAT_BC2_RGBA_UNORM_SRGB,
  801. SDL_GPU_TEXTUREFORMAT_BC3_RGBA_UNORM_SRGB,
  802. SDL_GPU_TEXTUREFORMAT_BC7_RGBA_UNORM_SRGB,
  803. /* Depth Formats */
  804. SDL_GPU_TEXTUREFORMAT_D16_UNORM,
  805. SDL_GPU_TEXTUREFORMAT_D24_UNORM,
  806. SDL_GPU_TEXTUREFORMAT_D32_FLOAT,
  807. SDL_GPU_TEXTUREFORMAT_D24_UNORM_S8_UINT,
  808. SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT,
  809. /* Compressed ASTC Normalized Float Color Formats*/
  810. SDL_GPU_TEXTUREFORMAT_ASTC_4x4_UNORM,
  811. SDL_GPU_TEXTUREFORMAT_ASTC_5x4_UNORM,
  812. SDL_GPU_TEXTUREFORMAT_ASTC_5x5_UNORM,
  813. SDL_GPU_TEXTUREFORMAT_ASTC_6x5_UNORM,
  814. SDL_GPU_TEXTUREFORMAT_ASTC_6x6_UNORM,
  815. SDL_GPU_TEXTUREFORMAT_ASTC_8x5_UNORM,
  816. SDL_GPU_TEXTUREFORMAT_ASTC_8x6_UNORM,
  817. SDL_GPU_TEXTUREFORMAT_ASTC_8x8_UNORM,
  818. SDL_GPU_TEXTUREFORMAT_ASTC_10x5_UNORM,
  819. SDL_GPU_TEXTUREFORMAT_ASTC_10x6_UNORM,
  820. SDL_GPU_TEXTUREFORMAT_ASTC_10x8_UNORM,
  821. SDL_GPU_TEXTUREFORMAT_ASTC_10x10_UNORM,
  822. SDL_GPU_TEXTUREFORMAT_ASTC_12x10_UNORM,
  823. SDL_GPU_TEXTUREFORMAT_ASTC_12x12_UNORM,
  824. /* Compressed SRGB ASTC Normalized Float Color Formats*/
  825. SDL_GPU_TEXTUREFORMAT_ASTC_4x4_UNORM_SRGB,
  826. SDL_GPU_TEXTUREFORMAT_ASTC_5x4_UNORM_SRGB,
  827. SDL_GPU_TEXTUREFORMAT_ASTC_5x5_UNORM_SRGB,
  828. SDL_GPU_TEXTUREFORMAT_ASTC_6x5_UNORM_SRGB,
  829. SDL_GPU_TEXTUREFORMAT_ASTC_6x6_UNORM_SRGB,
  830. SDL_GPU_TEXTUREFORMAT_ASTC_8x5_UNORM_SRGB,
  831. SDL_GPU_TEXTUREFORMAT_ASTC_8x6_UNORM_SRGB,
  832. SDL_GPU_TEXTUREFORMAT_ASTC_8x8_UNORM_SRGB,
  833. SDL_GPU_TEXTUREFORMAT_ASTC_10x5_UNORM_SRGB,
  834. SDL_GPU_TEXTUREFORMAT_ASTC_10x6_UNORM_SRGB,
  835. SDL_GPU_TEXTUREFORMAT_ASTC_10x8_UNORM_SRGB,
  836. SDL_GPU_TEXTUREFORMAT_ASTC_10x10_UNORM_SRGB,
  837. SDL_GPU_TEXTUREFORMAT_ASTC_12x10_UNORM_SRGB,
  838. SDL_GPU_TEXTUREFORMAT_ASTC_12x12_UNORM_SRGB,
  839. /* Compressed ASTC Signed Float Color Formats*/
  840. SDL_GPU_TEXTUREFORMAT_ASTC_4x4_FLOAT,
  841. SDL_GPU_TEXTUREFORMAT_ASTC_5x4_FLOAT,
  842. SDL_GPU_TEXTUREFORMAT_ASTC_5x5_FLOAT,
  843. SDL_GPU_TEXTUREFORMAT_ASTC_6x5_FLOAT,
  844. SDL_GPU_TEXTUREFORMAT_ASTC_6x6_FLOAT,
  845. SDL_GPU_TEXTUREFORMAT_ASTC_8x5_FLOAT,
  846. SDL_GPU_TEXTUREFORMAT_ASTC_8x6_FLOAT,
  847. SDL_GPU_TEXTUREFORMAT_ASTC_8x8_FLOAT,
  848. SDL_GPU_TEXTUREFORMAT_ASTC_10x5_FLOAT,
  849. SDL_GPU_TEXTUREFORMAT_ASTC_10x6_FLOAT,
  850. SDL_GPU_TEXTUREFORMAT_ASTC_10x8_FLOAT,
  851. SDL_GPU_TEXTUREFORMAT_ASTC_10x10_FLOAT,
  852. SDL_GPU_TEXTUREFORMAT_ASTC_12x10_FLOAT,
  853. SDL_GPU_TEXTUREFORMAT_ASTC_12x12_FLOAT
  854. } SDL_GPUTextureFormat;
  855. /**
  856. * Specifies how a texture is intended to be used by the client.
  857. *
  858. * A texture must have at least one usage flag. Note that some usage flag
  859. * combinations are invalid.
  860. *
  861. * With regards to compute storage usage, READ | WRITE means that you can have
  862. * shader A that only writes into the texture and shader B that only reads
  863. * from the texture and bind the same texture to either shader respectively.
  864. * SIMULTANEOUS means that you can do reads and writes within the same shader
  865. * or compute pass. It also implies that atomic ops can be used, since those
  866. * are read-modify-write operations. If you use SIMULTANEOUS, you are
  867. * responsible for avoiding data races, as there is no data synchronization
  868. * within a compute pass. Note that SIMULTANEOUS usage is only supported by a
  869. * limited number of texture formats.
  870. *
  871. * \since This datatype is available since SDL 3.2.0.
  872. *
  873. * \sa SDL_CreateGPUTexture
  874. */
  875. typedef Uint32 SDL_GPUTextureUsageFlags;
  876. #define SDL_GPU_TEXTUREUSAGE_SAMPLER (1u << 0) /**< Texture supports sampling. */
  877. #define SDL_GPU_TEXTUREUSAGE_COLOR_TARGET (1u << 1) /**< Texture is a color render target. */
  878. #define SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET (1u << 2) /**< Texture is a depth stencil target. */
  879. #define SDL_GPU_TEXTUREUSAGE_GRAPHICS_STORAGE_READ (1u << 3) /**< Texture supports storage reads in graphics stages. */
  880. #define SDL_GPU_TEXTUREUSAGE_COMPUTE_STORAGE_READ (1u << 4) /**< Texture supports storage reads in the compute stage. */
  881. #define SDL_GPU_TEXTUREUSAGE_COMPUTE_STORAGE_WRITE (1u << 5) /**< Texture supports storage writes in the compute stage. */
  882. #define SDL_GPU_TEXTUREUSAGE_COMPUTE_STORAGE_SIMULTANEOUS_READ_WRITE (1u << 6) /**< Texture supports reads and writes in the same compute shader. This is NOT equivalent to READ | WRITE. */
  883. /**
  884. * Specifies the type of a texture.
  885. *
  886. * \since This enum is available since SDL 3.2.0.
  887. *
  888. * \sa SDL_CreateGPUTexture
  889. */
  890. typedef enum SDL_GPUTextureType
  891. {
  892. SDL_GPU_TEXTURETYPE_2D, /**< The texture is a 2-dimensional image. */
  893. SDL_GPU_TEXTURETYPE_2D_ARRAY, /**< The texture is a 2-dimensional array image. */
  894. SDL_GPU_TEXTURETYPE_3D, /**< The texture is a 3-dimensional image. */
  895. SDL_GPU_TEXTURETYPE_CUBE, /**< The texture is a cube image. */
  896. SDL_GPU_TEXTURETYPE_CUBE_ARRAY /**< The texture is a cube array image. */
  897. } SDL_GPUTextureType;
  898. /**
  899. * Specifies the sample count of a texture.
  900. *
  901. * Used in multisampling. Note that this value only applies when the texture
  902. * is used as a render target.
  903. *
  904. * \since This enum is available since SDL 3.2.0.
  905. *
  906. * \sa SDL_CreateGPUTexture
  907. * \sa SDL_GPUTextureSupportsSampleCount
  908. */
  909. typedef enum SDL_GPUSampleCount
  910. {
  911. SDL_GPU_SAMPLECOUNT_1, /**< No multisampling. */
  912. SDL_GPU_SAMPLECOUNT_2, /**< MSAA 2x */
  913. SDL_GPU_SAMPLECOUNT_4, /**< MSAA 4x */
  914. SDL_GPU_SAMPLECOUNT_8 /**< MSAA 8x */
  915. } SDL_GPUSampleCount;
  916. /**
  917. * Specifies the face of a cube map.
  918. *
  919. * Can be passed in as the layer field in texture-related structs.
  920. *
  921. * \since This enum is available since SDL 3.2.0.
  922. */
  923. typedef enum SDL_GPUCubeMapFace
  924. {
  925. SDL_GPU_CUBEMAPFACE_POSITIVEX,
  926. SDL_GPU_CUBEMAPFACE_NEGATIVEX,
  927. SDL_GPU_CUBEMAPFACE_POSITIVEY,
  928. SDL_GPU_CUBEMAPFACE_NEGATIVEY,
  929. SDL_GPU_CUBEMAPFACE_POSITIVEZ,
  930. SDL_GPU_CUBEMAPFACE_NEGATIVEZ
  931. } SDL_GPUCubeMapFace;
  932. /**
  933. * Specifies how a buffer is intended to be used by the client.
  934. *
  935. * A buffer must have at least one usage flag. Note that some usage flag
  936. * combinations are invalid.
  937. *
  938. * Unlike textures, READ | WRITE can be used for simultaneous read-write
  939. * usage. The same data synchronization concerns as textures apply.
  940. *
  941. * If you use a STORAGE flag, the data in the buffer must respect std140
  942. * layout conventions. In practical terms this means you must ensure that vec3
  943. * and vec4 fields are 16-byte aligned.
  944. *
  945. * \since This datatype is available since SDL 3.2.0.
  946. *
  947. * \sa SDL_CreateGPUBuffer
  948. */
  949. typedef Uint32 SDL_GPUBufferUsageFlags;
  950. #define SDL_GPU_BUFFERUSAGE_VERTEX (1u << 0) /**< Buffer is a vertex buffer. */
  951. #define SDL_GPU_BUFFERUSAGE_INDEX (1u << 1) /**< Buffer is an index buffer. */
  952. #define SDL_GPU_BUFFERUSAGE_INDIRECT (1u << 2) /**< Buffer is an indirect buffer. */
  953. #define SDL_GPU_BUFFERUSAGE_GRAPHICS_STORAGE_READ (1u << 3) /**< Buffer supports storage reads in graphics stages. */
  954. #define SDL_GPU_BUFFERUSAGE_COMPUTE_STORAGE_READ (1u << 4) /**< Buffer supports storage reads in the compute stage. */
  955. #define SDL_GPU_BUFFERUSAGE_COMPUTE_STORAGE_WRITE (1u << 5) /**< Buffer supports storage writes in the compute stage. */
  956. /**
  957. * Specifies how a transfer buffer is intended to be used by the client.
  958. *
  959. * Note that mapping and copying FROM an upload transfer buffer or TO a
  960. * download transfer buffer is undefined behavior.
  961. *
  962. * \since This enum is available since SDL 3.2.0.
  963. *
  964. * \sa SDL_CreateGPUTransferBuffer
  965. */
  966. typedef enum SDL_GPUTransferBufferUsage
  967. {
  968. SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD,
  969. SDL_GPU_TRANSFERBUFFERUSAGE_DOWNLOAD
  970. } SDL_GPUTransferBufferUsage;
  971. /**
  972. * Specifies which stage a shader program corresponds to.
  973. *
  974. * \since This enum is available since SDL 3.2.0.
  975. *
  976. * \sa SDL_CreateGPUShader
  977. */
  978. typedef enum SDL_GPUShaderStage
  979. {
  980. SDL_GPU_SHADERSTAGE_VERTEX,
  981. SDL_GPU_SHADERSTAGE_FRAGMENT
  982. } SDL_GPUShaderStage;
  983. /**
  984. * Specifies the format of shader code.
  985. *
  986. * Each format corresponds to a specific backend that accepts it.
  987. *
  988. * \since This datatype is available since SDL 3.2.0.
  989. *
  990. * \sa SDL_CreateGPUShader
  991. */
  992. typedef Uint32 SDL_GPUShaderFormat;
  993. #define SDL_GPU_SHADERFORMAT_INVALID 0
  994. #define SDL_GPU_SHADERFORMAT_PRIVATE (1u << 0) /**< Shaders for NDA'd platforms. */
  995. #define SDL_GPU_SHADERFORMAT_SPIRV (1u << 1) /**< SPIR-V shaders for Vulkan. */
  996. #define SDL_GPU_SHADERFORMAT_DXBC (1u << 2) /**< DXBC SM5_1 shaders for D3D12. */
  997. #define SDL_GPU_SHADERFORMAT_DXIL (1u << 3) /**< DXIL SM6_0 shaders for D3D12. */
  998. #define SDL_GPU_SHADERFORMAT_MSL (1u << 4) /**< MSL shaders for Metal. */
  999. #define SDL_GPU_SHADERFORMAT_METALLIB (1u << 5) /**< Precompiled metallib shaders for Metal. */
  1000. /**
  1001. * Specifies the format of a vertex attribute.
  1002. *
  1003. * \since This enum is available since SDL 3.2.0.
  1004. *
  1005. * \sa SDL_CreateGPUGraphicsPipeline
  1006. */
  1007. typedef enum SDL_GPUVertexElementFormat
  1008. {
  1009. SDL_GPU_VERTEXELEMENTFORMAT_INVALID,
  1010. /* 32-bit Signed Integers */
  1011. SDL_GPU_VERTEXELEMENTFORMAT_INT,
  1012. SDL_GPU_VERTEXELEMENTFORMAT_INT2,
  1013. SDL_GPU_VERTEXELEMENTFORMAT_INT3,
  1014. SDL_GPU_VERTEXELEMENTFORMAT_INT4,
  1015. /* 32-bit Unsigned Integers */
  1016. SDL_GPU_VERTEXELEMENTFORMAT_UINT,
  1017. SDL_GPU_VERTEXELEMENTFORMAT_UINT2,
  1018. SDL_GPU_VERTEXELEMENTFORMAT_UINT3,
  1019. SDL_GPU_VERTEXELEMENTFORMAT_UINT4,
  1020. /* 32-bit Floats */
  1021. SDL_GPU_VERTEXELEMENTFORMAT_FLOAT,
  1022. SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2,
  1023. SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3,
  1024. SDL_GPU_VERTEXELEMENTFORMAT_FLOAT4,
  1025. /* 8-bit Signed Integers */
  1026. SDL_GPU_VERTEXELEMENTFORMAT_BYTE2,
  1027. SDL_GPU_VERTEXELEMENTFORMAT_BYTE4,
  1028. /* 8-bit Unsigned Integers */
  1029. SDL_GPU_VERTEXELEMENTFORMAT_UBYTE2,
  1030. SDL_GPU_VERTEXELEMENTFORMAT_UBYTE4,
  1031. /* 8-bit Signed Normalized */
  1032. SDL_GPU_VERTEXELEMENTFORMAT_BYTE2_NORM,
  1033. SDL_GPU_VERTEXELEMENTFORMAT_BYTE4_NORM,
  1034. /* 8-bit Unsigned Normalized */
  1035. SDL_GPU_VERTEXELEMENTFORMAT_UBYTE2_NORM,
  1036. SDL_GPU_VERTEXELEMENTFORMAT_UBYTE4_NORM,
  1037. /* 16-bit Signed Integers */
  1038. SDL_GPU_VERTEXELEMENTFORMAT_SHORT2,
  1039. SDL_GPU_VERTEXELEMENTFORMAT_SHORT4,
  1040. /* 16-bit Unsigned Integers */
  1041. SDL_GPU_VERTEXELEMENTFORMAT_USHORT2,
  1042. SDL_GPU_VERTEXELEMENTFORMAT_USHORT4,
  1043. /* 16-bit Signed Normalized */
  1044. SDL_GPU_VERTEXELEMENTFORMAT_SHORT2_NORM,
  1045. SDL_GPU_VERTEXELEMENTFORMAT_SHORT4_NORM,
  1046. /* 16-bit Unsigned Normalized */
  1047. SDL_GPU_VERTEXELEMENTFORMAT_USHORT2_NORM,
  1048. SDL_GPU_VERTEXELEMENTFORMAT_USHORT4_NORM,
  1049. /* 16-bit Floats */
  1050. SDL_GPU_VERTEXELEMENTFORMAT_HALF2,
  1051. SDL_GPU_VERTEXELEMENTFORMAT_HALF4
  1052. } SDL_GPUVertexElementFormat;
  1053. /**
  1054. * Specifies the rate at which vertex attributes are pulled from buffers.
  1055. *
  1056. * \since This enum is available since SDL 3.2.0.
  1057. *
  1058. * \sa SDL_CreateGPUGraphicsPipeline
  1059. */
  1060. typedef enum SDL_GPUVertexInputRate
  1061. {
  1062. SDL_GPU_VERTEXINPUTRATE_VERTEX, /**< Attribute addressing is a function of the vertex index. */
  1063. SDL_GPU_VERTEXINPUTRATE_INSTANCE /**< Attribute addressing is a function of the instance index. */
  1064. } SDL_GPUVertexInputRate;
  1065. /**
  1066. * Specifies the fill mode of the graphics pipeline.
  1067. *
  1068. * \since This enum is available since SDL 3.2.0.
  1069. *
  1070. * \sa SDL_CreateGPUGraphicsPipeline
  1071. */
  1072. typedef enum SDL_GPUFillMode
  1073. {
  1074. SDL_GPU_FILLMODE_FILL, /**< Polygons will be rendered via rasterization. */
  1075. SDL_GPU_FILLMODE_LINE /**< Polygon edges will be drawn as line segments. */
  1076. } SDL_GPUFillMode;
  1077. /**
  1078. * Specifies the facing direction in which triangle faces will be culled.
  1079. *
  1080. * \since This enum is available since SDL 3.2.0.
  1081. *
  1082. * \sa SDL_CreateGPUGraphicsPipeline
  1083. */
  1084. typedef enum SDL_GPUCullMode
  1085. {
  1086. SDL_GPU_CULLMODE_NONE, /**< No triangles are culled. */
  1087. SDL_GPU_CULLMODE_FRONT, /**< Front-facing triangles are culled. */
  1088. SDL_GPU_CULLMODE_BACK /**< Back-facing triangles are culled. */
  1089. } SDL_GPUCullMode;
  1090. /**
  1091. * Specifies the vertex winding that will cause a triangle to be determined to
  1092. * be front-facing.
  1093. *
  1094. * \since This enum is available since SDL 3.2.0.
  1095. *
  1096. * \sa SDL_CreateGPUGraphicsPipeline
  1097. */
  1098. typedef enum SDL_GPUFrontFace
  1099. {
  1100. SDL_GPU_FRONTFACE_COUNTER_CLOCKWISE, /**< A triangle with counter-clockwise vertex winding will be considered front-facing. */
  1101. SDL_GPU_FRONTFACE_CLOCKWISE /**< A triangle with clockwise vertex winding will be considered front-facing. */
  1102. } SDL_GPUFrontFace;
  1103. /**
  1104. * Specifies a comparison operator for depth, stencil and sampler operations.
  1105. *
  1106. * \since This enum is available since SDL 3.2.0.
  1107. *
  1108. * \sa SDL_CreateGPUGraphicsPipeline
  1109. */
  1110. typedef enum SDL_GPUCompareOp
  1111. {
  1112. SDL_GPU_COMPAREOP_INVALID,
  1113. SDL_GPU_COMPAREOP_NEVER, /**< The comparison always evaluates false. */
  1114. SDL_GPU_COMPAREOP_LESS, /**< The comparison evaluates reference < test. */
  1115. SDL_GPU_COMPAREOP_EQUAL, /**< The comparison evaluates reference == test. */
  1116. SDL_GPU_COMPAREOP_LESS_OR_EQUAL, /**< The comparison evaluates reference <= test. */
  1117. SDL_GPU_COMPAREOP_GREATER, /**< The comparison evaluates reference > test. */
  1118. SDL_GPU_COMPAREOP_NOT_EQUAL, /**< The comparison evaluates reference != test. */
  1119. SDL_GPU_COMPAREOP_GREATER_OR_EQUAL, /**< The comparison evaluates reference >= test. */
  1120. SDL_GPU_COMPAREOP_ALWAYS /**< The comparison always evaluates true. */
  1121. } SDL_GPUCompareOp;
  1122. /**
  1123. * Specifies what happens to a stored stencil value if stencil tests fail or
  1124. * pass.
  1125. *
  1126. * \since This enum is available since SDL 3.2.0.
  1127. *
  1128. * \sa SDL_CreateGPUGraphicsPipeline
  1129. */
  1130. typedef enum SDL_GPUStencilOp
  1131. {
  1132. SDL_GPU_STENCILOP_INVALID,
  1133. SDL_GPU_STENCILOP_KEEP, /**< Keeps the current value. */
  1134. SDL_GPU_STENCILOP_ZERO, /**< Sets the value to 0. */
  1135. SDL_GPU_STENCILOP_REPLACE, /**< Sets the value to reference. */
  1136. SDL_GPU_STENCILOP_INCREMENT_AND_CLAMP, /**< Increments the current value and clamps to the maximum value. */
  1137. SDL_GPU_STENCILOP_DECREMENT_AND_CLAMP, /**< Decrements the current value and clamps to 0. */
  1138. SDL_GPU_STENCILOP_INVERT, /**< Bitwise-inverts the current value. */
  1139. SDL_GPU_STENCILOP_INCREMENT_AND_WRAP, /**< Increments the current value and wraps back to 0. */
  1140. SDL_GPU_STENCILOP_DECREMENT_AND_WRAP /**< Decrements the current value and wraps to the maximum value. */
  1141. } SDL_GPUStencilOp;
  1142. /**
  1143. * Specifies the operator to be used when pixels in a render target are
  1144. * blended with existing pixels in the texture.
  1145. *
  1146. * The source color is the value written by the fragment shader. The
  1147. * destination color is the value currently existing in the texture.
  1148. *
  1149. * \since This enum is available since SDL 3.2.0.
  1150. *
  1151. * \sa SDL_CreateGPUGraphicsPipeline
  1152. */
  1153. typedef enum SDL_GPUBlendOp
  1154. {
  1155. SDL_GPU_BLENDOP_INVALID,
  1156. SDL_GPU_BLENDOP_ADD, /**< (source * source_factor) + (destination * destination_factor) */
  1157. SDL_GPU_BLENDOP_SUBTRACT, /**< (source * source_factor) - (destination * destination_factor) */
  1158. SDL_GPU_BLENDOP_REVERSE_SUBTRACT, /**< (destination * destination_factor) - (source * source_factor) */
  1159. SDL_GPU_BLENDOP_MIN, /**< min(source, destination) */
  1160. SDL_GPU_BLENDOP_MAX /**< max(source, destination) */
  1161. } SDL_GPUBlendOp;
  1162. /**
  1163. * Specifies a blending factor to be used when pixels in a render target are
  1164. * blended with existing pixels in the texture.
  1165. *
  1166. * The source color is the value written by the fragment shader. The
  1167. * destination color is the value currently existing in the texture.
  1168. *
  1169. * \since This enum is available since SDL 3.2.0.
  1170. *
  1171. * \sa SDL_CreateGPUGraphicsPipeline
  1172. */
  1173. typedef enum SDL_GPUBlendFactor
  1174. {
  1175. SDL_GPU_BLENDFACTOR_INVALID,
  1176. SDL_GPU_BLENDFACTOR_ZERO, /**< 0 */
  1177. SDL_GPU_BLENDFACTOR_ONE, /**< 1 */
  1178. SDL_GPU_BLENDFACTOR_SRC_COLOR, /**< source color */
  1179. SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_COLOR, /**< 1 - source color */
  1180. SDL_GPU_BLENDFACTOR_DST_COLOR, /**< destination color */
  1181. SDL_GPU_BLENDFACTOR_ONE_MINUS_DST_COLOR, /**< 1 - destination color */
  1182. SDL_GPU_BLENDFACTOR_SRC_ALPHA, /**< source alpha */
  1183. SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, /**< 1 - source alpha */
  1184. SDL_GPU_BLENDFACTOR_DST_ALPHA, /**< destination alpha */
  1185. SDL_GPU_BLENDFACTOR_ONE_MINUS_DST_ALPHA, /**< 1 - destination alpha */
  1186. SDL_GPU_BLENDFACTOR_CONSTANT_COLOR, /**< blend constant */
  1187. SDL_GPU_BLENDFACTOR_ONE_MINUS_CONSTANT_COLOR, /**< 1 - blend constant */
  1188. SDL_GPU_BLENDFACTOR_SRC_ALPHA_SATURATE /**< min(source alpha, 1 - destination alpha) */
  1189. } SDL_GPUBlendFactor;
  1190. /**
  1191. * Specifies which color components are written in a graphics pipeline.
  1192. *
  1193. * \since This datatype is available since SDL 3.2.0.
  1194. *
  1195. * \sa SDL_CreateGPUGraphicsPipeline
  1196. */
  1197. typedef Uint8 SDL_GPUColorComponentFlags;
  1198. #define SDL_GPU_COLORCOMPONENT_R (1u << 0) /**< the red component */
  1199. #define SDL_GPU_COLORCOMPONENT_G (1u << 1) /**< the green component */
  1200. #define SDL_GPU_COLORCOMPONENT_B (1u << 2) /**< the blue component */
  1201. #define SDL_GPU_COLORCOMPONENT_A (1u << 3) /**< the alpha component */
  1202. /**
  1203. * Specifies a filter operation used by a sampler.
  1204. *
  1205. * \since This enum is available since SDL 3.2.0.
  1206. *
  1207. * \sa SDL_CreateGPUSampler
  1208. */
  1209. typedef enum SDL_GPUFilter
  1210. {
  1211. SDL_GPU_FILTER_NEAREST, /**< Point filtering. */
  1212. SDL_GPU_FILTER_LINEAR /**< Linear filtering. */
  1213. } SDL_GPUFilter;
  1214. /**
  1215. * Specifies a mipmap mode used by a sampler.
  1216. *
  1217. * \since This enum is available since SDL 3.2.0.
  1218. *
  1219. * \sa SDL_CreateGPUSampler
  1220. */
  1221. typedef enum SDL_GPUSamplerMipmapMode
  1222. {
  1223. SDL_GPU_SAMPLERMIPMAPMODE_NEAREST, /**< Point filtering. */
  1224. SDL_GPU_SAMPLERMIPMAPMODE_LINEAR /**< Linear filtering. */
  1225. } SDL_GPUSamplerMipmapMode;
  1226. /**
  1227. * Specifies behavior of texture sampling when the coordinates exceed the 0-1
  1228. * range.
  1229. *
  1230. * \since This enum is available since SDL 3.2.0.
  1231. *
  1232. * \sa SDL_CreateGPUSampler
  1233. */
  1234. typedef enum SDL_GPUSamplerAddressMode
  1235. {
  1236. SDL_GPU_SAMPLERADDRESSMODE_REPEAT, /**< Specifies that the coordinates will wrap around. */
  1237. SDL_GPU_SAMPLERADDRESSMODE_MIRRORED_REPEAT, /**< Specifies that the coordinates will wrap around mirrored. */
  1238. SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE /**< Specifies that the coordinates will clamp to the 0-1 range. */
  1239. } SDL_GPUSamplerAddressMode;
  1240. /**
  1241. * Specifies the timing that will be used to present swapchain textures to the
  1242. * OS.
  1243. *
  1244. * VSYNC mode will always be supported. IMMEDIATE and MAILBOX modes may not be
  1245. * supported on certain systems.
  1246. *
  1247. * It is recommended to query SDL_WindowSupportsGPUPresentMode after claiming
  1248. * the window if you wish to change the present mode to IMMEDIATE or MAILBOX.
  1249. *
  1250. * - VSYNC: Waits for vblank before presenting. No tearing is possible. If
  1251. * there is a pending image to present, the new image is enqueued for
  1252. * presentation. Disallows tearing at the cost of visual latency.
  1253. * - IMMEDIATE: Immediately presents. Lowest latency option, but tearing may
  1254. * occur.
  1255. * - MAILBOX: Waits for vblank before presenting. No tearing is possible. If
  1256. * there is a pending image to present, the pending image is replaced by the
  1257. * new image. Similar to VSYNC, but with reduced visual latency.
  1258. *
  1259. * \since This enum is available since SDL 3.2.0.
  1260. *
  1261. * \sa SDL_SetGPUSwapchainParameters
  1262. * \sa SDL_WindowSupportsGPUPresentMode
  1263. * \sa SDL_WaitAndAcquireGPUSwapchainTexture
  1264. */
  1265. typedef enum SDL_GPUPresentMode
  1266. {
  1267. SDL_GPU_PRESENTMODE_VSYNC,
  1268. SDL_GPU_PRESENTMODE_IMMEDIATE,
  1269. SDL_GPU_PRESENTMODE_MAILBOX
  1270. } SDL_GPUPresentMode;
  1271. /**
  1272. * Specifies the texture format and colorspace of the swapchain textures.
  1273. *
  1274. * SDR will always be supported. Other compositions may not be supported on
  1275. * certain systems.
  1276. *
  1277. * It is recommended to query SDL_WindowSupportsGPUSwapchainComposition after
  1278. * claiming the window if you wish to change the swapchain composition from
  1279. * SDR.
  1280. *
  1281. * - SDR: B8G8R8A8 or R8G8B8A8 swapchain. Pixel values are in sRGB encoding.
  1282. * - SDR_LINEAR: B8G8R8A8_SRGB or R8G8B8A8_SRGB swapchain. Pixel values are
  1283. * stored in memory in sRGB encoding but accessed in shaders in "linear
  1284. * sRGB" encoding which is sRGB but with a linear transfer function.
  1285. * - HDR_EXTENDED_LINEAR: R16G16B16A16_FLOAT swapchain. Pixel values are in
  1286. * extended linear sRGB encoding and permits values outside of the [0, 1]
  1287. * range.
  1288. * - HDR10_ST2084: A2R10G10B10 or A2B10G10R10 swapchain. Pixel values are in
  1289. * BT.2020 ST2084 (PQ) encoding.
  1290. *
  1291. * \since This enum is available since SDL 3.2.0.
  1292. *
  1293. * \sa SDL_SetGPUSwapchainParameters
  1294. * \sa SDL_WindowSupportsGPUSwapchainComposition
  1295. * \sa SDL_WaitAndAcquireGPUSwapchainTexture
  1296. */
  1297. typedef enum SDL_GPUSwapchainComposition
  1298. {
  1299. SDL_GPU_SWAPCHAINCOMPOSITION_SDR,
  1300. SDL_GPU_SWAPCHAINCOMPOSITION_SDR_LINEAR,
  1301. SDL_GPU_SWAPCHAINCOMPOSITION_HDR_EXTENDED_LINEAR,
  1302. SDL_GPU_SWAPCHAINCOMPOSITION_HDR10_ST2084
  1303. } SDL_GPUSwapchainComposition;
  1304. /* Structures */
  1305. /**
  1306. * A structure specifying a viewport.
  1307. *
  1308. * \since This struct is available since SDL 3.2.0.
  1309. *
  1310. * \sa SDL_SetGPUViewport
  1311. */
  1312. typedef struct SDL_GPUViewport
  1313. {
  1314. float x; /**< The left offset of the viewport. */
  1315. float y; /**< The top offset of the viewport. */
  1316. float w; /**< The width of the viewport. */
  1317. float h; /**< The height of the viewport. */
  1318. float min_depth; /**< The minimum depth of the viewport. */
  1319. float max_depth; /**< The maximum depth of the viewport. */
  1320. } SDL_GPUViewport;
  1321. /**
  1322. * A structure specifying parameters related to transferring data to or from a
  1323. * texture.
  1324. *
  1325. * If either of `pixels_per_row` or `rows_per_layer` is zero, then width and
  1326. * height of passed SDL_GPUTextureRegion to SDL_UploadToGPUTexture or
  1327. * SDL_DownloadFromGPUTexture are used as default values respectively and data
  1328. * is considered to be tightly packed.
  1329. *
  1330. * **WARNING**: Direct3D 12 requires texture data row pitch to be 256 byte
  1331. * aligned, and offsets to be aligned to 512 bytes. If they are not, SDL will
  1332. * make a temporary copy of the data that is properly aligned, but this adds
  1333. * overhead to the transfer process. Apps can avoid this by aligning their
  1334. * data appropriately, or using a different GPU backend than Direct3D 12.
  1335. *
  1336. * \since This struct is available since SDL 3.2.0.
  1337. *
  1338. * \sa SDL_UploadToGPUTexture
  1339. * \sa SDL_DownloadFromGPUTexture
  1340. */
  1341. typedef struct SDL_GPUTextureTransferInfo
  1342. {
  1343. SDL_GPUTransferBuffer *transfer_buffer; /**< The transfer buffer used in the transfer operation. */
  1344. Uint32 offset; /**< The starting byte of the image data in the transfer buffer. */
  1345. Uint32 pixels_per_row; /**< The number of pixels from one row to the next. */
  1346. Uint32 rows_per_layer; /**< The number of rows from one layer/depth-slice to the next. */
  1347. } SDL_GPUTextureTransferInfo;
  1348. /**
  1349. * A structure specifying a location in a transfer buffer.
  1350. *
  1351. * Used when transferring buffer data to or from a transfer buffer.
  1352. *
  1353. * \since This struct is available since SDL 3.2.0.
  1354. *
  1355. * \sa SDL_UploadToGPUBuffer
  1356. * \sa SDL_DownloadFromGPUBuffer
  1357. */
  1358. typedef struct SDL_GPUTransferBufferLocation
  1359. {
  1360. SDL_GPUTransferBuffer *transfer_buffer; /**< The transfer buffer used in the transfer operation. */
  1361. Uint32 offset; /**< The starting byte of the buffer data in the transfer buffer. */
  1362. } SDL_GPUTransferBufferLocation;
  1363. /**
  1364. * A structure specifying a location in a texture.
  1365. *
  1366. * Used when copying data from one texture to another.
  1367. *
  1368. * \since This struct is available since SDL 3.2.0.
  1369. *
  1370. * \sa SDL_CopyGPUTextureToTexture
  1371. */
  1372. typedef struct SDL_GPUTextureLocation
  1373. {
  1374. SDL_GPUTexture *texture; /**< The texture used in the copy operation. */
  1375. Uint32 mip_level; /**< The mip level index of the location. */
  1376. Uint32 layer; /**< The layer index of the location. */
  1377. Uint32 x; /**< The left offset of the location. */
  1378. Uint32 y; /**< The top offset of the location. */
  1379. Uint32 z; /**< The front offset of the location. */
  1380. } SDL_GPUTextureLocation;
  1381. /**
  1382. * A structure specifying a region of a texture.
  1383. *
  1384. * Used when transferring data to or from a texture.
  1385. *
  1386. * \since This struct is available since SDL 3.2.0.
  1387. *
  1388. * \sa SDL_UploadToGPUTexture
  1389. * \sa SDL_DownloadFromGPUTexture
  1390. * \sa SDL_CreateGPUTexture
  1391. */
  1392. typedef struct SDL_GPUTextureRegion
  1393. {
  1394. SDL_GPUTexture *texture; /**< The texture used in the copy operation. */
  1395. Uint32 mip_level; /**< The mip level index to transfer. */
  1396. Uint32 layer; /**< The layer index to transfer. */
  1397. Uint32 x; /**< The left offset of the region. */
  1398. Uint32 y; /**< The top offset of the region. */
  1399. Uint32 z; /**< The front offset of the region. */
  1400. Uint32 w; /**< The width of the region. */
  1401. Uint32 h; /**< The height of the region. */
  1402. Uint32 d; /**< The depth of the region. */
  1403. } SDL_GPUTextureRegion;
  1404. /**
  1405. * A structure specifying a region of a texture used in the blit operation.
  1406. *
  1407. * \since This struct is available since SDL 3.2.0.
  1408. *
  1409. * \sa SDL_BlitGPUTexture
  1410. */
  1411. typedef struct SDL_GPUBlitRegion
  1412. {
  1413. SDL_GPUTexture *texture; /**< The texture. */
  1414. Uint32 mip_level; /**< The mip level index of the region. */
  1415. Uint32 layer_or_depth_plane; /**< The layer index or depth plane of the region. This value is treated as a layer index on 2D array and cube textures, and as a depth plane on 3D textures. */
  1416. Uint32 x; /**< The left offset of the region. */
  1417. Uint32 y; /**< The top offset of the region. */
  1418. Uint32 w; /**< The width of the region. */
  1419. Uint32 h; /**< The height of the region. */
  1420. } SDL_GPUBlitRegion;
  1421. /**
  1422. * A structure specifying a location in a buffer.
  1423. *
  1424. * Used when copying data between buffers.
  1425. *
  1426. * \since This struct is available since SDL 3.2.0.
  1427. *
  1428. * \sa SDL_CopyGPUBufferToBuffer
  1429. */
  1430. typedef struct SDL_GPUBufferLocation
  1431. {
  1432. SDL_GPUBuffer *buffer; /**< The buffer. */
  1433. Uint32 offset; /**< The starting byte within the buffer. */
  1434. } SDL_GPUBufferLocation;
  1435. /**
  1436. * A structure specifying a region of a buffer.
  1437. *
  1438. * Used when transferring data to or from buffers.
  1439. *
  1440. * \since This struct is available since SDL 3.2.0.
  1441. *
  1442. * \sa SDL_UploadToGPUBuffer
  1443. * \sa SDL_DownloadFromGPUBuffer
  1444. */
  1445. typedef struct SDL_GPUBufferRegion
  1446. {
  1447. SDL_GPUBuffer *buffer; /**< The buffer. */
  1448. Uint32 offset; /**< The starting byte within the buffer. */
  1449. Uint32 size; /**< The size in bytes of the region. */
  1450. } SDL_GPUBufferRegion;
  1451. /**
  1452. * A structure specifying the parameters of an indirect draw command.
  1453. *
  1454. * Note that the `first_vertex` and `first_instance` parameters are NOT
  1455. * compatible with built-in vertex/instance ID variables in shaders (for
  1456. * example, SV_VertexID); GPU APIs and shader languages do not define these
  1457. * built-in variables consistently, so if your shader depends on them, the
  1458. * only way to keep behavior consistent and portable is to always pass 0 for
  1459. * the correlating parameter in the draw calls.
  1460. *
  1461. * \since This struct is available since SDL 3.2.0.
  1462. *
  1463. * \sa SDL_DrawGPUPrimitivesIndirect
  1464. */
  1465. typedef struct SDL_GPUIndirectDrawCommand
  1466. {
  1467. Uint32 num_vertices; /**< The number of vertices to draw. */
  1468. Uint32 num_instances; /**< The number of instances to draw. */
  1469. Uint32 first_vertex; /**< The index of the first vertex to draw. */
  1470. Uint32 first_instance; /**< The ID of the first instance to draw. */
  1471. } SDL_GPUIndirectDrawCommand;
  1472. /**
  1473. * A structure specifying the parameters of an indexed indirect draw command.
  1474. *
  1475. * Note that the `first_vertex` and `first_instance` parameters are NOT
  1476. * compatible with built-in vertex/instance ID variables in shaders (for
  1477. * example, SV_VertexID); GPU APIs and shader languages do not define these
  1478. * built-in variables consistently, so if your shader depends on them, the
  1479. * only way to keep behavior consistent and portable is to always pass 0 for
  1480. * the correlating parameter in the draw calls.
  1481. *
  1482. * \since This struct is available since SDL 3.2.0.
  1483. *
  1484. * \sa SDL_DrawGPUIndexedPrimitivesIndirect
  1485. */
  1486. typedef struct SDL_GPUIndexedIndirectDrawCommand
  1487. {
  1488. Uint32 num_indices; /**< The number of indices to draw per instance. */
  1489. Uint32 num_instances; /**< The number of instances to draw. */
  1490. Uint32 first_index; /**< The base index within the index buffer. */
  1491. Sint32 vertex_offset; /**< The value added to the vertex index before indexing into the vertex buffer. */
  1492. Uint32 first_instance; /**< The ID of the first instance to draw. */
  1493. } SDL_GPUIndexedIndirectDrawCommand;
  1494. /**
  1495. * A structure specifying the parameters of an indexed dispatch command.
  1496. *
  1497. * \since This struct is available since SDL 3.2.0.
  1498. *
  1499. * \sa SDL_DispatchGPUComputeIndirect
  1500. */
  1501. typedef struct SDL_GPUIndirectDispatchCommand
  1502. {
  1503. Uint32 groupcount_x; /**< The number of local workgroups to dispatch in the X dimension. */
  1504. Uint32 groupcount_y; /**< The number of local workgroups to dispatch in the Y dimension. */
  1505. Uint32 groupcount_z; /**< The number of local workgroups to dispatch in the Z dimension. */
  1506. } SDL_GPUIndirectDispatchCommand;
  1507. /* State structures */
  1508. /**
  1509. * A structure specifying the parameters of a sampler.
  1510. *
  1511. * Note that mip_lod_bias is a no-op for the Metal driver. For Metal, LOD bias
  1512. * must be applied via shader instead.
  1513. *
  1514. * \since This function is available since SDL 3.2.0.
  1515. *
  1516. * \sa SDL_CreateGPUSampler
  1517. * \sa SDL_GPUFilter
  1518. * \sa SDL_GPUSamplerMipmapMode
  1519. * \sa SDL_GPUSamplerAddressMode
  1520. * \sa SDL_GPUCompareOp
  1521. */
  1522. typedef struct SDL_GPUSamplerCreateInfo
  1523. {
  1524. SDL_GPUFilter min_filter; /**< The minification filter to apply to lookups. */
  1525. SDL_GPUFilter mag_filter; /**< The magnification filter to apply to lookups. */
  1526. SDL_GPUSamplerMipmapMode mipmap_mode; /**< The mipmap filter to apply to lookups. */
  1527. SDL_GPUSamplerAddressMode address_mode_u; /**< The addressing mode for U coordinates outside [0, 1). */
  1528. SDL_GPUSamplerAddressMode address_mode_v; /**< The addressing mode for V coordinates outside [0, 1). */
  1529. SDL_GPUSamplerAddressMode address_mode_w; /**< The addressing mode for W coordinates outside [0, 1). */
  1530. float mip_lod_bias; /**< The bias to be added to mipmap LOD calculation. */
  1531. float max_anisotropy; /**< The anisotropy value clamp used by the sampler. If enable_anisotropy is false, this is ignored. */
  1532. SDL_GPUCompareOp compare_op; /**< The comparison operator to apply to fetched data before filtering. */
  1533. float min_lod; /**< Clamps the minimum of the computed LOD value. */
  1534. float max_lod; /**< Clamps the maximum of the computed LOD value. */
  1535. bool enable_anisotropy; /**< true to enable anisotropic filtering. */
  1536. bool enable_compare; /**< true to enable comparison against a reference value during lookups. */
  1537. Uint8 padding1;
  1538. Uint8 padding2;
  1539. SDL_PropertiesID props; /**< A properties ID for extensions. Should be 0 if no extensions are needed. */
  1540. } SDL_GPUSamplerCreateInfo;
  1541. /**
  1542. * A structure specifying the parameters of vertex buffers used in a graphics
  1543. * pipeline.
  1544. *
  1545. * When you call SDL_BindGPUVertexBuffers, you specify the binding slots of
  1546. * the vertex buffers. For example if you called SDL_BindGPUVertexBuffers with
  1547. * a first_slot of 2 and num_bindings of 3, the binding slots 2, 3, 4 would be
  1548. * used by the vertex buffers you pass in.
  1549. *
  1550. * Vertex attributes are linked to buffers via the buffer_slot field of
  1551. * SDL_GPUVertexAttribute. For example, if an attribute has a buffer_slot of
  1552. * 0, then that attribute belongs to the vertex buffer bound at slot 0.
  1553. *
  1554. * \since This struct is available since SDL 3.2.0.
  1555. *
  1556. * \sa SDL_GPUVertexAttribute
  1557. * \sa SDL_GPUVertexInputRate
  1558. */
  1559. typedef struct SDL_GPUVertexBufferDescription
  1560. {
  1561. Uint32 slot; /**< The binding slot of the vertex buffer. */
  1562. Uint32 pitch; /**< The size of a single element + the offset between elements. */
  1563. SDL_GPUVertexInputRate input_rate; /**< Whether attribute addressing is a function of the vertex index or instance index. */
  1564. Uint32 instance_step_rate; /**< Reserved for future use. Must be set to 0. */
  1565. } SDL_GPUVertexBufferDescription;
  1566. /**
  1567. * A structure specifying a vertex attribute.
  1568. *
  1569. * All vertex attribute locations provided to an SDL_GPUVertexInputState must
  1570. * be unique.
  1571. *
  1572. * \since This struct is available since SDL 3.2.0.
  1573. *
  1574. * \sa SDL_GPUVertexBufferDescription
  1575. * \sa SDL_GPUVertexInputState
  1576. * \sa SDL_GPUVertexElementFormat
  1577. */
  1578. typedef struct SDL_GPUVertexAttribute
  1579. {
  1580. Uint32 location; /**< The shader input location index. */
  1581. Uint32 buffer_slot; /**< The binding slot of the associated vertex buffer. */
  1582. SDL_GPUVertexElementFormat format; /**< The size and type of the attribute data. */
  1583. Uint32 offset; /**< The byte offset of this attribute relative to the start of the vertex element. */
  1584. } SDL_GPUVertexAttribute;
  1585. /**
  1586. * A structure specifying the parameters of a graphics pipeline vertex input
  1587. * state.
  1588. *
  1589. * \since This struct is available since SDL 3.2.0.
  1590. *
  1591. * \sa SDL_GPUGraphicsPipelineCreateInfo
  1592. * \sa SDL_GPUVertexBufferDescription
  1593. * \sa SDL_GPUVertexAttribute
  1594. */
  1595. typedef struct SDL_GPUVertexInputState
  1596. {
  1597. const SDL_GPUVertexBufferDescription *vertex_buffer_descriptions; /**< A pointer to an array of vertex buffer descriptions. */
  1598. Uint32 num_vertex_buffers; /**< The number of vertex buffer descriptions in the above array. */
  1599. const SDL_GPUVertexAttribute *vertex_attributes; /**< A pointer to an array of vertex attribute descriptions. */
  1600. Uint32 num_vertex_attributes; /**< The number of vertex attribute descriptions in the above array. */
  1601. } SDL_GPUVertexInputState;
  1602. /**
  1603. * A structure specifying the stencil operation state of a graphics pipeline.
  1604. *
  1605. * \since This struct is available since SDL 3.2.0.
  1606. *
  1607. * \sa SDL_GPUDepthStencilState
  1608. */
  1609. typedef struct SDL_GPUStencilOpState
  1610. {
  1611. SDL_GPUStencilOp fail_op; /**< The action performed on samples that fail the stencil test. */
  1612. SDL_GPUStencilOp pass_op; /**< The action performed on samples that pass the depth and stencil tests. */
  1613. SDL_GPUStencilOp depth_fail_op; /**< The action performed on samples that pass the stencil test and fail the depth test. */
  1614. SDL_GPUCompareOp compare_op; /**< The comparison operator used in the stencil test. */
  1615. } SDL_GPUStencilOpState;
  1616. /**
  1617. * A structure specifying the blend state of a color target.
  1618. *
  1619. * \since This struct is available since SDL 3.2.0.
  1620. *
  1621. * \sa SDL_GPUColorTargetDescription
  1622. * \sa SDL_GPUBlendFactor
  1623. * \sa SDL_GPUBlendOp
  1624. * \sa SDL_GPUColorComponentFlags
  1625. */
  1626. typedef struct SDL_GPUColorTargetBlendState
  1627. {
  1628. SDL_GPUBlendFactor src_color_blendfactor; /**< The value to be multiplied by the source RGB value. */
  1629. SDL_GPUBlendFactor dst_color_blendfactor; /**< The value to be multiplied by the destination RGB value. */
  1630. SDL_GPUBlendOp color_blend_op; /**< The blend operation for the RGB components. */
  1631. SDL_GPUBlendFactor src_alpha_blendfactor; /**< The value to be multiplied by the source alpha. */
  1632. SDL_GPUBlendFactor dst_alpha_blendfactor; /**< The value to be multiplied by the destination alpha. */
  1633. SDL_GPUBlendOp alpha_blend_op; /**< The blend operation for the alpha component. */
  1634. SDL_GPUColorComponentFlags color_write_mask; /**< A bitmask specifying which of the RGBA components are enabled for writing. Writes to all channels if enable_color_write_mask is false. */
  1635. bool enable_blend; /**< Whether blending is enabled for the color target. */
  1636. bool enable_color_write_mask; /**< Whether the color write mask is enabled. */
  1637. Uint8 padding1;
  1638. Uint8 padding2;
  1639. } SDL_GPUColorTargetBlendState;
  1640. /**
  1641. * A structure specifying code and metadata for creating a shader object.
  1642. *
  1643. * \since This struct is available since SDL 3.2.0.
  1644. *
  1645. * \sa SDL_CreateGPUShader
  1646. * \sa SDL_GPUShaderFormat
  1647. * \sa SDL_GPUShaderStage
  1648. */
  1649. typedef struct SDL_GPUShaderCreateInfo
  1650. {
  1651. size_t code_size; /**< The size in bytes of the code pointed to. */
  1652. const Uint8 *code; /**< A pointer to shader code. */
  1653. const char *entrypoint; /**< A pointer to a null-terminated UTF-8 string specifying the entry point function name for the shader. */
  1654. SDL_GPUShaderFormat format; /**< The format of the shader code. */
  1655. SDL_GPUShaderStage stage; /**< The stage the shader program corresponds to. */
  1656. Uint32 num_samplers; /**< The number of samplers defined in the shader. */
  1657. Uint32 num_storage_textures; /**< The number of storage textures defined in the shader. */
  1658. Uint32 num_storage_buffers; /**< The number of storage buffers defined in the shader. */
  1659. Uint32 num_uniform_buffers; /**< The number of uniform buffers defined in the shader. */
  1660. SDL_PropertiesID props; /**< A properties ID for extensions. Should be 0 if no extensions are needed. */
  1661. } SDL_GPUShaderCreateInfo;
  1662. /**
  1663. * A structure specifying the parameters of a texture.
  1664. *
  1665. * Usage flags can be bitwise OR'd together for combinations of usages. Note
  1666. * that certain usage combinations are invalid, for example SAMPLER and
  1667. * GRAPHICS_STORAGE.
  1668. *
  1669. * \since This struct is available since SDL 3.2.0.
  1670. *
  1671. * \sa SDL_CreateGPUTexture
  1672. * \sa SDL_GPUTextureType
  1673. * \sa SDL_GPUTextureFormat
  1674. * \sa SDL_GPUTextureUsageFlags
  1675. * \sa SDL_GPUSampleCount
  1676. */
  1677. typedef struct SDL_GPUTextureCreateInfo
  1678. {
  1679. SDL_GPUTextureType type; /**< The base dimensionality of the texture. */
  1680. SDL_GPUTextureFormat format; /**< The pixel format of the texture. */
  1681. SDL_GPUTextureUsageFlags usage; /**< How the texture is intended to be used by the client. */
  1682. Uint32 width; /**< The width of the texture. */
  1683. Uint32 height; /**< The height of the texture. */
  1684. Uint32 layer_count_or_depth; /**< The layer count or depth of the texture. This value is treated as a layer count on 2D array textures, and as a depth value on 3D textures. */
  1685. Uint32 num_levels; /**< The number of mip levels in the texture. */
  1686. SDL_GPUSampleCount sample_count; /**< The number of samples per texel. Only applies if the texture is used as a render target. */
  1687. SDL_PropertiesID props; /**< A properties ID for extensions. Should be 0 if no extensions are needed. */
  1688. } SDL_GPUTextureCreateInfo;
  1689. /**
  1690. * A structure specifying the parameters of a buffer.
  1691. *
  1692. * Usage flags can be bitwise OR'd together for combinations of usages. Note
  1693. * that certain combinations are invalid, for example VERTEX and INDEX.
  1694. *
  1695. * \since This struct is available since SDL 3.2.0.
  1696. *
  1697. * \sa SDL_CreateGPUBuffer
  1698. * \sa SDL_GPUBufferUsageFlags
  1699. */
  1700. typedef struct SDL_GPUBufferCreateInfo
  1701. {
  1702. SDL_GPUBufferUsageFlags usage; /**< How the buffer is intended to be used by the client. */
  1703. Uint32 size; /**< The size in bytes of the buffer. */
  1704. SDL_PropertiesID props; /**< A properties ID for extensions. Should be 0 if no extensions are needed. */
  1705. } SDL_GPUBufferCreateInfo;
  1706. /**
  1707. * A structure specifying the parameters of a transfer buffer.
  1708. *
  1709. * \since This struct is available since SDL 3.2.0.
  1710. *
  1711. * \sa SDL_CreateGPUTransferBuffer
  1712. */
  1713. typedef struct SDL_GPUTransferBufferCreateInfo
  1714. {
  1715. SDL_GPUTransferBufferUsage usage; /**< How the transfer buffer is intended to be used by the client. */
  1716. Uint32 size; /**< The size in bytes of the transfer buffer. */
  1717. SDL_PropertiesID props; /**< A properties ID for extensions. Should be 0 if no extensions are needed. */
  1718. } SDL_GPUTransferBufferCreateInfo;
  1719. /* Pipeline state structures */
  1720. /**
  1721. * A structure specifying the parameters of the graphics pipeline rasterizer
  1722. * state.
  1723. *
  1724. * Note that SDL_GPU_FILLMODE_LINE is not supported on many Android devices.
  1725. * For those devices, the fill mode will automatically fall back to FILL.
  1726. *
  1727. * Also note that the D3D12 driver will enable depth clamping even if
  1728. * enable_depth_clip is true. If you need this clamp+clip behavior, consider
  1729. * enabling depth clip and then manually clamping depth in your fragment
  1730. * shaders on Metal and Vulkan.
  1731. *
  1732. * \since This struct is available since SDL 3.2.0.
  1733. *
  1734. * \sa SDL_GPUGraphicsPipelineCreateInfo
  1735. */
  1736. typedef struct SDL_GPURasterizerState
  1737. {
  1738. SDL_GPUFillMode fill_mode; /**< Whether polygons will be filled in or drawn as lines. */
  1739. SDL_GPUCullMode cull_mode; /**< The facing direction in which triangles will be culled. */
  1740. SDL_GPUFrontFace front_face; /**< The vertex winding that will cause a triangle to be determined as front-facing. */
  1741. float depth_bias_constant_factor; /**< A scalar factor controlling the depth value added to each fragment. */
  1742. float depth_bias_clamp; /**< The maximum depth bias of a fragment. */
  1743. float depth_bias_slope_factor; /**< A scalar factor applied to a fragment's slope in depth calculations. */
  1744. bool enable_depth_bias; /**< true to bias fragment depth values. */
  1745. bool enable_depth_clip; /**< true to enable depth clip, false to enable depth clamp. */
  1746. Uint8 padding1;
  1747. Uint8 padding2;
  1748. } SDL_GPURasterizerState;
  1749. /**
  1750. * A structure specifying the parameters of the graphics pipeline multisample
  1751. * state.
  1752. *
  1753. * \since This struct is available since SDL 3.2.0.
  1754. *
  1755. * \sa SDL_GPUGraphicsPipelineCreateInfo
  1756. */
  1757. typedef struct SDL_GPUMultisampleState
  1758. {
  1759. SDL_GPUSampleCount sample_count; /**< The number of samples to be used in rasterization. */
  1760. Uint32 sample_mask; /**< Reserved for future use. Must be set to 0. */
  1761. bool enable_mask; /**< Reserved for future use. Must be set to false. */
  1762. bool enable_alpha_to_coverage; /**< true enables the alpha-to-coverage feature. */
  1763. Uint8 padding2;
  1764. Uint8 padding3;
  1765. } SDL_GPUMultisampleState;
  1766. /**
  1767. * A structure specifying the parameters of the graphics pipeline depth
  1768. * stencil state.
  1769. *
  1770. * \since This struct is available since SDL 3.2.0.
  1771. *
  1772. * \sa SDL_GPUGraphicsPipelineCreateInfo
  1773. */
  1774. typedef struct SDL_GPUDepthStencilState
  1775. {
  1776. SDL_GPUCompareOp compare_op; /**< The comparison operator used for depth testing. */
  1777. SDL_GPUStencilOpState back_stencil_state; /**< The stencil op state for back-facing triangles. */
  1778. SDL_GPUStencilOpState front_stencil_state; /**< The stencil op state for front-facing triangles. */
  1779. Uint8 compare_mask; /**< Selects the bits of the stencil values participating in the stencil test. */
  1780. Uint8 write_mask; /**< Selects the bits of the stencil values updated by the stencil test. */
  1781. bool enable_depth_test; /**< true enables the depth test. */
  1782. bool enable_depth_write; /**< true enables depth writes. Depth writes are always disabled when enable_depth_test is false. */
  1783. bool enable_stencil_test; /**< true enables the stencil test. */
  1784. Uint8 padding1;
  1785. Uint8 padding2;
  1786. Uint8 padding3;
  1787. } SDL_GPUDepthStencilState;
  1788. /**
  1789. * A structure specifying the parameters of color targets used in a graphics
  1790. * pipeline.
  1791. *
  1792. * \since This struct is available since SDL 3.2.0.
  1793. *
  1794. * \sa SDL_GPUGraphicsPipelineTargetInfo
  1795. */
  1796. typedef struct SDL_GPUColorTargetDescription
  1797. {
  1798. SDL_GPUTextureFormat format; /**< The pixel format of the texture to be used as a color target. */
  1799. SDL_GPUColorTargetBlendState blend_state; /**< The blend state to be used for the color target. */
  1800. } SDL_GPUColorTargetDescription;
  1801. /**
  1802. * A structure specifying the descriptions of render targets used in a
  1803. * graphics pipeline.
  1804. *
  1805. * \since This struct is available since SDL 3.2.0.
  1806. *
  1807. * \sa SDL_GPUGraphicsPipelineCreateInfo
  1808. * \sa SDL_GPUColorTargetDescription
  1809. * \sa SDL_GPUTextureFormat
  1810. */
  1811. typedef struct SDL_GPUGraphicsPipelineTargetInfo
  1812. {
  1813. const SDL_GPUColorTargetDescription *color_target_descriptions; /**< A pointer to an array of color target descriptions. */
  1814. Uint32 num_color_targets; /**< The number of color target descriptions in the above array. */
  1815. SDL_GPUTextureFormat depth_stencil_format; /**< The pixel format of the depth-stencil target. Ignored if has_depth_stencil_target is false. */
  1816. bool has_depth_stencil_target; /**< true specifies that the pipeline uses a depth-stencil target. */
  1817. Uint8 padding1;
  1818. Uint8 padding2;
  1819. Uint8 padding3;
  1820. } SDL_GPUGraphicsPipelineTargetInfo;
  1821. /**
  1822. * A structure specifying the parameters of a graphics pipeline state.
  1823. *
  1824. * \since This struct is available since SDL 3.2.0.
  1825. *
  1826. * \sa SDL_CreateGPUGraphicsPipeline
  1827. * \sa SDL_GPUShader
  1828. * \sa SDL_GPUVertexInputState
  1829. * \sa SDL_GPUPrimitiveType
  1830. * \sa SDL_GPURasterizerState
  1831. * \sa SDL_GPUMultisampleState
  1832. * \sa SDL_GPUDepthStencilState
  1833. * \sa SDL_GPUGraphicsPipelineTargetInfo
  1834. */
  1835. typedef struct SDL_GPUGraphicsPipelineCreateInfo
  1836. {
  1837. SDL_GPUShader *vertex_shader; /**< The vertex shader used by the graphics pipeline. */
  1838. SDL_GPUShader *fragment_shader; /**< The fragment shader used by the graphics pipeline. */
  1839. SDL_GPUVertexInputState vertex_input_state; /**< The vertex layout of the graphics pipeline. */
  1840. SDL_GPUPrimitiveType primitive_type; /**< The primitive topology of the graphics pipeline. */
  1841. SDL_GPURasterizerState rasterizer_state; /**< The rasterizer state of the graphics pipeline. */
  1842. SDL_GPUMultisampleState multisample_state; /**< The multisample state of the graphics pipeline. */
  1843. SDL_GPUDepthStencilState depth_stencil_state; /**< The depth-stencil state of the graphics pipeline. */
  1844. SDL_GPUGraphicsPipelineTargetInfo target_info; /**< Formats and blend modes for the render targets of the graphics pipeline. */
  1845. SDL_PropertiesID props; /**< A properties ID for extensions. Should be 0 if no extensions are needed. */
  1846. } SDL_GPUGraphicsPipelineCreateInfo;
  1847. /**
  1848. * A structure specifying the parameters of a compute pipeline state.
  1849. *
  1850. * \since This struct is available since SDL 3.2.0.
  1851. *
  1852. * \sa SDL_CreateGPUComputePipeline
  1853. * \sa SDL_GPUShaderFormat
  1854. */
  1855. typedef struct SDL_GPUComputePipelineCreateInfo
  1856. {
  1857. size_t code_size; /**< The size in bytes of the compute shader code pointed to. */
  1858. const Uint8 *code; /**< A pointer to compute shader code. */
  1859. const char *entrypoint; /**< A pointer to a null-terminated UTF-8 string specifying the entry point function name for the shader. */
  1860. SDL_GPUShaderFormat format; /**< The format of the compute shader code. */
  1861. Uint32 num_samplers; /**< The number of samplers defined in the shader. */
  1862. Uint32 num_readonly_storage_textures; /**< The number of readonly storage textures defined in the shader. */
  1863. Uint32 num_readonly_storage_buffers; /**< The number of readonly storage buffers defined in the shader. */
  1864. Uint32 num_readwrite_storage_textures; /**< The number of read-write storage textures defined in the shader. */
  1865. Uint32 num_readwrite_storage_buffers; /**< The number of read-write storage buffers defined in the shader. */
  1866. Uint32 num_uniform_buffers; /**< The number of uniform buffers defined in the shader. */
  1867. Uint32 threadcount_x; /**< The number of threads in the X dimension. This should match the value in the shader. */
  1868. Uint32 threadcount_y; /**< The number of threads in the Y dimension. This should match the value in the shader. */
  1869. Uint32 threadcount_z; /**< The number of threads in the Z dimension. This should match the value in the shader. */
  1870. SDL_PropertiesID props; /**< A properties ID for extensions. Should be 0 if no extensions are needed. */
  1871. } SDL_GPUComputePipelineCreateInfo;
  1872. /**
  1873. * A structure specifying the parameters of a color target used by a render
  1874. * pass.
  1875. *
  1876. * The load_op field determines what is done with the texture at the beginning
  1877. * of the render pass.
  1878. *
  1879. * - LOAD: Loads the data currently in the texture. Not recommended for
  1880. * multisample textures as it requires significant memory bandwidth.
  1881. * - CLEAR: Clears the texture to a single color.
  1882. * - DONT_CARE: The driver will do whatever it wants with the texture memory.
  1883. * This is a good option if you know that every single pixel will be touched
  1884. * in the render pass.
  1885. *
  1886. * The store_op field determines what is done with the color results of the
  1887. * render pass.
  1888. *
  1889. * - STORE: Stores the results of the render pass in the texture. Not
  1890. * recommended for multisample textures as it requires significant memory
  1891. * bandwidth.
  1892. * - DONT_CARE: The driver will do whatever it wants with the texture memory.
  1893. * This is often a good option for depth/stencil textures.
  1894. * - RESOLVE: Resolves a multisample texture into resolve_texture, which must
  1895. * have a sample count of 1. Then the driver may discard the multisample
  1896. * texture memory. This is the most performant method of resolving a
  1897. * multisample target.
  1898. * - RESOLVE_AND_STORE: Resolves a multisample texture into the
  1899. * resolve_texture, which must have a sample count of 1. Then the driver
  1900. * stores the multisample texture's contents. Not recommended as it requires
  1901. * significant memory bandwidth.
  1902. *
  1903. * \since This struct is available since SDL 3.2.0.
  1904. *
  1905. * \sa SDL_BeginGPURenderPass
  1906. * \sa SDL_FColor
  1907. */
  1908. typedef struct SDL_GPUColorTargetInfo
  1909. {
  1910. SDL_GPUTexture *texture; /**< The texture that will be used as a color target by a render pass. */
  1911. Uint32 mip_level; /**< The mip level to use as a color target. */
  1912. Uint32 layer_or_depth_plane; /**< The layer index or depth plane to use as a color target. This value is treated as a layer index on 2D array and cube textures, and as a depth plane on 3D textures. */
  1913. SDL_FColor clear_color; /**< The color to clear the color target to at the start of the render pass. Ignored if SDL_GPU_LOADOP_CLEAR is not used. */
  1914. SDL_GPULoadOp load_op; /**< What is done with the contents of the color target at the beginning of the render pass. */
  1915. SDL_GPUStoreOp store_op; /**< What is done with the results of the render pass. */
  1916. SDL_GPUTexture *resolve_texture; /**< The texture that will receive the results of a multisample resolve operation. Ignored if a RESOLVE* store_op is not used. */
  1917. Uint32 resolve_mip_level; /**< The mip level of the resolve texture to use for the resolve operation. Ignored if a RESOLVE* store_op is not used. */
  1918. Uint32 resolve_layer; /**< The layer index of the resolve texture to use for the resolve operation. Ignored if a RESOLVE* store_op is not used. */
  1919. bool cycle; /**< true cycles the texture if the texture is bound and load_op is not LOAD */
  1920. bool cycle_resolve_texture; /**< true cycles the resolve texture if the resolve texture is bound. Ignored if a RESOLVE* store_op is not used. */
  1921. Uint8 padding1;
  1922. Uint8 padding2;
  1923. } SDL_GPUColorTargetInfo;
  1924. /**
  1925. * A structure specifying the parameters of a depth-stencil target used by a
  1926. * render pass.
  1927. *
  1928. * The load_op field determines what is done with the depth contents of the
  1929. * texture at the beginning of the render pass.
  1930. *
  1931. * - LOAD: Loads the depth values currently in the texture.
  1932. * - CLEAR: Clears the texture to a single depth.
  1933. * - DONT_CARE: The driver will do whatever it wants with the memory. This is
  1934. * a good option if you know that every single pixel will be touched in the
  1935. * render pass.
  1936. *
  1937. * The store_op field determines what is done with the depth results of the
  1938. * render pass.
  1939. *
  1940. * - STORE: Stores the depth results in the texture.
  1941. * - DONT_CARE: The driver will do whatever it wants with the depth results.
  1942. * This is often a good option for depth/stencil textures that don't need to
  1943. * be reused again.
  1944. *
  1945. * The stencil_load_op field determines what is done with the stencil contents
  1946. * of the texture at the beginning of the render pass.
  1947. *
  1948. * - LOAD: Loads the stencil values currently in the texture.
  1949. * - CLEAR: Clears the stencil values to a single value.
  1950. * - DONT_CARE: The driver will do whatever it wants with the memory. This is
  1951. * a good option if you know that every single pixel will be touched in the
  1952. * render pass.
  1953. *
  1954. * The stencil_store_op field determines what is done with the stencil results
  1955. * of the render pass.
  1956. *
  1957. * - STORE: Stores the stencil results in the texture.
  1958. * - DONT_CARE: The driver will do whatever it wants with the stencil results.
  1959. * This is often a good option for depth/stencil textures that don't need to
  1960. * be reused again.
  1961. *
  1962. * Note that depth/stencil targets do not support multisample resolves.
  1963. *
  1964. * Due to ABI limitations, depth textures with more than 255 layers are not
  1965. * supported.
  1966. *
  1967. * \since This struct is available since SDL 3.2.0.
  1968. *
  1969. * \sa SDL_BeginGPURenderPass
  1970. */
  1971. typedef struct SDL_GPUDepthStencilTargetInfo
  1972. {
  1973. SDL_GPUTexture *texture; /**< The texture that will be used as the depth stencil target by the render pass. */
  1974. float clear_depth; /**< The value to clear the depth component to at the beginning of the render pass. Ignored if SDL_GPU_LOADOP_CLEAR is not used. */
  1975. SDL_GPULoadOp load_op; /**< What is done with the depth contents at the beginning of the render pass. */
  1976. SDL_GPUStoreOp store_op; /**< What is done with the depth results of the render pass. */
  1977. SDL_GPULoadOp stencil_load_op; /**< What is done with the stencil contents at the beginning of the render pass. */
  1978. SDL_GPUStoreOp stencil_store_op; /**< What is done with the stencil results of the render pass. */
  1979. bool cycle; /**< true cycles the texture if the texture is bound and any load ops are not LOAD */
  1980. Uint8 clear_stencil; /**< The value to clear the stencil component to at the beginning of the render pass. Ignored if SDL_GPU_LOADOP_CLEAR is not used. */
  1981. Uint8 mip_level; /**< The mip level to use as the depth stencil target. */
  1982. Uint8 layer; /**< The layer index to use as the depth stencil target. */
  1983. } SDL_GPUDepthStencilTargetInfo;
  1984. /**
  1985. * A structure containing parameters for a blit command.
  1986. *
  1987. * \since This struct is available since SDL 3.2.0.
  1988. *
  1989. * \sa SDL_BlitGPUTexture
  1990. */
  1991. typedef struct SDL_GPUBlitInfo {
  1992. SDL_GPUBlitRegion source; /**< The source region for the blit. */
  1993. SDL_GPUBlitRegion destination; /**< The destination region for the blit. */
  1994. SDL_GPULoadOp load_op; /**< What is done with the contents of the destination before the blit. */
  1995. SDL_FColor clear_color; /**< The color to clear the destination region to before the blit. Ignored if load_op is not SDL_GPU_LOADOP_CLEAR. */
  1996. SDL_FlipMode flip_mode; /**< The flip mode for the source region. */
  1997. SDL_GPUFilter filter; /**< The filter mode used when blitting. */
  1998. bool cycle; /**< true cycles the destination texture if it is already bound. */
  1999. Uint8 padding1;
  2000. Uint8 padding2;
  2001. Uint8 padding3;
  2002. } SDL_GPUBlitInfo;
  2003. /* Binding structs */
  2004. /**
  2005. * A structure specifying parameters in a buffer binding call.
  2006. *
  2007. * \since This struct is available since SDL 3.2.0.
  2008. *
  2009. * \sa SDL_BindGPUVertexBuffers
  2010. * \sa SDL_BindGPUIndexBuffer
  2011. */
  2012. typedef struct SDL_GPUBufferBinding
  2013. {
  2014. SDL_GPUBuffer *buffer; /**< The buffer to bind. Must have been created with SDL_GPU_BUFFERUSAGE_VERTEX for SDL_BindGPUVertexBuffers, or SDL_GPU_BUFFERUSAGE_INDEX for SDL_BindGPUIndexBuffer. */
  2015. Uint32 offset; /**< The starting byte of the data to bind in the buffer. */
  2016. } SDL_GPUBufferBinding;
  2017. /**
  2018. * A structure specifying parameters in a sampler binding call.
  2019. *
  2020. * \since This struct is available since SDL 3.2.0.
  2021. *
  2022. * \sa SDL_BindGPUVertexSamplers
  2023. * \sa SDL_BindGPUFragmentSamplers
  2024. * \sa SDL_GPUTexture
  2025. * \sa SDL_GPUSampler
  2026. */
  2027. typedef struct SDL_GPUTextureSamplerBinding
  2028. {
  2029. SDL_GPUTexture *texture; /**< The texture to bind. Must have been created with SDL_GPU_TEXTUREUSAGE_SAMPLER. */
  2030. SDL_GPUSampler *sampler; /**< The sampler to bind. */
  2031. } SDL_GPUTextureSamplerBinding;
  2032. /**
  2033. * A structure specifying parameters related to binding buffers in a compute
  2034. * pass.
  2035. *
  2036. * \since This struct is available since SDL 3.2.0.
  2037. *
  2038. * \sa SDL_BeginGPUComputePass
  2039. */
  2040. typedef struct SDL_GPUStorageBufferReadWriteBinding
  2041. {
  2042. SDL_GPUBuffer *buffer; /**< The buffer to bind. Must have been created with SDL_GPU_BUFFERUSAGE_COMPUTE_STORAGE_WRITE. */
  2043. bool cycle; /**< true cycles the buffer if it is already bound. */
  2044. Uint8 padding1;
  2045. Uint8 padding2;
  2046. Uint8 padding3;
  2047. } SDL_GPUStorageBufferReadWriteBinding;
  2048. /**
  2049. * A structure specifying parameters related to binding textures in a compute
  2050. * pass.
  2051. *
  2052. * \since This struct is available since SDL 3.2.0.
  2053. *
  2054. * \sa SDL_BeginGPUComputePass
  2055. */
  2056. typedef struct SDL_GPUStorageTextureReadWriteBinding
  2057. {
  2058. SDL_GPUTexture *texture; /**< The texture to bind. Must have been created with SDL_GPU_TEXTUREUSAGE_COMPUTE_STORAGE_WRITE or SDL_GPU_TEXTUREUSAGE_COMPUTE_STORAGE_SIMULTANEOUS_READ_WRITE. */
  2059. Uint32 mip_level; /**< The mip level index to bind. */
  2060. Uint32 layer; /**< The layer index to bind. */
  2061. bool cycle; /**< true cycles the texture if it is already bound. */
  2062. Uint8 padding1;
  2063. Uint8 padding2;
  2064. Uint8 padding3;
  2065. } SDL_GPUStorageTextureReadWriteBinding;
  2066. /* Functions */
  2067. /* Device */
  2068. /**
  2069. * Checks for GPU runtime support.
  2070. *
  2071. * \param format_flags a bitflag indicating which shader formats the app is
  2072. * able to provide.
  2073. * \param name the preferred GPU driver, or NULL to let SDL pick the optimal
  2074. * driver.
  2075. * \returns true if supported, false otherwise.
  2076. *
  2077. * \since This function is available since SDL 3.2.0.
  2078. *
  2079. * \sa SDL_CreateGPUDevice
  2080. */
  2081. extern SDL_DECLSPEC bool SDLCALL SDL_GPUSupportsShaderFormats(
  2082. SDL_GPUShaderFormat format_flags,
  2083. const char *name);
  2084. /**
  2085. * Checks for GPU runtime support.
  2086. *
  2087. * \param props the properties to use.
  2088. * \returns true if supported, false otherwise.
  2089. *
  2090. * \since This function is available since SDL 3.2.0.
  2091. *
  2092. * \sa SDL_CreateGPUDeviceWithProperties
  2093. */
  2094. extern SDL_DECLSPEC bool SDLCALL SDL_GPUSupportsProperties(
  2095. SDL_PropertiesID props);
  2096. /**
  2097. * Creates a GPU context.
  2098. *
  2099. * The GPU driver name can be one of the following:
  2100. *
  2101. * - "vulkan": [Vulkan](CategoryGPU#vulkan)
  2102. * - "direct3d12": [D3D12](CategoryGPU#d3d12)
  2103. * - "metal": [Metal](CategoryGPU#metal)
  2104. * - NULL: let SDL pick the optimal driver
  2105. *
  2106. * \param format_flags a bitflag indicating which shader formats the app is
  2107. * able to provide.
  2108. * \param debug_mode enable debug mode properties and validations.
  2109. * \param name the preferred GPU driver, or NULL to let SDL pick the optimal
  2110. * driver.
  2111. * \returns a GPU context on success or NULL on failure; call SDL_GetError()
  2112. * for more information.
  2113. *
  2114. * \since This function is available since SDL 3.2.0.
  2115. *
  2116. * \sa SDL_CreateGPUDeviceWithProperties
  2117. * \sa SDL_GetGPUShaderFormats
  2118. * \sa SDL_GetGPUDeviceDriver
  2119. * \sa SDL_DestroyGPUDevice
  2120. * \sa SDL_GPUSupportsShaderFormats
  2121. */
  2122. extern SDL_DECLSPEC SDL_GPUDevice * SDLCALL SDL_CreateGPUDevice(
  2123. SDL_GPUShaderFormat format_flags,
  2124. bool debug_mode,
  2125. const char *name);
  2126. /**
  2127. * Creates a GPU context.
  2128. *
  2129. * These are the supported properties:
  2130. *
  2131. * - `SDL_PROP_GPU_DEVICE_CREATE_DEBUGMODE_BOOLEAN`: enable debug mode
  2132. * properties and validations, defaults to true.
  2133. * - `SDL_PROP_GPU_DEVICE_CREATE_PREFERLOWPOWER_BOOLEAN`: enable to prefer
  2134. * energy efficiency over maximum GPU performance, defaults to false.
  2135. * - `SDL_PROP_GPU_DEVICE_CREATE_VERBOSE_BOOLEAN`: enable to automatically log
  2136. * useful debug information on device creation, defaults to true.
  2137. * - `SDL_PROP_GPU_DEVICE_CREATE_NAME_STRING`: the name of the GPU driver to
  2138. * use, if a specific one is desired.
  2139. * - `SDL_PROP_GPU_DEVICE_CREATE_FEATURE_CLIP_DISTANCE_BOOLEAN`: Enable Vulkan
  2140. * device feature shaderClipDistance. If disabled, clip distances are not
  2141. * supported in shader code: gl_ClipDistance[] built-ins of GLSL,
  2142. * SV_ClipDistance0/1 semantics of HLSL and [[clip_distance]] attribute of
  2143. * Metal. Disabling optional features allows the application to run on some
  2144. * older Android devices. Defaults to true.
  2145. * - `SDL_PROP_GPU_DEVICE_CREATE_FEATURE_DEPTH_CLAMPING_BOOLEAN`: Enable
  2146. * Vulkan device feature depthClamp. If disabled, there is no depth clamp
  2147. * support and enable_depth_clip in SDL_GPURasterizerState must always be
  2148. * set to true. Disabling optional features allows the application to run on
  2149. * some older Android devices. Defaults to true.
  2150. * - `SDL_PROP_GPU_DEVICE_CREATE_FEATURE_INDIRECT_DRAW_FIRST_INSTANCE_BOOLEAN`:
  2151. * Enable Vulkan device feature drawIndirectFirstInstance. If disabled, the
  2152. * argument first_instance of SDL_GPUIndirectDrawCommand must be set to
  2153. * zero. Disabling optional features allows the application to run on some
  2154. * older Android devices. Defaults to true.
  2155. * - `SDL_PROP_GPU_DEVICE_CREATE_FEATURE_ANISOTROPY_BOOLEAN`: Enable Vulkan
  2156. * device feature samplerAnisotropy. If disabled, enable_anisotropy of
  2157. * SDL_GPUSamplerCreateInfo must be set to false. Disabling optional
  2158. * features allows the application to run on some older Android devices.
  2159. * Defaults to true.
  2160. *
  2161. * These are the current shader format properties:
  2162. *
  2163. * - `SDL_PROP_GPU_DEVICE_CREATE_SHADERS_PRIVATE_BOOLEAN`: The app is able to
  2164. * provide shaders for an NDA platform.
  2165. * - `SDL_PROP_GPU_DEVICE_CREATE_SHADERS_SPIRV_BOOLEAN`: The app is able to
  2166. * provide SPIR-V shaders if applicable.
  2167. * - `SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXBC_BOOLEAN`: The app is able to
  2168. * provide DXBC shaders if applicable
  2169. * - `SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXIL_BOOLEAN`: The app is able to
  2170. * provide DXIL shaders if applicable.
  2171. * - `SDL_PROP_GPU_DEVICE_CREATE_SHADERS_MSL_BOOLEAN`: The app is able to
  2172. * provide MSL shaders if applicable.
  2173. * - `SDL_PROP_GPU_DEVICE_CREATE_SHADERS_METALLIB_BOOLEAN`: The app is able to
  2174. * provide Metal shader libraries if applicable.
  2175. *
  2176. * With the D3D12 renderer:
  2177. *
  2178. * - `SDL_PROP_GPU_DEVICE_CREATE_D3D12_SEMANTIC_NAME_STRING`: the prefix to
  2179. * use for all vertex semantics, default is "TEXCOORD".
  2180. * - `SDL_PROP_GPU_DEVICE_CREATE_D3D12_ALLOW_FEWER_RESOURCE_SLOTS_BOOLEAN`: By
  2181. * default, Resourcing Binding Tier 2 is required for D3D12 support.
  2182. * However, an application can set this property to true to enable Tier 1
  2183. * support, if (and only if) the application uses 8 or fewer storage
  2184. * resources across all shader stages. As of writing, this property is
  2185. * useful for targeting Intel Haswell and Broadwell GPUs; other hardware
  2186. * either supports Tier 2 Resource Binding or does not support D3D12 in any
  2187. * capacity. Defaults to false.
  2188. *
  2189. * \param props the properties to use.
  2190. * \returns a GPU context on success or NULL on failure; call SDL_GetError()
  2191. * for more information.
  2192. *
  2193. * \since This function is available since SDL 3.2.0.
  2194. *
  2195. * \sa SDL_GetGPUShaderFormats
  2196. * \sa SDL_GetGPUDeviceDriver
  2197. * \sa SDL_DestroyGPUDevice
  2198. * \sa SDL_GPUSupportsProperties
  2199. */
  2200. extern SDL_DECLSPEC SDL_GPUDevice * SDLCALL SDL_CreateGPUDeviceWithProperties(
  2201. SDL_PropertiesID props);
  2202. #define SDL_PROP_GPU_DEVICE_CREATE_DEBUGMODE_BOOLEAN "SDL.gpu.device.create.debugmode"
  2203. #define SDL_PROP_GPU_DEVICE_CREATE_PREFERLOWPOWER_BOOLEAN "SDL.gpu.device.create.preferlowpower"
  2204. #define SDL_PROP_GPU_DEVICE_CREATE_VERBOSE_BOOLEAN "SDL.gpu.device.create.verbose"
  2205. #define SDL_PROP_GPU_DEVICE_CREATE_NAME_STRING "SDL.gpu.device.create.name"
  2206. #define SDL_PROP_GPU_DEVICE_CREATE_FEATURE_CLIP_DISTANCE_BOOLEAN "SDL.gpu.device.create.feature.clip_distance"
  2207. #define SDL_PROP_GPU_DEVICE_CREATE_FEATURE_DEPTH_CLAMPING_BOOLEAN "SDL.gpu.device.create.feature.depth_clamping"
  2208. #define SDL_PROP_GPU_DEVICE_CREATE_FEATURE_INDIRECT_DRAW_FIRST_INSTANCE_BOOLEAN "SDL.gpu.device.create.feature.indirect_draw_first_instance"
  2209. #define SDL_PROP_GPU_DEVICE_CREATE_FEATURE_ANISOTROPY_BOOLEAN "SDL.gpu.device.create.feature.anisotropy"
  2210. #define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_PRIVATE_BOOLEAN "SDL.gpu.device.create.shaders.private"
  2211. #define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_SPIRV_BOOLEAN "SDL.gpu.device.create.shaders.spirv"
  2212. #define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXBC_BOOLEAN "SDL.gpu.device.create.shaders.dxbc"
  2213. #define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXIL_BOOLEAN "SDL.gpu.device.create.shaders.dxil"
  2214. #define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_MSL_BOOLEAN "SDL.gpu.device.create.shaders.msl"
  2215. #define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_METALLIB_BOOLEAN "SDL.gpu.device.create.shaders.metallib"
  2216. #define SDL_PROP_GPU_DEVICE_CREATE_D3D12_ALLOW_FEWER_RESOURCE_SLOTS_BOOLEAN "SDL.gpu.device.create.d3d12.allowtier1resourcebinding"
  2217. #define SDL_PROP_GPU_DEVICE_CREATE_D3D12_SEMANTIC_NAME_STRING "SDL.gpu.device.create.d3d12.semantic"
  2218. /**
  2219. * Destroys a GPU context previously returned by SDL_CreateGPUDevice.
  2220. *
  2221. * \param device a GPU Context to destroy.
  2222. *
  2223. * \since This function is available since SDL 3.2.0.
  2224. *
  2225. * \sa SDL_CreateGPUDevice
  2226. */
  2227. extern SDL_DECLSPEC void SDLCALL SDL_DestroyGPUDevice(SDL_GPUDevice *device);
  2228. /**
  2229. * Get the number of GPU drivers compiled into SDL.
  2230. *
  2231. * \returns the number of built in GPU drivers.
  2232. *
  2233. * \since This function is available since SDL 3.2.0.
  2234. *
  2235. * \sa SDL_GetGPUDriver
  2236. */
  2237. extern SDL_DECLSPEC int SDLCALL SDL_GetNumGPUDrivers(void);
  2238. /**
  2239. * Get the name of a built in GPU driver.
  2240. *
  2241. * The GPU drivers are presented in the order in which they are normally
  2242. * checked during initialization.
  2243. *
  2244. * The names of drivers are all simple, low-ASCII identifiers, like "vulkan",
  2245. * "metal" or "direct3d12". These never have Unicode characters, and are not
  2246. * meant to be proper names.
  2247. *
  2248. * \param index the index of a GPU driver.
  2249. * \returns the name of the GPU driver with the given **index**.
  2250. *
  2251. * \since This function is available since SDL 3.2.0.
  2252. *
  2253. * \sa SDL_GetNumGPUDrivers
  2254. */
  2255. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGPUDriver(int index);
  2256. /**
  2257. * Returns the name of the backend used to create this GPU context.
  2258. *
  2259. * \param device a GPU context to query.
  2260. * \returns the name of the device's driver, or NULL on error.
  2261. *
  2262. * \since This function is available since SDL 3.2.0.
  2263. */
  2264. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGPUDeviceDriver(SDL_GPUDevice *device);
  2265. /**
  2266. * Returns the supported shader formats for this GPU context.
  2267. *
  2268. * \param device a GPU context to query.
  2269. * \returns a bitflag indicating which shader formats the driver is able to
  2270. * consume.
  2271. *
  2272. * \since This function is available since SDL 3.2.0.
  2273. */
  2274. extern SDL_DECLSPEC SDL_GPUShaderFormat SDLCALL SDL_GetGPUShaderFormats(SDL_GPUDevice *device);
  2275. /**
  2276. * Get the properties associated with a GPU device.
  2277. *
  2278. * All properties are optional and may differ between GPU backends and SDL
  2279. * versions.
  2280. *
  2281. * The following properties are provided by SDL:
  2282. *
  2283. * `SDL_PROP_GPU_DEVICE_NAME_STRING`: Contains the name of the underlying
  2284. * device as reported by the system driver. This string has no standardized
  2285. * format, is highly inconsistent between hardware devices and drivers, and is
  2286. * able to change at any time. Do not attempt to parse this string as it is
  2287. * bound to fail at some point in the future when system drivers are updated,
  2288. * new hardware devices are introduced, or when SDL adds new GPU backends or
  2289. * modifies existing ones.
  2290. *
  2291. * Strings that have been found in the wild include:
  2292. *
  2293. * - GTX 970
  2294. * - GeForce GTX 970
  2295. * - NVIDIA GeForce GTX 970
  2296. * - Microsoft Direct3D12 (NVIDIA GeForce GTX 970)
  2297. * - NVIDIA Graphics Device
  2298. * - GeForce GPU
  2299. * - P106-100
  2300. * - AMD 15D8:C9
  2301. * - AMD Custom GPU 0405
  2302. * - AMD Radeon (TM) Graphics
  2303. * - ASUS Radeon RX 470 Series
  2304. * - Intel(R) Arc(tm) A380 Graphics (DG2)
  2305. * - Virtio-GPU Venus (NVIDIA TITAN V)
  2306. * - SwiftShader Device (LLVM 16.0.0)
  2307. * - llvmpipe (LLVM 15.0.4, 256 bits)
  2308. * - Microsoft Basic Render Driver
  2309. * - unknown device
  2310. *
  2311. * The above list shows that the same device can have different formats, the
  2312. * vendor name may or may not appear in the string, the included vendor name
  2313. * may not be the vendor of the chipset on the device, some manufacturers
  2314. * include pseudo-legal marks while others don't, some devices may not use a
  2315. * marketing name in the string, the device string may be wrapped by the name
  2316. * of a translation interface, the device may be emulated in software, or the
  2317. * string may contain generic text that does not identify the device at all.
  2318. *
  2319. * `SDL_PROP_GPU_DEVICE_DRIVER_NAME_STRING`: Contains the self-reported name
  2320. * of the underlying system driver.
  2321. *
  2322. * Strings that have been found in the wild include:
  2323. *
  2324. * - Intel Corporation
  2325. * - Intel open-source Mesa driver
  2326. * - Qualcomm Technologies Inc. Adreno Vulkan Driver
  2327. * - MoltenVK
  2328. * - Mali-G715
  2329. * - venus
  2330. *
  2331. * `SDL_PROP_GPU_DEVICE_DRIVER_VERSION_STRING`: Contains the self-reported
  2332. * version of the underlying system driver. This is a relatively short version
  2333. * string in an unspecified format. If SDL_PROP_GPU_DEVICE_DRIVER_INFO_STRING
  2334. * is available then that property should be preferred over this one as it may
  2335. * contain additional information that is useful for identifying the exact
  2336. * driver version used.
  2337. *
  2338. * Strings that have been found in the wild include:
  2339. *
  2340. * - 53.0.0
  2341. * - 0.405.2463
  2342. * - 32.0.15.6614
  2343. *
  2344. * `SDL_PROP_GPU_DEVICE_DRIVER_INFO_STRING`: Contains the detailed version
  2345. * information of the underlying system driver as reported by the driver. This
  2346. * is an arbitrary string with no standardized format and it may contain
  2347. * newlines. This property should be preferred over
  2348. * SDL_PROP_GPU_DEVICE_DRIVER_VERSION_STRING if it is available as it usually
  2349. * contains the same information but in a format that is easier to read.
  2350. *
  2351. * Strings that have been found in the wild include:
  2352. *
  2353. * - 101.6559
  2354. * - 1.2.11
  2355. * - Mesa 21.2.2 (LLVM 12.0.1)
  2356. * - Mesa 22.2.0-devel (git-f226222 2022-04-14 impish-oibaf-ppa)
  2357. * - v1.r53p0-00eac0.824c4f31403fb1fbf8ee1042422c2129
  2358. *
  2359. * This string has also been observed to be a multiline string (which has a
  2360. * trailing newline):
  2361. *
  2362. * ```
  2363. * Driver Build: 85da404, I46ff5fc46f, 1606794520
  2364. * Date: 11/30/20
  2365. * Compiler Version: EV031.31.04.01
  2366. * Driver Branch: promo490_3_Google
  2367. * ```
  2368. *
  2369. * \param device a GPU context to query.
  2370. * \returns a valid property ID on success or 0 on failure; call
  2371. * SDL_GetError() for more information.
  2372. *
  2373. * \threadsafety It is safe to call this function from any thread.
  2374. *
  2375. * \since This function is available since SDL 3.4.0.
  2376. */
  2377. extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetGPUDeviceProperties(SDL_GPUDevice *device);
  2378. #define SDL_PROP_GPU_DEVICE_NAME_STRING "SDL.gpu.device.name"
  2379. #define SDL_PROP_GPU_DEVICE_DRIVER_NAME_STRING "SDL.gpu.device.driver_name"
  2380. #define SDL_PROP_GPU_DEVICE_DRIVER_VERSION_STRING "SDL.gpu.device.driver_version"
  2381. #define SDL_PROP_GPU_DEVICE_DRIVER_INFO_STRING "SDL.gpu.device.driver_info"
  2382. /* State Creation */
  2383. /**
  2384. * Creates a pipeline object to be used in a compute workflow.
  2385. *
  2386. * Shader resource bindings must be authored to follow a particular order
  2387. * depending on the shader format.
  2388. *
  2389. * For SPIR-V shaders, use the following resource sets:
  2390. *
  2391. * - 0: Sampled textures, followed by read-only storage textures, followed by
  2392. * read-only storage buffers
  2393. * - 1: Read-write storage textures, followed by read-write storage buffers
  2394. * - 2: Uniform buffers
  2395. *
  2396. * For DXBC and DXIL shaders, use the following register order:
  2397. *
  2398. * - (t[n], space0): Sampled textures, followed by read-only storage textures,
  2399. * followed by read-only storage buffers
  2400. * - (u[n], space1): Read-write storage textures, followed by read-write
  2401. * storage buffers
  2402. * - (b[n], space2): Uniform buffers
  2403. *
  2404. * For MSL/metallib, use the following order:
  2405. *
  2406. * - [[buffer]]: Uniform buffers, followed by read-only storage buffers,
  2407. * followed by read-write storage buffers
  2408. * - [[texture]]: Sampled textures, followed by read-only storage textures,
  2409. * followed by read-write storage textures
  2410. *
  2411. * There are optional properties that can be provided through `props`. These
  2412. * are the supported properties:
  2413. *
  2414. * - `SDL_PROP_GPU_COMPUTEPIPELINE_CREATE_NAME_STRING`: a name that can be
  2415. * displayed in debugging tools.
  2416. *
  2417. * \param device a GPU Context.
  2418. * \param createinfo a struct describing the state of the compute pipeline to
  2419. * create.
  2420. * \returns a compute pipeline object on success, or NULL on failure; call
  2421. * SDL_GetError() for more information.
  2422. *
  2423. * \since This function is available since SDL 3.2.0.
  2424. *
  2425. * \sa SDL_BindGPUComputePipeline
  2426. * \sa SDL_ReleaseGPUComputePipeline
  2427. */
  2428. extern SDL_DECLSPEC SDL_GPUComputePipeline * SDLCALL SDL_CreateGPUComputePipeline(
  2429. SDL_GPUDevice *device,
  2430. const SDL_GPUComputePipelineCreateInfo *createinfo);
  2431. #define SDL_PROP_GPU_COMPUTEPIPELINE_CREATE_NAME_STRING "SDL.gpu.computepipeline.create.name"
  2432. /**
  2433. * Creates a pipeline object to be used in a graphics workflow.
  2434. *
  2435. * There are optional properties that can be provided through `props`. These
  2436. * are the supported properties:
  2437. *
  2438. * - `SDL_PROP_GPU_GRAPHICSPIPELINE_CREATE_NAME_STRING`: a name that can be
  2439. * displayed in debugging tools.
  2440. *
  2441. * \param device a GPU Context.
  2442. * \param createinfo a struct describing the state of the graphics pipeline to
  2443. * create.
  2444. * \returns a graphics pipeline object on success, or NULL on failure; call
  2445. * SDL_GetError() for more information.
  2446. *
  2447. * \since This function is available since SDL 3.2.0.
  2448. *
  2449. * \sa SDL_CreateGPUShader
  2450. * \sa SDL_BindGPUGraphicsPipeline
  2451. * \sa SDL_ReleaseGPUGraphicsPipeline
  2452. */
  2453. extern SDL_DECLSPEC SDL_GPUGraphicsPipeline * SDLCALL SDL_CreateGPUGraphicsPipeline(
  2454. SDL_GPUDevice *device,
  2455. const SDL_GPUGraphicsPipelineCreateInfo *createinfo);
  2456. #define SDL_PROP_GPU_GRAPHICSPIPELINE_CREATE_NAME_STRING "SDL.gpu.graphicspipeline.create.name"
  2457. /**
  2458. * Creates a sampler object to be used when binding textures in a graphics
  2459. * workflow.
  2460. *
  2461. * There are optional properties that can be provided through `props`. These
  2462. * are the supported properties:
  2463. *
  2464. * - `SDL_PROP_GPU_SAMPLER_CREATE_NAME_STRING`: a name that can be displayed
  2465. * in debugging tools.
  2466. *
  2467. * \param device a GPU Context.
  2468. * \param createinfo a struct describing the state of the sampler to create.
  2469. * \returns a sampler object on success, or NULL on failure; call
  2470. * SDL_GetError() for more information.
  2471. *
  2472. * \since This function is available since SDL 3.2.0.
  2473. *
  2474. * \sa SDL_BindGPUVertexSamplers
  2475. * \sa SDL_BindGPUFragmentSamplers
  2476. * \sa SDL_ReleaseGPUSampler
  2477. */
  2478. extern SDL_DECLSPEC SDL_GPUSampler * SDLCALL SDL_CreateGPUSampler(
  2479. SDL_GPUDevice *device,
  2480. const SDL_GPUSamplerCreateInfo *createinfo);
  2481. #define SDL_PROP_GPU_SAMPLER_CREATE_NAME_STRING "SDL.gpu.sampler.create.name"
  2482. /**
  2483. * Creates a shader to be used when creating a graphics pipeline.
  2484. *
  2485. * Shader resource bindings must be authored to follow a particular order
  2486. * depending on the shader format.
  2487. *
  2488. * For SPIR-V shaders, use the following resource sets:
  2489. *
  2490. * For vertex shaders:
  2491. *
  2492. * - 0: Sampled textures, followed by storage textures, followed by storage
  2493. * buffers
  2494. * - 1: Uniform buffers
  2495. *
  2496. * For fragment shaders:
  2497. *
  2498. * - 2: Sampled textures, followed by storage textures, followed by storage
  2499. * buffers
  2500. * - 3: Uniform buffers
  2501. *
  2502. * For DXBC and DXIL shaders, use the following register order:
  2503. *
  2504. * For vertex shaders:
  2505. *
  2506. * - (t[n], space0): Sampled textures, followed by storage textures, followed
  2507. * by storage buffers
  2508. * - (s[n], space0): Samplers with indices corresponding to the sampled
  2509. * textures
  2510. * - (b[n], space1): Uniform buffers
  2511. *
  2512. * For pixel shaders:
  2513. *
  2514. * - (t[n], space2): Sampled textures, followed by storage textures, followed
  2515. * by storage buffers
  2516. * - (s[n], space2): Samplers with indices corresponding to the sampled
  2517. * textures
  2518. * - (b[n], space3): Uniform buffers
  2519. *
  2520. * For MSL/metallib, use the following order:
  2521. *
  2522. * - [[texture]]: Sampled textures, followed by storage textures
  2523. * - [[sampler]]: Samplers with indices corresponding to the sampled textures
  2524. * - [[buffer]]: Uniform buffers, followed by storage buffers. Vertex buffer 0
  2525. * is bound at [[buffer(14)]], vertex buffer 1 at [[buffer(15)]], and so on.
  2526. * Rather than manually authoring vertex buffer indices, use the
  2527. * [[stage_in]] attribute which will automatically use the vertex input
  2528. * information from the SDL_GPUGraphicsPipeline.
  2529. *
  2530. * Shader semantics other than system-value semantics do not matter in D3D12
  2531. * and for ease of use the SDL implementation assumes that non system-value
  2532. * semantics will all be TEXCOORD. If you are using HLSL as the shader source
  2533. * language, your vertex semantics should start at TEXCOORD0 and increment
  2534. * like so: TEXCOORD1, TEXCOORD2, etc. If you wish to change the semantic
  2535. * prefix to something other than TEXCOORD you can use
  2536. * SDL_PROP_GPU_DEVICE_CREATE_D3D12_SEMANTIC_NAME_STRING with
  2537. * SDL_CreateGPUDeviceWithProperties().
  2538. *
  2539. * There are optional properties that can be provided through `props`. These
  2540. * are the supported properties:
  2541. *
  2542. * - `SDL_PROP_GPU_SHADER_CREATE_NAME_STRING`: a name that can be displayed in
  2543. * debugging tools.
  2544. *
  2545. * \param device a GPU Context.
  2546. * \param createinfo a struct describing the state of the shader to create.
  2547. * \returns a shader object on success, or NULL on failure; call
  2548. * SDL_GetError() for more information.
  2549. *
  2550. * \since This function is available since SDL 3.2.0.
  2551. *
  2552. * \sa SDL_CreateGPUGraphicsPipeline
  2553. * \sa SDL_ReleaseGPUShader
  2554. */
  2555. extern SDL_DECLSPEC SDL_GPUShader * SDLCALL SDL_CreateGPUShader(
  2556. SDL_GPUDevice *device,
  2557. const SDL_GPUShaderCreateInfo *createinfo);
  2558. #define SDL_PROP_GPU_SHADER_CREATE_NAME_STRING "SDL.gpu.shader.create.name"
  2559. /**
  2560. * Creates a texture object to be used in graphics or compute workflows.
  2561. *
  2562. * The contents of this texture are undefined until data is written to the
  2563. * texture, either via SDL_UploadToGPUTexture or by performing a render or
  2564. * compute pass with this texture as a target.
  2565. *
  2566. * Note that certain combinations of usage flags are invalid. For example, a
  2567. * texture cannot have both the SAMPLER and GRAPHICS_STORAGE_READ flags.
  2568. *
  2569. * If you request a sample count higher than the hardware supports, the
  2570. * implementation will automatically fall back to the highest available sample
  2571. * count.
  2572. *
  2573. * There are optional properties that can be provided through
  2574. * SDL_GPUTextureCreateInfo's `props`. These are the supported properties:
  2575. *
  2576. * - `SDL_PROP_GPU_TEXTURE_CREATE_D3D12_CLEAR_R_FLOAT`: (Direct3D 12 only) if
  2577. * the texture usage is SDL_GPU_TEXTUREUSAGE_COLOR_TARGET, clear the texture
  2578. * to a color with this red intensity. Defaults to zero.
  2579. * - `SDL_PROP_GPU_TEXTURE_CREATE_D3D12_CLEAR_G_FLOAT`: (Direct3D 12 only) if
  2580. * the texture usage is SDL_GPU_TEXTUREUSAGE_COLOR_TARGET, clear the texture
  2581. * to a color with this green intensity. Defaults to zero.
  2582. * - `SDL_PROP_GPU_TEXTURE_CREATE_D3D12_CLEAR_B_FLOAT`: (Direct3D 12 only) if
  2583. * the texture usage is SDL_GPU_TEXTUREUSAGE_COLOR_TARGET, clear the texture
  2584. * to a color with this blue intensity. Defaults to zero.
  2585. * - `SDL_PROP_GPU_TEXTURE_CREATE_D3D12_CLEAR_A_FLOAT`: (Direct3D 12 only) if
  2586. * the texture usage is SDL_GPU_TEXTUREUSAGE_COLOR_TARGET, clear the texture
  2587. * to a color with this alpha intensity. Defaults to zero.
  2588. * - `SDL_PROP_GPU_TEXTURE_CREATE_D3D12_CLEAR_DEPTH_FLOAT`: (Direct3D 12 only)
  2589. * if the texture usage is SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET, clear
  2590. * the texture to a depth of this value. Defaults to zero.
  2591. * - `SDL_PROP_GPU_TEXTURE_CREATE_D3D12_CLEAR_STENCIL_NUMBER`: (Direct3D 12
  2592. * only) if the texture usage is SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET,
  2593. * clear the texture to a stencil of this Uint8 value. Defaults to zero.
  2594. * - `SDL_PROP_GPU_TEXTURE_CREATE_NAME_STRING`: a name that can be displayed
  2595. * in debugging tools.
  2596. *
  2597. * \param device a GPU Context.
  2598. * \param createinfo a struct describing the state of the texture to create.
  2599. * \returns a texture object on success, or NULL on failure; call
  2600. * SDL_GetError() for more information.
  2601. *
  2602. * \since This function is available since SDL 3.2.0.
  2603. *
  2604. * \sa SDL_UploadToGPUTexture
  2605. * \sa SDL_DownloadFromGPUTexture
  2606. * \sa SDL_BeginGPURenderPass
  2607. * \sa SDL_BeginGPUComputePass
  2608. * \sa SDL_BindGPUVertexSamplers
  2609. * \sa SDL_BindGPUVertexStorageTextures
  2610. * \sa SDL_BindGPUFragmentSamplers
  2611. * \sa SDL_BindGPUFragmentStorageTextures
  2612. * \sa SDL_BindGPUComputeStorageTextures
  2613. * \sa SDL_BlitGPUTexture
  2614. * \sa SDL_ReleaseGPUTexture
  2615. * \sa SDL_GPUTextureSupportsFormat
  2616. */
  2617. extern SDL_DECLSPEC SDL_GPUTexture * SDLCALL SDL_CreateGPUTexture(
  2618. SDL_GPUDevice *device,
  2619. const SDL_GPUTextureCreateInfo *createinfo);
  2620. #define SDL_PROP_GPU_TEXTURE_CREATE_D3D12_CLEAR_R_FLOAT "SDL.gpu.texture.create.d3d12.clear.r"
  2621. #define SDL_PROP_GPU_TEXTURE_CREATE_D3D12_CLEAR_G_FLOAT "SDL.gpu.texture.create.d3d12.clear.g"
  2622. #define SDL_PROP_GPU_TEXTURE_CREATE_D3D12_CLEAR_B_FLOAT "SDL.gpu.texture.create.d3d12.clear.b"
  2623. #define SDL_PROP_GPU_TEXTURE_CREATE_D3D12_CLEAR_A_FLOAT "SDL.gpu.texture.create.d3d12.clear.a"
  2624. #define SDL_PROP_GPU_TEXTURE_CREATE_D3D12_CLEAR_DEPTH_FLOAT "SDL.gpu.texture.create.d3d12.clear.depth"
  2625. #define SDL_PROP_GPU_TEXTURE_CREATE_D3D12_CLEAR_STENCIL_NUMBER "SDL.gpu.texture.create.d3d12.clear.stencil"
  2626. #define SDL_PROP_GPU_TEXTURE_CREATE_NAME_STRING "SDL.gpu.texture.create.name"
  2627. /**
  2628. * Creates a buffer object to be used in graphics or compute workflows.
  2629. *
  2630. * The contents of this buffer are undefined until data is written to the
  2631. * buffer.
  2632. *
  2633. * Note that certain combinations of usage flags are invalid. For example, a
  2634. * buffer cannot have both the VERTEX and INDEX flags.
  2635. *
  2636. * If you use a STORAGE flag, the data in the buffer must respect std140
  2637. * layout conventions. In practical terms this means you must ensure that vec3
  2638. * and vec4 fields are 16-byte aligned.
  2639. *
  2640. * For better understanding of underlying concepts and memory management with
  2641. * SDL GPU API, you may refer
  2642. * [this blog post](https://moonside.games/posts/sdl-gpu-concepts-cycling/)
  2643. * .
  2644. *
  2645. * There are optional properties that can be provided through `props`. These
  2646. * are the supported properties:
  2647. *
  2648. * - `SDL_PROP_GPU_BUFFER_CREATE_NAME_STRING`: a name that can be displayed in
  2649. * debugging tools.
  2650. *
  2651. * \param device a GPU Context.
  2652. * \param createinfo a struct describing the state of the buffer to create.
  2653. * \returns a buffer object on success, or NULL on failure; call
  2654. * SDL_GetError() for more information.
  2655. *
  2656. * \since This function is available since SDL 3.2.0.
  2657. *
  2658. * \sa SDL_UploadToGPUBuffer
  2659. * \sa SDL_DownloadFromGPUBuffer
  2660. * \sa SDL_CopyGPUBufferToBuffer
  2661. * \sa SDL_BindGPUVertexBuffers
  2662. * \sa SDL_BindGPUIndexBuffer
  2663. * \sa SDL_BindGPUVertexStorageBuffers
  2664. * \sa SDL_BindGPUFragmentStorageBuffers
  2665. * \sa SDL_DrawGPUPrimitivesIndirect
  2666. * \sa SDL_DrawGPUIndexedPrimitivesIndirect
  2667. * \sa SDL_BindGPUComputeStorageBuffers
  2668. * \sa SDL_DispatchGPUComputeIndirect
  2669. * \sa SDL_ReleaseGPUBuffer
  2670. */
  2671. extern SDL_DECLSPEC SDL_GPUBuffer * SDLCALL SDL_CreateGPUBuffer(
  2672. SDL_GPUDevice *device,
  2673. const SDL_GPUBufferCreateInfo *createinfo);
  2674. #define SDL_PROP_GPU_BUFFER_CREATE_NAME_STRING "SDL.gpu.buffer.create.name"
  2675. /**
  2676. * Creates a transfer buffer to be used when uploading to or downloading from
  2677. * graphics resources.
  2678. *
  2679. * Download buffers can be particularly expensive to create, so it is good
  2680. * practice to reuse them if data will be downloaded regularly.
  2681. *
  2682. * There are optional properties that can be provided through `props`. These
  2683. * are the supported properties:
  2684. *
  2685. * - `SDL_PROP_GPU_TRANSFERBUFFER_CREATE_NAME_STRING`: a name that can be
  2686. * displayed in debugging tools.
  2687. *
  2688. * \param device a GPU Context.
  2689. * \param createinfo a struct describing the state of the transfer buffer to
  2690. * create.
  2691. * \returns a transfer buffer on success, or NULL on failure; call
  2692. * SDL_GetError() for more information.
  2693. *
  2694. * \since This function is available since SDL 3.2.0.
  2695. *
  2696. * \sa SDL_UploadToGPUBuffer
  2697. * \sa SDL_DownloadFromGPUBuffer
  2698. * \sa SDL_UploadToGPUTexture
  2699. * \sa SDL_DownloadFromGPUTexture
  2700. * \sa SDL_ReleaseGPUTransferBuffer
  2701. */
  2702. extern SDL_DECLSPEC SDL_GPUTransferBuffer * SDLCALL SDL_CreateGPUTransferBuffer(
  2703. SDL_GPUDevice *device,
  2704. const SDL_GPUTransferBufferCreateInfo *createinfo);
  2705. #define SDL_PROP_GPU_TRANSFERBUFFER_CREATE_NAME_STRING "SDL.gpu.transferbuffer.create.name"
  2706. /* Debug Naming */
  2707. /**
  2708. * Sets an arbitrary string constant to label a buffer.
  2709. *
  2710. * You should use SDL_PROP_GPU_BUFFER_CREATE_NAME_STRING with
  2711. * SDL_CreateGPUBuffer instead of this function to avoid thread safety issues.
  2712. *
  2713. * \param device a GPU Context.
  2714. * \param buffer a buffer to attach the name to.
  2715. * \param text a UTF-8 string constant to mark as the name of the buffer.
  2716. *
  2717. * \threadsafety This function is not thread safe, you must make sure the
  2718. * buffer is not simultaneously used by any other thread.
  2719. *
  2720. * \since This function is available since SDL 3.2.0.
  2721. *
  2722. * \sa SDL_CreateGPUBuffer
  2723. */
  2724. extern SDL_DECLSPEC void SDLCALL SDL_SetGPUBufferName(
  2725. SDL_GPUDevice *device,
  2726. SDL_GPUBuffer *buffer,
  2727. const char *text);
  2728. /**
  2729. * Sets an arbitrary string constant to label a texture.
  2730. *
  2731. * You should use SDL_PROP_GPU_TEXTURE_CREATE_NAME_STRING with
  2732. * SDL_CreateGPUTexture instead of this function to avoid thread safety
  2733. * issues.
  2734. *
  2735. * \param device a GPU Context.
  2736. * \param texture a texture to attach the name to.
  2737. * \param text a UTF-8 string constant to mark as the name of the texture.
  2738. *
  2739. * \threadsafety This function is not thread safe, you must make sure the
  2740. * texture is not simultaneously used by any other thread.
  2741. *
  2742. * \since This function is available since SDL 3.2.0.
  2743. *
  2744. * \sa SDL_CreateGPUTexture
  2745. */
  2746. extern SDL_DECLSPEC void SDLCALL SDL_SetGPUTextureName(
  2747. SDL_GPUDevice *device,
  2748. SDL_GPUTexture *texture,
  2749. const char *text);
  2750. /**
  2751. * Inserts an arbitrary string label into the command buffer callstream.
  2752. *
  2753. * Useful for debugging.
  2754. *
  2755. * \param command_buffer a command buffer.
  2756. * \param text a UTF-8 string constant to insert as the label.
  2757. *
  2758. * \since This function is available since SDL 3.2.0.
  2759. */
  2760. extern SDL_DECLSPEC void SDLCALL SDL_InsertGPUDebugLabel(
  2761. SDL_GPUCommandBuffer *command_buffer,
  2762. const char *text);
  2763. /**
  2764. * Begins a debug group with an arbitrary name.
  2765. *
  2766. * Used for denoting groups of calls when viewing the command buffer
  2767. * callstream in a graphics debugging tool.
  2768. *
  2769. * Each call to SDL_PushGPUDebugGroup must have a corresponding call to
  2770. * SDL_PopGPUDebugGroup.
  2771. *
  2772. * On some backends (e.g. Metal), pushing a debug group during a
  2773. * render/blit/compute pass will create a group that is scoped to the native
  2774. * pass rather than the command buffer. For best results, if you push a debug
  2775. * group during a pass, always pop it in the same pass.
  2776. *
  2777. * \param command_buffer a command buffer.
  2778. * \param name a UTF-8 string constant that names the group.
  2779. *
  2780. * \since This function is available since SDL 3.2.0.
  2781. *
  2782. * \sa SDL_PopGPUDebugGroup
  2783. */
  2784. extern SDL_DECLSPEC void SDLCALL SDL_PushGPUDebugGroup(
  2785. SDL_GPUCommandBuffer *command_buffer,
  2786. const char *name);
  2787. /**
  2788. * Ends the most-recently pushed debug group.
  2789. *
  2790. * \param command_buffer a command buffer.
  2791. *
  2792. * \since This function is available since SDL 3.2.0.
  2793. *
  2794. * \sa SDL_PushGPUDebugGroup
  2795. */
  2796. extern SDL_DECLSPEC void SDLCALL SDL_PopGPUDebugGroup(
  2797. SDL_GPUCommandBuffer *command_buffer);
  2798. /* Disposal */
  2799. /**
  2800. * Frees the given texture as soon as it is safe to do so.
  2801. *
  2802. * You must not reference the texture after calling this function.
  2803. *
  2804. * \param device a GPU context.
  2805. * \param texture a texture to be destroyed.
  2806. *
  2807. * \since This function is available since SDL 3.2.0.
  2808. */
  2809. extern SDL_DECLSPEC void SDLCALL SDL_ReleaseGPUTexture(
  2810. SDL_GPUDevice *device,
  2811. SDL_GPUTexture *texture);
  2812. /**
  2813. * Frees the given sampler as soon as it is safe to do so.
  2814. *
  2815. * You must not reference the sampler after calling this function.
  2816. *
  2817. * \param device a GPU context.
  2818. * \param sampler a sampler to be destroyed.
  2819. *
  2820. * \since This function is available since SDL 3.2.0.
  2821. */
  2822. extern SDL_DECLSPEC void SDLCALL SDL_ReleaseGPUSampler(
  2823. SDL_GPUDevice *device,
  2824. SDL_GPUSampler *sampler);
  2825. /**
  2826. * Frees the given buffer as soon as it is safe to do so.
  2827. *
  2828. * You must not reference the buffer after calling this function.
  2829. *
  2830. * \param device a GPU context.
  2831. * \param buffer a buffer to be destroyed.
  2832. *
  2833. * \since This function is available since SDL 3.2.0.
  2834. */
  2835. extern SDL_DECLSPEC void SDLCALL SDL_ReleaseGPUBuffer(
  2836. SDL_GPUDevice *device,
  2837. SDL_GPUBuffer *buffer);
  2838. /**
  2839. * Frees the given transfer buffer as soon as it is safe to do so.
  2840. *
  2841. * You must not reference the transfer buffer after calling this function.
  2842. *
  2843. * \param device a GPU context.
  2844. * \param transfer_buffer a transfer buffer to be destroyed.
  2845. *
  2846. * \since This function is available since SDL 3.2.0.
  2847. */
  2848. extern SDL_DECLSPEC void SDLCALL SDL_ReleaseGPUTransferBuffer(
  2849. SDL_GPUDevice *device,
  2850. SDL_GPUTransferBuffer *transfer_buffer);
  2851. /**
  2852. * Frees the given compute pipeline as soon as it is safe to do so.
  2853. *
  2854. * You must not reference the compute pipeline after calling this function.
  2855. *
  2856. * \param device a GPU context.
  2857. * \param compute_pipeline a compute pipeline to be destroyed.
  2858. *
  2859. * \since This function is available since SDL 3.2.0.
  2860. */
  2861. extern SDL_DECLSPEC void SDLCALL SDL_ReleaseGPUComputePipeline(
  2862. SDL_GPUDevice *device,
  2863. SDL_GPUComputePipeline *compute_pipeline);
  2864. /**
  2865. * Frees the given shader as soon as it is safe to do so.
  2866. *
  2867. * You must not reference the shader after calling this function.
  2868. *
  2869. * \param device a GPU context.
  2870. * \param shader a shader to be destroyed.
  2871. *
  2872. * \since This function is available since SDL 3.2.0.
  2873. */
  2874. extern SDL_DECLSPEC void SDLCALL SDL_ReleaseGPUShader(
  2875. SDL_GPUDevice *device,
  2876. SDL_GPUShader *shader);
  2877. /**
  2878. * Frees the given graphics pipeline as soon as it is safe to do so.
  2879. *
  2880. * You must not reference the graphics pipeline after calling this function.
  2881. *
  2882. * \param device a GPU context.
  2883. * \param graphics_pipeline a graphics pipeline to be destroyed.
  2884. *
  2885. * \since This function is available since SDL 3.2.0.
  2886. */
  2887. extern SDL_DECLSPEC void SDLCALL SDL_ReleaseGPUGraphicsPipeline(
  2888. SDL_GPUDevice *device,
  2889. SDL_GPUGraphicsPipeline *graphics_pipeline);
  2890. /**
  2891. * Acquire a command buffer.
  2892. *
  2893. * This command buffer is managed by the implementation and should not be
  2894. * freed by the user. The command buffer may only be used on the thread it was
  2895. * acquired on. The command buffer should be submitted on the thread it was
  2896. * acquired on.
  2897. *
  2898. * It is valid to acquire multiple command buffers on the same thread at once.
  2899. * In fact a common design pattern is to acquire two command buffers per frame
  2900. * where one is dedicated to render and compute passes and the other is
  2901. * dedicated to copy passes and other preparatory work such as generating
  2902. * mipmaps. Interleaving commands between the two command buffers reduces the
  2903. * total amount of passes overall which improves rendering performance.
  2904. *
  2905. * \param device a GPU context.
  2906. * \returns a command buffer, or NULL on failure; call SDL_GetError() for more
  2907. * information.
  2908. *
  2909. * \since This function is available since SDL 3.2.0.
  2910. *
  2911. * \sa SDL_SubmitGPUCommandBuffer
  2912. * \sa SDL_SubmitGPUCommandBufferAndAcquireFence
  2913. */
  2914. extern SDL_DECLSPEC SDL_GPUCommandBuffer * SDLCALL SDL_AcquireGPUCommandBuffer(
  2915. SDL_GPUDevice *device);
  2916. /* Uniform Data */
  2917. /**
  2918. * Pushes data to a vertex uniform slot on the command buffer.
  2919. *
  2920. * Subsequent draw calls will use this uniform data.
  2921. *
  2922. * The data being pushed must respect std140 layout conventions. In practical
  2923. * terms this means you must ensure that vec3 and vec4 fields are 16-byte
  2924. * aligned.
  2925. *
  2926. * For detailed information about accessing uniform data from a shader, please
  2927. * refer to SDL_CreateGPUShader.
  2928. *
  2929. * \param command_buffer a command buffer.
  2930. * \param slot_index the vertex uniform slot to push data to.
  2931. * \param data client data to write.
  2932. * \param length the length of the data to write.
  2933. *
  2934. * \since This function is available since SDL 3.2.0.
  2935. */
  2936. extern SDL_DECLSPEC void SDLCALL SDL_PushGPUVertexUniformData(
  2937. SDL_GPUCommandBuffer *command_buffer,
  2938. Uint32 slot_index,
  2939. const void *data,
  2940. Uint32 length);
  2941. /**
  2942. * Pushes data to a fragment uniform slot on the command buffer.
  2943. *
  2944. * Subsequent draw calls will use this uniform data.
  2945. *
  2946. * The data being pushed must respect std140 layout conventions. In practical
  2947. * terms this means you must ensure that vec3 and vec4 fields are 16-byte
  2948. * aligned.
  2949. *
  2950. * \param command_buffer a command buffer.
  2951. * \param slot_index the fragment uniform slot to push data to.
  2952. * \param data client data to write.
  2953. * \param length the length of the data to write.
  2954. *
  2955. * \since This function is available since SDL 3.2.0.
  2956. */
  2957. extern SDL_DECLSPEC void SDLCALL SDL_PushGPUFragmentUniformData(
  2958. SDL_GPUCommandBuffer *command_buffer,
  2959. Uint32 slot_index,
  2960. const void *data,
  2961. Uint32 length);
  2962. /**
  2963. * Pushes data to a uniform slot on the command buffer.
  2964. *
  2965. * Subsequent draw calls will use this uniform data.
  2966. *
  2967. * The data being pushed must respect std140 layout conventions. In practical
  2968. * terms this means you must ensure that vec3 and vec4 fields are 16-byte
  2969. * aligned.
  2970. *
  2971. * \param command_buffer a command buffer.
  2972. * \param slot_index the uniform slot to push data to.
  2973. * \param data client data to write.
  2974. * \param length the length of the data to write.
  2975. *
  2976. * \since This function is available since SDL 3.2.0.
  2977. */
  2978. extern SDL_DECLSPEC void SDLCALL SDL_PushGPUComputeUniformData(
  2979. SDL_GPUCommandBuffer *command_buffer,
  2980. Uint32 slot_index,
  2981. const void *data,
  2982. Uint32 length);
  2983. /* Graphics State */
  2984. /**
  2985. * Begins a render pass on a command buffer.
  2986. *
  2987. * A render pass consists of a set of texture subresources (or depth slices in
  2988. * the 3D texture case) which will be rendered to during the render pass,
  2989. * along with corresponding clear values and load/store operations. All
  2990. * operations related to graphics pipelines must take place inside of a render
  2991. * pass. A default viewport and scissor state are automatically set when this
  2992. * is called. You cannot begin another render pass, or begin a compute pass or
  2993. * copy pass until you have ended the render pass.
  2994. *
  2995. * Using SDL_GPU_LOADOP_LOAD before any contents have been written to the
  2996. * texture subresource will result in undefined behavior. SDL_GPU_LOADOP_CLEAR
  2997. * will set the contents of the texture subresource to a single value before
  2998. * any rendering is performed. It's fine to do an empty render pass using
  2999. * SDL_GPU_STOREOP_STORE to clear a texture, but in general it's better to
  3000. * think of clearing not as an independent operation but as something that's
  3001. * done as the beginning of a render pass.
  3002. *
  3003. * \param command_buffer a command buffer.
  3004. * \param color_target_infos an array of texture subresources with
  3005. * corresponding clear values and load/store ops.
  3006. * \param num_color_targets the number of color targets in the
  3007. * color_target_infos array.
  3008. * \param depth_stencil_target_info a texture subresource with corresponding
  3009. * clear value and load/store ops, may be
  3010. * NULL.
  3011. * \returns a render pass handle.
  3012. *
  3013. * \since This function is available since SDL 3.2.0.
  3014. *
  3015. * \sa SDL_EndGPURenderPass
  3016. */
  3017. extern SDL_DECLSPEC SDL_GPURenderPass * SDLCALL SDL_BeginGPURenderPass(
  3018. SDL_GPUCommandBuffer *command_buffer,
  3019. const SDL_GPUColorTargetInfo *color_target_infos,
  3020. Uint32 num_color_targets,
  3021. const SDL_GPUDepthStencilTargetInfo *depth_stencil_target_info);
  3022. /**
  3023. * Binds a graphics pipeline on a render pass to be used in rendering.
  3024. *
  3025. * A graphics pipeline must be bound before making any draw calls.
  3026. *
  3027. * \param render_pass a render pass handle.
  3028. * \param graphics_pipeline the graphics pipeline to bind.
  3029. *
  3030. * \since This function is available since SDL 3.2.0.
  3031. */
  3032. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUGraphicsPipeline(
  3033. SDL_GPURenderPass *render_pass,
  3034. SDL_GPUGraphicsPipeline *graphics_pipeline);
  3035. /**
  3036. * Sets the current viewport state on a command buffer.
  3037. *
  3038. * \param render_pass a render pass handle.
  3039. * \param viewport the viewport to set.
  3040. *
  3041. * \since This function is available since SDL 3.2.0.
  3042. */
  3043. extern SDL_DECLSPEC void SDLCALL SDL_SetGPUViewport(
  3044. SDL_GPURenderPass *render_pass,
  3045. const SDL_GPUViewport *viewport);
  3046. /**
  3047. * Sets the current scissor state on a command buffer.
  3048. *
  3049. * \param render_pass a render pass handle.
  3050. * \param scissor the scissor area to set.
  3051. *
  3052. * \since This function is available since SDL 3.2.0.
  3053. */
  3054. extern SDL_DECLSPEC void SDLCALL SDL_SetGPUScissor(
  3055. SDL_GPURenderPass *render_pass,
  3056. const SDL_Rect *scissor);
  3057. /**
  3058. * Sets the current blend constants on a command buffer.
  3059. *
  3060. * \param render_pass a render pass handle.
  3061. * \param blend_constants the blend constant color.
  3062. *
  3063. * \since This function is available since SDL 3.2.0.
  3064. *
  3065. * \sa SDL_GPU_BLENDFACTOR_CONSTANT_COLOR
  3066. * \sa SDL_GPU_BLENDFACTOR_ONE_MINUS_CONSTANT_COLOR
  3067. */
  3068. extern SDL_DECLSPEC void SDLCALL SDL_SetGPUBlendConstants(
  3069. SDL_GPURenderPass *render_pass,
  3070. SDL_FColor blend_constants);
  3071. /**
  3072. * Sets the current stencil reference value on a command buffer.
  3073. *
  3074. * \param render_pass a render pass handle.
  3075. * \param reference the stencil reference value to set.
  3076. *
  3077. * \since This function is available since SDL 3.2.0.
  3078. */
  3079. extern SDL_DECLSPEC void SDLCALL SDL_SetGPUStencilReference(
  3080. SDL_GPURenderPass *render_pass,
  3081. Uint8 reference);
  3082. /**
  3083. * Binds vertex buffers on a command buffer for use with subsequent draw
  3084. * calls.
  3085. *
  3086. * \param render_pass a render pass handle.
  3087. * \param first_slot the vertex buffer slot to begin binding from.
  3088. * \param bindings an array of SDL_GPUBufferBinding structs containing vertex
  3089. * buffers and offset values.
  3090. * \param num_bindings the number of bindings in the bindings array.
  3091. *
  3092. * \since This function is available since SDL 3.2.0.
  3093. */
  3094. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUVertexBuffers(
  3095. SDL_GPURenderPass *render_pass,
  3096. Uint32 first_slot,
  3097. const SDL_GPUBufferBinding *bindings,
  3098. Uint32 num_bindings);
  3099. /**
  3100. * Binds an index buffer on a command buffer for use with subsequent draw
  3101. * calls.
  3102. *
  3103. * \param render_pass a render pass handle.
  3104. * \param binding a pointer to a struct containing an index buffer and offset.
  3105. * \param index_element_size whether the index values in the buffer are 16- or
  3106. * 32-bit.
  3107. *
  3108. * \since This function is available since SDL 3.2.0.
  3109. */
  3110. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUIndexBuffer(
  3111. SDL_GPURenderPass *render_pass,
  3112. const SDL_GPUBufferBinding *binding,
  3113. SDL_GPUIndexElementSize index_element_size);
  3114. /**
  3115. * Binds texture-sampler pairs for use on the vertex shader.
  3116. *
  3117. * The textures must have been created with SDL_GPU_TEXTUREUSAGE_SAMPLER.
  3118. *
  3119. * Be sure your shader is set up according to the requirements documented in
  3120. * SDL_CreateGPUShader().
  3121. *
  3122. * \param render_pass a render pass handle.
  3123. * \param first_slot the vertex sampler slot to begin binding from.
  3124. * \param texture_sampler_bindings an array of texture-sampler binding
  3125. * structs.
  3126. * \param num_bindings the number of texture-sampler pairs to bind from the
  3127. * array.
  3128. *
  3129. * \since This function is available since SDL 3.2.0.
  3130. *
  3131. * \sa SDL_CreateGPUShader
  3132. */
  3133. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUVertexSamplers(
  3134. SDL_GPURenderPass *render_pass,
  3135. Uint32 first_slot,
  3136. const SDL_GPUTextureSamplerBinding *texture_sampler_bindings,
  3137. Uint32 num_bindings);
  3138. /**
  3139. * Binds storage textures for use on the vertex shader.
  3140. *
  3141. * These textures must have been created with
  3142. * SDL_GPU_TEXTUREUSAGE_GRAPHICS_STORAGE_READ.
  3143. *
  3144. * Be sure your shader is set up according to the requirements documented in
  3145. * SDL_CreateGPUShader().
  3146. *
  3147. * \param render_pass a render pass handle.
  3148. * \param first_slot the vertex storage texture slot to begin binding from.
  3149. * \param storage_textures an array of storage textures.
  3150. * \param num_bindings the number of storage texture to bind from the array.
  3151. *
  3152. * \since This function is available since SDL 3.2.0.
  3153. *
  3154. * \sa SDL_CreateGPUShader
  3155. */
  3156. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUVertexStorageTextures(
  3157. SDL_GPURenderPass *render_pass,
  3158. Uint32 first_slot,
  3159. SDL_GPUTexture *const *storage_textures,
  3160. Uint32 num_bindings);
  3161. /**
  3162. * Binds storage buffers for use on the vertex shader.
  3163. *
  3164. * These buffers must have been created with
  3165. * SDL_GPU_BUFFERUSAGE_GRAPHICS_STORAGE_READ.
  3166. *
  3167. * Be sure your shader is set up according to the requirements documented in
  3168. * SDL_CreateGPUShader().
  3169. *
  3170. * \param render_pass a render pass handle.
  3171. * \param first_slot the vertex storage buffer slot to begin binding from.
  3172. * \param storage_buffers an array of buffers.
  3173. * \param num_bindings the number of buffers to bind from the array.
  3174. *
  3175. * \since This function is available since SDL 3.2.0.
  3176. *
  3177. * \sa SDL_CreateGPUShader
  3178. */
  3179. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUVertexStorageBuffers(
  3180. SDL_GPURenderPass *render_pass,
  3181. Uint32 first_slot,
  3182. SDL_GPUBuffer *const *storage_buffers,
  3183. Uint32 num_bindings);
  3184. /**
  3185. * Binds texture-sampler pairs for use on the fragment shader.
  3186. *
  3187. * The textures must have been created with SDL_GPU_TEXTUREUSAGE_SAMPLER.
  3188. *
  3189. * Be sure your shader is set up according to the requirements documented in
  3190. * SDL_CreateGPUShader().
  3191. *
  3192. * \param render_pass a render pass handle.
  3193. * \param first_slot the fragment sampler slot to begin binding from.
  3194. * \param texture_sampler_bindings an array of texture-sampler binding
  3195. * structs.
  3196. * \param num_bindings the number of texture-sampler pairs to bind from the
  3197. * array.
  3198. *
  3199. * \since This function is available since SDL 3.2.0.
  3200. *
  3201. * \sa SDL_CreateGPUShader
  3202. */
  3203. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUFragmentSamplers(
  3204. SDL_GPURenderPass *render_pass,
  3205. Uint32 first_slot,
  3206. const SDL_GPUTextureSamplerBinding *texture_sampler_bindings,
  3207. Uint32 num_bindings);
  3208. /**
  3209. * Binds storage textures for use on the fragment shader.
  3210. *
  3211. * These textures must have been created with
  3212. * SDL_GPU_TEXTUREUSAGE_GRAPHICS_STORAGE_READ.
  3213. *
  3214. * Be sure your shader is set up according to the requirements documented in
  3215. * SDL_CreateGPUShader().
  3216. *
  3217. * \param render_pass a render pass handle.
  3218. * \param first_slot the fragment storage texture slot to begin binding from.
  3219. * \param storage_textures an array of storage textures.
  3220. * \param num_bindings the number of storage textures to bind from the array.
  3221. *
  3222. * \since This function is available since SDL 3.2.0.
  3223. *
  3224. * \sa SDL_CreateGPUShader
  3225. */
  3226. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUFragmentStorageTextures(
  3227. SDL_GPURenderPass *render_pass,
  3228. Uint32 first_slot,
  3229. SDL_GPUTexture *const *storage_textures,
  3230. Uint32 num_bindings);
  3231. /**
  3232. * Binds storage buffers for use on the fragment shader.
  3233. *
  3234. * These buffers must have been created with
  3235. * SDL_GPU_BUFFERUSAGE_GRAPHICS_STORAGE_READ.
  3236. *
  3237. * Be sure your shader is set up according to the requirements documented in
  3238. * SDL_CreateGPUShader().
  3239. *
  3240. * \param render_pass a render pass handle.
  3241. * \param first_slot the fragment storage buffer slot to begin binding from.
  3242. * \param storage_buffers an array of storage buffers.
  3243. * \param num_bindings the number of storage buffers to bind from the array.
  3244. *
  3245. * \since This function is available since SDL 3.2.0.
  3246. *
  3247. * \sa SDL_CreateGPUShader
  3248. */
  3249. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUFragmentStorageBuffers(
  3250. SDL_GPURenderPass *render_pass,
  3251. Uint32 first_slot,
  3252. SDL_GPUBuffer *const *storage_buffers,
  3253. Uint32 num_bindings);
  3254. /* Drawing */
  3255. /**
  3256. * Draws data using bound graphics state with an index buffer and instancing
  3257. * enabled.
  3258. *
  3259. * You must not call this function before binding a graphics pipeline.
  3260. *
  3261. * Note that the `first_vertex` and `first_instance` parameters are NOT
  3262. * compatible with built-in vertex/instance ID variables in shaders (for
  3263. * example, SV_VertexID); GPU APIs and shader languages do not define these
  3264. * built-in variables consistently, so if your shader depends on them, the
  3265. * only way to keep behavior consistent and portable is to always pass 0 for
  3266. * the correlating parameter in the draw calls.
  3267. *
  3268. * \param render_pass a render pass handle.
  3269. * \param num_indices the number of indices to draw per instance.
  3270. * \param num_instances the number of instances to draw.
  3271. * \param first_index the starting index within the index buffer.
  3272. * \param vertex_offset value added to vertex index before indexing into the
  3273. * vertex buffer.
  3274. * \param first_instance the ID of the first instance to draw.
  3275. *
  3276. * \since This function is available since SDL 3.2.0.
  3277. */
  3278. extern SDL_DECLSPEC void SDLCALL SDL_DrawGPUIndexedPrimitives(
  3279. SDL_GPURenderPass *render_pass,
  3280. Uint32 num_indices,
  3281. Uint32 num_instances,
  3282. Uint32 first_index,
  3283. Sint32 vertex_offset,
  3284. Uint32 first_instance);
  3285. /**
  3286. * Draws data using bound graphics state.
  3287. *
  3288. * You must not call this function before binding a graphics pipeline.
  3289. *
  3290. * Note that the `first_vertex` and `first_instance` parameters are NOT
  3291. * compatible with built-in vertex/instance ID variables in shaders (for
  3292. * example, SV_VertexID); GPU APIs and shader languages do not define these
  3293. * built-in variables consistently, so if your shader depends on them, the
  3294. * only way to keep behavior consistent and portable is to always pass 0 for
  3295. * the correlating parameter in the draw calls.
  3296. *
  3297. * \param render_pass a render pass handle.
  3298. * \param num_vertices the number of vertices to draw.
  3299. * \param num_instances the number of instances that will be drawn.
  3300. * \param first_vertex the index of the first vertex to draw.
  3301. * \param first_instance the ID of the first instance to draw.
  3302. *
  3303. * \since This function is available since SDL 3.2.0.
  3304. */
  3305. extern SDL_DECLSPEC void SDLCALL SDL_DrawGPUPrimitives(
  3306. SDL_GPURenderPass *render_pass,
  3307. Uint32 num_vertices,
  3308. Uint32 num_instances,
  3309. Uint32 first_vertex,
  3310. Uint32 first_instance);
  3311. /**
  3312. * Draws data using bound graphics state and with draw parameters set from a
  3313. * buffer.
  3314. *
  3315. * The buffer must consist of tightly-packed draw parameter sets that each
  3316. * match the layout of SDL_GPUIndirectDrawCommand. You must not call this
  3317. * function before binding a graphics pipeline.
  3318. *
  3319. * \param render_pass a render pass handle.
  3320. * \param buffer a buffer containing draw parameters.
  3321. * \param offset the offset to start reading from the draw buffer.
  3322. * \param draw_count the number of draw parameter sets that should be read
  3323. * from the draw buffer.
  3324. *
  3325. * \since This function is available since SDL 3.2.0.
  3326. */
  3327. extern SDL_DECLSPEC void SDLCALL SDL_DrawGPUPrimitivesIndirect(
  3328. SDL_GPURenderPass *render_pass,
  3329. SDL_GPUBuffer *buffer,
  3330. Uint32 offset,
  3331. Uint32 draw_count);
  3332. /**
  3333. * Draws data using bound graphics state with an index buffer enabled and with
  3334. * draw parameters set from a buffer.
  3335. *
  3336. * The buffer must consist of tightly-packed draw parameter sets that each
  3337. * match the layout of SDL_GPUIndexedIndirectDrawCommand. You must not call
  3338. * this function before binding a graphics pipeline.
  3339. *
  3340. * \param render_pass a render pass handle.
  3341. * \param buffer a buffer containing draw parameters.
  3342. * \param offset the offset to start reading from the draw buffer.
  3343. * \param draw_count the number of draw parameter sets that should be read
  3344. * from the draw buffer.
  3345. *
  3346. * \since This function is available since SDL 3.2.0.
  3347. */
  3348. extern SDL_DECLSPEC void SDLCALL SDL_DrawGPUIndexedPrimitivesIndirect(
  3349. SDL_GPURenderPass *render_pass,
  3350. SDL_GPUBuffer *buffer,
  3351. Uint32 offset,
  3352. Uint32 draw_count);
  3353. /**
  3354. * Ends the given render pass.
  3355. *
  3356. * All bound graphics state on the render pass command buffer is unset. The
  3357. * render pass handle is now invalid.
  3358. *
  3359. * \param render_pass a render pass handle.
  3360. *
  3361. * \since This function is available since SDL 3.2.0.
  3362. */
  3363. extern SDL_DECLSPEC void SDLCALL SDL_EndGPURenderPass(
  3364. SDL_GPURenderPass *render_pass);
  3365. /* Compute Pass */
  3366. /**
  3367. * Begins a compute pass on a command buffer.
  3368. *
  3369. * A compute pass is defined by a set of texture subresources and buffers that
  3370. * may be written to by compute pipelines. These textures and buffers must
  3371. * have been created with the COMPUTE_STORAGE_WRITE bit or the
  3372. * COMPUTE_STORAGE_SIMULTANEOUS_READ_WRITE bit. If you do not create a texture
  3373. * with COMPUTE_STORAGE_SIMULTANEOUS_READ_WRITE, you must not read from the
  3374. * texture in the compute pass. All operations related to compute pipelines
  3375. * must take place inside of a compute pass. You must not begin another
  3376. * compute pass, or a render pass or copy pass before ending the compute pass.
  3377. *
  3378. * A VERY IMPORTANT NOTE - Reads and writes in compute passes are NOT
  3379. * implicitly synchronized. This means you may cause data races by both
  3380. * reading and writing a resource region in a compute pass, or by writing
  3381. * multiple times to a resource region. If your compute work depends on
  3382. * reading the completed output from a previous dispatch, you MUST end the
  3383. * current compute pass and begin a new one before you can safely access the
  3384. * data. Otherwise you will receive unexpected results. Reading and writing a
  3385. * texture in the same compute pass is only supported by specific texture
  3386. * formats. Make sure you check the format support!
  3387. *
  3388. * \param command_buffer a command buffer.
  3389. * \param storage_texture_bindings an array of writeable storage texture
  3390. * binding structs.
  3391. * \param num_storage_texture_bindings the number of storage textures to bind
  3392. * from the array.
  3393. * \param storage_buffer_bindings an array of writeable storage buffer binding
  3394. * structs.
  3395. * \param num_storage_buffer_bindings the number of storage buffers to bind
  3396. * from the array.
  3397. * \returns a compute pass handle.
  3398. *
  3399. * \since This function is available since SDL 3.2.0.
  3400. *
  3401. * \sa SDL_EndGPUComputePass
  3402. */
  3403. extern SDL_DECLSPEC SDL_GPUComputePass * SDLCALL SDL_BeginGPUComputePass(
  3404. SDL_GPUCommandBuffer *command_buffer,
  3405. const SDL_GPUStorageTextureReadWriteBinding *storage_texture_bindings,
  3406. Uint32 num_storage_texture_bindings,
  3407. const SDL_GPUStorageBufferReadWriteBinding *storage_buffer_bindings,
  3408. Uint32 num_storage_buffer_bindings);
  3409. /**
  3410. * Binds a compute pipeline on a command buffer for use in compute dispatch.
  3411. *
  3412. * \param compute_pass a compute pass handle.
  3413. * \param compute_pipeline a compute pipeline to bind.
  3414. *
  3415. * \since This function is available since SDL 3.2.0.
  3416. */
  3417. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUComputePipeline(
  3418. SDL_GPUComputePass *compute_pass,
  3419. SDL_GPUComputePipeline *compute_pipeline);
  3420. /**
  3421. * Binds texture-sampler pairs for use on the compute shader.
  3422. *
  3423. * The textures must have been created with SDL_GPU_TEXTUREUSAGE_SAMPLER.
  3424. *
  3425. * Be sure your shader is set up according to the requirements documented in
  3426. * SDL_CreateGPUShader().
  3427. *
  3428. * \param compute_pass a compute pass handle.
  3429. * \param first_slot the compute sampler slot to begin binding from.
  3430. * \param texture_sampler_bindings an array of texture-sampler binding
  3431. * structs.
  3432. * \param num_bindings the number of texture-sampler bindings to bind from the
  3433. * array.
  3434. *
  3435. * \since This function is available since SDL 3.2.0.
  3436. *
  3437. * \sa SDL_CreateGPUShader
  3438. */
  3439. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUComputeSamplers(
  3440. SDL_GPUComputePass *compute_pass,
  3441. Uint32 first_slot,
  3442. const SDL_GPUTextureSamplerBinding *texture_sampler_bindings,
  3443. Uint32 num_bindings);
  3444. /**
  3445. * Binds storage textures as readonly for use on the compute pipeline.
  3446. *
  3447. * These textures must have been created with
  3448. * SDL_GPU_TEXTUREUSAGE_COMPUTE_STORAGE_READ.
  3449. *
  3450. * Be sure your shader is set up according to the requirements documented in
  3451. * SDL_CreateGPUShader().
  3452. *
  3453. * \param compute_pass a compute pass handle.
  3454. * \param first_slot the compute storage texture slot to begin binding from.
  3455. * \param storage_textures an array of storage textures.
  3456. * \param num_bindings the number of storage textures to bind from the array.
  3457. *
  3458. * \since This function is available since SDL 3.2.0.
  3459. *
  3460. * \sa SDL_CreateGPUShader
  3461. */
  3462. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUComputeStorageTextures(
  3463. SDL_GPUComputePass *compute_pass,
  3464. Uint32 first_slot,
  3465. SDL_GPUTexture *const *storage_textures,
  3466. Uint32 num_bindings);
  3467. /**
  3468. * Binds storage buffers as readonly for use on the compute pipeline.
  3469. *
  3470. * These buffers must have been created with
  3471. * SDL_GPU_BUFFERUSAGE_COMPUTE_STORAGE_READ.
  3472. *
  3473. * Be sure your shader is set up according to the requirements documented in
  3474. * SDL_CreateGPUShader().
  3475. *
  3476. * \param compute_pass a compute pass handle.
  3477. * \param first_slot the compute storage buffer slot to begin binding from.
  3478. * \param storage_buffers an array of storage buffer binding structs.
  3479. * \param num_bindings the number of storage buffers to bind from the array.
  3480. *
  3481. * \since This function is available since SDL 3.2.0.
  3482. *
  3483. * \sa SDL_CreateGPUShader
  3484. */
  3485. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUComputeStorageBuffers(
  3486. SDL_GPUComputePass *compute_pass,
  3487. Uint32 first_slot,
  3488. SDL_GPUBuffer *const *storage_buffers,
  3489. Uint32 num_bindings);
  3490. /**
  3491. * Dispatches compute work.
  3492. *
  3493. * You must not call this function before binding a compute pipeline.
  3494. *
  3495. * A VERY IMPORTANT NOTE If you dispatch multiple times in a compute pass, and
  3496. * the dispatches write to the same resource region as each other, there is no
  3497. * guarantee of which order the writes will occur. If the write order matters,
  3498. * you MUST end the compute pass and begin another one.
  3499. *
  3500. * \param compute_pass a compute pass handle.
  3501. * \param groupcount_x number of local workgroups to dispatch in the X
  3502. * dimension.
  3503. * \param groupcount_y number of local workgroups to dispatch in the Y
  3504. * dimension.
  3505. * \param groupcount_z number of local workgroups to dispatch in the Z
  3506. * dimension.
  3507. *
  3508. * \since This function is available since SDL 3.2.0.
  3509. */
  3510. extern SDL_DECLSPEC void SDLCALL SDL_DispatchGPUCompute(
  3511. SDL_GPUComputePass *compute_pass,
  3512. Uint32 groupcount_x,
  3513. Uint32 groupcount_y,
  3514. Uint32 groupcount_z);
  3515. /**
  3516. * Dispatches compute work with parameters set from a buffer.
  3517. *
  3518. * The buffer layout should match the layout of
  3519. * SDL_GPUIndirectDispatchCommand. You must not call this function before
  3520. * binding a compute pipeline.
  3521. *
  3522. * A VERY IMPORTANT NOTE If you dispatch multiple times in a compute pass, and
  3523. * the dispatches write to the same resource region as each other, there is no
  3524. * guarantee of which order the writes will occur. If the write order matters,
  3525. * you MUST end the compute pass and begin another one.
  3526. *
  3527. * \param compute_pass a compute pass handle.
  3528. * \param buffer a buffer containing dispatch parameters.
  3529. * \param offset the offset to start reading from the dispatch buffer.
  3530. *
  3531. * \since This function is available since SDL 3.2.0.
  3532. */
  3533. extern SDL_DECLSPEC void SDLCALL SDL_DispatchGPUComputeIndirect(
  3534. SDL_GPUComputePass *compute_pass,
  3535. SDL_GPUBuffer *buffer,
  3536. Uint32 offset);
  3537. /**
  3538. * Ends the current compute pass.
  3539. *
  3540. * All bound compute state on the command buffer is unset. The compute pass
  3541. * handle is now invalid.
  3542. *
  3543. * \param compute_pass a compute pass handle.
  3544. *
  3545. * \since This function is available since SDL 3.2.0.
  3546. */
  3547. extern SDL_DECLSPEC void SDLCALL SDL_EndGPUComputePass(
  3548. SDL_GPUComputePass *compute_pass);
  3549. /* TransferBuffer Data */
  3550. /**
  3551. * Maps a transfer buffer into application address space.
  3552. *
  3553. * You must unmap the transfer buffer before encoding upload commands. The
  3554. * memory is owned by the graphics driver - do NOT call SDL_free() on the
  3555. * returned pointer.
  3556. *
  3557. * \param device a GPU context.
  3558. * \param transfer_buffer a transfer buffer.
  3559. * \param cycle if true, cycles the transfer buffer if it is already bound.
  3560. * \returns the address of the mapped transfer buffer memory, or NULL on
  3561. * failure; call SDL_GetError() for more information.
  3562. *
  3563. * \since This function is available since SDL 3.2.0.
  3564. */
  3565. extern SDL_DECLSPEC void * SDLCALL SDL_MapGPUTransferBuffer(
  3566. SDL_GPUDevice *device,
  3567. SDL_GPUTransferBuffer *transfer_buffer,
  3568. bool cycle);
  3569. /**
  3570. * Unmaps a previously mapped transfer buffer.
  3571. *
  3572. * \param device a GPU context.
  3573. * \param transfer_buffer a previously mapped transfer buffer.
  3574. *
  3575. * \since This function is available since SDL 3.2.0.
  3576. */
  3577. extern SDL_DECLSPEC void SDLCALL SDL_UnmapGPUTransferBuffer(
  3578. SDL_GPUDevice *device,
  3579. SDL_GPUTransferBuffer *transfer_buffer);
  3580. /* Copy Pass */
  3581. /**
  3582. * Begins a copy pass on a command buffer.
  3583. *
  3584. * All operations related to copying to or from buffers or textures take place
  3585. * inside a copy pass. You must not begin another copy pass, or a render pass
  3586. * or compute pass before ending the copy pass.
  3587. *
  3588. * \param command_buffer a command buffer.
  3589. * \returns a copy pass handle.
  3590. *
  3591. * \since This function is available since SDL 3.2.0.
  3592. *
  3593. * \sa SDL_EndGPUCopyPass
  3594. */
  3595. extern SDL_DECLSPEC SDL_GPUCopyPass * SDLCALL SDL_BeginGPUCopyPass(
  3596. SDL_GPUCommandBuffer *command_buffer);
  3597. /**
  3598. * Uploads data from a transfer buffer to a texture.
  3599. *
  3600. * The upload occurs on the GPU timeline. You may assume that the upload has
  3601. * finished in subsequent commands.
  3602. *
  3603. * You must align the data in the transfer buffer to a multiple of the texel
  3604. * size of the texture format.
  3605. *
  3606. * \param copy_pass a copy pass handle.
  3607. * \param source the source transfer buffer with image layout information.
  3608. * \param destination the destination texture region.
  3609. * \param cycle if true, cycles the texture if the texture is bound, otherwise
  3610. * overwrites the data.
  3611. *
  3612. * \since This function is available since SDL 3.2.0.
  3613. */
  3614. extern SDL_DECLSPEC void SDLCALL SDL_UploadToGPUTexture(
  3615. SDL_GPUCopyPass *copy_pass,
  3616. const SDL_GPUTextureTransferInfo *source,
  3617. const SDL_GPUTextureRegion *destination,
  3618. bool cycle);
  3619. /**
  3620. * Uploads data from a transfer buffer to a buffer.
  3621. *
  3622. * The upload occurs on the GPU timeline. You may assume that the upload has
  3623. * finished in subsequent commands.
  3624. *
  3625. * \param copy_pass a copy pass handle.
  3626. * \param source the source transfer buffer with offset.
  3627. * \param destination the destination buffer with offset and size.
  3628. * \param cycle if true, cycles the buffer if it is already bound, otherwise
  3629. * overwrites the data.
  3630. *
  3631. * \since This function is available since SDL 3.2.0.
  3632. */
  3633. extern SDL_DECLSPEC void SDLCALL SDL_UploadToGPUBuffer(
  3634. SDL_GPUCopyPass *copy_pass,
  3635. const SDL_GPUTransferBufferLocation *source,
  3636. const SDL_GPUBufferRegion *destination,
  3637. bool cycle);
  3638. /**
  3639. * Performs a texture-to-texture copy.
  3640. *
  3641. * This copy occurs on the GPU timeline. You may assume the copy has finished
  3642. * in subsequent commands.
  3643. *
  3644. * \param copy_pass a copy pass handle.
  3645. * \param source a source texture region.
  3646. * \param destination a destination texture region.
  3647. * \param w the width of the region to copy.
  3648. * \param h the height of the region to copy.
  3649. * \param d the depth of the region to copy.
  3650. * \param cycle if true, cycles the destination texture if the destination
  3651. * texture is bound, otherwise overwrites the data.
  3652. *
  3653. * \since This function is available since SDL 3.2.0.
  3654. */
  3655. extern SDL_DECLSPEC void SDLCALL SDL_CopyGPUTextureToTexture(
  3656. SDL_GPUCopyPass *copy_pass,
  3657. const SDL_GPUTextureLocation *source,
  3658. const SDL_GPUTextureLocation *destination,
  3659. Uint32 w,
  3660. Uint32 h,
  3661. Uint32 d,
  3662. bool cycle);
  3663. /**
  3664. * Performs a buffer-to-buffer copy.
  3665. *
  3666. * This copy occurs on the GPU timeline. You may assume the copy has finished
  3667. * in subsequent commands.
  3668. *
  3669. * \param copy_pass a copy pass handle.
  3670. * \param source the buffer and offset to copy from.
  3671. * \param destination the buffer and offset to copy to.
  3672. * \param size the length of the buffer to copy.
  3673. * \param cycle if true, cycles the destination buffer if it is already bound,
  3674. * otherwise overwrites the data.
  3675. *
  3676. * \since This function is available since SDL 3.2.0.
  3677. */
  3678. extern SDL_DECLSPEC void SDLCALL SDL_CopyGPUBufferToBuffer(
  3679. SDL_GPUCopyPass *copy_pass,
  3680. const SDL_GPUBufferLocation *source,
  3681. const SDL_GPUBufferLocation *destination,
  3682. Uint32 size,
  3683. bool cycle);
  3684. /**
  3685. * Copies data from a texture to a transfer buffer on the GPU timeline.
  3686. *
  3687. * This data is not guaranteed to be copied until the command buffer fence is
  3688. * signaled.
  3689. *
  3690. * \param copy_pass a copy pass handle.
  3691. * \param source the source texture region.
  3692. * \param destination the destination transfer buffer with image layout
  3693. * information.
  3694. *
  3695. * \since This function is available since SDL 3.2.0.
  3696. */
  3697. extern SDL_DECLSPEC void SDLCALL SDL_DownloadFromGPUTexture(
  3698. SDL_GPUCopyPass *copy_pass,
  3699. const SDL_GPUTextureRegion *source,
  3700. const SDL_GPUTextureTransferInfo *destination);
  3701. /**
  3702. * Copies data from a buffer to a transfer buffer on the GPU timeline.
  3703. *
  3704. * This data is not guaranteed to be copied until the command buffer fence is
  3705. * signaled.
  3706. *
  3707. * \param copy_pass a copy pass handle.
  3708. * \param source the source buffer with offset and size.
  3709. * \param destination the destination transfer buffer with offset.
  3710. *
  3711. * \since This function is available since SDL 3.2.0.
  3712. */
  3713. extern SDL_DECLSPEC void SDLCALL SDL_DownloadFromGPUBuffer(
  3714. SDL_GPUCopyPass *copy_pass,
  3715. const SDL_GPUBufferRegion *source,
  3716. const SDL_GPUTransferBufferLocation *destination);
  3717. /**
  3718. * Ends the current copy pass.
  3719. *
  3720. * \param copy_pass a copy pass handle.
  3721. *
  3722. * \since This function is available since SDL 3.2.0.
  3723. */
  3724. extern SDL_DECLSPEC void SDLCALL SDL_EndGPUCopyPass(
  3725. SDL_GPUCopyPass *copy_pass);
  3726. /**
  3727. * Generates mipmaps for the given texture.
  3728. *
  3729. * This function must not be called inside of any pass.
  3730. *
  3731. * \param command_buffer a command_buffer.
  3732. * \param texture a texture with more than 1 mip level.
  3733. *
  3734. * \since This function is available since SDL 3.2.0.
  3735. */
  3736. extern SDL_DECLSPEC void SDLCALL SDL_GenerateMipmapsForGPUTexture(
  3737. SDL_GPUCommandBuffer *command_buffer,
  3738. SDL_GPUTexture *texture);
  3739. /**
  3740. * Blits from a source texture region to a destination texture region.
  3741. *
  3742. * This function must not be called inside of any pass.
  3743. *
  3744. * \param command_buffer a command buffer.
  3745. * \param info the blit info struct containing the blit parameters.
  3746. *
  3747. * \since This function is available since SDL 3.2.0.
  3748. */
  3749. extern SDL_DECLSPEC void SDLCALL SDL_BlitGPUTexture(
  3750. SDL_GPUCommandBuffer *command_buffer,
  3751. const SDL_GPUBlitInfo *info);
  3752. /* Submission/Presentation */
  3753. /**
  3754. * Determines whether a swapchain composition is supported by the window.
  3755. *
  3756. * The window must be claimed before calling this function.
  3757. *
  3758. * \param device a GPU context.
  3759. * \param window an SDL_Window.
  3760. * \param swapchain_composition the swapchain composition to check.
  3761. * \returns true if supported, false if unsupported.
  3762. *
  3763. * \since This function is available since SDL 3.2.0.
  3764. *
  3765. * \sa SDL_ClaimWindowForGPUDevice
  3766. */
  3767. extern SDL_DECLSPEC bool SDLCALL SDL_WindowSupportsGPUSwapchainComposition(
  3768. SDL_GPUDevice *device,
  3769. SDL_Window *window,
  3770. SDL_GPUSwapchainComposition swapchain_composition);
  3771. /**
  3772. * Determines whether a presentation mode is supported by the window.
  3773. *
  3774. * The window must be claimed before calling this function.
  3775. *
  3776. * \param device a GPU context.
  3777. * \param window an SDL_Window.
  3778. * \param present_mode the presentation mode to check.
  3779. * \returns true if supported, false if unsupported.
  3780. *
  3781. * \since This function is available since SDL 3.2.0.
  3782. *
  3783. * \sa SDL_ClaimWindowForGPUDevice
  3784. */
  3785. extern SDL_DECLSPEC bool SDLCALL SDL_WindowSupportsGPUPresentMode(
  3786. SDL_GPUDevice *device,
  3787. SDL_Window *window,
  3788. SDL_GPUPresentMode present_mode);
  3789. /**
  3790. * Claims a window, creating a swapchain structure for it.
  3791. *
  3792. * This must be called before SDL_AcquireGPUSwapchainTexture is called using
  3793. * the window. You should only call this function from the thread that created
  3794. * the window.
  3795. *
  3796. * The swapchain will be created with SDL_GPU_SWAPCHAINCOMPOSITION_SDR and
  3797. * SDL_GPU_PRESENTMODE_VSYNC. If you want to have different swapchain
  3798. * parameters, you must call SDL_SetGPUSwapchainParameters after claiming the
  3799. * window.
  3800. *
  3801. * \param device a GPU context.
  3802. * \param window an SDL_Window.
  3803. * \returns true on success, or false on failure; call SDL_GetError() for more
  3804. * information.
  3805. *
  3806. * \threadsafety This function should only be called from the thread that
  3807. * created the window.
  3808. *
  3809. * \since This function is available since SDL 3.2.0.
  3810. *
  3811. * \sa SDL_WaitAndAcquireGPUSwapchainTexture
  3812. * \sa SDL_ReleaseWindowFromGPUDevice
  3813. * \sa SDL_WindowSupportsGPUPresentMode
  3814. * \sa SDL_WindowSupportsGPUSwapchainComposition
  3815. */
  3816. extern SDL_DECLSPEC bool SDLCALL SDL_ClaimWindowForGPUDevice(
  3817. SDL_GPUDevice *device,
  3818. SDL_Window *window);
  3819. /**
  3820. * Unclaims a window, destroying its swapchain structure.
  3821. *
  3822. * \param device a GPU context.
  3823. * \param window an SDL_Window that has been claimed.
  3824. *
  3825. * \since This function is available since SDL 3.2.0.
  3826. *
  3827. * \sa SDL_ClaimWindowForGPUDevice
  3828. */
  3829. extern SDL_DECLSPEC void SDLCALL SDL_ReleaseWindowFromGPUDevice(
  3830. SDL_GPUDevice *device,
  3831. SDL_Window *window);
  3832. /**
  3833. * Changes the swapchain parameters for the given claimed window.
  3834. *
  3835. * This function will fail if the requested present mode or swapchain
  3836. * composition are unsupported by the device. Check if the parameters are
  3837. * supported via SDL_WindowSupportsGPUPresentMode /
  3838. * SDL_WindowSupportsGPUSwapchainComposition prior to calling this function.
  3839. *
  3840. * SDL_GPU_PRESENTMODE_VSYNC with SDL_GPU_SWAPCHAINCOMPOSITION_SDR is always
  3841. * supported.
  3842. *
  3843. * \param device a GPU context.
  3844. * \param window an SDL_Window that has been claimed.
  3845. * \param swapchain_composition the desired composition of the swapchain.
  3846. * \param present_mode the desired present mode for the swapchain.
  3847. * \returns true if successful, false on error; call SDL_GetError() for more
  3848. * information.
  3849. *
  3850. * \since This function is available since SDL 3.2.0.
  3851. *
  3852. * \sa SDL_WindowSupportsGPUPresentMode
  3853. * \sa SDL_WindowSupportsGPUSwapchainComposition
  3854. */
  3855. extern SDL_DECLSPEC bool SDLCALL SDL_SetGPUSwapchainParameters(
  3856. SDL_GPUDevice *device,
  3857. SDL_Window *window,
  3858. SDL_GPUSwapchainComposition swapchain_composition,
  3859. SDL_GPUPresentMode present_mode);
  3860. /**
  3861. * Configures the maximum allowed number of frames in flight.
  3862. *
  3863. * The default value when the device is created is 2. This means that after
  3864. * you have submitted 2 frames for presentation, if the GPU has not finished
  3865. * working on the first frame, SDL_AcquireGPUSwapchainTexture() will fill the
  3866. * swapchain texture pointer with NULL, and
  3867. * SDL_WaitAndAcquireGPUSwapchainTexture() will block.
  3868. *
  3869. * Higher values increase throughput at the expense of visual latency. Lower
  3870. * values decrease visual latency at the expense of throughput.
  3871. *
  3872. * Note that calling this function will stall and flush the command queue to
  3873. * prevent synchronization issues.
  3874. *
  3875. * The minimum value of allowed frames in flight is 1, and the maximum is 3.
  3876. *
  3877. * \param device a GPU context.
  3878. * \param allowed_frames_in_flight the maximum number of frames that can be
  3879. * pending on the GPU.
  3880. * \returns true if successful, false on error; call SDL_GetError() for more
  3881. * information.
  3882. *
  3883. * \since This function is available since SDL 3.2.0.
  3884. */
  3885. extern SDL_DECLSPEC bool SDLCALL SDL_SetGPUAllowedFramesInFlight(
  3886. SDL_GPUDevice *device,
  3887. Uint32 allowed_frames_in_flight);
  3888. /**
  3889. * Obtains the texture format of the swapchain for the given window.
  3890. *
  3891. * Note that this format can change if the swapchain parameters change.
  3892. *
  3893. * \param device a GPU context.
  3894. * \param window an SDL_Window that has been claimed.
  3895. * \returns the texture format of the swapchain.
  3896. *
  3897. * \since This function is available since SDL 3.2.0.
  3898. */
  3899. extern SDL_DECLSPEC SDL_GPUTextureFormat SDLCALL SDL_GetGPUSwapchainTextureFormat(
  3900. SDL_GPUDevice *device,
  3901. SDL_Window *window);
  3902. /**
  3903. * Acquire a texture to use in presentation.
  3904. *
  3905. * When a swapchain texture is acquired on a command buffer, it will
  3906. * automatically be submitted for presentation when the command buffer is
  3907. * submitted. The swapchain texture should only be referenced by the command
  3908. * buffer used to acquire it.
  3909. *
  3910. * This function will fill the swapchain texture handle with NULL if too many
  3911. * frames are in flight. This is not an error. This NULL pointer should not be
  3912. * passed back into SDL. Instead, it should be considered as an indication to
  3913. * wait until the swapchain is available.
  3914. *
  3915. * If you use this function, it is possible to create a situation where many
  3916. * command buffers are allocated while the rendering context waits for the GPU
  3917. * to catch up, which will cause memory usage to grow. You should use
  3918. * SDL_WaitAndAcquireGPUSwapchainTexture() unless you know what you are doing
  3919. * with timing.
  3920. *
  3921. * The swapchain texture is managed by the implementation and must not be
  3922. * freed by the user. You MUST NOT call this function from any thread other
  3923. * than the one that created the window.
  3924. *
  3925. * \param command_buffer a command buffer.
  3926. * \param window a window that has been claimed.
  3927. * \param swapchain_texture a pointer filled in with a swapchain texture
  3928. * handle.
  3929. * \param swapchain_texture_width a pointer filled in with the swapchain
  3930. * texture width, may be NULL.
  3931. * \param swapchain_texture_height a pointer filled in with the swapchain
  3932. * texture height, may be NULL.
  3933. * \returns true on success, false on error; call SDL_GetError() for more
  3934. * information.
  3935. *
  3936. * \threadsafety This function should only be called from the thread that
  3937. * created the window.
  3938. *
  3939. * \since This function is available since SDL 3.2.0.
  3940. *
  3941. * \sa SDL_ClaimWindowForGPUDevice
  3942. * \sa SDL_SubmitGPUCommandBuffer
  3943. * \sa SDL_SubmitGPUCommandBufferAndAcquireFence
  3944. * \sa SDL_CancelGPUCommandBuffer
  3945. * \sa SDL_GetWindowSizeInPixels
  3946. * \sa SDL_WaitForGPUSwapchain
  3947. * \sa SDL_WaitAndAcquireGPUSwapchainTexture
  3948. * \sa SDL_SetGPUAllowedFramesInFlight
  3949. */
  3950. extern SDL_DECLSPEC bool SDLCALL SDL_AcquireGPUSwapchainTexture(
  3951. SDL_GPUCommandBuffer *command_buffer,
  3952. SDL_Window *window,
  3953. SDL_GPUTexture **swapchain_texture,
  3954. Uint32 *swapchain_texture_width,
  3955. Uint32 *swapchain_texture_height);
  3956. /**
  3957. * Blocks the thread until a swapchain texture is available to be acquired.
  3958. *
  3959. * \param device a GPU context.
  3960. * \param window a window that has been claimed.
  3961. * \returns true on success, false on failure; call SDL_GetError() for more
  3962. * information.
  3963. *
  3964. * \threadsafety This function should only be called from the thread that
  3965. * created the window.
  3966. *
  3967. * \since This function is available since SDL 3.2.0.
  3968. *
  3969. * \sa SDL_AcquireGPUSwapchainTexture
  3970. * \sa SDL_WaitAndAcquireGPUSwapchainTexture
  3971. * \sa SDL_SetGPUAllowedFramesInFlight
  3972. */
  3973. extern SDL_DECLSPEC bool SDLCALL SDL_WaitForGPUSwapchain(
  3974. SDL_GPUDevice *device,
  3975. SDL_Window *window);
  3976. /**
  3977. * Blocks the thread until a swapchain texture is available to be acquired,
  3978. * and then acquires it.
  3979. *
  3980. * When a swapchain texture is acquired on a command buffer, it will
  3981. * automatically be submitted for presentation when the command buffer is
  3982. * submitted. The swapchain texture should only be referenced by the command
  3983. * buffer used to acquire it. It is an error to call
  3984. * SDL_CancelGPUCommandBuffer() after a swapchain texture is acquired.
  3985. *
  3986. * This function can fill the swapchain texture handle with NULL in certain
  3987. * cases, for example if the window is minimized. This is not an error. You
  3988. * should always make sure to check whether the pointer is NULL before
  3989. * actually using it.
  3990. *
  3991. * The swapchain texture is managed by the implementation and must not be
  3992. * freed by the user. You MUST NOT call this function from any thread other
  3993. * than the one that created the window.
  3994. *
  3995. * The swapchain texture is write-only and cannot be used as a sampler or for
  3996. * another reading operation.
  3997. *
  3998. * \param command_buffer a command buffer.
  3999. * \param window a window that has been claimed.
  4000. * \param swapchain_texture a pointer filled in with a swapchain texture
  4001. * handle.
  4002. * \param swapchain_texture_width a pointer filled in with the swapchain
  4003. * texture width, may be NULL.
  4004. * \param swapchain_texture_height a pointer filled in with the swapchain
  4005. * texture height, may be NULL.
  4006. * \returns true on success, false on error; call SDL_GetError() for more
  4007. * information.
  4008. *
  4009. * \threadsafety This function should only be called from the thread that
  4010. * created the window.
  4011. *
  4012. * \since This function is available since SDL 3.2.0.
  4013. *
  4014. * \sa SDL_SubmitGPUCommandBuffer
  4015. * \sa SDL_SubmitGPUCommandBufferAndAcquireFence
  4016. * \sa SDL_AcquireGPUSwapchainTexture
  4017. */
  4018. extern SDL_DECLSPEC bool SDLCALL SDL_WaitAndAcquireGPUSwapchainTexture(
  4019. SDL_GPUCommandBuffer *command_buffer,
  4020. SDL_Window *window,
  4021. SDL_GPUTexture **swapchain_texture,
  4022. Uint32 *swapchain_texture_width,
  4023. Uint32 *swapchain_texture_height);
  4024. /**
  4025. * Submits a command buffer so its commands can be processed on the GPU.
  4026. *
  4027. * It is invalid to use the command buffer after this is called.
  4028. *
  4029. * This must be called from the thread the command buffer was acquired on.
  4030. *
  4031. * All commands in the submission are guaranteed to begin executing before any
  4032. * command in a subsequent submission begins executing.
  4033. *
  4034. * \param command_buffer a command buffer.
  4035. * \returns true on success, false on failure; call SDL_GetError() for more
  4036. * information.
  4037. *
  4038. * \since This function is available since SDL 3.2.0.
  4039. *
  4040. * \sa SDL_AcquireGPUCommandBuffer
  4041. * \sa SDL_WaitAndAcquireGPUSwapchainTexture
  4042. * \sa SDL_AcquireGPUSwapchainTexture
  4043. * \sa SDL_SubmitGPUCommandBufferAndAcquireFence
  4044. */
  4045. extern SDL_DECLSPEC bool SDLCALL SDL_SubmitGPUCommandBuffer(
  4046. SDL_GPUCommandBuffer *command_buffer);
  4047. /**
  4048. * Submits a command buffer so its commands can be processed on the GPU, and
  4049. * acquires a fence associated with the command buffer.
  4050. *
  4051. * You must release this fence when it is no longer needed or it will cause a
  4052. * leak. It is invalid to use the command buffer after this is called.
  4053. *
  4054. * This must be called from the thread the command buffer was acquired on.
  4055. *
  4056. * All commands in the submission are guaranteed to begin executing before any
  4057. * command in a subsequent submission begins executing.
  4058. *
  4059. * \param command_buffer a command buffer.
  4060. * \returns a fence associated with the command buffer, or NULL on failure;
  4061. * call SDL_GetError() for more information.
  4062. *
  4063. * \since This function is available since SDL 3.2.0.
  4064. *
  4065. * \sa SDL_AcquireGPUCommandBuffer
  4066. * \sa SDL_WaitAndAcquireGPUSwapchainTexture
  4067. * \sa SDL_AcquireGPUSwapchainTexture
  4068. * \sa SDL_SubmitGPUCommandBuffer
  4069. * \sa SDL_ReleaseGPUFence
  4070. */
  4071. extern SDL_DECLSPEC SDL_GPUFence * SDLCALL SDL_SubmitGPUCommandBufferAndAcquireFence(
  4072. SDL_GPUCommandBuffer *command_buffer);
  4073. /**
  4074. * Cancels a command buffer.
  4075. *
  4076. * None of the enqueued commands are executed.
  4077. *
  4078. * It is an error to call this function after a swapchain texture has been
  4079. * acquired.
  4080. *
  4081. * This must be called from the thread the command buffer was acquired on.
  4082. *
  4083. * You must not reference the command buffer after calling this function.
  4084. *
  4085. * \param command_buffer a command buffer.
  4086. * \returns true on success, false on error; call SDL_GetError() for more
  4087. * information.
  4088. *
  4089. * \since This function is available since SDL 3.2.0.
  4090. *
  4091. * \sa SDL_WaitAndAcquireGPUSwapchainTexture
  4092. * \sa SDL_AcquireGPUCommandBuffer
  4093. * \sa SDL_AcquireGPUSwapchainTexture
  4094. */
  4095. extern SDL_DECLSPEC bool SDLCALL SDL_CancelGPUCommandBuffer(
  4096. SDL_GPUCommandBuffer *command_buffer);
  4097. /**
  4098. * Blocks the thread until the GPU is completely idle.
  4099. *
  4100. * \param device a GPU context.
  4101. * \returns true on success, false on failure; call SDL_GetError() for more
  4102. * information.
  4103. *
  4104. * \since This function is available since SDL 3.2.0.
  4105. *
  4106. * \sa SDL_WaitForGPUFences
  4107. */
  4108. extern SDL_DECLSPEC bool SDLCALL SDL_WaitForGPUIdle(
  4109. SDL_GPUDevice *device);
  4110. /**
  4111. * Blocks the thread until the given fences are signaled.
  4112. *
  4113. * \param device a GPU context.
  4114. * \param wait_all if 0, wait for any fence to be signaled, if 1, wait for all
  4115. * fences to be signaled.
  4116. * \param fences an array of fences to wait on.
  4117. * \param num_fences the number of fences in the fences array.
  4118. * \returns true on success, false on failure; call SDL_GetError() for more
  4119. * information.
  4120. *
  4121. * \since This function is available since SDL 3.2.0.
  4122. *
  4123. * \sa SDL_SubmitGPUCommandBufferAndAcquireFence
  4124. * \sa SDL_WaitForGPUIdle
  4125. */
  4126. extern SDL_DECLSPEC bool SDLCALL SDL_WaitForGPUFences(
  4127. SDL_GPUDevice *device,
  4128. bool wait_all,
  4129. SDL_GPUFence *const *fences,
  4130. Uint32 num_fences);
  4131. /**
  4132. * Checks the status of a fence.
  4133. *
  4134. * \param device a GPU context.
  4135. * \param fence a fence.
  4136. * \returns true if the fence is signaled, false if it is not.
  4137. *
  4138. * \since This function is available since SDL 3.2.0.
  4139. *
  4140. * \sa SDL_SubmitGPUCommandBufferAndAcquireFence
  4141. */
  4142. extern SDL_DECLSPEC bool SDLCALL SDL_QueryGPUFence(
  4143. SDL_GPUDevice *device,
  4144. SDL_GPUFence *fence);
  4145. /**
  4146. * Releases a fence obtained from SDL_SubmitGPUCommandBufferAndAcquireFence.
  4147. *
  4148. * You must not reference the fence after calling this function.
  4149. *
  4150. * \param device a GPU context.
  4151. * \param fence a fence.
  4152. *
  4153. * \since This function is available since SDL 3.2.0.
  4154. *
  4155. * \sa SDL_SubmitGPUCommandBufferAndAcquireFence
  4156. */
  4157. extern SDL_DECLSPEC void SDLCALL SDL_ReleaseGPUFence(
  4158. SDL_GPUDevice *device,
  4159. SDL_GPUFence *fence);
  4160. /* Format Info */
  4161. /**
  4162. * Obtains the texel block size for a texture format.
  4163. *
  4164. * \param format the texture format you want to know the texel size of.
  4165. * \returns the texel block size of the texture format.
  4166. *
  4167. * \since This function is available since SDL 3.2.0.
  4168. *
  4169. * \sa SDL_UploadToGPUTexture
  4170. */
  4171. extern SDL_DECLSPEC Uint32 SDLCALL SDL_GPUTextureFormatTexelBlockSize(
  4172. SDL_GPUTextureFormat format);
  4173. /**
  4174. * Determines whether a texture format is supported for a given type and
  4175. * usage.
  4176. *
  4177. * \param device a GPU context.
  4178. * \param format the texture format to check.
  4179. * \param type the type of texture (2D, 3D, Cube).
  4180. * \param usage a bitmask of all usage scenarios to check.
  4181. * \returns whether the texture format is supported for this type and usage.
  4182. *
  4183. * \since This function is available since SDL 3.2.0.
  4184. */
  4185. extern SDL_DECLSPEC bool SDLCALL SDL_GPUTextureSupportsFormat(
  4186. SDL_GPUDevice *device,
  4187. SDL_GPUTextureFormat format,
  4188. SDL_GPUTextureType type,
  4189. SDL_GPUTextureUsageFlags usage);
  4190. /**
  4191. * Determines if a sample count for a texture format is supported.
  4192. *
  4193. * \param device a GPU context.
  4194. * \param format the texture format to check.
  4195. * \param sample_count the sample count to check.
  4196. * \returns whether the sample count is supported for this texture format.
  4197. *
  4198. * \since This function is available since SDL 3.2.0.
  4199. */
  4200. extern SDL_DECLSPEC bool SDLCALL SDL_GPUTextureSupportsSampleCount(
  4201. SDL_GPUDevice *device,
  4202. SDL_GPUTextureFormat format,
  4203. SDL_GPUSampleCount sample_count);
  4204. /**
  4205. * Calculate the size in bytes of a texture format with dimensions.
  4206. *
  4207. * \param format a texture format.
  4208. * \param width width in pixels.
  4209. * \param height height in pixels.
  4210. * \param depth_or_layer_count depth for 3D textures or layer count otherwise.
  4211. * \returns the size of a texture with this format and dimensions.
  4212. *
  4213. * \since This function is available since SDL 3.2.0.
  4214. */
  4215. extern SDL_DECLSPEC Uint32 SDLCALL SDL_CalculateGPUTextureFormatSize(
  4216. SDL_GPUTextureFormat format,
  4217. Uint32 width,
  4218. Uint32 height,
  4219. Uint32 depth_or_layer_count);
  4220. /**
  4221. * Get the SDL pixel format corresponding to a GPU texture format.
  4222. *
  4223. * \param format a texture format.
  4224. * \returns the corresponding pixel format, or SDL_PIXELFORMAT_UNKNOWN if
  4225. * there is no corresponding pixel format.
  4226. *
  4227. * \since This function is available since SDL 3.4.0.
  4228. */
  4229. extern SDL_DECLSPEC SDL_PixelFormat SDLCALL SDL_GetPixelFormatFromGPUTextureFormat(SDL_GPUTextureFormat format);
  4230. /**
  4231. * Get the GPU texture format corresponding to an SDL pixel format.
  4232. *
  4233. * \param format a pixel format.
  4234. * \returns the corresponding GPU texture format, or
  4235. * SDL_GPU_TEXTUREFORMAT_INVALID if there is no corresponding GPU
  4236. * texture format.
  4237. *
  4238. * \since This function is available since SDL 3.4.0.
  4239. */
  4240. extern SDL_DECLSPEC SDL_GPUTextureFormat SDLCALL SDL_GetGPUTextureFormatFromPixelFormat(SDL_PixelFormat format);
  4241. #ifdef SDL_PLATFORM_GDK
  4242. /**
  4243. * Call this to suspend GPU operation on Xbox when you receive the
  4244. * SDL_EVENT_DID_ENTER_BACKGROUND event.
  4245. *
  4246. * Do NOT call any SDL_GPU functions after calling this function! This must
  4247. * also be called before calling SDL_GDKSuspendComplete.
  4248. *
  4249. * \param device a GPU context.
  4250. *
  4251. * \since This function is available since SDL 3.2.0.
  4252. *
  4253. * \sa SDL_AddEventWatch
  4254. */
  4255. extern SDL_DECLSPEC void SDLCALL SDL_GDKSuspendGPU(SDL_GPUDevice *device);
  4256. /**
  4257. * Call this to resume GPU operation on Xbox when you receive the
  4258. * SDL_EVENT_WILL_ENTER_FOREGROUND event.
  4259. *
  4260. * When resuming, this function MUST be called before calling any other
  4261. * SDL_GPU functions.
  4262. *
  4263. * \param device a GPU context.
  4264. *
  4265. * \since This function is available since SDL 3.2.0.
  4266. *
  4267. * \sa SDL_AddEventWatch
  4268. */
  4269. extern SDL_DECLSPEC void SDLCALL SDL_GDKResumeGPU(SDL_GPUDevice *device);
  4270. #endif /* SDL_PLATFORM_GDK */
  4271. #ifdef __cplusplus
  4272. }
  4273. #endif /* __cplusplus */
  4274. #include <SDL3/SDL_close_code.h>
  4275. #endif /* SDL_gpu_h_ */