SDL_gpu.h 186 KB

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