RHI: Add embedded shader source support via ShaderCompileDesc

- Add ShaderLanguage enum (HLSL, GLSL, SPIRV)
- Extend ShaderCompileDesc with source/sourceLanguage fields
- D3D12Device::CompileShader supports both file and embedded source
- OpenGLDevice::CompileShader supports embedded GLSL source
- Refactor test_shader.cpp to use embedded source for both backends

This enables consistent shader compilation across D3D12 and OpenGL
backends while maintaining backend-specific shader language support.
This commit is contained in:
2026-03-25 12:00:26 +08:00
parent 600892bbe2
commit 32c04b86b7
5 changed files with 178 additions and 45 deletions

View File

@@ -293,9 +293,17 @@ RHITexture* D3D12Device::CreateTexture(const TextureDesc& desc) {
RHIShader* D3D12Device::CompileShader(const ShaderCompileDesc& desc) {
auto* shader = new D3D12Shader();
if (shader->CompileFromFile(desc.fileName.c_str(),
reinterpret_cast<const char*>(desc.entryPoint.c_str()),
reinterpret_cast<const char*>(desc.profile.c_str()))) {
const char* entryPoint = desc.entryPoint.empty() ? nullptr : reinterpret_cast<const char*>(desc.entryPoint.c_str());
const char* profile = desc.profile.empty() ? nullptr : reinterpret_cast<const char*>(desc.profile.c_str());
bool success = false;
if (!desc.source.empty()) {
success = shader->Compile(desc.source.data(), desc.source.size(), entryPoint, profile);
} else if (!desc.fileName.empty()) {
success = shader->CompileFromFile(desc.fileName.c_str(), entryPoint, profile);
}
if (success) {
return shader;
}
delete shader;