135 lines
		
	
	
		
			8.9 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
		
		
			
		
	
	
			135 lines
		
	
	
		
			8.9 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
| 
								 | 
							
								---
							 | 
						|||
| 
								 | 
							
								title: 使用Fastbuild加快UnrealEngine编译速度
							 | 
						|||
| 
								 | 
							
								date: 2021-11-09 22:34:16
							 | 
						|||
| 
								 | 
							
								excerpt: 
							 | 
						|||
| 
								 | 
							
								tags: FastBuild
							 | 
						|||
| 
								 | 
							
								rating: ⭐
							 | 
						|||
| 
								 | 
							
								---
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								# 使用Fastbuild加快UnrealEngine编译速度
							 | 
						|||
| 
								 | 
							
								如果你有多台电脑或者服务器就可以使用FastBuild提高编译速度。虽然最后测试法线,i7-7700+一台几年前的e5 40核心服务器依然比不过今年买的枪神5笔记本。
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								如果你完全按照 https://zhuanlan.zhihu.com/p/158400394 的教程来操作,那你就被坑了。目前Fastbuild的最新版本与UE是不兼容的。很可能会出现寻找的目录与FastBuild创建的目录不一致的问题。以下是本人的log:
							 | 
						|||
| 
								 | 
							
								```
							 | 
						|||
| 
								 | 
							
								已启动生成…
							 | 
						|||
| 
								 | 
							
								1>------ 已启动生成: 项目: UE4, 配置: Development_Editor x64 ------
							 | 
						|||
| 
								 | 
							
								1>Building UE4Editor and ShaderCompileWorker...
							 | 
						|||
| 
								 | 
							
								1>Using Visual Studio 2019 14.29.30136 toolchain (D:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133) and Windows 10.0.19041.0 SDK (D:\Windows Kits\10).
							 | 
						|||
| 
								 | 
							
								1>Detected build type as Windows from 'D:\UnrealEngine\UnrealEngine4.27\Engine\Build\Windows\cl-filter\cl-filter.exe' using search term 'Windows'
							 | 
						|||
| 
								 | 
							
								1>Using path : {D:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC/Redist/MSVC\14.29.30133} for vccorlib_.dll (MSVC redist)...
							 | 
						|||
| 
								 | 
							
								1>	...Add an entry for MsvcCRTRedistVersion in BuildConfiguration.xml to specify a version number
							 | 
						|||
| 
								 | 
							
								1>FBuild Command Line Arguments: '-monitor -summary -dist -cacheread -ide -clean -config "D:\UnrealEngine\UnrealEngine4.27\Engine\Intermediate\Build\fbuild.bff" -nostoponerror
							 | 
						|||
| 
								 | 
							
								1>BFF file 'D:\UnrealEngine\UnrealEngine4.27\Engine\Intermediate\Build\fbuild.bff' has changed (reparsing will occur).
							 | 
						|||
| 
								 | 
							
								1>Using brokerage folder
							 | 
						|||
| 
								 | 
							
								1>No workers found in '\\DESKTOP-QI1GP15\FastBuildBroker\main\20.windows\'
							 | 
						|||
| 
								 | 
							
								1>No workers available - Distributed compilation disabled
							 | 
						|||
| 
								 | 
							
								```
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								## 操作步骤
							 | 
						|||
| 
								 | 
							
								上述问题是因为当前使用的FastBuild协议版本与UE4所需的不同造成的,所以你需要使用EPIC定制的FastBuild。本人使用Win10与UnrelEngine4.27.0源码版目前正确的操作步骤如下:
							 | 
						|||
| 
								 | 
							
								1. 使用源码目录`Engine\Extras\ThirdPartyNotUE\FASTBuild\Win64\`下的FastBuild。指定一个不含用中文路径的目录。
							 | 
						|||
| 
								 | 
							
								2. 在该目录中再新建一个名为`FBuild`的文件夹,并将3个文件复制进去。这一步是可选步骤,是为了兼容`FBDashboard.exe`。你可以去FastBuild官网下载,并且指定目录下。(只需要复制FBDashboard.exe,放在FBuild外面)
							 | 
						|||
| 
								 | 
							
								3. 创建共享文件夹。添加当前用户与Everyone用户权限为读/写。之后再用其他电脑访问一次,能进入并且写文件就完成了。(只需要其中一台电脑or服务器创建共享文件夹即可,其他所有机器都会使用这个共享文件夹)
							 | 
						|||
| 
								 | 
							
								4. 添加环境变量FASTBUILD_BROKERAGE_PATH,内容为共享文件夹的网络路径,比如`\\DESKTOP-QI1GP15\FastBuildBroker`;Path变量添加FBuild.exe所在目录,之后在CMD中输入FBuild,运行后提示`Failed to open BFF 'fbuild.bff'`就代表添加成功了。
							 | 
						|||
| 
								 | 
							
								5. 在其他电脑与服务器上执行上述步骤。
							 | 
						|||
| 
								 | 
							
								6. 添加编译配置。给`Engine\Saved\UnrealBuildTool\BuildConfiguration.xml`添加`bAllowFASTBuild`配置为true。
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								比如这样:
							 | 
						|||
| 
								 | 
							
								```xml
							 | 
						|||
