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.
Files changed (85) hide show
  1. package/android/CMakeLists.txt +1 -1
  2. package/android/build.gradle +2 -1
  3. package/android/src/main/java/com/webgpu/WebGPUAHBView.java +247 -45
  4. package/android/src/main/java/com/webgpu/WebGPUView.java +4 -4
  5. package/apple/ApplePlatformContext.h +1 -0
  6. package/apple/RNWGUIKit.h +5 -0
  7. package/apple/platform/ThreadUtils.cpp +1 -0
  8. package/cpp/WGPULogger.h +1 -0
  9. package/cpp/dawn/dawn_proc_table.h +31 -10
  10. package/cpp/dawn/native/D3D11Backend.h +8 -2
  11. package/cpp/dawn/native/D3DBackend.h +0 -3
  12. package/cpp/dawn/native/DawnNative.h +4 -0
  13. package/cpp/dawn/platform/DawnPlatform.h +2 -1
  14. package/cpp/dawn/webgpu_cpp_print.h +202 -25
  15. package/cpp/dawn_logging.cpp +3 -6
  16. package/cpp/jsi/RNFHybridObject.cpp +2 -1
  17. package/cpp/jsi/RNFHybridObject.h +6 -0
  18. package/cpp/jsi/RNFJSIConverter.h +7 -2
  19. package/cpp/jsi/RNFPromise.cpp +2 -0
  20. package/cpp/jsi/RNFWorkletRuntimeRegistry.cpp +1 -0
  21. package/cpp/rnwgpu/SurfaceRegistry.h +1 -0
  22. package/cpp/rnwgpu/api/GPU.cpp +5 -1
  23. package/cpp/rnwgpu/api/GPU.h +7 -3
  24. package/cpp/rnwgpu/api/GPUAdapter.cpp +3 -0
  25. package/cpp/rnwgpu/api/GPUBindGroup.h +7 -0
  26. package/cpp/rnwgpu/api/GPUBindGroupLayout.h +7 -0
  27. package/cpp/rnwgpu/api/GPUBuffer.cpp +1 -0
  28. package/cpp/rnwgpu/api/GPUBuffer.h +2 -0
  29. package/cpp/rnwgpu/api/GPUCanvasContext.cpp +1 -0
  30. package/cpp/rnwgpu/api/GPUCanvasContext.h +1 -0
  31. package/cpp/rnwgpu/api/GPUCommandEncoder.cpp +2 -0
  32. package/cpp/rnwgpu/api/GPUComputePassEncoder.cpp +2 -0
  33. package/cpp/rnwgpu/api/GPUComputePipeline.cpp +1 -0
  34. package/cpp/rnwgpu/api/GPUComputePipeline.h +7 -0
  35. package/cpp/rnwgpu/api/GPUDevice.cpp +3 -0
  36. package/cpp/rnwgpu/api/GPUDeviceLostInfo.cpp +1 -0
  37. package/cpp/rnwgpu/api/GPUQuerySet.h +21 -0
  38. package/cpp/rnwgpu/api/GPUQueue.cpp +10 -5
  39. package/cpp/rnwgpu/api/GPURenderBundleEncoder.cpp +3 -0
  40. package/cpp/rnwgpu/api/GPURenderPassEncoder.cpp +5 -1
  41. package/cpp/rnwgpu/api/GPURenderPipeline.h +8 -0
  42. package/cpp/rnwgpu/api/GPUShaderModule.cpp +1 -0
  43. package/cpp/rnwgpu/api/GPUShaderModule.h +8 -0
  44. package/cpp/rnwgpu/api/GPUTexture.h +76 -0
  45. package/cpp/rnwgpu/api/ImageBitmap.h +2 -0
  46. package/cpp/rnwgpu/api/descriptors/Unions.h +3 -2
  47. package/cpp/threading/Dispatcher.cpp +2 -1
  48. package/cpp/threading/ThreadPool.cpp +2 -0
  49. package/cpp/webgpu/webgpu.h +571 -261
  50. package/cpp/webgpu/webgpu_cpp.h +871 -313
  51. package/lib/commonjs/Canvas.js +3 -1
  52. package/lib/commonjs/Canvas.js.map +1 -1
  53. package/lib/module/Canvas.js +3 -1
  54. package/lib/module/Canvas.js.map +1 -1
  55. package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
  56. package/lib/typescript/src/__tests__/setup.d.ts +0 -1
  57. package/lib/typescript/src/__tests__/setup.d.ts.map +1 -1
  58. package/libs/android/arm64-v8a/libwebgpu_dawn.a +0 -0
  59. package/libs/android/arm64-v8a/libwebgpu_dawn.so +0 -0
  60. package/libs/android/armeabi-v7a/libwebgpu_dawn.a +0 -0
  61. package/libs/android/armeabi-v7a/libwebgpu_dawn.so +0 -0
  62. package/libs/android/x86/libwebgpu_dawn.a +0 -0
  63. package/libs/android/x86/libwebgpu_dawn.so +0 -0
  64. package/libs/android/x86_64/libwebgpu_dawn.a +0 -0
  65. package/libs/android/x86_64/libwebgpu_dawn.so +0 -0
  66. package/libs/apple/arm64_iphoneos/libwebgpu_dawn.a +0 -0
  67. package/libs/apple/arm64_iphonesimulator/libwebgpu_dawn.a +0 -0
  68. package/libs/apple/arm64_xros/libwebgpu_dawn.a +0 -0
  69. package/libs/apple/arm64_xrsimulator/libwebgpu_dawn.a +0 -0
  70. package/libs/apple/iphonesimulator/libwebgpu_dawn.a +0 -0
  71. package/libs/apple/libwebgpu_dawn.xcframework/Info.plist +10 -10
  72. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/libwebgpu_dawn.a +0 -0
  73. package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -0
  74. package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/libwebgpu_dawn.a +0 -0
  75. package/libs/apple/libwebgpu_dawn.xcframework/xros-arm64/libwebgpu_dawn.a +0 -0
  76. package/libs/apple/libwebgpu_dawn.xcframework/xros-arm64-simulator/libwebgpu_dawn.a +0 -0
  77. package/libs/apple/universal_macosx/libwebgpu_dawn.a +0 -0
  78. package/libs/apple/x86_64_iphonesimulator/libwebgpu_dawn.a +0 -0
  79. package/libs/dawn.json +422 -206
  80. package/package.json +1 -1
  81. package/src/Canvas.tsx +1 -1
  82. package/src/__tests__/Constants.spec.ts +2 -4
  83. package/src/__tests__/Device.spec.ts +42 -24
  84. package/src/__tests__/GPU.spec.ts +115 -105
  85. 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 > uint64_t(src.size / src.bytesPerElement)) {
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,5 +1,8 @@
1
1
  #include "GPURenderBundleEncoder.h"
2
2
 
3
+ #include <memory>
4
+ #include <string>
5
+
3
6
  #include "Convertors.h"
4
7
 
5
8
  namespace rnwgpu {
@@ -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;
@@ -1,5 +1,6 @@
1
1
  #include "GPUShaderModule.h"
2
2
 
3
+ #include <memory>
3
4
  #include <utility>
4
5
 
5
6
  namespace rnwgpu {
@@ -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;
@@ -27,6 +27,8 @@ public:
27
27
  registerHybridGetter("height", &ImageBitmap::getHeight, this);
28
28
  }
29
29
 
30
+ size_t getMemoryPressure() override { return getSize(); }
31
+
30
32
  private:
31
33
  ImageData _imageData;
32
34
  };
@@ -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 = wgpu::FeatureName::ChromiumExperimentalTimestampQueryInsidePasses;
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
- case wgpu::FeatureName::ChromiumExperimentalSubgroupMatrix:
617
+ case wgpu::FeatureName::ChromiumExperimentalSubgroupMatrix:
617
618
  *outUnion = "chromium-experimental-subgroups-matrix";
618
619
  break;
619
620
  case wgpu::FeatureName::PixelLocalStorageCoherent:
@@ -1,10 +1,11 @@
1
1
  //
2
2
  // Created by Marc Rousavy on 12.03.24.
3
3
  //
4
+ #include <memory>
5
+ #include <unordered_map>
4
6
 
5
7
  #include "Dispatcher.h"
6
8
 
7
- #include <memory>
8
9
  #include "RNFJSIHelper.h"
9
10
 
10
11
  namespace margelo {
@@ -10,6 +10,8 @@
10
10
 
11
11
  #include <utility>
12
12
  #include <algorithm>
13
+ #include <string>
14
+ #include <memory>
13
15
 
14
16
  namespace margelo {
15
17