Split backend-specific RHI unit tests
This commit is contained in:
@@ -1,15 +1,11 @@
|
||||
#include "fixtures/RHITestFixture.h"
|
||||
#include "XCEngine/RHI/D3D12/D3D12DescriptorSet.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLDescriptorSet.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLDevice.h"
|
||||
#include "XCEngine/RHI/RHIDescriptorPool.h"
|
||||
#include "XCEngine/RHI/RHIDescriptorSet.h"
|
||||
#include "XCEngine/RHI/RHISampler.h"
|
||||
#include "XCEngine/RHI/RHIResourceView.h"
|
||||
#include "XCEngine/RHI/RHITexture.h"
|
||||
|
||||
#include <glad/glad.h>
|
||||
|
||||
using namespace XCEngine::RHI;
|
||||
|
||||
TEST_P(RHITestFixture, DescriptorSet_Allocate_Basic) {
|
||||
@@ -406,243 +402,3 @@ TEST_P(RHITestFixture, DescriptorSet_MultipleAllocations_AdvanceDescriptorOffset
|
||||
pool->Shutdown();
|
||||
delete pool;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, DescriptorSet_D3D12MixedBindings_AssignDescriptorIndicesByType) {
|
||||
if (GetBackendType() != RHIType::D3D12) {
|
||||
GTEST_SKIP() << "D3D12-specific descriptor index verification";
|
||||
}
|
||||
|
||||
DescriptorPoolDesc poolDesc = {};
|
||||
poolDesc.type = DescriptorHeapType::CBV_SRV_UAV;
|
||||
poolDesc.descriptorCount = 4;
|
||||
poolDesc.shaderVisible = true;
|
||||
|
||||
RHIDescriptorPool* pool = GetDevice()->CreateDescriptorPool(poolDesc);
|
||||
ASSERT_NE(pool, nullptr);
|
||||
|
||||
DescriptorSetLayoutBinding bindings[3] = {};
|
||||
bindings[0].binding = 2;
|
||||
bindings[0].type = static_cast<uint32_t>(DescriptorType::UAV);
|
||||
bindings[0].count = 1;
|
||||
bindings[1].binding = 0;
|
||||
bindings[1].type = static_cast<uint32_t>(DescriptorType::CBV);
|
||||
bindings[1].count = 1;
|
||||
bindings[2].binding = 1;
|
||||
bindings[2].type = static_cast<uint32_t>(DescriptorType::SRV);
|
||||
bindings[2].count = 1;
|
||||
|
||||
DescriptorSetLayoutDesc layoutDesc = {};
|
||||
layoutDesc.bindings = bindings;
|
||||
layoutDesc.bindingCount = 3;
|
||||
|
||||
RHIDescriptorSet* firstSet = pool->AllocateSet(layoutDesc);
|
||||
RHIDescriptorSet* secondSet = pool->AllocateSet(layoutDesc);
|
||||
ASSERT_NE(firstSet, nullptr);
|
||||
ASSERT_NE(secondSet, nullptr);
|
||||
|
||||
auto* firstD3D12Set = static_cast<D3D12DescriptorSet*>(firstSet);
|
||||
auto* secondD3D12Set = static_cast<D3D12DescriptorSet*>(secondSet);
|
||||
EXPECT_EQ(firstD3D12Set->GetCount(), 2u);
|
||||
EXPECT_EQ(firstD3D12Set->GetDescriptorIndexForBinding(1), 0u);
|
||||
EXPECT_EQ(firstD3D12Set->GetDescriptorIndexForBinding(2), 1u);
|
||||
EXPECT_EQ(firstD3D12Set->GetDescriptorIndexForBinding(0), UINT32_MAX);
|
||||
EXPECT_EQ(firstD3D12Set->GetOffset(), 0u);
|
||||
EXPECT_EQ(secondD3D12Set->GetOffset(), 2u);
|
||||
|
||||
firstSet->Shutdown();
|
||||
delete firstSet;
|
||||
secondSet->Shutdown();
|
||||
delete secondSet;
|
||||
pool->Shutdown();
|
||||
delete pool;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, DescriptorSet_D3D12MultipleConstantBuffersUploadIndependently) {
|
||||
if (GetBackendType() != RHIType::D3D12) {
|
||||
GTEST_SKIP() << "D3D12-specific constant buffer verification";
|
||||
}
|
||||
|
||||
DescriptorPoolDesc poolDesc = {};
|
||||
poolDesc.type = DescriptorHeapType::CBV_SRV_UAV;
|
||||
poolDesc.descriptorCount = 1;
|
||||
poolDesc.shaderVisible = false;
|
||||
|
||||
RHIDescriptorPool* pool = GetDevice()->CreateDescriptorPool(poolDesc);
|
||||
ASSERT_NE(pool, nullptr);
|
||||
|
||||
DescriptorSetLayoutBinding bindings[2] = {};
|
||||
bindings[0].binding = 0;
|
||||
bindings[0].type = static_cast<uint32_t>(DescriptorType::CBV);
|
||||
bindings[0].count = 1;
|
||||
bindings[1].binding = 1;
|
||||
bindings[1].type = static_cast<uint32_t>(DescriptorType::CBV);
|
||||
bindings[1].count = 1;
|
||||
|
||||
DescriptorSetLayoutDesc layoutDesc = {};
|
||||
layoutDesc.bindings = bindings;
|
||||
layoutDesc.bindingCount = 2;
|
||||
|
||||
RHIDescriptorSet* set = pool->AllocateSet(layoutDesc);
|
||||
ASSERT_NE(set, nullptr);
|
||||
|
||||
auto* d3d12Set = static_cast<D3D12DescriptorSet*>(set);
|
||||
const float firstData[16] = { 1.0f, 0.0f, 0.0f, 0.0f };
|
||||
const float secondData[16] = { 2.0f, 0.0f, 0.0f, 0.0f };
|
||||
d3d12Set->WriteConstant(0, firstData, sizeof(firstData));
|
||||
d3d12Set->WriteConstant(1, secondData, sizeof(secondData));
|
||||
|
||||
ASSERT_TRUE(d3d12Set->UploadConstantBuffer(0));
|
||||
ASSERT_TRUE(d3d12Set->UploadConstantBuffer(1));
|
||||
|
||||
const D3D12_GPU_VIRTUAL_ADDRESS firstAddress = d3d12Set->GetConstantBufferGPUAddress(0);
|
||||
const D3D12_GPU_VIRTUAL_ADDRESS secondAddress = d3d12Set->GetConstantBufferGPUAddress(1);
|
||||
EXPECT_NE(firstAddress, 0u);
|
||||
EXPECT_NE(secondAddress, 0u);
|
||||
EXPECT_NE(firstAddress, secondAddress);
|
||||
|
||||
set->Shutdown();
|
||||
delete set;
|
||||
pool->Shutdown();
|
||||
delete pool;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, DescriptorSet_Update_UsesBindingNumberOnOpenGL) {
|
||||
if (GetBackendType() != RHIType::OpenGL) {
|
||||
GTEST_SKIP() << "OpenGL-specific descriptor binding verification";
|
||||
}
|
||||
|
||||
auto* openGLDevice = static_cast<OpenGLDevice*>(GetDevice());
|
||||
ASSERT_NE(openGLDevice, nullptr);
|
||||
ASSERT_TRUE(openGLDevice->MakeContextCurrent());
|
||||
|
||||
DescriptorPoolDesc poolDesc = {};
|
||||
poolDesc.type = DescriptorHeapType::CBV_SRV_UAV;
|
||||
poolDesc.descriptorCount = 8;
|
||||
poolDesc.shaderVisible = true;
|
||||
|
||||
RHIDescriptorPool* pool = GetDevice()->CreateDescriptorPool(poolDesc);
|
||||
ASSERT_NE(pool, nullptr);
|
||||
|
||||
TextureDesc textureDesc = {};
|
||||
textureDesc.width = 1;
|
||||
textureDesc.height = 1;
|
||||
textureDesc.depth = 1;
|
||||
textureDesc.mipLevels = 1;
|
||||
textureDesc.arraySize = 1;
|
||||
textureDesc.format = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
|
||||
textureDesc.textureType = static_cast<uint32_t>(TextureType::Texture2D);
|
||||
textureDesc.sampleCount = 1;
|
||||
|
||||
const uint8_t pixel[4] = { 255, 255, 255, 255 };
|
||||
RHITexture* texture = GetDevice()->CreateTexture(textureDesc, pixel, sizeof(pixel), 4);
|
||||
ASSERT_NE(texture, nullptr);
|
||||
|
||||
ResourceViewDesc srvDesc = {};
|
||||
srvDesc.format = textureDesc.format;
|
||||
srvDesc.dimension = ResourceViewDimension::Texture2D;
|
||||
RHIResourceView* srv = GetDevice()->CreateShaderResourceView(texture, srvDesc);
|
||||
ASSERT_NE(srv, nullptr);
|
||||
|
||||
DescriptorSetLayoutBinding bindings[2] = {};
|
||||
bindings[0].binding = 3;
|
||||
bindings[0].type = static_cast<uint32_t>(DescriptorType::SRV);
|
||||
bindings[0].count = 1;
|
||||
bindings[1].binding = 7;
|
||||
bindings[1].type = static_cast<uint32_t>(DescriptorType::SRV);
|
||||
bindings[1].count = 1;
|
||||
|
||||
DescriptorSetLayoutDesc layoutDesc = {};
|
||||
layoutDesc.bindings = bindings;
|
||||
layoutDesc.bindingCount = 2;
|
||||
|
||||
RHIDescriptorSet* set = pool->AllocateSet(layoutDesc);
|
||||
ASSERT_NE(set, nullptr);
|
||||
|
||||
auto* openGLSet = static_cast<OpenGLDescriptorSet*>(set);
|
||||
const uint32_t untouchedUnit = openGLSet->GetBindingPoint(3);
|
||||
const uint32_t updatedUnit = openGLSet->GetBindingPoint(7);
|
||||
ASSERT_NE(untouchedUnit, updatedUnit);
|
||||
|
||||
set->Update(7, srv);
|
||||
set->Bind();
|
||||
|
||||
GLint updatedTexture = 0;
|
||||
glActiveTexture(GL_TEXTURE0 + updatedUnit);
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &updatedTexture);
|
||||
EXPECT_EQ(static_cast<unsigned int>(updatedTexture), static_cast<unsigned int>(reinterpret_cast<uintptr_t>(srv->GetNativeHandle())));
|
||||
|
||||
GLint untouchedTexture = 0;
|
||||
glActiveTexture(GL_TEXTURE0 + untouchedUnit);
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &untouchedTexture);
|
||||
EXPECT_EQ(untouchedTexture, 0);
|
||||
|
||||
set->Unbind();
|
||||
|
||||
GLint unboundTexture = 0;
|
||||
glActiveTexture(GL_TEXTURE0 + updatedUnit);
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &unboundTexture);
|
||||
EXPECT_EQ(unboundTexture, 0);
|
||||
|
||||
set->Shutdown();
|
||||
delete set;
|
||||
srv->Shutdown();
|
||||
delete srv;
|
||||
texture->Shutdown();
|
||||
delete texture;
|
||||
pool->Shutdown();
|
||||
delete pool;
|
||||
}
|
||||
|
||||
TEST_P(RHITestFixture, DescriptorSet_BindConstantBuffer_UsesBindingNumberOnOpenGL) {
|
||||
if (GetBackendType() != RHIType::OpenGL) {
|
||||
GTEST_SKIP() << "OpenGL-specific constant buffer binding verification";
|
||||
}
|
||||
|
||||
auto* openGLDevice = static_cast<OpenGLDevice*>(GetDevice());
|
||||
ASSERT_NE(openGLDevice, nullptr);
|
||||
ASSERT_TRUE(openGLDevice->MakeContextCurrent());
|
||||
|
||||
DescriptorPoolDesc poolDesc = {};
|
||||
poolDesc.type = DescriptorHeapType::CBV_SRV_UAV;
|
||||
poolDesc.descriptorCount = 1;
|
||||
poolDesc.shaderVisible = false;
|
||||
|
||||
RHIDescriptorPool* pool = GetDevice()->CreateDescriptorPool(poolDesc);
|
||||
ASSERT_NE(pool, nullptr);
|
||||
|
||||
DescriptorSetLayoutBinding binding = {};
|
||||
binding.binding = 3;
|
||||
binding.type = static_cast<uint32_t>(DescriptorType::CBV);
|
||||
binding.count = 1;
|
||||
|
||||
DescriptorSetLayoutDesc layoutDesc = {};
|
||||
layoutDesc.bindings = &binding;
|
||||
layoutDesc.bindingCount = 1;
|
||||
|
||||
RHIDescriptorSet* set = pool->AllocateSet(layoutDesc);
|
||||
ASSERT_NE(set, nullptr);
|
||||
|
||||
const float matrixData[16] = {
|
||||
1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f,
|
||||
};
|
||||
set->WriteConstant(3, matrixData, sizeof(matrixData));
|
||||
set->Bind();
|
||||
|
||||
GLint boundBuffer = 0;
|
||||
glGetIntegeri_v(GL_UNIFORM_BUFFER_BINDING, 3, &boundBuffer);
|
||||
EXPECT_NE(boundBuffer, 0);
|
||||
|
||||
set->Unbind();
|
||||
|
||||
GLint unboundBuffer = -1;
|
||||
glGetIntegeri_v(GL_UNIFORM_BUFFER_BINDING, 3, &unboundBuffer);
|
||||
EXPECT_EQ(unboundBuffer, 0);
|
||||
|
||||
set->Shutdown();
|
||||
delete set;
|
||||
pool->Shutdown();
|
||||
delete pool;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user