@nativescript/canvas 2.0.0-beta.9 → 2.0.0-webgpu.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 (285) hide show
  1. package/Canvas/common.d.ts +23 -15
  2. package/Canvas/common.js +125 -56
  3. package/Canvas/common.js.map +1 -1
  4. package/Canvas/index.android.d.ts +5 -7
  5. package/Canvas/index.android.js +61 -133
  6. package/Canvas/index.android.js.map +1 -1
  7. package/Canvas/index.d.ts +4 -1
  8. package/Canvas/index.ios.d.ts +4 -5
  9. package/Canvas/index.ios.js +72 -82
  10. package/Canvas/index.ios.js.map +1 -1
  11. package/Canvas2D/CanvasRenderingContext2D/index.d.ts +1 -1
  12. package/Canvas2D/CanvasRenderingContext2D/index.js +8 -11
  13. package/Canvas2D/CanvasRenderingContext2D/index.js.map +1 -1
  14. package/Canvas2D/DOMMatrix/index.d.ts +14 -0
  15. package/Canvas2D/DOMMatrix/index.js +62 -0
  16. package/Canvas2D/DOMMatrix/index.js.map +1 -1
  17. package/Canvas2D/ImageData/index.js +4 -6
  18. package/Canvas2D/ImageData/index.js.map +1 -1
  19. package/ImageAsset/index.d.ts +1 -0
  20. package/ImageAsset/index.js +49 -0
  21. package/ImageAsset/index.js.map +1 -1
  22. package/WebGL/WebGLRenderingContext/index.d.ts +1 -0
  23. package/WebGL/WebGLRenderingContext/index.js +86 -32
  24. package/WebGL/WebGLRenderingContext/index.js.map +1 -1
  25. package/WebGL2/WebGL2RenderingContext/index.d.ts +1 -0
  26. package/WebGL2/WebGL2RenderingContext/index.js +2 -3
  27. package/WebGL2/WebGL2RenderingContext/index.js.map +1 -1
  28. package/WebGPU/Constants.d.ts +36 -0
  29. package/WebGPU/Constants.js +42 -0
  30. package/WebGPU/Constants.js.map +1 -0
  31. package/WebGPU/Errors.d.ts +18 -0
  32. package/WebGPU/Errors.js +21 -0
  33. package/WebGPU/Errors.js.map +1 -0
  34. package/WebGPU/GPU.d.ts +13 -0
  35. package/WebGPU/GPU.js +35 -0
  36. package/WebGPU/GPU.js.map +1 -0
  37. package/WebGPU/GPUAdapter.d.ts +23 -0
  38. package/WebGPU/GPUAdapter.js +62 -0
  39. package/WebGPU/GPUAdapter.js.map +1 -0
  40. package/WebGPU/GPUAdapterInfo.d.ts +9 -0
  41. package/WebGPU/GPUAdapterInfo.js +24 -0
  42. package/WebGPU/GPUAdapterInfo.js.map +1 -0
  43. package/WebGPU/GPUBindGroup.d.ts +5 -0
  44. package/WebGPU/GPUBindGroup.js +12 -0
  45. package/WebGPU/GPUBindGroup.js.map +1 -0
  46. package/WebGPU/GPUBindGroupLayout.d.ts +5 -0
  47. package/WebGPU/GPUBindGroupLayout.js +12 -0
  48. package/WebGPU/GPUBindGroupLayout.js.map +1 -0
  49. package/WebGPU/GPUBuffer.d.ts +15 -0
  50. package/WebGPU/GPUBuffer.js +54 -0
  51. package/WebGPU/GPUBuffer.js.map +1 -0
  52. package/WebGPU/GPUCanvasContext.d.ts +33 -0
  53. package/WebGPU/GPUCanvasContext.js +67 -0
  54. package/WebGPU/GPUCanvasContext.js.map +1 -0
  55. package/WebGPU/GPUCommandBuffer.d.ts +5 -0
  56. package/WebGPU/GPUCommandBuffer.js +12 -0
  57. package/WebGPU/GPUCommandBuffer.js.map +1 -0
  58. package/WebGPU/GPUCommandEncoder.d.ts +41 -0
  59. package/WebGPU/GPUCommandEncoder.js +105 -0
  60. package/WebGPU/GPUCommandEncoder.js.map +1 -0
  61. package/WebGPU/GPUComputePassEncoder.d.ts +16 -0
  62. package/WebGPU/GPUComputePassEncoder.js +50 -0
  63. package/WebGPU/GPUComputePassEncoder.js.map +1 -0
  64. package/WebGPU/GPUComputePipeline.d.ts +7 -0
  65. package/WebGPU/GPUComputePipeline.js +16 -0
  66. package/WebGPU/GPUComputePipeline.js.map +1 -0
  67. package/WebGPU/GPUDevice.d.ts +173 -0
  68. package/WebGPU/GPUDevice.js +381 -0
  69. package/WebGPU/GPUDevice.js.map +1 -0
  70. package/WebGPU/GPUDeviceLostInfo.d.ts +1 -0
  71. package/WebGPU/GPUDeviceLostInfo.js +10 -0
  72. package/WebGPU/GPUDeviceLostInfo.js.map +1 -0
  73. package/WebGPU/GPUExternalTexture.d.ts +5 -0
  74. package/WebGPU/GPUExternalTexture.js +12 -0
  75. package/WebGPU/GPUExternalTexture.js.map +1 -0
  76. package/WebGPU/GPUPipelineLayout.d.ts +5 -0
  77. package/WebGPU/GPUPipelineLayout.js +12 -0
  78. package/WebGPU/GPUPipelineLayout.js.map +1 -0
  79. package/WebGPU/GPUQuerySet.d.ts +5 -0
  80. package/WebGPU/GPUQuerySet.js +12 -0
  81. package/WebGPU/GPUQuerySet.js.map +1 -0
  82. package/WebGPU/GPUQueue.d.ts +14 -0
  83. package/WebGPU/GPUQueue.js +77 -0
  84. package/WebGPU/GPUQueue.js.map +1 -0
  85. package/WebGPU/GPURenderBundle.d.ts +5 -0
  86. package/WebGPU/GPURenderBundle.js +12 -0
  87. package/WebGPU/GPURenderBundle.js.map +1 -0
  88. package/WebGPU/GPURenderBundleEncoder.d.ts +20 -0
  89. package/WebGPU/GPURenderBundleEncoder.js +61 -0
  90. package/WebGPU/GPURenderBundleEncoder.js.map +1 -0
  91. package/WebGPU/GPURenderPassEncoder.d.ts +29 -0
  92. package/WebGPU/GPURenderPassEncoder.js +94 -0
  93. package/WebGPU/GPURenderPassEncoder.js.map +1 -0
  94. package/WebGPU/GPURenderPipeline.d.ts +7 -0
  95. package/WebGPU/GPURenderPipeline.js +16 -0
  96. package/WebGPU/GPURenderPipeline.js.map +1 -0
  97. package/WebGPU/GPUSampler.d.ts +5 -0
  98. package/WebGPU/GPUSampler.js +12 -0
  99. package/WebGPU/GPUSampler.js.map +1 -0
  100. package/WebGPU/GPUShaderModule.d.ts +6 -0
  101. package/WebGPU/GPUShaderModule.js +15 -0
  102. package/WebGPU/GPUShaderModule.js.map +1 -0
  103. package/WebGPU/GPUTexture.d.ts +16 -0
  104. package/WebGPU/GPUTexture.js +41 -0
  105. package/WebGPU/GPUTexture.js.map +1 -0
  106. package/WebGPU/GPUTextureView.d.ts +5 -0
  107. package/WebGPU/GPUTextureView.js +12 -0
  108. package/WebGPU/GPUTextureView.js.map +1 -0
  109. package/WebGPU/Interfaces.d.ts +155 -0
  110. package/WebGPU/Interfaces.js +2 -0
  111. package/WebGPU/Interfaces.js.map +1 -0
  112. package/WebGPU/Types.d.ts +39 -0
  113. package/WebGPU/Types.js +2 -0
  114. package/WebGPU/Types.js.map +1 -0
  115. package/WebGPU/Utils.d.ts +1 -0
  116. package/WebGPU/Utils.js +75 -0
  117. package/WebGPU/Utils.js.map +1 -0
  118. package/WebGPU/index.d.ts +28 -0
  119. package/WebGPU/index.js +29 -0
  120. package/WebGPU/index.js.map +1 -0
  121. package/index.d.ts +1 -1
  122. package/index.js +22 -1
  123. package/index.js.map +1 -1
  124. package/package.json +1 -4
  125. package/platforms/android/canvas-release.aar +0 -0
  126. package/platforms/ios/CanvasNative.xcframework/Info.plist +5 -5
  127. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative +0 -0
  128. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative-Swift.h +23 -23
  129. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_ios.h +41 -8
  130. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h +2280 -103
  131. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Info.plist +0 -0
  132. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios.swiftsourceinfo +0 -0
  133. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.abi.json +1563 -3729
  134. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.private.swiftinterface +27 -34
  135. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  136. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftinterface +27 -34
  137. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  138. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +602 -663
  139. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative +0 -0
  140. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative-Swift.h +46 -46
  141. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_ios.h +41 -8
  142. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h +2280 -103
  143. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Info.plist +0 -0
  144. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo +0 -0
  145. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/x86_64-apple-ios-simulator.swiftsourceinfo +0 -0
  146. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.abi.json +1563 -3729
  147. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +27 -34
  148. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  149. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftinterface +27 -34
  150. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.abi.json +1563 -3729
  151. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +27 -34
  152. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  153. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +27 -34
  154. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources +31 -31
  155. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  156. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +604 -662
  157. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/x86_64/CanvasNative.yml +638 -641
  158. package/platforms/ios/build.xcconfig +3 -1
  159. package/platforms/ios/src/cpp/Caches.h +69 -1
  160. package/platforms/ios/src/cpp/CanvasJSIModule.cpp +320 -395
  161. package/platforms/ios/src/cpp/CanvasJSIModule.h +7 -1
  162. package/platforms/ios/src/cpp/Helpers.h +43 -8
  163. package/platforms/ios/src/cpp/ImageAssetImpl.cpp +35 -37
  164. package/platforms/ios/src/cpp/ImageAssetImpl.h +14 -10
  165. package/platforms/ios/src/cpp/ImageBitmapImpl.cpp +2 -2
  166. package/platforms/ios/src/cpp/ImageBitmapImpl.h +1 -1
  167. package/platforms/ios/src/cpp/canvas2d/CanvasPattern.cpp +0 -10
  168. package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.cpp +41 -4
  169. package/platforms/ios/src/cpp/canvas2d/MatrixImpl.cpp +409 -3
  170. package/platforms/ios/src/cpp/canvas2d/MatrixImpl.h +27 -0
  171. package/platforms/ios/src/cpp/webgl/WebGLRenderingContext.cpp +131 -149
  172. package/platforms/ios/src/cpp/webgl2/WebGL2RenderingContext.cpp +1766 -1659
  173. package/platforms/ios/src/cpp/webgpu/GPUAdapterImpl.cpp +302 -0
  174. package/platforms/ios/src/cpp/webgpu/GPUAdapterImpl.h +63 -0
  175. package/platforms/ios/src/cpp/webgpu/GPUAdapterInfoImpl.cpp +174 -0
  176. package/platforms/ios/src/cpp/webgpu/GPUAdapterInfoImpl.h +58 -0
  177. package/platforms/ios/src/cpp/webgpu/GPUBindGroupImpl.cpp +53 -0
  178. package/platforms/ios/src/cpp/webgpu/GPUBindGroupImpl.h +45 -0
  179. package/platforms/ios/src/cpp/webgpu/GPUBindGroupLayoutImpl.cpp +53 -0
  180. package/platforms/ios/src/cpp/webgpu/GPUBindGroupLayoutImpl.h +45 -0
  181. package/platforms/ios/src/cpp/webgpu/GPUBufferImpl.cpp +229 -0
  182. package/platforms/ios/src/cpp/webgpu/GPUBufferImpl.h +59 -0
  183. package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.cpp +317 -0
  184. package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.h +55 -0
  185. package/platforms/ios/src/cpp/webgpu/GPUCommandBufferImpl.cpp +54 -0
  186. package/platforms/ios/src/cpp/webgpu/GPUCommandBufferImpl.h +45 -0
  187. package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.cpp +1087 -0
  188. package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.h +69 -0
  189. package/platforms/ios/src/cpp/webgpu/GPUComputePassEncoderImpl.cpp +260 -0
  190. package/platforms/ios/src/cpp/webgpu/GPUComputePassEncoderImpl.h +62 -0
  191. package/platforms/ios/src/cpp/webgpu/GPUComputePipelineImpl.cpp +84 -0
  192. package/platforms/ios/src/cpp/webgpu/GPUComputePipelineImpl.h +49 -0
  193. package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.cpp +2741 -0
  194. package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.h +95 -0
  195. package/platforms/ios/src/cpp/webgpu/GPUImpl.cpp +186 -0
  196. package/platforms/ios/src/cpp/webgpu/GPUImpl.h +55 -0
  197. package/platforms/ios/src/cpp/webgpu/GPUPipelineLayoutImpl.cpp +54 -0
  198. package/platforms/ios/src/cpp/webgpu/GPUPipelineLayoutImpl.h +46 -0
  199. package/platforms/ios/src/cpp/webgpu/GPUQuerySetImpl.cpp +137 -0
  200. package/platforms/ios/src/cpp/webgpu/GPUQuerySetImpl.h +55 -0
  201. package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.cpp +521 -0
  202. package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.h +56 -0
  203. package/platforms/ios/src/cpp/webgpu/GPURenderBundleEncoderImpl.cpp +469 -0
  204. package/platforms/ios/src/cpp/webgpu/GPURenderBundleEncoderImpl.h +71 -0
  205. package/platforms/ios/src/cpp/webgpu/GPURenderBundleImpl.cpp +53 -0
  206. package/platforms/ios/src/cpp/webgpu/GPURenderBundleImpl.h +45 -0
  207. package/platforms/ios/src/cpp/webgpu/GPURenderPassEncoderImpl.cpp +653 -0
  208. package/platforms/ios/src/cpp/webgpu/GPURenderPassEncoderImpl.h +85 -0
  209. package/platforms/ios/src/cpp/webgpu/GPURenderPipelineImpl.cpp +84 -0
  210. package/platforms/ios/src/cpp/webgpu/GPURenderPipelineImpl.h +49 -0
  211. package/platforms/ios/src/cpp/webgpu/GPUSamplerImpl.cpp +53 -0
  212. package/platforms/ios/src/cpp/webgpu/GPUSamplerImpl.h +45 -0
  213. package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.cpp +56 -0
  214. package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.h +45 -0
  215. package/platforms/ios/src/cpp/webgpu/GPUSupportedLimitsImpl.cpp +1304 -0
  216. package/platforms/ios/src/cpp/webgpu/GPUSupportedLimitsImpl.h +288 -0
  217. package/platforms/ios/src/cpp/webgpu/GPUTextureImpl.cpp +360 -0
  218. package/platforms/ios/src/cpp/webgpu/GPUTextureImpl.h +75 -0
  219. package/platforms/ios/src/cpp/webgpu/GPUTextureViewImpl.cpp +53 -0
  220. package/platforms/ios/src/cpp/webgpu/GPUTextureViewImpl.h +45 -0
  221. package/platforms/ios/src/cpp/webgpu/GPUUtils.h +178 -0
  222. package/SVG/Circle.d.ts +0 -11
  223. package/SVG/Circle.js +0 -21
  224. package/SVG/Circle.js.map +0 -1
  225. package/SVG/ClipPath.d.ts +0 -4
  226. package/SVG/ClipPath.js +0 -9
  227. package/SVG/ClipPath.js.map +0 -1
  228. package/SVG/Defs.d.ts +0 -4
  229. package/SVG/Defs.js +0 -9
  230. package/SVG/Defs.js.map +0 -1
  231. package/SVG/Ellipse.d.ts +0 -13
  232. package/SVG/Ellipse.js +0 -26
  233. package/SVG/Ellipse.js.map +0 -1
  234. package/SVG/G.d.ts +0 -7
  235. package/SVG/G.js +0 -9
  236. package/SVG/G.js.map +0 -1
  237. package/SVG/Image.d.ts +0 -11
  238. package/SVG/Image.js +0 -40
  239. package/SVG/Image.js.map +0 -1
  240. package/SVG/Line.d.ts +0 -13
  241. package/SVG/Line.js +0 -26
  242. package/SVG/Line.js.map +0 -1
  243. package/SVG/LinearGradient.d.ts +0 -10
  244. package/SVG/LinearGradient.js +0 -13
  245. package/SVG/LinearGradient.js.map +0 -1
  246. package/SVG/Path.d.ts +0 -7
  247. package/SVG/Path.js +0 -14
  248. package/SVG/Path.js.map +0 -1
  249. package/SVG/Pattern.d.ts +0 -4
  250. package/SVG/Pattern.js +0 -9
  251. package/SVG/Pattern.js.map +0 -1
  252. package/SVG/Polygon.d.ts +0 -7
  253. package/SVG/Polygon.js +0 -14
  254. package/SVG/Polygon.js.map +0 -1
  255. package/SVG/Polyline.d.ts +0 -7
  256. package/SVG/Polyline.js +0 -14
  257. package/SVG/Polyline.js.map +0 -1
  258. package/SVG/Rect.d.ts +0 -8
  259. package/SVG/Rect.js +0 -13
  260. package/SVG/Rect.js.map +0 -1
  261. package/SVG/SVG.d.ts +0 -32
  262. package/SVG/SVG.js +0 -204
  263. package/SVG/SVG.js.map +0 -1
  264. package/SVG/SVGItem.d.ts +0 -5
  265. package/SVG/SVGItem.js +0 -8
  266. package/SVG/SVGItem.js.map +0 -1
  267. package/SVG/Stop.d.ts +0 -5
  268. package/SVG/Stop.js +0 -9
  269. package/SVG/Stop.js.map +0 -1
  270. package/SVG/Symbol.d.ts +0 -4
  271. package/SVG/Symbol.js +0 -9
  272. package/SVG/Symbol.js.map +0 -1
  273. package/SVG/Text.d.ts +0 -14
  274. package/SVG/Text.js +0 -26
  275. package/SVG/Text.js.map +0 -1
  276. package/SVG/Use.d.ts +0 -4
  277. package/SVG/Use.js +0 -9
  278. package/SVG/Use.js.map +0 -1
  279. package/SVG/index.d.ts +0 -18
  280. package/SVG/index.js +0 -19
  281. package/SVG/index.js.map +0 -1
  282. package/platforms/ios/src/cpp/PerIsolateData.cpp +0 -49
  283. package/platforms/ios/src/cpp/PerIsolateData.h +0 -54
  284. package/platforms/ios/src/cpp/URLImpl.cpp +0 -464
  285. package/platforms/ios/src/cpp/URLImpl.h +0 -121
