@nativescript/canvas 2.0.0-webgpu.3 → 2.0.0-webgpu.30
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 +4 -9
- package/Canvas/common.js +37 -126
- package/Canvas/common.js.map +1 -1
- package/Canvas/index.android.d.ts +0 -1
- package/Canvas/index.android.js +45 -38
- package/Canvas/index.android.js.map +1 -1
- package/Canvas/index.d.ts +11 -3
- package/Canvas/index.ios.js +49 -40
- package/Canvas/index.ios.js.map +1 -1
- package/Canvas/utils.d.ts +3 -0
- package/Canvas/utils.js +85 -0
- package/Canvas/utils.js.map +1 -0
- package/Canvas2D/CanvasRenderingContext2D/index.d.ts +1 -0
- package/Canvas2D/CanvasRenderingContext2D/index.js +1 -0
- package/Canvas2D/CanvasRenderingContext2D/index.js.map +1 -1
- package/Dom/Group.d.ts +1 -2
- package/Dom/Group.js.map +1 -1
- package/Dom/Image.js +0 -1
- package/Dom/Image.js.map +1 -1
- package/Dom/Paint.d.ts +1 -1
- package/Dom/shapes/Path.d.ts +1 -1
- package/ImageAsset/index.js +77 -33
- package/ImageAsset/index.js.map +1 -1
- package/ImageBitmap/index.js +107 -20
- package/ImageBitmap/index.js.map +1 -1
- package/README.md +2 -4
- package/WebGL/WebGLRenderingContext/index.js +73 -31
- package/WebGL/WebGLRenderingContext/index.js.map +1 -1
- package/WebGL2/WebGL2RenderingContext/index.js +4 -4
- package/WebGL2/WebGL2RenderingContext/index.js.map +1 -1
- package/WebGPU/GPU.js +4 -3
- package/WebGPU/GPU.js.map +1 -1
- package/WebGPU/GPUAdapter.d.ts +6 -3
- package/WebGPU/GPUAdapter.js +31 -0
- package/WebGPU/GPUAdapter.js.map +1 -1
- package/WebGPU/GPUBindGroup.d.ts +1 -0
- package/WebGPU/GPUBindGroup.js +3 -0
- package/WebGPU/GPUBindGroup.js.map +1 -1
- package/WebGPU/GPUBindGroupLayout.d.ts +1 -0
- package/WebGPU/GPUBindGroupLayout.js +3 -0
- package/WebGPU/GPUBindGroupLayout.js.map +1 -1
- package/WebGPU/GPUBuffer.js +10 -2
- package/WebGPU/GPUBuffer.js.map +1 -1
- package/WebGPU/GPUCanvasContext.d.ts +3 -2
- package/WebGPU/GPUCanvasContext.js +52 -10
- package/WebGPU/GPUCanvasContext.js.map +1 -1
- package/WebGPU/GPUCommandBuffer.d.ts +1 -0
- package/WebGPU/GPUCommandBuffer.js +3 -0
- package/WebGPU/GPUCommandBuffer.js.map +1 -1
- package/WebGPU/GPUCommandEncoder.d.ts +3 -9
- package/WebGPU/GPUCommandEncoder.js +94 -41
- package/WebGPU/GPUCommandEncoder.js.map +1 -1
- package/WebGPU/GPUComputePassEncoder.d.ts +1 -0
- package/WebGPU/GPUComputePassEncoder.js +3 -0
- package/WebGPU/GPUComputePassEncoder.js.map +1 -1
- package/WebGPU/GPUComputePipeline.d.ts +1 -0
- package/WebGPU/GPUComputePipeline.js +3 -0
- package/WebGPU/GPUComputePipeline.js.map +1 -1
- package/WebGPU/GPUDevice.d.ts +17 -79
- package/WebGPU/GPUDevice.js +76 -91
- package/WebGPU/GPUDevice.js.map +1 -1
- package/WebGPU/GPUExternalTexture.d.ts +1 -0
- package/WebGPU/GPUExternalTexture.js +3 -0
- package/WebGPU/GPUExternalTexture.js.map +1 -1
- package/WebGPU/GPUPipelineLayout.d.ts +1 -0
- package/WebGPU/GPUPipelineLayout.js +3 -0
- package/WebGPU/GPUPipelineLayout.js.map +1 -1
- package/WebGPU/GPUQuerySet.d.ts +1 -0
- package/WebGPU/GPUQuerySet.js +3 -0
- package/WebGPU/GPUQuerySet.js.map +1 -1
- package/WebGPU/GPUQueue.d.ts +1 -0
- package/WebGPU/GPUQueue.js +56 -14
- package/WebGPU/GPUQueue.js.map +1 -1
- package/WebGPU/GPURenderBundle.d.ts +1 -0
- package/WebGPU/GPURenderBundle.js +3 -0
- package/WebGPU/GPURenderBundle.js.map +1 -1
- package/WebGPU/GPURenderBundleEncoder.d.ts +4 -2
- package/WebGPU/GPURenderBundleEncoder.js +7 -3
- package/WebGPU/GPURenderBundleEncoder.js.map +1 -1
- package/WebGPU/GPURenderPassEncoder.d.ts +2 -1
- package/WebGPU/GPURenderPassEncoder.js +5 -2
- package/WebGPU/GPURenderPassEncoder.js.map +1 -1
- package/WebGPU/GPURenderPipeline.d.ts +1 -0
- package/WebGPU/GPURenderPipeline.js +3 -0
- package/WebGPU/GPURenderPipeline.js.map +1 -1
- package/WebGPU/GPUSampler.d.ts +1 -0
- package/WebGPU/GPUSampler.js +3 -0
- package/WebGPU/GPUSampler.js.map +1 -1
- package/WebGPU/GPUShaderModule.d.ts +1 -1
- package/WebGPU/GPUShaderModule.js +2 -2
- package/WebGPU/GPUShaderModule.js.map +1 -1
- package/WebGPU/GPUTexture.d.ts +1 -0
- package/WebGPU/GPUTexture.js +3 -0
- package/WebGPU/GPUTexture.js.map +1 -1
- package/WebGPU/GPUTextureView.d.ts +1 -0
- package/WebGPU/GPUTextureView.js +3 -0
- package/WebGPU/GPUTextureView.js.map +1 -1
- package/WebGPU/Interfaces.d.ts +95 -4
- package/WebGPU/Types.d.ts +9 -1
- package/WebGPU/Utils.d.ts +6 -0
- package/WebGPU/Utils.js +224 -0
- package/WebGPU/Utils.js.map +1 -1
- package/angular/esm2022/index.mjs +4 -4
- package/angular/fesm2022/nativescript-canvas-angular.mjs +4 -4
- 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 +39 -10
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_ios.h +7 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h +227 -62
- 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 +1635 -151
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.private.swiftinterface +57 -1
- 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 +57 -1
- package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/NSCCanvas.nib +0 -0
- 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 +690 -644
- 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 +78 -20
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_ios.h +7 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h +227 -62
- 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 +1635 -151
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +57 -1
- 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 +57 -1
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.abi.json +1635 -151
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +57 -1
- 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 +57 -1
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/NSCCanvas.nib +0 -0
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources +27 -27
- 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 +692 -646
- package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/x86_64/CanvasNative.yml +730 -684
- package/platforms/ios/src/NSOperationQueueWrapper.h +1 -1
- package/platforms/ios/src/NSOperationQueueWrapper.mm +41 -9
- package/platforms/ios/src/cpp/AsyncCallback.h +16 -8
- package/platforms/ios/src/cpp/CanvasJSIModule.cpp +208 -789
- package/platforms/ios/src/cpp/ImageAssetImpl.cpp +18 -28
- package/platforms/ios/src/cpp/ImageAssetImpl.h +3 -3
- package/platforms/ios/src/cpp/ImageBitmapImpl.cpp +60 -3
- package/platforms/ios/src/cpp/ImageBitmapImpl.h +10 -3
- package/platforms/ios/src/cpp/PromiseCallback.h +1 -2
- package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.cpp +1 -1
- package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.h +3 -3
- package/platforms/ios/src/cpp/canvas2d/Path2D.h +5 -5
- package/platforms/ios/src/cpp/webgl/WebGLRenderingContext.cpp +106 -1
- package/platforms/ios/src/cpp/webgpu/GPUAdapterImpl.cpp +26 -23
- package/platforms/ios/src/cpp/webgpu/GPUBindGroupImpl.cpp +31 -5
- package/platforms/ios/src/cpp/webgpu/GPUBindGroupImpl.h +4 -1
- package/platforms/ios/src/cpp/webgpu/GPUBindGroupLayoutImpl.cpp +26 -0
- package/platforms/ios/src/cpp/webgpu/GPUBindGroupLayoutImpl.h +3 -0
- package/platforms/ios/src/cpp/webgpu/GPUBufferImpl.cpp +41 -7
- package/platforms/ios/src/cpp/webgpu/GPUBufferImpl.h +4 -0
- package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.cpp +11 -5
- package/platforms/ios/src/cpp/webgpu/GPUCommandBufferImpl.cpp +28 -1
- package/platforms/ios/src/cpp/webgpu/GPUCommandBufferImpl.h +3 -0
- package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.cpp +75 -79
- package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.h +4 -0
- package/platforms/ios/src/cpp/webgpu/GPUComputePassEncoderImpl.cpp +42 -14
- package/platforms/ios/src/cpp/webgpu/GPUComputePassEncoderImpl.h +3 -0
- package/platforms/ios/src/cpp/webgpu/GPUComputePipelineImpl.cpp +25 -0
- package/platforms/ios/src/cpp/webgpu/GPUComputePipelineImpl.h +2 -0
- package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.cpp +1597 -674
- package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.h +2 -0
- package/platforms/ios/src/cpp/webgpu/GPUImpl.cpp +2 -1
- package/platforms/ios/src/cpp/webgpu/GPUImpl.h +1 -1
- package/platforms/ios/src/cpp/webgpu/GPULabel.h +33 -0
- package/platforms/ios/src/cpp/webgpu/GPUPipelineLayoutImpl.cpp +26 -0
- package/platforms/ios/src/cpp/webgpu/GPUPipelineLayoutImpl.h +3 -1
- package/platforms/ios/src/cpp/webgpu/GPUQuerySetImpl.cpp +1 -2
- package/platforms/ios/src/cpp/webgpu/GPUQuerySetImpl.h +1 -1
- package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.cpp +50 -13
- package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.h +3 -0
- package/platforms/ios/src/cpp/webgpu/GPURenderBundleEncoderImpl.cpp +43 -14
- package/platforms/ios/src/cpp/webgpu/GPURenderBundleEncoderImpl.h +3 -0
- package/platforms/ios/src/cpp/webgpu/GPURenderBundleImpl.cpp +25 -0
- package/platforms/ios/src/cpp/webgpu/GPURenderBundleImpl.h +3 -0
- package/platforms/ios/src/cpp/webgpu/GPURenderPassEncoderImpl.cpp +39 -13
- package/platforms/ios/src/cpp/webgpu/GPURenderPassEncoderImpl.h +3 -0
- package/platforms/ios/src/cpp/webgpu/GPURenderPipelineImpl.cpp +25 -0
- package/platforms/ios/src/cpp/webgpu/GPURenderPipelineImpl.h +3 -0
- package/platforms/ios/src/cpp/webgpu/GPUSamplerImpl.cpp +26 -0
- package/platforms/ios/src/cpp/webgpu/GPUSamplerImpl.h +4 -1
- package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.cpp +24 -0
- package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.h +3 -0
- package/platforms/ios/src/cpp/webgpu/GPUTextureImpl.cpp +34 -8
- package/platforms/ios/src/cpp/webgpu/GPUTextureImpl.h +2 -0
- package/platforms/ios/src/cpp/webgpu/GPUTextureViewImpl.cpp +26 -0
- package/platforms/ios/src/cpp/webgpu/GPUTextureViewImpl.h +3 -0
- package/platforms/ios/src/cpp/webgpu/GPUUtils.h +511 -0
- package/utils.d.ts +1 -1
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
#include "GPUQuerySetImpl.h"
|
|
22
22
|
#include "GPURenderBundleEncoderImpl.h"
|
|
23
23
|
#include "GPUUtils.h"
|
|
24
|
+
#include "GPULabel.h"
|
|
24
25
|
|
|
25
26
|
GPUDeviceImpl::GPUDeviceImpl(const CanvasGPUDevice *device) : device_(device) {}
|
|
26
27
|
|
|
@@ -63,6 +64,11 @@ v8::Local<v8::FunctionTemplate> GPUDeviceImpl::GetCtor(v8::Isolate *isolate) {
|
|
|
63
64
|
auto tmpl = ctorTmpl->InstanceTemplate();
|
|
64
65
|
tmpl->SetInternalFieldCount(2);
|
|
65
66
|
|
|
67
|
+
tmpl->SetLazyDataProperty(
|
|
68
|
+
ConvertToV8String(isolate, "label"),
|
|
69
|
+
GetLabel
|
|
70
|
+
);
|
|
71
|
+
|
|
66
72
|
tmpl->SetLazyDataProperty(
|
|
67
73
|
ConvertToV8String(isolate, "features"),
|
|
68
74
|
GetFeatures
|
|
@@ -103,6 +109,10 @@ v8::Local<v8::FunctionTemplate> GPUDeviceImpl::GetCtor(v8::Isolate *isolate) {
|
|
|
103
109
|
ConvertToV8String(isolate, "createComputePipeline"),
|
|
104
110
|
v8::FunctionTemplate::New(isolate, &CreateComputePipeline));
|
|
105
111
|
|
|
112
|
+
tmpl->Set(
|
|
113
|
+
ConvertToV8String(isolate, "createComputePipelineAsync"),
|
|
114
|
+
v8::FunctionTemplate::New(isolate, &CreateComputePipelineAsync));
|
|
115
|
+
|
|
106
116
|
tmpl->Set(
|
|
107
117
|
ConvertToV8String(isolate, "createPipelineLayout"),
|
|
108
118
|
v8::FunctionTemplate::New(isolate, &CreatePipelineLayout));
|
|
@@ -119,6 +129,10 @@ v8::Local<v8::FunctionTemplate> GPUDeviceImpl::GetCtor(v8::Isolate *isolate) {
|
|
|
119
129
|
ConvertToV8String(isolate, "createRenderPipeline"),
|
|
120
130
|
v8::FunctionTemplate::New(isolate, &CreateRenderPipeline));
|
|
121
131
|
|
|
132
|
+
tmpl->Set(
|
|
133
|
+
ConvertToV8String(isolate, "createRenderPipelineAsync"),
|
|
134
|
+
v8::FunctionTemplate::New(isolate, &CreateRenderPipelineAsync));
|
|
135
|
+
|
|
122
136
|
tmpl->Set(
|
|
123
137
|
ConvertToV8String(isolate, "createSampler"),
|
|
124
138
|
v8::FunctionTemplate::New(isolate, &CreateSampler));
|
|
@@ -154,6 +168,26 @@ v8::Local<v8::FunctionTemplate> GPUDeviceImpl::GetCtor(v8::Isolate *isolate) {
|
|
|
154
168
|
return ctorTmpl;
|
|
155
169
|
}
|
|
156
170
|
|
|
171
|
+
void
|
|
172
|
+
GPUDeviceImpl::GetLabel(v8::Local<v8::Name> name,
|
|
173
|
+
const v8::PropertyCallbackInfo<v8::Value> &info) {
|
|
174
|
+
auto ptr = GetPointer(info.This());
|
|
175
|
+
if (ptr != nullptr) {
|
|
176
|
+
auto label = canvas_native_webgpu_device_get_label(ptr->device_);
|
|
177
|
+
if (label == nullptr) {
|
|
178
|
+
info.GetReturnValue().SetEmptyString();
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
info.GetReturnValue().Set(
|
|
182
|
+
ConvertToV8String(info.GetIsolate(), label)
|
|
183
|
+
);
|
|
184
|
+
canvas_native_string_destroy(label);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
info.GetReturnValue().SetEmptyString();
|
|
189
|
+
}
|
|
190
|
+
|
|
157
191
|
void
|
|
158
192
|
GPUDeviceImpl::SetUncapturedError(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
159
193
|
auto *ptr = GetPointer(args.This());
|
|
@@ -244,19 +278,19 @@ GPUDeviceImpl::GetFeatures(v8::Local<v8::Name> name,
|
|
|
244
278
|
|
|
245
279
|
auto len = canvas_native_string_buffer_get_length(features);
|
|
246
280
|
|
|
247
|
-
auto
|
|
281
|
+
auto set = v8::Set::New(isolate);
|
|
248
282
|
for (int i = 0; i < len; ++i) {
|
|
249
283
|
auto item = canvas_native_string_buffer_get_value_at(features, i);
|
|
250
284
|
if (item != nullptr) {
|
|
251
285
|
auto keyValue = ConvertToV8String(isolate, (char *) item);
|
|
252
|
-
|
|
286
|
+
set->Add(context, keyValue);
|
|
253
287
|
canvas_native_string_destroy(item);
|
|
254
288
|
}
|
|
255
289
|
|
|
256
290
|
}
|
|
257
291
|
canvas_native_string_buffer_release(features);
|
|
258
292
|
|
|
259
|
-
info.GetReturnValue().Set(
|
|
293
|
+
info.GetReturnValue().Set(set);
|
|
260
294
|
|
|
261
295
|
return;
|
|
262
296
|
}
|
|
@@ -399,7 +433,7 @@ void GPUDeviceImpl::CreateBindGroup(const v8::FunctionCallbackInfo<v8::Value> &a
|
|
|
399
433
|
}
|
|
400
434
|
auto isolate = args.GetIsolate();
|
|
401
435
|
auto context = isolate->GetCurrentContext();
|
|
402
|
-
|
|
436
|
+
GPULabel label;
|
|
403
437
|
|
|
404
438
|
auto optionsVal = args[0];
|
|
405
439
|
|
|
@@ -410,12 +444,10 @@ void GPUDeviceImpl::CreateBindGroup(const v8::FunctionCallbackInfo<v8::Value> &a
|
|
|
410
444
|
v8::Local<v8::Value> labelVal;
|
|
411
445
|
options->Get(context, ConvertToV8String(isolate, "label")).ToLocal(&labelVal);
|
|
412
446
|
|
|
413
|
-
if (!labelVal.IsEmpty() && labelVal->IsString()) {
|
|
414
|
-
label = *v8::String::Utf8Value(isolate, labelVal);
|
|
415
|
-
}
|
|
416
447
|
|
|
417
|
-
|
|
448
|
+
label = GPULabel(isolate, labelVal);
|
|
418
449
|
|
|
450
|
+
const CanvasGPUBindGroupLayout *layout = nullptr;
|
|
419
451
|
|
|
420
452
|
v8::Local<v8::Value> layoutVal;
|
|
421
453
|
options->Get(context, ConvertToV8String(isolate, "layout")).ToLocal(&layoutVal);
|
|
@@ -432,108 +464,10 @@ void GPUDeviceImpl::CreateBindGroup(const v8::FunctionCallbackInfo<v8::Value> &a
|
|
|
432
464
|
v8::Local<v8::Value> entriesVal;
|
|
433
465
|
options->Get(context, ConvertToV8String(isolate, "entries")).ToLocal(&entriesVal);
|
|
434
466
|
|
|
435
|
-
|
|
436
|
-
auto entriesArray = entriesVal.As<v8::Array>();
|
|
437
|
-
auto len = entriesArray->Length();
|
|
438
|
-
for (int i = 0; i < len; i++) {
|
|
439
|
-
v8::Local<v8::Value> entryVal;
|
|
440
|
-
entriesArray->Get(context, i).ToLocal(&entryVal);
|
|
441
|
-
if (!entryVal.IsEmpty() && entryVal->IsObject()) {
|
|
442
|
-
auto entryObj = entryVal.As<v8::Object>();
|
|
443
|
-
auto binding = entryObj->Get(context, ConvertToV8String(isolate,
|
|
444
|
-
"binding")).ToLocalChecked()->Uint32Value(
|
|
445
|
-
context).FromJust();
|
|
446
|
-
v8::Local<v8::Value> resourceVal;
|
|
447
|
-
entryObj->Get(context, ConvertToV8String(isolate, "resource")).ToLocal(
|
|
448
|
-
&resourceVal);
|
|
449
|
-
|
|
450
|
-
auto resourceType = GetNativeType(resourceVal);
|
|
451
|
-
switch (resourceType) {
|
|
452
|
-
case NativeType::GPUSampler: {
|
|
453
|
-
auto sampler = GPUSamplerImpl::GetPointer(resourceVal.As<v8::Object>());
|
|
454
|
-
if (sampler != nullptr) {
|
|
455
|
-
auto resource = CanvasBindGroupEntryResource{
|
|
456
|
-
CanvasBindGroupEntryResourceSampler,
|
|
457
|
-
};
|
|
458
|
-
resource.sampler = sampler->GetSampler();
|
|
459
|
-
CanvasBindGroupEntry entry{binding, resource};
|
|
460
|
-
entries.push_back(entry);
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
}
|
|
464
|
-
break;
|
|
465
|
-
case NativeType::GPUTextureView: {
|
|
466
|
-
auto textureView = GPUTextureViewImpl::GetPointer(
|
|
467
|
-
resourceVal.As<v8::Object>());
|
|
468
|
-
if (textureView != nullptr) {
|
|
469
|
-
auto resource = CanvasBindGroupEntryResource{
|
|
470
|
-
CanvasBindGroupEntryResourceTextureView,
|
|
471
|
-
};
|
|
472
|
-
resource.texture_view = textureView->GetTextureView();
|
|
473
|
-
CanvasBindGroupEntry entry{binding, resource};
|
|
474
|
-
entries.push_back(entry);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
break;
|
|
478
|
-
default: {
|
|
479
|
-
if (!resourceVal.IsEmpty() && resourceVal->IsObject()) {
|
|
480
|
-
auto resourceObj = resourceVal.As<v8::Object>();
|
|
481
|
-
v8::Local<v8::Value> bufferVal;
|
|
482
|
-
resourceObj->Get(context,
|
|
483
|
-
ConvertToV8String(isolate, "buffer")).ToLocal(
|
|
484
|
-
&bufferVal);
|
|
485
|
-
if (GetNativeType(bufferVal) == NativeType::GPUBuffer) {
|
|
486
|
-
auto bufferObj = bufferVal.As<v8::Object>();
|
|
487
|
-
auto buffer = GPUBufferImpl::GetPointer(bufferObj);
|
|
488
|
-
if (buffer != nullptr) {
|
|
489
|
-
auto resource = CanvasBindGroupEntryResource{
|
|
490
|
-
CanvasBindGroupEntryResourceBuffer,
|
|
491
|
-
};
|
|
492
|
-
int64_t offset = -1;
|
|
493
|
-
|
|
494
|
-
v8::Local<v8::Value> offsetVal;
|
|
495
|
-
|
|
496
|
-
resourceObj->Get(context,
|
|
497
|
-
ConvertToV8String(isolate,
|
|
498
|
-
"offset")).ToLocal(
|
|
499
|
-
&offsetVal);
|
|
500
|
-
if (!offsetVal.IsEmpty() && offsetVal->IsNumber()) {
|
|
501
|
-
offset = (int64_t) offsetVal->NumberValue(
|
|
502
|
-
context).ToChecked();
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
int64_t size = -1;
|
|
506
|
-
|
|
507
|
-
v8::Local<v8::Value> sizeVal;
|
|
508
|
-
resourceObj->Get(context,
|
|
509
|
-
ConvertToV8String(isolate,
|
|
510
|
-
"size")).ToLocal(
|
|
511
|
-
&sizeVal);
|
|
512
|
-
if (!sizeVal.IsEmpty() && sizeVal->IsNumber()) {
|
|
513
|
-
size = (int64_t) sizeVal->NumberValue(
|
|
514
|
-
context).ToChecked();
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
resource.buffer = CanvasBufferBinding{
|
|
518
|
-
buffer->GetGPUBuffer(), offset, size
|
|
519
|
-
};
|
|
520
|
-
|
|
521
|
-
CanvasBindGroupEntry entry{binding, resource};
|
|
522
|
-
entries.push_back(entry);
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
}
|
|
528
|
-
break;
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
|
|
467
|
+
entries = ParseBindGroupEntries(isolate, entriesVal);
|
|
535
468
|
|
|
536
|
-
auto bind_group = canvas_native_webgpu_device_create_bind_group(ptr->GetGPUDevice(),
|
|
469
|
+
auto bind_group = canvas_native_webgpu_device_create_bind_group(ptr->GetGPUDevice(),
|
|
470
|
+
*label,
|
|
537
471
|
layout, entries.data(),
|
|
538
472
|
entries.size());
|
|
539
473
|
|
|
@@ -554,7 +488,7 @@ void GPUDeviceImpl::CreateBindGroupLayout(const v8::FunctionCallbackInfo<v8::Val
|
|
|
554
488
|
}
|
|
555
489
|
auto isolate = args.GetIsolate();
|
|
556
490
|
auto context = isolate->GetCurrentContext();
|
|
557
|
-
|
|
491
|
+
GPULabel label;
|
|
558
492
|
|
|
559
493
|
auto optionsVal = args[0];
|
|
560
494
|
|
|
@@ -563,381 +497,16 @@ void GPUDeviceImpl::CreateBindGroupLayout(const v8::FunctionCallbackInfo<v8::Val
|
|
|
563
497
|
v8::Local<v8::Value> labelVal;
|
|
564
498
|
options->Get(context, ConvertToV8String(isolate, "label")).ToLocal(&labelVal);
|
|
565
499
|
|
|
566
|
-
|
|
567
|
-
label = *v8::String::Utf8Value(isolate, labelVal);
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
std::vector<CanvasBindGroupLayoutEntry> entries;
|
|
500
|
+
label = GPULabel(isolate, labelVal);
|
|
572
501
|
|
|
573
502
|
v8::Local<v8::Value> entriesVal;
|
|
574
503
|
options->Get(context, ConvertToV8String(isolate, "entries")).ToLocal(&entriesVal);
|
|
575
504
|
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
auto len = entriesArray->Length();
|
|
579
|
-
for (int i = 0; i < len; i++) {
|
|
580
|
-
v8::Local<v8::Value> entryVal;
|
|
581
|
-
entriesArray->Get(context, i).ToLocal(&entryVal);
|
|
582
|
-
if (!entryVal.IsEmpty() && entryVal->IsObject()) {
|
|
583
|
-
auto entryObj = entryVal.As<v8::Object>();
|
|
584
|
-
auto binding = entryObj->Get(context, ConvertToV8String(isolate,
|
|
585
|
-
"binding")).ToLocalChecked()->Uint32Value(
|
|
586
|
-
context).FromJust();
|
|
587
|
-
v8::Local<v8::Value> resourceVal;
|
|
588
|
-
entryObj->Get(context, ConvertToV8String(isolate, "resource")).ToLocal(
|
|
589
|
-
&resourceVal);
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
auto visibility = entryObj->Get(context, ConvertToV8String(isolate,
|
|
593
|
-
"visibility")).ToLocalChecked()->Uint32Value(
|
|
594
|
-
context).FromJust();
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
v8::Local<v8::Value> bufferVal;
|
|
598
|
-
|
|
599
|
-
entryObj->Get(context, ConvertToV8String(isolate, "buffer")).ToLocal(
|
|
600
|
-
&bufferVal);
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
if (!bufferVal.IsEmpty() && bufferVal->IsObject()) {
|
|
604
|
-
auto bufferObj = bufferVal.As<v8::Object>();
|
|
605
|
-
v8::Local<v8::Value> bufferType;
|
|
606
|
-
bufferObj->Get(context, ConvertToV8String(isolate, "type")).ToLocal(
|
|
607
|
-
&bufferType);
|
|
608
|
-
|
|
609
|
-
CanvasBufferBindingType type = CanvasBufferBindingTypeUniform;
|
|
610
|
-
|
|
611
|
-
if (!bufferType.IsEmpty() && bufferType->IsString()) {
|
|
612
|
-
auto typeStr = ConvertFromV8String(isolate, bufferType);
|
|
613
|
-
if (typeStr == "read-only-storage") {
|
|
614
|
-
type = CanvasBufferBindingTypeReadOnlyStorage;
|
|
615
|
-
} else if (typeStr == "storage") {
|
|
616
|
-
type = CanvasBufferBindingTypeStorage;
|
|
617
|
-
} else if (typeStr == "uniform") {
|
|
618
|
-
type = CanvasBufferBindingTypeUniform;
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
bool has_dynamic_offset = false;
|
|
623
|
-
|
|
624
|
-
v8::Local<v8::Value> hasDynamicOffsetVal;
|
|
625
|
-
bufferObj->Get(context,
|
|
626
|
-
ConvertToV8String(isolate, "hasDynamicOffset")).ToLocal(
|
|
627
|
-
&hasDynamicOffsetVal);
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
if (!hasDynamicOffsetVal.IsEmpty() && hasDynamicOffsetVal->IsBoolean()) {
|
|
631
|
-
has_dynamic_offset = hasDynamicOffsetVal->BooleanValue(isolate);
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
int64_t min_binding_size = -1;
|
|
635
|
-
|
|
636
|
-
v8::Local<v8::Value> minBindingSizeVal;
|
|
637
|
-
bufferObj->Get(context,
|
|
638
|
-
ConvertToV8String(isolate, "minBindingSize")).ToLocal(
|
|
639
|
-
&minBindingSizeVal);
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
if (!minBindingSizeVal.IsEmpty() && minBindingSizeVal->IsNumber()) {
|
|
643
|
-
min_binding_size = (int64_t) minBindingSizeVal->NumberValue(
|
|
644
|
-
context).ToChecked();
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
CanvasBindingType buffer{
|
|
648
|
-
CanvasBindingTypeBuffer
|
|
649
|
-
};
|
|
650
|
-
|
|
651
|
-
buffer.buffer = CanvasBufferBindingLayout{
|
|
652
|
-
type, has_dynamic_offset, min_binding_size
|
|
653
|
-
};
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
CanvasBindGroupLayoutEntry entry{
|
|
657
|
-
binding,
|
|
658
|
-
visibility,
|
|
659
|
-
buffer
|
|
660
|
-
};
|
|
661
|
-
|
|
662
|
-
entries.push_back(entry);
|
|
663
|
-
|
|
664
|
-
continue;
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
v8::Local<v8::Value> externalTextureVal;
|
|
669
|
-
|
|
670
|
-
entryObj->Get(context, ConvertToV8String(isolate, "externalTexture")).ToLocal(
|
|
671
|
-
&externalTextureVal);
|
|
672
|
-
|
|
673
|
-
if (!externalTextureVal.IsEmpty() && externalTextureVal->IsObject()) {
|
|
674
|
-
// todo
|
|
675
|
-
// CanvasBindingType buffer{
|
|
676
|
-
// CanvasBindingTypeTexture
|
|
677
|
-
// };
|
|
678
|
-
//
|
|
679
|
-
// buffer.buffer = CanvasBufferBindingLayout{
|
|
680
|
-
// type, has_dynamic_offset, min_binding_size
|
|
681
|
-
// };
|
|
682
|
-
//
|
|
683
|
-
//
|
|
684
|
-
// CanvasBindGroupLayoutEntry entry{
|
|
685
|
-
// binding,
|
|
686
|
-
// visibility,
|
|
687
|
-
// buffer
|
|
688
|
-
// };
|
|
689
|
-
|
|
690
|
-
continue;
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
v8::Local<v8::Value> samplerVal;
|
|
695
|
-
|
|
696
|
-
entryObj->Get(context, ConvertToV8String(isolate, "sampler")).ToLocal(
|
|
697
|
-
&samplerVal);
|
|
698
|
-
|
|
699
|
-
if (!samplerVal.IsEmpty() && samplerVal->IsObject()) {
|
|
700
|
-
auto samplerObj = samplerVal.As<v8::Object>();
|
|
701
|
-
v8::Local<v8::Value> samplerType;
|
|
702
|
-
samplerObj->Get(context, ConvertToV8String(isolate, "type")).ToLocal(
|
|
703
|
-
&samplerType);
|
|
704
|
-
|
|
705
|
-
CanvasSamplerBindingType type = CanvasSamplerBindingTypeFiltering;
|
|
706
|
-
|
|
707
|
-
if (!samplerType.IsEmpty() && samplerType->IsString()) {
|
|
708
|
-
auto typeStr = ConvertFromV8String(isolate, samplerType);
|
|
709
|
-
if (typeStr == "comparison") {
|
|
710
|
-
type = CanvasSamplerBindingTypeComparison;
|
|
711
|
-
} else if (typeStr == "non-filtering") {
|
|
712
|
-
type = CanvasSamplerBindingTypeNonFiltering;
|
|
713
|
-
} else if (typeStr == "filtering") {
|
|
714
|
-
type = CanvasSamplerBindingTypeFiltering;
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
CanvasBindingType sampler{
|
|
720
|
-
CanvasBindingTypeSampler
|
|
721
|
-
};
|
|
722
|
-
|
|
723
|
-
sampler.sampler = CanvasSamplerBindingLayout{
|
|
724
|
-
type
|
|
725
|
-
};
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
CanvasBindGroupLayoutEntry entry{
|
|
729
|
-
binding,
|
|
730
|
-
visibility,
|
|
731
|
-
sampler
|
|
732
|
-
};
|
|
733
|
-
|
|
734
|
-
entries.push_back(entry);
|
|
735
|
-
|
|
736
|
-
continue;
|
|
737
|
-
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
v8::Local<v8::Value> storageTextureVal;
|
|
742
|
-
|
|
743
|
-
entryObj->Get(context, ConvertToV8String(isolate, "storageTexture")).ToLocal(
|
|
744
|
-
&storageTextureVal);
|
|
745
|
-
|
|
746
|
-
if (!storageTextureVal.IsEmpty() && storageTextureVal->IsObject()) {
|
|
747
|
-
auto storageTextureObj = storageTextureVal.As<v8::Object>();
|
|
748
|
-
|
|
749
|
-
CanvasBindingType storage{
|
|
750
|
-
CanvasBindingTypeStorageTexture
|
|
751
|
-
};
|
|
752
|
-
|
|
753
|
-
CanvasStorageTextureAccess access = CanvasStorageTextureAccessWriteOnly;
|
|
754
|
-
|
|
755
|
-
v8::Local<v8::Value> accessVal;
|
|
756
|
-
|
|
757
|
-
storageTextureObj->Get(context,
|
|
758
|
-
ConvertToV8String(isolate, "access")).ToLocal(
|
|
759
|
-
&accessVal);
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
if (!accessVal.IsEmpty() && accessVal->IsString()) {
|
|
763
|
-
auto accessStr = ConvertFromV8String(isolate, accessVal);
|
|
764
|
-
|
|
765
|
-
if (accessStr == "write-only") {
|
|
766
|
-
access = CanvasStorageTextureAccessWriteOnly;
|
|
767
|
-
} else if (accessStr == "read-only") {
|
|
768
|
-
access = CanvasStorageTextureAccessReadOnly;
|
|
769
|
-
} else if (accessStr == "read-write") {
|
|
770
|
-
access = CanvasStorageTextureAccessReadWrite;
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
CanvasTextureViewDimension view_dimension = CanvasTextureViewDimensionD2;
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
v8::Local<v8::Value> viewDimensionVal;
|
|
779
|
-
|
|
780
|
-
storageTextureObj->Get(context,
|
|
781
|
-
ConvertToV8String(isolate, "viewDimension")).ToLocal(
|
|
782
|
-
&viewDimensionVal);
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
if (!viewDimensionVal.IsEmpty() && viewDimensionVal->IsString()) {
|
|
786
|
-
auto viewDimensionStr = ConvertFromV8String(isolate, viewDimensionVal);
|
|
787
|
-
if (viewDimensionStr == "1d") {
|
|
788
|
-
view_dimension = CanvasTextureViewDimensionD1;
|
|
789
|
-
} else if (viewDimensionStr == "2d") {
|
|
790
|
-
view_dimension = CanvasTextureViewDimensionD2;
|
|
791
|
-
} else if (viewDimensionStr == "2d-array") {
|
|
792
|
-
view_dimension = CanvasTextureViewDimensionD2Array;
|
|
793
|
-
} else if (viewDimensionStr == "cube") {
|
|
794
|
-
view_dimension = CanvasTextureViewDimensionCube;
|
|
795
|
-
} else if (viewDimensionStr == "cube-array") {
|
|
796
|
-
view_dimension = CanvasTextureViewDimensionCubeArray;
|
|
797
|
-
} else if (viewDimensionStr == "3d") {
|
|
798
|
-
view_dimension = CanvasTextureViewDimensionD3;
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
v8::Local<v8::Value> formatVal;
|
|
804
|
-
|
|
805
|
-
storageTextureObj->Get(context,
|
|
806
|
-
ConvertToV8String(isolate, "format")).ToLocal(
|
|
807
|
-
&formatVal);
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
if (!formatVal.IsEmpty() && formatVal->IsString()) {
|
|
811
|
-
auto formatStr = ConvertFromV8String(isolate, formatVal);
|
|
812
|
-
auto textureFormat = canvas_native_webgpu_enum_string_to_gpu_texture(
|
|
813
|
-
formatStr.c_str());
|
|
814
|
-
if (textureFormat.tag == CanvasOptionalGPUTextureFormatSome) {
|
|
815
|
-
storage.storage_texture = CanvasStorageTextureBindingLayout{
|
|
816
|
-
access,
|
|
817
|
-
textureFormat.some,
|
|
818
|
-
view_dimension
|
|
819
|
-
};
|
|
820
|
-
|
|
821
|
-
CanvasBindGroupLayoutEntry entry{
|
|
822
|
-
binding,
|
|
823
|
-
visibility,
|
|
824
|
-
storage
|
|
825
|
-
};
|
|
826
|
-
|
|
827
|
-
entries.push_back(entry);
|
|
828
|
-
|
|
829
|
-
continue;
|
|
830
|
-
|
|
831
|
-
} else {
|
|
832
|
-
// todo throw ??
|
|
833
|
-
continue;
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
v8::Local<v8::Value> textureVal;
|
|
842
|
-
|
|
843
|
-
entryObj->Get(context, ConvertToV8String(isolate, "texture")).ToLocal(
|
|
844
|
-
&textureVal);
|
|
845
|
-
|
|
846
|
-
if (!textureVal.IsEmpty() && textureVal->IsObject()) {
|
|
847
|
-
auto textureObj = textureVal.As<v8::Object>();
|
|
848
|
-
bool multisampled = false;
|
|
849
|
-
|
|
850
|
-
v8::Local<v8::Value> multisampledVal;
|
|
851
|
-
|
|
852
|
-
textureObj->Get(context,
|
|
853
|
-
ConvertToV8String(isolate, "multisampled")).ToLocal(
|
|
854
|
-
&multisampledVal);
|
|
855
|
-
|
|
856
|
-
if (!multisampledVal.IsEmpty() && multisampledVal->IsBoolean()) {
|
|
857
|
-
multisampled = multisampledVal->BooleanValue(isolate);
|
|
858
|
-
}
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
v8::Local<v8::Value> sampleTypeVal;
|
|
862
|
-
textureObj->Get(context, ConvertToV8String(isolate, "sampleType")).ToLocal(
|
|
863
|
-
&sampleTypeVal);
|
|
864
|
-
|
|
865
|
-
CanvasTextureSampleType type = CanvasTextureSampleTypeFloat;
|
|
866
|
-
|
|
867
|
-
if (!sampleTypeVal.IsEmpty() && sampleTypeVal->IsString()) {
|
|
868
|
-
auto typeStr = ConvertFromV8String(isolate, sampleTypeVal);
|
|
869
|
-
if (typeStr == "depth") {
|
|
870
|
-
type = CanvasTextureSampleTypeDepth;
|
|
871
|
-
} else if (typeStr == "float") {
|
|
872
|
-
type = CanvasTextureSampleTypeFloat;
|
|
873
|
-
} else if (typeStr == "sint") {
|
|
874
|
-
type = CanvasTextureSampleTypeSint;
|
|
875
|
-
} else if (typeStr == "uint") {
|
|
876
|
-
type = CanvasTextureSampleTypeUint;
|
|
877
|
-
} else if (typeStr == "unfilterable-float") {
|
|
878
|
-
type = CanvasTextureSampleTypeUnfilterableFloat;
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
CanvasTextureViewDimension view_dimension = CanvasTextureViewDimensionD2;
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
v8::Local<v8::Value> viewDimensionVal;
|
|
887
|
-
|
|
888
|
-
textureObj->Get(context,
|
|
889
|
-
ConvertToV8String(isolate, "viewDimension")).ToLocal(
|
|
890
|
-
&viewDimensionVal);
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
if (!viewDimensionVal.IsEmpty() && viewDimensionVal->IsString()) {
|
|
894
|
-
auto viewDimensionStr = ConvertFromV8String(isolate, viewDimensionVal);
|
|
895
|
-
if (viewDimensionStr == "1d") {
|
|
896
|
-
view_dimension = CanvasTextureViewDimensionD1;
|
|
897
|
-
} else if (viewDimensionStr == "2d") {
|
|
898
|
-
view_dimension = CanvasTextureViewDimensionD2;
|
|
899
|
-
} else if (viewDimensionStr == "2d-array") {
|
|
900
|
-
view_dimension = CanvasTextureViewDimensionD2Array;
|
|
901
|
-
} else if (viewDimensionStr == "cube") {
|
|
902
|
-
view_dimension = CanvasTextureViewDimensionCube;
|
|
903
|
-
} else if (viewDimensionStr == "cube-array") {
|
|
904
|
-
view_dimension = CanvasTextureViewDimensionCubeArray;
|
|
905
|
-
} else if (viewDimensionStr == "3d") {
|
|
906
|
-
view_dimension = CanvasTextureViewDimensionD3;
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
CanvasBindingType texture{
|
|
912
|
-
CanvasBindingTypeTexture
|
|
913
|
-
};
|
|
914
|
-
|
|
915
|
-
texture.texture = CanvasTextureBindingLayout{
|
|
916
|
-
type,
|
|
917
|
-
view_dimension,
|
|
918
|
-
multisampled
|
|
919
|
-
};
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
CanvasBindGroupLayoutEntry entry{
|
|
923
|
-
binding,
|
|
924
|
-
visibility,
|
|
925
|
-
texture
|
|
926
|
-
};
|
|
927
|
-
|
|
928
|
-
entries.push_back(entry);
|
|
929
|
-
|
|
930
|
-
continue;
|
|
931
|
-
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
|
|
505
|
+
std::vector<CanvasBindGroupLayoutEntry> entries = ParseBindGroupLayoutEntries(isolate,
|
|
506
|
+
entriesVal);
|
|
938
507
|
|
|
939
508
|
auto bind_group = canvas_native_webgpu_device_create_bind_group_layout(ptr->GetGPUDevice(),
|
|
940
|
-
label,
|
|
509
|
+
*label,
|
|
941
510
|
entries.data(),
|
|
942
511
|
entries.size());
|
|
943
512
|
|
|
@@ -959,7 +528,7 @@ void GPUDeviceImpl::CreateBuffer(const v8::FunctionCallbackInfo<v8::Value> &args
|
|
|
959
528
|
}
|
|
960
529
|
auto isolate = args.GetIsolate();
|
|
961
530
|
auto context = isolate->GetCurrentContext();
|
|
962
|
-
|
|
531
|
+
GPULabel label;
|
|
963
532
|
bool mappedAtCreation = false;
|
|
964
533
|
uint64_t size = 0;
|
|
965
534
|
uint32_t usage = 0;
|
|
@@ -971,10 +540,7 @@ void GPUDeviceImpl::CreateBuffer(const v8::FunctionCallbackInfo<v8::Value> &args
|
|
|
971
540
|
v8::Local<v8::Value> labelVal;
|
|
972
541
|
options->Get(context, ConvertToV8String(isolate, "label")).ToLocal(&labelVal);
|
|
973
542
|
|
|
974
|
-
|
|
975
|
-
label = *v8::String::Utf8Value(isolate, labelVal);
|
|
976
|
-
}
|
|
977
|
-
|
|
543
|
+
label = GPULabel(isolate, labelVal);
|
|
978
544
|
v8::Local<v8::Value> mappedAtCreationVal;
|
|
979
545
|
|
|
980
546
|
options->Get(context, ConvertToV8String(isolate, "mappedAtCreation")).ToLocal(
|
|
@@ -1000,7 +566,8 @@ void GPUDeviceImpl::CreateBuffer(const v8::FunctionCallbackInfo<v8::Value> &args
|
|
|
1000
566
|
}
|
|
1001
567
|
}
|
|
1002
568
|
|
|
1003
|
-
auto buffer = canvas_native_webgpu_device_create_buffer(ptr->GetGPUDevice(), label,
|
|
569
|
+
auto buffer = canvas_native_webgpu_device_create_buffer(ptr->GetGPUDevice(), *label,
|
|
570
|
+
size, usage,
|
|
1004
571
|
mappedAtCreation);
|
|
1005
572
|
|
|
1006
573
|
if (buffer != nullptr) {
|
|
@@ -1021,15 +588,10 @@ void GPUDeviceImpl::CreateCommandEncoder(const v8::FunctionCallbackInfo<v8::Valu
|
|
|
1021
588
|
}
|
|
1022
589
|
auto isolate = args.GetIsolate();
|
|
1023
590
|
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
auto labelVal = args[0];
|
|
591
|
+
auto label = GPULabel(isolate, args[0]);
|
|
1027
592
|
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
|
-
auto encoder = canvas_native_webgpu_device_create_command_encoder(ptr->GetGPUDevice(), label);
|
|
593
|
+
auto encoder = canvas_native_webgpu_device_create_command_encoder(ptr->GetGPUDevice(),
|
|
594
|
+
*label);
|
|
1033
595
|
|
|
1034
596
|
if (encoder != nullptr) {
|
|
1035
597
|
auto instance = new GPUCommandEncoderImpl(encoder);
|
|
@@ -1061,11 +623,7 @@ void GPUDeviceImpl::CreateComputePipeline(const v8::FunctionCallbackInfo<v8::Val
|
|
|
1061
623
|
v8::Local<v8::Value> labelVal;
|
|
1062
624
|
options->Get(context, ConvertToV8String(isolate, "label")).ToLocal(&labelVal);
|
|
1063
625
|
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
if (!labelVal.IsEmpty() && labelVal->IsString()) {
|
|
1067
|
-
label = *v8::String::Utf8Value(isolate, labelVal);
|
|
1068
|
-
}
|
|
626
|
+
GPULabel label(isolate, labelVal);
|
|
1069
627
|
|
|
1070
628
|
CanvasGPUPipelineLayoutOrGPUAutoLayoutMode layout{
|
|
1071
629
|
CanvasGPUPipelineLayoutOrGPUAutoLayoutModeAuto
|
|
@@ -1151,7 +709,8 @@ void GPUDeviceImpl::CreateComputePipeline(const v8::FunctionCallbackInfo<v8::Val
|
|
|
1151
709
|
};
|
|
1152
710
|
|
|
1153
711
|
auto pipeline = canvas_native_webgpu_device_create_compute_pipeline(ptr->GetGPUDevice(),
|
|
1154
|
-
label, layout,
|
|
712
|
+
*label, layout,
|
|
713
|
+
&stage);
|
|
1155
714
|
|
|
1156
715
|
if (entry_point != nullptr) {
|
|
1157
716
|
free(entry_point);
|
|
@@ -1174,7 +733,34 @@ void GPUDeviceImpl::CreateComputePipeline(const v8::FunctionCallbackInfo<v8::Val
|
|
|
1174
733
|
args.GetReturnValue().SetUndefined();
|
|
1175
734
|
}
|
|
1176
735
|
|
|
1177
|
-
|
|
736
|
+
struct ComputePipeLineAsyncData {
|
|
737
|
+
char *label;
|
|
738
|
+
CanvasConstants *constants;
|
|
739
|
+
enum CanvasGPUErrorType type;
|
|
740
|
+
char *errorMessage;
|
|
741
|
+
const CanvasGPUComputePipeline *pipeline;
|
|
742
|
+
|
|
743
|
+
~ComputePipeLineAsyncData() {
|
|
744
|
+
if (label != nullptr) {
|
|
745
|
+
free(label);
|
|
746
|
+
label = nullptr;
|
|
747
|
+
canvas_native_webgpu_constants_destroy(constants);
|
|
748
|
+
constants = nullptr;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
if (constants != nullptr) {
|
|
752
|
+
canvas_native_webgpu_constants_destroy(constants);
|
|
753
|
+
constants = nullptr;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
if (errorMessage != nullptr) {
|
|
757
|
+
canvas_native_string_destroy(errorMessage);
|
|
758
|
+
errorMessage = nullptr;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
};
|
|
762
|
+
|
|
763
|
+
void GPUDeviceImpl::CreateComputePipelineAsync(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
1178
764
|
GPUDeviceImpl *ptr = GetPointer(args.This());
|
|
1179
765
|
if (ptr == nullptr) {
|
|
1180
766
|
return;
|
|
@@ -1183,6 +769,7 @@ void GPUDeviceImpl::CreatePipelineLayout(const v8::FunctionCallbackInfo<v8::Valu
|
|
|
1183
769
|
auto context = isolate->GetCurrentContext();
|
|
1184
770
|
|
|
1185
771
|
auto optionsVal = args[0];
|
|
772
|
+
auto callback = args[1];
|
|
1186
773
|
|
|
1187
774
|
if (!optionsVal->IsObject()) {
|
|
1188
775
|
// should error at this point
|
|
@@ -1193,34 +780,283 @@ void GPUDeviceImpl::CreatePipelineLayout(const v8::FunctionCallbackInfo<v8::Valu
|
|
|
1193
780
|
v8::Local<v8::Value> labelVal;
|
|
1194
781
|
options->Get(context, ConvertToV8String(isolate, "label")).ToLocal(&labelVal);
|
|
1195
782
|
|
|
1196
|
-
|
|
783
|
+
auto label = GPULabel(isolate, labelVal);
|
|
784
|
+
|
|
785
|
+
CanvasGPUPipelineLayoutOrGPUAutoLayoutMode layout{
|
|
786
|
+
CanvasGPUPipelineLayoutOrGPUAutoLayoutModeAuto
|
|
787
|
+
};
|
|
788
|
+
|
|
789
|
+
v8::Local<v8::Value> layoutVal;
|
|
1197
790
|
|
|
1198
|
-
if (
|
|
1199
|
-
|
|
791
|
+
if (options->Get(context, ConvertToV8String(isolate, "layout")).ToLocal(&layoutVal) &&
|
|
792
|
+
layoutVal->IsObject()) {
|
|
793
|
+
auto layoutImpl = GPUPipelineLayoutImpl::GetPointer(layoutVal.As<v8::Object>());
|
|
794
|
+
if (layoutImpl != nullptr) {
|
|
795
|
+
layout.tag = CanvasGPUPipelineLayoutOrGPUAutoLayoutModeLayout;
|
|
796
|
+
layout.layout = layoutImpl->GetPipeline();
|
|
797
|
+
}
|
|
1200
798
|
}
|
|
1201
799
|
|
|
1202
800
|
|
|
1203
|
-
|
|
801
|
+
v8::Local<v8::Value> computeVal;
|
|
802
|
+
options->Get(context, ConvertToV8String(isolate, "compute")).ToLocal(&computeVal);
|
|
1204
803
|
|
|
1205
|
-
|
|
1206
|
-
|
|
804
|
+
if (!computeVal.IsEmpty() && computeVal->IsObject()) {
|
|
805
|
+
|
|
806
|
+
auto computeObj = computeVal.As<v8::Object>();
|
|
807
|
+
|
|
808
|
+
v8::Local<v8::Value> constantsVal;
|
|
809
|
+
computeObj->Get(context, ConvertToV8String(isolate, "constants")).ToLocal(
|
|
810
|
+
&constantsVal);
|
|
811
|
+
|
|
812
|
+
CanvasConstants *store = nullptr;
|
|
813
|
+
|
|
814
|
+
if (!constantsVal.IsEmpty() && constantsVal->IsMap()) {
|
|
815
|
+
auto constants = constantsVal.As<v8::Map>();
|
|
816
|
+
auto keyValues = constants->AsArray();
|
|
817
|
+
auto length = keyValues->Length();
|
|
818
|
+
if (length > 0) {
|
|
819
|
+
store = canvas_native_webgpu_constants_create();
|
|
820
|
+
for (int i = 0; i < length; i += 2) {
|
|
821
|
+
auto k = i;
|
|
822
|
+
auto v = k + 1;
|
|
823
|
+
|
|
824
|
+
v8::Local<v8::Value> keyVal;
|
|
825
|
+
keyValues->Get(context, k).ToLocal(&keyVal);
|
|
826
|
+
v8::Local<v8::Value> valueVal;
|
|
827
|
+
keyValues->Get(context, v).ToLocal(&valueVal);
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
if (!keyVal.IsEmpty() && keyVal->IsString() && !valueVal.IsEmpty() &&
|
|
831
|
+
valueVal->IsNumber()) {
|
|
832
|
+
auto val = ConvertFromV8String(isolate, keyVal);
|
|
833
|
+
canvas_native_webgpu_constants_insert(
|
|
834
|
+
store,
|
|
835
|
+
val.c_str(),
|
|
836
|
+
valueVal.As<v8::Number>()->Value()
|
|
837
|
+
);
|
|
838
|
+
}
|
|
1207
839
|
|
|
1208
|
-
if (!groupLayoutsVal.IsEmpty() && groupLayoutsVal->IsArray()) {
|
|
1209
|
-
auto groupLayoutsArray = groupLayoutsVal.As<v8::Array>();
|
|
1210
|
-
auto len = groupLayoutsArray->Length();
|
|
1211
|
-
for (int i = 0; i < len; i++) {
|
|
1212
|
-
v8::Local<v8::Value> groupVal;
|
|
1213
|
-
groupLayoutsArray->Get(context, i).ToLocal(&groupVal);
|
|
1214
|
-
if (GetNativeType(groupVal) == NativeType::GPUBindGroupLayout) {
|
|
1215
|
-
auto layout = GPUBindGroupLayoutImpl::GetPointer(groupVal.As<v8::Object>());
|
|
1216
|
-
if (layout != nullptr) {
|
|
1217
|
-
group_layouts.push_back(layout->GetBindGroupLayout());
|
|
1218
840
|
}
|
|
1219
841
|
}
|
|
1220
842
|
}
|
|
1221
843
|
|
|
1222
|
-
|
|
1223
|
-
|
|
844
|
+
|
|
845
|
+
v8::Local<v8::Value> entryPoint;
|
|
846
|
+
computeObj->Get(context, ConvertToV8String(isolate, "entryPoint")).ToLocal(
|
|
847
|
+
&entryPoint);
|
|
848
|
+
|
|
849
|
+
char *entry_point = nullptr;
|
|
850
|
+
|
|
851
|
+
if (!entryPoint.IsEmpty() && entryPoint->IsString()) {
|
|
852
|
+
auto ep = v8::String::Utf8Value(isolate, entryPoint);
|
|
853
|
+
entry_point = (char *) malloc(ep.length());
|
|
854
|
+
std::strcpy(entry_point, *ep);
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
v8::Local<v8::Value> moduleVal;
|
|
858
|
+
computeObj->Get(context, ConvertToV8String(isolate, "module")).ToLocal(&moduleVal);
|
|
859
|
+
|
|
860
|
+
auto module = GPUShaderModuleImpl::GetPointer(moduleVal.As<v8::Object>());
|
|
861
|
+
|
|
862
|
+
CanvasProgrammableStage stage{
|
|
863
|
+
module->GetShaderModule(),
|
|
864
|
+
entry_point,
|
|
865
|
+
store
|
|
866
|
+
};
|
|
867
|
+
|
|
868
|
+
|
|
869
|
+
auto async_callback = new AsyncCallback(isolate, callback.As<v8::Function>(),
|
|
870
|
+
[](bool success, void *data) {
|
|
871
|
+
if (data != nullptr) {
|
|
872
|
+
|
|
873
|
+
auto async_data = static_cast<AsyncCallback *>(data);
|
|
874
|
+
auto func = async_data->inner_.get();
|
|
875
|
+
if (func != nullptr &&
|
|
876
|
+
func->isolate_ != nullptr) {
|
|
877
|
+
v8::Isolate *isolate = func->isolate_;
|
|
878
|
+
v8::Locker locker(isolate);
|
|
879
|
+
v8::Isolate::Scope isolate_scope(
|
|
880
|
+
isolate);
|
|
881
|
+
v8::HandleScope handle_scope(isolate);
|
|
882
|
+
v8::Local<v8::Function> callback = func->callback_.Get(
|
|
883
|
+
isolate);
|
|
884
|
+
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
885
|
+
v8::Context::Scope context_scope(
|
|
886
|
+
context);
|
|
887
|
+
|
|
888
|
+
ComputePipeLineAsyncData *pipelineData = nullptr;
|
|
889
|
+
if (func->data != nullptr) {
|
|
890
|
+
pipelineData = static_cast<ComputePipeLineAsyncData *>(func->data);
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
if (pipelineData == nullptr) {
|
|
894
|
+
// Should never happen
|
|
895
|
+
|
|
896
|
+
auto error = v8::Object::New(
|
|
897
|
+
isolate);
|
|
898
|
+
error->Set(context,
|
|
899
|
+
ConvertToV8String(
|
|
900
|
+
isolate,
|
|
901
|
+
"error"),
|
|
902
|
+
v8::Exception::Error(
|
|
903
|
+
ConvertToV8String(
|
|
904
|
+
isolate,
|
|
905
|
+
"Internal Error")));
|
|
906
|
+
error->Set(context,
|
|
907
|
+
ConvertToV8String(
|
|
908
|
+
isolate,
|
|
909
|
+
"type"),
|
|
910
|
+
v8::Uint32::NewFromUnsigned(
|
|
911
|
+
isolate,
|
|
912
|
+
(uint32_t) CanvasGPUErrorType::CanvasGPUErrorTypeInternal));
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
v8::Local<v8::Value> args[1] = {
|
|
916
|
+
error};
|
|
917
|
+
|
|
918
|
+
callback->Call(context,
|
|
919
|
+
context->Global(),
|
|
920
|
+
1,
|
|
921
|
+
args); // ignore JS return value
|
|
922
|
+
delete static_cast<AsyncCallback *>(data);
|
|
923
|
+
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
if (pipelineData->type !=
|
|
928
|
+
CanvasGPUErrorType::CanvasGPUErrorTypeNone) {
|
|
929
|
+
|
|
930
|
+
auto error = v8::Object::New(
|
|
931
|
+
isolate);
|
|
932
|
+
error->Set(context,
|
|
933
|
+
ConvertToV8String(
|
|
934
|
+
isolate,
|
|
935
|
+
"error"),
|
|
936
|
+
v8::Exception::Error(
|
|
937
|
+
ConvertToV8String(
|
|
938
|
+
isolate,
|
|
939
|
+
pipelineData->errorMessage)));
|
|
940
|
+
|
|
941
|
+
error->Set(context,
|
|
942
|
+
ConvertToV8String(
|
|
943
|
+
isolate,
|
|
944
|
+
"type"),
|
|
945
|
+
v8::Uint32::NewFromUnsigned(
|
|
946
|
+
isolate,
|
|
947
|
+
(uint32_t) pipelineData->type));
|
|
948
|
+
|
|
949
|
+
v8::Local<v8::Value> args[1] = {
|
|
950
|
+
error};
|
|
951
|
+
|
|
952
|
+
callback->Call(context,
|
|
953
|
+
context->Global(),
|
|
954
|
+
1,
|
|
955
|
+
args); // ignore JS return value
|
|
956
|
+
} else {
|
|
957
|
+
|
|
958
|
+
auto ret = GPUComputePipelineImpl::NewInstance(
|
|
959
|
+
isolate,
|
|
960
|
+
new GPUComputePipelineImpl(
|
|
961
|
+
pipelineData->pipeline));
|
|
962
|
+
|
|
963
|
+
v8::Local<v8::Value> args[2] = {
|
|
964
|
+
v8::Null(isolate), ret};
|
|
965
|
+
|
|
966
|
+
|
|
967
|
+
callback->Call(context,
|
|
968
|
+
context->Global(),
|
|
969
|
+
2,
|
|
970
|
+
args); // ignore JS return value
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
if (pipelineData != nullptr) {
|
|
974
|
+
delete pipelineData;
|
|
975
|
+
pipelineData = nullptr;
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
delete static_cast<AsyncCallback *>(data);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
});
|
|
982
|
+
async_callback->inner_->data = new ComputePipeLineAsyncData{
|
|
983
|
+
entry_point,
|
|
984
|
+
store,
|
|
985
|
+
CanvasGPUErrorType::CanvasGPUErrorTypeNone,
|
|
986
|
+
nullptr,
|
|
987
|
+
nullptr
|
|
988
|
+
};
|
|
989
|
+
async_callback->prepare();
|
|
990
|
+
canvas_native_webgpu_device_create_compute_pipeline_async(ptr->GetGPUDevice(),
|
|
991
|
+
*label, layout, &stage,
|
|
992
|
+
[](const struct CanvasGPUComputePipeline *pipeline,
|
|
993
|
+
enum CanvasGPUErrorType type,
|
|
994
|
+
char *message,
|
|
995
|
+
void *data) {
|
|
996
|
+
if (data != nullptr) {
|
|
997
|
+
auto async_data = static_cast<AsyncCallback *>(data);
|
|
998
|
+
auto inner = async_data->inner_.get();
|
|
999
|
+
if (inner != nullptr) {
|
|
1000
|
+
auto pipeline_data = static_cast<ComputePipeLineAsyncData *>(inner->data);
|
|
1001
|
+
pipeline_data->errorMessage = message;
|
|
1002
|
+
pipeline_data->type = type;
|
|
1003
|
+
pipeline_data->pipeline = pipeline;
|
|
1004
|
+
async_data->execute(
|
|
1005
|
+
true);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
}, async_callback);
|
|
1009
|
+
|
|
1010
|
+
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
args.GetReturnValue().SetUndefined();
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
void GPUDeviceImpl::CreatePipelineLayout(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
1017
|
+
GPUDeviceImpl *ptr = GetPointer(args.This());
|
|
1018
|
+
if (ptr == nullptr) {
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1021
|
+
auto isolate = args.GetIsolate();
|
|
1022
|
+
auto context = isolate->GetCurrentContext();
|
|
1023
|
+
|
|
1024
|
+
auto optionsVal = args[0];
|
|
1025
|
+
|
|
1026
|
+
if (!optionsVal->IsObject()) {
|
|
1027
|
+
// should error at this point
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
auto options = optionsVal.As<v8::Object>();
|
|
1031
|
+
|
|
1032
|
+
v8::Local<v8::Value> labelVal;
|
|
1033
|
+
options->Get(context, ConvertToV8String(isolate, "label")).ToLocal(&labelVal);
|
|
1034
|
+
|
|
1035
|
+
auto label = GPULabel(isolate, labelVal);
|
|
1036
|
+
|
|
1037
|
+
|
|
1038
|
+
std::vector<const CanvasGPUBindGroupLayout *> group_layouts;
|
|
1039
|
+
|
|
1040
|
+
v8::Local<v8::Value> groupLayoutsVal;
|
|
1041
|
+
options->Get(context, ConvertToV8String(isolate, "bindGroupLayouts")).ToLocal(&groupLayoutsVal);
|
|
1042
|
+
|
|
1043
|
+
if (!groupLayoutsVal.IsEmpty() && groupLayoutsVal->IsArray()) {
|
|
1044
|
+
auto groupLayoutsArray = groupLayoutsVal.As<v8::Array>();
|
|
1045
|
+
auto len = groupLayoutsArray->Length();
|
|
1046
|
+
for (int i = 0; i < len; i++) {
|
|
1047
|
+
v8::Local<v8::Value> groupVal;
|
|
1048
|
+
groupLayoutsArray->Get(context, i).ToLocal(&groupVal);
|
|
1049
|
+
if (GetNativeType(groupVal) == NativeType::GPUBindGroupLayout) {
|
|
1050
|
+
auto layout = GPUBindGroupLayoutImpl::GetPointer(groupVal.As<v8::Object>());
|
|
1051
|
+
if (layout != nullptr) {
|
|
1052
|
+
group_layouts.push_back(layout->GetBindGroupLayout());
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
auto layout = canvas_native_webgpu_device_create_pipeline_layout(ptr->GetGPUDevice(),
|
|
1058
|
+
*label,
|
|
1059
|
+
group_layouts.data(),
|
|
1224
1060
|
group_layouts.size());
|
|
1225
1061
|
|
|
1226
1062
|
if (layout != nullptr) {
|
|
@@ -1229,158 +1065,1126 @@ void GPUDeviceImpl::CreatePipelineLayout(const v8::FunctionCallbackInfo<v8::Valu
|
|
|
1229
1065
|
args.GetReturnValue().Set(ret);
|
|
1230
1066
|
return;
|
|
1231
1067
|
}
|
|
1232
|
-
}
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
|
|
1071
|
+
args.GetReturnValue().SetUndefined();
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
void GPUDeviceImpl::CreateQuerySet(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
1075
|
+
GPUDeviceImpl *ptr = GetPointer(args.This());
|
|
1076
|
+
if (ptr == nullptr) {
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
auto isolate = args.GetIsolate();
|
|
1080
|
+
auto context = isolate->GetCurrentContext();
|
|
1081
|
+
|
|
1082
|
+
auto optionsVal = args[0];
|
|
1083
|
+
|
|
1084
|
+
if (!optionsVal->IsObject()) {
|
|
1085
|
+
// should error at this point
|
|
1086
|
+
return;
|
|
1087
|
+
}
|
|
1088
|
+
auto options = optionsVal.As<v8::Object>();
|
|
1089
|
+
|
|
1090
|
+
v8::Local<v8::Value> labelVal;
|
|
1091
|
+
options->Get(context, ConvertToV8String(isolate, "label")).ToLocal(&labelVal);
|
|
1092
|
+
|
|
1093
|
+
auto label = GPULabel(isolate, labelVal);
|
|
1094
|
+
v8::Local<v8::Value> typeVal;
|
|
1095
|
+
options->Get(context, ConvertToV8String(isolate, "type")).ToLocal(&typeVal);
|
|
1096
|
+
|
|
1097
|
+
|
|
1098
|
+
v8::Local<v8::Value> countVal;
|
|
1099
|
+
options->Get(context, ConvertToV8String(isolate, "count")).ToLocal(&countVal);
|
|
1100
|
+
|
|
1101
|
+
auto typeStr = ConvertFromV8String(isolate, typeVal);
|
|
1102
|
+
|
|
1103
|
+
const CanvasGPUQuerySet *query_set = nullptr;
|
|
1104
|
+
if (typeStr == "occlusion") {
|
|
1105
|
+
query_set = canvas_native_webgpu_device_create_query_set(ptr->GetGPUDevice(), *label,
|
|
1106
|
+
CanvasQueryTypeOcclusion,
|
|
1107
|
+
countVal->Uint32Value(
|
|
1108
|
+
context).FromJust());
|
|
1109
|
+
} else if (typeStr == "timestamp") {
|
|
1110
|
+
query_set = canvas_native_webgpu_device_create_query_set(ptr->GetGPUDevice(), *label,
|
|
1111
|
+
CanvasQueryTypeTimestamp,
|
|
1112
|
+
countVal->Uint32Value(
|
|
1113
|
+
context).FromJust());
|
|
1114
|
+
} else {
|
|
1115
|
+
// todo throw
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
|
|
1119
|
+
if (query_set != nullptr) {
|
|
1120
|
+
auto ret = GPUQuerySetImpl::NewInstance(isolate, new GPUQuerySetImpl(query_set));
|
|
1121
|
+
args.GetReturnValue().Set(ret);
|
|
1122
|
+
return;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
args.GetReturnValue().SetUndefined();
|
|
1126
|
+
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
void GPUDeviceImpl::CreateRenderBundleEncoder(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
1130
|
+
GPUDeviceImpl *ptr = GetPointer(args.This());
|
|
1131
|
+
if (ptr == nullptr) {
|
|
1132
|
+
return;
|
|
1133
|
+
}
|
|
1134
|
+
auto isolate = args.GetIsolate();
|
|
1135
|
+
auto context = isolate->GetCurrentContext();
|
|
1136
|
+
|
|
1137
|
+
auto optionsVal = args[0];
|
|
1138
|
+
|
|
1139
|
+
if (!optionsVal->IsObject()) {
|
|
1140
|
+
// should error at this point
|
|
1141
|
+
return;
|
|
1142
|
+
}
|
|
1143
|
+
auto options = optionsVal.As<v8::Object>();
|
|
1144
|
+
|
|
1145
|
+
v8::Local<v8::Value> labelVal;
|
|
1146
|
+
options->Get(context, ConvertToV8String(isolate, "label")).ToLocal(&labelVal);
|
|
1147
|
+
|
|
1148
|
+
auto label = GPULabel(isolate, labelVal);
|
|
1149
|
+
|
|
1150
|
+
std::vector<CanvasGPUTextureFormat> colorFormats;
|
|
1151
|
+
|
|
1152
|
+
v8::Local<v8::Value> colorFormatsVal;
|
|
1153
|
+
options->Get(context, ConvertToV8String(isolate, "colorFormats")).ToLocal(&colorFormatsVal);
|
|
1154
|
+
|
|
1155
|
+
if (!colorFormatsVal.IsEmpty() && colorFormatsVal->IsArray()) {
|
|
1156
|
+
auto colorFormatsArray = colorFormatsVal.As<v8::Array>();
|
|
1157
|
+
auto len = colorFormatsArray->Length();
|
|
1158
|
+
for (int i = 0; i < len; i++) {
|
|
1159
|
+
v8::Local<v8::Value> formatVal;
|
|
1160
|
+
colorFormatsArray->Get(context, i).ToLocal(&formatVal);
|
|
1161
|
+
if (!formatVal.IsEmpty() && formatVal->IsString()) {
|
|
1162
|
+
auto formatStr = ConvertFromV8String(isolate, formatVal);
|
|
1163
|
+
auto format = canvas_native_webgpu_enum_string_to_gpu_texture(formatStr.c_str());
|
|
1164
|
+
if (format.tag == CanvasOptionalGPUTextureFormatSome) {
|
|
1165
|
+
colorFormats.push_back(format.some);
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
|
|
1173
|
+
auto depthStencilFormat = CanvasOptionalGPUTextureFormat{
|
|
1174
|
+
CanvasOptionalGPUTextureFormatNone
|
|
1175
|
+
};
|
|
1176
|
+
|
|
1177
|
+
v8::Local<v8::Value> depthStencilFormatVal;
|
|
1178
|
+
options->Get(context, ConvertToV8String(isolate, "depthStencilFormat")).ToLocal(
|
|
1179
|
+
&depthStencilFormatVal);
|
|
1180
|
+
|
|
1181
|
+
if (!depthStencilFormatVal.IsEmpty() && depthStencilFormatVal->IsString()) {
|
|
1182
|
+
auto depthStencilFormatStr = ConvertFromV8String(isolate, depthStencilFormatVal);
|
|
1183
|
+
depthStencilFormat = canvas_native_webgpu_enum_string_to_gpu_texture(
|
|
1184
|
+
depthStencilFormatStr.c_str());
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
uint32_t sampleCount = 1;
|
|
1188
|
+
|
|
1189
|
+
bool depthReadOnly = false;
|
|
1190
|
+
|
|
1191
|
+
bool stencilReadOnly = false;
|
|
1192
|
+
|
|
1193
|
+
CanvasCreateRenderBundleEncoderDescriptor descriptor{
|
|
1194
|
+
*label,
|
|
1195
|
+
colorFormats.data(),
|
|
1196
|
+
colorFormats.size(),
|
|
1197
|
+
depthStencilFormat,
|
|
1198
|
+
sampleCount,
|
|
1199
|
+
depthReadOnly,
|
|
1200
|
+
stencilReadOnly
|
|
1201
|
+
};
|
|
1202
|
+
|
|
1203
|
+
|
|
1204
|
+
auto encoder = canvas_native_webgpu_device_create_render_bundle_encoder(ptr->GetGPUDevice(),
|
|
1205
|
+
&descriptor);
|
|
1206
|
+
|
|
1207
|
+
if (encoder != nullptr) {
|
|
1208
|
+
auto ret = GPURenderBundleEncoderImpl::NewInstance(isolate,
|
|
1209
|
+
new GPURenderBundleEncoderImpl(encoder));
|
|
1210
|
+
args.GetReturnValue().Set(ret);
|
|
1211
|
+
return;
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
args.GetReturnValue().SetUndefined();
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
struct RenderPipeLineAsyncData {
|
|
1218
|
+
char *label;
|
|
1219
|
+
char *vertex_entry_point;
|
|
1220
|
+
char *fragment_entry_point;
|
|
1221
|
+
CanvasConstants *constants;
|
|
1222
|
+
enum CanvasGPUErrorType type;
|
|
1223
|
+
char *errorMessage;
|
|
1224
|
+
const CanvasGPURenderPipeline *pipeline;
|
|
1225
|
+
CanvasPrimitiveState *primitive;
|
|
1226
|
+
CanvasMultisampleState *multisample;
|
|
1227
|
+
CanvasDepthStencilState *depth_stencil;
|
|
1228
|
+
CanvasConstants *vertex_constants;
|
|
1229
|
+
|
|
1230
|
+
~RenderPipeLineAsyncData() {
|
|
1231
|
+
if (label != nullptr) {
|
|
1232
|
+
free(label);
|
|
1233
|
+
label = nullptr;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
if (constants != nullptr) {
|
|
1237
|
+
canvas_native_webgpu_constants_destroy(constants);
|
|
1238
|
+
constants = nullptr;
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
if (errorMessage != nullptr) {
|
|
1242
|
+
canvas_native_string_destroy(errorMessage);
|
|
1243
|
+
errorMessage = nullptr;
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
if (primitive != nullptr) {
|
|
1247
|
+
delete primitive;
|
|
1248
|
+
primitive = nullptr;
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
if (multisample != nullptr) {
|
|
1252
|
+
delete multisample;
|
|
1253
|
+
multisample = nullptr;
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
if (vertex_entry_point != nullptr) {
|
|
1257
|
+
free(vertex_entry_point);
|
|
1258
|
+
vertex_entry_point = nullptr;
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
if (fragment_entry_point != nullptr) {
|
|
1262
|
+
free(fragment_entry_point);
|
|
1263
|
+
fragment_entry_point = nullptr;
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
if (depth_stencil != nullptr) {
|
|
1267
|
+
delete depth_stencil;
|
|
1268
|
+
depth_stencil = nullptr;
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
if (vertex_constants != nullptr) {
|
|
1272
|
+
canvas_native_webgpu_constants_destroy(vertex_constants);
|
|
1273
|
+
vertex_constants = nullptr;
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
};
|
|
1277
|
+
|
|
1278
|
+
void GPUDeviceImpl::CreateRenderPipeline(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
1279
|
+
GPUDeviceImpl *ptr = GetPointer(args.This());
|
|
1280
|
+
if (ptr == nullptr) {
|
|
1281
|
+
return;
|
|
1282
|
+
}
|
|
1283
|
+
auto isolate = args.GetIsolate();
|
|
1284
|
+
auto context = isolate->GetCurrentContext();
|
|
1285
|
+
|
|
1286
|
+
CanvasCreateRenderPipelineDescriptor descriptor{};
|
|
1287
|
+
descriptor.label = nullptr;
|
|
1288
|
+
|
|
1289
|
+
auto optionsVal = args[0];
|
|
1290
|
+
|
|
1291
|
+
if (!optionsVal->IsObject()) {
|
|
1292
|
+
// should error at this point
|
|
1293
|
+
return;
|
|
1294
|
+
}
|
|
1295
|
+
auto options = optionsVal.As<v8::Object>();
|
|
1296
|
+
|
|
1297
|
+
v8::Local<v8::Value> stencilValue;
|
|
1298
|
+
options->Get(context, ConvertToV8String(isolate, "depthStencil")).ToLocal(
|
|
1299
|
+
&stencilValue);
|
|
1300
|
+
|
|
1301
|
+
CanvasDepthStencilState *stencil = nullptr;
|
|
1302
|
+
|
|
1303
|
+
if (!stencilValue.IsEmpty() && stencilValue->IsObject()) {
|
|
1304
|
+
auto stencilObj = stencilValue.As<v8::Object>();
|
|
1305
|
+
stencil = new CanvasDepthStencilState{};
|
|
1306
|
+
stencil->depth_bias = 0;
|
|
1307
|
+
stencil->depth_bias_clamp = 0;
|
|
1308
|
+
stencil->depth_bias_slope_scale = 0;
|
|
1309
|
+
stencil->stencil_read_mask = 0xFFFFFFFF;
|
|
1310
|
+
stencil->stencil_write_mask = 0xFFFFFFFF;
|
|
1311
|
+
stencil->stencil_front = CanvasStencilFaceState{
|
|
1312
|
+
CanvasCompareFunctionAlways,
|
|
1313
|
+
CanvasStencilOperationKeep,
|
|
1314
|
+
CanvasStencilOperationKeep,
|
|
1315
|
+
CanvasStencilOperationKeep
|
|
1316
|
+
};
|
|
1317
|
+
|
|
1318
|
+
stencil->stencil_back = CanvasStencilFaceState{
|
|
1319
|
+
CanvasCompareFunctionAlways,
|
|
1320
|
+
CanvasStencilOperationKeep,
|
|
1321
|
+
CanvasStencilOperationKeep,
|
|
1322
|
+
CanvasStencilOperationKeep
|
|
1323
|
+
};
|
|
1324
|
+
// todo throw if failed
|
|
1325
|
+
v8::Local<v8::Value> formatValue;
|
|
1326
|
+
|
|
1327
|
+
stencilObj->Get(context, ConvertToV8String(isolate, "format")).ToLocal(&formatValue);
|
|
1328
|
+
if (!formatValue.IsEmpty() && formatValue->IsString()) {
|
|
1329
|
+
auto val = ConvertFromV8String(isolate, formatValue);
|
|
1330
|
+
auto format = canvas_native_webgpu_enum_string_to_gpu_texture(
|
|
1331
|
+
val.c_str());
|
|
1332
|
+
if (format.tag ==
|
|
1333
|
+
CanvasOptionalGPUTextureFormat_Tag::CanvasOptionalGPUTextureFormatSome) {
|
|
1334
|
+
stencil->format = format.some;
|
|
1335
|
+
}
|
|
1336
|
+
} else {
|
|
1337
|
+
// todo throw
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
v8::Local<v8::Value> depthBiasVal;
|
|
1341
|
+
stencilObj->Get(context, ConvertToV8String(isolate, "depthBias")).ToLocal(&depthBiasVal);
|
|
1342
|
+
|
|
1343
|
+
if (!depthBiasVal.IsEmpty() && depthBiasVal->IsInt32()) {
|
|
1344
|
+
stencil->depth_bias = depthBiasVal->Int32Value(context).FromJust();
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
v8::Local<v8::Value> depthBiasClampVal;
|
|
1348
|
+
stencilObj->Get(context, ConvertToV8String(isolate, "depthBiasClamp")).ToLocal(
|
|
1349
|
+
&depthBiasClampVal);
|
|
1350
|
+
|
|
1351
|
+
if (!depthBiasClampVal.IsEmpty() && depthBiasClampVal->IsNumber()) {
|
|
1352
|
+
stencil->depth_bias_clamp = (float) depthBiasClampVal->NumberValue(context).FromJust();
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
|
|
1356
|
+
v8::Local<v8::Value> depthBiasSlopeScaleVal;
|
|
1357
|
+
stencilObj->Get(context, ConvertToV8String(isolate, "depthBiasSlopeScale")).ToLocal(
|
|
1358
|
+
&depthBiasSlopeScaleVal);
|
|
1359
|
+
|
|
1360
|
+
if (!depthBiasSlopeScaleVal.IsEmpty() && depthBiasSlopeScaleVal->IsNumber()) {
|
|
1361
|
+
stencil->depth_bias_slope_scale = (float) depthBiasSlopeScaleVal->NumberValue(
|
|
1362
|
+
context).FromJust();
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
v8::Local<v8::Value> depthCompareVal;
|
|
1366
|
+
stencilObj->Get(context, ConvertToV8String(isolate, "depthCompare")).ToLocal(
|
|
1367
|
+
&depthCompareVal);
|
|
1368
|
+
|
|
1369
|
+
auto depthCompareStr = ConvertFromV8String(isolate, depthCompareVal);
|
|
1370
|
+
|
|
1371
|
+
if (depthCompareStr == "never") {
|
|
1372
|
+
stencil->depth_compare = CanvasCompareFunctionNever;
|
|
1373
|
+
} else if (depthCompareStr == "less") {
|
|
1374
|
+
stencil->depth_compare = CanvasCompareFunctionLess;
|
|
1375
|
+
} else if (depthCompareStr == "equal") {
|
|
1376
|
+
stencil->depth_compare = CanvasCompareFunctionEqual;
|
|
1377
|
+
} else if (depthCompareStr == "less-equal") {
|
|
1378
|
+
stencil->depth_compare = CanvasCompareFunctionLessEqual;
|
|
1379
|
+
} else if (depthCompareStr == "greater") {
|
|
1380
|
+
stencil->depth_compare = CanvasCompareFunctionGreater;
|
|
1381
|
+
} else if (depthCompareStr == "not-equal") {
|
|
1382
|
+
stencil->depth_compare = CanvasCompareFunctionNotEqual;
|
|
1383
|
+
} else if (depthCompareStr == "greater-equal") {
|
|
1384
|
+
stencil->depth_compare = CanvasCompareFunctionGreaterEqual;
|
|
1385
|
+
} else if (depthCompareStr == "always") {
|
|
1386
|
+
stencil->depth_compare = CanvasCompareFunctionAlways;
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
stencil->depth_write_enabled = stencilObj->Get(context, ConvertToV8String(isolate,
|
|
1390
|
+
"depthWriteEnabled")).ToLocalChecked()->BooleanValue(
|
|
1391
|
+
isolate);
|
|
1392
|
+
|
|
1393
|
+
|
|
1394
|
+
v8::Local<v8::Value> stencilBackVal;
|
|
1395
|
+
stencilObj->Get(context, ConvertToV8String(isolate, "stencilBack")).ToLocal(
|
|
1396
|
+
&stencilBackVal);
|
|
1397
|
+
|
|
1398
|
+
if (!stencilBackVal.IsEmpty() && stencilBackVal->IsObject()) {
|
|
1399
|
+
auto stencilBackObj = stencilBackVal.As<v8::Object>();
|
|
1400
|
+
|
|
1401
|
+
v8::Local<v8::Value> compareVal;
|
|
1402
|
+
stencilBackObj->Get(context, ConvertToV8String(isolate, "compare")).ToLocal(
|
|
1403
|
+
&compareVal);
|
|
1404
|
+
|
|
1405
|
+
stencil->stencil_back.compare = ParseCompareFunction(isolate, compareVal,
|
|
1406
|
+
stencil->stencil_back.compare);
|
|
1407
|
+
|
|
1408
|
+
v8::Local<v8::Value> depthFailOpVal;
|
|
1409
|
+
stencilBackObj->Get(context, ConvertToV8String(isolate, "depthFailOp")).ToLocal(
|
|
1410
|
+
&depthFailOpVal);
|
|
1411
|
+
|
|
1412
|
+
stencil->stencil_back.depth_fail_op = ParseStencilOperation(isolate, depthFailOpVal,
|
|
1413
|
+
stencil->stencil_back.depth_fail_op);
|
|
1414
|
+
|
|
1415
|
+
|
|
1416
|
+
v8::Local<v8::Value> failOpVal;
|
|
1417
|
+
stencilBackObj->Get(context, ConvertToV8String(isolate, "failOp")).ToLocal(
|
|
1418
|
+
&failOpVal);
|
|
1419
|
+
|
|
1420
|
+
stencil->stencil_back.fail_op = ParseStencilOperation(isolate, failOpVal,
|
|
1421
|
+
stencil->stencil_back.fail_op);
|
|
1422
|
+
|
|
1423
|
+
v8::Local<v8::Value> passOpVal;
|
|
1424
|
+
stencilBackObj->Get(context, ConvertToV8String(isolate, "passOp")).ToLocal(
|
|
1425
|
+
&passOpVal);
|
|
1426
|
+
|
|
1427
|
+
stencil->stencil_back.pass_op = ParseStencilOperation(isolate, passOpVal,
|
|
1428
|
+
stencil->stencil_back.pass_op);
|
|
1429
|
+
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
|
|
1433
|
+
v8::Local<v8::Value> stencilFrontVal;
|
|
1434
|
+
stencilObj->Get(context, ConvertToV8String(isolate, "stencilFront")).ToLocal(
|
|
1435
|
+
&stencilFrontVal);
|
|
1436
|
+
|
|
1437
|
+
if (!stencilFrontVal.IsEmpty() && stencilFrontVal->IsObject()) {
|
|
1438
|
+
auto stencilFrontObj = stencilFrontVal.As<v8::Object>();
|
|
1439
|
+
|
|
1440
|
+
v8::Local<v8::Value> compareVal;
|
|
1441
|
+
stencilFrontObj->Get(context, ConvertToV8String(isolate, "compare")).ToLocal(
|
|
1442
|
+
&compareVal);
|
|
1443
|
+
|
|
1444
|
+
stencil->stencil_front.compare = ParseCompareFunction(isolate, compareVal,
|
|
1445
|
+
stencil->stencil_front.compare);
|
|
1446
|
+
|
|
1447
|
+
v8::Local<v8::Value> depthFailOpVal;
|
|
1448
|
+
stencilFrontObj->Get(context, ConvertToV8String(isolate, "depthFailOp")).ToLocal(
|
|
1449
|
+
&depthFailOpVal);
|
|
1450
|
+
|
|
1451
|
+
stencil->stencil_front.depth_fail_op = ParseStencilOperation(isolate, depthFailOpVal,
|
|
1452
|
+
stencil->stencil_front.depth_fail_op);
|
|
1453
|
+
|
|
1454
|
+
|
|
1455
|
+
v8::Local<v8::Value> failOpVal;
|
|
1456
|
+
stencilFrontObj->Get(context, ConvertToV8String(isolate, "failOp")).ToLocal(
|
|
1457
|
+
&failOpVal);
|
|
1458
|
+
|
|
1459
|
+
stencil->stencil_front.fail_op = ParseStencilOperation(isolate, failOpVal,
|
|
1460
|
+
stencil->stencil_front.fail_op);
|
|
1461
|
+
|
|
1462
|
+
v8::Local<v8::Value> passOpVal;
|
|
1463
|
+
stencilFrontObj->Get(context, ConvertToV8String(isolate, "passOp")).ToLocal(
|
|
1464
|
+
&passOpVal);
|
|
1465
|
+
|
|
1466
|
+
stencil->stencil_front.pass_op = ParseStencilOperation(isolate, passOpVal,
|
|
1467
|
+
stencil->stencil_front.pass_op);
|
|
1468
|
+
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
v8::Local<v8::Value> stencilReadMaskVal;
|
|
1472
|
+
stencilObj->Get(context, ConvertToV8String(isolate, "stencilReadMask")).ToLocal(
|
|
1473
|
+
&stencilReadMaskVal);
|
|
1474
|
+
|
|
1475
|
+
if (!stencilReadMaskVal.IsEmpty() && stencilReadMaskVal->IsUint32()) {
|
|
1476
|
+
stencil->stencil_read_mask = stencilReadMaskVal->Uint32Value(context).FromJust();
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
|
|
1480
|
+
v8::Local<v8::Value> stencilWriteMaskVal;
|
|
1481
|
+
stencilObj->Get(context, ConvertToV8String(isolate, "stencilWriteMask")).ToLocal(
|
|
1482
|
+
&stencilWriteMaskVal);
|
|
1483
|
+
|
|
1484
|
+
if (!stencilWriteMaskVal.IsEmpty() && stencilWriteMaskVal->IsUint32()) {
|
|
1485
|
+
stencil->stencil_write_mask = stencilWriteMaskVal->Uint32Value(context).FromJust();
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
descriptor.depth_stencil = stencil;
|
|
1489
|
+
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
|
|
1493
|
+
v8::Local<v8::Value> fragmentValue;
|
|
1494
|
+
options->Get(context, ConvertToV8String(isolate, "fragment")).ToLocal(
|
|
1495
|
+
&fragmentValue);
|
|
1496
|
+
|
|
1497
|
+
CanvasFragmentState *fragment = nullptr;
|
|
1498
|
+
|
|
1499
|
+
std::vector<CanvasColorTargetState> targets;
|
|
1500
|
+
|
|
1501
|
+
if (!fragmentValue.IsEmpty() && fragmentValue->IsObject()) {
|
|
1502
|
+
auto fragmentValueObj = fragmentValue.As<v8::Object>();
|
|
1503
|
+
fragment = new CanvasFragmentState{};
|
|
1504
|
+
|
|
1505
|
+
v8::Local<v8::Value> targetsVal;
|
|
1506
|
+
fragmentValueObj->Get(context, ConvertToV8String(isolate, "targets")).ToLocal(&targetsVal);
|
|
1507
|
+
|
|
1508
|
+
|
|
1509
|
+
auto targetsArray = targetsVal.As<v8::Array>();
|
|
1510
|
+
auto len = targetsArray->Length();
|
|
1511
|
+
|
|
1512
|
+
for (int i = 0; i < len; i++) {
|
|
1513
|
+
auto state = targetsArray->Get(context, i).ToLocalChecked().As<v8::Object>();
|
|
1514
|
+
|
|
1515
|
+
auto formatVal = state->Get(context,
|
|
1516
|
+
ConvertToV8String(isolate, "format")).ToLocalChecked();
|
|
1517
|
+
auto formatStr = ConvertFromV8String(isolate, formatVal);
|
|
1518
|
+
auto formatResult = canvas_native_webgpu_enum_string_to_gpu_texture(formatStr.c_str());
|
|
1519
|
+
|
|
1520
|
+
|
|
1521
|
+
if (formatResult.tag == CanvasOptionalGPUTextureFormatNone) {
|
|
1522
|
+
// todo throw
|
|
1523
|
+
args.GetReturnValue().SetUndefined();
|
|
1524
|
+
return;
|
|
1525
|
+
} else {}
|
|
1526
|
+
|
|
1527
|
+
auto format = CanvasGPUTextureFormat{
|
|
1528
|
+
formatResult.some.tag
|
|
1529
|
+
};
|
|
1530
|
+
|
|
1531
|
+
uint32_t writeMask = 0xF;
|
|
1532
|
+
|
|
1533
|
+
v8::Local<v8::Value> writeMaskVal;
|
|
1534
|
+
|
|
1535
|
+
state->Get(context, ConvertToV8String(isolate, "writeMask")).ToLocal(&writeMaskVal);
|
|
1536
|
+
|
|
1537
|
+
if (!writeMaskVal.IsEmpty() && writeMaskVal->IsUint32()) {
|
|
1538
|
+
writeMask = writeMaskVal->Uint32Value(context).FromJust();
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
CanvasOptionalBlendState blend{
|
|
1542
|
+
CanvasOptionalBlendStateNone
|
|
1543
|
+
};
|
|
1544
|
+
|
|
1545
|
+
v8::Local<v8::Value> blendVal;
|
|
1546
|
+
|
|
1547
|
+
state->Get(context, ConvertToV8String(isolate, "blend")).ToLocal(&blendVal);
|
|
1548
|
+
|
|
1549
|
+
if (!blendVal.IsEmpty() && blendVal->IsObject()) {
|
|
1550
|
+
auto blendObj = blendVal.As<v8::Object>();
|
|
1551
|
+
auto alpha = blendObj->Get(context, ConvertToV8String(isolate,
|
|
1552
|
+
"alpha")).ToLocalChecked().As<v8::Object>();
|
|
1553
|
+
|
|
1554
|
+
v8::Local<v8::Value> alphaSrcFactorVal;
|
|
1555
|
+
|
|
1556
|
+
alpha->Get(context,
|
|
1557
|
+
ConvertToV8String(isolate,
|
|
1558
|
+
"srcFactor")).ToLocal(&alphaSrcFactorVal);
|
|
1559
|
+
|
|
1560
|
+
auto alphaSrcFactor = ParseBlendFactor(isolate, alphaSrcFactorVal,
|
|
1561
|
+
CanvasBlendFactorZero);
|
|
1562
|
+
|
|
1563
|
+
v8::Local<v8::Value> alphaDstFactorVal;
|
|
1564
|
+
alpha->Get(context,
|
|
1565
|
+
ConvertToV8String(isolate,
|
|
1566
|
+
"dstFactor")).ToLocal(&alphaDstFactorVal);
|
|
1567
|
+
|
|
1568
|
+
auto alphaDstFactor = ParseBlendFactor(isolate, alphaDstFactorVal,
|
|
1569
|
+
CanvasBlendFactorZero);
|
|
1570
|
+
|
|
1571
|
+
v8::Local<v8::Value> alphaOperationVal;
|
|
1572
|
+
|
|
1573
|
+
alpha->Get(context,
|
|
1574
|
+
ConvertToV8String(isolate,
|
|
1575
|
+
"operation")).ToLocal(&alphaOperationVal);
|
|
1576
|
+
|
|
1577
|
+
auto alphaOperation = ParseBlendOperation(isolate, alphaOperationVal,
|
|
1578
|
+
CanvasBlendOperationAdd);
|
|
1579
|
+
|
|
1580
|
+
auto alpha_val = CanvasBlendComponent{alphaSrcFactor, alphaDstFactor,
|
|
1581
|
+
alphaOperation};
|
|
1582
|
+
|
|
1583
|
+
auto color = blendObj->Get(context, ConvertToV8String(isolate,
|
|
1584
|
+
"color")).ToLocalChecked().As<v8::Object>();
|
|
1585
|
+
|
|
1586
|
+
|
|
1587
|
+
v8::Local<v8::Value> colorSrcFactorVal;
|
|
1588
|
+
|
|
1589
|
+
color->Get(context,
|
|
1590
|
+
ConvertToV8String(isolate,
|
|
1591
|
+
"srcFactor")).ToLocal(&colorSrcFactorVal);
|
|
1592
|
+
|
|
1593
|
+
auto colorSrcFactor = ParseBlendFactor(isolate, colorSrcFactorVal,
|
|
1594
|
+
CanvasBlendFactorZero);
|
|
1595
|
+
|
|
1596
|
+
v8::Local<v8::Value> colorDstFactorVal;
|
|
1597
|
+
color->Get(context,
|
|
1598
|
+
ConvertToV8String(isolate,
|
|
1599
|
+
"dstFactor")).ToLocal(&colorDstFactorVal);
|
|
1600
|
+
|
|
1601
|
+
auto colorDstFactor = ParseBlendFactor(isolate, colorDstFactorVal,
|
|
1602
|
+
CanvasBlendFactorZero);
|
|
1603
|
+
|
|
1604
|
+
v8::Local<v8::Value> colorOperationVal;
|
|
1605
|
+
|
|
1606
|
+
color->Get(context,
|
|
1607
|
+
ConvertToV8String(isolate,
|
|
1608
|
+
"operation")).ToLocal(&colorOperationVal);
|
|
1609
|
+
|
|
1610
|
+
auto colorOperation = ParseBlendOperation(isolate, colorOperationVal,
|
|
1611
|
+
CanvasBlendOperationAdd);
|
|
1612
|
+
|
|
1613
|
+
|
|
1614
|
+
auto color_val = CanvasBlendComponent{colorSrcFactor, colorDstFactor,
|
|
1615
|
+
colorOperation};
|
|
1616
|
+
|
|
1617
|
+
|
|
1618
|
+
blend = CanvasOptionalBlendState{
|
|
1619
|
+
CanvasOptionalBlendStateSome,
|
|
1620
|
+
CanvasBlendState{
|
|
1621
|
+
color_val, alpha_val
|
|
1622
|
+
}
|
|
1623
|
+
};
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
auto targetState = CanvasColorTargetState{
|
|
1627
|
+
format,
|
|
1628
|
+
blend,
|
|
1629
|
+
writeMask
|
|
1630
|
+
};
|
|
1631
|
+
|
|
1632
|
+
targets.push_back(targetState);
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
if (!targets.empty()) {
|
|
1636
|
+
fragment->targets = targets.data();
|
|
1637
|
+
fragment->targets_size = targets.size();
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
v8::Local<v8::Value> constantsVal;
|
|
1641
|
+
fragmentValueObj->Get(context, ConvertToV8String(isolate, "constants")).ToLocal(
|
|
1642
|
+
&constantsVal);
|
|
1643
|
+
|
|
1644
|
+
if (!constantsVal.IsEmpty() && constantsVal->IsMap()) {
|
|
1645
|
+
auto constants = constantsVal.As<v8::Map>();
|
|
1646
|
+
auto keyValues = constants->AsArray();
|
|
1647
|
+
auto length = keyValues->Length();
|
|
1648
|
+
CanvasConstants *store = nullptr;
|
|
1649
|
+
|
|
1650
|
+
if (length > 0) {
|
|
1651
|
+
store = canvas_native_webgpu_constants_create();
|
|
1652
|
+
for (int i = 0; i < length; i += 2) {
|
|
1653
|
+
auto k = i;
|
|
1654
|
+
auto v = k + 1;
|
|
1655
|
+
|
|
1656
|
+
v8::Local<v8::Value> keyVal;
|
|
1657
|
+
keyValues->Get(context, k).ToLocal(&keyVal);
|
|
1658
|
+
v8::Local<v8::Value> valueVal;
|
|
1659
|
+
keyValues->Get(context, v).ToLocal(&valueVal);
|
|
1660
|
+
|
|
1661
|
+
|
|
1662
|
+
if (!keyVal.IsEmpty() && keyVal->IsString() && !valueVal.IsEmpty() &&
|
|
1663
|
+
valueVal->IsNumber()) {
|
|
1664
|
+
canvas_native_webgpu_constants_insert(
|
|
1665
|
+
store,
|
|
1666
|
+
*v8::String::Utf8Value(isolate, keyVal),
|
|
1667
|
+
valueVal.As<v8::Number>()->Value()
|
|
1668
|
+
);
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
fragment->constants = store;
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1676
|
+
|
|
1677
|
+
v8::Local<v8::Value> entryPoint;
|
|
1678
|
+
fragmentValueObj->Get(context, ConvertToV8String(isolate, "entryPoint")).ToLocal(
|
|
1679
|
+
&entryPoint);
|
|
1680
|
+
|
|
1681
|
+
|
|
1682
|
+
if (!entryPoint.IsEmpty() && entryPoint->IsString()) {
|
|
1683
|
+
auto ep = v8::String::Utf8Value(isolate, entryPoint);
|
|
1684
|
+
char *entry_point = (char *) malloc(ep.length());
|
|
1685
|
+
std::strcpy(entry_point, *ep);
|
|
1686
|
+
|
|
1687
|
+
fragment->entry_point = entry_point;
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1690
|
+
|
|
1691
|
+
v8::Local<v8::Value> moduleVal;
|
|
1692
|
+
fragmentValueObj->Get(context, ConvertToV8String(isolate, "module")).ToLocal(&moduleVal);
|
|
1693
|
+
|
|
1694
|
+
auto module = GPUShaderModuleImpl::GetPointer(moduleVal.As<v8::Object>());
|
|
1695
|
+
|
|
1696
|
+
fragment->module = module->GetShaderModule();
|
|
1697
|
+
|
|
1698
|
+
descriptor.fragment = fragment;
|
|
1699
|
+
|
|
1700
|
+
}
|
|
1701
|
+
|
|
1702
|
+
|
|
1703
|
+
v8::Local<v8::Value> labelVal;
|
|
1704
|
+
options->Get(context, ConvertToV8String(isolate, "label")).ToLocal(
|
|
1705
|
+
&labelVal);
|
|
1706
|
+
|
|
1707
|
+
|
|
1708
|
+
auto label = GPULabel(isolate, labelVal);
|
|
1709
|
+
|
|
1710
|
+
|
|
1711
|
+
descriptor.label = *label;
|
|
1712
|
+
|
|
1713
|
+
|
|
1714
|
+
v8::Local<v8::Value> layoutVal;
|
|
1715
|
+
options->Get(context, ConvertToV8String(isolate, "layout")).ToLocal(
|
|
1716
|
+
&layoutVal);
|
|
1717
|
+
|
|
1718
|
+
CanvasGPUPipelineLayoutOrGPUAutoLayoutMode layout;
|
|
1719
|
+
|
|
1720
|
+
if (layoutVal->IsString()) {
|
|
1721
|
+
layout = CanvasGPUPipelineLayoutOrGPUAutoLayoutMode{
|
|
1722
|
+
CanvasGPUPipelineLayoutOrGPUAutoLayoutModeAuto
|
|
1723
|
+
};
|
|
1724
|
+
} else if (!layoutVal->IsNullOrUndefined() && layoutVal->IsObject()) {
|
|
1725
|
+
auto pipeline = GPUPipelineLayoutImpl::GetPointer(layoutVal.As<v8::Object>());
|
|
1726
|
+
layout = CanvasGPUPipelineLayoutOrGPUAutoLayoutMode{
|
|
1727
|
+
CanvasGPUPipelineLayoutOrGPUAutoLayoutModeLayout,
|
|
1728
|
+
layout.layout = pipeline->GetPipeline()
|
|
1729
|
+
};
|
|
1730
|
+
} else {
|
|
1731
|
+
// todo throw ?
|
|
1732
|
+
layout = CanvasGPUPipelineLayoutOrGPUAutoLayoutMode{
|
|
1733
|
+
CanvasGPUPipelineLayoutOrGPUAutoLayoutModeAuto
|
|
1734
|
+
};
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
descriptor.layout = layout;
|
|
1738
|
+
|
|
1739
|
+
|
|
1740
|
+
v8::Local<v8::Value> multisampleValue;
|
|
1741
|
+
options->Get(context, ConvertToV8String(isolate, "multisample")).ToLocal(
|
|
1742
|
+
&multisampleValue);
|
|
1743
|
+
|
|
1744
|
+
|
|
1745
|
+
CanvasMultisampleState *multisample = nullptr;
|
|
1746
|
+
|
|
1747
|
+
if (!multisampleValue.IsEmpty() && multisampleValue->IsObject()) {
|
|
1748
|
+
auto multisampleObj = multisampleValue.As<v8::Object>();
|
|
1749
|
+
multisample = new CanvasMultisampleState{};
|
|
1750
|
+
multisample->alpha_to_coverage_enabled = false;
|
|
1751
|
+
multisample->count = 1;
|
|
1752
|
+
multisample->mask = 0xFFFFFFFF;
|
|
1753
|
+
|
|
1754
|
+
v8::Local<v8::Value> alphaToCoverageEnabled;
|
|
1755
|
+
v8::Local<v8::Value> count;
|
|
1756
|
+
v8::Local<v8::Value> mask;
|
|
1757
|
+
|
|
1758
|
+
multisampleObj->Get(context, ConvertToV8String(isolate, "alphaToCoverageEnabled")).
|
|
1759
|
+
ToLocal(&alphaToCoverageEnabled);
|
|
1760
|
+
|
|
1761
|
+
if (!alphaToCoverageEnabled.IsEmpty() && alphaToCoverageEnabled->IsBoolean()) {
|
|
1762
|
+
multisample->alpha_to_coverage_enabled = alphaToCoverageEnabled->BooleanValue(
|
|
1763
|
+
isolate);
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
multisampleObj->Get(context, ConvertToV8String(isolate, "count")).
|
|
1767
|
+
ToLocal(&count);
|
|
1768
|
+
|
|
1769
|
+
if (!count.IsEmpty() && count->IsUint32()) {
|
|
1770
|
+
multisample->count = count.As<v8::Uint32>()->Value();
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
multisampleObj->Get(context, ConvertToV8String(isolate, "mask")).
|
|
1774
|
+
ToLocal(&mask);
|
|
1775
|
+
|
|
1776
|
+
if (!mask.IsEmpty() && mask->IsNumber()) {
|
|
1777
|
+
// todo verify mask
|
|
1778
|
+
auto maskValue = mask.As<v8::Number>()->Value();
|
|
1779
|
+
multisample->mask = (uint64_t) maskValue;
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
|
|
1783
|
+
descriptor.multisample = multisample;
|
|
1784
|
+
|
|
1785
|
+
}
|
|
1786
|
+
|
|
1787
|
+
|
|
1788
|
+
v8::Local<v8::Value> primitiveValue;
|
|
1789
|
+
options->Get(context, ConvertToV8String(isolate, "primitive")).ToLocal(
|
|
1790
|
+
&primitiveValue);
|
|
1791
|
+
|
|
1792
|
+
|
|
1793
|
+
CanvasPrimitiveState *primitive = nullptr;
|
|
1794
|
+
|
|
1795
|
+
if (!primitiveValue.IsEmpty() && primitiveValue->IsObject()) {
|
|
1796
|
+
auto primitiveObj = primitiveValue.As<v8::Object>();
|
|
1797
|
+
primitive = new CanvasPrimitiveState{};
|
|
1798
|
+
|
|
1799
|
+
primitive->cull_mode = CanvasCullMode::CanvasCullModeNone;
|
|
1800
|
+
primitive->front_face = CanvasFrontFaceCcw;
|
|
1801
|
+
primitive->strip_index_format = CanvasOptionalIndexFormat{
|
|
1802
|
+
CanvasOptionalIndexFormatNone
|
|
1803
|
+
};
|
|
1804
|
+
|
|
1805
|
+
primitive->topology = CanvasPrimitiveTopologyTriangleList;
|
|
1806
|
+
|
|
1807
|
+
primitive->unclipped_depth = false;
|
|
1808
|
+
|
|
1809
|
+
|
|
1810
|
+
v8::Local<v8::Value> cullModeValue;
|
|
1811
|
+
|
|
1812
|
+
if (primitiveObj->Get(context, ConvertToV8String(isolate, "cullMode")).ToLocal(
|
|
1813
|
+
&cullModeValue)) {
|
|
1814
|
+
if (cullModeValue->IsUint32()) {
|
|
1815
|
+
auto cullMode = cullModeValue.As<v8::Uint32>()->Value();
|
|
1816
|
+
|
|
1817
|
+
switch (cullMode) {
|
|
1818
|
+
case 0:
|
|
1819
|
+
primitive->cull_mode = CanvasCullMode::CanvasCullModeNone;
|
|
1820
|
+
break;
|
|
1821
|
+
case 1:
|
|
1822
|
+
primitive->cull_mode = CanvasCullMode::CanvasCullModeFront;
|
|
1823
|
+
break;
|
|
1824
|
+
case 2:
|
|
1825
|
+
primitive->cull_mode = CanvasCullMode::CanvasCullModeBack;
|
|
1826
|
+
break;
|
|
1827
|
+
default:
|
|
1828
|
+
break;
|
|
1829
|
+
}
|
|
1830
|
+
} else if (cullModeValue->IsString()) {
|
|
1831
|
+
|
|
1832
|
+
auto cullMode = ConvertFromV8String(isolate, cullModeValue);
|
|
1833
|
+
|
|
1834
|
+
if (cullMode == "none") {
|
|
1835
|
+
primitive->cull_mode = CanvasCullMode::CanvasCullModeNone;
|
|
1836
|
+
} else if (cullMode == "front") {
|
|
1837
|
+
primitive->cull_mode = CanvasCullMode::CanvasCullModeFront;
|
|
1838
|
+
} else if (cullMode == "back") {
|
|
1839
|
+
primitive->cull_mode = CanvasCullMode::CanvasCullModeBack;
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
v8::Local<v8::Value> frontFaceValue;
|
|
1846
|
+
|
|
1847
|
+
if (primitiveObj->Get(context, ConvertToV8String(isolate, "frontFace")).ToLocal(
|
|
1848
|
+
&frontFaceValue)) {
|
|
1849
|
+
if (frontFaceValue->IsUint32()) {
|
|
1850
|
+
auto frontFace = frontFaceValue.As<v8::Uint32>()->Value();
|
|
1851
|
+
switch (frontFace) {
|
|
1852
|
+
case 0:
|
|
1853
|
+
primitive->front_face = CanvasFrontFace::CanvasFrontFaceCcw;
|
|
1854
|
+
break;
|
|
1855
|
+
case 1:
|
|
1856
|
+
primitive->front_face = CanvasFrontFace::CanvasFrontFaceCw;
|
|
1857
|
+
break;
|
|
1858
|
+
default:
|
|
1859
|
+
break;
|
|
1860
|
+
}
|
|
1861
|
+
} else if (frontFaceValue->IsString()) {
|
|
1862
|
+
auto frontFace = ConvertFromV8String(isolate, frontFaceValue);
|
|
1863
|
+
if (frontFace == "ccw") {
|
|
1864
|
+
primitive->front_face = CanvasFrontFace::CanvasFrontFaceCcw;
|
|
1865
|
+
} else if (frontFace == "cw") {
|
|
1866
|
+
primitive->front_face = CanvasFrontFace::CanvasFrontFaceCw;
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
|
|
1871
|
+
|
|
1872
|
+
v8::Local<v8::Value> stripIndexFormatValue;
|
|
1873
|
+
|
|
1874
|
+
if (primitiveObj->Get(context, ConvertToV8String(isolate, "stripIndexFormat")).ToLocal(
|
|
1875
|
+
&stripIndexFormatValue)) {
|
|
1876
|
+
if (stripIndexFormatValue->IsUint32()) {
|
|
1877
|
+
auto stripIndexFormat = stripIndexFormatValue.As<v8::Uint32>()->Value();
|
|
1878
|
+
switch (stripIndexFormat) {
|
|
1879
|
+
case 0:
|
|
1880
|
+
primitive->strip_index_format = CanvasOptionalIndexFormat{
|
|
1881
|
+
CanvasOptionalIndexFormatSome,
|
|
1882
|
+
CanvasIndexFormat::CanvasIndexFormatUint16
|
|
1883
|
+
};
|
|
1884
|
+
break;
|
|
1885
|
+
case 1:
|
|
1886
|
+
primitive->strip_index_format = CanvasOptionalIndexFormat{
|
|
1887
|
+
CanvasOptionalIndexFormatSome,
|
|
1888
|
+
CanvasIndexFormat::CanvasIndexFormatUint32
|
|
1889
|
+
};
|
|
1890
|
+
break;
|
|
1891
|
+
default:
|
|
1892
|
+
break;
|
|
1893
|
+
}
|
|
1894
|
+
} else if (stripIndexFormatValue->IsString()) {
|
|
1895
|
+
auto stripIndexFormat = ConvertFromV8String(isolate, stripIndexFormatValue);
|
|
1896
|
+
|
|
1897
|
+
|
|
1898
|
+
if (stripIndexFormat == "uint16") {
|
|
1899
|
+
primitive->strip_index_format = CanvasOptionalIndexFormat{
|
|
1900
|
+
CanvasOptionalIndexFormatSome,
|
|
1901
|
+
CanvasIndexFormat::CanvasIndexFormatUint16
|
|
1902
|
+
};
|
|
1903
|
+
} else if (stripIndexFormat == "uint32") {
|
|
1904
|
+
primitive->strip_index_format = CanvasOptionalIndexFormat{
|
|
1905
|
+
CanvasOptionalIndexFormatSome,
|
|
1906
|
+
CanvasIndexFormat::CanvasIndexFormatUint32
|
|
1907
|
+
};
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
|
|
1913
|
+
v8::Local<v8::Value> topologyValue;
|
|
1914
|
+
|
|
1915
|
+
if (primitiveObj->Get(context, ConvertToV8String(isolate, "topology")).ToLocal(
|
|
1916
|
+
&topologyValue)) {
|
|
1917
|
+
|
|
1918
|
+
if (topologyValue->IsUint32()) {
|
|
1919
|
+
auto topology = topologyValue.As<v8::Uint32>()->Value();
|
|
1920
|
+
switch (topology) {
|
|
1921
|
+
case 0:
|
|
1922
|
+
primitive->topology = CanvasPrimitiveTopology::CanvasPrimitiveTopologyPointList;
|
|
1923
|
+
break;
|
|
1924
|
+
case 1:
|
|
1925
|
+
primitive->topology = CanvasPrimitiveTopology::CanvasPrimitiveTopologyLineList;
|
|
1926
|
+
break;
|
|
1927
|
+
case 2:
|
|
1928
|
+
primitive->topology = CanvasPrimitiveTopology::CanvasPrimitiveTopologyLineStrip;
|
|
1929
|
+
break;
|
|
1930
|
+
case 3:
|
|
1931
|
+
primitive->topology = CanvasPrimitiveTopology::CanvasPrimitiveTopologyTriangleList;
|
|
1932
|
+
break;
|
|
1933
|
+
case 4:
|
|
1934
|
+
primitive->topology = CanvasPrimitiveTopology::CanvasPrimitiveTopologyTriangleStrip;
|
|
1935
|
+
break;
|
|
1936
|
+
default:
|
|
1937
|
+
break;
|
|
1938
|
+
}
|
|
1939
|
+
} else if (topologyValue->IsString()) {
|
|
1940
|
+
auto topology = ConvertFromV8String(isolate, topologyValue);
|
|
1941
|
+
if (topology == "line-list") {
|
|
1942
|
+
primitive->topology = CanvasPrimitiveTopology::CanvasPrimitiveTopologyLineList;
|
|
1943
|
+
} else if (topology == "line-strip") {
|
|
1944
|
+
primitive->topology = CanvasPrimitiveTopology::CanvasPrimitiveTopologyLineStrip;
|
|
1945
|
+
} else if (topology == "point-list") {
|
|
1946
|
+
primitive->topology = CanvasPrimitiveTopology::CanvasPrimitiveTopologyPointList;
|
|
1947
|
+
} else if (topology == "triangle-list") {
|
|
1948
|
+
primitive->topology = CanvasPrimitiveTopology::CanvasPrimitiveTopologyTriangleList;
|
|
1949
|
+
} else if (topology == "triangle-strip") {
|
|
1950
|
+
primitive->topology = CanvasPrimitiveTopology::CanvasPrimitiveTopologyTriangleStrip;
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1953
|
+
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
|
|
1957
|
+
v8::Local<v8::Value> unclippedDepthValue;
|
|
1958
|
+
primitiveObj->Get(context, ConvertToV8String(isolate, "unclippedDepth")).ToLocal(
|
|
1959
|
+
&unclippedDepthValue);
|
|
1960
|
+
|
|
1961
|
+
if (!unclippedDepthValue.IsEmpty() && unclippedDepthValue->IsBoolean()) {
|
|
1962
|
+
primitive->unclipped_depth = unclippedDepthValue->BooleanValue(isolate);
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
descriptor.primitive = primitive;
|
|
1966
|
+
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1969
|
+
|
|
1970
|
+
v8::Local<v8::Value> vertexValue;
|
|
1971
|
+
options->Get(context, ConvertToV8String(isolate, "vertex")).ToLocal(
|
|
1972
|
+
&vertexValue);
|
|
1973
|
+
|
|
1974
|
+
|
|
1975
|
+
CanvasVertexState *vertex = nullptr;
|
|
1976
|
+
|
|
1977
|
+
std::vector<CanvasVertexBufferLayout> bufferLayout;
|
|
1978
|
+
|
|
1979
|
+
std::vector<std::vector<CanvasVertexAttribute>> attributes;
|
|
1980
|
+
|
|
1981
|
+
if (!vertexValue.IsEmpty() && vertexValue->IsObject()) {
|
|
1982
|
+
auto vertexObj = vertexValue.As<v8::Object>();
|
|
1983
|
+
vertex = new CanvasVertexState{};
|
|
1984
|
+
|
|
1985
|
+
v8::Local<v8::Value> moduleVal;
|
|
1986
|
+
vertexObj->Get(context, ConvertToV8String(isolate, "module")).ToLocal(&moduleVal);
|
|
1987
|
+
|
|
1988
|
+
auto module = GPUShaderModuleImpl::GetPointer(moduleVal.As<v8::Object>());
|
|
1989
|
+
|
|
1990
|
+
vertex->module = module->GetShaderModule();
|
|
1991
|
+
|
|
1992
|
+
v8::Local<v8::Value> constantsVal;
|
|
1993
|
+
vertexObj->Get(context, ConvertToV8String(isolate, "constants")).ToLocal(&constantsVal);
|
|
1994
|
+
|
|
1995
|
+
if (!constantsVal.IsEmpty() && constantsVal->IsMap()) {
|
|
1996
|
+
auto constants = constantsVal.As<v8::Map>();
|
|
1997
|
+
auto keyValues = constants->AsArray();
|
|
1998
|
+
auto len = keyValues->Length();
|
|
1999
|
+
CanvasConstants *store = nullptr;
|
|
2000
|
+
|
|
2001
|
+
if (len > 0) {
|
|
2002
|
+
store = canvas_native_webgpu_constants_create();
|
|
2003
|
+
for (int i = 0; i < len; i += 2) {
|
|
2004
|
+
auto k = i;
|
|
2005
|
+
auto v = k + 1;
|
|
2006
|
+
|
|
2007
|
+
v8::Local<v8::Value> keyVal;
|
|
2008
|
+
keyValues->Get(context, k).ToLocal(&keyVal);
|
|
2009
|
+
v8::Local<v8::Value> valueVal;
|
|
2010
|
+
keyValues->Get(context, v).ToLocal(&valueVal);
|
|
2011
|
+
|
|
2012
|
+
|
|
2013
|
+
if (!keyVal.IsEmpty() && keyVal->IsString() && !valueVal.IsEmpty() &&
|
|
2014
|
+
valueVal->IsNumber()) {
|
|
2015
|
+
canvas_native_webgpu_constants_insert(
|
|
2016
|
+
store,
|
|
2017
|
+
*v8::String::Utf8Value(isolate, keyVal),
|
|
2018
|
+
valueVal.As<v8::Number>()->Value()
|
|
2019
|
+
);
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
|
|
2025
|
+
vertex->constants = store;
|
|
2026
|
+
|
|
2027
|
+
}
|
|
1233
2028
|
|
|
2029
|
+
v8::Local<v8::Value> buffersVal;
|
|
2030
|
+
vertexObj->Get(context, ConvertToV8String(isolate, "buffers")).ToLocal(&buffersVal);
|
|
1234
2031
|
|
|
1235
|
-
|
|
1236
|
-
|
|
2032
|
+
uint64_t stride = 0;
|
|
2033
|
+
if (!buffersVal.IsEmpty() && buffersVal->IsArray()) {
|
|
2034
|
+
auto buffers = buffersVal.As<v8::Array>();
|
|
2035
|
+
auto len = buffers->Length();
|
|
1237
2036
|
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
if (ptr == nullptr) {
|
|
1241
|
-
return;
|
|
1242
|
-
}
|
|
1243
|
-
auto isolate = args.GetIsolate();
|
|
1244
|
-
auto context = isolate->GetCurrentContext();
|
|
2037
|
+
for (int i = 0; i < len; i++) {
|
|
2038
|
+
auto buffer = buffers->Get(context, i).ToLocalChecked().As<v8::Object>();
|
|
1245
2039
|
|
|
1246
|
-
|
|
2040
|
+
v8::Local<v8::Value> arrayStride;
|
|
1247
2041
|
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
return;
|
|
1251
|
-
}
|
|
1252
|
-
auto options = optionsVal.As<v8::Object>();
|
|
2042
|
+
buffer->Get(context, ConvertToV8String(isolate, "arrayStride")).ToLocal(
|
|
2043
|
+
&arrayStride);
|
|
1253
2044
|
|
|
1254
|
-
|
|
1255
|
-
|
|
2045
|
+
if (!arrayStride.IsEmpty() && arrayStride->IsNumber()) {
|
|
2046
|
+
stride = (uint64_t) arrayStride.As<v8::Number>()->Value();
|
|
2047
|
+
}
|
|
1256
2048
|
|
|
1257
|
-
|
|
2049
|
+
std::vector<CanvasVertexAttribute> attributes_;
|
|
1258
2050
|
|
|
1259
|
-
|
|
1260
|
-
label = *v8::String::Utf8Value(isolate, labelVal);
|
|
1261
|
-
}
|
|
2051
|
+
v8::Local<v8::Value> attributesValue;
|
|
1262
2052
|
|
|
1263
|
-
|
|
1264
|
-
|
|
2053
|
+
buffer->Get(context, ConvertToV8String(isolate, "attributes")).ToLocal(
|
|
2054
|
+
&attributesValue);
|
|
1265
2055
|
|
|
2056
|
+
if (!attributesValue.IsEmpty() && attributesValue->IsArray()) {
|
|
2057
|
+
auto attributes_array = attributesValue.As<v8::Array>();
|
|
2058
|
+
auto attributes_len = attributes_array->Length();
|
|
1266
2059
|
|
|
1267
|
-
|
|
1268
|
-
|
|
2060
|
+
for (int j = 0; j < attributes_len; j++) {
|
|
2061
|
+
auto attr = attributes_array->Get(context,
|
|
2062
|
+
j).ToLocalChecked().As<v8::Object>();
|
|
2063
|
+
auto format = attr->Get(context, ConvertToV8String(isolate,
|
|
2064
|
+
"format")).ToLocalChecked()->Uint32Value(
|
|
2065
|
+
context).ToChecked();
|
|
1269
2066
|
|
|
1270
|
-
|
|
2067
|
+
auto offset = (uint64_t) attr->Get(context, ConvertToV8String(isolate,
|
|
2068
|
+
"offset")).ToLocalChecked()->NumberValue(
|
|
2069
|
+
context).ToChecked();
|
|
2070
|
+
auto shaderLocation = attr->Get(context, ConvertToV8String(isolate,
|
|
2071
|
+
"shaderLocation")).ToLocalChecked()->Uint32Value(
|
|
2072
|
+
context).ToChecked();
|
|
1271
2073
|
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
context).FromJust());
|
|
1278
|
-
} else if (typeStr == "timestamp") {
|
|
1279
|
-
query_set = canvas_native_webgpu_device_create_query_set(ptr->GetGPUDevice(), label,
|
|
1280
|
-
CanvasQueryTypeTimestamp,
|
|
1281
|
-
countVal->Uint32Value(
|
|
1282
|
-
context).FromJust());
|
|
1283
|
-
} else {
|
|
1284
|
-
// todo throw
|
|
1285
|
-
}
|
|
2074
|
+
auto attribute = CanvasVertexAttribute{
|
|
2075
|
+
(CanvasVertexFormat) format,
|
|
2076
|
+
offset,
|
|
2077
|
+
shaderLocation
|
|
2078
|
+
};
|
|
1286
2079
|
|
|
2080
|
+
attributes_.push_back(attribute);
|
|
2081
|
+
}
|
|
1287
2082
|
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
args.GetReturnValue().Set(ret);
|
|
1291
|
-
return;
|
|
1292
|
-
}
|
|
2083
|
+
attributes.push_back(attributes_);
|
|
2084
|
+
}
|
|
1293
2085
|
|
|
1294
|
-
args.GetReturnValue().SetUndefined();
|
|
1295
2086
|
|
|
1296
|
-
|
|
2087
|
+
CanvasVertexStepMode stepMode = CanvasVertexStepModeVertex;
|
|
1297
2088
|
|
|
1298
|
-
|
|
1299
|
-
GPUDeviceImpl *ptr = GetPointer(args.This());
|
|
1300
|
-
if (ptr == nullptr) {
|
|
1301
|
-
return;
|
|
1302
|
-
}
|
|
1303
|
-
auto isolate = args.GetIsolate();
|
|
1304
|
-
auto context = isolate->GetCurrentContext();
|
|
2089
|
+
v8::Local<v8::Value> stepModeVal;
|
|
1305
2090
|
|
|
1306
|
-
|
|
2091
|
+
buffer->Get(context, ConvertToV8String(isolate, "stepMode")).ToLocal(
|
|
2092
|
+
&stepModeVal);
|
|
1307
2093
|
|
|
1308
|
-
if (!optionsVal->IsObject()) {
|
|
1309
|
-
// should error at this point
|
|
1310
|
-
return;
|
|
1311
|
-
}
|
|
1312
|
-
auto options = optionsVal.As<v8::Object>();
|
|
1313
2094
|
|
|
1314
|
-
|
|
1315
|
-
|
|
2095
|
+
if (!stepModeVal.IsEmpty()) {
|
|
2096
|
+
if (stepModeVal->IsUint32()) {
|
|
2097
|
+
switch (stepModeVal.As<v8::Uint32>()->Value()) {
|
|
2098
|
+
case 0:
|
|
2099
|
+
stepMode = CanvasVertexStepMode::CanvasVertexStepModeVertex;
|
|
2100
|
+
break;
|
|
2101
|
+
case 1:
|
|
2102
|
+
stepMode = CanvasVertexStepMode::CanvasVertexStepModeInstance;
|
|
2103
|
+
break;
|
|
2104
|
+
}
|
|
2105
|
+
} else if (stepModeVal->IsString()) {
|
|
2106
|
+
auto stepModeStr = ConvertFromV8String(isolate, stepModeVal);
|
|
2107
|
+
if (stepModeStr == "vertex") {
|
|
2108
|
+
stepMode = CanvasVertexStepMode::CanvasVertexStepModeVertex;
|
|
2109
|
+
} else if (stepModeStr == "instance") {
|
|
2110
|
+
stepMode = CanvasVertexStepMode::CanvasVertexStepModeInstance;
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2115
|
+
auto vertexBufferLayout = CanvasVertexBufferLayout{
|
|
2116
|
+
stride,
|
|
2117
|
+
stepMode,
|
|
2118
|
+
attributes[i].data(),
|
|
2119
|
+
attributes[i].size()
|
|
2120
|
+
};
|
|
1316
2121
|
|
|
1317
|
-
|
|
2122
|
+
bufferLayout.push_back(vertexBufferLayout);
|
|
2123
|
+
}
|
|
1318
2124
|
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
}
|
|
2125
|
+
vertex->buffers = bufferLayout.data();
|
|
2126
|
+
vertex->buffers_size = bufferLayout.size();
|
|
1322
2127
|
|
|
2128
|
+
}
|
|
1323
2129
|
|
|
1324
|
-
std::vector<CanvasGPUTextureFormat> colorFormats;
|
|
1325
2130
|
|
|
1326
|
-
|
|
1327
|
-
|
|
2131
|
+
v8::Local<v8::Value> entryPoint;
|
|
2132
|
+
vertexObj->Get(context, ConvertToV8String(isolate, "entryPoint")).ToLocal(&entryPoint);
|
|
1328
2133
|
|
|
1329
|
-
if (!colorFormatsVal.IsEmpty() && colorFormatsVal->IsArray()) {
|
|
1330
|
-
auto colorFormatsArray = colorFormatsVal.As<v8::Array>();
|
|
1331
|
-
auto len = colorFormatsArray->Length();
|
|
1332
|
-
for (int i = 0; i < len; i++) {
|
|
1333
|
-
v8::Local<v8::Value> formatVal;
|
|
1334
|
-
colorFormatsArray->Get(context, i).ToLocal(&formatVal);
|
|
1335
|
-
if (!formatVal.IsEmpty() && formatVal->IsString()) {
|
|
1336
|
-
auto formatStr = ConvertFromV8String(isolate, formatVal);
|
|
1337
|
-
auto format = canvas_native_webgpu_enum_string_to_gpu_texture(formatStr.c_str());
|
|
1338
|
-
if (format.tag == CanvasOptionalGPUTextureFormatSome) {
|
|
1339
|
-
colorFormats.push_back(format.some);
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1342
2134
|
|
|
2135
|
+
if (!entryPoint.IsEmpty() && entryPoint->IsString()) {
|
|
2136
|
+
auto ep = v8::String::Utf8Value(isolate, entryPoint);
|
|
2137
|
+
char *entry_point = (char *) malloc(ep.length());
|
|
2138
|
+
std::strcpy(entry_point, *ep);
|
|
2139
|
+
vertex->entry_point = entry_point;
|
|
1343
2140
|
}
|
|
2141
|
+
|
|
2142
|
+
descriptor.vertex = vertex;
|
|
2143
|
+
|
|
1344
2144
|
}
|
|
1345
2145
|
|
|
1346
2146
|
|
|
1347
|
-
auto
|
|
1348
|
-
|
|
1349
|
-
};
|
|
2147
|
+
auto pipeline = canvas_native_webgpu_device_create_render_pipeline(ptr->GetGPUDevice(),
|
|
2148
|
+
&descriptor);
|
|
1350
2149
|
|
|
1351
|
-
v8::Local<v8::Value> depthStencilFormatVal;
|
|
1352
|
-
options->Get(context, ConvertToV8String(isolate, "depthStencilFormat")).ToLocal(
|
|
1353
|
-
&depthStencilFormatVal);
|
|
1354
2150
|
|
|
1355
|
-
if (
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
2151
|
+
if (descriptor.fragment != nullptr) {
|
|
2152
|
+
if (descriptor.fragment->entry_point != nullptr) {
|
|
2153
|
+
free((void *) descriptor.fragment->entry_point);
|
|
2154
|
+
}
|
|
1359
2155
|
}
|
|
1360
2156
|
|
|
1361
|
-
|
|
2157
|
+
if (descriptor.primitive != nullptr) {
|
|
2158
|
+
delete descriptor.primitive;
|
|
2159
|
+
descriptor.primitive = nullptr;
|
|
2160
|
+
}
|
|
1362
2161
|
|
|
1363
|
-
|
|
2162
|
+
if (descriptor.multisample != nullptr) {
|
|
2163
|
+
delete descriptor.multisample;
|
|
2164
|
+
descriptor.multisample = nullptr;
|
|
2165
|
+
}
|
|
1364
2166
|
|
|
1365
|
-
bool stencilReadOnly = false;
|
|
1366
2167
|
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
sampleCount,
|
|
1373
|
-
depthReadOnly,
|
|
1374
|
-
stencilReadOnly
|
|
1375
|
-
};
|
|
2168
|
+
if (descriptor.vertex != nullptr) {
|
|
2169
|
+
if (descriptor.vertex->constants != nullptr) {
|
|
2170
|
+
canvas_native_webgpu_constants_destroy(
|
|
2171
|
+
(CanvasConstants *) descriptor.vertex->constants);
|
|
2172
|
+
}
|
|
1376
2173
|
|
|
2174
|
+
if (descriptor.vertex->entry_point != nullptr) {
|
|
2175
|
+
free((void *) descriptor.vertex->entry_point);
|
|
2176
|
+
}
|
|
1377
2177
|
|
|
1378
|
-
|
|
1379
|
-
&descriptor);
|
|
2178
|
+
}
|
|
1380
2179
|
|
|
1381
|
-
if (
|
|
1382
|
-
|
|
1383
|
-
|
|
2180
|
+
if (descriptor.depth_stencil != nullptr) {
|
|
2181
|
+
delete descriptor.depth_stencil;
|
|
2182
|
+
descriptor.depth_stencil = nullptr;
|
|
2183
|
+
}
|
|
2184
|
+
|
|
2185
|
+
|
|
2186
|
+
if (pipeline != nullptr) {
|
|
2187
|
+
auto ret = GPURenderPipelineImpl::NewInstance(isolate, new GPURenderPipelineImpl(pipeline));
|
|
1384
2188
|
args.GetReturnValue().Set(ret);
|
|
1385
2189
|
return;
|
|
1386
2190
|
}
|
|
@@ -1388,7 +2192,7 @@ void GPUDeviceImpl::CreateRenderBundleEncoder(const v8::FunctionCallbackInfo<v8:
|
|
|
1388
2192
|
args.GetReturnValue().SetUndefined();
|
|
1389
2193
|
}
|
|
1390
2194
|
|
|
1391
|
-
void GPUDeviceImpl::
|
|
2195
|
+
void GPUDeviceImpl::CreateRenderPipelineAsync(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
1392
2196
|
GPUDeviceImpl *ptr = GetPointer(args.This());
|
|
1393
2197
|
if (ptr == nullptr) {
|
|
1394
2198
|
return;
|
|
@@ -1400,13 +2204,14 @@ void GPUDeviceImpl::CreateRenderPipeline(const v8::FunctionCallbackInfo<v8::Valu
|
|
|
1400
2204
|
descriptor.label = nullptr;
|
|
1401
2205
|
|
|
1402
2206
|
auto optionsVal = args[0];
|
|
2207
|
+
auto callback = args[1];
|
|
1403
2208
|
|
|
1404
2209
|
if (!optionsVal->IsObject()) {
|
|
1405
2210
|
// should error at this point
|
|
1406
2211
|
return;
|
|
1407
2212
|
}
|
|
1408
2213
|
auto options = optionsVal.As<v8::Object>();
|
|
1409
|
-
|
|
2214
|
+
GPULabel label;
|
|
1410
2215
|
|
|
1411
2216
|
v8::Local<v8::Value> stencilValue;
|
|
1412
2217
|
options->Get(context, ConvertToV8String(isolate, "depthStencil")).ToLocal(
|
|
@@ -1818,10 +2623,10 @@ void GPUDeviceImpl::CreateRenderPipeline(const v8::FunctionCallbackInfo<v8::Valu
|
|
|
1818
2623
|
options->Get(context, ConvertToV8String(isolate, "label")).ToLocal(
|
|
1819
2624
|
&labelVal);
|
|
1820
2625
|
|
|
2626
|
+
label = GPULabel(isolate, labelVal);
|
|
2627
|
+
|
|
2628
|
+
descriptor.label = *label;
|
|
1821
2629
|
|
|
1822
|
-
if (!labelVal.IsEmpty() && labelVal->IsString()) {
|
|
1823
|
-
descriptor.label = *v8::String::Utf8Value(isolate, labelVal);
|
|
1824
|
-
}
|
|
1825
2630
|
|
|
1826
2631
|
|
|
1827
2632
|
v8::Local<v8::Value> layoutVal;
|
|
@@ -2256,50 +3061,176 @@ void GPUDeviceImpl::CreateRenderPipeline(const v8::FunctionCallbackInfo<v8::Valu
|
|
|
2256
3061
|
|
|
2257
3062
|
}
|
|
2258
3063
|
|
|
3064
|
+
auto async_callback = new AsyncCallback(isolate, callback.As<v8::Function>(),
|
|
3065
|
+
[](bool success, void *data) {
|
|
3066
|
+
if (data != nullptr) {
|
|
3067
|
+
auto async_data = static_cast<AsyncCallback *>(data);
|
|
3068
|
+
auto func = async_data->inner_.get();
|
|
3069
|
+
if (func != nullptr &&
|
|
3070
|
+
func->isolate_ != nullptr) {
|
|
3071
|
+
v8::Isolate *isolate = func->isolate_;
|
|
3072
|
+
v8::Locker locker(isolate);
|
|
3073
|
+
v8::Isolate::Scope isolate_scope(
|
|
3074
|
+
isolate);
|
|
3075
|
+
v8::HandleScope handle_scope(isolate);
|
|
3076
|
+
v8::Local<v8::Function> callback = func->callback_.Get(
|
|
3077
|
+
isolate);
|
|
3078
|
+
v8::Local<v8::Context> context = callback->GetCreationContextChecked();
|
|
3079
|
+
v8::Context::Scope context_scope(
|
|
3080
|
+
context);
|
|
3081
|
+
|
|
3082
|
+
RenderPipeLineAsyncData *pipelineData = nullptr;
|
|
3083
|
+
if (func->data != nullptr) {
|
|
3084
|
+
pipelineData = static_cast<RenderPipeLineAsyncData *>(func->data);
|
|
3085
|
+
}
|
|
3086
|
+
|
|
3087
|
+
if (pipelineData == nullptr) {
|
|
3088
|
+
// Should never happen
|
|
3089
|
+
auto error = v8::Object::New(isolate);
|
|
3090
|
+
error->Set(context,
|
|
3091
|
+
ConvertToV8String(isolate,
|
|
3092
|
+
"error"),
|
|
3093
|
+
v8::Exception::Error(
|
|
3094
|
+
ConvertToV8String(
|
|
3095
|
+
isolate,
|
|
3096
|
+
"Internal Error")));
|
|
3097
|
+
error->Set(context, ConvertToV8String(
|
|
3098
|
+
isolate,
|
|
3099
|
+
"type"),
|
|
3100
|
+
v8::Uint32::NewFromUnsigned(
|
|
3101
|
+
isolate,
|
|
3102
|
+
(uint32_t) CanvasGPUErrorType::CanvasGPUErrorTypeInternal));
|
|
3103
|
+
|
|
3104
|
+
v8::Local<v8::Value> args[1] = {error};
|
|
3105
|
+
|
|
3106
|
+
callback->Call(context,
|
|
3107
|
+
context->Global(),
|
|
3108
|
+
1,
|
|
3109
|
+
args); // ignore JS return value
|
|
3110
|
+
delete static_cast<AsyncCallback *>(data);
|
|
3111
|
+
|
|
3112
|
+
return;
|
|
3113
|
+
}
|
|
3114
|
+
|
|
3115
|
+
if (pipelineData->type !=
|
|
3116
|
+
CanvasGPUErrorType::CanvasGPUErrorTypeNone) {
|
|
3117
|
+
|
|
3118
|
+
|
|
3119
|
+
auto error = v8::Object::New(isolate);
|
|
3120
|
+
error->Set(context,
|
|
3121
|
+
ConvertToV8String(isolate,
|
|
3122
|
+
"error"),
|
|
3123
|
+
v8::Exception::Error(
|
|
3124
|
+
ConvertToV8String(
|
|
3125
|
+
isolate,
|
|
3126
|
+
pipelineData->errorMessage)));
|
|
3127
|
+
error->Set(context, ConvertToV8String(
|
|
3128
|
+
isolate,
|
|
3129
|
+
"type"),
|
|
3130
|
+
v8::Uint32::NewFromUnsigned(
|
|
3131
|
+
isolate,
|
|
3132
|
+
(uint32_t) pipelineData->type));
|
|
3133
|
+
|
|
3134
|
+
v8::Local<v8::Value> args[1] = {error};
|
|
3135
|
+
|
|
3136
|
+
callback->Call(context,
|
|
3137
|
+
context->Global(),
|
|
3138
|
+
1,
|
|
3139
|
+
args); // ignore JS return value
|
|
3140
|
+
} else {
|
|
3141
|
+
|
|
3142
|
+
auto ret = GPURenderPipelineImpl::NewInstance(
|
|
3143
|
+
isolate,
|
|
3144
|
+
new GPURenderPipelineImpl(
|
|
3145
|
+
pipelineData->pipeline));
|
|
3146
|
+
|
|
3147
|
+
v8::Local<v8::Value> args[2] = {
|
|
3148
|
+
v8::Null(isolate), ret};
|
|
3149
|
+
|
|
3150
|
+
|
|
3151
|
+
callback->Call(context,
|
|
3152
|
+
context->Global(),
|
|
3153
|
+
2,
|
|
3154
|
+
args); // ignore JS return value
|
|
3155
|
+
}
|
|
3156
|
+
|
|
3157
|
+
if (pipelineData != nullptr) {
|
|
3158
|
+
delete pipelineData;
|
|
3159
|
+
pipelineData = nullptr;
|
|
3160
|
+
}
|
|
3161
|
+
|
|
3162
|
+
delete static_cast<AsyncCallback *>(data);
|
|
3163
|
+
}
|
|
3164
|
+
}
|
|
3165
|
+
});
|
|
3166
|
+
|
|
3167
|
+
auto data = new RenderPipeLineAsyncData{
|
|
3168
|
+
nullptr,
|
|
3169
|
+
nullptr,
|
|
3170
|
+
nullptr,
|
|
3171
|
+
nullptr,
|
|
3172
|
+
CanvasGPUErrorType::CanvasGPUErrorTypeNone,
|
|
3173
|
+
nullptr,
|
|
3174
|
+
nullptr,
|
|
3175
|
+
nullptr,
|
|
3176
|
+
nullptr,
|
|
3177
|
+
nullptr,
|
|
3178
|
+
nullptr
|
|
3179
|
+
};
|
|
2259
3180
|
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
if (descriptor.fragment != nullptr) {
|
|
2265
|
-
if (descriptor.fragment->entry_point != nullptr) {
|
|
2266
|
-
free((void *) descriptor.fragment->entry_point);
|
|
3181
|
+
if (fragment != nullptr) {
|
|
3182
|
+
if (fragment->entry_point != nullptr) {
|
|
3183
|
+
data->fragment_entry_point = (char *) fragment->entry_point;
|
|
2267
3184
|
}
|
|
2268
3185
|
}
|
|
2269
3186
|
|
|
2270
|
-
if (
|
|
2271
|
-
|
|
3187
|
+
if (primitive != nullptr) {
|
|
3188
|
+
data->primitive = primitive;
|
|
2272
3189
|
}
|
|
2273
3190
|
|
|
2274
|
-
if (
|
|
2275
|
-
|
|
3191
|
+
if (multisample != nullptr) {
|
|
3192
|
+
data->multisample = multisample;
|
|
2276
3193
|
}
|
|
2277
3194
|
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
canvas_native_webgpu_constants_destroy(
|
|
2282
|
-
(CanvasConstants *) descriptor.vertex->constants);
|
|
3195
|
+
if (vertex != nullptr) {
|
|
3196
|
+
if (vertex->constants != nullptr) {
|
|
3197
|
+
data->vertex_constants = (CanvasConstants *) vertex->constants;
|
|
2283
3198
|
}
|
|
2284
3199
|
|
|
2285
|
-
if (
|
|
2286
|
-
|
|
3200
|
+
if (vertex->entry_point != nullptr) {
|
|
3201
|
+
data->vertex_entry_point = (char *) descriptor.vertex->entry_point;
|
|
2287
3202
|
}
|
|
2288
3203
|
|
|
2289
3204
|
}
|
|
2290
3205
|
|
|
2291
|
-
if (
|
|
3206
|
+
if (stencil != nullptr) {
|
|
2292
3207
|
delete descriptor.depth_stencil;
|
|
3208
|
+
data->depth_stencil = stencil;
|
|
2293
3209
|
}
|
|
2294
3210
|
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
3211
|
+
async_callback->inner_->data = data;
|
|
3212
|
+
|
|
3213
|
+
async_callback->prepare();
|
|
3214
|
+
|
|
3215
|
+
canvas_native_webgpu_device_create_render_pipeline_async(ptr->GetGPUDevice(),
|
|
3216
|
+
&descriptor, [](
|
|
3217
|
+
const struct CanvasGPURenderPipeline *pipeline,
|
|
3218
|
+
enum CanvasGPUErrorType type,
|
|
3219
|
+
char *message,
|
|
3220
|
+
void *data) {
|
|
3221
|
+
if (data != nullptr) {
|
|
3222
|
+
auto async_data = static_cast<AsyncCallback *>(data);
|
|
3223
|
+
auto inner = async_data->inner_.get();
|
|
3224
|
+
if (inner != nullptr) {
|
|
3225
|
+
auto pipeline_data = static_cast<RenderPipeLineAsyncData *>(inner->data);
|
|
3226
|
+
pipeline_data->errorMessage = message;
|
|
3227
|
+
pipeline_data->type = type;
|
|
3228
|
+
pipeline_data->pipeline = pipeline;
|
|
3229
|
+
async_data->execute(
|
|
3230
|
+
true);
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3233
|
+
}, async_callback);
|
|
2303
3234
|
}
|
|
2304
3235
|
|
|
2305
3236
|
void GPUDeviceImpl::CreateSampler(const v8::FunctionCallbackInfo<v8::Value> &args) {
|
|
@@ -2319,11 +3250,7 @@ void GPUDeviceImpl::CreateSampler(const v8::FunctionCallbackInfo<v8::Value> &arg
|
|
|
2319
3250
|
v8::Local<v8::Value> labelVal;
|
|
2320
3251
|
options->Get(context, ConvertToV8String(isolate, "label")).ToLocal(&labelVal);
|
|
2321
3252
|
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
if (!labelVal.IsEmpty() && labelVal->IsString()) {
|
|
2325
|
-
label = *v8::String::Utf8Value(isolate, labelVal);
|
|
2326
|
-
}
|
|
3253
|
+
GPULabel label(isolate, labelVal);
|
|
2327
3254
|
|
|
2328
3255
|
auto addressModeU = CanvasAddressModeClampToEdge;
|
|
2329
3256
|
|
|
@@ -2453,12 +3380,12 @@ void GPUDeviceImpl::CreateSampler(const v8::FunctionCallbackInfo<v8::Value> &arg
|
|
|
2453
3380
|
&maxAnisotropyVal);
|
|
2454
3381
|
|
|
2455
3382
|
if (!maxAnisotropyVal.IsEmpty() && maxAnisotropyVal->IsNumber()) {
|
|
2456
|
-
maxAnisotropy = (
|
|
3383
|
+
maxAnisotropy = (uint16_t) maxAnisotropyVal->NumberValue(context).FromJust();
|
|
2457
3384
|
}
|
|
2458
3385
|
|
|
2459
3386
|
|
|
2460
3387
|
CanvasCreateSamplerDescriptor descriptor{
|
|
2461
|
-
label,
|
|
3388
|
+
*label,
|
|
2462
3389
|
addressModeU,
|
|
2463
3390
|
addressModeV,
|
|
2464
3391
|
addressModeW,
|
|
@@ -2509,11 +3436,7 @@ void GPUDeviceImpl::CreateShaderModule(const v8::FunctionCallbackInfo<v8::Value>
|
|
|
2509
3436
|
v8::Local<v8::Value> labelVal;
|
|
2510
3437
|
desc->Get(context, ConvertToV8String(isolate, "label")).ToLocal(&labelVal);
|
|
2511
3438
|
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
if (!labelVal.IsEmpty() && labelVal->IsString()) {
|
|
2515
|
-
label = *v8::String::Utf8Value(isolate, labelVal);
|
|
2516
|
-
}
|
|
3439
|
+
GPULabel label(isolate, labelVal);
|
|
2517
3440
|
|
|
2518
3441
|
v8::Local<v8::Value> codeVal;
|
|
2519
3442
|
|
|
@@ -2523,7 +3446,8 @@ void GPUDeviceImpl::CreateShaderModule(const v8::FunctionCallbackInfo<v8::Value>
|
|
|
2523
3446
|
code = ConvertFromV8String(isolate, codeVal);
|
|
2524
3447
|
}
|
|
2525
3448
|
|
|
2526
|
-
auto module = canvas_native_webgpu_device_create_shader_module(ptr->GetGPUDevice(),
|
|
3449
|
+
auto module = canvas_native_webgpu_device_create_shader_module(ptr->GetGPUDevice(),
|
|
3450
|
+
*label,
|
|
2527
3451
|
code.c_str());
|
|
2528
3452
|
|
|
2529
3453
|
if (module != nullptr) {
|
|
@@ -2621,7 +3545,6 @@ void GPUDeviceImpl::CreateTexture(const v8::FunctionCallbackInfo<v8::Value> &arg
|
|
|
2621
3545
|
|
|
2622
3546
|
if (dimensionVal->IsString()) {
|
|
2623
3547
|
auto dimension = ConvertFromV8String(isolate, dimensionVal);
|
|
2624
|
-
|
|
2625
3548
|
// todo use enum
|
|
2626
3549
|
if (dimension == "1d") {
|
|
2627
3550
|
descriptor.dimension = CanvasTextureDimension::CanvasTextureDimensionD1;
|