Skip to content

Commit

Permalink
[rhi] improved submit() performance by making the mutex lock conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
PanosK92 committed Dec 9, 2024
1 parent d6e0be0 commit 756b97e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 3 additions & 1 deletion runtime/RHI/RHI_SyncPrimitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ namespace Spartan

private:
RHI_SyncPrimitive_Type m_type = RHI_SyncPrimitive_Type::Max;
void* m_rhi_resource = nullptr;
uint64_t m_value_wait = 0;
bool m_signaled = false;

// rhi
void* m_rhi_resource = nullptr;
};
}
14 changes: 10 additions & 4 deletions runtime/RHI/Vulkan/Vulkan_Queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

//= INCLUDES =====================
//= INCLUDES =======================
#include "pch.h"
#include "../RHI_Implementation.h"
#include "../RHI_Device.h"
#include "../RHI_Queue.h"
#include "../RHI_SyncPrimitive.h"
#include "../RHI_FidelityFX.h"
#include "../Core/Debugging.h"
//================================
#include "../Core/ProgressTracker.h"
//==================================

//= NAMESPACES =====
using namespace std;
Expand Down Expand Up @@ -143,7 +144,6 @@ namespace Spartan

void RHI_Queue::Wait()
{
lock_guard<mutex> lock(get_mutex(this));
SP_ASSERT_VK(vkQueueWaitIdle(static_cast<VkQueue>(RHI_Device::GetQueueRhiResource(m_type))));
}

Expand All @@ -154,7 +154,13 @@ namespace Spartan
SP_ASSERT(semaphore != nullptr);
SP_ASSERT(semaphore_timeline != nullptr);

lock_guard<mutex> lock(get_mutex(this));
// locking only during texture loading to stage data without race conditions
unique_lock<mutex> lock;
if (ProgressTracker::IsLoading())
{
lock = unique_lock<mutex>(get_mutex(this));
}

VkSemaphoreSubmitInfo semaphores[2] = {};

// semaphore binary
Expand Down

0 comments on commit 756b97e

Please sign in to comment.