Skip to content

Commit c0d93fe

Browse files
authored
Merge branch 'google:main' into master
2 parents c775259 + 843a324 commit c0d93fe

9 files changed

Lines changed: 175 additions & 74 deletions

File tree

DEPS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ deps = {
10891089
},
10901090

10911091
'third_party/vulkan-deps': {
1092-
'url': Var('chromium_git') + '/vulkan-deps@b79339a8e7c52f938604741a2a902fba55816d23',
1092+
'url': Var('chromium_git') + '/vulkan-deps@6501b79e3449586d51254f747e516b82d2646fde',
10931093
'condition': 'not build_with_chromium',
10941094
},
10951095

@@ -1139,7 +1139,7 @@ deps = {
11391139
},
11401140

11411141
'third_party/vulkan-validation-layers/src': {
1142-
'url': '{chromium_git}/external/github.com/KhronosGroup/Vulkan-ValidationLayers@16858697f5fe48f7a052ee62623b7d8dcff8361a',
1142+
'url': '{chromium_git}/external/github.com/KhronosGroup/Vulkan-ValidationLayers@9b30be121a2c1b60e72cc54d3219cac8f2664205',
11431143
'condition': 'not build_with_chromium',
11441144
},
11451145

src/libANGLE/HandleAllocator.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "libANGLE/HandleAllocator.h"
1111

1212
#include <algorithm>
13-
#include <functional>
1413
#include <limits>
1514

1615
#include "common/debug.h"
@@ -34,12 +33,11 @@ HandleAllocator::~HandleAllocator() {}
3433

3534
bool HandleAllocator::allocate(GLuint *outId)
3635
{
37-
// Allocate from released list, logarithmic time for pop_heap.
36+
// Allocate from released list, constant time for FIFO pop_front.
3837
if (!mReleasedList.empty())
3938
{
40-
std::pop_heap(mReleasedList.begin(), mReleasedList.end(), std::greater<GLuint>());
41-
GLuint reusedHandle = mReleasedList.back();
42-
mReleasedList.pop_back();
39+
GLuint reusedHandle = mReleasedList.front();
40+
mReleasedList.pop_front();
4341

4442
if (mLoggingEnabled)
4543
{
@@ -119,9 +117,8 @@ void HandleAllocator::release(GLuint handle)
119117
}
120118
}
121119

122-
// Add to released list, logarithmic time for push_heap.
120+
// Add to released list, constant time for FIFO push_back.
123121
mReleasedList.push_back(handle);
124-
std::push_heap(mReleasedList.begin(), mReleasedList.end(), std::greater<GLuint>());
125122
}
126123

127124
void HandleAllocator::reserve(GLuint handle)
@@ -145,7 +142,6 @@ void HandleAllocator::reserve(GLuint handle)
145142
if (releasedIt != mReleasedList.end())
146143
{
147144
mReleasedList.erase(releasedIt);
148-
std::make_heap(mReleasedList.begin(), mReleasedList.end(), std::greater<GLuint>());
149145
return;
150146
}
151147
}

src/libANGLE/HandleAllocator.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#ifndef LIBANGLE_HANDLEALLOCATOR_H_
1111
#define LIBANGLE_HANDLEALLOCATOR_H_
1212

13+
#include <deque>
14+
1315
#include "common/angleutils.h"
1416

1517
#include "angle_gl.h"
@@ -50,7 +52,7 @@ class HandleAllocator final : angle::NonCopyable
5052
// as ranges, and handles that were previously allocated and
5153
// released, stored in a heap.
5254
std::vector<HandleRange> mUnallocatedList;
53-
std::vector<GLuint> mReleasedList;
55+
std::deque<GLuint> mReleasedList;
5456

5557
bool mLoggingEnabled;
5658
};

src/libANGLE/HandleAllocator_unittest.cpp

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,123 @@ TEST(HandleAllocatorTest, HandleExhaustion)
295295
EXPECT_FALSE(allocator.anyHandleAvailableForAllocation());
296296
}
297297

