react-native-wgpu 0.4.2 → 0.5.1
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/README.md +31 -0
- package/android/CMakeLists.txt +3 -3
- package/cpp/jsi/{RNFEnumMapper.h → EnumMapper.h} +2 -6
- package/cpp/jsi/{RNFJSIConverter.h → JSIConverter.h} +27 -110
- package/cpp/jsi/NativeObject.h +607 -0
- package/cpp/jsi/{RNFPromise.cpp → Promise.cpp} +3 -6
- package/cpp/jsi/{RNFPromise.h → Promise.h} +2 -5
- package/cpp/jsi/RuntimeAwareCache.cpp +7 -0
- package/cpp/jsi/RuntimeAwareCache.h +100 -0
- package/cpp/jsi/RuntimeLifecycleMonitor.cpp +72 -0
- package/cpp/jsi/RuntimeLifecycleMonitor.h +32 -0
- package/cpp/rnwgpu/ArrayBuffer.h +8 -12
- package/cpp/rnwgpu/RNWebGPUManager.cpp +187 -28
- package/cpp/rnwgpu/RNWebGPUManager.h +7 -0
- package/cpp/rnwgpu/api/Canvas.h +14 -12
- package/cpp/rnwgpu/api/GPU.cpp +4 -6
- package/cpp/rnwgpu/api/GPU.h +13 -11
- package/cpp/rnwgpu/api/GPUAdapter.cpp +9 -9
- package/cpp/rnwgpu/api/GPUAdapter.h +14 -11
- package/cpp/rnwgpu/api/GPUAdapterInfo.h +17 -15
- package/cpp/rnwgpu/api/GPUBindGroup.h +11 -10
- package/cpp/rnwgpu/api/GPUBindGroupLayout.h +12 -11
- package/cpp/rnwgpu/api/GPUBuffer.h +19 -16
- package/cpp/rnwgpu/api/GPUCanvasContext.h +17 -13
- package/cpp/rnwgpu/api/GPUCommandBuffer.h +12 -10
- package/cpp/rnwgpu/api/GPUCommandEncoder.h +35 -32
- package/cpp/rnwgpu/api/GPUCompilationInfo.h +19 -19
- package/cpp/rnwgpu/api/GPUCompilationMessage.h +10 -7
- package/cpp/rnwgpu/api/GPUComputePassEncoder.h +28 -27
- package/cpp/rnwgpu/api/GPUComputePipeline.h +14 -13
- package/cpp/rnwgpu/api/GPUDevice.cpp +111 -95
- package/cpp/rnwgpu/api/GPUDevice.h +51 -43
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +12 -10
- package/cpp/rnwgpu/api/GPUError.h +19 -29
- package/cpp/rnwgpu/api/GPUExtent3D.h +7 -10
- package/cpp/rnwgpu/api/GPUExternalTexture.h +12 -11
- package/cpp/rnwgpu/api/GPUInternalError.h +31 -0
- package/cpp/rnwgpu/api/GPUOrigin2D.h +6 -10
- package/cpp/rnwgpu/api/GPUOrigin3D.h +6 -10
- package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +33 -0
- package/cpp/rnwgpu/api/GPUPipelineLayout.h +12 -10
- package/cpp/rnwgpu/api/GPUQuerySet.h +14 -12
- package/cpp/rnwgpu/api/GPUQueue.h +18 -17
- package/cpp/rnwgpu/api/GPURenderBundle.h +11 -10
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +36 -33
- package/cpp/rnwgpu/api/GPURenderPassEncoder.h +49 -47
- package/cpp/rnwgpu/api/GPURenderPipeline.h +14 -12
- package/cpp/rnwgpu/api/GPUSampler.h +11 -10
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +7 -8
- package/cpp/rnwgpu/api/GPUShaderModule.h +13 -12
- package/cpp/rnwgpu/api/GPUSupportedLimits.h +73 -93
- package/cpp/rnwgpu/api/GPUTexture.h +24 -20
- package/cpp/rnwgpu/api/GPUTextureView.h +11 -10
- package/cpp/rnwgpu/api/GPUValidationError.h +32 -0
- package/cpp/rnwgpu/api/ImageBitmap.h +10 -6
- package/cpp/rnwgpu/api/RNWebGPU.h +21 -21
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +7 -11
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUBufferUsage.h +28 -32
- package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUColor.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUColorWrite.h +18 -20
- package/cpp/rnwgpu/api/descriptors/GPUCommandBufferDescriptor.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUCommandEncoderDescriptor.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUMapMode.h +11 -14
- package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUQueueDescriptor.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleDescriptor.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUShaderStage.h +14 -16
- package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUTextureUsage.h +18 -29
- package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +3 -8
- package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +3 -7
- package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +3 -7
- package/cpp/rnwgpu/api/descriptors/Unions.h +3 -3
- package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +10 -10
- package/cpp/rnwgpu/async/AsyncTaskHandle.h +2 -2
- package/lib/commonjs/external/ModuleProxy.js +36 -0
- package/lib/commonjs/external/ModuleProxy.js.map +1 -0
- package/lib/commonjs/external/index.js +17 -0
- package/lib/commonjs/external/index.js.map +1 -0
- package/lib/commonjs/external/reanimated/ReanimatedProxy.js +18 -0
- package/lib/commonjs/external/reanimated/ReanimatedProxy.js.map +1 -0
- package/lib/commonjs/external/reanimated/index.js +21 -0
- package/lib/commonjs/external/reanimated/index.js.map +1 -0
- package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js +50 -0
- package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js.map +1 -0
- package/lib/commonjs/main/index.js +2 -142
- package/lib/commonjs/main/index.js.map +1 -1
- package/lib/module/external/ModuleProxy.js +28 -0
- package/lib/module/external/ModuleProxy.js.map +1 -0
- package/lib/module/external/index.js +2 -0
- package/lib/module/external/index.js.map +1 -0
- package/lib/module/external/reanimated/ReanimatedProxy.js +12 -0
- package/lib/module/external/reanimated/ReanimatedProxy.js.map +1 -0
- package/lib/module/external/reanimated/index.js +3 -0
- package/lib/module/external/reanimated/index.js.map +1 -0
- package/lib/module/external/reanimated/registerWebGPUForReanimated.js +43 -0
- package/lib/module/external/reanimated/registerWebGPUForReanimated.js.map +1 -0
- package/lib/module/main/index.js +2 -141
- package/lib/module/main/index.js.map +1 -1
- package/lib/typescript/babel.config.d.ts +1 -0
- package/lib/typescript/lib/commonjs/external/ModuleProxy.d.ts +12 -0
- package/lib/typescript/lib/commonjs/external/ModuleProxy.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/external/index.d.ts +2 -0
- package/lib/typescript/lib/commonjs/external/index.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/external/reanimated/ReanimatedProxy.d.ts +6 -0
- package/lib/typescript/lib/commonjs/external/reanimated/ReanimatedProxy.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/external/reanimated/index.d.ts +4 -0
- package/lib/typescript/lib/commonjs/external/reanimated/index.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/external/reanimated/registerWebGPUForReanimated.d.ts +9 -0
- package/lib/typescript/lib/commonjs/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -0
- package/lib/typescript/lib/module/external/ModuleProxy.d.ts +7 -0
- package/lib/typescript/lib/module/external/ModuleProxy.d.ts.map +1 -0
- package/lib/typescript/lib/module/external/index.d.ts +2 -0
- package/lib/typescript/lib/module/external/index.d.ts.map +1 -0
- package/lib/typescript/lib/module/external/reanimated/ReanimatedProxy.d.ts +5 -0
- package/lib/typescript/lib/module/external/reanimated/ReanimatedProxy.d.ts.map +1 -0
- package/lib/typescript/lib/module/external/reanimated/index.d.ts +3 -0
- package/lib/typescript/lib/module/external/reanimated/index.d.ts.map +1 -0
- package/lib/typescript/lib/module/external/reanimated/registerWebGPUForReanimated.d.ts +2 -0
- package/lib/typescript/lib/module/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -0
- package/lib/typescript/src/external/ModuleProxy.d.ts +11 -0
- package/lib/typescript/src/external/ModuleProxy.d.ts.map +1 -0
- package/lib/typescript/src/external/index.d.ts +2 -0
- package/lib/typescript/src/external/index.d.ts.map +1 -0
- package/lib/typescript/src/external/reanimated/ReanimatedProxy.d.ts +4 -0
- package/lib/typescript/src/external/reanimated/ReanimatedProxy.d.ts.map +1 -0
- package/lib/typescript/src/external/reanimated/index.d.ts +3 -0
- package/lib/typescript/src/external/reanimated/index.d.ts.map +1 -0
- package/lib/typescript/src/external/reanimated/registerWebGPUForReanimated.d.ts +8 -0
- package/lib/typescript/src/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -0
- package/package.json +16 -3
- package/src/external/ModuleProxy.ts +30 -0
- package/src/external/index.ts +1 -0
- package/src/external/reanimated/ReanimatedProxy.ts +19 -0
- package/src/external/reanimated/index.ts +2 -0
- package/src/external/reanimated/registerWebGPUForReanimated.ts +43 -0
- package/src/main/index.tsx +3 -170
- package/cpp/jsi/RNFHybridObject.cpp +0 -150
- package/cpp/jsi/RNFHybridObject.h +0 -181
- package/cpp/jsi/RNFJSIHelper.h +0 -51
- package/cpp/jsi/RNFPointerHolder.h +0 -95
- package/cpp/jsi/RNFRuntimeState.cpp +0 -18
- package/cpp/jsi/RNFRuntimeState.h +0 -106
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Created by Marc Rousavy on 16.04.24.
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
#pragma once
|
|
6
|
-
|
|
7
|
-
#include "RNFHybridObject.h"
|
|
8
|
-
#include "RNFLogger.h"
|
|
9
|
-
#include <memory>
|
|
10
|
-
#include <mutex>
|
|
11
|
-
#include <utility>
|
|
12
|
-
#include <string>
|
|
13
|
-
|
|
14
|
-
namespace margelo {
|
|
15
|
-
|
|
16
|
-
namespace jsi = facebook::jsi;
|
|
17
|
-
|
|
18
|
-
template <typename T> class PointerHolder : public HybridObject {
|
|
19
|
-
protected:
|
|
20
|
-
// no default constructor
|
|
21
|
-
PointerHolder() = delete;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Create a new instance of a pointer holder which holds the given shared_ptr.
|
|
25
|
-
* @param name The name of the implementing class, for example "ViewWrapper".
|
|
26
|
-
* @param pointer The pointer this class will hold. It might be released from JS at any point via `release()`.
|
|
27
|
-
*/
|
|
28
|
-
PointerHolder(const char* name, std::shared_ptr<T> pointer) : HybridObject(name), _name(name), _pointer(pointer) {
|
|
29
|
-
// eagerly initialize the release() method instead of putting it in `loadHybridMethods`
|
|
30
|
-
registerHybridMethod("release", &PointerHolder<T>::release, this);
|
|
31
|
-
registerHybridGetter("isValid", &PointerHolder<T>::getIsValid, this);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Create a new instance of a pointer holder which holds a shared_ptr of the given value.
|
|
36
|
-
* The shared_ptr will be move-constructed.
|
|
37
|
-
* @param name The name of the implementing class, for example "ViewWrapper".
|
|
38
|
-
* @param value The value this class will hold as a shared_ptr. It might be destroyed from JS at any point via `release()`.
|
|
39
|
-
*/
|
|
40
|
-
PointerHolder(const char* name, T&& value) : PointerHolder(name, std::make_shared<T>(std::move(value))) {}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Called when the PointerHolder gets automatically destroyed (e.g. via GC) and the shared_ptr will be destroyed.
|
|
44
|
-
*/
|
|
45
|
-
~PointerHolder() {
|
|
46
|
-
if (_pointer != nullptr) {
|
|
47
|
-
Logger::log(TAG, "Automatically releasing %s... (~PointerHolder())", _name.c_str());
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
protected:
|
|
52
|
-
/**
|
|
53
|
-
* Manually release this reference to the pointer.
|
|
54
|
-
* If there are any other references to this pointer, no memory will be force-deleted.
|
|
55
|
-
*/
|
|
56
|
-
virtual void release() {
|
|
57
|
-
std::unique_lock lock(_mutex);
|
|
58
|
-
|
|
59
|
-
if (_pointer == nullptr) {
|
|
60
|
-
throw std::runtime_error("Pointer " + _name + " has already been manually released!");
|
|
61
|
-
}
|
|
62
|
-
Logger::log(TAG, "Manually releasing %s... (PointerHolder::release())", _name.c_str());
|
|
63
|
-
_pointer = nullptr;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Get the shared_ptr this class is holding.
|
|
68
|
-
* If it has already been manually released from JS, this method will throw a runtime_error.
|
|
69
|
-
*/
|
|
70
|
-
std::shared_ptr<T> pointee() {
|
|
71
|
-
std::unique_lock lock(_mutex);
|
|
72
|
-
|
|
73
|
-
if (_pointer == nullptr) {
|
|
74
|
-
throw std::runtime_error("Pointer " + _name + " has already been manually released!");
|
|
75
|
-
}
|
|
76
|
-
return _pointer;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Get if the pointer is still valid and strong.
|
|
81
|
-
*/
|
|
82
|
-
bool getIsValid() {
|
|
83
|
-
std::unique_lock lock(_mutex);
|
|
84
|
-
|
|
85
|
-
return _pointer != nullptr;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
private:
|
|
89
|
-
std::string _name;
|
|
90
|
-
std::shared_ptr<T> _pointer;
|
|
91
|
-
std::mutex _mutex;
|
|
92
|
-
static constexpr auto TAG = "PointerHolder";
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
} // namespace margelo
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
#include "RNFRuntimeState.h"
|
|
2
|
-
|
|
3
|
-
namespace rnwgpu {
|
|
4
|
-
|
|
5
|
-
const facebook::jsi::UUID RNFRuntimeState::kRuntimeStateKey = facebook::jsi::UUID();
|
|
6
|
-
|
|
7
|
-
std::shared_ptr<RNFRuntimeState> RNFRuntimeState::get(facebook::jsi::Runtime& runtime) {
|
|
8
|
-
auto existing = runtime.getRuntimeData(kRuntimeStateKey);
|
|
9
|
-
if (existing) {
|
|
10
|
-
return std::static_pointer_cast<RNFRuntimeState>(existing);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
auto state = std::shared_ptr<RNFRuntimeState>(new RNFRuntimeState());
|
|
14
|
-
runtime.setRuntimeData(kRuntimeStateKey, state);
|
|
15
|
-
return state;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
} // namespace rnwgpu
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <jsi/jsi.h>
|
|
4
|
-
|
|
5
|
-
#include <memory>
|
|
6
|
-
#include <mutex>
|
|
7
|
-
#include <unordered_map>
|
|
8
|
-
#include <unordered_set>
|
|
9
|
-
|
|
10
|
-
namespace rnwgpu {
|
|
11
|
-
|
|
12
|
-
namespace jsi = facebook::jsi;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Runtime state management using Hermes' runtime.setRuntimeData API.
|
|
16
|
-
* This replaces the old RuntimeLifecycleMonitor/RuntimeAwareCache system.
|
|
17
|
-
*/
|
|
18
|
-
class RNFRuntimeState {
|
|
19
|
-
public:
|
|
20
|
-
// UUID key for storing our runtime state
|
|
21
|
-
static const jsi::UUID kRuntimeStateKey;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Get or create the runtime state for the given runtime
|
|
25
|
-
*/
|
|
26
|
-
static std::shared_ptr<RNFRuntimeState> get(jsi::Runtime& runtime);
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Template cache that can store any type T per object pointer
|
|
30
|
-
*/
|
|
31
|
-
template <typename T>
|
|
32
|
-
class ObjectCache {
|
|
33
|
-
public:
|
|
34
|
-
std::shared_ptr<T> getOrCreate(void* object) {
|
|
35
|
-
std::lock_guard<std::mutex> lock(mutex_);
|
|
36
|
-
auto it = cache_.find(object);
|
|
37
|
-
if (it != cache_.end()) {
|
|
38
|
-
return it->second;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
auto value = std::make_shared<T>();
|
|
42
|
-
cache_[object] = value;
|
|
43
|
-
return value;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
void remove(void* object) {
|
|
47
|
-
std::lock_guard<std::mutex> lock(mutex_);
|
|
48
|
-
cache_.erase(object);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
void clear() {
|
|
52
|
-
std::lock_guard<std::mutex> lock(mutex_);
|
|
53
|
-
cache_.clear();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
private:
|
|
57
|
-
std::mutex mutex_;
|
|
58
|
-
std::unordered_map<void*, std::shared_ptr<T>> cache_;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Get or create a cache for a specific type T
|
|
63
|
-
*/
|
|
64
|
-
template <typename T>
|
|
65
|
-
std::shared_ptr<ObjectCache<T>> getCache() {
|
|
66
|
-
std::lock_guard<std::mutex> lock(mutex_);
|
|
67
|
-
|
|
68
|
-
// Use type_info as key for the cache type
|
|
69
|
-
const std::type_info& typeId = typeid(T);
|
|
70
|
-
auto it = typeCaches_.find(&typeId);
|
|
71
|
-
|
|
72
|
-
if (it != typeCaches_.end()) {
|
|
73
|
-
return std::static_pointer_cast<ObjectCache<T>>(it->second);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
auto cache = std::make_shared<ObjectCache<T>>();
|
|
77
|
-
typeCaches_[&typeId] = cache;
|
|
78
|
-
return cache;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
private:
|
|
82
|
-
RNFRuntimeState() = default;
|
|
83
|
-
|
|
84
|
-
std::mutex mutex_;
|
|
85
|
-
// Map from type_info to cache instance
|
|
86
|
-
std::unordered_map<const std::type_info*, std::shared_ptr<void>> typeCaches_;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Template helper for runtime-aware caching compatible with the old API
|
|
91
|
-
* This provides a migration path from RuntimeAwareCache
|
|
92
|
-
*/
|
|
93
|
-
template <typename T>
|
|
94
|
-
class RuntimeAwareCache {
|
|
95
|
-
public:
|
|
96
|
-
T& get(jsi::Runtime& rt) {
|
|
97
|
-
auto state = RNFRuntimeState::get(rt);
|
|
98
|
-
auto cache = state->getCache<T>();
|
|
99
|
-
|
|
100
|
-
// For compatibility, we use the runtime pointer as the object key
|
|
101
|
-
auto ptr = cache->getOrCreate(&rt);
|
|
102
|
-
return *ptr;
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
} // namespace rnwgpu
|