Skip to content

Commit

Permalink
Merge pull request #8 from pynbody/multivis-fix
Browse files Browse the repository at this point in the history
Only create one device across all visualizers
  • Loading branch information
apontzen authored Dec 4, 2023
2 parents aec4546 + 2342104 commit c69e08e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/topsy/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
class VisualizerBase:
colorbar_aspect_ratio = config.COLORBAR_ASPECT_RATIO
show_status = True
device = None # device will be shared across all instances

def __init__(self, data_loader_class = loader.TestDataLoader, data_loader_args = (),
*, render_resolution = config.DEFAULT_RESOLUTION, periodic_tiling = False,
Expand Down Expand Up @@ -77,8 +78,9 @@ def __init__(self, data_loader_class = loader.TestDataLoader, data_loader_args =

def _setup_wgpu(self):
self.adapter: wgpu.GPUAdapter = wgpu.gpu.request_adapter(power_preference="high-performance")
self.device: wgpu.GPUDevice = self.adapter.request_device(
required_features=["TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES"])
if self.device is None:
type(self).device: wgpu.GPUDevice = self.adapter.request_device(
required_features=["TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES"])
self.context: wgpu.GPUCanvasContext = self.canvas.get_context()
self.canvas_format = self.context.get_preferred_format(self.adapter)
if self.canvas_format.endswith("-srgb"):
Expand Down
7 changes: 6 additions & 1 deletion tests/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,9 @@ def test_rotated_sph_output():
result = vis.get_presentation_image()
plt.imsave(folder / "test_rotated.png", result) # needs manual verification
finally:
vis.rotation_matrix = np.eye(3, dtype=np.float32)
vis.rotation_matrix = np.eye(3, dtype=np.float32)


def test_second_renderer():
# tests that creating a second renderer works OK
vis2 = topsy._test(2000, render_resolution=200, canvas_class=offscreen.VisualizerCanvas)

0 comments on commit c69e08e

Please sign in to comment.