218 lines
6.7 KiB
Markdown
218 lines
6.7 KiB
Markdown
---
|
||
title: 剖析虚幻渲染体系(11)- RDG
|
||
date: 2024-02-04 21:42:54
|
||
excerpt:
|
||
tags:
|
||
rating: ⭐
|
||
---
|
||
# 前言
|
||
https://www.cnblogs.com/timlly/p/15217090.html
|
||
|
||
## RDG基础类型
|
||
```c++
|
||
enum class ERDGBuilderFlags
|
||
{
|
||
None = 0,
|
||
|
||
/** Allows the builder to parallelize execution of passes. Without this flag, all passes execute on the render thread. */
|
||
AllowParallelExecute = 1 << 0
|
||
};
|
||
|
||
/** Flags to annotate a pass with when calling AddPass. */
|
||
enum class ERDGPassFlags : uint16
|
||
{
|
||
/** Pass doesn't have any inputs or outputs tracked by the graph. This may only be used by the parameterless AddPass function. */
|
||
None = 0,
|
||
|
||
/** Pass uses rasterization on the graphics pipe. */
|
||
Raster = 1 << 0,
|
||
|
||
/** Pass uses compute on the graphics pipe. */
|
||
Compute = 1 << 1,
|
||
|
||
/** Pass uses compute on the async compute pipe. */
|
||
AsyncCompute = 1 << 2,
|
||
|
||
/** Pass uses copy commands on the graphics pipe. */
|
||
Copy = 1 << 3,
|
||
|
||
/** Pass (and its producers) will never be culled. Necessary if outputs cannot be tracked by the graph. */
|
||
NeverCull = 1 << 4,
|
||
|
||
/** Render pass begin / end is skipped and left to the user. Only valid when combined with 'Raster'. Disables render pass merging for the pass. */
|
||
SkipRenderPass = 1 << 5,
|
||
|
||
/** Pass will never have its render pass merged with other passes. */
|
||
NeverMerge = 1 << 6,
|
||
|
||
/** Pass will never run off the render thread. */
|
||
NeverParallel = 1 << 7,
|
||
|
||
ParallelTranslate = 1 << 8,
|
||
|
||
/** Pass uses copy commands but writes to a staging resource. */
|
||
Readback = Copy | NeverCull
|
||
};
|
||
|
||
/** Flags to annotate a render graph buffer. */
|
||
enum class ERDGBufferFlags : uint8
|
||
{
|
||
None = 0,
|
||
|
||
/** Tag the buffer to survive through frame, that is important for multi GPU alternate frame rendering. */
|
||
MultiFrame = 1 << 0,
|
||
|
||
/** The buffer is ignored by RDG tracking and will never be transitioned. Use the flag when registering a buffer with no writable GPU flags.
|
||
* Write access is not allowed for the duration of the graph. This flag is intended as an optimization to cull out tracking of read-only
|
||
* buffers that are used frequently throughout the graph. Note that it's the user's responsibility to ensure the resource is in the correct
|
||
* readable state for use with RDG passes, as RDG does not know the exact state of the resource.
|
||
*/
|
||
SkipTracking = 1 << 1,
|
||
|
||
/** When set, RDG will perform its first barrier without splitting. Practically, this means the resource is left in its initial state
|
||
* until the first pass it's used within the graph. Without this flag, the resource is split-transitioned at the start of the graph.
|
||
*/
|
||
ForceImmediateFirstBarrier = 1 << 2,
|
||
};
|
||
|
||
/** Flags to annotate a render graph texture. */
|
||
enum class ERDGTextureFlags : uint8
|
||
{
|
||
None = 0,
|
||
|
||
/** Tag the texture to survive through frame, that is important for multi GPU alternate frame rendering. */
|
||
MultiFrame = 1 << 0,
|
||
|
||
/** The buffer is ignored by RDG tracking and will never be transitioned. Use the flag when registering a buffer with no writable GPU flags.
|
||
* Write access is not allowed for the duration of the graph. This flag is intended as an optimization to cull out tracking of read-only
|
||
* buffers that are used frequently throughout the graph. Note that it's the user's responsibility to ensure the resource is in the correct
|
||
* readable state for use with RDG passes, as RDG does not know the exact state of the resource.
|
||
*/
|
||
SkipTracking = 1 << 1,
|
||
|
||
/** When set, RDG will perform its first barrier without splitting. Practically, this means the resource is left in its initial state
|
||
* until the first pass it's used within the graph. Without this flag, the resource is split-transitioned at the start of the graph.
|
||
*/
|
||
ForceImmediateFirstBarrier = 1 << 2,
|
||
|
||
/** Prevents metadata decompression on this texture. */
|
||
MaintainCompression = 1 << 3,
|
||
};
|
||
ENUM_CLASS_FLAGS(ERDGTextureFlags);
|
||
|
||
/** Flags to annotate a view with when calling CreateUAV. */
|
||
enum class ERDGUnorderedAccessViewFlags : uint8
|
||
{
|
||
None = 0,
|
||
|
||
// The view will not perform UAV barriers between consecutive usage.
|
||
SkipBarrier = 1 << 0
|
||
};
|
||
ENUM_CLASS_FLAGS(ERDGUnorderedAccessViewFlags);
|
||
|
||
/** The set of concrete parent resource types. */
|
||
enum class ERDGViewableResourceType : uint8
|
||
{
|
||
Texture,
|
||
Buffer,
|
||
MAX
|
||
};
|
||
|
||
/** The set of concrete view types. */
|
||
enum class ERDGViewType : uint8
|
||
{
|
||
TextureUAV,
|
||
TextureSRV,
|
||
BufferUAV,
|
||
BufferSRV,
|
||
MAX
|
||
};
|
||
|
||
inline ERDGViewableResourceType GetParentType(ERDGViewType ViewType)
|
||
{
|
||
switch (ViewType)
|
||
{
|
||
case ERDGViewType::TextureUAV:
|
||
case ERDGViewType::TextureSRV:
|
||
return ERDGViewableResourceType::Texture;
|
||
case ERDGViewType::BufferUAV:
|
||
case ERDGViewType::BufferSRV:
|
||
return ERDGViewableResourceType::Buffer;
|
||
}
|
||
checkNoEntry();
|
||
return ERDGViewableResourceType::MAX;
|
||
}
|
||
|
||
enum class ERDGResourceExtractionFlags : uint8
|
||
{
|
||
None = 0,
|
||
|
||
// Allows the resource to remain transient. Only use this flag if you intend to register the resource back
|
||
// into the graph and release the reference. This should not be used if the resource is cached for a long
|
||
// period of time.
|
||
AllowTransient = 1,
|
||
};
|
||
|
||
enum class ERDGInitialDataFlags : uint8
|
||
{
|
||
/** Specifies the default behavior, which is to make a copy of the initial data for replay when
|
||
* the graph is executed. The user does not need to preserve lifetime of the data pointer.
|
||
*/
|
||
None = 0,
|
||
|
||
/** Specifies that the user will maintain ownership of the data until the graph is executed. The
|
||
* upload pass will only use a reference to store the data. Use caution with this flag since graph
|
||
* execution is deferred! Useful to avoid the copy if the initial data lifetime is guaranteed to
|
||
* outlive the graph.
|
||
*/
|
||
NoCopy = 1 << 0
|
||
};
|
||
|
||
enum class ERDGPooledBufferAlignment : uint8
|
||
{
|
||
// The buffer size is not aligned.
|
||
None,
|
||
|
||
// The buffer size is aligned up to the next page size.
|
||
Page,
|
||
|
||
// The buffer size is aligned up to the next power of two.
|
||
PowerOfTwo
|
||
};
|
||
|
||
/** Returns the equivalent parent resource type for a view type. */
|
||
inline ERDGViewableResourceType GetViewableResourceType(ERDGViewType ViewType)
|
||
{
|
||
switch (ViewType)
|
||
{
|
||
case ERDGViewType::TextureUAV:
|
||
case ERDGViewType::TextureSRV:
|
||
return ERDGViewableResourceType::Texture;
|
||
case ERDGViewType::BufferUAV:
|
||
case ERDGViewType::BufferSRV:
|
||
return ERDGViewableResourceType::Buffer;
|
||
default:
|
||
checkNoEntry();
|
||
return ERDGViewableResourceType::MAX;
|
||
}
|
||
}
|
||
|
||
using ERDGTextureMetaDataAccess = ERHITextureMetaDataAccess;
|
||
|
||
/** Returns the associated FRHITransitionInfo plane index. */
|
||
inline int32 GetResourceTransitionPlaneForMetadataAccess(ERDGTextureMetaDataAccess Metadata)
|
||
{
|
||
switch (Metadata)
|
||
{
|
||
case ERDGTextureMetaDataAccess::CompressedSurface:
|
||
case ERDGTextureMetaDataAccess::HTile:
|
||
case ERDGTextureMetaDataAccess::Depth:
|
||
return FRHITransitionInfo::kDepthPlaneSlice;
|
||
case ERDGTextureMetaDataAccess::Stencil:
|
||
return FRHITransitionInfo::kStencilPlaneSlice;
|
||
default:
|
||
return 0;
|
||
}
|
||
}
|
||
```
|