@nativescript/canvas 2.0.0-rc.2 → 2.0.0-rc.21

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