Skip to content
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

[EXPERIMENTAL] Improve rendering time by rewriting STD140BufferFormat._write_padded() #4058

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions manim/renderer/buffers/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(
self.name = name
self.binding = binding
self.dtype = []
self._paddings = {} # LUT for future writes
self._paddings: dict[str, int] = {} # LUT for future writes
byte_offset = 0 # Track the offset so we can calculate padding for alignment -- NOTE: use RenderDoc to debug
for data_type, var_name in struct:
_base_char, base_bytesize, shape = self._GL_DTYPES[data_type]
Expand Down Expand Up @@ -97,11 +97,16 @@ def _write_padded(self, data: tuple | np.ndarray, var: str) -> np.ndarray:
np.ndarray
the same data with 0 or 1 columns of 0s appended
"""
try:
# This fails for 1D data (python or np.array)
return np.pad(data, ((0, 0), (0, self._paddings[var])), mode="constant")
except Exception:
return np.pad(data, ((0, self._paddings[var])), mode="constant")
data = np.asarray(data)
if self._paddings[var] == 0 or data.ndim == 0:
return data

# Make a new array with extra columns of 0s
new_shape = list(data.shape)
new_shape[-1] += self._paddings[var]
padded_data = np.zeros(new_shape)
padded_data[..., : data.shape[-1]] = data
return padded_data

def write(self, data: dict) -> None:
"""Write a dictionary of key value pairs to the STD140BufferFormat's data attribute
Expand Down
Loading