Skip to content

Commit

Permalink
Merge pull request #7 from pynbody/wgpu-0.13.0
Browse files Browse the repository at this point in the history
Fixes for wgpu v0.13.0
  • Loading branch information
apontzen authored Dec 1, 2023
2 parents 4a86031 + 74c0fdd commit aec4546
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/topsy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

__version__ = "0.3.2"
__version__ = "0.3.3"

import argparse
import logging
Expand Down
1 change: 0 additions & 1 deletion src/topsy/colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
19 changes: 10 additions & 9 deletions src/topsy/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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),
},
Expand Down

0 comments on commit aec4546

Please sign in to comment.