Add pipeline layout support for graphics PSOs

This commit is contained in:
2026-03-25 23:49:48 +08:00
parent 83cd2fa591
commit 605ef56e16
8 changed files with 166 additions and 16 deletions

View File

@@ -1,4 +1,5 @@
#include "fixtures/RHITestFixture.h"
#include "XCEngine/RHI/RHIPipelineLayout.h"
#include "XCEngine/RHI/RHIPipelineState.h"
#include <cstring>
@@ -248,3 +249,92 @@ void main() {
pso->Shutdown();
delete pso;
}
TEST_P(RHITestFixture, PipelineState_Create_WithPipelineLayout) {
RHIPipelineLayoutDesc layoutDesc = {};
layoutDesc.textureCount = 1;
layoutDesc.samplerCount = 1;
RHIPipelineLayout* layout = GetDevice()->CreatePipelineLayout(layoutDesc);
ASSERT_NE(layout, nullptr);
ASSERT_NE(layout->GetNativeHandle(), nullptr);
GraphicsPipelineDesc desc = {};
desc.pipelineLayout = layout;
desc.topologyType = static_cast<uint32_t>(PrimitiveTopologyType::Triangle);
desc.renderTargetFormats[0] = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
desc.depthStencilFormat = static_cast<uint32_t>(Format::Unknown);
InputElementDesc position = {};
position.semanticName = "POSITION";
position.semanticIndex = 0;
position.format = static_cast<uint32_t>(Format::R32G32B32A32_Float);
position.inputSlot = 0;
position.alignedByteOffset = 0;
desc.inputLayout.elements.push_back(position);
if (GetBackendType() == RHIType::D3D12) {
const char* hlslSource = R"(
struct VSInput {
float4 position : POSITION;
};
struct PSInput {
float4 position : SV_POSITION;
};
PSInput MainVS(VSInput input) {
PSInput output;
output.position = input.position;
return output;
}
float4 MainPS(PSInput input) : SV_TARGET {
return float4(1.0f, 0.0f, 0.0f, 1.0f);
}
)";
desc.vertexShader.source.assign(hlslSource, hlslSource + std::strlen(hlslSource));
desc.vertexShader.entryPoint = L"MainVS";
desc.vertexShader.profile = L"vs_5_0";
desc.vertexShader.sourceLanguage = ShaderLanguage::HLSL;
desc.fragmentShader.source.assign(hlslSource, hlslSource + std::strlen(hlslSource));
desc.fragmentShader.entryPoint = L"MainPS";
desc.fragmentShader.profile = L"ps_5_0";
desc.fragmentShader.sourceLanguage = ShaderLanguage::HLSL;
} else {
const char* vertexSource = R"(#version 430
layout(location = 0) in vec4 aPosition;
void main() {
gl_Position = aPosition;
}
)";
const char* fragmentSource = R"(#version 430
layout(location = 0) out vec4 fragColor;
void main() {
fragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
)";
desc.vertexShader.source.assign(vertexSource, vertexSource + std::strlen(vertexSource));
desc.vertexShader.sourceLanguage = ShaderLanguage::GLSL;
desc.vertexShader.profile = L"vs_4_30";
desc.fragmentShader.source.assign(fragmentSource, fragmentSource + std::strlen(fragmentSource));
desc.fragmentShader.sourceLanguage = ShaderLanguage::GLSL;
desc.fragmentShader.profile = L"fs_4_30";
}
RHIPipelineState* pso = GetDevice()->CreatePipelineState(desc);
ASSERT_NE(pso, nullptr);
EXPECT_TRUE(pso->IsValid());
EXPECT_NE(pso->GetNativeHandle(), nullptr);
pso->Shutdown();
delete pso;
layout->Shutdown();
delete layout;
}