Ver código fonte

Added recompile function on PdbUtils that just hands back compilation result. (#3529)

Adam Yang 4 anos atrás
pai
commit
c7d8ac5793
2 arquivos alterados com 29 adições e 10 exclusões
  1. 1 0
      include/dxc/dxcapi.h
  2. 28 10
      tools/clang/tools/dxcompiler/dxcpdbutils.cpp

+ 1 - 0
include/dxc/dxcapi.h

@@ -605,6 +605,7 @@ struct IDxcPdbUtils : public IUnknown {
   virtual HRESULT STDMETHODCALLTYPE GetVersionInfo(_COM_Outptr_ IDxcVersionInfo **ppVersionInfo) = 0;
   virtual HRESULT STDMETHODCALLTYPE GetVersionInfo(_COM_Outptr_ IDxcVersionInfo **ppVersionInfo) = 0;
 
 
   virtual HRESULT STDMETHODCALLTYPE SetCompiler(_In_ IDxcCompiler3 *pCompiler) = 0;
   virtual HRESULT STDMETHODCALLTYPE SetCompiler(_In_ IDxcCompiler3 *pCompiler) = 0;
+  virtual HRESULT STDMETHODCALLTYPE CompileForFullPDB(_COM_Outptr_ IDxcResult **ppResult) = 0;
 };
 };
 
 
 // Note: __declspec(selectany) requires 'extern'
 // Note: __declspec(selectany) requires 'extern'

+ 28 - 10
tools/clang/tools/dxcompiler/dxcpdbutils.cpp

@@ -264,6 +264,7 @@ private:
   hlsl::DxilCompilerVersion m_VersionInfo;
   hlsl::DxilCompilerVersion m_VersionInfo;
   std::string m_VersionCommitSha;
   std::string m_VersionCommitSha;
   std::string m_VersionString;
   std::string m_VersionString;
+  CComPtr<IDxcResult> m_pCachedRecompileResult;
 
 
   // NOTE: This is not set to null by Reset() since it doesn't
   // NOTE: This is not set to null by Reset() since it doesn't
   // necessarily change across different PDBs.
   // necessarily change across different PDBs.
@@ -293,6 +294,7 @@ private:
     m_VersionCommitSha.clear();
     m_VersionCommitSha.clear();
     m_VersionString.clear();
     m_VersionString.clear();
     m_ArgPairs.clear();
     m_ArgPairs.clear();
+    m_pCachedRecompileResult = nullptr;
   }
   }
 
 
   bool HasSources() const {
   bool HasSources() const {
@@ -717,18 +719,15 @@ public:
     return m_pDebugProgramBlob != nullptr;
     return m_pDebugProgramBlob != nullptr;
   }
   }
 
 
-  virtual HRESULT STDMETHODCALLTYPE GetFullPDB(_COM_Outptr_ IDxcBlob **ppFullPDB) override {
+  virtual HRESULT STDMETHODCALLTYPE CompileForFullPDB(_COM_Outptr_ IDxcResult **ppResult) {
+    if (!ppResult) return E_POINTER;
+    *ppResult = nullptr;
+
     if (!m_InputBlob)
     if (!m_InputBlob)
       return E_FAIL;
       return E_FAIL;
 
 
-    if (!ppFullPDB) return E_POINTER;
-
-    *ppFullPDB = nullptr;
-
-    // If we are already a full pdb, just return the input blob
-    if (IsFullPDB()) {
-      return m_InputBlob.QueryInterface(ppFullPDB);
-    }
+    if (m_pCachedRecompileResult)
+      return m_pCachedRecompileResult.QueryInterface(ppResult);
 
 
     if (!m_pCompiler)
     if (!m_pCompiler)
       IFR(DxcCreateInstance2(m_pMalloc, CLSID_DxcCompiler, IID_PPV_ARGS(&m_pCompiler)));
       IFR(DxcCreateInstance2(m_pMalloc, CLSID_DxcCompiler, IID_PPV_ARGS(&m_pCompiler)));
@@ -769,7 +768,25 @@ public:
     IFR(main_file->GetEncoding(&bEndodingKnown, &source_buf.Encoding));
     IFR(main_file->GetEncoding(&bEndodingKnown, &source_buf.Encoding));
 
 
     CComPtr<IDxcResult> pResult;
     CComPtr<IDxcResult> pResult;
-    IFR(m_pCompiler->Compile(&source_buf, new_args.data(), new_args.size(), pIncludeHandler, IID_PPV_ARGS(&pResult)));
+    IFR(m_pCompiler->Compile(&source_buf, new_args.data(), new_args.size(), pIncludeHandler, IID_PPV_ARGS(&m_pCachedRecompileResult)));
+
+    CComPtr<IDxcOperationResult> pOperationResult;
+    return m_pCachedRecompileResult.QueryInterface(ppResult);
+  }
+
+  virtual HRESULT STDMETHODCALLTYPE GetFullPDB(_COM_Outptr_ IDxcBlob **ppFullPDB) override {
+    if (!m_InputBlob)
+      return E_FAIL;
+    if (!ppFullPDB) return E_POINTER;
+    *ppFullPDB = nullptr;
+    // If we are already a full pdb, just return the input blob
+    if (IsFullPDB()) {
+      return m_InputBlob.QueryInterface(ppFullPDB);
+    }
+
+    CComPtr<IDxcResult> pResult;
+
+    IFR(CompileForFullPDB(&pResult));
 
 
     CComPtr<IDxcOperationResult> pOperationResult;
     CComPtr<IDxcOperationResult> pOperationResult;
     IFR(pResult.QueryInterface(&pOperationResult));
     IFR(pResult.QueryInterface(&pOperationResult));
@@ -850,6 +867,7 @@ public:
 
 
   virtual HRESULT STDMETHODCALLTYPE SetCompiler(_In_ IDxcCompiler3 *pCompiler) override {
   virtual HRESULT STDMETHODCALLTYPE SetCompiler(_In_ IDxcCompiler3 *pCompiler) override {
     m_pCompiler = pCompiler;
     m_pCompiler = pCompiler;
+    m_pCachedRecompileResult = nullptr; // Clear the previously compiled result
     return S_OK;
     return S_OK;
   }
   }
 };
 };