From 3f5f731c42e8be12699f52629139386ab07581b0 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 3 Aug 2022 17:13:32 +0200 Subject: [PATCH] [d3d11] Move D3D11UserDefinedAnnotation member to D3D11CommonContext This needs to be temlpated because we'll be moving EmitCs to the common implementation as well, and make EmitCsChunk non-virtual. --- src/d3d11/d3d11_annotation.cpp | 41 ++++++++++++++++++++---------- src/d3d11/d3d11_annotation.h | 16 +++++++----- src/d3d11/d3d11_context.cpp | 6 ----- src/d3d11/d3d11_context.h | 6 +---- src/d3d11/d3d11_context_common.cpp | 9 ++++++- src/d3d11/d3d11_context_common.h | 4 +++ 6 files changed, 51 insertions(+), 31 deletions(-) diff --git a/src/d3d11/d3d11_annotation.cpp b/src/d3d11/d3d11_annotation.cpp index 2eb79d7aa..b46dfe41e 100644 --- a/src/d3d11/d3d11_annotation.cpp +++ b/src/d3d11/d3d11_annotation.cpp @@ -1,5 +1,6 @@ #include "d3d11_annotation.h" -#include "d3d11_context.h" +#include "d3d11_context_def.h" +#include "d3d11_context_imm.h" #include "d3d11_device.h" #include "../util/util_misc.h" @@ -30,40 +31,47 @@ namespace dxvk { registrationFunction(annotation); } - D3D11UserDefinedAnnotation::D3D11UserDefinedAnnotation( - D3D11DeviceContext* container, + + template + D3D11UserDefinedAnnotation::D3D11UserDefinedAnnotation( + ContextType* container, const Rc& dxvkDevice) : m_container(container), m_eventDepth(0), m_annotationsEnabled(dxvkDevice->instance()->extensions().extDebugUtils) { - if (m_annotationsEnabled) + if (!IsDeferred && m_annotationsEnabled) RegisterUserDefinedAnnotation(this); } - D3D11UserDefinedAnnotation::~D3D11UserDefinedAnnotation() { - if (m_annotationsEnabled) + template + D3D11UserDefinedAnnotation::~D3D11UserDefinedAnnotation() { + if (!IsDeferred && m_annotationsEnabled) RegisterUserDefinedAnnotation(this); } - ULONG STDMETHODCALLTYPE D3D11UserDefinedAnnotation::AddRef() { + template + ULONG STDMETHODCALLTYPE D3D11UserDefinedAnnotation::AddRef() { return m_container->AddRef(); } - ULONG STDMETHODCALLTYPE D3D11UserDefinedAnnotation::Release() { + template + ULONG STDMETHODCALLTYPE D3D11UserDefinedAnnotation::Release() { return m_container->Release(); } - HRESULT STDMETHODCALLTYPE D3D11UserDefinedAnnotation::QueryInterface( + template + HRESULT STDMETHODCALLTYPE D3D11UserDefinedAnnotation::QueryInterface( REFIID riid, void** ppvObject) { return m_container->QueryInterface(riid, ppvObject); } - INT STDMETHODCALLTYPE D3D11UserDefinedAnnotation::BeginEvent( + template + INT STDMETHODCALLTYPE D3D11UserDefinedAnnotation::BeginEvent( D3DCOLOR Color, LPCWSTR Name) { if (!m_annotationsEnabled) @@ -85,7 +93,8 @@ namespace dxvk { } - INT STDMETHODCALLTYPE D3D11UserDefinedAnnotation::EndEvent() { + template + INT STDMETHODCALLTYPE D3D11UserDefinedAnnotation::EndEvent() { if (!m_annotationsEnabled) return -1; @@ -99,7 +108,8 @@ namespace dxvk { } - void STDMETHODCALLTYPE D3D11UserDefinedAnnotation::SetMarker( + template + void STDMETHODCALLTYPE D3D11UserDefinedAnnotation::SetMarker( D3DCOLOR Color, LPCWSTR Name) { if (!m_annotationsEnabled) @@ -119,8 +129,13 @@ namespace dxvk { } - BOOL STDMETHODCALLTYPE D3D11UserDefinedAnnotation::GetStatus() { + template + BOOL STDMETHODCALLTYPE D3D11UserDefinedAnnotation::GetStatus() { return m_annotationsEnabled; } + + template class D3D11UserDefinedAnnotation; + template class D3D11UserDefinedAnnotation; + } diff --git a/src/d3d11/d3d11_annotation.h b/src/d3d11/d3d11_annotation.h index 8419b92cc..ec569a9a0 100644 --- a/src/d3d11/d3d11_annotation.h +++ b/src/d3d11/d3d11_annotation.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "d3d11_include.h" #include "../dxvk/dxvk_annotation.h" @@ -7,14 +9,16 @@ namespace dxvk { - class D3D11DeviceContext; + class D3D11DeferredContext; + class D3D11ImmediateContext; + template class D3D11UserDefinedAnnotation final : public IDXVKUserDefinedAnnotation { - + constexpr static bool IsDeferred = std::is_same_v; public: D3D11UserDefinedAnnotation( - D3D11DeviceContext* container, + ContextType* container, const Rc& dxvkDevice); ~D3D11UserDefinedAnnotation(); @@ -44,9 +48,9 @@ namespace dxvk { private: - D3D11DeviceContext* m_container; - int32_t m_eventDepth; - bool m_annotationsEnabled; + ContextType* m_container; + int32_t m_eventDepth; + bool m_annotationsEnabled; }; } diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index 6ca5ca272..f9251f447 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -19,7 +19,6 @@ namespace dxvk { m_multithread(this, false), m_device (Device), m_staging (Device, StagingBufferSize), - m_annotation(this, Device), m_csFlags (CsFlags), m_csChunk (AllocCsChunk()), m_cmdData (nullptr) { @@ -2780,11 +2779,6 @@ namespace dxvk { } - BOOL STDMETHODCALLTYPE D3D11DeviceContext::IsAnnotationEnabled() { - return m_annotation.GetStatus(); - } - - void STDMETHODCALLTYPE D3D11DeviceContext::SetMarkerInt( LPCWSTR pLabel, INT Data) { diff --git a/src/d3d11/d3d11_context.h b/src/d3d11/d3d11_context.h index 9fb3724a7..93e85e879 100644 --- a/src/d3d11/d3d11_context.h +++ b/src/d3d11/d3d11_context.h @@ -21,6 +21,7 @@ namespace dxvk { class D3D11DeviceContext : public D3D11DeviceChild { friend class D3D11DeviceContextExt; // Needed in order to call EmitCs for pushing markers + template friend class D3D11UserDefinedAnnotation; constexpr static VkDeviceSize StagingBufferSize = 4ull << 20; @@ -658,8 +659,6 @@ namespace dxvk { ID3D11Buffer** ppSOTargets, UINT* pOffsets); - BOOL STDMETHODCALLTYPE IsAnnotationEnabled(); - void STDMETHODCALLTYPE SetMarkerInt( LPCWSTR pLabel, INT Data); @@ -695,9 +694,6 @@ namespace dxvk { Rc m_updateBuffer; DxvkStagingBuffer m_staging; - - //has to be declared after m_device, as compiler initialize in order of declaration in the class - D3D11UserDefinedAnnotation m_annotation; DxvkCsChunkFlags m_csFlags; DxvkCsChunkRef m_csChunk; diff --git a/src/d3d11/d3d11_context_common.cpp b/src/d3d11/d3d11_context_common.cpp index ffe4ac16f..786e9840c 100644 --- a/src/d3d11/d3d11_context_common.cpp +++ b/src/d3d11/d3d11_context_common.cpp @@ -9,7 +9,8 @@ namespace dxvk { D3D11Device* pParent, const Rc& Device, DxvkCsChunkFlags CsFlags) - : D3D11DeviceContext(pParent, Device, CsFlags) { + : D3D11DeviceContext(pParent, Device, CsFlags), + m_annotation(static_cast(this), Device) { } @@ -88,6 +89,12 @@ namespace dxvk { } + template + BOOL STDMETHODCALLTYPE D3D11CommonContext::IsAnnotationEnabled() { + return m_annotation.GetStatus(); + } + + template void D3D11CommonContext::UpdateResource( ID3D11Resource* pDstResource, diff --git a/src/d3d11/d3d11_context_common.h b/src/d3d11/d3d11_context_common.h index cc04fe5aa..8161142bf 100644 --- a/src/d3d11/d3d11_context_common.h +++ b/src/d3d11/d3d11_context_common.h @@ -85,8 +85,12 @@ namespace dxvk { UINT SrcDepthPitch, UINT CopyFlags); + BOOL STDMETHODCALLTYPE IsAnnotationEnabled(); + protected: + D3D11UserDefinedAnnotation m_annotation; + void UpdateResource( ID3D11Resource* pDstResource, UINT DstSubresource,