UFO 1.0.0
An Efficient Probabilistic 3D Mapping Framework That Embraces the Unknown
Loading...
Searching...
No Matches
compute.hpp
1
42#ifndef UFO_COMPUTE_COMPUTE_HPP
43#define UFO_COMPUTE_COMPUTE_HPP
44
45#define UFO_WEBGPU
46
47// STL
48#include <filesystem>
49#include <string>
50#include <vector>
51
52// WebGPU
53#include <webgpu/webgpu.h>
54#include <webgpu/wgpu.h>
55
56// TODO: Remove these when webgpu.h is updated to the latest spec.
57// clang-format off
64#define WGPU_TRUE (UINT32_C(1))
71#define WGPU_FALSE (UINT32_C(0))
72
73#define _wgpu_ENUM_ZERO_INIT(type) type{}
74#define _wgpu_STRUCT_ZERO_INIT {}
75
79#define WGPU_INSTANCE_DESCRIPTOR_INIT _wgpu_MAKE_INIT_STRUCT(WGPUInstanceDescriptor, { \
80 /*.nextInChain=*/NULL _wgpu_COMMA \
81 /*.requiredFeatureCount=*/0 _wgpu_COMMA \
82 /*.requiredFeatures=*/NULL _wgpu_COMMA \
83 /*.requiredLimits=*/NULL _wgpu_COMMA \
84})
85
89#define WGPU_SURFACE_DESCRIPTOR_INIT _wgpu_MAKE_INIT_STRUCT(WGPUSurfaceDescriptor, { \
90 /*.nextInChain=*/NULL _wgpu_COMMA \
91 /*.label=*/WGPU_STRING_VIEW_INIT _wgpu_COMMA \
92})
93
97#define WGPU_SURFACE_SOURCE_METAL_LAYER_INIT _wgpu_MAKE_INIT_STRUCT(WGPUSurfaceSourceMetalLayer, { \
98 /*.chain=*/_wgpu_MAKE_INIT_STRUCT(WGPUChainedStruct, { \
99 /*.next=*/NULL _wgpu_COMMA \
100 /*.sType=*/WGPUSType_SurfaceSourceMetalLayer _wgpu_COMMA \
101 }) _wgpu_COMMA \
102 /*.layer=*/NULL _wgpu_COMMA \
103})
104
108#define WGPU_SURFACE_SOURCE_XLIB_WINDOW_INIT _wgpu_MAKE_INIT_STRUCT(WGPUSurfaceSourceXlibWindow, { \
109 /*.chain=*/_wgpu_MAKE_INIT_STRUCT(WGPUChainedStruct, { \
110 /*.next=*/NULL _wgpu_COMMA \
111 /*.sType=*/WGPUSType_SurfaceSourceXlibWindow _wgpu_COMMA \
112 }) _wgpu_COMMA \
113 /*.display=*/NULL _wgpu_COMMA \
114 /*.window=*/0 _wgpu_COMMA \
115})
116
120#define WGPU_SURFACE_SOURCE_WAYLAND_SURFACE_INIT _wgpu_MAKE_INIT_STRUCT(WGPUSurfaceSourceWaylandSurface, { \
121 /*.chain=*/_wgpu_MAKE_INIT_STRUCT(WGPUChainedStruct, { \
122 /*.next=*/NULL _wgpu_COMMA \
123 /*.sType=*/WGPUSType_SurfaceSourceWaylandSurface _wgpu_COMMA \
124 }) _wgpu_COMMA \
125 /*.display=*/NULL _wgpu_COMMA \
126 /*.surface=*/NULL _wgpu_COMMA \
127})
128
132#define WGPU_SURFACE_SOURCE_WINDOWS_HWND_INIT _wgpu_MAKE_INIT_STRUCT(WGPUSurfaceSourceWindowsHWND, { \
133 /*.chain=*/_wgpu_MAKE_INIT_STRUCT(WGPUChainedStruct, { \
134 /*.next=*/NULL _wgpu_COMMA \
135 /*.sType=*/WGPUSType_SurfaceSourceWindowsHWND _wgpu_COMMA \
136 }) _wgpu_COMMA \
137 /*.hinstance=*/NULL _wgpu_COMMA \
138 /*.hwnd=*/NULL _wgpu_COMMA \
139})
140
144#define WGPU_REQUEST_ADAPTER_OPTIONS_INIT _wgpu_MAKE_INIT_STRUCT(WGPURequestAdapterOptions, { \
145 /*.nextInChain=*/NULL _wgpu_COMMA \
146 /*.featureLevel=*/WGPUFeatureLevel_Core _wgpu_COMMA \
147 /*.powerPreference=*/WGPUPowerPreference_Undefined _wgpu_COMMA \
148 /*.forceFallbackAdapter=*/WGPU_FALSE _wgpu_COMMA \
149 /*.backendType=*/WGPUBackendType_Undefined _wgpu_COMMA \
150 /*.compatibleSurface=*/NULL _wgpu_COMMA \
151})
152
156#define WGPU_REQUEST_ADAPTER_CALLBACK_INFO_INIT _wgpu_MAKE_INIT_STRUCT(WGPURequestAdapterCallbackInfo, { \
157 /*.nextInChain=*/NULL _wgpu_COMMA \
158 /*.mode=*/_wgpu_ENUM_ZERO_INIT(WGPUCallbackMode) _wgpu_COMMA \
159 /*.callback=*/NULL _wgpu_COMMA \
160 /*.userdata1=*/NULL _wgpu_COMMA \
161 /*.userdata2=*/NULL _wgpu_COMMA \
162})
163
167#define WGPU_QUEUE_DESCRIPTOR_INIT _wgpu_MAKE_INIT_STRUCT(WGPUQueueDescriptor, { \
168 /*.nextInChain=*/NULL _wgpu_COMMA \
169 /*.label=*/WGPU_STRING_VIEW_INIT _wgpu_COMMA \
170})
171
175#define WGPU_DEVICE_LOST_CALLBACK_INFO_INIT _wgpu_MAKE_INIT_STRUCT(WGPUDeviceLostCallbackInfo, { \
176 /*.nextInChain=*/NULL _wgpu_COMMA \
177 /*.mode=*/_wgpu_ENUM_ZERO_INIT(WGPUCallbackMode) _wgpu_COMMA \
178 /*.callback=*/NULL _wgpu_COMMA \
179 /*.userdata1=*/NULL _wgpu_COMMA \
180 /*.userdata2=*/NULL _wgpu_COMMA \
181})
182
186#define WGPU_UNCAPTURED_ERROR_CALLBACK_INFO_INIT _wgpu_MAKE_INIT_STRUCT(WGPUUncapturedErrorCallbackInfo, { \
187 /*.nextInChain=*/NULL _wgpu_COMMA \
188 /*.callback=*/NULL _wgpu_COMMA \
189 /*.userdata1=*/NULL _wgpu_COMMA \
190 /*.userdata2=*/NULL _wgpu_COMMA \
191})
192
196#define WGPU_REQUEST_DEVICE_CALLBACK_INFO_INIT _wgpu_MAKE_INIT_STRUCT(WGPURequestDeviceCallbackInfo, { \
197 /*.nextInChain=*/NULL _wgpu_COMMA \
198 /*.mode=*/_wgpu_ENUM_ZERO_INIT(WGPUCallbackMode) _wgpu_COMMA \
199 /*.callback=*/NULL _wgpu_COMMA \
200 /*.userdata1=*/NULL _wgpu_COMMA \
201 /*.userdata2=*/NULL _wgpu_COMMA \
202})
203
207#define WGPU_DEVICE_DESCRIPTOR_INIT _wgpu_MAKE_INIT_STRUCT(WGPUDeviceDescriptor, { \
208 /*.nextInChain=*/NULL _wgpu_COMMA \
209 /*.label=*/WGPU_STRING_VIEW_INIT _wgpu_COMMA \
210 /*.requiredFeatureCount=*/0 _wgpu_COMMA \
211 /*.requiredFeatures=*/NULL _wgpu_COMMA \
212 /*.requiredLimits=*/NULL _wgpu_COMMA \
213 /*.defaultQueue=*/WGPU_QUEUE_DESCRIPTOR_INIT _wgpu_COMMA \
214 /*.deviceLostCallbackInfo=*/WGPU_DEVICE_LOST_CALLBACK_INFO_INIT _wgpu_COMMA \
215 /*.uncapturedErrorCallbackInfo=*/WGPU_UNCAPTURED_ERROR_CALLBACK_INFO_INIT _wgpu_COMMA \
216})
217
221#define WGPU_LIMITS_INIT _wgpu_MAKE_INIT_STRUCT(WGPULimits, { \
222 /*.nextInChain=*/NULL _wgpu_COMMA \
223 /*.maxTextureDimension1D=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
224 /*.maxTextureDimension2D=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
225 /*.maxTextureDimension3D=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
226 /*.maxTextureArrayLayers=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
227 /*.maxBindGroups=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
228 /*.maxBindGroupsPlusVertexBuffers=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
229 /*.maxBindingsPerBindGroup=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
230 /*.maxDynamicUniformBuffersPerPipelineLayout=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
231 /*.maxDynamicStorageBuffersPerPipelineLayout=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
232 /*.maxSampledTexturesPerShaderStage=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
233 /*.maxSamplersPerShaderStage=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
234 /*.maxStorageBuffersPerShaderStage=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
235 /*.maxStorageTexturesPerShaderStage=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
236 /*.maxUniformBuffersPerShaderStage=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
237 /*.maxUniformBufferBindingSize=*/WGPU_LIMIT_U64_UNDEFINED _wgpu_COMMA \
238 /*.maxStorageBufferBindingSize=*/WGPU_LIMIT_U64_UNDEFINED _wgpu_COMMA \
239 /*.minUniformBufferOffsetAlignment=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
240 /*.minStorageBufferOffsetAlignment=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
241 /*.maxVertexBuffers=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
242 /*.maxBufferSize=*/WGPU_LIMIT_U64_UNDEFINED _wgpu_COMMA \
243 /*.maxVertexAttributes=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
244 /*.maxVertexBufferArrayStride=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
245 /*.maxInterStageShaderVariables=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
246 /*.maxColorAttachments=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
247 /*.maxColorAttachmentBytesPerSample=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
248 /*.maxComputeWorkgroupStorageSize=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
249 /*.maxComputeInvocationsPerWorkgroup=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
250 /*.maxComputeWorkgroupSizeX=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
251 /*.maxComputeWorkgroupSizeY=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
252 /*.maxComputeWorkgroupSizeZ=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
253 /*.maxComputeWorkgroupsPerDimension=*/WGPU_LIMIT_U32_UNDEFINED _wgpu_COMMA \
254})
255
259#define WGPU_BUFFER_DESCRIPTOR_INIT _wgpu_MAKE_INIT_STRUCT(WGPUBufferDescriptor, { \
260 /*.nextInChain=*/NULL _wgpu_COMMA \
261 /*.label=*/WGPU_STRING_VIEW_INIT _wgpu_COMMA \
262 /*.usage=*/WGPUBufferUsage_None _wgpu_COMMA \
263 /*.size=*/0 _wgpu_COMMA \
264 /*.mappedAtCreation=*/WGPU_FALSE _wgpu_COMMA \
265})
266
270#define WGPU_SHADER_SOURCE_WGSL_INIT _wgpu_MAKE_INIT_STRUCT(WGPUShaderSourceWGSL, { \
271 /*.chain=*/_wgpu_MAKE_INIT_STRUCT(WGPUChainedStruct, { \
272 /*.next=*/NULL _wgpu_COMMA \
273 /*.sType=*/WGPUSType_ShaderSourceWGSL _wgpu_COMMA \
274 }) _wgpu_COMMA \
275 /*.code=*/WGPU_STRING_VIEW_INIT _wgpu_COMMA \
276})
277
281#define WGPU_PIPELINE_LAYOUT_DESCRIPTOR_INIT _wgpu_MAKE_INIT_STRUCT(WGPUPipelineLayoutDescriptor, { \
282 /*.nextInChain=*/NULL _wgpu_COMMA \
283 /*.label=*/WGPU_STRING_VIEW_INIT _wgpu_COMMA \
284 /*.bindGroupLayoutCount=*/0 _wgpu_COMMA \
285 /*.bindGroupLayouts=*/NULL _wgpu_COMMA \
286})
287
291#define WGPU_CONSTANT_ENTRY_INIT _wgpu_MAKE_INIT_STRUCT(WGPUConstantEntry, { \
292 /*.nextInChain=*/NULL _wgpu_COMMA \
293 /*.key=*/WGPU_STRING_VIEW_INIT _wgpu_COMMA \
294 /*.value=*/0. _wgpu_COMMA \
295})
296
300#define WGPU_SHADER_MODULE_DESCRIPTOR_INIT _wgpu_MAKE_INIT_STRUCT(WGPUShaderModuleDescriptor, { \
301 /*.nextInChain=*/NULL _wgpu_COMMA \
302 /*.label=*/WGPU_STRING_VIEW_INIT _wgpu_COMMA \
303})
304
308#define WGPU_BIND_GROUP_ENTRY_INIT _wgpu_MAKE_INIT_STRUCT(WGPUBindGroupEntry, { \
309 /*.nextInChain=*/NULL _wgpu_COMMA \
310 /*.binding=*/0 _wgpu_COMMA \
311 /*.buffer=*/NULL _wgpu_COMMA \
312 /*.offset=*/0 _wgpu_COMMA \
313 /*.size=*/WGPU_WHOLE_SIZE _wgpu_COMMA \
314 /*.sampler=*/NULL _wgpu_COMMA \
315 /*.textureView=*/NULL _wgpu_COMMA \
316})
317
321#define WGPU_BIND_GROUP_LAYOUT_ENTRY_INIT _wgpu_MAKE_INIT_STRUCT(WGPUBindGroupLayoutEntry, { \
322 /*.nextInChain=*/NULL _wgpu_COMMA \
323 /*.binding=*/0 _wgpu_COMMA \
324 /*.visibility=*/WGPUShaderStage_None _wgpu_COMMA \
325 /*.bindingArraySize=*/0 _wgpu_COMMA \
326 /*.buffer=*/_wgpu_STRUCT_ZERO_INIT _wgpu_COMMA \
327 /*.sampler=*/_wgpu_STRUCT_ZERO_INIT _wgpu_COMMA \
328 /*.texture=*/_wgpu_STRUCT_ZERO_INIT _wgpu_COMMA \
329 /*.storageTexture=*/_wgpu_STRUCT_ZERO_INIT _wgpu_COMMA \
330})
331
335#define WGPU_PROGRAMMABLE_STAGE_DESCRIPTOR_INIT _wgpu_MAKE_INIT_STRUCT(WGPUProgrammableStageDescriptor, { \
336 /*.nextInChain=*/NULL _wgpu_COMMA \
337 /*.module=*/NULL _wgpu_COMMA \
338 /*.entryPoint=*/WGPU_STRING_VIEW_INIT _wgpu_COMMA \
339 /*.constantCount=*/0 _wgpu_COMMA \
340 /*.constants=*/NULL _wgpu_COMMA \
341})
342
346#define WGPU_COMPUTE_PIPELINE_DESCRIPTOR_INIT _wgpu_MAKE_INIT_STRUCT(WGPUComputePipelineDescriptor, { \
347 /*.nextInChain=*/NULL _wgpu_COMMA \
348 /*.label=*/WGPU_STRING_VIEW_INIT _wgpu_COMMA \
349 /*.layout=*/NULL _wgpu_COMMA \
350 /*.compute=*/WGPU_PROGRAMMABLE_STAGE_DESCRIPTOR_INIT _wgpu_COMMA \
351})
352
356#define WGPU_COMMAND_ENCODER_DESCRIPTOR_INIT _wgpu_MAKE_INIT_STRUCT(WGPUCommandEncoderDescriptor, { \
357 /*.nextInChain=*/NULL _wgpu_COMMA \
358 /*.label=*/WGPU_STRING_VIEW_INIT _wgpu_COMMA \
359})
360
364#define WGPU_COMPUTE_PASS_DESCRIPTOR_INIT _wgpu_MAKE_INIT_STRUCT(WGPUComputePassDescriptor, { \
365 /*.nextInChain=*/NULL _wgpu_COMMA \
366 /*.label=*/WGPU_STRING_VIEW_INIT _wgpu_COMMA \
367 /*.timestampWrites=*/NULL _wgpu_COMMA \
368})
369
373#define WGPU_COMMAND_BUFFER_DESCRIPTOR_INIT _wgpu_MAKE_INIT_STRUCT(WGPUCommandBufferDescriptor, { \
374 /*.nextInChain=*/NULL _wgpu_COMMA \
375 /*.label=*/WGPU_STRING_VIEW_INIT _wgpu_COMMA \
376})
377
381#define WGPU_TEXTURE_DESCRIPTOR_INIT _wgpu_MAKE_INIT_STRUCT(WGPUTextureDescriptor, { \
382 /*.nextInChain=*/NULL _wgpu_COMMA \
383 /*.label=*/WGPU_STRING_VIEW_INIT _wgpu_COMMA \
384 /*.usage=*/WGPUTextureUsage_None _wgpu_COMMA \
385 /*.dimension=*/WGPUTextureDimension_Undefined _wgpu_COMMA \
386 /*.size=*/WGPU_EXTENT_3D_INIT _wgpu_COMMA \
387 /*.format=*/WGPUTextureFormat_Undefined _wgpu_COMMA \
388 /*.mipLevelCount=*/1 _wgpu_COMMA \
389 /*.sampleCount=*/1 _wgpu_COMMA \
390 /*.viewFormatCount=*/0 _wgpu_COMMA \
391 /*.viewFormats=*/NULL _wgpu_COMMA \
392})
393
397#define WGPU_TEXTURE_VIEW_DESCRIPTOR_INIT _wgpu_MAKE_INIT_STRUCT(WGPUTextureViewDescriptor, { \
398 /*.nextInChain=*/NULL _wgpu_COMMA \
399 /*.label=*/WGPU_STRING_VIEW_INIT _wgpu_COMMA \
400 /*.format=*/WGPUTextureFormat_Undefined _wgpu_COMMA \
401 /*.dimension=*/WGPUTextureViewDimension_Undefined _wgpu_COMMA \
402 /*.baseMipLevel=*/0 _wgpu_COMMA \
403 /*.mipLevelCount=*/WGPU_MIP_LEVEL_COUNT_UNDEFINED _wgpu_COMMA \
404 /*.baseArrayLayer=*/0 _wgpu_COMMA \
405 /*.arrayLayerCount=*/WGPU_ARRAY_LAYER_COUNT_UNDEFINED _wgpu_COMMA \
406 /*.aspect=*/WGPUTextureAspect_Undefined _wgpu_COMMA \
407 /*.usage=*/WGPUTextureUsage_None _wgpu_COMMA \
408})
409
413#define WGPU_BIND_GROUP_LAYOUT_DESCRIPTOR_INIT _wgpu_MAKE_INIT_STRUCT(WGPUBindGroupLayoutDescriptor, { \
414 /*.nextInChain=*/NULL _wgpu_COMMA \
415 /*.label=*/WGPU_STRING_VIEW_INIT _wgpu_COMMA \
416 /*.entryCount=*/0 _wgpu_COMMA \
417 /*.entries=*/NULL _wgpu_COMMA \
418})
419
423#define WGPU_BIND_GROUP_DESCRIPTOR_INIT _wgpu_MAKE_INIT_STRUCT(WGPUBindGroupDescriptor, { \
424 /*.nextInChain=*/NULL _wgpu_COMMA \
425 /*.label=*/WGPU_STRING_VIEW_INIT _wgpu_COMMA \
426 /*.layout=*/NULL _wgpu_COMMA \
427 /*.entryCount=*/0 _wgpu_COMMA \
428 /*.entries=*/NULL _wgpu_COMMA \
429})
430
434#define WGPU_ORIGIN_3D_INIT _wgpu_MAKE_INIT_STRUCT(WGPUOrigin3D, { \
435 /*.x=*/0 _wgpu_COMMA \
436 /*.y=*/0 _wgpu_COMMA \
437 /*.z=*/0 _wgpu_COMMA \
438})
439
443#define WGPU_TEXEL_COPY_TEXTURE_INFO_INIT _wgpu_MAKE_INIT_STRUCT(WGPUTexelCopyTextureInfo, { \
444 /*.texture=*/NULL _wgpu_COMMA \
445 /*.mipLevel=*/0 _wgpu_COMMA \
446 /*.origin=*/WGPU_ORIGIN_3D_INIT _wgpu_COMMA \
447 /*.aspect=*/WGPUTextureAspect_Undefined _wgpu_COMMA \
448})
449
453#define WGPU_EXTENT_3D_INIT _wgpu_MAKE_INIT_STRUCT(WGPUExtent3D, { \
454 /*.width=*/0 _wgpu_COMMA \
455 /*.height=*/1 _wgpu_COMMA \
456 /*.depthOrArrayLayers=*/1 _wgpu_COMMA \
457})
458
462#define WGPU_TEXEL_COPY_BUFFER_LAYOUT_INIT _wgpu_MAKE_INIT_STRUCT(WGPUTexelCopyBufferLayout, { \
463 /*.offset=*/0 _wgpu_COMMA \
464 /*.bytesPerRow=*/WGPU_COPY_STRIDE_UNDEFINED _wgpu_COMMA \
465 /*.rowsPerImage=*/WGPU_COPY_STRIDE_UNDEFINED _wgpu_COMMA \
466})
467
471#define WGPU_TEXEL_COPY_BUFFER_INFO_INIT _wgpu_MAKE_INIT_STRUCT(WGPUTexelCopyBufferInfo, { \
472 /*.layout=*/WGPU_TEXEL_COPY_BUFFER_LAYOUT_INIT _wgpu_COMMA \
473 /*.buffer=*/NULL _wgpu_COMMA \
474})
475
479#define WGPU_BUFFER_MAP_CALLBACK_INFO_INIT _wgpu_MAKE_INIT_STRUCT(WGPUBufferMapCallbackInfo, { \
480 /*.nextInChain=*/NULL _wgpu_COMMA \
481 /*.mode=*/_wgpu_ENUM_ZERO_INIT(WGPUCallbackMode) _wgpu_COMMA \
482 /*.callback=*/NULL _wgpu_COMMA \
483 /*.userdata1=*/NULL _wgpu_COMMA \
484 /*.userdata2=*/NULL _wgpu_COMMA \
485})
486
490#define WGPU_SURFACE_CAPABILITIES_INIT _wgpu_MAKE_INIT_STRUCT(WGPUSurfaceCapabilities, { \
491 /*.nextInChain=*/NULL _wgpu_COMMA \
492 /*.usages=*/WGPUTextureUsage_None _wgpu_COMMA \
493 /*.formatCount=*/0 _wgpu_COMMA \
494 /*.formats=*/NULL _wgpu_COMMA \
495 /*.presentModeCount=*/0 _wgpu_COMMA \
496 /*.presentModes=*/NULL _wgpu_COMMA \
497 /*.alphaModeCount=*/0 _wgpu_COMMA \
498 /*.alphaModes=*/NULL _wgpu_COMMA \
499})
500
504#define WGPU_SURFACE_CONFIGURATION_INIT _wgpu_MAKE_INIT_STRUCT(WGPUSurfaceConfiguration, { \
505 /*.nextInChain=*/NULL _wgpu_COMMA \
506 /*.device=*/NULL _wgpu_COMMA \
507 /*.format=*/WGPUTextureFormat_Undefined _wgpu_COMMA \
508 /*.usage=*/WGPUTextureUsage_RenderAttachment _wgpu_COMMA \
509 /*.width=*/0 _wgpu_COMMA \
510 /*.height=*/0 _wgpu_COMMA \
511 /*.viewFormatCount=*/0 _wgpu_COMMA \
512 /*.viewFormats=*/NULL _wgpu_COMMA \
513 /*.alphaMode=*/WGPUCompositeAlphaMode_Auto _wgpu_COMMA \
514 /*.presentMode=*/WGPUPresentMode_Undefined _wgpu_COMMA \
515})
516
520#define WGPU_SURFACE_TEXTURE_INIT _wgpu_MAKE_INIT_STRUCT(WGPUSurfaceTexture, { \
521 /*.nextInChain=*/NULL _wgpu_COMMA \
522 /*.texture=*/NULL _wgpu_COMMA \
523 /*.status=*/_wgpu_ENUM_ZERO_INIT(WGPUSurfaceGetCurrentTextureStatus) _wgpu_COMMA \
524})
525
530#define WGPU_DEPTH_CLEAR_VALUE_UNDEFINED (NAN)
531
535#define WGPU_RENDER_PASS_DEPTH_STENCIL_ATTACHMENT_INIT _wgpu_MAKE_INIT_STRUCT(WGPURenderPassDepthStencilAttachment, { \
536 /*.view=*/NULL _wgpu_COMMA \
537 /*.depthLoadOp=*/WGPULoadOp_Undefined _wgpu_COMMA \
538 /*.depthStoreOp=*/WGPUStoreOp_Undefined _wgpu_COMMA \
539 /*.depthClearValue=*/WGPU_DEPTH_CLEAR_VALUE_UNDEFINED _wgpu_COMMA \
540 /*.depthReadOnly=*/WGPU_FALSE _wgpu_COMMA \
541 /*.stencilLoadOp=*/WGPULoadOp_Undefined _wgpu_COMMA \
542 /*.stencilStoreOp=*/WGPUStoreOp_Undefined _wgpu_COMMA \
543 /*.stencilClearValue=*/0 _wgpu_COMMA \
544 /*.stencilReadOnly=*/WGPU_FALSE _wgpu_COMMA \
545})
546
550#define WGPU_RENDER_PASS_DESCRIPTOR_INIT _wgpu_MAKE_INIT_STRUCT(WGPURenderPassDescriptor, { \
551 /*.nextInChain=*/NULL _wgpu_COMMA \
552 /*.label=*/WGPU_STRING_VIEW_INIT _wgpu_COMMA \
553 /*.colorAttachmentCount=*/0 _wgpu_COMMA \
554 /*.colorAttachments=*/NULL _wgpu_COMMA \
555 /*.depthStencilAttachment=*/NULL _wgpu_COMMA \
556 /*.occlusionQuerySet=*/NULL _wgpu_COMMA \
557 /*.timestampWrites=*/NULL _wgpu_COMMA \
558})
559
563#define WGPU_COLOR_INIT _wgpu_MAKE_INIT_STRUCT(WGPUColor, { \
564 /*.r=*/0. _wgpu_COMMA \
565 /*.g=*/0. _wgpu_COMMA \
566 /*.b=*/0. _wgpu_COMMA \
567 /*.a=*/0. _wgpu_COMMA \
568})
569
573#define WGPU_RENDER_PASS_COLOR_ATTACHMENT_INIT _wgpu_MAKE_INIT_STRUCT(WGPURenderPassColorAttachment, { \
574 /*.nextInChain=*/NULL _wgpu_COMMA \
575 /*.view=*/NULL _wgpu_COMMA \
576 /*.depthSlice=*/WGPU_DEPTH_SLICE_UNDEFINED _wgpu_COMMA \
577 /*.resolveTarget=*/NULL _wgpu_COMMA \
578 /*.loadOp=*/WGPULoadOp_Undefined _wgpu_COMMA \
579 /*.storeOp=*/WGPUStoreOp_Undefined _wgpu_COMMA \
580 /*.clearValue=*/WGPU_COLOR_INIT _wgpu_COMMA \
581})
582
586#define WGPU_VERTEX_STATE_INIT _wgpu_MAKE_INIT_STRUCT(WGPUVertexState, { \
587 /*.nextInChain=*/NULL _wgpu_COMMA \
588 /*.module=*/NULL _wgpu_COMMA \
589 /*.entryPoint=*/WGPU_STRING_VIEW_INIT _wgpu_COMMA \
590 /*.constantCount=*/0 _wgpu_COMMA \
591 /*.constants=*/NULL _wgpu_COMMA \
592 /*.bufferCount=*/0 _wgpu_COMMA \
593 /*.buffers=*/NULL _wgpu_COMMA \
594})
595
599#define WGPU_PRIMITIVE_STATE_INIT _wgpu_MAKE_INIT_STRUCT(WGPUPrimitiveState, { \
600 /*.nextInChain=*/NULL _wgpu_COMMA \
601 /*.topology=*/WGPUPrimitiveTopology_Undefined _wgpu_COMMA \
602 /*.stripIndexFormat=*/WGPUIndexFormat_Undefined _wgpu_COMMA \
603 /*.frontFace=*/WGPUFrontFace_Undefined _wgpu_COMMA \
604 /*.cullMode=*/WGPUCullMode_Undefined _wgpu_COMMA \
605 /*.unclippedDepth=*/WGPU_FALSE _wgpu_COMMA \
606})
607
611#define WGPU_MULTISAMPLE_STATE_INIT _wgpu_MAKE_INIT_STRUCT(WGPUMultisampleState, { \
612 /*.nextInChain=*/NULL _wgpu_COMMA \
613 /*.count=*/1 _wgpu_COMMA \
614 /*.mask=*/0xFFFFFFFF _wgpu_COMMA \
615 /*.alphaToCoverageEnabled=*/WGPU_FALSE _wgpu_COMMA \
616})
617
621#define WGPU_RENDER_PIPELINE_DESCRIPTOR_INIT _wgpu_MAKE_INIT_STRUCT(WGPURenderPipelineDescriptor, { \
622 /*.nextInChain=*/NULL _wgpu_COMMA \
623 /*.label=*/WGPU_STRING_VIEW_INIT _wgpu_COMMA \
624 /*.layout=*/NULL _wgpu_COMMA \
625 /*.vertex=*/WGPU_VERTEX_STATE_INIT _wgpu_COMMA \
626 /*.primitive=*/WGPU_PRIMITIVE_STATE_INIT _wgpu_COMMA \
627 /*.depthStencil=*/NULL _wgpu_COMMA \
628 /*.multisample=*/WGPU_MULTISAMPLE_STATE_INIT _wgpu_COMMA \
629 /*.fragment=*/NULL _wgpu_COMMA \
630})
631
635#define WGPU_VERTEX_BUFFER_LAYOUT_INIT _wgpu_MAKE_INIT_STRUCT(WGPUVertexBufferLayout, { \
636 /*.nextInChain=*/NULL _wgpu_COMMA \
637 /*.stepMode=*/WGPUVertexStepMode_Undefined _wgpu_COMMA \
638 /*.arrayStride=*/0 _wgpu_COMMA \
639 /*.attributeCount=*/0 _wgpu_COMMA \
640 /*.attributes=*/NULL _wgpu_COMMA \
641})
642
646#define WGPU_FRAGMENT_STATE_INIT _wgpu_MAKE_INIT_STRUCT(WGPUFragmentState, { \
647 /*.nextInChain=*/NULL _wgpu_COMMA \
648 /*.module=*/NULL _wgpu_COMMA \
649 /*.entryPoint=*/WGPU_STRING_VIEW_INIT _wgpu_COMMA \
650 /*.constantCount=*/0 _wgpu_COMMA \
651 /*.constants=*/NULL _wgpu_COMMA \
652 /*.targetCount=*/0 _wgpu_COMMA \
653 /*.targets=*/NULL _wgpu_COMMA \
654})
655
659#define WGPU_COLOR_TARGET_STATE_INIT _wgpu_MAKE_INIT_STRUCT(WGPUColorTargetState, { \
660 /*.nextInChain=*/NULL _wgpu_COMMA \
661 /*.format=*/WGPUTextureFormat_Undefined _wgpu_COMMA \
662 /*.blend=*/NULL _wgpu_COMMA \
663 /*.writeMask=*/WGPUColorWriteMask_All _wgpu_COMMA \
664})
665
669#define WGPU_BLEND_COMPONENT_INIT _wgpu_MAKE_INIT_STRUCT(WGPUBlendComponent, { \
670 /*.operation=*/WGPUBlendOperation_Undefined _wgpu_COMMA \
671 /*.srcFactor=*/WGPUBlendFactor_Undefined _wgpu_COMMA \
672 /*.dstFactor=*/WGPUBlendFactor_Undefined _wgpu_COMMA \
673})
674
678#define WGPU_BLEND_STATE_INIT _wgpu_MAKE_INIT_STRUCT(WGPUBlendState, { \
679 /*.color=*/WGPU_BLEND_COMPONENT_INIT _wgpu_COMMA \
680 /*.alpha=*/WGPU_BLEND_COMPONENT_INIT _wgpu_COMMA \
681})
682
686#define WGPU_STENCIL_FACE_STATE_INIT _wgpu_MAKE_INIT_STRUCT(WGPUStencilFaceState, { \
687 /*.compare=*/WGPUCompareFunction_Undefined _wgpu_COMMA \
688 /*.failOp=*/WGPUStencilOperation_Undefined _wgpu_COMMA \
689 /*.depthFailOp=*/WGPUStencilOperation_Undefined _wgpu_COMMA \
690 /*.passOp=*/WGPUStencilOperation_Undefined _wgpu_COMMA \
691})
692
696#define WGPU_DEPTH_STENCIL_STATE_INIT _wgpu_MAKE_INIT_STRUCT(WGPUDepthStencilState, { \
697 /*.nextInChain=*/NULL _wgpu_COMMA \
698 /*.format=*/WGPUTextureFormat_Undefined _wgpu_COMMA \
699 /*.depthWriteEnabled=*/WGPUOptionalBool_Undefined _wgpu_COMMA \
700 /*.depthCompare=*/WGPUCompareFunction_Undefined _wgpu_COMMA \
701 /*.stencilFront=*/WGPU_STENCIL_FACE_STATE_INIT _wgpu_COMMA \
702 /*.stencilBack=*/WGPU_STENCIL_FACE_STATE_INIT _wgpu_COMMA \
703 /*.stencilReadMask=*/0xFFFFFFFF _wgpu_COMMA \
704 /*.stencilWriteMask=*/0xFFFFFFFF _wgpu_COMMA \
705 /*.depthBias=*/0 _wgpu_COMMA \
706 /*.depthBiasSlopeScale=*/0.f _wgpu_COMMA \
707 /*.depthBiasClamp=*/0.f _wgpu_COMMA \
708})
709
713#define WGPU_SAMPLER_DESCRIPTOR_INIT _wgpu_MAKE_INIT_STRUCT(WGPUSamplerDescriptor, { \
714 /*.nextInChain=*/NULL _wgpu_COMMA \
715 /*.label=*/WGPU_STRING_VIEW_INIT _wgpu_COMMA \
716 /*.addressModeU=*/WGPUAddressMode_Undefined _wgpu_COMMA \
717 /*.addressModeV=*/WGPUAddressMode_Undefined _wgpu_COMMA \
718 /*.addressModeW=*/WGPUAddressMode_Undefined _wgpu_COMMA \
719 /*.magFilter=*/WGPUFilterMode_Undefined _wgpu_COMMA \
720 /*.minFilter=*/WGPUFilterMode_Undefined _wgpu_COMMA \
721 /*.mipmapFilter=*/WGPUMipmapFilterMode_Undefined _wgpu_COMMA \
722 /*.lodMinClamp=*/0.f _wgpu_COMMA \
723 /*.lodMaxClamp=*/32.f _wgpu_COMMA \
724 /*.compare=*/WGPUCompareFunction_Undefined _wgpu_COMMA \
725 /*.maxAnisotropy=*/1 _wgpu_COMMA \
726})
727// clang-format on
728
730{
731struct GPUInfo {
732 std::string name;
733 std::string architecture;
734 std::string vendor;
735 std::string type;
736 std::string backend;
737 std::string description;
738};
739
740[[nodiscard]] WGPUInstance createInstance(
741 WGPUInstanceDescriptor const* descriptor = nullptr);
742
743[[nodiscard]] WGPUAdapter createAdapter(
744 WGPUInstance instance, WGPUSurface compatible_surface = nullptr,
745 WGPUPowerPreference power_preference = WGPUPowerPreference_Undefined,
746 WGPUBackendType backend_type = WGPUBackendType_Undefined,
747 WGPUBool force_fallback_adapter = false);
748
749[[nodiscard]] WGPUDevice createDevice(WGPUAdapter adapter,
750 WGPULimits const* required_limits = nullptr);
751
752[[nodiscard]] WGPUQueue queue(WGPUDevice device);
753
754[[nodiscard]] std::size_t bufferPaddedSize(std::size_t size);
755
756[[nodiscard]] std::size_t bufferPaddedSize(std::size_t width,
757 std::size_t bytes_per_pixel);
758
759[[nodiscard]] WGPUBuffer createBuffer(WGPUDevice device, std::string label,
760 std::size_t size, WGPUBufferUsage usage,
761 bool mapped_at_creation = false);
762
763[[nodiscard]] WGPUBuffer createBufferInit(WGPUDevice device, WGPUBufferUsage usage,
764 void* content, std::size_t content_size);
765
766[[nodiscard]] WGPUSurfaceCapabilities surfaceCapabilities(WGPUSurface surface,
767 WGPUAdapter adapter);
768
769[[nodiscard]] WGPUShaderModule loadShaderModule(WGPUDevice device,
770 std::filesystem::path const& path);
771
772// Release
773
774void release(WGPUInstance instance);
775
776void release(WGPUSurface surface);
777
778void release(WGPUAdapter adapter);
779
780void release(WGPUDevice device);
781
782void release(WGPUQueue queue);
783
784void release(WGPUShaderModule shader_module);
785
786void release(WGPUBindGroupLayout bind_group_layout);
787
788void release(WGPUPipelineLayout pipeline_layout);
789
790void release(WGPURenderPipeline render_pipeline);
791
792void release(WGPUTexture texture);
793
794void release(WGPUTextureView texture_view);
795
796void release(WGPURenderPassEncoder render_pass_encoder);
797
798void release(WGPUCommandEncoder command_encoder);
799
800void release(WGPUCommandBuffer command_buffer);
801
802void release(WGPUSampler sampler);
803
804[[nodiscard]] GPUInfo gpuInfo(WGPUAdapter adapter = nullptr);
805
806[[nodiscard]] std::vector<GPUInfo> gpusInfo();
807} // namespace ufo::compute
808
809#endif // UFO_COMPUTE_COMPUTE_HPP