SDL_gpu.h 164 KB

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