Skip to content

Use singleton for WebGPU instance #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

wcandillon
Copy link
Owner

the idea is to be use that the same instance is always used even in case of hot reload and so on

@wcandillon wcandillon requested a review from Copilot June 25, 2025 20:29
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the GPU initialization to use a singleton pattern, ensuring that the same GPU instance is re-used even during hot reloads. Key changes include moving the GPU constructor to private, introducing a static getInstance() function, and updating consumers (e.g., RNWebGPUManager) to use the singleton instance.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/webgpu/cpp/rnwgpu/api/descriptors/Unions.h Minor formatting update for readability.
packages/webgpu/cpp/rnwgpu/api/GPU.h Refactored GPU class to implement singleton pattern.
packages/webgpu/cpp/rnwgpu/api/GPU.cpp Added static member definitions for the singleton pattern.
packages/webgpu/cpp/rnwgpu/RNWebGPUManager.cpp Updated usage to fetch the singleton GPU instance.
externals/dawn Updated subproject commit.
Comments suppressed due to low confidence (1)

packages/webgpu/cpp/rnwgpu/api/GPU.h:76

  • The name '_instance' is used both for the static singleton pointer and for the member variable of type wgpu::Instance (line 80), which may lead to confusion. Consider renaming the member variable (e.g., to 'gpuInstance') to improve clarity.
  static std::shared_ptr<GPU> _instance;

@wcandillon wcandillon self-assigned this Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant