From 74c0fdd982432a194d5699a52195dddf2baaefbb Mon Sep 17 00:00:00 2001 From: Andrew Pontzen Date: Fri, 1 Dec 2023 19:33:03 +0000 Subject: [PATCH] Fixes for wgpu v0.13.0 --- pyproject.toml | 2 +- src/topsy/__init__.py | 2 +- src/topsy/colormap.py | 1 - src/topsy/visualizer.py | 19 ++++++++++--------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 210f60d..a0c1cd3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,7 @@ dependencies = [ "pynbody >=1.3.0", "matplotlib >=3.6.0", "pillow >=9.5.0", # 9.5.0 needed for Image.frombytes accepting memoryview - "wgpu >= 0.9.4", + "wgpu == 0.13.0", "jupyter_rfb >=0.4.1", "tqdm >=4.62.0", "opencv-python >=4.8.0", diff --git a/src/topsy/__init__.py b/src/topsy/__init__.py index d3bf94c..52ca033 100644 --- a/src/topsy/__init__.py +++ b/src/topsy/__init__.py @@ -2,7 +2,7 @@ from __future__ import annotations -__version__ = "0.3.2" +__version__ = "0.3.3" import argparse import logging diff --git a/src/topsy/colormap.py b/src/topsy/colormap.py index 8fa7870..34d11d9 100644 --- a/src/topsy/colormap.py +++ b/src/topsy/colormap.py @@ -259,7 +259,6 @@ def _update_parameter_buffer(self, width, height): parameters["vmin"] = self.vmin parameters["vmax"] = self.vmax - self._visualizer.context.get_current_texture() parameters["window_aspect_ratio"] = float(width)/height self._device.queue.write_buffer(self._parameter_buffer, 0, parameters) \ No newline at end of file diff --git a/src/topsy/visualizer.py b/src/topsy/visualizer.py index 31bf372..04f411d 100644 --- a/src/topsy/visualizer.py +++ b/src/topsy/visualizer.py @@ -4,7 +4,6 @@ import numpy as np import time import wgpu -import wgpu.backends.rs # noqa: F401, Select Rust backend from contextlib import contextmanager @@ -77,8 +76,7 @@ def __init__(self, data_loader_class = loader.TestDataLoader, data_loader_args = self.invalidate(DrawReason.INITIAL_UPDATE) def _setup_wgpu(self): - self.adapter: wgpu.GPUAdapter = wgpu.request_adapter(canvas=self.canvas, - power_preference="high-performance") + 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"]) self.context: wgpu.GPUCanvasContext = self.canvas.get_context() @@ -215,8 +213,7 @@ def prevent_sph_rendering(self): self._prevent_sph_rendering = False def draw(self, reason, target_texture_view=None): - if target_texture_view is None: - target_texture_view = self.context.get_current_texture() # weirdly returns a view, not a texture + if reason == DrawReason.REFINE or reason == DrawReason.EXPORT: self._sph.downsample_factor = 1 @@ -241,8 +238,12 @@ def draw(self, reason, target_texture_view=None): self.vmin_vmax_is_set = True self._refresh_colorbar() + command_encoder = self.device.create_command_encoder() + + if target_texture_view is None: + target_texture_view = self.canvas.get_context().get_current_texture().create_view() + - command_encoder = self.device.create_command_encoder(label="render_to_screen") self._colormap.encode_render_pass(command_encoder, target_texture_view) if self.show_colorbar: self._colorbar.encode_render_pass(command_encoder, target_texture_view) @@ -362,12 +363,12 @@ def get_sph_image(self) -> np.ndarray: return im def get_presentation_image(self) -> np.ndarray: - texture_view = self.context.get_current_texture() - size = texture_view.size + texture = self.context.get_current_texture() + size = texture.size bytes_per_pixel = 4 # NB this might be wrong in principle! data = self.device.queue.read_texture( { - "texture": texture_view.texture, + "texture": texture, "mip_level": 0, "origin": (0, 0, 0), },