From 301e35d90d8d385cb4a675a2c0c19f5d0fe5794a Mon Sep 17 00:00:00 2001 From: Colin Cornaby Date: Sat, 4 Nov 2023 15:04:12 -0700 Subject: [PATCH] More feedback implementation --- .../FeatureLib/pfMetalPipeline/CMakeLists.txt | 1 - .../pfMetalPipeline/plMetalDevice.cpp | 4 +- .../pfMetalPipeline/plMetalDevice.h | 4 +- .../pfMetalPipeline/plMetalDeviceRef.h | 10 ++--- .../plMetalMaterialShaderRef.h | 16 ++++---- .../pfMetalPipeline/plMetalPipeline.cpp | 37 +++++++++---------- .../pfMetalPipeline/plMetalPipelineState.cpp | 2 +- .../pfMetalPipeline/plMetalPipelineState.h | 8 ++-- .../pfMetalPipeline/plMetalPlateManager.h | 14 +++---- 9 files changed, 48 insertions(+), 48 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/CMakeLists.txt b/Sources/Plasma/FeatureLib/pfMetalPipeline/CMakeLists.txt index cd55e74749..8f3a9cb084 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/CMakeLists.txt +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/CMakeLists.txt @@ -2,7 +2,6 @@ include(FetchContent) FetchContent_Declare( metalcpp - DOWNLOAD_EXTRACT_TIMESTAMP TRUE URL_HASH_SHA256 0afd87ca851465191ae4e3980aa036c7e9e02fe32e7c760ac1a74244aae6023b URL "https://developer.apple.com/metal/cpp/files/metal-cpp_macOS13.3_iOS16.4.zip" ) diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDevice.cpp b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDevice.cpp index 8f14e4fc4d..ea1b7a0652 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDevice.cpp +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDevice.cpp @@ -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]; } @@ -1256,7 +1256,7 @@ MTL::RenderCommandEncoder* plMetalDevice::CurrentRenderCommandEncoder() return fCurrentRenderTargetCommandEncoder; } -CA::MetalDrawable* plMetalDevice::GetCurrentDrawable() +CA::MetalDrawable* plMetalDevice::GetCurrentDrawable() const { return fCurrentDrawable; } diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDevice.h b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDevice.h index 84767ca168..e24da29fc1 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDevice.h +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDevice.h @@ -162,7 +162,7 @@ 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); @@ -170,7 +170,7 @@ class plMetalDevice 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() { diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDeviceRef.h b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDeviceRef.h index c7608d6aad..8206757594 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDeviceRef.h +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalDeviceRef.h @@ -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) @@ -212,7 +212,7 @@ class plMetalVertexBufferRef : public plMetalBufferPoolRef virtual ~plMetalVertexBufferRef(); void Link(plMetalVertexBufferRef** back) { plMetalDeviceRef::Link((plMetalDeviceRef**)back); } - plMetalVertexBufferRef* GetNext() const { return (plMetalVertexBufferRef*)fNext; } + plMetalVertexBufferRef* const GetNext() const { return (plMetalVertexBufferRef*)fNext; } void Release() override; }; @@ -244,7 +244,7 @@ class plMetalIndexBufferRef : public plMetalBufferPoolRef void Release() override; void Link(plMetalIndexBufferRef** back) { plMetalDeviceRef::Link((plMetalDeviceRef**)back); } - plMetalIndexBufferRef* GetNext() { return (plMetalIndexBufferRef*)fNext; } + plMetalIndexBufferRef* const GetNext() { return (plMetalIndexBufferRef*)fNext; } virtual ~plMetalIndexBufferRef(); plMetalIndexBufferRef() : plMetalBufferPoolRef(), @@ -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) { diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalMaterialShaderRef.h b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalMaterialShaderRef.h index 84b7eea0e4..0638cfe2c8 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalMaterialShaderRef.h +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalMaterialShaderRef.h @@ -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 fPassIndices; // FIXME: This should be retained/released - MTL::Device *fDevice; - std::vector fPassArgumentBuffers; + MTL::Device* fDevice; + std::vector 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; @@ -116,7 +116,7 @@ class plMetalMaterialShaderRef : public plMetalDeviceRef std::vector* piggybacks, const std::function& preEncodeTransform, const std::function& 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); diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp index d2dfeada91..47b6523dbd 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp @@ -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(); } } @@ -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(material->GetDeviceRef()); @@ -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(); } } @@ -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 @@ -2532,7 +2532,7 @@ void plMetalPipeline::PopCurrentLightSources() plLayerInterface* plMetalPipeline::IPushOverBaseLayer(plLayerInterface* li) { if (!li) - return nil; + return nullptr; fOverLayerStack.emplace_back(li); @@ -2569,7 +2569,7 @@ plLayerInterface* plMetalPipeline::IPopOverBaseLayer(plLayerInterface* li) plLayerInterface* plMetalPipeline::IPushOverAllLayer(plLayerInterface* li) { if (!li) - return nil; + return nullptr; fOverLayerStack.push_back(li); @@ -2592,7 +2592,7 @@ plLayerInterface* plMetalPipeline::IPushOverAllLayer(plLayerInterface* li) plLayerInterface* plMetalPipeline::IPopOverAllLayer(plLayerInterface* li) { if (!li) - return nil; + return nullptr; fForceMatHandle = true; @@ -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; @@ -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. @@ -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; @@ -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; @@ -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 @@ -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; @@ -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) diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipelineState.cpp b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipelineState.cpp index 640599a957..4f511dc026 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipelineState.cpp +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipelineState.cpp @@ -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(), diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipelineState.h b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipelineState.h index 021baa0bcc..46e879600a 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipelineState.h +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipelineState.h @@ -59,7 +59,8 @@ enum plMetalPipelineType ShadowRender, Clear, Dynamic, - Text + Text, + Plate }; //MARK: Base pipeline state @@ -68,6 +69,8 @@ class plMetalPipelineState { public: plMetalPipelineState(plMetalDevice* device); + virtual ~plMetalPipelineState() = default; + plMetalDevice::plMetalLinkedPipeline* GetRenderPipelineState(); void PrewarmRenderPipelineState(); bool operator==(const plMetalPipelineState& p) const @@ -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; @@ -132,7 +134,7 @@ class plMetalRenderSpanPipelineState : public plMetalPipelineState MTL::FunctionConstantValues* MakeFunctionConstants() { MTL::FunctionConstantValues* constants = MTL::FunctionConstantValues::alloc()->init()->autorelease(); - this->GetFunctionConstants(constants); + GetFunctionConstants(constants); return constants; } }; diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPlateManager.h b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPlateManager.h index 27d579302a..490ae31388 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPlateManager.h +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPlateManager.h @@ -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; };