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
|
/*
* Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
*
* NVIDIA CORPORATION and its licensors retain all intellectual property
* and proprietary rights in and to this software, related documentation
* and any modifications thereto. Any use, reproduction, disclosure or
* distribution of this software and related documentation without an express
* license agreement from NVIDIA CORPORATION is strictly prohibited.
*/
/*
* █████ █████ ██████ ████ ████ ███████ ████ ██████ ██ ██
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
* ██████ ████ ██ ████ █████ ██ ██ ██ ██████ ██ ███████
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
* ██ ██ ██ ██ █████ ██ ██ ██ ██ ██ ██ ██ ██ ██ DEBUGGER
* ██ ██
* ████████████████████████████████████████████████████████ ██ █ ██ ████████████
*
*
* HOW TO USE;
*
* 1) Call, 'GFSDK_Aftermath_DXxx_Initialize', to initialize the library.
* This must be done before any other library calls are made, and the method
* must return 'GFSDK_Aftermath_Result_Success' for initialization to
* be complete.
*
* NOTE: Your application will need to be enabled for Aftermath - if this isn't
* the case, you can rename the executable to; "NvAftermath-Enable.exe"
* to enable Aftermath during development.
*
*
* 2) Call 'GFSDK_Aftermath_DXxx_SetEventMarker', to inject an event
* marker directly into the command stream at that point.
*
*
* 3) Once TDR/hang occurs, call the 'GFSDK_Aftermath_DXxx_GetData' API
* to fetch the event marker last processed by the GPU for each context.
* This API also supports fetching the current execution state for each
* the GPU.
*
*
*
* PERFORMANCE TIP;
*
* o) Try make as few calls to 'GFSDK_Aftermath_DXxx_GetData', as possible. The
* API is flexible enough to allow collection of data from all contexts in one call.
*
*
* Contact: Alex Dunn [[email protected]]
*/
#ifndef GFSDK_Aftermath_H
#define GFSDK_Aftermath_H
#include "defines.h"
enum GFSDK_Aftermath_Version { GFSDK_Aftermath_Version_API = 0x00000121 }; // Version 1.21
enum GFSDK_Aftermath_Result
{
GFSDK_Aftermath_Result_Success = 0x1,
GFSDK_Aftermath_Result_Fail = 0xBAD00000,
// The callee tries to use a library version
// which does not match the built binary.
GFSDK_Aftermath_Result_FAIL_VersionMismatch = GFSDK_Aftermath_Result_Fail | 1,
// The library hasn't been initialized, see;
// 'GFSDK_Aftermath_Initialize'.
GFSDK_Aftermath_Result_FAIL_NotInitialized = GFSDK_Aftermath_Result_Fail | 2,
// The callee tries to use the library with
// a non-supported GPU. Currently, only
// NVIDIA GPUs are supported.
GFSDK_Aftermath_Result_FAIL_InvalidAdapter = GFSDK_Aftermath_Result_Fail | 3,
// The callee passed an invalid parameter to the
// library, likely a null pointer or bad handle.
GFSDK_Aftermath_Result_FAIL_InvalidParameter = GFSDK_Aftermath_Result_Fail | 4,
// Something weird happened that caused the
// library to fail for some reason.
GFSDK_Aftermath_Result_FAIL_Unknown = GFSDK_Aftermath_Result_Fail | 5,
// Got a fail error code from the graphics API.
GFSDK_Aftermath_Result_FAIL_ApiError = GFSDK_Aftermath_Result_Fail | 6,
// Make sure that the NvAPI DLL is up to date.
GFSDK_Aftermath_Result_FAIL_NvApiIncompatible = GFSDK_Aftermath_Result_Fail | 7,
// It would appear as though a call has been
// made to fetch the Aftermath data for a
// context that hasn't been used with
// the EventMarker API yet.
GFSDK_Aftermath_Result_FAIL_GettingContextDataWithNewCommandList = GFSDK_Aftermath_Result_Fail | 8,
// Looks like the library has already been initialized.
GFSDK_Aftermath_Result_FAIL_AlreadyInitialized = GFSDK_Aftermath_Result_Fail | 9,
// Debug layer not compatible with Aftermath.
GFSDK_Aftermath_Result_FAIL_D3DDebugLayerNotCompatible = GFSDK_Aftermath_Result_Fail | 10,
// Aftermath not enabled in the driver. This is
// generally dealt with via application profile,
// but if installed driver version is greater than
// 382.53, this issue can be resolved by renaming
// the application to: "NvAftermath-Enable.exe".
GFSDK_Aftermath_Result_FAIL_NotEnabledInDriver = GFSDK_Aftermath_Result_Fail | 11,
// Aftermath requires driver version r378.66 and beyond
GFSDK_Aftermath_Result_FAIL_DriverVersionNotSupported = GFSDK_Aftermath_Result_Fail | 12,
// The system ran out of memory for allocations
GFSDK_Aftermath_Result_FAIL_OutOfMemory = GFSDK_Aftermath_Result_Fail | 13,
// No need to get data on bundles, as markers
// execute on the command list.
GFSDK_Aftermath_Result_FAIL_GetDataOnBundle = GFSDK_Aftermath_Result_Fail | 14,
// No need to get data on deferred contexts, as markers
// execute on the immediate context.
GFSDK_Aftermath_Result_FAIL_GetDataOnDeferredContext = GFSDK_Aftermath_Result_Fail | 15,
};
#define GFSDK_Aftermath_SUCCEED(value) (((value) & 0xFFF00000) != GFSDK_Aftermath_Result_Fail)
enum GFSDK_Aftermath_Context_Status
{
// GPU:
// The GPU has not started processing this command list yet.
GFSDK_Aftermath_Context_Status_NotStarted = 0,
// This command list has begun execution on the GPU.Thi
GFSDK_Aftermath_Context_Status_Executing,
// This command list has finished execution on the GPU.
GFSDK_Aftermath_Context_Status_Finished,
// This context has an invalid state, which could be
// caused by an error.
//
// NOTE: See, 'GFSDK_Aftermath_ContextData::getErrorCode()'
// for more information.
GFSDK_Aftermath_Context_Status_Invalid,
};
enum GFSDK_Aftermath_Status
{
// The GPU is still active, and hasn't gone down.
GFSDK_Aftermath_Status_Active = 0,
// A long running shader/operation has caused a
// GPU timeout. Reconfiguring the timeout length
// might help tease out the problem.
GFSDK_Aftermath_Status_Timeout,
// Run out of memory to complete operations.
GFSDK_Aftermath_Status_OutOfMemory,
// An invalid VA access has caused a fault.
GFSDK_Aftermath_Status_PageFault,
// Unknown problem - likely using an older driver
// incompatible with this Aftermath feature.
GFSDK_Aftermath_Status_Unknown,
};
// Used with, 'GFSDK_Aftermath_DXxx_GetData'. Filled with information,
// about each requested context.
extern "C" {
struct GFSDK_Aftermath_DLLSPEC GFSDK_Aftermath_ContextData
{
void* markerData;
unsigned int markerSize;
GFSDK_Aftermath_Context_Status status;
// Call this when 'status' is 'GFSDK_Aftermath_Context_Status_Invalid;
// to determine what the error failure reason is.
GFSDK_Aftermath_Result getErrorCode();
};
}
/////////////////////////////////////////////////////////////////////////
// GFSDK_Aftermath_DX11_Initialize
// GFSDK_Aftermath_DX12_Initialize
// ---------------------------------
//
// [pDx11Device]; DX11-Only
// the current dx11 device pointer.
//
// [pDx12Device]; DX12-Only
// the current dx12 device pointer.
//
// version;
// use the version supplied in this header - library will match
// that with what it believes to be the version internally.
//
//// DESCRIPTION;
// Library must be initialized before any other call is made.
// This should be done after device creation.
//
/////////////////////////////////////////////////////////////////////////
#ifdef __d3d11_h__
GFSDK_Aftermath_API GFSDK_Aftermath_DX11_Initialize(GFSDK_Aftermath_Version version, ID3D11Device* const pDx11Device);
#endif
#ifdef __d3d12_h__
GFSDK_Aftermath_API GFSDK_Aftermath_DX12_Initialize(GFSDK_Aftermath_Version version, ID3D12Device* const pDx12Device);
#endif
/////////////////////////////////////////////////////////////////////////
// GFSDK_Aftermath_Dx11_SetEventMarker
// GFSDK_Aftermath_Dx12_SetEventMarker
// -------------------------------------
//
// (pDx11DeviceContext); DX11-Only
// Command list currently being populated.
//
// (pDx12CommandList); DX12-Only
// Command list currently being populated.
//
// markerData;
// Pointer to data used for event marker.
// NOTE: An internal copy will be made of this data, no
// need to keep it around after this call - stack alloc is safe.
//
// markerSize;
// Size of event in bytes.
// NOTE: Passing a 0 for this parameter is valid, and will
// only copy off the ptr supplied by markerData, rather
// than internally making a copy.
// NOTE: This is a requirement for deferred contexts on D3D11.
//
// DESCRIPTION;
// Drops a event into the command stream with a payload that can be
// linked back to the data given here, 'markerData'. It's
// safe to call from multiple threads simultaneously, normal D3D
// API threading restrictions apply.
//
/////////////////////////////////////////////////////////////////////////
#ifdef __d3d11_h__
GFSDK_Aftermath_API GFSDK_Aftermath_DX11_SetEventMarker(ID3D11DeviceContext* const pDx11DeviceContext, void* markerData, unsigned int markerSize);
#endif
#ifdef __d3d12_h__
GFSDK_Aftermath_API GFSDK_Aftermath_DX12_SetEventMarker(ID3D12GraphicsCommandList* const pDx12CommandList, void* markerData, unsigned int markerSize);
#endif
/////////////////////////////////////////////////////////////////////////
// GFSDK_Aftermath_DX11_GetData
// GFSDK_Aftermath_DX12_GetData
// ------------------------------
//
// numContexts;
// Number of contexts to fetch information for.
// NOTE: Passing a 0 for this parameter will only
// return the GPU status in pStatusOut.
//
// (ppDx11DeviceContexts); DX11-Only
// Array of pointers to ID3D11DeviceContexts containing Aftermath
// event markers.
//
// (ppDx12CommandLists); DX12-Only
// Array of pointers to ID3D12GraphicsCommandList containing Aftermath
// event markers.
//
// pContextDataOut;
// OUTPUT: context data for each context requested. Contains event
// last reached on the GPU, and status of context if
// applicable (DX12-Only).
// NOTE: must allocate enough space for 'numContexts' worth of structures.
// stack allocation is fine.
//
// pStatusOut;
// OUTPUT: the current status of the GPU.
//
// DESCRIPTION;
// Once a TDR/crash/hang has occurred (or whenever you like), call
// this API to retrieve the event last processed by the GPU on the
// given context. Also - fetch the GPUs current execution status.
//
// NOTE: Passing a 0 for numContexts will only return the GPU
// status in pStatusOut and skip fetching the current value
// for each context. You will still need to pass something
// via ppDx11DeviceContexts or ppDx12CommandLists though...
//
/////////////////////////////////////////////////////////////////////////
#ifdef __d3d11_h__
GFSDK_Aftermath_API GFSDK_Aftermath_DX11_GetData(const unsigned int numContexts, ID3D11DeviceContext* const* ppDx11DeviceContexts, GFSDK_Aftermath_ContextData* pContextDataOut, GFSDK_Aftermath_Status* pStatusOut);
#endif
#ifdef __d3d12_h__
GFSDK_Aftermath_API GFSDK_Aftermath_DX12_GetData(const unsigned int numContexts, ID3D12GraphicsCommandList* const* ppDx12CommandLists, GFSDK_Aftermath_ContextData* pContextDataOut, GFSDK_Aftermath_Status* pStatusOut);
#endif
/////////////////////////////////////////////////////////////////////////
//
// NOTE: Function table provided - if dynamic loading is preferred.
//
/////////////////////////////////////////////////////////////////////////
#ifdef __d3d11_h__
GFSDK_Aftermath_PFN(*PFN_GFSDK_Aftermath_DX11_Initialize)(GFSDK_Aftermath_Version version, ID3D11Device* const pDx11Device);
GFSDK_Aftermath_PFN(*PFN_GFSDK_Aftermath_DX11_SetEventMarker)(ID3D11DeviceContext* const pDx11DeviceContext, void* markerData, unsigned int markerSize);
GFSDK_Aftermath_PFN(*PFN_GFSDK_Aftermath_DX11_GetData)(const unsigned int numContexts, ID3D11DeviceContext* const* ppDx11DeviceContexts, GFSDK_Aftermath_ContextData* pContextDataOut, GFSDK_Aftermath_Status* pStatusOut);
#endif
#ifdef __d3d12_h__
GFSDK_Aftermath_PFN(*PFN_GFSDK_Aftermath_DX12_Initialize)(GFSDK_Aftermath_Version version, ID3D12Device* const pDx12Device);
GFSDK_Aftermath_PFN(*PFN_GFSDK_Aftermath_DX12_SetEventMarker)(ID3D12GraphicsCommandList* const pDx12CommandList, void* markerData, unsigned int markerSize);
GFSDK_Aftermath_PFN(*PFN_GFSDK_Aftermath_DX12_GetData)(const unsigned int numContexts, ID3D12GraphicsCommandList* const* ppDx12CommandLists, GFSDK_Aftermath_ContextData* pContextDataOut, GFSDK_Aftermath_Status* pStatusOut);
#endif
#endif // GFSDK_Aftermath_H
|