1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-05 02:52:11 +01:00
dxvk/src/d3d11/d3d11_query.h

121 lines
2.9 KiB
C
Raw Normal View History

2017-12-29 22:20:31 +01:00
#pragma once
#include "../dxvk/dxvk_gpu_event.h"
2018-11-17 10:48:18 +01:00
#include "../dxvk/dxvk_gpu_query.h"
2018-02-18 22:34:23 +01:00
2018-08-12 00:20:17 +02:00
#include "../d3d10/d3d10_query.h"
#include "d3d11_device_child.h"
2017-12-29 22:20:31 +01:00
namespace dxvk {
enum D3D11_VK_QUERY_STATE : uint32_t {
D3D11_VK_QUERY_INITIAL,
D3D11_VK_QUERY_BEGUN,
D3D11_VK_QUERY_ENDED,
};
2019-09-16 15:13:48 +02:00
class D3D11Query : public D3D11DeviceChild<ID3D11Query1> {
constexpr static uint32_t MaxGpuQueries = 2;
constexpr static uint32_t MaxGpuEvents = 1;
2017-12-29 22:20:31 +01:00
public:
D3D11Query(
2019-09-16 15:13:48 +02:00
D3D11Device* device,
const D3D11_QUERY_DESC1& desc);
2017-12-29 22:20:31 +01:00
~D3D11Query();
HRESULT STDMETHODCALLTYPE QueryInterface(
REFIID riid,
void** ppvObject) final;
UINT STDMETHODCALLTYPE GetDataSize();
2019-09-16 15:13:48 +02:00
void STDMETHODCALLTYPE GetDesc(D3D11_QUERY_DESC* pDesc) final;
void STDMETHODCALLTYPE GetDesc1(D3D11_QUERY_DESC1* pDesc) final;
2018-11-17 10:48:18 +01:00
void Begin(DxvkContext* ctx);
2018-02-18 22:34:23 +01:00
void End(DxvkContext* ctx);
bool STDMETHODCALLTYPE DoBegin();
bool STDMETHODCALLTYPE DoEnd();
HRESULT STDMETHODCALLTYPE GetData(
void* pData,
UINT GetDataFlags);
void DoDeferredEnd() {
m_state = D3D11_VK_QUERY_ENDED;
m_resetCtr.fetch_add(1, std::memory_order_acquire);
}
bool IsScoped() const {
return m_desc.Query != D3D11_QUERY_EVENT
&& m_desc.Query != D3D11_QUERY_TIMESTAMP;
}
bool IsEvent() const {
return m_desc.Query == D3D11_QUERY_EVENT;
}
bool TrackStalls() const {
return m_desc.Query == D3D11_QUERY_EVENT
|| m_desc.Query == D3D11_QUERY_TIMESTAMP
|| m_desc.Query == D3D11_QUERY_TIMESTAMP_DISJOINT;
}
bool IsStalling() const {
return m_stallFlag;
}
void NotifyEnd() {
m_stallMask <<= 1;
}
void NotifyStall() {
m_stallMask |= 1;
m_stallFlag |= bit::popcnt(m_stallMask) >= 16;
}
2018-08-12 00:20:17 +02:00
D3D10Query* GetD3D10Iface() {
return &m_d3d10;
}
2019-09-16 15:13:48 +02:00
2019-09-16 16:04:06 +02:00
static HRESULT ValidateDesc(const D3D11_QUERY_DESC1* pDesc);
2019-09-16 15:13:48 +02:00
static ID3D11Predicate* AsPredicate(ID3D11Query* pQuery) {
// ID3D11Predicate and ID3D11Query have the same vtable. This
// saves us some headache in all query-related functions.
2019-09-16 15:13:48 +02:00
return static_cast<ID3D11Predicate*>(pQuery);
}
static D3D11Query* FromPredicate(ID3D11Predicate* pPredicate) {
return static_cast<D3D11Query*>(static_cast<ID3D11Query*>(pPredicate));
}
2018-08-12 00:20:17 +02:00
2017-12-29 22:20:31 +01:00
private:
2019-09-16 15:13:48 +02:00
D3D11_QUERY_DESC1 m_desc;
D3D11_VK_QUERY_STATE m_state;
2017-12-29 22:20:31 +01:00
std::array<Rc<DxvkQuery>, MaxGpuQueries> m_query;
std::array<Rc<DxvkEvent>, MaxGpuEvents> m_event;
2018-08-12 00:20:17 +02:00
D3D10Query m_d3d10;
uint32_t m_stallMask = 0;
bool m_stallFlag = false;
std::atomic<uint32_t> m_resetCtr = { 0u };
UINT64 GetTimestampQueryFrequency() const;
2018-02-18 22:34:23 +01:00
2017-12-29 22:20:31 +01:00
};
}