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
2 changes: 1 addition & 1 deletion src/gpgmm/d3d12/ResidencySetD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace gpgmm { namespace d3d12 {
if (mSet.insert(heap).second) {
return S_OK;
}
return E_FAIL;
return S_FALSE;
}

HRESULT ResidencySet::Reset() {
Expand Down
18 changes: 16 additions & 2 deletions src/gpgmm/d3d12/ResidencySetD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,27 @@ namespace gpgmm { namespace d3d12 {

class Heap;

// Represents a set of heaps which are referenced by a command list.
// The set must be updated to ensure each heap is made resident for execution.
/** \brief Represents a set of heaps which are referenced by a command list.

The set must be updated to ensure each heap is made resident for execution.
*/
class GPGMM_EXPORT ResidencySet {
public:
/** \brief Create a residency set or collection of heaps to manage together for residency.
*/
ResidencySet() = default;

/** \brief Insert heap into this residency set.

@param heap A pointer to Heap about to be inserted.
\return S_OK if heap was inserted or S_FALSE if heap already exists, else error.
*/
HRESULT Insert(Heap* heap);

/** \brief Reset this residency set.

Removes all heaps in the set so the set can be re-used.
*/
HRESULT Reset();

std::set<Heap*>::iterator begin() const;
Expand Down
24 changes: 24 additions & 0 deletions src/tests/end2end/D3D12ResidencyManagerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,30 @@ class D3D12ResidencyManagerTests : public D3D12TestBase, public ::testing::Test
}
};

TEST_F(D3D12ResidencyManagerTests, CreateResidencySet) {
ComPtr<ResourceAllocator> resourceAllocator;
ASSERT_SUCCEEDED(ResourceAllocator::CreateAllocator(CreateBasicAllocatorDesc(),
&resourceAllocator, nullptr));

ComPtr<ResourceAllocation> allocation;
ASSERT_SUCCEEDED(resourceAllocator->CreateResource(
{}, CreateBasicBufferDesc(1), D3D12_RESOURCE_STATE_COMMON, nullptr, &allocation));

// Inserting a non-existant heap should always fail
{
ResidencySet set;
Heap* invalid = nullptr;
ASSERT_FAILED(set.Insert(invalid));
}

// Inserting from a valid allocation should always succeed.
{
ResidencySet set;
ASSERT_SUCCEEDED(set.Insert(allocation->GetMemory()));
ASSERT_SUCCEEDED(set.Insert(allocation->GetMemory()));
}
}

TEST_F(D3D12ResidencyManagerTests, CreateResidencyManager) {
ComPtr<ResidencyManager> residencyManager;
ComPtr<ResourceAllocator> resourceAllocator;
Expand Down