Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/gpgmm/common/MemoryAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,14 @@ namespace gpgmm {

/** \brief Return free memory back to the OS.

@param bytesToRelease Amount of memory to release, in bytes. A kInvalidSize means ALL memory
will be released.
@param bytesToRelease Amount of memory to release, in bytes. A value of UINT64_MAX
releases ALL memory held by the allocator.

\return Amount of memory, in bytes, released. The released size might be smaller then
bytesToRelease if there was not enough memory or larger if releasable memory doesn't exactly
total up to the amount.
*/
virtual uint64_t ReleaseMemory(uint64_t bytesToRelease = kInvalidSize);
virtual uint64_t ReleaseMemory(uint64_t bytesToRelease);

/** \brief Get the fixed-memory sized of the MemoryAllocator.

Expand Down
6 changes: 3 additions & 3 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,14 +485,14 @@ namespace gpgmm::d3d12 {
system. Apps should call ReleaseMemory() when going idle for a period of time since there is
a brief performance hit when the internal resource heaps get reallocated by the OS.

@param bytesToRelease Amount of memory to release, in bytes. A kInvalidSize means ALL memory
will be released.
@param bytesToRelease Amount of memory to release, in bytes. A value of UINT64_MAX
releases ALL memory held by the allocator.

\return Amount of memory, in bytes, released. The released size might be smaller then
bytesToRelease if there was not enough memory or larger if releasable memory doesn't exactly
total up to the amount.
*/
uint64_t ReleaseMemory(uint64_t bytesToRelease = kInvalidSize) override;
uint64_t ReleaseMemory(uint64_t bytesToRelease) override;

/** \brief Return the current allocator usage.

Expand Down
3 changes: 2 additions & 1 deletion src/tests/end2end/D3D12ResourceAllocatorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using namespace gpgmm::d3d12;

static constexpr uint64_t kDefaultBufferSize = 4ll * 1024ll * 1024ll; // 4MB
static constexpr uint64_t kReleaseAllMemory = std::numeric_limits<uint64_t>::max();

#define GPGMM_GET_VAR_NAME(x) (#x)

Expand Down Expand Up @@ -942,7 +943,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferPooled) {

EXPECT_EQ(poolAllocator->GetInfo().FreeMemoryUsage, bufferSize + bufferSize / 2);

EXPECT_EQ(poolAllocator->ReleaseMemory(), bufferSize + bufferSize / 2);
EXPECT_EQ(poolAllocator->ReleaseMemory(kReleaseAllMemory), bufferSize + bufferSize / 2);

EXPECT_EQ(poolAllocator->GetInfo().FreeMemoryUsage, 0u);

Expand Down
5 changes: 3 additions & 2 deletions src/tests/unittests/BuddyMemoryAllocatorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ using namespace gpgmm;

static constexpr uint64_t kDefaultMemorySize = 128u;
static constexpr uint64_t kDefaultMemoryAlignment = 128u;
static constexpr uint64_t kReleaseAllMemory = std::numeric_limits<uint64_t>::max();

class BuddyMemoryAllocatorTests : public testing::Test {
public:
Expand Down Expand Up @@ -510,7 +511,7 @@ TEST_F(BuddyMemoryAllocatorTests, ReuseFreedHeaps) {

EXPECT_EQ(allocator.GetInfo().UsedMemoryCount, 0u);

allocator.ReleaseMemory();
allocator.ReleaseMemory(kReleaseAllMemory);
}

// Verify resource heaps that were reused from a pool can be destroyed.
Expand Down Expand Up @@ -550,5 +551,5 @@ TEST_F(BuddyMemoryAllocatorTests, DestroyHeaps) {

EXPECT_EQ(allocator.GetInfo().FreeMemoryUsage, kNumOfHeaps * kDefaultMemorySize);

allocator.ReleaseMemory();
allocator.ReleaseMemory(kReleaseAllMemory);
}
8 changes: 5 additions & 3 deletions src/tests/unittests/MemoryAllocatorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

using namespace gpgmm;

static constexpr uint64_t kReleaseAllMemory = std::numeric_limits<uint64_t>::max();

static uint64_t DestructCount = 0;
static uint64_t ReleaseMemoryCount = 0;

Expand All @@ -36,7 +38,7 @@ class TestMemoryAllocator final : public DummyMemoryAllocator {
DestructCount++;
}

uint64_t ReleaseMemory(uint64_t bytesToRelease = kInvalidSize) override {
uint64_t ReleaseMemory(uint64_t bytesToRelease) override {
ReleaseMemoryCount++;
return MemoryAllocator::ReleaseMemory(bytesToRelease);
}
Expand All @@ -56,7 +58,7 @@ TEST_F(MemoryAllocatorTests, SingleAllocator) {

EXPECT_TRUE(parent->GetNextInChain() != nullptr);

parent->ReleaseMemory();
parent->ReleaseMemory(kReleaseAllMemory);
EXPECT_EQ(ReleaseMemoryCount, 2u);

parent.reset();
Expand All @@ -70,7 +72,7 @@ TEST_F(MemoryAllocatorTests, MultipleAllocators) {

EXPECT_TRUE(parent->GetNextInChain() != nullptr);

parent->ReleaseMemory();
parent->ReleaseMemory(kReleaseAllMemory);
EXPECT_EQ(ReleaseMemoryCount, 3u);

parent.reset();
Expand Down