48 lines
2.0 KiB
HLSL
48 lines
2.0 KiB
HLSL
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
#include "../Common.ush"
|
|
#include "../WaveOpUtil.ush"
|
|
#include "/Engine/Shared/NaniteDefinitions.h"
|
|
|
|
struct FStreamingRequest
|
|
{
|
|
uint RuntimeResourceID_Magic;
|
|
uint PageIndex_NumPages_Magic;
|
|
uint Priority_Magic;
|
|
};
|
|
|
|
uint StreamingRequestsBufferVersion;
|
|
uint StreamingRequestsBufferSize;
|
|
|
|
void RequestPageRange( RWStructuredBuffer<FStreamingRequest> RequestsBuffer, uint RuntimeResourceID, uint StartPageIndex, uint NumPages, uint PriorityCategory, float Priority )
|
|
{
|
|
if ((RenderFlags & NANITE_RENDER_FLAG_OUTPUT_STREAMING_REQUESTS) && NumPages > 0)
|
|
{
|
|
uint Index;
|
|
WaveInterlockedAddScalar_(RequestsBuffer[0].RuntimeResourceID_Magic, 1, Index); // HACK: Store count in RuntimeResourceID_Magic of first request.
|
|
|
|
if (Index < StreamingRequestsBufferSize - 1)
|
|
{
|
|
const uint MinPriority = NANITE_SANITY_CHECK_STREAMING_REQUESTS ? (1u << NANITE_STREAMING_REQUEST_MAGIC_BITS) : 1u;
|
|
const uint UIntPriority = clamp((PriorityCategory << 30) | (asuint(Priority) >> 2), MinPriority, NANITE_MAX_PRIORITY_BEFORE_PARENTS);
|
|
|
|
FStreamingRequest Request;
|
|
#if NANITE_SANITY_CHECK_STREAMING_REQUESTS
|
|
Request.RuntimeResourceID_Magic = (RuntimeResourceID << NANITE_STREAMING_REQUEST_MAGIC_BITS);
|
|
Request.PageIndex_NumPages_Magic = (((StartPageIndex << NANITE_MAX_GROUP_PARTS_BITS) | NumPages) << NANITE_STREAMING_REQUEST_MAGIC_BITS);
|
|
Request.Priority_Magic = UIntPriority & ~NANITE_STREAMING_REQUEST_MAGIC_MASK; // Mask off low bits to leave space for magic
|
|
const uint FrameNibble = StreamingRequestsBufferVersion & 0xF;
|
|
Request.RuntimeResourceID_Magic |= 0x10 | FrameNibble;
|
|
Request.PageIndex_NumPages_Magic |= 0x20 | FrameNibble;
|
|
Request.Priority_Magic |= 0x30 | FrameNibble;
|
|
#else
|
|
Request.RuntimeResourceID_Magic = RuntimeResourceID;
|
|
Request.PageIndex_NumPages_Magic = (StartPageIndex << NANITE_MAX_GROUP_PARTS_BITS) | NumPages;
|
|
Request.Priority_Magic = UIntPriority;
|
|
#endif
|
|
RequestsBuffer[Index + 1] = Request;
|
|
}
|
|
}
|
|
} |