Daemon icon indicating copy to clipboard operation
Daemon copied to clipboard

Implement compute shaders support, make fragment shader non-mandatory

Open VReaperV opened this issue 1 year ago • 5 comments

Requires #1124.

Cherry-picked from #1137 to split a large pr up a bit.

Adds some code to allow using compute shaders. Shaders can now have either of vertex, fragment, or compute shaders enabled/disabled.

VReaperV avatar May 18 '24 06:05 VReaperV

It seems like compute shaders are a totally separate workflow from the existing draw shaders, which would ideally be a separate class. Like instead of just GLShader you have one class with fragment shader, vertex shader, and vertex attribs; and another with just compute shader.

I considered that, the reason I made it part of GLShader is that they can still make use of the way uniforms are set, vertex/fragment includes, same paths for loading/compiling shaders including shader binaries, as well as GLHeaders. Maybe both classes should be derived from GLShader which would just provide the aforementioned functionality.

VReaperV avatar May 24 '24 08:05 VReaperV

A really easy way to make things a bit clearer could be to have two constructors for GLShader, one for each use case. Instead of having a constructor that allows all 3 shader types at once.

slipher avatar May 24 '24 08:05 slipher

So something like

GLShader( const std::string &name, const std::string &mainShaderName, uint32_t vertexAttribsRequired, GLShaderManager *manager,
const bool hasVertexShader, const bool hasFragmentShader)

and

GLShader( const std::string &name, const std::string &mainShaderName, uint32_t vertexAttribsRequired, GLShaderManager *manager,
const bool hasComputeShader

?

VReaperV avatar May 24 '24 08:05 VReaperV

I guess there's nothing that distinguishes the constructors very well so maybe it would be easier to go ahead and define the subclasses even if all the functionality is in the base class. Like

class GLShaderBase {
    // everything that's in GLShader right now
};
class GLShader : public GLShaderBase { //draw shader
   // constructor does _hasFragment = true, _haveVertex = true?
};
class ComputeShader : public GLShaderBase {
    // constructor does _hasCompute = true
};

slipher avatar May 24 '24 09:05 slipher

Yeah, I ran into some issues with GLShader constructors earlier too, since the wrong one was being selected with some types being converted.

VReaperV avatar May 24 '24 10:05 VReaperV

I guess there's nothing that distinguishes the constructors very well so maybe it would be easier to go ahead and define the subclasses even if all the functionality is in the base class. Like

class GLShaderBase {
    // everything that's in GLShader right now
};
class GLShader : public GLShaderBase { //draw shader
   // constructor does _hasFragment = true, _haveVertex = true?
};
class ComputeShader : public GLShaderBase {
    // constructor does _hasCompute = true
};

This should be evaluated later because #1105 and some further PRs add more GLShader constructors.

VReaperV avatar Jun 16 '24 12:06 VReaperV

Don't forget to squash the fix commit. ;-)

illwieckz avatar Jun 22 '24 14:06 illwieckz

Yep, done.

VReaperV avatar Jun 22 '24 16:06 VReaperV