【问题标题】:In Unreal, how can I access the instruction count of a material from a plugin?在 Unreal 中,如何从插件访问材质的指令数?
【发布时间】:2022-09-24 10:13:56
【问题描述】:

我正在 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();
    }
};

    标签: c++ game-development unreal-engine4


    【解决方案1】:

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

    FMaterialStatistics Stats = UMaterialEditingLibrary::GetStatistics(_YourMaterialInterfaceObject_);
    

    【讨论】:

      猜你喜欢
      • 2020-02-23
      • 2016-11-16
      • 2022-09-29
      • 2019-01-07
      • 1970-01-01
      • 2019-02-04
      • 1970-01-01
      • 2018-02-11
      • 1970-01-01
      相关资源
      最近更新 更多