Files
XCEngine/tests/RHI/D3D12/unit/test_descriptor_heap.cpp

128 lines
4.9 KiB
C++
Raw Normal View History

#include "fixtures/D3D12TestFixture.h"
#include "XCEngine/RHI/D3D12/D3D12DescriptorHeap.h"
using namespace XCEngine::RHI;
TEST_F(D3D12TestFixture, DescriptorHeap_Wrapper_Initialize_RTV) {
D3D12DescriptorHeap heap;
bool result = heap.Initialize(GetDevice(), DescriptorHeapType::RTV, 4);
ASSERT_TRUE(result);
EXPECT_EQ(heap.GetDescriptorCount(), 4u);
EXPECT_EQ(heap.GetType(), DescriptorHeapType::RTV);
heap.Shutdown();
}
TEST_F(D3D12TestFixture, DescriptorHeap_Wrapper_GetCPUDescriptorHandle) {
D3D12DescriptorHeap heap;
ASSERT_TRUE(heap.Initialize(GetDevice(), DescriptorHeapType::RTV, 4));
uint32_t descriptorSize = heap.GetDescriptorSize();
CPUDescriptorHandle handle0 = heap.GetCPUDescriptorHandle(0);
CPUDescriptorHandle handle1 = heap.GetCPUDescriptorHandle(1);
CPUDescriptorHandle handle2 = heap.GetCPUDescriptorHandle(2);
EXPECT_EQ(handle1.ptr - handle0.ptr, descriptorSize);
EXPECT_EQ(handle2.ptr - handle1.ptr, descriptorSize);
heap.Shutdown();
}
TEST_F(D3D12TestFixture, DescriptorHeap_Wrapper_GetGPUDescriptorHandle) {
D3D12DescriptorHeap heap;
ASSERT_TRUE(heap.Initialize(GetDevice(), DescriptorHeapType::CBV_SRV_UAV, 4, true));
uint32_t descriptorSize = heap.GetDescriptorSize();
GPUDescriptorHandle handle0 = heap.GetGPUDescriptorHandle(0);
GPUDescriptorHandle handle1 = heap.GetGPUDescriptorHandle(1);
EXPECT_EQ(handle1.ptr - handle0.ptr, descriptorSize);
heap.Shutdown();
}
TEST_F(D3D12TestFixture, DescriptorHeap_Wrapper_GetDescriptorSize) {
D3D12DescriptorHeap rtvHeap;
ASSERT_TRUE(rtvHeap.Initialize(GetDevice(), DescriptorHeapType::RTV, 4));
EXPECT_GT(rtvHeap.GetDescriptorSize(), 0u);
D3D12DescriptorHeap cbvHeap;
ASSERT_TRUE(cbvHeap.Initialize(GetDevice(), DescriptorHeapType::CBV_SRV_UAV, 4));
EXPECT_GT(cbvHeap.GetDescriptorSize(), 0u);
}
TEST_F(D3D12TestFixture, DescriptorHeap_Wrapper_Shutdown) {
D3D12DescriptorHeap heap;
ASSERT_TRUE(heap.Initialize(GetDevice(), DescriptorHeapType::RTV, 2));
heap.Shutdown();
}
TEST_F(D3D12TestFixture, DescriptorHeap_Create_CBV_SRV_UAV) {
D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
heapDesc.NumDescriptors = 10;
heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
ComPtr<ID3D12DescriptorHeap> descriptorHeap;
HRESULT hr = GetDevice()->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&descriptorHeap));
ASSERT_HRESULT_SUCCEEDED(hr);
ASSERT_NE(descriptorHeap.Get(), nullptr);
D3D12_DESCRIPTOR_HEAP_DESC desc = descriptorHeap->GetDesc();
EXPECT_EQ(desc.Type, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
EXPECT_EQ(desc.NumDescriptors, 10);
}
TEST_F(D3D12TestFixture, DescriptorHeap_Create_Sampler) {
D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER;
heapDesc.NumDescriptors = 5;
heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
ComPtr<ID3D12DescriptorHeap> descriptorHeap;
HRESULT hr = GetDevice()->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&descriptorHeap));
ASSERT_HRESULT_SUCCEEDED(hr);
D3D12_DESCRIPTOR_HEAP_DESC desc = descriptorHeap->GetDesc();
EXPECT_EQ(desc.Type, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
}
TEST_F(D3D12TestFixture, DescriptorHeap_Create_RTV) {
D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
heapDesc.NumDescriptors = 4;
heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
ComPtr<ID3D12DescriptorHeap> descriptorHeap;
HRESULT hr = GetDevice()->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&descriptorHeap));
ASSERT_HRESULT_SUCCEEDED(hr);
D3D12_DESCRIPTOR_HEAP_DESC desc = descriptorHeap->GetDesc();
EXPECT_EQ(desc.Type, D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
}
TEST_F(D3D12TestFixture, DescriptorHeap_Create_DSV) {
D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV;
heapDesc.NumDescriptors = 2;
heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
ComPtr<ID3D12DescriptorHeap> descriptorHeap;
HRESULT hr = GetDevice()->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&descriptorHeap));
ASSERT_HRESULT_SUCCEEDED(hr);
D3D12_DESCRIPTOR_HEAP_DESC desc = descriptorHeap->GetDesc();
EXPECT_EQ(desc.Type, D3D12_DESCRIPTOR_HEAP_TYPE_DSV);
}
TEST_F(D3D12TestFixture, DescriptorHeap_Get_HandleIncrementSize) {
UINT cbvSrvUavSize = GetDevice()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
UINT samplerSize = GetDevice()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER);
UINT rtvSize = GetDevice()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
UINT dsvSize = GetDevice()->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV);
EXPECT_GT(cbvSrvUavSize, 0);
EXPECT_GT(samplerSize, 0);
EXPECT_GT(rtvSize, 0);
EXPECT_GT(dsvSize, 0);
}