hle: service: vi: Remove usage of SleepClientThread.

This commit is contained in:
bunnei 2020-12-09 22:52:09 -08:00
parent 28281ae250
commit b377da042b
1 changed files with 41 additions and 32 deletions

View File

@ -536,9 +536,6 @@ private:
LOG_DEBUG(Service_VI, "called. id=0x{:08X} transaction={:X}, flags=0x{:08X}", id, LOG_DEBUG(Service_VI, "called. id=0x{:08X} transaction={:X}, flags=0x{:08X}", id,
transaction, flags); transaction, flags);
const auto guard = nv_flinger.Lock();
auto& buffer_queue = nv_flinger.FindBufferQueue(id);
switch (transaction) { switch (transaction) {
case TransactionId::Connect: { case TransactionId::Connect: {
IGBPConnectRequestParcel request{ctx.ReadBuffer()}; IGBPConnectRequestParcel request{ctx.ReadBuffer()};
@ -553,7 +550,11 @@ private:
case TransactionId::SetPreallocatedBuffer: { case TransactionId::SetPreallocatedBuffer: {
IGBPSetPreallocatedBufferRequestParcel request{ctx.ReadBuffer()}; IGBPSetPreallocatedBufferRequestParcel request{ctx.ReadBuffer()};
buffer_queue.SetPreallocatedBuffer(request.data.slot, request.buffer_container.buffer); {
const auto guard = nv_flinger.Lock();
auto& buffer_queue = nv_flinger.FindBufferQueue(id);
buffer_queue.SetPreallocatedBuffer(request.data.slot, request.buffer_container.buffer);
}
IGBPSetPreallocatedBufferResponseParcel response{}; IGBPSetPreallocatedBufferResponseParcel response{};
ctx.WriteBuffer(response.Serialize()); ctx.WriteBuffer(response.Serialize());
@ -563,48 +564,46 @@ private:
IGBPDequeueBufferRequestParcel request{ctx.ReadBuffer()}; IGBPDequeueBufferRequestParcel request{ctx.ReadBuffer()};
const u32 width{request.data.width}; const u32 width{request.data.width};
const u32 height{request.data.height}; const u32 height{request.data.height};
auto result = buffer_queue.DequeueBuffer(width, height);
if (result) { std::optional<std::pair<u32, Service::Nvidia::MultiFence*>> result;
// Buffer is available
IGBPDequeueBufferResponseParcel response{result->first, *result->second};
ctx.WriteBuffer(response.Serialize());
} else {
// Wait the current thread until a buffer becomes available
ctx.SleepClientThread(
"IHOSBinderDriver::DequeueBuffer", UINT64_MAX,
[=, this](std::shared_ptr<Kernel::Thread> thread,
Kernel::HLERequestContext& ctx, Kernel::ThreadWakeupReason reason) {
// Repeat TransactParcel DequeueBuffer when a buffer is available
const auto guard = nv_flinger.Lock();
auto& buffer_queue = nv_flinger.FindBufferQueue(id);
auto result = buffer_queue.DequeueBuffer(width, height);
ASSERT_MSG(result != std::nullopt, "Could not dequeue buffer.");
IGBPDequeueBufferResponseParcel response{result->first, *result->second}; while (!result) {
ctx.WriteBuffer(response.Serialize()); {
IPC::ResponseBuilder rb{ctx, 2}; const auto guard = nv_flinger.Lock();
rb.Push(RESULT_SUCCESS); auto& buffer_queue = nv_flinger.FindBufferQueue(id);
}, result = buffer_queue.DequeueBuffer(width, height);
buffer_queue.GetWritableBufferWaitEvent()); }
if (result) {
// Buffer is available
IGBPDequeueBufferResponseParcel response{result->first, *result->second};
ctx.WriteBuffer(response.Serialize());
}
} }
break; break;
} }
case TransactionId::RequestBuffer: { case TransactionId::RequestBuffer: {
IGBPRequestBufferRequestParcel request{ctx.ReadBuffer()}; IGBPRequestBufferRequestParcel request{ctx.ReadBuffer()};
const auto guard = nv_flinger.Lock();
auto& buffer_queue = nv_flinger.FindBufferQueue(id);
auto& buffer = buffer_queue.RequestBuffer(request.slot); auto& buffer = buffer_queue.RequestBuffer(request.slot);
IGBPRequestBufferResponseParcel response{buffer}; IGBPRequestBufferResponseParcel response{buffer};
ctx.WriteBuffer(response.Serialize()); ctx.WriteBuffer(response.Serialize());
break; break;
} }
case TransactionId::QueueBuffer: { case TransactionId::QueueBuffer: {
IGBPQueueBufferRequestParcel request{ctx.ReadBuffer()}; IGBPQueueBufferRequestParcel request{ctx.ReadBuffer()};
buffer_queue.QueueBuffer(request.data.slot, request.data.transform, {
request.data.GetCropRect(), request.data.swap_interval, const auto guard = nv_flinger.Lock();
request.data.multi_fence); auto& buffer_queue = nv_flinger.FindBufferQueue(id);
buffer_queue.QueueBuffer(request.data.slot, request.data.transform,
request.data.GetCropRect(), request.data.swap_interval,
request.data.multi_fence);
}
IGBPQueueBufferResponseParcel response{1280, 720}; IGBPQueueBufferResponseParcel response{1280, 720};
ctx.WriteBuffer(response.Serialize()); ctx.WriteBuffer(response.Serialize());
@ -613,6 +612,8 @@ private:
case TransactionId::Query: { case TransactionId::Query: {
IGBPQueryRequestParcel request{ctx.ReadBuffer()}; IGBPQueryRequestParcel request{ctx.ReadBuffer()};
const auto guard = nv_flinger.Lock();
auto& buffer_queue = nv_flinger.FindBufferQueue(id);
const u32 value = const u32 value =
buffer_queue.Query(static_cast<NVFlinger::BufferQueue::QueryType>(request.type)); buffer_queue.Query(static_cast<NVFlinger::BufferQueue::QueryType>(request.type));
@ -623,7 +624,11 @@ private:
case TransactionId::CancelBuffer: { case TransactionId::CancelBuffer: {
IGBPCancelBufferRequestParcel request{ctx.ReadBuffer()}; IGBPCancelBufferRequestParcel request{ctx.ReadBuffer()};
buffer_queue.CancelBuffer(request.data.slot, request.data.multi_fence); {
const auto guard = nv_flinger.Lock();
auto& buffer_queue = nv_flinger.FindBufferQueue(id);
buffer_queue.CancelBuffer(request.data.slot, request.data.multi_fence);
}
IGBPCancelBufferResponseParcel response{}; IGBPCancelBufferResponseParcel response{};
ctx.WriteBuffer(response.Serialize()); ctx.WriteBuffer(response.Serialize());
@ -633,7 +638,11 @@ private:
LOG_WARNING(Service_VI, "(STUBBED) called, transaction=Disconnect"); LOG_WARNING(Service_VI, "(STUBBED) called, transaction=Disconnect");
const auto buffer = ctx.ReadBuffer(); const auto buffer = ctx.ReadBuffer();
buffer_queue.Disconnect(); {
const auto guard = nv_flinger.Lock();
auto& buffer_queue = nv_flinger.FindBufferQueue(id);
buffer_queue.Disconnect();
}
IGBPEmptyResponseParcel response{}; IGBPEmptyResponseParcel response{};
ctx.WriteBuffer(response.Serialize()); ctx.WriteBuffer(response.Serialize());