-
Notifications
You must be signed in to change notification settings - Fork 3
/
AmdPix3.h
166 lines (137 loc) · 6.06 KB
/
AmdPix3.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//==============================================================================
// Copyright (c) 2017 Advanced Micro Devices, Inc. All rights reserved.
/// \author AMD Developer Tools Team
/// \file
/// \brief This file contains the implementation of three macro redefinitions
/// from pix3_win.h with AMD RGP marker support.
/// This requires AMD driver with a device level marker extension support
/// (driver 17.30.1081 or newer).
/// To use: Update the pix3.h file to replace #include "pix3_win.h" by
/// including this file instead. Also check the RGP
/// user documentation for a complete user guide.
/// \warning Only support the unicode character set (does not support multi-byte)
//==============================================================================
#ifndef _AMD_PIX3_H_
#define _AMD_PIX3_H_
// include original Microsoft PIX3 header file
#include "../pix3_win.h"
#include <stdio.h>
#include <stdarg.h>
#include "AmdExtD3D.h"
#include "AmdExtD3DDeviceApi.h"
// undefine three macro definitions from pix3_win.h to be redefined with AMD RGP marker support
#undef PIXSetCPUMarkerOnContext
#undef PIXBeginCPUEventOnContext
#undef PIXEndCPUEventOnContext
#define MAX_MARKER_STRING_LENGTH 1024
// per thread amd ext device object using TLS
static __declspec(thread) IAmdExtD3DDevice1* tls_pAmdExtDeviceObject = nullptr;
// this function will initialize the tls_pAmdExtDeviceObject per thread
// tls_pAmdExtDeviceObject contains the marker API
inline void InitializeAmdExtDeviceObject(ID3D12GraphicsCommandList* pCommandList)
{
// return immediately if the device extension object has been created for the thread
if (nullptr != tls_pAmdExtDeviceObject)
{
return;
}
HMODULE hpAmdD3dDl2 = LoadLibrary(L"amdxc64.dll");
if (nullptr != hpAmdD3dDl2)
{
PFNAmdExtD3DCreateInterface pAmdExtD3dCreateFunc = (PFNAmdExtD3DCreateInterface) GetProcAddress(hpAmdD3dDl2,
"AmdExtD3DCreateInterface");
if (nullptr != pAmdExtD3dCreateFunc)
{
ID3D12Device* pDevice = nullptr;
if (nullptr != pCommandList)
{
pCommandList->GetDevice(__uuidof(ID3D12Device),
reinterpret_cast<void**>(&pDevice));
}
if (nullptr != pDevice)
{
// create the extension object factory
IAmdExtD3DFactory* pAmdExtObject = nullptr;
pAmdExtD3dCreateFunc(pDevice,
__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(pDevice,
__uuidof(IAmdExtD3DDevice1),
reinterpret_cast<void**>(&tls_pAmdExtDeviceObject));
}
}
}
}
}
inline void RgpSetMarker(ID3D12GraphicsCommandList* pCommandList, PCWSTR formatString, ...)
{
InitializeAmdExtDeviceObject(pCommandList);
if (nullptr != tls_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
tls_pAmdExtDeviceObject->SetMarker(pCommandList, markerString);
}
}
inline void RgpPushMarker(ID3D12GraphicsCommandList* pCommandList, PCWSTR formatString, ...)
{
InitializeAmdExtDeviceObject(pCommandList);
if (nullptr != tls_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
tls_pAmdExtDeviceObject->PushMarker(pCommandList, markerString);
}
}
inline void RgpPopMarker(ID3D12GraphicsCommandList* pCommandList)
{
InitializeAmdExtDeviceObject(pCommandList);
if (nullptr != tls_pAmdExtDeviceObject)
{
tls_pAmdExtDeviceObject->PopMarker(pCommandList);
}
}
inline void RgpSetMarker(ID3D12CommandQueue*, PCWSTR, ...)
{
// there is no queue-based marker yet
}
inline void RgpPushMarker(ID3D12CommandQueue*, PCWSTR, ...)
{
// there is no queue-based marker yet
}
inline void RgpPopMarker(ID3D12CommandQueue*)
{
// there is no queue-based marker yet
}
// redefine the three macros from pix_win3.h
#define PIXSetCPUMarkerOnContext(context, metadata, formatString, ...) \
RgpSetMarker(context, formatString, __VA_ARGS__); \
MakeCPUSetMarkerForContext(metadata, context, formatString, __VA_ARGS__)
#define PIXBeginCPUEventOnContext(context, metadata, formatString, ...) \
RgpPushMarker(context, formatString, __VA_ARGS__); \
MakeCPUBeginEventForContext(metadata, context, formatString, __VA_ARGS__)
#define PIXEndCPUEventOnContext(context) \
RgpPopMarker(context); \
MakeCPUEndEventForContext(context)
#endif //_AMD_PIX3_H_