Organisation
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
#include "RenderCommandQueue.h"
|
||||
|
||||
void RenderCommandQueue::RequestPreviewPresent(const RenderPreviewPresentRequest& request)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
if (mHasPreviewPresentRequest)
|
||||
++mCoalescedCount;
|
||||
else
|
||||
++mEnqueuedCount;
|
||||
|
||||
mPreviewPresentRequest = request;
|
||||
mHasPreviewPresentRequest = true;
|
||||
}
|
||||
|
||||
bool RenderCommandQueue::TryTakePreviewPresent(RenderPreviewPresentRequest& request)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
if (!mHasPreviewPresentRequest)
|
||||
return false;
|
||||
|
||||
request = mPreviewPresentRequest;
|
||||
mPreviewPresentRequest = {};
|
||||
mHasPreviewPresentRequest = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderCommandQueue::RequestScreenshotCapture(const RenderScreenshotCaptureRequest& request)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
if (mHasScreenshotCaptureRequest)
|
||||
++mCoalescedCount;
|
||||
else
|
||||
++mEnqueuedCount;
|
||||
|
||||
mScreenshotCaptureRequest = request;
|
||||
mHasScreenshotCaptureRequest = true;
|
||||
}
|
||||
|
||||
bool RenderCommandQueue::TryTakeScreenshotCapture(RenderScreenshotCaptureRequest& request)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
if (!mHasScreenshotCaptureRequest)
|
||||
return false;
|
||||
|
||||
request = mScreenshotCaptureRequest;
|
||||
mScreenshotCaptureRequest = {};
|
||||
mHasScreenshotCaptureRequest = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderCommandQueue::RequestInputUpload(const RenderInputUploadRequest& request)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
if (mHasInputUploadRequest)
|
||||
++mCoalescedCount;
|
||||
else
|
||||
++mEnqueuedCount;
|
||||
|
||||
mInputUploadRequest = request;
|
||||
mHasInputUploadRequest = true;
|
||||
}
|
||||
|
||||
bool RenderCommandQueue::TryTakeInputUpload(RenderInputUploadRequest& request)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
if (!mHasInputUploadRequest)
|
||||
return false;
|
||||
|
||||
request = mInputUploadRequest;
|
||||
mInputUploadRequest = {};
|
||||
mHasInputUploadRequest = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderCommandQueue::RequestOutputFrame(const RenderOutputFrameRequest& request)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
mOutputFrameRequests.push_back(request);
|
||||
++mEnqueuedCount;
|
||||
}
|
||||
|
||||
bool RenderCommandQueue::TryTakeOutputFrame(RenderOutputFrameRequest& request)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
if (mOutputFrameRequests.empty())
|
||||
return false;
|
||||
|
||||
request = mOutputFrameRequests.front();
|
||||
mOutputFrameRequests.pop_front();
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderCommandQueue::RequestRenderReset(RenderCommandResetScope scope)
|
||||
{
|
||||
if (scope == RenderCommandResetScope::None)
|
||||
return;
|
||||
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
if (mRenderResetScope != RenderCommandResetScope::None)
|
||||
++mCoalescedCount;
|
||||
else
|
||||
++mEnqueuedCount;
|
||||
|
||||
mRenderResetScope = MergeResetScopes(mRenderResetScope, scope);
|
||||
}
|
||||
|
||||
bool RenderCommandQueue::TryTakeRenderReset(RenderCommandResetScope& scope)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
if (mRenderResetScope == RenderCommandResetScope::None)
|
||||
return false;
|
||||
|
||||
scope = mRenderResetScope;
|
||||
mRenderResetScope = RenderCommandResetScope::None;
|
||||
return true;
|
||||
}
|
||||
|
||||
RenderCommandQueueMetrics RenderCommandQueue::GetMetrics() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mMutex);
|
||||
RenderCommandQueueMetrics metrics;
|
||||
metrics.depth =
|
||||
(mHasPreviewPresentRequest ? 1u : 0u) +
|
||||
(mHasScreenshotCaptureRequest ? 1u : 0u) +
|
||||
(mHasInputUploadRequest ? 1u : 0u) +
|
||||
mOutputFrameRequests.size() +
|
||||
(mRenderResetScope != RenderCommandResetScope::None ? 1u : 0u);
|
||||
metrics.enqueuedCount = mEnqueuedCount;
|
||||
metrics.coalescedCount = mCoalescedCount;
|
||||
return metrics;
|
||||
}
|
||||
|
||||
RenderCommandResetScope RenderCommandQueue::MergeResetScopes(RenderCommandResetScope current, RenderCommandResetScope requested)
|
||||
{
|
||||
if (current == RenderCommandResetScope::TemporalHistoryAndFeedback ||
|
||||
requested == RenderCommandResetScope::TemporalHistoryAndFeedback)
|
||||
{
|
||||
return RenderCommandResetScope::TemporalHistoryAndFeedback;
|
||||
}
|
||||
|
||||
if ((current == RenderCommandResetScope::TemporalHistoryOnly && requested == RenderCommandResetScope::ShaderFeedbackOnly) ||
|
||||
(current == RenderCommandResetScope::ShaderFeedbackOnly && requested == RenderCommandResetScope::TemporalHistoryOnly))
|
||||
{
|
||||
return RenderCommandResetScope::TemporalHistoryAndFeedback;
|
||||
}
|
||||
|
||||
if (current == RenderCommandResetScope::TemporalHistoryOnly ||
|
||||
requested == RenderCommandResetScope::TemporalHistoryOnly)
|
||||
{
|
||||
return RenderCommandResetScope::TemporalHistoryOnly;
|
||||
}
|
||||
|
||||
if (current == RenderCommandResetScope::ShaderFeedbackOnly ||
|
||||
requested == RenderCommandResetScope::ShaderFeedbackOnly)
|
||||
{
|
||||
return RenderCommandResetScope::ShaderFeedbackOnly;
|
||||
}
|
||||
|
||||
return RenderCommandResetScope::None;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
#pragma once
|
||||
|
||||
#include "VideoIOTypes.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
enum class RenderCommandResetScope
|
||||
{
|
||||
None,
|
||||
ShaderFeedbackOnly,
|
||||
TemporalHistoryOnly,
|
||||
TemporalHistoryAndFeedback
|
||||
};
|
||||
|
||||
struct RenderPreviewPresentRequest
|
||||
{
|
||||
unsigned outputFrameWidth = 0;
|
||||
unsigned outputFrameHeight = 0;
|
||||
};
|
||||
|
||||
struct RenderScreenshotCaptureRequest
|
||||
{
|
||||
unsigned width = 0;
|
||||
unsigned height = 0;
|
||||
};
|
||||
|
||||
struct RenderInputUploadRequest
|
||||
{
|
||||
VideoIOFrame inputFrame;
|
||||
VideoIOState videoState;
|
||||
std::vector<unsigned char> ownedBytes;
|
||||
};
|
||||
|
||||
struct RenderOutputFrameRequest
|
||||
{
|
||||
VideoIOState videoState;
|
||||
VideoIOCompletion completion;
|
||||
};
|
||||
|
||||
struct RenderCommandQueueMetrics
|
||||
{
|
||||
std::size_t depth = 0;
|
||||
uint64_t enqueuedCount = 0;
|
||||
uint64_t coalescedCount = 0;
|
||||
};
|
||||
|
||||
class RenderCommandQueue
|
||||
{
|
||||
public:
|
||||
void RequestPreviewPresent(const RenderPreviewPresentRequest& request);
|
||||
bool TryTakePreviewPresent(RenderPreviewPresentRequest& request);
|
||||
|
||||
void RequestScreenshotCapture(const RenderScreenshotCaptureRequest& request);
|
||||
bool TryTakeScreenshotCapture(RenderScreenshotCaptureRequest& request);
|
||||
|
||||
void RequestInputUpload(const RenderInputUploadRequest& request);
|
||||
bool TryTakeInputUpload(RenderInputUploadRequest& request);
|
||||
|
||||
void RequestOutputFrame(const RenderOutputFrameRequest& request);
|
||||
bool TryTakeOutputFrame(RenderOutputFrameRequest& request);
|
||||
|
||||
void RequestRenderReset(RenderCommandResetScope scope);
|
||||
bool TryTakeRenderReset(RenderCommandResetScope& scope);
|
||||
|
||||
RenderCommandQueueMetrics GetMetrics() const;
|
||||
|
||||
private:
|
||||
static RenderCommandResetScope MergeResetScopes(RenderCommandResetScope current, RenderCommandResetScope requested);
|
||||
|
||||
mutable std::mutex mMutex;
|
||||
bool mHasPreviewPresentRequest = false;
|
||||
RenderPreviewPresentRequest mPreviewPresentRequest;
|
||||
bool mHasScreenshotCaptureRequest = false;
|
||||
RenderScreenshotCaptureRequest mScreenshotCaptureRequest;
|
||||
bool mHasInputUploadRequest = false;
|
||||
RenderInputUploadRequest mInputUploadRequest;
|
||||
std::deque<RenderOutputFrameRequest> mOutputFrameRequests;
|
||||
RenderCommandResetScope mRenderResetScope = RenderCommandResetScope::None;
|
||||
uint64_t mEnqueuedCount = 0;
|
||||
uint64_t mCoalescedCount = 0;
|
||||
};
|
||||
Reference in New Issue
Block a user