fix(rhi): make opengl descriptor binding set-aware

This commit is contained in:
2026-03-26 15:10:03 +08:00
parent 9218ea20b5
commit 733b573963
8 changed files with 379 additions and 21 deletions

View File

@@ -122,10 +122,10 @@ MatrixBufferData CreateMatrixBufferData() {
}
const char kSphereHlsl[] = R"(
Texture2D gDiffuseTexture : register(t0);
SamplerState gSampler : register(s0);
Texture2D gDiffuseTexture : register(t1);
SamplerState gSampler : register(s1);
cbuffer MatrixBuffer : register(b0) {
cbuffer MatrixBuffer : register(b1) {
float4x4 gProjectionMatrix;
float4x4 gViewMatrix;
float4x4 gModelMatrix;
@@ -159,7 +159,7 @@ const char kSphereVertexShader[] = R"(#version 430
layout(location = 0) in vec4 aPosition;
layout(location = 1) in vec2 aTexCoord;
layout(std140, binding = 0) uniform MatrixBuffer {
layout(std140, binding = 1) uniform MatrixBuffer {
mat4 gProjectionMatrix;
mat4 gViewMatrix;
mat4 gModelMatrix;
@@ -176,7 +176,7 @@ void main() {
)";
const char kSphereFragmentShader[] = R"(#version 430
layout(binding = 0) uniform sampler2D uTexture;
layout(binding = 1) uniform sampler2D uTexture;
in vec2 vTexCoord;
@@ -454,8 +454,24 @@ void SphereTest::InitializeSphereResources() {
ASSERT_NE(mSamplerSet, nullptr);
mSamplerSet->UpdateSampler(0, mSampler);
DescriptorSetLayoutBinding reservedSetBindings[3] = {};
reservedSetBindings[0].binding = 0;
reservedSetBindings[0].type = static_cast<uint32_t>(DescriptorType::CBV);
reservedSetBindings[0].count = 1;
reservedSetBindings[1].binding = 0;
reservedSetBindings[1].type = static_cast<uint32_t>(DescriptorType::SRV);
reservedSetBindings[1].count = 1;
reservedSetBindings[2].binding = 0;
reservedSetBindings[2].type = static_cast<uint32_t>(DescriptorType::Sampler);
reservedSetBindings[2].count = 1;
DescriptorSetLayoutDesc reservedLayoutDesc = {};
reservedLayoutDesc.bindings = reservedSetBindings;
reservedLayoutDesc.bindingCount = 3;
DescriptorSetLayoutDesc setLayouts[kSphereDescriptorSetCount] = {};
// Reserve set0 so the integration test exercises non-zero firstSet binding.
// Reserve slot0 so the bound sets land on binding point 1 for every descriptor class.
setLayouts[0] = reservedLayoutDesc;
setLayouts[1] = constantLayoutDesc;
setLayouts[2] = textureLayoutDesc;
setLayouts[3] = samplerLayoutDesc;