From 1d39266956c762e41ee82758d85cda806ea2ec31 Mon Sep 17 00:00:00 2001 From: Samuliak Date: Sat, 5 Oct 2024 17:02:46 +0200 Subject: [PATCH] fix: constant buffers not getting bound --- src/shader_recompiler/backend/msl/emit_msl_image.cpp | 1 - src/shader_recompiler/backend/msl/msl_emit_context.cpp | 4 ++-- src/video_core/renderer_metal/mtl_buffer_cache.cpp | 6 ++++-- src/video_core/renderer_metal/mtl_buffer_cache.h | 2 +- src/video_core/renderer_metal/mtl_graphics_pipeline.cpp | 6 ++++++ src/video_core/renderer_metal/mtl_graphics_pipeline.h | 3 ++- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/shader_recompiler/backend/msl/emit_msl_image.cpp b/src/shader_recompiler/backend/msl/emit_msl_image.cpp index 7dc857d733..c03866a30f 100644 --- a/src/shader_recompiler/backend/msl/emit_msl_image.cpp +++ b/src/shader_recompiler/backend/msl/emit_msl_image.cpp @@ -1,7 +1,6 @@ // SPDX-FileCopyrightText: Copyright 2024 suyu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include #include #include "shader_recompiler/backend/msl/emit_msl_instructions.h" diff --git a/src/shader_recompiler/backend/msl/msl_emit_context.cpp b/src/shader_recompiler/backend/msl/msl_emit_context.cpp index cfe7dd9068..4f13d732a5 100644 --- a/src/shader_recompiler/backend/msl/msl_emit_context.cpp +++ b/src/shader_recompiler/backend/msl/msl_emit_context.cpp @@ -342,7 +342,7 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile void EmitContext::DefineInputs(Bindings& bindings) { // Constant buffers - bindings.uniform_buffer = 0; + bindings.uniform_buffer = 0; // HACK for (const auto& desc : info.constant_buffer_descriptors) { const u32 cbuf_used_size{Common::DivCeil(info.constant_buffer_used_sizes[desc.index], 16U)}; const u32 cbuf_binding_size{info.uses_global_memory ? 0x1000U : cbuf_used_size}; @@ -363,7 +363,7 @@ void EmitContext::DefineInputs(Bindings& bindings) { // TODO // Storage space buffers - bindings.uniform_buffer = 15; + bindings.uniform_buffer = 8; // HACK u32 index{}; for (const auto& desc : info.storage_buffers_descriptors) { if (has_at_least_one_input) diff --git a/src/video_core/renderer_metal/mtl_buffer_cache.cpp b/src/video_core/renderer_metal/mtl_buffer_cache.cpp index d93c63491f..acddd34f05 100644 --- a/src/video_core/renderer_metal/mtl_buffer_cache.cpp +++ b/src/video_core/renderer_metal/mtl_buffer_cache.cpp @@ -102,8 +102,10 @@ void BufferCacheRuntime::BindVertexBuffer(u32 index, MTL::Buffer* buffer, u32 of void BufferCacheRuntime::BindVertexBuffers(VideoCommon::HostBindings& bindings) { for (u32 index = 0; index < bindings.buffers.size(); ++index) { auto handle = bindings.buffers[index]->Handle(); - // TODO: set stride? - BindVertexBuffer(index, handle, bindings.offsets[index], bindings.sizes[index], 0); + if (handle) { + // TODO: set stride? + BindVertexBuffer(index, handle, bindings.offsets[index], bindings.sizes[index], 0); + } } } diff --git a/src/video_core/renderer_metal/mtl_buffer_cache.h b/src/video_core/renderer_metal/mtl_buffer_cache.h index e0ad846795..1af11d3cec 100644 --- a/src/video_core/renderer_metal/mtl_buffer_cache.h +++ b/src/video_core/renderer_metal/mtl_buffer_cache.h @@ -138,7 +138,7 @@ public: void BindStorageBuffer(size_t stage, u32 binding_index, MTL::Buffer* buffer, u32 offset, u32 size, [[maybe_unused]] bool is_written) { - BindBuffer(stage, binding_index, buffer, offset, size); + BindBuffer(stage, binding_index + 8, buffer, offset, size); // HACK: offset by 8 } // TODO: implement diff --git a/src/video_core/renderer_metal/mtl_graphics_pipeline.cpp b/src/video_core/renderer_metal/mtl_graphics_pipeline.cpp index 2e2e1d926d..a13b044727 100644 --- a/src/video_core/renderer_metal/mtl_graphics_pipeline.cpp +++ b/src/video_core/renderer_metal/mtl_graphics_pipeline.cpp @@ -46,6 +46,8 @@ GraphicsPipeline::GraphicsPipeline(const Device& device_, CommandRecorder& comma continue; } stage_infos[stage] = *info; + enabled_uniform_buffer_masks[stage] = info->constant_buffer_mask; + std::ranges::copy(info->constant_buffer_used_sizes, uniform_buffer_sizes[stage].begin()); } Validate(); // TODO: is the framebuffer available by this time? @@ -81,6 +83,10 @@ void GraphicsPipeline::Configure(bool is_indexed) { size_t& view_index{all_views[stage].view_index}; size_t& sampler_index{all_samplers[stage].sampler_index}; + texture_cache.SynchronizeGraphicsDescriptors(); + + buffer_cache.SetUniformBuffersState(enabled_uniform_buffer_masks, &uniform_buffer_sizes); + buffer_cache.UnbindGraphicsStorageBuffers(stage); size_t ssbo_index{}; for (const auto& desc : info.storage_buffers_descriptors) { diff --git a/src/video_core/renderer_metal/mtl_graphics_pipeline.h b/src/video_core/renderer_metal/mtl_graphics_pipeline.h index c848fdf487..ab11298c6d 100644 --- a/src/video_core/renderer_metal/mtl_graphics_pipeline.h +++ b/src/video_core/renderer_metal/mtl_graphics_pipeline.h @@ -114,7 +114,8 @@ private: std::array functions; std::array stage_infos; - // VideoCommon::UniformBufferSizes uniform_buffer_sizes{}; + std::array enabled_uniform_buffer_masks{}; + VideoCommon::UniformBufferSizes uniform_buffer_sizes{}; // u32 num_textures{}; MTL::RenderPipelineState* pipeline_state{nullptr};