Skip to content

Commit c7d8ac5

Browse files
authored
Added recompile function on PdbUtils that just hands back compilation result. (#3529)
1 parent 83d6fd5 commit c7d8ac5

2 files changed

Lines changed: 29 additions & 10 deletions

File tree

include/dxc/dxcapi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ struct IDxcPdbUtils : public IUnknown {
605605
virtual HRESULT STDMETHODCALLTYPE GetVersionInfo(_COM_Outptr_ IDxcVersionInfo **ppVersionInfo) = 0;
606606

607607
virtual HRESULT STDMETHODCALLTYPE SetCompiler(_In_ IDxcCompiler3 *pCompiler) = 0;
608+
virtual HRESULT STDMETHODCALLTYPE CompileForFullPDB(_COM_Outptr_ IDxcResult **ppResult) = 0;
608609
};
609610

610611
// Note: __declspec(selectany) requires 'extern'

tools/clang/tools/dxcompiler/dxcpdbutils.cpp

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ struct DxcPdbUtils : public IDxcPdbUtils, public IDxcPixDxilDebugInfoFactory
264264
hlsl::DxilCompilerVersion m_VersionInfo;
265265
std::string m_VersionCommitSha;
266266
std::string m_VersionString;
267+
CComPtr<IDxcResult> m_pCachedRecompileResult;
267268

268269
// NOTE: This is not set to null by Reset() since it doesn't
269270
// necessarily change across different PDBs.
@@ -293,6 +294,7 @@ struct DxcPdbUtils : public IDxcPdbUtils, public IDxcPixDxilDebugInfoFactory
293294
m_VersionCommitSha.clear();
294295
m_VersionString.clear();
295296
m_ArgPairs.clear();
297+
m_pCachedRecompileResult = nullptr;
296298
}
297299

298300
bool HasSources() const {
@@ -717,18 +719,15 @@ struct DxcPdbUtils : public IDxcPdbUtils, public IDxcPixDxilDebugInfoFactory
717719
return m_pDebugProgramBlob != nullptr;
718720
}
719721

720-
virtual HRESULT STDMETHODCALLTYPE GetFullPDB(_COM_Outptr_ IDxcBlob **ppFullPDB) override {
722+
virtual HRESULT STDMETHODCALLTYPE CompileForFullPDB(_COM_Outptr_ IDxcResult **ppResult) {
723+
if (!ppResult) return E_POINTER;
724+
*ppResult = nullptr;
725+
721726
if (!m_InputBlob)
722727
return E_FAIL;
723728

724-
if (!ppFullPDB) return E_POINTER;
725-
726-
*ppFullPDB = nullptr;
727-
728-
// If we are already a full pdb, just return the input blob
729-
if (IsFullPDB()) {
730-
return m_InputBlob.QueryInterface(ppFullPDB);
731-
}
729+
if (m_pCachedRecompileResult)
730+
return m_pCachedRecompileResult.QueryInterface(ppResult);
732731

733732
if (!m_pCompiler)
734733
IFR(DxcCreateInstance2(m_pMalloc, CLSID_DxcCompiler, IID_PPV_ARGS(&m_pCompiler)));
@@ -769,7 +768,25 @@ struct DxcPdbUtils : public IDxcPdbUtils, public IDxcPixDxilDebugInfoFactory
769768
IFR(main_file->GetEncoding(&bEndodingKnown, &source_buf.Encoding));
770769

771770
CComPtr<IDxcResult> pResult;
772-
IFR(m_pCompiler->Compile(&source_buf, new_args.data(), new_args.size(), pIncludeHandler, IID_PPV_ARGS(&pResult)));
771+
IFR(m_pCompiler->Compile(&source_buf, new_args.data(), new_args.size(), pIncludeHandler, IID_PPV_ARGS(&m_pCachedRecompileResult)));
772+
773+
CComPtr<IDxcOperationResult> pOperationResult;
774+
return m_pCachedRecompileResult.QueryInterface(ppResult);
775+
}
776+
777+
virtual HRESULT STDMETHODCALLTYPE GetFullPDB(_COM_Outptr_ IDxcBlob **ppFullPDB) override {
778+
if (!m_InputBlob)
779+
return E_FAIL;
780+
if (!ppFullPDB) return E_POINTER;
781+
*ppFullPDB = nullptr;
782+
// If we are already a full pdb, just return the input blob
783+
if (IsFullPDB()) {
784+
return m_InputBlob.QueryInterface(ppFullPDB);
785+
}
786+
787+
CComPtr<IDxcResult> pResult;
788+
789+
IFR(CompileForFullPDB(&pResult));
773790

774791
CComPtr<IDxcOperationResult> pOperationResult;
775792
IFR(pResult.QueryInterface(&pOperationResult));
@@ -850,6 +867,7 @@ struct DxcPdbUtils : public IDxcPdbUtils, public IDxcPixDxilDebugInfoFactory
850867

851868
virtual HRESULT STDMETHODCALLTYPE SetCompiler(_In_ IDxcCompiler3 *pCompiler) override {
852869
m_pCompiler = pCompiler;
870+
m_pCachedRecompileResult = nullptr; // Clear the previously compiled result
853871
return S_OK;
854872
}
855873
};

0 commit comments

Comments
 (0)