webgpu_cpp.h 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  1. #ifndef WEBGPU_CPP_H_
  2. #define WEBGPU_CPP_H_
  3. #include "webgpu.h"
  4. #include "EnumClassBitmasks.h"
  5. namespace wgpu {
  6. static constexpr uint64_t kWholeSize = WGPU_WHOLE_SIZE;
  7. // TODO(crbug.com/520): Remove kStrideUndefined in favor of kCopyStrideUndefined.
  8. static constexpr uint32_t kStrideUndefined = WGPU_STRIDE_UNDEFINED;
  9. static constexpr uint32_t kCopyStrideUndefined = WGPU_COPY_STRIDE_UNDEFINED;
  10. enum class AdapterType : uint32_t {
  11. DiscreteGPU = 0x00000000,
  12. IntegratedGPU = 0x00000001,
  13. CPU = 0x00000002,
  14. Unknown = 0x00000003,
  15. };
  16. enum class AddressMode : uint32_t {
  17. Repeat = 0x00000000,
  18. MirrorRepeat = 0x00000001,
  19. ClampToEdge = 0x00000002,
  20. };
  21. enum class BackendType : uint32_t {
  22. Null = 0x00000000,
  23. D3D11 = 0x00000001,
  24. D3D12 = 0x00000002,
  25. Metal = 0x00000003,
  26. Vulkan = 0x00000004,
  27. OpenGL = 0x00000005,
  28. OpenGLES = 0x00000006,
  29. };
  30. enum class BindingType : uint32_t {
  31. Undefined = 0x00000000,
  32. UniformBuffer = 0x00000001,
  33. StorageBuffer = 0x00000002,
  34. ReadonlyStorageBuffer = 0x00000003,
  35. Sampler = 0x00000004,
  36. ComparisonSampler = 0x00000005,
  37. SampledTexture = 0x00000006,
  38. MultisampledTexture = 0x00000007,
  39. ReadonlyStorageTexture = 0x00000008,
  40. WriteonlyStorageTexture = 0x00000009,
  41. };
  42. enum class BlendFactor : uint32_t {
  43. Zero = 0x00000000,
  44. One = 0x00000001,
  45. SrcColor = 0x00000002,
  46. OneMinusSrcColor = 0x00000003,
  47. SrcAlpha = 0x00000004,
  48. OneMinusSrcAlpha = 0x00000005,
  49. DstColor = 0x00000006,
  50. OneMinusDstColor = 0x00000007,
  51. DstAlpha = 0x00000008,
  52. OneMinusDstAlpha = 0x00000009,
  53. SrcAlphaSaturated = 0x0000000A,
  54. BlendColor = 0x0000000B,
  55. OneMinusBlendColor = 0x0000000C,
  56. };
  57. enum class BlendOperation : uint32_t {
  58. Add = 0x00000000,
  59. Subtract = 0x00000001,
  60. ReverseSubtract = 0x00000002,
  61. Min = 0x00000003,
  62. Max = 0x00000004,
  63. };
  64. enum class BufferBindingType : uint32_t {
  65. Undefined = 0x00000000,
  66. Uniform = 0x00000001,
  67. Storage = 0x00000002,
  68. ReadOnlyStorage = 0x00000003,
  69. };
  70. enum class BufferMapAsyncStatus : uint32_t {
  71. Success = 0x00000000,
  72. Error = 0x00000001,
  73. Unknown = 0x00000002,
  74. DeviceLost = 0x00000003,
  75. DestroyedBeforeCallback = 0x00000004,
  76. UnmappedBeforeCallback = 0x00000005,
  77. };
  78. enum class CompareFunction : uint32_t {
  79. Undefined = 0x00000000,
  80. Never = 0x00000001,
  81. Less = 0x00000002,
  82. LessEqual = 0x00000003,
  83. Greater = 0x00000004,
  84. GreaterEqual = 0x00000005,
  85. Equal = 0x00000006,
  86. NotEqual = 0x00000007,
  87. Always = 0x00000008,
  88. };
  89. enum class CreateReadyPipelineStatus : uint32_t {
  90. Success = 0x00000000,
  91. Error = 0x00000001,
  92. DeviceLost = 0x00000002,
  93. DeviceDestroyed = 0x00000003,
  94. Unknown = 0x00000004,
  95. };
  96. enum class CullMode : uint32_t {
  97. None = 0x00000000,
  98. Front = 0x00000001,
  99. Back = 0x00000002,
  100. };
  101. enum class ErrorFilter : uint32_t {
  102. None = 0x00000000,
  103. Validation = 0x00000001,
  104. OutOfMemory = 0x00000002,
  105. };
  106. enum class ErrorType : uint32_t {
  107. NoError = 0x00000000,
  108. Validation = 0x00000001,
  109. OutOfMemory = 0x00000002,
  110. Unknown = 0x00000003,
  111. DeviceLost = 0x00000004,
  112. };
  113. enum class FenceCompletionStatus : uint32_t {
  114. Success = 0x00000000,
  115. Error = 0x00000001,
  116. Unknown = 0x00000002,
  117. DeviceLost = 0x00000003,
  118. };
  119. enum class FilterMode : uint32_t {
  120. Nearest = 0x00000000,
  121. Linear = 0x00000001,
  122. };
  123. enum class FrontFace : uint32_t {
  124. CCW = 0x00000000,
  125. CW = 0x00000001,
  126. };
  127. enum class IndexFormat : uint32_t {
  128. Undefined = 0x00000000,
  129. Uint16 = 0x00000001,
  130. Uint32 = 0x00000002,
  131. };
  132. enum class InputStepMode : uint32_t {
  133. Vertex = 0x00000000,
  134. Instance = 0x00000001,
  135. };
  136. enum class LoadOp : uint32_t {
  137. Clear = 0x00000000,
  138. Load = 0x00000001,
  139. };
  140. enum class PipelineStatisticName : uint32_t {
  141. VertexShaderInvocations = 0x00000000,
  142. ClipperInvocations = 0x00000001,
  143. ClipperPrimitivesOut = 0x00000002,
  144. FragmentShaderInvocations = 0x00000003,
  145. ComputeShaderInvocations = 0x00000004,
  146. };
  147. enum class PresentMode : uint32_t {
  148. Immediate = 0x00000000,
  149. Mailbox = 0x00000001,
  150. Fifo = 0x00000002,
  151. };
  152. enum class PrimitiveTopology : uint32_t {
  153. PointList = 0x00000000,
  154. LineList = 0x00000001,
  155. LineStrip = 0x00000002,
  156. TriangleList = 0x00000003,
  157. TriangleStrip = 0x00000004,
  158. };
  159. enum class QueryType : uint32_t {
  160. Occlusion = 0x00000000,
  161. PipelineStatistics = 0x00000001,
  162. Timestamp = 0x00000002,
  163. };
  164. enum class SType : uint32_t {
  165. Invalid = 0x00000000,
  166. SurfaceDescriptorFromMetalLayer = 0x00000001,
  167. SurfaceDescriptorFromWindowsHWND = 0x00000002,
  168. SurfaceDescriptorFromXlib = 0x00000003,
  169. SurfaceDescriptorFromCanvasHTMLSelector = 0x00000004,
  170. ShaderModuleSPIRVDescriptor = 0x00000005,
  171. ShaderModuleWGSLDescriptor = 0x00000006,
  172. SamplerDescriptorDummyAnisotropicFiltering = 0x00000007,
  173. RenderPipelineDescriptorDummyExtension = 0x00000008,
  174. };
  175. enum class SamplerBindingType : uint32_t {
  176. Undefined = 0x00000000,
  177. Filtering = 0x00000001,
  178. NonFiltering = 0x00000002,
  179. Comparison = 0x00000003,
  180. };
  181. enum class StencilOperation : uint32_t {
  182. Keep = 0x00000000,
  183. Zero = 0x00000001,
  184. Replace = 0x00000002,
  185. Invert = 0x00000003,
  186. IncrementClamp = 0x00000004,
  187. DecrementClamp = 0x00000005,
  188. IncrementWrap = 0x00000006,
  189. DecrementWrap = 0x00000007,
  190. };
  191. enum class StorageTextureAccess : uint32_t {
  192. Undefined = 0x00000000,
  193. ReadOnly = 0x00000001,
  194. WriteOnly = 0x00000002,
  195. };
  196. enum class StoreOp : uint32_t {
  197. Store = 0x00000000,
  198. Clear = 0x00000001,
  199. };
  200. enum class TextureAspect : uint32_t {
  201. All = 0x00000000,
  202. StencilOnly = 0x00000001,
  203. DepthOnly = 0x00000002,
  204. };
  205. enum class TextureComponentType : uint32_t {
  206. Float = 0x00000000,
  207. Sint = 0x00000001,
  208. Uint = 0x00000002,
  209. DepthComparison = 0x00000003,
  210. };
  211. enum class TextureDimension : uint32_t {
  212. e1D = 0x00000000,
  213. e2D = 0x00000001,
  214. e3D = 0x00000002,
  215. };
  216. enum class TextureFormat : uint32_t {
  217. Undefined = 0x00000000,
  218. R8Unorm = 0x00000001,
  219. R8Snorm = 0x00000002,
  220. R8Uint = 0x00000003,
  221. R8Sint = 0x00000004,
  222. R16Uint = 0x00000005,
  223. R16Sint = 0x00000006,
  224. R16Float = 0x00000007,
  225. RG8Unorm = 0x00000008,
  226. RG8Snorm = 0x00000009,
  227. RG8Uint = 0x0000000A,
  228. RG8Sint = 0x0000000B,
  229. R32Float = 0x0000000C,
  230. R32Uint = 0x0000000D,
  231. R32Sint = 0x0000000E,
  232. RG16Uint = 0x0000000F,
  233. RG16Sint = 0x00000010,
  234. RG16Float = 0x00000011,
  235. RGBA8Unorm = 0x00000012,
  236. RGBA8UnormSrgb = 0x00000013,
  237. RGBA8Snorm = 0x00000014,
  238. RGBA8Uint = 0x00000015,
  239. RGBA8Sint = 0x00000016,
  240. BGRA8Unorm = 0x00000017,
  241. BGRA8UnormSrgb = 0x00000018,
  242. RGB10A2Unorm = 0x00000019,
  243. RG11B10Ufloat = 0x0000001A,
  244. RGB9E5Ufloat = 0x0000001B,
  245. RG32Float = 0x0000001C,
  246. RG32Uint = 0x0000001D,
  247. RG32Sint = 0x0000001E,
  248. RGBA16Uint = 0x0000001F,
  249. RGBA16Sint = 0x00000020,
  250. RGBA16Float = 0x00000021,
  251. RGBA32Float = 0x00000022,
  252. RGBA32Uint = 0x00000023,
  253. RGBA32Sint = 0x00000024,
  254. Depth32Float = 0x00000025,
  255. Depth24Plus = 0x00000026,
  256. Depth24PlusStencil8 = 0x00000027,
  257. BC1RGBAUnorm = 0x00000028,
  258. BC1RGBAUnormSrgb = 0x00000029,
  259. BC2RGBAUnorm = 0x0000002A,
  260. BC2RGBAUnormSrgb = 0x0000002B,
  261. BC3RGBAUnorm = 0x0000002C,
  262. BC3RGBAUnormSrgb = 0x0000002D,
  263. BC4RUnorm = 0x0000002E,
  264. BC4RSnorm = 0x0000002F,
  265. BC5RGUnorm = 0x00000030,
  266. BC5RGSnorm = 0x00000031,
  267. BC6HRGBUfloat = 0x00000032,
  268. BC6HRGBFloat = 0x00000033,
  269. BC7RGBAUnorm = 0x00000034,
  270. BC7RGBAUnormSrgb = 0x00000035,
  271. };
  272. enum class TextureSampleType : uint32_t {
  273. Undefined = 0x00000000,
  274. Float = 0x00000001,
  275. UnfilterableFloat = 0x00000002,
  276. Depth = 0x00000003,
  277. Sint = 0x00000004,
  278. Uint = 0x00000005,
  279. };
  280. enum class TextureViewDimension : uint32_t {
  281. Undefined = 0x00000000,
  282. e1D = 0x00000001,
  283. e2D = 0x00000002,
  284. e2DArray = 0x00000003,
  285. Cube = 0x00000004,
  286. CubeArray = 0x00000005,
  287. e3D = 0x00000006,
  288. };
  289. enum class VertexFormat : uint32_t {
  290. UChar2 = 0x00000000,
  291. UChar4 = 0x00000001,
  292. Char2 = 0x00000002,
  293. Char4 = 0x00000003,
  294. UChar2Norm = 0x00000004,
  295. UChar4Norm = 0x00000005,
  296. Char2Norm = 0x00000006,
  297. Char4Norm = 0x00000007,
  298. UShort2 = 0x00000008,
  299. UShort4 = 0x00000009,
  300. Short2 = 0x0000000A,
  301. Short4 = 0x0000000B,
  302. UShort2Norm = 0x0000000C,
  303. UShort4Norm = 0x0000000D,
  304. Short2Norm = 0x0000000E,
  305. Short4Norm = 0x0000000F,
  306. Half2 = 0x00000010,
  307. Half4 = 0x00000011,
  308. Float = 0x00000012,
  309. Float2 = 0x00000013,
  310. Float3 = 0x00000014,
  311. Float4 = 0x00000015,
  312. UInt = 0x00000016,
  313. UInt2 = 0x00000017,
  314. UInt3 = 0x00000018,
  315. UInt4 = 0x00000019,
  316. Int = 0x0000001A,
  317. Int2 = 0x0000001B,
  318. Int3 = 0x0000001C,
  319. Int4 = 0x0000001D,
  320. };
  321. enum class BufferUsage : uint32_t {
  322. None = 0x00000000,
  323. MapRead = 0x00000001,
  324. MapWrite = 0x00000002,
  325. CopySrc = 0x00000004,
  326. CopyDst = 0x00000008,
  327. Index = 0x00000010,
  328. Vertex = 0x00000020,
  329. Uniform = 0x00000040,
  330. Storage = 0x00000080,
  331. Indirect = 0x00000100,
  332. QueryResolve = 0x00000200,
  333. };
  334. enum class ColorWriteMask : uint32_t {
  335. None = 0x00000000,
  336. Red = 0x00000001,
  337. Green = 0x00000002,
  338. Blue = 0x00000004,
  339. Alpha = 0x00000008,
  340. All = 0x0000000F,
  341. };
  342. enum class MapMode : uint32_t {
  343. None = 0x00000000,
  344. Read = 0x00000001,
  345. Write = 0x00000002,
  346. };
  347. enum class ShaderStage : uint32_t {
  348. None = 0x00000000,
  349. Vertex = 0x00000001,
  350. Fragment = 0x00000002,
  351. Compute = 0x00000004,
  352. };
  353. enum class TextureUsage : uint32_t {
  354. None = 0x00000000,
  355. CopySrc = 0x00000001,
  356. CopyDst = 0x00000002,
  357. Sampled = 0x00000004,
  358. Storage = 0x00000008,
  359. OutputAttachment = 0x00000010,
  360. RenderAttachment = 0x00000010,
  361. Present = 0x00000020,
  362. };
  363. template<>
  364. struct IsDawnBitmask<BufferUsage> {
  365. static constexpr bool enable = true;
  366. };
  367. template<>
  368. struct IsDawnBitmask<ColorWriteMask> {
  369. static constexpr bool enable = true;
  370. };
  371. template<>
  372. struct IsDawnBitmask<MapMode> {
  373. static constexpr bool enable = true;
  374. };
  375. template<>
  376. struct IsDawnBitmask<ShaderStage> {
  377. static constexpr bool enable = true;
  378. };
  379. template<>
  380. struct IsDawnBitmask<TextureUsage> {
  381. static constexpr bool enable = true;
  382. };
  383. using Proc = WGPUProc;
  384. using BufferMapCallback = WGPUBufferMapCallback;
  385. using CreateReadyComputePipelineCallback = WGPUCreateReadyComputePipelineCallback;
  386. using CreateReadyRenderPipelineCallback = WGPUCreateReadyRenderPipelineCallback;
  387. using DeviceLostCallback = WGPUDeviceLostCallback;
  388. using ErrorCallback = WGPUErrorCallback;
  389. using FenceOnCompletionCallback = WGPUFenceOnCompletionCallback;
  390. class BindGroup;
  391. class BindGroupLayout;
  392. class Buffer;
  393. class CommandBuffer;
  394. class CommandEncoder;
  395. class ComputePassEncoder;
  396. class ComputePipeline;
  397. class Device;
  398. class Fence;
  399. class Instance;
  400. class PipelineLayout;
  401. class QuerySet;
  402. class Queue;
  403. class RenderBundle;
  404. class RenderBundleEncoder;
  405. class RenderPassEncoder;
  406. class RenderPipeline;
  407. class Sampler;
  408. class ShaderModule;
  409. class Surface;
  410. class SwapChain;
  411. class Texture;
  412. class TextureView;
  413. struct AdapterProperties;
  414. struct BindGroupEntry;
  415. struct BlendDescriptor;
  416. struct BufferBindingLayout;
  417. struct BufferDescriptor;
  418. struct Color;
  419. struct CommandBufferDescriptor;
  420. struct CommandEncoderDescriptor;
  421. struct ComputePassDescriptor;
  422. struct CopyTextureForBrowserOptions;
  423. struct DeviceProperties;
  424. struct Extent3D;
  425. struct FenceDescriptor;
  426. struct InstanceDescriptor;
  427. struct Origin3D;
  428. struct PipelineLayoutDescriptor;
  429. struct ProgrammableStageDescriptor;
  430. struct QuerySetDescriptor;
  431. struct RasterizationStateDescriptor;
  432. struct RenderBundleDescriptor;
  433. struct RenderBundleEncoderDescriptor;
  434. struct RenderPassDepthStencilAttachmentDescriptor;
  435. struct SamplerBindingLayout;
  436. struct SamplerDescriptor;
  437. struct SamplerDescriptorDummyAnisotropicFiltering;
  438. struct ShaderModuleDescriptor;
  439. struct ShaderModuleSPIRVDescriptor;
  440. struct ShaderModuleWGSLDescriptor;
  441. struct StencilStateFaceDescriptor;
  442. struct StorageTextureBindingLayout;
  443. struct SurfaceDescriptor;
  444. struct SurfaceDescriptorFromCanvasHTMLSelector;
  445. struct SurfaceDescriptorFromMetalLayer;
  446. struct SurfaceDescriptorFromWindowsHWND;
  447. struct SurfaceDescriptorFromXlib;
  448. struct SwapChainDescriptor;
  449. struct TextureBindingLayout;
  450. struct TextureDataLayout;
  451. struct TextureViewDescriptor;
  452. struct VertexAttributeDescriptor;
  453. struct BindGroupDescriptor;
  454. struct BindGroupLayoutEntry;
  455. struct BufferCopyView;
  456. struct ColorStateDescriptor;
  457. struct ComputePipelineDescriptor;
  458. struct DepthStencilStateDescriptor;
  459. struct RenderPassColorAttachmentDescriptor;
  460. struct RenderPipelineDescriptorDummyExtension;
  461. struct TextureCopyView;
  462. struct TextureDescriptor;
  463. struct VertexBufferLayoutDescriptor;
  464. struct BindGroupLayoutDescriptor;
  465. struct RenderPassDescriptor;
  466. struct VertexStateDescriptor;
  467. struct RenderPipelineDescriptor;
  468. template<typename Derived, typename CType>
  469. class ObjectBase {
  470. public:
  471. ObjectBase() = default;
  472. ObjectBase(CType handle): mHandle(handle) {
  473. if (mHandle) Derived::WGPUReference(mHandle);
  474. }
  475. ~ObjectBase() {
  476. if (mHandle) Derived::WGPURelease(mHandle);
  477. }
  478. ObjectBase(ObjectBase const& other)
  479. : ObjectBase(other.Get()) {
  480. }
  481. Derived& operator=(ObjectBase const& other) {
  482. if (&other != this) {
  483. if (mHandle) Derived::WGPURelease(mHandle);
  484. mHandle = other.mHandle;
  485. if (mHandle) Derived::WGPUReference(mHandle);
  486. }
  487. return static_cast<Derived&>(*this);
  488. }
  489. ObjectBase(ObjectBase&& other) {
  490. mHandle = other.mHandle;
  491. other.mHandle = 0;
  492. }
  493. Derived& operator=(ObjectBase&& other) {
  494. if (&other != this) {
  495. if (mHandle) Derived::WGPURelease(mHandle);
  496. mHandle = other.mHandle;
  497. other.mHandle = 0;
  498. }
  499. return static_cast<Derived&>(*this);
  500. }
  501. ObjectBase(std::nullptr_t) {}
  502. Derived& operator=(std::nullptr_t) {
  503. if (mHandle != nullptr) {
  504. Derived::WGPURelease(mHandle);
  505. mHandle = nullptr;
  506. }
  507. return static_cast<Derived&>(*this);
  508. }
  509. bool operator==(std::nullptr_t) const {
  510. return mHandle == nullptr;
  511. }
  512. bool operator!=(std::nullptr_t) const {
  513. return mHandle != nullptr;
  514. }
  515. explicit operator bool() const {
  516. return mHandle != nullptr;
  517. }
  518. CType Get() const {
  519. return mHandle;
  520. }
  521. CType Release() {
  522. CType result = mHandle;
  523. mHandle = 0;
  524. return result;
  525. }
  526. static Derived Acquire(CType handle) {
  527. Derived result;
  528. result.mHandle = handle;
  529. return result;
  530. }
  531. protected:
  532. CType mHandle = nullptr;
  533. };
  534. class BindGroup : public ObjectBase<BindGroup, WGPUBindGroup> {
  535. public:
  536. using ObjectBase::ObjectBase;
  537. using ObjectBase::operator=;
  538. private:
  539. friend ObjectBase<BindGroup, WGPUBindGroup>;
  540. static void WGPUReference(WGPUBindGroup handle);
  541. static void WGPURelease(WGPUBindGroup handle);
  542. };
  543. class BindGroupLayout : public ObjectBase<BindGroupLayout, WGPUBindGroupLayout> {
  544. public:
  545. using ObjectBase::ObjectBase;
  546. using ObjectBase::operator=;
  547. private:
  548. friend ObjectBase<BindGroupLayout, WGPUBindGroupLayout>;
  549. static void WGPUReference(WGPUBindGroupLayout handle);
  550. static void WGPURelease(WGPUBindGroupLayout handle);
  551. };
  552. class Buffer : public ObjectBase<Buffer, WGPUBuffer> {
  553. public:
  554. using ObjectBase::ObjectBase;
  555. using ObjectBase::operator=;
  556. void Destroy() const;
  557. void const * GetConstMappedRange(size_t offset = 0, size_t size = 0) const;
  558. void * GetMappedRange(size_t offset = 0, size_t size = 0) const;
  559. void MapAsync(MapMode mode, size_t offset, size_t size, BufferMapCallback callback, void * userdata) const;
  560. void Unmap() const;
  561. private:
  562. friend ObjectBase<Buffer, WGPUBuffer>;
  563. static void WGPUReference(WGPUBuffer handle);
  564. static void WGPURelease(WGPUBuffer handle);
  565. };
  566. class CommandBuffer : public ObjectBase<CommandBuffer, WGPUCommandBuffer> {
  567. public:
  568. using ObjectBase::ObjectBase;
  569. using ObjectBase::operator=;
  570. private:
  571. friend ObjectBase<CommandBuffer, WGPUCommandBuffer>;
  572. static void WGPUReference(WGPUCommandBuffer handle);
  573. static void WGPURelease(WGPUCommandBuffer handle);
  574. };
  575. class CommandEncoder : public ObjectBase<CommandEncoder, WGPUCommandEncoder> {
  576. public:
  577. using ObjectBase::ObjectBase;
  578. using ObjectBase::operator=;
  579. ComputePassEncoder BeginComputePass(ComputePassDescriptor const * descriptor = nullptr) const;
  580. RenderPassEncoder BeginRenderPass(RenderPassDescriptor const * descriptor) const;
  581. void CopyBufferToBuffer(Buffer const& source, uint64_t sourceOffset, Buffer const& destination, uint64_t destinationOffset, uint64_t size) const;
  582. void CopyBufferToTexture(BufferCopyView const * source, TextureCopyView const * destination, Extent3D const * copySize) const;
  583. void CopyTextureToBuffer(TextureCopyView const * source, BufferCopyView const * destination, Extent3D const * copySize) const;
  584. void CopyTextureToTexture(TextureCopyView const * source, TextureCopyView const * destination, Extent3D const * copySize) const;
  585. CommandBuffer Finish(CommandBufferDescriptor const * descriptor = nullptr) const;
  586. void InjectValidationError(char const * message) const;
  587. void InsertDebugMarker(char const * markerLabel) const;
  588. void PopDebugGroup() const;
  589. void PushDebugGroup(char const * groupLabel) const;
  590. void ResolveQuerySet(QuerySet const& querySet, uint32_t firstQuery, uint32_t queryCount, Buffer const& destination, uint64_t destinationOffset) const;
  591. void WriteTimestamp(QuerySet const& querySet, uint32_t queryIndex) const;
  592. private:
  593. friend ObjectBase<CommandEncoder, WGPUCommandEncoder>;
  594. static void WGPUReference(WGPUCommandEncoder handle);
  595. static void WGPURelease(WGPUCommandEncoder handle);
  596. };
  597. class ComputePassEncoder : public ObjectBase<ComputePassEncoder, WGPUComputePassEncoder> {
  598. public:
  599. using ObjectBase::ObjectBase;
  600. using ObjectBase::operator=;
  601. void Dispatch(uint32_t x, uint32_t y = 1, uint32_t z = 1) const;
  602. void DispatchIndirect(Buffer const& indirectBuffer, uint64_t indirectOffset) const;
  603. void EndPass() const;
  604. void InsertDebugMarker(char const * markerLabel) const;
  605. void PopDebugGroup() const;
  606. void PushDebugGroup(char const * groupLabel) const;
  607. void SetBindGroup(uint32_t groupIndex, BindGroup const& group, uint32_t dynamicOffsetCount = 0, uint32_t const * dynamicOffsets = nullptr) const;
  608. void SetPipeline(ComputePipeline const& pipeline) const;
  609. void WriteTimestamp(QuerySet const& querySet, uint32_t queryIndex) const;
  610. private:
  611. friend ObjectBase<ComputePassEncoder, WGPUComputePassEncoder>;
  612. static void WGPUReference(WGPUComputePassEncoder handle);
  613. static void WGPURelease(WGPUComputePassEncoder handle);
  614. };
  615. class ComputePipeline : public ObjectBase<ComputePipeline, WGPUComputePipeline> {
  616. public:
  617. using ObjectBase::ObjectBase;
  618. using ObjectBase::operator=;
  619. BindGroupLayout GetBindGroupLayout(uint32_t groupIndex) const;
  620. private:
  621. friend ObjectBase<ComputePipeline, WGPUComputePipeline>;
  622. static void WGPUReference(WGPUComputePipeline handle);
  623. static void WGPURelease(WGPUComputePipeline handle);
  624. };
  625. class Device : public ObjectBase<Device, WGPUDevice> {
  626. public:
  627. using ObjectBase::ObjectBase;
  628. using ObjectBase::operator=;
  629. BindGroup CreateBindGroup(BindGroupDescriptor const * descriptor) const;
  630. BindGroupLayout CreateBindGroupLayout(BindGroupLayoutDescriptor const * descriptor) const;
  631. Buffer CreateBuffer(BufferDescriptor const * descriptor) const;
  632. CommandEncoder CreateCommandEncoder(CommandEncoderDescriptor const * descriptor = nullptr) const;
  633. ComputePipeline CreateComputePipeline(ComputePipelineDescriptor const * descriptor) const;
  634. Buffer CreateErrorBuffer() const;
  635. PipelineLayout CreatePipelineLayout(PipelineLayoutDescriptor const * descriptor) const;
  636. QuerySet CreateQuerySet(QuerySetDescriptor const * descriptor) const;
  637. void CreateReadyComputePipeline(ComputePipelineDescriptor const * descriptor, CreateReadyComputePipelineCallback callback, void * userdata) const;
  638. void CreateReadyRenderPipeline(RenderPipelineDescriptor const * descriptor, CreateReadyRenderPipelineCallback callback, void * userdata) const;
  639. RenderBundleEncoder CreateRenderBundleEncoder(RenderBundleEncoderDescriptor const * descriptor) const;
  640. RenderPipeline CreateRenderPipeline(RenderPipelineDescriptor const * descriptor) const;
  641. Sampler CreateSampler(SamplerDescriptor const * descriptor) const;
  642. ShaderModule CreateShaderModule(ShaderModuleDescriptor const * descriptor) const;
  643. SwapChain CreateSwapChain(Surface const& surface, SwapChainDescriptor const * descriptor) const;
  644. Texture CreateTexture(TextureDescriptor const * descriptor) const;
  645. Queue GetDefaultQueue() const;
  646. void InjectError(ErrorType type, char const * message) const;
  647. void LoseForTesting() const;
  648. bool PopErrorScope(ErrorCallback callback, void * userdata) const;
  649. void PushErrorScope(ErrorFilter filter) const;
  650. void SetDeviceLostCallback(DeviceLostCallback callback, void * userdata) const;
  651. void SetUncapturedErrorCallback(ErrorCallback callback, void * userdata) const;
  652. void Tick() const;
  653. private:
  654. friend ObjectBase<Device, WGPUDevice>;
  655. static void WGPUReference(WGPUDevice handle);
  656. static void WGPURelease(WGPUDevice handle);
  657. };
  658. class Fence : public ObjectBase<Fence, WGPUFence> {
  659. public:
  660. using ObjectBase::ObjectBase;
  661. using ObjectBase::operator=;
  662. uint64_t GetCompletedValue() const;
  663. void OnCompletion(uint64_t value, FenceOnCompletionCallback callback, void * userdata) const;
  664. private:
  665. friend ObjectBase<Fence, WGPUFence>;
  666. static void WGPUReference(WGPUFence handle);
  667. static void WGPURelease(WGPUFence handle);
  668. };
  669. class Instance : public ObjectBase<Instance, WGPUInstance> {
  670. public:
  671. using ObjectBase::ObjectBase;
  672. using ObjectBase::operator=;
  673. Surface CreateSurface(SurfaceDescriptor const * descriptor) const;
  674. private:
  675. friend ObjectBase<Instance, WGPUInstance>;
  676. static void WGPUReference(WGPUInstance handle);
  677. static void WGPURelease(WGPUInstance handle);
  678. };
  679. class PipelineLayout : public ObjectBase<PipelineLayout, WGPUPipelineLayout> {
  680. public:
  681. using ObjectBase::ObjectBase;
  682. using ObjectBase::operator=;
  683. private:
  684. friend ObjectBase<PipelineLayout, WGPUPipelineLayout>;
  685. static void WGPUReference(WGPUPipelineLayout handle);
  686. static void WGPURelease(WGPUPipelineLayout handle);
  687. };
  688. class QuerySet : public ObjectBase<QuerySet, WGPUQuerySet> {
  689. public:
  690. using ObjectBase::ObjectBase;
  691. using ObjectBase::operator=;
  692. void Destroy() const;
  693. private:
  694. friend ObjectBase<QuerySet, WGPUQuerySet>;
  695. static void WGPUReference(WGPUQuerySet handle);
  696. static void WGPURelease(WGPUQuerySet handle);
  697. };
  698. class Queue : public ObjectBase<Queue, WGPUQueue> {
  699. public:
  700. using ObjectBase::ObjectBase;
  701. using ObjectBase::operator=;
  702. void CopyTextureForBrowser(TextureCopyView const * source, TextureCopyView const * destination, Extent3D const * copySize, CopyTextureForBrowserOptions const * options) const;
  703. Fence CreateFence(FenceDescriptor const * descriptor = nullptr) const;
  704. void Signal(Fence const& fence, uint64_t signalValue) const;
  705. void Submit(uint32_t commandCount, CommandBuffer const * commands) const;
  706. void WriteBuffer(Buffer const& buffer, uint64_t bufferOffset, void const * data, size_t size) const;
  707. void WriteTexture(TextureCopyView const * destination, void const * data, size_t dataSize, TextureDataLayout const * dataLayout, Extent3D const * writeSize) const;
  708. private:
  709. friend ObjectBase<Queue, WGPUQueue>;
  710. static void WGPUReference(WGPUQueue handle);
  711. static void WGPURelease(WGPUQueue handle);
  712. };
  713. class RenderBundle : public ObjectBase<RenderBundle, WGPURenderBundle> {
  714. public:
  715. using ObjectBase::ObjectBase;
  716. using ObjectBase::operator=;
  717. private:
  718. friend ObjectBase<RenderBundle, WGPURenderBundle>;
  719. static void WGPUReference(WGPURenderBundle handle);
  720. static void WGPURelease(WGPURenderBundle handle);
  721. };
  722. class RenderBundleEncoder : public ObjectBase<RenderBundleEncoder, WGPURenderBundleEncoder> {
  723. public:
  724. using ObjectBase::ObjectBase;
  725. using ObjectBase::operator=;
  726. void Draw(uint32_t vertexCount, uint32_t instanceCount = 1, uint32_t firstVertex = 0, uint32_t firstInstance = 0) const;
  727. void DrawIndexed(uint32_t indexCount, uint32_t instanceCount = 1, uint32_t firstIndex = 0, int32_t baseVertex = 0, uint32_t firstInstance = 0) const;
  728. void DrawIndexedIndirect(Buffer const& indirectBuffer, uint64_t indirectOffset) const;
  729. void DrawIndirect(Buffer const& indirectBuffer, uint64_t indirectOffset) const;
  730. RenderBundle Finish(RenderBundleDescriptor const * descriptor = nullptr) const;
  731. void InsertDebugMarker(char const * markerLabel) const;
  732. void PopDebugGroup() const;
  733. void PushDebugGroup(char const * groupLabel) const;
  734. void SetBindGroup(uint32_t groupIndex, BindGroup const& group, uint32_t dynamicOffsetCount = 0, uint32_t const * dynamicOffsets = nullptr) const;
  735. void SetIndexBuffer(Buffer const& buffer, IndexFormat format, uint64_t offset = 0, uint64_t size = 0) const;
  736. void SetIndexBufferWithFormat(Buffer const& buffer, IndexFormat format, uint64_t offset = 0, uint64_t size = 0) const;
  737. void SetPipeline(RenderPipeline const& pipeline) const;
  738. void SetVertexBuffer(uint32_t slot, Buffer const& buffer, uint64_t offset = 0, uint64_t size = 0) const;
  739. private:
  740. friend ObjectBase<RenderBundleEncoder, WGPURenderBundleEncoder>;
  741. static void WGPUReference(WGPURenderBundleEncoder handle);
  742. static void WGPURelease(WGPURenderBundleEncoder handle);
  743. };
  744. class RenderPassEncoder : public ObjectBase<RenderPassEncoder, WGPURenderPassEncoder> {
  745. public:
  746. using ObjectBase::ObjectBase;
  747. using ObjectBase::operator=;
  748. void BeginOcclusionQuery(uint32_t queryIndex) const;
  749. void Draw(uint32_t vertexCount, uint32_t instanceCount = 1, uint32_t firstVertex = 0, uint32_t firstInstance = 0) const;
  750. void DrawIndexed(uint32_t indexCount, uint32_t instanceCount = 1, uint32_t firstIndex = 0, int32_t baseVertex = 0, uint32_t firstInstance = 0) const;
  751. void DrawIndexedIndirect(Buffer const& indirectBuffer, uint64_t indirectOffset) const;
  752. void DrawIndirect(Buffer const& indirectBuffer, uint64_t indirectOffset) const;
  753. void EndOcclusionQuery() const;
  754. void EndPass() const;
  755. void ExecuteBundles(uint32_t bundlesCount, RenderBundle const * bundles) const;
  756. void InsertDebugMarker(char const * markerLabel) const;
  757. void PopDebugGroup() const;
  758. void PushDebugGroup(char const * groupLabel) const;
  759. void SetBindGroup(uint32_t groupIndex, BindGroup const& group, uint32_t dynamicOffsetCount = 0, uint32_t const * dynamicOffsets = nullptr) const;
  760. void SetBlendColor(Color const * color) const;
  761. void SetIndexBuffer(Buffer const& buffer, IndexFormat format, uint64_t offset = 0, uint64_t size = 0) const;
  762. void SetIndexBufferWithFormat(Buffer const& buffer, IndexFormat format, uint64_t offset = 0, uint64_t size = 0) const;
  763. void SetPipeline(RenderPipeline const& pipeline) const;
  764. void SetScissorRect(uint32_t x, uint32_t y, uint32_t width, uint32_t height) const;
  765. void SetStencilReference(uint32_t reference) const;
  766. void SetVertexBuffer(uint32_t slot, Buffer const& buffer, uint64_t offset = 0, uint64_t size = 0) const;
  767. void SetViewport(float x, float y, float width, float height, float minDepth, float maxDepth) const;
  768. void WriteTimestamp(QuerySet const& querySet, uint32_t queryIndex) const;
  769. private:
  770. friend ObjectBase<RenderPassEncoder, WGPURenderPassEncoder>;
  771. static void WGPUReference(WGPURenderPassEncoder handle);
  772. static void WGPURelease(WGPURenderPassEncoder handle);
  773. };
  774. class RenderPipeline : public ObjectBase<RenderPipeline, WGPURenderPipeline> {
  775. public:
  776. using ObjectBase::ObjectBase;
  777. using ObjectBase::operator=;
  778. BindGroupLayout GetBindGroupLayout(uint32_t groupIndex) const;
  779. private:
  780. friend ObjectBase<RenderPipeline, WGPURenderPipeline>;
  781. static void WGPUReference(WGPURenderPipeline handle);
  782. static void WGPURelease(WGPURenderPipeline handle);
  783. };
  784. class Sampler : public ObjectBase<Sampler, WGPUSampler> {
  785. public:
  786. using ObjectBase::ObjectBase;
  787. using ObjectBase::operator=;
  788. private:
  789. friend ObjectBase<Sampler, WGPUSampler>;
  790. static void WGPUReference(WGPUSampler handle);
  791. static void WGPURelease(WGPUSampler handle);
  792. };
  793. class ShaderModule : public ObjectBase<ShaderModule, WGPUShaderModule> {
  794. public:
  795. using ObjectBase::ObjectBase;
  796. using ObjectBase::operator=;
  797. private:
  798. friend ObjectBase<ShaderModule, WGPUShaderModule>;
  799. static void WGPUReference(WGPUShaderModule handle);
  800. static void WGPURelease(WGPUShaderModule handle);
  801. };
  802. class Surface : public ObjectBase<Surface, WGPUSurface> {
  803. public:
  804. using ObjectBase::ObjectBase;
  805. using ObjectBase::operator=;
  806. private:
  807. friend ObjectBase<Surface, WGPUSurface>;
  808. static void WGPUReference(WGPUSurface handle);
  809. static void WGPURelease(WGPUSurface handle);
  810. };
  811. class SwapChain : public ObjectBase<SwapChain, WGPUSwapChain> {
  812. public:
  813. using ObjectBase::ObjectBase;
  814. using ObjectBase::operator=;
  815. void Configure(TextureFormat format, TextureUsage allowedUsage, uint32_t width, uint32_t height) const;
  816. TextureView GetCurrentTextureView() const;
  817. void Present() const;
  818. private:
  819. friend ObjectBase<SwapChain, WGPUSwapChain>;
  820. static void WGPUReference(WGPUSwapChain handle);
  821. static void WGPURelease(WGPUSwapChain handle);
  822. };
  823. class Texture : public ObjectBase<Texture, WGPUTexture> {
  824. public:
  825. using ObjectBase::ObjectBase;
  826. using ObjectBase::operator=;
  827. TextureView CreateView(TextureViewDescriptor const * descriptor = nullptr) const;
  828. void Destroy() const;
  829. private:
  830. friend ObjectBase<Texture, WGPUTexture>;
  831. static void WGPUReference(WGPUTexture handle);
  832. static void WGPURelease(WGPUTexture handle);
  833. };
  834. class TextureView : public ObjectBase<TextureView, WGPUTextureView> {
  835. public:
  836. using ObjectBase::ObjectBase;
  837. using ObjectBase::operator=;
  838. private:
  839. friend ObjectBase<TextureView, WGPUTextureView>;
  840. static void WGPUReference(WGPUTextureView handle);
  841. static void WGPURelease(WGPUTextureView handle);
  842. };
  843. Instance CreateInstance(InstanceDescriptor const * descriptor = nullptr);
  844. Proc GetProcAddress(Device const& device, const char* procName);
  845. struct ChainedStruct {
  846. ChainedStruct const * nextInChain = nullptr;
  847. SType sType = SType::Invalid;
  848. };
  849. struct AdapterProperties {
  850. ChainedStruct const * nextInChain = nullptr;
  851. uint32_t deviceID;
  852. uint32_t vendorID;
  853. char const * name;
  854. char const * driverDescription;
  855. AdapterType adapterType;
  856. BackendType backendType;
  857. };
  858. struct BindGroupEntry {
  859. uint32_t binding;
  860. Buffer buffer = nullptr;
  861. uint64_t offset = 0;
  862. uint64_t size;
  863. Sampler sampler = nullptr;
  864. TextureView textureView = nullptr;
  865. };
  866. struct BlendDescriptor {
  867. BlendOperation operation = BlendOperation::Add;
  868. BlendFactor srcFactor = BlendFactor::One;
  869. BlendFactor dstFactor = BlendFactor::Zero;
  870. };
  871. struct BufferBindingLayout {
  872. ChainedStruct const * nextInChain = nullptr;
  873. BufferBindingType type = BufferBindingType::Undefined;
  874. bool hasDynamicOffset = false;
  875. uint64_t minBindingSize = 0;
  876. };
  877. struct BufferDescriptor {
  878. ChainedStruct const * nextInChain = nullptr;
  879. char const * label = nullptr;
  880. BufferUsage usage;
  881. uint64_t size;
  882. bool mappedAtCreation = false;
  883. };
  884. struct Color {
  885. double r;
  886. double g;
  887. double b;
  888. double a;
  889. };
  890. struct CommandBufferDescriptor {
  891. ChainedStruct const * nextInChain = nullptr;
  892. char const * label = nullptr;
  893. };
  894. struct CommandEncoderDescriptor {
  895. ChainedStruct const * nextInChain = nullptr;
  896. char const * label = nullptr;
  897. };
  898. struct ComputePassDescriptor {
  899. ChainedStruct const * nextInChain = nullptr;
  900. char const * label = nullptr;
  901. };
  902. struct CopyTextureForBrowserOptions {
  903. ChainedStruct const * nextInChain = nullptr;
  904. bool flipY = false;
  905. };
  906. struct DeviceProperties {
  907. bool textureCompressionBC = false;
  908. bool shaderFloat16 = false;
  909. bool pipelineStatisticsQuery = false;
  910. bool timestampQuery = false;
  911. };
  912. struct Extent3D {
  913. uint32_t width = 1;
  914. uint32_t height = 1;
  915. uint32_t depth = 1;
  916. };
  917. struct FenceDescriptor {
  918. ChainedStruct const * nextInChain = nullptr;
  919. char const * label = nullptr;
  920. uint64_t initialValue = 0;
  921. };
  922. struct InstanceDescriptor {
  923. ChainedStruct const * nextInChain = nullptr;
  924. };
  925. struct Origin3D {
  926. uint32_t x = 0;
  927. uint32_t y = 0;
  928. uint32_t z = 0;
  929. };
  930. struct PipelineLayoutDescriptor {
  931. ChainedStruct const * nextInChain = nullptr;
  932. char const * label = nullptr;
  933. uint32_t bindGroupLayoutCount;
  934. BindGroupLayout const * bindGroupLayouts;
  935. };
  936. struct ProgrammableStageDescriptor {
  937. ChainedStruct const * nextInChain = nullptr;
  938. ShaderModule module;
  939. char const * entryPoint;
  940. };
  941. struct QuerySetDescriptor {
  942. ChainedStruct const * nextInChain = nullptr;
  943. char const * label = nullptr;
  944. QueryType type;
  945. uint32_t count;
  946. PipelineStatisticName const * pipelineStatistics;
  947. uint32_t pipelineStatisticsCount = 0;
  948. };
  949. struct RasterizationStateDescriptor {
  950. ChainedStruct const * nextInChain = nullptr;
  951. FrontFace frontFace = FrontFace::CCW;
  952. CullMode cullMode = CullMode::None;
  953. int32_t depthBias = 0;
  954. float depthBiasSlopeScale = 0.0f;
  955. float depthBiasClamp = 0.0f;
  956. };
  957. struct RenderBundleDescriptor {
  958. ChainedStruct const * nextInChain = nullptr;
  959. char const * label = nullptr;
  960. };
  961. struct RenderBundleEncoderDescriptor {
  962. ChainedStruct const * nextInChain = nullptr;
  963. char const * label = nullptr;
  964. uint32_t colorFormatsCount;
  965. TextureFormat const * colorFormats;
  966. TextureFormat depthStencilFormat = TextureFormat::Undefined;
  967. uint32_t sampleCount = 1;
  968. };
  969. struct RenderPassDepthStencilAttachmentDescriptor {
  970. TextureView attachment;
  971. LoadOp depthLoadOp;
  972. StoreOp depthStoreOp;
  973. float clearDepth;
  974. bool depthReadOnly = false;
  975. LoadOp stencilLoadOp;
  976. StoreOp stencilStoreOp;
  977. uint32_t clearStencil = 0;
  978. bool stencilReadOnly = false;
  979. };
  980. struct SamplerBindingLayout {
  981. ChainedStruct const * nextInChain = nullptr;
  982. SamplerBindingType type = SamplerBindingType::Undefined;
  983. };
  984. struct SamplerDescriptor {
  985. ChainedStruct const * nextInChain = nullptr;
  986. char const * label = nullptr;
  987. AddressMode addressModeU = AddressMode::ClampToEdge;
  988. AddressMode addressModeV = AddressMode::ClampToEdge;
  989. AddressMode addressModeW = AddressMode::ClampToEdge;
  990. FilterMode magFilter = FilterMode::Nearest;
  991. FilterMode minFilter = FilterMode::Nearest;
  992. FilterMode mipmapFilter = FilterMode::Nearest;
  993. float lodMinClamp = 0.0f;
  994. float lodMaxClamp = 1000.0f;
  995. CompareFunction compare = CompareFunction::Undefined;
  996. uint16_t maxAnisotropy = 1;
  997. };
  998. struct SamplerDescriptorDummyAnisotropicFiltering : ChainedStruct {
  999. SamplerDescriptorDummyAnisotropicFiltering() {
  1000. sType = SType::SamplerDescriptorDummyAnisotropicFiltering;
  1001. }
  1002. alignas(ChainedStruct) float maxAnisotropy;
  1003. };
  1004. struct ShaderModuleDescriptor {
  1005. ChainedStruct const * nextInChain = nullptr;
  1006. char const * label = nullptr;
  1007. };
  1008. struct ShaderModuleSPIRVDescriptor : ChainedStruct {
  1009. ShaderModuleSPIRVDescriptor() {
  1010. sType = SType::ShaderModuleSPIRVDescriptor;
  1011. }
  1012. alignas(ChainedStruct) uint32_t codeSize;
  1013. uint32_t const * code;
  1014. };
  1015. struct ShaderModuleWGSLDescriptor : ChainedStruct {
  1016. ShaderModuleWGSLDescriptor() {
  1017. sType = SType::ShaderModuleWGSLDescriptor;
  1018. }
  1019. alignas(ChainedStruct) char const * source;
  1020. };
  1021. struct StencilStateFaceDescriptor {
  1022. CompareFunction compare = CompareFunction::Always;
  1023. StencilOperation failOp = StencilOperation::Keep;
  1024. StencilOperation depthFailOp = StencilOperation::Keep;
  1025. StencilOperation passOp = StencilOperation::Keep;
  1026. };
  1027. struct StorageTextureBindingLayout {
  1028. ChainedStruct const * nextInChain = nullptr;
  1029. StorageTextureAccess access = StorageTextureAccess::Undefined;
  1030. TextureFormat format = TextureFormat::Undefined;
  1031. TextureViewDimension viewDimension = TextureViewDimension::Undefined;
  1032. };
  1033. struct SurfaceDescriptor {
  1034. ChainedStruct const * nextInChain = nullptr;
  1035. char const * label = nullptr;
  1036. };
  1037. struct SurfaceDescriptorFromCanvasHTMLSelector : ChainedStruct {
  1038. SurfaceDescriptorFromCanvasHTMLSelector() {
  1039. sType = SType::SurfaceDescriptorFromCanvasHTMLSelector;
  1040. }
  1041. alignas(ChainedStruct) char const * selector;
  1042. };
  1043. struct SurfaceDescriptorFromMetalLayer : ChainedStruct {
  1044. SurfaceDescriptorFromMetalLayer() {
  1045. sType = SType::SurfaceDescriptorFromMetalLayer;
  1046. }
  1047. alignas(ChainedStruct) void * layer;
  1048. };
  1049. struct SurfaceDescriptorFromWindowsHWND : ChainedStruct {
  1050. SurfaceDescriptorFromWindowsHWND() {
  1051. sType = SType::SurfaceDescriptorFromWindowsHWND;
  1052. }
  1053. alignas(ChainedStruct) void * hinstance;
  1054. void * hwnd;
  1055. };
  1056. struct SurfaceDescriptorFromXlib : ChainedStruct {
  1057. SurfaceDescriptorFromXlib() {
  1058. sType = SType::SurfaceDescriptorFromXlib;
  1059. }
  1060. alignas(ChainedStruct) void * display;
  1061. uint32_t window;
  1062. };
  1063. struct SwapChainDescriptor {
  1064. ChainedStruct const * nextInChain = nullptr;
  1065. char const * label = nullptr;
  1066. TextureUsage usage;
  1067. TextureFormat format;
  1068. uint32_t width;
  1069. uint32_t height;
  1070. PresentMode presentMode;
  1071. uint64_t implementation = 0;
  1072. };
  1073. struct TextureBindingLayout {
  1074. ChainedStruct const * nextInChain = nullptr;
  1075. TextureSampleType sampleType = TextureSampleType::Undefined;
  1076. TextureViewDimension viewDimension = TextureViewDimension::Undefined;
  1077. bool multisampled = false;
  1078. };
  1079. struct TextureDataLayout {
  1080. ChainedStruct const * nextInChain = nullptr;
  1081. uint64_t offset = 0;
  1082. uint32_t bytesPerRow = WGPU_COPY_STRIDE_UNDEFINED;
  1083. uint32_t rowsPerImage = WGPU_COPY_STRIDE_UNDEFINED;
  1084. };
  1085. struct TextureViewDescriptor {
  1086. ChainedStruct const * nextInChain = nullptr;
  1087. char const * label = nullptr;
  1088. TextureFormat format = TextureFormat::Undefined;
  1089. TextureViewDimension dimension = TextureViewDimension::Undefined;
  1090. uint32_t baseMipLevel = 0;
  1091. uint32_t mipLevelCount = 0;
  1092. uint32_t baseArrayLayer = 0;
  1093. uint32_t arrayLayerCount = 0;
  1094. TextureAspect aspect = TextureAspect::All;
  1095. };
  1096. struct VertexAttributeDescriptor {
  1097. VertexFormat format;
  1098. uint64_t offset;
  1099. uint32_t shaderLocation;
  1100. };
  1101. struct BindGroupDescriptor {
  1102. ChainedStruct const * nextInChain = nullptr;
  1103. char const * label = nullptr;
  1104. BindGroupLayout layout;
  1105. uint32_t entryCount;
  1106. BindGroupEntry const * entries;
  1107. };
  1108. struct BindGroupLayoutEntry {
  1109. uint32_t binding;
  1110. ShaderStage visibility;
  1111. BindingType type = BindingType::Undefined;
  1112. bool hasDynamicOffset = false;
  1113. uint64_t minBufferBindingSize = 0;
  1114. TextureViewDimension viewDimension = TextureViewDimension::Undefined;
  1115. TextureComponentType textureComponentType = TextureComponentType::Float;
  1116. TextureFormat storageTextureFormat = TextureFormat::Undefined;
  1117. BufferBindingLayout buffer;
  1118. SamplerBindingLayout sampler;
  1119. TextureBindingLayout texture;
  1120. StorageTextureBindingLayout storageTexture;
  1121. };
  1122. struct BufferCopyView {
  1123. ChainedStruct const * nextInChain = nullptr;
  1124. TextureDataLayout layout;
  1125. Buffer buffer;
  1126. };
  1127. struct ColorStateDescriptor {
  1128. ChainedStruct const * nextInChain = nullptr;
  1129. TextureFormat format;
  1130. BlendDescriptor alphaBlend;
  1131. BlendDescriptor colorBlend;
  1132. ColorWriteMask writeMask = ColorWriteMask::All;
  1133. };
  1134. struct ComputePipelineDescriptor {
  1135. ChainedStruct const * nextInChain = nullptr;
  1136. char const * label = nullptr;
  1137. PipelineLayout layout = nullptr;
  1138. ProgrammableStageDescriptor computeStage;
  1139. };
  1140. struct DepthStencilStateDescriptor {
  1141. ChainedStruct const * nextInChain = nullptr;
  1142. TextureFormat format;
  1143. bool depthWriteEnabled = false;
  1144. CompareFunction depthCompare = CompareFunction::Always;
  1145. StencilStateFaceDescriptor stencilFront;
  1146. StencilStateFaceDescriptor stencilBack;
  1147. uint32_t stencilReadMask = 0xFFFFFFFF;
  1148. uint32_t stencilWriteMask = 0xFFFFFFFF;
  1149. };
  1150. struct RenderPassColorAttachmentDescriptor {
  1151. TextureView attachment;
  1152. TextureView resolveTarget = nullptr;
  1153. LoadOp loadOp;
  1154. StoreOp storeOp;
  1155. Color clearColor;
  1156. };
  1157. struct RenderPipelineDescriptorDummyExtension : ChainedStruct {
  1158. RenderPipelineDescriptorDummyExtension() {
  1159. sType = SType::RenderPipelineDescriptorDummyExtension;
  1160. }
  1161. alignas(ChainedStruct) ProgrammableStageDescriptor dummyStage;
  1162. };
  1163. struct TextureCopyView {
  1164. ChainedStruct const * nextInChain = nullptr;
  1165. Texture texture;
  1166. uint32_t mipLevel = 0;
  1167. Origin3D origin;
  1168. TextureAspect aspect = TextureAspect::All;
  1169. };
  1170. struct TextureDescriptor {
  1171. ChainedStruct const * nextInChain = nullptr;
  1172. char const * label = nullptr;
  1173. TextureUsage usage;
  1174. TextureDimension dimension = TextureDimension::e2D;
  1175. Extent3D size;
  1176. TextureFormat format;
  1177. uint32_t mipLevelCount = 1;
  1178. uint32_t sampleCount = 1;
  1179. };
  1180. struct VertexBufferLayoutDescriptor {
  1181. uint64_t arrayStride;
  1182. InputStepMode stepMode = InputStepMode::Vertex;
  1183. uint32_t attributeCount;
  1184. VertexAttributeDescriptor const * attributes;
  1185. };
  1186. struct BindGroupLayoutDescriptor {
  1187. ChainedStruct const * nextInChain = nullptr;
  1188. char const * label = nullptr;
  1189. uint32_t entryCount;
  1190. BindGroupLayoutEntry const * entries;
  1191. };
  1192. struct RenderPassDescriptor {
  1193. ChainedStruct const * nextInChain = nullptr;
  1194. char const * label = nullptr;
  1195. uint32_t colorAttachmentCount;
  1196. RenderPassColorAttachmentDescriptor const * colorAttachments;
  1197. RenderPassDepthStencilAttachmentDescriptor const * depthStencilAttachment = nullptr;
  1198. QuerySet occlusionQuerySet = nullptr;
  1199. };
  1200. struct VertexStateDescriptor {
  1201. ChainedStruct const * nextInChain = nullptr;
  1202. IndexFormat indexFormat = IndexFormat::Undefined;
  1203. uint32_t vertexBufferCount = 0;
  1204. VertexBufferLayoutDescriptor const * vertexBuffers;
  1205. };
  1206. struct RenderPipelineDescriptor {
  1207. ChainedStruct const * nextInChain = nullptr;
  1208. char const * label = nullptr;
  1209. PipelineLayout layout = nullptr;
  1210. ProgrammableStageDescriptor vertexStage;
  1211. ProgrammableStageDescriptor const * fragmentStage = nullptr;
  1212. VertexStateDescriptor const * vertexState = nullptr;
  1213. PrimitiveTopology primitiveTopology;
  1214. RasterizationStateDescriptor const * rasterizationState = nullptr;
  1215. uint32_t sampleCount = 1;
  1216. DepthStencilStateDescriptor const * depthStencilState = nullptr;
  1217. uint32_t colorStateCount;
  1218. ColorStateDescriptor const * colorStates;
  1219. uint32_t sampleMask = 0xFFFFFFFF;
  1220. bool alphaToCoverageEnabled = false;
  1221. };
  1222. } // namespace wgpu
  1223. #endif // WEBGPU_CPP_H_