SDL_gpu.h 169 KB

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