react-native-wgpu 0.2.10 → 0.3.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 (248) hide show
  1. package/README.md +155 -69
  2. package/android/CMakeLists.txt +4 -5
  3. package/android/build.gradle +7 -18
  4. package/android/src/main/java/com/webgpu/WebGPUViewPackage.java +34 -10
  5. package/apple/MetalView.mm +0 -19
  6. package/apple/WebGPUModule.h +1 -9
  7. package/apple/WebGPUModule.mm +0 -3
  8. package/apple/WebGPUView.h +0 -3
  9. package/apple/WebGPUView.mm +0 -2
  10. package/cpp/WGPULogger.h +10 -0
  11. package/cpp/dawn/dawn_proc_table.h +1 -1
  12. package/cpp/dawn/webgpu.h +4855 -0
  13. package/cpp/dawn/webgpu_cpp.h +10168 -0
  14. package/cpp/dawn/wire/client/webgpu.h +354 -0
  15. package/cpp/dawn/wire/client/webgpu_cpp.h +10343 -0
  16. package/cpp/dawn/wire/client/webgpu_cpp_print.h +2715 -0
  17. package/cpp/jsi/RNFJSIConverter.h +17 -59
  18. package/cpp/rnwgpu/RNWebGPUManager.cpp +1 -9
  19. package/cpp/rnwgpu/api/GPU.cpp +51 -26
  20. package/cpp/rnwgpu/api/GPU.h +5 -18
  21. package/cpp/rnwgpu/api/GPUAdapter.cpp +75 -54
  22. package/cpp/rnwgpu/api/GPUAdapter.h +6 -6
  23. package/cpp/rnwgpu/api/GPUAdapterInfo.h +0 -1
  24. package/cpp/rnwgpu/api/GPUBindGroup.h +1 -3
  25. package/cpp/rnwgpu/api/GPUBindGroupLayout.h +1 -3
  26. package/cpp/rnwgpu/api/GPUBuffer.cpp +35 -32
  27. package/cpp/rnwgpu/api/GPUBuffer.h +9 -7
  28. package/cpp/rnwgpu/api/GPUCanvasContext.cpp +5 -1
  29. package/cpp/rnwgpu/api/GPUCanvasContext.h +0 -2
  30. package/cpp/rnwgpu/api/GPUCommandBuffer.h +1 -3
  31. package/cpp/rnwgpu/api/GPUCommandEncoder.h +1 -3
  32. package/cpp/rnwgpu/api/GPUCompilationInfo.h +0 -2
  33. package/cpp/rnwgpu/api/GPUCompilationMessage.h +1 -3
  34. package/cpp/rnwgpu/api/GPUComputePassEncoder.h +1 -3
  35. package/cpp/rnwgpu/api/GPUComputePipeline.h +1 -3
  36. package/cpp/rnwgpu/api/GPUDevice.cpp +183 -128
  37. package/cpp/rnwgpu/api/GPUDevice.h +22 -21
  38. package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +1 -3
  39. package/cpp/rnwgpu/api/GPUExternalTexture.h +1 -3
  40. package/cpp/rnwgpu/api/GPUPipelineLayout.h +1 -3
  41. package/cpp/rnwgpu/api/GPUQuerySet.h +1 -3
  42. package/cpp/rnwgpu/api/GPUQueue.cpp +19 -8
  43. package/cpp/rnwgpu/api/GPUQueue.h +7 -6
  44. package/cpp/rnwgpu/api/GPURenderBundle.h +1 -3
  45. package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +1 -3
  46. package/cpp/rnwgpu/api/GPURenderPassEncoder.h +1 -3
  47. package/cpp/rnwgpu/api/GPURenderPipeline.h +1 -3
  48. package/cpp/rnwgpu/api/GPUSampler.h +1 -3
  49. package/cpp/rnwgpu/api/GPUShaderModule.cpp +42 -28
  50. package/cpp/rnwgpu/api/GPUShaderModule.h +6 -6
  51. package/cpp/rnwgpu/api/GPUSupportedLimits.h +1 -3
  52. package/cpp/rnwgpu/api/GPUTexture.h +1 -3
  53. package/cpp/rnwgpu/api/GPUTextureView.h +1 -3
  54. package/cpp/rnwgpu/api/RNWebGPU.h +1 -7
  55. package/cpp/rnwgpu/async/AsyncDispatcher.h +28 -0
  56. package/cpp/rnwgpu/async/AsyncRunner.cpp +215 -0
  57. package/cpp/rnwgpu/async/AsyncRunner.h +53 -0
  58. package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +181 -0
  59. package/cpp/rnwgpu/async/AsyncTaskHandle.h +55 -0
  60. package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.cpp +23 -0
  61. package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.h +22 -0
  62. package/cpp/webgpu/webgpu.h +5 -4827
  63. package/cpp/webgpu/webgpu_cpp.h +5 -10140
  64. package/cpp/{dawn/native/WebGPUBackend.h → webgpu/webgpu_cpp_print.h} +4 -20
  65. package/lib/commonjs/Canvas.js +6 -66
  66. package/lib/commonjs/Canvas.js.map +1 -1
  67. package/lib/commonjs/hooks.js +6 -42
  68. package/lib/commonjs/hooks.js.map +1 -1
  69. package/lib/module/Canvas.js +7 -67
  70. package/lib/module/Canvas.js.map +1 -1
  71. package/lib/module/hooks.js +5 -40
  72. package/lib/module/hooks.js.map +1 -1
  73. package/lib/typescript/lib/commonjs/hooks.d.ts +1 -5
  74. package/lib/typescript/lib/commonjs/hooks.d.ts.map +1 -1
  75. package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
  76. package/lib/typescript/lib/module/hooks.d.ts +1 -5
  77. package/lib/typescript/lib/module/hooks.d.ts.map +1 -1
  78. package/lib/typescript/src/Canvas.d.ts +0 -1
  79. package/lib/typescript/src/Canvas.d.ts.map +1 -1
  80. package/lib/typescript/src/hooks.d.ts +2 -7
  81. package/lib/typescript/src/hooks.d.ts.map +1 -1
  82. package/libs/android/arm64-v8a/libwebgpu_dawn.so +0 -0
  83. package/libs/android/armeabi-v7a/libwebgpu_dawn.so +0 -0
  84. package/libs/android/x86/libwebgpu_dawn.so +0 -0
  85. package/libs/android/x86_64/libwebgpu_dawn.so +0 -0
  86. package/libs/apple/libwebgpu_dawn.xcframework/Info.plist +5 -35
  87. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/libwebgpu_dawn.a +0 -0
  88. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -0
  89. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/libwebgpu_dawn.a +0 -0
  90. package/package.json +4 -3
  91. package/react-native-wgpu.podspec +12 -16
  92. package/src/Canvas.tsx +8 -69
  93. package/src/hooks.tsx +14 -48
  94. package/android/cpp/platform/ThreadUtils.cpp +0 -41
  95. package/android/src/oldarch/com/webgpu/NativeWebGPUModuleSpec.java +0 -23
  96. package/android/src/oldarch/com/webgpu/WebGPUViewManagerSpec.java +0 -12
  97. package/apple/WebGPUViewManager.mm +0 -24
  98. package/apple/platform/ThreadUtils.cpp +0 -34
  99. package/cpp/dawn/dawn_proc.h +0 -50
  100. package/cpp/dawn/dawn_thread_dispatch_proc.h +0 -47
  101. package/cpp/dawn/native/D3D11Backend.h +0 -77
  102. package/cpp/dawn/native/D3D12Backend.h +0 -68
  103. package/cpp/dawn/native/D3DBackend.h +0 -56
  104. package/cpp/dawn/native/MetalBackend.h +0 -56
  105. package/cpp/dawn/platform/DawnPlatform.h +0 -167
  106. package/cpp/dawn/platform/dawn_platform_export.h +0 -49
  107. package/cpp/platform/ThreadUtils.h +0 -30
  108. package/cpp/rnwgpu/api/AsyncRunner.h +0 -30
  109. package/cpp/threading/CallInvokerDispatcher.h +0 -37
  110. package/cpp/threading/Dispatcher.cpp +0 -55
  111. package/cpp/threading/Dispatcher.h +0 -93
  112. package/cpp/threading/ThreadPool.cpp +0 -88
  113. package/cpp/threading/ThreadPool.h +0 -53
  114. package/cpp/webgpu/webgpu_glfw.h +0 -88
  115. package/lib/typescript/src/__tests__/Alpha.spec.d.ts +0 -2
  116. package/lib/typescript/src/__tests__/Alpha.spec.d.ts.map +0 -1
  117. package/lib/typescript/src/__tests__/ArrayBuffer.spec.d.ts +0 -2
  118. package/lib/typescript/src/__tests__/ArrayBuffer.spec.d.ts.map +0 -1
  119. package/lib/typescript/src/__tests__/Buffer.spec.d.ts +0 -2
  120. package/lib/typescript/src/__tests__/Buffer.spec.d.ts.map +0 -1
  121. package/lib/typescript/src/__tests__/ComputeShader.spec.d.ts +0 -2
  122. package/lib/typescript/src/__tests__/ComputeShader.spec.d.ts.map +0 -1
  123. package/lib/typescript/src/__tests__/Constants.spec.d.ts +0 -2
  124. package/lib/typescript/src/__tests__/Constants.spec.d.ts.map +0 -1
  125. package/lib/typescript/src/__tests__/Device.spec.d.ts +0 -2
  126. package/lib/typescript/src/__tests__/Device.spec.d.ts.map +0 -1
  127. package/lib/typescript/src/__tests__/ErrorScope.spec.d.ts +0 -2
  128. package/lib/typescript/src/__tests__/ErrorScope.spec.d.ts.map +0 -1
  129. package/lib/typescript/src/__tests__/ExternalTexture.spec.d.ts +0 -2
  130. package/lib/typescript/src/__tests__/ExternalTexture.spec.d.ts.map +0 -1
  131. package/lib/typescript/src/__tests__/GPU.spec.d.ts +0 -2
  132. package/lib/typescript/src/__tests__/GPU.spec.d.ts.map +0 -1
  133. package/lib/typescript/src/__tests__/ImageData.spec.d.ts +0 -2
  134. package/lib/typescript/src/__tests__/ImageData.spec.d.ts.map +0 -1
  135. package/lib/typescript/src/__tests__/Shaders.spec.d.ts +0 -2
  136. package/lib/typescript/src/__tests__/Shaders.spec.d.ts.map +0 -1
  137. package/lib/typescript/src/__tests__/Texture.spec.d.ts +0 -2
  138. package/lib/typescript/src/__tests__/Texture.spec.d.ts.map +0 -1
  139. package/lib/typescript/src/__tests__/components/Wireframe/Shaders.d.ts +0 -3
  140. package/lib/typescript/src/__tests__/components/Wireframe/Shaders.d.ts.map +0 -1
  141. package/lib/typescript/src/__tests__/components/Wireframe/models.d.ts +0 -29
  142. package/lib/typescript/src/__tests__/components/Wireframe/models.d.ts.map +0 -1
  143. package/lib/typescript/src/__tests__/components/Wireframe/utils.d.ts +0 -5
  144. package/lib/typescript/src/__tests__/components/Wireframe/utils.d.ts.map +0 -1
  145. package/lib/typescript/src/__tests__/components/cube.d.ts +0 -7
  146. package/lib/typescript/src/__tests__/components/cube.d.ts.map +0 -1
  147. package/lib/typescript/src/__tests__/components/meshes/mesh.d.ts +0 -22
  148. package/lib/typescript/src/__tests__/components/meshes/mesh.d.ts.map +0 -1
  149. package/lib/typescript/src/__tests__/components/meshes/sphere.d.ts +0 -12
  150. package/lib/typescript/src/__tests__/components/meshes/sphere.d.ts.map +0 -1
  151. package/lib/typescript/src/__tests__/components/meshes/stanfordDragon.d.ts +0 -7
  152. package/lib/typescript/src/__tests__/components/meshes/stanfordDragon.d.ts.map +0 -1
  153. package/lib/typescript/src/__tests__/components/meshes/stanfordDragonData.d.ts +0 -6
  154. package/lib/typescript/src/__tests__/components/meshes/stanfordDragonData.d.ts.map +0 -1
  155. package/lib/typescript/src/__tests__/components/meshes/teapot.d.ts +0 -6
  156. package/lib/typescript/src/__tests__/components/meshes/teapot.d.ts.map +0 -1
  157. package/lib/typescript/src/__tests__/components/meshes/utils.d.ts +0 -10
  158. package/lib/typescript/src/__tests__/components/meshes/utils.d.ts.map +0 -1
  159. package/lib/typescript/src/__tests__/components/triangle.d.ts +0 -3
  160. package/lib/typescript/src/__tests__/components/triangle.d.ts.map +0 -1
  161. package/lib/typescript/src/__tests__/config.d.ts +0 -3
  162. package/lib/typescript/src/__tests__/config.d.ts.map +0 -1
  163. package/lib/typescript/src/__tests__/demos/ABuffer.spec.d.ts +0 -2
  164. package/lib/typescript/src/__tests__/demos/ABuffer.spec.d.ts.map +0 -1
  165. package/lib/typescript/src/__tests__/demos/Blur.spec.d.ts +0 -2
  166. package/lib/typescript/src/__tests__/demos/Blur.spec.d.ts.map +0 -1
  167. package/lib/typescript/src/__tests__/demos/Cube.spec.d.ts +0 -2
  168. package/lib/typescript/src/__tests__/demos/Cube.spec.d.ts.map +0 -1
  169. package/lib/typescript/src/__tests__/demos/FractalCube.spec.d.ts +0 -2
  170. package/lib/typescript/src/__tests__/demos/FractalCube.spec.d.ts.map +0 -1
  171. package/lib/typescript/src/__tests__/demos/OcclusionQuery.spec.d.ts +0 -2
  172. package/lib/typescript/src/__tests__/demos/OcclusionQuery.spec.d.ts.map +0 -1
  173. package/lib/typescript/src/__tests__/demos/RenderBundles.spec.d.ts +0 -2
  174. package/lib/typescript/src/__tests__/demos/RenderBundles.spec.d.ts.map +0 -1
  175. package/lib/typescript/src/__tests__/demos/Triangle.spec.d.ts +0 -2
  176. package/lib/typescript/src/__tests__/demos/Triangle.spec.d.ts.map +0 -1
  177. package/lib/typescript/src/__tests__/demos/Wireframe.spec.d.ts +0 -2
  178. package/lib/typescript/src/__tests__/demos/Wireframe.spec.d.ts.map +0 -1
  179. package/lib/typescript/src/__tests__/globalSetup.d.ts +0 -3
  180. package/lib/typescript/src/__tests__/globalSetup.d.ts.map +0 -1
  181. package/lib/typescript/src/__tests__/globalTeardown.d.ts +0 -3
  182. package/lib/typescript/src/__tests__/globalTeardown.d.ts.map +0 -1
  183. package/lib/typescript/src/__tests__/setup.d.ts +0 -63
  184. package/lib/typescript/src/__tests__/setup.d.ts.map +0 -1
  185. package/libs/apple/arm64_iphoneos/libwebgpu_dawn.a +0 -0
  186. package/libs/apple/arm64_iphonesimulator/libwebgpu_dawn.a +0 -0
  187. package/libs/apple/arm64_xros/libwebgpu_dawn.a +0 -0
  188. package/libs/apple/arm64_xrsimulator/libwebgpu_dawn.a +0 -0
  189. package/libs/apple/iphonesimulator/libwebgpu_dawn.a +0 -0
  190. package/libs/apple/libwebgpu_dawn.xcframework/xros-arm64/libwebgpu_dawn.a +0 -0
  191. package/libs/apple/libwebgpu_dawn.xcframework/xros-arm64-simulator/libwebgpu_dawn.a +0 -0
  192. package/libs/apple/universal_macosx/libwebgpu_dawn.a +0 -0
  193. package/libs/apple/x86_64_iphonesimulator/libwebgpu_dawn.a +0 -0
  194. package/libs/dawn.json +0 -4670
  195. package/src/__tests__/Alpha.spec.ts +0 -28
  196. package/src/__tests__/ArrayBuffer.spec.ts +0 -76
  197. package/src/__tests__/Buffer.spec.ts +0 -357
  198. package/src/__tests__/ComputeShader.spec.ts +0 -375
  199. package/src/__tests__/Constants.spec.ts +0 -89
  200. package/src/__tests__/Device.spec.ts +0 -84
  201. package/src/__tests__/ErrorScope.spec.ts +0 -92
  202. package/src/__tests__/ExternalTexture.spec.ts +0 -284
  203. package/src/__tests__/GPU.spec.ts +0 -272
  204. package/src/__tests__/ImageData.spec.ts +0 -26
  205. package/src/__tests__/Shaders.spec.ts +0 -232
  206. package/src/__tests__/Texture.spec.ts +0 -197
  207. package/src/__tests__/assets/Di-3d.png +0 -0
  208. package/src/__tests__/components/Wireframe/Shaders.ts +0 -138
  209. package/src/__tests__/components/Wireframe/models.ts +0 -113
  210. package/src/__tests__/components/Wireframe/utils.ts +0 -22
  211. package/src/__tests__/components/cube.ts +0 -51
  212. package/src/__tests__/components/meshes/mesh.ts +0 -96
  213. package/src/__tests__/components/meshes/sphere.ts +0 -103
  214. package/src/__tests__/components/meshes/stanfordDragon.ts +0 -44
  215. package/src/__tests__/components/meshes/stanfordDragonData.ts +0 -5
  216. package/src/__tests__/components/meshes/teapot.ts +0 -13
  217. package/src/__tests__/components/meshes/utils.ts +0 -235
  218. package/src/__tests__/components/triangle.ts +0 -17
  219. package/src/__tests__/config.ts +0 -2
  220. package/src/__tests__/demos/ABuffer.spec.ts +0 -890
  221. package/src/__tests__/demos/Blur.spec.ts +0 -398
  222. package/src/__tests__/demos/Cube.spec.ts +0 -929
  223. package/src/__tests__/demos/FractalCube.spec.ts +0 -240
  224. package/src/__tests__/demos/OcclusionQuery.spec.ts +0 -376
  225. package/src/__tests__/demos/RenderBundles.spec.ts +0 -580
  226. package/src/__tests__/demos/Triangle.spec.ts +0 -266
  227. package/src/__tests__/demos/Wireframe.spec.ts +0 -188
  228. package/src/__tests__/globalSetup.ts +0 -45
  229. package/src/__tests__/globalTeardown.ts +0 -11
  230. package/src/__tests__/setup.ts +0 -423
  231. package/src/__tests__/snapshots/abuffer.png +0 -0
  232. package/src/__tests__/snapshots/asteroid.png +0 -0
  233. package/src/__tests__/snapshots/blur.png +0 -0
  234. package/src/__tests__/snapshots/buffer.png +0 -0
  235. package/src/__tests__/snapshots/constant-triangle.png +0 -0
  236. package/src/__tests__/snapshots/cube.png +0 -0
  237. package/src/__tests__/snapshots/f.png +0 -0
  238. package/src/__tests__/snapshots/f2.png +0 -0
  239. package/src/__tests__/snapshots/fractal-cubes.png +0 -0
  240. package/src/__tests__/snapshots/instanced-cubes.png +0 -0
  241. package/src/__tests__/snapshots/occlusion-query.png +0 -0
  242. package/src/__tests__/snapshots/ref.png +0 -0
  243. package/src/__tests__/snapshots/semi-opaque-cyan.png +0 -0
  244. package/src/__tests__/snapshots/texture.png +0 -0
  245. package/src/__tests__/snapshots/textured-cube.png +0 -0
  246. package/src/__tests__/snapshots/triangle-msaa.png +0 -0
  247. package/src/__tests__/snapshots/triangle.png +0 -0
  248. package/src/__tests__/snapshots/two-cube.png +0 -0
