在Unreal中,如何从插件访问材料的指令数



我正在Unreal中开发一个编辑器插件,需要访问材料的指令数。我在引擎代码中找到了编辑器通常执行此操作的位置。

\Engine\Source\Editor\MaterialEditor\Public\中的MaterialStatsCommon.h具有包含该类的类FMaterialStatsUtils。

/** class used for various stats utilities */
class FMaterialStatsUtils
{
public:
MATERIALEDITOR_API static void ExtractMatertialStatsInfo(struct FShaderStatsInfo& OutInfo, const FMaterialResource* Target);
};

这里的所有内容都是公共的,但FShaderStatsInfo是在MaterialStats.h中声明的,它在同一个模块中,但在一个私有文件夹中。

在我的插件中包含模块之后,使用这个函数就足够简单了。也就是说,只要我转发声明FShaderStatsInfo。然而,当我真的试图从我的插件中访问任何FShaderStatsInfo时,我不能,因为它说类型不完整,我实际上无法包括MaterialStats.h。

有没有围绕这一点,或者有不同的方式来访问材料上的相同内容?

我陷入困境的地方:

#include "MaterialStatsCommon.h"
struct FShaderStatsInfo;
void MyEditorBPLibraryName::GetMaterialStatsInfo(UMaterial* Material, int32 BasePassShaderInstructionCount, int32 VertexShaderInstructionCount, int32 TextureSampleCount)
{
if (Material == nullptr)
{
return;
}
FShaderStatsInfo* OutInfo = nullptr;
FMaterialStatsUtils::ExtractMatertialStatsInfo(*OutInfo, Material->GetMaterialResource(ERHIFeatureLevel::SM5, EMaterialQualityLevel::Num));
//OutInfo-> I needed ShaderInstructionCount from this struct, but can't access anything in it
return;
}

以及我需要在MaterialStats.h:中使用的结构

#include "MaterialStatsCommon.h"
#include "UObject/GCObject.h"
/** structure used to store various statistics extracted from compiled shaders */
struct FShaderStatsInfo
{
struct FContent
{
FString StrDescription;
FString StrDescriptionLong;
};
TMap<ERepresentativeShader, FContent> ShaderInstructionCount;
FContent SamplersCount;
FContent InterpolatorsCount;
FContent TextureSampleCount;
FContent VirtualTextureLookupCount;
FString StrShaderErrors;
void Reset()
{
ShaderInstructionCount.Empty();
SamplersCount.StrDescription = TEXT("Compiling...");
SamplersCount.StrDescriptionLong = TEXT("Compiling...");
InterpolatorsCount.StrDescription = TEXT("Compiling...");
InterpolatorsCount.StrDescriptionLong = TEXT("Compiling...");
TextureSampleCount.StrDescription = TEXT("Compiling...");
TextureSampleCount.StrDescriptionLong = TEXT("Compiling...");
VirtualTextureLookupCount.StrDescription = TEXT("Compiling...");
VirtualTextureLookupCount.StrDescriptionLong = TEXT("Compiling...");

StrShaderErrors.Empty();
}
void Empty()
{
ShaderInstructionCount.Empty();
SamplersCount.StrDescription.Empty();
SamplersCount.StrDescriptionLong.Empty();
InterpolatorsCount.StrDescription.Empty();
InterpolatorsCount.StrDescriptionLong.Empty();

TextureSampleCount.StrDescription.Empty();
TextureSampleCount.StrDescriptionLong.Empty();
VirtualTextureLookupCount.StrDescription.Empty();
VirtualTextureLookupCount.StrDescriptionLong.Empty();
StrShaderErrors.Empty();
}
bool HasErrors()
{
return !StrShaderErrors.IsEmpty();
}
};

对于统计数据本身,您可以使用:

FMaterialStatistics Stats = UMaterialEditingLibrary::GetStatistics(_YourMaterialInterfaceObject_);

最新更新