metal: bind pipeline and draw for the first time

This commit is contained in:
Samuliak 2024-04-07 18:46:01 +02:00
parent 4d700ac01c
commit 90b8671ddb
No known key found for this signature in database
6 changed files with 37 additions and 16 deletions

View file

@ -81,10 +81,11 @@ void BufferCacheRuntime::Finish() {}
void BufferCacheRuntime::CopyBuffer(MTL::Buffer* dst_buffer, MTL::Buffer* src_buffer, void BufferCacheRuntime::CopyBuffer(MTL::Buffer* dst_buffer, MTL::Buffer* src_buffer,
std::span<const VideoCommon::BufferCopy> copies, bool barrier, std::span<const VideoCommon::BufferCopy> copies, bool barrier,
bool can_reorder_upload) { bool can_reorder_upload) {
for (const VideoCommon::BufferCopy& copy : copies) { // HACK: needs to be commented out, since it iterrupts render pass
command_recorder.GetBlitCommandEncoder()->copyFromBuffer( // for (const VideoCommon::BufferCopy& copy : copies) {
src_buffer, copy.src_offset, dst_buffer, copy.dst_offset, copy.size); // command_recorder.GetBlitCommandEncoder()->copyFromBuffer(
} // src_buffer, copy.src_offset, dst_buffer, copy.dst_offset, copy.size);
// }
} }
void BufferCacheRuntime::ClearBuffer(MTL::Buffer* dest_buffer, u32 offset, size_t size, u32 value) { void BufferCacheRuntime::ClearBuffer(MTL::Buffer* dest_buffer, u32 offset, size_t size, u32 value) {

View file

@ -4,18 +4,16 @@
#include "video_core/renderer_metal/mtl_command_recorder.h" #include "video_core/renderer_metal/mtl_command_recorder.h"
#include "video_core/renderer_metal/mtl_device.h" #include "video_core/renderer_metal/mtl_device.h"
#include <iostream>
namespace Metal { namespace Metal {
CommandRecorder::CommandRecorder(const Device& device_) : device(device_) {} CommandRecorder::CommandRecorder(const Device& device_) : device(device_) {}
CommandRecorder::~CommandRecorder() = default; CommandRecorder::~CommandRecorder() = default;
void CommandRecorder::BeginRenderPass(MTL::RenderPassDescriptor* render_pass_descriptor) { void CommandRecorder::BeginRenderPass(MTL::RenderPassDescriptor* render_pass) {
RequireCommandBuffer(); RequireCommandBuffer();
EndEncoding(); EndEncoding();
encoder = command_buffer->renderCommandEncoder(render_pass_descriptor); encoder = command_buffer->renderCommandEncoder(render_pass);
encoder_type = EncoderType::Render; encoder_type = EncoderType::Render;
} }
@ -41,7 +39,7 @@ void CommandRecorder::EndEncoding() {
if (encoder) { if (encoder) {
encoder->endEncoding(); encoder->endEncoding();
//[encoder release]; //[encoder release];
encoder = nil; encoder = nullptr;
} }
} }
@ -55,7 +53,7 @@ void CommandRecorder::Submit() {
EndEncoding(); EndEncoding();
command_buffer->commit(); command_buffer->commit();
//[command_buffer release]; //[command_buffer release];
command_buffer = nil; command_buffer = nullptr;
} }
} }

View file