| 
								 | 
							
								<?xml version="1.0" encoding="utf-8" ?>
							 | 
						|||
| 
								 | 
							
								<Configuration xmlns="https://www.unrealengine.com/BuildConfiguration">
							 | 
						|||
| 
								 | 
							
								    <BuildConfiguration>
							 | 
						|||
| 
								 | 
							
								        <bAllowFASTBuild>true</bAllowFASTBuild>
							 | 
						|||
| 
								 | 
							
								    </BuildConfiguration>
							 | 
						|||
| 
								 | 
							
								</Configuration>
							 | 
						|||
| 
								 | 
							
								```
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								## 共享问题
							 | 
						|||
| 
								 | 
							
								你很可能会遇到无法打开共享或是网络发现的功能,下面我分享以下解决方法。测试系统:win10、win2012 r2。
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								1. 关闭win防火墙。
							 | 
						|||
| 
								 | 
							
								2. 在控制面板-程序-启动或者关闭服务器功能中,确保安装了SMB 1.0/CIFS 文件共享支持下的所有功能。
							 | 
						|||
| 
								 | 
							
								3. 运行services.msc,启动Computer Browser服务并将启动方式设置为自动。将下列服务启动并将启动方式设置为自动(延迟启动):Function Discovery Provider Host、Function Discovery Resource Publication、Network Connections、UPnP Device Host。
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								## 其他注意点
							 | 
						|||
| 
								 | 
							
								`江湖小辈`教程中使用FastBuild源码版是为了做测试以及通过修改源代码来实现通过Ip来代替计算机名来寻找共享。如果你想使用最新版本就需要修改FastBuild源码中的`distributed protocol version`。本人没有试过,但应该是这样没错。
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								对于团队来说添加Shader编译也许必须的,所以还可能修改UBT代码。(可以参考《腾讯游戏开发精粹》一书的对应章节)但记住在修改完UBT代码后,需要重新编译UBT。 调试UBT的话,需要在UBT工程上右键-属性-调试页面中,将配置设为Debug,之后添加命行参数,之后在Debug模式下就可以命中断点了。编译UE4源码命令行如下:
							 | 
						|||
| 
								 | 
							
								```
							 | 
						|||
| 
								 | 
							
								UE4Editor Win64 Development -Quiet -WaitMutex -FromMsBuild
							 | 
						|||
| 
								 | 
							
								```
							 | 
						|||
| 
								 | 
							
								对于在家办公想要使用公司服务器进行编译,使用反向代理+OpenConnect应该是可行的,只要带宽足够。
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								## 编译配置
							 | 
						|||
| 
								 | 
							
								是一个名为`BuildConfiguration.xml`的xml文件,用于控制编译。除了可以在项目`Config/UnrealBuildTool`中添加外。UBT还会从以下位置(Windows系统)的XML配置文件读取设置:
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								- Engine/Saved/UnrealBuildTool/BuildConfiguration.xml - 针对特定引擎版本。
							 | 
						|||
| 
								 | 
							
								- User Folder/AppData/Roaming/Unreal Engine/UnrealBuildTool/BuildConfiguration.xml
							 | 
						|||
| 
								 | 
							
								- My Documents/Unreal Engine/UnrealBuildTool/BuildConfiguration.xml - 适用于所有已安装的引擎版本。
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								除了上文中说到的bAllowFASTBuild外,因为本人使用附带git信息的引擎源码,编译时UBT会先去读取git信息,但因为源码git信息量太大,非常浪费时间。这里可以添加
							 | 
						|||
| 
								 | 
							
								```xml
							 | 
						|||
| 
								 | 
							
								<SourceFileWorkingSet> 
							 | 
						|||
| 
								 | 
							
								    <Provider>None</Provider> 
							 | 
						|||
| 
								 | 
							
								    <RepositoryPath></RepositoryPath> 
							 | 
						|||
| 
								 | 
							
								    <GitPath></GitPath> 
							 | 
						|||
| 
								 | 
							
								</SourceFileWorkingSet>
							 | 
						|||
| 
								 | 
							
								```
							 | 
						|||
| 
								 | 
							
								起到让UBT禁用“使用 'git status' 来确定AdaptiveUnityBuild。下面介绍一下其他参数,完整参数请去官方文档参考。
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								### LocalExecutor
							 | 
						|||
| 
								 | 
							
								- ProcessorCountMultiplier:本地执行的处理器计数乘数。设为小于1可为其他任务保留CPU。使用本地执行器(非XGE)时,在每个CPU核心上运行单一操作。注意: 可将该属性设为较大的值,在多数情况下可稍微提高编译速度,但电脑在编译期间的响应速度将变慢。
							 | 
						|||
| 
								 | 
							
								- MaxProcessorCount:本地执行的最大处理器数量。
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								### ParallelExecutor
							 | 
						|||
| 
								 | 
							
								- MaxProcessorCount:本地执行的最大处理器数量。
							 | 
						|||
| 
								 | 
							
								- ProcessorCountMultiplier:本地执行的处理器计数乘数。设为小于1可为其他任务保留CPU。
							 | 
						|||
| 
								 | 
							
								- bStopCompilationAfterErrors:启用时,将在发生编译错误后停止编译目标。
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								我在查看了AnswerHUB看到有人分享了自己的配置:
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								查阅代码之后发现,这些配置选项要去看 BuildConfigProperties.INT.udn 里的参数,ProcessorCountMultiplier 是在 ParallelExecutor 下的,所以改成以下配置:
							 | 
						|||
| 
								 | 
							
								```xml
							 | 
						|||
