diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index f4e4fa916..f12899eff 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -411,10 +411,11 @@ namespace gpgmm { namespace d3d12 { ResidencyManager::CreateResidencyManager(residencyDesc, &residencyManager)); } - *resourceAllocatorOut = - new ResourceAllocator(newDescriptor, residencyManager, std::move(caps)); - - GPGMM_TRACE_EVENT_OBJECT_SNAPSHOT(*resourceAllocatorOut, newDescriptor); + if (resourceAllocatorOut != nullptr) { + *resourceAllocatorOut = + new ResourceAllocator(newDescriptor, residencyManager, std::move(caps)); + GPGMM_TRACE_EVENT_OBJECT_SNAPSHOT(*resourceAllocatorOut, newDescriptor); + } if (residencyManagerOut != nullptr) { *residencyManagerOut = residencyManager.Detach(); diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h index 9ed6bc9cc..f6db723a2 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h @@ -383,12 +383,10 @@ namespace gpgmm { namespace d3d12 { @param descriptor A reference to ALLOCATOR_DESC structure that describes the allocator. @param[out] resourceAllocatorOut Pointer to a memory block that recieves a pointer to the resource allocator. Pass NULL to test if allocator creation would succeed, but not actually - create the allocator. If NULL is passed and allocator creating would succeed, S_FALSE is - returned. + create the allocator. @param[out] residencyManagerOut Pointer to a memory block that recieves a pointer to the - residency manager. Pass NULL to test if residency manager creation would succeed, but not - actually create the residency manager. If NULL is passed and residency manager creation - would succeed, S_FALSE is returned. + residency manager. If NULL is passed, the allocator will be created without using + residency for resources. */ static HRESULT CreateAllocator(const ALLOCATOR_DESC& descriptor, ResourceAllocator** resourceAllocatorOut, diff --git a/src/tests/D3D12Test.h b/src/tests/D3D12Test.h index 96d6a4a1b..7b1416a47 100644 --- a/src/tests/D3D12Test.h +++ b/src/tests/D3D12Test.h @@ -22,6 +22,9 @@ #define ASSERT_FAILED(expr) ASSERT_TRUE(FAILED(expr)) #define ASSERT_SUCCEEDED(expr) ASSERT_TRUE(SUCCEEDED(expr)) +#define EXPECT_FAILED(expr) EXPECT_TRUE(FAILED(expr)) +#define EXPECT_SUCCEEDED(expr) EXPECT_TRUE(SUCCEEDED(expr)) + namespace gpgmm { namespace d3d12 { struct ALLOCATOR_DESC; diff --git a/src/tests/end2end/D3D12ResourceAllocatorTests.cpp b/src/tests/end2end/D3D12ResourceAllocatorTests.cpp index 2ced4224c..e6b60fb26 100644 --- a/src/tests/end2end/D3D12ResourceAllocatorTests.cpp +++ b/src/tests/end2end/D3D12ResourceAllocatorTests.cpp @@ -41,7 +41,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateAllocator) { // Creating an invalid allocator should always fail. { ComPtr resourceAllocator; - ASSERT_FAILED(ResourceAllocator::CreateAllocator({}, &resourceAllocator)); + EXPECT_FAILED(ResourceAllocator::CreateAllocator({}, &resourceAllocator)); EXPECT_EQ(resourceAllocator, nullptr); } @@ -51,24 +51,27 @@ TEST_F(D3D12ResourceAllocatorTests, CreateAllocator) { desc.Device = nullptr; ComPtr resourceAllocator; - ASSERT_FAILED(ResourceAllocator::CreateAllocator(desc, &resourceAllocator)); + EXPECT_FAILED(ResourceAllocator::CreateAllocator(desc, &resourceAllocator)); EXPECT_EQ(resourceAllocator, nullptr); } + // Creating a NULL allocator should always succeed. + EXPECT_SUCCEEDED(ResourceAllocator::CreateAllocator(CreateBasicAllocatorDesc(), nullptr)); + // Creating an allocator without an adapter should always fail. { ALLOCATOR_DESC desc = CreateBasicAllocatorDesc(); desc.Adapter = nullptr; ComPtr resourceAllocator; - ASSERT_FAILED(ResourceAllocator::CreateAllocator(desc, &resourceAllocator)); + EXPECT_FAILED(ResourceAllocator::CreateAllocator(desc, &resourceAllocator)); EXPECT_EQ(resourceAllocator, nullptr); } // Creating a new allocator using the defaults should always succeed. { ComPtr resourceAllocator; - ASSERT_SUCCEEDED( + EXPECT_SUCCEEDED( ResourceAllocator::CreateAllocator(CreateBasicAllocatorDesc(), &resourceAllocator)); EXPECT_NE(resourceAllocator, nullptr); } @@ -81,7 +84,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateAllocator) { desc.MaxResourceHeapSize = kDefaultBufferSize / 2; ComPtr resourceAllocator; - ASSERT_FAILED(ResourceAllocator::CreateAllocator(desc, &resourceAllocator)); + EXPECT_FAILED(ResourceAllocator::CreateAllocator(desc, &resourceAllocator)); EXPECT_EQ(resourceAllocator, nullptr); } }