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
11 changes: 1 addition & 10 deletions src/tests/D3D12Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,23 +109,14 @@ namespace gpgmm::d3d12 {
GPGMMTestBase::TearDown();
}

ALLOCATOR_DESC D3D12TestBase::CreateBasicAllocatorDesc(bool isPrefetchAllowed) const {
ALLOCATOR_DESC D3D12TestBase::CreateBasicAllocatorDesc() const {
ALLOCATOR_DESC desc = {};

// Required parameters.
desc.Adapter = mAdapter;
desc.Device = mDevice;
desc.ResourceHeapTier = mResourceHeapTier;

// Pre-fetching is enabled by default. However for testing purposes, pre-fetching changes
// expectations that check GPU memory usage and needs to be tested in isolation.
if (!isPrefetchAllowed) {
desc.Flags |= ALLOCATOR_FLAG_DISABLE_MEMORY_PREFETCH;
}

// Make sure leak detection is always enabled.
desc.Flags |= gpgmm::d3d12::ALLOCATOR_FLAG_NEVER_LEAK_MEMORY;

desc.MinLogLevel = GetMessageSeverity(GetLogLevel());

if (IsDumpAllEventsEnabled()) {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/D3D12Test.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace gpgmm::d3d12 {
void SetUp();
void TearDown();

ALLOCATOR_DESC CreateBasicAllocatorDesc(bool isPrefetchAllowed = false) const;
ALLOCATOR_DESC CreateBasicAllocatorDesc() const;

static D3D12_RESOURCE_DESC CreateBasicBufferDesc(uint64_t width, uint64_t alignment = 0);

Expand Down
7 changes: 5 additions & 2 deletions src/tests/capture_replay_tests/D3D12EventTraceReplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,12 @@ class D3D12EventTraceReplay : public D3D12TestBase, public CaptureReplayTestWith
const Json::Value& snapshot = event["args"]["snapshot"];
ASSERT_FALSE(snapshot.empty());

ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc();
if (!envParams.IsPrefetchAllowed) {
allocatorDesc.Flags |= ALLOCATOR_FLAG_DISABLE_MEMORY_PREFETCH;
}

// Apply profile (if specified).
ALLOCATOR_DESC allocatorDesc =
CreateBasicAllocatorDesc(envParams.IsPrefetchAllowed);
if (envParams.AllocatorProfile ==
AllocatorProfile::ALLOCATOR_PROFILE_CAPTURED) {
allocatorDesc.Flags |=
Expand Down
23 changes: 21 additions & 2 deletions src/tests/end2end/D3D12ResourceAllocatorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ class D3D12ResourceAllocatorTests : public D3D12TestBase, public ::testing::Test
void TearDown() override {
D3D12TestBase::TearDown();
}

// Configures allocator for testing allocation in a controlled and predictable
// fashion.
ALLOCATOR_DESC CreateBasicAllocatorDesc() const {
ALLOCATOR_DESC desc = D3D12TestBase::CreateBasicAllocatorDesc();

// Pre-fetching is enabled by default. However for testing purposes, pre-fetching changes
// expectations that check GPU memory usage and needs to be tested in isolation.
desc.Flags |= ALLOCATOR_FLAG_DISABLE_MEMORY_PREFETCH;

// Make sure leak detection is always enabled.
desc.Flags |= gpgmm::d3d12::ALLOCATOR_FLAG_NEVER_LEAK_MEMORY;

return desc;
}
};

TEST_F(D3D12ResourceAllocatorTests, CreateAllocator) {
Expand Down Expand Up @@ -1520,9 +1535,13 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithLimitedFragmentation) {

// Creates a bunch of small buffers using the smallest size allowed with pre-fetching enabled.
TEST_F(D3D12ResourceAllocatorTests, CreateBufferManyPrefetch) {
// Prefetching is explicitly disabled but otherwise allowed, re-enable it by clearing the
// disable flag.
ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc();
allocatorDesc.Flags ^= ALLOCATOR_FLAG_DISABLE_MEMORY_PREFETCH;

ComPtr<ResourceAllocator> resourceAllocator;
ASSERT_SUCCEEDED(ResourceAllocator::CreateAllocator(
CreateBasicAllocatorDesc(/*allowPrefetch*/ true), &resourceAllocator));
ASSERT_SUCCEEDED(ResourceAllocator::CreateAllocator(allocatorDesc, &resourceAllocator));
ASSERT_NE(resourceAllocator, nullptr);

constexpr uint64_t kNumOfBuffers = 1000u;
Expand Down