Skip to content

Commit 7a0f1ca

Browse files
committed
do not upload gpu data in each frame (cfrenderer)
1 parent 15922c6 commit 7a0f1ca

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

ngsolve_webgpu/cf.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from webgpu.colormap import Colormap
1010
from webgpu.renderer import Renderer, RenderOptions, check_timestamp
1111
from webgpu.shapes import ShapeRenderer, generate_cylinder
12-
from webgpu.utils import BufferBinding, UniformBinding, buffer_from_array, write_array_to_buffer, read_shader_file
12+
from webgpu.utils import BufferBinding, UniformBinding, buffer_from_array, write_array_to_buffer, read_shader_file, device_generation
1313
from webgpu.renderer import BaseRenderer, RenderOptions, check_timestamp
1414
from webgpu.uniforms import UniformBase, ct
1515
from webgpu.utils import (
@@ -212,6 +212,7 @@ class FunctionData:
212212
order_3d: int
213213
_timestamp: float = -1
214214
_gpu_dirty: bool = True
215+
_gpu_generation: int = -1
215216
minval: list[float]
216217
maxval: list[float]
217218

@@ -336,21 +337,24 @@ def get_buffers(self, include_mesh_data=True):
336337
buffers = self.mesh_data.get_buffers().copy()
337338
else:
338339
buffers = {}
340+
gen = device_generation()
341+
stale = self._gpu_generation != gen
339342
if self.data_2d is not None:
340-
if self._gpu_dirty or self.gpu_2d is None:
343+
if self._gpu_dirty or stale or self.gpu_2d is None:
341344
self.gpu_2d = buffer_from_array(
342345
self.data_2d, label="function_data_2d", reuse=self.gpu_2d
343346
)
344347
buffers["data_2d"] = self.gpu_2d
345348

346349
if self.data_3d is not None:
347-
if self._gpu_dirty or self.gpu_3d is None:
350+
if self._gpu_dirty or stale or self.gpu_3d is None:
348351
self.gpu_3d = buffer_from_array(
349352
self.data_3d, label="function_data_3d", reuse=self.gpu_3d
350353
)
351354
buffers["data_3d"] = self.gpu_3d
352355

353356
self._gpu_dirty = False
357+
self._gpu_generation = gen
354358

355359
return buffers
356360

ngsolve_webgpu/mesh.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
BufferBinding,
2222
UniformBinding,
2323
buffer_from_array,
24+
device_generation,
2425
get_device,
2526
read_shader_file,
2627
uniform_from_array,
@@ -130,6 +131,7 @@ class MeshData:
130131
_need_3d: bool = False
131132
_update_lock: Lock
132133
_gpu_dirty: bool = True
134+
_gpu_generation: int = -1
133135

134136
def __init__(self, mesh, el2d_bitarray=None, el3d_bitarray=None):
135137
import netgen.meshing
@@ -592,6 +594,12 @@ def get_bounding_box(self):
592594
return ([pmin[0], pmin[1], pmin[2]], [pmax[0], pmax[1], pmax[2]])
593595

594596
def get_buffers(self):
597+
gen = device_generation()
598+
if self._gpu_generation != gen:
599+
self._gpu_dirty = True
600+
self.gpu_elements = {}
601+
self._dummy_buffer = None
602+
self._gpu_generation = gen
595603

596604
if self._gpu_dirty:
597605
self.gpu_data = buffer_from_array(

0 commit comments

Comments
 (0)