SDL_gpu.h 122 KB

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