From 5588183cc77cc93feb9755354d5fc450430681e8 Mon Sep 17 00:00:00 2001 From: Colin Cornaby Date: Thu, 19 Oct 2023 21:52:00 -0700 Subject: [PATCH] Documeting/cleaning up pipeline state header --- .../pfMetalPipeline/plMetalPipelineState.cpp | 19 ++--------------- .../pfMetalPipeline/plMetalPipelineState.h | 21 +++++++++++++------ 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipelineState.cpp b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipelineState.cpp index b0d79bf911..834c7f713e 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipelineState.cpp +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipelineState.cpp @@ -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); @@ -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); @@ -217,7 +211,6 @@ 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); @@ -225,7 +218,6 @@ void plMetalRenderSpanPipelineState::ConfigureBlendMode(const uint32_t blendMode // 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; @@ -233,13 +225,11 @@ void plMetalRenderSpanPipelineState::ConfigureBlendMode(const uint32_t blendMode // 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); @@ -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: { @@ -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( @@ -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( diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipelineState.h b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipelineState.h index 85ce9317e7..e6a87e32ce 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipelineState.h +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipelineState.h @@ -50,6 +50,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plMetalDevice.h" #include "plSurface/plShaderTable.h" +//MARK: Base pipeline state + class plMetalPipelineState { public: @@ -89,6 +91,8 @@ class plMetalPipelineState } }; +//MARK: Abstract FVF vertex shader program parent type + class plMetalRenderSpanPipelineState : public plMetalPipelineState { public: @@ -121,6 +125,8 @@ class plMetalRenderSpanPipelineState : public plMetalPipelineState } }; +//MARK: Fixed function emulating material program + struct plMetalFragmentShaderDescription { uint8_t passTypes[8]; @@ -205,6 +211,8 @@ class plMetalMaterialPassPipelineState : public plMetalRenderSpanPipelineState plMetalFragmentShaderDescription fFragmentShaderDescription; }; +//MARK: Shadow casting program + class plMetalRenderShadowCasterPipelineState : public plMetalRenderSpanPipelineState { public: @@ -233,6 +241,8 @@ class plMetalRenderShadowCasterPipelineState : public plMetalRenderSpanPipelineS } }; +//MARK: Shadow rendering program + class plMetalRenderShadowPipelineState : public plMetalMaterialPassPipelineState { public: @@ -256,6 +266,8 @@ class plMetalRenderShadowPipelineState : public plMetalMaterialPassPipelineState } }; +//MARK: Shader based render programs + class plMetalDynamicMaterialPipelineState : public plMetalRenderSpanPipelineState { public: @@ -319,6 +331,8 @@ struct std::hash } }; +//MARK: Clear buffer program + class plMetalClearPipelineState : public plMetalPipelineState { public: @@ -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"), @@ -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