-
Notifications
You must be signed in to change notification settings - Fork 3
/
AmdExtDeviceWrapper.h
137 lines (116 loc) · 4.88 KB
/
AmdExtDeviceWrapper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//==============================================================================
// Copyright (c) 2017-2018 Advanced Micro Devices, Inc. All rights reserved.
/// \author AMD Developer Tools Team
/// \file
/// \brief This file contains a wrapper implementation for the IAmdExtD3DDevice1
/// interface.
/// This requires AMD driver with a device level marker extension support
/// (driver 17.30.1081 or newer).
/// \warning Only support the unicode character set (does not support multi-byte)
//==============================================================================
#ifndef _AMD_EXT_DEVICE_WRAPPER_H_
#define _AMD_EXT_DEVICE_WRAPPER_H_
#include <stdio.h>
#include <stdarg.h>
#include "AmdExtD3D.h"
#include "AmdExtD3DDeviceApi.h"
class AmdExtD3DDeviceWrapper
{
public:
static const uint32_t MAX_MARKER_STRING_LENGTH = 1024;
~AmdExtD3DDeviceWrapper()
{
if (nullptr != m_pAmdExtDeviceObject)
{
m_pAmdExtDeviceObject = nullptr;
m_d3d12Device.Reset();
}
}
// this function will initialize the m_pAmdExtDeviceObject which contains the marker API
inline void InitializeAmdExtDeviceObject(ID3D12GraphicsCommandList* pCommandList)
{
// return immediately if the device extension object has been created
if (nullptr != m_pAmdExtDeviceObject)
{
return;
}
HMODULE hpAmdD3dDl2 = LoadLibrary(L"amdxc64.dll");
if (nullptr != hpAmdD3dDl2)
{
PFNAmdExtD3DCreateInterface pAmdExtD3dCreateFunc = (PFNAmdExtD3DCreateInterface)GetProcAddress(hpAmdD3dDl2,
"AmdExtD3DCreateInterface");
if (nullptr != pAmdExtD3dCreateFunc)
{
if (nullptr != pCommandList)
{
pCommandList->GetDevice(__uuidof(ID3D12Device),
reinterpret_cast<void**>(m_d3d12Device.GetAddressOf()));
}
if (nullptr != m_d3d12Device.Get())
{
// create the extension object factory
IAmdExtD3DFactory* pAmdExtObject = nullptr;
pAmdExtD3dCreateFunc(m_d3d12Device.Get(),
__uuidof(IAmdExtD3DFactory),
reinterpret_cast<void**>(&pAmdExtObject));
if (nullptr != pAmdExtObject)
{
// use the extension factory object to create a device extension object that contains the marker API
pAmdExtObject->CreateInterface(m_d3d12Device.Get(),
__uuidof(IAmdExtD3DDevice1),
reinterpret_cast<void**>(&m_pAmdExtDeviceObject));
}
}
}
}
}
inline void RgpSetMarker(ID3D12GraphicsCommandList* pCommandList, PCWSTR formatString, ...)
{
if (nullptr != m_pAmdExtDeviceObject)
{
// convert from wchar_t to char string
char formatStringInChar[MAX_MARKER_STRING_LENGTH];
size_t retValue = 0;
wcstombs_s(&retValue, formatStringInChar, MAX_MARKER_STRING_LENGTH, formatString, MAX_MARKER_STRING_LENGTH);
// create a new marker string that includes all the variadic args
char markerString[MAX_MARKER_STRING_LENGTH];
va_list args;
va_start(args, formatString);
vsprintf_s(markerString, formatStringInChar, args);
va_end(args);
// set the rgp marker
m_pAmdExtDeviceObject->SetMarker(pCommandList, markerString);
}
}
inline void RgpPushMarker(ID3D12GraphicsCommandList* pCommandList, PCWSTR formatString, ...)
{
if (nullptr != m_pAmdExtDeviceObject)
{
// convert from wchar_t to char string
char formatStringInChar[MAX_MARKER_STRING_LENGTH];
size_t retValue = 0;
wcstombs_s(&retValue, formatStringInChar, MAX_MARKER_STRING_LENGTH, formatString, MAX_MARKER_STRING_LENGTH);
// create a new marker string that includes all the variadic args
char markerString[MAX_MARKER_STRING_LENGTH];
va_list args;
va_start(args, formatString);
vsprintf_s(markerString, formatStringInChar, args);
va_end(args);
// push the rgp marker
m_pAmdExtDeviceObject->PushMarker(pCommandList, markerString);
}
}
inline void RgpPopMarker(ID3D12GraphicsCommandList* pCommandList)
{
if (nullptr != m_pAmdExtDeviceObject)
{
m_pAmdExtDeviceObject->PopMarker(pCommandList);
}
}
private:
// IDirect3D12Device interface object
ComPtr<ID3D12Device> m_d3d12Device;
// IAmdExtD3DDevice1 interface object
IAmdExtD3DDevice1* m_pAmdExtDeviceObject = nullptr;
} static gs_amdExtD3DDeviceWrapper;
#endif //_AMD_EXT_DEVICE_WRAPPER_H_