metal: use texture cache to create textures render passes

This commit is contained in:
Samuliak 2024-04-06 12:39:24 +02:00
parent 88154b6c6d
commit 863842948b
5 changed files with 28 additions and 11 deletions

View file

@ -40,7 +40,7 @@ void CommandRecorder::RequireBlitEncoder() {
void CommandRecorder::EndEncoding() { void CommandRecorder::EndEncoding() {
if (encoder) { if (encoder) {
[encoder endEncoding]; [encoder endEncoding];
[encoder release]; //[encoder release];
encoder = nil; encoder = nil;
} }
} }
@ -53,7 +53,7 @@ void CommandRecorder::Submit() {
if (command_buffer) { if (command_buffer) {
EndEncoding(); EndEncoding();
[command_buffer commit]; [command_buffer commit];
[command_buffer release]; //[command_buffer release];
command_buffer = nil; command_buffer = nil;
} }
} }

View file

@ -43,7 +43,7 @@ void RasterizerMetal::Draw(bool is_indexed, u32 instance_count) {
//command_recorder.CheckIfRenderPassIsActive(); //command_recorder.CheckIfRenderPassIsActive();
//const auto& draw_state = maxwell3d->draw_manager->GetDrawState(); //const auto& draw_state = maxwell3d->draw_manager->GetDrawState();
if (is_indexed) { if (is_indexed) {
std::cout << "DrawIndexed" << std::endl; std::cout << "Draw indexed" << std::endl;
/*[command_buffer drawIndexedPrimitives:MTLPrimitiveTypeTriangle /*[command_buffer drawIndexedPrimitives:MTLPrimitiveTypeTriangle
indexCount:draw_params.num_indices indexCount:draw_params.num_indices
indexType:MTLIndexTypeUInt32 indexType:MTLIndexTypeUInt32
@ -61,8 +61,24 @@ void RasterizerMetal::Draw(bool is_indexed, u32 instance_count) {
// draw_params.base_vertex, draw_params.base_instance); // draw_params.base_vertex, draw_params.base_instance);
} }
} }
void RasterizerMetal::DrawTexture() {}
void RasterizerMetal::Clear(u32 layer_count) {} void RasterizerMetal::DrawTexture() {
std::cout << "Draw texture" << std::endl;
}
void RasterizerMetal::Clear(u32 layer_count) {
std::cout << "Clear" << std::endl;
texture_cache.UpdateRenderTargets(true);
const Framebuffer* const framebuffer = texture_cache.GetFramebuffer();
if (!framebuffer) {
return;
}
// Begin render pass
command_recorder.BeginRenderPass(framebuffer->GetHandle());
}
void RasterizerMetal::DispatchCompute() {} void RasterizerMetal::DispatchCompute() {}
void RasterizerMetal::ResetCounter(VideoCommon::QueryType type) {} void RasterizerMetal::ResetCounter(VideoCommon::QueryType type) {}
void RasterizerMetal::Query(GPUVAddr gpu_addr, VideoCommon::QueryType type, void RasterizerMetal::Query(GPUVAddr gpu_addr, VideoCommon::QueryType type,
@ -135,12 +151,15 @@ void RasterizerMetal::LoadDiskResources(u64 title_id, std::stop_token stop_loadi
const VideoCore::DiskResourceLoadCallback& callback) {} const VideoCore::DiskResourceLoadCallback& callback) {}
void RasterizerMetal::InitializeChannel(Tegra::Control::ChannelState& channel) { void RasterizerMetal::InitializeChannel(Tegra::Control::ChannelState& channel) {
CreateChannel(channel); CreateChannel(channel);
texture_cache.CreateChannel(channel);
} }
void RasterizerMetal::BindChannel(Tegra::Control::ChannelState& channel) { void RasterizerMetal::BindChannel(Tegra::Control::ChannelState& channel) {
BindToChannel(channel.bind_id); BindToChannel(channel.bind_id);
texture_cache.BindToChannel(channel.bind_id);
} }
void RasterizerMetal::ReleaseChannel(s32 channel_id) { void RasterizerMetal::ReleaseChannel(s32 channel_id) {
EraseChannel(channel_id); EraseChannel(channel_id);
texture_cache.EraseChannel(channel_id);
} }
} // namespace Metal } // namespace Metal

View file

@ -20,6 +20,7 @@ public:
void Present(); void Present();
// Can only be called between AcquireNextDrawable and Present
MTLTexture_t GetDrawableTexture(); MTLTexture_t GetDrawableTexture();
private: private:

View file

@ -15,21 +15,17 @@ SwapChain::SwapChain(const Device& device_, CommandRecorder& command_recorder_,
} }
SwapChain::~SwapChain() { SwapChain::~SwapChain() {
if (drawable) {
// TODO: should drawable be released?
[drawable release];
}
[layer release]; [layer release];
} }
void SwapChain::AcquireNextDrawable() { void SwapChain::AcquireNextDrawable() {
// Get the next drawable // Get the next drawable
drawable = [layer nextDrawable]; drawable = [[layer nextDrawable] retain];
} }
void SwapChain::Present() { void SwapChain::Present() {
command_recorder.EndEncoding();
command_recorder.Present(drawable); command_recorder.Present(drawable);
[drawable release];
} }
MTLTexture_t SwapChain::GetDrawableTexture() { MTLTexture_t SwapChain::GetDrawableTexture() {

View file

@ -37,6 +37,7 @@ void RendererMetal::Composite(std::span<const Tegra::FramebufferConfig> framebuf
render_pass_descriptor.colorAttachments[0].texture = swap_chain.GetDrawableTexture(); render_pass_descriptor.colorAttachments[0].texture = swap_chain.GetDrawableTexture();
command_recorder.BeginRenderPass(render_pass_descriptor); command_recorder.BeginRenderPass(render_pass_descriptor);
command_recorder.EndEncoding();
swap_chain.Present(); swap_chain.Present();
command_recorder.Submit(); command_recorder.Submit();