@@ -126,14 +126,14 @@ nvrhi::CommandListHandle vhCmdListGet( nvrhi::CommandQueue type )
126126// - Copy feeds Compute and Graphics
127127// - Compute feeds Graphics
128128//
129- void vhCmdListFlush_SingleQueueInternal ( nvrhi::CommandQueue type )
129+ void vhCmdListFlush_SingleQueueInternal_DeviceStateLocked ( nvrhi::CommandQueue type )
130130{
131+ // WARNING: Lock g_nvRHIStateMutex before calling this.
131132 auto typeIdx = ( uint64_t ) type;
132133 uint64_t instance = 0 ;
133134
134135 if ( g_vhCmdLists[typeIdx] )
135136 {
136- std::lock_guard<std::mutex> lock ( g_nvRHIStateMutex );
137137 g_vhCmdLists[typeIdx]->close ();
138138
139139 // Execute and get the instance ID for synchronisation
@@ -160,20 +160,22 @@ void vhCmdListFlush_SingleQueueInternal( nvrhi::CommandQueue type )
160160
161161void vhCmdListFlush ( nvrhi::CommandQueue type )
162162{
163+ std::lock_guard< std::mutex > lock ( g_nvRHIStateMutex );
164+
163165 // Both queues depend on copy; flush copy first
164166 if ( type == nvrhi::CommandQueue::Graphics || type == nvrhi::CommandQueue::Compute )
165167 {
166- vhCmdListFlush_SingleQueueInternal ( nvrhi::CommandQueue::Copy );
168+ vhCmdListFlush_SingleQueueInternal_DeviceStateLocked ( nvrhi::CommandQueue::Copy );
167169 }
168170
169171 // Graphics depends on compute; flush compute first
170172 if ( type == nvrhi::CommandQueue::Graphics )
171173 {
172- vhCmdListFlush_SingleQueueInternal ( nvrhi::CommandQueue::Compute );
174+ vhCmdListFlush_SingleQueueInternal_DeviceStateLocked ( nvrhi::CommandQueue::Compute );
173175 }
174176
175177 // Flush the requested queue
176- vhCmdListFlush_SingleQueueInternal ( type );
178+ vhCmdListFlush_SingleQueueInternal_DeviceStateLocked ( type );
177179}
178180
179181void vhCmdListFlushTransferIfNeeded ()
@@ -186,13 +188,20 @@ void vhCmdListFlushTransferIfNeeded()
186188 }
187189}
188190
189- void vhCmdListFlushAll ()
191+ void vhCmdListFlushAll_DeviceStateLocked ()
190192{
193+ // WARNING: Lock g_nvRHIStateMutex before calling this.
191194 // The order here matters slightly for efficiency ( Flush upsteam first ),
192195 // but the actual dependency correctness is handled by the waits inserted inside vhCmdListFlush.
193- vhCmdListFlush_SingleQueueInternal ( nvrhi::CommandQueue::Copy );
194- vhCmdListFlush_SingleQueueInternal ( nvrhi::CommandQueue::Compute );
195- vhCmdListFlush_SingleQueueInternal ( nvrhi::CommandQueue::Graphics );
196+ vhCmdListFlush_SingleQueueInternal_DeviceStateLocked ( nvrhi::CommandQueue::Copy );
197+ vhCmdListFlush_SingleQueueInternal_DeviceStateLocked ( nvrhi::CommandQueue::Compute );
198+ vhCmdListFlush_SingleQueueInternal_DeviceStateLocked ( nvrhi::CommandQueue::Graphics );
199+ }
200+
201+ void vhCmdListFlushAll ()
202+ {
203+ std::lock_guard< std::mutex > lock ( g_nvRHIStateMutex );
204+ vhCmdListFlushAll_DeviceStateLocked ();
196205}
197206
198207// Global states for user convenience.
0 commit comments