@@ -33,33 +33,6 @@ static_assert(gl::isPow2(kBufferSizeGranularity), "use as alignment, must be pow
3333// Start with a fairly small buffer size. We can increase this dynamically as we convert more data.
3434constexpr size_t kConvertedArrayBufferInitialSize = 1024 * 8 ;
3535
36- // Base size for all staging buffers
37- constexpr size_t kStagingBufferBaseSize = 1024 ;
38- // Fix the staging buffer size multiplier for unpack buffers, for now
39- constexpr size_t kUnpackBufferStagingBufferMultiplier = 1024 ;
40-
41- size_t CalculateStagingBufferSize (gl::BufferBinding target, size_t size, size_t alignment)
42- {
43- size_t alignedSize = rx::roundUp (size, alignment);
44- int multiplier = std::max (gl::log2 (alignedSize), 1 );
45-
46- switch (target)
47- {
48- case gl::BufferBinding::Array:
49- case gl::BufferBinding::DrawIndirect:
50- case gl::BufferBinding::ElementArray:
51- case gl::BufferBinding::Uniform:
52- return kStagingBufferBaseSize * multiplier;
53-
54- case gl::BufferBinding::PixelUnpack:
55- return std::max (alignedSize,
56- (kStagingBufferBaseSize * kUnpackBufferStagingBufferMultiplier ));
57-
58- default :
59- return kStagingBufferBaseSize ;
60- }
61- }
62-
6336// Buffers that have a static usage pattern will be allocated in
6437// device local memory to speed up access to and from the GPU.
6538// Dynamic usage patterns or that are frequently mapped
@@ -163,7 +136,6 @@ void BufferVk::destroy(const gl::Context *context)
163136void BufferVk::release (ContextVk *contextVk)
164137{
165138 RendererVk *renderer = contextVk->getRenderer ();
166- mStagingBuffer .release (renderer);
167139 mShadowBuffer .release ();
168140 mBufferPool .release (renderer);
169141 mBuffer = nullptr ;
@@ -174,18 +146,6 @@ void BufferVk::release(ContextVk *contextVk)
174146 }
175147}
176148
177- void BufferVk::initializeStagingBuffer (ContextVk *contextVk, gl::BufferBinding target, size_t size)
178- {
179- RendererVk *rendererVk = contextVk->getRenderer ();
180-
181- constexpr VkImageUsageFlags kBufferUsageFlags = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
182- size_t alignment =
183- static_cast <size_t >(rendererVk->getPhysicalDeviceProperties ().limits .minMemoryMapAlignment );
184- size_t stagingBufferSize = CalculateStagingBufferSize (target, size, alignment);
185-
186- mStagingBuffer .init (rendererVk, kBufferUsageFlags , alignment, stagingBufferSize, true );
187- }
188-
189149angle::Result BufferVk::initializeShadowBuffer (ContextVk *contextVk,
190150 gl::BufferBinding target,
191151 size_t size)
@@ -258,9 +218,6 @@ angle::Result BufferVk::setData(const gl::Context *context,
258218
259219 ANGLE_TRY (acquireBufferHelper (contextVk, size, &mBuffer ));
260220
261- // Initialize the staging buffer
262- initializeStagingBuffer (contextVk, target, size);
263-
264221 // Initialize the shadow buffer
265222 ANGLE_TRY (initializeShadowBuffer (contextVk, target, size));
266223 }
@@ -530,29 +487,23 @@ angle::Result BufferVk::stagedUpdate(ContextVk *contextVk,
530487 size_t offset)
531488{
532489 // Acquire a "new" staging buffer
533- bool needToReleasePreviousBuffers = false ;
534- uint8_t *mapPointer = nullptr ;
535- VkDeviceSize stagingBufferOffset = 0 ;
490+ uint8_t *mapPointer = nullptr ;
491+ VkDeviceSize stagingBufferOffset = 0 ;
536492
537- ANGLE_TRY (mStagingBuffer .allocate (contextVk, size, &mapPointer, nullptr , &stagingBufferOffset,
538- &needToReleasePreviousBuffers));
539- if (needToReleasePreviousBuffers)
540- {
541- // Release previous staging buffers
542- mStagingBuffer .releaseInFlightBuffers (contextVk);
543- }
493+ vk::DynamicBuffer *stagingBuffer = contextVk->getStagingBufferStorage ();
494+ ANGLE_TRY (stagingBuffer->allocate (contextVk, size, &mapPointer, nullptr , &stagingBufferOffset,
495+ nullptr ));
544496 ASSERT (mapPointer);
545497
546498 memcpy (mapPointer, data, size);
547- ASSERT (!mStagingBuffer . isCoherent ());
548- ANGLE_TRY (mStagingBuffer . flush (contextVk));
549- mStagingBuffer . getCurrentBuffer ()->onExternalWrite (VK_ACCESS_HOST_WRITE_BIT);
499+ ASSERT (!stagingBuffer-> isCoherent ());
500+ ANGLE_TRY (stagingBuffer-> flush (contextVk));
501+ stagingBuffer-> getCurrentBuffer ()->onExternalWrite (VK_ACCESS_HOST_WRITE_BIT);
550502
551503 // Enqueue a copy command on the GPU.
552504 VkBufferCopy copyRegion = {stagingBufferOffset, offset, size};
553505 ANGLE_TRY (
554- mBuffer ->copyFromBuffer (contextVk, mStagingBuffer .getCurrentBuffer (), 1 , ©Region));
555- mStagingBuffer .getCurrentBuffer ()->retain (&contextVk->getResourceUseList ());
506+ mBuffer ->copyFromBuffer (contextVk, stagingBuffer->getCurrentBuffer (), 1 , ©Region));
556507
557508 return angle::Result::Continue;
558509}
0 commit comments