Skip to content

Commit

Permalink
Merge pull request #26 from Devaniti/refactor-output
Browse files Browse the repository at this point in the history
Refactored output
  • Loading branch information
sawickiap authored Feb 27, 2025
2 parents d908342 + 3a67fcb commit 8774e90
Show file tree
Hide file tree
Showing 24 changed files with 2,108 additions and 1,648 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "Src/ThirdParty/gpudetect"]
path = Src/ThirdParty/gpudetect
url = https://github.com/GameTechDev/gpudetect.git
[submodule "Src/ThirdParty/rapidjson"]
path = Src/ThirdParty/rapidjson
url = https://github.com/Tencent/rapidjson.git
[submodule "Src/ThirdParty/nvapi"]
path = Src/ThirdParty/nvapi
url = https://github.com/NVIDIA/nvapi.git
Expand Down
44 changes: 34 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,40 @@ cmake_minimum_required(VERSION 3.17)

project(D3d12info LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
file(GLOB CPP_FILES "Src/*.cpp")
file(GLOB HPP_FILES "Src/*.hpp")
set(RAPIDJSON_NATVIS_FILE "Src/ThirdParty/rapidjson/contrib/natvis/rapidjson.natvis")
set(INTEL_GPUDETECT_CFG_FILE "Src/ThirdParty/gpudetect/IntelGfx.cfg")
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CPP_FILES
Src/AgsData.cpp
Src/AmdDeviceInfoData.cpp
Src/IntelData.cpp
Src/Main.cpp
Src/NvApiData.cpp
Src/Printer.cpp
Src/Resources.rc
Src/Utils.cpp
Src/VulkanData.cpp
Src/ReportFormatter/TextReportFormatter.cpp
Src/ReportFormatter/JSONReportFormatter.cpp
Src/ReportFormatter/ReportFormatter.cpp
)

set(HPP_FILES
Src/AgsData.hpp
Src/AmdDeviceInfoData.hpp
Src/Enums.hpp
Src/IntelData.hpp
Src/NvApiData.hpp
Src/pch.hpp
Src/Printer.hpp
Src/Utils.hpp
Src/VulkanData.hpp
Src/ReportFormatter/TextReportFormatter.hpp
Src/ReportFormatter/JSONReportFormatter.hpp
Src/ReportFormatter/ReportFormatter.hpp
)

if(NOT EXISTS "${PROJECT_SOURCE_DIR}/Src/ThirdParty/rapidjson/include/rapidjson/rapidjson.h")
message(FATAL_ERROR "rapidjson library not found. This is likely due to missing submodule. Please initialize submodules.")
endif()
set(INTEL_GPUDETECT_CFG_FILE "Src/ThirdParty/gpudetect/IntelGfx.cfg")

option(ENABLE_AGS "Enables usage of AMD GPU Services (AGS) library." ON)
if(ENABLE_AGS)
Expand Down Expand Up @@ -82,6 +108,7 @@ function(add_my_executable USE_PREVIEW_AGILITY_SDK)
endif()

add_executable(${EXE_NAME} ${CPP_FILES} ${HPP_FILES})
target_include_directories(${EXE_NAME} PRIVATE Src)

