SDL_gpu.h 164 KB

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