1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-02 19:24:12 +01:00

[dxvk] Implement backend part for event queries

This commit is contained in:
Philip Rebohle 2018-02-18 22:57:45 +01:00
parent 5334ff57bf
commit 5fea615ed7
10 changed files with 139 additions and 6 deletions

View File

@ -141,8 +141,13 @@ namespace dxvk {
void D3D11Query::Signal(DxvkContext* ctx, uint32_t revision) { void D3D11Query::Signal(DxvkContext* ctx, uint32_t revision) {
switch (m_desc.Query) { switch (m_desc.Query) {
case D3D11_QUERY_EVENT: {
DxvkEventRevision rev = { m_event, revision };
ctx->signalEvent(rev);
} break;
case D3D11_QUERY_TIMESTAMP: { case D3D11_QUERY_TIMESTAMP: {
DxvkQueryRevision rev = { m_query, m_revision }; DxvkQueryRevision rev = { m_query, revision };
ctx->writeTimestamp(rev); ctx->writeTimestamp(rev);
} break; } break;

View File

@ -4,6 +4,7 @@
#include "dxvk_binding.h" #include "dxvk_binding.h"
#include "dxvk_descriptor.h" #include "dxvk_descriptor.h"
#include "dxvk_event_tracker.h"
#include "dxvk_lifetime.h" #include "dxvk_lifetime.h"
#include "dxvk_limits.h" #include "dxvk_limits.h"
#include "dxvk_pipelayout.h" #include "dxvk_pipelayout.h"
@ -85,12 +86,32 @@ namespace dxvk {
m_queryTracker.trackQueryRange(std::move(queries)); m_queryTracker.trackQueryRange(std::move(queries));
} }
/**
* \brief Adds an event revision to track
*
* The event will be signaled after the command
* buffer has finished executing on the GPU.
*/
void trackEvent(const DxvkEventRevision& event) {
m_eventTracker.trackEvent(event);
}
/**
* \brief Signals tracked events
*
* Marks all tracked events as signaled. Call this after
* synchronizing with a fence for this command list.
*/
void signalEvents() {
m_eventTracker.signalEvents();
}
/** /**
* \brief Writes back query results * \brief Writes back query results
* *
* Uses the query range to write back query data * Writes back query data to all queries tracked by the
* after the command list has finished executing * query range tracker. Call this after synchronizing
* on the GPU. * with a fence for this command list.
*/ */
void writeQueryData() { void writeQueryData() {
m_queryTracker.writeQueryData(); m_queryTracker.writeQueryData();
@ -486,6 +507,7 @@ namespace dxvk {
DxvkDescriptorAlloc m_descAlloc; DxvkDescriptorAlloc m_descAlloc;
DxvkStagingAlloc m_stagingAlloc; DxvkStagingAlloc m_stagingAlloc;
DxvkQueryTracker m_queryTracker; DxvkQueryTracker m_queryTracker;
DxvkEventTracker m_eventTracker;
}; };

View File

@ -1201,6 +1201,11 @@ namespace dxvk {
} }
void DxvkContext::signalEvent(const DxvkEventRevision& event) {
m_cmd->trackEvent(event);
}
void DxvkContext::writeTimestamp(const DxvkQueryRevision& query) { void DxvkContext::writeTimestamp(const DxvkQueryRevision& query) {
DxvkQueryHandle handle = this->allocQuery(query); DxvkQueryHandle handle = this->allocQuery(query);

View File

@ -5,6 +5,8 @@
#include "dxvk_cmdlist.h" #include "dxvk_cmdlist.h"
#include "dxvk_context_state.h" #include "dxvk_context_state.h"
#include "dxvk_data.h" #include "dxvk_data.h"
#include "dxvk_event.h"
#include "dxvk_query.h"
#include "dxvk_query_pool.h" #include "dxvk_query_pool.h"
#include "dxvk_util.h" #include "dxvk_util.h"
@ -542,6 +544,13 @@ namespace dxvk {
uint32_t attachment, uint32_t attachment,
const DxvkBlendMode& blendMode); const DxvkBlendMode& blendMode);
/**
* \brief Signals an event
* \param [in] event The event
*/
void signalEvent(
const DxvkEventRevision& event);
/** /**
* \brief Writes to a timestamp query * \brief Writes to a timestamp query
* \param [in] query The timestamp query * \param [in] query The timestamp query

View File

@ -14,7 +14,7 @@ namespace dxvk {
} }
void DxvkEvent::signalEvent(uint32_t revision) { void DxvkEvent::signal(uint32_t revision) {
std::unique_lock<std::mutex> lock(m_mutex); std::unique_lock<std::mutex> lock(m_mutex);
if (m_revision == revision) { if (m_revision == revision) {

View File

@ -7,6 +7,9 @@
namespace dxvk { namespace dxvk {
/**
* \brief Event status
*/
enum class DxvkEventStatus { enum class DxvkEventStatus {
Reset = 0, Reset = 0,
Signaled = 1, Signaled = 1,
@ -36,7 +39,7 @@ namespace dxvk {
* \brief Signals the event * \brief Signals the event
* \param [in] revision The revision ID * \param [in] revision The revision ID
*/ */
void signalEvent(uint32_t revision); void signal(uint32_t revision);
/** /**
* \brief Queries event status * \brief Queries event status
@ -54,4 +57,15 @@ namespace dxvk {
}; };
/**
* \brief Event revision
*
* Stores the event object and the
* version ID for event operations.
*/
struct DxvkEventRevision {
Rc<DxvkEvent> event;
uint32_t revision;
};
} }

View File

@ -0,0 +1,30 @@
#include "dxvk_event_tracker.h"
namespace dxvk {
DxvkEventTracker::DxvkEventTracker() {
}
DxvkEventTracker::~DxvkEventTracker() {
}
void DxvkEventTracker::trackEvent(const DxvkEventRevision& event) {
m_events.push_back(event);
}
void DxvkEventTracker::signalEvents() {
for (const DxvkEventRevision& event : m_events)
event.event->signal(event.revision);
}
void DxvkEventTracker::reset() {
m_events.clear();
}
}

View File

@ -0,0 +1,45 @@
#pragma once
#include "dxvk_event.h"
namespace dxvk {
/**
* \brief Event tracker
*/
class DxvkEventTracker {
public:
DxvkEventTracker();
~DxvkEventTracker();
/**
* \brief Adds an event to track
* \param [in] event The event revision
*/
void trackEvent(const DxvkEventRevision& event);
/**
* \brief Signals tracked events
*
* Retrieves query data from the query pools
* and writes it back to the query objects.
*/
void signalEvents();
/**
* \brief Resets event tracker
*
* Releases all events from the tracker.
* Call this after signaling the events.
*/
void reset();
private:
std::vector<DxvkEventRevision> m_events;
};
}

View File

@ -58,7 +58,9 @@ namespace dxvk {
entry.fence->wait(std::numeric_limits<uint64_t>::max()); entry.fence->wait(std::numeric_limits<uint64_t>::max());
entry.cmdList->writeQueryData(); entry.cmdList->writeQueryData();
entry.cmdList->signalEvents();
entry.cmdList->reset(); entry.cmdList->reset();
m_device->recycleCommandList(entry.cmdList); m_device->recycleCommandList(entry.cmdList);
} }
} }

View File

@ -17,6 +17,7 @@ dxvk_src = files([
'dxvk_device.cpp', 'dxvk_device.cpp',
'dxvk_extensions.cpp', 'dxvk_extensions.cpp',
'dxvk_event.cpp', 'dxvk_event.cpp',
'dxvk_event_tracker.cpp',
'dxvk_format.cpp', 'dxvk_format.cpp',
'dxvk_framebuffer.cpp', 'dxvk_framebuffer.cpp',
'dxvk_graphics.cpp', 'dxvk_graphics.cpp',