SDL_gpu.h 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /* WIKI CATEGORY: GPU */
  19. /**
  20. * # CategoryGPU
  21. *
  22. * 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. typedef struct SDL_GPUDevice SDL_GPUDevice;
  38. typedef struct SDL_GPUBuffer SDL_GPUBuffer;
  39. typedef struct SDL_GPUTransferBuffer SDL_GPUTransferBuffer;
  40. typedef struct SDL_GPUTexture SDL_GPUTexture;
  41. typedef struct SDL_GPUSampler SDL_GPUSampler;
  42. typedef struct SDL_GPUShader SDL_GPUShader;
  43. typedef struct SDL_GPUComputePipeline SDL_GPUComputePipeline;
  44. typedef struct SDL_GPUGraphicsPipeline SDL_GPUGraphicsPipeline;
  45. typedef struct SDL_GPUCommandBuffer SDL_GPUCommandBuffer;
  46. typedef struct SDL_GPURenderPass SDL_GPURenderPass;
  47. typedef struct SDL_GPUComputePass SDL_GPUComputePass;
  48. typedef struct SDL_GPUCopyPass SDL_GPUCopyPass;
  49. typedef struct SDL_GPUFence SDL_GPUFence;
  50. typedef enum SDL_GPUPrimitiveType
  51. {
  52. SDL_GPU_PRIMITIVETYPE_POINTLIST,
  53. SDL_GPU_PRIMITIVETYPE_LINELIST,
  54. SDL_GPU_PRIMITIVETYPE_LINESTRIP,
  55. SDL_GPU_PRIMITIVETYPE_TRIANGLELIST,
  56. SDL_GPU_PRIMITIVETYPE_TRIANGLESTRIP
  57. } SDL_GPUPrimitiveType;
  58. typedef enum SDL_GPULoadOp
  59. {
  60. SDL_GPU_LOADOP_LOAD,
  61. SDL_GPU_LOADOP_CLEAR,
  62. SDL_GPU_LOADOP_DONT_CARE
  63. } SDL_GPULoadOp;
  64. typedef enum SDL_GPUStoreOp
  65. {
  66. SDL_GPU_STOREOP_STORE,
  67. SDL_GPU_STOREOP_DONT_CARE
  68. } SDL_GPUStoreOp;
  69. typedef enum SDL_GPUIndexElementSize
  70. {
  71. SDL_GPU_INDEXELEMENTSIZE_16BIT,
  72. SDL_GPU_INDEXELEMENTSIZE_32BIT
  73. } SDL_GPUIndexElementSize;
  74. /* Texture format support varies depending on driver, hardware, and usage flags.
  75. * In general, you should use SDL_GPUTextureSupportsFormat to query if a format
  76. * is supported before using it. However, there are a few guaranteed formats.
  77. *
  78. * For SAMPLER usage, the following formats are universally supported:
  79. * - R8G8B8A8_UNORM
  80. * - B8G8R8A8_UNORM
  81. * - R8_UNORM
  82. * - R8_SNORM
  83. * - R8G8_UNORM
  84. * - R8G8_SNORM
  85. * - R8G8B8A8_SNORM
  86. * - R16_FLOAT
  87. * - R16G16_FLOAT
  88. * - R16G16B16A16_FLOAT
  89. * - R32_FLOAT
  90. * - R32G32_FLOAT
  91. * - R32G32B32A32_FLOAT
  92. * - R11G11B10_UFLOAT
  93. * - R8G8B8A8_UNORM_SRGB
  94. * - B8G8R8A8_UNORM_SRGB
  95. * - D16_UNORM
  96. *
  97. * For COLOR_TARGET usage, the following formats are universally supported:
  98. * - R8G8B8A8_UNORM
  99. * - B8G8R8A8_UNORM
  100. * - R8_UNORM
  101. * - R16_FLOAT
  102. * - R16G16_FLOAT
  103. * - R16G16B16A16_FLOAT
  104. * - R32_FLOAT
  105. * - R32G32_FLOAT
  106. * - R32G32B32A32_FLOAT
  107. * - R8_UINT
  108. * - R8G8_UINT
  109. * - R8G8B8A8_UINT
  110. * - R16_UINT
  111. * - R16G16_UINT
  112. * - R16G16B16A16_UINT
  113. * - R8_INT
  114. * - R8G8_INT
  115. * - R8G8B8A8_INT
  116. * - R16_INT
  117. * - R16G16_INT
  118. * - R16G16B16A16_INT
  119. * - R8G8B8A8_UNORM_SRGB
  120. * - B8G8R8A8_UNORM_SRGB
  121. *
  122. * For STORAGE usages, the following formats are universally supported:
  123. * - R8G8B8A8_UNORM
  124. * - R8G8B8A8_SNORM
  125. * - R16G16B16A16_FLOAT
  126. * - R32_FLOAT
  127. * - R32G32_FLOAT
  128. * - R32G32B32A32_FLOAT
  129. * - R8G8B8A8_UINT
  130. * - R16G16B16A16_UINT
  131. * - R8G8B8A8_INT
  132. * - R16G16B16A16_IINT
  133. *
  134. * For DEPTH_STENCIL_TARGET usage, the following formats are universally supported:
  135. * - D16_UNORM
  136. * - Either (but not necessarily both!) D24_UNORM or D32_SFLOAT
  137. * - Either (but not necessarily both!) D24_UNORM_S8_UINT or D32_SFLOAT_S8_UINT
  138. *
  139. * Unless D16_UNORM is sufficient for your purposes, always check which
  140. * of D24/D32 is supported before creating a depth-stencil texture!
  141. */
  142. typedef enum SDL_GPUTextureFormat
  143. {
  144. SDL_GPU_TEXTUREFORMAT_INVALID = -1,
  145. /* Unsigned Normalized Float Color Formats */
  146. SDL_GPU_TEXTUREFORMAT_A8_UNORM,
  147. SDL_GPU_TEXTUREFORMAT_R8_UNORM,
  148. SDL_GPU_TEXTUREFORMAT_R8G8_UNORM,
  149. SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM,
  150. SDL_GPU_TEXTUREFORMAT_R16_UNORM,
  151. SDL_GPU_TEXTUREFORMAT_R16G16_UNORM,
  152. SDL_GPU_TEXTUREFORMAT_R16G16B16A16_UNORM,
  153. SDL_GPU_TEXTUREFORMAT_R10G10B10A2_UNORM,
  154. SDL_GPU_TEXTUREFORMAT_B5G6R5_UNORM,
  155. SDL_GPU_TEXTUREFORMAT_B5G5R5A1_UNORM,
  156. SDL_GPU_TEXTUREFORMAT_B4G4R4A4_UNORM,
  157. SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM,
  158. /* Compressed Unsigned Normalized Float Color Formats */
  159. SDL_GPU_TEXTUREFORMAT_BC1_RGBA_UNORM,
  160. SDL_GPU_TEXTUREFORMAT_BC2_RGBA_UNORM,
  161. SDL_GPU_TEXTUREFORMAT_BC3_RGBA_UNORM,
  162. SDL_GPU_TEXTUREFORMAT_BC4_R_UNORM,
  163. SDL_GPU_TEXTUREFORMAT_BC5_RG_UNORM,
  164. SDL_GPU_TEXTUREFORMAT_BC7_RGBA_UNORM,
  165. /* Compressed Signed Float Color Formats */
  166. SDL_GPU_TEXTUREFORMAT_BC6H_RGB_FLOAT,
  167. /* Compressed Unsigned Float Color Formats */
  168. SDL_GPU_TEXTUREFORMAT_BC6H_RGB_UFLOAT,
  169. /* Signed Normalized Float Color Formats */
  170. SDL_GPU_TEXTUREFORMAT_R8_SNORM,
  171. SDL_GPU_TEXTUREFORMAT_R8G8_SNORM,
  172. SDL_GPU_TEXTUREFORMAT_R8G8B8A8_SNORM,
  173. SDL_GPU_TEXTUREFORMAT_R16_SNORM,
  174. SDL_GPU_TEXTUREFORMAT_R16G16_SNORM,
  175. SDL_GPU_TEXTUREFORMAT_R16G16B16A16_SNORM,
  176. /* Signed Float Color Formats */
  177. SDL_GPU_TEXTUREFORMAT_R16_FLOAT,
  178. SDL_GPU_TEXTUREFORMAT_R16G16_FLOAT,
  179. SDL_GPU_TEXTUREFORMAT_R16G16B16A16_FLOAT,
  180. SDL_GPU_TEXTUREFORMAT_R32_FLOAT,
  181. SDL_GPU_TEXTUREFORMAT_R32G32_FLOAT,
  182. SDL_GPU_TEXTUREFORMAT_R32G32B32A32_FLOAT,
  183. /* Unsigned Float Color Formats */
  184. SDL_GPU_TEXTUREFORMAT_R11G11B10_UFLOAT,
  185. /* Unsigned Integer Color Formats */
  186. SDL_GPU_TEXTUREFORMAT_R8_UINT,
  187. SDL_GPU_TEXTUREFORMAT_R8G8_UINT,
  188. SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UINT,
  189. SDL_GPU_TEXTUREFORMAT_R16_UINT,
  190. SDL_GPU_TEXTUREFORMAT_R16G16_UINT,
  191. SDL_GPU_TEXTUREFORMAT_R16G16B16A16_UINT,
  192. /* Signed Integer Color Formats */
  193. SDL_GPU_TEXTUREFORMAT_R8_INT,
  194. SDL_GPU_TEXTUREFORMAT_R8G8_INT,
  195. SDL_GPU_TEXTUREFORMAT_R8G8B8A8_INT,
  196. SDL_GPU_TEXTUREFORMAT_R16_INT,
  197. SDL_GPU_TEXTUREFORMAT_R16G16_INT,
  198. SDL_GPU_TEXTUREFORMAT_R16G16B16A16_INT,
  199. /* SRGB Unsigned Normalized Color Formats */
  200. SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM_SRGB,
  201. SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM_SRGB,
  202. /* Compressed SRGB Unsigned Normalized Color Formats */
  203. SDL_GPU_TEXTUREFORMAT_BC1_RGBA_UNORM_SRGB,
  204. SDL_GPU_TEXTUREFORMAT_BC2_RGBA_UNORM_SRGB,
  205. SDL_GPU_TEXTUREFORMAT_BC3_RGBA_UNORM_SRGB,
  206. SDL_GPU_TEXTUREFORMAT_BC7_RGBA_UNORM_SRGB,
  207. /* Depth Formats */
  208. SDL_GPU_TEXTUREFORMAT_D16_UNORM,
  209. SDL_GPU_TEXTUREFORMAT_D24_UNORM,
  210. SDL_GPU_TEXTUREFORMAT_D32_FLOAT,
  211. SDL_GPU_TEXTUREFORMAT_D24_UNORM_S8_UINT,
  212. SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT
  213. } SDL_GPUTextureFormat;
  214. typedef Uint32 SDL_GPUTextureUsageFlags;
  215. #define SDL_GPU_TEXTUREUSAGE_SAMPLER (1u << 0) /**< & if the texture supports sampling */
  216. #define SDL_GPU_TEXTUREUSAGE_COLOR_TARGET (1u << 1) /**< & if the texture is a color render target */
  217. #define SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET (1u << 2) /**< & if the texture is a depth stencil target */
  218. #define SDL_GPU_TEXTUREUSAGE_GRAPHICS_STORAGE_READ (1u << 3) /**< & if the texture supports storage reads in graphics stages */
  219. #define SDL_GPU_TEXTUREUSAGE_COMPUTE_STORAGE_READ (1u << 4) /**< & if the texture supports storage reads in the compute stage */
  220. #define SDL_GPU_TEXTUREUSAGE_COMPUTE_STORAGE_WRITE (1u << 5) /**< & if the texture supports storage writes in the compute stage */
  221. typedef enum SDL_GPUTextureType
  222. {
  223. SDL_GPU_TEXTURETYPE_2D,
  224. SDL_GPU_TEXTURETYPE_2D_ARRAY,
  225. SDL_GPU_TEXTURETYPE_3D,
  226. SDL_GPU_TEXTURETYPE_CUBE
  227. } SDL_GPUTextureType;
  228. typedef enum SDL_GPUSampleCount
  229. {
  230. SDL_GPU_SAMPLECOUNT_1,
  231. SDL_GPU_SAMPLECOUNT_2,
  232. SDL_GPU_SAMPLECOUNT_4,
  233. SDL_GPU_SAMPLECOUNT_8
  234. } SDL_GPUSampleCount;
  235. typedef enum SDL_GPUCubeMapFace
  236. {
  237. SDL_GPU_CUBEMAPFACE_POSITIVEX,
  238. SDL_GPU_CUBEMAPFACE_NEGATIVEX,
  239. SDL_GPU_CUBEMAPFACE_POSITIVEY,
  240. SDL_GPU_CUBEMAPFACE_NEGATIVEY,
  241. SDL_GPU_CUBEMAPFACE_POSITIVEZ,
  242. SDL_GPU_CUBEMAPFACE_NEGATIVEZ
  243. } SDL_GPUCubeMapFace;
  244. typedef Uint32 SDL_GPUBufferUsageFlags;
  245. #define SDL_GPU_BUFFERUSAGE_VERTEX (1u << 0) /**< & if the buffer is a vertex buffer */
  246. #define SDL_GPU_BUFFERUSAGE_INDEX (1u << 1) /**< & if the buffer is an index buffer */
  247. #define SDL_GPU_BUFFERUSAGE_INDIRECT (1u << 2) /**< & if the buffer is an indirect buffer */
  248. #define SDL_GPU_BUFFERUSAGE_GRAPHICS_STORAGE_READ (1u << 3) /**< & if the buffer supports storage reads in graphics stages */
  249. #define SDL_GPU_BUFFERUSAGE_COMPUTE_STORAGE_READ (1u << 4) /**< & if the buffer supports storage reads in the compute stage */
  250. #define SDL_GPU_BUFFERUSAGE_COMPUTE_STORAGE_WRITE (1u << 5) /**< & if the buffer supports storage writes in the compute stage */
  251. typedef enum SDL_GPUTransferBufferUsage
  252. {
  253. SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD,
  254. SDL_GPU_TRANSFERBUFFERUSAGE_DOWNLOAD
  255. } SDL_GPUTransferBufferUsage;
  256. typedef enum SDL_GPUShaderStage
  257. {
  258. SDL_GPU_SHADERSTAGE_VERTEX,
  259. SDL_GPU_SHADERSTAGE_FRAGMENT
  260. } SDL_GPUShaderStage;
  261. typedef Uint32 SDL_GPUShaderFormat;
  262. #define SDL_GPU_SHADERFORMAT_SECRET (1u << 0) /**< & if you are providing shaders for NDA'd platforms */
  263. #define SDL_GPU_SHADERFORMAT_SPIRV (1u << 1) /**< & if you are providing SPIR-V shaders for Vulkan */
  264. #define SDL_GPU_SHADERFORMAT_DXBC (1u << 2) /**< & if you are providing DXBC SM5_0 shaders for D3D11 */
  265. #define SDL_GPU_SHADERFORMAT_DXIL (1u << 3) /**< & if you are providing DXIL shaders for D3D12 */
  266. #define SDL_GPU_SHADERFORMAT_MSL (1u << 4) /**< & if you are providing MSL shaders for Metal */
  267. #define SDL_GPU_SHADERFORMAT_METALLIB (1u << 5) /**< & if you are providing precompiled metallib shaders for Metal */
  268. typedef enum SDL_GPUVertexElementFormat
  269. {
  270. /* 32-bit Signed Integers */
  271. SDL_GPU_VERTEXELEMENTFORMAT_INT,
  272. SDL_GPU_VERTEXELEMENTFORMAT_INT2,
  273. SDL_GPU_VERTEXELEMENTFORMAT_INT3,
  274. SDL_GPU_VERTEXELEMENTFORMAT_INT4,
  275. /* 32-bit Unsigned Integers */
  276. SDL_GPU_VERTEXELEMENTFORMAT_UINT,
  277. SDL_GPU_VERTEXELEMENTFORMAT_UINT2,
  278. SDL_GPU_VERTEXELEMENTFORMAT_UINT3,
  279. SDL_GPU_VERTEXELEMENTFORMAT_UINT4,
  280. /* 32-bit Floats */
  281. SDL_GPU_VERTEXELEMENTFORMAT_FLOAT,
  282. SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2,
  283. SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3,
  284. SDL_GPU_VERTEXELEMENTFORMAT_FLOAT4,
  285. /* 8-bit Signed Integers */
  286. SDL_GPU_VERTEXELEMENTFORMAT_BYTE2,
  287. SDL_GPU_VERTEXELEMENTFORMAT_BYTE4,
  288. /* 8-bit Unsigned Integers */
  289. SDL_GPU_VERTEXELEMENTFORMAT_UBYTE2,
  290. SDL_GPU_VERTEXELEMENTFORMAT_UBYTE4,
  291. /* 8-bit Signed Normalized */
  292. SDL_GPU_VERTEXELEMENTFORMAT_BYTE2_NORM,
  293. SDL_GPU_VERTEXELEMENTFORMAT_BYTE4_NORM,
  294. /* 8-bit Unsigned Normalized */
  295. SDL_GPU_VERTEXELEMENTFORMAT_UBYTE2_NORM,
  296. SDL_GPU_VERTEXELEMENTFORMAT_UBYTE4_NORM,
  297. /* 16-bit Signed Integers */
  298. SDL_GPU_VERTEXELEMENTFORMAT_SHORT2,
  299. SDL_GPU_VERTEXELEMENTFORMAT_SHORT4,
  300. /* 16-bit Unsigned Integers */
  301. SDL_GPU_VERTEXELEMENTFORMAT_USHORT2,
  302. SDL_GPU_VERTEXELEMENTFORMAT_USHORT4,
  303. /* 16-bit Signed Normalized */
  304. SDL_GPU_VERTEXELEMENTFORMAT_SHORT2_NORM,
  305. SDL_GPU_VERTEXELEMENTFORMAT_SHORT4_NORM,
  306. /* 16-bit Unsigned Normalized */
  307. SDL_GPU_VERTEXELEMENTFORMAT_USHORT2_NORM,
  308. SDL_GPU_VERTEXELEMENTFORMAT_USHORT4_NORM,
  309. /* 16-bit Floats */
  310. SDL_GPU_VERTEXELEMENTFORMAT_HALF2,
  311. SDL_GPU_VERTEXELEMENTFORMAT_HALF4
  312. } SDL_GPUVertexElementFormat;
  313. typedef enum SDL_GPUVertexInputRate
  314. {
  315. SDL_GPU_VERTEXINPUTRATE_VERTEX = 0,
  316. SDL_GPU_VERTEXINPUTRATE_INSTANCE = 1
  317. } SDL_GPUVertexInputRate;
  318. typedef enum SDL_GPUFillMode
  319. {
  320. SDL_GPU_FILLMODE_FILL,
  321. SDL_GPU_FILLMODE_LINE
  322. } SDL_GPUFillMode;
  323. typedef enum SDL_GPUCullMode
  324. {
  325. SDL_GPU_CULLMODE_NONE,
  326. SDL_GPU_CULLMODE_FRONT,
  327. SDL_GPU_CULLMODE_BACK
  328. } SDL_GPUCullMode;
  329. typedef enum SDL_GPUFrontFace
  330. {
  331. SDL_GPU_FRONTFACE_COUNTER_CLOCKWISE,
  332. SDL_GPU_FRONTFACE_CLOCKWISE
  333. } SDL_GPUFrontFace;
  334. typedef enum SDL_GPUCompareOp
  335. {
  336. SDL_GPU_COMPAREOP_NEVER,
  337. SDL_GPU_COMPAREOP_LESS,
  338. SDL_GPU_COMPAREOP_EQUAL,
  339. SDL_GPU_COMPAREOP_LESS_OR_EQUAL,
  340. SDL_GPU_COMPAREOP_GREATER,
  341. SDL_GPU_COMPAREOP_NOT_EQUAL,
  342. SDL_GPU_COMPAREOP_GREATER_OR_EQUAL,
  343. SDL_GPU_COMPAREOP_ALWAYS
  344. } SDL_GPUCompareOp;
  345. typedef enum SDL_GPUStencilOp
  346. {
  347. SDL_GPU_STENCILOP_KEEP,
  348. SDL_GPU_STENCILOP_ZERO,
  349. SDL_GPU_STENCILOP_REPLACE,
  350. SDL_GPU_STENCILOP_INCREMENT_AND_CLAMP,
  351. SDL_GPU_STENCILOP_DECREMENT_AND_CLAMP,
  352. SDL_GPU_STENCILOP_INVERT,
  353. SDL_GPU_STENCILOP_INCREMENT_AND_WRAP,
  354. SDL_GPU_STENCILOP_DECREMENT_AND_WRAP
  355. } SDL_GPUStencilOp;
  356. typedef enum SDL_GPUBlendOp
  357. {
  358. SDL_GPU_BLENDOP_ADD,
  359. SDL_GPU_BLENDOP_SUBTRACT,
  360. SDL_GPU_BLENDOP_REVERSE_SUBTRACT,
  361. SDL_GPU_BLENDOP_MIN,
  362. SDL_GPU_BLENDOP_MAX
  363. } SDL_GPUBlendOp;
  364. typedef enum SDL_GPUBlendFactor
  365. {
  366. SDL_GPU_BLENDFACTOR_ZERO,
  367. SDL_GPU_BLENDFACTOR_ONE,
  368. SDL_GPU_BLENDFACTOR_SRC_COLOR,
  369. SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_COLOR,
  370. SDL_GPU_BLENDFACTOR_DST_COLOR,
  371. SDL_GPU_BLENDFACTOR_ONE_MINUS_DST_COLOR,
  372. SDL_GPU_BLENDFACTOR_SRC_ALPHA,
  373. SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
  374. SDL_GPU_BLENDFACTOR_DST_ALPHA,
  375. SDL_GPU_BLENDFACTOR_ONE_MINUS_DST_ALPHA,
  376. SDL_GPU_BLENDFACTOR_CONSTANT_COLOR,
  377. SDL_GPU_BLENDFACTOR_ONE_MINUS_CONSTANT_COLOR,
  378. SDL_GPU_BLENDFACTOR_SRC_ALPHA_SATURATE
  379. } SDL_GPUBlendFactor;
  380. typedef Uint8 SDL_GPUColorComponentFlags;
  381. #define SDL_GPU_COLORCOMPONENT_R (1u << 0) /**< & for the Red component */
  382. #define SDL_GPU_COLORCOMPONENT_G (1u << 1) /**< & for the Green component */
  383. #define SDL_GPU_COLORCOMPONENT_B (1u << 2) /**< & for the Blue component */
  384. #define SDL_GPU_COLORCOMPONENT_A (1u << 3) /**< & for the Alpha component */
  385. typedef enum SDL_GPUFilter
  386. {
  387. SDL_GPU_FILTER_NEAREST,
  388. SDL_GPU_FILTER_LINEAR
  389. } SDL_GPUFilter;
  390. typedef enum SDL_GPUSamplerMipmapMode
  391. {
  392. SDL_GPU_SAMPLERMIPMAPMODE_NEAREST,
  393. SDL_GPU_SAMPLERMIPMAPMODE_LINEAR
  394. } SDL_GPUSamplerMipmapMode;
  395. typedef enum SDL_GPUSamplerAddressMode
  396. {
  397. SDL_GPU_SAMPLERADDRESSMODE_REPEAT,
  398. SDL_GPU_SAMPLERADDRESSMODE_MIRRORED_REPEAT,
  399. SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE
  400. } SDL_GPUSamplerAddressMode;
  401. /*
  402. * VSYNC:
  403. * Waits for vblank before presenting.
  404. * If there is a pending image to present, the new image is enqueued for presentation.
  405. * Disallows tearing at the cost of visual latency.
  406. * When using this present mode, AcquireSwapchainTexture will block if too many frames are in flight.
  407. * IMMEDIATE:
  408. * Immediately presents.
  409. * Lowest latency option, but tearing may occur.
  410. * When using this mode, AcquireSwapchainTexture will return NULL if too many frames are in flight.
  411. * MAILBOX:
  412. * Waits for vblank before presenting. No tearing is possible.
  413. * If there is a pending image to present, the pending image is replaced by the new image.
  414. * Similar to VSYNC, but with reduced visual latency.
  415. * When using this mode, AcquireSwapchainTexture will return NULL if too many frames are in flight.
  416. */
  417. typedef enum SDL_GPUPresentMode
  418. {
  419. SDL_GPU_PRESENTMODE_VSYNC,
  420. SDL_GPU_PRESENTMODE_IMMEDIATE,
  421. SDL_GPU_PRESENTMODE_MAILBOX
  422. } SDL_GPUPresentMode;
  423. /*
  424. * SDR:
  425. * B8G8R8A8 or R8G8B8A8 swapchain. Pixel values are in nonlinear sRGB encoding. Blends raw pixel values.
  426. * SDR_LINEAR:
  427. * B8G8R8A8_SRGB or R8G8B8A8_SRGB swapchain. Pixel values are in nonlinear sRGB encoding. Blends in linear space.
  428. * HDR_EXTENDED_LINEAR:
  429. * R16G16B16A16_SFLOAT swapchain. Pixel values are in extended linear encoding. Blends in linear space.
  430. * HDR10_ST2048:
  431. * A2R10G10B10 or A2B10G10R10 swapchain. Pixel values are in PQ ST2048 encoding. Blends raw pixel values. (TODO: verify this)
  432. */
  433. typedef enum SDL_GPUSwapchainComposition
  434. {
  435. SDL_GPU_SWAPCHAINCOMPOSITION_SDR,
  436. SDL_GPU_SWAPCHAINCOMPOSITION_SDR_LINEAR,
  437. SDL_GPU_SWAPCHAINCOMPOSITION_HDR_EXTENDED_LINEAR,
  438. SDL_GPU_SWAPCHAINCOMPOSITION_HDR10_ST2048
  439. } SDL_GPUSwapchainComposition;
  440. typedef enum SDL_GPUDriver
  441. {
  442. SDL_GPU_DRIVER_INVALID = -1,
  443. SDL_GPU_DRIVER_SECRET, /* NDA'd platforms */
  444. SDL_GPU_DRIVER_VULKAN,
  445. SDL_GPU_DRIVER_D3D11,
  446. SDL_GPU_DRIVER_D3D12,
  447. SDL_GPU_DRIVER_METAL
  448. } SDL_GPUDriver;
  449. /* Structures */
  450. typedef struct SDL_GPUDepthStencilValue
  451. {
  452. float depth;
  453. Uint8 stencil;
  454. } SDL_GPUDepthStencilValue;
  455. typedef struct SDL_GPUViewport
  456. {
  457. float x;
  458. float y;
  459. float w;
  460. float h;
  461. float minDepth;
  462. float maxDepth;
  463. } SDL_GPUViewport;
  464. typedef struct SDL_GPUTextureTransferInfo
  465. {
  466. SDL_GPUTransferBuffer *transferBuffer;
  467. Uint32 offset; /* starting location of the image data */
  468. Uint32 imagePitch; /* number of pixels from one row to the next */
  469. Uint32 imageHeight; /* number of rows from one layer/depth-slice to the next */
  470. } SDL_GPUTextureTransferInfo;
  471. typedef struct SDL_GPUTransferBufferLocation
  472. {
  473. SDL_GPUTransferBuffer *transferBuffer;
  474. Uint32 offset;
  475. } SDL_GPUTransferBufferLocation;
  476. typedef struct SDL_GPUTextureLocation
  477. {
  478. SDL_GPUTexture *texture;
  479. Uint32 mipLevel;
  480. Uint32 layer;
  481. Uint32 x;
  482. Uint32 y;
  483. Uint32 z;
  484. } SDL_GPUTextureLocation;
  485. typedef struct SDL_GPUTextureRegion
  486. {
  487. SDL_GPUTexture *texture;
  488. Uint32 mipLevel;
  489. Uint32 layer;
  490. Uint32 x;
  491. Uint32 y;
  492. Uint32 z;
  493. Uint32 w;
  494. Uint32 h;
  495. Uint32 d;
  496. } SDL_GPUTextureRegion;
  497. typedef struct SDL_GPUBlitRegion
  498. {
  499. SDL_GPUTexture *texture;
  500. Uint32 mipLevel;
  501. Uint32 layerOrDepthPlane;
  502. Uint32 x;
  503. Uint32 y;
  504. Uint32 w;
  505. Uint32 h;
  506. } SDL_GPUBlitRegion;
  507. typedef struct SDL_GPUBufferLocation
  508. {
  509. SDL_GPUBuffer *buffer;
  510. Uint32 offset;
  511. } SDL_GPUBufferLocation;
  512. typedef struct SDL_GPUBufferRegion
  513. {
  514. SDL_GPUBuffer *buffer;
  515. Uint32 offset;
  516. Uint32 size;
  517. } SDL_GPUBufferRegion;
  518. /* Note that the `firstVertex` and `firstInstance` parameters are NOT compatible with
  519. * built-in vertex/instance ID variables in shaders (for example, SV_VertexID). If
  520. * your shader depends on these variables, the correlating draw call parameter MUST
  521. * be 0.
  522. */
  523. typedef struct SDL_GPUIndirectDrawCommand
  524. {
  525. Uint32 vertexCount; /* number of vertices to draw */
  526. Uint32 instanceCount; /* number of instances to draw */
  527. Uint32 firstVertex; /* index of the first vertex to draw */
  528. Uint32 firstInstance; /* ID of the first instance to draw */
  529. } SDL_GPUIndirectDrawCommand;
  530. typedef struct SDL_GPUIndexedIndirectDrawCommand
  531. {
  532. Uint32 indexCount; /* number of vertices to draw per instance */
  533. Uint32 instanceCount; /* number of instances to draw */
  534. Uint32 firstIndex; /* base index within the index buffer */
  535. Sint32 vertexOffset; /* value added to vertex index before indexing into the vertex buffer */
  536. Uint32 firstInstance; /* ID of the first instance to draw */
  537. } SDL_GPUIndexedIndirectDrawCommand;
  538. typedef struct SDL_GPUIndirectDispatchCommand
  539. {
  540. Uint32 groupCountX;
  541. Uint32 groupCountY;
  542. Uint32 groupCountZ;
  543. } SDL_GPUIndirectDispatchCommand;
  544. /* State structures */
  545. typedef struct SDL_GPUSamplerCreateInfo
  546. {
  547. SDL_GPUFilter minFilter;
  548. SDL_GPUFilter magFilter;
  549. SDL_GPUSamplerMipmapMode mipmapMode;
  550. SDL_GPUSamplerAddressMode addressModeU;
  551. SDL_GPUSamplerAddressMode addressModeV;
  552. SDL_GPUSamplerAddressMode addressModeW;
  553. float mipLodBias;
  554. SDL_bool anisotropyEnable;
  555. float maxAnisotropy;
  556. SDL_bool compareEnable;
  557. SDL_GPUCompareOp compareOp;
  558. float minLod;
  559. float maxLod;
  560. SDL_PropertiesID props;
  561. } SDL_GPUSamplerCreateInfo;
  562. typedef struct SDL_GPUVertexBinding
  563. {
  564. Uint32 binding;
  565. Uint32 stride;
  566. SDL_GPUVertexInputRate inputRate;
  567. Uint32 instanceStepRate; /* ignored unless inputRate is INSTANCE */
  568. } SDL_GPUVertexBinding;
  569. typedef struct SDL_GPUVertexAttribute
  570. {
  571. Uint32 location;
  572. Uint32 binding;
  573. SDL_GPUVertexElementFormat format;
  574. Uint32 offset;
  575. } SDL_GPUVertexAttribute;
  576. typedef struct SDL_GPUVertexInputState
  577. {
  578. const SDL_GPUVertexBinding *vertexBindings;
  579. Uint32 vertexBindingCount;
  580. const SDL_GPUVertexAttribute *vertexAttributes;
  581. Uint32 vertexAttributeCount;
  582. } SDL_GPUVertexInputState;
  583. typedef struct SDL_GPUStencilOpState
  584. {
  585. SDL_GPUStencilOp failOp;
  586. SDL_GPUStencilOp passOp;
  587. SDL_GPUStencilOp depthFailOp;
  588. SDL_GPUCompareOp compareOp;
  589. } SDL_GPUStencilOpState;
  590. typedef struct SDL_GPUColorAttachmentBlendState
  591. {
  592. SDL_bool blendEnable;
  593. SDL_GPUBlendFactor srcColorBlendFactor;
  594. SDL_GPUBlendFactor dstColorBlendFactor;
  595. SDL_GPUBlendOp colorBlendOp;
  596. SDL_GPUBlendFactor srcAlphaBlendFactor;
  597. SDL_GPUBlendFactor dstAlphaBlendFactor;
  598. SDL_GPUBlendOp alphaBlendOp;
  599. SDL_GPUColorComponentFlags colorWriteMask;
  600. } SDL_GPUColorAttachmentBlendState;
  601. typedef struct SDL_GPUShaderCreateInfo
  602. {
  603. size_t codeSize;
  604. const Uint8 *code;
  605. const char *entryPointName;
  606. SDL_GPUShaderFormat format;
  607. SDL_GPUShaderStage stage;
  608. Uint32 samplerCount;
  609. Uint32 storageTextureCount;
  610. Uint32 storageBufferCount;
  611. Uint32 uniformBufferCount;
  612. SDL_PropertiesID props;
  613. } SDL_GPUShaderCreateInfo;
  614. typedef struct SDL_GPUTextureCreateInfo
  615. {
  616. SDL_GPUTextureType type;
  617. SDL_GPUTextureFormat format;
  618. SDL_GPUTextureUsageFlags usageFlags;
  619. Uint32 width;
  620. Uint32 height;
  621. Uint32 layerCountOrDepth;
  622. Uint32 levelCount;
  623. SDL_GPUSampleCount sampleCount;
  624. SDL_PropertiesID props;
  625. } SDL_GPUTextureCreateInfo;
  626. #define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_R_FLOAT "SDL.gpu.createtexture.d3d12.clear.r"
  627. #define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_G_FLOAT "SDL.gpu.createtexture.d3d12.clear.g"
  628. #define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_B_FLOAT "SDL.gpu.createtexture.d3d12.clear.b"
  629. #define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_A_FLOAT "SDL.gpu.createtexture.d3d12.clear.a"
  630. #define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_DEPTH_FLOAT "SDL.gpu.createtexture.d3d12.clear.depth"
  631. #define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_STENCIL_UINT8 "SDL.gpu.createtexture.d3d12.clear.stencil"
  632. typedef struct SDL_GPUBufferCreateInfo
  633. {
  634. SDL_GPUBufferUsageFlags usageFlags;
  635. Uint32 sizeInBytes;
  636. SDL_PropertiesID props;
  637. } SDL_GPUBufferCreateInfo;
  638. typedef struct SDL_GPUTransferBufferCreateInfo
  639. {
  640. SDL_GPUTransferBufferUsage usage;
  641. Uint32 sizeInBytes;
  642. SDL_PropertiesID props;
  643. } SDL_GPUTransferBufferCreateInfo;
  644. /* Pipeline state structures */
  645. typedef struct SDL_GPURasterizerState
  646. {
  647. SDL_GPUFillMode fillMode;
  648. SDL_GPUCullMode cullMode;
  649. SDL_GPUFrontFace frontFace;
  650. SDL_bool depthBiasEnable;
  651. float depthBiasConstantFactor;
  652. float depthBiasClamp;
  653. float depthBiasSlopeFactor;
  654. } SDL_GPURasterizerState;
  655. typedef struct SDL_GPUMultisampleState
  656. {
  657. SDL_GPUSampleCount sampleCount;
  658. Uint32 sampleMask;
  659. } SDL_GPUMultisampleState;
  660. typedef struct SDL_GPUDepthStencilState
  661. {
  662. SDL_bool depthTestEnable;
  663. SDL_bool depthWriteEnable;
  664. SDL_GPUCompareOp compareOp;
  665. SDL_bool stencilTestEnable;
  666. SDL_GPUStencilOpState backStencilState;
  667. SDL_GPUStencilOpState frontStencilState;
  668. Uint8 compareMask;
  669. Uint8 writeMask;
  670. Uint8 reference;
  671. } SDL_GPUDepthStencilState;
  672. typedef struct SDL_GPUColorAttachmentDescription
  673. {
  674. SDL_GPUTextureFormat format;
  675. SDL_GPUColorAttachmentBlendState blendState;
  676. } SDL_GPUColorAttachmentDescription;
  677. typedef struct SDL_GPUGraphicsPipelineAttachmentInfo
  678. {
  679. SDL_GPUColorAttachmentDescription *colorAttachmentDescriptions;
  680. Uint32 colorAttachmentCount;
  681. SDL_bool hasDepthStencilAttachment;
  682. SDL_GPUTextureFormat depthStencilFormat;
  683. } SDL_GPUGraphicsPipelineAttachmentInfo;
  684. typedef struct SDL_GPUGraphicsPipelineCreateInfo
  685. {
  686. SDL_GPUShader *vertexShader;
  687. SDL_GPUShader *fragmentShader;
  688. SDL_GPUVertexInputState vertexInputState;
  689. SDL_GPUPrimitiveType primitiveType;
  690. SDL_GPURasterizerState rasterizerState;
  691. SDL_GPUMultisampleState multisampleState;
  692. SDL_GPUDepthStencilState depthStencilState;
  693. SDL_GPUGraphicsPipelineAttachmentInfo attachmentInfo;
  694. float blendConstants[4];
  695. SDL_PropertiesID props;
  696. } SDL_GPUGraphicsPipelineCreateInfo;
  697. typedef struct SDL_GPUComputePipelineCreateInfo
  698. {
  699. size_t codeSize;
  700. const Uint8 *code;
  701. const char *entryPointName;
  702. SDL_GPUShaderFormat format;
  703. Uint32 readOnlyStorageTextureCount;
  704. Uint32 readOnlyStorageBufferCount;
  705. Uint32 writeOnlyStorageTextureCount;
  706. Uint32 writeOnlyStorageBufferCount;
  707. Uint32 uniformBufferCount;
  708. Uint32 threadCountX;
  709. Uint32 threadCountY;
  710. Uint32 threadCountZ;
  711. SDL_PropertiesID props;
  712. } SDL_GPUComputePipelineCreateInfo;
  713. typedef struct SDL_GPUColorAttachmentInfo
  714. {
  715. /* The texture that will be used as a color attachment by a render pass. */
  716. SDL_GPUTexture *texture;
  717. Uint32 mipLevel;
  718. Uint32 layerOrDepthPlane; /* For 3D textures, you can bind an individual depth plane as an attachment. */
  719. /* Can be ignored by RenderPass if CLEAR is not used */
  720. SDL_FColor clearColor;
  721. /* Determines what is done with the texture at the beginning of the render pass.
  722. *
  723. * LOAD:
  724. * Loads the data currently in the texture.
  725. *
  726. * CLEAR:
  727. * Clears the texture to a single color.
  728. *
  729. * DONT_CARE:
  730. * The driver will do whatever it wants with the texture memory.
  731. * This is a good option if you know that every single pixel will be touched in the render pass.
  732. */
  733. SDL_GPULoadOp loadOp;
  734. /* Determines what is done with the texture at the end of the render pass.
  735. *
  736. * STORE:
  737. * Stores the results of the render pass in the texture.
  738. *
  739. * DONT_CARE:
  740. * The driver will do whatever it wants with the texture memory.
  741. * This is often a good option for depth/stencil textures.
  742. */
  743. SDL_GPUStoreOp storeOp;
  744. /* if SDL_TRUE, cycles the texture if the texture is bound and loadOp is not LOAD */
  745. SDL_bool cycle;
  746. } SDL_GPUColorAttachmentInfo;
  747. typedef struct SDL_GPUDepthStencilAttachmentInfo
  748. {
  749. /* The texture that will be used as the depth stencil attachment by a render pass. */
  750. SDL_GPUTexture *texture;
  751. /* Can be ignored by the render pass if CLEAR is not used */
  752. SDL_GPUDepthStencilValue depthStencilClearValue;
  753. /* Determines what is done with the depth values at the beginning of the render pass.
  754. *
  755. * LOAD:
  756. * Loads the depth values currently in the texture.
  757. *
  758. * CLEAR:
  759. * Clears the texture to a single depth.
  760. *
  761. * DONT_CARE:
  762. * The driver will do whatever it wants with the memory.
  763. * This is a good option if you know that every single pixel will be touched in the render pass.
  764. */
  765. SDL_GPULoadOp loadOp;
  766. /* Determines what is done with the depth values at the end of the render pass.
  767. *
  768. * STORE:
  769. * Stores the depth results in the texture.
  770. *
  771. * DONT_CARE:
  772. * The driver will do whatever it wants with the texture memory.
  773. * This is often a good option for depth/stencil textures.
  774. */
  775. SDL_GPUStoreOp storeOp;
  776. /* Determines what is done with the stencil values at the beginning of the render pass.
  777. *
  778. * LOAD:
  779. * Loads the stencil values currently in the texture.
  780. *
  781. * CLEAR:
  782. * Clears the texture to a single stencil value.
  783. *
  784. * DONT_CARE:
  785. * The driver will do whatever it wants with the memory.
  786. * This is a good option if you know that every single pixel will be touched in the render pass.
  787. */
  788. SDL_GPULoadOp stencilLoadOp;
  789. /* Determines what is done with the stencil values at the end of the render pass.
  790. *
  791. * STORE:
  792. * Stores the stencil results in the texture.
  793. *
  794. * DONT_CARE:
  795. * The driver will do whatever it wants with the texture memory.
  796. * This is often a good option for depth/stencil textures.
  797. */
  798. SDL_GPUStoreOp stencilStoreOp;
  799. /* if SDL_TRUE, cycles the texture if the texture is bound and any load ops are not LOAD */
  800. SDL_bool cycle;
  801. } SDL_GPUDepthStencilAttachmentInfo;
  802. /* Binding structs */
  803. typedef struct SDL_GPUBufferBinding
  804. {
  805. SDL_GPUBuffer *buffer;
  806. Uint32 offset;
  807. } SDL_GPUBufferBinding;
  808. typedef struct SDL_GPUTextureSamplerBinding
  809. {
  810. SDL_GPUTexture *texture;
  811. SDL_GPUSampler *sampler;
  812. } SDL_GPUTextureSamplerBinding;
  813. typedef struct SDL_GPUStorageBufferWriteOnlyBinding
  814. {
  815. SDL_GPUBuffer *buffer;
  816. /* if SDL_TRUE, cycles the buffer if it is bound. */
  817. SDL_bool cycle;
  818. } SDL_GPUStorageBufferWriteOnlyBinding;
  819. typedef struct SDL_GPUStorageTextureWriteOnlyBinding
  820. {
  821. SDL_GPUTexture *texture;
  822. Uint32 mipLevel;
  823. Uint32 layer;
  824. /* if SDL_TRUE, cycles the texture if the texture is bound. */
  825. SDL_bool cycle;
  826. } SDL_GPUStorageTextureWriteOnlyBinding;
  827. /* Functions */
  828. /* Device */
  829. /**
  830. * Creates a GPU context.
  831. *
  832. * \param formatFlags a bitflag indicating which shader formats the app is
  833. * able to provide.
  834. * \param debugMode enable debug mode properties and validations.
  835. * \param name the preferred GPU driver, or NULL to let SDL pick the optimal
  836. * driver.
  837. * \returns a GPU context on success or NULL on failure.
  838. *
  839. * \since This function is available since SDL 3.0.0.
  840. *
  841. * \sa SDL_GetGPUDriver
  842. * \sa SDL_DestroyGPUDevice
  843. */
  844. extern SDL_DECLSPEC SDL_GPUDevice *SDLCALL SDL_CreateGPUDevice(
  845. SDL_GPUShaderFormat formatFlags,
  846. SDL_bool debugMode,
  847. const char *name);
  848. /**
  849. * Creates a GPU context.
  850. *
  851. * These are the supported properties:
  852. *
  853. * - `SDL_PROP_GPU_DEVICE_CREATE_DEBUGMODE_BOOL`: enable debug mode properties
  854. * and validations, defaults to SDL_TRUE.
  855. * - `SDL_PROP_GPU_DEVICE_CREATE_PREFERLOWPOWER_BOOL`: enable to prefer energy
  856. * efficiency over maximum GPU performance, defaults to SDL_FALSE.
  857. * - `SDL_PROP_GPU_DEVICE_CREATE_NAME_STRING`: the name of the GPU driver to
  858. * use, if a specific one is desired.
  859. *
  860. * These are the current shader format properties:
  861. *
  862. * - `SDL_PROP_GPU_DEVICE_CREATE_SHADERS_SECRET_BOOL`: The app is able to
  863. * provide shaders for an NDA platform.
  864. * - `SDL_PROP_GPU_DEVICE_CREATE_SHADERS_SPIRV_BOOL`: The app is able to
  865. * provide SPIR-V shaders if applicable.
  866. * - SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXBC_BOOL`: The app is able to provide
  867. * DXBC shaders if applicable
  868. * `SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXIL_BOOL`: The app is able to
  869. * provide DXIL shaders if applicable.
  870. * - `SDL_PROP_GPU_DEVICE_CREATE_SHADERS_MSL_BOOL`: The app is able to provide
  871. * MSL shaders if applicable.
  872. * - `SDL_PROP_GPU_DEVICE_CREATE_SHADERS_METALLIB_BOOL`: The app is able to
  873. * provide Metal shader libraries if applicable.
  874. *
  875. * With the D3D12 renderer:
  876. *
  877. * - `SDL_PROP_GPU_DEVICE_CREATE_D3D12_SEMANTIC_NAME_STRING`: the prefix to
  878. * use for all vertex semantics, default is "TEXCOORD".
  879. *
  880. * \param props the properties to use.
  881. * \returns a GPU context on success or NULL on failure.
  882. *
  883. * \since This function is available since SDL 3.0.0.
  884. *
  885. * \sa SDL_GetGPUDriver
  886. * \sa SDL_DestroyGPUDevice
  887. */
  888. extern SDL_DECLSPEC SDL_GPUDevice *SDLCALL SDL_CreateGPUDeviceWithProperties(
  889. SDL_PropertiesID props);
  890. #define SDL_PROP_GPU_DEVICE_CREATE_DEBUGMODE_BOOL "SDL.gpu.device.create.debugmode"
  891. #define SDL_PROP_GPU_DEVICE_CREATE_PREFERLOWPOWER_BOOL "SDL.gpu.device.create.preferlowpower"
  892. #define SDL_PROP_GPU_DEVICE_CREATE_NAME_STRING "SDL.gpu.device.create.name"
  893. #define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_SECRET_BOOL "SDL.gpu.device.create.shaders.secret"
  894. #define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_SPIRV_BOOL "SDL.gpu.device.create.shaders.spirv"
  895. #define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXBC_BOOL "SDL.gpu.device.create.shaders.dxbc"
  896. #define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXIL_BOOL "SDL.gpu.device.create.shaders.dxil"
  897. #define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_MSL_BOOL "SDL.gpu.device.create.shaders.msl"
  898. #define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_METALLIB_BOOL "SDL.gpu.device.create.shaders.metallib"
  899. #define SDL_PROP_GPU_DEVICE_CREATE_D3D12_SEMANTIC_NAME_STRING "SDL.gpu.device.create.d3d12.semantic"
  900. /**
  901. * Destroys a GPU context previously returned by SDL_CreateGPUDevice.
  902. *
  903. * \param device a GPU Context to destroy.
  904. *
  905. * \since This function is available since SDL 3.0.0.
  906. *
  907. * \sa SDL_CreateGPUDevice
  908. */
  909. extern SDL_DECLSPEC void SDLCALL SDL_DestroyGPUDevice(SDL_GPUDevice *device);
  910. /**
  911. * Returns the backend used to create this GPU context.
  912. *
  913. * \param device a GPU context to query.
  914. * \returns an SDL_GPUDriver value, or SDL_GPU_DRIVER_INVALID on error.
  915. *
  916. * \since This function is available since SDL 3.0.0.
  917. */
  918. extern SDL_DECLSPEC SDL_GPUDriver SDLCALL SDL_GetGPUDriver(SDL_GPUDevice *device);
  919. /* State Creation */
  920. /**
  921. * Creates a pipeline object to be used in a compute workflow.
  922. *
  923. * Shader resource bindings must be authored to follow a particular order. For
  924. * SPIR-V shaders, use the following resource sets: 0: Read-only storage
  925. * textures, followed by read-only storage buffers 1: Write-only storage
  926. * textures, followed by write-only storage buffers 2: Uniform buffers
  927. *
  928. * For DXBC Shader Model 5_0 shaders, use the following register order: For t
  929. * registers: Read-only storage textures, followed by read-only storage
  930. * buffers For u registers: Write-only storage textures, followed by
  931. * write-only storage buffers For b registers: Uniform buffers
  932. *
  933. * For DXIL shaders, use the following register order: (t[n], space0):
  934. * Read-only storage textures, followed by read-only storage buffers (u[n],
  935. * space1): Write-only storage textures, followed by write-only storage
  936. * buffers (b[n], space2): Uniform buffers
  937. *
  938. * For MSL/metallib, use the following order: For [[buffer]]: Uniform buffers,
  939. * followed by write-only storage buffers, followed by write-only storage
  940. * buffers For [[texture]]: Read-only storage textures, followed by write-only
  941. * storage textures
  942. *
  943. * \param device a GPU Context.
  944. * \param computePipelineCreateInfo a struct describing the state of the
  945. * requested compute pipeline.
  946. * \returns a compute pipeline object on success, or NULL on failure.
  947. *
  948. * \since This function is available since SDL 3.0.0.
  949. *
  950. * \sa SDL_BindGPUComputePipeline
  951. * \sa SDL_ReleaseGPUComputePipeline
  952. */
  953. extern SDL_DECLSPEC SDL_GPUComputePipeline *SDLCALL SDL_CreateGPUComputePipeline(
  954. SDL_GPUDevice *device,
  955. SDL_GPUComputePipelineCreateInfo *computePipelineCreateInfo);
  956. /**
  957. * Creates a pipeline object to be used in a graphics workflow.
  958. *
  959. * \param device a GPU Context.
  960. * \param pipelineCreateInfo a struct describing the state of the desired
  961. * graphics pipeline.
  962. * \returns a graphics pipeline object on success, or NULL on failure.
  963. *
  964. * \since This function is available since SDL 3.0.0.
  965. *
  966. * \sa SDL_CreateGPUShader
  967. * \sa SDL_BindGPUGraphicsPipeline
  968. * \sa SDL_ReleaseGPUGraphicsPipeline
  969. */
  970. extern SDL_DECLSPEC SDL_GPUGraphicsPipeline *SDLCALL SDL_CreateGPUGraphicsPipeline(
  971. SDL_GPUDevice *device,
  972. SDL_GPUGraphicsPipelineCreateInfo *pipelineCreateInfo);
  973. /**
  974. * Creates a sampler object to be used when binding textures in a graphics
  975. * workflow.
  976. *
  977. * \param device a GPU Context.
  978. * \param samplerCreateInfo a struct describing the state of the desired
  979. * sampler.
  980. * \returns a sampler object on success, or NULL on failure.
  981. *
  982. * \since This function is available since SDL 3.0.0.
  983. *
  984. * \sa SDL_BindGPUVertexSamplers
  985. * \sa SDL_BindGPUFragmentSamplers
  986. * \sa SDL_ReleaseSampler
  987. */
  988. extern SDL_DECLSPEC SDL_GPUSampler *SDLCALL SDL_CreateGPUSampler(
  989. SDL_GPUDevice *device,
  990. SDL_GPUSamplerCreateInfo *samplerCreateInfo);
  991. /**
  992. * Creates a shader to be used when creating a graphics pipeline.
  993. *
  994. * Shader resource bindings must be authored to follow a particular order
  995. * depending on the shader format.
  996. *
  997. * For SPIR-V shaders, use the following resource sets: For vertex shaders: 0:
  998. * Sampled textures, followed by storage textures, followed by storage buffers
  999. * 1: Uniform buffers For fragment shaders: 2: Sampled textures, followed by
  1000. * storage textures, followed by storage buffers 3: Uniform buffers
  1001. *
  1002. * For DXBC Shader Model 5_0 shaders, use the following register order: For t
  1003. * registers: Sampled textures, followed by storage textures, followed by
  1004. * storage buffers For s registers: Samplers with indices corresponding to the
  1005. * sampled textures For b registers: Uniform buffers
  1006. *
  1007. * For DXIL shaders, use the following register order: For vertex shaders:
  1008. * (t[n], space0): Sampled textures, followed by storage textures, followed by
  1009. * storage buffers (s[n], space0): Samplers with indices corresponding to the
  1010. * sampled textures (b[n], space1): Uniform buffers For pixel shaders: (t[n],
  1011. * space2): Sampled textures, followed by storage textures, followed by
  1012. * storage buffers (s[n], space2): Samplers with indices corresponding to the
  1013. * sampled textures (b[n], space3): Uniform buffers
  1014. *
  1015. * For MSL/metallib, use the following order: For [[texture]]: Sampled
  1016. * textures, followed by storage textures For [[sampler]]: Samplers with
  1017. * indices corresponding to the sampled textures For [[buffer]]: Uniform
  1018. * buffers, followed by storage buffers. Vertex buffer 0 is bound at
  1019. * [[buffer(30)]], vertex buffer 1 at [[buffer(29)]], and so on. Rather than
  1020. * manually authoring vertex buffer indices, use the [[stage_in]] attribute
  1021. * which will automatically use the vertex input information from the
  1022. * SDL_GPUPipeline.
  1023. *
  1024. * \param device a GPU Context.
  1025. * \param shaderCreateInfo a struct describing the state of the desired
  1026. * shader.
  1027. * \returns a shader object on success, or NULL on failure.
  1028. *
  1029. * \since This function is available since SDL 3.0.0.
  1030. *
  1031. * \sa SDL_CreateGPUGraphicsPipeline
  1032. * \sa SDL_ReleaseGPUShader
  1033. */
  1034. extern SDL_DECLSPEC SDL_GPUShader *SDLCALL SDL_CreateGPUShader(
  1035. SDL_GPUDevice *device,
  1036. SDL_GPUShaderCreateInfo *shaderCreateInfo);
  1037. /**
  1038. * Creates a texture object to be used in graphics or compute workflows.
  1039. *
  1040. * The contents of this texture are undefined until data is written to the
  1041. * texture.
  1042. *
  1043. * Note that certain combinations of usage flags are invalid. For example, a
  1044. * texture cannot have both the SAMPLER and GRAPHICS_STORAGE_READ flags.
  1045. *
  1046. * If you request a sample count higher than the hardware supports, the
  1047. * implementation will automatically fall back to the highest available sample
  1048. * count.
  1049. *
  1050. * \param device a GPU Context.
  1051. * \param textureCreateInfo a struct describing the state of the texture to
  1052. * create.
  1053. * \returns a texture object on success, or NULL on failure.
  1054. *
  1055. * \since This function is available since SDL 3.0.0.
  1056. *
  1057. * \sa SDL_UploadToGPUTexture
  1058. * \sa SDL_DownloadFromGPUTexture
  1059. * \sa SDL_BindGPUVertexSamplers
  1060. * \sa SDL_BindGPUVertexStorageTextures
  1061. * \sa SDL_BindGPUFragmentSamplers
  1062. * \sa SDL_BindGPUFragmentStorageTextures
  1063. * \sa SDL_BindGPUComputeStorageTextures
  1064. * \sa SDL_BlitGPUTexture
  1065. * \sa SDL_ReleaseGPUTexture
  1066. * \sa SDL_GPUTextureSupportsFormat
  1067. */
  1068. extern SDL_DECLSPEC SDL_GPUTexture *SDLCALL SDL_CreateGPUTexture(
  1069. SDL_GPUDevice *device,
  1070. SDL_GPUTextureCreateInfo *textureCreateInfo);
  1071. /**
  1072. * Creates a buffer object to be used in graphics or compute workflows.
  1073. *
  1074. * The contents of this buffer are undefined until data is written to the
  1075. * buffer.
  1076. *
  1077. * Note that certain combinations of usage flags are invalid. For example, a
  1078. * buffer cannot have both the VERTEX and INDEX flags.
  1079. *
  1080. * \param device a GPU Context.
  1081. * \param bufferCreateInfo a struct describing the state of the buffer to
  1082. * create.
  1083. * \returns a buffer object on success, or NULL on failure.
  1084. *
  1085. * \since This function is available since SDL 3.0.0.
  1086. *
  1087. * \sa SDL_UploadToGPUBuffer
  1088. * \sa SDL_BindGPUVertexBuffers
  1089. * \sa SDL_BindGPUIndexBuffer
  1090. * \sa SDL_BindGPUVertexStorageBuffers
  1091. * \sa SDL_BindGPUFragmentStorageBuffers
  1092. * \sa SDL_BindGPUComputeStorageBuffers
  1093. * \sa SDL_ReleaseGPUBuffer
  1094. */
  1095. extern SDL_DECLSPEC SDL_GPUBuffer *SDLCALL SDL_CreateGPUBuffer(
  1096. SDL_GPUDevice *device,
  1097. SDL_GPUBufferCreateInfo *bufferCreateInfo);
  1098. /**
  1099. * Creates a transfer buffer to be used when uploading to or downloading from
  1100. * graphics resources.
  1101. *
  1102. * \param device a GPU Context.
  1103. * \param transferBufferCreateInfo a struct describing the state of the
  1104. * transfer buffer to create.
  1105. * \returns a transfer buffer on success, or NULL on failure.
  1106. *
  1107. * \since This function is available since SDL 3.0.0.
  1108. *
  1109. * \sa SDL_UploadToGPUBuffer
  1110. * \sa SDL_DownloadFromGPUBuffer
  1111. * \sa SDL_UploadToGPUTexture
  1112. * \sa SDL_DownloadFromGPUTexture
  1113. * \sa SDL_ReleaseGPUTransferBuffer
  1114. */
  1115. extern SDL_DECLSPEC SDL_GPUTransferBuffer *SDLCALL SDL_CreateGPUTransferBuffer(
  1116. SDL_GPUDevice *device,
  1117. SDL_GPUTransferBufferCreateInfo *transferBufferCreateInfo);
  1118. /* Debug Naming */
  1119. /**
  1120. * Sets an arbitrary string constant to label a buffer.
  1121. *
  1122. * Useful for debugging.
  1123. *
  1124. * \param device a GPU Context.
  1125. * \param buffer a buffer to attach the name to.
  1126. * \param text a UTF-8 string constant to mark as the name of the buffer.
  1127. *
  1128. * \since This function is available since SDL 3.0.0.
  1129. */
  1130. extern SDL_DECLSPEC void SDLCALL SDL_SetGPUBufferName(
  1131. SDL_GPUDevice *device,
  1132. SDL_GPUBuffer *buffer,
  1133. const char *text);
  1134. /**
  1135. * Sets an arbitrary string constant to label a texture.
  1136. *
  1137. * Useful for debugging.
  1138. *
  1139. * \param device a GPU Context.
  1140. * \param texture a texture to attach the name to.
  1141. * \param text a UTF-8 string constant to mark as the name of the texture.
  1142. *
  1143. * \since This function is available since SDL 3.0.0.
  1144. */
  1145. extern SDL_DECLSPEC void SDLCALL SDL_SetGPUTextureName(
  1146. SDL_GPUDevice *device,
  1147. SDL_GPUTexture *texture,
  1148. const char *text);
  1149. /**
  1150. * Inserts an arbitrary string label into the command buffer callstream.
  1151. *
  1152. * Useful for debugging.
  1153. *
  1154. * \param commandBuffer a command buffer.
  1155. * \param text a UTF-8 string constant to insert as the label.
  1156. *
  1157. * \since This function is available since SDL 3.0.0.
  1158. */
  1159. extern SDL_DECLSPEC void SDLCALL SDL_InsertGPUDebugLabel(
  1160. SDL_GPUCommandBuffer *commandBuffer,
  1161. const char *text);
  1162. /**
  1163. * Begins a debug group with an arbitary name.
  1164. *
  1165. * Used for denoting groups of calls when viewing the command buffer
  1166. * callstream in a graphics debugging tool.
  1167. *
  1168. * Each call to SDL_PushGPUDebugGroup must have a corresponding call to
  1169. * SDL_PopGPUDebugGroup.
  1170. *
  1171. * On some backends (e.g. Metal), pushing a debug group during a
  1172. * render/blit/compute pass will create a group that is scoped to the native
  1173. * pass rather than the command buffer. For best results, if you push a debug
  1174. * group during a pass, always pop it in the same pass.
  1175. *
  1176. * \param commandBuffer a command buffer.
  1177. * \param name a UTF-8 string constant that names the group.
  1178. *
  1179. * \since This function is available since SDL 3.0.0.
  1180. *
  1181. * \sa SDL_PopGPUDebugGroup
  1182. */
  1183. extern SDL_DECLSPEC void SDLCALL SDL_PushGPUDebugGroup(
  1184. SDL_GPUCommandBuffer *commandBuffer,
  1185. const char *name);
  1186. /**
  1187. * Ends the most-recently pushed debug group.
  1188. *
  1189. * \param commandBuffer a command buffer.
  1190. *
  1191. * \since This function is available since SDL 3.0.0.
  1192. *
  1193. * \sa SDL_PushGPUDebugGroup
  1194. */
  1195. extern SDL_DECLSPEC void SDLCALL SDL_PopGPUDebugGroup(
  1196. SDL_GPUCommandBuffer *commandBuffer);
  1197. /* Disposal */
  1198. /**
  1199. * Frees the given texture as soon as it is safe to do so.
  1200. *
  1201. * You must not reference the texture after calling this function.
  1202. *
  1203. * \param device a GPU context.
  1204. * \param texture a texture to be destroyed.
  1205. *
  1206. * \since This function is available since SDL 3.0.0.
  1207. */
  1208. extern SDL_DECLSPEC void SDLCALL SDL_ReleaseGPUTexture(
  1209. SDL_GPUDevice *device,
  1210. SDL_GPUTexture *texture);
  1211. /**
  1212. * Frees the given sampler as soon as it is safe to do so.
  1213. *
  1214. * You must not reference the texture after calling this function.
  1215. *
  1216. * \param device a GPU context.
  1217. * \param sampler a sampler to be destroyed.
  1218. *
  1219. * \since This function is available since SDL 3.0.0.
  1220. */
  1221. extern SDL_DECLSPEC void SDLCALL SDL_ReleaseGPUSampler(
  1222. SDL_GPUDevice *device,
  1223. SDL_GPUSampler *sampler);
  1224. /**
  1225. * Frees the given buffer as soon as it is safe to do so.
  1226. *
  1227. * You must not reference the buffer after calling this function.
  1228. *
  1229. * \param device a GPU context.
  1230. * \param buffer a buffer to be destroyed.
  1231. *
  1232. * \since This function is available since SDL 3.0.0.
  1233. */
  1234. extern SDL_DECLSPEC void SDLCALL SDL_ReleaseGPUBuffer(
  1235. SDL_GPUDevice *device,
  1236. SDL_GPUBuffer *buffer);
  1237. /**
  1238. * Frees the given transfer buffer as soon as it is safe to do so.
  1239. *
  1240. * You must not reference the transfer buffer after calling this function.
  1241. *
  1242. * \param device a GPU context.
  1243. * \param transferBuffer a transfer buffer to be destroyed.
  1244. *
  1245. * \since This function is available since SDL 3.0.0.
  1246. */
  1247. extern SDL_DECLSPEC void SDLCALL SDL_ReleaseGPUTransferBuffer(
  1248. SDL_GPUDevice *device,
  1249. SDL_GPUTransferBuffer *transferBuffer);
  1250. /**
  1251. * Frees the given compute pipeline as soon as it is safe to do so.
  1252. *
  1253. * You must not reference the compute pipeline after calling this function.
  1254. *
  1255. * \param device a GPU context.
  1256. * \param computePipeline a compute pipeline to be destroyed.
  1257. *
  1258. * \since This function is available since SDL 3.0.0.
  1259. */
  1260. extern SDL_DECLSPEC void SDLCALL SDL_ReleaseGPUComputePipeline(
  1261. SDL_GPUDevice *device,
  1262. SDL_GPUComputePipeline *computePipeline);
  1263. /**
  1264. * Frees the given shader as soon as it is safe to do so.
  1265. *
  1266. * You must not reference the shader after calling this function.
  1267. *
  1268. * \param device a GPU context.
  1269. * \param shader a shader to be destroyed.
  1270. *
  1271. * \since This function is available since SDL 3.0.0.
  1272. */
  1273. extern SDL_DECLSPEC void SDLCALL SDL_ReleaseGPUShader(
  1274. SDL_GPUDevice *device,
  1275. SDL_GPUShader *shader);
  1276. /**
  1277. * Frees the given graphics pipeline as soon as it is safe to do so.
  1278. *
  1279. * You must not reference the graphics pipeline after calling this function.
  1280. *
  1281. * \param device a GPU context.
  1282. * \param graphicsPipeline a graphics pipeline to be destroyed.
  1283. *
  1284. * \since This function is available since SDL 3.0.0.
  1285. */
  1286. extern SDL_DECLSPEC void SDLCALL SDL_ReleaseGPUGraphicsPipeline(
  1287. SDL_GPUDevice *device,
  1288. SDL_GPUGraphicsPipeline *graphicsPipeline);
  1289. /*
  1290. * COMMAND BUFFERS
  1291. *
  1292. * Render state is managed via command buffers.
  1293. * When setting render state, that state is always local to the command buffer.
  1294. *
  1295. * Commands only begin execution on the GPU once Submit is called.
  1296. * Once the command buffer is submitted, it is no longer valid to use it.
  1297. *
  1298. * Command buffers are executed in submission order. If you submit command buffer A and then command buffer B
  1299. * all commands in A will begin executing before any command in B begins executing.
  1300. *
  1301. * In multi-threading scenarios, you should acquire and submit a command buffer on the same thread.
  1302. * As long as you satisfy this requirement, all functionality related to command buffers is thread-safe.
  1303. */
  1304. /**
  1305. * Acquire a command buffer.
  1306. *
  1307. * This command buffer is managed by the implementation and should not be
  1308. * freed by the user. The command buffer may only be used on the thread it was
  1309. * acquired on. The command buffer should be submitted on the thread it was
  1310. * acquired on.
  1311. *
  1312. * \param device a GPU context.
  1313. * \returns a command buffer.
  1314. *
  1315. * \since This function is available since SDL 3.0.0.
  1316. *
  1317. * \sa SDL_SubmitGPUCommandBuffer
  1318. * \sa SDL_SubmitGPUCommandBufferAndAcquireFence
  1319. */
  1320. extern SDL_DECLSPEC SDL_GPUCommandBuffer *SDLCALL SDL_AcquireGPUCommandBuffer(
  1321. SDL_GPUDevice *device);
  1322. /*
  1323. * UNIFORM DATA
  1324. *
  1325. * Uniforms are for passing data to shaders.
  1326. * The uniform data will be constant across all executions of the shader.
  1327. *
  1328. * There are 4 available uniform slots per shader stage (vertex, fragment, compute).
  1329. * Uniform data pushed to a slot on a stage keeps its value throughout the command buffer
  1330. * until you call the relevant Push function on that slot again.
  1331. *
  1332. * For example, you could write your vertex shaders to read a camera matrix from uniform binding slot 0,
  1333. * push the camera matrix at the start of the command buffer, and that data will be used for every
  1334. * subsequent draw call.
  1335. *
  1336. * It is valid to push uniform data during a render or compute pass.
  1337. *
  1338. * Uniforms are best for pushing small amounts of data.
  1339. * If you are pushing more than a matrix or two per call you should consider using a storage buffer instead.
  1340. */
  1341. /**
  1342. * Pushes data to a vertex uniform slot on the command buffer.
  1343. *
  1344. * Subsequent draw calls will use this uniform data.
  1345. *
  1346. * \param commandBuffer a command buffer.
  1347. * \param slotIndex the vertex uniform slot to push data to.
  1348. * \param data client data to write.
  1349. * \param dataLengthInBytes the length of the data to write.
  1350. *
  1351. * \since This function is available since SDL 3.0.0.
  1352. */
  1353. extern SDL_DECLSPEC void SDLCALL SDL_PushGPUVertexUniformData(
  1354. SDL_GPUCommandBuffer *commandBuffer,
  1355. Uint32 slotIndex,
  1356. const void *data,
  1357. Uint32 dataLengthInBytes);
  1358. /**
  1359. * Pushes data to a fragment uniform slot on the command buffer.
  1360. *
  1361. * Subsequent draw calls will use this uniform data.
  1362. *
  1363. * \param commandBuffer a command buffer.
  1364. * \param slotIndex the fragment uniform slot to push data to.
  1365. * \param data client data to write.
  1366. * \param dataLengthInBytes the length of the data to write.
  1367. *
  1368. * \since This function is available since SDL 3.0.0.
  1369. */
  1370. extern SDL_DECLSPEC void SDLCALL SDL_PushGPUFragmentUniformData(
  1371. SDL_GPUCommandBuffer *commandBuffer,
  1372. Uint32 slotIndex,
  1373. const void *data,
  1374. Uint32 dataLengthInBytes);
  1375. /**
  1376. * Pushes data to a uniform slot on the command buffer.
  1377. *
  1378. * Subsequent draw calls will use this uniform data.
  1379. *
  1380. * \param commandBuffer a command buffer.
  1381. * \param slotIndex the uniform slot to push data to.
  1382. * \param data client data to write.
  1383. * \param dataLengthInBytes the length of the data to write.
  1384. *
  1385. * \since This function is available since SDL 3.0.0.
  1386. */
  1387. extern SDL_DECLSPEC void SDLCALL SDL_PushGPUComputeUniformData(
  1388. SDL_GPUCommandBuffer *commandBuffer,
  1389. Uint32 slotIndex,
  1390. const void *data,
  1391. Uint32 dataLengthInBytes);
  1392. /*
  1393. * A NOTE ON CYCLING
  1394. *
  1395. * When using a command buffer, operations do not occur immediately -
  1396. * they occur some time after the command buffer is submitted.
  1397. *
  1398. * When a resource is used in a pending or active command buffer, it is considered to be "bound".
  1399. * When a resource is no longer used in any pending or active command buffers, it is considered to be "unbound".
  1400. *
  1401. * If data resources are bound, it is unspecified when that data will be unbound
  1402. * unless you acquire a fence when submitting the command buffer and wait on it.
  1403. * However, this doesn't mean you need to track resource usage manually.
  1404. *
  1405. * All of the functions and structs that involve writing to a resource have a "cycle" bool.
  1406. * GPUTransferBuffer, GPUBuffer, and GPUTexture all effectively function as ring buffers on internal resources.
  1407. * When cycle is SDL_TRUE, if the resource is bound, the cycle rotates to the next unbound internal resource,
  1408. * or if none are available, a new one is created.
  1409. * This means you don't have to worry about complex state tracking and synchronization as long as cycling is correctly employed.
  1410. *
  1411. * For example: you can call MapTransferBuffer, write texture data, UnmapTransferBuffer, and then UploadToTexture.
  1412. * The next time you write texture data to the transfer buffer, if you set the cycle param to SDL_TRUE, you don't have
  1413. * to worry about overwriting any data that is not yet uploaded.
  1414. *
  1415. * Another example: If you are using a texture in a render pass every frame, this can cause a data dependency between frames.
  1416. * If you set cycle to SDL_TRUE in the ColorAttachmentInfo struct, you can prevent this data dependency.
  1417. *
  1418. * Cycling will never undefine already bound data.
  1419. * When cycling, all data in the resource is considered to be undefined for subsequent commands until that data is written again.
  1420. * You must take care not to read undefined data.
  1421. *
  1422. * Note that when cycling a texture, the entire texture will be cycled,
  1423. * even if only part of the texture is used in the call,
  1424. * so you must consider the entire texture to contain undefined data after cycling.
  1425. *
  1426. * You must also take care not to overwrite a section of data that has been referenced in a command without cycling first.
  1427. * It is OK to overwrite unreferenced data in a bound resource without cycling,
  1428. * but overwriting a section of data that has already been referenced will produce unexpected results.
  1429. */
  1430. /* Graphics State */
  1431. /**
  1432. * Begins a render pass on a command buffer.
  1433. *
  1434. * A render pass consists of a set of texture subresources (or depth slices in
  1435. * the 3D texture case) which will be rendered to during the render pass,
  1436. * along with corresponding clear values and load/store operations. All
  1437. * operations related to graphics pipelines must take place inside of a render
  1438. * pass. A default viewport and scissor state are automatically set when this
  1439. * is called. You cannot begin another render pass, or begin a compute pass or
  1440. * copy pass until you have ended the render pass.
  1441. *
  1442. * \param commandBuffer a command buffer.
  1443. * \param colorAttachmentInfos an array of texture subresources with
  1444. * corresponding clear values and load/store ops.
  1445. * \param colorAttachmentCount the number of color attachments in the
  1446. * colorAttachmentInfos array.
  1447. * \param depthStencilAttachmentInfo a texture subresource with corresponding
  1448. * clear value and load/store ops, may be
  1449. * NULL.
  1450. * \returns a render pass handle.
  1451. *
  1452. * \since This function is available since SDL 3.0.0.
  1453. *
  1454. * \sa SDL_EndGPURenderPass
  1455. */
  1456. extern SDL_DECLSPEC SDL_GPURenderPass *SDLCALL SDL_BeginGPURenderPass(
  1457. SDL_GPUCommandBuffer *commandBuffer,
  1458. SDL_GPUColorAttachmentInfo *colorAttachmentInfos,
  1459. Uint32 colorAttachmentCount,
  1460. SDL_GPUDepthStencilAttachmentInfo *depthStencilAttachmentInfo);
  1461. /**
  1462. * Binds a graphics pipeline on a render pass to be used in rendering.
  1463. *
  1464. * A graphics pipeline must be bound before making any draw calls.
  1465. *
  1466. * \param renderPass a render pass handle.
  1467. * \param graphicsPipeline the graphics pipeline to bind.
  1468. *
  1469. * \since This function is available since SDL 3.0.0.
  1470. */
  1471. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUGraphicsPipeline(
  1472. SDL_GPURenderPass *renderPass,
  1473. SDL_GPUGraphicsPipeline *graphicsPipeline);
  1474. /**
  1475. * Sets the current viewport state on a command buffer.
  1476. *
  1477. * \param renderPass a render pass handle.
  1478. * \param viewport the viewport to set.
  1479. *
  1480. * \since This function is available since SDL 3.0.0.
  1481. */
  1482. extern SDL_DECLSPEC void SDLCALL SDL_SetGPUViewport(
  1483. SDL_GPURenderPass *renderPass,
  1484. SDL_GPUViewport *viewport);
  1485. /**
  1486. * Sets the current scissor state on a command buffer.
  1487. *
  1488. * \param renderPass a render pass handle.
  1489. * \param scissor the scissor area to set.
  1490. *
  1491. * \since This function is available since SDL 3.0.0.
  1492. */
  1493. extern SDL_DECLSPEC void SDLCALL SDL_SetGPUScissor(
  1494. SDL_GPURenderPass *renderPass,
  1495. SDL_Rect *scissor);
  1496. /**
  1497. * Binds vertex buffers on a command buffer for use with subsequent draw
  1498. * calls.
  1499. *
  1500. * \param renderPass a render pass handle.
  1501. * \param firstBinding the starting bind point for the vertex buffers.
  1502. * \param pBindings an array of SDL_GPUBufferBinding structs containing vertex
  1503. * buffers and offset values.
  1504. * \param bindingCount the number of bindings in the pBindings array.
  1505. *
  1506. * \since This function is available since SDL 3.0.0.
  1507. */
  1508. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUVertexBuffers(
  1509. SDL_GPURenderPass *renderPass,
  1510. Uint32 firstBinding,
  1511. SDL_GPUBufferBinding *pBindings,
  1512. Uint32 bindingCount);
  1513. /**
  1514. * Binds an index buffer on a command buffer for use with subsequent draw
  1515. * calls.
  1516. *
  1517. * \param renderPass a render pass handle.
  1518. * \param pBinding a pointer to a struct containing an index buffer and
  1519. * offset.
  1520. * \param indexElementSize whether the index values in the buffer are 16- or
  1521. * 32-bit.
  1522. *
  1523. * \since This function is available since SDL 3.0.0.
  1524. */
  1525. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUIndexBuffer(
  1526. SDL_GPURenderPass *renderPass,
  1527. SDL_GPUBufferBinding *pBinding,
  1528. SDL_GPUIndexElementSize indexElementSize);
  1529. /**
  1530. * Binds texture-sampler pairs for use on the vertex shader.
  1531. *
  1532. * The textures must have been created with SDL_GPU_TEXTUREUSAGE_SAMPLER.
  1533. *
  1534. * \param renderPass a render pass handle.
  1535. * \param firstSlot the vertex sampler slot to begin binding from.
  1536. * \param textureSamplerBindings an array of texture-sampler binding structs.
  1537. * \param bindingCount the number of texture-sampler pairs to bind from the
  1538. * array.
  1539. *
  1540. * \since This function is available since SDL 3.0.0.
  1541. */
  1542. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUVertexSamplers(
  1543. SDL_GPURenderPass *renderPass,
  1544. Uint32 firstSlot,
  1545. SDL_GPUTextureSamplerBinding *textureSamplerBindings,
  1546. Uint32 bindingCount);
  1547. /**
  1548. * Binds storage textures for use on the vertex shader.
  1549. *
  1550. * These textures must have been created with
  1551. * SDL_GPU_TEXTUREUSAGE_GRAPHICS_STORAGE_READ.
  1552. *
  1553. * \param renderPass a render pass handle.
  1554. * \param firstSlot the vertex storage texture slot to begin binding from.
  1555. * \param storageTextures an array of storage textures.
  1556. * \param bindingCount the number of storage texture to bind from the array.
  1557. *
  1558. * \since This function is available since SDL 3.0.0.
  1559. */
  1560. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUVertexStorageTextures(
  1561. SDL_GPURenderPass *renderPass,
  1562. Uint32 firstSlot,
  1563. SDL_GPUTexture **storageTextures,
  1564. Uint32 bindingCount);
  1565. /**
  1566. * Binds storage buffers for use on the vertex shader.
  1567. *
  1568. * These buffers must have been created with
  1569. * SDL_GPU_BUFFERUSAGE_GRAPHICS_STORAGE_READ.
  1570. *
  1571. * \param renderPass a render pass handle.
  1572. * \param firstSlot the vertex storage buffer slot to begin binding from.
  1573. * \param storageBuffers an array of buffers.
  1574. * \param bindingCount the number of buffers to bind from the array.
  1575. *
  1576. * \since This function is available since SDL 3.0.0.
  1577. */
  1578. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUVertexStorageBuffers(
  1579. SDL_GPURenderPass *renderPass,
  1580. Uint32 firstSlot,
  1581. SDL_GPUBuffer **storageBuffers,
  1582. Uint32 bindingCount);
  1583. /**
  1584. * Binds texture-sampler pairs for use on the fragment shader.
  1585. *
  1586. * The textures must have been created with SDL_GPU_TEXTUREUSAGE_SAMPLER.
  1587. *
  1588. * \param renderPass a render pass handle.
  1589. * \param firstSlot the fragment sampler slot to begin binding from.
  1590. * \param textureSamplerBindings an array of texture-sampler binding structs.
  1591. * \param bindingCount the number of texture-sampler pairs to bind from the
  1592. * array.
  1593. *
  1594. * \since This function is available since SDL 3.0.0.
  1595. */
  1596. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUFragmentSamplers(
  1597. SDL_GPURenderPass *renderPass,
  1598. Uint32 firstSlot,
  1599. SDL_GPUTextureSamplerBinding *textureSamplerBindings,
  1600. Uint32 bindingCount);
  1601. /**
  1602. * Binds storage textures for use on the fragment shader.
  1603. *
  1604. * These textures must have been created with
  1605. * SDL_GPU_TEXTUREUSAGE_GRAPHICS_STORAGE_READ.
  1606. *
  1607. * \param renderPass a render pass handle.
  1608. * \param firstSlot the fragment storage texture slot to begin binding from.
  1609. * \param storageTextures an array of storage textures.
  1610. * \param bindingCount the number of storage textures to bind from the array.
  1611. *
  1612. * \since This function is available since SDL 3.0.0.
  1613. */
  1614. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUFragmentStorageTextures(
  1615. SDL_GPURenderPass *renderPass,
  1616. Uint32 firstSlot,
  1617. SDL_GPUTexture **storageTextures,
  1618. Uint32 bindingCount);
  1619. /**
  1620. * Binds storage buffers for use on the fragment shader.
  1621. *
  1622. * These buffers must have been created with
  1623. * SDL_GPU_BUFFERUSAGE_GRAPHICS_STORAGE_READ.
  1624. *
  1625. * \param renderPass a render pass handle.
  1626. * \param firstSlot the fragment storage buffer slot to begin binding from.
  1627. * \param storageBuffers an array of storage buffers.
  1628. * \param bindingCount the number of storage buffers to bind from the array.
  1629. *
  1630. * \since This function is available since SDL 3.0.0.
  1631. */
  1632. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUFragmentStorageBuffers(
  1633. SDL_GPURenderPass *renderPass,
  1634. Uint32 firstSlot,
  1635. SDL_GPUBuffer **storageBuffers,
  1636. Uint32 bindingCount);
  1637. /* Drawing */
  1638. /**
  1639. * Draws data using bound graphics state with an index buffer and instancing
  1640. * enabled.
  1641. *
  1642. * You must not call this function before binding a graphics pipeline.
  1643. *
  1644. * Note that the `firstVertex` and `firstInstance` parameters are NOT
  1645. * compatible with built-in vertex/instance ID variables in shaders (for
  1646. * example, SV_VertexID). If your shader depends on these variables, the
  1647. * correlating draw call parameter MUST be 0.
  1648. *
  1649. * \param renderPass a render pass handle.
  1650. * \param indexCount the number of vertices to draw per instance.
  1651. * \param instanceCount the number of instances to draw.
  1652. * \param firstIndex the starting index within the index buffer.
  1653. * \param vertexOffset value added to vertex index before indexing into the
  1654. * vertex buffer.
  1655. * \param firstInstance the ID of the first instance to draw.
  1656. *
  1657. * \since This function is available since SDL 3.0.0.
  1658. */
  1659. extern SDL_DECLSPEC void SDLCALL SDL_DrawGPUIndexedPrimitives(
  1660. SDL_GPURenderPass *renderPass,
  1661. Uint32 indexCount,
  1662. Uint32 instanceCount,
  1663. Uint32 firstIndex,
  1664. Sint32 vertexOffset,
  1665. Uint32 firstInstance);
  1666. /**
  1667. * Draws data using bound graphics state.
  1668. *
  1669. * You must not call this function before binding a graphics pipeline.
  1670. *
  1671. * Note that the `firstVertex` and `firstInstance` parameters are NOT
  1672. * compatible with built-in vertex/instance ID variables in shaders (for
  1673. * example, SV_VertexID). If your shader depends on these variables, the
  1674. * correlating draw call parameter MUST be 0.
  1675. *
  1676. * \param renderPass a render pass handle.
  1677. * \param vertexCount the number of vertices to draw.
  1678. * \param instanceCount the number of instances that will be drawn.
  1679. * \param firstVertex the index of the first vertex to draw.
  1680. * \param firstInstance the ID of the first instance to draw.
  1681. *
  1682. * \since This function is available since SDL 3.0.0.
  1683. */
  1684. extern SDL_DECLSPEC void SDLCALL SDL_DrawGPUPrimitives(
  1685. SDL_GPURenderPass *renderPass,
  1686. Uint32 vertexCount,
  1687. Uint32 instanceCount,
  1688. Uint32 firstVertex,
  1689. Uint32 firstInstance);
  1690. /**
  1691. * Draws data using bound graphics state and with draw parameters set from a
  1692. * buffer.
  1693. *
  1694. * The buffer layout should match the layout of SDL_GPUIndirectDrawCommand.
  1695. * You must not call this function before binding a graphics pipeline.
  1696. *
  1697. * \param renderPass a render pass handle.
  1698. * \param buffer a buffer containing draw parameters.
  1699. * \param offsetInBytes the offset to start reading from the draw buffer.
  1700. * \param drawCount the number of draw parameter sets that should be read from
  1701. * the draw buffer.
  1702. * \param stride the byte stride between sets of draw parameters.
  1703. *
  1704. * \since This function is available since SDL 3.0.0.
  1705. */
  1706. extern SDL_DECLSPEC void SDLCALL SDL_DrawGPUPrimitivesIndirect(
  1707. SDL_GPURenderPass *renderPass,
  1708. SDL_GPUBuffer *buffer,
  1709. Uint32 offsetInBytes,
  1710. Uint32 drawCount,
  1711. Uint32 stride);
  1712. /**
  1713. * Draws data using bound graphics state with an index buffer enabled and with
  1714. * draw parameters set from a buffer.
  1715. *
  1716. * The buffer layout should match the layout of
  1717. * SDL_GPUIndexedIndirectDrawCommand. You must not call this function before
  1718. * binding a graphics pipeline.
  1719. *
  1720. * \param renderPass a render pass handle.
  1721. * \param buffer a buffer containing draw parameters.
  1722. * \param offsetInBytes the offset to start reading from the draw buffer.
  1723. * \param drawCount the number of draw parameter sets that should be read from
  1724. * the draw buffer.
  1725. * \param stride the byte stride between sets of draw parameters.
  1726. *
  1727. * \since This function is available since SDL 3.0.0.
  1728. */
  1729. extern SDL_DECLSPEC void SDLCALL SDL_DrawGPUIndexedPrimitivesIndirect(
  1730. SDL_GPURenderPass *renderPass,
  1731. SDL_GPUBuffer *buffer,
  1732. Uint32 offsetInBytes,
  1733. Uint32 drawCount,
  1734. Uint32 stride);
  1735. /**
  1736. * Ends the given render pass.
  1737. *
  1738. * All bound graphics state on the render pass command buffer is unset. The
  1739. * render pass handle is now invalid.
  1740. *
  1741. * \param renderPass a render pass handle.
  1742. *
  1743. * \since This function is available since SDL 3.0.0.
  1744. */
  1745. extern SDL_DECLSPEC void SDLCALL SDL_EndGPURenderPass(
  1746. SDL_GPURenderPass *renderPass);
  1747. /* Compute Pass */
  1748. /**
  1749. * Begins a compute pass on a command buffer.
  1750. *
  1751. * A compute pass is defined by a set of texture subresources and buffers that
  1752. * will be written to by compute pipelines. These textures and buffers must
  1753. * have been created with the COMPUTE_STORAGE_WRITE bit. All operations
  1754. * related to compute pipelines must take place inside of a compute pass. You
  1755. * must not begin another compute pass, or a render pass or copy pass before
  1756. * ending the compute pass.
  1757. *
  1758. * A VERY IMPORTANT NOTE Textures and buffers bound as write-only MUST NOT be
  1759. * read from during the compute pass. Doing so will result in undefined
  1760. * behavior. If your compute work requires reading the output from a previous
  1761. * dispatch, you MUST end the current compute pass and begin a new one before
  1762. * you can safely access the data.
  1763. *
  1764. * \param commandBuffer a command buffer.
  1765. * \param storageTextureBindings an array of writeable storage texture binding
  1766. * structs.
  1767. * \param storageTextureBindingCount the number of storage textures to bind
  1768. * from the array.
  1769. * \param storageBufferBindings an array of writeable storage buffer binding
  1770. * structs.
  1771. * \param storageBufferBindingCount the number of storage buffers to bind from
  1772. * the array.
  1773. * \returns a compute pass handle.
  1774. *
  1775. * \since This function is available since SDL 3.0.0.
  1776. *
  1777. * \sa SDL_EndGPUComputePass
  1778. */
  1779. extern SDL_DECLSPEC SDL_GPUComputePass *SDLCALL SDL_BeginGPUComputePass(
  1780. SDL_GPUCommandBuffer *commandBuffer,
  1781. SDL_GPUStorageTextureWriteOnlyBinding *storageTextureBindings,
  1782. Uint32 storageTextureBindingCount,
  1783. SDL_GPUStorageBufferWriteOnlyBinding *storageBufferBindings,
  1784. Uint32 storageBufferBindingCount);
  1785. /**
  1786. * Binds a compute pipeline on a command buffer for use in compute dispatch.
  1787. *
  1788. * \param computePass a compute pass handle.
  1789. * \param computePipeline a compute pipeline to bind.
  1790. *
  1791. * \since This function is available since SDL 3.0.0.
  1792. */
  1793. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUComputePipeline(
  1794. SDL_GPUComputePass *computePass,
  1795. SDL_GPUComputePipeline *computePipeline);
  1796. /**
  1797. * Binds storage textures as readonly for use on the compute pipeline.
  1798. *
  1799. * These textures must have been created with
  1800. * SDL_GPU_TEXTUREUSAGE_COMPUTE_STORAGE_READ.
  1801. *
  1802. * \param computePass a compute pass handle.
  1803. * \param firstSlot the compute storage texture slot to begin binding from.
  1804. * \param storageTextures an array of storage textures.
  1805. * \param bindingCount the number of storage textures to bind from the array.
  1806. *
  1807. * \since This function is available since SDL 3.0.0.
  1808. */
  1809. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUComputeStorageTextures(
  1810. SDL_GPUComputePass *computePass,
  1811. Uint32 firstSlot,
  1812. SDL_GPUTexture **storageTextures,
  1813. Uint32 bindingCount);
  1814. /**
  1815. * Binds storage buffers as readonly for use on the compute pipeline.
  1816. *
  1817. * These buffers must have been created with
  1818. * SDL_GPU_BUFFERUSAGE_COMPUTE_STORAGE_READ.
  1819. *
  1820. * \param computePass a compute pass handle.
  1821. * \param firstSlot the compute storage buffer slot to begin binding from.
  1822. * \param storageBuffers an array of storage buffer binding structs.
  1823. * \param bindingCount the number of storage buffers to bind from the array.
  1824. *
  1825. * \since This function is available since SDL 3.0.0.
  1826. */
  1827. extern SDL_DECLSPEC void SDLCALL SDL_BindGPUComputeStorageBuffers(
  1828. SDL_GPUComputePass *computePass,
  1829. Uint32 firstSlot,
  1830. SDL_GPUBuffer **storageBuffers,
  1831. Uint32 bindingCount);
  1832. /**
  1833. * Dispatches compute work.
  1834. *
  1835. * You must not call this function before binding a compute pipeline.
  1836. *
  1837. * A VERY IMPORTANT NOTE If you dispatch multiple times in a compute pass, and
  1838. * the dispatches write to the same resource region as each other, there is no
  1839. * guarantee of which order the writes will occur. If the write order matters,
  1840. * you MUST end the compute pass and begin another one.
  1841. *
  1842. * \param computePass a compute pass handle.
  1843. * \param groupCountX number of local workgroups to dispatch in the X
  1844. * dimension.
  1845. * \param groupCountY number of local workgroups to dispatch in the Y
  1846. * dimension.
  1847. * \param groupCountZ number of local workgroups to dispatch in the Z
  1848. * dimension.
  1849. *
  1850. * \since This function is available since SDL 3.0.0.
  1851. */
  1852. extern SDL_DECLSPEC void SDLCALL SDL_DispatchGPUCompute(
  1853. SDL_GPUComputePass *computePass,
  1854. Uint32 groupCountX,
  1855. Uint32 groupCountY,
  1856. Uint32 groupCountZ);
  1857. /**
  1858. * Dispatches compute work with parameters set from a buffer.
  1859. *
  1860. * The buffer layout should match the layout of
  1861. * SDL_GPUIndirectDispatchCommand. You must not call this function before
  1862. * binding a compute pipeline.
  1863. *
  1864. * A VERY IMPORTANT NOTE If you dispatch multiple times in a compute pass, and
  1865. * the dispatches write to the same resource region as each other, there is no
  1866. * guarantee of which order the writes will occur. If the write order matters,
  1867. * you MUST end the compute pass and begin another one.
  1868. *
  1869. * \param computePass a compute pass handle.
  1870. * \param buffer a buffer containing dispatch parameters.
  1871. * \param offsetInBytes the offset to start reading from the dispatch buffer.
  1872. *
  1873. * \since This function is available since SDL 3.0.0.
  1874. */
  1875. extern SDL_DECLSPEC void SDLCALL SDL_DispatchGPUComputeIndirect(
  1876. SDL_GPUComputePass *computePass,
  1877. SDL_GPUBuffer *buffer,
  1878. Uint32 offsetInBytes);
  1879. /**
  1880. * Ends the current compute pass.
  1881. *
  1882. * All bound compute state on the command buffer is unset. The compute pass
  1883. * handle is now invalid.
  1884. *
  1885. * \param computePass a compute pass handle.
  1886. *
  1887. * \since This function is available since SDL 3.0.0.
  1888. */
  1889. extern SDL_DECLSPEC void SDLCALL SDL_EndGPUComputePass(
  1890. SDL_GPUComputePass *computePass);
  1891. /* TransferBuffer Data */
  1892. /**
  1893. * Maps a transfer buffer into application address space.
  1894. *
  1895. * You must unmap the transfer buffer before encoding upload commands.
  1896. *
  1897. * \param device a GPU context.
  1898. * \param transferBuffer a transfer buffer.
  1899. * \param cycle if SDL_TRUE, cycles the transfer buffer if it is bound.
  1900. * \returns the address of the mapped transfer buffer memory.
  1901. *
  1902. * \since This function is available since SDL 3.0.0.
  1903. */
  1904. extern SDL_DECLSPEC void *SDLCALL SDL_MapGPUTransferBuffer(
  1905. SDL_GPUDevice *device,
  1906. SDL_GPUTransferBuffer *transferBuffer,
  1907. SDL_bool cycle);
  1908. /**
  1909. * Unmaps a previously mapped transfer buffer.
  1910. *
  1911. * \param device a GPU context.
  1912. * \param transferBuffer a previously mapped transfer buffer.
  1913. *
  1914. * \since This function is available since SDL 3.0.0.
  1915. */
  1916. extern SDL_DECLSPEC void SDLCALL SDL_UnmapGPUTransferBuffer(
  1917. SDL_GPUDevice *device,
  1918. SDL_GPUTransferBuffer *transferBuffer);
  1919. /* Copy Pass */
  1920. /**
  1921. * Begins a copy pass on a command buffer.
  1922. *
  1923. * All operations related to copying to or from buffers or textures take place
  1924. * inside a copy pass. You must not begin another copy pass, or a render pass
  1925. * or compute pass before ending the copy pass.
  1926. *
  1927. * \param commandBuffer a command buffer.
  1928. * \returns a copy pass handle.
  1929. *
  1930. * \since This function is available since SDL 3.0.0.
  1931. */
  1932. extern SDL_DECLSPEC SDL_GPUCopyPass *SDLCALL SDL_BeginGPUCopyPass(
  1933. SDL_GPUCommandBuffer *commandBuffer);
  1934. /**
  1935. * Uploads data from a transfer buffer to a texture.
  1936. *
  1937. * The upload occurs on the GPU timeline. You may assume that the upload has
  1938. * finished in subsequent commands.
  1939. *
  1940. * You must align the data in the transfer buffer to a multiple of the texel
  1941. * size of the texture format.
  1942. *
  1943. * \param copyPass a copy pass handle.
  1944. * \param source the source transfer buffer with image layout information.
  1945. * \param destination the destination texture region.
  1946. * \param cycle if SDL_TRUE, cycles the texture if the texture is bound,
  1947. * otherwise overwrites the data.
  1948. *
  1949. * \since This function is available since SDL 3.0.0.
  1950. */
  1951. extern SDL_DECLSPEC void SDLCALL SDL_UploadToGPUTexture(
  1952. SDL_GPUCopyPass *copyPass,
  1953. SDL_GPUTextureTransferInfo *source,
  1954. SDL_GPUTextureRegion *destination,
  1955. SDL_bool cycle);
  1956. /* Uploads data from a TransferBuffer to a Buffer. */
  1957. /**
  1958. * Uploads data from a transfer buffer to a buffer.
  1959. *
  1960. * The upload occurs on the GPU timeline. You may assume that the upload has
  1961. * finished in subsequent commands.
  1962. *
  1963. * \param copyPass a copy pass handle.
  1964. * \param source the source transfer buffer with offset.
  1965. * \param destination the destination buffer with offset and size.
  1966. * \param cycle if SDL_TRUE, cycles the buffer if it is bound, otherwise
  1967. * overwrites the data.
  1968. *
  1969. * \since This function is available since SDL 3.0.0.
  1970. */
  1971. extern SDL_DECLSPEC void SDLCALL SDL_UploadToGPUBuffer(
  1972. SDL_GPUCopyPass *copyPass,
  1973. SDL_GPUTransferBufferLocation *source,
  1974. SDL_GPUBufferRegion *destination,
  1975. SDL_bool cycle);
  1976. /**
  1977. * Performs a texture-to-texture copy.
  1978. *
  1979. * This copy occurs on the GPU timeline. You may assume the copy has finished
  1980. * in subsequent commands.
  1981. *
  1982. * \param copyPass a copy pass handle.
  1983. * \param source a source texture region.
  1984. * \param destination a destination texture region.
  1985. * \param w the width of the region to copy.
  1986. * \param h the height of the region to copy.
  1987. * \param d the depth of the region to copy.
  1988. * \param cycle if SDL_TRUE, cycles the destination texture if the destination
  1989. * texture is bound, otherwise overwrites the data.
  1990. *
  1991. * \since This function is available since SDL 3.0.0.
  1992. */
  1993. extern SDL_DECLSPEC void SDLCALL SDL_CopyGPUTextureToTexture(
  1994. SDL_GPUCopyPass *copyPass,
  1995. SDL_GPUTextureLocation *source,
  1996. SDL_GPUTextureLocation *destination,
  1997. Uint32 w,
  1998. Uint32 h,
  1999. Uint32 d,
  2000. SDL_bool cycle);
  2001. /* Copies data from a buffer to a buffer. */
  2002. /**
  2003. * Performs a buffer-to-buffer copy.
  2004. *
  2005. * This copy occurs on the GPU timeline. You may assume the copy has finished
  2006. * in subsequent commands.
  2007. *
  2008. * \param copyPass a copy pass handle.
  2009. * \param source the buffer and offset to copy from.
  2010. * \param destination the buffer and offset to copy to.
  2011. * \param size the length of the buffer to copy.
  2012. * \param cycle if SDL_TRUE, cycles the destination buffer if it is bound,
  2013. * otherwise overwrites the data.
  2014. *
  2015. * \since This function is available since SDL 3.0.0.
  2016. */
  2017. extern SDL_DECLSPEC void SDLCALL SDL_CopyGPUBufferToBuffer(
  2018. SDL_GPUCopyPass *copyPass,
  2019. SDL_GPUBufferLocation *source,
  2020. SDL_GPUBufferLocation *destination,
  2021. Uint32 size,
  2022. SDL_bool cycle);
  2023. /**
  2024. * Copies data from a texture to a transfer buffer on the GPU timeline.
  2025. *
  2026. * This data is not guaranteed to be copied until the command buffer fence is
  2027. * signaled.
  2028. *
  2029. * \param copyPass a copy pass handle.
  2030. * \param source the source texture region.
  2031. * \param destination the destination transfer buffer with image layout
  2032. * information.
  2033. *
  2034. * \since This function is available since SDL 3.0.0.
  2035. */
  2036. extern SDL_DECLSPEC void SDLCALL SDL_DownloadFromGPUTexture(
  2037. SDL_GPUCopyPass *copyPass,
  2038. SDL_GPUTextureRegion *source,
  2039. SDL_GPUTextureTransferInfo *destination);
  2040. /**
  2041. * Copies data from a buffer to a transfer buffer on the GPU timeline.
  2042. *
  2043. * This data is not guaranteed to be copied until the command buffer fence is
  2044. * signaled.
  2045. *
  2046. * \param copyPass a copy pass handle.
  2047. * \param source the source buffer with offset and size.
  2048. * \param destination the destination transfer buffer with offset.
  2049. *
  2050. * \since This function is available since SDL 3.0.0.
  2051. */
  2052. extern SDL_DECLSPEC void SDLCALL SDL_DownloadFromGPUBuffer(
  2053. SDL_GPUCopyPass *copyPass,
  2054. SDL_GPUBufferRegion *source,
  2055. SDL_GPUTransferBufferLocation *destination);
  2056. /**
  2057. * Ends the current copy pass.
  2058. *
  2059. * \param copyPass a copy pass handle.
  2060. *
  2061. * \since This function is available since SDL 3.0.0.
  2062. */
  2063. extern SDL_DECLSPEC void SDLCALL SDL_EndGPUCopyPass(
  2064. SDL_GPUCopyPass *copyPass);
  2065. /**
  2066. * Generates mipmaps for the given texture.
  2067. *
  2068. * This function must not be called inside of any pass.
  2069. *
  2070. * \param commandBuffer a commandBuffer.
  2071. * \param texture a texture with more than 1 mip level.
  2072. *
  2073. * \since This function is available since SDL 3.0.0.
  2074. */
  2075. extern SDL_DECLSPEC void SDLCALL SDL_GenerateMipmapsForGPUTexture(
  2076. SDL_GPUCommandBuffer *commandBuffer,
  2077. SDL_GPUTexture *texture);
  2078. /**
  2079. * Blits from a source texture region to a destination texture region.
  2080. *
  2081. * This function must not be called inside of any pass.
  2082. *
  2083. * \param commandBuffer a command buffer.
  2084. * \param source the texture region to copy from.
  2085. * \param destination the texture region to copy to.
  2086. * \param flipMode the flip mode for the source texture region.
  2087. * \param filterMode the filter mode that will be used when blitting.
  2088. * \param cycle if SDL_TRUE, cycles the destination texture if the destination
  2089. * texture is bound, otherwise overwrites the data.
  2090. *
  2091. * \since This function is available since SDL 3.0.0.
  2092. */
  2093. extern SDL_DECLSPEC void SDLCALL SDL_BlitGPUTexture(
  2094. SDL_GPUCommandBuffer *commandBuffer,
  2095. SDL_GPUBlitRegion *source,
  2096. SDL_GPUBlitRegion *destination,
  2097. SDL_FlipMode flipMode,
  2098. SDL_GPUFilter filterMode,
  2099. SDL_bool cycle);
  2100. /* Submission/Presentation */
  2101. /**
  2102. * Determines whether a swapchain composition is supported by the window.
  2103. *
  2104. * The window must be claimed before calling this function.
  2105. *
  2106. * \param device a GPU context.
  2107. * \param window an SDL_Window.
  2108. * \param swapchainComposition the swapchain composition to check.
  2109. * \returns SDL_TRUE if supported, SDL_FALSE if unsupported (or on error).
  2110. *
  2111. * \since This function is available since SDL 3.0.0.
  2112. *
  2113. * \sa SDL_ClaimWindowForGPUDevice
  2114. */
  2115. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_WindowSupportsGPUSwapchainComposition(
  2116. SDL_GPUDevice *device,
  2117. SDL_Window *window,
  2118. SDL_GPUSwapchainComposition swapchainComposition);
  2119. /**
  2120. * Determines whether a presentation mode is supported by the window.
  2121. *
  2122. * The window must be claimed before calling this function.
  2123. *
  2124. * \param device a GPU context.
  2125. * \param window an SDL_Window.
  2126. * \param presentMode the presentation mode to check.
  2127. * \returns SDL_TRUE if supported, SDL_FALSE if unsupported (or on error).
  2128. *
  2129. * \since This function is available since SDL 3.0.0.
  2130. *
  2131. * \sa SDL_ClaimWindowForGPUDevice
  2132. */
  2133. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_WindowSupportsGPUPresentMode(
  2134. SDL_GPUDevice *device,
  2135. SDL_Window *window,
  2136. SDL_GPUPresentMode presentMode);
  2137. /**
  2138. * Claims a window, creating a swapchain structure for it.
  2139. *
  2140. * This must be called before SDL_AcquireGPUSwapchainTexture is called using
  2141. * the window.
  2142. *
  2143. * The swapchain will be created with SDL_GPU_SWAPCHAINCOMPOSITION_SDR and
  2144. * SDL_GPU_PRESENTMODE_VSYNC. If you want to have different swapchain
  2145. * parameters, you must call SetSwapchainParameters after claiming the window.
  2146. *
  2147. * \param device a GPU context.
  2148. * \param window an SDL_Window.
  2149. * \returns SDL_TRUE on success, otherwise SDL_FALSE.
  2150. *
  2151. * \since This function is available since SDL 3.0.0.
  2152. *
  2153. * \sa SDL_AcquireGPUSwapchainTexture
  2154. * \sa SDL_ReleaseWindowFromGPUDevice
  2155. * \sa SDL_WindowSupportsGPUPresentMode
  2156. * \sa SDL_WindowSupportsGPUSwapchainComposition
  2157. */
  2158. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ClaimWindowForGPUDevice(
  2159. SDL_GPUDevice *device,
  2160. SDL_Window *window);
  2161. /**
  2162. * Unclaims a window, destroying its swapchain structure.
  2163. *
  2164. * \param device a GPU context.
  2165. * \param window an SDL_Window that has been claimed.
  2166. *
  2167. * \since This function is available since SDL 3.0.0.
  2168. *
  2169. * \sa SDL_ClaimWindowForGPUDevice
  2170. */
  2171. extern SDL_DECLSPEC void SDLCALL SDL_ReleaseWindowFromGPUDevice(
  2172. SDL_GPUDevice *device,
  2173. SDL_Window *window);
  2174. /**
  2175. * Changes the swapchain parameters for the given claimed window.
  2176. *
  2177. * This function will fail if the requested present mode or swapchain
  2178. * composition are unsupported by the device. Check if the parameters are
  2179. * supported via SDL_WindowSupportsGPUPresentMode /
  2180. * SDL_WindowSupportsGPUSwapchainComposition prior to calling this function.
  2181. *
  2182. * SDL_GPU_PRESENTMODE_VSYNC and SDL_GPU_SWAPCHAINCOMPOSITION_SDR are always
  2183. * supported.
  2184. *
  2185. * \param device a GPU context.
  2186. * \param window an SDL_Window that has been claimed.
  2187. * \param swapchainComposition the desired composition of the swapchain.
  2188. * \param presentMode the desired present mode for the swapchain.
  2189. * \returns SDL_TRUE if successful, SDL_FALSE on error.
  2190. *
  2191. * \since This function is available since SDL 3.0.0.
  2192. *
  2193. * \sa SDL_WindowSupportsGPUPresentMode
  2194. * \sa SDL_WindowSupportsGPUSwapchainComposition
  2195. */
  2196. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetGPUSwapchainParameters(
  2197. SDL_GPUDevice *device,
  2198. SDL_Window *window,
  2199. SDL_GPUSwapchainComposition swapchainComposition,
  2200. SDL_GPUPresentMode presentMode);
  2201. /**
  2202. * Obtains the texture format of the swapchain for the given window.
  2203. *
  2204. * \param device a GPU context.
  2205. * \param window an SDL_Window that has been claimed.
  2206. * \returns the texture format of the swapchain.
  2207. *
  2208. * \since This function is available since SDL 3.0.0.
  2209. */
  2210. extern SDL_DECLSPEC SDL_GPUTextureFormat SDLCALL SDL_GetGPUSwapchainTextureFormat(
  2211. SDL_GPUDevice *device,
  2212. SDL_Window *window);
  2213. /**
  2214. * Acquire a texture to use in presentation.
  2215. *
  2216. * When a swapchain texture is acquired on a command buffer, it will
  2217. * automatically be submitted for presentation when the command buffer is
  2218. * submitted. The swapchain texture should only be referenced by the command
  2219. * buffer used to acquire it. May return NULL under certain conditions. This
  2220. * is not necessarily an error. This texture is managed by the implementation
  2221. * and must not be freed by the user. You MUST NOT call this function from any
  2222. * thread other than the one that created the window.
  2223. *
  2224. * \param commandBuffer a command buffer.
  2225. * \param window a window that has been claimed.
  2226. * \param pWidth a pointer filled in with the swapchain width.
  2227. * \param pHeight a pointer filled in with the swapchain height.
  2228. * \returns a swapchain texture.
  2229. *
  2230. * \since This function is available since SDL 3.0.0.
  2231. *
  2232. * \sa SDL_ClaimWindowForGPUDevice
  2233. * \sa SDL_SubmitGPUCommandBuffer
  2234. * \sa SDL_SubmitGPUCommandBufferAndAcquireFence
  2235. */
  2236. extern SDL_DECLSPEC SDL_GPUTexture *SDLCALL SDL_AcquireGPUSwapchainTexture(
  2237. SDL_GPUCommandBuffer *commandBuffer,
  2238. SDL_Window *window,
  2239. Uint32 *pWidth,
  2240. Uint32 *pHeight);
  2241. /**
  2242. * Submits a command buffer so its commands can be processed on the GPU.
  2243. *
  2244. * It is invalid to use the command buffer after this is called.
  2245. *
  2246. * This must be called from the thread the command buffer was acquired on.
  2247. *
  2248. * All commands in the submission are guaranteed to begin executing before any
  2249. * command in a subsequent submission begins executing.
  2250. *
  2251. * \param commandBuffer a command buffer.
  2252. *
  2253. * \since This function is available since SDL 3.0.0.
  2254. *
  2255. * \sa SDL_AcquireGPUCommandBuffer
  2256. * \sa SDL_AcquireGPUSwapchainTexture
  2257. * \sa SDL_SubmitGPUCommandBufferAndAcquireFence
  2258. */
  2259. extern SDL_DECLSPEC void SDLCALL SDL_SubmitGPUCommandBuffer(
  2260. SDL_GPUCommandBuffer *commandBuffer);
  2261. /**
  2262. * Submits a command buffer so its commands can be processed on the GPU, and
  2263. * acquires a fence associated with the command buffer.
  2264. *
  2265. * You must release this fence when it is no longer needed or it will cause a
  2266. * leak. It is invalid to use the command buffer after this is called.
  2267. *
  2268. * This must be called from the thread the command buffer was acquired on.
  2269. *
  2270. * All commands in the submission are guaranteed to begin executing before any
  2271. * command in a subsequent submission begins executing.
  2272. *
  2273. * \param commandBuffer a command buffer.
  2274. * \returns a fence associated with the command buffer.
  2275. *
  2276. * \since This function is available since SDL 3.0.0.
  2277. *
  2278. * \sa SDL_AcquireGPUCommandBuffer
  2279. * \sa SDL_AcquireGPUSwapchainTexture
  2280. * \sa SDL_SubmitGPUCommandBuffer
  2281. * \sa SDL_ReleaseGPUFence
  2282. */
  2283. extern SDL_DECLSPEC SDL_GPUFence *SDLCALL SDL_SubmitGPUCommandBufferAndAcquireFence(
  2284. SDL_GPUCommandBuffer *commandBuffer);
  2285. /**
  2286. * Blocks the thread until the GPU is completely idle.
  2287. *
  2288. * \param device a GPU context.
  2289. *
  2290. * \since This function is available since SDL 3.0.0.
  2291. *
  2292. * \sa SDL_WaitForGPUFences
  2293. */
  2294. extern SDL_DECLSPEC void SDLCALL SDL_WaitForGPUIdle(
  2295. SDL_GPUDevice *device);
  2296. /**
  2297. * Blocks the thread until the given fences are signaled.
  2298. *
  2299. * \param device a GPU context.
  2300. * \param waitAll if 0, wait for any fence to be signaled, if 1, wait for all
  2301. * fences to be signaled.
  2302. * \param pFences an array of fences to wait on.
  2303. * \param fenceCount the number of fences in the pFences array.
  2304. *
  2305. * \since This function is available since SDL 3.0.0.
  2306. *
  2307. * \sa SDL_SubmitGPUCommandBufferAndAcquireFence
  2308. * \sa SDL_WaitForGPUIdle
  2309. */
  2310. extern SDL_DECLSPEC void SDLCALL SDL_WaitForGPUFences(
  2311. SDL_GPUDevice *device,
  2312. SDL_bool waitAll,
  2313. SDL_GPUFence **pFences,
  2314. Uint32 fenceCount);
  2315. /**
  2316. * Checks the status of a fence.
  2317. *
  2318. * \param device a GPU context.
  2319. * \param fence a fence.
  2320. * \returns SDL_TRUE if the fence is signaled, SDL_FALSE if it is not.
  2321. *
  2322. * \since This function is available since SDL 3.0.0.
  2323. *
  2324. * \sa SDL_SubmitGPUCommandBufferAndAcquireFence
  2325. */
  2326. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_QueryGPUFence(
  2327. SDL_GPUDevice *device,
  2328. SDL_GPUFence *fence);
  2329. /**
  2330. * Releases a fence obtained from SDL_SubmitGPUCommandBufferAndAcquireFence.
  2331. *
  2332. * \param device a GPU context.
  2333. * \param fence a fence.
  2334. *
  2335. * \since This function is available since SDL 3.0.0.
  2336. *
  2337. * \sa SDL_SubmitGPUCommandBufferAndAcquireFence
  2338. */
  2339. extern SDL_DECLSPEC void SDLCALL SDL_ReleaseGPUFence(
  2340. SDL_GPUDevice *device,
  2341. SDL_GPUFence *fence);
  2342. /* Format Info */
  2343. /**
  2344. * Obtains the texel block size for a texture format.
  2345. *
  2346. * \param textureFormat the texture format you want to know the texel size of.
  2347. * \returns the texel block size of the texture format.
  2348. *
  2349. * \since This function is available since SDL 3.0.0.
  2350. *
  2351. * \sa SDL_UploadToGPUTexture
  2352. */
  2353. extern SDL_DECLSPEC Uint32 SDLCALL SDL_GPUTextureFormatTexelBlockSize(
  2354. SDL_GPUTextureFormat textureFormat);
  2355. /**
  2356. * Determines whether a texture format is supported for a given type and
  2357. * usage.
  2358. *
  2359. * \param device a GPU context.
  2360. * \param format the texture format to check.
  2361. * \param type the type of texture (2D, 3D, Cube).
  2362. * \param usage a bitmask of all usage scenarios to check.
  2363. * \returns whether the texture format is supported for this type and usage.
  2364. *
  2365. * \since This function is available since SDL 3.0.0.
  2366. */
  2367. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GPUTextureSupportsFormat(
  2368. SDL_GPUDevice *device,
  2369. SDL_GPUTextureFormat format,
  2370. SDL_GPUTextureType type,
  2371. SDL_GPUTextureUsageFlags usage);
  2372. /**
  2373. * Determines if a sample count for a texture format is supported.
  2374. *
  2375. * \param device a GPU context.
  2376. * \param format the texture format to check.
  2377. * \param sampleCount the sample count to check.
  2378. * \returns a hardware-specific version of min(preferred, possible).
  2379. *
  2380. * \since This function is available since SDL 3.0.0.
  2381. */
  2382. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GPUTextureSupportsSampleCount(
  2383. SDL_GPUDevice *device,
  2384. SDL_GPUTextureFormat format,
  2385. SDL_GPUSampleCount sampleCount);
  2386. #ifdef SDL_PLATFORM_GDK
  2387. /**
  2388. * Call this to suspend GPU operation on Xbox when you receive the
  2389. * SDL_EVENT_DID_ENTER_BACKGROUND event.
  2390. *
  2391. * Do NOT call any SDL_GPU functions after calling this function! This must
  2392. * also be called before calling SDL_GDKSuspendComplete.
  2393. *
  2394. * \param device a GPU context.
  2395. *
  2396. * \since This function is available since SDL 3.0.0.
  2397. *
  2398. * \sa SDL_AddEventWatch
  2399. */
  2400. extern SDL_DECLSPEC void SDLCALL SDL_GDKSuspendGPU(SDL_GPUDevice *device);
  2401. /**
  2402. * Call this to resume GPU operation on Xbox when you receive the
  2403. * SDL_EVENT_WILL_ENTER_FOREGROUND event.
  2404. *
  2405. * When resuming, this function MUST be called before calling any other
  2406. * SDL_GPU functions.
  2407. *
  2408. * \param device a GPU context.
  2409. *
  2410. * \since This function is available since SDL 3.0.0.
  2411. *
  2412. * \sa SDL_AddEventWatch
  2413. */
  2414. extern SDL_DECLSPEC void SDLCALL SDL_GDKResumeGPU(SDL_GPUDevice *device);
  2415. #endif /* SDL_PLATFORM_GDK */
  2416. #ifdef __cplusplus
  2417. }
  2418. #endif /* __cplusplus */
  2419. #include <SDL3/SDL_close_code.h>
  2420. #endif /* SDL_gpu_h_ */