Fixed pdbutils recompilation failure when the main file is in a relative path. (#3486)
This commit is contained in:
Родитель
81eb9808ce
Коммит
b63b179587
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include "dxc/dxcapi.h"
|
||||
#include "llvm/Support/MSFileSystem.h"
|
||||
#include <string>
|
||||
|
||||
namespace clang {
|
||||
class CompilerInstance;
|
||||
|
@ -46,4 +47,6 @@ DxcArgsFileSystem *
|
|||
CreateDxcArgsFileSystem(_In_ IDxcBlobUtf8 *pSource, _In_ LPCWSTR pSourceName,
|
||||
_In_opt_ IDxcIncludeHandler *pIncludeHandler);
|
||||
|
||||
void MakeAbsoluteOrCurDirRelativeW(LPCWSTR &Path, std::wstring &PathStorage);
|
||||
|
||||
} // namespace dxcutil
|
|
@ -180,6 +180,10 @@ bool IsAbsoluteOrCurDirRelativeW(LPCWSTR Path) {
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace dxcutil {
|
||||
|
||||
void MakeAbsoluteOrCurDirRelativeW(LPCWSTR &Path, std::wstring &PathStorage) {
|
||||
if (IsAbsoluteOrCurDirRelativeW(Path)) {
|
||||
return;
|
||||
|
@ -191,9 +195,6 @@ void MakeAbsoluteOrCurDirRelativeW(LPCWSTR &Path, std::wstring &PathStorage) {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace dxcutil {
|
||||
/// File system based on API arguments. Support being added incrementally.
|
||||
///
|
||||
/// DxcArgsFileSystem emulates a file system to clang/llvm based on API
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "dxc/Support/HLSLOptions.h"
|
||||
|
||||
#include "dxcshadersourceinfo.h"
|
||||
#include "dxc/Support/dxcfilesystem.h"
|
||||
|
||||
#include <vector>
|
||||
#include <locale>
|
||||
|
@ -79,6 +80,8 @@ static HRESULT CopyWstringToBSTR(const std::wstring &str, BSTR *pResult) {
|
|||
}
|
||||
|
||||
static std::wstring NormalizePath(const WCHAR *path) {
|
||||
std::wstring PathStorage;
|
||||
dxcutil::MakeAbsoluteOrCurDirRelativeW(path, PathStorage);
|
||||
std::string FilenameStr8 = Unicode::UTF16ToUTF8StringOrThrow(path);
|
||||
llvm::SmallString<128> NormalizedPath;
|
||||
llvm::sys::path::native(FilenameStr8, NormalizedPath);
|
||||
|
@ -223,7 +226,8 @@ struct PdbRecompilerIncludeHandler : public IDxcIncludeHandler {
|
|||
return E_POINTER;
|
||||
*ppIncludeSource = nullptr;
|
||||
|
||||
auto it = m_FileMap.find(NormalizePath(pFilename));
|
||||
std::wstring Filename = NormalizePath(pFilename);
|
||||
auto it = m_FileMap.find(Filename);
|
||||
if (it == m_FileMap.end())
|
||||
return E_FAIL;
|
||||
|
||||
|
|
|
@ -130,6 +130,7 @@ public:
|
|||
TEST_METHOD(CompileThenTestPdbUtils)
|
||||
TEST_METHOD(CompileThenTestPdbUtilsStripped)
|
||||
TEST_METHOD(CompileThenTestPdbUtilsEmptyEntry)
|
||||
TEST_METHOD(CompileThenTestPdbUtilsRelativePath)
|
||||
TEST_METHOD(CompileWithRootSignatureThenStripRootSignature)
|
||||
|
||||
TEST_METHOD(CompileWhenIncludeThenLoadInvoked)
|
||||
|
@ -1536,6 +1537,58 @@ TEST_F(CompilerTest, CompileThenTestPdbUtils) {
|
|||
TestPdbUtils(/*bSlim*/true, /*bSourceInDebugModule*/false, /*strip*/true); // Slim PDB, where source info is stored in its own part, and debug module is NOT present
|
||||
}
|
||||
|
||||
TEST_F(CompilerTest, CompileThenTestPdbUtilsRelativePath) {
|
||||
std::string main_source = R"x(
|
||||
#include "helper.h"
|
||||
cbuffer MyCbuffer : register(b1) {
|
||||
float4 my_cbuf_foo;
|
||||
}
|
||||
|
||||
[RootSignature("CBV(b1)")]
|
||||
float4 main() : SV_Target {
|
||||
return my_cbuf_foo;
|
||||
}
|
||||
)x";
|
||||
|
||||
CComPtr<IDxcCompiler3> pCompiler;
|
||||
VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcCompiler, &pCompiler));
|
||||
|
||||
DxcBuffer SourceBuf = {};
|
||||
SourceBuf.Ptr = main_source.c_str();
|
||||
SourceBuf.Size = main_source.size();
|
||||
SourceBuf.Encoding = CP_UTF8;
|
||||
|
||||
std::vector<const WCHAR *> args;
|
||||
args.push_back(L"/Tps_6_0");
|
||||
args.push_back(L"/Zi");
|
||||
args.push_back(L"/Qsource_only_debug");
|
||||
args.push_back(L"shaders/Shader.hlsl");
|
||||
|
||||
CComPtr<TestIncludeHandler> pInclude;
|
||||
std::string included_File = "#define ZERO 0";
|
||||
pInclude = new TestIncludeHandler(m_dllSupport);
|
||||
pInclude->CallResults.emplace_back(included_File.c_str());
|
||||
|
||||
CComPtr<IDxcResult> pResult;
|
||||
VERIFY_SUCCEEDED(pCompiler->Compile(&SourceBuf, args.data(), args.size(), pInclude, IID_PPV_ARGS(&pResult)));
|
||||
|
||||
CComPtr<IDxcBlob> pPdb;
|
||||
CComPtr<IDxcBlobUtf16> pPdbName;
|
||||
VERIFY_SUCCEEDED(pResult->GetOutput(DXC_OUT_PDB, IID_PPV_ARGS(&pPdb), &pPdbName));
|
||||
|
||||
CComPtr<IDxcPdbUtils> pPdbUtils;
|
||||
VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcPdbUtils, &pPdbUtils));
|
||||
|
||||
VERIFY_SUCCEEDED(pPdbUtils->Load(pPdb));
|
||||
|
||||
CComPtr<IDxcBlob> pFullPdb;
|
||||
VERIFY_SUCCEEDED(pPdbUtils->GetFullPDB(&pFullPdb));
|
||||
|
||||
VERIFY_SUCCEEDED(pPdbUtils->Load(pFullPdb));
|
||||
VERIFY_IS_TRUE(pPdbUtils->IsFullPDB());
|
||||
}
|
||||
|
||||
|
||||
TEST_F(CompilerTest, CompileThenTestPdbUtilsEmptyEntry) {
|
||||
std::string main_source = R"x(
|
||||
cbuffer MyCbuffer : register(b1) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче