@nativescript/canvas 2.0.0-webgpu.4 → 2.0.0-webgpu.40

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 (211) hide show
  1. package/Canvas/common.d.ts +5 -10
  2. package/Canvas/common.js +61 -144
  3. package/Canvas/common.js.map +1 -1
  4. package/Canvas/index.android.d.ts +6 -5
  5. package/Canvas/index.android.js +63 -42
  6. package/Canvas/index.android.js.map +1 -1
  7. package/Canvas/index.d.ts +13 -3
  8. package/Canvas/index.ios.d.ts +9 -1
  9. package/Canvas/index.ios.js +117 -66
  10. package/Canvas/index.ios.js.map +1 -1
  11. package/Canvas/utils.d.ts +3 -0
  12. package/Canvas/utils.js +85 -0
  13. package/Canvas/utils.js.map +1 -0
  14. package/Canvas2D/CanvasRenderingContext2D/index.d.ts +3 -1
  15. package/Canvas2D/CanvasRenderingContext2D/index.js +2 -4
  16. package/Canvas2D/CanvasRenderingContext2D/index.js.map +1 -1
  17. package/Dom/Group.d.ts +1 -2
  18. package/Dom/Group.js.map +1 -1
  19. package/Dom/Image.js +0 -1
  20. package/Dom/Image.js.map +1 -1
  21. package/Dom/Paint.d.ts +1 -1
  22. package/Dom/shapes/Path.d.ts +1 -1
  23. package/ImageAsset/index.d.ts +4 -2
  24. package/ImageAsset/index.js +151 -37
  25. package/ImageAsset/index.js.map +1 -1
  26. package/ImageBitmap/index.js +107 -20
  27. package/ImageBitmap/index.js.map +1 -1
  28. package/README.md +2 -4
  29. package/WebGL/WebGLRenderingContext/common.d.ts +1 -1
  30. package/WebGL/WebGLRenderingContext/index.js +76 -32
  31. package/WebGL/WebGLRenderingContext/index.js.map +1 -1
  32. package/WebGL2/WebGL2RenderingContext/index.js +5 -5
  33. package/WebGL2/WebGL2RenderingContext/index.js.map +1 -1
  34. package/WebGPU/GPU.js +4 -3
  35. package/WebGPU/GPU.js.map +1 -1
  36. package/WebGPU/GPUAdapter.d.ts +6 -3
  37. package/WebGPU/GPUAdapter.js +31 -0
  38. package/WebGPU/GPUAdapter.js.map +1 -1
  39. package/WebGPU/GPUBindGroup.d.ts +1 -0
  40. package/WebGPU/GPUBindGroup.js +3 -0
  41. package/WebGPU/GPUBindGroup.js.map +1 -1
  42. package/WebGPU/GPUBindGroupLayout.d.ts +1 -0
  43. package/WebGPU/GPUBindGroupLayout.js +3 -0
  44. package/WebGPU/GPUBindGroupLayout.js.map +1 -1
  45. package/WebGPU/GPUBuffer.js +10 -2
  46. package/WebGPU/GPUBuffer.js.map +1 -1
  47. package/WebGPU/GPUCanvasContext.d.ts +5 -3
  48. package/WebGPU/GPUCanvasContext.js +52 -10
  49. package/WebGPU/GPUCanvasContext.js.map +1 -1
  50. package/WebGPU/GPUCommandBuffer.d.ts +1 -0
  51. package/WebGPU/GPUCommandBuffer.js +3 -0
  52. package/WebGPU/GPUCommandBuffer.js.map +1 -1
  53. package/WebGPU/GPUCommandEncoder.d.ts +3 -9
  54. package/WebGPU/GPUCommandEncoder.js +94 -41
  55. package/WebGPU/GPUCommandEncoder.js.map +1 -1
  56. package/WebGPU/GPUComputePassEncoder.d.ts +1 -0
  57. package/WebGPU/GPUComputePassEncoder.js +3 -0
  58. package/WebGPU/GPUComputePassEncoder.js.map +1 -1
  59. package/WebGPU/GPUComputePipeline.d.ts +1 -0
  60. package/WebGPU/GPUComputePipeline.js +3 -0
  61. package/WebGPU/GPUComputePipeline.js.map +1 -1
  62. package/WebGPU/GPUDevice.d.ts +17 -79
  63. package/WebGPU/GPUDevice.js +75 -91
  64. package/WebGPU/GPUDevice.js.map +1 -1
  65. package/WebGPU/GPUExternalTexture.d.ts +1 -0
  66. package/WebGPU/GPUExternalTexture.js +3 -0
  67. package/WebGPU/GPUExternalTexture.js.map +1 -1
  68. package/WebGPU/GPUPipelineLayout.d.ts +1 -0
  69. package/WebGPU/GPUPipelineLayout.js +3 -0
  70. package/WebGPU/GPUPipelineLayout.js.map +1 -1
  71. package/WebGPU/GPUQuerySet.d.ts +1 -0
  72. package/WebGPU/GPUQuerySet.js +3 -0
  73. package/WebGPU/GPUQuerySet.js.map +1 -1
  74. package/WebGPU/GPUQueue.d.ts +1 -0
  75. package/WebGPU/GPUQueue.js +65 -14
  76. package/WebGPU/GPUQueue.js.map +1 -1
  77. package/WebGPU/GPURenderBundle.d.ts +1 -0
  78. package/WebGPU/GPURenderBundle.js +3 -0
  79. package/WebGPU/GPURenderBundle.js.map +1 -1
  80. package/WebGPU/GPURenderBundleEncoder.d.ts +4 -2
  81. package/WebGPU/GPURenderBundleEncoder.js +7 -3
  82. package/WebGPU/GPURenderBundleEncoder.js.map +1 -1
  83. package/WebGPU/GPURenderPassEncoder.d.ts +5 -1
  84. package/WebGPU/GPURenderPassEncoder.js +14 -2
  85. package/WebGPU/GPURenderPassEncoder.js.map +1 -1
  86. package/WebGPU/GPURenderPipeline.d.ts +1 -0
  87. package/WebGPU/GPURenderPipeline.js +3 -0
  88. package/WebGPU/GPURenderPipeline.js.map +1 -1
  89. package/WebGPU/GPUSampler.d.ts +1 -0
  90. package/WebGPU/GPUSampler.js +3 -0
  91. package/WebGPU/GPUSampler.js.map +1 -1
  92. package/WebGPU/GPUShaderModule.d.ts +1 -1
  93. package/WebGPU/GPUShaderModule.js +2 -2
  94. package/WebGPU/GPUShaderModule.js.map +1 -1
  95. package/WebGPU/GPUTexture.d.ts +1 -0
  96. package/WebGPU/GPUTexture.js +3 -0
  97. package/WebGPU/GPUTexture.js.map +1 -1
  98. package/WebGPU/GPUTextureView.d.ts +1 -0
  99. package/WebGPU/GPUTextureView.js +3 -0
  100. package/WebGPU/GPUTextureView.js.map +1 -1
  101. package/WebGPU/Interfaces.d.ts +95 -4
  102. package/WebGPU/Types.d.ts +9 -1
  103. package/WebGPU/Utils.d.ts +6 -0
  104. package/WebGPU/Utils.js +226 -0
  105. package/WebGPU/Utils.js.map +1 -1
  106. package/angular/esm2022/index.mjs +4 -4
  107. package/angular/fesm2022/nativescript-canvas-angular.mjs +4 -4
  108. package/angular/fesm2022/nativescript-canvas-angular.mjs.map +1 -1
  109. package/common.js.map +1 -1
  110. package/index.d.ts +2 -1
  111. package/index.js +3 -2
  112. package/index.js.map +1 -1
  113. package/package.json +1 -1
  114. package/platforms/android/canvas-release.aar +0 -0
  115. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative +0 -0
  116. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative-Swift.h +61 -30
  117. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative.h +1 -0
  118. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/NSCMTLView.h +32 -0
  119. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_ios.h +144 -176
  120. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h +342 -72
  121. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Info.plist +0 -0
  122. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios.swiftsourceinfo +0 -0
  123. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.abi.json +7997 -5995
  124. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.private.swiftinterface +85 -23
  125. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  126. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftinterface +85 -23
  127. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/NSCCanvas.nib +0 -0
  128. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  129. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +681 -644
  130. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative +0 -0
  131. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative-Swift.h +122 -60
  132. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative.h +1 -0
  133. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/NSCMTLView.h +32 -0
  134. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_ios.h +144 -176
  135. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h +342 -72
  136. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Info.plist +0 -0
  137. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo +0 -0
  138. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/x86_64-apple-ios-simulator.swiftsourceinfo +0 -0
  139. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.abi.json +7997 -5995
  140. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +85 -23
  141. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  142. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftinterface +85 -23
  143. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.abi.json +7997 -5995
  144. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +85 -23
  145. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  146. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +85 -23
  147. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/NSCCanvas.nib +0 -0
  148. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources +40 -29
  149. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  150. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +683 -646
  151. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/x86_64/CanvasNative.yml +736 -684
  152. package/platforms/ios/src/NSOperationQueueWrapper.h +1 -1
  153. package/platforms/ios/src/NSOperationQueueWrapper.mm +41 -9
  154. package/platforms/ios/src/cpp/AsyncCallback.h +16 -8
  155. package/platforms/ios/src/cpp/CanvasJSIModule.cpp +310 -801
  156. package/platforms/ios/src/cpp/CanvasJSIModule.h +2 -0
  157. package/platforms/ios/src/cpp/ImageAssetImpl.cpp +578 -413
  158. package/platforms/ios/src/cpp/ImageAssetImpl.h +7 -3
  159. package/platforms/ios/src/cpp/ImageBitmapImpl.cpp +60 -3
  160. package/platforms/ios/src/cpp/ImageBitmapImpl.h +10 -3
  161. package/platforms/ios/src/cpp/PromiseCallback.h +1 -2
  162. package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.cpp +7 -11
  163. package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.h +3 -3
  164. package/platforms/ios/src/cpp/canvas2d/Path2D.h +5 -5
  165. package/platforms/ios/src/cpp/webgl/WebGLRenderingContext.cpp +106 -1
  166. package/platforms/ios/src/cpp/webgl/WebGLRenderingContextBase.cpp +6 -6
  167. package/platforms/ios/src/cpp/webgpu/GPUAdapterImpl.cpp +26 -23
  168. package/platforms/ios/src/cpp/webgpu/GPUBindGroupImpl.cpp +31 -5
  169. package/platforms/ios/src/cpp/webgpu/GPUBindGroupImpl.h +4 -1
  170. package/platforms/ios/src/cpp/webgpu/GPUBindGroupLayoutImpl.cpp +26 -0
  171. package/platforms/ios/src/cpp/webgpu/GPUBindGroupLayoutImpl.h +3 -0
  172. package/platforms/ios/src/cpp/webgpu/GPUBufferImpl.cpp +41 -7
  173. package/platforms/ios/src/cpp/webgpu/GPUBufferImpl.h +4 -0
  174. package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.cpp +11 -5
  175. package/platforms/ios/src/cpp/webgpu/GPUCommandBufferImpl.cpp +28 -1
  176. package/platforms/ios/src/cpp/webgpu/GPUCommandBufferImpl.h +3 -0
  177. package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.cpp +75 -79
  178. package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.h +4 -0
  179. package/platforms/ios/src/cpp/webgpu/GPUComputePassEncoderImpl.cpp +56 -23
  180. package/platforms/ios/src/cpp/webgpu/GPUComputePassEncoderImpl.h +3 -0
  181. package/platforms/ios/src/cpp/webgpu/GPUComputePipelineImpl.cpp +25 -0
  182. package/platforms/ios/src/cpp/webgpu/GPUComputePipelineImpl.h +2 -0
  183. package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.cpp +1606 -681
  184. package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.h +2 -0
  185. package/platforms/ios/src/cpp/webgpu/GPUImpl.cpp +2 -1
  186. package/platforms/ios/src/cpp/webgpu/GPUImpl.h +1 -1
  187. package/platforms/ios/src/cpp/webgpu/GPULabel.h +33 -0
  188. package/platforms/ios/src/cpp/webgpu/GPUPipelineLayoutImpl.cpp +26 -0
  189. package/platforms/ios/src/cpp/webgpu/GPUPipelineLayoutImpl.h +3 -1
  190. package/platforms/ios/src/cpp/webgpu/GPUQuerySetImpl.cpp +1 -2
  191. package/platforms/ios/src/cpp/webgpu/GPUQuerySetImpl.h +1 -1
  192. package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.cpp +83 -14
  193. package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.h +3 -0
  194. package/platforms/ios/src/cpp/webgpu/GPURenderBundleEncoderImpl.cpp +66 -34
  195. package/platforms/ios/src/cpp/webgpu/GPURenderBundleEncoderImpl.h +3 -0
  196. package/platforms/ios/src/cpp/webgpu/GPURenderBundleImpl.cpp +25 -0
  197. package/platforms/ios/src/cpp/webgpu/GPURenderBundleImpl.h +3 -0
  198. package/platforms/ios/src/cpp/webgpu/GPURenderPassEncoderImpl.cpp +151 -52
  199. package/platforms/ios/src/cpp/webgpu/GPURenderPassEncoderImpl.h +7 -0
  200. package/platforms/ios/src/cpp/webgpu/GPURenderPipelineImpl.cpp +25 -0
  201. package/platforms/ios/src/cpp/webgpu/GPURenderPipelineImpl.h +3 -0
  202. package/platforms/ios/src/cpp/webgpu/GPUSamplerImpl.cpp +26 -0
  203. package/platforms/ios/src/cpp/webgpu/GPUSamplerImpl.h +4 -1
  204. package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.cpp +24 -0
  205. package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.h +3 -0
  206. package/platforms/ios/src/cpp/webgpu/GPUTextureImpl.cpp +34 -8
  207. package/platforms/ios/src/cpp/webgpu/GPUTextureImpl.h +2 -0
  208. package/platforms/ios/src/cpp/webgpu/GPUTextureViewImpl.cpp +26 -0
  209. package/platforms/ios/src/cpp/webgpu/GPUTextureViewImpl.h +3 -0
  210. package/platforms/ios/src/cpp/webgpu/GPUUtils.h +511 -0
  211. package/utils.d.ts +1 -1
