@@ -99,15 +99,16 @@ std::tuple<Range, std::shared_ptr<DeviceBuffer>> HostBuffer::EmplaceInternal(
99
99
DeviceBufferDescriptor desc;
100
100
desc.size = length;
101
101
desc.storage_mode = StorageMode::kHostVisible ;
102
- auto device_buffer = allocator_->CreateBuffer (desc);
102
+ std::shared_ptr<DeviceBuffer> device_buffer =
103
+ allocator_->CreateBuffer (desc);
103
104
if (!device_buffer) {
104
105
return {};
105
106
}
106
107
if (cb) {
107
108
cb (device_buffer->OnGetContents ());
108
109
device_buffer->Flush (Range{0 , length});
109
110
}
110
- return std::make_tuple (Range{0 , length}, device_buffer);
111
+ return std::make_tuple (Range{0 , length}, std::move ( device_buffer) );
111
112
}
112
113
113
114
size_t padding = 0 ;
@@ -120,14 +121,14 @@ std::tuple<Range, std::shared_ptr<DeviceBuffer>> HostBuffer::EmplaceInternal(
120
121
offset_ += padding;
121
122
}
122
123
123
- auto current_buffer = GetCurrentBuffer ();
124
+ const std::shared_ptr<DeviceBuffer>& current_buffer = GetCurrentBuffer ();
124
125
auto contents = current_buffer->OnGetContents ();
125
126
cb (contents + offset_);
126
127
Range output_range (offset_, length);
127
128
current_buffer->Flush (output_range);
128
129
129
130
offset_ += length;
130
- return std::make_tuple (output_range, std::move ( current_buffer) );
131
+ return std::make_tuple (output_range, current_buffer);
131
132
}
132
133
133
134
std::tuple<Range, std::shared_ptr<DeviceBuffer>> HostBuffer::EmplaceInternal (
@@ -139,7 +140,8 @@ std::tuple<Range, std::shared_ptr<DeviceBuffer>> HostBuffer::EmplaceInternal(
139
140
DeviceBufferDescriptor desc;
140
141
desc.size = length;
141
142
desc.storage_mode = StorageMode::kHostVisible ;
142
- auto device_buffer = allocator_->CreateBuffer (desc);
143
+ std::shared_ptr<DeviceBuffer> device_buffer =
144
+ allocator_->CreateBuffer (desc);
143
145
if (!device_buffer) {
144
146
return {};
145
147
}
@@ -149,7 +151,7 @@ std::tuple<Range, std::shared_ptr<DeviceBuffer>> HostBuffer::EmplaceInternal(
149
151
return {};
150
152
}
151
153
}
152
- return std::make_tuple (Range{0 , length}, device_buffer);
154
+ return std::make_tuple (Range{0 , length}, std::move ( device_buffer) );
153
155
}
154
156
155
157
auto old_length = GetLength ();
@@ -158,14 +160,14 @@ std::tuple<Range, std::shared_ptr<DeviceBuffer>> HostBuffer::EmplaceInternal(
158
160
}
159
161
old_length = GetLength ();
160
162
161
- auto current_buffer = GetCurrentBuffer ();
163
+ const std::shared_ptr<DeviceBuffer>& current_buffer = GetCurrentBuffer ();
162
164
auto contents = current_buffer->OnGetContents ();
163
165
if (buffer) {
164
166
::memmove (contents + old_length, buffer, length);
165
167
current_buffer->Flush (Range{old_length, length});
166
168
}
167
169
offset_ += length;
168
- return std::make_tuple (Range{old_length, length}, std::move ( current_buffer) );
170
+ return std::make_tuple (Range{old_length, length}, current_buffer);
169
171
}
170
172
171
173
std::tuple<Range, std::shared_ptr<DeviceBuffer>>
@@ -186,6 +188,10 @@ HostBuffer::EmplaceInternal(const void* buffer, size_t length, size_t align) {
186
188
return EmplaceInternal (buffer, length);
187
189
}
188
190
191
+ const std::shared_ptr<DeviceBuffer>& HostBuffer::GetCurrentBuffer () const {
192
+ return device_buffers_[frame_index_][current_buffer_];
193
+ }
194
+
189
195
void HostBuffer::Reset () {
190
196
// When resetting the host buffer state at the end of the frame, check if
191
197
// there are any unused buffers and remove them.
0 commit comments