2
3
4
5
6
22 bool ShaderDataBase::ReadFile(
const char* filename, std::vector<uint8_t>& data)
26 std::ifstream fs(filename, std::ios::in | std::ios::binary);
32 fs.seekg(0, std::ios::end);
33 data.resize(fs.tellg());
34 fs.seekg(0, std::ios::beg);
35 fs.read(
reinterpret_cast<
char*>(data.data()), data.size());
46
47
48 std::vector<uint8_t> data;
49 if (!ReadFile(shaderFilePath, data))
55
56
57 const GFSDK_Aftermath_SpirvCode shader{ data.data(), uint32_t(data.size()) };
58 GFSDK_Aftermath_ShaderBinaryHash shaderHash;
60 GFSDK_Aftermath_Version_API ,
66
67
68
69 m_ShaderBinaries[shaderHash].swap(data);
77
78
79 const GFSDK_Aftermath_SpirvCode shader{ spirv.data(),
static_cast<uint32_t>(spirv.size()) };
80 GFSDK_Aftermath_ShaderBinaryHash shaderHash;
82 GFSDK_Aftermath_Version_API ,
88
89
90
91 m_ShaderBinaries[shaderHash].swap(spirv);
99
100
101 std::vector<uint8_t> data;
102 if (!ReadFile(shaderFilePath, data))
106 std::vector<uint8_t> strippedData;
107 if (!ReadFile(strippedShaderFilePath, strippedData))
113
114
115 GFSDK_Aftermath_ShaderDebugName debugName;
116 const GFSDK_Aftermath_SpirvCode shader{ data.data(),
static_cast<uint32_t>(data.size()) };
117 const GFSDK_Aftermath_SpirvCode strippedShader{ strippedData.data(),
static_cast<uint32_t>(strippedData.size()) };
119 GFSDK_Aftermath_Version_API ,
126
127
128
129 m_ShaderBinariesWithDebugInfo[debugName].swap(data);
137
138
139 GFSDK_Aftermath_ShaderDebugName debugName;
140 const GFSDK_Aftermath_SpirvCode shader{ spirv.data(),
static_cast<uint32_t>(spirv.size()) };
141 const GFSDK_Aftermath_SpirvCode strippedShader{ strippedSpirv.data(),
static_cast<uint32_t>(strippedSpirv.size()) };
143 GFSDK_Aftermath_Version_API ,
150
151
152
153 m_ShaderBinariesWithDebugInfo[debugName].swap(spirv);
161
162
163 const auto i_shader = m_ShaderBinaries.find(shaderHash);
164 if (i_shader == m_ShaderBinaries.end())
167
168
172 shader = i_shader->second;
181
182
183 const auto i_shader = m_ShaderBinariesWithDebugInfo.find(shaderDebugName);
184 if (i_shader == m_ShaderBinariesWithDebugInfo.end())
187
188
192 shader = i_shader->second;
#define AFTERMATH_CHECK_ERROR(FC)
Helper macro for checking Nsight Aftermath results and throwing exception in case of a failure.
#define SPICES_PROFILE_ZONE
void AddShaderSource(std::vector< uint8_t > spirv)
Add a shader source to m_ShaderBinaries.
ShaderDataBase()
Constructor Function.
bool FindShaderBinaryWithDebugData(const GFSDK_Aftermath_ShaderDebugName &shaderDebugName, std::vector< uint8_t > &shader) const
Find a source shader debug info by shader debug name generated by the DXC compiler.
void AddShaderBinary(const char *shaderFilePath)
Add a shader binary to m_ShaderBinaries.
void AddShaderBinaryWithDebugInfo(const char *strippedShaderFilePath, const char *shaderFilePath)
Add a shader binary with debug info to m_ShaderBinariesWithDebugInfo.
bool FindShaderBinary(const GFSDK_Aftermath_ShaderBinaryHash &shaderHash, std::vector< uint8_t > &shader) const
Find a shader bytecode binary by shader hash.
void AddShaderSourceWithDebugInfo(std::vector< uint8_t > strippedSpirv, std::vector< uint8_t > spirv)
Add a shader Source with debug info to m_ShaderBinariesWithDebugInfo.
Implements a very simple shader database to help demonstrate how to use the Nsight Aftermath GPU cras...