@@ -36,6 +36,8 @@ public:
36
36
  return scope.Escape(object);
37
37
  }
38
38
 
39
+ static void GetLabel(v8::Local<v8::Name> name,
40
+ const v8::PropertyCallbackInfo<v8::Value> &info);
39
41
 
40
42
  static void GetFeatures(v8::Local<v8::Name> name,
41
43
  const v8::PropertyCallbackInfo<v8::Value> &info);
@@ -154,8 +154,9 @@ void GPUImpl::RequestAdapter(const v8::FunctionCallbackInfo<v8::Value> &args) {
154
154
  callback->Call(context, context->Global(),
155
155
  2,
156
156
  args); // ignore JS return value
157
-
157
+
158
158
  delete static_cast<AsyncCallback *>(data);
159
+
159
160
  } else {
160
161
  v8::Local<v8::Value> args[1] = {
161
162
  v8::Null(isolate)};
@@ -12,7 +12,7 @@
12
12
 
13
13
  class GPUImpl : ObjectWrapperImpl {
14
14
  public:
15
- GPUImpl(const CanvasWebGPUInstance *instance);
15
+ explicit GPUImpl(const CanvasWebGPUInstance *instance);
16
16
 
17
17
  ~GPUImpl() {
18
18
  if (this->instance_ != nullptr) {
@@ -0,0 +1,33 @@
1
+ //
2
+ // Created by Osei Fortune on 19/08/2024.
3
+ //
4
+
5
+ #ifndef CANVAS_ANDROID_GPULABEL_H
6
+ #define CANVAS_ANDROID_GPULABEL_H
7
+
8
+ #include "Common.h"
9
+ #include "Helpers.h"
10
+
11
+ class GPULabel {
12
+ public:
13
+ GPULabel(){}
14
+ GPULabel(v8::Isolate *isolate, const v8::Local<v8::Value> &label) {
15
+ if (label->IsString() || label->IsStringObject()) {
16
+ label_ = ConvertFromV8String(isolate, label);
17
+ hasLabel_ = true;
18
+ }
19
+ }
20
+
21
+ const char *operator*() {
22
+ if (hasLabel_) {
23
+ return label_.c_str();
24
+ }
25
+ return nullptr;
26
+ }
27
+
28
+ private:
29
+ std::string label_;
30
+ bool hasLabel_ = false;
31
+ };
32
+
33
+ #endif //CANVAS_ANDROID_GPULABEL_H
@@ -47,8 +47,34 @@ v8::Local<v8::FunctionTemplate> GPUPipelineLayoutImpl::GetCtor(v8::Isolate *isol
47
47
  auto tmpl = ctorTmpl->InstanceTemplate();
48
48
  tmpl->SetInternalFieldCount(2);
49
49
 
50
+ tmpl->SetLazyDataProperty(
51
+ ConvertToV8String(isolate, "label"),
52
+ GetLabel
53
+ );
54
+
50
55
  cache->GPUPipelineLayoutTmpl =
51
56
  std::make_unique<v8::Persistent<v8::FunctionTemplate>>(isolate, ctorTmpl);
52
57
  return ctorTmpl;
53
58
  }
54
59
 
60
+
61
+ void
62
+ GPUPipelineLayoutImpl::GetLabel(v8::Local<v8::Name> name,
63
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
64
+ auto ptr = GetPointer(info.This());
65
+ if (ptr != nullptr) {
66
+ auto label = canvas_native_webgpu_pipeline_layout_get_label(ptr->pipeline_);
67
+ if (label == nullptr) {
68
+ info.GetReturnValue().SetEmptyString();
69
+ return;
70
+ }
71
+ info.GetReturnValue().Set(
72
+ ConvertToV8String(info.GetIsolate(), label)
73
+ );
74
+ canvas_native_string_destroy(label);
75
+ return;
76
+ }
77
+
78
+ info.GetReturnValue().SetEmptyString();
79
+ }
80
+
@@ -12,7 +12,7 @@
12
12
 
13
13
  class GPUPipelineLayoutImpl : ObjectWrapperImpl {
14
14
  public:
15
- GPUPipelineLayoutImpl(const CanvasGPUPipelineLayout *pipeline);
15
+ explicit GPUPipelineLayoutImpl(const CanvasGPUPipelineLayout *pipeline);
16
16
 
17
17
  ~GPUPipelineLayoutImpl() {
18
18
  canvas_native_webgpu_pipeline_layout_release(this->GetPipeline());
@@ -38,6 +38,8 @@ public:
38
38
  return scope.Escape(object);
39
39
  }
40
40
 
41
+ static void GetLabel(v8::Local<v8::Name> name,
42
+ const v8::PropertyCallbackInfo<v8::Value> &info);
41
43
 
42
44
  private:
43
45
  const CanvasGPUPipelineLayout *pipeline_;
@@ -78,7 +78,6 @@ void
78
78
  GPUQuerySetImpl::GetCount(v8::Local<v8::Name> name,
79
79
  const v8::PropertyCallbackInfo<v8::Value> &info) {
80
80
  auto ptr = GetPointer(info.This());
81
- auto isolate = info.GetIsolate();
82
81
  if (ptr != nullptr) {
83
82
  info.GetReturnValue().Set(canvas_native_webgpu_query_set_get_count(ptr->GetQuerySet()));
84
83
  return;
@@ -132,6 +131,6 @@ void GPUQuerySetImpl::Destroy(const v8::FunctionCallbackInfo<v8::Value> &args) {
132
131
  if (ptr == nullptr) {
133
132
  return;
134
133
  }
135
- // todo
134
+ canvas_native_webgpu_query_set_destroy(ptr->querySet_);
136
135
 
137
136
  }
@@ -10,7 +10,7 @@
10
10
 
11
11
  class GPUQuerySetImpl : ObjectWrapperImpl {
12
12
  public:
13
- GPUQuerySetImpl(const CanvasGPUQuerySet *querySet);
13
+ explicit GPUQuerySetImpl(const CanvasGPUQuerySet *querySet);
14
14
 
15
15
  ~GPUQuerySetImpl() {
16
16
  canvas_native_webgpu_query_set_release(this->GetQuerySet());
@@ -55,6 +55,10 @@ v8::Local<v8::FunctionTemplate> GPUQueueImpl::GetCtor(v8::Isolate *isolate) {
55
55
  auto tmpl = ctorTmpl->InstanceTemplate();
56
56
  tmpl->SetInternalFieldCount(2);
57
57
 
58
+ tmpl->SetLazyDataProperty(
59
+ ConvertToV8String(isolate, "label"),
60
+ GetLabel
61
+ );
58
62
 
59
63
  tmpl->Set(
60
64
  ConvertToV8String(isolate, "copyExternalImageToTexture"),
@@ -84,6 +88,28 @@ v8::Local<v8::FunctionTemplate> GPUQueueImpl::GetCtor(v8::Isolate *isolate) {
84
88
  return ctorTmpl;
85
89
  }
86
90
 
91
+
92
+ void
93
+ GPUQueueImpl::GetLabel(v8::Local<v8::Name> name,
94
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
95
+ auto ptr = GetPointer(info.This());
96
+ if (ptr != nullptr) {
97
+ auto label = canvas_native_webgpu_queue_get_label(ptr->queue_);
98
+ if (label == nullptr) {
99
+ info.GetReturnValue().SetEmptyString();
100
+ return;
101
+ }
102
+ info.GetReturnValue().Set(
103
+ ConvertToV8String(info.GetIsolate(), label)
104
+ );
105
+ canvas_native_string_destroy(label);
106
+ return;
107
+ }
108
+
109
+ info.GetReturnValue().SetEmptyString();
110
+ }
111
+
112
+
87
113
  void GPUQueueImpl::CopyExternalImageToTexture(const v8::FunctionCallbackInfo<v8::Value> &args) {
88
114
  auto *ptr = GetPointer(args.This());
89
115
  if (ptr == nullptr) {
@@ -110,28 +136,29 @@ void GPUQueueImpl::CopyExternalImageToTexture(const v8::FunctionCallbackInfo<v8:
110
136
  U8Buffer *buffer = nullptr;
111
137
  uint32_t width = 0;
112
138
  uint32_t height = 0;
139
+ const ImageAsset *imageAsset = nullptr;
140
+ const WebGLState *gl = nullptr;
141
+ const CanvasRenderingContext2D *c2d = nullptr;
113
142
  if (sourceType == NativeType::ImageBitmap) {
114
- auto imageAsset = ImageBitmapImpl::GetPointer(sourceSourceValue.As<v8::Object>());
115
- buffer = canvas_native_image_asset_get_data(imageAsset->GetImageAsset());
116
- width = canvas_native_image_asset_width(imageAsset->GetImageAsset());
117
- height = canvas_native_image_asset_height(imageAsset->GetImageAsset());
143
+ auto bitmap = ImageBitmapImpl::GetPointer(sourceSourceValue.As<v8::Object>());
144
+ imageAsset = bitmap->GetImageAsset();
118
145
  } else if (sourceType == NativeType::ImageAsset) {
119
- auto imageAsset = ImageAssetImpl::GetPointer(sourceSourceValue.As<v8::Object>());
120
- buffer = canvas_native_image_asset_get_data(imageAsset->GetImageAsset());
121
- width = canvas_native_image_asset_width(imageAsset->GetImageAsset());
122
- height = canvas_native_image_asset_height(imageAsset->GetImageAsset());
146
+ auto asset = ImageAssetImpl::GetPointer(sourceSourceValue.As<v8::Object>());
147
+ imageAsset = asset->GetImageAsset();
123
148
  } else if (sourceType == NativeType::ImageData) {
124
149
  auto imageData = ImageDataImpl::GetPointer(sourceSourceValue.As<v8::Object>());
125
150
  buffer = canvas_native_image_data_get_data(imageData->GetImageData());
126
151
  width = canvas_native_image_data_get_width(imageData->GetImageData());
127
152
  height = canvas_native_image_data_get_height(imageData->GetImageData());
128
153
  } else if (sourceType == NativeType::CanvasRenderingContext2D) {
129
- auto c2d = CanvasRenderingContext2DImpl::GetPointer(sourceSourceValue.As<v8::Object>());
154
+ auto ctx = CanvasRenderingContext2DImpl::GetPointer(sourceSourceValue.As<v8::Object>());
155
+ c2d = ctx->GetContext();
130
156
  } else if (sourceType == NativeType::WebGLRenderingContextBase) {
131
157
  auto webgl = WebGLRenderingContextBase::GetPointer(sourceSourceValue.As<v8::Object>());
158
+ gl = webgl->GetState();
132
159
  }
133
160
 
134
- if (buffer == nullptr) {
161
+ if (buffer == nullptr && imageAsset == nullptr && gl == nullptr && c2d == nullptr) {
135
162
  // todo error ??
136
163
  return;
137
164
  }
@@ -237,9 +264,54 @@ void GPUQueueImpl::CopyExternalImageToTexture(const v8::FunctionCallbackInfo<v8:
237
264
 
238
265
  CanvasExtent3d extent3D = ParseExtent3d(isolate, sizeVal);
239
266
 
267
+ if (imageAsset != nullptr) {
268
+ CanvasImageCopyImageAsset source{
269
+ imageAsset,
270
+ sourceOrigin,
271
+ flipY,
272
+ };
273
+
274
+
275
+ canvas_native_webgpu_queue_copy_image_asset_to_texture(ptr->GetGPUQueue(), &source,
276
+ &destination,
277
+ &extent3D);
278
+ return;
279
+ }
280
+
281
+
282
+ if (c2d != nullptr) {
283
+ CanvasImageCopyCanvasRenderingContext2D source{
284
+ c2d,
285
+ sourceOrigin,
286
+ flipY,
287
+ };
288
+
289
+
290
+ canvas_native_webgpu_queue_copy_context_to_texture(ptr->GetGPUQueue(), &source,
291
+ &destination,
292
+ &extent3D);
293
+ return;
294
+ }
295
+
296
+ if (gl != nullptr) {
297
+ CanvasImageCopyWebGL source{
298
+ gl,
299
+ sourceOrigin,
300
+ flipY,
301
+ };
302
+
303
+
304
+ canvas_native_webgpu_queue_copy_webgl_to_texture(ptr->GetGPUQueue(), &source,
305
+ &destination,
306
+ &extent3D);
307
+ return;
308
+ }
309
+
310
+
240
311
  auto data = canvas_native_u8_buffer_get_bytes(buffer);
241
312
  auto size = canvas_native_u8_buffer_get_length(buffer);
242
313
 
314
+
243
315
  if (data == nullptr || size == 0) {
244
316
  // todo error
245
317
  return;
@@ -368,7 +440,6 @@ void GPUQueueImpl::WriteBuffer(const v8::FunctionCallbackInfo<v8::Value> &args)
368
440
  if (bufferValue->IsObject()) {
369
441
  auto buffer = GPUBufferImpl::GetPointer(bufferValue.As<v8::Object>());
370
442
 
371
-
372
443
  auto bufferOffset = (uint64_t) args[1].As<v8::Number>()->Value();
373
444
 
374
445
  auto dataValue = args[2].As<v8::TypedArray>();
@@ -379,7 +450,7 @@ void GPUQueueImpl::WriteBuffer(const v8::FunctionCallbackInfo<v8::Value> &args)
379
450
 
380
451
  auto data = static_cast<uint8_t *>(store->Data()) + offset;
381
452
 
382
- auto data_size = store->ByteLength();
453
+ auto data_size = store->ByteLength() - offset;
383
454
 
384
455
  auto dataOffset = (uint64_t) args[3].As<v8::Number>()->Value();
385
456
 
@@ -410,8 +481,6 @@ void GPUQueueImpl::WriteTexture(const v8::FunctionCallbackInfo<v8::Value> &args)
410
481
  auto isolate = args.GetIsolate();
411
482
  auto context = isolate->GetCurrentContext();
412
483
 
413
- bool flipY = false;
414
-
415
484
 
416
485
  auto destinationVal = args[0];
417
486
  auto dataVal = args[1];
@@ -37,6 +37,9 @@ public:
37
37
  return scope.Escape(object);
38
38
  }
39
39
 
40
+ static void GetLabel(v8::Local<v8::Name> name,
41
+ const v8::PropertyCallbackInfo<v8::Value> &info);
42
+
40
43
  static void CopyExternalImageToTexture(const v8::FunctionCallbackInfo<v8::Value> &args);
41
44
 
42
45
  static void Submit(const v8::FunctionCallbackInfo<v8::Value> &args);
@@ -8,6 +8,7 @@
8
8
  #include "GPUBufferImpl.h"
9
9
  #include "GPURenderBundleImpl.h"
10
10
  #include "GPUBindGroupImpl.h"
11
+ #include "GPULabel.h"
11
12
 
12
13
  GPURenderBundleEncoderImpl::GPURenderBundleEncoderImpl(const CanvasGPURenderBundleEncoder *encoder)
13
14
  : encoder_(
@@ -54,6 +55,11 @@ v8::Local<v8::FunctionTemplate> GPURenderBundleEncoderImpl::GetCtor(v8::Isolate
54
55
  auto tmpl = ctorTmpl->InstanceTemplate();
55
56
  tmpl->SetInternalFieldCount(2);
56
57
 
58
+ tmpl->SetLazyDataProperty(
59
+ ConvertToV8String(isolate, "label"),
60
+ GetLabel
61
+ );
62
+
57
63
  tmpl->Set(
58
64
  ConvertToV8String(isolate, "draw"),
59
65
  v8::FunctionTemplate::New(isolate, &Draw));
@@ -109,6 +115,28 @@ v8::Local<v8::FunctionTemplate> GPURenderBundleEncoderImpl::GetCtor(v8::Isolate
109
115
  return ctorTmpl;
110
116
  }
111
117
 
118
+
119
+ void
120
+ GPURenderBundleEncoderImpl::GetLabel(v8::Local<v8::Name> name,
121
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
122
+ auto ptr = GetPointer(info.This());
123
+ if (ptr != nullptr) {
124
+ auto label = canvas_native_webgpu_render_bundle_encoder_get_label(ptr->encoder_);
125
+ if (label == nullptr) {
126
+ info.GetReturnValue().SetEmptyString();
127
+ return;
128
+ }
129
+ info.GetReturnValue().Set(
130
+ ConvertToV8String(info.GetIsolate(), label)
131
+ );
132
+ canvas_native_string_destroy(label);
133
+ return;
134
+ }
135
+
136
+ info.GetReturnValue().SetEmptyString();
137
+ }
138
+
139
+
112
140
  void GPURenderBundleEncoderImpl::Draw(const v8::FunctionCallbackInfo<v8::Value> &args) {
113
141
  auto *ptr = GetPointer(args.This());
114
142
  if (ptr == nullptr) {
@@ -163,12 +191,16 @@ void GPURenderBundleEncoderImpl::DrawIndexed(const v8::FunctionCallbackInfo<v8::
163
191
 
164
192
 
165
193
  auto indexCountVal = args[0];
166
- auto firstIndexVal = args[1];
167
- auto baseVertexVal = args[2];
168
- auto firstInstanceVal = args[3];
194
+ auto instanceCountVal = args[1];
195
+ auto firstIndexVal = args[2];
196
+ auto baseVertexVal = args[3];
197
+ auto firstInstanceVal = args[4];
169
198
 
170
199
  if (indexCountVal->IsUint32()) {
171
200
 
201
+ if (instanceCountVal->IsUint32()) {
202
+ instanceCount = instanceCountVal.As<v8::Uint32>()->Value();
203
+ }
172
204
 
173
205
  if (firstIndexVal->IsUint32()) {
174
206
  firstIndex = firstIndexVal.As<v8::Uint32>()->Value();
@@ -256,7 +288,7 @@ void GPURenderBundleEncoderImpl::Finish(const v8::FunctionCallbackInfo<v8::Value
256
288
  auto isolate = args.GetIsolate();
257
289
  auto context = isolate->GetCurrentContext();
258
290
 
259
- char *label = nullptr;
291
+ GPULabel label;
260
292
  v8::Local<v8::Value> labelVal;
261
293
 
262
294
  auto optionsVal = args[0];
@@ -265,13 +297,11 @@ void GPURenderBundleEncoderImpl::Finish(const v8::FunctionCallbackInfo<v8::Value
265
297
  auto options = optionsVal.As<v8::Object>();
266
298
  options->Get(context, ConvertToV8String(isolate, "label")).ToLocal(&labelVal);
267
299
 
268
- if (!labelVal.IsEmpty() && labelVal->IsString()) {
269
- label = *v8::String::Utf8Value(isolate, labelVal);
270
- }
300
+ label = GPULabel(isolate, labelVal);
271
301
  }
272
302
 
273
303
 
274
- auto bundle = canvas_native_webgpu_render_bundle_encoder_finish(ptr->GetEncoder(), label);
304
+ auto bundle = canvas_native_webgpu_render_bundle_encoder_finish(ptr->GetEncoder(), *label);
275
305
 
276
306
  if (bundle != nullptr) {
277
307
  auto ret = GPURenderBundleImpl::NewInstance(isolate, new GPURenderBundleImpl(bundle));
@@ -339,30 +369,33 @@ void GPURenderBundleEncoderImpl::SetBindGroup(const v8::FunctionCallbackInfo<v8:
339
369
  auto dynamicOffsetsStart = args[3];
340
370
  auto dynamicOffsetsLength = args[4];
341
371
 
372
+ const CanvasGPUBindGroup *bindGroup = nullptr;
342
373
  auto type = GetNativeType(bindGroupVal);
343
374
 
375
+ auto index = indexVal->Uint32Value(context).FromJust();
376
+
344
377
  if (type == NativeType::GPUBindGroup) {
345
- auto index = indexVal->Uint32Value(context).FromJust();
346
- auto bindGroup = GPUBindGroupImpl::GetPointer(bindGroupVal.As<v8::Object>());
347
-
348
- if (dynamicOffsets->IsUint8Array()) {
349
- auto buf = dynamicOffsets.As<v8::Uint32Array>();
350
- auto buffer = buf->Buffer();
351
- auto store = buffer->GetBackingStore();
352
- auto offset = buf->ByteOffset();
353
- auto data = static_cast<uint8_t *>(buffer->GetBackingStore()->Data()) + offset;
354
- auto size = buf->Length();
355
- auto start = (size_t) dynamicOffsetsStart->NumberValue(context).FromJust();
356
- auto offset_length = (size_t) dynamicOffsetsLength->NumberValue(context).FromJust();
357
- canvas_native_webgpu_render_bundle_encoder_set_bind_group(ptr->GetEncoder(), index,
358
- bindGroup->GetBindGroup(),
359
- static_cast<const uint32_t *>(static_cast<void *>(data)),
360
- size, start, offset_length);
361
- } else {
362
- canvas_native_webgpu_render_bundle_encoder_set_bind_group(ptr->GetEncoder(), index,
363
- bindGroup->GetBindGroup(),
364
- nullptr, 0, 0, 0);
365
- }
378
+ auto group = GPUBindGroupImpl::GetPointer(bindGroupVal.As<v8::Object>());
379
+ bindGroup = group->GetBindGroup();
380
+ }
381
+
382
+ if (dynamicOffsets->IsUint32Array()) {
383
+ auto buf = dynamicOffsets.As<v8::Uint32Array>();
384
+ auto buffer = buf->Buffer();
385
+ auto store = buffer->GetBackingStore();
386
+ auto offset = buf->ByteOffset();
387
+ auto data = static_cast<uint8_t *>(buffer->GetBackingStore()->Data()) + offset;
388
+ auto size = buf->Length();
389
+ auto start = (size_t) dynamicOffsetsStart->NumberValue(context).FromJust();
390
+ auto offset_length = (size_t) dynamicOffsetsLength->NumberValue(context).FromJust();
391
+ canvas_native_webgpu_render_bundle_encoder_set_bind_group(ptr->GetEncoder(), index,
392
+ bindGroup,
393
+ static_cast<const uint32_t *>(static_cast<void *>(data)),
394
+ size, start, offset_length);
395
+ } else {
396
+ canvas_native_webgpu_render_bundle_encoder_set_bind_group(ptr->GetEncoder(), index,
397
+ bindGroup,
398
+ nullptr, 0, 0, 0);
366
399
  }
367
400
 
368
401
  }
@@ -374,7 +407,6 @@ void GPURenderBundleEncoderImpl::SetIndexBuffer(const v8::FunctionCallbackInfo<v
374
407
  }
375
408
 
376
409
  auto isolate = args.GetIsolate();
377
- auto context = isolate->GetCurrentContext();
378
410
 
379
411
  auto bufferVal = args[0];
380
412
  auto indexFormatVal = args[1];
@@ -385,7 +417,7 @@ void GPURenderBundleEncoderImpl::SetIndexBuffer(const v8::FunctionCallbackInfo<v
385
417
 
386
418
  auto type = GetNativeType(bufferVal);
387
419
 
388
- if (type == NativeType::GPURenderBundleEncoder) {
420
+ if (type == NativeType::GPUBuffer) {
389
421
  auto buffer = GPUBufferImpl::GetPointer(bufferVal.As<v8::Object>());
390
422
  auto indexFormat = ConvertFromV8String(isolate, indexFormatVal);
391
423
  if (offsetVal->IsNumber()) {
@@ -421,7 +453,7 @@ void GPURenderBundleEncoderImpl::SetPipeline(const v8::FunctionCallbackInfo<v8::
421
453
  }
422
454
 
423
455
  auto pipelineVal = args[0];
424
- if (pipelineVal->IsObject()) {
456
+ if (GetNativeType(pipelineVal) == NativeType::GPURenderPipeline) {
425
457
  auto pipeline = GPURenderPipelineImpl::GetPointer(pipelineVal.As<v8::Object>());
426
458
  if (pipeline != nullptr) {
427
459
  canvas_native_webgpu_render_bundle_encoder_set_pipeline(ptr->GetEncoder(),
@@ -445,11 +477,11 @@ void GPURenderBundleEncoderImpl::SetVertexBuffer(const v8::FunctionCallbackInfo<
445
477
 
446
478
  if (slotVal->IsUint32() && bufferVal->IsObject()) {
447
479
  auto slot = slotVal.As<v8::Uint32>()->Value();
448
- auto buffer = GPUBufferImpl::GetPointer(bufferVal.As<v8::Object>());
449
- if (buffer == nullptr) {
480
+ if (GetNativeType(bufferVal) != NativeType::GPUBuffer) {
450
481
  // todo throw ??
451
482
  return;
452
483
  }
484
+ auto buffer = GPUBufferImpl::GetPointer(bufferVal.As<v8::Object>());
453
485
 
454
486
  if (offsetVal->IsNumber()) {
455
487
  offset = (int64_t) offsetVal.As<v8::Number>()->Value();
@@ -38,6 +38,9 @@ public:
38
38
  return scope.Escape(object);
39
39
  }
40
40
 
41
+ static void GetLabel(v8::Local<v8::Name> name,
42
+ const v8::PropertyCallbackInfo<v8::Value> &info);
43
+
41
44
  static void Draw(const v8::FunctionCallbackInfo<v8::Value> &args);
42
45
 
43
46
  static void DrawIndexed(const v8::FunctionCallbackInfo<v8::Value> &args);
@@ -47,7 +47,32 @@ v8::Local<v8::FunctionTemplate> GPURenderBundleImpl::GetCtor(v8::Isolate *isolat
47
47
  auto tmpl = ctorTmpl->InstanceTemplate();
48
48
  tmpl->SetInternalFieldCount(2);
49
49
 
50
+ tmpl->SetLazyDataProperty(
51
+ ConvertToV8String(isolate, "label"),
52
+ GetLabel
53
+ );
54
+
50
55
  cache->GPURenderBundleTmpl =
51
56
  std::make_unique<v8::Persistent<v8::FunctionTemplate>>(isolate, ctorTmpl);
52
57
  return ctorTmpl;
53
58
  }
59
+
60
+ void
61
+ GPURenderBundleImpl::GetLabel(v8::Local<v8::Name> name,
62
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
63
+ auto ptr = GetPointer(info.This());
64
+ if (ptr != nullptr) {
65
+ auto label = canvas_native_webgpu_render_bundle_get_label(ptr->bundle_);
66
+ if (label == nullptr) {
67
+ info.GetReturnValue().SetEmptyString();
68
+ return;
69
+ }
70
+ info.GetReturnValue().Set(
71
+ ConvertToV8String(info.GetIsolate(), label)
72
+ );
73
+ canvas_native_string_destroy(label);
74
+ return;
75
+ }
76
+
77
+ info.GetReturnValue().SetEmptyString();
78
+ }
@@ -36,6 +36,9 @@ public:
36
36
  return scope.Escape(object);
37
37
  }
38
38
 
39
+ static void GetLabel(v8::Local<v8::Name> name,
40
+ const v8::PropertyCallbackInfo<v8::Value> &info);
41
+
39
42
 
40
43
  private:
41
44
  const CanvasGPURenderBundle *bundle_;