From 9890f380fa6b20f695c535eee93222050486dad4 Mon Sep 17 00:00:00 2001 From: Simon Kallweit <64953474+skallweitNV@users.noreply.github.com> Date: Fri, 20 Dec 2024 11:20:56 +0100 Subject: [PATCH] use size/offset to specify buffer cursor data section (#144) * use size/offset to specify buffer cursor data section * ignore typing issues --- examples/pathtracer/pathtracer.py | 4 +++- src/sgl/core/tests/test_bitmap.py | 2 +- src/sgl/core/tests/test_struct.py | 4 ++-- src/sgl/device/buffer_cursor.cpp | 11 +++-------- src/sgl/device/buffer_cursor.h | 7 +------ src/sgl/device/python/buffer_cursor.cpp | 4 ++-- src/sgl/device/tests/test_declrefs.py | 2 +- src/sgl/device/tests/test_shader_cursor.py | 2 +- src/sgl/utils/tests/test_texture_loader.py | 2 +- 9 files changed, 15 insertions(+), 23 deletions(-) diff --git a/examples/pathtracer/pathtracer.py b/examples/pathtracer/pathtracer.py index 301a18a9..2b7853b4 100644 --- a/examples/pathtracer/pathtracer.py +++ b/examples/pathtracer/pathtracer.py @@ -140,7 +140,9 @@ def __init__(self, base_color: "sgl.float3param" = sgl.float3(0.5)): class Mesh: def __init__( - self, vertices: npt.NDArray[np.float32], indices: npt.NDArray[np.uint32] + self, + vertices: npt.NDArray[np.float32], # type: ignore + indices: npt.NDArray[np.uint32], # type: ignore ): super().__init__() assert vertices.ndim == 2 and vertices.dtype == np.float32 diff --git a/src/sgl/core/tests/test_bitmap.py b/src/sgl/core/tests/test_bitmap.py index 16d810e4..defe20bd 100644 --- a/src/sgl/core/tests/test_bitmap.py +++ b/src/sgl/core/tests/test_bitmap.py @@ -34,7 +34,7 @@ def create_test_array( width: int, height: int, channels: int, - dtype: npt.DTypeLike, + dtype: npt.DTypeLike, # type: ignore type_range: tuple[float, float], ): img = np.zeros((height, width, channels), dtype) diff --git a/src/sgl/core/tests/test_struct.py b/src/sgl/core/tests/test_struct.py index 84c1212a..68b241e4 100644 --- a/src/sgl/core/tests/test_struct.py +++ b/src/sgl/core/tests/test_struct.py @@ -44,8 +44,8 @@ def check_conversion( converter: StructConverter, src_fmt: str | bytes, dst_fmt: str | bytes, - src_values: npt.ArrayLike, - ref_values: Optional[npt.ArrayLike] = None, + src_values: npt.ArrayLike, # type: ignore + ref_values: Optional[npt.ArrayLike] = None, # type: ignore err_thresh: float = 1e-6, ): # print("\nsrc_values: " + str(src_values)) diff --git a/src/sgl/device/buffer_cursor.cpp b/src/sgl/device/buffer_cursor.cpp index 9455cb1c..6961025e 100644 --- a/src/sgl/device/buffer_cursor.cpp +++ b/src/sgl/device/buffer_cursor.cpp @@ -411,17 +411,12 @@ BufferCursor::BufferCursor(ref element_layout, ref m_owner = true; } -BufferCursor::BufferCursor( - ref element_layout, - ref resource, - size_t element_count, - size_t first_element -) +BufferCursor::BufferCursor(ref element_layout, ref resource, size_t size, size_t offset) : m_element_type_layout(std::move(element_layout)) { m_resource = std::move(resource); - m_size = m_element_type_layout->stride() * element_count; - m_offset = m_element_type_layout->stride() * first_element; + m_size = size; + m_offset = offset; m_buffer = nullptr; m_owner = true; } diff --git a/src/sgl/device/buffer_cursor.h b/src/sgl/device/buffer_cursor.h index c3a35377..e5ddd9e1 100644 --- a/src/sgl/device/buffer_cursor.h +++ b/src/sgl/device/buffer_cursor.h @@ -103,12 +103,7 @@ class SGL_API BufferCursor : Object { BufferCursor(ref element_layout, ref resource); /// Create as a view onto a section of a buffer resource. - BufferCursor( - ref element_layout, - ref resource, - size_t element_count, - size_t first_element - ); + BufferCursor(ref element_layout, ref resource, size_t size, size_t offset); ~BufferCursor(); diff --git a/src/sgl/device/python/buffer_cursor.cpp b/src/sgl/device/python/buffer_cursor.cpp index 019772c8..27940182 100644 --- a/src/sgl/device/python/buffer_cursor.cpp +++ b/src/sgl/device/python/buffer_cursor.cpp @@ -93,8 +93,8 @@ SGL_PY_EXPORT(device_buffer_cursor) nb::init, ref, size_t, size_t>(), "element_layout"_a, "buffer_resource"_a, - "element_count"_a, - "first_element"_a, + "size"_a, + "offset"_a, D_NA(BufferCursor, BufferCursor) ) .def_prop_ro("element_type_layout", &BufferCursor::element_type_layout, D_NA(BufferCursor, type_layout)) diff --git a/src/sgl/device/tests/test_declrefs.py b/src/sgl/device/tests/test_declrefs.py index 39bff706..4727a09d 100644 --- a/src/sgl/device/tests/test_declrefs.py +++ b/src/sgl/device/tests/test_declrefs.py @@ -4,7 +4,7 @@ import sys import sgl from pathlib import Path -from deepdiff import DeepDiff +from deepdiff.diff import DeepDiff sys.path.append(str(Path(__file__).parent)) import sglhelpers as helpers diff --git a/src/sgl/device/tests/test_shader_cursor.py b/src/sgl/device/tests/test_shader_cursor.py index 864ebe51..3f6573c4 100644 --- a/src/sgl/device/tests/test_shader_cursor.py +++ b/src/sgl/device/tests/test_shader_cursor.py @@ -31,7 +31,7 @@ class TypeInfo: # encoding of read back data struct: str # numpy dtype - dtype: DTypeLike + dtype: DTypeLike # type: ignore TYPE_INFOS = { diff --git a/src/sgl/utils/tests/test_texture_loader.py b/src/sgl/utils/tests/test_texture_loader.py index ce7773ca..8782cdae 100644 --- a/src/sgl/utils/tests/test_texture_loader.py +++ b/src/sgl/utils/tests/test_texture_loader.py @@ -144,7 +144,7 @@ def create_test_array( width: int, height: int, channels: int, - dtype: npt.DTypeLike, + dtype: npt.DTypeLike, # type: ignore type_range: tuple[float, float], ): img = np.zeros((height, width, channels), dtype)