From 3fa495840a0f9f5b470ede7e716eeee615f22ef2 Mon Sep 17 00:00:00 2001 From: Samuliak Date: Mon, 8 Apr 2024 16:47:08 +0200 Subject: [PATCH] metal: configure pipeline before drawing --- .../renderer_metal/mtl_graphics_pipeline.cpp | 16 +++++++--------- .../renderer_metal/mtl_graphics_pipeline.h | 18 +----------------- .../renderer_metal/mtl_rasterizer.cpp | 10 +++------- 3 files changed, 11 insertions(+), 33 deletions(-) diff --git a/src/video_core/renderer_metal/mtl_graphics_pipeline.cpp b/src/video_core/renderer_metal/mtl_graphics_pipeline.cpp index d0e9bebfce..acca0c5bbf 100644 --- a/src/video_core/renderer_metal/mtl_graphics_pipeline.cpp +++ b/src/video_core/renderer_metal/mtl_graphics_pipeline.cpp @@ -53,22 +53,20 @@ GraphicsPipeline::GraphicsPipeline(const Device& device_, CommandRecorder& comma return; } MakePipeline(framebuffer->GetHandle()); - // configure_func = ConfigureFunc(functions, stage_infos); } -template -void GraphicsPipeline::ConfigureImpl(bool is_indexed) { - // TODO: implement -} +void GraphicsPipeline::Configure(bool is_indexed) { + buffer_cache.UpdateGraphicsBuffers(is_indexed); + buffer_cache.BindHostGeometryBuffers(is_indexed); -void GraphicsPipeline::ConfigureDraw() { - Framebuffer* framebuffer = texture_cache.GetFramebuffer(); + texture_cache.UpdateRenderTargets(true); + const Framebuffer* const framebuffer = texture_cache.GetFramebuffer(); if (!framebuffer) { return; } - // MTL::RenderPassDescriptor* render_pass = framebuffer->GetHandle(); + command_recorder.BeginOrContinueRenderPass(framebuffer->GetHandle()); - // TODO: bind resources + command_recorder.GetRenderCommandEncoder()->setRenderPipelineState(pipeline_state); } void GraphicsPipeline::MakePipeline(MTL::RenderPassDescriptor* render_pass) { diff --git a/src/video_core/renderer_metal/mtl_graphics_pipeline.h b/src/video_core/renderer_metal/mtl_graphics_pipeline.h index ff9548eaee..c848fdf487 100644 --- a/src/video_core/renderer_metal/mtl_graphics_pipeline.h +++ b/src/video_core/renderer_metal/mtl_graphics_pipeline.h @@ -80,9 +80,7 @@ public: // TODO: implement void AddTransition(GraphicsPipeline* transition) {} - void Configure(bool is_indexed) { - // configure_func(this, is_indexed); - } + void Configure(bool is_indexed); [[nodiscard]] GraphicsPipeline* Next(const GraphicsPipelineCacheKey& current_key) noexcept { // TODO: implement @@ -93,26 +91,12 @@ public: return true; } - template - static auto MakeConfigureSpecFunc() { - return [](GraphicsPipeline* pl, bool is_indexed) { pl->ConfigureImpl(is_indexed); }; - } - void SetEngine(Tegra::Engines::Maxwell3D* maxwell3d_, Tegra::MemoryManager* gpu_memory_) { maxwell3d = maxwell3d_; gpu_memory = gpu_memory_; } - MTL::RenderPipelineState* GetPipelineState() const noexcept { - return pipeline_state; - } - private: - template - void ConfigureImpl(bool is_indexed); - - void ConfigureDraw(); - void MakePipeline(MTL::RenderPassDescriptor* render_pass); void Validate(); diff --git a/src/video_core/renderer_metal/mtl_rasterizer.cpp b/src/video_core/renderer_metal/mtl_rasterizer.cpp index 544f153d99..a244038409 100644 --- a/src/video_core/renderer_metal/mtl_rasterizer.cpp +++ b/src/video_core/renderer_metal/mtl_rasterizer.cpp @@ -48,12 +48,7 @@ void RasterizerMetal::Draw(bool is_indexed, u32 instance_count) { if (!pipeline) { return; } - command_recorder.GetRenderCommandEncoder()->setRenderPipelineState( - pipeline->GetPipelineState()); - - // HACK: test is buffers are being correctly created - buffer_cache.UpdateGraphicsBuffers(is_indexed); - buffer_cache.BindHostGeometryBuffers(is_indexed); + pipeline->Configure(is_indexed); // HACK: dummy draw call command_recorder.GetRenderCommandEncoder()->drawPrimitives(MTL::PrimitiveTypeTriangle, @@ -95,7 +90,8 @@ void RasterizerMetal::Clear(u32 layer_count) { return; } - // Begin render pass + // TODO: track the textures used by render pass and only begin the render pass if their contents + // are needed Begin render pass command_recorder.BeginOrContinueRenderPass(framebuffer->GetHandle()); }