| 
								 | 
							
								<?xml version="1.0" encoding="utf-8" ?>
							 | 
						|||
| 
								 | 
							
								<Configuration xmlns="https://www.unrealengine.com/BuildConfiguration">
							 | 
						|||
| 
								 | 
							
								  <ParallelExecutor>
							 | 
						|||
| 
								 | 
							
								    <ProcessorCountMultiplier>7</ProcessorCountMultiplier>
							 | 
						|||
| 
								 | 
							
								    <MaxProcessorCount>7</MaxProcessorCount>
							 | 
						|||
| 
								 | 
							
								    <bStopCompilationAfterErrors>true</bStopCompilationAfterErrors>
							 | 
						|||
| 
								 | 
							
								  </ParallelExecutor>
							 | 
						|||
| 
								 | 
							
								</Configuration>
							 | 
						|||
| 
								 | 
							
								```
							 | 
						|||
| 
								 | 
							
								目前我使用的完整配置:
							 | 
						|||
| 
								 | 
							
								```xml
							 | 
						|||
| 
								 | 
							
								<?xml version="1.0" encoding="utf-8" ?>
							 | 
						|||
| 
								 | 
							
								<Configuration xmlns="https://www.unrealengine.com/BuildConfiguration">
							 | 
						|||
| 
								 | 
							
								  <BuildConfiguration>
							 | 
						|||
| 
								 | 
							
								    <ProcessorCountMultiplier>7</ProcessorCountMultiplier>
							 | 
						|||
| 
								 | 
							
								    <MaxParallelActions>7</MaxParallelActions>
							 | 
						|||
| 
								 | 
							
								    <bAllowParallelExecutor>true</bAllowParallelExecutor>
							 | 
						|||
| 
								 | 
							
								  </BuildConfiguration>
							 | 
						|||
| 
								 | 
							
								  <SNDBS>
							 | 
						|||
| 
								 | 
							
								    <ProcessorCountMultiplier>4</ProcessorCountMultiplier>
							 | 
						|||
| 
								 | 
							
								    <MaxProcessorCount>4</MaxProcessorCount>
							 | 
						|||
| 
								 | 
							
								  </SNDBS>
							 | 
						|||
| 
								 | 
							
								  <ParallelExecutor>
							 | 
						|||
| 
								 | 
							
								    <ProcessorCountMultiplier>7</ProcessorCountMultiplier>
							 | 
						|||
| 
								 | 
							
								    <MaxProcessorCount>7</MaxProcessorCount>
							 | 
						|||
| 
								 | 
							
								    <bStopCompilationAfterErrors>true</bStopCompilationAfterErrors>
							 | 
						|||
| 
								 | 
							
								  </ParallelExecutor>
							 | 
						|||
| 
								 | 
							
								</Configuration>
							 | 
						|||
| 
								 | 
							
								```
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								### FASTBuild
							 | 
						|||
| 
								 | 
							
								- FBuildExecutablePath:用于指定 fbuild.exe 的位置(如果发布的二进制文件未使用)
							 | 
						|||
| 
								 | 
							
								- bEnableDistribution:控制网络构建分布(network build distribution)
							 | 
						|||
| 
								 | 
							
								- FBuildBrokeragePath:用于指定中间件的位置。如为null,则FASTBuild退回检查FASTBUILD_BROKERAGE_PATH
							 | 
						|||
| 
								 | 
							
								- bEnableCaching:控制是否使用缓存。仅当该选项启用后,CachePath和FASTCacheMode才会相关。
							 | 
						|||
| 
								 | 
							
								- CacheMode:缓存访问模式 - 仅当bEnableCaching为真时相关;
							 | 
						|||
| 
								 | 
							
								- FBuildCachePath:用于指定缓存的位置。如为null,FASTBuild会退回检查FASTBUILD_CACHE_PATH
							 | 
						|||
| 
								 | 
							
								- bForceRemote:是否强制远程
							 | 
						|||
| 
								 | 
							
								- bStopOnError:是否在错误上停止
							 | 
						|||
| 
								 | 
							
								- MsvcCRTRedistVersion:使用哪个MSVC CRT Redist版本
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								## UnityBuild
							 | 
						|||
| 
								 | 
							
								- bUseAdaptiveUnityBuild:使用启发式方法来确定哪些文件目前正在被迭代,并将它们从unity blobs中排除,从而加快增量编译的时间。目前的实现使用只读标志来区分工作集,假设文件正在被修改,源码控制系统将使其可写。这对Perforce是正确的,但对Git不是。
							 |