wgpu 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE-APACHE +190 -0
  3. data/LICENSE-MIT +21 -0
  4. data/README.md +228 -0
  5. data/ext/wgpu/Makefile +7 -0
  6. data/ext/wgpu/extconf.rb +161 -0
  7. data/lib/wgpu/async_task.rb +55 -0
  8. data/lib/wgpu/commands/command_buffer.rb +17 -0
  9. data/lib/wgpu/commands/command_encoder.rb +201 -0
  10. data/lib/wgpu/commands/compute_pass.rb +89 -0
  11. data/lib/wgpu/commands/render_bundle.rb +18 -0
  12. data/lib/wgpu/commands/render_bundle_encoder.rb +148 -0
  13. data/lib/wgpu/commands/render_pass.rb +207 -0
  14. data/lib/wgpu/core/adapter.rb +186 -0
  15. data/lib/wgpu/core/canvas_context.rb +104 -0
  16. data/lib/wgpu/core/device.rb +397 -0
  17. data/lib/wgpu/core/instance.rb +81 -0
  18. data/lib/wgpu/core/queue.rb +197 -0
  19. data/lib/wgpu/core/surface.rb +221 -0
  20. data/lib/wgpu/error.rb +16 -0
  21. data/lib/wgpu/native/callbacks.rb +26 -0
  22. data/lib/wgpu/native/enums.rb +529 -0
  23. data/lib/wgpu/native/functions.rb +419 -0
  24. data/lib/wgpu/native/loader.rb +61 -0
  25. data/lib/wgpu/native/structs.rb +646 -0
  26. data/lib/wgpu/pipeline/bind_group.rb +80 -0
  27. data/lib/wgpu/pipeline/bind_group_layout.rb +121 -0
  28. data/lib/wgpu/pipeline/compute_pipeline.rb +88 -0
  29. data/lib/wgpu/pipeline/pipeline_layout.rb +43 -0
  30. data/lib/wgpu/pipeline/render_pipeline.rb +278 -0
  31. data/lib/wgpu/pipeline/shader_module.rb +202 -0
  32. data/lib/wgpu/resources/buffer.rb +228 -0
  33. data/lib/wgpu/resources/query_set.rb +45 -0
  34. data/lib/wgpu/resources/sampler.rb +47 -0
  35. data/lib/wgpu/resources/texture.rb +136 -0
  36. data/lib/wgpu/resources/texture_view.rb +49 -0
  37. data/lib/wgpu/version.rb +5 -0
  38. data/lib/wgpu/window.rb +177 -0
  39. data/lib/wgpu.rb +36 -0
  40. metadata +125 -0
