Following the guidelines in the documentation, and due to wanting to get the absolute minimum latency out of the system as possible, I moved to asynchronous mode on Windows 10.
When encoding and then waiting for the completion event and locking output buffers on the same thread, my code works fine.
When I move the code which waits on the completion event and then calls nvEncLockBitstream and nvEncUnlockBitstream, I was getting unpredictable crashes in nvwgf2umx.dll. I turned on the debug runtime, and the following message was shown:
D3D11 CORRUPTION: ID3D11DeviceContext::IASetPrimitiveTopology: Two threads were found to be executing functions associated with the same Device[Context] at the same time. This will cause corruption of memory. Appropriate thread synchronization needs to occur external to the Direct3D API (or through the ID3D10Multithread interface). 19248 and 14720 are the implicated thread ids. [ MISCELLANEOUS CORRUPTION #28: CORRUPTED_MULTITHREADING] D3D11: **BREAK** enabled for the previous message, which was: [ CORRUPTION MISCELLANEOUS #28: CORRUPTED_MULTITHREADING ]
This usually occurs while within the call to nvencLockBitstream, and other times within the call to nvEncUnlockBitstream. This occurs on the secondary non-render thread, as per the documentation. I’ve verified that the main thread is not attempting to access the input resource that was being processed by the encoder.
The callstack of the call into nvencLockBitstream is as follows:
A few years ago, a similar thread was brought up on this forum, and the solution was to move back to a single thread. DirectX 11 and asynchronous encoding I wonder if asynchronous receipt of the encoded packets is actually not supported? Do we have to use CUDA perhaps? It’s really not clear, and there don’t seem to be any examples of this approach.