Skip to content

Commit

Permalink
use size/offset to specify buffer cursor data section (#144)
Browse files Browse the repository at this point in the history
* use size/offset to specify buffer cursor data section

* ignore typing issues
  • Loading branch information
skallweitNV authored Dec 20, 2024
1 parent 13d5973 commit 9890f38
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 23 deletions.
4 changes: 3 additions & 1 deletion examples/pathtracer/pathtracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/sgl/core/tests/test_bitmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/sgl/core/tests/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
11 changes: 3 additions & 8 deletions src/sgl/device/buffer_cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,17 +411,12 @@ BufferCursor::BufferCursor(ref<TypeLayoutReflection> element_layout, ref<Buffer>
m_owner = true;
}

BufferCursor::BufferCursor(
ref<TypeLayoutReflection> element_layout,
ref<Buffer> resource,
size_t element_count,
size_t first_element
)
BufferCursor::BufferCursor(ref<TypeLayoutReflection> element_layout, ref<Buffer> 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;
}
Expand Down
7 changes: 1 addition & 6 deletions src/sgl/device/buffer_cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,7 @@ class SGL_API BufferCursor : Object {
BufferCursor(ref<TypeLayoutReflection> element_layout, ref<Buffer> resource);

/// Create as a view onto a section of a buffer resource.
BufferCursor(
ref<TypeLayoutReflection> element_layout,
ref<Buffer> resource,
size_t element_count,
size_t first_element
);
BufferCursor(ref<TypeLayoutReflection> element_layout, ref<Buffer> resource, size_t size, size_t offset);

~BufferCursor();

Expand Down
4 changes: 2 additions & 2 deletions src/sgl/device/python/buffer_cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ SGL_PY_EXPORT(device_buffer_cursor)
nb::init<ref<TypeLayoutReflection>, ref<Buffer>, 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))
Expand Down
2 changes: 1 addition & 1 deletion src/sgl/device/tests/test_declrefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/sgl/device/tests/test_shader_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TypeInfo:
# encoding of read back data
struct: str
# numpy dtype
dtype: DTypeLike
dtype: DTypeLike # type: ignore


TYPE_INFOS = {
Expand Down
2 changes: 1 addition & 1 deletion src/sgl/utils/tests/test_texture_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9890f38

Please sign in to comment.