@@ -23,8 +23,6 @@ class StagingBuffer final {
2323 private: 
2424  Context* context_p_;
2525  vkapi::ScalarType dtype_;
26-   size_t  numel_;
27-   size_t  nbytes_;
2826  vkapi::VulkanBuffer vulkan_buffer_;
2927
3028  void * mapped_data_;
@@ -36,10 +34,8 @@ class StagingBuffer final {
3634      const  size_t  numel)
3735      : context_p_(context_p),
3836        dtype_ (dtype),
39-         numel_(numel),
40-         nbytes_(element_size(dtype_) * numel_),
41-         vulkan_buffer_(
42-             context_p_->adapter_ptr ()->vma().create_staging_buffer(nbytes_)),
37+         vulkan_buffer_(context_p_->adapter_ptr ()->vma().create_staging_buffer(
38+             element_size (dtype_) * numel)),
4339        mapped_data_(nullptr ) {}
4440
4541  StagingBuffer (const  StagingBuffer&) = delete;
@@ -68,15 +64,15 @@ class StagingBuffer final {
6864  }
6965
7066  inline  size_t  numel () {
71-     return  numel_ ;
67+     return  nbytes () /  element_size (dtype_) ;
7268  }
7369
7470  inline  size_t  nbytes () {
75-     return  nbytes_ ;
71+     return  vulkan_buffer_. mem_size () ;
7672  }
7773
7874  inline  void  copy_from (const  void * src, const  size_t  nbytes) {
79-     VK_CHECK_COND (nbytes <= nbytes_ );
75+     VK_CHECK_COND (nbytes <= this -> nbytes () );
8076    memcpy (data (), src, nbytes);
8177    vmaFlushAllocation (
8278        vulkan_buffer_.vma_allocator (),
@@ -86,7 +82,7 @@ class StagingBuffer final {
8682  }
8783
8884  inline  void  copy_to (void * dst, const  size_t  nbytes) {
89-     VK_CHECK_COND (nbytes <= nbytes_ );
85+     VK_CHECK_COND (nbytes <= this -> nbytes () );
9086    vmaInvalidateAllocation (
9187        vulkan_buffer_.vma_allocator (),
9288        vulkan_buffer_.allocation (),
@@ -96,7 +92,7 @@ class StagingBuffer final {
9692  }
9793
9894  inline  void  set_staging_zeros () {
99-     memset (data (), 0 , nbytes_ );
95+     memset (data (), 0 , nbytes () );
10096  }
10197};
10298
0 commit comments