SDL_sysgpu.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  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. #include "../video/SDL_sysvideo.h"
  19. #include "SDL_internal.h"
  20. #ifndef SDL_GPU_DRIVER_H
  21. #define SDL_GPU_DRIVER_H
  22. // Common Structs
  23. typedef struct Pass
  24. {
  25. SDL_GPUCommandBuffer *command_buffer;
  26. bool in_progress;
  27. } Pass;
  28. typedef struct CommandBufferCommonHeader
  29. {
  30. SDL_GPUDevice *device;
  31. Pass render_pass;
  32. bool graphics_pipeline_bound;
  33. Pass compute_pass;
  34. bool compute_pipeline_bound;
  35. Pass copy_pass;
  36. bool submitted;
  37. } CommandBufferCommonHeader;
  38. typedef struct TextureCommonHeader
  39. {
  40. SDL_GPUTextureCreateInfo info;
  41. } TextureCommonHeader;
  42. typedef struct BlitFragmentUniforms
  43. {
  44. // texcoord space
  45. float left;
  46. float top;
  47. float width;
  48. float height;
  49. Uint32 mip_level;
  50. float layer_or_depth;
  51. } BlitFragmentUniforms;
  52. typedef struct BlitPipelineCacheEntry
  53. {
  54. SDL_GPUTextureType type;
  55. SDL_GPUTextureFormat format;
  56. SDL_GPUGraphicsPipeline *pipeline;
  57. } BlitPipelineCacheEntry;
  58. // Internal Helper Utilities
  59. #define SDL_GPU_TEXTUREFORMAT_MAX_ENUM_VALUE (SDL_GPU_TEXTUREFORMAT_ASTC_12x12_FLOAT + 1)
  60. #define SDL_GPU_VERTEXELEMENTFORMAT_MAX_ENUM_VALUE (SDL_GPU_VERTEXELEMENTFORMAT_HALF4 + 1)
  61. #define SDL_GPU_COMPAREOP_MAX_ENUM_VALUE (SDL_GPU_COMPAREOP_ALWAYS + 1)
  62. #define SDL_GPU_STENCILOP_MAX_ENUM_VALUE (SDL_GPU_STENCILOP_DECREMENT_AND_WRAP + 1)
  63. #define SDL_GPU_BLENDOP_MAX_ENUM_VALUE (SDL_GPU_BLENDOP_MAX + 1)
  64. #define SDL_GPU_BLENDFACTOR_MAX_ENUM_VALUE (SDL_GPU_BLENDFACTOR_SRC_ALPHA_SATURATE + 1)
  65. #define SDL_GPU_SWAPCHAINCOMPOSITION_MAX_ENUM_VALUE (SDL_GPU_SWAPCHAINCOMPOSITION_HDR10_ST2048 + 1)
  66. #define SDL_GPU_PRESENTMODE_MAX_ENUM_VALUE (SDL_GPU_PRESENTMODE_MAILBOX + 1)
  67. static inline Sint32 Texture_GetBlockWidth(
  68. SDL_GPUTextureFormat format)
  69. {
  70. switch (format) {
  71. case SDL_GPU_TEXTUREFORMAT_ASTC_12x10_UNORM:
  72. case SDL_GPU_TEXTUREFORMAT_ASTC_12x12_UNORM:
  73. case SDL_GPU_TEXTUREFORMAT_ASTC_12x10_UNORM_SRGB:
  74. case SDL_GPU_TEXTUREFORMAT_ASTC_12x12_UNORM_SRGB:
  75. case SDL_GPU_TEXTUREFORMAT_ASTC_12x10_FLOAT:
  76. case SDL_GPU_TEXTUREFORMAT_ASTC_12x12_FLOAT:
  77. return 12;
  78. case SDL_GPU_TEXTUREFORMAT_ASTC_10x5_UNORM:
  79. case SDL_GPU_TEXTUREFORMAT_ASTC_10x6_UNORM:
  80. case SDL_GPU_TEXTUREFORMAT_ASTC_10x8_UNORM:
  81. case SDL_GPU_TEXTUREFORMAT_ASTC_10x10_UNORM:
  82. case SDL_GPU_TEXTUREFORMAT_ASTC_10x5_UNORM_SRGB:
  83. case SDL_GPU_TEXTUREFORMAT_ASTC_10x6_UNORM_SRGB:
  84. case SDL_GPU_TEXTUREFORMAT_ASTC_10x8_UNORM_SRGB:
  85. case SDL_GPU_TEXTUREFORMAT_ASTC_10x10_UNORM_SRGB:
  86. case SDL_GPU_TEXTUREFORMAT_ASTC_10x5_FLOAT:
  87. case SDL_GPU_TEXTUREFORMAT_ASTC_10x6_FLOAT:
  88. case SDL_GPU_TEXTUREFORMAT_ASTC_10x8_FLOAT:
  89. case SDL_GPU_TEXTUREFORMAT_ASTC_10x10_FLOAT:
  90. return 10;
  91. case SDL_GPU_TEXTUREFORMAT_ASTC_8x5_UNORM:
  92. case SDL_GPU_TEXTUREFORMAT_ASTC_8x6_UNORM:
  93. case SDL_GPU_TEXTUREFORMAT_ASTC_8x8_UNORM:
  94. case SDL_GPU_TEXTUREFORMAT_ASTC_8x5_UNORM_SRGB:
  95. case SDL_GPU_TEXTUREFORMAT_ASTC_8x6_UNORM_SRGB:
  96. case SDL_GPU_TEXTUREFORMAT_ASTC_8x8_UNORM_SRGB:
  97. case SDL_GPU_TEXTUREFORMAT_ASTC_8x5_FLOAT:
  98. case SDL_GPU_TEXTUREFORMAT_ASTC_8x6_FLOAT:
  99. case SDL_GPU_TEXTUREFORMAT_ASTC_8x8_FLOAT:
  100. return 8;
  101. case SDL_GPU_TEXTUREFORMAT_ASTC_6x5_UNORM:
  102. case SDL_GPU_TEXTUREFORMAT_ASTC_6x6_UNORM:
  103. case SDL_GPU_TEXTUREFORMAT_ASTC_6x5_UNORM_SRGB:
  104. case SDL_GPU_TEXTUREFORMAT_ASTC_6x6_UNORM_SRGB:
  105. case SDL_GPU_TEXTUREFORMAT_ASTC_6x5_FLOAT:
  106. case SDL_GPU_TEXTUREFORMAT_ASTC_6x6_FLOAT:
  107. return 6;
  108. case SDL_GPU_TEXTUREFORMAT_ASTC_5x4_UNORM:
  109. case SDL_GPU_TEXTUREFORMAT_ASTC_5x5_UNORM:
  110. case SDL_GPU_TEXTUREFORMAT_ASTC_5x4_UNORM_SRGB:
  111. case SDL_GPU_TEXTUREFORMAT_ASTC_5x5_UNORM_SRGB:
  112. case SDL_GPU_TEXTUREFORMAT_ASTC_5x4_FLOAT:
  113. case SDL_GPU_TEXTUREFORMAT_ASTC_5x5_FLOAT:
  114. return 5;
  115. case SDL_GPU_TEXTUREFORMAT_BC1_RGBA_UNORM:
  116. case SDL_GPU_TEXTUREFORMAT_BC2_RGBA_UNORM:
  117. case SDL_GPU_TEXTUREFORMAT_BC3_RGBA_UNORM:
  118. case SDL_GPU_TEXTUREFORMAT_BC4_R_UNORM:
  119. case SDL_GPU_TEXTUREFORMAT_BC5_RG_UNORM:
  120. case SDL_GPU_TEXTUREFORMAT_BC7_RGBA_UNORM:
  121. case SDL_GPU_TEXTUREFORMAT_BC6H_RGB_FLOAT:
  122. case SDL_GPU_TEXTUREFORMAT_BC6H_RGB_UFLOAT:
  123. case SDL_GPU_TEXTUREFORMAT_BC1_RGBA_UNORM_SRGB:
  124. case SDL_GPU_TEXTUREFORMAT_BC3_RGBA_UNORM_SRGB:
  125. case SDL_GPU_TEXTUREFORMAT_BC7_RGBA_UNORM_SRGB:
  126. case SDL_GPU_TEXTUREFORMAT_ASTC_4x4_UNORM:
  127. case SDL_GPU_TEXTUREFORMAT_ASTC_4x4_UNORM_SRGB:
  128. case SDL_GPU_TEXTUREFORMAT_ASTC_4x4_FLOAT:
  129. return 4;
  130. case SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM:
  131. case SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM:
  132. case SDL_GPU_TEXTUREFORMAT_B5G6R5_UNORM:
  133. case SDL_GPU_TEXTUREFORMAT_B5G5R5A1_UNORM:
  134. case SDL_GPU_TEXTUREFORMAT_B4G4R4A4_UNORM:
  135. case SDL_GPU_TEXTUREFORMAT_R10G10B10A2_UNORM:
  136. case SDL_GPU_TEXTUREFORMAT_R8G8_UNORM:
  137. case SDL_GPU_TEXTUREFORMAT_R16G16_UNORM:
  138. case SDL_GPU_TEXTUREFORMAT_R16G16B16A16_UNORM:
  139. case SDL_GPU_TEXTUREFORMAT_R8_UNORM:
  140. case SDL_GPU_TEXTUREFORMAT_R16_UNORM:
  141. case SDL_GPU_TEXTUREFORMAT_A8_UNORM:
  142. case SDL_GPU_TEXTUREFORMAT_R8_SNORM:
  143. case SDL_GPU_TEXTUREFORMAT_R8G8_SNORM:
  144. case SDL_GPU_TEXTUREFORMAT_R8G8B8A8_SNORM:
  145. case SDL_GPU_TEXTUREFORMAT_R16_SNORM:
  146. case SDL_GPU_TEXTUREFORMAT_R16G16_SNORM:
  147. case SDL_GPU_TEXTUREFORMAT_R16G16B16A16_SNORM:
  148. case SDL_GPU_TEXTUREFORMAT_R16_FLOAT:
  149. case SDL_GPU_TEXTUREFORMAT_R16G16_FLOAT:
  150. case SDL_GPU_TEXTUREFORMAT_R16G16B16A16_FLOAT:
  151. case SDL_GPU_TEXTUREFORMAT_R32_FLOAT:
  152. case SDL_GPU_TEXTUREFORMAT_R32G32_FLOAT:
  153. case SDL_GPU_TEXTUREFORMAT_R32G32B32A32_FLOAT:
  154. case SDL_GPU_TEXTUREFORMAT_R11G11B10_UFLOAT:
  155. case SDL_GPU_TEXTUREFORMAT_R8_UINT:
  156. case SDL_GPU_TEXTUREFORMAT_R8G8_UINT:
  157. case SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UINT:
  158. case SDL_GPU_TEXTUREFORMAT_R16_UINT:
  159. case SDL_GPU_TEXTUREFORMAT_R16G16_UINT:
  160. case SDL_GPU_TEXTUREFORMAT_R16G16B16A16_UINT:
  161. case SDL_GPU_TEXTUREFORMAT_R8_INT:
  162. case SDL_GPU_TEXTUREFORMAT_R8G8_INT:
  163. case SDL_GPU_TEXTUREFORMAT_R8G8B8A8_INT:
  164. case SDL_GPU_TEXTUREFORMAT_R16_INT:
  165. case SDL_GPU_TEXTUREFORMAT_R16G16_INT:
  166. case SDL_GPU_TEXTUREFORMAT_R16G16B16A16_INT:
  167. case SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM_SRGB:
  168. case SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM_SRGB:
  169. return 1;
  170. default:
  171. SDL_assert_release(!"Unrecognized TextureFormat!");
  172. return 0;
  173. }
  174. }
  175. static inline Sint32 Texture_GetBlockHeight(
  176. SDL_GPUTextureFormat format)
  177. {
  178. switch (format) {
  179. case SDL_GPU_TEXTUREFORMAT_ASTC_12x12_UNORM:
  180. case SDL_GPU_TEXTUREFORMAT_ASTC_12x12_UNORM_SRGB:
  181. case SDL_GPU_TEXTUREFORMAT_ASTC_12x12_FLOAT:
  182. return 12;
  183. case SDL_GPU_TEXTUREFORMAT_ASTC_12x10_UNORM:
  184. case SDL_GPU_TEXTUREFORMAT_ASTC_12x10_UNORM_SRGB:
  185. case SDL_GPU_TEXTUREFORMAT_ASTC_12x10_FLOAT:
  186. case SDL_GPU_TEXTUREFORMAT_ASTC_10x10_UNORM:
  187. case SDL_GPU_TEXTUREFORMAT_ASTC_10x10_UNORM_SRGB:
  188. case SDL_GPU_TEXTUREFORMAT_ASTC_10x10_FLOAT:
  189. return 10;
  190. case SDL_GPU_TEXTUREFORMAT_ASTC_10x8_UNORM:
  191. case SDL_GPU_TEXTUREFORMAT_ASTC_10x8_UNORM_SRGB:
  192. case SDL_GPU_TEXTUREFORMAT_ASTC_10x8_FLOAT:
  193. case SDL_GPU_TEXTUREFORMAT_ASTC_8x8_UNORM:
  194. case SDL_GPU_TEXTUREFORMAT_ASTC_8x8_UNORM_SRGB:
  195. case SDL_GPU_TEXTUREFORMAT_ASTC_8x8_FLOAT:
  196. return 8;
  197. case SDL_GPU_TEXTUREFORMAT_ASTC_10x6_UNORM:
  198. case SDL_GPU_TEXTUREFORMAT_ASTC_10x6_UNORM_SRGB:
  199. case SDL_GPU_TEXTUREFORMAT_ASTC_10x6_FLOAT:
  200. case SDL_GPU_TEXTUREFORMAT_ASTC_8x6_UNORM:
  201. case SDL_GPU_TEXTUREFORMAT_ASTC_8x6_UNORM_SRGB:
  202. case SDL_GPU_TEXTUREFORMAT_ASTC_8x6_FLOAT:
  203. case SDL_GPU_TEXTUREFORMAT_ASTC_6x6_UNORM:
  204. case SDL_GPU_TEXTUREFORMAT_ASTC_6x6_UNORM_SRGB:
  205. case SDL_GPU_TEXTUREFORMAT_ASTC_6x6_FLOAT:
  206. return 6;
  207. case SDL_GPU_TEXTUREFORMAT_ASTC_10x5_UNORM:
  208. case SDL_GPU_TEXTUREFORMAT_ASTC_10x5_UNORM_SRGB:
  209. case SDL_GPU_TEXTUREFORMAT_ASTC_10x5_FLOAT:
  210. case SDL_GPU_TEXTUREFORMAT_ASTC_8x5_UNORM:
  211. case SDL_GPU_TEXTUREFORMAT_ASTC_8x5_UNORM_SRGB:
  212. case SDL_GPU_TEXTUREFORMAT_ASTC_8x5_FLOAT:
  213. case SDL_GPU_TEXTUREFORMAT_ASTC_6x5_UNORM:
  214. case SDL_GPU_TEXTUREFORMAT_ASTC_6x5_UNORM_SRGB:
  215. case SDL_GPU_TEXTUREFORMAT_ASTC_6x5_FLOAT:
  216. case SDL_GPU_TEXTUREFORMAT_ASTC_5x5_UNORM:
  217. case SDL_GPU_TEXTUREFORMAT_ASTC_5x5_UNORM_SRGB:
  218. case SDL_GPU_TEXTUREFORMAT_ASTC_5x5_FLOAT:
  219. return 5;
  220. case SDL_GPU_TEXTUREFORMAT_BC1_RGBA_UNORM:
  221. case SDL_GPU_TEXTUREFORMAT_BC2_RGBA_UNORM:
  222. case SDL_GPU_TEXTUREFORMAT_BC3_RGBA_UNORM:
  223. case SDL_GPU_TEXTUREFORMAT_BC4_R_UNORM:
  224. case SDL_GPU_TEXTUREFORMAT_BC5_RG_UNORM:
  225. case SDL_GPU_TEXTUREFORMAT_BC7_RGBA_UNORM:
  226. case SDL_GPU_TEXTUREFORMAT_BC6H_RGB_FLOAT:
  227. case SDL_GPU_TEXTUREFORMAT_BC6H_RGB_UFLOAT:
  228. case SDL_GPU_TEXTUREFORMAT_BC1_RGBA_UNORM_SRGB:
  229. case SDL_GPU_TEXTUREFORMAT_BC3_RGBA_UNORM_SRGB:
  230. case SDL_GPU_TEXTUREFORMAT_BC7_RGBA_UNORM_SRGB:
  231. case SDL_GPU_TEXTUREFORMAT_ASTC_5x4_UNORM:
  232. case SDL_GPU_TEXTUREFORMAT_ASTC_5x4_UNORM_SRGB:
  233. case SDL_GPU_TEXTUREFORMAT_ASTC_5x4_FLOAT:
  234. case SDL_GPU_TEXTUREFORMAT_ASTC_4x4_UNORM:
  235. case SDL_GPU_TEXTUREFORMAT_ASTC_4x4_UNORM_SRGB:
  236. case SDL_GPU_TEXTUREFORMAT_ASTC_4x4_FLOAT:
  237. return 4;
  238. case SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM:
  239. case SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM:
  240. case SDL_GPU_TEXTUREFORMAT_B5G6R5_UNORM:
  241. case SDL_GPU_TEXTUREFORMAT_B5G5R5A1_UNORM:
  242. case SDL_GPU_TEXTUREFORMAT_B4G4R4A4_UNORM:
  243. case SDL_GPU_TEXTUREFORMAT_R10G10B10A2_UNORM:
  244. case SDL_GPU_TEXTUREFORMAT_R8G8_UNORM:
  245. case SDL_GPU_TEXTUREFORMAT_R16G16_UNORM:
  246. case SDL_GPU_TEXTUREFORMAT_R16G16B16A16_UNORM:
  247. case SDL_GPU_TEXTUREFORMAT_R8_UNORM:
  248. case SDL_GPU_TEXTUREFORMAT_R16_UNORM:
  249. case SDL_GPU_TEXTUREFORMAT_A8_UNORM:
  250. case SDL_GPU_TEXTUREFORMAT_R8_SNORM:
  251. case SDL_GPU_TEXTUREFORMAT_R8G8_SNORM:
  252. case SDL_GPU_TEXTUREFORMAT_R8G8B8A8_SNORM:
  253. case SDL_GPU_TEXTUREFORMAT_R16_SNORM:
  254. case SDL_GPU_TEXTUREFORMAT_R16G16_SNORM:
  255. case SDL_GPU_TEXTUREFORMAT_R16G16B16A16_SNORM:
  256. case SDL_GPU_TEXTUREFORMAT_R16_FLOAT:
  257. case SDL_GPU_TEXTUREFORMAT_R16G16_FLOAT:
  258. case SDL_GPU_TEXTUREFORMAT_R16G16B16A16_FLOAT:
  259. case SDL_GPU_TEXTUREFORMAT_R32_FLOAT:
  260. case SDL_GPU_TEXTUREFORMAT_R32G32_FLOAT:
  261. case SDL_GPU_TEXTUREFORMAT_R32G32B32A32_FLOAT:
  262. case SDL_GPU_TEXTUREFORMAT_R11G11B10_UFLOAT:
  263. case SDL_GPU_TEXTUREFORMAT_R8_UINT:
  264. case SDL_GPU_TEXTUREFORMAT_R8G8_UINT:
  265. case SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UINT:
  266. case SDL_GPU_TEXTUREFORMAT_R16_UINT:
  267. case SDL_GPU_TEXTUREFORMAT_R16G16_UINT:
  268. case SDL_GPU_TEXTUREFORMAT_R16G16B16A16_UINT:
  269. case SDL_GPU_TEXTUREFORMAT_R8_INT:
  270. case SDL_GPU_TEXTUREFORMAT_R8G8_INT:
  271. case SDL_GPU_TEXTUREFORMAT_R8G8B8A8_INT:
  272. case SDL_GPU_TEXTUREFORMAT_R16_INT:
  273. case SDL_GPU_TEXTUREFORMAT_R16G16_INT:
  274. case SDL_GPU_TEXTUREFORMAT_R16G16B16A16_INT:
  275. case SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM_SRGB:
  276. case SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM_SRGB:
  277. return 1;
  278. default:
  279. SDL_assert_release(!"Unrecognized TextureFormat!");
  280. return 0;
  281. }
  282. }
  283. static inline bool IsDepthFormat(
  284. SDL_GPUTextureFormat format)
  285. {
  286. switch (format) {
  287. case SDL_GPU_TEXTUREFORMAT_D16_UNORM:
  288. case SDL_GPU_TEXTUREFORMAT_D24_UNORM:
  289. case SDL_GPU_TEXTUREFORMAT_D32_FLOAT:
  290. case SDL_GPU_TEXTUREFORMAT_D24_UNORM_S8_UINT:
  291. case SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT:
  292. return true;
  293. default:
  294. return false;
  295. }
  296. }
  297. static inline bool IsStencilFormat(
  298. SDL_GPUTextureFormat format)
  299. {
  300. switch (format) {
  301. case SDL_GPU_TEXTUREFORMAT_D24_UNORM_S8_UINT:
  302. case SDL_GPU_TEXTUREFORMAT_D32_FLOAT_S8_UINT:
  303. return true;
  304. default:
  305. return false;
  306. }
  307. }
  308. static inline bool IsIntegerFormat(
  309. SDL_GPUTextureFormat format)
  310. {
  311. switch (format) {
  312. case SDL_GPU_TEXTUREFORMAT_R8_UINT:
  313. case SDL_GPU_TEXTUREFORMAT_R8G8_UINT:
  314. case SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UINT:
  315. case SDL_GPU_TEXTUREFORMAT_R16_UINT:
  316. case SDL_GPU_TEXTUREFORMAT_R16G16_UINT:
  317. case SDL_GPU_TEXTUREFORMAT_R16G16B16A16_UINT:
  318. case SDL_GPU_TEXTUREFORMAT_R8_INT:
  319. case SDL_GPU_TEXTUREFORMAT_R8G8_INT:
  320. case SDL_GPU_TEXTUREFORMAT_R8G8B8A8_INT:
  321. case SDL_GPU_TEXTUREFORMAT_R16_INT:
  322. case SDL_GPU_TEXTUREFORMAT_R16G16_INT:
  323. case SDL_GPU_TEXTUREFORMAT_R16G16B16A16_INT:
  324. return true;
  325. default:
  326. return false;
  327. }
  328. }
  329. static inline Uint32 IndexSize(SDL_GPUIndexElementSize size)
  330. {
  331. return (size == SDL_GPU_INDEXELEMENTSIZE_16BIT) ? 2 : 4;
  332. }
  333. static inline Uint32 BytesPerRow(
  334. Sint32 width,
  335. SDL_GPUTextureFormat format)
  336. {
  337. Uint32 blockWidth = Texture_GetBlockWidth(format);
  338. Uint32 blocksPerRow = (width + blockWidth - 1) / blockWidth;
  339. return blocksPerRow * SDL_GPUTextureFormatTexelBlockSize(format);
  340. }
  341. // GraphicsDevice Limits
  342. #define MAX_TEXTURE_SAMPLERS_PER_STAGE 16
  343. #define MAX_STORAGE_TEXTURES_PER_STAGE 8
  344. #define MAX_STORAGE_BUFFERS_PER_STAGE 8
  345. #define MAX_UNIFORM_BUFFERS_PER_STAGE 4
  346. #define MAX_COMPUTE_WRITE_TEXTURES 8
  347. #define MAX_COMPUTE_WRITE_BUFFERS 8
  348. #define UNIFORM_BUFFER_SIZE 32768
  349. #define MAX_VERTEX_BUFFERS 16
  350. #define MAX_VERTEX_ATTRIBUTES 16
  351. #define MAX_COLOR_TARGET_BINDINGS 4
  352. #define MAX_PRESENT_COUNT 16
  353. #define MAX_FRAMES_IN_FLIGHT 3
  354. // Internal Macros
  355. #define EXPAND_ARRAY_IF_NEEDED(arr, elementType, newCount, capacity, newCapacity) \
  356. if (newCount >= capacity) { \
  357. capacity = newCapacity; \
  358. arr = (elementType *)SDL_realloc( \
  359. arr, \
  360. sizeof(elementType) * capacity); \
  361. }
  362. // Internal Declarations
  363. #ifdef __cplusplus
  364. extern "C" {
  365. #endif // __cplusplus
  366. SDL_GPUGraphicsPipeline *SDL_GPU_FetchBlitPipeline(
  367. SDL_GPUDevice *device,
  368. SDL_GPUTextureType sourceTextureType,
  369. SDL_GPUTextureFormat destinationFormat,
  370. SDL_GPUShader *blitVertexShader,
  371. SDL_GPUShader *blitFrom2DShader,
  372. SDL_GPUShader *blitFrom2DArrayShader,
  373. SDL_GPUShader *blitFrom3DShader,
  374. SDL_GPUShader *blitFromCubeShader,
  375. SDL_GPUShader *blitFromCubeArrayShader,
  376. BlitPipelineCacheEntry **blitPipelines,
  377. Uint32 *blitPipelineCount,
  378. Uint32 *blitPipelineCapacity);
  379. void SDL_GPU_BlitCommon(
  380. SDL_GPUCommandBuffer *commandBuffer,
  381. const SDL_GPUBlitInfo *info,
  382. SDL_GPUSampler *blitLinearSampler,
  383. SDL_GPUSampler *blitNearestSampler,
  384. SDL_GPUShader *blitVertexShader,
  385. SDL_GPUShader *blitFrom2DShader,
  386. SDL_GPUShader *blitFrom2DArrayShader,
  387. SDL_GPUShader *blitFrom3DShader,
  388. SDL_GPUShader *blitFromCubeShader,
  389. SDL_GPUShader *blitFromCubeArrayShader,
  390. BlitPipelineCacheEntry **blitPipelines,
  391. Uint32 *blitPipelineCount,
  392. Uint32 *blitPipelineCapacity);
  393. #ifdef __cplusplus
  394. }
  395. #endif // __cplusplus
  396. // SDL_GPUDevice Definition
  397. typedef struct SDL_GPURenderer SDL_GPURenderer;
  398. struct SDL_GPUDevice
  399. {
  400. // Quit
  401. void (*DestroyDevice)(SDL_GPUDevice *device);
  402. // State Creation
  403. SDL_GPUComputePipeline *(*CreateComputePipeline)(
  404. SDL_GPURenderer *driverData,
  405. const SDL_GPUComputePipelineCreateInfo *createinfo);
  406. SDL_GPUGraphicsPipeline *(*CreateGraphicsPipeline)(
  407. SDL_GPURenderer *driverData,
  408. const SDL_GPUGraphicsPipelineCreateInfo *createinfo);
  409. SDL_GPUSampler *(*CreateSampler)(
  410. SDL_GPURenderer *driverData,
  411. const SDL_GPUSamplerCreateInfo *createinfo);
  412. SDL_GPUShader *(*CreateShader)(
  413. SDL_GPURenderer *driverData,
  414. const SDL_GPUShaderCreateInfo *createinfo);
  415. SDL_GPUTexture *(*CreateTexture)(
  416. SDL_GPURenderer *driverData,
  417. const SDL_GPUTextureCreateInfo *createinfo);
  418. SDL_GPUBuffer *(*CreateBuffer)(
  419. SDL_GPURenderer *driverData,
  420. SDL_GPUBufferUsageFlags usageFlags,
  421. Uint32 size);
  422. SDL_GPUTransferBuffer *(*CreateTransferBuffer)(
  423. SDL_GPURenderer *driverData,
  424. SDL_GPUTransferBufferUsage usage,
  425. Uint32 size);
  426. // Debug Naming
  427. void (*SetBufferName)(
  428. SDL_GPURenderer *driverData,
  429. SDL_GPUBuffer *buffer,
  430. const char *text);
  431. void (*SetTextureName)(
  432. SDL_GPURenderer *driverData,
  433. SDL_GPUTexture *texture,
  434. const char *text);
  435. void (*InsertDebugLabel)(
  436. SDL_GPUCommandBuffer *commandBuffer,
  437. const char *text);
  438. void (*PushDebugGroup)(
  439. SDL_GPUCommandBuffer *commandBuffer,
  440. const char *name);
  441. void (*PopDebugGroup)(
  442. SDL_GPUCommandBuffer *commandBuffer);
  443. // Disposal
  444. void (*ReleaseTexture)(
  445. SDL_GPURenderer *driverData,
  446. SDL_GPUTexture *texture);
  447. void (*ReleaseSampler)(
  448. SDL_GPURenderer *driverData,
  449. SDL_GPUSampler *sampler);
  450. void (*ReleaseBuffer)(
  451. SDL_GPURenderer *driverData,
  452. SDL_GPUBuffer *buffer);
  453. void (*ReleaseTransferBuffer)(
  454. SDL_GPURenderer *driverData,
  455. SDL_GPUTransferBuffer *transferBuffer);
  456. void (*ReleaseShader)(
  457. SDL_GPURenderer *driverData,
  458. SDL_GPUShader *shader);
  459. void (*ReleaseComputePipeline)(
  460. SDL_GPURenderer *driverData,
  461. SDL_GPUComputePipeline *computePipeline);
  462. void (*ReleaseGraphicsPipeline)(
  463. SDL_GPURenderer *driverData,
  464. SDL_GPUGraphicsPipeline *graphicsPipeline);
  465. // Render Pass
  466. void (*BeginRenderPass)(
  467. SDL_GPUCommandBuffer *commandBuffer,
  468. const SDL_GPUColorTargetInfo *colorTargetInfos,
  469. Uint32 numColorTargets,
  470. const SDL_GPUDepthStencilTargetInfo *depthStencilTargetInfo);
  471. void (*BindGraphicsPipeline)(
  472. SDL_GPUCommandBuffer *commandBuffer,
  473. SDL_GPUGraphicsPipeline *graphicsPipeline);
  474. void (*SetViewport)(
  475. SDL_GPUCommandBuffer *commandBuffer,
  476. const SDL_GPUViewport *viewport);
  477. void (*SetScissor)(
  478. SDL_GPUCommandBuffer *commandBuffer,
  479. const SDL_Rect *scissor);
  480. void (*SetBlendConstants)(
  481. SDL_GPUCommandBuffer *commandBuffer,
  482. SDL_FColor blendConstants);
  483. void (*SetStencilReference)(
  484. SDL_GPUCommandBuffer *commandBuffer,
  485. Uint8 reference);
  486. void (*BindVertexBuffers)(
  487. SDL_GPUCommandBuffer *commandBuffer,
  488. Uint32 firstSlot,
  489. const SDL_GPUBufferBinding *bindings,
  490. Uint32 numBindings);
  491. void (*BindIndexBuffer)(
  492. SDL_GPUCommandBuffer *commandBuffer,
  493. const SDL_GPUBufferBinding *binding,
  494. SDL_GPUIndexElementSize indexElementSize);
  495. void (*BindVertexSamplers)(
  496. SDL_GPUCommandBuffer *commandBuffer,
  497. Uint32 firstSlot,
  498. const SDL_GPUTextureSamplerBinding *textureSamplerBindings,
  499. Uint32 numBindings);
  500. void (*BindVertexStorageTextures)(
  501. SDL_GPUCommandBuffer *commandBuffer,
  502. Uint32 firstSlot,
  503. SDL_GPUTexture *const *storageTextures,
  504. Uint32 numBindings);
  505. void (*BindVertexStorageBuffers)(
  506. SDL_GPUCommandBuffer *commandBuffer,
  507. Uint32 firstSlot,
  508. SDL_GPUBuffer *const *storageBuffers,
  509. Uint32 numBindings);
  510. void (*BindFragmentSamplers)(
  511. SDL_GPUCommandBuffer *commandBuffer,
  512. Uint32 firstSlot,
  513. const SDL_GPUTextureSamplerBinding *textureSamplerBindings,
  514. Uint32 numBindings);
  515. void (*BindFragmentStorageTextures)(
  516. SDL_GPUCommandBuffer *commandBuffer,
  517. Uint32 firstSlot,
  518. SDL_GPUTexture *const *storageTextures,
  519. Uint32 numBindings);
  520. void (*BindFragmentStorageBuffers)(
  521. SDL_GPUCommandBuffer *commandBuffer,
  522. Uint32 firstSlot,
  523. SDL_GPUBuffer *const *storageBuffers,
  524. Uint32 numBindings);
  525. void (*PushVertexUniformData)(
  526. SDL_GPUCommandBuffer *commandBuffer,
  527. Uint32 slotIndex,
  528. const void *data,
  529. Uint32 length);
  530. void (*PushFragmentUniformData)(
  531. SDL_GPUCommandBuffer *commandBuffer,
  532. Uint32 slotIndex,
  533. const void *data,
  534. Uint32 length);
  535. void (*DrawIndexedPrimitives)(
  536. SDL_GPUCommandBuffer *commandBuffer,
  537. Uint32 numIndices,
  538. Uint32 numInstances,
  539. Uint32 firstIndex,
  540. Sint32 vertexOffset,
  541. Uint32 firstInstance);
  542. void (*DrawPrimitives)(
  543. SDL_GPUCommandBuffer *commandBuffer,
  544. Uint32 numVertices,
  545. Uint32 numInstances,
  546. Uint32 firstVertex,
  547. Uint32 firstInstance);
  548. void (*DrawPrimitivesIndirect)(
  549. SDL_GPUCommandBuffer *commandBuffer,
  550. SDL_GPUBuffer *buffer,
  551. Uint32 offset,
  552. Uint32 drawCount);
  553. void (*DrawIndexedPrimitivesIndirect)(
  554. SDL_GPUCommandBuffer *commandBuffer,
  555. SDL_GPUBuffer *buffer,
  556. Uint32 offset,
  557. Uint32 drawCount);
  558. void (*EndRenderPass)(
  559. SDL_GPUCommandBuffer *commandBuffer);
  560. // Compute Pass
  561. void (*BeginComputePass)(
  562. SDL_GPUCommandBuffer *commandBuffer,
  563. const SDL_GPUStorageTextureReadWriteBinding *storageTextureBindings,
  564. Uint32 numStorageTextureBindings,
  565. const SDL_GPUStorageBufferReadWriteBinding *storageBufferBindings,
  566. Uint32 numStorageBufferBindings);
  567. void (*BindComputePipeline)(
  568. SDL_GPUCommandBuffer *commandBuffer,
  569. SDL_GPUComputePipeline *computePipeline);
  570. void (*BindComputeSamplers)(
  571. SDL_GPUCommandBuffer *commandBuffer,
  572. Uint32 firstSlot,
  573. const SDL_GPUTextureSamplerBinding *textureSamplerBindings,
  574. Uint32 numBindings);
  575. void (*BindComputeStorageTextures)(
  576. SDL_GPUCommandBuffer *commandBuffer,
  577. Uint32 firstSlot,
  578. SDL_GPUTexture *const *storageTextures,
  579. Uint32 numBindings);
  580. void (*BindComputeStorageBuffers)(
  581. SDL_GPUCommandBuffer *commandBuffer,
  582. Uint32 firstSlot,
  583. SDL_GPUBuffer *const *storageBuffers,
  584. Uint32 numBindings);
  585. void (*PushComputeUniformData)(
  586. SDL_GPUCommandBuffer *commandBuffer,
  587. Uint32 slotIndex,
  588. const void *data,
  589. Uint32 length);
  590. void (*DispatchCompute)(
  591. SDL_GPUCommandBuffer *commandBuffer,
  592. Uint32 groupcountX,
  593. Uint32 groupcountY,
  594. Uint32 groupcountZ);
  595. void (*DispatchComputeIndirect)(
  596. SDL_GPUCommandBuffer *commandBuffer,
  597. SDL_GPUBuffer *buffer,
  598. Uint32 offset);
  599. void (*EndComputePass)(
  600. SDL_GPUCommandBuffer *commandBuffer);
  601. // TransferBuffer Data
  602. void *(*MapTransferBuffer)(
  603. SDL_GPURenderer *device,
  604. SDL_GPUTransferBuffer *transferBuffer,
  605. bool cycle);
  606. void (*UnmapTransferBuffer)(
  607. SDL_GPURenderer *device,
  608. SDL_GPUTransferBuffer *transferBuffer);
  609. // Copy Pass
  610. void (*BeginCopyPass)(
  611. SDL_GPUCommandBuffer *commandBuffer);
  612. void (*UploadToTexture)(
  613. SDL_GPUCommandBuffer *commandBuffer,
  614. const SDL_GPUTextureTransferInfo *source,
  615. const SDL_GPUTextureRegion *destination,
  616. bool cycle);
  617. void (*UploadToBuffer)(
  618. SDL_GPUCommandBuffer *commandBuffer,
  619. const SDL_GPUTransferBufferLocation *source,
  620. const SDL_GPUBufferRegion *destination,
  621. bool cycle);
  622. void (*CopyTextureToTexture)(
  623. SDL_GPUCommandBuffer *commandBuffer,
  624. const SDL_GPUTextureLocation *source,
  625. const SDL_GPUTextureLocation *destination,
  626. Uint32 w,
  627. Uint32 h,
  628. Uint32 d,
  629. bool cycle);
  630. void (*CopyBufferToBuffer)(
  631. SDL_GPUCommandBuffer *commandBuffer,
  632. const SDL_GPUBufferLocation *source,
  633. const SDL_GPUBufferLocation *destination,
  634. Uint32 size,
  635. bool cycle);
  636. void (*GenerateMipmaps)(
  637. SDL_GPUCommandBuffer *commandBuffer,
  638. SDL_GPUTexture *texture);
  639. void (*DownloadFromTexture)(
  640. SDL_GPUCommandBuffer *commandBuffer,
  641. const SDL_GPUTextureRegion *source,
  642. const SDL_GPUTextureTransferInfo *destination);
  643. void (*DownloadFromBuffer)(
  644. SDL_GPUCommandBuffer *commandBuffer,
  645. const SDL_GPUBufferRegion *source,
  646. const SDL_GPUTransferBufferLocation *destination);
  647. void (*EndCopyPass)(
  648. SDL_GPUCommandBuffer *commandBuffer);
  649. void (*Blit)(
  650. SDL_GPUCommandBuffer *commandBuffer,
  651. const SDL_GPUBlitInfo *info);
  652. // Submission/Presentation
  653. bool (*SupportsSwapchainComposition)(
  654. SDL_GPURenderer *driverData,
  655. SDL_Window *window,
  656. SDL_GPUSwapchainComposition swapchainComposition);
  657. bool (*SupportsPresentMode)(
  658. SDL_GPURenderer *driverData,
  659. SDL_Window *window,
  660. SDL_GPUPresentMode presentMode);
  661. bool (*ClaimWindow)(
  662. SDL_GPURenderer *driverData,
  663. SDL_Window *window);
  664. void (*ReleaseWindow)(
  665. SDL_GPURenderer *driverData,
  666. SDL_Window *window);
  667. bool (*SetSwapchainParameters)(
  668. SDL_GPURenderer *driverData,
  669. SDL_Window *window,
  670. SDL_GPUSwapchainComposition swapchainComposition,
  671. SDL_GPUPresentMode presentMode);
  672. SDL_GPUTextureFormat (*GetSwapchainTextureFormat)(
  673. SDL_GPURenderer *driverData,
  674. SDL_Window *window);
  675. SDL_GPUCommandBuffer *(*AcquireCommandBuffer)(
  676. SDL_GPURenderer *driverData);
  677. bool (*AcquireSwapchainTexture)(
  678. SDL_GPUCommandBuffer *commandBuffer,
  679. SDL_Window *window,
  680. SDL_GPUTexture **swapchainTexture,
  681. Uint32 *swapchainTextureWidth,
  682. Uint32 *swapchainTextureHeight);
  683. bool (*Submit)(
  684. SDL_GPUCommandBuffer *commandBuffer);
  685. SDL_GPUFence *(*SubmitAndAcquireFence)(
  686. SDL_GPUCommandBuffer *commandBuffer);
  687. bool (*Wait)(
  688. SDL_GPURenderer *driverData);
  689. bool (*WaitForFences)(
  690. SDL_GPURenderer *driverData,
  691. bool waitAll,
  692. SDL_GPUFence *const *fences,
  693. Uint32 numFences);
  694. bool (*QueryFence)(
  695. SDL_GPURenderer *driverData,
  696. SDL_GPUFence *fence);
  697. void (*ReleaseFence)(
  698. SDL_GPURenderer *driverData,
  699. SDL_GPUFence *fence);
  700. // Feature Queries
  701. bool (*SupportsTextureFormat)(
  702. SDL_GPURenderer *driverData,
  703. SDL_GPUTextureFormat format,
  704. SDL_GPUTextureType type,
  705. SDL_GPUTextureUsageFlags usage);
  706. bool (*SupportsSampleCount)(
  707. SDL_GPURenderer *driverData,
  708. SDL_GPUTextureFormat format,
  709. SDL_GPUSampleCount desiredSampleCount);
  710. // Opaque pointer for the Driver
  711. SDL_GPURenderer *driverData;
  712. // Store this for SDL_GetGPUDeviceDriver()
  713. const char *backend;
  714. // Store this for SDL_GetGPUShaderFormats()
  715. SDL_GPUShaderFormat shader_formats;
  716. // Store this for SDL_gpu.c's debug layer
  717. bool debug_mode;
  718. };
  719. #define ASSIGN_DRIVER_FUNC(func, name) \
  720. result->func = name##_##func;
  721. #define ASSIGN_DRIVER(name) \
  722. ASSIGN_DRIVER_FUNC(DestroyDevice, name) \
  723. ASSIGN_DRIVER_FUNC(CreateComputePipeline, name) \
  724. ASSIGN_DRIVER_FUNC(CreateGraphicsPipeline, name) \
  725. ASSIGN_DRIVER_FUNC(CreateSampler, name) \
  726. ASSIGN_DRIVER_FUNC(CreateShader, name) \
  727. ASSIGN_DRIVER_FUNC(CreateTexture, name) \
  728. ASSIGN_DRIVER_FUNC(CreateBuffer, name) \
  729. ASSIGN_DRIVER_FUNC(CreateTransferBuffer, name) \
  730. ASSIGN_DRIVER_FUNC(SetBufferName, name) \
  731. ASSIGN_DRIVER_FUNC(SetTextureName, name) \
  732. ASSIGN_DRIVER_FUNC(InsertDebugLabel, name) \
  733. ASSIGN_DRIVER_FUNC(PushDebugGroup, name) \
  734. ASSIGN_DRIVER_FUNC(PopDebugGroup, name) \
  735. ASSIGN_DRIVER_FUNC(ReleaseTexture, name) \
  736. ASSIGN_DRIVER_FUNC(ReleaseSampler, name) \
  737. ASSIGN_DRIVER_FUNC(ReleaseBuffer, name) \
  738. ASSIGN_DRIVER_FUNC(ReleaseTransferBuffer, name) \
  739. ASSIGN_DRIVER_FUNC(ReleaseShader, name) \
  740. ASSIGN_DRIVER_FUNC(ReleaseComputePipeline, name) \
  741. ASSIGN_DRIVER_FUNC(ReleaseGraphicsPipeline, name) \
  742. ASSIGN_DRIVER_FUNC(BeginRenderPass, name) \
  743. ASSIGN_DRIVER_FUNC(BindGraphicsPipeline, name) \
  744. ASSIGN_DRIVER_FUNC(SetViewport, name) \
  745. ASSIGN_DRIVER_FUNC(SetScissor, name) \
  746. ASSIGN_DRIVER_FUNC(SetBlendConstants, name) \
  747. ASSIGN_DRIVER_FUNC(SetStencilReference, name) \
  748. ASSIGN_DRIVER_FUNC(BindVertexBuffers, name) \
  749. ASSIGN_DRIVER_FUNC(BindIndexBuffer, name) \
  750. ASSIGN_DRIVER_FUNC(BindVertexSamplers, name) \
  751. ASSIGN_DRIVER_FUNC(BindVertexStorageTextures, name) \
  752. ASSIGN_DRIVER_FUNC(BindVertexStorageBuffers, name) \
  753. ASSIGN_DRIVER_FUNC(BindFragmentSamplers, name) \
  754. ASSIGN_DRIVER_FUNC(BindFragmentStorageTextures, name) \
  755. ASSIGN_DRIVER_FUNC(BindFragmentStorageBuffers, name) \
  756. ASSIGN_DRIVER_FUNC(PushVertexUniformData, name) \
  757. ASSIGN_DRIVER_FUNC(PushFragmentUniformData, name) \
  758. ASSIGN_DRIVER_FUNC(DrawIndexedPrimitives, name) \
  759. ASSIGN_DRIVER_FUNC(DrawPrimitives, name) \
  760. ASSIGN_DRIVER_FUNC(DrawPrimitivesIndirect, name) \
  761. ASSIGN_DRIVER_FUNC(DrawIndexedPrimitivesIndirect, name) \
  762. ASSIGN_DRIVER_FUNC(EndRenderPass, name) \
  763. ASSIGN_DRIVER_FUNC(BeginComputePass, name) \
  764. ASSIGN_DRIVER_FUNC(BindComputePipeline, name) \
  765. ASSIGN_DRIVER_FUNC(BindComputeSamplers, name) \
  766. ASSIGN_DRIVER_FUNC(BindComputeStorageTextures, name) \
  767. ASSIGN_DRIVER_FUNC(BindComputeStorageBuffers, name) \
  768. ASSIGN_DRIVER_FUNC(PushComputeUniformData, name) \
  769. ASSIGN_DRIVER_FUNC(DispatchCompute, name) \
  770. ASSIGN_DRIVER_FUNC(DispatchComputeIndirect, name) \
  771. ASSIGN_DRIVER_FUNC(EndComputePass, name) \
  772. ASSIGN_DRIVER_FUNC(MapTransferBuffer, name) \
  773. ASSIGN_DRIVER_FUNC(UnmapTransferBuffer, name) \
  774. ASSIGN_DRIVER_FUNC(BeginCopyPass, name) \
  775. ASSIGN_DRIVER_FUNC(UploadToTexture, name) \
  776. ASSIGN_DRIVER_FUNC(UploadToBuffer, name) \
  777. ASSIGN_DRIVER_FUNC(DownloadFromTexture, name) \
  778. ASSIGN_DRIVER_FUNC(DownloadFromBuffer, name) \
  779. ASSIGN_DRIVER_FUNC(CopyTextureToTexture, name) \
  780. ASSIGN_DRIVER_FUNC(CopyBufferToBuffer, name) \
  781. ASSIGN_DRIVER_FUNC(GenerateMipmaps, name) \
  782. ASSIGN_DRIVER_FUNC(EndCopyPass, name) \
  783. ASSIGN_DRIVER_FUNC(Blit, name) \
  784. ASSIGN_DRIVER_FUNC(SupportsSwapchainComposition, name) \
  785. ASSIGN_DRIVER_FUNC(SupportsPresentMode, name) \
  786. ASSIGN_DRIVER_FUNC(ClaimWindow, name) \
  787. ASSIGN_DRIVER_FUNC(ReleaseWindow, name) \
  788. ASSIGN_DRIVER_FUNC(SetSwapchainParameters, name) \
  789. ASSIGN_DRIVER_FUNC(GetSwapchainTextureFormat, name) \
  790. ASSIGN_DRIVER_FUNC(AcquireCommandBuffer, name) \
  791. ASSIGN_DRIVER_FUNC(AcquireSwapchainTexture, name) \
  792. ASSIGN_DRIVER_FUNC(Submit, name) \
  793. ASSIGN_DRIVER_FUNC(SubmitAndAcquireFence, name) \
  794. ASSIGN_DRIVER_FUNC(Wait, name) \
  795. ASSIGN_DRIVER_FUNC(WaitForFences, name) \
  796. ASSIGN_DRIVER_FUNC(QueryFence, name) \
  797. ASSIGN_DRIVER_FUNC(ReleaseFence, name) \
  798. ASSIGN_DRIVER_FUNC(SupportsTextureFormat, name) \
  799. ASSIGN_DRIVER_FUNC(SupportsSampleCount, name)
  800. typedef struct SDL_GPUBootstrap
  801. {
  802. const char *name;
  803. const SDL_GPUShaderFormat shader_formats;
  804. bool (*PrepareDriver)(SDL_VideoDevice *_this);
  805. SDL_GPUDevice *(*CreateDevice)(bool debug_mode, bool prefer_low_power, SDL_PropertiesID props);
  806. } SDL_GPUBootstrap;
  807. #ifdef __cplusplus
  808. extern "C" {
  809. #endif
  810. extern SDL_GPUBootstrap VulkanDriver;
  811. extern SDL_GPUBootstrap D3D11Driver;
  812. extern SDL_GPUBootstrap D3D12Driver;
  813. extern SDL_GPUBootstrap MetalDriver;
  814. extern SDL_GPUBootstrap PS5Driver;
  815. #ifdef __cplusplus
  816. }
  817. #endif
  818. #endif // SDL_GPU_DRIVER_H