@nativescript/canvas 2.0.0-webgpu.11 → 2.0.0-webgpu.12

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