@ -17,7 +17,7 @@ public:
CommandRecorder(const Device& device_); CommandRecorder(const Device& device_);
~CommandRecorder(); ~CommandRecorder();
void BeginRenderPass(MTL::RenderPassDescriptor* render_pass_descriptor); void BeginRenderPass(MTL::RenderPassDescriptor* render_pass);
void CheckIfRenderPassIsActive() { void CheckIfRenderPassIsActive() {
if (!encoder || encoder_type != EncoderType::Render) { if (!encoder || encoder_type != EncoderType::Render) {

View file

@ -103,6 +103,10 @@ public:
gpu_memory = gpu_memory_; gpu_memory = gpu_memory_;
} }
MTL::RenderPipelineState* GetPipelineState() const noexcept {
return pipeline_state;
}
private: private:
template <typename Spec> template <typename Spec>
void ConfigureImpl(bool is_indexed); void ConfigureImpl(bool is_indexed);

View file

@ -157,6 +157,7 @@ GraphicsPipeline* PipelineCache::CurrentGraphicsPipeline() {
return BuiltPipeline(current_pipeline); return BuiltPipeline(current_pipeline);
} }
} }
return CurrentGraphicsPipelineSlowPath(); return CurrentGraphicsPipelineSlowPath();
} }
@ -263,7 +264,7 @@ std::unique_ptr<GraphicsPipeline> PipelineCache::CreateGraphicsPipeline(
library->newFunction(NS::String::string("fragmentMain", NS::ASCIIStringEncoding)); library->newFunction(NS::String::string("fragmentMain", NS::ASCIIStringEncoding));
// HACK: dummy info // HACK: dummy info
std::array<const Shader::Info*, VideoCommon::NUM_STAGES> infos; std::array<const Shader::Info*, VideoCommon::NUM_STAGES> infos = {nullptr};
infos[0] = new Shader::Info{}; infos[0] = new Shader::Info{};
infos[1] = new Shader::Info{}; infos[1] = new Shader::Info{};

View file

@ -41,6 +41,24 @@ RasterizerMetal::RasterizerMetal(Tegra::GPU& gpu_,
RasterizerMetal::~RasterizerMetal() = default; RasterizerMetal::~RasterizerMetal() = default;
void RasterizerMetal::Draw(bool is_indexed, u32 instance_count) { void RasterizerMetal::Draw(bool is_indexed, u32 instance_count) {
LOG_DEBUG(Render_Metal, "called");
// Bind the current graphics pipeline
GraphicsPipeline* const pipeline{pipeline_cache.CurrentGraphicsPipeline()};
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);
// HACK: dummy draw call
command_recorder.GetRenderCommandEncoder()->drawPrimitives(MTL::PrimitiveTypeTriangle,
NS::UInteger(0), NS::UInteger(3));
// TODO: uncomment // TODO: uncomment
// command_recorder.CheckIfRenderPassIsActive(); // command_recorder.CheckIfRenderPassIsActive();
// const auto& draw_state = maxwell3d->draw_manager->GetDrawState(); // const auto& draw_state = maxwell3d->draw_manager->GetDrawState();
@ -62,10 +80,6 @@ void RasterizerMetal::Draw(bool is_indexed, u32 instance_count) {
// cmdbuf.Draw(draw_params.num_vertices, draw_params.num_instances, // cmdbuf.Draw(draw_params.num_vertices, draw_params.num_instances,
// draw_params.base_vertex, draw_params.base_instance); // draw_params.base_vertex, draw_params.base_instance);
} }
// HACK: test is buffers are being correctly created
buffer_cache.UpdateGraphicsBuffers(is_indexed);
buffer_cache.BindHostGeometryBuffers(is_indexed);
} }
void RasterizerMetal::DrawTexture() { void RasterizerMetal::DrawTexture() {
@ -246,6 +260,7 @@ void RasterizerMetal::InitializeChannel(Tegra::Control::ChannelState& channel) {
CreateChannel(channel); CreateChannel(channel);
buffer_cache.CreateChannel(channel); buffer_cache.CreateChannel(channel);
texture_cache.CreateChannel(channel); texture_cache.CreateChannel(channel);
pipeline_cache.CreateChannel(channel);
} }
void RasterizerMetal::BindChannel(Tegra::Control::ChannelState& channel) { void RasterizerMetal::BindChannel(Tegra::Control::ChannelState& channel) {
@ -254,6 +269,7 @@ void RasterizerMetal::BindChannel(Tegra::Control::ChannelState& channel) {
BindToChannel(channel.bind_id); BindToChannel(channel.bind_id);
buffer_cache.BindToChannel(channel.bind_id); buffer_cache.BindToChannel(channel.bind_id);
texture_cache.BindToChannel(channel.bind_id); texture_cache.BindToChannel(channel.bind_id);
pipeline_cache.BindToChannel(channel.bind_id);
} }
void RasterizerMetal::ReleaseChannel(s32 channel_id) { void RasterizerMetal::ReleaseChannel(s32 channel_id) {
@ -262,6 +278,7 @@ void RasterizerMetal::ReleaseChannel(s32 channel_id) {
EraseChannel(channel_id); EraseChannel(channel_id);
buffer_cache.EraseChannel(channel_id); buffer_cache.EraseChannel(channel_id);
texture_cache.EraseChannel(channel_id); texture_cache.EraseChannel(channel_id);
pipeline_cache.EraseChannel(channel_id);
} }
} // namespace Metal } // namespace Metal