Skip to content

Commit

Permalink
Documeting/cleaning up pipeline state header
Browse files Browse the repository at this point in the history
  • Loading branch information
colincornaby committed Nov 3, 2023
1 parent e8f47d3 commit c70da8d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
19 changes: 2 additions & 17 deletions Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipelineState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,16 @@ void plMetalRenderSpanPipelineState::ConfigureBlendMode(const uint32_t blendMode
case hsGMatState::kBlendAlpha:
if (blendMode & hsGMatState::kBlendInvertFinalAlpha) {
if (blendMode & hsGMatState::kBlendAlphaPremultiplied) {
// printf("glBlendFunc(GL_ONE, GL_SRC_ALPHA);\n");
descriptor->setSourceRGBBlendFactor(MTL::BlendFactorOne);
} else {
// printf("glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);\n");
descriptor->setSourceRGBBlendFactor(MTL::BlendFactorOneMinusSourceAlpha);
;
}
descriptor->setDestinationRGBBlendFactor(MTL::BlendFactorSourceAlpha);
} else {
if (blendMode & hsGMatState::kBlendAlphaPremultiplied) {
// printf("glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);\n");
descriptor->setSourceRGBBlendFactor(MTL::BlendFactorOne);
} else {
// printf("glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);\n");
descriptor->setSourceRGBBlendFactor(MTL::BlendFactorSourceAlpha);
}
descriptor->setDestinationRGBBlendFactor(MTL::BlendFactorOneMinusSourceAlpha);
Expand All @@ -201,13 +197,11 @@ void plMetalRenderSpanPipelineState::ConfigureBlendMode(const uint32_t blendMode
// Multiply the final color onto the frame buffer.
case hsGMatState::kBlendMult:
if (blendMode & hsGMatState::kBlendInvertFinalColor) {
// printf("glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR);\n");
descriptor->setSourceRGBBlendFactor(MTL::BlendFactorZero);
descriptor->setSourceAlphaBlendFactor(MTL::BlendFactorZero);
descriptor->setDestinationRGBBlendFactor(MTL::BlendFactorOneMinusSourceColor);
descriptor->setDestinationAlphaBlendFactor(MTL::BlendFactorOneMinusSourceColor);
} else {
// printf("glBlendFunc(GL_ZERO, GL_SRC_COLOR);\n");
descriptor->setSourceRGBBlendFactor(MTL::BlendFactorZero);
descriptor->setSourceAlphaBlendFactor(MTL::BlendFactorZero);
descriptor->setDestinationRGBBlendFactor(MTL::BlendFactorSourceColor);
Expand All @@ -217,29 +211,25 @@ void plMetalRenderSpanPipelineState::ConfigureBlendMode(const uint32_t blendMode

// Add final color to FB.
case hsGMatState::kBlendAdd:
// printf("glBlendFunc(GL_ONE, GL_ONE);\n");
descriptor->setRgbBlendOperation(MTL::BlendOperationAdd);
descriptor->setSourceRGBBlendFactor(MTL::BlendFactorOne);
descriptor->setDestinationRGBBlendFactor(MTL::BlendFactorOne);
break;

// Multiply final color by FB color and add it into the FB.
case hsGMatState::kBlendMADD:
// printf("glBlendFunc(GL_DST_COLOR, GL_ONE);\n");
descriptor->setSourceRGBBlendFactor(MTL::BlendFactorDestinationColor);
descriptor->setDestinationRGBBlendFactor(MTL::BlendFactorOne);
break;

// Final color times final alpha, added into the FB.
case hsGMatState::kBlendAddColorTimesAlpha:
if (blendMode & hsGMatState::kBlendInvertFinalAlpha) {
// printf("glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_ONE);\n");
descriptor->setSourceRGBBlendFactor(MTL::BlendFactorOneMinusSourceAlpha);
descriptor->setSourceAlphaBlendFactor(MTL::BlendFactorOneMinusSourceAlpha);
descriptor->setDestinationRGBBlendFactor(MTL::BlendFactorOne);
descriptor->setDestinationAlphaBlendFactor(MTL::BlendFactorOne);
} else {
// printf("glBlendFunc(GL_SRC_ALPHA, GL_ONE);\n");
descriptor->setSourceRGBBlendFactor(MTL::BlendFactorSourceAlpha);
descriptor->setSourceAlphaBlendFactor(MTL::BlendFactorSourceAlpha);
descriptor->setDestinationRGBBlendFactor(MTL::BlendFactorOne);
Expand All @@ -249,19 +239,12 @@ void plMetalRenderSpanPipelineState::ConfigureBlendMode(const uint32_t blendMode

// Overwrite final color onto FB
case 0:
// printf("glBlendFunc(GL_ONE, GL_ZERO);\n");
descriptor->setRgbBlendOperation(MTL::BlendOperationAdd);
descriptor->setAlphaBlendOperation(MTL::BlendOperationAdd);
// printf("glBlendFunc(GL_ONE, GL_ZERO);\n");
descriptor->setSourceRGBBlendFactor(MTL::BlendFactorOne);
descriptor->setDestinationRGBBlendFactor(MTL::BlendFactorZero);
descriptor->setSourceAlphaBlendFactor(MTL::BlendFactorOne);
descriptor->setDestinationAlphaBlendFactor(MTL::BlendFactorZero);

/*descriptor->colorAttachments()->object(0)->setSourceRGBBlendFactor(MTL::BlendFactorOne);
descriptor->colorAttachments()->object(0)->setSourceAlphaBlendFactor(MTL::BlendFactorOne);
descriptor->colorAttachments()->object(0)->setDestinationRGBBlendFactor(MTL::BlendFactorZero);
descriptor->colorAttachments()->object(0)->setDestinationAlphaBlendFactor(MTL::BlendFactorZero);*/
break;

default: {
Expand Down Expand Up @@ -400,6 +383,7 @@ const MTL::Function* plMetalDynamicMaterialPipelineState::GetVertexFunction(MTL:
{
MTL::FunctionConstantValues* functionConstants = MakeFunctionConstants();
MTL::Function* vertFunction;
// map the original engine vertex shader id to the pixel shader function
switch (fVertexShaderID) {
case plShaderID::vs_WaveFixedFin7:
vertFunction = library->newFunction(
Expand Down Expand Up @@ -453,6 +437,7 @@ const MTL::Function* plMetalDynamicMaterialPipelineState::GetFragmentFunction(MT
{
MTL::FunctionConstantValues* functionConstants = MakeFunctionConstants();
MTL::Function* fragFunction;
// map the original engine pixel shader id to the pixel shader function
switch (fFragmentShaderID) {
case plShaderID::ps_WaveFixed:
fragFunction = library->newFunction(
Expand Down
21 changes: 15 additions & 6 deletions Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipelineState.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#include "plMetalDevice.h"
#include "plSurface/plShaderTable.h"

//MARK: Base pipeline state

class plMetalPipelineState
{
public:
Expand Down Expand Up @@ -89,6 +91,8 @@ class plMetalPipelineState
}
};

//MARK: Abstract FVF vertex shader program parent type

class plMetalRenderSpanPipelineState : public plMetalPipelineState
{
public:
Expand Down Expand Up @@ -121,6 +125,8 @@ class plMetalRenderSpanPipelineState : public plMetalPipelineState
}
};

//MARK: Fixed function emulating material program

struct plMetalFragmentShaderDescription
{
uint8_t passTypes[8];
Expand Down Expand Up @@ -205,6 +211,8 @@ class plMetalMaterialPassPipelineState : public plMetalRenderSpanPipelineState
plMetalFragmentShaderDescription fFragmentShaderDescription;
};

//MARK: Shadow casting program

class plMetalRenderShadowCasterPipelineState : public plMetalRenderSpanPipelineState
{
public:
Expand Down Expand Up @@ -233,6 +241,8 @@ class plMetalRenderShadowCasterPipelineState : public plMetalRenderSpanPipelineS
}
};

//MARK: Shadow rendering program

class plMetalRenderShadowPipelineState : public plMetalMaterialPassPipelineState
{
public:
Expand All @@ -256,6 +266,8 @@ class plMetalRenderShadowPipelineState : public plMetalMaterialPassPipelineState
}
};

//MARK: Shader based render programs

class plMetalDynamicMaterialPipelineState : public plMetalRenderSpanPipelineState
{
public:
Expand Down Expand Up @@ -319,6 +331,8 @@ struct std::hash<plMetalPipelineState>
}
};

//MARK: Clear buffer program

class plMetalClearPipelineState : public plMetalPipelineState
{
public:
Expand All @@ -343,11 +357,11 @@ class plMetalClearPipelineState : public plMetalPipelineState
return new plMetalClearPipelineState(*this);
};

//
virtual const MTL::Function* GetVertexFunction(MTL::Library* library) override
{
return library->newFunction(NS::MakeConstantString("clearVertex"));
};

virtual const MTL::Function* GetFragmentFunction(MTL::Library* library) override
{
return library->newFunction(NS::MakeConstantString("clearFragment"),
Expand All @@ -362,13 +376,8 @@ class plMetalClearPipelineState : public plMetalPipelineState

virtual void ConfigureBlend(MTL::RenderPipelineColorAttachmentDescriptor* descriptor) override
{
// if (fShouldClearColor) {
descriptor->setSourceRGBBlendFactor(MTL::BlendFactorOne);
descriptor->setDestinationRGBBlendFactor(MTL::BlendFactorZero);
//} else {
// descriptor->setSourceRGBBlendFactor(MTL::BlendFactorZero);
// descriptor->setDestinationRGBBlendFactor(MTL::BlendFactorOne);
//}
};

virtual void ConfigureVertexDescriptor(MTL::VertexDescriptor* vertexDescriptor) override
Expand Down

0 comments on commit c70da8d

Please sign in to comment.