2019-12-26 14:45:42 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2018-09-11 14:44:10 -04:00
|
|
|
|
|
|
|
|
#include "VirtualTextureTest.h"
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
#include "SpriteIndexBuffer.h"
|
|
|
|
|
#include "ScreenRendering.h"
|
|
|
|
|
#include "SceneFilterRendering.h"
|
|
|
|
|
#include "RenderTargetPool.h"
|
|
|
|
|
#include "GlobalShader.h"
|
|
|
|
|
#include "PipelineStateCache.h"
|
|
|
|
|
#include "SceneUtils.h"
|
|
|
|
|
|
|
|
|
|
// TEMP will have reference from VT typedef
|
|
|
|
|
#include "TexturePagePool.h"
|
|
|
|
|
#include "VirtualTextureSpace.h"
|
|
|
|
|
#include "VirtualTextureSystem.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TGlobalResource< FVirtualTextureTestType > GVirtualTextureTestType;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FVirtualTextureTestType::FVirtualTextureTestType()
|
|
|
|
|
{
|
|
|
|
|
PhysicalTextureFormat = PF_B8G8R8A8;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Pool = new FTexturePagePool( 64 * 64, 2 );
|
|
|
|
|
PhysicalTextureSize = FIntPoint(64 * pPageSize, 64 * pPageSize);
|
|
|
|
|
|
|
|
|
|
#if CPU_TEST == 0
|
|
|
|
|
Space = new FVirtualTextureSpace( 1024, 2, PF_R16_UINT, Pool );
|
|
|
|
|
BeginInitResource(Space);
|
|
|
|
|
|
|
|
|
|
VT = new FVirtualTextureTest(1024, 1024, 1);
|
|
|
|
|
Space->Allocator.Alloc(VT);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FVirtualTextureTestType::~FVirtualTextureTestType()
|
|
|
|
|
{
|
|
|
|
|
#if CPU_TEST == 0
|
|
|
|
|
ReleaseResourceAndFlush( Space );
|
|
|
|
|
delete Space;
|
|
|
|
|
#endif
|
|
|
|
|
delete Pool;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FVirtualTextureTestType::InitDynamicRHI()
|
|
|
|
|
{
|
|
|
|
|
FRHICommandListImmediate& RHICmdList = FRHICommandListExecutor::GetImmediateCommandList();
|
|
|
|
|
FPooledRenderTargetDesc Desc( FPooledRenderTargetDesc::Create2DDesc( PhysicalTextureSize, PhysicalTextureFormat, FClearValueBinding::None, TexCreate_None, TexCreate_SRGB | TexCreate_RenderTargetable | TexCreate_ShaderResource, false ) );
|
|
|
|
|
GRenderTargetPool.FindFreeElement( RHICmdList, Desc, PhysicalTexture, TEXT("PhysicalTexture") );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FVirtualTextureTestType::ReleaseDynamicRHI()
|
|
|
|
|
{
|
|
|
|
|
GRenderTargetPool.FreeUnusedResource( PhysicalTexture );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FRHITexture* FVirtualTextureTestType::GetPageTableTexture() const
|
|
|
|
|
{
|
|
|
|
|
#if CPU_TEST
|
|
|
|
|
// FVirtualTextureSpace* FSpace = (FVirtualTextureSpace*)TEMP_GetVirtualTextureSpaceResource();
|
|
|
|
|
// if (FSpace)
|
|
|
|
|
// {
|
|
|
|
|
// return FSpace->GetPageTableTexture();
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
// {
|
|
|
|
|
return GBlackTexture->TextureRHI; //todo black is probably not a valid 'dummy' pagetable format
|
|
|
|
|
// }
|
|
|
|
|
#else
|
|
|
|
|
return Space->GetPageTableTexture();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FVirtualTextureTest::FVirtualTextureTest( uint32 InSizeX, uint32 InSizeY, uint32 InSizeZ )
|
|
|
|
|
: IVirtualTexture( InSizeX, InSizeY, InSizeY )
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
FVirtualTextureTest::~FVirtualTextureTest()
|
|
|
|
|
{}
|
|
|
|
|
|
2019-06-11 18:27:07 -04:00
|
|
|
bool FVirtualTextureTest::RequestPageData( uint8 vLevel, uint64 vAddress, void* RESTRICT& Location ) /*const*/
|
2018-09-11 14:44:10 -04:00
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
const size_t VTHeaderSize = 0;
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
// Look up offset and size from offset table
|
|
|
|
|
// Only required for variable bit-rate compression
|
|
|
|
|
size_t Offsets[2] = { 0 };
|
|
|
|
|
size_t DataRead = FileCache->Read( Offsets, VT->FileName, VTHeaderSize + VTPageIndex * sizeof( size_t ), sizeof( Offsets ), priority );
|
|
|
|
|
|
|
|
|
|
size_t PageSize = Offsets[1] - Offsets[0];
|
|
|
|
|
size_t PageOffset = Offsets[0];
|
|
|
|
|
#else
|
|
|
|
|
size_t PageSize = 16;
|
|
|
|
|
size_t PageOffset = VTHeaderSize + VTPageIndex * PageSize;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Need to know if the actual data is there
|
|
|
|
|
size_t DataRead = FileCache->Read( Data, VT->FileName, PageOffset, PageSize, priority );
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class FVirtualTextureTestPS : public FGlobalShader
|
|
|
|
|
{
|
2021-12-06 14:36:06 -05:00
|
|
|
DECLARE_GLOBAL_SHADER(FVirtualTextureTestPS);
|
2018-09-11 14:44:10 -04:00
|
|
|
|
|
|
|
|
static bool ShouldCache( EShaderPlatform Platform )
|
|
|
|
|
{
|
|
|
|
|
return IsFeatureLevelSupported( Platform, ERHIFeatureLevel::SM5 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FVirtualTextureTestPS() {}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
FVirtualTextureTestPS(const ShaderMetaType::CompiledShaderInitializerType& Initializer)
|
|
|
|
|
: FGlobalShader(Initializer)
|
|
|
|
|
{}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
IMPLEMENT_SHADER_TYPE(, FVirtualTextureTestPS, TEXT("/Engine/Private/VTtest.usf"), TEXT("VirtualTextureTestPS"), SF_Pixel );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FVirtualTextureTest::ProducePageData( FRHICommandList& RHICmdList, ERHIFeatureLevel::Type FeatureLevel, uint8 vLevel, uint64 vAddress, uint16 pAddress, void* Location ) /*const*/
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
#if 0
|
|
|
|
|
// Copy data from file cache to ByteAddressBuffer for decompression on GPU
|
|
|
|
|
uint8* Data = (uint8*)CompressedBuffer + CompressedBufferOffset;
|
|
|
|
|
size_t DataRead = FileCache->Read( Data, VT->FileName, PageOffset, PageSize, priority );
|
|
|
|
|
check( DataRead == PageSize );
|
|
|
|
|
// TODO Dispatch decompress CS
|
|
|
|
|
#else
|
|
|
|
|
// Copy data from file cache to staging texture
|
|
|
|
|
uint8* Data = nullptr;
|
|
|
|
|
size_t DataRead = FileCache->Read( Data, VT->FileName, PageOffset, PageSize, priority );
|
|
|
|
|
check( DataRead == PageSize );
|
|
|
|
|
// TODO Transfer CPU staging texture to GPU
|
|
|
|
|
#endif
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// TODO These should come from VT typedef
|
|
|
|
|
const uint32 vPageSize = 128;
|
|
|
|
|
const uint32 pPageBorder = 4;
|
|
|
|
|
const uint32 pPageSize = vPageSize + 2 * pPageBorder;
|
|
|
|
|
|
|
|
|
|
const uint32 vPageX = FMath::ReverseMortonCode2( vAddress );
|
|
|
|
|
const uint32 vPageY = FMath::ReverseMortonCode2( vAddress >> 1 );
|
|
|
|
|
|
|
|
|
|
const uint32 pPageX = FMath::ReverseMortonCode2( pAddress );
|
|
|
|
|
const uint32 pPageY = FMath::ReverseMortonCode2( pAddress >> 1 );
|
|
|
|
|
|
|
|
|
|
FIntRect SrcRect(
|
|
|
|
|
( vPageX + (0 << vLevel) ) * vPageSize - ( pPageBorder << vLevel ),
|
|
|
|
|
( vPageY + (0 << vLevel) ) * vPageSize - ( pPageBorder << vLevel ),
|
|
|
|
|
( vPageX + (1 << vLevel) ) * vPageSize + ( pPageBorder << vLevel ),
|
|
|
|
|
( vPageY + (1 << vLevel) ) * vPageSize + ( pPageBorder << vLevel )
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
FIntRect DstRect(
|
|
|
|
|
( pPageX + 0 ) * pPageSize,
|
|
|
|
|
( pPageY + 0 ) * pPageSize,
|
|
|
|
|
( pPageX + 1 ) * pPageSize,
|
|
|
|
|
( pPageY + 1 ) * pPageSize
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
FIntPoint SrcSize( 1024 * vPageSize, 1024 * vPageSize );
|
|
|
|
|
FIntPoint DstSize( 64 * pPageSize, 64 * pPageSize );
|
|
|
|
|
|
|
|
|
|
TRefCountPtr< IPooledRenderTarget > PhysicalTexture = GVirtualTextureTestType.PhysicalTexture;
|
|
|
|
|
|
|
|
|
|
SCOPED_DRAW_EVENT( RHICmdList, TestProducePageData );
|
|
|
|
|
|
|
|
|
|
auto ShaderMap = GetGlobalShaderMap( FeatureLevel );
|
|
|
|
|
|
2022-04-06 18:24:24 -04:00
|
|
|
FRHITexture* RenderTarget = PhysicalTexture->GetRHI();
|
2018-09-11 14:44:10 -04:00
|
|
|
|
2022-04-06 18:24:24 -04:00
|
|
|
FRHIRenderPassInfo RPInfo(RenderTarget, ERenderTargetActions::Load_Store);
|
2018-10-29 17:34:53 -04:00
|
|
|
RHICmdList.BeginRenderPass(RPInfo, TEXT("ProducePageData"));
|
|
|
|
|
{
|
|
|
|
|
RHICmdList.SetViewport(DstRect.Min.X, DstRect.Min.Y, 0.0f, DstRect.Max.X, DstRect.Max.Y, 1.0f);
|
2018-09-11 14:44:10 -04:00
|
|
|
|
2018-10-29 17:34:53 -04:00
|
|
|
FGraphicsPipelineStateInitializer GraphicsPSOInit;
|
|
|
|
|
RHICmdList.ApplyCachedRenderTargets(GraphicsPSOInit);
|
2018-09-11 14:44:10 -04:00
|
|
|
|
2018-10-29 17:34:53 -04:00
|
|
|
GraphicsPSOInit.BlendState = TStaticBlendState<>::GetRHI();
|
|
|
|
|
GraphicsPSOInit.RasterizerState = TStaticRasterizerState<>::GetRHI();
|
|
|
|
|
GraphicsPSOInit.DepthStencilState = TStaticDepthStencilState<false, CF_Always>::GetRHI();
|
|
|
|
|
GraphicsPSOInit.PrimitiveType = PT_TriangleList;
|
2018-09-11 14:44:10 -04:00
|
|
|
|
2018-10-29 17:34:53 -04:00
|
|
|
TShaderMapRef< FScreenVS > VertexShader(ShaderMap);
|
|
|
|
|
TShaderMapRef< FVirtualTextureTestPS > PixelShader(ShaderMap);
|
2018-09-11 14:44:10 -04:00
|
|
|
|
2018-10-29 17:34:53 -04:00
|
|
|
GraphicsPSOInit.BoundShaderState.VertexDeclarationRHI = GFilterVertexDeclaration.VertexDeclarationRHI;
|
2020-02-06 13:13:41 -05:00
|
|
|
GraphicsPSOInit.BoundShaderState.VertexShaderRHI = VertexShader.GetVertexShader();
|
|
|
|
|
GraphicsPSOInit.BoundShaderState.PixelShaderRHI = PixelShader.GetPixelShader();
|
2021-09-03 12:04:52 -04:00
|
|
|
SetGraphicsPipelineState(RHICmdList, GraphicsPSOInit, 0);
|
2018-09-11 14:44:10 -04:00
|
|
|
|
2018-10-29 17:34:53 -04:00
|
|
|
DrawRectangle(
|
|
|
|
|
RHICmdList,
|
|
|
|
|
0, 0,
|
|
|
|
|
DstRect.Width(), DstRect.Height(),
|
|
|
|
|
SrcRect.Min.X, SrcRect.Min.Y,
|
|
|
|
|
SrcRect.Width(), SrcRect.Height(),
|
|
|
|
|
DstRect.Size(),
|
|
|
|
|
SrcSize,
|
2020-02-06 13:13:41 -05:00
|
|
|
VertexShader,
|
2018-10-29 17:34:53 -04:00
|
|
|
EDRF_UseTriangleOptimization);
|
|
|
|
|
}
|
|
|
|
|
RHICmdList.EndRenderPass();
|
2022-04-06 18:24:24 -04:00
|
|
|
RHICmdList.Transition(FRHITransitionInfo(RenderTarget, ERHIAccess::RTV, ERHIAccess::SRVMask));
|
2018-09-11 14:44:10 -04:00
|
|
|
|
Merging //UE4/Dev-Rendering-Graph@4492585 to Dev-Rendering (//UE4/Dev-Rendering)
This implements the framework to write the high level rendering code into passes organized in direct acyclic graph. It is also unifying the uniform buffer, shader parameters, and pass parameters to same single API: structures with run time meta data. This allow high level user code be extremely seamless, user code debugging, and render graph ease of implementation and debugging.
Issue of collaborative work of Arne Schnober, Brian Karis, Daniel Wright, Marcus Wassmer and Guillaume Abadie.
Names of the graph managed resources are not final.
#rb Arne.Schnober, Brian.Karis, Daniel.Wright, Marcus.Wassmer
[CL 4492694 by Guillaume Abadie in Dev-Rendering branch]
2018-10-19 17:36:35 -04:00
|
|
|
GVisualizeTexture.SetCheckPoint( RHICmdList, PhysicalTexture );
|
2018-09-11 14:44:10 -04:00
|
|
|
}
|
|
|
|
|
|
2019-06-11 18:27:07 -04:00
|
|
|
void FVirtualTextureTest::DumpToConsole(bool verbose)
|
2018-09-11 14:44:10 -04:00
|
|
|
{
|
|
|
|
|
UE_LOG(LogConsoleResponse, Display, TEXT("Test Virtual Texture"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|