Skip to content

NanoVDB: type the Mask scratch buffers as Buffer<Mask<N>> once Mask is trivially copyable #2312

Description

@harrism

Context

#2310 defaults nanovdb::Mask's copy constructor, making it trivially copyable. That satisfies cuda::Buffer<T, R>'s is_trivially_copyable<T> requirement, so the scratch buffers that exist solely to hold arrays of Mask<N> can become typed cuda::Buffer<Mask<N>, ...> instead of Buffer<std::byte> (or a legacy buffer) plus a cast. A census of the tree found exactly seven such sidecar sites; recording them here so they don't need re-finding.

Pure retypes (change the element type, delete the cast)

  1. tools::cuda::MeshToGrid — the retainMaskBuffer in the first getHandle overload (allocated as bytes, reinterpret_cast to Mask<3>*, memset to 0xFF for all-on init).
  2. tools::cuda::MeshToGrid — the per-subdivision-pass maskBuffer holding CTA hit results (Mask<3>). Its sibling countsBuffer is a separate allocation, so no offset arithmetic is affected.
  3. tools::cuda::MeshToGrid — the retainMaskBuffer in the UDF-sidecar getHandle overload (same shape as 1).
  4. examples/ex_dilate_nanovdb_cudadstLeafMaskBuffer in the kernels file (Mask<3> array).
  5. unittest/TestNanoVDB.cu — the leaf-mask buffer in the dilation test (currently on the legacy dual-space buffer via create() + deviceData(); retyping folds into its migration to cuda::Buffer).

Retype with a small refactor

  1. tools::cuda::TopologyBuilder::mUpperMasks (Mask<5> array): the builder's single byte-buffer ScratchT alias is shared by ~9 members, so typing the mask members means per-member aliases; the deviceUpperMasks() accessor returns void* and each consumer in util/cuda/Morphology.cuh and MeshToGrid.cuh casts — the accessor should return Mask<5>* and the casts go.
  2. tools::cuda::TopologyBuilder::mLowerMasks (Mask<4>, viewed as a 2D Mask<4>(*)[Mask<5>::SIZE]): same alias/accessor refactor; note the 2D array-shape cast at the use site remains even after the element type is fixed.

Notes

  • The zero/0xFF cudaMemsetAsync initializations stay as-is (a typed buffer's storage is still just bytes to initialize; noInit construction plus memset remains the right pattern).
  • VoxelBlockManager has no mask sidecar despite being the intuitive candidate — its scratch arrays are uint32_t/uint64_t (typed-buffer candidates of their own, but not Mask).
  • Sites 1–5 are all touched by NanoVDB: migrate off the dual-space buffers and deprecate the DeviceBuffer name (CUDA) #2301, so this work should land after it merges and be based on its post-merge shape to avoid conflicts.
  • Out of scope: casts into grid internals (NanoVDB grids are byte blobs by design), shared-memory reinterpretations, and the union workaround in MeshToGrid's leaf-mask kernel — the latter is blocked by Mask's user-provided zeroing default constructor, which NanoVDB: default Mask's copy constructor #2310 deliberately leaves alone.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions