Skip to content

Implement shader pipelines #1587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
1,408 changes: 836 additions & 572 deletions src/engine/renderer/gl_shader.cpp

Large diffs are not rendered by default.

1,066 changes: 716 additions & 350 deletions src/engine/renderer/gl_shader.h

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/engine/renderer/glsl_source/cull_cp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ layout (local_size_x = 64, local_size_y = 1, local_size_z = 1) in;

layout(binding = 0) uniform sampler2D depthImage;

struct SurfaceDescriptor {
BoundingSphere boundingSphere;
uint surfaceCommandIDs[MAX_SURFACE_COMMANDS];
};

layout(std430, binding = BIND_SURFACE_DESCRIPTORS) readonly restrict buffer surfaceDescriptorsSSBO {
SurfaceDescriptor surfaces[];
};
Expand Down
6 changes: 3 additions & 3 deletions src/engine/renderer/glsl_source/fogQuake3_vp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ void DeformVertex( inout vec4 pos,
inout vec3 normal,
inout vec2 st,
inout vec4 color,
in float time);
in float time );

void main()
void main()
{
#insert material_vp

Expand All @@ -63,7 +63,7 @@ void main()
LB.normal,
texCoord,
color,
u_Time);
u_Time );

// transform vertex position into homogenous clip-space
gl_Position = u_ModelViewProjectionMatrix * position;
Expand Down
10 changes: 3 additions & 7 deletions src/engine/renderer/glsl_source/generic_vp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ void DeformVertex( inout vec4 pos,
inout vec3 normal,
inout vec2 st,
inout vec4 color,
in float time);
in float time );

