forked from GPUOpen-Tools/gpu_performance_api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GPACounterGeneratorDX12Base.cpp
325 lines (293 loc) · 10.1 KB
/
GPACounterGeneratorDX12Base.cpp
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
//==============================================================================
// Copyright (c) 2017-2018 Advanced Micro Devices, Inc. All rights reserved.
/// \author AMD Developer Tools Team
/// \file
/// \brief Common DX12 counter generation
//==============================================================================
#include <d3d12.h>
#include "GPACounterGeneratorDX12Base.h"
#include "GPACounterGeneratorSchedulerManager.h"
#include "GPACommonDefs.h"
const GPA_SoftwareCounterDesc GPA_CounterGeneratorDX12Base::s_dx12SWCounters[] =
{
{
// D3D12_QUERY_TYPE_TIMESTAMP
D3D12_QUERY_TYPE_TIMESTAMP,
"D3DGPUTime",
"D3D12",
"Time spent in GPU",
GPA_DATA_TYPE_FLOAT64,
},
{
// D3D12_QUERY_TYPE_TIMESTAMP
D3D12_QUERY_TYPE_TIMESTAMP,
"PreBottomTimestamp",
"D3D12",
"Bottom of the pipeline GPU timestamp",
GPA_DATA_TYPE_UINT64,
},
{
// D3D12_QUERY_TYPE_TIMESTAMP
D3D12_QUERY_TYPE_TIMESTAMP,
"PostBottomTimestamp",
"D3D12",
"Bottom of the pipeline GPU timestamp",
GPA_DATA_TYPE_UINT64,
},
{
// D3D12_QUERY_TYPE_OCCLUSION
D3D12_QUERY_TYPE_OCCLUSION,
"Occlusion",
"D3D12",
"Get the number of samples that passed the depth and stencil tests.",
GPA_DATA_TYPE_UINT64,
},
{
// D3D12_QUERY_TYPE_BINARY_OCCLUSION
D3D12_QUERY_TYPE_BINARY_OCCLUSION,
"BinaryOcclusion",
"D3D12",
"True/false if any samples passed depth and stencil tests.",
GPA_DATA_TYPE_UINT64,
},
{
// D3D12_QUERY_TYPE_PIPELINE_STATISTICS IAVertices
D3D12_QUERY_TYPE_PIPELINE_STATISTICS,
"IAVertices",
"D3D12",
"Number of vertices read by input assembler.",
GPA_DATA_TYPE_UINT64,
},
{
// D3D12_QUERY_TYPE_PIPELINE_STATISTICS IAPrimitives
D3D12_QUERY_TYPE_PIPELINE_STATISTICS,
"IAPrimitives",
"D3D12",
"Number of primitives read by the input assembler.",
GPA_DATA_TYPE_UINT64,
},
{
// D3D12_QUERY_TYPE_PIPELINE_STATISTICS VSInvocations
D3D12_QUERY_TYPE_PIPELINE_STATISTICS,
"VSInvocations",
"D3D12",
"Number of times a vertex shader was invoked.",
GPA_DATA_TYPE_UINT64,
},
{
// D3D12_QUERY_TYPE_PIPELINE_STATISTICS GSPrimitives
D3D12_QUERY_TYPE_PIPELINE_STATISTICS,
"GSInvocations",
"D3D12",
"Number of times a geometry shader was invoked.",
GPA_DATA_TYPE_UINT64,
},
{
// D3D12_QUERY_TYPE_PIPELINE_STATISTICS GSPrimitives
D3D12_QUERY_TYPE_PIPELINE_STATISTICS,
"GSPrimitives",
"D3D12",
"Number of primitives output by a geometry shader.",
GPA_DATA_TYPE_UINT64,
},
{
// D3D12_QUERY_TYPE_PIPELINE_STATISTICS CInvocations
D3D12_QUERY_TYPE_PIPELINE_STATISTICS,
"CInvocations",
"D3D12",
"Number of primitives that were sent to the rasterizer.",
GPA_DATA_TYPE_UINT64,
},
{
// D3D12_QUERY_TYPE_PIPELINE_STATISTICS CPrimitives
D3D12_QUERY_TYPE_PIPELINE_STATISTICS,
"CPrimitives",
"D3D12",
"Number of primitives that were rendered.",
GPA_DATA_TYPE_UINT64,
},
{
// D3D12_QUERY_TYPE_PIPELINE_STATISTICS PSInvocations
D3D12_QUERY_TYPE_PIPELINE_STATISTICS,
"PSInvocations",
"D3D12",
"Number of times a pixel shader was invoked.",
GPA_DATA_TYPE_UINT64,
},
{
// D3D12_QUERY_TYPE_PIPELINE_STATISTICS HSInvocations
D3D12_QUERY_TYPE_PIPELINE_STATISTICS,
"HSInvocations",
"D3D12",
"Number of times a hull shader was invoked.",
GPA_DATA_TYPE_UINT64,
},
{
// D3D12_QUERY_TYPE_PIPELINE_STATISTICS DSInvocations
D3D12_QUERY_TYPE_PIPELINE_STATISTICS,
"DSInvocations",
"D3D12",
"Number of times a domain shader was invoked.",
GPA_DATA_TYPE_UINT64,
},
{
// D3D12_QUERY_TYPE_PIPELINE_STATISTICS CSInvocations
D3D12_QUERY_TYPE_PIPELINE_STATISTICS,
"CSInvocations",
"D3D12",
"Number of times a compute shader was invoked.",
GPA_DATA_TYPE_UINT64,
},
};
const size_t GPA_CounterGeneratorDX12Base::s_dx12SWCountersCount =
(sizeof(s_dx12SWCounters) / sizeof(GPA_SoftwareCounterDesc));
bool GPA_CounterGeneratorDX12Base::GetSwCounterDesc(
const gpa_uint32 swCounterIndex, GPA_SoftwareCounterDesc& swCounterDesc)
{
bool result = (s_dx12SWCountersCount >= swCounterIndex);
if (result)
{
swCounterDesc = s_dx12SWCounters[swCounterIndex];
}
return result;
}
GPA_Status GPA_CounterGeneratorDX12Base::GeneratePublicCounters(
GDT_HW_GENERATION desiredGeneration,
GDT_HW_ASIC_TYPE asicType,
gpa_uint8 generateAsicSpecificCounters,
GPA_PublicCounters* pPublicCounters)
{
UNREFERENCED_PARAMETER(desiredGeneration);
UNREFERENCED_PARAMETER(asicType);
UNREFERENCED_PARAMETER(generateAsicSpecificCounters);
UNREFERENCED_PARAMETER(pPublicCounters);
return GPA_STATUS_OK;
}
GPA_Status GPA_CounterGeneratorDX12Base::GenerateHardwareCounters(
GDT_HW_GENERATION desiredGeneration,
GDT_HW_ASIC_TYPE asicType,
gpa_uint8 generateAsicSpecificCounters,
GPA_HardwareCounters* pHardwareCounters)
{
UNREFERENCED_PARAMETER(desiredGeneration);
UNREFERENCED_PARAMETER(asicType);
UNREFERENCED_PARAMETER(generateAsicSpecificCounters);
UNREFERENCED_PARAMETER(pHardwareCounters);
return GPA_STATUS_OK;
}
GPA_Status GPA_CounterGeneratorDX12Base::GenerateSoftwareCounters(
GDT_HW_GENERATION desiredGeneration,
GDT_HW_ASIC_TYPE asicType,
gpa_uint8 generateAsicSpecificCounters,
GPA_SoftwareCounters* pSoftwareCounters)
{
UNREFERENCED_PARAMETER(asicType);
UNREFERENCED_PARAMETER(generateAsicSpecificCounters);
GPA_Status status = GPA_STATUS_OK;
if (pSoftwareCounters->m_countersGenerated)
{
return status;
}
if (nullptr == pSoftwareCounters)
{
status = GPA_STATUS_ERROR_NULL_POINTER;
}
else
{
switch (desiredGeneration)
{
case GDT_HW_GENERATION_SOUTHERNISLAND:
case GDT_HW_GENERATION_SEAISLAND:
case GDT_HW_GENERATION_VOLCANICISLAND:
case GDT_HW_GENERATION_GFX9:
case GDT_HW_GENERATION_INTEL:
case GDT_HW_GENERATION_NVIDIA:
break;
default:
status = GPA_STATUS_ERROR_HARDWARE_NOT_SUPPORTED;
break;
}
if (GPA_STATUS_OK == status)
{
status = GenerateDX12SoftwareCounters();
if (GPA_STATUS_OK == status)
{
const size_t dx12SwCounterCount = SwCounterManager::Instance()->GetNumSwCounters();
const SwCounterDescVec* pDX12SoftwareCounters = SwCounterManager::Instance()->GetSwCounters();
pSoftwareCounters->m_counters.resize(dx12SwCounterCount);
for (size_t ci = 0 ; dx12SwCounterCount > ci ; ++ci)
{
(pSoftwareCounters->m_counters)[ci].m_groupIndex = 0;
(pSoftwareCounters->m_counters)[ci].m_groupIdDriver = static_cast<gpa_uint32>(ci);
(pSoftwareCounters->m_counters)[ci].m_counterIdDriver =
static_cast<gpa_uint32>((*pDX12SoftwareCounters)[ci].m_counterIndexInGroup);
(pSoftwareCounters->m_counters)[ci].m_pSoftwareCounter =
const_cast<GPA_SoftwareCounterDesc*>(&((*pDX12SoftwareCounters)[ci]));
}
}
}
}
pSoftwareCounters->m_countersGenerated = true;
return status;
}
void GPA_CounterGeneratorDX12Base::ComputeSWCounterValue(
gpa_uint32 counterIndex, gpa_uint64 value, void* pResult, const GPA_HWInfo* pHwInfo) const
{
const SwCounterDescVec* pSwCounters = SwCounterManager::Instance()->GetSwCounters();
if (counterIndex < static_cast<gpa_uint32>(pSwCounters->size()))
{
const std::string d3dGPUTime = "D3DGPUTime";
const std::string preTimeStamp = "PreBottomTimestamp";
const std::string postTimeStamp = "PostBottomTimestamp";
const std::string counterName = pSwCounters->at(counterIndex).m_name;
if (counterName == d3dGPUTime)
{
gpa_uint64 freq = 1u;
GPA_ASSERT(pHwInfo->GetTimeStampFrequency(freq));
gpa_float64* pBuf = static_cast<gpa_float64*>(pResult);
*pBuf = static_cast<gpa_float64>(value) / static_cast<gpa_float64>(freq) * 1000.0;
}
else if (counterName == preTimeStamp || counterName == postTimeStamp)
{
gpa_uint64 freq = 1u;
GPA_ASSERT(pHwInfo->GetTimeStampFrequency(freq));
gpa_float64* pBuf = static_cast<gpa_float64*>(pResult);
*pBuf = static_cast<gpa_float64>(value * 1000.0) / freq;
}
else // other SW DX counters
{
GPA_Data_Type type = (*pSwCounters)[counterIndex].m_type;
if (GPA_DATA_TYPE_UINT64 == type)
{
gpa_uint64* pBuf = static_cast<gpa_uint64*>(pResult);
*pBuf = static_cast<gpa_uint64>(value);
}
else if (GPA_DATA_TYPE_FLOAT64 == type)
{
memcpy(pResult, &value, sizeof(gpa_float64));
}
else
{
GPA_LogError("Unexpected software counter type.");
}
}
}
}
GPA_Status GPA_CounterGeneratorDX12Base::GenerateDX12SoftwareCounters() const
{
GPA_Status result = GPA_STATUS_OK;
SwCounterManager::Instance()->SetNumAmdCounters(GetNumAMDCounters());
if (!SwCounterManager::Instance()->SwCountersGenerated())
{
for (size_t ci = 0; s_dx12SWCountersCount > ci; ++ci)
{
SwCounterManager::Instance()->AddSwCounter(s_dx12SWCounters[ci]);
}
if (0 == SwCounterManager::Instance()->GetNumSwCounters())
{
result = GPA_STATUS_ERROR_FAILED;
}
SwCounterManager::Instance()->SetSwCountersGenerated(true);
}
return result;
}