diff --git a/src/shader_recompiler/backend/msl/msl_emit_context.cpp b/src/shader_recompiler/backend/msl/msl_emit_context.cpp index 1027d3ff03..cfe7dd9068 100644 --- a/src/shader_recompiler/backend/msl/msl_emit_context.cpp +++ b/src/shader_recompiler/backend/msl/msl_emit_context.cpp @@ -342,6 +342,7 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile void EmitContext::DefineInputs(Bindings& bindings) { // Constant buffers + bindings.uniform_buffer = 0; 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}; @@ -362,6 +363,7 @@ void EmitContext::DefineInputs(Bindings& bindings) { // TODO // Storage space buffers + bindings.uniform_buffer = 15; 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 e7bc6e8672..d93c63491f 100644 --- a/src/video_core/renderer_metal/mtl_buffer_cache.cpp +++ b/src/video_core/renderer_metal/mtl_buffer_cache.cpp @@ -109,7 +109,7 @@ void BufferCacheRuntime::BindVertexBuffers(VideoCommon::HostBindings& bi void BufferCacheRuntime::BindBuffer(size_t stage, u32 binding_index, MTL::Buffer* buffer, u32 offset, u32 size) { - command_recorder.SetBuffer(stage, buffer, binding_index, offset); + command_recorder.SetBuffer(stage, buffer, offset, binding_index); } void BufferCacheRuntime::ReserveNullBuffer() { diff --git a/src/video_core/renderer_metal/mtl_buffer_cache.h b/src/video_core/renderer_metal/mtl_buffer_cache.h index f165813c3c..e0ad846795 100644 --- a/src/video_core/renderer_metal/mtl_buffer_cache.h +++ b/src/video_core/renderer_metal/mtl_buffer_cache.h @@ -124,6 +124,7 @@ public: std::span BindMappedUniformBuffer(size_t stage, u32 binding_index, u32 size) { const StagingBufferRef ref = staging_pool.Request(size, MemoryUsage::Upload); BindBuffer(stage, binding_index, ref.buffer, static_cast(ref.offset), size); + return ref.mapped_span; } diff --git a/src/video_core/renderer_metal/mtl_command_recorder.cpp b/src/video_core/renderer_metal/mtl_command_recorder.cpp index 701c9d3b03..e17a043490 100644 --- a/src/video_core/renderer_metal/mtl_command_recorder.cpp +++ b/src/video_core/renderer_metal/mtl_command_recorder.cpp @@ -20,6 +20,7 @@ void CommandRecorder::BeginOrContinueRenderPass(MTL::RenderPassDescriptor* rende render_state.render_pass = render_pass; should_reset_bound_resources = true; } + const auto bind_resources{[&](size_t stage) { // Buffers for (u8 i = 0; i < MAX_BUFFERS; i++) { @@ -28,17 +29,18 @@ void CommandRecorder::BeginOrContinueRenderPass(MTL::RenderPassDescriptor* rende (bound_buffer.needs_update || should_reset_bound_resources)) { switch (stage) { case 0: - GetRenderCommandEncoderUnchecked()->setVertexBuffer(bound_buffer.buffer, i, - bound_buffer.offset); + GetRenderCommandEncoderUnchecked()->setVertexBuffer(bound_buffer.buffer, + bound_buffer.offset, i); break; case 4: - GetRenderCommandEncoderUnchecked()->setFragmentBuffer(bound_buffer.buffer, i, - bound_buffer.offset); + GetRenderCommandEncoderUnchecked()->setFragmentBuffer(bound_buffer.buffer, + bound_buffer.offset, i); break; } bound_buffer.needs_update = false; } } + // Textures for (u8 i = 0; i < MAX_TEXTURES; i++) { auto& bound_texture = render_state.textures[stage][i]; @@ -56,6 +58,7 @@ void CommandRecorder::BeginOrContinueRenderPass(MTL::RenderPassDescriptor* rende bound_texture.needs_update = false; } } + // Sampler states for (u8 i = 0; i < MAX_SAMPLERS; i++) { auto& bound_sampler_state = render_state.sampler_states[stage][i]; @@ -78,20 +81,6 @@ void CommandRecorder::BeginOrContinueRenderPass(MTL::RenderPassDescriptor* rende bind_resources(0); bind_resources(4); - - if (should_reset_bound_resources) { - for (size_t stage = 0; stage < 5; stage++) { - for (u8 i = 0; i < MAX_BUFFERS; i++) { - render_state.buffers[stage][i].buffer = nullptr; - } - for (u8 i = 0; i < MAX_TEXTURES; i++) { - render_state.textures[stage][i].texture = nullptr; - } - for (u8 i = 0; i < MAX_SAMPLERS; i++) { - render_state.sampler_states[stage][i].sampler_state = nullptr; - } - } - } } void CommandRecorder::RequireComputeEncoder() { diff --git a/src/video_core/renderer_metal/mtl_command_recorder.h b/src/video_core/renderer_metal/mtl_command_recorder.h index 449bbe308d..7d7b8efd3b 100644 --- a/src/video_core/renderer_metal/mtl_command_recorder.h +++ b/src/video_core/renderer_metal/mtl_command_recorder.h @@ -114,7 +114,7 @@ public: } } - inline void SetBuffer(size_t stage, MTL::Buffer* buffer, size_t index, size_t offset) { + inline void SetBuffer(size_t stage, MTL::Buffer* buffer, size_t offset, size_t index) { auto& bound_buffer = render_state.buffers[stage][index]; if (buffer != bound_buffer.buffer) { bound_buffer = {true, buffer, offset};