@@ -0,0 +1,1087 @@
1
+ //
2
+ // Created by Osei Fortune on 23/06/2024.
3
+ //
4
+
5
+ #include "GPUCommandEncoderImpl.h"
6
+ #include "Caches.h"
7
+ #include "GPUComputePassEncoderImpl.h"
8
+ #include "GPUQuerySetImpl.h"
9
+ #include "GPUBufferImpl.h"
10
+ #include "GPUTextureViewImpl.h"
11
+ #include "GPURenderPassEncoderImpl.h"
12
+ #include "GPUCommandBufferImpl.h"
13
+ #include "GPUTextureImpl.h"
14
+
15
+ GPUCommandEncoderImpl::GPUCommandEncoderImpl(const CanvasGPUCommandEncoder *encoder) : encoder_(
16
+ encoder) {}
17
+
18
+ const CanvasGPUCommandEncoder *GPUCommandEncoderImpl::GetEncoder() {
19
+ return this->encoder_;
20
+ }
21
+
22
+ void GPUCommandEncoderImpl::Init(v8::Local<v8::Object> canvasModule, v8::Isolate *isolate) {
23
+ v8::Locker locker(isolate);
24
+ v8::Isolate::Scope isolate_scope(isolate);
25
+ v8::HandleScope handle_scope(isolate);
26
+
27
+ auto ctor = GetCtor(isolate);
28
+ auto context = isolate->GetCurrentContext();
29
+ auto func = ctor->GetFunction(context).ToLocalChecked();
30
+
31
+ canvasModule->Set(context, ConvertToV8String(isolate, "GPUCommandEncoder"), func).FromJust();;
32
+ }
33
+
34
+ GPUCommandEncoderImpl *GPUCommandEncoderImpl::GetPointer(const v8::Local<v8::Object> &object) {
35
+ auto ptr = object->GetAlignedPointerFromInternalField(0);
36
+ if (ptr == nullptr) {
37
+ return nullptr;
38
+ }
39
+ return static_cast<GPUCommandEncoderImpl *>(ptr);
40
+ }
41
+
42
+ v8::Local<v8::FunctionTemplate> GPUCommandEncoderImpl::GetCtor(v8::Isolate *isolate) {
43
+ auto cache = Caches::Get(isolate);
44
+ auto ctor = cache->GPUCommandEncoderTmpl.get();
45
+ if (ctor != nullptr) {
46
+ return ctor->Get(isolate);
47
+ }
48
+
49
+ v8::Local<v8::FunctionTemplate> ctorTmpl = v8::FunctionTemplate::New(isolate);
50
+ ctorTmpl->InstanceTemplate()->SetInternalFieldCount(2);
51
+ ctorTmpl->SetClassName(ConvertToV8String(isolate, "GPUCommandEncoder"));
52
+
53
+ auto tmpl = ctorTmpl->InstanceTemplate();
54
+ tmpl->SetInternalFieldCount(2);
55
+
56
+
57
+ tmpl->Set(
58
+ ConvertToV8String(isolate, "beginComputePass"),
59
+ v8::FunctionTemplate::New(isolate, &BeginComputePass));
60
+
61
+ tmpl->Set(
62
+ ConvertToV8String(isolate, "beginRenderPass"),
63
+ v8::FunctionTemplate::New(isolate, &BeginRenderPass));
64
+
65
+ tmpl->Set(
66
+ ConvertToV8String(isolate, "clearBuffer"),
67
+ v8::FunctionTemplate::New(isolate, &ClearBuffer));
68
+
69
+ tmpl->Set(
70
+ ConvertToV8String(isolate, "copyBufferToBuffer"),
71
+ v8::FunctionTemplate::New(isolate, &CopyBufferToBuffer));
72
+
73
+ tmpl->Set(
74
+ ConvertToV8String(isolate, "copyBufferToTexture"),
75
+ v8::FunctionTemplate::New(isolate, &CopyBufferToTexture));
76
+
77
+ tmpl->Set(
78
+ ConvertToV8String(isolate, "copyTextureToBuffer"),
79
+ v8::FunctionTemplate::New(isolate, &CopyTextureToBuffer));
80
+
81
+ tmpl->Set(
82
+ ConvertToV8String(isolate, "copyTextureToTexture"),
83
+ v8::FunctionTemplate::New(isolate, &CopyTextureToTexture));
84
+
85
+ tmpl->Set(
86
+ ConvertToV8String(isolate, "finish"),
87
+ v8::FunctionTemplate::New(isolate, &Finish));
88
+
89
+ tmpl->Set(
90
+ ConvertToV8String(isolate, "insertDebugMarker"),
91
+ v8::FunctionTemplate::New(isolate, &InsertDebugMarker));
92
+
93
+ tmpl->Set(
94
+ ConvertToV8String(isolate, "popDebugGroup"),
95
+ v8::FunctionTemplate::New(isolate, &PopDebugGroup));
96
+
97
+ tmpl->Set(
98
+ ConvertToV8String(isolate, "pushDebugGroup"),
99
+ v8::FunctionTemplate::New(isolate, &PushDebugGroup));
100
+
101
+ tmpl->Set(
102
+ ConvertToV8String(isolate, "resolveQuerySet"),
103
+ v8::FunctionTemplate::New(isolate, &ResolveQuerySet));
104
+
105
+ tmpl->Set(
106
+ ConvertToV8String(isolate, "writeTimestamp"),
107
+ v8::FunctionTemplate::New(isolate, &WriteTimestamp));
108
+
109
+
110
+ cache->GPUCommandEncoderTmpl =
111
+ std::make_unique<v8::Persistent<v8::FunctionTemplate>>(isolate, ctorTmpl);
112
+ return ctorTmpl;
113
+ }
114
+
115
+
116
+ void GPUCommandEncoderImpl::BeginComputePass(const v8::FunctionCallbackInfo<v8::Value> &args) {
117
+ auto ptr = GetPointer(args.This());
118
+ if (ptr == nullptr) {
119
+ return;
120
+ }
121
+
122
+ auto isolate = args.GetIsolate();
123
+ auto context = isolate->GetCurrentContext();
124
+
125
+ auto descVal = args[0];
126
+
127
+ const CanvasGPUComputePassEncoder *pass;
128
+
129
+ if (!descVal->IsNullOrUndefined() && descVal->IsObject()) {
130
+ auto desc = descVal.As<v8::Object>();
131
+
132
+
133
+ v8::Local<v8::Value> labelVal;
134
+ desc->Get(context, ConvertToV8String(isolate, "label")).ToLocal(&labelVal);
135
+
136
+ char *label = nullptr;
137
+
138
+ if (!labelVal.IsEmpty() && labelVal->IsString()) {
139
+ label = *v8::String::Utf8Value(isolate, labelVal);
140
+ }
141
+
142
+ const CanvasGPUQuerySet *querySet = nullptr;
143
+ int32_t beginningOfPassWriteIndex = -1;
144
+
145
+ int32_t endOfPassWriteIndex = -1;
146
+
147
+
148
+ v8::Local<v8::Value> timestampWritesVal;
149
+ desc->Get(context, ConvertToV8String(isolate, "timestampWrites")).ToLocal(
150
+ &timestampWritesVal);
151
+
152
+
153
+ if (!timestampWritesVal.IsEmpty() && timestampWritesVal->IsObject()) {
154
+ auto timestampWrites = timestampWritesVal.As<v8::Object>();
155
+
156
+ v8::Local<v8::Value> querySetVal;
157
+ timestampWrites->Get(context, ConvertToV8String(isolate, "querySet")).ToLocal(
158
+ &querySetVal);
159
+
160
+
161
+ if (!querySetVal.IsEmpty() && querySetVal->IsObject()) {
162
+ auto queryPtr = GPUQuerySetImpl::GetPointer(querySetVal.As<v8::Object>());
163
+ if (queryPtr != nullptr) {
164
+ querySet = queryPtr->GetQuerySet();
165
+ }
166
+ }
167
+
168
+ v8::Local<v8::Value> beginningOfPassWriteIndexVal;
169
+
170
+
171
+ v8::Local<v8::Value> endOfPassWriteIndexVal;
172
+
173
+
174
+ timestampWrites->Get(context,
175
+ ConvertToV8String(isolate, "beginningOfPassWriteIndex")).ToLocal(
176
+ &beginningOfPassWriteIndexVal);
177
+
178
+ timestampWrites->Get(context,
179
+ ConvertToV8String(isolate, "endOfPassWriteIndex")).ToLocal(
180
+ &endOfPassWriteIndexVal);
181
+
182
+
183
+ if (beginningOfPassWriteIndexVal->IsInt32()) {
184
+ beginningOfPassWriteIndex = beginningOfPassWriteIndexVal.As<v8::Int32>()->Value();
185
+ }
186
+
187
+ if (endOfPassWriteIndexVal->IsInt32()) {
188
+ endOfPassWriteIndex = endOfPassWriteIndexVal.As<v8::Int32>()->Value();
189
+ }
190
+ }
191
+
192
+
193
+ pass = canvas_native_webgpu_command_encoder_begin_compute_pass(ptr->GetEncoder(),
194
+ querySet, label,
195
+ beginningOfPassWriteIndex,
196
+ endOfPassWriteIndex);
197
+
198
+
199
+ } else {
200
+ pass = canvas_native_webgpu_command_encoder_begin_compute_pass(ptr->GetEncoder(),
201
+ nullptr, nullptr, -1,
202
+ -1);
203
+
204
+ }
205
+
206
+
207
+ if (pass != nullptr) {
208
+ auto value = new GPUComputePassEncoderImpl(pass);
209
+ auto ret = GPUComputePassEncoderImpl::NewInstance(isolate, value);
210
+ args.GetReturnValue().Set(ret);
211
+ } else {
212
+ args.GetReturnValue().SetUndefined();
213
+ }
214
+
215
+ }
216
+
217
+ void GPUCommandEncoderImpl::BeginRenderPass(const v8::FunctionCallbackInfo<v8::Value> &args) {
218
+ auto ptr = GetPointer(args.This());
219
+ if (ptr == nullptr) {
220
+ return;
221
+ }
222
+
223
+ auto isolate = args.GetIsolate();
224
+ auto context = isolate->GetCurrentContext();
225
+
226
+ auto descVal = args[0];
227
+
228
+ const CanvasGPURenderPassEncoder *pass = nullptr;
229
+
230
+ std::vector<CanvasRenderPassColorAttachment> colorAttachments_;
231
+
232
+ if (!descVal->IsNullOrUndefined() && descVal->IsObject()) {
233
+ auto desc = descVal.As<v8::Object>();
234
+
235
+
236
+ v8::Local<v8::Value> labelVal;
237
+ desc->Get(context, ConvertToV8String(isolate, "label")).ToLocal(&labelVal);
238
+
239
+ char *label = nullptr;
240
+
241
+ if (!labelVal.IsEmpty() && labelVal->IsString()) {
242
+ label = *v8::String::Utf8Value(isolate, labelVal);
243
+ }
244
+
245
+
246
+ v8::Local<v8::Value> colorAttachmentsVal;
247
+ desc->Get(context, ConvertToV8String(isolate, "colorAttachments")).ToLocal(
248
+ &colorAttachmentsVal);
249
+
250
+ auto colorAttachments = colorAttachmentsVal.As<v8::Array>();
251
+ auto colorAttachmentsLength = colorAttachments->Length();
252
+
253
+ for (int i = 0; i < colorAttachmentsLength; i++) {
254
+ auto colorAttachment = colorAttachments->Get(context,
255
+ i).ToLocalChecked().As<v8::Object>();
256
+
257
+ v8::Local<v8::Value> clearValueVal;
258
+ colorAttachment->Get(context, ConvertToV8String(isolate, "clearValue")).ToLocal(
259
+ &clearValueVal);
260
+ auto clearValue = CanvasColor{0, 0, 0, 0};
261
+ if (!clearValueVal.IsEmpty() && clearValueVal->IsObject()) {
262
+ auto clearValueObj = clearValueVal.As<v8::Object>();
263
+
264
+ v8::Local<v8::Value> r;
265
+ v8::Local<v8::Value> g;
266
+ v8::Local<v8::Value> b;
267
+ v8::Local<v8::Value> a;
268
+
269
+ clearValueObj->Get(context, ConvertToV8String(isolate, "r")).ToLocal(&r);
270
+ clearValueObj->Get(context, ConvertToV8String(isolate, "g")).ToLocal(&g);
271
+ clearValueObj->Get(context, ConvertToV8String(isolate, "b")).ToLocal(&b);
272
+ clearValueObj->Get(context, ConvertToV8String(isolate, "a")).ToLocal(&a);
273
+
274
+ if (!r.IsEmpty() && r->IsNumber()) {
275
+ clearValue.r = r.As<v8::Number>()->Value();
276
+ }
277
+
278
+ if (!g.IsEmpty() && g->IsNumber()) {
279
+ clearValue.g = g.As<v8::Number>()->Value();
280
+ }
281
+
282
+
283
+ if (!b.IsEmpty() && b->IsNumber()) {
284
+ clearValue.b = b.As<v8::Number>()->Value();
285
+ }
286
+
287
+ if (!a.IsEmpty() && a->IsNumber()) {
288
+ clearValue.a = a.As<v8::Number>()->Value();
289
+ }
290
+ }
291
+
292
+
293
+ auto viewVal = colorAttachment->Get(context, ConvertToV8String(isolate,
294
+ "view")).ToLocalChecked();
295
+
296
+ auto view = GPUTextureViewImpl::GetPointer(viewVal.As<v8::Object>());
297
+
298
+
299
+ const CanvasGPUTextureView *resolve_target = nullptr;
300
+
301
+ v8::Local<v8::Value> resolve_target_val;
302
+
303
+ colorAttachment->Get(context, ConvertToV8String(isolate, "resolveTarget")).ToLocal(
304
+ &resolve_target_val);
305
+
306
+ auto resolve_target_type = GetNativeType(resolve_target_val);
307
+
308
+ if (resolve_target_type == NativeType::GPUTextureView) {
309
+ auto res = GPUTextureViewImpl::GetPointer(resolve_target_val.As<v8::Object>());
310
+ resolve_target = res->GetTextureView();
311
+ }
312
+
313
+ // default
314
+ CanvasLoadOp load = CanvasLoadOp::CanvasLoadOpClear;
315
+ CanvasStoreOp store = CanvasStoreOp::CanvasStoreOpStore;
316
+ auto loadVal = colorAttachment->Get(context, ConvertToV8String(isolate,
317
+ "loadOp")).ToLocalChecked();
318
+
319
+ if (loadVal->IsUint32()) {
320
+ load = (CanvasLoadOp) loadVal->Uint32Value(
321
+ context).ToChecked();
322
+ } else if (loadVal->IsString()) {
323
+ auto val = ConvertFromV8String(isolate, loadVal);
324
+ if (val == "clear") {
325
+ load = CanvasLoadOp::CanvasLoadOpClear;
326
+ } else if (val == "load") {
327
+ load = CanvasLoadOp::CanvasLoadOpLoad;
328
+ }
329
+ }
330
+
331
+
332
+ auto storeVal = colorAttachment->Get(context, ConvertToV8String(isolate,
333
+ "storeOp")).ToLocalChecked();
334
+
335
+ if (!storeVal.IsEmpty() && storeVal->IsUint32()) {
336
+ store = (CanvasStoreOp) storeVal->Uint32Value(
337
+ context).ToChecked();
338
+ } else if (storeVal->IsString()) {
339
+ auto val = ConvertFromV8String(isolate, storeVal);
340
+ if (val == "discard") {
341
+ store = CanvasStoreOp::CanvasStoreOpDiscard;
342
+ } else if (val == "store") {
343
+ store = CanvasStoreOp::CanvasStoreOpStore;
344
+ }
345
+ }
346
+
347
+ CanvasPassChannelColor channel{
348
+ load,
349
+ store,
350
+ clearValue,
351
+ false
352
+ };
353
+
354
+ auto attachment = CanvasRenderPassColorAttachment{
355
+ view->GetTextureView(),
356
+ resolve_target,
357
+ channel
358
+ };
359
+
360
+ colorAttachments_.push_back(attachment);
361
+
362
+ }
363
+
364
+
365
+ v8::Local<v8::Value> maxDrawCountVal;
366
+
367
+ desc->Get(context, ConvertToV8String(isolate, "maxDrawCount")).ToLocal(&maxDrawCountVal);
368
+
369
+
370
+ CanvasRenderPassDepthStencilAttachment *depthStencilAttachment = nullptr;
371
+ v8::Local<v8::Value> depthStencilAttachmentVal;
372
+
373
+ desc->Get(context, ConvertToV8String(isolate, "depthStencilAttachment")).ToLocal(
374
+ &depthStencilAttachmentVal);
375
+
376
+
377
+ if (!depthStencilAttachmentVal.IsEmpty() && depthStencilAttachmentVal->IsObject()) {
378
+ auto depthStencilAttachmentObj = depthStencilAttachmentVal.As<v8::Object>();
379
+ }
380
+
381
+
382
+ const CanvasGPUQuerySet *occlusion_query_set = nullptr;
383
+ v8::Local<v8::Value> occlusionQuerySetVal;
384
+
385
+
386
+ desc->Get(context, ConvertToV8String(isolate, "occlusionQuerySet")).ToLocal(
387
+ &occlusionQuerySetVal);
388
+
389
+
390
+ if (!occlusionQuerySetVal.IsEmpty() && occlusionQuerySetVal->IsObject()) {
391
+ auto occlusionQuerySet = GPUQuerySetImpl::GetPointer(
392
+ occlusionQuerySetVal.As<v8::Object>());
393
+ occlusion_query_set = occlusionQuerySet->GetQuerySet();
394
+ }
395
+
396
+
397
+ v8::Local<v8::Value> timestampWritesVal;
398
+ desc->Get(context, ConvertToV8String(isolate, "timestampWrites")).ToLocal(
399
+ &timestampWritesVal);
400
+
401
+
402
+ const CanvasGPUQuerySet *querySet = nullptr;
403
+ int32_t beginningOfPassWriteIndex = -1;
404
+ int32_t endOfPassWriteIndex = -1;
405
+
406
+ if (!timestampWritesVal.IsEmpty() && timestampWritesVal->IsObject()) {
407
+ auto timestampWrites = timestampWritesVal.As<v8::Object>();
408
+ v8::Local<v8::Value> querySetVal;
409
+ timestampWrites->Get(context, ConvertToV8String(isolate, "querySet")).ToLocal(
410
+ &querySetVal);
411
+
412
+
413
+ if (!querySetVal.IsEmpty() && querySetVal->IsObject()) {
414
+ auto queryPtr = GPUQuerySetImpl::GetPointer(querySetVal.As<v8::Object>());
415
+ if (queryPtr != nullptr) {
416
+ querySet = queryPtr->GetQuerySet();
417
+ }
418
+ }
419
+
420
+ v8::Local<v8::Value> beginningOfPassWriteIndexVal;
421
+
422
+ v8::Local<v8::Value> endOfPassWriteIndexVal;
423
+
424
+
425
+ auto beginningOfPassWriteIndexValSuccess = timestampWrites->Get(context,
426
+ ConvertToV8String(
427
+ isolate,
428
+ "beginningOfPassWriteIndex")).ToLocal(
429
+ &beginningOfPassWriteIndexVal);
430
+
431
+ auto endOfPassWriteIndexValSuccess = timestampWrites->Get(context,
432
+ ConvertToV8String(isolate,
433
+ "endOfPassWriteIndex")).ToLocal(
434
+ &endOfPassWriteIndexVal);
435
+
436
+
437
+ if (beginningOfPassWriteIndexValSuccess && beginningOfPassWriteIndexVal->IsInt32()) {
438
+ beginningOfPassWriteIndex = beginningOfPassWriteIndexVal.As<v8::Int32>()->Value();
439
+ }
440
+
441
+ if (endOfPassWriteIndexValSuccess && endOfPassWriteIndexVal->IsInt32()) {
442
+ endOfPassWriteIndex = endOfPassWriteIndexVal.As<v8::Int32>()->Value();
443
+ }
444
+
445
+ }
446
+
447
+
448
+ pass = canvas_native_webgpu_command_encoder_begin_render_pass(
449
+ ptr->GetEncoder(), label, colorAttachments_.data(), colorAttachments_.size(),
450
+ depthStencilAttachment, occlusion_query_set,
451
+ querySet, beginningOfPassWriteIndex, endOfPassWriteIndex
452
+ );
453
+
454
+
455
+ }
456
+
457
+
458
+ if (pass != nullptr) {
459
+ auto value = new GPURenderPassEncoderImpl(pass);
460
+ auto ret = GPURenderPassEncoderImpl::NewInstance(isolate, value);
461
+ args.GetReturnValue().Set(ret);
462
+ } else {
463
+ args.GetReturnValue().SetUndefined();
464
+ }
465
+
466
+ }
467
+
468
+ void GPUCommandEncoderImpl::ClearBuffer(const v8::FunctionCallbackInfo<v8::Value> &args) {
469
+ auto ptr = GetPointer(args.This());
470
+ if (ptr == nullptr) {
471
+ return;
472
+ }
473
+
474
+ auto bufferVal = args[0];
475
+ const CanvasGPUBuffer *buffer = nullptr;
476
+
477
+ if (bufferVal->IsObject()) {
478
+ auto bufferPtr = GPUBufferImpl::GetPointer(bufferVal.As<v8::Object>());
479
+ if (bufferPtr != nullptr) {
480
+ buffer = bufferPtr->GetGPUBuffer();
481
+ }
482
+ }
483
+
484
+ if (buffer == nullptr) {
485
+ return;
486
+ }
487
+
488
+ int64_t offset = -1;
489
+ auto offsetVal = args[1];
490
+
491
+ if (offsetVal->IsNumber()) {
492
+ offset = (int64_t) offsetVal.As<v8::Number>()->Value();
493
+ }
494
+
495
+ int64_t size = -1;
496
+ auto sizeVal = args[2];
497
+
498
+ if (sizeVal->IsNumber()) {
499
+ size = (int64_t) sizeVal.As<v8::Number>()->Value();
500
+ }
501
+
502
+ canvas_native_webgpu_command_encoder_clear_buffer(ptr->GetEncoder(), buffer, offset, size);
503
+
504
+ }
505
+
506
+ void GPUCommandEncoderImpl::CopyBufferToBuffer(const v8::FunctionCallbackInfo<v8::Value> &args) {
507
+ auto ptr = GetPointer(args.This());
508
+ if (ptr == nullptr) {
509
+ return;
510
+ }
511
+ auto isolate = args.GetIsolate();
512
+ auto context = isolate->GetCurrentContext();
513
+
514
+ auto source = args[0];
515
+ auto sourceType = GetNativeType(source);
516
+ auto sourceOffset = args[1];
517
+ auto destination = args[2];
518
+ auto destinationType = GetNativeType(destination);
519
+ auto destinationOffset = args[3];
520
+ auto size = args[4];
521
+
522
+ if (sourceType == NativeType::GPUBuffer && destinationType == NativeType::GPUBuffer) {
523
+ auto src = GPUBufferImpl::GetPointer(source.As<v8::Object>());
524
+ auto dst = GPUBufferImpl::GetPointer(destination.As<v8::Object>());
525
+ canvas_native_webgpu_command_encoder_copy_buffer_to_buffer(ptr->GetEncoder(),
526
+ src->GetGPUBuffer(),
527
+ (int64_t) sourceOffset->NumberValue(
528
+ context).FromJust(),
529
+ dst->GetGPUBuffer(),
530
+ (int64_t) destinationOffset->NumberValue(
531
+ context).FromJust(),
532
+ (uint64_t) size->NumberValue(
533
+ context).FromJust()
534
+ );
535
+ }
536
+
537
+ }
538
+
539
+ void GPUCommandEncoderImpl::CopyBufferToTexture(const v8::FunctionCallbackInfo<v8::Value> &args) {
540
+ auto ptr = GetPointer(args.This());
541
+ if (ptr == nullptr) {
542
+ return;
543
+ }
544
+
545
+
546
+ auto isolate = args.GetIsolate();
547
+ auto context = isolate->GetCurrentContext();
548
+
549
+ auto source = args[0];
550
+ auto destination = args[1];
551
+ auto copySize = args[2];
552
+
553
+ if (source->IsObject() && destination->IsObject() && copySize->IsObject()) {
554
+ const CanvasGPUBuffer *buffer = nullptr;
555
+ auto src = source.As<v8::Object>();
556
+ v8::Local<v8::Value> bufferVal;
557
+ src->Get(context, ConvertToV8String(isolate, "buffer")).ToLocal(&bufferVal);
558
+ if (GetNativeType(bufferVal) == NativeType::GPUBuffer) {
559
+ buffer = GPUBufferImpl::GetPointer(bufferVal.As<v8::Object>())->GetGPUBuffer();
560
+ }
561
+ uint64_t offset = 0;
562
+ int32_t rowsPerImage = -1;
563
+
564
+ v8::Local<v8::Value> rowsPerImageVal;
565
+
566
+ src->Get(context, ConvertToV8String(isolate, "rowsPerImage")).ToLocal(&rowsPerImageVal);
567
+
568
+ if (!rowsPerImageVal.IsEmpty() && rowsPerImageVal->IsInt32()) {
569
+ rowsPerImage = rowsPerImageVal->Int32Value(context).FromJust();
570
+ }
571
+
572
+
573
+ v8::Local<v8::Value> offsetVal;
574
+
575
+ src->Get(context, ConvertToV8String(isolate, "offset")).ToLocal(&offsetVal);
576
+
577
+ if (!offsetVal.IsEmpty() && offsetVal->IsNumber()) {
578
+ offset = (int64_t) offsetVal->NumberValue(context).FromJust();
579
+ }
580
+
581
+ v8::Local<v8::Value> bytesPerRowVal;
582
+
583
+ src->Get(context, ConvertToV8String(isolate, "bytesPerRow")).ToLocal(&bytesPerRowVal);
584
+
585
+ CanvasImageCopyBuffer copy{
586
+ buffer,
587
+ offset,
588
+ bytesPerRowVal->Int32Value(context).FromJust(),
589
+ rowsPerImage
590
+ };
591
+
592
+
593
+ uint32_t mipLevel = 0;
594
+ CanvasOrigin3d origin{0, 0, 0};
595
+ CanvasTextureAspect aspect = CanvasTextureAspectAll;
596
+
597
+ const CanvasGPUTexture *texture = nullptr;
598
+ auto dst = destination.As<v8::Object>();
599
+
600
+
601
+ v8::Local<v8::Value> textureVal;
602
+ dst->Get(context, ConvertToV8String(isolate, "texture")).ToLocal(&textureVal);
603
+ if (GetNativeType(textureVal) == NativeType::GPUTexture) {
604
+ texture = GPUTextureImpl::GetPointer(textureVal.As<v8::Object>())->GetTexture();
605
+ }
606
+
607
+
608
+ v8::Local<v8::Value> mipLevelVal;
609
+ dst->Get(context, ConvertToV8String(isolate, "mipLevel")).ToLocal(&mipLevelVal);
610
+
611
+ if (!mipLevelVal.IsEmpty() && mipLevelVal->IsUint32()) {
612
+ mipLevel = mipLevelVal->Uint32Value(context).FromJust();
613
+ }
614
+
615
+ v8::Local<v8::Value> originVal;
616
+ dst->Get(context, ConvertToV8String(isolate, "origin")).ToLocal(&originVal);
617
+
618
+
619
+ if (!originVal.IsEmpty() && originVal->IsObject()) {
620
+ auto originObj = originVal.As<v8::Object>();
621
+
622
+
623
+ v8::Local<v8::Value> xVal;
624
+ v8::Local<v8::Value> yVal;
625
+ v8::Local<v8::Value> zVal;
626
+ originObj->Get(context, ConvertToV8String(isolate, "x")).ToLocal(&xVal);
627
+ originObj->Get(context, ConvertToV8String(isolate, "y")).ToLocal(&yVal);
628
+ originObj->Get(context, ConvertToV8String(isolate, "z")).ToLocal(&zVal);
629
+
630
+ if (xVal->IsUint32()) {
631
+ origin.x = xVal->Uint32Value(context).FromJust();
632
+ }
633
+ if (yVal->IsUint32()) {
634
+ origin.y = yVal->Uint32Value(context).FromJust();
635
+ }
636
+ if (zVal->IsUint32()) {
637
+ origin.z = zVal->Uint32Value(context).FromJust();
638
+ }
639
+
640
+ }
641
+
642
+
643
+ v8::Local<v8::Value> aspectVal;
644
+ dst->Get(context, ConvertToV8String(isolate, "aspect")).ToLocal(&aspectVal);
645
+
646
+
647
+ auto aspectStr = ConvertFromV8String(isolate, aspectVal);
648
+
649
+ if (aspectStr == "stencil-only") {
650
+ aspect = CanvasTextureAspectStencilOnly;
651
+ } else if (aspectStr == "depth-only") {
652
+ aspect = CanvasTextureAspectDepthOnly;
653
+ }
654
+
655
+ CanvasImageCopyTexture ct{
656
+ texture, mipLevel, origin, aspect
657
+ };
658
+
659
+ CanvasExtent3d cz = ParseExtent3d(isolate, copySize);
660
+ canvas_native_webgpu_command_encoder_copy_buffer_to_texture(
661
+ ptr->GetEncoder(),
662
+ &copy,
663
+ &ct,
664
+ &cz
665
+ );
666
+ }
667
+
668
+
669
+ }
670
+
671
+ void GPUCommandEncoderImpl::CopyTextureToBuffer(const v8::FunctionCallbackInfo<v8::Value> &args) {
672
+ auto ptr = GetPointer(args.This());
673
+ if (ptr == nullptr) {
674
+ return;
675
+ }
676
+
677
+
678
+ auto isolate = args.GetIsolate();
679
+ auto context = isolate->GetCurrentContext();
680
+
681
+ // copying texture to buffer swapped the real source and dst
682
+ auto source = args[1];
683
+ auto destination = args[0];
684
+ auto copySize = args[2];
685
+
686
+ if (source->IsObject() && destination->IsObject() && copySize->IsObject()) {
687
+ const CanvasGPUBuffer *buffer = nullptr;
688
+ auto src = source.As<v8::Object>();
689
+
690
+ v8::Local<v8::Value> bufferVal;
691
+ src->Get(context, ConvertToV8String(isolate, "buffer")).ToLocal(&bufferVal);
692
+ if (GetNativeType(bufferVal) == NativeType::GPUBuffer) {
693
+ buffer = GPUBufferImpl::GetPointer(bufferVal.As<v8::Object>())->GetGPUBuffer();
694
+ }
695
+ uint64_t offset = 0;
696
+ int32_t rowsPerImage = -1;
697
+
698
+ v8::Local<v8::Value> rowsPerImageVal;
699
+
700
+ src->Get(context, ConvertToV8String(isolate, "rowsPerImage")).ToLocal(&rowsPerImageVal);
701
+
702
+ if (!rowsPerImageVal.IsEmpty() && rowsPerImageVal->IsInt32()) {
703
+ rowsPerImage = rowsPerImageVal->Int32Value(context).FromJust();
704
+ }
705
+
706
+
707
+ v8::Local<v8::Value> offsetVal;
708
+
709
+ src->Get(context, ConvertToV8String(isolate, "offset")).ToLocal(&offsetVal);
710
+
711
+ if (!offsetVal.IsEmpty() && offsetVal->IsNumber()) {
712
+ offset = (int64_t) offsetVal->NumberValue(context).FromJust();
713
+ }
714
+
715
+ v8::Local<v8::Value> bytesPerRowVal;
716
+
717
+ src->Get(context, ConvertToV8String(isolate, "bytesPerRow")).ToLocal(&bytesPerRowVal);
718
+
719
+ CanvasImageCopyBuffer copy{
720
+ buffer,
721
+ offset,
722
+ bytesPerRowVal->Int32Value(context).FromJust(),
723
+ rowsPerImage
724
+ };
725
+
726
+
727
+ uint32_t mipLevel = 0;
728
+ CanvasOrigin3d origin{0, 0, 0};
729
+ CanvasTextureAspect aspect = CanvasTextureAspectAll;
730
+
731
+ const CanvasGPUTexture *texture = nullptr;
732
+ auto dst = destination.As<v8::Object>();
733
+
734
+
735
+ v8::Local<v8::Value> textureVal;
736
+ dst->Get(context, ConvertToV8String(isolate, "texture")).ToLocal(&textureVal);
737
+ if (GetNativeType(textureVal) == NativeType::GPUTexture) {
738
+ texture = GPUTextureImpl::GetPointer(textureVal.As<v8::Object>())->GetTexture();
739
+ }
740
+
741
+
742
+ v8::Local<v8::Value> mipLevelVal;
743
+ dst->Get(context, ConvertToV8String(isolate, "mipLevel")).ToLocal(&mipLevelVal);
744
+
745
+ if (!mipLevelVal.IsEmpty() && mipLevelVal->IsUint32()) {
746
+ mipLevel = mipLevelVal->Uint32Value(context).FromJust();
747
+ }
748
+
749
+ v8::Local<v8::Value> originVal;
750
+ dst->Get(context, ConvertToV8String(isolate, "origin")).ToLocal(&originVal);
751
+
752
+
753
+ if (!originVal.IsEmpty() && originVal->IsObject()) {
754
+ auto originObj = originVal.As<v8::Object>();
755
+
756
+
757
+ v8::Local<v8::Value> xVal;
758
+ v8::Local<v8::Value> yVal;
759
+ v8::Local<v8::Value> zVal;
760
+ originObj->Get(context, ConvertToV8String(isolate, "x")).ToLocal(&xVal);
761
+ originObj->Get(context, ConvertToV8String(isolate, "y")).ToLocal(&yVal);
762
+ originObj->Get(context, ConvertToV8String(isolate, "z")).ToLocal(&zVal);
763
+
764
+ if (xVal->IsUint32()) {
765
+ origin.x = xVal->Uint32Value(context).FromJust();
766
+ }
767
+ if (yVal->IsUint32()) {
768
+ origin.y = yVal->Uint32Value(context).FromJust();
769
+ }
770
+ if (zVal->IsUint32()) {
771
+ origin.z = zVal->Uint32Value(context).FromJust();
772
+ }
773
+
774
+ }
775
+
776
+
777
+ v8::Local<v8::Value> aspectVal;
778
+ dst->Get(context, ConvertToV8String(isolate, "aspect")).ToLocal(&aspectVal);
779
+
780
+
781
+ auto aspectStr = ConvertFromV8String(isolate, aspectVal);
782
+
783
+ if (aspectStr == "stencil-only") {
784
+ aspect = CanvasTextureAspectStencilOnly;
785
+ } else if (aspectStr == "depth-only") {
786
+ aspect = CanvasTextureAspectDepthOnly;
787
+ }
788
+
789
+ CanvasImageCopyTexture ct{
790
+ texture, mipLevel, origin, aspect
791
+ };
792
+
793
+ CanvasExtent3d cz = ParseExtent3d(isolate, copySize);
794
+ canvas_native_webgpu_command_encoder_copy_texture_to_buffer(
795
+ ptr->GetEncoder(),
796
+ &ct,
797
+ &copy,
798
+ &cz
799
+ );
800
+ }
801
+
802
+
803
+ }
804
+
805
+ void GPUCommandEncoderImpl::CopyTextureToTexture(const v8::FunctionCallbackInfo<v8::Value> &args) {
806
+ auto ptr = GetPointer(args.This());
807
+ if (ptr == nullptr) {
808
+ return;
809
+ }
810
+
811
+ auto isolate = args.GetIsolate();
812
+ auto context = isolate->GetCurrentContext();
813
+
814
+ // copying texture to buffer swapped the real source and dst
815
+ auto source = args[0];
816
+ auto destination = args[1];
817
+ auto copySize = args[2];
818
+
819
+ if (source->IsObject() && destination->IsObject() && copySize->IsObject()) {
820
+ auto src = source.As<v8::Object>();
821
+
822
+ uint32_t mipLevelA = 0;
823
+ CanvasOrigin3d originA{0, 0, 0};
824
+ CanvasTextureAspect aspectA = CanvasTextureAspectAll;
825
+
826
+ const CanvasGPUTexture *textureA = nullptr;
827
+
828
+ v8::Local<v8::Value> srcTextureVal;
829
+ src->Get(context, ConvertToV8String(isolate, "texture")).ToLocal(&srcTextureVal);
830
+ if (GetNativeType(srcTextureVal) == NativeType::GPUTexture) {
831
+ textureA = GPUTextureImpl::GetPointer(srcTextureVal.As<v8::Object>())->GetTexture();
832
+ }
833
+
834
+ v8::Local<v8::Value> mipLevelAVal;
835
+ src->Get(context, ConvertToV8String(isolate, "mipLevel")).ToLocal(&mipLevelAVal);
836
+
837
+ if (!mipLevelAVal.IsEmpty() && mipLevelAVal->IsUint32()) {
838
+ mipLevelA = mipLevelAVal->Uint32Value(context).FromJust();
839
+ }
840
+
841
+ v8::Local<v8::Value> originAVal;
842
+ src->Get(context, ConvertToV8String(isolate, "origin")).ToLocal(&originAVal);
843
+
844
+
845
+ if (!originAVal.IsEmpty() && originAVal->IsObject()) {
846
+ auto originObj = originAVal.As<v8::Object>();
847
+
848
+ v8::Local<v8::Value> xVal;
849
+ v8::Local<v8::Value> yVal;
850
+ v8::Local<v8::Value> zVal;
851
+ originObj->Get(context, ConvertToV8String(isolate, "x")).ToLocal(&xVal);
852
+ originObj->Get(context, ConvertToV8String(isolate, "y")).ToLocal(&yVal);
853
+ originObj->Get(context, ConvertToV8String(isolate, "z")).ToLocal(&zVal);
854
+
855
+ if (xVal->IsUint32()) {
856
+ originA.x = xVal->Uint32Value(context).FromJust();
857
+ }
858
+ if (yVal->IsUint32()) {
859
+ originA.y = yVal->Uint32Value(context).FromJust();
860
+ }
861
+ if (zVal->IsUint32()) {
862
+ originA.z = zVal->Uint32Value(context).FromJust();
863
+ }
864
+
865
+ }
866
+
867
+ v8::Local<v8::Value> aspectAVal;
868
+ src->Get(context, ConvertToV8String(isolate, "aspect")).ToLocal(&aspectAVal);
869
+
870
+ auto aspectAStr = ConvertFromV8String(isolate, aspectAVal);
871
+
872
+ if (aspectAStr == "stencil-only") {
873
+ aspectA = CanvasTextureAspectStencilOnly;
874
+ } else if (aspectAStr == "depth-only") {
875
+ aspectA = CanvasTextureAspectDepthOnly;
876
+ }
877
+ CanvasImageCopyTexture copy{
878
+ textureA, mipLevelA, originA, aspectA
879
+ };
880
+
881
+ uint32_t mipLevel = 0;
882
+ CanvasOrigin3d origin{0, 0, 0};
883
+ CanvasTextureAspect aspect = CanvasTextureAspectAll;
884
+
885
+ const CanvasGPUTexture *texture = nullptr;
886
+ auto dst = destination.As<v8::Object>();
887
+
888
+
889
+ v8::Local<v8::Value> textureVal;
890
+ dst->Get(context, ConvertToV8String(isolate, "texture")).ToLocal(&textureVal);
891
+ if (GetNativeType(textureVal) == NativeType::GPUTexture) {
892
+ texture = GPUTextureImpl::GetPointer(textureVal.As<v8::Object>())->GetTexture();
893
+ }
894
+
895
+
896
+ v8::Local<v8::Value> mipLevelVal;
897
+ dst->Get(context, ConvertToV8String(isolate, "mipLevel")).ToLocal(&mipLevelVal);
898
+
899
+ if (!mipLevelVal.IsEmpty() && mipLevelVal->IsUint32()) {
900
+ mipLevel = mipLevelVal->Uint32Value(context).FromJust();
901
+ }
902
+
903
+ v8::Local<v8::Value> originVal;
904
+ dst->Get(context, ConvertToV8String(isolate, "origin")).ToLocal(&originVal);
905
+
906
+ if (!originVal.IsEmpty() && originVal->IsObject()) {
907
+ auto originObj = originVal.As<v8::Object>();
908
+
909
+ v8::Local<v8::Value> xVal;
910
+ v8::Local<v8::Value> yVal;
911
+ v8::Local<v8::Value> zVal;
912
+ originObj->Get(context, ConvertToV8String(isolate, "x")).ToLocal(&xVal);
913
+ originObj->Get(context, ConvertToV8String(isolate, "y")).ToLocal(&yVal);
914
+ originObj->Get(context, ConvertToV8String(isolate, "z")).ToLocal(&zVal);
915
+
916
+ if (xVal->IsUint32()) {
917
+ origin.x = xVal->Uint32Value(context).FromJust();
918
+ }
919
+ if (yVal->IsUint32()) {
920
+ origin.y = yVal->Uint32Value(context).FromJust();
921
+ }
922
+ if (zVal->IsUint32()) {
923
+ origin.z = zVal->Uint32Value(context).FromJust();
924
+ }
925
+
926
+ }
927
+
928
+
929
+ v8::Local<v8::Value> aspectVal;
930
+ dst->Get(context, ConvertToV8String(isolate, "aspect")).ToLocal(&aspectVal);
931
+
932
+ auto aspectStr = ConvertFromV8String(isolate, aspectVal);
933
+
934
+ if (aspectStr == "stencil-only") {
935
+ aspect = CanvasTextureAspectStencilOnly;
936
+ } else if (aspectStr == "depth-only") {
937
+ aspect = CanvasTextureAspectDepthOnly;
938
+ }
939
+
940
+ CanvasImageCopyTexture ct{
941
+ texture, mipLevel, origin, aspect
942
+ };
943
+
944
+ CanvasExtent3d cz = ParseExtent3d(isolate, copySize);
945
+
946
+ canvas_native_webgpu_command_encoder_copy_texture_to_texture(
947
+ ptr->GetEncoder(),
948
+ &copy,
949
+ &ct,
950
+ &cz
951
+ );
952
+ }
953
+
954
+
955
+ }
956
+
957
+ void GPUCommandEncoderImpl::Finish(const v8::FunctionCallbackInfo<v8::Value> &args) {
958
+ auto ptr = GetPointer(args.This());
959
+ if (ptr == nullptr) {
960
+ return;
961
+ }
962
+
963
+ auto isolate = args.GetIsolate();
964
+ auto context = isolate->GetCurrentContext();
965
+
966
+
967
+ auto descVal = args[0];
968
+ std::string label;
969
+ bool didSet = false;
970
+ if (descVal->IsObject()) {
971
+ auto desc = descVal.As<v8::Object>();
972
+ v8::Local<v8::Value> labelVal;
973
+ desc->Get(context, ConvertToV8String(isolate, "label")).ToLocal(&labelVal);
974
+ if (!labelVal.IsEmpty() && labelVal->IsString()) {
975
+ label = ConvertFromV8String(isolate, labelVal);
976
+ didSet = true;
977
+ }
978
+ }
979
+
980
+ auto value = canvas_native_webgpu_command_encoder_finish(ptr->GetEncoder(),
981
+ didSet ? label.c_str() : nullptr);
982
+
983
+ if (value != nullptr) {
984
+ auto ret = GPUCommandBufferImpl::NewInstance(isolate, new GPUCommandBufferImpl(value));
985
+ args.GetReturnValue().Set(ret);
986
+ return;
987
+ }
988
+
989
+ args.GetReturnValue().SetUndefined();
990
+ }
991
+
992
+ void
993
+ GPUCommandEncoderImpl::InsertDebugMarker(const v8::FunctionCallbackInfo<v8::Value> &args) {
994
+ auto *ptr = GetPointer(args.This());
995
+ if (ptr == nullptr) {
996
+ return;
997
+ }
998
+
999
+ auto isolate = args.GetIsolate();
1000
+
1001
+ auto markerLabelVal = args[0];
1002
+ if (markerLabelVal->IsString()) {
1003
+ auto markerLabel = ConvertFromV8String(isolate, markerLabelVal);
1004
+ canvas_native_webgpu_command_encoder_insert_debug_marker(ptr->GetEncoder(),
1005
+ markerLabel.c_str());
1006
+ }
1007
+ }
1008
+
1009
+ void GPUCommandEncoderImpl::PopDebugGroup(const v8::FunctionCallbackInfo<v8::Value> &args) {
1010
+ auto *ptr = GetPointer(args.This());
1011
+ if (ptr == nullptr) {
1012
+ return;
1013
+ }
1014
+
1015
+ canvas_native_webgpu_command_encoder_pop_debug_group(ptr->GetEncoder());
1016
+ }
1017
+
1018
+ void GPUCommandEncoderImpl::PushDebugGroup(const v8::FunctionCallbackInfo<v8::Value> &args) {
1019
+ auto *ptr = GetPointer(args.This());
1020
+ if (ptr == nullptr) {
1021
+ return;
1022
+ }
1023
+
1024
+ auto isolate = args.GetIsolate();
1025
+
1026
+ auto groupLabelVal = args[0];
1027
+ if (groupLabelVal->IsString()) {
1028
+ auto groupLabel = ConvertFromV8String(isolate, groupLabelVal);
1029
+ canvas_native_webgpu_command_encoder_push_debug_group(ptr->GetEncoder(),
1030
+ groupLabel.c_str());
1031
+ }
1032
+ }
1033
+
1034
+ void GPUCommandEncoderImpl::ResolveQuerySet(const v8::FunctionCallbackInfo<v8::Value> &args) {
1035
+ auto *ptr = GetPointer(args.This());
1036
+ if (ptr == nullptr) {
1037
+ return;
1038
+ }
1039
+
1040
+ auto isolate = args.GetIsolate();
1041
+ auto context = isolate->GetCurrentContext();
1042
+
1043
+ auto querySet = args[0];
1044
+ auto queryType = GetNativeType(querySet);
1045
+ auto firstQuery = args[1];
1046
+ auto queryCount = args[2];
1047
+ auto destination = args[3];
1048
+ auto destinationType = GetNativeType(destination);
1049
+ auto destinationOffset = args[4];
1050
+
1051
+
1052
+ if (queryType == NativeType::GPUQuerySet && destinationType == NativeType::GPUBuffer) {
1053
+ auto qs = GPUQuerySetImpl::GetPointer(querySet.As<v8::Object>());
1054
+ auto dest = GPUBufferImpl::GetPointer(destination.As<v8::Object>());
1055
+ canvas_native_webgpu_command_encoder_resolve_query_set(ptr->GetEncoder(), qs->GetQuerySet(),
1056
+ firstQuery->Uint32Value(
1057
+ context).FromJust(),
1058
+ queryCount->Uint32Value(
1059
+ context).FromJust(),
1060
+ dest->GetGPUBuffer(),
1061
+ (uint64_t) destinationOffset->NumberValue(
1062
+ context).FromJust());
1063
+ }
1064
+ }
1065
+
1066
+ void GPUCommandEncoderImpl::WriteTimestamp(const v8::FunctionCallbackInfo<v8::Value> &args) {
1067
+ auto *ptr = GetPointer(args.This());
1068
+ if (ptr == nullptr) {
1069
+ return;
1070
+ }
1071
+
1072
+ auto isolate = args.GetIsolate();
1073
+ auto context = isolate->GetCurrentContext();
1074
+
1075
+ auto querySet = args[0];
1076
+ auto queryType = GetNativeType(querySet);
1077
+ auto queryIndex = args[1];
1078
+
1079
+ if (queryType == NativeType::GPUQuerySet) {
1080
+ auto qs = GPUQuerySetImpl::GetPointer(querySet.As<v8::Object>());
1081
+ canvas_native_webgpu_command_encoder_write_timestamp(ptr->GetEncoder(), qs->GetQuerySet(),
1082
+ queryIndex->Uint32Value(
1083
+ context).FromJust());
1084
+ }
1085
+
1086
+
1087
+ }