SDL_gpu.h 84 KB

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