@shopify/react-native-skia 2.4.15 → 2.4.17
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/android/CMakeLists.txt +69 -0
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +19 -7
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseViewManager.java +7 -0
- package/apple/RNSkApplePlatformContext.mm +4 -0
- package/cpp/api/JsiSkApi.h +31 -0
- package/cpp/api/JsiSkImageFactory.h +69 -1
- package/cpp/api/JsiSkImageFilter.h +1 -0
- package/cpp/api/JsiSkPath.h +1 -1
- package/cpp/jsi/RuntimeAwareCache.h +0 -2
- package/cpp/jsi2/EnumMapper.h +45 -0
- package/cpp/jsi2/JSIConverter.h +468 -0
- package/cpp/jsi2/NativeObject.h +598 -0
- package/cpp/jsi2/Promise.cpp +44 -0
- package/cpp/jsi2/Promise.h +35 -0
- package/cpp/rnskia/RNDawnContext.h +114 -0
- package/cpp/rnskia/RNSkManager.cpp +41 -1
- package/cpp/rnwgpu/ArrayBuffer.h +68 -0
- package/cpp/rnwgpu/api/Convertors.h +761 -0
- package/cpp/rnwgpu/api/External.h +12 -0
- package/cpp/rnwgpu/api/GPU.cpp +129 -0
- package/cpp/rnwgpu/api/GPU.h +57 -0
- package/cpp/rnwgpu/api/GPUAdapter.cpp +178 -0
- package/cpp/rnwgpu/api/GPUAdapter.h +59 -0
- package/cpp/rnwgpu/api/GPUAdapterInfo.h +57 -0
- package/cpp/rnwgpu/api/GPUBindGroup.cpp +3 -0
- package/cpp/rnwgpu/api/GPUBindGroup.h +51 -0
- package/cpp/rnwgpu/api/GPUBindGroupLayout.h +52 -0
- package/cpp/rnwgpu/api/GPUBuffer.cpp +97 -0
- package/cpp/rnwgpu/api/GPUBuffer.h +87 -0
- package/cpp/rnwgpu/api/GPUCommandBuffer.h +45 -0
- package/cpp/rnwgpu/api/GPUCommandEncoder.cpp +179 -0
- package/cpp/rnwgpu/api/GPUCommandEncoder.h +111 -0
- package/cpp/rnwgpu/api/GPUCompilationInfo.h +79 -0
- package/cpp/rnwgpu/api/GPUCompilationMessage.h +36 -0
- package/cpp/rnwgpu/api/GPUComputePassEncoder.cpp +60 -0
- package/cpp/rnwgpu/api/GPUComputePassEncoder.h +85 -0
- package/cpp/rnwgpu/api/GPUComputePipeline.cpp +12 -0
- package/cpp/rnwgpu/api/GPUComputePipeline.h +60 -0
- package/cpp/rnwgpu/api/GPUDevice.cpp +434 -0
- package/cpp/rnwgpu/api/GPUDevice.h +174 -0
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.cpp +7 -0
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +40 -0
- package/cpp/rnwgpu/api/GPUError.h +35 -0
- package/cpp/rnwgpu/api/GPUExtent3D.h +66 -0
- package/cpp/rnwgpu/api/GPUExternalTexture.h +45 -0
- package/cpp/rnwgpu/api/GPUFeatures.h +212 -0
- package/cpp/rnwgpu/api/GPUInternalError.h +31 -0
- package/cpp/rnwgpu/api/GPUOrigin2D.h +55 -0
- package/cpp/rnwgpu/api/GPUOrigin3D.h +62 -0
- package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +33 -0
- package/cpp/rnwgpu/api/GPUPipelineLayout.h +45 -0
- package/cpp/rnwgpu/api/GPUQuerySet.cpp +11 -0
- package/cpp/rnwgpu/api/GPUQuerySet.h +73 -0
- package/cpp/rnwgpu/api/GPUQueue.cpp +169 -0
- package/cpp/rnwgpu/api/GPUQueue.h +84 -0
- package/cpp/rnwgpu/api/GPURenderBundle.h +44 -0
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.cpp +131 -0
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +110 -0
- package/cpp/rnwgpu/api/GPURenderPassEncoder.cpp +165 -0
- package/cpp/rnwgpu/api/GPURenderPassEncoder.h +130 -0
- package/cpp/rnwgpu/api/GPURenderPipeline.cpp +13 -0
- package/cpp/rnwgpu/api/GPURenderPipeline.h +61 -0
- package/cpp/rnwgpu/api/GPUSampler.h +44 -0
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +51 -0
- package/cpp/rnwgpu/api/GPUShaderModule.h +66 -0
- package/cpp/rnwgpu/api/GPUSupportedLimits.cpp +129 -0
- package/cpp/rnwgpu/api/GPUSupportedLimits.h +131 -0
- package/cpp/rnwgpu/api/GPUTexture.cpp +47 -0
- package/cpp/rnwgpu/api/GPUTexture.h +150 -0
- package/cpp/rnwgpu/api/GPUTextureView.h +44 -0
- package/cpp/rnwgpu/api/GPUValidationError.h +32 -0
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +64 -0
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +71 -0
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +56 -0
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +97 -0
- package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +57 -0
- package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +52 -0
- package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +56 -0
- package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +56 -0
- package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +59 -0
- package/cpp/rnwgpu/api/descriptors/GPUBufferUsage.h +39 -0
- package/cpp/rnwgpu/api/descriptors/GPUColor.h +66 -0
- package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +58 -0
- package/cpp/rnwgpu/api/descriptors/GPUColorWrite.h +29 -0
- package/cpp/rnwgpu/api/descriptors/GPUCommandBufferDescriptor.h +45 -0
- package/cpp/rnwgpu/api/descriptors/GPUCommandEncoderDescriptor.h +45 -0
- package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +56 -0
- package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +58 -0
- package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +67 -0
- package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +103 -0
- package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +99 -0
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +38 -0
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +71 -0
- package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +73 -0
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +62 -0
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +62 -0
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +65 -0
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +81 -0
- package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +54 -0
- package/cpp/rnwgpu/api/descriptors/GPUMapMode.h +22 -0
- package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +54 -0
- package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +57 -0
- package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +69 -0
- package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +61 -0
- package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +55 -0
- package/cpp/rnwgpu/api/descriptors/GPUQueueDescriptor.h +43 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleDescriptor.h +45 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +80 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +81 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +101 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +92 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +58 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +103 -0
- package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +51 -0
- package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +45 -0
- package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +110 -0
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +60 -0
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +62 -0
- package/cpp/rnwgpu/api/descriptors/GPUShaderStage.h +25 -0
- package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +64 -0
- package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +59 -0
- package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +59 -0
- package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +91 -0
- package/cpp/rnwgpu/api/descriptors/GPUTextureUsage.h +29 -0
- package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +91 -0
- package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +64 -0
- package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +53 -0
- package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +62 -0
- package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +73 -0
- package/cpp/rnwgpu/api/descriptors/Unions.h +1984 -0
- package/cpp/rnwgpu/async/AsyncDispatcher.h +28 -0
- package/cpp/rnwgpu/async/AsyncRunner.cpp +181 -0
- package/cpp/rnwgpu/async/AsyncRunner.h +56 -0
- package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +181 -0
- package/cpp/rnwgpu/async/AsyncTaskHandle.h +55 -0
- package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.cpp +23 -0
- package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.h +22 -0
- package/lib/commonjs/Platform/Platform.web.js +1 -2
- package/lib/commonjs/Platform/Platform.web.js.map +1 -1
- package/lib/commonjs/external/reanimated/buffers.js.map +1 -1
- package/lib/commonjs/external/reanimated/interpolators.d.ts +1 -4
- package/lib/commonjs/renderer/Canvas.js +4 -3
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/components/Group.js +1 -2
- package/lib/commonjs/renderer/components/Group.js.map +1 -1
- package/lib/commonjs/renderer/components/shapes/FitBox.js +1 -2
- package/lib/commonjs/renderer/components/shapes/FitBox.js.map +1 -1
- package/lib/commonjs/skia/types/ContourMeasure.js.map +1 -1
- package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +20 -0
- package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/commonjs/skia/types/RuntimeEffect/RuntimeEffect.js.map +1 -1
- package/lib/commonjs/skia/types/Skia.d.ts +17 -0
- package/lib/commonjs/skia/types/Skia.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +2 -0
- package/lib/commonjs/skia/web/JsiSkImageFactory.js +6 -0
- package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkParagraphStyle.js +2 -2
- package/lib/commonjs/skia/web/JsiSkParagraphStyle.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js +6 -0
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/ColorFilters.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/PathEffects.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Shaders.js.map +1 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.d.ts +2 -0
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js +2 -0
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.web.js +4 -4
- package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
- package/lib/commonjs/web/WithSkiaWeb.js +1 -2
- package/lib/commonjs/web/WithSkiaWeb.js.map +1 -1
- package/lib/module/external/reanimated/buffers.js.map +1 -1
- package/lib/module/external/reanimated/interpolators.d.ts +1 -4
- package/lib/module/renderer/Canvas.js +3 -1
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/skia/types/ContourMeasure.js.map +1 -1
- package/lib/module/skia/types/Image/ImageFactory.d.ts +20 -0
- package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/module/skia/types/RuntimeEffect/RuntimeEffect.js.map +1 -1
- package/lib/module/skia/types/Skia.d.ts +17 -0
- package/lib/module/skia/types/Skia.js.map +1 -1
- package/lib/module/skia/web/JsiSkImageFactory.d.ts +2 -0
- package/lib/module/skia/web/JsiSkImageFactory.js +6 -0
- package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkParagraphStyle.js +2 -2
- package/lib/module/skia/web/JsiSkParagraphStyle.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.js +6 -0
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/ColorFilters.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/ImageFilters.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/PathEffects.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Shaders.js.map +1 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.d.ts +2 -0
- package/lib/module/specs/SkiaPictureViewNativeComponent.js +4 -0
- package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/module/views/SkiaPictureView.web.js +3 -2
- package/lib/module/views/SkiaPictureView.web.js.map +1 -1
- package/lib/typescript/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +2 -0
- package/lib/typescript/lib/commonjs/skia/web/JsiSkia.d.ts +2 -0
- package/lib/typescript/lib/module/renderer/Canvas.d.ts +1 -1
- package/lib/typescript/lib/module/skia/Skia.web.d.ts +2 -0
- package/lib/typescript/lib/module/skia/web/JsiSkImageFactory.d.ts +2 -0
- package/lib/typescript/lib/module/skia/web/JsiSkia.d.ts +2 -0
- package/lib/typescript/lib/module/views/SkiaPictureView.d.ts +1 -1
- package/lib/typescript/src/external/reanimated/interpolators.d.ts +1 -4
- package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +20 -0
- package/lib/typescript/src/skia/types/Skia.d.ts +17 -0
- package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +2 -0
- package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.d.ts +2 -0
- package/package.json +20 -16
- package/react-native-skia.podspec +52 -13
- package/scripts/install-skia.mjs +99 -48
- package/src/external/reanimated/buffers.ts +1 -1
- package/src/renderer/Canvas.tsx +3 -2
- package/src/skia/types/ContourMeasure.tsx +1 -2
- package/src/skia/types/Image/ImageFactory.ts +22 -0
- package/src/skia/types/RuntimeEffect/RuntimeEffect.ts +1 -2
- package/src/skia/types/Skia.ts +17 -0
- package/src/skia/web/JsiSkImageFactory.ts +8 -0
- package/src/skia/web/JsiSkia.ts +6 -0
- package/src/sksg/Recorder/commands/ColorFilters.ts +3 -2
- package/src/sksg/Recorder/commands/ImageFilters.ts +3 -2
- package/src/sksg/Recorder/commands/PathEffects.ts +3 -2
- package/src/sksg/Recorder/commands/Shaders.ts +3 -2
- package/src/specs/SkiaPictureViewNativeComponent.ts +7 -0
- package/src/views/SkiaPictureView.web.tsx +4 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
|
|
5
|
+
#include "jsi2/JSIConverter.h"
|
|
6
|
+
|
|
7
|
+
#include "webgpu/webgpu_cpp.h"
|
|
8
|
+
|
|
9
|
+
namespace rnwgpu {
|
|
10
|
+
|
|
11
|
+
struct GPUOrigin3D {
|
|
12
|
+
double x = 0;
|
|
13
|
+
double y = 0;
|
|
14
|
+
double z = 0;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
template <> struct JSIConverter<std::shared_ptr<GPUOrigin3D>> {
|
|
18
|
+
static std::shared_ptr<GPUOrigin3D>
|
|
19
|
+
fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBounds) {
|
|
20
|
+
auto result = std::make_unique<GPUOrigin3D>();
|
|
21
|
+
if (!outOfBounds && arg.isObject()) {
|
|
22
|
+
if (arg.getObject(runtime).isArray(runtime)) {
|
|
23
|
+
auto array = arg.getObject(runtime).asArray(runtime);
|
|
24
|
+
auto size = array.size(runtime);
|
|
25
|
+
if (size == 0) {
|
|
26
|
+
throw std::runtime_error(
|
|
27
|
+
"Expected an array of size >1 for GPUTExtent3D");
|
|
28
|
+
}
|
|
29
|
+
if (size > 0) {
|
|
30
|
+
result->x = array.getValueAtIndex(runtime, 0).asNumber();
|
|
31
|
+
}
|
|
32
|
+
if (size > 1) {
|
|
33
|
+
result->y = array.getValueAtIndex(runtime, 1).asNumber();
|
|
34
|
+
}
|
|
35
|
+
if (size > 2) {
|
|
36
|
+
result->z = array.getValueAtIndex(runtime, 2).asNumber();
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
auto object = arg.getObject(runtime);
|
|
40
|
+
if (object.hasProperty(runtime, "x")) {
|
|
41
|
+
result->x = object.getProperty(runtime, "x").asNumber();
|
|
42
|
+
}
|
|
43
|
+
if (object.hasProperty(runtime, "y")) {
|
|
44
|
+
result->y = object.getProperty(runtime, "y").asNumber();
|
|
45
|
+
}
|
|
46
|
+
if (object.hasProperty(runtime, "z")) {
|
|
47
|
+
result->z = object.getProperty(runtime, "z").asNumber();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
throw std::runtime_error("Expected an object for GPUOrigin3D");
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
static jsi::Value toJSI(jsi::Runtime &runtime,
|
|
56
|
+
std::shared_ptr<GPUOrigin3D> arg) {
|
|
57
|
+
// No conversions here
|
|
58
|
+
return jsi::Value::null();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <string>
|
|
4
|
+
|
|
5
|
+
#include "jsi2/NativeObject.h"
|
|
6
|
+
|
|
7
|
+
namespace rnwgpu {
|
|
8
|
+
|
|
9
|
+
namespace jsi = facebook::jsi;
|
|
10
|
+
|
|
11
|
+
class GPUOutOfMemoryError : public NativeObject<GPUOutOfMemoryError> {
|
|
12
|
+
public:
|
|
13
|
+
static constexpr const char *CLASS_NAME = "GPUOutOfMemoryError";
|
|
14
|
+
|
|
15
|
+
explicit GPUOutOfMemoryError(std::string message)
|
|
16
|
+
: NativeObject(CLASS_NAME), _message(std::move(message)) {}
|
|
17
|
+
|
|
18
|
+
public:
|
|
19
|
+
std::string getBrand() { return CLASS_NAME; }
|
|
20
|
+
std::string getMessage() { return _message; }
|
|
21
|
+
|
|
22
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
23
|
+
installGetter(runtime, prototype, "__brand",
|
|
24
|
+
&GPUOutOfMemoryError::getBrand);
|
|
25
|
+
installGetter(runtime, prototype, "message",
|
|
26
|
+
&GPUOutOfMemoryError::getMessage);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private:
|
|
30
|
+
std::string _message;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <string>
|
|
4
|
+
|
|
5
|
+
#include "descriptors/Unions.h"
|
|
6
|
+
|
|
7
|
+
#include "jsi2/NativeObject.h"
|
|
8
|
+
|
|
9
|
+
#include "webgpu/webgpu_cpp.h"
|
|
10
|
+
|
|
11
|
+
namespace rnwgpu {
|
|
12
|
+
|
|
13
|
+
namespace jsi = facebook::jsi;
|
|
14
|
+
|
|
15
|
+
class GPUPipelineLayout : public NativeObject<GPUPipelineLayout> {
|
|
16
|
+
public:
|
|
17
|
+
static constexpr const char *CLASS_NAME = "GPUPipelineLayout";
|
|
18
|
+
|
|
19
|
+
explicit GPUPipelineLayout(wgpu::PipelineLayout instance, std::string label)
|
|
20
|
+
: NativeObject(CLASS_NAME), _instance(instance), _label(label) {}
|
|
21
|
+
|
|
22
|
+
public:
|
|
23
|
+
std::string getBrand() { return CLASS_NAME; }
|
|
24
|
+
|
|
25
|
+
std::string getLabel() { return _label; }
|
|
26
|
+
void setLabel(const std::string &label) {
|
|
27
|
+
_label = label;
|
|
28
|
+
_instance.SetLabel(_label.c_str());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
32
|
+
installGetter(runtime, prototype, "__brand", &GPUPipelineLayout::getBrand);
|
|
33
|
+
installGetterSetter(runtime, prototype, "label",
|
|
34
|
+
&GPUPipelineLayout::getLabel,
|
|
35
|
+
&GPUPipelineLayout::setLabel);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
inline const wgpu::PipelineLayout get() { return _instance; }
|
|
39
|
+
|
|
40
|
+
private:
|
|
41
|
+
wgpu::PipelineLayout _instance;
|
|
42
|
+
std::string _label;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#include "GPUQuerySet.h"
|
|
2
|
+
|
|
3
|
+
namespace rnwgpu {
|
|
4
|
+
|
|
5
|
+
void GPUQuerySet::destroy() { _instance.Destroy(); }
|
|
6
|
+
|
|
7
|
+
wgpu::QueryType GPUQuerySet::getType() { return _instance.GetType(); }
|
|
8
|
+
|
|
9
|
+
uint32_t GPUQuerySet::getCount() { return _instance.GetCount(); }
|
|
10
|
+
|
|
11
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <string>
|
|
4
|
+
|
|
5
|
+
#include "descriptors/Unions.h"
|
|
6
|
+
|
|
7
|
+
#include "jsi2/NativeObject.h"
|
|
8
|
+
|
|
9
|
+
#include "webgpu/webgpu_cpp.h"
|
|
10
|
+
|
|
11
|
+
namespace rnwgpu {
|
|
12
|
+
|
|
13
|
+
namespace jsi = facebook::jsi;
|
|
14
|
+
|
|
15
|
+
class GPUQuerySet : public NativeObject<GPUQuerySet> {
|
|
16
|
+
public:
|
|
17
|
+
static constexpr const char *CLASS_NAME = "GPUQuerySet";
|
|
18
|
+
|
|
19
|
+
explicit GPUQuerySet(wgpu::QuerySet instance, std::string label)
|
|
20
|
+
: NativeObject(CLASS_NAME), _instance(instance), _label(label) {}
|
|
21
|
+
|
|
22
|
+
public:
|
|
23
|
+
std::string getBrand() { return CLASS_NAME; }
|
|
24
|
+
|
|
25
|
+
void destroy();
|
|
26
|
+
|
|
27
|
+
wgpu::QueryType getType();
|
|
28
|
+
uint32_t getCount();
|
|
29
|
+
|
|
30
|
+
std::string getLabel() { return _label; }
|
|
31
|
+
void setLabel(const std::string &label) {
|
|
32
|
+
_label = label;
|
|
33
|
+
_instance.SetLabel(_label.c_str());
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
37
|
+
installGetter(runtime, prototype, "__brand", &GPUQuerySet::getBrand);
|
|
38
|
+
installMethod(runtime, prototype, "destroy", &GPUQuerySet::destroy);
|
|
39
|
+
installGetter(runtime, prototype, "type", &GPUQuerySet::getType);
|
|
40
|
+
installGetter(runtime, prototype, "count", &GPUQuerySet::getCount);
|
|
41
|
+
installGetterSetter(runtime, prototype, "label", &GPUQuerySet::getLabel,
|
|
42
|
+
&GPUQuerySet::setLabel);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
inline const wgpu::QuerySet get() { return _instance; }
|
|
46
|
+
|
|
47
|
+
size_t getMemoryPressure() override {
|
|
48
|
+
uint32_t count = getCount();
|
|
49
|
+
wgpu::QueryType type = getType();
|
|
50
|
+
|
|
51
|
+
// Estimate bytes per query based on type
|
|
52
|
+
size_t bytesPerQuery = 8; // Default estimate
|
|
53
|
+
switch (type) {
|
|
54
|
+
case wgpu::QueryType::Occlusion:
|
|
55
|
+
bytesPerQuery = 8; // 64-bit counter
|
|
56
|
+
break;
|
|
57
|
+
case wgpu::QueryType::Timestamp:
|
|
58
|
+
bytesPerQuery = 8; // 64-bit timestamp
|
|
59
|
+
break;
|
|
60
|
+
default:
|
|
61
|
+
bytesPerQuery = 8; // Safe default
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return static_cast<size_t>(count) * bytesPerQuery;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private:
|
|
69
|
+
wgpu::QuerySet _instance;
|
|
70
|
+
std::string _label;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
#include "GPUQueue.h"
|
|
2
|
+
|
|
3
|
+
#include <limits>
|
|
4
|
+
#include <memory>
|
|
5
|
+
#include <vector>
|
|
6
|
+
|
|
7
|
+
#include "Convertors.h"
|
|
8
|
+
|
|
9
|
+
namespace rnwgpu {
|
|
10
|
+
|
|
11
|
+
struct BufferSource {
|
|
12
|
+
void *data;
|
|
13
|
+
size_t size; // in bytes
|
|
14
|
+
size_t bytesPerElement; // 1 for ArrayBuffers
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
void GPUQueue::submit(
|
|
18
|
+
std::vector<std::shared_ptr<GPUCommandBuffer>> commandBuffers) {
|
|
19
|
+
std::vector<wgpu::CommandBuffer> bufs(commandBuffers.size());
|
|
20
|
+
for (size_t i = 0; i < commandBuffers.size(); i++) {
|
|
21
|
+
bufs[i] = commandBuffers[i]->get();
|
|
22
|
+
}
|
|
23
|
+
Convertor conv;
|
|
24
|
+
uint32_t bufs_size;
|
|
25
|
+
if (!conv(bufs_size, bufs.size())) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
_instance.Submit(bufs_size, bufs.data());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
void GPUQueue::writeBuffer(std::shared_ptr<GPUBuffer> buffer,
|
|
32
|
+
uint64_t bufferOffset,
|
|
33
|
+
std::shared_ptr<ArrayBuffer> data,
|
|
34
|
+
std::optional<uint64_t> dataOffsetElements,
|
|
35
|
+
std::optional<size_t> sizeElements) {
|
|
36
|
+
wgpu::Buffer buf = buffer->get();
|
|
37
|
+
BufferSource src{.data = data->_data,
|
|
38
|
+
.size = data->_size,
|
|
39
|
+
.bytesPerElement = data->_bytesPerElement};
|
|
40
|
+
|
|
41
|
+
// Note that in the JS semantics of WebGPU, writeBuffer works in number of
|
|
42
|
+
// elements of the typed arrays.
|
|
43
|
+
if (dataOffsetElements >
|
|
44
|
+
static_cast<uint64_t>(src.size / src.bytesPerElement)) {
|
|
45
|
+
throw std::runtime_error("dataOffset is larger than data's size.");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
uint64_t dataOffset = dataOffsetElements.value_or(0) * src.bytesPerElement;
|
|
49
|
+
src.data = reinterpret_cast<uint8_t *>(src.data) + dataOffset;
|
|
50
|
+
src.size -= dataOffset;
|
|
51
|
+
|
|
52
|
+
// Size defaults to dataSize - dataOffset. Instead of computing in elements,
|
|
53
|
+
// we directly use it in bytes, and convert the provided value, if any, in
|
|
54
|
+
// bytes.
|
|
55
|
+
uint64_t size64 = static_cast<uint64_t>(src.size);
|
|
56
|
+
if (sizeElements.has_value()) {
|
|
57
|
+
if (sizeElements.value() >
|
|
58
|
+
std::numeric_limits<uint64_t>::max() / src.bytesPerElement) {
|
|
59
|
+
throw std::runtime_error("size overflows.");
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
size64 = sizeElements.value() * src.bytesPerElement;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (size64 > static_cast<uint64_t>(src.size)) {
|
|
66
|
+
throw std::runtime_error("size + dataOffset is larger than data's size.");
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (size64 % 4 != 0) {
|
|
71
|
+
throw std::runtime_error("size is not a multiple of 4 bytes.");
|
|
72
|
+
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
assert(size64 <= std::numeric_limits<size_t>::max());
|
|
77
|
+
_instance.WriteBuffer(buf, bufferOffset, src.data,
|
|
78
|
+
static_cast<size_t>(size64));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async::AsyncTaskHandle GPUQueue::onSubmittedWorkDone() {
|
|
82
|
+
auto queue = _instance;
|
|
83
|
+
return _async->postTask(
|
|
84
|
+
[queue](const async::AsyncTaskHandle::ResolveFunction &resolve,
|
|
85
|
+
const async::AsyncTaskHandle::RejectFunction &reject) {
|
|
86
|
+
queue.OnSubmittedWorkDone(
|
|
87
|
+
wgpu::CallbackMode::AllowProcessEvents,
|
|
88
|
+
[resolve, reject](wgpu::QueueWorkDoneStatus status,
|
|
89
|
+
wgpu::StringView message) {
|
|
90
|
+
if (status == wgpu::QueueWorkDoneStatus::Success) {
|
|
91
|
+
resolve(nullptr);
|
|
92
|
+
} else {
|
|
93
|
+
std::string error =
|
|
94
|
+
message.length ? std::string(message.data, message.length)
|
|
95
|
+
: "Queue work did not complete successfully";
|
|
96
|
+
reject(std::move(error));
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
void GPUQueue::copyExternalImageToTexture(
|
|
103
|
+
std::shared_ptr<GPUImageCopyExternalImage> source,
|
|
104
|
+
std::shared_ptr<GPUImageCopyTextureTagged> destination,
|
|
105
|
+
std::shared_ptr<GPUExtent3D> size) {
|
|
106
|
+
// wgpu::TexelCopyTextureInfo dst{};
|
|
107
|
+
// wgpu::TexelCopyBufferLayout layout{};
|
|
108
|
+
// wgpu::Extent3D sz{};
|
|
109
|
+
// Convertor conv;
|
|
110
|
+
// uint32_t bytesPerPixel =
|
|
111
|
+
// source->source->getSize() /
|
|
112
|
+
// (source->source->getWidth() * source->source->getHeight());
|
|
113
|
+
// auto dataLayout = std::make_shared<GPUImageDataLayout>(GPUImageDataLayout{
|
|
114
|
+
// std::optional<double>{0.0},
|
|
115
|
+
// std::optional<double>{
|
|
116
|
+
// static_cast<double>(bytesPerPixel * source->source->getWidth())},
|
|
117
|
+
// std::optional<double>{static_cast<double>(source->source->getHeight())}});
|
|
118
|
+
// if (!conv(dst.aspect, destination->aspect) ||
|
|
119
|
+
// !conv(dst.mipLevel, destination->mipLevel) ||
|
|
120
|
+
// !conv(dst.origin, destination->origin) ||
|
|
121
|
+
// !conv(dst.texture, destination->texture) ||
|
|
122
|
+
// !conv(layout, dataLayout) || //
|
|
123
|
+
// !conv(sz, size)) {
|
|
124
|
+
// throw std::runtime_error("Invalid input for GPUQueue::writeTexture()");
|
|
125
|
+
// }
|
|
126
|
+
//
|
|
127
|
+
// if (source->flipY) {
|
|
128
|
+
// // Calculate the row size and total size
|
|
129
|
+
// uint32_t rowSize = bytesPerPixel * source->source->getWidth();
|
|
130
|
+
// uint32_t totalSize = source->source->getSize();
|
|
131
|
+
//
|
|
132
|
+
// // Create a new buffer for the flipped data
|
|
133
|
+
// std::vector<uint8_t> flippedData(totalSize);
|
|
134
|
+
//
|
|
135
|
+
// // Flip the data vertically
|
|
136
|
+
// for (uint32_t row = 0; row < source->source->getHeight(); ++row) {
|
|
137
|
+
// std::memcpy(flippedData.data() +
|
|
138
|
+
// (source->source->getHeight() - 1 - row) * rowSize,
|
|
139
|
+
// static_cast<const uint8_t *>(source->source->getData()) +
|
|
140
|
+
// row * rowSize,
|
|
141
|
+
// rowSize);
|
|
142
|
+
// }
|
|
143
|
+
// // Use the flipped data for writing to texture
|
|
144
|
+
// _instance.WriteTexture(&dst, flippedData.data(), totalSize, &layout, &sz);
|
|
145
|
+
// } else {
|
|
146
|
+
//
|
|
147
|
+
// _instance.WriteTexture(&dst, source->source->getData(),
|
|
148
|
+
// source->source->getSize(), &layout, &sz);
|
|
149
|
+
// }
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
void GPUQueue::writeTexture(std::shared_ptr<GPUImageCopyTexture> destination,
|
|
153
|
+
std::shared_ptr<ArrayBuffer> data,
|
|
154
|
+
std::shared_ptr<GPUImageDataLayout> dataLayout,
|
|
155
|
+
std::shared_ptr<GPUExtent3D> size) {
|
|
156
|
+
wgpu::TexelCopyTextureInfo dst{};
|
|
157
|
+
wgpu::TexelCopyBufferLayout layout{};
|
|
158
|
+
wgpu::Extent3D sz{};
|
|
159
|
+
Convertor conv;
|
|
160
|
+
if (!conv(dst, destination) || //
|
|
161
|
+
!conv(layout, dataLayout) || //
|
|
162
|
+
!conv(sz, size)) {
|
|
163
|
+
throw std::runtime_error("Invalid input for GPUQueue::writeTexture()");
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
_instance.WriteTexture(&dst, data->_data, data->_size, &layout, &sz);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <string>
|
|
5
|
+
#include <vector>
|
|
6
|
+
|
|
7
|
+
#include "descriptors/Unions.h"
|
|
8
|
+
|
|
9
|
+
#include "jsi2/NativeObject.h"
|
|
10
|
+
|
|
11
|
+
#include "rnwgpu/async/AsyncRunner.h"
|
|
12
|
+
#include "rnwgpu/async/AsyncTaskHandle.h"
|
|
13
|
+
|
|
14
|
+
#include "webgpu/webgpu_cpp.h"
|
|
15
|
+
|
|
16
|
+
#include "rnwgpu/ArrayBuffer.h"
|
|
17
|
+
#include "GPUBuffer.h"
|
|
18
|
+
#include "GPUCommandBuffer.h"
|
|
19
|
+
#include "GPUExtent3D.h"
|
|
20
|
+
#include "descriptors/GPUImageCopyExternalImage.h"
|
|
21
|
+
#include "descriptors/GPUImageCopyTexture.h"
|
|
22
|
+
#include "descriptors/GPUImageCopyTextureTagged.h"
|
|
23
|
+
#include "descriptors/GPUImageDataLayout.h"
|
|
24
|
+
|
|
25
|
+
namespace rnwgpu {
|
|
26
|
+
|
|
27
|
+
namespace jsi = facebook::jsi;
|
|
28
|
+
|
|
29
|
+
class GPUQueue : public NativeObject<GPUQueue> {
|
|
30
|
+
public:
|
|
31
|
+
static constexpr const char *CLASS_NAME = "GPUQueue";
|
|
32
|
+
|
|
33
|
+
explicit GPUQueue(wgpu::Queue instance,
|
|
34
|
+
std::shared_ptr<async::AsyncRunner> async,
|
|
35
|
+
std::string label)
|
|
36
|
+
: NativeObject(CLASS_NAME), _instance(instance), _async(async),
|
|
37
|
+
_label(label) {}
|
|
38
|
+
|
|
39
|
+
public:
|
|
40
|
+
std::string getBrand() { return CLASS_NAME; }
|
|
41
|
+
|
|
42
|
+
void submit(std::vector<std::shared_ptr<GPUCommandBuffer>> commandBuffers);
|
|
43
|
+
async::AsyncTaskHandle onSubmittedWorkDone();
|
|
44
|
+
void writeBuffer(std::shared_ptr<GPUBuffer> buffer, uint64_t bufferOffset,
|
|
45
|
+
std::shared_ptr<ArrayBuffer> data,
|
|
46
|
+
std::optional<uint64_t> dataOffsetElements,
|
|
47
|
+
std::optional<size_t> sizeElements);
|
|
48
|
+
void writeTexture(std::shared_ptr<GPUImageCopyTexture> destination,
|
|
49
|
+
std::shared_ptr<ArrayBuffer> data,
|
|
50
|
+
std::shared_ptr<GPUImageDataLayout> dataLayout,
|
|
51
|
+
std::shared_ptr<GPUExtent3D> size);
|
|
52
|
+
void copyExternalImageToTexture(
|
|
53
|
+
std::shared_ptr<GPUImageCopyExternalImage> source,
|
|
54
|
+
std::shared_ptr<GPUImageCopyTextureTagged> destination,
|
|
55
|
+
std::shared_ptr<GPUExtent3D> copySize);
|
|
56
|
+
|
|
57
|
+
std::string getLabel() { return _label; }
|
|
58
|
+
void setLabel(const std::string &label) {
|
|
59
|
+
_label = label;
|
|
60
|
+
_instance.SetLabel(_label.c_str());
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
64
|
+
installGetter(runtime, prototype, "__brand", &GPUQueue::getBrand);
|
|
65
|
+
installMethod(runtime, prototype, "submit", &GPUQueue::submit);
|
|
66
|
+
installMethod(runtime, prototype, "onSubmittedWorkDone",
|
|
67
|
+
&GPUQueue::onSubmittedWorkDone);
|
|
68
|
+
installMethod(runtime, prototype, "writeBuffer", &GPUQueue::writeBuffer);
|
|
69
|
+
installMethod(runtime, prototype, "writeTexture", &GPUQueue::writeTexture);
|
|
70
|
+
installMethod(runtime, prototype, "copyExternalImageToTexture",
|
|
71
|
+
&GPUQueue::copyExternalImageToTexture);
|
|
72
|
+
installGetterSetter(runtime, prototype, "label", &GPUQueue::getLabel,
|
|
73
|
+
&GPUQueue::setLabel);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
inline const wgpu::Queue get() { return _instance; }
|
|
77
|
+
|
|
78
|
+
private:
|
|
79
|
+
wgpu::Queue _instance;
|
|
80
|
+
std::shared_ptr<async::AsyncRunner> _async;
|
|
81
|
+
std::string _label;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <string>
|
|
4
|
+
|
|
5
|
+
#include "descriptors/Unions.h"
|
|
6
|
+
|
|
7
|
+
#include "jsi2/NativeObject.h"
|
|
8
|
+
|
|
9
|
+
#include "webgpu/webgpu_cpp.h"
|
|
10
|
+
|
|
11
|
+
namespace rnwgpu {
|
|
12
|
+
|
|
13
|
+
namespace jsi = facebook::jsi;
|
|
14
|
+
|
|
15
|
+
class GPURenderBundle : public NativeObject<GPURenderBundle> {
|
|
16
|
+
public:
|
|
17
|
+
static constexpr const char *CLASS_NAME = "GPURenderBundle";
|
|
18
|
+
|
|
19
|
+
explicit GPURenderBundle(wgpu::RenderBundle instance, std::string label)
|
|
20
|
+
: NativeObject(CLASS_NAME), _instance(instance), _label(label) {}
|
|
21
|
+
|
|
22
|
+
public:
|
|
23
|
+
std::string getBrand() { return CLASS_NAME; }
|
|
24
|
+
|
|
25
|
+
std::string getLabel() { return _label; }
|
|
26
|
+
void setLabel(const std::string &label) {
|
|
27
|
+
_label = label;
|
|
28
|
+
_instance.SetLabel(_label.c_str());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
32
|
+
installGetter(runtime, prototype, "__brand", &GPURenderBundle::getBrand);
|
|
33
|
+
installGetterSetter(runtime, prototype, "label", &GPURenderBundle::getLabel,
|
|
34
|
+
&GPURenderBundle::setLabel);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
inline const wgpu::RenderBundle get() { return _instance; }
|
|
38
|
+
|
|
39
|
+
private:
|
|
40
|
+
wgpu::RenderBundle _instance;
|
|
41
|
+
std::string _label;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
#include "GPURenderBundleEncoder.h"
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <string>
|
|
5
|
+
|
|
6
|
+
#include "Convertors.h"
|
|
7
|
+
|
|
8
|
+
namespace rnwgpu {
|
|
9
|
+
|
|
10
|
+
std::shared_ptr<GPURenderBundle> GPURenderBundleEncoder::finish(
|
|
11
|
+
std::optional<std::shared_ptr<GPURenderBundleDescriptor>> descriptor) {
|
|
12
|
+
wgpu::RenderBundleDescriptor desc;
|
|
13
|
+
Convertor conv;
|
|
14
|
+
if (!conv(desc, descriptor)) {
|
|
15
|
+
throw std::runtime_error("GPURenderBundleEncoder.finish(): couldn't get "
|
|
16
|
+
"GPURenderBundleDescriptor");
|
|
17
|
+
}
|
|
18
|
+
auto bundle = _instance.Finish(&desc);
|
|
19
|
+
return std::make_shared<GPURenderBundle>(
|
|
20
|
+
bundle,
|
|
21
|
+
descriptor.has_value() ? descriptor.value()->label.value_or("") : "");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
void GPURenderBundleEncoder::setPipeline(
|
|
25
|
+
std::shared_ptr<GPURenderPipeline> pipeline) {
|
|
26
|
+
_instance.SetPipeline(pipeline->get());
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
void GPURenderBundleEncoder::draw(uint32_t vertexCount,
|
|
30
|
+
std::optional<uint32_t> instanceCount,
|
|
31
|
+
std::optional<uint32_t> firstVertex,
|
|
32
|
+
std::optional<uint32_t> firstInstance) {
|
|
33
|
+
_instance.Draw(vertexCount, instanceCount.value_or(1),
|
|
34
|
+
firstVertex.value_or(0), firstInstance.value_or(0));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
void GPURenderBundleEncoder::setVertexBuffer(
|
|
38
|
+
uint32_t slot,
|
|
39
|
+
std::variant<std::nullptr_t, std::shared_ptr<GPUBuffer>> buffer,
|
|
40
|
+
std::optional<uint64_t> offset, std::optional<uint64_t> size) {
|
|
41
|
+
Convertor conv;
|
|
42
|
+
|
|
43
|
+
wgpu::Buffer b{};
|
|
44
|
+
uint64_t s = wgpu::kWholeSize;
|
|
45
|
+
if (!conv(b, buffer) || !conv(s, size)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
_instance.SetVertexBuffer(slot, b, offset.value_or(0), s);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
void GPURenderBundleEncoder::setBindGroup(
|
|
52
|
+
uint32_t groupIndex,
|
|
53
|
+
std::variant<std::nullptr_t, std::shared_ptr<GPUBindGroup>> bindGroup,
|
|
54
|
+
std::optional<std::vector<uint32_t>> dynamicOffsets) {
|
|
55
|
+
auto dynOffsets = dynamicOffsets.value_or(std::vector<uint32_t>());
|
|
56
|
+
if (dynOffsets.size() == 0) {
|
|
57
|
+
if (std::holds_alternative<std::nullptr_t>(bindGroup)) {
|
|
58
|
+
_instance.SetBindGroup(groupIndex, nullptr, 0, nullptr);
|
|
59
|
+
} else {
|
|
60
|
+
auto group = std::get<std::shared_ptr<GPUBindGroup>>(bindGroup);
|
|
61
|
+
_instance.SetBindGroup(groupIndex, group->get(), 0, nullptr);
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
if (std::holds_alternative<std::nullptr_t>(bindGroup)) {
|
|
65
|
+
_instance.SetBindGroup(groupIndex, nullptr, dynOffsets.size(),
|
|
66
|
+
dynamicOffsets->data());
|
|
67
|
+
} else {
|
|
68
|
+
auto group = std::get<std::shared_ptr<GPUBindGroup>>(bindGroup);
|
|
69
|
+
_instance.SetBindGroup(groupIndex, group->get(), dynOffsets.size(),
|
|
70
|
+
dynamicOffsets->data());
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
void GPURenderBundleEncoder::setIndexBuffer(std::shared_ptr<GPUBuffer> buffer,
|
|
76
|
+
wgpu::IndexFormat indexFormat,
|
|
77
|
+
std::optional<uint64_t> offset,
|
|
78
|
+
std::optional<uint64_t> size) {
|
|
79
|
+
Convertor conv;
|
|
80
|
+
|
|
81
|
+
wgpu::Buffer b{};
|
|
82
|
+
wgpu::IndexFormat f{};
|
|
83
|
+
uint64_t o = 0;
|
|
84
|
+
uint64_t s = wgpu::kWholeSize;
|
|
85
|
+
if (!conv(b, buffer) || //
|
|
86
|
+
!conv(f, indexFormat) || //
|
|
87
|
+
!conv(o, offset) || //
|
|
88
|
+
!conv(s, size)) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
_instance.SetIndexBuffer(b, f, o, s);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
void GPURenderBundleEncoder::drawIndexed(
|
|
96
|
+
uint32_t indexCount, std::optional<uint32_t> instanceCount,
|
|
97
|
+
std::optional<uint32_t> firstIndex, std::optional<double> baseVertex,
|
|
98
|
+
std::optional<uint32_t> firstInstance) {
|
|
99
|
+
_instance.DrawIndexed(indexCount, instanceCount.value_or(1),
|
|
100
|
+
firstIndex.value_or(0), baseVertex.value_or(0),
|
|
101
|
+
firstInstance.value_or(0));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
void GPURenderBundleEncoder::pushDebugGroup(std::string groupLabel) {
|
|
105
|
+
_instance.PushDebugGroup(groupLabel.c_str());
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
void GPURenderBundleEncoder::popDebugGroup() { _instance.PopDebugGroup(); }
|
|
109
|
+
|
|
110
|
+
void GPURenderBundleEncoder::insertDebugMarker(std::string markerLabel) {
|
|
111
|
+
_instance.InsertDebugMarker(markerLabel.c_str());
|
|
112
|
+
}
|
|
113
|
+
void GPURenderBundleEncoder::drawIndirect(
|
|
114
|
+
std::shared_ptr<GPUBuffer> indirectBuffer, uint64_t indirectOffset) {
|
|
115
|
+
Convertor conv;
|
|
116
|
+
wgpu::Buffer b{};
|
|
117
|
+
if (!conv(b, indirectBuffer)) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
_instance.DrawIndirect(b, indirectOffset);
|
|
121
|
+
}
|
|
122
|
+
void GPURenderBundleEncoder::drawIndexedIndirect(
|
|
123
|
+
std::shared_ptr<GPUBuffer> indirectBuffer, uint64_t indirectOffset) {
|
|
124
|
+
Convertor conv;
|
|
125
|
+
wgpu::Buffer b{};
|
|
126
|
+
if (!conv(b, indirectBuffer)) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
_instance.DrawIndexedIndirect(b, indirectOffset);
|
|
130
|
+
}
|
|
131
|
+
} // namespace rnwgpu
|