@nativescript/canvas 2.0.0-rc.2 → 2.0.0-rc.20
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.
- package/Canvas/common.d.ts +13 -6
- package/Canvas/common.js +257 -206
- package/Canvas/common.js.map +1 -1
- package/Canvas/index.android.d.ts +2 -0
- package/Canvas/index.android.js +23 -4
- package/Canvas/index.android.js.map +1 -1
- package/Canvas/index.d.ts +3 -0
- package/Canvas/index.ios.d.ts +2 -0
- package/Canvas/index.ios.js +16 -3
- package/Canvas/index.ios.js.map +1 -1
- package/Canvas/utils.js +2 -1
- package/Canvas/utils.js.map +1 -1
- package/Canvas2D/CanvasRenderingContext2D/index.d.ts +1 -0
- package/Canvas2D/CanvasRenderingContext2D/index.js +158 -6
- package/Canvas2D/CanvasRenderingContext2D/index.js.map +1 -1
- package/Canvas2D/DOMMatrix/index.js +280 -2
- package/Canvas2D/DOMMatrix/index.js.map +1 -1
- package/Canvas2D/Path2D/index.js.map +1 -1
- package/Fonts/FontFace.android.js +7 -3
- package/Fonts/FontFace.android.js.map +1 -1
- package/Fonts/FontFace.ios.d.ts +1 -0
- package/Fonts/FontFace.ios.js +10 -3
- package/Fonts/FontFace.ios.js.map +1 -1
- package/TextDecoder/index.d.ts +1 -0
- package/TextDecoder/index.js +17 -0
- package/TextDecoder/index.js.map +1 -1
- package/WebGL/WebGLRenderingContext/index.js +0 -1
- package/WebGL/WebGLRenderingContext/index.js.map +1 -1
- package/WebGPU/GPUCanvasContext.d.ts +0 -1
- package/WebGPU/GPUCanvasContext.js +6 -18
- package/WebGPU/GPUCanvasContext.js.map +1 -1
- package/WebGPU/GPUCommandEncoder.d.ts +1 -1
- package/WebGPU/GPUCommandEncoder.js +1 -1
- package/WebGPU/GPUCommandEncoder.js.map +1 -1
- package/WebGPU/GPUCompilationInfo.d.ts +10 -0
- package/WebGPU/GPUCompilationInfo.js +20 -0
- package/WebGPU/GPUCompilationInfo.js.map +1 -0
- package/WebGPU/GPUCompilationMessage.d.ts +11 -0
- package/WebGPU/GPUCompilationMessage.js +30 -0
- package/WebGPU/GPUCompilationMessage.js.map +1 -0
- package/WebGPU/GPUDevice.d.ts +2 -2
- package/WebGPU/GPUDevice.js.map +1 -1
- package/WebGPU/GPUQueue.js +1 -4
- package/WebGPU/GPUQueue.js.map +1 -1
- package/WebGPU/GPURenderPassEncoder.d.ts +1 -1
- package/WebGPU/GPURenderPassEncoder.js +2 -2
- package/WebGPU/GPURenderPassEncoder.js.map +1 -1
- package/WebGPU/GPUShaderModule.d.ts +2 -0
- package/WebGPU/GPUShaderModule.js +10 -0
- package/WebGPU/GPUShaderModule.js.map +1 -1
- package/WebGPU/Interfaces.d.ts +1 -0
- package/WebGPU/Types.d.ts +3 -3
- package/WebGPU/Utils.d.ts +1 -1
- package/WebGPU/Utils.js +67 -93
- package/WebGPU/Utils.js.map +1 -1
- package/WebGPU/index.d.ts +2 -0
- package/WebGPU/index.js +2 -0
- package/WebGPU/index.js.map +1 -1
- package/angular/fesm2022/nativescript-canvas-angular.mjs +5 -5
- package/angular/package.json +0 -2
- package/helpers.d.ts +3 -0
- package/helpers.js +9 -0
- package/helpers.js.map +1 -1
- package/index.js +6 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/platforms/android/canvas-release.aar +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative-Swift.h +10 -5
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h +294 -47
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Info.plist +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios.swiftsourceinfo +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.abi.json +11317 -11881
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.private.swiftinterface +55 -49
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftinterface +55 -49
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +954 -994
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative-Swift.h +20 -10
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h +294 -47
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Info.plist +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/x86_64-apple-ios-simulator.swiftsourceinfo +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.abi.json +11317 -11881
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +55 -49
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftinterface +55 -49
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.abi.json +11317 -11881
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +55 -49
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +55 -49
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources +29 -29
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +955 -993
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/x86_64/CanvasNative.yml +824 -1037
- package/platforms/ios/src/cpp/Caches.h +6 -0
- package/platforms/ios/src/cpp/CanvasJSIModule.cpp +1172 -1011
- package/platforms/ios/src/cpp/CanvasJSIModule.h +6 -0
- package/platforms/ios/src/cpp/Helpers.h +23 -2
- package/platforms/ios/src/cpp/NativeType.h +3 -1
- package/platforms/ios/src/cpp/OnRafCallback.cpp +15 -10
- package/platforms/ios/src/cpp/OnRafCallback.h +1 -0
- package/platforms/ios/src/cpp/PromiseCallback.h +42 -20
- package/platforms/ios/src/cpp/TextDecoderImpl.cpp +142 -0
- package/platforms/ios/src/cpp/TextDecoderImpl.h +2 -0
- package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.cpp +59 -15
- package/platforms/ios/src/cpp/canvas2d/Path2D.cpp +1 -1
- package/platforms/ios/src/cpp/webgpu/GPUAdapterImpl.cpp +4 -8
- package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.cpp +431 -326
- package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.h +98 -42
- package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.cpp +1150 -1144
- package/platforms/ios/src/cpp/webgpu/GPUCompilationInfoImpl.cpp +88 -0
- package/platforms/ios/src/cpp/webgpu/GPUCompilationInfoImpl.h +49 -0
- package/platforms/ios/src/cpp/webgpu/GPUCompilationMessageImpl.cpp +193 -0
- package/platforms/ios/src/cpp/webgpu/GPUCompilationMessageImpl.h +64 -0
- package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.cpp +69 -34
- package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.cpp +45 -18
- package/platforms/ios/src/cpp/webgpu/GPURenderPassEncoderImpl.cpp +22 -19
- package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.cpp +23 -0
- package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.h +2 -0
- package/platforms/ios/src/cpp/webgpu/GPUTextureImpl.cpp +11 -0
- package/platforms/ios/src/cpp/webgpu/GPUUtils.h +25 -15
- package/angular/esm2022/index.mjs +0 -17
- 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
|
-
|
|
17
|
+
encoder) {}
|
|
18
18
|
|
|
19
19
|
const CanvasGPUCommandEncoder *GPUCommandEncoderImpl::GetEncoder() {
|
|
20
|
-
|
|
20
|
+
return this->encoder_;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
void GPUCommandEncoderImpl::Init(v8::Local<v8::Object> canvasModule, v8::Isolate *isolate) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
+
×tampWritesVal);
|
|
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
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
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
|
+
×tampWritesVal);
|
|
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
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
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
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
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
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
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
|
+
©,
|
|
805
|
+
&ct,
|
|
806
|
+
&cz
|
|
807
|
+
);
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
|
|
805
811
|
}
|
|
806
812
|
|
|
807
813
|
void GPUCommandEncoderImpl::CopyTextureToBuffer(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
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
|
+
©,
|
|
940
|
+
&cz
|
|
941
|
+
);
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
|
|
939
945
|
}
|
|
940
946
|
|
|
941
947
|
void GPUCommandEncoderImpl::CopyTextureToTexture(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
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
|
+
©,
|
|
1091
|
+
&ct,
|
|
1092
|
+
&cz
|
|
1093
|
+
);
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
|
|
1091
1097
|
}
|
|
1092
1098
|
|
|
1093
1099
|
void GPUCommandEncoderImpl::Finish(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
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
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
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
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
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
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
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
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
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
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
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
|
}
|