Files
UnrealEngineUWP/Engine/Source/Developer/ShaderCompilerCommon/Private/HlslUtils.cpp
Rolando Caloca c0f0eeb9f7 CCT - Move allocator to HlslUtils
- Add interpolation modifiers
- Ignore #pragma
- Fix for strings in attributes
- Do translation units separately

[CL 2469349 by Rolando Caloca in Main branch]
2015-03-04 17:00:58 -05:00

76 lines
1.5 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
/*=============================================================================
HlslUtils.cpp - Utils for HLSL.
=============================================================================*/
#include "ShaderCompilerCommon.h"
#include "HlslUtils.h"
namespace CrossCompiler
{
namespace Memory
{
static struct FPagePoolInstance
{
~FPagePoolInstance()
{
check(UsedPages.Num() == 0);
for (int32 Index = 0; Index < FreePages.Num(); ++Index)
{
delete FreePages[Index];
}
}
FPage* AllocatePage()
{
FScopeLock ScopeLock(&CriticalSection);
if (FreePages.Num() == 0)
{
FreePages.Add(new FPage(PageSize));
}
auto* Page = FreePages.Last();
FreePages.RemoveAt(FreePages.Num() - 1, 1, false);
UsedPages.Add(Page);
return Page;
}
void FreePage(FPage* Page)
{
FScopeLock ScopeLock(&CriticalSection);
int32 Index = UsedPages.Find(Page);
check(Index >= 0);
UsedPages.RemoveAt(Index, 1, false);
FreePages.Add(Page);
}
TArray<FPage*, TInlineAllocator<8> > FreePages;
TArray<FPage*, TInlineAllocator<8> > UsedPages;
FCriticalSection CriticalSection;
} GMemoryPagePool;
FPage* FPage::AllocatePage()
{
#if USE_PAGE_POOLING
return GMemoryPagePool.AllocatePage();
#else
return new FPage(PageSize);
#endif
}
void FPage::FreePage(FPage* Page)
{
#if USE_PAGE_POOLING
GMemoryPagePool.FreePage(Page);
#else
delete Page;
#endif
}
}
}