# Change Visual C++ runtime library to get rid of dependency on Visual C++ Redistributable
set_property(TARGET ${EXE_NAME} PROPERTY
Expand All @@ -91,9 +118,6 @@ function(add_my_executable USE_PREVIEW_AGILITY_SDK)
target_compile_definitions(${EXE_NAME} PRIVATE UNICODE _UNICODE)
target_precompile_headers(${EXE_NAME} PRIVATE "Src/pch.hpp")

target_sources(${EXE_NAME} PRIVATE "${PROJECT_SOURCE_DIR}/${RAPIDJSON_NATVIS_FILE}")
source_group("ThirdParty" FILES ${RAPIDJSON_NATVIS_FILE})

if(USE_PREVIEW_AGILITY_SDK)
target_compile_definitions(${EXE_NAME} PRIVATE USE_PREVIEW_AGILITY_SDK=1)
set(AGILITY_SDK_DIRECTORY "${PROJECT_SOURCE_DIR}/Src/ThirdParty/microsoft.direct3d.d3d12.1.716.0-preview")
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ Options:
-h --Help Only print this help (command line syntax).
-l --List Only print the list of all adapters.
-a --Adapter=<Index> Print details of adapter at specified index.
--AllNonSoftware Print details of all (except WARP and Software) adapters (default behavior).
--AllAdapters Print details of all (except WARP) adapters.
--AllAdapters Print details of all adapters.
-j --JSON Print output in JSON format instead of human-friendly text.
--MinimizeJson Print JSON in minimal size form.
-o --OutputFile=<FilePath> Output to specified file.
-f --Formats Include information about DXGI format capabilities.
--MetaCommands Include information about meta commands.
-e --Enums Include information about all known enums and their values.
Expand All @@ -89,8 +90,6 @@ It uses following thirt-party libraries:

- **[DirectX 12 Agility SDK](https://devblogs.microsoft.com/directx/directx12agility/)** - latest API to Direct3D, by Microsoft.
- Embedded in directory: Src\ThirdParty\microsoft.direct3d.d3d12.*
- **[RapidJSON](https://rapidjson.org/)** - a fast JSON parser/generator, by Tencent. License: MIT.
- Linked via submodule.
- **[AMD GPU Services](https://github.com/GPUOpen-LibrariesAndSDKs/AGS_SDK)** - custom vendor extensions to graphics APIs by AMD.
- Linked via submodule.
- Optional, controlled by Cmake variable `ENABLE_AGS` - on by default.
Expand Down
88 changes: 39 additions & 49 deletions Src/AgsData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ License: MIT
For more information, see files README.md, LICENSE.txt.
*/
#include "AgsData.hpp"
#include "Printing.hpp"
#include "Utils.hpp"
#include "Json.hpp"
#include "Enums.hpp"
#include "ReportFormatter/ReportFormatter.hpp"

// Macro set by Cmake.
#if USE_AGS
Expand Down Expand Up @@ -67,22 +66,11 @@ static bool FindDevice(const AGS_Initialize_RAII::DeviceId& id, int& outIndex)

void AGS_Initialize_RAII::PrintStaticParams()
{
Print_string(L"AMD_AGS_VERSION", std::format(L"{}.{}.{}",
ReportFormatter::GetInstance().AddFieldString(L"AMD_AGS_VERSION", std::format(L"{}.{}.{}",
AMD_AGS_VERSION_MAJOR, AMD_AGS_VERSION_MINOR, AMD_AGS_VERSION_PATCH).c_str());

const uint32_t version = (uint32_t)agsGetVersionNumber();
if(g_UseJson)
{
Print_hex32(L"agsGetVersionNumber", version);
}
else
{
wstring s = std::format(L"{}.{}.{}",
version >> 22,
(version >> 12) & 0b11'1111'1111,
version & 0b1111'1111'1111);
Print_string(L"agsGetVersionNumber", s.c_str());
}
ReportFormatter::GetInstance().AddFieldAMDVersion(L"agsGetVersionNumber", version);
}

AGS_Initialize_RAII::AGS_Initialize_RAII()
Expand Down Expand Up @@ -110,9 +98,9 @@ void AGS_Initialize_RAII::PrintData()
if(IsStrEmpty(g_GpuInfo.driverVersion) && IsStrEmpty(g_GpuInfo.radeonSoftwareVersion))
return;

ScopedStructRegion region(L"AGSGPUInfo");
Print_string(L"driverVersion", StrToWstr(g_GpuInfo.driverVersion, CP_ACP).c_str());
Print_string(L"radeonSoftwareVersion", StrToWstr(g_GpuInfo.radeonSoftwareVersion, CP_ACP).c_str());
ReportScopeObject region(L"AGSGPUInfo");
ReportFormatter::GetInstance().AddFieldString(L"driverVersion", StrToWstr(g_GpuInfo.driverVersion, CP_ACP).c_str());
ReportFormatter::GetInstance().AddFieldString(L"radeonSoftwareVersion", StrToWstr(g_GpuInfo.radeonSoftwareVersion, CP_ACP).c_str());
}

void AGS_Initialize_RAII::PrintAgsDeviceData(const DeviceId& id)
Expand All @@ -124,23 +112,24 @@ void AGS_Initialize_RAII::PrintAgsDeviceData(const DeviceId& id)
return;
const AGSDeviceInfo& device = g_GpuInfo.devices[deviceIndex];

ScopedStructRegion region(L"AGSDeviceInfo");
Print_string(L"adapterString", StrToWstr(device.adapterString, CP_ACP).c_str());
PrintEnum(L"asicFamily", device.asicFamily, Enum_AGSDeviceInfo_AsicFamily);
Print_BOOL(L"isAPU", device.isAPU);
Print_BOOL(L"isExternal", device.isExternal);
PrintVendorId(L"vendorId", (uint32_t)device.vendorId);
Print_hex32(L"deviceId", (uint32_t)device.deviceId);
Print_hex32(L"revisionId", (uint32_t)device.revisionId);
Print_int32(L"numCUs", device.numCUs);
Print_int32(L"numWGPs", device.numWGPs);
Print_int32(L"numROPs", device.numROPs);
Print_int32(L"coreClock", device.coreClock, L"MHz");
Print_int32(L"memoryClock", device.memoryClock, L"MHz");
Print_int32(L"memoryBandwidth", device.memoryBandwidth, L"MB/s");
Print_float(L"teraFlops", device.teraFlops, L"TFLOPS");
Print_size(L"localMemoryInBytes", device.localMemoryInBytes);
Print_size(L"sharedMemoryInBytes", device.sharedMemoryInBytes);
ReportScopeObject region(L"AGSDeviceInfo");
ReportFormatter& formatter = ReportFormatter::GetInstance();
formatter.AddFieldString(L"adapterString", StrToWstr(device.adapterString, CP_ACP).c_str());
formatter.AddFieldEnum(L"asicFamily", device.asicFamily, Enum_AGSDeviceInfo_AsicFamily);
formatter.AddFieldBool(L"isAPU", device.isAPU);
formatter.AddFieldBool(L"isExternal", device.isExternal);
formatter.AddFieldVendorId(L"vendorId", (uint32_t)device.vendorId);
formatter.AddFieldHex32(L"deviceId", (uint32_t)device.deviceId);
formatter.AddFieldHex32(L"revisionId", (uint32_t)device.revisionId);
formatter.AddFieldInt32(L"numCUs", device.numCUs);
formatter.AddFieldInt32(L"numWGPs", device.numWGPs);
formatter.AddFieldInt32(L"numROPs", device.numROPs);
formatter.AddFieldInt32(L"coreClock", device.coreClock, L"MHz");
formatter.AddFieldInt32(L"memoryClock", device.memoryClock, L"MHz");
formatter.AddFieldInt32(L"memoryBandwidth", device.memoryBandwidth, L"MB/s");
formatter.AddFieldFloat(L"teraFlops", device.teraFlops, L"TFLOPS");
formatter.AddFieldSize(L"localMemoryInBytes", device.localMemoryInBytes);
formatter.AddFieldSize(L"sharedMemoryInBytes", device.sharedMemoryInBytes);
}

ComPtr<ID3D12Device> AGS_Initialize_RAII::CreateDeviceAndPrintData(IDXGIAdapter* adapter, D3D_FEATURE_LEVEL featureLevel)
Expand All @@ -163,20 +152,21 @@ ComPtr<ID3D12Device> AGS_Initialize_RAII::CreateDeviceAndPrintData(IDXGIAdapter*
ComPtr<ID3D12Device> device{returnedParams.pDevice};
g_DeviceCreatedWithAgs = true;

ScopedStructRegion region(L"AGSDX12ReturnedParams::ExtensionsSupported");
Print_BOOL(L"intrinsics16", returnedParams.extensionsSupported.intrinsics16);
Print_BOOL(L"intrinsics17", returnedParams.extensionsSupported.intrinsics17);
Print_BOOL(L"userMarkers", returnedParams.extensionsSupported.userMarkers);
Print_BOOL(L"appRegistration", returnedParams.extensionsSupported.appRegistration);
Print_BOOL(L"UAVBindSlot", returnedParams.extensionsSupported.UAVBindSlot);
Print_BOOL(L"intrinsics19", returnedParams.extensionsSupported.intrinsics19);
Print_BOOL(L"baseVertex", returnedParams.extensionsSupported.baseVertex);
Print_BOOL(L"baseInstance", returnedParams.extensionsSupported.baseInstance);
Print_BOOL(L"getWaveSize", returnedParams.extensionsSupported.getWaveSize);
Print_BOOL(L"floatConversion", returnedParams.extensionsSupported.floatConversion);
Print_BOOL(L"readLaneAt", returnedParams.extensionsSupported.readLaneAt);
Print_BOOL(L"rayHitToken", returnedParams.extensionsSupported.rayHitToken);
Print_BOOL(L"shaderClock", returnedParams.extensionsSupported.shaderClock);
ReportScopeObject region(L"AGSDX12ReturnedParams::ExtensionsSupported");
ReportFormatter& formatter = ReportFormatter::GetInstance();
formatter.AddFieldBool(L"intrinsics16", returnedParams.extensionsSupported.intrinsics16);
formatter.AddFieldBool(L"intrinsics17", returnedParams.extensionsSupported.intrinsics17);
formatter.AddFieldBool(L"userMarkers", returnedParams.extensionsSupported.userMarkers);
formatter.AddFieldBool(L"appRegistration", returnedParams.extensionsSupported.appRegistration);
formatter.AddFieldBool(L"UAVBindSlot", returnedParams.extensionsSupported.UAVBindSlot);
formatter.AddFieldBool(L"intrinsics19", returnedParams.extensionsSupported.intrinsics19);
formatter.AddFieldBool(L"baseVertex", returnedParams.extensionsSupported.baseVertex);
formatter.AddFieldBool(L"baseInstance", returnedParams.extensionsSupported.baseInstance);
formatter.AddFieldBool(L"getWaveSize", returnedParams.extensionsSupported.getWaveSize);
formatter.AddFieldBool(L"floatConversion", returnedParams.extensionsSupported.floatConversion);
formatter.AddFieldBool(L"readLaneAt", returnedParams.extensionsSupported.readLaneAt);
formatter.AddFieldBool(L"rayHitToken", returnedParams.extensionsSupported.rayHitToken);
formatter.AddFieldBool(L"shaderClock", returnedParams.extensionsSupported.shaderClock);

return device;
}
Expand Down
39 changes: 20 additions & 19 deletions Src/AmdDeviceInfoData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ License: MIT
For more information, see files README.md, LICENSE.txt.
*/
#include "AmdDeviceInfoData.hpp"
#include "Printing.hpp"
#include "Utils.hpp"
#include "Json.hpp"
#include "Enums.hpp"
#include "ReportFormatter/ReportFormatter.hpp"

// Macro set by Cmake.
#if USE_AMD_DEVICE_INFO
Expand Down Expand Up @@ -116,7 +115,7 @@ static const GDT_GfxCardInfo* FindCardInfo(const AmdDeviceInfo_Initialize_RAII::

void AmdDeviceInfo_Initialize_RAII::PrintStaticParams()
{
Print_string(L"AMD device_info compiled version", AMD_DEVICE_INFO_COMPILED_VERSION);
ReportFormatter::GetInstance().AddFieldString(L"AMD device_info compiled version", AMD_DEVICE_INFO_COMPILED_VERSION);
}

void AmdDeviceInfo_Initialize_RAII::PrintDeviceData(const DeviceId& id)
Expand All @@ -125,30 +124,32 @@ void AmdDeviceInfo_Initialize_RAII::PrintDeviceData(const DeviceId& id)
if(!cardInfo)
return;

ReportFormatter& formatter = ReportFormatter::GetInstance();

{
ScopedStructRegion region{L"AMD GDT_GfxCardInfo"};
PrintEnum(L"asicType", cardInfo->m_asicType, Enum_GDT_HW_ASIC_TYPE);
PrintEnum(L"generation", cardInfo->m_generation, Enum_GDT_HW_GENERATION);
Print_BOOL(L"APU", cardInfo->m_bAPU ? TRUE : FALSE);
Print_string(L"CALName", StrToWstr(cardInfo->m_szCALName, CP_UTF8).c_str());
Print_string(L"MarketingName", StrToWstr(cardInfo->m_szMarketingName, CP_UTF8).c_str());
ReportScopeObject region{ L"AMD GDT_GfxCardInfo" };
formatter.AddFieldEnum(L"asicType", cardInfo->m_asicType, Enum_GDT_HW_ASIC_TYPE);
formatter.AddFieldEnum(L"generation", cardInfo->m_generation, Enum_GDT_HW_GENERATION);
formatter.AddFieldBool(L"APU", cardInfo->m_bAPU ? TRUE : FALSE);
formatter.AddFieldString(L"CALName", StrToWstr(cardInfo->m_szCALName, CP_UTF8).c_str());
formatter.AddFieldString(L"MarketingName", StrToWstr(cardInfo->m_szMarketingName, CP_UTF8).c_str());
}

if(cardInfo->m_asicType >= 0 && cardInfo->m_asicType < gs_deviceInfoSize)
{
const GDT_DeviceInfo& devInfo = gs_deviceInfo[cardInfo->m_asicType];
if(devInfo.m_deviceInfoValid)
{
ScopedStructRegion region(L"AMD GDT_DeviceInfo");
Print_uint64(L"NumShaderEngines", devInfo.m_nNumShaderEngines); // Number of shader engines.
Print_uint64(L"MaxWavePerSIMD", devInfo.m_nMaxWavePerSIMD); // Number of wave slots per SIMD.
Print_uint64(L"ClocksPrim", devInfo.m_suClocksPrim); // Number of clocks it takes to process a primitive.
Print_uint64(L"NumSQMaxCounters", devInfo.m_nNumSQMaxCounters); // Max number of SQ counters.
Print_uint64(L"NumPrimPipes", devInfo.m_nNumPrimPipes); // Number of primitive pipes.
Print_uint64(L"WaveSize", devInfo.m_nWaveSize); // Wavefront size.
Print_uint64(L"NumSHPerSE", devInfo.m_nNumSHPerSE); // Number of shader array per Shader Engine.
Print_uint64(L"NumCUPerSH", devInfo.m_nNumCUPerSH); // Number of compute unit per Shader Array.
Print_uint64(L"NumSIMDPerCU", devInfo.m_nNumSIMDPerCU); // Number of SIMDs per Compute unit.
ReportScopeObject region(L"AMD GDT_DeviceInfo");
formatter.AddFieldUint64(L"NumShaderEngines", devInfo.m_nNumShaderEngines); // Number of shader engines.
formatter.AddFieldUint64(L"MaxWavePerSIMD", devInfo.m_nMaxWavePerSIMD); // Number of wave slots per SIMD.
formatter.AddFieldUint64(L"ClocksPrim", devInfo.m_suClocksPrim); // Number of clocks it takes to process a primitive.
formatter.AddFieldUint64(L"NumSQMaxCounters", devInfo.m_nNumSQMaxCounters); // Max number of SQ counters.
formatter.AddFieldUint64(L"NumPrimPipes", devInfo.m_nNumPrimPipes); // Number of primitive pipes.
formatter.AddFieldUint64(L"WaveSize", devInfo.m_nWaveSize); // Wavefront size.
formatter.AddFieldUint64(L"NumSHPerSE", devInfo.m_nNumSHPerSE); // Number of shader array per Shader Engine.
formatter.AddFieldUint64(L"NumCUPerSH", devInfo.m_nNumCUPerSH); // Number of compute unit per Shader Array.
formatter.AddFieldUint64(L"NumSIMDPerCU", devInfo.m_nNumSIMDPerCU); // Number of SIMDs per Compute unit.
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions Src/Enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ For more information, see files README.md, LICENSE.txt.
*/
#pragma once

#include <unordered_map>

struct EnumItem
{
const wchar_t* m_Name;
Expand Down
Loading

0 comments on commit 8774e90

Please sign in to comment.