Skip to content

Commit

Permalink
Remove Usage of std::set in ResidencySet
Browse files Browse the repository at this point in the history
Removes usage of std::set in ResidencySet and replaces it with a vector.
This does allow duplicat heaps to be inserted into the ResidencySet,
however insertion will be O(1) instead of O(log(n)) and instead we can
easily identify duplicate heaps by checking their last used fence value
when when they are iterated.
  • Loading branch information
bjjones committed Jul 29, 2022
1 parent 29ec121 commit d639981
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/gpgmm/d3d12/ResidencyManagerD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,12 @@ namespace gpgmm::d3d12 {
continue;
}

// ResidencySet can contain duplicates. We can skip them by checking if the heap's last
// used fence is the same as the current one.
if (heap->GetLastUsedFenceValue() == mFence->GetCurrentFence()) {
continue;
}

if (heap->IsInResidencyLRUCache()) {
// If the heap is already in the LRU, we must remove it and append again below to
// update its position in the LRU.
Expand Down
11 changes: 5 additions & 6 deletions src/gpgmm/d3d12/ResidencySetD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,21 @@ namespace gpgmm::d3d12 {
if (pHeap == nullptr) {
return E_INVALIDARG;
}
if (mSet.insert(pHeap).second) {
return S_OK;
}
return S_FALSE;

mSet.push_back(pHeap);
return S_OK;
}

HRESULT ResidencySet::Reset() {
mSet.clear();
return S_OK;
}

ResidencySet::UnderlyingType::iterator ResidencySet::begin() const {
ResidencySet::UnderlyingType::const_iterator ResidencySet::begin() const {
return mSet.begin();
}

ResidencySet::UnderlyingType::iterator ResidencySet::end() const {
ResidencySet::UnderlyingType::const_iterator ResidencySet::end() const {
return mSet.end();
}

Expand Down
8 changes: 4 additions & 4 deletions src/gpgmm/d3d12/ResidencySetD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "gpgmm/d3d12/d3d12_platform.h"
#include "include/gpgmm_export.h"

#include <set>
#include <vector>

namespace gpgmm::d3d12 {

Expand Down Expand Up @@ -60,10 +60,10 @@ namespace gpgmm::d3d12 {
*/
HRESULT Reset();

using UnderlyingType = std::set<Heap*>;
using UnderlyingType = std::vector<Heap*>;

UnderlyingType::iterator begin() const;
UnderlyingType::iterator end() const;
UnderlyingType::const_iterator begin() const;
UnderlyingType::const_iterator end() const;

private:
const char* GetTypename() const;
Expand Down
2 changes: 1 addition & 1 deletion src/tests/end2end/D3D12ResidencyManagerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ TEST_F(D3D12ResidencyManagerTests, CreateResidencySet) {
ResidencySet setA;
ASSERT_SUCCEEDED(setA.Insert(allocation->GetMemory()));
ResidencySet setB(setA);
EXPECT_EQ(setA.Insert(allocation->GetMemory()), S_FALSE);
EXPECT_EQ(setA.Insert(allocation->GetMemory()), S_OK);
ResidencySet setC;
EXPECT_EQ(setC.Insert(allocation->GetMemory()), S_OK);
}
Expand Down

0 comments on commit d639981

Please sign in to comment.