Skip to content

Commit f1ca282

Browse files
authored
fix(šŸ›): avoid spurious Hermes GC cycles from canvas texture memory pressure (#341)
1 parent bfbe325 commit f1ca282

4 files changed

Lines changed: 21 additions & 7 deletions

File tree

ā€Žapps/example/ios/Podfile.lockā€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,7 +1865,7 @@ PODS:
18651865
- ReactCommon/turbomodule/core
18661866
- SocketRocket
18671867
- Yoga
1868-
- react-native-wgpu (0.5.8):
1868+
- react-native-wgpu (0.5.10):
18691869
- boost
18701870
- DoubleConversion
18711871
- fast_float
@@ -2937,8 +2937,8 @@ SPEC CHECKSUMS:
29372937
React-Mapbuffer: 9d2434a42701d6144ca18f0ca1c4507808ca7696
29382938
React-microtasksnativemodule: 75b6604b667d297292345302cc5bfb6b6aeccc1b
29392939
react-native-safe-area-context: c00143b4823773bba23f2f19f85663ae89ceb460
2940-
react-native-skia: 3dab14f6a3de3c479a73d87cb1f9aa9556dcec13
2941-
react-native-wgpu: 32f373d5a9ee83fad1cdddd288bb0738cb97e0ba
2940+
react-native-skia: 888a5bf5ed5008ae9593990e7dc2ea022b9aea11
2941+
react-native-wgpu: 1ec8f2457ce741ac80bf5bf7b33e13c3c76c7b2a
29422942
React-NativeModulesApple: 879fbdc5dcff7136abceb7880fe8a2022a1bd7c3
29432943
React-oscompat: 93b5535ea7f7dff46aaee4f78309a70979bdde9d
29442944
React-perflogger: 5536d2df3d18fe0920263466f7b46a56351c0510

ā€Žpackages/webgpu/cpp/rnwgpu/api/GPUCanvasContext.cppā€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ std::shared_ptr<GPUTexture> GPUCanvasContext::getCurrentTexture() {
4848
_surfaceInfo->reconfigure(width, height);
4949
}
5050
auto texture = _surfaceInfo->getCurrentTexture();
51-
return std::make_shared<GPUTexture>(texture, "");
51+
// Pass reportsMemoryPressure=false to avoid triggering spurious Hermes GC
52+
// cycles every frame since the canvas texture doesn't own the buffer.
53+
return std::make_shared<GPUTexture>(texture, "", false);
5254
}
5355

5456
void GPUCanvasContext::present() {

ā€Žpackages/webgpu/cpp/rnwgpu/api/GPUTexture.hā€Ž

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ class GPUTexture : public NativeObject<GPUTexture> {
2121
public:
2222
static constexpr const char *CLASS_NAME = "GPUTexture";
2323

24-
explicit GPUTexture(wgpu::Texture instance, std::string label)
25-
: NativeObject(CLASS_NAME), _instance(instance), _label(label) {}
24+
explicit GPUTexture(wgpu::Texture instance, std::string label,
25+
bool reportsMemoryPressure = true)
26+
: NativeObject(CLASS_NAME), _instance(instance), _label(label),
27+
_reportsMemoryPressure(reportsMemoryPressure) {}
2628

2729
public:
2830
std::string getBrand() { return CLASS_NAME; }
@@ -68,6 +70,9 @@ class GPUTexture : public NativeObject<GPUTexture> {
6870
inline const wgpu::Texture get() { return _instance; }
6971

7072
size_t getMemoryPressure() override {
73+
if (!_reportsMemoryPressure) {
74+
return sizeof(GPUTexture);
75+
}
7176
// Calculate approximate memory usage based on texture properties
7277
uint32_t width = getWidth();
7378
uint32_t height = getHeight();
@@ -85,6 +90,7 @@ class GPUTexture : public NativeObject<GPUTexture> {
8590
case wgpu::TextureFormat::R8Snorm:
8691
case wgpu::TextureFormat::R8Uint:
8792
case wgpu::TextureFormat::R8Sint:
93+
case wgpu::TextureFormat::Stencil8:
8894
bytesPerPixel = 1;
8995
break;
9096
case wgpu::TextureFormat::R16Uint:
@@ -94,6 +100,7 @@ class GPUTexture : public NativeObject<GPUTexture> {
94100
case wgpu::TextureFormat::RG8Snorm:
95101
case wgpu::TextureFormat::RG8Uint:
96102
case wgpu::TextureFormat::RG8Sint:
103+
case wgpu::TextureFormat::Depth16Unorm:
97104
bytesPerPixel = 2;
98105
break;
99106
case wgpu::TextureFormat::RGBA8Unorm:
@@ -110,6 +117,9 @@ class GPUTexture : public NativeObject<GPUTexture> {
110117
case wgpu::TextureFormat::RG16Uint:
111118
case wgpu::TextureFormat::RG16Sint:
112119
case wgpu::TextureFormat::RG16Float:
120+
case wgpu::TextureFormat::Depth24Plus:
121+
case wgpu::TextureFormat::Depth24PlusStencil8:
122+
case wgpu::TextureFormat::Depth32Float:
113123
bytesPerPixel = 4;
114124
break;
115125
case wgpu::TextureFormat::RG32Float:
@@ -118,6 +128,7 @@ class GPUTexture : public NativeObject<GPUTexture> {
118128
case wgpu::TextureFormat::RGBA16Uint:
119129
case wgpu::TextureFormat::RGBA16Sint:
120130
case wgpu::TextureFormat::RGBA16Float:
131+
case wgpu::TextureFormat::Depth32FloatStencil8:
121132
bytesPerPixel = 8;
122133
break;
123134
case wgpu::TextureFormat::RGBA32Float:
@@ -145,6 +156,7 @@ class GPUTexture : public NativeObject<GPUTexture> {
145156
private:
146157
wgpu::Texture _instance;
147158
std::string _label;
159+
bool _reportsMemoryPressure = true;
148160
};
149161

150162
} // namespace rnwgpu

ā€Žpackages/webgpu/package.jsonā€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-wgpu",
3-
"version": "0.5.9",
3+
"version": "0.5.10",
44
"description": "React Native WebGPU",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

0 commit comments

Comments
Ā (0)