void main()
void main()
{
#insert material_vp

Expand All @@ -72,11 +72,7 @@ void main()
color = color * ColorModulateToColor( u_ColorModulateColorGen, lightFactor )
+ unpackUnorm4x8( u_Color ) * vec4( lightFactor, lightFactor, lightFactor, 1.0 );

DeformVertex( position,
LB.normal,
texCoord,
color,
u_Time);
DeformVertex( position, LB.normal, texCoord, color, u_Time );

// transform vertex position into homogenous clip-space
gl_Position = u_ModelViewProjectionMatrix * position;
Expand Down
4 changes: 2 additions & 2 deletions src/engine/renderer/glsl_source/lightMapping_vp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ OUT(smooth) vec3 var_Normal;

OUT(smooth) vec4 var_Color;

void DeformVertex(inout vec4 pos, inout vec3 normal, inout vec2 st, inout vec4 color, in float time);
void DeformVertex( inout vec4 pos, inout vec3 normal, inout vec2 st, inout vec4 color, in float time );

void main()
{
Expand All @@ -78,7 +78,7 @@ void main()

color = color * ColorModulateToColor( u_ColorModulateColorGen ) + unpackUnorm4x8( u_Color );

DeformVertex(position, LB.normal, texCoord, color, u_Time);
DeformVertex( position, LB.normal, texCoord, color, u_Time );

// transform vertex position into homogenous clip-space
gl_Position = u_ModelViewProjectionMatrix * position;
Expand Down
4 changes: 2 additions & 2 deletions src/engine/renderer/glsl_source/material_cp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ struct BoundingSphere {
float radius;
};

struct SurfaceDescriptor {
/* struct SurfaceDescriptor {
BoundingSphere boundingSphere;
uint surfaceCommandIDs[MAX_SURFACE_COMMANDS];
};
}; */

struct PortalSurface {
BoundingSphere boundingSphere;
Expand Down
38 changes: 21 additions & 17 deletions src/engine/renderer/tr_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,32 +120,36 @@ GLuint64 BindAnimatedImage( int unit, const textureBundle_t *bundle )
return GL_BindToTMU( unit, bundle->image[ index ] );
}

void GL_BindProgram( shaderProgram_t *program )
{
if ( !program )
{
void GL_BindProgram( GLuint pipeline, bool override ) {
if ( !pipeline ) {
GL_BindNullProgram();
return;
}

if ( glState.currentProgram != program )
{
glUseProgram( program->program );
glState.currentProgram = program;
if ( glState.currentPipeline != pipeline ) {
if ( glConfig2.separateShaderObjectsAvailable && !override ) {
glBindProgramPipeline( pipeline );
} else {
glUseProgram( pipeline );
}

glState.currentPipeline = pipeline;
}
}

void GL_BindNullProgram()
{
if ( r_logFile->integer )
{
void GL_BindNullProgram( bool override ) {
if ( r_logFile->integer ) {
GLimp_LogComment( "--- GL_BindNullProgram ---\n" );
}

if ( glState.currentProgram )
{
glUseProgram( 0 );
glState.currentProgram = nullptr;
if ( glState.currentPipeline ) {
if ( glConfig2.separateShaderObjectsAvailable && !override ) {
glBindProgramPipeline( 0 );
} else {
glUseProgram( 0 );
}

glState.currentPipeline = 0;
}
}

Expand Down Expand Up @@ -1378,7 +1382,7 @@ static void RB_SetupLightForShadowing( trRefLight_t *light, int index,
bool shadowClip )
{
// HACK: bring OpenGL into a safe state or strange FBO update problems will occur
GL_BindProgram( nullptr );
GL_BindNullProgram();
GL_State( GLS_DEFAULT );

GL_Bind( tr.whiteImage );
Expand Down
2 changes: 2 additions & 0 deletions src/engine/renderer/tr_bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5081,6 +5081,7 @@ void RE_LoadWorldMap( const char *name )

Q_strncpyz( s_worldData.baseName, COM_SkipPath( s_worldData.name ), sizeof( s_worldData.name ) );
COM_StripExtension3( s_worldData.baseName, s_worldData.baseName, sizeof( s_worldData.baseName ) );
tr.loadingMap = s_worldData.baseName;

startMarker = (byte*) ri.Hunk_Alloc( 0, ha_pref::h_low );

Expand Down Expand Up @@ -5239,6 +5240,7 @@ void RE_LoadWorldMap( const char *name )
}

tr.worldLoaded = true;
tr.loadingMap = "";
GLSL_InitWorldShaders();

if ( glConfig2.reflectionMappingAvailable ) {
Expand Down
4 changes: 2 additions & 2 deletions src/engine/renderer/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
glState.vertexAttribsState = 0;
glState.vertexAttribPointersSet = 0;

GL_BindProgram( nullptr );
GL_BindNullProgram();

glBindBuffer( GL_ARRAY_BUFFER, 0 );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
Expand Down Expand Up @@ -1137,7 +1137,7 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
}

int deformIndex =
gl_shaderManager.getDeformShaderIndex( shader.deforms, shader.numDeforms );
gl_shaderManager.GetDeformShaderIndex( shader.deforms, shader.numDeforms );

for ( shaderStage_t *stage = shader.stages; stage != shader.lastStage; stage++ )
{
Expand Down
23 changes: 7 additions & 16 deletions src/engine/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -1415,18 +1415,8 @@ enum class shaderProfilerRenderSubGroupsMode {
};

// *INDENT-ON*

// Tr3B - shaderProgram_t represents a pair of one
// GLSL vertex and one GLSL fragment shader
struct shaderProgram_t
{
GLuint program;
GLuint VS, FS, CS;
uint32_t attribs; // vertex array attributes
GLint *uniformLocations;
GLuint *uniformBlockIndexes;
byte *uniformFirewall;
};
struct ShaderProgramDescriptor;
struct ShaderPipelineDescriptor;

// trRefdef_t holds everything that comes in refdef_t,
// as well as the locally generated scene information
Expand Down Expand Up @@ -2439,7 +2429,7 @@ enum class shaderProfilerRenderSubGroupsMode {
float vertexAttribsInterpolation; // 0 = no interpolation, 1 = final position
uint32_t vertexAttribsNewFrame; // offset for VBO vertex animations
uint32_t vertexAttribsOldFrame; // offset for VBO vertex animations
shaderProgram_t *currentProgram;
GLuint currentPipeline;
FBO_t *currentFBO;
VBO_t *currentVBO;
IBO_t *currentIBO;
Expand Down Expand Up @@ -2723,6 +2713,7 @@ enum class shaderProfilerRenderSubGroupsMode {

bool worldLoaded;
world_t *world;
std::string loadingMap;

TextureManager textureManager;

Expand Down Expand Up @@ -3239,10 +3230,10 @@ inline bool checkGLErrors()
void GL_BindNearestCubeMap( int unit, const vec3_t xyz );
void GL_Unbind( image_t *image );
GLuint64 BindAnimatedImage( int unit, const textureBundle_t *bundle );
void GL_TextureFilter( image_t *image, filterType_t filterType );
void GL_BindProgram( shaderProgram_t *program );
GLuint64 GL_BindToTMU( int unit, image_t *image );
void GL_BindNullProgram();
void GL_TextureFilter( image_t *image, filterType_t filterType );
void GL_BindProgram( GLuint pipeline, bool override = false );
void GL_BindNullProgram( bool override = false);
void GL_SetDefaultState();
void GL_SelectTexture( int unit );
void GL_TextureMode( const char *string );
Expand Down
2 changes: 1 addition & 1 deletion src/engine/renderer/tr_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2469,7 +2469,7 @@ static void R_DebugGraphics()
// the render thread can't make callbacks to the main thread
R_SyncRenderThread();

GL_BindProgram( nullptr );
GL_BindNullProgram();

GL_Bind( tr.whiteImage );

Expand Down
1 change: 1 addition & 0 deletions src/engine/renderer/tr_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ struct glconfig2_t
int textureRGBA16BlendAvailable;
bool textureIntegerAvailable;
bool textureRGAvailable;
bool separateShaderObjectsAvailable;
bool computeShaderAvailable;
bool bindlessTexturesAvailable; // do the driver/hardware support it
bool usingBindlessTextures; // are we using them right now
Expand Down
Loading
Loading