You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#jira none #rb zach.bethel #preflight 62573bf61543022eed4bc2aa [CL 19746250 by christopher waters in ue5-main branch]
269 lines
11 KiB
C++
269 lines
11 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
/*=============================================================================
|
|
DebugViewModeRendering.h: Contains definitions for rendering debug viewmodes.
|
|
=============================================================================*/
|
|
|
|
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "ShaderParameters.h"
|
|
#include "Shader.h"
|
|
#include "GlobalShader.h"
|
|
#include "ShaderParameterUtils.h"
|
|
#include "MeshMaterialShaderType.h"
|
|
#include "MeshMaterialShader.h"
|
|
#include "ShaderBaseClasses.h"
|
|
#include "MeshPassProcessor.h"
|
|
#include "DebugViewModeInterface.h"
|
|
#include "GPUSkinCache.h"
|
|
#include "SceneRenderTargetParameters.h"
|
|
|
|
class FPrimitiveSceneProxy;
|
|
struct FMeshBatchElement;
|
|
struct FMeshDrawingRenderState;
|
|
class FDebugViewModeInterface;
|
|
|
|
static const int32 NumStreamingAccuracyColors = 5;
|
|
static const int32 NumLODColorationColors = 8;
|
|
static const float UndefinedStreamingAccuracyIntensity = .015f;
|
|
|
|
BEGIN_GLOBAL_SHADER_PARAMETER_STRUCT(FDebugViewModeUniformParameters, )
|
|
SHADER_PARAMETER_ARRAY(FLinearColor, AccuracyColors, [NumStreamingAccuracyColors])
|
|
SHADER_PARAMETER_ARRAY(FLinearColor, LODColors, [NumLODColorationColors])
|
|
END_GLOBAL_SHADER_PARAMETER_STRUCT()
|
|
|
|
BEGIN_GLOBAL_SHADER_PARAMETER_STRUCT(FDebugViewModePassUniformParameters, )
|
|
SHADER_PARAMETER_STRUCT(FSceneTextureUniformParameters, SceneTextures)
|
|
SHADER_PARAMETER_STRUCT(FDebugViewModeUniformParameters, DebugViewMode)
|
|
SHADER_PARAMETER_RDG_TEXTURE_UAV(RWTexture2D<uint>, QuadOverdraw)
|
|
END_GLOBAL_SHADER_PARAMETER_STRUCT()
|
|
|
|
#if WITH_DEBUG_VIEW_MODES
|
|
|
|
void SetupDebugViewModePassUniformBufferConstants(const FViewInfo& ViewInfo, FDebugViewModeUniformParameters& Parameters);
|
|
TRDGUniformBufferRef<FDebugViewModePassUniformParameters> CreateDebugViewModePassUniformBuffer(FRDGBuilder& GraphBuilder, const FViewInfo& View, FRDGTextureRef QuadOverdrawTexture);
|
|
|
|
/** Returns the RT index where the QuadOverdrawUAV will be bound. */
|
|
extern int32 GetQuadOverdrawUAVIndex(EShaderPlatform Platform, ERHIFeatureLevel::Type FeatureLevel);
|
|
|
|
class FDebugViewModeShaderElementData : public FMeshMaterialShaderElementData
|
|
{
|
|
public:
|
|
|
|
FDebugViewModeShaderElementData(
|
|
const FMaterialRenderProxy& InMaterialRenderProxy,
|
|
const FMaterial& InMaterial,
|
|
EDebugViewShaderMode InDebugViewMode,
|
|
const FVector& InViewOrigin,
|
|
int32 InVisualizeLODIndex,
|
|
const FColor& InSkinCacheDebugColor,
|
|
int32 InViewModeParam,
|
|
const FName& InViewModeParamName)
|
|
: MaterialRenderProxy(InMaterialRenderProxy)
|
|
, Material(InMaterial)
|
|
, DebugViewMode(InDebugViewMode)
|
|
, ViewOrigin(InViewOrigin)
|
|
, VisualizeLODIndex(InVisualizeLODIndex)
|
|
, SkinCacheDebugColor(InSkinCacheDebugColor)
|
|
, ViewModeParam(InViewModeParam)
|
|
, ViewModeParamName(InViewModeParamName)
|
|
, NumVSInstructions(0)
|
|
, NumPSInstructions(0)
|
|
{}
|
|
|
|
const FMaterialRenderProxy& MaterialRenderProxy;
|
|
const FMaterial& Material;
|
|
|
|
EDebugViewShaderMode DebugViewMode;
|
|
FVector ViewOrigin;
|
|
int32 VisualizeLODIndex;
|
|
FColor SkinCacheDebugColor;
|
|
int32 ViewModeParam;
|
|
FName ViewModeParamName;
|
|
|
|
int32 NumVSInstructions;
|
|
int32 NumPSInstructions;
|
|
};
|
|
|
|
/**
|
|
* Vertex shader for quad overdraw. Required because overdraw shaders need to have SV_Position as first PS interpolant.
|
|
*/
|
|
class FDebugViewModeVS : public FMeshMaterialShader
|
|
{
|
|
DECLARE_SHADER_TYPE(FDebugViewModeVS,MeshMaterial);
|
|
protected:
|
|
|
|
FDebugViewModeVS() = default;
|
|
FDebugViewModeVS(const FMeshMaterialShaderType::CompiledShaderInitializerType& Initializer)
|
|
: FMeshMaterialShader(Initializer)
|
|
{}
|
|
|
|
public:
|
|
|
|
static bool ShouldCompilePermutation(const FMeshMaterialShaderPermutationParameters& Parameters);
|
|
|
|
void GetShaderBindings(
|
|
const FScene* Scene,
|
|
ERHIFeatureLevel::Type FeatureLevel,
|
|
const FPrimitiveSceneProxy* PrimitiveSceneProxy,
|
|
const FMaterialRenderProxy& MaterialRenderProxy,
|
|
const FMaterial& Material,
|
|
const FMeshPassProcessorRenderState& DrawRenderState,
|
|
const FDebugViewModeShaderElementData& ShaderElementData,
|
|
FMeshDrawSingleShaderBindings& ShaderBindings) const
|
|
{
|
|
FMeshMaterialShader::GetShaderBindings(Scene, FeatureLevel, PrimitiveSceneProxy, MaterialRenderProxy, Material, DrawRenderState, ShaderElementData, ShaderBindings);
|
|
}
|
|
|
|
static void SetCommonDefinitions(const FMaterialShaderPermutationParameters& Parameters, FShaderCompilerEnvironment& OutEnvironment)
|
|
{
|
|
// SM4 has less input interpolants. Also instanced meshes use more interpolants.
|
|
if (Parameters.MaterialParameters.bIsDefaultMaterial || (IsFeatureLevelSupported(Parameters.Platform, ERHIFeatureLevel::SM5) && !Parameters.MaterialParameters.bIsUsedWithInstancedStaticMeshes))
|
|
{ // Force the default material to pass enough texcoords to the pixel shaders (even though not using them).
|
|
// This is required to allow material shaders to have access to the sampled coords.
|
|
OutEnvironment.SetDefine(TEXT("MIN_MATERIAL_TEXCOORDS"), (uint32)4);
|
|
}
|
|
else // Otherwise still pass at minimum amount to have debug shader using a texcoord to work (material might not use any).
|
|
{
|
|
OutEnvironment.SetDefine(TEXT("MIN_MATERIAL_TEXCOORDS"), (uint32)2);
|
|
}
|
|
|
|
}
|
|
|
|
static void ModifyCompilationEnvironment(const FMaterialShaderPermutationParameters& Parameters, FShaderCompilerEnvironment& OutEnvironment)
|
|
{
|
|
SetCommonDefinitions(Parameters, OutEnvironment);
|
|
FMeshMaterialShader::ModifyCompilationEnvironment(Parameters, OutEnvironment);
|
|
}
|
|
};
|
|
|
|
class FDebugViewModePS : public FMeshMaterialShader
|
|
{
|
|
public:
|
|
DECLARE_SHADER_TYPE(FDebugViewModePS, MeshMaterial);
|
|
|
|
FDebugViewModePS() = default;
|
|
FDebugViewModePS(const FMeshMaterialShaderType::CompiledShaderInitializerType& Initializer)
|
|
: FMeshMaterialShader(Initializer)
|
|
{
|
|
OneOverCPUTexCoordScalesParameter.Bind(Initializer.ParameterMap, TEXT("OneOverCPUTexCoordScales"));
|
|
TexCoordIndicesParameter.Bind(Initializer.ParameterMap, TEXT("TexCoordIndices"));
|
|
CPUTexelFactorParameter.Bind(Initializer.ParameterMap, TEXT("CPUTexelFactor"));
|
|
NormalizedComplexity.Bind(Initializer.ParameterMap, TEXT("NormalizedComplexity"));
|
|
AnalysisParamsParameter.Bind(Initializer.ParameterMap, TEXT("AnalysisParams"));
|
|
PrimitiveAlphaParameter.Bind(Initializer.ParameterMap, TEXT("PrimitiveAlpha"));
|
|
TexCoordAnalysisIndexParameter.Bind(Initializer.ParameterMap, TEXT("TexCoordAnalysisIndex"));
|
|
CPULogDistanceParameter.Bind(Initializer.ParameterMap, TEXT("CPULogDistance"));
|
|
ShowQuadOverdraw.Bind(Initializer.ParameterMap, TEXT("bShowQuadOverdraw"));
|
|
OutputQuadOverdrawParameter.Bind(Initializer.ParameterMap, TEXT("bOutputQuadOverdraw"));
|
|
LODIndexParameter.Bind(Initializer.ParameterMap, TEXT("LODIndex"));
|
|
SkinCacheDebugColorParameter.Bind(Initializer.ParameterMap, TEXT("SkinCacheDebugColor"));
|
|
VisualizeModeParameter.Bind(Initializer.ParameterMap, TEXT("VisualizeMode"));
|
|
QuadBufferUAV.Bind(Initializer.ParameterMap, TEXT("RWQuadBuffer"));
|
|
}
|
|
|
|
static bool ShouldCompilePermutation(const FMeshMaterialShaderPermutationParameters& Parameters);
|
|
|
|
static void ModifyCompilationEnvironment(const FMaterialShaderPermutationParameters& Parameters, FShaderCompilerEnvironment& OutEnvironment)
|
|
{
|
|
OutEnvironment.SetDefine(TEXT("UNDEFINED_ACCURACY"), UndefinedStreamingAccuracyIntensity);
|
|
OutEnvironment.SetDefine(TEXT("MAX_NUM_TEX_COORD"), (uint32)TEXSTREAM_MAX_NUM_UVCHANNELS);
|
|
OutEnvironment.SetDefine(TEXT("INITIAL_GPU_SCALE"), (uint32)TEXSTREAM_INITIAL_GPU_SCALE);
|
|
OutEnvironment.SetDefine(TEXT("TILE_RESOLUTION"), (uint32)TEXSTREAM_TILE_RESOLUTION);
|
|
OutEnvironment.SetDefine(TEXT("MAX_NUM_TEXTURE_REGISTER"), (uint32)TEXSTREAM_MAX_NUM_TEXTURES_PER_MATERIAL);
|
|
OutEnvironment.SetDefine(TEXT("SCENE_TEXTURES_DISABLED"), 1u);
|
|
TCHAR BufferRegister[] = { 'u', '0', 0 };
|
|
BufferRegister[1] += GetQuadOverdrawUAVIndex(Parameters.Platform, Parameters.MaterialParameters.FeatureLevel);
|
|
OutEnvironment.SetDefine(TEXT("QUAD_BUFFER_REGISTER"), BufferRegister);
|
|
OutEnvironment.SetDefine(TEXT("OUTPUT_QUAD_OVERDRAW"), 1);
|
|
|
|
for (int i = 0; i < DVSM_MAX; ++i)
|
|
{
|
|
OutEnvironment.SetDefine(DebugViewShaderModeToString(static_cast<EDebugViewShaderMode>(i)), i);
|
|
}
|
|
|
|
FMeshMaterialShader::ModifyCompilationEnvironment(Parameters, OutEnvironment);
|
|
}
|
|
|
|
void GetElementShaderBindings(
|
|
const FShaderMapPointerTable& PointerTable,
|
|
const FScene* Scene,
|
|
const FSceneView* ViewIfDynamicMeshCommand,
|
|
const FVertexFactory* VertexFactory,
|
|
const EVertexInputStreamType InputStreamType,
|
|
ERHIFeatureLevel::Type FeatureLevel,
|
|
const FPrimitiveSceneProxy* PrimitiveSceneProxy,
|
|
const FMeshBatch& MeshBatch,
|
|
const FMeshBatchElement& BatchElement,
|
|
const FDebugViewModeShaderElementData& ShaderElementData,
|
|
FMeshDrawSingleShaderBindings& ShaderBindings,
|
|
FVertexInputStreamArray& VertexStreams) const;
|
|
|
|
LAYOUT_FIELD(FShaderParameter, OneOverCPUTexCoordScalesParameter);
|
|
LAYOUT_FIELD(FShaderParameter, TexCoordIndicesParameter);
|
|
LAYOUT_FIELD(FShaderParameter, CPUTexelFactorParameter);
|
|
LAYOUT_FIELD(FShaderParameter, NormalizedComplexity);
|
|
LAYOUT_FIELD(FShaderParameter, AnalysisParamsParameter);
|
|
LAYOUT_FIELD(FShaderParameter, PrimitiveAlphaParameter);
|
|
LAYOUT_FIELD(FShaderParameter, TexCoordAnalysisIndexParameter);
|
|
LAYOUT_FIELD(FShaderParameter, CPULogDistanceParameter);
|
|
LAYOUT_FIELD(FShaderParameter, ShowQuadOverdraw);
|
|
LAYOUT_FIELD(FShaderParameter, LODIndexParameter);
|
|
LAYOUT_FIELD(FShaderParameter, SkinCacheDebugColorParameter);
|
|
LAYOUT_FIELD(FShaderParameter, OutputQuadOverdrawParameter);
|
|
LAYOUT_FIELD(FShaderParameter, VisualizeModeParameter);
|
|
LAYOUT_FIELD(FShaderResourceParameter, QuadBufferUAV);
|
|
};
|
|
|
|
class FDebugViewModeMeshProcessor : public FMeshPassProcessor
|
|
{
|
|
public:
|
|
FDebugViewModeMeshProcessor(const FScene* InScene, ERHIFeatureLevel::Type InFeatureLevel, const FSceneView* InViewIfDynamicMeshCommand, bool bTranslucentBasePass, FMeshPassDrawListContext* InDrawListContext);
|
|
virtual void AddMeshBatch(const FMeshBatch& RESTRICT MeshBatch, uint64 BatchElementMask, const FPrimitiveSceneProxy* RESTRICT PrimitiveSceneProxy, int32 StaticMeshId = -1) override final;
|
|
|
|
private:
|
|
|
|
void UpdateInstructionCount(FDebugViewModeShaderElementData& OutShaderElementData, const FMaterial* InBatchMaterial, FVertexFactoryType* InVertexFactoryType);
|
|
|
|
EDebugViewShaderMode DebugViewMode;
|
|
int32 ViewModeParam;
|
|
FName ViewModeParamName;
|
|
|
|
const FDebugViewModeInterface* DebugViewModeInterface;
|
|
};
|
|
|
|
class FDebugViewModeImplementation : public FDebugViewModeInterface
|
|
{
|
|
public:
|
|
FDebugViewModeImplementation() : FDebugViewModeInterface() {}
|
|
|
|
virtual void AddShaderTypes(ERHIFeatureLevel::Type InFeatureLevel,
|
|
const FVertexFactoryType* InVertexFactoryType,
|
|
FMaterialShaderTypes& OutShaderTypes) const override;
|
|
|
|
virtual void GetDebugViewModeShaderBindings(
|
|
const FDebugViewModePS& BaseShader,
|
|
const FPrimitiveSceneProxy* RESTRICT PrimitiveSceneProxy,
|
|
const FMaterialRenderProxy& RESTRICT MaterialRenderProxy,
|
|
const FMaterial& RESTRICT Material,
|
|
EDebugViewShaderMode DebugViewMode,
|
|
const FVector& ViewOrigin,
|
|
int32 VisualizeLODIndex,
|
|
const FColor& SkinCacheDebugColor,
|
|
int32 VisualizeElementIndex,
|
|
int32 NumVSInstructions,
|
|
int32 NumPSInstructions,
|
|
int32 ViewModeParam,
|
|
FName ViewModeParamName,
|
|
FMeshDrawSingleShaderBindings& ShaderBindings
|
|
) const override;
|
|
};
|
|
|
|
#endif // WITH_DEBUG_VIEW_MODES
|
|
|
|
void RenderDebugViewMode(
|
|
FRDGBuilder& GraphBuilder,
|
|
TArrayView<FViewInfo> Views,
|
|
FRDGTextureRef QuadOverdrawTexture,
|
|
const FRenderTargetBindingSlots& RenderTargets); |