SDL_gpu.h 158 KB

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