2025-08-02 12:09:34 +08:00
|
|
|
|
---
|
|
|
|
|
|
title: PSO Precache机制笔记
|
|
|
|
|
|
date: 2025-02-08 20:42:16
|
|
|
|
|
|
excerpt:
|
|
|
|
|
|
tags:
|
|
|
|
|
|
rating: ⭐
|
|
|
|
|
|
---
|
|
|
|
|
|
# 前言
|
2025-10-23 21:57:16 +08:00
|
|
|
|
- 视频
|
2025-10-23 22:54:41 +08:00
|
|
|
|
- [Unreal Engine 5: Setup Precompiling Shaders (Bundled PSO's)](https://www.youtube.com/watch?v=NVoXDgXKS5k)
|
|
|
|
|
|
- [Unreal Engine 5: Show Number Of Compiling Shaders](https://www.youtube.com/watch?v=8h1k2ViADgU)
|
2025-10-23 21:57:16 +08:00
|
|
|
|
- 文章
|
|
|
|
|
|
- [UE5.3] PSO Cache&PreCache 源码阅读:https://zhuanlan.zhihu.com/p/679832250
|
|
|
|
|
|
- [UE5.3] PSO Cache&PreCache 源码阅读(二):https://zhuanlan.zhihu.com/p/681803986
|
|
|
|
|
|
- Unreal Engine 5.2 MeshPass拓展:https://zhuanlan.zhihu.com/p/671423486
|
|
|
|
|
|
- 优化UE5的PSO卡顿:FileCache,PreCache和异步PSO https://zhuanlan.zhihu.com/p/1898646962561094034
|
2025-10-23 22:54:41 +08:00
|
|
|
|
|
|
|
|
|
|
# BundledPSO
|
2025-10-24 15:40:29 +08:00
|
|
|
|
- 相关启动参数
|
2025-10-23 22:54:41 +08:00
|
|
|
|
- -logPSO
|
|
|
|
|
|
- -clearPSODriverCache
|
2025-10-24 15:40:29 +08:00
|
|
|
|
- 需要添加的配置
|
2025-10-24 00:00:08 +08:00
|
|
|
|
- RendererSettings
|
|
|
|
|
|
- r.ShaderPipelineCache.Enable=1
|
|
|
|
|
|
- DevOptions.Shaders
|
|
|
|
|
|
- NeedsSHaderStableKeys=true
|
|
|
|
|
|
- /Script/UnrealEd.ProjectPackagingSettings
|
|
|
|
|
|
- bShareMaterialShaderCode=True
|
|
|
|
|
|
- bSharedMaterialNativeLibraries=True
|
2025-10-23 22:54:41 +08:00
|
|
|
|
|
2025-10-24 16:22:02 +08:00
|
|
|
|
## 大致步骤
|
|
|
|
|
|
1. 可选:使用快捷方式 -clearPSODriverCache,清空PSO。
|
|
|
|
|
|
2. 添加上述配置。
|
2025-10-24 19:12:40 +08:00
|
|
|
|
3. 执行Launch打包并且启动项目。
|
2025-10-27 12:14:24 +08:00
|
|
|
|
4. 收集打包PSO:完成后可以在Saved/Metadata/PipelineCaches/找到打包的PSO文件,将其复制出来。
|
|
|
|
|
|
5. 收集RuntimePSO:运行打包后的项目,跑测后在Saved/CollectedPSOs可以找到Runtime PSO文件,将其复制出来。
|
|
|
|
|
|
6. 将所有收集的PSO放到一个制定的文件夹里,比如项目目录下PSOCollection,进行CommandLet`ShaderPipelineCacheTools`,之后会生成制定名称的spc文件。
|
|
|
|
|
|
7. 回到打包后的项目在指定平台的目录文件夹(在项目的Build文件夹下的Windows、Android)中新建文件夹PipelineCaches,并将spc文件放入。
|
|
|
|
|
|
8. 重新使用Launch打包,完成后可以在log中知道spc文件中 pso数量。
|
2025-10-24 16:22:02 +08:00
|
|
|
|
|
2025-10-27 12:14:24 +08:00
|
|
|
|
## 将收集的PSO打包进Pak中
|
|
|
|
|
|
```bash
|
|
|
|
|
|
Engine\Binaries\Win64\UnrealEditor-Cmd.exe -run=ShaderPipelineCacheTools expand #Run ShaderPipelineCacheTools with expand optionl
|
|
|
|
|
|
Project\PSOCollection\*.rec.upipelinecache #Use all .rec.upipelinecache files
|
|
|
|
|
|
Project\PSOCollection\*.shk #Use all .shk files
|
|
|
|
|
|
Project\PSOCollection\PSO_SKGZombies_PCD3D_SM6.spc # Output PSO to be bundled
|
|
|
|
|
|
|
|
|
|
|
|
cmd /k #保证CMD开启
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
"D:\UnrealEngine\UE_5.6\Engine\Binaries\Win64\UnrealEditor-Cmd.exe" -run=ShaderPipelineCacheTools expand "D:\Project\Demo\PSOCollection\*.rec.upipelinecache" "D:\Project\Demo\PSOCollection\*.shk" "D:\Project\Demo\PSOCollection\PSO_Demo_PCD3D_SM6.spc"
|
|
|
|
|
|
```
|
2025-08-02 12:09:34 +08:00
|
|
|
|
# 执行链
|
|
|
|
|
|
- FGraphEventArray UPrimitiveComponent::PrecachePSOs()
|
|
|
|
|
|
- void UMaterialInterface::InitDefaultMaterials()
|
|
|
|
|
|
- UMaterial::PrecachePSOs
|
|
|
|
|
|
|
|
|
|
|
|
UMaterial::PrecachePSOs => **MaterialResource->CollectPSOs()** => PrecacheMaterialPSOs() => PrecachePSOs() => CollectPSOs() => CollectPSOInitializers()
|
|
|
|
|
|
|
|
|
|
|
|
# CollectPSOInitializers()
|
|
|
|
|
|
接口IPSOCollector::CollectPSOInitializers()
|
|
|
|
|
|
|
|
|
|
|
|
## 其他MeshProcessor实现
|
|
|
|
|
|
|