Skip to content

Commit

Permalink
Preventing redundant binds of samplers by tracking them locally
Browse files Browse the repository at this point in the history
  • Loading branch information
colincornaby committed Aug 20, 2023
1 parent 7a3473f commit 8e84b91
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,13 @@ void plMetalMaterialShaderRef::IBuildLayerTexture(MTL::RenderCommandEncoder *enc

}

MTL::SamplerState* samplerState = fPipeline->fDevice.SampleStateForClampFlags(hsGMatState::hsGMatClampFlags(layer->GetClampFlags()));
encoder->setFragmentSamplerState(samplerState, offsetFromRootLayer);
if (fPipeline->fState.layerStates[offsetFromRootLayer].clampFlag != layer->GetClampFlags())
{
MTL::SamplerState* samplerState = fPipeline->fDevice.SampleStateForClampFlags(hsGMatState::hsGMatClampFlags(layer->GetClampFlags()));
encoder->setFragmentSamplerState(samplerState, offsetFromRootLayer);

fPipeline->fState.layerStates[offsetFromRootLayer].clampFlag = hsGMatState::hsGMatClampFlags(layer->GetClampFlags());
}
}

uint32_t plMetalMaterialShaderRef::ILayersAtOnce(uint32_t which)
Expand Down
5 changes: 5 additions & 0 deletions Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4619,4 +4619,9 @@ void plMetalPipeline::plMetalPipelineCurrentState::Reset()
fCurrentDepthStencilState = nullptr;
fCurrentVertexBuffer = nullptr;
fCurrentCullMode.reset();

for(auto& layer: layerStates)
{
layer.clampFlag = hsGMatState::hsGMatClampFlags(-1);
}
}
10 changes: 10 additions & 0 deletions Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,17 @@ class plMetalPipeline : public pl3DPipeline<plMetalDevice>

NS::AutoreleasePool* fCurrentPool;

/// Describes the state for the "fixed function" shader.
struct plMetalPipelineCurrentState {

// notes state of a given layer for a draw pass
// index is the offset from the curent root layer
// for the draw pass, not the overall index in the
// material
struct plMetalPipelineLayerState {
hsGMatState::hsGMatClampFlags clampFlag;
} layerStates[8];

std::optional<MTL::CullMode> fCurrentCullMode;
const MTL::RenderPipelineState* fCurrentPipelineState;
MTL::Buffer* fCurrentVertexBuffer;
Expand Down

0 comments on commit 8e84b91

Please sign in to comment.