diff --git a/include/gpgmm_d3d12.h b/include/gpgmm_d3d12.h index 3fd09a75..f230be85 100644 --- a/include/gpgmm_d3d12.h +++ b/include/gpgmm_d3d12.h @@ -782,11 +782,12 @@ namespace gpgmm::d3d12 { */ RESOURCE_ALLOCATOR_FLAG_ALWAYS_IN_BUDGET = 0x2, - /** \brief Disables pre-fetching of GPU memory. + /** \brief Allow pre-fetching of resource heaps on background thread. - Should be only used for debugging and testing purposes. + Allows GPGMM to trigger prefetching based on heurstics. Prefetching enables more + performance when allocating for contiguous allocations or many resources of the same size. */ - RESOURCE_ALLOCATOR_FLAG_DISABLE_PREFETCH = 0x4, + RESOURCE_ALLOCATOR_FLAG_ALLOW_PREFETCH = 0x4, /** \brief Disables recycling of GPU memory. @@ -1057,12 +1058,9 @@ namespace gpgmm::d3d12 { */ ALLOCATION_FLAG_NEVER_SUBALLOCATE_HEAP = 0x4, - /** \brief Prefetch memory for the next resource allocation. + /** \brief Force pre-fetch for the next resource allocation. - The call to prefetch is deferred to a background thread by GPGMM which runs - when the current allocation requested is completed. By default, GPGMM will automatically - trigger prefetching based on heurstics. Prefetching enables more performance when - allocating for contiguous allocations or many resources of the same size. + This flag has no effect if RESOURCE_ALLOCATOR_FLAG_ALLOW_PREFETCH was not specified. Should not be used with ALLOCATION_FLAG_NEVER_ALLOCATE_HEAP. */ diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index 1e447980..41ee6b3d 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -772,7 +772,7 @@ namespace gpgmm::d3d12 { descriptor.ResourceHeapFragmentationLimit, descriptor.ResourceHeapGrowthFactor, /*allowSlabPrefetch*/ - !(descriptor.Flags & RESOURCE_ALLOCATOR_FLAG_DISABLE_PREFETCH), + (descriptor.Flags & RESOURCE_ALLOCATOR_FLAG_ALLOW_PREFETCH), std::move(pooledOrNonPooledAllocator)); } diff --git a/src/tests/capture_replay_tests/D3D12MemoryTraceReplay.cpp b/src/tests/capture_replay_tests/D3D12MemoryTraceReplay.cpp index 94d839f3..8e4afea1 100644 --- a/src/tests/capture_replay_tests/D3D12MemoryTraceReplay.cpp +++ b/src/tests/capture_replay_tests/D3D12MemoryTraceReplay.cpp @@ -204,8 +204,8 @@ class D3D12MemoryTraceReplay : public D3D12TestBase, public CaptureReplayTestWit baseAllocatorDesc.RecordOptions.EventScope = RECORD_SCOPE_PER_INSTANCE; } - if (!envParams.IsPrefetchAllowed) { - baseAllocatorDesc.Flags |= RESOURCE_ALLOCATOR_FLAG_DISABLE_PREFETCH; + if (envParams.IsPrefetchAllowed) { + baseAllocatorDesc.Flags |= RESOURCE_ALLOCATOR_FLAG_ALLOW_PREFETCH; } RESIDENCY_MANAGER_DESC baseResidencyDesc = CreateBasicResidencyDesc(); diff --git a/src/tests/end2end/D3D12ResidencyManagerTests.cpp b/src/tests/end2end/D3D12ResidencyManagerTests.cpp index a669cb66..c469ee17 100644 --- a/src/tests/end2end/D3D12ResidencyManagerTests.cpp +++ b/src/tests/end2end/D3D12ResidencyManagerTests.cpp @@ -42,8 +42,6 @@ class D3D12ResidencyManagerTests : public D3D12TestBase, public ::testing::Test RESOURCE_ALLOCATOR_DESC CreateBasicAllocatorDesc() const { RESOURCE_ALLOCATOR_DESC desc = D3D12TestBase::CreateBasicAllocatorDesc(); - // Disable pre-fetching since it will could cause over-committment unpredictably. - desc.Flags |= gpgmm::d3d12::RESOURCE_ALLOCATOR_FLAG_DISABLE_PREFETCH; // Require MakeResident/Evict occur near CreateResource, for debugging purposes. desc.Flags |= gpgmm::d3d12::RESOURCE_ALLOCATOR_FLAG_ALWAYS_IN_BUDGET; diff --git a/src/tests/end2end/D3D12ResourceAllocatorTests.cpp b/src/tests/end2end/D3D12ResourceAllocatorTests.cpp index 7d4539fd..057cfd01 100644 --- a/src/tests/end2end/D3D12ResourceAllocatorTests.cpp +++ b/src/tests/end2end/D3D12ResourceAllocatorTests.cpp @@ -65,10 +65,6 @@ class D3D12ResourceAllocatorTests : public D3D12TestBase, public ::testing::Test RESOURCE_ALLOCATOR_DESC CreateBasicAllocatorDesc() const { RESOURCE_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 |= RESOURCE_ALLOCATOR_FLAG_DISABLE_PREFETCH; - // Make sure leak detection is always enabled. desc.Flags |= gpgmm::d3d12::RESOURCE_ALLOCATOR_FLAG_NEVER_LEAK; @@ -1741,10 +1737,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferManyPrefetch) { GPGMM_SKIP_TEST_IF(true); #endif - // Prefetching is explicitly disabled but otherwise allowed, re-enable it by clearing the - // disable flag. RESOURCE_ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); - allocatorDesc.Flags ^= RESOURCE_ALLOCATOR_FLAG_DISABLE_PREFETCH; + allocatorDesc.Flags |= RESOURCE_ALLOCATOR_FLAG_ALLOW_PREFETCH; ComPtr resourceAllocator; ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, mDevice.Get(), mAdapter.Get(),