SDL_gpu.h 137 KB

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