Files
UnrealEngineUWP/Engine/Source/Runtime/OpenGLDrv/Private/OpenGL4.cpp

117 lines
3.8 KiB
C++
Raw Normal View History

// Copyright Epic Games, Inc. All Rights Reserved.
/*=============================================================================
OpenGL4.cpp: OpenGL 4.3 implementation.
=============================================================================*/
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3209340 on 2016/11/23 by Ben.Marsh Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h. Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms. * Every header now includes everything it needs to compile. * There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first. * There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h. * Every .cpp file includes its matching .h file first. * This helps validate that each header is including everything it needs to compile. * No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more. * You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there. * There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible. * No engine code explicitly includes a precompiled header any more. * We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies. * PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files. Tool used to generate this transform is at Engine\Source\Programs\IncludeTool. [CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
#include "CoreMinimal.h"
#include "OpenGLDrv.h"
#include "OpenGLDrvPrivate.h"
#if OPENGL_GL4
GLint FOpenGL4::MaxComputeTextureImageUnits = -1;
GLint FOpenGL4::MaxComputeUniformComponents = -1;
GLint FOpenGL4::MaxCombinedUAVUnits = 0;
GLint FOpenGL4::MaxComputeUAVUnits = -1;
GLint FOpenGL4::MaxPixelUAVUnits = -1;
bool FOpenGL4::bSupportsGPUMemoryInfo = false;
void FOpenGL4::ProcessQueryGLInt()
{
GET_GL_INT(GL_MAX_COMBINED_IMAGE_UNIFORMS, 0, MaxCombinedUAVUnits);
GET_GL_INT(GL_MAX_FRAGMENT_IMAGE_UNIFORMS, 0, MaxPixelUAVUnits);
GET_GL_INT(GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, 0, TextureBufferAlignment);
GET_GL_INT(GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS, 0, MaxComputeTextureImageUnits);
GET_GL_INT(GL_MAX_COMPUTE_UNIFORM_COMPONENTS, 0, MaxComputeUniformComponents);
GET_GL_INT(GL_MAX_COMPUTE_IMAGE_UNIFORMS, 0, MaxComputeUAVUnits);
GLint MaxCombinedSSBOUnits = 0;
GET_GL_INT(GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS, 0, MaxCombinedSSBOUnits);
// UAVs slots in UE are shared between Images and SSBO, so this should be max(GL_MAX_COMBINED_IMAGE_UNIFORMS, GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS)
MaxCombinedUAVUnits = FMath::Max(MaxCombinedUAVUnits, MaxCombinedSSBOUnits);
// clamp UAV units to a sensible limit
MaxCombinedUAVUnits = FMath::Min(MaxCombinedUAVUnits, 16);
MaxComputeUAVUnits = FMath::Min(MaxComputeUAVUnits, 16);
// this is split between VS and PS, 4 to each stage
MaxPixelUAVUnits = FMath::Min(MaxPixelUAVUnits, 4);
}
void FOpenGL4::ProcessExtensions( const FString& ExtensionsString )
{
int32 MajorVersion =0;
int32 MinorVersion =0;
FString Version = ANSI_TO_TCHAR((const ANSICHAR*)glGetString(GL_VERSION));
FString MajorString, MinorString;
if (Version.Split(TEXT("."), &MajorString, &MinorString))
{
MajorVersion = FCString::Atoi(*MajorString);
MinorVersion = FCString::Atoi(*MinorString);
}
check(MajorVersion!=0);
bSupportsGPUMemoryInfo = ExtensionsString.Contains(TEXT("GL_NVX_gpu_memory_info"));
//Process Queries after extensions to avoid queries that use functionality that might not be present
ProcessQueryGLInt();
FOpenGL3::ProcessExtensions(ExtensionsString);
}
#ifndef GL_NVX_gpu_memory_info
#define GL_NVX_gpu_memory_info 1
#define GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX 0x9047
#define GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX 0x9048
#define GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX 0x9049
#define GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX 0x904A
#define GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX 0x904B
#endif
uint64 FOpenGL4::GetVideoMemorySize()
{
uint64 VideoMemorySize = 0;
if (bSupportsGPUMemoryInfo)
{
GLint VMSizeKB = 0;
glGetIntegerv( GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &VMSizeKB);
VideoMemorySize = VMSizeKB * 1024ll;
}
return VideoMemorySize;
}
static FORCEINLINE void BindVertexBuffer(GLuint BindingIndex, GLuint Buffer, GLintptr Offset, GLsizei Stride)
{
glBindVertexBuffer(BindingIndex, Buffer, Offset, Stride);
}
static FORCEINLINE void VertexAttribFormat(GLuint AttribIndex, GLint Size, GLenum Type, GLboolean Normalized, GLuint RelativeOffset)
{
glVertexAttribFormat(AttribIndex, Size, Type, Normalized, RelativeOffset);
}
static FORCEINLINE void VertexAttribIFormat(GLuint AttribIndex, GLint Size, GLenum Type, GLuint RelativeOffset)
{
glVertexAttribIFormat(AttribIndex, Size, Type, RelativeOffset);
}
static FORCEINLINE void VertexAttribBinding(GLuint AttribIndex, GLuint BindingIndex)
{
glVertexAttribBinding(AttribIndex, BindingIndex);
}
static FORCEINLINE void VertexBindingDivisor(GLuint BindingIndex, GLuint Divisor)
{
glVertexBindingDivisor(BindingIndex, Divisor);
}
#endif