Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/engine/renderer/BufferBind.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ namespace BufferBind {
MATERIALS = 0,
TEX_DATA = 1,
LIGHTMAP_DATA = 2,
LIGHTS = 3,
GLOBAL_DATA = 3,
LIGHTS = 4,

SURFACE_BATCHES = 4,
SURFACE_BATCHES = 5,

// SSBO
SURFACE_DESCRIPTORS = 0,
Expand Down
40 changes: 40 additions & 0 deletions src/engine/renderer/GLMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "GLMemory.h"

#include "gl_shader.h"

// 128 MB, should be enough to fit anything in BAR without going overboard
const GLsizeiptr GLStagingBuffer::SIZE = 128 * 1024 * 1024 / sizeof( uint32_t );

GLStagingBuffer stagingBuffer;
PushBuffer pushBuffer;

void GLBufferCopy( GLBuffer* src, GLBuffer* dst, GLintptr srcOffset, GLintptr dstOffset, GLsizeiptr size ) {
glCopyNamedBufferSubData( src->id, dst->id,
Expand Down Expand Up @@ -114,6 +117,10 @@ void GLStagingBuffer::FlushAll() {
FlushStagingCopyQueue();
}

bool GLStagingBuffer::Active() const {
return buffer.id;
}

void GLStagingBuffer::InitGLBuffer() {
buffer.GenBuffer();

Expand All @@ -130,3 +137,36 @@ void GLStagingBuffer::FreeGLBuffer() {
current = 0;
last = 0;
}

void PushBuffer::InitGLBuffers() {
globalUBO.GenBuffer();

globalUBO.BufferStorage( pushBuffer.constUniformsSize + pushBuffer.frameUniformsSize, 1, nullptr );

globalUBO.BindBufferBase();
}

void PushBuffer::FreeGLBuffers() {
globalUBO.DelBuffer();
}

uint32_t* PushBuffer::MapGlobalUniformData( const int updateType ) {
switch ( updateType ) {
case GLUniform::CONST:
globalUBOData = stagingBuffer.MapBuffer( constUniformsSize );
stagingBuffer.QueueStagingCopy( &globalUBO, 0 );
break;
case GLUniform::FRAME:
globalUBOData = stagingBuffer.MapBuffer( frameUniformsSize );
stagingBuffer.QueueStagingCopy( &globalUBO, constUniformsSize );
break;
default:
ASSERT_UNREACHABLE();
}

return globalUBOData;
}

void PushBuffer::PushGlobalUniforms() {
stagingBuffer.FlushAll();
}
27 changes: 26 additions & 1 deletion src/engine/renderer/GLMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class GLBuffer {

void DelBuffer() {
glDeleteBuffers( 1, &id );
id = 0;
mapped = false;
}

Expand Down Expand Up @@ -303,6 +304,8 @@ class GLStagingBuffer {
void FlushStagingCopyQueue();
void FlushAll();

bool Active() const;

void InitGLBuffer();
void FreeGLBuffer();

Expand All @@ -321,6 +324,28 @@ class GLStagingBuffer {
GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_INVALIDATE_BUFFER_BIT );
};

struct PushBuffer {
uint32_t constUniformsSize;
uint32_t frameUniformsSize;
uint32_t globalUBOSize;
uint32_t* globalUBOData;

uint32_t pushStart = UINT32_MAX;
uint32_t pushEnd = 0;

uint32_t sector = 0;
const uint32_t MAX_SECTORS = 1024;

GLUBO globalUBO = GLUBO( "globalUniforms", BufferBind::GLOBAL_DATA, 0, 0 );

void InitGLBuffers();
void FreeGLBuffers();

uint32_t* MapGlobalUniformData( const int updateType );
void PushGlobalUniforms();
};

extern GLStagingBuffer stagingBuffer;
extern PushBuffer pushBuffer;

#endif // GLMEMORY_H
#endif // GLMEMORY_H
46 changes: 28 additions & 18 deletions src/engine/renderer/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void UpdateSurfaceDataGeneric3D( uint32_t* materials, shaderStage_t* pStage, boo

gl_genericShaderMaterial->SetUniform_DepthScale( pStage->depthFadeValue );

gl_genericShaderMaterial->WriteUniformsToBuffer( materials );
gl_genericShaderMaterial->WriteUniformsToBuffer( materials, GLShader::MATERIAL );
}

void UpdateSurfaceDataLightMapping( uint32_t* materials, shaderStage_t* pStage, bool, bool vertexLit, bool fullbright ) {
Expand Down Expand Up @@ -207,7 +207,7 @@ void UpdateSurfaceDataLightMapping( uint32_t* materials, shaderStage_t* pStage,

gl_lightMappingShaderMaterial->SetUniform_SpecularExponent( specExpMin, specExpMax );

gl_lightMappingShaderMaterial->WriteUniformsToBuffer( materials );
gl_lightMappingShaderMaterial->WriteUniformsToBuffer( materials, GLShader::MATERIAL );
}

void UpdateSurfaceDataReflection( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ) {
Expand Down Expand Up @@ -244,7 +244,7 @@ void UpdateSurfaceDataReflection( uint32_t* materials, shaderStage_t* pStage, bo
gl_reflectionShaderMaterial->SetUniform_ReliefDepthScale( depthScale );
gl_reflectionShaderMaterial->SetUniform_ReliefOffsetBias( shader->reliefOffsetBias );

gl_reflectionShaderMaterial->WriteUniformsToBuffer( materials );
gl_reflectionShaderMaterial->WriteUniformsToBuffer( materials, GLShader::MATERIAL );
}

void UpdateSurfaceDataSkybox( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ) {
Expand All @@ -255,7 +255,7 @@ void UpdateSurfaceDataSkybox( uint32_t* materials, shaderStage_t* pStage, bool,
// u_AlphaThreshold
gl_skyboxShaderMaterial->SetUniform_AlphaTest( GLS_ATEST_NONE );

gl_skyboxShaderMaterial->WriteUniformsToBuffer( materials );
gl_skyboxShaderMaterial->WriteUniformsToBuffer( materials, GLShader::MATERIAL );
}

void UpdateSurfaceDataScreen( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ) {
Expand All @@ -268,7 +268,7 @@ void UpdateSurfaceDataScreen( uint32_t* materials, shaderStage_t* pStage, bool,
this seems to be the only material system shader that might need it to not be global */
gl_screenShaderMaterial->SetUniform_CurrentMapBindless( BindAnimatedImage( 0, &pStage->bundle[TB_COLORMAP] ) );

gl_screenShaderMaterial->WriteUniformsToBuffer( materials );
gl_screenShaderMaterial->WriteUniformsToBuffer( materials, GLShader::MATERIAL );
}

void UpdateSurfaceDataHeatHaze( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ) {
Expand All @@ -285,7 +285,7 @@ void UpdateSurfaceDataHeatHaze( uint32_t* materials, shaderStage_t* pStage, bool
// bind u_NormalScale
gl_heatHazeShaderMaterial->SetUniform_NormalScale( normalScale );

gl_heatHazeShaderMaterial->WriteUniformsToBuffer( materials );
gl_heatHazeShaderMaterial->WriteUniformsToBuffer( materials, GLShader::MATERIAL );
}

void UpdateSurfaceDataLiquid( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ) {
Expand Down Expand Up @@ -331,15 +331,15 @@ void UpdateSurfaceDataLiquid( uint32_t* materials, shaderStage_t* pStage, bool,

gl_liquidShaderMaterial->SetUniform_NormalScale( normalScale );

gl_liquidShaderMaterial->WriteUniformsToBuffer( materials );
gl_liquidShaderMaterial->WriteUniformsToBuffer( materials, GLShader::MATERIAL );
}

void UpdateSurfaceDataFog( uint32_t* materials, shaderStage_t* pStage, bool, bool, bool ) {
// shader_t* shader = pStage->shader;

materials += pStage->bufferOffset;

gl_fogQuake3ShaderMaterial->WriteUniformsToBuffer( materials );
gl_fogQuake3ShaderMaterial->WriteUniformsToBuffer( materials, GLShader::MATERIAL );
}

/*
Expand Down Expand Up @@ -1593,9 +1593,24 @@ void MaterialSystem::UpdateDynamicSurfaces() {
GL_CheckErrors();
}

void MaterialSystem::SetConstUniforms() {
globalUBOProxy->SetUniform_SurfaceDescriptorsCount( surfaceDescriptorsCount );
uint32_t globalWorkGroupX = surfaceDescriptorsCount % MAX_COMMAND_COUNTERS == 0 ?
surfaceDescriptorsCount / MAX_COMMAND_COUNTERS : surfaceDescriptorsCount / MAX_COMMAND_COUNTERS + 1;

globalUBOProxy->SetUniform_FirstPortalGroup( globalWorkGroupX );
globalUBOProxy->SetUniform_TotalPortals( totalPortals );
}

void MaterialSystem::SetFrameUniforms() {
globalUBOProxy->SetUniform_Frame( nextFrame );

globalUBOProxy->SetUniform_UseFrustumCulling( r_gpuFrustumCulling.Get() );
globalUBOProxy->SetUniform_UseOcclusionCulling( r_gpuOcclusionCulling.Get() );
}

void MaterialSystem::UpdateFrameData() {
gl_clearSurfacesShader->BindProgram( 0 );
gl_clearSurfacesShader->SetUniform_Frame( nextFrame );
gl_clearSurfacesShader->DispatchCompute( MAX_VIEWS, 1, 1 );

GL_CheckErrors();
Expand Down Expand Up @@ -1624,8 +1639,10 @@ void MaterialSystem::DepthReduction() {
uint32_t globalWorkgroupX = ( width + 7 ) / 8;
uint32_t globalWorkgroupY = ( height + 7 ) / 8;

// FIXME: u_DepthMap object on the shader is not actually used
GL_Bind( tr.currentDepthImage );
gl_depthReductionShader->SetUniform_DepthMapBindless(
GL_BindToTMU( 0, tr.currentDepthImage )
);

glBindImageTexture( 2, depthImage->texnum, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_R32F );

gl_depthReductionShader->SetUniform_InitialDepthLevel( true );
Expand Down Expand Up @@ -1681,15 +1698,9 @@ void MaterialSystem::CullSurfaces() {
uint32_t globalWorkGroupX = surfaceDescriptorsCount % MAX_COMMAND_COUNTERS == 0 ?
surfaceDescriptorsCount / MAX_COMMAND_COUNTERS : surfaceDescriptorsCount / MAX_COMMAND_COUNTERS + 1;
GL_Bind( depthImage );
gl_cullShader->SetUniform_Frame( nextFrame );
gl_cullShader->SetUniform_ViewID( view );
gl_cullShader->SetUniform_SurfaceDescriptorsCount( surfaceDescriptorsCount );
gl_cullShader->SetUniform_UseFrustumCulling( r_gpuFrustumCulling.Get() );
gl_cullShader->SetUniform_UseOcclusionCulling( r_gpuOcclusionCulling.Get() );
gl_cullShader->SetUniform_CameraPosition( origin );
gl_cullShader->SetUniform_ModelViewMatrix( viewMatrix );
gl_cullShader->SetUniform_FirstPortalGroup( globalWorkGroupX );
gl_cullShader->SetUniform_TotalPortals( totalPortals );
gl_cullShader->SetUniform_ViewWidth( depthImage->width );
gl_cullShader->SetUniform_ViewHeight( depthImage->height );
gl_cullShader->SetUniform_SurfaceCommandsOffset( surfaceCommandsCount * ( MAX_VIEWS * nextFrame + view ) );
Expand Down Expand Up @@ -1721,7 +1732,6 @@ void MaterialSystem::CullSurfaces() {
gl_cullShader->DispatchCompute( globalWorkGroupX, 1, 1 );

gl_processSurfacesShader->BindProgram( 0 );
gl_processSurfacesShader->SetUniform_Frame( nextFrame );
gl_processSurfacesShader->SetUniform_ViewID( view );
gl_processSurfacesShader->SetUniform_SurfaceCommandsOffset( surfaceCommandsCount * ( MAX_VIEWS * nextFrame + view ) );

Expand Down
2 changes: 2 additions & 0 deletions src/engine/renderer/Material.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ class MaterialSystem {

void StartFrame();
void EndFrame();
void SetConstUniforms();
void SetFrameUniforms();

void GenerateDepthImages( const int width, const int height, imageParams_t imageParms );

Expand Down
Loading
Loading