Grindstone Game Engine
v0.2.0
An open source game engine and toolkit.
Toggle main menu visibility
Loading...
Searching...
No Matches
NsightAftermathHelpers.h
1
//*********************************************************
2
//
3
// Copyright (c) 2019-2022, NVIDIA CORPORATION. All rights reserved.
4
//
5
// Permission is hereby granted, free of charge, to any person obtaining a
6
// copy of this software and associated documentation files (the "Software"),
7
// to deal in the Software without restriction, including without limitation
8
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
// and/or sell copies of the Software, and to permit persons to whom the
10
// Software is furnished to do so, subject to the following conditions:
11
//
12
// The above copyright notice and this permission notice shall be included in
13
// all copies or substantial portions of the Software.
14
//
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
// DEALINGS IN THE SOFTWARE.
22
//
23
//*********************************************************
24
25
#pragma once
26
27
#include <iomanip>
28
#include <string>
29
#include <sstream>
30
31
#include <vulkan/vulkan.hpp>
32
#include <GFSDK_Aftermath.h>
33
#include <GFSDK_Aftermath_GpuCrashDump.h>
34
#include <GFSDK_Aftermath_GpuCrashDumpDecoding.h>
35
36
//*********************************************************
37
// Some std::to_string overloads for some Nsight Aftermath
38
// API types.
39
//
40
41
namespace
std
42
{
43
template
<
typename
T>
44
inline
std::string to_hex_string(T n)
45
{
46
std::stringstream stream;
47
stream << std::setfill(
'0'
) << std::setw(2 *
sizeof
(T)) << std::hex << n;
48
return
stream.str();
49
}
50
51
inline
std::string to_string(GFSDK_Aftermath_Result result)
52
{
53
return
std::string(
"0x"
) + to_hex_string(
static_cast<
uint32_t
>
(result));
54
}
55
56
inline
std::string to_string(
const
GFSDK_Aftermath_ShaderDebugInfoIdentifier& identifier)
57
{
58
return
to_hex_string(identifier.id[0]) +
"-"
+ to_hex_string(identifier.id[1]);
59
}
60
61
inline
std::string to_string(
const
GFSDK_Aftermath_ShaderBinaryHash& hash)
62
{
63
return
to_hex_string(hash.hash);
64
}
65
}
// namespace std
66
67
//*********************************************************
68
// Helper for comparing shader hashes and debug info identifier.
69
//
70
71
// Helper for comparing GFSDK_Aftermath_ShaderDebugInfoIdentifier.
72
inline
bool
operator<(
const
GFSDK_Aftermath_ShaderDebugInfoIdentifier& lhs,
const
GFSDK_Aftermath_ShaderDebugInfoIdentifier& rhs)
73
{
74
if
(lhs.id[0] == rhs.id[0])
75
{
76
return
lhs.id[1] < rhs.id[1];
77
}
78
return
lhs.id[0] < rhs.id[0];
79
}
80
81
// Helper for comparing GFSDK_Aftermath_ShaderBinaryHash.
82
inline
bool
operator<(
const
GFSDK_Aftermath_ShaderBinaryHash& lhs,
const
GFSDK_Aftermath_ShaderBinaryHash& rhs)
83
{
84
return
lhs.hash < rhs.hash;
85
}
86
87
// Helper for comparing GFSDK_Aftermath_ShaderDebugName.
88
inline
bool
operator<(
const
GFSDK_Aftermath_ShaderDebugName& lhs,
const
GFSDK_Aftermath_ShaderDebugName& rhs)
89
{
90
return
strncmp(lhs.name, rhs.name,
sizeof
(lhs.name)) < 0;
91
}
92
93
//*********************************************************
94
// Helper for checking Nsight Aftermath failures.
95
//
96
97
inline
std::string AftermathErrorMessage(GFSDK_Aftermath_Result result)
98
{
99
switch
(result)
100
{
101
case
GFSDK_Aftermath_Result_FAIL_DriverVersionNotSupported:
102
return
"Unsupported driver version - requires an NVIDIA R495 display driver or newer."
;
103
default
:
104
return
"Aftermath Error 0x"
+ std::to_hex_string(result);
105
}
106
}
107
108
// Helper macro for checking Nsight Aftermath results and throwing exception
109
// in case of a failure.
110
#ifdef _WIN32
111
#define AFTERMATH_CHECK_ERROR(FC) \
112
[&]() { \
113
GFSDK_Aftermath_Result _result = FC; \
114
if (!GFSDK_Aftermath_SUCCEED(_result)) \
115
{ \
116
MessageBoxA(0, AftermathErrorMessage(_result).c_str(), "Aftermath Error", MB_OK); \
117
exit(1); \
118
} \
119
}()
120
#else
121
#define AFTERMATH_CHECK_ERROR(FC) \
122
[&]() { \
123
GFSDK_Aftermath_Result _result = FC; \
124
if (!GFSDK_Aftermath_SUCCEED(_result)) \
125
{ \
126
printf("%s\n", AftermathErrorMessage(_result).c_str()); \
127
fflush(stdout); \
128
exit(1); \
129
} \
130
}()
131
#endif
std
Definition
DescriptorSetLayout.hpp:65
plugins
Grindstone.RHI.Vulkan
include
GpuCrashTracker
NsightAftermathHelpers.h
Generated by
1.17.0