Skip to content

Commit

Permalink
Use IDxcPdbUtils2 instead of dia sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejnau committed Jan 14, 2024
1 parent 1f9fbd2 commit b396bb7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 75 deletions.
7 changes: 0 additions & 7 deletions cmake/3rdparty/dxc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,3 @@ target_include_directories(dxc INTERFACE "${get_include}")
if (NOT WIN32)
target_compile_definitions(dxc INTERFACE __EMULATE_UUID)
endif()

if (WIN32)
list(PREPEND CMAKE_MODULE_PATH "${project_root}/3rdparty/dxc/cmake/modules")
find_package(DiaSDK REQUIRED)
add_library(dia INTERFACE)
target_include_directories(dia INTERFACE "${DIASDK_INCLUDE_DIRS}")
endif()
1 change: 0 additions & 1 deletion src/FlyCube/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ endif()

target_link_libraries(FlyCube
$<$<BOOL:${DIRECTX_SUPPORT}>:d3d12>
$<$<BOOL:${DIRECTX_SUPPORT}>:dia>
$<$<BOOL:${DIRECTX_SUPPORT}>:DirectX-Headers>
$<$<BOOL:${DIRECTX_SUPPORT}>:dxgi>
$<$<BOOL:${DIRECTX_SUPPORT}>:dxguid>
Expand Down
73 changes: 6 additions & 67 deletions src/FlyCube/ShaderReflection/DXILReflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
#include <dxc/DxilContainer/DxilRuntimeReflection.inl>
#include <nowide/convert.hpp>

#ifdef _WIN32
#include <dia2.h>
#endif

#include <algorithm>
#include <set>

Expand Down Expand Up @@ -47,54 +43,6 @@ ShaderKind ConvertShaderKind(hlsl::DXIL::ShaderKind kind)
return ShaderKind::kUnknown;
}

#ifdef _WIN32
CComPtr<IDiaTable> FindTable(CComPtr<IDiaSession> session, const std::wstring& name)
{
CComPtr<IDiaEnumTables> enum_tables;
session->getEnumTables(&enum_tables);
LONG count = 0;
enum_tables->get_Count(&count);
for (LONG i = 0; i < count; ++i) {
ULONG fetched = 0;
CComPtr<IDiaTable> table;
enum_tables->Next(1, &table, &fetched);
CComBSTR table_name;
table->get_name(&table_name);
if (table_name.m_str == name) {
return table;
}
}
return nullptr;
}

std::string FindStrValue(CComPtr<IDiaTable> table, const std::wstring& name)
{
LONG count = 0;
table->get_Count(&count);
for (LONG i = 0; i < count; ++i) {
CComPtr<IUnknown> item;
table->Item(i, &item);
CComPtr<IDiaSymbol> symbol;
if (FAILED(item.QueryInterface(&symbol))) {
continue;
}

CComBSTR item_name;
symbol->get_name(&item_name);
if (!item_name || item_name.m_str != name) {
continue;
}

VARIANT value = {};
symbol->get_value(&value);
if (value.vt == VT_BSTR) {
return nowide::narrow(value.bstrVal);
}
}
return "";
}
#endif

DXILReflection::DXILReflection(const void* data, size_t size)
{
decltype(auto) dxc_support = GetDxcSupport(ShaderBlobType::kDXIL);
Expand Down Expand Up @@ -560,20 +508,11 @@ void DXILReflection::ParseLibraryReflection(CComPtr<ID3D12LibraryReflection> lib

void DXILReflection::ParseDebugInfo(dxc::DxcDllSupport& dxc_support, CComPtr<IDxcBlob> pdb)
{
#ifdef _WIN32
CComPtr<IDxcLibrary> library;
ASSERT_SUCCEEDED(dxc_support.CreateInstance(CLSID_DxcLibrary, &library));
CComPtr<IStream> stream;
ASSERT_SUCCEEDED(library->CreateStreamFromBlobReadOnly(pdb, &stream));

CComPtr<IDiaDataSource> dia;
ASSERT_SUCCEEDED(dxc_support.CreateInstance(CLSID_DxcDiaDataSource, &dia));
ASSERT_SUCCEEDED(dia->loadDataFromIStream(stream));
CComPtr<IDiaSession> session;
ASSERT_SUCCEEDED(dia->openSession(&session));

CComPtr<IDiaTable> symbols_table = FindTable(session, L"Symbols");
CComPtr<IDxcPdbUtils2> pdb_utils;
ASSERT_SUCCEEDED(dxc_support.CreateInstance(CLSID_DxcPdbUtils, &pdb_utils));
ASSERT_SUCCEEDED(pdb_utils->Load(pdb));
CComPtr<IDxcBlobWide> entry_point;
ASSERT_SUCCEEDED(pdb_utils->GetEntryPoint(&entry_point));
assert(m_entry_points.size() == 1);
m_entry_points.front().name = FindStrValue(symbols_table, L"hlslEntry");
#endif
m_entry_points.front().name = nowide::narrow(entry_point->GetStringPointer());
}

0 comments on commit b396bb7

Please sign in to comment.