@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,110 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <optional>
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <variant>
|
|
7
|
+
#include <vector>
|
|
8
|
+
|
|
9
|
+
#include "descriptors/Unions.h"
|
|
10
|
+
|
|
11
|
+
#include "jsi2/NativeObject.h"
|
|
12
|
+
|
|
13
|
+
#include "webgpu/webgpu_cpp.h"
|
|
14
|
+
|
|
15
|
+
#include "GPUBindGroup.h"
|
|
16
|
+
#include "GPUBuffer.h"
|
|
17
|
+
#include "GPURenderBundle.h"
|
|
18
|
+
#include "descriptors/GPURenderBundleDescriptor.h"
|
|
19
|
+
#include "GPURenderPipeline.h"
|
|
20
|
+
|
|
21
|
+
namespace rnwgpu {
|
|
22
|
+
|
|
23
|
+
namespace jsi = facebook::jsi;
|
|
24
|
+
|
|
25
|
+
class GPURenderBundleEncoder : public NativeObject<GPURenderBundleEncoder> {
|
|
26
|
+
public:
|
|
27
|
+
static constexpr const char *CLASS_NAME = "GPURenderBundleEncoder";
|
|
28
|
+
|
|
29
|
+
explicit GPURenderBundleEncoder(wgpu::RenderBundleEncoder instance,
|
|
30
|
+
std::string label)
|
|
31
|
+
: NativeObject(CLASS_NAME), _instance(instance), _label(label) {}
|
|
32
|
+
|
|
33
|
+
public:
|
|
34
|
+
std::string getBrand() { return CLASS_NAME; }
|
|
35
|
+
|
|
36
|
+
std::shared_ptr<GPURenderBundle>
|
|
37
|
+
finish(std::optional<std::shared_ptr<GPURenderBundleDescriptor>> descriptor);
|
|
38
|
+
void pushDebugGroup(std::string groupLabel);
|
|
39
|
+
void popDebugGroup();
|
|
40
|
+
void insertDebugMarker(std::string markerLabel);
|
|
41
|
+
void setBindGroup(
|
|
42
|
+
uint32_t index,
|
|
43
|
+
std::variant<std::nullptr_t, std::shared_ptr<GPUBindGroup>> bindGroup,
|
|
44
|
+
std::optional<std::vector<uint32_t>> dynamicOffsets);
|
|
45
|
+
void setPipeline(std::shared_ptr<GPURenderPipeline> pipeline);
|
|
46
|
+
void setIndexBuffer(std::shared_ptr<GPUBuffer> buffer,
|
|
47
|
+
wgpu::IndexFormat indexFormat,
|
|
48
|
+
std::optional<uint64_t> offset,
|
|
49
|
+
std::optional<uint64_t> size);
|
|
50
|
+
void setVertexBuffer(
|
|
51
|
+
uint32_t slot,
|
|
52
|
+
std::variant<std::nullptr_t, std::shared_ptr<GPUBuffer>> buffer,
|
|
53
|
+
std::optional<uint64_t> offset, std::optional<uint64_t> size);
|
|
54
|
+
void draw(uint32_t vertexCount, std::optional<uint32_t> instanceCount,
|
|
55
|
+
std::optional<uint32_t> firstVertex,
|
|
56
|
+
std::optional<uint32_t> firstInstance);
|
|
57
|
+
void drawIndexed(uint32_t indexCount, std::optional<uint32_t> instanceCount,
|
|
58
|
+
std::optional<uint32_t> firstIndex,
|
|
59
|
+
std::optional<double> baseVertex,
|
|
60
|
+
std::optional<uint32_t> firstInstance);
|
|
61
|
+
void drawIndirect(std::shared_ptr<GPUBuffer> indirectBuffer,
|
|
62
|
+
uint64_t indirectOffset);
|
|
63
|
+
void drawIndexedIndirect(std::shared_ptr<GPUBuffer> indirectBuffer,
|
|
64
|
+
uint64_t indirectOffset);
|
|
65
|
+
|
|
66
|
+
std::string getLabel() { return _label; }
|
|
67
|
+
void setLabel(const std::string &label) {
|
|
68
|
+
_label = label;
|
|
69
|
+
_instance.SetLabel(_label.c_str());
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
73
|
+
installGetter(runtime, prototype, "__brand",
|
|
74
|
+
&GPURenderBundleEncoder::getBrand);
|
|
75
|
+
installMethod(runtime, prototype, "finish",
|
|
76
|
+
&GPURenderBundleEncoder::finish);
|
|
77
|
+
installMethod(runtime, prototype, "pushDebugGroup",
|
|
78
|
+
&GPURenderBundleEncoder::pushDebugGroup);
|
|
79
|
+
installMethod(runtime, prototype, "popDebugGroup",
|
|
80
|
+
&GPURenderBundleEncoder::popDebugGroup);
|
|
81
|
+
installMethod(runtime, prototype, "insertDebugMarker",
|
|
82
|
+
&GPURenderBundleEncoder::insertDebugMarker);
|
|
83
|
+
installMethod(runtime, prototype, "setBindGroup",
|
|
84
|
+
&GPURenderBundleEncoder::setBindGroup);
|
|
85
|
+
installMethod(runtime, prototype, "setPipeline",
|
|
86
|
+
&GPURenderBundleEncoder::setPipeline);
|
|
87
|
+
installMethod(runtime, prototype, "setIndexBuffer",
|
|
88
|
+
&GPURenderBundleEncoder::setIndexBuffer);
|
|
89
|
+
installMethod(runtime, prototype, "setVertexBuffer",
|
|
90
|
+
&GPURenderBundleEncoder::setVertexBuffer);
|
|
91
|
+
installMethod(runtime, prototype, "draw", &GPURenderBundleEncoder::draw);
|
|
92
|
+
installMethod(runtime, prototype, "drawIndexed",
|
|
93
|
+
&GPURenderBundleEncoder::drawIndexed);
|
|
94
|
+
installMethod(runtime, prototype, "drawIndirect",
|
|
95
|
+
&GPURenderBundleEncoder::drawIndirect);
|
|
96
|
+
installMethod(runtime, prototype, "drawIndexedIndirect",
|
|
97
|
+
&GPURenderBundleEncoder::drawIndexedIndirect);
|
|
98
|
+
installGetterSetter(runtime, prototype, "label",
|
|
99
|
+
&GPURenderBundleEncoder::getLabel,
|
|
100
|
+
&GPURenderBundleEncoder::setLabel);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
inline const wgpu::RenderBundleEncoder get() { return _instance; }
|
|
104
|
+
|
|
105
|
+
private:
|
|
106
|
+
wgpu::RenderBundleEncoder _instance;
|
|
107
|
+
std::string _label;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
#include <memory>
|
|
2
|
+
#include <string>
|
|
3
|
+
#include <vector>
|
|
4
|
+
|
|
5
|
+
#include "Convertors.h"
|
|
6
|
+
#include "GPURenderPassEncoder.h"
|
|
7
|
+
|
|
8
|
+
namespace rnwgpu {
|
|
9
|
+
|
|
10
|
+
void GPURenderPassEncoder::end() { _instance.End(); }
|
|
11
|
+
|
|
12
|
+
void GPURenderPassEncoder::setPipeline(
|
|
13
|
+
std::shared_ptr<GPURenderPipeline> pipeline) {
|
|
14
|
+
_instance.SetPipeline(pipeline->get());
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
void GPURenderPassEncoder::draw(uint32_t vertexCount,
|
|
18
|
+
std::optional<uint32_t> instanceCount,
|
|
19
|
+
std::optional<uint32_t> firstVertex,
|
|
20
|
+
std::optional<uint32_t> firstInstance) {
|
|
21
|
+
_instance.Draw(vertexCount, instanceCount.value_or(1),
|
|
22
|
+
firstVertex.value_or(0), firstInstance.value_or(0));
|
|
23
|
+
}
|
|
24
|
+
void GPURenderPassEncoder::setVertexBuffer(
|
|
25
|
+
uint32_t slot,
|
|
26
|
+
std::variant<std::nullptr_t, std::shared_ptr<GPUBuffer>> buffer,
|
|
27
|
+
std::optional<uint64_t> offset, std::optional<uint64_t> size) {
|
|
28
|
+
Convertor conv;
|
|
29
|
+
|
|
30
|
+
wgpu::Buffer b{};
|
|
31
|
+
uint64_t s = wgpu::kWholeSize;
|
|
32
|
+
if (!conv(b, buffer) || !conv(s, size)) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
_instance.SetVertexBuffer(slot, b, offset.value_or(0), s);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
void GPURenderPassEncoder::setBindGroup(
|
|
39
|
+
uint32_t groupIndex,
|
|
40
|
+
std::variant<std::nullptr_t, std::shared_ptr<GPUBindGroup>> bindGroup,
|
|
41
|
+
std::optional<std::vector<uint32_t>> dynamicOffsets) {
|
|
42
|
+
auto dynOffsets = dynamicOffsets.value_or(std::vector<uint32_t>());
|
|
43
|
+
if (dynOffsets.size() == 0) {
|
|
44
|
+
if (std::holds_alternative<nullptr_t>(bindGroup)) {
|
|
45
|
+
_instance.SetBindGroup(groupIndex, nullptr, 0, nullptr);
|
|
46
|
+
} else {
|
|
47
|
+
auto group = std::get<std::shared_ptr<GPUBindGroup>>(bindGroup);
|
|
48
|
+
_instance.SetBindGroup(groupIndex, group->get(), 0, nullptr);
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
if (std::holds_alternative<nullptr_t>(bindGroup)) {
|
|
52
|
+
_instance.SetBindGroup(groupIndex, nullptr, dynOffsets.size(),
|
|
53
|
+
dynamicOffsets->data());
|
|
54
|
+
} else {
|
|
55
|
+
auto group = std::get<std::shared_ptr<GPUBindGroup>>(bindGroup);
|
|
56
|
+
_instance.SetBindGroup(groupIndex, group->get(), dynOffsets.size(),
|
|
57
|
+
dynamicOffsets->data());
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
void GPURenderPassEncoder::setIndexBuffer(std::shared_ptr<GPUBuffer> buffer,
|
|
63
|
+
wgpu::IndexFormat indexFormat,
|
|
64
|
+
std::optional<uint64_t> offset,
|
|
65
|
+
std::optional<uint64_t> size) {
|
|
66
|
+
Convertor conv;
|
|
67
|
+
|
|
68
|
+
wgpu::Buffer b{};
|
|
69
|
+
wgpu::IndexFormat f{};
|
|
70
|
+
uint64_t o = 0;
|
|
71
|
+
uint64_t s = wgpu::kWholeSize;
|
|
72
|
+
if (!conv(b, buffer) || //
|
|
73
|
+
!conv(f, indexFormat) || //
|
|
74
|
+
!conv(o, offset) || //
|
|
75
|
+
!conv(s, size)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
_instance.SetIndexBuffer(b, f, o, s);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
void GPURenderPassEncoder::endOcclusionQuery() {
|
|
83
|
+
_instance.EndOcclusionQuery();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
void GPURenderPassEncoder::beginOcclusionQuery(uint32_t queryIndex) {
|
|
87
|
+
_instance.BeginOcclusionQuery(queryIndex);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
void GPURenderPassEncoder::drawIndexed(uint32_t indexCount,
|
|
91
|
+
std::optional<uint32_t> instanceCount,
|
|
92
|
+
std::optional<uint32_t> firstIndex,
|
|
93
|
+
std::optional<double> baseVertex,
|
|
94
|
+
std::optional<uint32_t> firstInstance) {
|
|
95
|
+
_instance.DrawIndexed(indexCount, instanceCount.value_or(1),
|
|
96
|
+
firstIndex.value_or(0), baseVertex.value_or(0),
|
|
97
|
+
firstInstance.value_or(0));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
void GPURenderPassEncoder::executeBundles(
|
|
101
|
+
std::vector<std::shared_ptr<GPURenderBundle>> bundles_in) {
|
|
102
|
+
Convertor conv;
|
|
103
|
+
|
|
104
|
+
wgpu::RenderBundle *bundles = nullptr;
|
|
105
|
+
size_t bundleCount = 0;
|
|
106
|
+
if (!conv(bundles, bundleCount, bundles_in)) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
_instance.ExecuteBundles(bundleCount, bundles);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
void GPURenderPassEncoder::setScissorRect(uint32_t x, uint32_t y,
|
|
114
|
+
uint32_t width, uint32_t height) {
|
|
115
|
+
_instance.SetScissorRect(x, y, width, height);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
void GPURenderPassEncoder::setViewport(double x, double y, double width,
|
|
119
|
+
double height, double minDepth,
|
|
120
|
+
double maxDepth) {
|
|
121
|
+
_instance.SetViewport(x, y, width, height, minDepth, maxDepth);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
void GPURenderPassEncoder::setBlendConstant(std::shared_ptr<GPUColor> color) {
|
|
125
|
+
Convertor conv;
|
|
126
|
+
wgpu::Color c{};
|
|
127
|
+
if (!conv(c, color)) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
_instance.SetBlendConstant(&c);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
void GPURenderPassEncoder::setStencilReference(uint32_t reference) {
|
|
134
|
+
_instance.SetStencilReference(reference);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
void GPURenderPassEncoder::pushDebugGroup(std::string groupLabel) {
|
|
138
|
+
_instance.PushDebugGroup(groupLabel.c_str());
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
void GPURenderPassEncoder::popDebugGroup() { _instance.PopDebugGroup(); }
|
|
142
|
+
|
|
143
|
+
void GPURenderPassEncoder::insertDebugMarker(std::string markerLabel) {
|
|
144
|
+
_instance.InsertDebugMarker(markerLabel.c_str());
|
|
145
|
+
}
|
|
146
|
+
void GPURenderPassEncoder::drawIndirect(
|
|
147
|
+
std::shared_ptr<GPUBuffer> indirectBuffer, uint64_t indirectOffset) {
|
|
148
|
+
Convertor conv;
|
|
149
|
+
wgpu::Buffer b{};
|
|
150
|
+
if (!conv(b, indirectBuffer)) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
_instance.DrawIndirect(b, indirectOffset);
|
|
154
|
+
}
|
|
155
|
+
void GPURenderPassEncoder::drawIndexedIndirect(
|
|
156
|
+
std::shared_ptr<GPUBuffer> indirectBuffer, uint64_t indirectOffset) {
|
|
157
|
+
Convertor conv;
|
|
158
|
+
wgpu::Buffer b{};
|
|
159
|
+
if (!conv(b, indirectBuffer)) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
_instance.DrawIndexedIndirect(b, indirectOffset);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <optional>
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <variant>
|
|
7
|
+
#include <vector>
|
|
8
|
+
|
|
9
|
+
#include "descriptors/Unions.h"
|
|
10
|
+
|
|
11
|
+
#include "jsi2/NativeObject.h"
|
|
12
|
+
|
|
13
|
+
#include "webgpu/webgpu_cpp.h"
|
|
14
|
+
|
|
15
|
+
#include "GPUBindGroup.h"
|
|
16
|
+
#include "GPUBuffer.h"
|
|
17
|
+
#include "descriptors/GPUColor.h"
|
|
18
|
+
#include "GPURenderBundle.h"
|
|
19
|
+
#include "GPURenderPipeline.h"
|
|
20
|
+
|
|
21
|
+
namespace rnwgpu {
|
|
22
|
+
|
|
23
|
+
namespace jsi = facebook::jsi;
|
|
24
|
+
|
|
25
|
+
class GPURenderPassEncoder : public NativeObject<GPURenderPassEncoder> {
|
|
26
|
+
public:
|
|
27
|
+
static constexpr const char *CLASS_NAME = "GPURenderPassEncoder";
|
|
28
|
+
|
|
29
|
+
explicit GPURenderPassEncoder(wgpu::RenderPassEncoder instance,
|
|
30
|
+
std::string label)
|
|
31
|
+
: NativeObject(CLASS_NAME), _instance(instance), _label(label) {}
|
|
32
|
+
|
|
33
|
+
public:
|
|
34
|
+
std::string getBrand() { return CLASS_NAME; }
|
|
35
|
+
|
|
36
|
+
void setViewport(double x, double y, double width, double height,
|
|
37
|
+
double minDepth, double maxDepth);
|
|
38
|
+
void setScissorRect(uint32_t x, uint32_t y, uint32_t width, uint32_t height);
|
|
39
|
+
void setBlendConstant(std::shared_ptr<GPUColor> color);
|
|
40
|
+
void setStencilReference(uint32_t reference);
|
|
41
|
+
void beginOcclusionQuery(uint32_t queryIndex);
|
|
42
|
+
void endOcclusionQuery();
|
|
43
|
+
void executeBundles(std::vector<std::shared_ptr<GPURenderBundle>> bundles);
|
|
44
|
+
void end();
|
|
45
|
+
void pushDebugGroup(std::string groupLabel);
|
|
46
|
+
void popDebugGroup();
|
|
47
|
+
void insertDebugMarker(std::string markerLabel);
|
|
48
|
+
void setBindGroup(
|
|
49
|
+
uint32_t index,
|
|
50
|
+
std::variant<std::nullptr_t, std::shared_ptr<GPUBindGroup>> bindGroup,
|
|
51
|
+
std::optional<std::vector<uint32_t>> dynamicOffsets);
|
|
52
|
+
void setPipeline(std::shared_ptr<GPURenderPipeline> pipeline);
|
|
53
|
+
void setIndexBuffer(std::shared_ptr<GPUBuffer> buffer,
|
|
54
|
+
wgpu::IndexFormat indexFormat,
|
|
55
|
+
std::optional<uint64_t> offset,
|
|
56
|
+
std::optional<uint64_t> size);
|
|
57
|
+
void setVertexBuffer(
|
|
58
|
+
uint32_t slot,
|
|
59
|
+
std::variant<std::nullptr_t, std::shared_ptr<GPUBuffer>> buffer,
|
|
60
|
+
std::optional<uint64_t> offset, std::optional<uint64_t> size);
|
|
61
|
+
void draw(uint32_t vertexCount, std::optional<uint32_t> instanceCount,
|
|
62
|
+
std::optional<uint32_t> firstVertex,
|
|
63
|
+
std::optional<uint32_t> firstInstance);
|
|
64
|
+
void drawIndexed(uint32_t indexCount, std::optional<uint32_t> instanceCount,
|
|
65
|
+
std::optional<uint32_t> firstIndex,
|
|
66
|
+
std::optional<double> baseVertex,
|
|
67
|
+
std::optional<uint32_t> firstInstance);
|
|
68
|
+
void drawIndirect(std::shared_ptr<GPUBuffer> indirectBuffer,
|
|
69
|
+
uint64_t indirectOffset);
|
|
70
|
+
void drawIndexedIndirect(std::shared_ptr<GPUBuffer> indirectBuffer,
|
|
71
|
+
uint64_t indirectOffset);
|
|
72
|
+
|
|
73
|
+
std::string getLabel() { return _label; }
|
|
74
|
+
void setLabel(const std::string &label) {
|
|
75
|
+
_label = label;
|
|
76
|
+
_instance.SetLabel(_label.c_str());
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
80
|
+
installGetter(runtime, prototype, "__brand",
|
|
81
|
+
&GPURenderPassEncoder::getBrand);
|
|
82
|
+
installMethod(runtime, prototype, "setViewport",
|
|
83
|
+
&GPURenderPassEncoder::setViewport);
|
|
84
|
+
installMethod(runtime, prototype, "setScissorRect",
|
|
85
|
+
&GPURenderPassEncoder::setScissorRect);
|
|
86
|
+
installMethod(runtime, prototype, "setBlendConstant",
|
|
87
|
+
&GPURenderPassEncoder::setBlendConstant);
|
|
88
|
+
installMethod(runtime, prototype, "setStencilReference",
|
|
89
|
+
&GPURenderPassEncoder::setStencilReference);
|
|
90
|
+
installMethod(runtime, prototype, "beginOcclusionQuery",
|
|
91
|
+
&GPURenderPassEncoder::beginOcclusionQuery);
|
|
92
|
+
installMethod(runtime, prototype, "endOcclusionQuery",
|
|
93
|
+
&GPURenderPassEncoder::endOcclusionQuery);
|
|
94
|
+
installMethod(runtime, prototype, "executeBundles",
|
|
95
|
+
&GPURenderPassEncoder::executeBundles);
|
|
96
|
+
installMethod(runtime, prototype, "end", &GPURenderPassEncoder::end);
|
|
97
|
+
installMethod(runtime, prototype, "pushDebugGroup",
|
|
98
|
+
&GPURenderPassEncoder::pushDebugGroup);
|
|
99
|
+
installMethod(runtime, prototype, "popDebugGroup",
|
|
100
|
+
&GPURenderPassEncoder::popDebugGroup);
|
|
101
|
+
installMethod(runtime, prototype, "insertDebugMarker",
|
|
102
|
+
&GPURenderPassEncoder::insertDebugMarker);
|
|
103
|
+
installMethod(runtime, prototype, "setBindGroup",
|
|
104
|
+
&GPURenderPassEncoder::setBindGroup);
|
|
105
|
+
installMethod(runtime, prototype, "setPipeline",
|
|
106
|
+
&GPURenderPassEncoder::setPipeline);
|
|
107
|
+
installMethod(runtime, prototype, "setIndexBuffer",
|
|
108
|
+
&GPURenderPassEncoder::setIndexBuffer);
|
|
109
|
+
installMethod(runtime, prototype, "setVertexBuffer",
|
|
110
|
+
&GPURenderPassEncoder::setVertexBuffer);
|
|
111
|
+
installMethod(runtime, prototype, "draw", &GPURenderPassEncoder::draw);
|
|
112
|
+
installMethod(runtime, prototype, "drawIndexed",
|
|
113
|
+
&GPURenderPassEncoder::drawIndexed);
|
|
114
|
+
installMethod(runtime, prototype, "drawIndirect",
|
|
115
|
+
&GPURenderPassEncoder::drawIndirect);
|
|
116
|
+
installMethod(runtime, prototype, "drawIndexedIndirect",
|
|
117
|
+
&GPURenderPassEncoder::drawIndexedIndirect);
|
|
118
|
+
installGetterSetter(runtime, prototype, "label",
|
|
119
|
+
&GPURenderPassEncoder::getLabel,
|
|
120
|
+
&GPURenderPassEncoder::setLabel);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
inline const wgpu::RenderPassEncoder get() { return _instance; }
|
|
124
|
+
|
|
125
|
+
private:
|
|
126
|
+
wgpu::RenderPassEncoder _instance;
|
|
127
|
+
std::string _label;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#include "GPURenderPipeline.h"
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
|
|
5
|
+
namespace rnwgpu {
|
|
6
|
+
|
|
7
|
+
std::shared_ptr<GPUBindGroupLayout>
|
|
8
|
+
GPURenderPipeline::getBindGroupLayout(uint32_t groupIndex) {
|
|
9
|
+
auto bindGroupLayout = _instance.GetBindGroupLayout(groupIndex);
|
|
10
|
+
return std::make_shared<GPUBindGroupLayout>(bindGroupLayout, "");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <string>
|
|
5
|
+
|
|
6
|
+
#include "descriptors/Unions.h"
|
|
7
|
+
|
|
8
|
+
#include "jsi2/NativeObject.h"
|
|
9
|
+
|
|
10
|
+
#include "webgpu/webgpu_cpp.h"
|
|
11
|
+
|
|
12
|
+
#include "GPUBindGroupLayout.h"
|
|
13
|
+
|
|
14
|
+
namespace rnwgpu {
|
|
15
|
+
|
|
16
|
+
namespace jsi = facebook::jsi;
|
|
17
|
+
|
|
18
|
+
class GPURenderPipeline : public NativeObject<GPURenderPipeline> {
|
|
19
|
+
public:
|
|
20
|
+
static constexpr const char *CLASS_NAME = "GPURenderPipeline";
|
|
21
|
+
|
|
22
|
+
explicit GPURenderPipeline(wgpu::RenderPipeline instance, std::string label)
|
|
23
|
+
: NativeObject(CLASS_NAME), _instance(instance), _label(label) {}
|
|
24
|
+
|
|
25
|
+
public:
|
|
26
|
+
std::string getBrand() { return CLASS_NAME; }
|
|
27
|
+
|
|
28
|
+
std::shared_ptr<GPUBindGroupLayout> getBindGroupLayout(uint32_t index);
|
|
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", &GPURenderPipeline::getBrand);
|
|
38
|
+
installMethod(runtime, prototype, "getBindGroupLayout",
|
|
39
|
+
&GPURenderPipeline::getBindGroupLayout);
|
|
40
|
+
installGetterSetter(runtime, prototype, "label",
|
|
41
|
+
&GPURenderPipeline::getLabel,
|
|
42
|
+
&GPURenderPipeline::setLabel);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
inline const wgpu::RenderPipeline get() { return _instance; }
|
|
46
|
+
|
|
47
|
+
size_t getMemoryPressure() override {
|
|
48
|
+
// Render pipelines contain compiled shader state, vertex/fragment shaders,
|
|
49
|
+
// render state, and driver-specific optimized code
|
|
50
|
+
// Estimate: 24KB for a typical render pipeline with vertex + fragment
|
|
51
|
+
// shaders
|
|
52
|
+
return 24 * 1024;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private:
|
|
56
|
+
wgpu::RenderPipeline _instance;
|
|
57
|
+
std::string _label;
|
|
58
|
+
friend class GPUDevice;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
} // 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 GPUSampler : public NativeObject<GPUSampler> {
|
|
16
|
+
public:
|
|
17
|
+
static constexpr const char *CLASS_NAME = "GPUSampler";
|
|
18
|
+
|
|
19
|
+
explicit GPUSampler(wgpu::Sampler 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", &GPUSampler::getBrand);
|
|
33
|
+
installGetterSetter(runtime, prototype, "label", &GPUSampler::getLabel,
|
|
34
|
+
&GPUSampler::setLabel);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
inline const wgpu::Sampler get() { return _instance; }
|
|
38
|
+
|
|
39
|
+
private:
|
|
40
|
+
wgpu::Sampler _instance;
|
|
41
|
+
std::string _label;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#include "GPUShaderModule.h"
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <utility>
|
|
5
|
+
|
|
6
|
+
#include "jsi2/JSIConverter.h"
|
|
7
|
+
|
|
8
|
+
namespace rnwgpu {
|
|
9
|
+
|
|
10
|
+
async::AsyncTaskHandle GPUShaderModule::getCompilationInfo() {
|
|
11
|
+
auto module = _instance;
|
|
12
|
+
|
|
13
|
+
return _async->postTask(
|
|
14
|
+
[module](const async::AsyncTaskHandle::ResolveFunction &resolve,
|
|
15
|
+
const async::AsyncTaskHandle::RejectFunction &reject) {
|
|
16
|
+
auto result = std::make_shared<GPUCompilationInfo>();
|
|
17
|
+
module.GetCompilationInfo(
|
|
18
|
+
wgpu::CallbackMode::AllowProcessEvents,
|
|
19
|
+
[result, resolve,
|
|
20
|
+
reject](wgpu::CompilationInfoRequestStatus status,
|
|
21
|
+
const wgpu::CompilationInfo *compilationInfo) mutable {
|
|
22
|
+
if (status != wgpu::CompilationInfoRequestStatus::Success ||
|
|
23
|
+
compilationInfo == nullptr) {
|
|
24
|
+
reject("Failed to get compilation info");
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
result->_messages.reserve(compilationInfo->messageCount);
|
|
29
|
+
for (size_t i = 0; i < compilationInfo->messageCount; ++i) {
|
|
30
|
+
const auto &wgpuMessage = compilationInfo->messages[i];
|
|
31
|
+
GPUCompilationMessageData message;
|
|
32
|
+
message.message =
|
|
33
|
+
wgpuMessage.message.length ? wgpuMessage.message.data : "";
|
|
34
|
+
message.type = wgpuMessage.type;
|
|
35
|
+
message.lineNum = wgpuMessage.lineNum;
|
|
36
|
+
message.linePos = wgpuMessage.linePos;
|
|
37
|
+
message.offset = wgpuMessage.offset;
|
|
38
|
+
message.length = wgpuMessage.length;
|
|
39
|
+
result->_messages.push_back(std::move(message));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
resolve([result =
|
|
43
|
+
std::move(result)](jsi::Runtime &runtime) mutable {
|
|
44
|
+
return JSIConverter<std::shared_ptr<GPUCompilationInfo>>::toJSI(
|
|
45
|
+
runtime, result);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <string>
|
|
5
|
+
|
|
6
|
+
#include "descriptors/Unions.h"
|
|
7
|
+
|
|
8
|
+
#include "jsi2/NativeObject.h"
|
|
9
|
+
|
|
10
|
+
#include "rnwgpu/async/AsyncRunner.h"
|
|
11
|
+
#include "rnwgpu/async/AsyncTaskHandle.h"
|
|
12
|
+
|
|
13
|
+
#include "webgpu/webgpu_cpp.h"
|
|
14
|
+
|
|
15
|
+
#include "GPUCompilationInfo.h"
|
|
16
|
+
|
|
17
|
+
namespace rnwgpu {
|
|
18
|
+
|
|
19
|
+
namespace jsi = facebook::jsi;
|
|
20
|
+
|
|
21
|
+
class GPUShaderModule : public NativeObject<GPUShaderModule> {
|
|
22
|
+
public:
|
|
23
|
+
static constexpr const char *CLASS_NAME = "GPUShaderModule";
|
|
24
|
+
|
|
25
|
+
explicit GPUShaderModule(wgpu::ShaderModule instance,
|
|
26
|
+
std::shared_ptr<async::AsyncRunner> async,
|
|
27
|
+
std::string label)
|
|
28
|
+
: NativeObject(CLASS_NAME), _instance(instance), _async(async),
|
|
29
|
+
_label(label) {}
|
|
30
|
+
|
|
31
|
+
public:
|
|
32
|
+
std::string getBrand() { return CLASS_NAME; }
|
|
33
|
+
|
|
34
|
+
async::AsyncTaskHandle getCompilationInfo();
|
|
35
|
+
|
|
36
|
+
std::string getLabel() { return _label; }
|
|
37
|
+
void setLabel(const std::string &label) {
|
|
38
|
+
_label = label;
|
|
39
|
+
_instance.SetLabel(_label.c_str());
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
43
|
+
installGetter(runtime, prototype, "__brand", &GPUShaderModule::getBrand);
|
|
44
|
+
installMethod(runtime, prototype, "getCompilationInfo",
|
|
45
|
+
&GPUShaderModule::getCompilationInfo);
|
|
46
|
+
installGetterSetter(runtime, prototype, "label", &GPUShaderModule::getLabel,
|
|
47
|
+
&GPUShaderModule::setLabel);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
inline const wgpu::ShaderModule get() { return _instance; }
|
|
51
|
+
|
|
52
|
+
size_t getMemoryPressure() override {
|
|
53
|
+
// Estimate memory usage for compiled shader module
|
|
54
|
+
// Shaders can vary widely, but a reasonable estimate is 8-16KB for typical
|
|
55
|
+
// shaders Complex shaders (with many uniforms, textures, or computations)
|
|
56
|
+
// can be much larger
|
|
57
|
+
return 12 * 1024; // 12KB estimate for average shader
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private:
|
|
61
|
+
wgpu::ShaderModule _instance;
|
|
62
|
+
std::shared_ptr<async::AsyncRunner> _async;
|
|
63
|
+
std::string _label;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
} // namespace rnwgpu
|