#if defined(XCENGINE_SUPPORT_VULKAN) #include "fixtures/VulkanTestFixture.h" #include "XCEngine/RHI/RHIPipelineState.h" #include 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(PrimitiveTopologyType::Triangle); pipelineDesc.renderTargetFormats[0] = static_cast(Format::R8G8B8A8_UNorm); pipelineDesc.depthStencilFormat = static_cast(Format::Unknown); InputElementDesc position = {}; position.semanticName = "POSITION"; position.semanticIndex = 0; position.format = static_cast(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; } TEST_F(VulkanGraphicsFixture, CreateGraphicsPipelineFromHlslShadersProducesValidPipeline) { static const char* vertexSource = R"( float4 MainVS(uint vertexId : SV_VertexID) : SV_POSITION { const float x = (vertexId == 1u) ? 0.5f : -0.5f; const float y = (vertexId == 2u) ? -0.5f : 0.5f; return float4(x, y, 0.0f, 1.0f); } )"; static const char* fragmentSource = R"( float4 MainPS() : SV_TARGET { return float4(1.0f, 0.0f, 0.0f, 1.0f); } )"; GraphicsPipelineDesc pipelineDesc = {}; pipelineDesc.topologyType = static_cast(PrimitiveTopologyType::Triangle); pipelineDesc.renderTargetFormats[0] = static_cast(Format::R8G8B8A8_UNorm); pipelineDesc.depthStencilFormat = static_cast(Format::Unknown); pipelineDesc.vertexShader.sourceLanguage = ShaderLanguage::HLSL; pipelineDesc.vertexShader.entryPoint = L"MainVS"; pipelineDesc.vertexShader.profile = L"vs_5_0"; pipelineDesc.vertexShader.source.assign(vertexSource, vertexSource + std::strlen(vertexSource)); pipelineDesc.fragmentShader.sourceLanguage = ShaderLanguage::HLSL; pipelineDesc.fragmentShader.entryPoint = L"MainPS"; pipelineDesc.fragmentShader.profile = L"ps_5_0"; 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