Files
UnrealEngineUWP/Engine/Shaders/Shared/SceneCullingDefinitions.h
Ola Olsson f6a42df34a Implemented instance culling hierarchy (main feature in SceneCulling.h/cpp) to construct & update a loose hierarchical spatial hash over all scene instances and support for Nanite instance culling based on this.
The feature is disabled by default, and may be considered Beta for the current release.

- Added support for passing an FSceneInstanceCullingQuery to Nanite::IRenderer::DrawGeometry
- Added some more interface (inline) functions to Nanite::IRenderer to help guide the user.
- Implemented FInstanceHierarchyCull_CS to handle the hierarchy culling in the Nanite culling passes.
- Added FInstanceHierarchyAppendUncullable_CS to append "uncullable" instances
- Adapted FCompactViewsVSM_CS to handle view group ranges, use with the new hierarchy
- Moved VirtualShadowMapViews from FSortedShadowMaps to FShadowSceneRenderer (public -> private)

#rb brian.karis,jamie.hayes
#jira UE-147060
#preflight 6448d4961150e908d01f0049

[CL 25194831 by Ola Olsson in ue5-main branch]
2023-04-26 04:02:53 -04:00

90 lines
2.4 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
// 1 + 7 + 24 bits_
#define INSTANCE_HIERARCHY_ITEM_CHUNK_COUNT_SHIFT (24u)
#define INSTANCE_HIERARCHY_ITEM_CHUNK_ID_MASK ((1u << INSTANCE_HIERARCHY_ITEM_CHUNK_COUNT_SHIFT) - 1u)
#define INSTANCE_HIERARCHY_ITEM_CHUNK_COMPRESSED_FLAG (1u << 31u)
#define INSTANCE_HIERARCHY_ITEM_CHUNK_COMPRESSED_PAYLOAD_MASK ((1u << 31u) - 1u)
#define INSTANCE_HIERARCHY_MAX_CHUNK_SIZE (64u)
#ifdef __cplusplus
#include "HLSLTypeAliases.h"
namespace UE::HLSL
{
#endif
#ifndef __cplusplus //HLSL
#include "/Engine/Private/LargeWorldCoordinates.ush"
#endif
// Representation in hierarchy buffer
struct FCellHeader
{
uint NumItemChunks;
uint ItemChunksOffset;
};
struct FCellBlockData
{
FLWCVector3 WorldPos;
float LevelCellSize; // Note, not the block size, but the cell size.
uint Pad;
};
/**
* Represent one item of work for the hierarchical culling stage, linking a cell to either a group of views (main-pass) or a singlular view (post-pass).
*/
struct FCellDraw
{
uint CellId;
uint ViewGroupId;
};
/**
* Represent one item of work for the post-pass of the hierarchical culling stage.
*/
struct FOccludedCellDraw
{
FCellDraw CellDraw;
uint OccludedViewMask;
uint Pad;
};
/**
* Represents a group of views, e.g., for a clipmap or point light, or anything else really that share the same broad-phase culling result.
* Wrt mip-views, there is no explicit handling in the hierarchical culling stage, as they are expected to come in a compact range (post view compaction)
* A view group should typically share view flags, might want/need to make assumptions around that.
*/
struct FViewDrawGroup
{
uint FirstView;
uint NumViews;
};
// Info for one instance culling workgroup (64 threads).
// TODO: Pack/unpack into fewer bits?
// TODO: Move to some nanite specific header probably.
struct FInstanceCullingGroupWork
{
uint ViewGroupId;
uint PackedItemChunkDesc;
uint ActiveViewMask; // Up to 32 active views in the group (NOTE: this may overflow for example if all mip levels were mapped at the same time on a point light, 48 mips)
uint Pad;
};
#ifdef __cplusplus
} // namespace
using FCellHeader = UE::HLSL::FCellHeader;
using FCellBlockData = UE::HLSL::FCellBlockData;
using FCellDraw = UE::HLSL::FCellDraw;
using FOccludedCellDraw = UE::HLSL::FOccludedCellDraw;
using FViewDrawGroup = UE::HLSL::FViewDrawGroup;
using FInstanceCullingGroupWork = UE::HLSL::FInstanceCullingGroupWork;
#endif