Files
XCEngine/docs/api/rhi/device/compile-shader.md

36 lines
822 B
Markdown
Raw Normal View History

# RHIDevice::CompileShader
```cpp
virtual RHIShader* CompileShader(const ShaderCompileDesc& desc) = 0;
```
编译着色器程序。
**参数:**
- `desc` - 着色器编译描述符,包含入口点、配置文件、源文件等
**返回:** 新创建的着色器指针,失败返回 `nullptr`
**复杂度:** O(n) - 取决于着色器代码复杂度
**示例:**
```cpp
ShaderCompileDesc shaderDesc;
shaderDesc.entryPoint = L"main";
shaderDesc.profile = L"vs_6_0";
shaderDesc.fileName = L"shaders/vertex.hlsl";
shaderDesc.macros = {};
RHIShader* vertexShader = device->CompileShader(shaderDesc);
if (!vertexShader->IsValid()) {
// 处理编译错误
vertexShader->Shutdown();
}
```
## 相关文档
- [RHIDevice 总览](device.md) - 返回类总览
- [RHIShader](../shader/shader.md) - 着色器类