Fix RHI constant binding and add sphere test

This commit is contained in:
2026-03-26 01:23:29 +08:00
parent c5605c2a32
commit 39edb0b497
17 changed files with 959 additions and 35 deletions

View File

@@ -493,3 +493,57 @@ TEST_P(RHITestFixture, DescriptorSet_Update_UsesBindingNumberOnOpenGL) {
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;
}