Files
XCEngine/tests/RHI/Vulkan/unit/test_pipeline_state.cpp

59 lines
1.9 KiB
C++

#if defined(XCENGINE_SUPPORT_VULKAN)
#include "fixtures/VulkanTestFixture.h"
#include "XCEngine/RHI/RHIPipelineState.h"
#include <cstring>
using namespace XCEngine::RHI;
namespace {
TEST_F(VulkanGraphicsFixture, CreateGraphicsPipelineFromGlslShadersProducesValidPipeline) {
static const char* vertexSource = R"(#version 450
layout(location = 0) in vec4 aPosition;
void main() {
gl_Position = aPosition;
}
)";
static const char* fragmentSource = R"(#version 450
layout(location = 0) out vec4 fragColor;
void main() {
fragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
)";
GraphicsPipelineDesc pipelineDesc = {};
pipelineDesc.topologyType = static_cast<uint32_t>(PrimitiveTopologyType::Triangle);
pipelineDesc.renderTargetFormats[0] = static_cast<uint32_t>(Format::R8G8B8A8_UNorm);
pipelineDesc.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;
pipelineDesc.inputLayout.elements.push_back(position);
pipelineDesc.vertexShader.sourceLanguage = ShaderLanguage::GLSL;
pipelineDesc.vertexShader.profile = L"vs_4_50";
pipelineDesc.vertexShader.source.assign(vertexSource, vertexSource + std::strlen(vertexSource));
pipelineDesc.fragmentShader.sourceLanguage = ShaderLanguage::GLSL;
pipelineDesc.fragmentShader.profile = L"fs_4_50";
pipelineDesc.fragmentShader.source.assign(fragmentSource, fragmentSource + std::strlen(fragmentSource));
RHIPipelineState* pipelineState = m_device->CreatePipelineState(pipelineDesc);
ASSERT_NE(pipelineState, nullptr);
EXPECT_TRUE(pipelineState->IsValid());
EXPECT_NE(pipelineState->GetNativeHandle(), nullptr);
pipelineState->Shutdown();
delete pipelineState;
}
} // namespace
#endif