@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,12 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "webgpu/webgpu_cpp.h"
|
|
4
|
+
|
|
5
|
+
namespace rnwgpu {
|
|
6
|
+
enum class PredefinedColorSpace : uint32_t {
|
|
7
|
+
DisplayP3 = 0,
|
|
8
|
+
Srgb = 1,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
enum class PremultiplyAlpha : uint32_t { Default = 0, None = 1, Premultiply };
|
|
12
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#include "GPU.h"
|
|
2
|
+
|
|
3
|
+
#include <cstdio>
|
|
4
|
+
#include <memory>
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <unordered_set>
|
|
7
|
+
#include <utility>
|
|
8
|
+
#include <vector>
|
|
9
|
+
|
|
10
|
+
#include "Convertors.h"
|
|
11
|
+
#include "jsi2/JSIConverter.h"
|
|
12
|
+
#include "rnwgpu/async/JSIMicrotaskDispatcher.h"
|
|
13
|
+
|
|
14
|
+
namespace rnwgpu {
|
|
15
|
+
|
|
16
|
+
GPU::GPU(jsi::Runtime &runtime, wgpu::Instance instance)
|
|
17
|
+
: NativeObject(CLASS_NAME), _instance(instance) {
|
|
18
|
+
auto dispatcher = std::make_shared<async::JSIMicrotaskDispatcher>(runtime);
|
|
19
|
+
_async = async::AsyncRunner::getOrCreate(runtime, _instance, dispatcher);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async::AsyncTaskHandle GPU::requestAdapter(
|
|
23
|
+
std::optional<std::shared_ptr<GPURequestAdapterOptions>> options) {
|
|
24
|
+
wgpu::RequestAdapterOptions aOptions;
|
|
25
|
+
Convertor conv;
|
|
26
|
+
if (!conv(aOptions, options)) {
|
|
27
|
+
throw std::runtime_error("Failed to convert GPUDeviceDescriptor");
|
|
28
|
+
}
|
|
29
|
+
#ifdef __APPLE__
|
|
30
|
+
constexpr auto kDefaultBackendType = wgpu::BackendType::Metal;
|
|
31
|
+
#else
|
|
32
|
+
constexpr auto kDefaultBackendType = wgpu::BackendType::Vulkan;
|
|
33
|
+
#endif
|
|
34
|
+
aOptions.backendType = kDefaultBackendType;
|
|
35
|
+
return _async->postTask(
|
|
36
|
+
[this, aOptions](const async::AsyncTaskHandle::ResolveFunction &resolve,
|
|
37
|
+
const async::AsyncTaskHandle::RejectFunction &reject) {
|
|
38
|
+
_instance.RequestAdapter(
|
|
39
|
+
&aOptions, wgpu::CallbackMode::AllowProcessEvents,
|
|
40
|
+
[asyncRunner = _async, resolve,
|
|
41
|
+
reject](wgpu::RequestAdapterStatus status, wgpu::Adapter adapter,
|
|
42
|
+
wgpu::StringView message) {
|
|
43
|
+
if (message.length) {
|
|
44
|
+
fprintf(stderr, "%s", message.data);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (status == wgpu::RequestAdapterStatus::Success && adapter) {
|
|
48
|
+
auto adapterHost = std::make_shared<GPUAdapter>(
|
|
49
|
+
std::move(adapter), asyncRunner);
|
|
50
|
+
auto result =
|
|
51
|
+
std::variant<std::nullptr_t, std::shared_ptr<GPUAdapter>>(
|
|
52
|
+
adapterHost);
|
|
53
|
+
resolve([result =
|
|
54
|
+
std::move(result)](jsi::Runtime &runtime) mutable {
|
|
55
|
+
return JSIConverter<decltype(result)>::toJSI(runtime, result);
|
|
56
|
+
});
|
|
57
|
+
} else {
|
|
58
|
+
auto result =
|
|
59
|
+
std::variant<std::nullptr_t, std::shared_ptr<GPUAdapter>>(
|
|
60
|
+
nullptr);
|
|
61
|
+
resolve([result =
|
|
62
|
+
std::move(result)](jsi::Runtime &runtime) mutable {
|
|
63
|
+
return JSIConverter<decltype(result)>::toJSI(runtime, result);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
std::unordered_set<std::string> GPU::getWgslLanguageFeatures() {
|
|
71
|
+
wgpu::SupportedWGSLLanguageFeatures supportedFeatures = {};
|
|
72
|
+
_instance.GetWGSLLanguageFeatures(&supportedFeatures);
|
|
73
|
+
|
|
74
|
+
std::unordered_set<std::string> result;
|
|
75
|
+
for (size_t i = 0; i < supportedFeatures.featureCount; i++) {
|
|
76
|
+
wgpu::WGSLLanguageFeatureName feature = supportedFeatures.features[i];
|
|
77
|
+
std::string name;
|
|
78
|
+
switch (feature) {
|
|
79
|
+
case wgpu::WGSLLanguageFeatureName::ReadonlyAndReadwriteStorageTextures:
|
|
80
|
+
name = "readonly_and_readwrite_storage_textures";
|
|
81
|
+
break;
|
|
82
|
+
case wgpu::WGSLLanguageFeatureName::Packed4x8IntegerDotProduct:
|
|
83
|
+
name = "packed_4x8_integer_dot_product";
|
|
84
|
+
break;
|
|
85
|
+
case wgpu::WGSLLanguageFeatureName::UnrestrictedPointerParameters:
|
|
86
|
+
name = "unrestricted_pointer_parameters";
|
|
87
|
+
break;
|
|
88
|
+
case wgpu::WGSLLanguageFeatureName::PointerCompositeAccess:
|
|
89
|
+
name = "pointer_composite_access";
|
|
90
|
+
break;
|
|
91
|
+
case wgpu::WGSLLanguageFeatureName::ChromiumTestingUnimplemented:
|
|
92
|
+
name = "chromium_testing_unimplemented";
|
|
93
|
+
break;
|
|
94
|
+
case wgpu::WGSLLanguageFeatureName::ChromiumTestingUnsafeExperimental:
|
|
95
|
+
name = "chromium_testing_unsafe_experimental";
|
|
96
|
+
break;
|
|
97
|
+
case wgpu::WGSLLanguageFeatureName::ChromiumTestingExperimental:
|
|
98
|
+
name = "chromium_testing_experimental";
|
|
99
|
+
break;
|
|
100
|
+
case wgpu::WGSLLanguageFeatureName::ChromiumTestingShippedWithKillswitch:
|
|
101
|
+
name = "chromium_testing_shipped_with_killswitch";
|
|
102
|
+
break;
|
|
103
|
+
case wgpu::WGSLLanguageFeatureName::ChromiumTestingShipped:
|
|
104
|
+
name = "chromium_testing_shipped";
|
|
105
|
+
break;
|
|
106
|
+
case wgpu::WGSLLanguageFeatureName::SizedBindingArray:
|
|
107
|
+
name = "sized_binding_array";
|
|
108
|
+
break;
|
|
109
|
+
case wgpu::WGSLLanguageFeatureName::TexelBuffers:
|
|
110
|
+
name = "texel_buffers";
|
|
111
|
+
break;
|
|
112
|
+
case wgpu::WGSLLanguageFeatureName::ChromiumPrint:
|
|
113
|
+
name = "chromium_print";
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
result.insert(name);
|
|
117
|
+
}
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
wgpu::TextureFormat GPU::getPreferredCanvasFormat() {
|
|
122
|
+
#if defined(__ANDROID__)
|
|
123
|
+
return wgpu::TextureFormat::RGBA8Unorm;
|
|
124
|
+
#else
|
|
125
|
+
return wgpu::TextureFormat::BGRA8Unorm;
|
|
126
|
+
#endif // defined(__ANDROID__)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <string>
|
|
5
|
+
#include <unordered_set>
|
|
6
|
+
#include <variant>
|
|
7
|
+
|
|
8
|
+
#include "descriptors/Unions.h"
|
|
9
|
+
|
|
10
|
+
#include "jsi2/NativeObject.h"
|
|
11
|
+
|
|
12
|
+
#include "rnwgpu/async/AsyncRunner.h"
|
|
13
|
+
#include "rnwgpu/async/AsyncTaskHandle.h"
|
|
14
|
+
|
|
15
|
+
#include "webgpu/webgpu_cpp.h"
|
|
16
|
+
|
|
17
|
+
#include "GPUAdapter.h"
|
|
18
|
+
#include "descriptors/GPURequestAdapterOptions.h"
|
|
19
|
+
|
|
20
|
+
#include <webgpu/webgpu.h>
|
|
21
|
+
|
|
22
|
+
namespace rnwgpu {
|
|
23
|
+
|
|
24
|
+
namespace jsi = facebook::jsi;
|
|
25
|
+
|
|
26
|
+
class GPU : public NativeObject<GPU> {
|
|
27
|
+
public:
|
|
28
|
+
static constexpr const char *CLASS_NAME = "GPU";
|
|
29
|
+
|
|
30
|
+
explicit GPU(jsi::Runtime &runtime, wgpu::Instance instance);
|
|
31
|
+
|
|
32
|
+
public:
|
|
33
|
+
std::string getBrand() { return CLASS_NAME; }
|
|
34
|
+
|
|
35
|
+
async::AsyncTaskHandle requestAdapter(
|
|
36
|
+
std::optional<std::shared_ptr<GPURequestAdapterOptions>> options);
|
|
37
|
+
wgpu::TextureFormat getPreferredCanvasFormat();
|
|
38
|
+
|
|
39
|
+
std::unordered_set<std::string> getWgslLanguageFeatures();
|
|
40
|
+
|
|
41
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
42
|
+
installGetter(runtime, prototype, "__brand", &GPU::getBrand);
|
|
43
|
+
installMethod(runtime, prototype, "requestAdapter", &GPU::requestAdapter);
|
|
44
|
+
installMethod(runtime, prototype, "getPreferredCanvasFormat",
|
|
45
|
+
&GPU::getPreferredCanvasFormat);
|
|
46
|
+
installGetter(runtime, prototype, "wgslLanguageFeatures",
|
|
47
|
+
&GPU::getWgslLanguageFeatures);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
inline const wgpu::Instance get() { return _instance; }
|
|
51
|
+
|
|
52
|
+
private:
|
|
53
|
+
wgpu::Instance _instance;
|
|
54
|
+
std::shared_ptr<async::AsyncRunner> _async;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
#include "GPUAdapter.h"
|
|
2
|
+
|
|
3
|
+
#include <cstdio>
|
|
4
|
+
#include <memory>
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <unordered_set>
|
|
7
|
+
#include <utility>
|
|
8
|
+
#include <vector>
|
|
9
|
+
|
|
10
|
+
#include "Convertors.h"
|
|
11
|
+
|
|
12
|
+
#include "GPUFeatures.h"
|
|
13
|
+
#include "jsi2/JSIConverter.h"
|
|
14
|
+
|
|
15
|
+
namespace rnwgpu {
|
|
16
|
+
|
|
17
|
+
async::AsyncTaskHandle GPUAdapter::requestDevice(
|
|
18
|
+
std::optional<std::shared_ptr<GPUDeviceDescriptor>> descriptor) {
|
|
19
|
+
wgpu::DeviceDescriptor aDescriptor;
|
|
20
|
+
Convertor conv;
|
|
21
|
+
if (!conv(aDescriptor, descriptor)) {
|
|
22
|
+
throw std::runtime_error("Failed to convert GPUDeviceDescriptor");
|
|
23
|
+
}
|
|
24
|
+
auto deviceLostBinding = std::make_shared<std::weak_ptr<GPUDevice>>();
|
|
25
|
+
// Set device lost callback using new template API
|
|
26
|
+
aDescriptor.SetDeviceLostCallback(
|
|
27
|
+
wgpu::CallbackMode::AllowSpontaneous,
|
|
28
|
+
[deviceLostBinding](const wgpu::Device & /*device*/,
|
|
29
|
+
wgpu::DeviceLostReason reason,
|
|
30
|
+
wgpu::StringView message) {
|
|
31
|
+
const char *lostReason = "";
|
|
32
|
+
switch (reason) {
|
|
33
|
+
case wgpu::DeviceLostReason::Destroyed:
|
|
34
|
+
lostReason = "Destroyed";
|
|
35
|
+
break;
|
|
36
|
+
case wgpu::DeviceLostReason::Unknown:
|
|
37
|
+
lostReason = "Unknown";
|
|
38
|
+
break;
|
|
39
|
+
default:
|
|
40
|
+
lostReason = "Unknown";
|
|
41
|
+
}
|
|
42
|
+
std::string msg =
|
|
43
|
+
message.length ? std::string(message.data, message.length) : "";
|
|
44
|
+
fprintf(stderr, "GPU Device Lost (%s): %s\n", lostReason,
|
|
45
|
+
msg.c_str());
|
|
46
|
+
if (auto deviceHost = deviceLostBinding->lock()) {
|
|
47
|
+
deviceHost->notifyDeviceLost(reason, std::move(msg));
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Set uncaptured error callback using new template API
|
|
52
|
+
aDescriptor.SetUncapturedErrorCallback([](const wgpu::Device &device,
|
|
53
|
+
wgpu::ErrorType type,
|
|
54
|
+
wgpu::StringView message) {
|
|
55
|
+
const char *errorType = "";
|
|
56
|
+
switch (type) {
|
|
57
|
+
case wgpu::ErrorType::Validation:
|
|
58
|
+
errorType = "Validation";
|
|
59
|
+
break;
|
|
60
|
+
case wgpu::ErrorType::OutOfMemory:
|
|
61
|
+
errorType = "Out of Memory";
|
|
62
|
+
break;
|
|
63
|
+
case wgpu::ErrorType::Internal:
|
|
64
|
+
errorType = "Internal";
|
|
65
|
+
break;
|
|
66
|
+
case wgpu::ErrorType::Unknown:
|
|
67
|
+
errorType = "Unknown";
|
|
68
|
+
break;
|
|
69
|
+
default:
|
|
70
|
+
errorType = "Unknown";
|
|
71
|
+
}
|
|
72
|
+
std::string fullMessage =
|
|
73
|
+
message.length > 0 ? std::string(errorType) + ": " +
|
|
74
|
+
std::string(message.data, message.length)
|
|
75
|
+
: "no message";
|
|
76
|
+
fprintf(stderr, "%s", fullMessage.c_str());
|
|
77
|
+
});
|
|
78
|
+
std::string label =
|
|
79
|
+
descriptor.has_value() ? descriptor.value()->label.value_or("") : "";
|
|
80
|
+
|
|
81
|
+
auto creationRuntime = getCreationRuntime();
|
|
82
|
+
return _async->postTask(
|
|
83
|
+
[this, aDescriptor, descriptor, label = std::move(label),
|
|
84
|
+
deviceLostBinding,
|
|
85
|
+
creationRuntime](const async::AsyncTaskHandle::ResolveFunction &resolve,
|
|
86
|
+
const async::AsyncTaskHandle::RejectFunction &reject) {
|
|
87
|
+
(void)descriptor;
|
|
88
|
+
_instance.RequestDevice(
|
|
89
|
+
&aDescriptor, wgpu::CallbackMode::AllowProcessEvents,
|
|
90
|
+
[asyncRunner = _async, resolve, reject, label, creationRuntime,
|
|
91
|
+
deviceLostBinding](wgpu::RequestDeviceStatus status,
|
|
92
|
+
wgpu::Device device,
|
|
93
|
+
wgpu::StringView message) mutable {
|
|
94
|
+
if (message.length) {
|
|
95
|
+
fprintf(stderr, "%s", message.data);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (status != wgpu::RequestDeviceStatus::Success || !device) {
|
|
99
|
+
std::string error =
|
|
100
|
+
message.length ? std::string(message.data, message.length)
|
|
101
|
+
: "Failed to request device";
|
|
102
|
+
reject(std::move(error));
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
device.SetLoggingCallback([creationRuntime](
|
|
107
|
+
wgpu::LoggingType type,
|
|
108
|
+
wgpu::StringView msg) {
|
|
109
|
+
if (creationRuntime == nullptr) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const char *logLevel = "";
|
|
113
|
+
switch (type) {
|
|
114
|
+
case wgpu::LoggingType::Warning:
|
|
115
|
+
logLevel = "Warning";
|
|
116
|
+
fprintf(stderr, "WebGPU Warning: %.*s\n",
|
|
117
|
+
static_cast<int>(msg.length), msg.data);
|
|
118
|
+
break;
|
|
119
|
+
case wgpu::LoggingType::Error:
|
|
120
|
+
logLevel = "Error";
|
|
121
|
+
fprintf(stderr, "WebGPU Error: %.*s\n",
|
|
122
|
+
static_cast<int>(msg.length), msg.data);
|
|
123
|
+
break;
|
|
124
|
+
case wgpu::LoggingType::Verbose:
|
|
125
|
+
logLevel = "Verbose";
|
|
126
|
+
break;
|
|
127
|
+
case wgpu::LoggingType::Info:
|
|
128
|
+
logLevel = "Info";
|
|
129
|
+
break;
|
|
130
|
+
default:
|
|
131
|
+
logLevel = "Unknown";
|
|
132
|
+
fprintf(stderr, "%s: %.*s\n", logLevel,
|
|
133
|
+
static_cast<int>(msg.length), msg.data);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
auto deviceHost = std::make_shared<GPUDevice>(std::move(device),
|
|
138
|
+
asyncRunner, label);
|
|
139
|
+
*deviceLostBinding = deviceHost;
|
|
140
|
+
resolve([deviceHost = std::move(deviceHost)](
|
|
141
|
+
jsi::Runtime &runtime) mutable {
|
|
142
|
+
return JSIConverter<std::shared_ptr<GPUDevice>>::toJSI(
|
|
143
|
+
runtime, deviceHost);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
std::unordered_set<std::string> GPUAdapter::getFeatures() {
|
|
150
|
+
wgpu::SupportedFeatures supportedFeatures;
|
|
151
|
+
_instance.GetFeatures(&supportedFeatures);
|
|
152
|
+
std::unordered_set<std::string> result;
|
|
153
|
+
for (size_t i = 0; i < supportedFeatures.featureCount; ++i) {
|
|
154
|
+
auto feature = supportedFeatures.features[i];
|
|
155
|
+
std::string name;
|
|
156
|
+
convertEnumToJSUnion(feature, &name);
|
|
157
|
+
if (name != "") {
|
|
158
|
+
result.insert(name);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
std::shared_ptr<GPUSupportedLimits> GPUAdapter::getLimits() {
|
|
165
|
+
wgpu::Limits limits{};
|
|
166
|
+
if (!_instance.GetLimits(&limits)) {
|
|
167
|
+
throw std::runtime_error("Failed to get limits");
|
|
168
|
+
}
|
|
169
|
+
return std::make_shared<GPUSupportedLimits>(limits);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
std::shared_ptr<GPUAdapterInfo> GPUAdapter::getInfo() {
|
|
173
|
+
wgpu::AdapterInfo info = {};
|
|
174
|
+
_instance.GetInfo(&info);
|
|
175
|
+
return std::make_shared<GPUAdapterInfo>(info);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <string>
|
|
5
|
+
#include <unordered_set>
|
|
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 "GPUAdapterInfo.h"
|
|
17
|
+
#include "GPUDevice.h"
|
|
18
|
+
#include "descriptors/GPUDeviceDescriptor.h"
|
|
19
|
+
#include "GPUSupportedLimits.h"
|
|
20
|
+
|
|
21
|
+
namespace rnwgpu {
|
|
22
|
+
|
|
23
|
+
namespace jsi = facebook::jsi;
|
|
24
|
+
|
|
25
|
+
class GPUAdapter : public NativeObject<GPUAdapter> {
|
|
26
|
+
public:
|
|
27
|
+
static constexpr const char *CLASS_NAME = "GPUAdapter";
|
|
28
|
+
|
|
29
|
+
explicit GPUAdapter(wgpu::Adapter instance,
|
|
30
|
+
std::shared_ptr<async::AsyncRunner> async)
|
|
31
|
+
: NativeObject(CLASS_NAME), _instance(instance), _async(async) {}
|
|
32
|
+
|
|
33
|
+
public:
|
|
34
|
+
std::string getBrand() { return CLASS_NAME; }
|
|
35
|
+
|
|
36
|
+
async::AsyncTaskHandle
|
|
37
|
+
requestDevice(std::optional<std::shared_ptr<GPUDeviceDescriptor>> descriptor);
|
|
38
|
+
|
|
39
|
+
std::unordered_set<std::string> getFeatures();
|
|
40
|
+
std::shared_ptr<GPUSupportedLimits> getLimits();
|
|
41
|
+
std::shared_ptr<GPUAdapterInfo> getInfo();
|
|
42
|
+
|
|
43
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
44
|
+
installGetter(runtime, prototype, "__brand", &GPUAdapter::getBrand);
|
|
45
|
+
installMethod(runtime, prototype, "requestDevice",
|
|
46
|
+
&GPUAdapter::requestDevice);
|
|
47
|
+
installGetter(runtime, prototype, "features", &GPUAdapter::getFeatures);
|
|
48
|
+
installGetter(runtime, prototype, "limits", &GPUAdapter::getLimits);
|
|
49
|
+
installGetter(runtime, prototype, "info", &GPUAdapter::getInfo);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
inline const wgpu::Adapter get() { return _instance; }
|
|
53
|
+
|
|
54
|
+
private:
|
|
55
|
+
wgpu::Adapter _instance;
|
|
56
|
+
std::shared_ptr<async::AsyncRunner> _async;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <string>
|
|
4
|
+
#include <utility>
|
|
5
|
+
|
|
6
|
+
#include "descriptors/Unions.h"
|
|
7
|
+
|
|
8
|
+
#include "jsi2/NativeObject.h"
|
|
9
|
+
|
|
10
|
+
#include "Convertors.h"
|
|
11
|
+
|
|
12
|
+
#include "webgpu/webgpu_cpp.h"
|
|
13
|
+
|
|
14
|
+
namespace rnwgpu {
|
|
15
|
+
|
|
16
|
+
namespace jsi = facebook::jsi;
|
|
17
|
+
|
|
18
|
+
class GPUAdapterInfo : public NativeObject<GPUAdapterInfo> {
|
|
19
|
+
public:
|
|
20
|
+
static constexpr const char *CLASS_NAME = "GPUAdapterInfo";
|
|
21
|
+
|
|
22
|
+
explicit GPUAdapterInfo(wgpu::AdapterInfo &info)
|
|
23
|
+
: NativeObject(CLASS_NAME), _vendor(info.vendor),
|
|
24
|
+
_architecture(info.architecture), _device(info.device),
|
|
25
|
+
_description(info.description),
|
|
26
|
+
_isFallbackAdapter(info.adapterType == wgpu::AdapterType::CPU) {}
|
|
27
|
+
|
|
28
|
+
public:
|
|
29
|
+
std::string getBrand() { return CLASS_NAME; }
|
|
30
|
+
|
|
31
|
+
std::string getVendor() { return _vendor; }
|
|
32
|
+
std::string getArchitecture() { return _architecture; }
|
|
33
|
+
std::string getDevice() { return _device; }
|
|
34
|
+
std::string getDescription() { return _description; }
|
|
35
|
+
bool getIsFallbackAdapter() { return _isFallbackAdapter; }
|
|
36
|
+
|
|
37
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
38
|
+
installGetter(runtime, prototype, "__brand", &GPUAdapterInfo::getBrand);
|
|
39
|
+
installGetter(runtime, prototype, "vendor", &GPUAdapterInfo::getVendor);
|
|
40
|
+
installGetter(runtime, prototype, "architecture",
|
|
41
|
+
&GPUAdapterInfo::getArchitecture);
|
|
42
|
+
installGetter(runtime, prototype, "device", &GPUAdapterInfo::getDevice);
|
|
43
|
+
installGetter(runtime, prototype, "description",
|
|
44
|
+
&GPUAdapterInfo::getDescription);
|
|
45
|
+
installGetter(runtime, prototype, "isFallbackAdapter",
|
|
46
|
+
&GPUAdapterInfo::getIsFallbackAdapter);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private:
|
|
50
|
+
std::string _vendor;
|
|
51
|
+
std::string _architecture;
|
|
52
|
+
std::string _device;
|
|
53
|
+
std::string _description;
|
|
54
|
+
bool _isFallbackAdapter;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,51 @@
|
|
|
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 GPUBindGroup : public NativeObject<GPUBindGroup> {
|
|
16
|
+
public:
|
|
17
|
+
static constexpr const char *CLASS_NAME = "GPUBindGroup";
|
|
18
|
+
|
|
19
|
+
explicit GPUBindGroup(wgpu::BindGroup 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", &GPUBindGroup::getBrand);
|
|
33
|
+
installGetterSetter(runtime, prototype, "label", &GPUBindGroup::getLabel,
|
|
34
|
+
&GPUBindGroup::setLabel);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
inline const wgpu::BindGroup get() { return _instance; }
|
|
38
|
+
|
|
39
|
+
size_t getMemoryPressure() override {
|
|
40
|
+
// Bind groups store resource bindings and descriptor state
|
|
41
|
+
// They reference buffers, textures, samplers, etc.
|
|
42
|
+
// Estimate: 1KB per bind group (descriptor tables and binding state)
|
|
43
|
+
return 1024;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private:
|
|
47
|
+
wgpu::BindGroup _instance;
|
|
48
|
+
std::string _label;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,52 @@
|
|
|
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 GPUBindGroupLayout : public NativeObject<GPUBindGroupLayout> {
|
|
16
|
+
public:
|
|
17
|
+
static constexpr const char *CLASS_NAME = "GPUBindGroupLayout";
|
|
18
|
+
|
|
19
|
+
explicit GPUBindGroupLayout(wgpu::BindGroupLayout 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", &GPUBindGroupLayout::getBrand);
|
|
33
|
+
installGetterSetter(runtime, prototype, "label",
|
|
34
|
+
&GPUBindGroupLayout::getLabel,
|
|
35
|
+
&GPUBindGroupLayout::setLabel);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
inline const wgpu::BindGroupLayout get() { return _instance; }
|
|
39
|
+
|
|
40
|
+
size_t getMemoryPressure() override {
|
|
41
|
+
// Bind group layouts define the structure/schema for bind groups
|
|
42
|
+
// They store binding descriptors, types, and validation info
|
|
43
|
+
// Estimate: 512 bytes per layout (smaller than actual bind groups)
|
|
44
|
+
return 512;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private:
|
|
48
|
+
wgpu::BindGroupLayout _instance;
|
|
49
|
+
std::string _label;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
} // namespace rnwgpu
|