298+
// Verifies that released handles are reused in FIFO order.
299+
TEST(HandleAllocatorTest, ReleaseThenReuseInFIFO)
300+
{
301+
gl::HandleAllocator allocator(1000);
302+
303+
// Allocate handles 1-11. The next unallocated index is 12.
304+
GLuint handles[11];
305+
for (int i = 0; i < 11; i++)
306+
{
307+
EXPECT_TRUE(allocator.allocate(&handles[i]));
308+
}
309+
310+
// Release handles in a non-sorted order. None is adjacent to 12, so all go into mReleasedList
311+
// rather than being consolidated into mUnallocatedList.
312+
constexpr GLuint kReleaseOrder[] = {3, 1, 5, 2, 4, 8, 6, 10, 7, 9};
313+
for (GLuint i : kReleaseOrder)
314+
{
315+
allocator.release(i);
316+
}
317+
318+
// Each allocation should return the next handle in the same order they were released.
319+
for (GLuint expected : kReleaseOrder)
320+
{
321+
GLuint handle = 0;
322+
EXPECT_TRUE(allocator.allocate(&handle));
323+
EXPECT_EQ(expected, handle);
324+
}
325+
}
326+
327+
// Verifies that reserve() correctly removes handles from the released list even when the released
328+
// list has many entries.
329+
TEST(HandleAllocatorTest, ReserveFromLargeReleasedList)
330+
{
331+
gl::HandleAllocator allocator(1000);
332+
333+
// Need to allocate 101 to push the next unallocated index to 102, so it is no longer adjacent
334+
// to 1-100.
335+
GLuint prevHandle;
336+
for (GLuint i = 1; i <= 101; i++)
337+
{
338+
EXPECT_TRUE(allocator.allocate(&prevHandle));
339+
}
340+
341+
// Release 1-100. All should go to mReleasedList.
342+
for (GLuint i = 1; i <= 100; i++)
343+
{
344+
allocator.release(i);
345+
}
346+
347+
// Reserve some specific handles.
348+
allocator.reserve(50);
349+
allocator.reserve(75);
350+
allocator.reserve(25);
351+
352+
// Verify those reserved handles are not allocated.
353+
GLuint handle;
354+
for (GLuint i = 1; i <= 100; i++)
355+
{
356+
if (allocator.allocate(&handle))
357+
{
358+
EXPECT_NE(25u, handle);
359+
EXPECT_NE(50u, handle);
360+
EXPECT_NE(75u, handle);
361+
}
362+
}
363+
}
364+
365+
// Verifies that interleaved release and allocate operations work correctly.
366+
// Simulates handle usage patterns similar to real-world resource management.
367+
TEST(HandleAllocatorTest, InterleavedReleaseAllocate)
368+
{
369+
gl::HandleAllocator allocator(kMaxHandleForTesting);
370+
constexpr GLuint kPoolSize = 16;
371+
372+
// Allocate more handles than the pool to prevent consolidation.
373+
std::vector<GLuint> pool;
374+
for (GLuint i = 0; i < kPoolSize; i++)
375+
{
376+
GLuint handle;
377+
EXPECT_TRUE(allocator.allocate(&handle));
378+
pool.push_back(handle);
379+
}
380+
381+
// Keep the next unallocated handle advanced.
382+
GLuint gapHandle;
383+
EXPECT_TRUE(allocator.allocate(&gapHandle));
384+
385+
// Release half of the pool.
386+
std::vector<GLuint> releasedHandles;
387+
for (GLuint i = 0; i < kPoolSize / 2; i++)
388+
{
389+
allocator.release(pool[i]);
390+
releasedHandles.push_back(pool[i]);
391+
}
392+
393+
// Release more handles.
394+
std::vector<GLuint> releasedHandles2;
395+
for (GLuint i = kPoolSize / 2; i < kPoolSize; i++)
396+
{
397+
allocator.release(pool[i]);
398+
releasedHandles2.push_back(pool[i]);
399+
}
400+
401+
// Allocate them back. It should return in FIFO order.
402+
for (GLuint handle : releasedHandles)
403+
{
404+
GLuint newHandle;
405+
EXPECT_TRUE(allocator.allocate(&newHandle));
406+
EXPECT_EQ(handle, newHandle);
407+
}
408+
409+
for (GLuint handle : releasedHandles2)
410+
{
411+
GLuint newHandle;
412+
EXPECT_TRUE(allocator.allocate(&newHandle));
413+
EXPECT_EQ(handle, newHandle);
414+
}
415+
}
416+
298417
} // anonymous namespace

src/libANGLE/renderer/metal/BufferMtl.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,11 @@ class BufferMtl : public BufferImpl, public BufferHolderMtl
202202

203203
angle::Result setDataImpl(const gl::Context *context,
204204
gl::BufferBinding target,
205-
const void *data,
206205
size_t size,
207206
gl::BufferUsage usage,
208207
BufferFeedback *feedback);
209208
angle::Result setSubDataImpl(const gl::Context *context,
210-
const void *data,
211-
size_t size,
209+
angle::Span<const uint8_t> data,
212210
size_t offset,
213211
BufferFeedback *feedback);
214212

@@ -219,21 +217,17 @@ class BufferMtl : public BufferImpl, public BufferHolderMtl
219217
void clearConversionBuffers();
220218

221219
angle::Result putDataInNewBufferAndStartUsingNewBuffer(ContextMtl *contextMtl,
222-
const uint8_t *srcPtr,
223-
size_t sizeToCopy,
220+
angle::Span<const uint8_t> data,
224221
size_t offset,
225222
BufferFeedback *feedback);
226223
angle::Result updateExistingBufferViaBlitFromStagingBuffer(ContextMtl *contextMtl,
227-
const uint8_t *srcPtr,
228-
size_t sizeToCopy,
224+
angle::Span<const uint8_t> data,
229225
size_t offset);
230226
angle::Result copyDataToExistingBufferViaCPU(ContextMtl *contextMtl,
231-
const uint8_t *srcPtr,
232-
size_t sizeToCopy,
227+
angle::Span<const uint8_t> data,
233228
size_t offset);
234229
angle::Result updateShadowCopyThenCopyShadowToNewBuffer(ContextMtl *contextMtl,
235-
const uint8_t *srcPtr,
236-
size_t sizeToCopy,
230+
angle::Span<const uint8_t> data,
237231
size_t offset,
238232
BufferFeedback *feedback);
239233

0 commit comments

Comments
 (0)