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 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446
|
/*
** Copyright (c) 2018-2020 Valve Corporation
** Copyright (c) 2018-2020 LunarG, Inc.
** Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
**
** Permission is hereby granted, free of charge, to any person obtaining a
** copy of this software and associated documentation files (the "Software"),
** to deal in the Software without restriction, including without limitation
** the rights to use, copy, modify, merge, publish, distribute, sublicense,
** and/or sell copies of the Software, and to permit persons to whom the
** Software is furnished to do so, subject to the following conditions:
**
** The above copyright notice and this permission notice shall be included in
** all copies or substantial portions of the Software.
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
** FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
** DEALINGS IN THE SOFTWARE.
*/
#ifndef GFXRECON_DECODE_VULKAN_STAT_CONSUMER_H
#define GFXRECON_DECODE_VULKAN_STAT_CONSUMER_H
#include "decode/custom_vulkan_struct_decoders.h"
#include "decode/api_decoder.h"
#include "generated/generated_vulkan_struct_decoders.h"
#include "generated/generated_vulkan_consumer.h"
#include "util/defines.h"
#include "vulkan/vulkan.h"
#include <set>
#include <unordered_map>
GFXRECON_BEGIN_NAMESPACE(gfxrecon)
GFXRECON_BEGIN_NAMESPACE(decode)
class VulkanStatsConsumer : public gfxrecon::decode::VulkanConsumer, public gfxrecon::decode::AnnotationHandler
{
public:
uint32_t GetTrimmedStartFrame() const { return trimmed_frame_; }
const std::string& GetAppName() const { return app_name_; }
uint32_t GetAppVersion() const { return app_version_; }
const std::string& GetEngineName() const { return engine_name_; }
uint32_t GetEngineVersion() const { return engine_version_; }
uint32_t GetApiVersion() const { return api_version_; }
uint64_t GetGraphicsPipelineCount() const { return graphics_pipelines_; }
uint64_t GetComputePipelineCount() const { return compute_pipelines_; }
uint64_t GetDrawCount() const { return draw_count_; }
uint64_t GetDispatchCount() const { return dispatch_count_; }
uint64_t GetAllocationCount() const { return allocation_count_; }
uint64_t GetMinAllocationSize() const { return min_allocation_size_; }
uint64_t GetMaxAllocationSize() const { return max_allocation_size_; }
uint64_t GetAnnotationCount() const { return annotation_count_; }
const std::vector<std::string>& GetOperationAnnotationDatas() const { return operation_annotation_datas_; }
const std::set<gfxrecon::format::HandleId>& GetInstantiatedDevices() const { return used_physical_devices_; }
const VkPhysicalDeviceProperties* GetDeviceProperties(gfxrecon::format::HandleId id) const
{
auto entry = physical_device_properties_.find(id);
if (entry != physical_device_properties_.end())
{
return &entry->second;
}
return nullptr;
}
virtual void ProcessStateBeginMarker(uint64_t frame_number) override
{
// Theres should only be one of these in a capture file.
trimmed_frame_ = static_cast<uint32_t>(frame_number);
}
/// @brief Count all annotations and save the operation ones which contain data
/// such as build versions from the tools that have processed the file.
virtual void ProcessAnnotation(uint64_t block_index,
gfxrecon::format::AnnotationType type,
const std::string& label,
const std::string& data) override
{
++annotation_count_;
if (type == gfxrecon::format::AnnotationType::kJson &&
label.compare(gfxrecon::format::kAnnotationLabelOperation) == 0)
{
operation_annotation_datas_.push_back(data);
}
}
virtual void Process_vkCreateInstance(
const gfxrecon::decode::ApiCallInfo& call_info,
VkResult returnValue,
gfxrecon::decode::StructPointerDecoder<gfxrecon::decode::Decoded_VkInstanceCreateInfo>* pCreateInfo,
gfxrecon::decode::StructPointerDecoder<gfxrecon::decode::Decoded_VkAllocationCallbacks>*,
gfxrecon::decode::HandlePointerDecoder<VkInstance>*) override
{
if ((pCreateInfo != nullptr) && (returnValue >= 0) && !pCreateInfo->IsNull())
{
auto create_info = pCreateInfo->GetPointer();
auto app_info = create_info->pApplicationInfo;
if (app_info != nullptr)
{
if (app_info->pApplicationName != nullptr)
{
app_name_ = app_info->pApplicationName;
}
if (app_info->pEngineName != nullptr)
{
engine_name_ = app_info->pEngineName;
}
app_version_ = app_info->applicationVersion;
engine_version_ = app_info->engineVersion;
api_version_ = app_info->apiVersion;
}
}
}
virtual void Process_vkGetPhysicalDeviceProperties(
const gfxrecon::decode::ApiCallInfo& call_info,
gfxrecon::format::HandleId physicalDevice,
gfxrecon::decode::StructPointerDecoder<gfxrecon::decode::Decoded_VkPhysicalDeviceProperties>* pProperties)
override
{
if ((pProperties != nullptr) && !pProperties->IsNull())
{
physical_device_properties_[physicalDevice] = *pProperties->GetPointer();
}
}
virtual void Process_vkGetPhysicalDeviceProperties2(
const gfxrecon::decode::ApiCallInfo& call_info,
gfxrecon::format::HandleId physicalDevice,
gfxrecon::decode::StructPointerDecoder<gfxrecon::decode::Decoded_VkPhysicalDeviceProperties2>* pProperties)
override
{
if ((pProperties != nullptr) && !pProperties->IsNull())
{
auto properties2 = pProperties->GetPointer();
physical_device_properties_[physicalDevice] = properties2->properties;
}
}
virtual void Process_vkGetPhysicalDeviceProperties2KHR(
const gfxrecon::decode::ApiCallInfo& call_info,
gfxrecon::format::HandleId physicalDevice,
gfxrecon::decode::StructPointerDecoder<gfxrecon::decode::Decoded_VkPhysicalDeviceProperties2>* pProperties)
override
{
if ((pProperties != nullptr) && !pProperties->IsNull())
{
auto properties2 = pProperties->GetPointer();
physical_device_properties_[physicalDevice] = properties2->properties;
}
}
virtual void
Process_vkCreateDevice(const gfxrecon::decode::ApiCallInfo& call_info,
VkResult returnValue,
gfxrecon::format::HandleId physicalDevice,
gfxrecon::decode::StructPointerDecoder<gfxrecon::decode::Decoded_VkDeviceCreateInfo>*,
gfxrecon::decode::StructPointerDecoder<gfxrecon::decode::Decoded_VkAllocationCallbacks>*,
gfxrecon::decode::HandlePointerDecoder<VkDevice>*) override
{
if (returnValue >= 0)
{
used_physical_devices_.insert(physicalDevice);
}
}
virtual void Process_vkCreateGraphicsPipelines(
const gfxrecon::decode::ApiCallInfo& call_info,
VkResult returnValue,
gfxrecon::format::HandleId,
gfxrecon::format::HandleId,
uint32_t createInfoCount,
gfxrecon::decode::StructPointerDecoder<gfxrecon::decode::Decoded_VkGraphicsPipelineCreateInfo>*,
gfxrecon::decode::StructPointerDecoder<gfxrecon::decode::Decoded_VkAllocationCallbacks>*,
gfxrecon::decode::HandlePointerDecoder<VkPipeline>*) override
{
if (returnValue >= 0)
{
graphics_pipelines_ += createInfoCount;
}
}
virtual void Process_vkCreateComputePipelines(
const gfxrecon::decode::ApiCallInfo& call_info,
VkResult returnValue,
gfxrecon::format::HandleId,
gfxrecon::format::HandleId,
uint32_t createInfoCount,
gfxrecon::decode::StructPointerDecoder<gfxrecon::decode::Decoded_VkComputePipelineCreateInfo>*,
gfxrecon::decode::StructPointerDecoder<gfxrecon::decode::Decoded_VkAllocationCallbacks>*,
gfxrecon::decode::HandlePointerDecoder<VkPipeline>*) override
{
if (returnValue >= 0)
{
compute_pipelines_ += createInfoCount;
}
}
virtual void Process_vkCmdDraw(const gfxrecon::decode::ApiCallInfo& call_info,
gfxrecon::format::HandleId,
uint32_t,
uint32_t,
uint32_t,
uint32_t) override
{
++draw_count_;
}
virtual void Process_vkCmdDrawIndexed(const gfxrecon::decode::ApiCallInfo& call_info,
gfxrecon::format::HandleId,
uint32_t,
uint32_t,
uint32_t,
int32_t,
uint32_t) override
{
++draw_count_;
}
virtual void Process_vkCmdDrawIndirect(const gfxrecon::decode::ApiCallInfo& call_info,
gfxrecon::format::HandleId,
gfxrecon::format::HandleId,
VkDeviceSize,
uint32_t,
uint32_t) override
{
++draw_count_;
}
virtual void Process_vkCmdDrawIndexedIndirect(const gfxrecon::decode::ApiCallInfo& call_info,
gfxrecon::format::HandleId,
gfxrecon::format::HandleId,
VkDeviceSize,
uint32_t,
uint32_t) override
{
++draw_count_;
}
virtual void Process_vkCmdDrawIndirectCountKHR(const gfxrecon::decode::ApiCallInfo& call_info,
gfxrecon::format::HandleId,
gfxrecon::format::HandleId,
VkDeviceSize,
gfxrecon::format::HandleId,
VkDeviceSize,
uint32_t,
uint32_t) override
{
++draw_count_;
}
virtual void Process_vkCmdDrawIndexedIndirectCountKHR(const gfxrecon::decode::ApiCallInfo& call_info,
gfxrecon::format::HandleId,
gfxrecon::format::HandleId,
VkDeviceSize,
gfxrecon::format::HandleId,
VkDeviceSize,
uint32_t,
uint32_t) override
{
++draw_count_;
}
virtual void Process_vkCmdDrawIndirectByteCountEXT(const gfxrecon::decode::ApiCallInfo& call_info,
gfxrecon::format::HandleId,
uint32_t,
uint32_t,
gfxrecon::format::HandleId,
VkDeviceSize,
uint32_t,
uint32_t) override
{
++draw_count_;
}
virtual void Process_vkCmdDrawIndirectCountAMD(const gfxrecon::decode::ApiCallInfo& call_info,
gfxrecon::format::HandleId,
gfxrecon::format::HandleId,
VkDeviceSize,
gfxrecon::format::HandleId,
VkDeviceSize,
uint32_t,
uint32_t) override
{
++draw_count_;
}
virtual void Process_vkCmdDrawIndexedIndirectCountAMD(const gfxrecon::decode::ApiCallInfo& call_info,
gfxrecon::format::HandleId,
gfxrecon::format::HandleId,
VkDeviceSize,
gfxrecon::format::HandleId,
VkDeviceSize,
uint32_t,
uint32_t) override
{
++draw_count_;
}
virtual void Process_vkCmdDrawMeshTasksNV(const gfxrecon::decode::ApiCallInfo& call_info,
gfxrecon::format::HandleId,
uint32_t,
uint32_t) override
{
++draw_count_;
}
virtual void Process_vkCmdDrawMeshTasksIndirectNV(const gfxrecon::decode::ApiCallInfo& call_info,
gfxrecon::format::HandleId,
gfxrecon::format::HandleId,
VkDeviceSize,
uint32_t,
uint32_t) override
{
++draw_count_;
}
virtual void Process_vkCmdDrawMeshTasksIndirectCountNV(const gfxrecon::decode::ApiCallInfo& call_info,
gfxrecon::format::HandleId,
gfxrecon::format::HandleId,
VkDeviceSize,
gfxrecon::format::HandleId,
VkDeviceSize,
uint32_t,
uint32_t) override
{
++draw_count_;
}
virtual void Process_vkCmdDispatch(const gfxrecon::decode::ApiCallInfo& call_info,
gfxrecon::format::HandleId,
uint32_t,
uint32_t,
uint32_t) override
{
++dispatch_count_;
}
virtual void Process_vkCmdDispatchIndirect(const gfxrecon::decode::ApiCallInfo& call_info,
gfxrecon::format::HandleId,
gfxrecon::format::HandleId,
VkDeviceSize) override
{
++dispatch_count_;
}
virtual void Process_vkCmdDispatchBase(const gfxrecon::decode::ApiCallInfo& call_info,
gfxrecon::format::HandleId,
uint32_t,
uint32_t,
uint32_t,
uint32_t,
uint32_t,
uint32_t) override
{
++dispatch_count_;
}
virtual void Process_vkCmdDispatchBaseKHR(const gfxrecon::decode::ApiCallInfo& call_info,
gfxrecon::format::HandleId,
uint32_t,
uint32_t,
uint32_t,
uint32_t,
uint32_t,
uint32_t) override
{
++dispatch_count_;
}
virtual void Process_vkAllocateMemory(
const gfxrecon::decode::ApiCallInfo& call_info,
VkResult returnValue,
gfxrecon::format::HandleId,
gfxrecon::decode::StructPointerDecoder<gfxrecon::decode::Decoded_VkMemoryAllocateInfo>* pAllocateInfo,
gfxrecon::decode::StructPointerDecoder<gfxrecon::decode::Decoded_VkAllocationCallbacks>*,
gfxrecon::decode::HandlePointerDecoder<VkDeviceMemory>*) override
{
assert(pAllocateInfo != nullptr);
if (returnValue >= 0)
{
++allocation_count_;
if (!pAllocateInfo->IsNull())
{
auto allocate_info = pAllocateInfo->GetPointer();
if (allocate_info->allocationSize < min_allocation_size_)
{
min_allocation_size_ = allocate_info->allocationSize;
}
if (allocate_info->allocationSize > max_allocation_size_)
{
max_allocation_size_ = allocate_info->allocationSize;
}
}
}
}
private:
uint32_t trimmed_frame_{ 0 };
// Application info.
std::string app_name_;
uint32_t app_version_{ 0 };
std::string engine_name_;
uint32_t engine_version_{ 0 };
uint32_t api_version_{ 0 };
// Physical device info.
std::set<gfxrecon::format::HandleId> used_physical_devices_;
std::unordered_map<gfxrecon::format::HandleId, VkPhysicalDeviceProperties> physical_device_properties_;
// Total pipeline counts by type.
uint64_t graphics_pipelines_{ 0 };
uint64_t compute_pipelines_{ 0 };
// Total draw/dispatch counts.
uint64_t draw_count_{ 0 };
uint64_t dispatch_count_{ 0 };
// Memory allocation info.
uint64_t allocation_count_{ 0 };
uint64_t min_allocation_size_{ std::numeric_limits<uint64_t>::max() };
uint64_t max_allocation_size_{ 0 };
// Annotation info.
std::vector<std::string> operation_annotation_datas_;
uint64_t annotation_count_{ 0 };
};
GFXRECON_END_NAMESPACE(decode)
GFXRECON_END_NAMESPACE(gfxrecon)
#endif // GFXRECON_DECODE_VULKAN_STAT_CONSUMER_H
|