Skip to content

Commit

Permalink
More feedback implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
colincornaby committed Nov 4, 2023
1 parent 55ff113 commit 8e5feed
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 44 deletions.
4 changes: 2 additions & 2 deletions Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ void plMetalDevice::SubmitCommandBuffer()
fClearDrawableDepth = 1.0;
}

MTL::SamplerState* plMetalDevice::SampleStateForClampFlags(hsGMatState::hsGMatClampFlags sampleState)
MTL::SamplerState* plMetalDevice::SampleStateForClampFlags(hsGMatState::hsGMatClampFlags sampleState) const
{
return fSamplerStates[sampleState];
}
Expand Down Expand Up @@ -1256,7 +1256,7 @@ MTL::RenderCommandEncoder* plMetalDevice::CurrentRenderCommandEncoder()
return fCurrentRenderTargetCommandEncoder;
}

CA::MetalDrawable* plMetalDevice::GetCurrentDrawable()
CA::MetalDrawable* plMetalDevice::GetCurrentDrawable() const
{
return fCurrentDrawable;
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ class plMetalDevice
// Currently requires a CA drawable and not a Metal drawable. In since CA drawable is only abstract implementation I know about, not sure where we would find others?
void CreateNewCommandBuffer(CA::MetalDrawable* drawable);
MTL::CommandBuffer* GetCurrentCommandBuffer();
CA::MetalDrawable* GetCurrentDrawable();
CA::MetalDrawable* GetCurrentDrawable() const;
/// Submit the command buffer to the GPU and draws all the render passes. Clears the current command buffer.
void SubmitCommandBuffer();
void Clear(bool shouldClearColor, simd_float4 clearColor, bool shouldClearDepth, float clearDepth);

void SetMaxAnsiotropy(uint8_t maxAnsiotropy);
void SetMSAASampleCount(uint8_t sampleCount);

MTL::SamplerState* SampleStateForClampFlags(hsGMatState::hsGMatClampFlags sampleState);
MTL::SamplerState* SampleStateForClampFlags(hsGMatState::hsGMatClampFlags sampleState) const;

NS::UInteger CurrentTargetSampleCount()
{
Expand Down
6 changes: 3 additions & 3 deletions Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDeviceRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class plMetalDeviceRef : public hsGDeviceRef
public:
void Unlink();
void Link(plMetalDeviceRef** back);
plMetalDeviceRef* GetNext() { return fNext; }
bool IsLinked() { return fBack != nullptr; }
plMetalDeviceRef* GetNext() const { return fNext; }
bool IsLinked() { return fBack != nullptr; } const

bool HasFlag(uint32_t f) const { return 0 != (fFlags & f); }
void SetFlag(uint32_t f, bool on)
Expand Down Expand Up @@ -287,7 +287,7 @@ class plMetalRenderTargetRef : public plMetalTextureRef
MTL::Texture* fDepthBuffer;

void Link(plMetalRenderTargetRef** back) { plMetalDeviceRef::Link((plMetalDeviceRef**)back); }
plMetalRenderTargetRef* GetNext() { return (plMetalRenderTargetRef*)fNext; }
plMetalRenderTargetRef* GetNext() const { return (plMetalRenderTargetRef*)fNext; }

plMetalRenderTargetRef() : fDepthBuffer(nullptr)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,22 @@ class plLayerInterface;
class plMetalMaterialShaderRef : public plMetalDeviceRef
{
protected:
plMetalPipeline *fPipeline;
hsGMaterial *fMaterial;
plMetalPipeline* fPipeline;
hsGMaterial* fMaterial;
// temporary holder for the fragment shader to use, we don't own this reference
MTL::Function *fFragFunction;
MTL::Function* fFragFunction;

private:
std::vector<uint32_t> fPassIndices;
// FIXME: This should be retained/released
MTL::Device *fDevice;
std::vector<MTL::Buffer *> fPassArgumentBuffers;
MTL::Device* fDevice;
std::vector<MTL::Buffer*> fPassArgumentBuffers;

public:
void Link(plMetalMaterialShaderRef **back) { plMetalDeviceRef::Link((plMetalDeviceRef **)back); }
plMetalMaterialShaderRef* GetNext() const { return (plMetalMaterialShaderRef *)fNext; }
plMetalMaterialShaderRef* GetNext() const { return (plMetalMaterialShaderRef*)fNext; }

plMetalMaterialShaderRef(hsGMaterial *mat, plMetalPipeline *pipe);
plMetalMaterialShaderRef(hsGMaterial* mat, plMetalPipeline* pipe);
~plMetalMaterialShaderRef();

void Release() override;
Expand Down Expand Up @@ -116,7 +116,7 @@ class plMetalMaterialShaderRef : public plMetalDeviceRef
std::vector<plLayerInterface*>* piggybacks,
const std::function<plLayerInterface* (plLayerInterface*, uint32_t)>& preEncodeTransform,
const std::function<plLayerInterface* (plLayerInterface*, uint32_t)>& postEncodeTransform);
bool ICanEatLayer(plLayerInterface *lay);
bool ICanEatLayer(plLayerInterface* lay);
uint32_t ILayersAtOnce(uint32_t which);

void IBuildLayerTexture(MTL::RenderCommandEncoder* encoder, uint32_t offsetFromRootLayer, plLayerInterface* layer);
Expand Down
37 changes: 18 additions & 19 deletions Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ void plMetalPipeline::ClearRenderTarget(const hsColorRGBA* col, const float* dep
if (fView.fRenderState & (kRenderClearColor | kRenderClearDepth)) {
hsColorRGBA clearColor = col ? *col : GetClearColor();
float clearDepth = depth ? *depth : fView.GetClearDepth();
fDevice.Clear(fView.fRenderState & kRenderClearColor, {clearColor.r, clearColor.g, clearColor.b, clearColor.a}, fView.fRenderState & kRenderClearDepth, 1.0);
fDevice.Clear(fView.fRenderState & kRenderClearColor, { clearColor.r, clearColor.g, clearColor.b, clearColor.a }, fView.fRenderState & kRenderClearDepth, 1.0);
fState.Reset();
}
}
Expand Down Expand Up @@ -1361,7 +1361,7 @@ void plMetalPipeline::IRenderProjectionEach(const plRenderPrimFunc& render, hsGM
// For each projector:
int k;
for (k = 0; k < fProjEach.size(); k++) {
// Push it's projected texture as a piggyback.
// Push its projected texture as a piggyback.
plLightInfo* li = fProjEach[k];
plMetalMaterialShaderRef* mRef = static_cast<plMetalMaterialShaderRef*>(material->GetDeviceRef());

Expand All @@ -1384,7 +1384,7 @@ void plMetalPipeline::IRenderProjectionEach(const plRenderPrimFunc& render, hsGM

RemoveLayerInterface(&layLightBase, false);

// Pop it's projected texture off piggyback
// Pop its projected texture off piggyback
IPopProjPiggyBacks();
}
}
Expand Down Expand Up @@ -1539,11 +1539,11 @@ bool plMetalPipeline::IHandleMaterialPass(hsGMaterial* material, uint32_t pass,
/*
The programmable pipeline doesn't do things like set the texture transform matrices,
In practice, the transforms aren't set and used. Does it matter that the Metal
implementation doesn't implemention the full inputs the DX version gets?
implementation doesn't implement the full inputs the DX version gets?
If it is implemented, the same checks the DX version does should be also implemented.
DX will set texture transforms, but then turn them off in the pipeline and manually
manipulate texture co-ords in the shader.
manipulate texture coords in the shader.
Texture setting should also _maybe_ be reconciled with the "fixed" pipeline. But
the fixed pipeline uses indirect textures mapped to a buffer. That approach could
Expand Down Expand Up @@ -2532,7 +2532,7 @@ void plMetalPipeline::PopCurrentLightSources()
plLayerInterface* plMetalPipeline::IPushOverBaseLayer(plLayerInterface* li)
{
if (!li)
return nil;
return nullptr;

fOverLayerStack.emplace_back(li);

Expand Down Expand Up @@ -2569,7 +2569,7 @@ plLayerInterface* plMetalPipeline::IPopOverBaseLayer(plLayerInterface* li)
plLayerInterface* plMetalPipeline::IPushOverAllLayer(plLayerInterface* li)
{
if (!li)
return nil;
return nullptr;

fOverLayerStack.push_back(li);

Expand All @@ -2592,7 +2592,7 @@ plLayerInterface* plMetalPipeline::IPushOverAllLayer(plLayerInterface* li)
plLayerInterface* plMetalPipeline::IPopOverAllLayer(plLayerInterface* li)
{
if (!li)
return nil;
return nullptr;

fForceMatHandle = true;

Expand Down Expand Up @@ -2638,8 +2638,7 @@ void plMetalPipeline::IPushPiggyBacks(hsGMaterial* mat)
if (fView.fRenderState & plPipeline::kRenderNoPiggyBacks)
return;

int i;
for (i = 0; i < mat->GetNumPiggyBacks(); i++) {
for (int i = 0; i < mat->GetNumPiggyBacks(); i++) {
if (!mat->GetPiggyBack(i))
continue;

Expand Down Expand Up @@ -2916,7 +2915,7 @@ bool plMetalPipeline::ICreateDynDeviceObjects()

// Create device-specific stuff
fDebugTextMgr = new plDebugTextManager();
if (fDebugTextMgr == nil)
if (fDebugTextMgr == nullptr)
return true;

// Vertex buffers, index buffers, textures, etc.
Expand All @@ -2934,7 +2933,7 @@ void plMetalPipeline::IReleaseDynDeviceObjects()
// We should do this earlier, but the textFont objects don't remove
// themselves from their parent objects yet
delete fDebugTextMgr;
fDebugTextMgr = nil;
fDebugTextMgr = nullptr;

while (fTextFontRefList)
delete fTextFontRefList;
Expand Down Expand Up @@ -3397,10 +3396,10 @@ plRenderTarget* plMetalPipeline::IFindRenderTarget(uint32_t& width, uint32_t& he
// about that.
hsGDeviceRef* plMetalPipeline::SharedRenderTargetRef(plRenderTarget* share, plRenderTarget* owner)
{
plMetalRenderTargetRef* ref = nil;
MTL::Texture* depthSurface = nil;
MTL::Texture* texture = nil;
MTL::Texture* cTexture = nil;
plMetalRenderTargetRef* ref = nullptr;
MTL::Texture* depthSurface = nullptr;
MTL::Texture* texture = nullptr;
MTL::Texture* cTexture = nullptr;
int i;
plCubicRenderTarget* cubicRT;
uint16_t width, height;
Expand Down Expand Up @@ -3435,7 +3434,7 @@ hsGDeviceRef* plMetalPipeline::SharedRenderTargetRef(plRenderTarget* share, plRe
// if( !IFindRenderTargetInfo(owner, surfFormat, resType) )
//{
// hsAssert( false, "Error getting renderTarget info" );
// return nil;
// return nullptr;
//}

/// Create the render target now
Expand Down Expand Up @@ -3623,7 +3622,7 @@ void plMetalPipeline::IMakeRenderTargetPools()
if (!SharedRenderTargetRef((*pool)[0], rt)) {
delete rt;
pool->resize(j + 1);
(*pool)[j] = nil;
(*pool)[j] = nullptr;
break;
}
(*pool)[j] = rt;
Expand Down Expand Up @@ -3964,7 +3963,7 @@ bool plMetalPipeline::IIsViewLeftHanded()
}

//// ISetCullMode /////////////////////////////////////////////////////////////
// Tests and sets the current winding order cull mode (CW, CCW, or none).
// Tests and sets the current winding order cull mode (CW, CCW, or none).
// Will reverse the cull mode as necessary for left handed camera or local to world
// transforms.
void plMetalPipeline::ISetCullMode(bool flip)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ MTL::Function* plMetalMaterialPassPipelineState::GetVertexFunction(MTL::Library*
{
NS::Error* error = nullptr;
MTL::FunctionConstantValues* constants = MTL::FunctionConstantValues::alloc()->init()->autorelease();
this->GetFunctionConstants(constants);
GetFunctionConstants(constants);
MTL::Function* function = library->newFunction(
NS::String::string("pipelineVertexShader", NS::ASCIIStringEncoding),
MakeFunctionConstants(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ enum plMetalPipelineType
ShadowRender,
Clear,
Dynamic,
Text
Text,
Plate
};

//MARK: Base pipeline state
Expand All @@ -68,6 +69,8 @@ class plMetalPipelineState
{
public:
plMetalPipelineState(plMetalDevice* device);
virtual ~plMetalPipelineState() = default;

plMetalDevice::plMetalLinkedPipeline* GetRenderPipelineState();
void PrewarmRenderPipelineState();
bool operator==(const plMetalPipelineState& p) const
Expand All @@ -90,7 +93,6 @@ class plMetalPipelineState

virtual void ConfigureBlend(MTL::RenderPipelineColorAttachmentDescriptor* descriptor) = 0;
virtual void ConfigureVertexDescriptor(MTL::VertexDescriptor* vertexDescriptor) = 0;
virtual ~plMetalPipelineState() = default;

protected:
plMetalDevice* fDevice;
Expand Down
14 changes: 7 additions & 7 deletions Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPlateManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ class plMetalDevice;
class plMetalPlatePipelineState : public plMetalPipelineState
{
public:
plMetalPlatePipelineState(plMetalDevice *device) : plMetalPipelineState(device){};
bool IsEqual(const plMetalPipelineState &p) const override;
uint16_t GetID() const override { return 5; };
plMetalPlatePipelineState(plMetalDevice* device) : plMetalPipelineState(device){};
bool IsEqual(const plMetalPipelineState& p) const override;
uint16_t GetID() const override { return plMetalPipelineType::Plate; }
plMetalPipelineState* Clone() override;
const MTL::Function * GetVertexFunction(MTL::Library *library) override;
const MTL::Function * GetFragmentFunction(MTL::Library *library) override;
const MTL::Function * GetVertexFunction(MTL::Library* library) override;
const MTL::Function * GetFragmentFunction(MTL::Library* library) override;
const NS::String* GetDescription() override;

void ConfigureBlend(MTL::RenderPipelineColorAttachmentDescriptor *descriptor) override;
void ConfigureBlend(MTL::RenderPipelineColorAttachmentDescriptor* descriptor) override;

void ConfigureVertexDescriptor(MTL::VertexDescriptor *vertexDescriptor) override;
void ConfigureVertexDescriptor(MTL::VertexDescriptor* vertexDescriptor) override;

void GetFunctionConstants(MTL::FunctionConstantValues*) const override;
};
Expand Down

0 comments on commit 8e5feed

Please sign in to comment.