@@ -1,266 +0,0 @@
1
- import { checkImage, client, encodeImage } from "../setup";
2
-
3
- describe("Triangle", () => {
4
- it("Simple Triangle", async () => {
5
- const result = await client.eval(
6
- ({
7
- device,
8
- shaders: { triangleVertWGSL, redFragWGSL },
9
- gpu,
10
- ctx,
11
- canvas,
12
- }) => {
13
- const pipeline = device.createRenderPipeline({
14
- layout: "auto",
15
- vertex: {
16
- module: device.createShaderModule({
17
- code: triangleVertWGSL,
18
- }),
19
- },
20
- fragment: {
21
- module: device.createShaderModule({
22
- code: redFragWGSL,
23
- }),
24
- targets: [
25
- {
26
- format: gpu.getPreferredCanvasFormat(),
27
- },
28
- ],
29
- },
30
- primitive: {
31
- topology: "triangle-list",
32
- },
33
- });
34
-
35
- const commandEncoder = device.createCommandEncoder();
36
- const textureView = ctx.getCurrentTexture().createView();
37
-
38
- const renderPassDescriptor: GPURenderPassDescriptor = {
39
- colorAttachments: [
40
- {
41
- view: textureView,
42
- clearValue: [0.3, 0.6, 1, 1],
43
- loadOp: "clear",
44
- storeOp: "store",
45
- },
46
- ],
47
- };
48
-
49
- const passEncoder =
50
- commandEncoder.beginRenderPass(renderPassDescriptor);
51
- passEncoder.setPipeline(pipeline);
52
- passEncoder.draw(3);
53
- passEncoder.end();
54
- device.queue.submit([commandEncoder.finish()]);
55
- return canvas.getImageData();
56
- },
57
- );
58
- const image = encodeImage(result);
59
- checkImage(image, "snapshots/triangle.png");
60
- });
61
- it("Async Simple Triangle", async () => {
62
- const result = await client.eval(
63
- ({
64
- device,
65
- shaders: { triangleVertWGSL, redFragWGSL },
66
- gpu,
67
- ctx,
68
- canvas,
69
- }) => {
70
- return device
71
- .createRenderPipelineAsync({
72
- layout: "auto",
73
- vertex: {
74
- module: device.createShaderModule({
75
- code: triangleVertWGSL,
76
- }),
77
- },
78
- fragment: {
79
- module: device.createShaderModule({
80
- code: redFragWGSL,
81
- }),
82
- targets: [
83
- {
84
- format: gpu.getPreferredCanvasFormat(),
85
- },
86
- ],
87
- },
88
- primitive: {
89
- topology: "triangle-list",
90
- },
91
- })
92
- .then((pipeline) => {
93
- const commandEncoder = device.createCommandEncoder();
94
- const textureView = ctx.getCurrentTexture().createView();
95
-
96
- const renderPassDescriptor: GPURenderPassDescriptor = {
97
- colorAttachments: [
98
- {
99
- view: textureView,
100
- clearValue: [0.3, 0.6, 1, 1],
101
- loadOp: "clear",
102
- storeOp: "store",
103
- },
104
- ],
105
- };
106
-
107
- const passEncoder =
108
- commandEncoder.beginRenderPass(renderPassDescriptor);
109
- passEncoder.setPipeline(pipeline);
110
- passEncoder.draw(3);
111
- passEncoder.end();
112
- device.queue.submit([commandEncoder.finish()]);
113
- return canvas.getImageData();
114
- });
115
- },
116
- );
117
- const image = encodeImage(result);
118
- checkImage(image, "snapshots/triangle.png");
119
- });
120
- it("Triangle MSAA", async () => {
121
- const result = await client.eval(
122
- ({
123
- device,
124
- shaders: { triangleVertWGSL, redFragWGSL },
125
- gpu,
126
- ctx,
127
- canvas,
128
- }) => {
129
- const sampleCount = 4;
130
- const presentationFormat = gpu.getPreferredCanvasFormat();
131
- const pipeline = device.createRenderPipeline({
132
- layout: "auto",
133
- vertex: {
134
- module: device.createShaderModule({
135
- code: triangleVertWGSL,
136
- }),
137
- },
138
- fragment: {
139
- module: device.createShaderModule({
140
- code: redFragWGSL,
141
- }),
142
- targets: [
143
- {
144
- format: presentationFormat,
145
- },
146
- ],
147
- },
148
- primitive: {
149
- topology: "triangle-list",
150
- },
151
- multisample: {
152
- count: sampleCount,
153
- },
154
- });
155
-
156
- const texture = device.createTexture({
157
- size: [ctx.canvas.width, ctx.canvas.height],
158
- sampleCount,
159
- format: presentationFormat,
160
- usage: GPUTextureUsage.RENDER_ATTACHMENT,
161
- });
162
- const view = texture.createView();
163
-
164
- const commandEncoder = device.createCommandEncoder();
165
-
166
- const renderPassDescriptor: GPURenderPassDescriptor = {
167
- colorAttachments: [
168
- {
169
- view,
170
- resolveTarget: ctx.getCurrentTexture().createView(),
171
- clearValue: [0, 0, 0, 1],
172
- loadOp: "clear",
173
- storeOp: "discard",
174
- },
175
- ],
176
- };
177
-
178
- const passEncoder =
179
- commandEncoder.beginRenderPass(renderPassDescriptor);
180
- passEncoder.setPipeline(pipeline);
181
- passEncoder.draw(3);
182
- passEncoder.end();
183
- device.queue.submit([commandEncoder.finish()]);
184
- return canvas.getImageData();
185
- },
186
- );
187
- const image = encodeImage(result);
188
- checkImage(image, "snapshots/triangle-msaa.png");
189
- });
190
- it("Triangle with constants", async () => {
191
- const result = await client.eval(
192
- ({ device, shaders: { triangleVertWGSL }, gpu, ctx, canvas }) => {
193
- const pipeline = device.createRenderPipeline({
194
- layout: "auto",
195
- vertex: {
196
- module: device.createShaderModule({
197
- code: triangleVertWGSL,
198
- }),
199
- },
200
- fragment: {
201
- module: device.createShaderModule({
202
- code: `
203
- @vertex fn vs(
204
- @builtin(vertex_index) vertexIndex : u32
205
- ) -> @builtin(position) vec4f {
206
- let pos = array(
207
- vec2f( 0.0, 0.5), // top center
208
- vec2f(-0.5, -0.5), // bottom left
209
- vec2f( 0.5, -0.5) // bottom right
210
- );
211
-
212
- return vec4f(pos[vertexIndex], 0.0, 1.0);
213
- }
214
-
215
- override red = 0.0;
216
- override green = 0.0;
217
- override blue = 0.0;
218
-
219
- @fragment fn fs() -> @location(0) vec4f {
220
- return vec4f(red, green, blue, 1.0);
221
- }
222
- `,
223
- }),
224
- targets: [
225
- {
226
- format: gpu.getPreferredCanvasFormat(),
227
- },
228
- ],
229
- constants: {
230
- red: 1,
231
- green: 0.5,
232
- blue: 1,
233
- },
234
- },
235
- primitive: {
236
- topology: "triangle-list",
237
- },
238
- });
239
-
240
- const commandEncoder = device.createCommandEncoder();
241
- const textureView = ctx.getCurrentTexture().createView();
242
-
243
- const renderPassDescriptor: GPURenderPassDescriptor = {
244
- colorAttachments: [
245
- {
246
- view: textureView,
247
- clearValue: [0.3, 0.6, 1, 1],
248
- loadOp: "clear",
249
- storeOp: "store",
250
- },
251
- ],
252
- };
253
-
254
- const passEncoder =
255
- commandEncoder.beginRenderPass(renderPassDescriptor);
256
- passEncoder.setPipeline(pipeline);
257
- passEncoder.draw(3);
258
- passEncoder.end();
259
- device.queue.submit([commandEncoder.finish()]);
260
- return canvas.getImageData();
261
- },
262
- );
263
- const image = encodeImage(result);
264
- checkImage(image, "snapshots/constant-triangle.png");
265
- });
266
- });
@@ -1,188 +0,0 @@
1
- /* eslint-disable @typescript-eslint/ban-ts-comment */
2
- import { modelData as model } from "../components/Wireframe/models";
3
- import {
4
- solidColorLitWGSL as solidColorLit,
5
- wireframeWGSL as wireframe,
6
- } from "../components/Wireframe/Shaders";
7
- import { client } from "../setup";
8
-
9
- type Model = {
10
- vertexBuffer: GPUBuffer;
11
- indexBuffer: GPUBuffer;
12
- indexFormat: GPUIndexFormat;
13
- vertexCount: number;
14
- };
15
-
16
- type ModelData = Record<
17
- string,
18
- { vertices: Float32Array; indices: Uint32Array }
19
- >;
20
-
21
- type SerializedModelData = Record<
22
- string,
23
- { vertices: number[]; indices: number[] }
24
- >;
25
-
26
- const serializeModelData = (m: ModelData): SerializedModelData => {
27
- const serialized: SerializedModelData = {};
28
- for (const [key, value] of Object.entries(m)) {
29
- serialized[key] = {
30
- vertices: Array.from(value.vertices),
31
- indices: Array.from(value.indices),
32
- };
33
- }
34
- return serialized;
35
- };
36
-
37
- describe("Wireframe", () => {
38
- it("draw scene", async () => {
39
- const result = await client.eval(
40
- ({ device, gpu, serializedData, solidColorLitWGSL, wireframeWGSL }) => {
41
- const parseModelData = (m: SerializedModelData): ModelData => {
42
- const parsed: ModelData = {};
43
- for (const entry of Object.entries(m)) {
44
- parsed[entry[0]] = {
45
- vertices: new Float32Array(entry[1].vertices),
46
- indices: new Uint32Array(entry[1].indices),
47
- };
48
- }
49
- return parsed;
50
- };
51
-
52
- const modelData = parseModelData(serializedData);
53
- const settings = {
54
- barycentricCoordinatesBased: false,
55
- thickness: 2,
56
- alphaThreshold: 0.5,
57
- animate: true,
58
- lines: true,
59
- depthBias: 1,
60
- depthBiasSlopeScale: 0.5,
61
- models: true,
62
- };
63
- function createBufferWithData(
64
- // eslint-disable-next-line @typescript-eslint/no-shadow
65
- device: GPUDevice,
66
- data: Float32Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>,
67
- usage: GPUBufferUsageFlags,
68
- ) {
69
- const buffer = device.createBuffer({
70
- size: data.byteLength,
71
- usage,
72
- });
73
- device.queue.writeBuffer(buffer, 0, data.buffer);
74
- return buffer;
75
- }
76
-
77
- function createVertexAndIndexBuffer(
78
- // eslint-disable-next-line @typescript-eslint/no-shadow
79
- device: GPUDevice,
80
- {
81
- vertices,
82
- indices,
83
- }: { vertices: Float32Array; indices: Uint32Array },
84
- ): Model {
85
- const vertexBuffer = createBufferWithData(
86
- device,
87
- vertices,
88
- GPUBufferUsage.VERTEX |
89
- GPUBufferUsage.STORAGE |
90
- GPUBufferUsage.COPY_DST,
91
- );
92
- const indexBuffer = createBufferWithData(
93
- device,
94
- indices,
95
- GPUBufferUsage.INDEX |
96
- GPUBufferUsage.STORAGE |
97
- GPUBufferUsage.COPY_DST,
98
- );
99
- return {
100
- vertexBuffer,
101
- indexBuffer,
102
- indexFormat: "uint32",
103
- vertexCount: indices.length,
104
- };
105
- }
106
-
107
- const presentationFormat = gpu.getPreferredCanvasFormat();
108
- const depthFormat = "depth24plus";
109
- // @ts-ignore
110
- const models = Object.values(modelData).map((data) =>
111
- createVertexAndIndexBuffer(device, data),
112
- );
113
- const litModule = device.createShaderModule({
114
- code: solidColorLitWGSL,
115
- });
116
- // @ts-ignore
117
- const wireframeModule = device.createShaderModule({
118
- code: wireframeWGSL,
119
- });
120
- const litBindGroupLayout = device.createBindGroupLayout({
121
- label: "lit bind group layout",
122
- entries: [
123
- {
124
- binding: 0,
125
- visibility: GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT,
126
- buffer: {},
127
- },
128
- ],
129
- });
130
- const litPipeline = device.createRenderPipeline({
131
- label: "lit pipeline",
132
- layout: device.createPipelineLayout({
133
- bindGroupLayouts: [litBindGroupLayout],
134
- }),
135
- vertex: {
136
- module: litModule,
137
- buffers: [
138
- {
139
- arrayStride: 6 * 4, // position, normal
140
- attributes: [
141
- {
142
- // position
143
- shaderLocation: 0,
144
- offset: 0,
145
- format: "float32x3",
146
- },
147
- {
148
- // normal
149
- shaderLocation: 1,
150
- offset: 3 * 4,
151
- format: "float32x3",
152
- },
153
- ],
154
- },
155
- ],
156
- },
157
- fragment: {
158
- module: litModule,
159
- targets: [{ format: presentationFormat }],
160
- },
161
- primitive: {
162
- cullMode: "back",
163
- },
164
- depthStencil: {
165
- depthWriteEnabled: true,
166
- depthCompare: "less",
167
- // Applying a depth bias can prevent aliasing from z-fighting with the
168
- // wireframe lines. The depth bias has to be applied to the lit meshes
169
- // rather that the wireframe because depthBias isn't considered when
170
- // drawing line or point primitives.
171
- depthBias: settings.depthBias,
172
- depthBiasSlopeScale: settings.depthBiasSlopeScale,
173
- format: depthFormat,
174
- },
175
- });
176
- return litPipeline.label;
177
- },
178
- {
179
- serializedData: serializeModelData(model),
180
- solidColorLitWGSL: solidColorLit,
181
- wireframeWGSL: wireframe,
182
- },
183
- );
184
- expect(result).toBe("lit pipeline");
185
- // const image = encodeImage(result);
186
- // checkImage(image, "snapshots/wireframe.png");
187
- });
188
- });
@@ -1,45 +0,0 @@
1
- import { WebSocketServer } from "ws";
2
-
3
- import { REFERENCE } from "./config";
4
-
5
- const isOS = (os: string): os is "android" | "ios" | "web" => {
6
- return ["ios", "android", "web"].indexOf(os) !== -1;
7
- };
8
-
9
- const isArch = (arc: string): arc is "paper" | "fabric" => {
10
- return ["paper", "fabric"].indexOf(arc) !== -1;
11
- };
12
-
13
- const globalSetup = () => {
14
- return new Promise<void>((resolve) => {
15
- if (REFERENCE) {
16
- resolve();
17
- return;
18
- }
19
- const port = 4242;
20
- global.testServer = new WebSocketServer({ port });
21
- console.log(
22
- `\n\nTest server listening on port ${port} (waiting for the example app to open on E2E tests screen)`,
23
- );
24
- global.testServer.on("connection", (client) => {
25
- global.testClient = client;
26
- client.once("message", (msg) => {
27
- const obj = JSON.parse(msg.toString("utf8"));
28
- const { OS, arch } = obj;
29
- if (!isOS(OS)) {
30
- throw new Error("Unknown testing platform: " + OS);
31
- }
32
- if (!isArch(arch)) {
33
- throw new Error("Unknown testing architecture: " + arch);
34
- }
35
- global.testOS = OS;
36
- global.testArch = arch;
37
- console.log(`${OS} device connected (${arch})`);
38
- resolve();
39
- });
40
- });
41
- });
42
- };
43
-
44
- // eslint-disable-next-line import/no-default-export
45
- export default globalSetup;
@@ -1,11 +0,0 @@
1
- const globalTeardown = () => {
2
- if (global.testClient) {
3
- global.testClient.close();
4
- }
5
- if (global.testServer) {
6
- global.testServer.close();
7
- }
8
- };
9
-
10
- // eslint-disable-next-line import/no-default-export
11
- export default globalTeardown;