react-native-wgpu 0.2.1 → 0.2.3
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 +1 -1
- package/android/build.gradle +2 -1
- package/android/src/main/java/com/webgpu/WebGPUAHBView.java +247 -45
- package/android/src/main/java/com/webgpu/WebGPUView.java +4 -4
- package/apple/ApplePlatformContext.h +1 -0
- package/apple/RNWGUIKit.h +5 -0
- package/apple/platform/ThreadUtils.cpp +1 -0
- package/cpp/WGPULogger.h +1 -0
- package/cpp/dawn/dawn_proc_table.h +31 -10
- package/cpp/dawn/native/D3D11Backend.h +8 -2
- package/cpp/dawn/native/D3DBackend.h +0 -3
- package/cpp/dawn/native/DawnNative.h +4 -0
- package/cpp/dawn/platform/DawnPlatform.h +2 -1
- package/cpp/dawn/webgpu_cpp_print.h +202 -25
- package/cpp/dawn_logging.cpp +3 -6
- package/cpp/jsi/RNFHybridObject.cpp +2 -1
- package/cpp/jsi/RNFHybridObject.h +6 -0
- package/cpp/jsi/RNFJSIConverter.h +7 -2
- package/cpp/jsi/RNFPromise.cpp +2 -0
- package/cpp/jsi/RNFWorkletRuntimeRegistry.cpp +1 -0
- package/cpp/rnwgpu/SurfaceRegistry.h +1 -0
- package/cpp/rnwgpu/api/GPU.cpp +5 -1
- package/cpp/rnwgpu/api/GPU.h +7 -3
- package/cpp/rnwgpu/api/GPUAdapter.cpp +3 -0
- package/cpp/rnwgpu/api/GPUBindGroup.h +7 -0
- package/cpp/rnwgpu/api/GPUBindGroupLayout.h +7 -0
- package/cpp/rnwgpu/api/GPUBuffer.cpp +1 -0
- package/cpp/rnwgpu/api/GPUBuffer.h +2 -0
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +1 -0
- package/cpp/rnwgpu/api/GPUCanvasContext.h +1 -0
- package/cpp/rnwgpu/api/GPUCommandEncoder.cpp +2 -0
- package/cpp/rnwgpu/api/GPUComputePassEncoder.cpp +2 -0
- package/cpp/rnwgpu/api/GPUComputePipeline.cpp +1 -0
- package/cpp/rnwgpu/api/GPUComputePipeline.h +7 -0
- package/cpp/rnwgpu/api/GPUDevice.cpp +3 -0
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.cpp +1 -0
- package/cpp/rnwgpu/api/GPUQuerySet.h +21 -0
- package/cpp/rnwgpu/api/GPUQueue.cpp +10 -5
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.cpp +3 -0
- package/cpp/rnwgpu/api/GPURenderPassEncoder.cpp +5 -1
- package/cpp/rnwgpu/api/GPURenderPipeline.h +8 -0
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +1 -0
- package/cpp/rnwgpu/api/GPUShaderModule.h +8 -0
- package/cpp/rnwgpu/api/GPUTexture.h +76 -0
- package/cpp/rnwgpu/api/ImageBitmap.h +2 -0
- package/cpp/rnwgpu/api/descriptors/Unions.h +3 -2
- package/cpp/threading/Dispatcher.cpp +2 -1
- package/cpp/threading/ThreadPool.cpp +2 -0
- package/cpp/webgpu/webgpu.h +571 -261
- package/cpp/webgpu/webgpu_cpp.h +871 -313
- package/lib/commonjs/Canvas.js +3 -1
- package/lib/commonjs/Canvas.js.map +1 -1
- package/lib/module/Canvas.js +3 -1
- package/lib/module/Canvas.js.map +1 -1
- package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
- package/lib/typescript/src/__tests__/setup.d.ts +0 -1
- package/lib/typescript/src/__tests__/setup.d.ts.map +1 -1
- package/libs/android/arm64-v8a/libwebgpu_dawn.a +0 -0
- package/libs/android/arm64-v8a/libwebgpu_dawn.so +0 -0
- package/libs/android/armeabi-v7a/libwebgpu_dawn.a +0 -0
- package/libs/android/armeabi-v7a/libwebgpu_dawn.so +0 -0
- package/libs/android/x86/libwebgpu_dawn.a +0 -0
- package/libs/android/x86/libwebgpu_dawn.so +0 -0
- package/libs/android/x86_64/libwebgpu_dawn.a +0 -0
- package/libs/android/x86_64/libwebgpu_dawn.so +0 -0
- package/libs/apple/arm64_iphoneos/libwebgpu_dawn.a +0 -0
- package/libs/apple/arm64_iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/arm64_xros/libwebgpu_dawn.a +0 -0
- package/libs/apple/arm64_xrsimulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/Info.plist +10 -10
- package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/xros-arm64/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/xros-arm64-simulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/universal_macosx/libwebgpu_dawn.a +0 -0
- package/libs/apple/x86_64_iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/dawn.json +422 -206
- package/package.json +1 -1
- package/src/Canvas.tsx +1 -1
- package/src/__tests__/Constants.spec.ts +2 -4
- package/src/__tests__/Device.spec.ts +42 -24
- package/src/__tests__/GPU.spec.ts +115 -105
- package/src/__tests__/setup.ts +0 -1
|
@@ -44,6 +44,27 @@ public:
|
|
|
44
44
|
|
|
45
45
|
inline const wgpu::QuerySet get() { return _instance; }
|
|
46
46
|
|
|
47
|
+
size_t getMemoryPressure() override {
|
|
48
|
+
uint32_t count = getCount();
|
|
49
|
+
wgpu::QueryType type = getType();
|
|
50
|
+
|
|
51
|
+
// Estimate bytes per query based on type
|
|
52
|
+
size_t bytesPerQuery = 8; // Default estimate
|
|
53
|
+
switch (type) {
|
|
54
|
+
case wgpu::QueryType::Occlusion:
|
|
55
|
+
bytesPerQuery = 8; // 64-bit counter
|
|
56
|
+
break;
|
|
57
|
+
case wgpu::QueryType::Timestamp:
|
|
58
|
+
bytesPerQuery = 8; // 64-bit timestamp
|
|
59
|
+
break;
|
|
60
|
+
default:
|
|
61
|
+
bytesPerQuery = 8; // Safe default
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return static_cast<size_t>(count) * bytesPerQuery;
|
|
66
|
+
}
|
|
67
|
+
|
|
47
68
|
private:
|
|
48
69
|
wgpu::QuerySet _instance;
|
|
49
70
|
std::string _label;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#include "GPUQueue.h"
|
|
2
2
|
|
|
3
3
|
#include <limits>
|
|
4
|
+
#include <memory>
|
|
5
|
+
#include <vector>
|
|
4
6
|
|
|
5
7
|
#include "Convertors.h"
|
|
6
8
|
|
|
@@ -38,7 +40,8 @@ void GPUQueue::writeBuffer(std::shared_ptr<GPUBuffer> buffer,
|
|
|
38
40
|
|
|
39
41
|
// Note that in the JS semantics of WebGPU, writeBuffer works in number of
|
|
40
42
|
// elements of the typed arrays.
|
|
41
|
-
if (dataOffsetElements >
|
|
43
|
+
if (dataOffsetElements >
|
|
44
|
+
static_cast<uint64_t>(src.size / src.bytesPerElement)) {
|
|
42
45
|
throw std::runtime_error("dataOffset is larger than data's size.");
|
|
43
46
|
return;
|
|
44
47
|
}
|
|
@@ -49,7 +52,7 @@ void GPUQueue::writeBuffer(std::shared_ptr<GPUBuffer> buffer,
|
|
|
49
52
|
// Size defaults to dataSize - dataOffset. Instead of computing in elements,
|
|
50
53
|
// we directly use it in bytes, and convert the provided value, if any, in
|
|
51
54
|
// bytes.
|
|
52
|
-
uint64_t size64 = uint64_t(src.size);
|
|
55
|
+
uint64_t size64 = static_cast<uint64_t>(src.size);
|
|
53
56
|
if (sizeElements.has_value()) {
|
|
54
57
|
if (sizeElements.value() >
|
|
55
58
|
std::numeric_limits<uint64_t>::max() / src.bytesPerElement) {
|
|
@@ -59,7 +62,7 @@ void GPUQueue::writeBuffer(std::shared_ptr<GPUBuffer> buffer,
|
|
|
59
62
|
size64 = sizeElements.value() * src.bytesPerElement;
|
|
60
63
|
}
|
|
61
64
|
|
|
62
|
-
if (size64 > uint64_t(src.size)) {
|
|
65
|
+
if (size64 > static_cast<uint64_t>(src.size)) {
|
|
63
66
|
throw std::runtime_error("size + dataOffset is larger than data's size.");
|
|
64
67
|
return;
|
|
65
68
|
}
|
|
@@ -76,10 +79,12 @@ void GPUQueue::writeBuffer(std::shared_ptr<GPUBuffer> buffer,
|
|
|
76
79
|
}
|
|
77
80
|
|
|
78
81
|
std::future<void> GPUQueue::onSubmittedWorkDone() {
|
|
79
|
-
return _async->runAsync([
|
|
82
|
+
return _async->runAsync([&] {
|
|
80
83
|
return _instance.OnSubmittedWorkDone(
|
|
81
84
|
wgpu::CallbackMode::WaitAnyOnly,
|
|
82
|
-
[](wgpu::QueueWorkDoneStatus status) {
|
|
85
|
+
[](wgpu::QueueWorkDoneStatus status, wgpu::StringView message) {
|
|
86
|
+
// Handle the callback if needed
|
|
87
|
+
});
|
|
83
88
|
});
|
|
84
89
|
}
|
|
85
90
|
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
#include <memory>
|
|
2
|
+
#include <string>
|
|
3
|
+
#include <vector>
|
|
4
|
+
|
|
1
5
|
#include "GPURenderPassEncoder.h"
|
|
2
6
|
#include "Convertors.h"
|
|
3
7
|
|
|
@@ -158,4 +162,4 @@ void GPURenderPassEncoder::drawIndexedIndirect(
|
|
|
158
162
|
_instance.DrawIndexedIndirect(b, indirectOffset);
|
|
159
163
|
}
|
|
160
164
|
|
|
161
|
-
} // namespace rnwgpu
|
|
165
|
+
} // namespace rnwgpu
|
|
@@ -44,6 +44,14 @@ public:
|
|
|
44
44
|
|
|
45
45
|
inline const wgpu::RenderPipeline get() { return _instance; }
|
|
46
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
|
+
|
|
47
55
|
private:
|
|
48
56
|
wgpu::RenderPipeline _instance;
|
|
49
57
|
std::string _label;
|
|
@@ -48,6 +48,14 @@ public:
|
|
|
48
48
|
|
|
49
49
|
inline const wgpu::ShaderModule get() { return _instance; }
|
|
50
50
|
|
|
51
|
+
size_t getMemoryPressure() override {
|
|
52
|
+
// Estimate memory usage for compiled shader module
|
|
53
|
+
// Shaders can vary widely, but a reasonable estimate is 8-16KB for typical
|
|
54
|
+
// shaders Complex shaders (with many uniforms, textures, or computations)
|
|
55
|
+
// can be much larger
|
|
56
|
+
return 12 * 1024; // 12KB estimate for average shader
|
|
57
|
+
}
|
|
58
|
+
|
|
51
59
|
private:
|
|
52
60
|
wgpu::ShaderModule _instance;
|
|
53
61
|
std::shared_ptr<AsyncRunner> _async;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
+
#include <algorithm>
|
|
3
4
|
#include <memory>
|
|
4
5
|
#include <string>
|
|
5
6
|
|
|
@@ -64,6 +65,81 @@ public:
|
|
|
64
65
|
|
|
65
66
|
inline const wgpu::Texture get() { return _instance; }
|
|
66
67
|
|
|
68
|
+
size_t getMemoryPressure() override {
|
|
69
|
+
// Calculate approximate memory usage based on texture properties
|
|
70
|
+
uint32_t width = getWidth();
|
|
71
|
+
uint32_t height = getHeight();
|
|
72
|
+
uint32_t depthOrArrayLayers = getDepthOrArrayLayers();
|
|
73
|
+
uint32_t mipLevelCount = getMipLevelCount();
|
|
74
|
+
uint32_t sampleCount = getSampleCount();
|
|
75
|
+
|
|
76
|
+
// Estimate bytes per pixel based on format
|
|
77
|
+
// This is a simplified estimate - actual values depend on the specific
|
|
78
|
+
// format
|
|
79
|
+
size_t bytesPerPixel = 4; // Default to RGBA8 format
|
|
80
|
+
wgpu::TextureFormat format = getFormat();
|
|
81
|
+
switch (format) {
|
|
82
|
+
case wgpu::TextureFormat::R8Unorm:
|
|
83
|
+
case wgpu::TextureFormat::R8Snorm:
|
|
84
|
+
case wgpu::TextureFormat::R8Uint:
|
|
85
|
+
case wgpu::TextureFormat::R8Sint:
|
|
86
|
+
bytesPerPixel = 1;
|
|
87
|
+
break;
|
|
88
|
+
case wgpu::TextureFormat::R16Uint:
|
|
89
|
+
case wgpu::TextureFormat::R16Sint:
|
|
90
|
+
case wgpu::TextureFormat::R16Float:
|
|
91
|
+
case wgpu::TextureFormat::RG8Unorm:
|
|
92
|
+
case wgpu::TextureFormat::RG8Snorm:
|
|
93
|
+
case wgpu::TextureFormat::RG8Uint:
|
|
94
|
+
case wgpu::TextureFormat::RG8Sint:
|
|
95
|
+
bytesPerPixel = 2;
|
|
96
|
+
break;
|
|
97
|
+
case wgpu::TextureFormat::RGBA8Unorm:
|
|
98
|
+
case wgpu::TextureFormat::RGBA8UnormSrgb:
|
|
99
|
+
case wgpu::TextureFormat::RGBA8Snorm:
|
|
100
|
+
case wgpu::TextureFormat::RGBA8Uint:
|
|
101
|
+
case wgpu::TextureFormat::RGBA8Sint:
|
|
102
|
+
case wgpu::TextureFormat::BGRA8Unorm:
|
|
103
|
+
case wgpu::TextureFormat::BGRA8UnormSrgb:
|
|
104
|
+
case wgpu::TextureFormat::RGB10A2Unorm:
|
|
105
|
+
case wgpu::TextureFormat::R32Float:
|
|
106
|
+
case wgpu::TextureFormat::R32Uint:
|
|
107
|
+
case wgpu::TextureFormat::R32Sint:
|
|
108
|
+
case wgpu::TextureFormat::RG16Uint:
|
|
109
|
+
case wgpu::TextureFormat::RG16Sint:
|
|
110
|
+
case wgpu::TextureFormat::RG16Float:
|
|
111
|
+
bytesPerPixel = 4;
|
|
112
|
+
break;
|
|
113
|
+
case wgpu::TextureFormat::RG32Float:
|
|
114
|
+
case wgpu::TextureFormat::RG32Uint:
|
|
115
|
+
case wgpu::TextureFormat::RG32Sint:
|
|
116
|
+
case wgpu::TextureFormat::RGBA16Uint:
|
|
117
|
+
case wgpu::TextureFormat::RGBA16Sint:
|
|
118
|
+
case wgpu::TextureFormat::RGBA16Float:
|
|
119
|
+
bytesPerPixel = 8;
|
|
120
|
+
break;
|
|
121
|
+
case wgpu::TextureFormat::RGBA32Float:
|
|
122
|
+
case wgpu::TextureFormat::RGBA32Uint:
|
|
123
|
+
case wgpu::TextureFormat::RGBA32Sint:
|
|
124
|
+
bytesPerPixel = 16;
|
|
125
|
+
break;
|
|
126
|
+
default:
|
|
127
|
+
bytesPerPixel = 4; // Safe default
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Calculate total memory for all mip levels
|
|
132
|
+
size_t totalMemory = 0;
|
|
133
|
+
for (uint32_t mip = 0; mip < mipLevelCount; ++mip) {
|
|
134
|
+
uint32_t mipWidth = std::max(1u, width >> mip);
|
|
135
|
+
uint32_t mipHeight = std::max(1u, height >> mip);
|
|
136
|
+
totalMemory += static_cast<size_t>(mipWidth) * mipHeight *
|
|
137
|
+
depthOrArrayLayers * bytesPerPixel * sampleCount;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return totalMemory;
|
|
141
|
+
}
|
|
142
|
+
|
|
67
143
|
private:
|
|
68
144
|
wgpu::Texture _instance;
|
|
69
145
|
std::string _label;
|
|
@@ -441,7 +441,8 @@ static void convertJSUnionToEnum(const std::string &inUnion,
|
|
|
441
441
|
} else if (inUnion == "dawn-native") {
|
|
442
442
|
*outEnum = wgpu::FeatureName::DawnNative;
|
|
443
443
|
} else if (inUnion == "chromium-experimental-timestamp-query-inside-passes") {
|
|
444
|
-
*outEnum =
|
|
444
|
+
*outEnum =
|
|
445
|
+
wgpu::FeatureName::ChromiumExperimentalTimestampQueryInsidePasses;
|
|
445
446
|
} else if (inUnion == "implicit-device-synchronization") {
|
|
446
447
|
*outEnum = wgpu::FeatureName::ImplicitDeviceSynchronization;
|
|
447
448
|
} else if (inUnion == "transient-attachments") {
|
|
@@ -613,7 +614,7 @@ static void convertEnumToJSUnion(wgpu::FeatureName inEnum,
|
|
|
613
614
|
case wgpu::FeatureName::ANGLETextureSharing:
|
|
614
615
|
*outUnion = "angle-texture-sharing";
|
|
615
616
|
break;
|
|
616
|
-
|
|
617
|
+
case wgpu::FeatureName::ChromiumExperimentalSubgroupMatrix:
|
|
617
618
|
*outUnion = "chromium-experimental-subgroups-matrix";
|
|
618
619
|
break;
|
|
619
620
|
case wgpu::FeatureName::PixelLocalStorageCoherent:
|