@@ -0,0 +1,419 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WGPU
4
+ module Native
5
+ attach_function :wgpuCreateInstance,
6
+ [InstanceDescriptor.by_ref], :pointer
7
+
8
+ attach_function :wgpuInstanceRelease,
9
+ [:pointer], :void
10
+
11
+ attach_function :wgpuInstanceRequestAdapter,
12
+ [:pointer, RequestAdapterOptions.by_ref, RequestAdapterCallbackInfo.by_value], :pointer
13
+
14
+ attach_function :wgpuInstanceEnumerateAdapters,
15
+ [:pointer, :pointer, :pointer], :size_t
16
+
17
+ attach_function :wgpuInstanceProcessEvents,
18
+ [:pointer], :void
19
+
20
+ attach_function :wgpuAdapterRelease,
21
+ [:pointer], :void
22
+
23
+ attach_function :wgpuAdapterGetInfo,
24
+ [:pointer, AdapterInfo.by_ref], :void
25
+
26
+ attach_function :wgpuAdapterRequestDevice,
27
+ [:pointer, DeviceDescriptor.by_ref, RequestDeviceCallbackInfo.by_value], :pointer
28
+
29
+ attach_function :wgpuAdapterGetFeatures,
30
+ [:pointer, :pointer], :void
31
+
32
+ attach_function :wgpuAdapterGetLimits,
33
+ [:pointer, :pointer], :uint32
34
+
35
+ attach_function :wgpuDeviceRelease,
36
+ [:pointer], :void
37
+
38
+ attach_function :wgpuDeviceDestroy,
39
+ [:pointer], :void
40
+
41
+ attach_function :wgpuDeviceGetQueue,
42
+ [:pointer], :pointer
43
+
44
+ attach_function :wgpuDeviceCreateBuffer,
45
+ [:pointer, BufferDescriptor.by_ref], :pointer
46
+
47
+ attach_function :wgpuDeviceCreateTexture,
48
+ [:pointer, TextureDescriptor.by_ref], :pointer
49
+
50
+ attach_function :wgpuDeviceCreateSampler,
51
+ [:pointer, :pointer], :pointer
52
+
53
+ attach_function :wgpuDeviceCreateShaderModule,
54
+ [:pointer, ShaderModuleDescriptor.by_ref], :pointer
55
+
56
+ attach_function :wgpuDeviceCreateBindGroupLayout,
57
+ [:pointer, BindGroupLayoutDescriptor.by_ref], :pointer
58
+
59
+ attach_function :wgpuDeviceCreateBindGroup,
60
+ [:pointer, BindGroupDescriptor.by_ref], :pointer
61
+
62
+ attach_function :wgpuDeviceCreatePipelineLayout,
63
+ [:pointer, PipelineLayoutDescriptor.by_ref], :pointer
64
+
65
+ attach_function :wgpuDeviceCreateRenderPipeline,
66
+ [:pointer, :pointer], :pointer
67
+
68
+ attach_function :wgpuDeviceCreateComputePipeline,
69
+ [:pointer, ComputePipelineDescriptor.by_ref], :pointer
70
+
71
+ attach_function :wgpuDeviceCreateCommandEncoder,
72
+ [:pointer, CommandEncoderDescriptor.by_ref], :pointer
73
+
74
+ attach_function :wgpuDevicePoll,
75
+ [:pointer, :uint32, :pointer], :uint32
76
+
77
+ attach_function :wgpuQueueRelease,
78
+ [:pointer], :void
79
+
80
+ attach_function :wgpuQueueSubmit,
81
+ [:pointer, :size_t, :pointer], :void
82
+
83
+ attach_function :wgpuQueueOnSubmittedWorkDone,
84
+ [:pointer, QueueWorkDoneCallbackInfo.by_value], :pointer
85
+
86
+ attach_function :wgpuQueueWriteBuffer,
87
+ [:pointer, :pointer, :uint64, :pointer, :size_t], :void
88
+
89
+ attach_function :wgpuQueueWriteTexture,
90
+ [:pointer, :pointer, :pointer, :size_t, :pointer, :pointer], :void
91
+
92
+ attach_function :wgpuBufferRelease,
93
+ [:pointer], :void
94
+
95
+ attach_function :wgpuBufferDestroy,
96
+ [:pointer], :void
97
+
98
+ attach_function :wgpuBufferMapAsync,
99
+ [:pointer, :uint64, :size_t, :size_t, BufferMapCallbackInfo.by_value], :pointer
100
+
101
+ attach_function :wgpuBufferUnmap,
102
+ [:pointer], :void
103
+
104
+ attach_function :wgpuBufferGetMappedRange,
105
+ [:pointer, :size_t, :size_t], :pointer
106
+
107
+ attach_function :wgpuBufferGetConstMappedRange,
108
+ [:pointer, :size_t, :size_t], :pointer
109
+
110
+ attach_function :wgpuBufferGetSize,
111
+ [:pointer], :uint64
112
+
113
+ attach_function :wgpuBufferGetUsage,
114
+ [:pointer], :uint64
115
+
116
+ attach_function :wgpuBufferGetMapState,
117
+ [:pointer], BufferMapState
118
+
119
+ attach_function :wgpuShaderModuleRelease,
120
+ [:pointer], :void
121
+
122
+ attach_function :wgpuShaderModuleGetCompilationInfo,
123
+ [:pointer, CompilationInfoCallbackInfo.by_value], :pointer
124
+
125
+ attach_function :wgpuCommandEncoderRelease,
126
+ [:pointer], :void
127
+
128
+ attach_function :wgpuCommandEncoderBeginRenderPass,
129
+ [:pointer, RenderPassDescriptor.by_ref], :pointer
130
+
131
+ attach_function :wgpuCommandEncoderBeginComputePass,
132
+ [:pointer, ComputePassDescriptor.by_ref], :pointer
133
+
134
+ attach_function :wgpuCommandEncoderCopyBufferToBuffer,
135
+ [:pointer, :pointer, :uint64, :pointer, :uint64, :uint64], :void
136
+
137
+ attach_function :wgpuCommandEncoderCopyBufferToTexture,
138
+ [:pointer, :pointer, :pointer, :pointer], :void
139
+
140
+ attach_function :wgpuCommandEncoderCopyTextureToBuffer,
141
+ [:pointer, :pointer, :pointer, :pointer], :void
142
+
143
+ attach_function :wgpuCommandEncoderCopyTextureToTexture,
144
+ [:pointer, :pointer, :pointer, :pointer], :void
145
+
146
+ attach_function :wgpuCommandEncoderFinish,
147
+ [:pointer, :pointer], :pointer
148
+
149
+ attach_function :wgpuCommandEncoderClearBuffer,
150
+ [:pointer, :pointer, :uint64, :uint64], :void
151
+
152
+ attach_function :wgpuCommandEncoderWriteTimestamp,
153
+ [:pointer, :pointer, :uint32], :void
154
+
155
+ attach_function :wgpuCommandEncoderPushDebugGroup,
156
+ [:pointer, StringView.by_value], :void
157
+
158
+ attach_function :wgpuCommandEncoderPopDebugGroup,
159
+ [:pointer], :void
160
+
161
+ attach_function :wgpuCommandEncoderInsertDebugMarker,
162
+ [:pointer, StringView.by_value], :void
163
+
164
+ attach_function :wgpuCommandBufferRelease,
165
+ [:pointer], :void
166
+
167
+ attach_function :wgpuRenderPassEncoderRelease,
168
+ [:pointer], :void
169
+
170
+ attach_function :wgpuRenderPassEncoderEnd,
171
+ [:pointer], :void
172
+
173
+ attach_function :wgpuRenderPassEncoderSetPipeline,
174
+ [:pointer, :pointer], :void
175
+
176
+ attach_function :wgpuRenderPassEncoderSetBindGroup,
177
+ [:pointer, :uint32, :pointer, :size_t, :pointer], :void
178
+
179
+ attach_function :wgpuRenderPassEncoderSetVertexBuffer,
180
+ [:pointer, :uint32, :pointer, :uint64, :uint64], :void
181
+
182
+ attach_function :wgpuRenderPassEncoderSetIndexBuffer,
183
+ [:pointer, :pointer, IndexFormat, :uint64, :uint64], :void
184
+
185
+ attach_function :wgpuRenderPassEncoderDraw,
186
+ [:pointer, :uint32, :uint32, :uint32, :uint32], :void
187
+
188
+ attach_function :wgpuRenderPassEncoderDrawIndexed,
189
+ [:pointer, :uint32, :uint32, :uint32, :int32, :uint32], :void
190
+
191
+ attach_function :wgpuRenderPassEncoderSetViewport,
192
+ [:pointer, :float, :float, :float, :float, :float, :float], :void
193
+
194
+ attach_function :wgpuRenderPassEncoderSetScissorRect,
195
+ [:pointer, :uint32, :uint32, :uint32, :uint32], :void
196
+
197
+ attach_function :wgpuRenderPassEncoderSetBlendConstant,
198
+ [:pointer, :pointer], :void
199
+
200
+ attach_function :wgpuRenderPassEncoderSetStencilReference,
201
+ [:pointer, :uint32], :void
202
+
203
+ attach_function :wgpuRenderPassEncoderDrawIndirect,
204
+ [:pointer, :pointer, :uint64], :void
205
+
206
+ attach_function :wgpuRenderPassEncoderDrawIndexedIndirect,
207
+ [:pointer, :pointer, :uint64], :void
208
+
209
+ attach_function :wgpuRenderPassEncoderExecuteBundles,
210
+ [:pointer, :size_t, :pointer], :void
211
+
212
+ attach_function :wgpuRenderPassEncoderBeginOcclusionQuery,
213
+ [:pointer, :uint32], :void
214
+
215
+ attach_function :wgpuRenderPassEncoderEndOcclusionQuery,
216
+ [:pointer], :void
217
+
218
+ attach_function :wgpuRenderPassEncoderPushDebugGroup,
219
+ [:pointer, StringView.by_value], :void
220
+
221
+ attach_function :wgpuRenderPassEncoderPopDebugGroup,
222
+ [:pointer], :void
223
+
224
+ attach_function :wgpuRenderPassEncoderInsertDebugMarker,
225
+ [:pointer, StringView.by_value], :void
226
+
227
+ attach_function :wgpuComputePassEncoderRelease,
228
+ [:pointer], :void
229
+
230
+ attach_function :wgpuComputePassEncoderEnd,
231
+ [:pointer], :void
232
+
233
+ attach_function :wgpuComputePassEncoderSetPipeline,
234
+ [:pointer, :pointer], :void
235
+
236
+ attach_function :wgpuComputePassEncoderSetBindGroup,
237
+ [:pointer, :uint32, :pointer, :size_t, :pointer], :void
238
+
239
+ attach_function :wgpuComputePassEncoderDispatchWorkgroups,
240
+ [:pointer, :uint32, :uint32, :uint32], :void
241
+
242
+ attach_function :wgpuComputePassEncoderDispatchWorkgroupsIndirect,
243
+ [:pointer, :pointer, :uint64], :void
244
+
245
+ attach_function :wgpuComputePassEncoderPushDebugGroup,
246
+ [:pointer, StringView.by_value], :void
247
+
248
+ attach_function :wgpuComputePassEncoderPopDebugGroup,
249
+ [:pointer], :void
250
+
251
+ attach_function :wgpuComputePassEncoderInsertDebugMarker,
252
+ [:pointer, StringView.by_value], :void
253
+
254
+ attach_function :wgpuBindGroupRelease,
255
+ [:pointer], :void
256
+
257
+ attach_function :wgpuBindGroupLayoutRelease,
258
+ [:pointer], :void
259
+
260
+ attach_function :wgpuPipelineLayoutRelease,
261
+ [:pointer], :void
262
+
263
+ attach_function :wgpuComputePipelineRelease,
264
+ [:pointer], :void
265
+
266
+ attach_function :wgpuRenderPipelineRelease,
267
+ [:pointer], :void
268
+
269
+ attach_function :wgpuTextureRelease,
270
+ [:pointer], :void
271
+
272
+ attach_function :wgpuTextureDestroy,
273
+ [:pointer], :void
274
+
275
+ attach_function :wgpuTextureCreateView,
276
+ [:pointer, :pointer], :pointer
277
+
278
+ attach_function :wgpuTextureViewRelease,
279
+ [:pointer], :void
280
+
281
+ attach_function :wgpuAdapterInfoFreeMembers,
282
+ [AdapterInfo.by_value], :void
283
+
284
+ attach_function :wgpuSamplerRelease,
285
+ [:pointer], :void
286
+
287
+ attach_function :wgpuInstanceCreateSurface,
288
+ [:pointer, SurfaceDescriptor.by_ref], :pointer
289
+
290
+ attach_function :wgpuSurfaceRelease,
291
+ [:pointer], :void
292
+
293
+ attach_function :wgpuSurfaceConfigure,
294
+ [:pointer, SurfaceConfiguration.by_ref], :void
295
+
296
+ attach_function :wgpuSurfaceUnconfigure,
297
+ [:pointer], :void
298
+
299
+ attach_function :wgpuSurfaceGetCurrentTexture,
300
+ [:pointer, SurfaceTexture.by_ref], :void
301
+
302
+ attach_function :wgpuSurfacePresent,
303
+ [:pointer], :void
304
+
305
+ attach_function :wgpuSurfaceGetCapabilities,
306
+ [:pointer, :pointer, SurfaceCapabilities.by_ref], :void
307
+
308
+ attach_function :wgpuSurfaceCapabilitiesFreeMembers,
309
+ [SurfaceCapabilities.by_value], :void
310
+
311
+ attach_function :wgpuTextureGetWidth,
312
+ [:pointer], :uint32
313
+
314
+ attach_function :wgpuTextureGetHeight,
315
+ [:pointer], :uint32
316
+
317
+ attach_function :wgpuTextureGetDepthOrArrayLayers,
318
+ [:pointer], :uint32
319
+
320
+ attach_function :wgpuTextureGetMipLevelCount,
321
+ [:pointer], :uint32
322
+
323
+ attach_function :wgpuTextureGetSampleCount,
324
+ [:pointer], :uint32
325
+
326
+ attach_function :wgpuTextureGetDimension,
327
+ [:pointer], TextureDimension
328
+
329
+ attach_function :wgpuTextureGetFormat,
330
+ [:pointer], TextureFormat
331
+
332
+ attach_function :wgpuTextureGetUsage,
333
+ [:pointer], :uint64
334
+
335
+ attach_function :wgpuDeviceCreateQuerySet,
336
+ [:pointer, QuerySetDescriptor.by_ref], :pointer
337
+
338
+ attach_function :wgpuQuerySetDestroy,
339
+ [:pointer], :void
340
+
341
+ attach_function :wgpuQuerySetRelease,
342
+ [:pointer], :void
343
+
344
+ attach_function :wgpuQuerySetGetCount,
345
+ [:pointer], :uint32
346
+
347
+ attach_function :wgpuQuerySetGetType,
348
+ [:pointer], QueryType
349
+
350
+ attach_function :wgpuCommandEncoderResolveQuerySet,
351
+ [:pointer, :pointer, :uint32, :uint32, :pointer, :uint64], :void
352
+
353
+ attach_function :wgpuAdapterGetFeatures,
354
+ [:pointer, SupportedFeatures.by_ref], :void
355
+
356
+ attach_function :wgpuDeviceGetFeatures,
357
+ [:pointer, SupportedFeatures.by_ref], :void
358
+
359
+ attach_function :wgpuDeviceGetLimits,
360
+ [:pointer, SupportedLimits.by_ref], :uint32
361
+
362
+ attach_function :wgpuDevicePushErrorScope,
363
+ [:pointer, ErrorFilter], :void
364
+
365
+ attach_function :wgpuDevicePopErrorScope,
366
+ [:pointer, PopErrorScopeCallbackInfo.by_value], :pointer
367
+
368
+ attach_function :wgpuComputePipelineGetBindGroupLayout,
369
+ [:pointer, :uint32], :pointer
370
+
371
+ attach_function :wgpuRenderPipelineGetBindGroupLayout,
372
+ [:pointer, :uint32], :pointer
373
+
374
+ attach_function :wgpuDeviceCreateRenderBundleEncoder,
375
+ [:pointer, RenderBundleEncoderDescriptor.by_ref], :pointer
376
+
377
+ attach_function :wgpuRenderBundleEncoderFinish,
378
+ [:pointer, :pointer], :pointer
379
+
380
+ attach_function :wgpuRenderBundleEncoderRelease,
381
+ [:pointer], :void
382
+
383
+ attach_function :wgpuRenderBundleRelease,
384
+ [:pointer], :void
385
+
386
+ attach_function :wgpuRenderBundleEncoderSetPipeline,
387
+ [:pointer, :pointer], :void
388
+
389
+ attach_function :wgpuRenderBundleEncoderSetBindGroup,
390
+ [:pointer, :uint32, :pointer, :size_t, :pointer], :void
391
+
392
+ attach_function :wgpuRenderBundleEncoderSetVertexBuffer,
393
+ [:pointer, :uint32, :pointer, :uint64, :uint64], :void
394
+
395
+ attach_function :wgpuRenderBundleEncoderSetIndexBuffer,
396
+ [:pointer, :pointer, IndexFormat, :uint64, :uint64], :void
397
+
398
+ attach_function :wgpuRenderBundleEncoderDraw,
399
+ [:pointer, :uint32, :uint32, :uint32, :uint32], :void
400
+
401
+ attach_function :wgpuRenderBundleEncoderDrawIndexed,
402
+ [:pointer, :uint32, :uint32, :uint32, :int32, :uint32], :void
403
+
404
+ attach_function :wgpuRenderBundleEncoderDrawIndirect,
405
+ [:pointer, :pointer, :uint64], :void
406
+
407
+ attach_function :wgpuRenderBundleEncoderDrawIndexedIndirect,
408
+ [:pointer, :pointer, :uint64], :void
409
+
410
+ attach_function :wgpuRenderBundleEncoderPushDebugGroup,
411
+ [:pointer, StringView.by_value], :void
412
+
413
+ attach_function :wgpuRenderBundleEncoderPopDebugGroup,
414
+ [:pointer], :void
415
+
416
+ attach_function :wgpuRenderBundleEncoderInsertDebugMarker,
417
+ [:pointer, StringView.by_value], :void
418
+ end
419
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ffi"
4
+ require "rbconfig"
5
+
6
+ module WGPU
7
+ module Native
8
+ extend FFI::Library
9
+
10
+ WGPU_VERSION = "v27.0.4.0"
11
+
12
+ class << self
13
+ def library_path
14
+ if ENV["WGPU_LIB_PATH"]
15
+ path = ENV["WGPU_LIB_PATH"]
16
+ raise LoadError, "WGPU_LIB_PATH points to non-existent file: #{path}" unless File.exist?(path)
17
+ return path
18
+ end
19
+
20
+ cached_path = File.join(cache_dir, "lib", library_name)
21
+ return cached_path if File.exist?(cached_path)
22
+
23
+ raise LoadError, <<~MSG
24
+ wgpu-native library not found.
25
+ Expected at: #{cached_path}
26
+
27
+ Try reinstalling the gem:
28
+ gem install wgpu
29
+
30
+ Or set WGPU_LIB_PATH environment variable to your custom wgpu-native build.
31
+ MSG
32
+ end
33
+
34
+ def cache_dir
35
+ File.join(Dir.home, ".cache", "wgpu-ruby", WGPU_VERSION)
36
+ end
37
+
38
+ def library_name
39
+ case host_os
40
+ when /linux/ then "libwgpu_native.so"
41
+ when /darwin/ then "libwgpu_native.dylib"
42
+ when /mingw|mswin/ then "wgpu_native.dll"
43
+ else raise LoadError, "Unsupported OS: #{host_os}"
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def host_os
50
+ RbConfig::CONFIG["host_os"]
51
+ end
52
+ end
53
+
54
+ ffi_lib library_path
55
+ end
56
+ end
57
+
58
+ require_relative "enums"
59
+ require_relative "structs"
60
+ require_relative "callbacks"
61
+ require_relative "functions"