diff --git a/rpcs3/Emu/RSX/VK/vkutils/commands.cpp b/rpcs3/Emu/RSX/VK/vkutils/commands.cpp index 3886ee811f..549d557afb 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/commands.cpp +++ b/rpcs3/Emu/RSX/VK/vkutils/commands.cpp @@ -72,14 +72,17 @@ namespace vk void command_buffer::reset() { - // Nuke the state cache - m_bound_pipeline = VK_NULL_HANDLE; - m_bound_descriptor_sets[0] = VK_NULL_HANDLE; - // Do the driver reset CHECK_RESULT(vkResetCommandBuffer(commands, 0)); } + void command_buffer::clear_state_cache() + { + m_bound_pipelines[0] = VK_NULL_HANDLE; + m_bound_pipelines[1] = VK_NULL_HANDLE; + m_bound_descriptor_sets[0] = VK_NULL_HANDLE; + } + void command_buffer::begin() { if (m_submit_fence && is_pending) @@ -104,6 +107,8 @@ namespace vk begin_infos.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; CHECK_RESULT(vkBeginCommandBuffer(commands, &begin_infos)); is_open = true; + + clear_state_cache(); } void command_buffer::end() @@ -142,12 +147,14 @@ namespace vk void command_buffer::bind_pipeline(VkPipeline pipeline, VkPipelineBindPoint bind_point) const { - if (m_bound_pipeline == pipeline) + ensure(is_open && bind_point <= VK_PIPELINE_BIND_POINT_COMPUTE); + auto& cached = m_bound_pipelines[static_cast(bind_point)]; + if (cached == pipeline) { return; } - m_bound_pipeline = pipeline; + cached = pipeline; vkCmdBindPipeline(commands, bind_point, pipeline); } @@ -176,7 +183,7 @@ namespace vk VkPipelineLayout pipe_layout) const { const u32 num_sets = ::size32(sets); - ensure(num_sets <= 2); + ensure(is_open && num_sets <= 2); if (!memcmp(sets.data(), m_bound_descriptor_sets.data(), sets.size_bytes())) { diff --git a/rpcs3/Emu/RSX/VK/vkutils/commands.h b/rpcs3/Emu/RSX/VK/vkutils/commands.h index 1519eb436b..12a414405e 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/commands.h +++ b/rpcs3/Emu/RSX/VK/vkutils/commands.h @@ -75,7 +75,9 @@ namespace vk // State cache mutable std::array m_bound_descriptor_sets {{ VK_NULL_HANDLE }}; - mutable VkPipeline m_bound_pipeline = VK_NULL_HANDLE; + mutable std::array m_bound_pipelines{{ VK_NULL_HANDLE }}; + + void clear_state_cache(); public: enum access_type_hint