Skip to content

Commit 39864aa

Browse files
committed
add IDxcCompiler wrapper as well
1 parent 1aa2736 commit 39864aa

4 files changed

Lines changed: 173 additions & 30 deletions

File tree

include/dxc/Support/dxcapi.extval.h

Lines changed: 95 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
namespace dxc {
99

10-
class ExternalValidationHelper : public IDxcCompiler3 {
10+
class ExternalValidationHelper3 : public IDxcCompiler3 {
1111

1212
public:
13-
CComPtr<IDxcCompiler3> m_pCompiler;
13+
CComPtr<IDxcCompiler3> m_pCompiler3;
1414
CComPtr<IDxcValidator> m_pValidator;
1515

16-
ExternalValidationHelper() {
17-
m_pCompiler = nullptr;
16+
ExternalValidationHelper3() {
17+
m_pCompiler3 = nullptr;
1818
m_pValidator = nullptr;
1919
}
2020

@@ -37,7 +37,95 @@ class ExternalValidationHelper : public IDxcCompiler3 {
3737
_Out_ LPVOID *ppResult)
3838
override ///< IDxcResult: status, disassembly text, and errors.
3939
{
40-
return m_pCompiler->Disassemble(pObject, riid, ppResult);
40+
return m_pCompiler3->Disassemble(pObject, riid, ppResult);
41+
}
42+
43+
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid,
44+
void **ppvObject) override {
45+
return m_pCompiler3->QueryInterface(riid, ppvObject);
46+
}
47+
48+
ULONG STDMETHODCALLTYPE AddRef() override { return m_pCompiler3.p->AddRef(); }
49+
50+
ULONG STDMETHODCALLTYPE Release() override {
51+
return m_pCompiler3.p->Release();
52+
}
53+
54+
HRESULT STDMETHODCALLTYPE Validate(
55+
IDxcBlob *pShader, // Shader to validate.
56+
UINT32 Flags, // Validation flags.
57+
IDxcOperationResult *
58+
*ppResult // Validation output status, buffer, and errors
59+
) {
60+
return m_pValidator->Validate(pShader, Flags, ppResult);
61+
}
62+
63+
ExternalValidationHelper3(CComPtr<IDxcCompiler3> pCompiler,
64+
CComPtr<IDxcValidator> pValidator) {
65+
m_pCompiler3 = pCompiler;
66+
m_pValidator = pValidator;
67+
}
68+
};
69+
70+
class ExternalValidationHelper : public IDxcCompiler {
71+
public:
72+
CComPtr<IDxcCompiler> m_pCompiler;
73+
CComPtr<IDxcValidator> m_pValidator;
74+
75+
ExternalValidationHelper() {
76+
m_pCompiler = nullptr;
77+
m_pValidator = nullptr;
78+
}
79+
HRESULT STDMETHODCALLTYPE Compile(
80+
_In_ IDxcBlob *pSource, // Source text to compile.
81+
_In_opt_z_ LPCWSTR pSourceName, // Optional file name for pSource. Used in
82+
// errors and include handlers.
83+
_In_opt_z_ LPCWSTR pEntryPoint, // Entry point name.
84+
_In_z_ LPCWSTR pTargetProfile, // Shader profile to compile.
85+
_In_opt_count_(argCount)
86+
LPCWSTR *pArguments, // Array of pointers to arguments.
87+
_In_ UINT32 argCount, // Number of arguments.
88+
_In_count_(defineCount) const DxcDefine *pDefines, // Array of defines.
89+
_In_ UINT32 defineCount, // Number of defines.
90+
_In_opt_ IDxcIncludeHandler
91+
*pIncludeHandler, // User-provided interface to handle #include
92+
// directives (optional).
93+
_COM_Outptr_ IDxcOperationResult *
94+
*ppResult // Compiler output status, buffer, and errors.
95+
) override;
96+
97+
/// \brief Preprocess source text.
98+
///
99+
/// \deprecated Please use IDxcCompiler3::Compile() with the "-P" argument
100+
/// instead.
101+
HRESULT STDMETHODCALLTYPE Preprocess(
102+
_In_ IDxcBlob *pSource, // Source text to preprocess.
103+
_In_opt_z_ LPCWSTR pSourceName, // Optional file name for pSource. Used in
104+
// errors and include handlers.
105+
_In_opt_count_(argCount)
106+
LPCWSTR *pArguments, // Array of pointers to arguments.
107+
_In_ UINT32 argCount, // Number of arguments.
108+
_In_count_(defineCount) const DxcDefine *pDefines, // Array of defines.
109+
_In_ UINT32 defineCount, // Number of defines.
110+
_In_opt_ IDxcIncludeHandler
111+
*pIncludeHandler, // user-provided interface to handle #include
112+
// directives (optional).
113+
_COM_Outptr_ IDxcOperationResult *
114+
*ppResult // Preprocessor output status, buffer, and errors.
115+
) override {
116+
return m_pCompiler->Preprocess(pSource, pSourceName, pArguments, argCount,
117+
pDefines, defineCount, pIncludeHandler,
118+
ppResult);
119+
}
120+
121+
/// \brief Disassemble a program.
122+
///
123+
/// \deprecated Please use IDxcCompiler3::Disassemble() instead.
124+
HRESULT STDMETHODCALLTYPE Disassemble(
125+
_In_ IDxcBlob *pSource, // Program to disassemble.
126+
_COM_Outptr_ IDxcBlobEncoding **ppDisassembly // Disassembly text.
127+
) override {
128+
return m_pCompiler->Disassemble(pSource, ppDisassembly);
41129
}
42130

43131
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid,
@@ -50,6 +138,7 @@ class ExternalValidationHelper : public IDxcCompiler3 {
50138
ULONG STDMETHODCALLTYPE Release() override {
51139
return m_pCompiler.p->Release();
52140
}
141+
53142
HRESULT STDMETHODCALLTYPE Validate(
54143
IDxcBlob *pShader, // Shader to validate.
55144
UINT32 Flags, // Validation flags.
@@ -59,7 +148,7 @@ class ExternalValidationHelper : public IDxcCompiler3 {
59148
return m_pValidator->Validate(pShader, Flags, ppResult);
60149
}
61150

62-
ExternalValidationHelper(CComPtr<IDxcCompiler3> pCompiler,
151+
ExternalValidationHelper(CComPtr<IDxcCompiler> pCompiler,
63152
CComPtr<IDxcValidator> pValidator) {
64153
m_pCompiler = pCompiler;
65154
m_pValidator = pValidator;

lib/DxcSupport/dxcapi.extval.cpp

Lines changed: 76 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,42 @@
77
namespace dxc {
88

99
HRESULT STDMETHODCALLTYPE ExternalValidationHelper::Compile(
10+
_In_ IDxcBlob *pSource, // Source text to compile.
11+
_In_opt_z_ LPCWSTR pSourceName, // Optional file name for pSource. Used
12+
// in errors and include handlers.
13+
_In_opt_z_ LPCWSTR pEntryPoint, // Entry point name.
14+
_In_z_ LPCWSTR pTargetProfile, // Shader profile to compile.
15+
_In_opt_count_(argCount)
16+
LPCWSTR *pArguments, // Array of pointers to arguments.
17+
_In_ UINT32 argCount, // Number of arguments.
18+
_In_count_(defineCount) const DxcDefine *pDefines, // Array of defines.
19+
_In_ UINT32 defineCount, // Number of defines.
20+
_In_opt_ IDxcIncludeHandler
21+
*pIncludeHandler, // User-provided interface to handle #include
22+
// directives (optional).
23+
_COM_Outptr_ IDxcOperationResult *
24+
*ppResult // Compiler output status, buffer, and errors.
25+
) {
26+
// First, add -Vd to the compilation args
27+
UINT32 newArgCount = argCount + 1;
28+
std::vector<LPCWSTR> newArgs;
29+
newArgs.reserve(newArgCount);
30+
31+
// Copy existing args
32+
for (unsigned int i = 0; i < argCount; ++i) {
33+
newArgs.push_back(pArguments[i]);
34+
}
35+
36+
// Add an extra argument
37+
newArgs.push_back(L"-Vd");
38+
39+
return m_pCompiler->Compile(pSource, pSourceName, pEntryPoint, pTargetProfile,
40+
newArgs.data(), newArgCount, pDefines,
41+
defineCount, pIncludeHandler, ppResult);
42+
}
43+
44+
// Implement the IDxcCompiler3 interface Compile command
45+
HRESULT STDMETHODCALLTYPE ExternalValidationHelper3::Compile(
1046
_In_ const DxcBuffer *pSource, ///< Source text to compile.
1147
_In_opt_count_(argCount)
1248
LPCWSTR *pArguments, ///< Array of pointers to arguments.
@@ -30,8 +66,8 @@ HRESULT STDMETHODCALLTYPE ExternalValidationHelper::Compile(
3066
// Add an extra argument
3167
newArgs.push_back(L"-Vd");
3268

33-
return m_pCompiler->Compile(pSource, newArgs.data(), newArgCount,
34-
pIncludeHandler, riid, ppResult);
69+
return m_pCompiler3->Compile(pSource, newArgs.data(), newArgCount,
70+
pIncludeHandler, riid, ppResult);
3571
}
3672

3773
HRESULT DxcDllExtValidationLoader::CreateInstanceImpl(REFCLSID clsid,
@@ -45,29 +81,48 @@ HRESULT DxcDllExtValidationLoader::CreateInstanceImpl(REFCLSID clsid,
4581
// If there is intent to use an external dxil.dll
4682
if (!DxilDllPath.empty() && !DxilDllFailedToLoad()) {
4783
if (clsid == CLSID_DxcCompiler) {
48-
// Create compiler
49-
CComPtr<IDxcCompiler3> m_pCompiler;
50-
HRESULT hr = DxCompilerSupport.CreateInstance<IDxcCompiler3>(
51-
CLSID_DxcCompiler, &m_pCompiler);
52-
if (FAILED(hr))
53-
return hr;
5484

5585
// Create validator
5686
CComPtr<IDxcValidator> m_pValidator;
57-
hr = DxilExtValSupport.CreateInstance<IDxcValidator>(CLSID_DxcValidator,
58-
&m_pValidator);
59-
if (FAILED(hr))
60-
return hr;
87+
HRESULT ValHR = DxilExtValSupport.CreateInstance<IDxcValidator>(
88+
CLSID_DxcValidator, &m_pValidator);
89+
if (FAILED(ValHR))
90+
return ValHR;
6191

6292
// Wrap compiler + validator
63-
ExternalValidationHelper *evh = new (std::nothrow)
64-
ExternalValidationHelper(m_pCompiler, m_pValidator);
65-
if (!evh)
66-
return E_OUTOFMEMORY;
93+
// The wrapper should be selected based on the target interface
94+
if (riid == __uuidof(IDxcCompiler3)) {
95+
// Create compiler
96+
CComPtr<IDxcCompiler3> m_pCompiler3;
97+
HRESULT hr = DxCompilerSupport.CreateInstance<IDxcCompiler3>(
98+
CLSID_DxcCompiler, &m_pCompiler3);
99+
if (FAILED(hr))
100+
return hr;
101+
ExternalValidationHelper3 *evh = new (std::nothrow)
102+
ExternalValidationHelper3(m_pCompiler3, m_pValidator);
103+
if (!evh)
104+
return E_OUTOFMEMORY;
105+
106+
hr = evh->QueryInterface(riid, reinterpret_cast<void **>(pResult));
107+
evh->Release();
108+
return hr;
109+
} else if (riid == __uuidof(IDxcCompiler)) {
110+
// Create compiler
111+
CComPtr<IDxcCompiler> m_pCompiler;
112+
HRESULT hr = DxCompilerSupport.CreateInstance<IDxcCompiler>(
113+
CLSID_DxcCompiler, &m_pCompiler);
114+
if (FAILED(hr))
115+
return hr;
116+
ExternalValidationHelper *evh = new (std::nothrow)
117+
ExternalValidationHelper(m_pCompiler, m_pValidator);
118+
if (!evh)
119+
return E_OUTOFMEMORY;
120+
121+
hr = evh->QueryInterface(riid, reinterpret_cast<void **>(pResult));
122+
evh->Release();
123+
return hr;
124+
}
67125

68-
hr = evh->QueryInterface(riid, reinterpret_cast<void **>(pResult));
69-
evh->Release();
70-
return hr;
71126
} else if (clsid == CLSID_DxcValidator) {
72127
return DxilExtValSupport.CreateInstance<IDxcValidator>(
73128
clsid, reinterpret_cast<IDxcValidator **>(pResult));
@@ -105,8 +160,8 @@ HRESULT DxcDllExtValidationLoader::CreateInstance2Impl(IMalloc *pMalloc,
105160
return hr;
106161

107162
// Wrap compiler + validator
108-
ExternalValidationHelper *evh = new (std::nothrow)
109-
ExternalValidationHelper(m_pCompiler, m_pValidator);
163+
ExternalValidationHelper3 *evh = new (std::nothrow)
164+
ExternalValidationHelper3(m_pCompiler, m_pValidator);
110165
if (!evh)
111166
return E_OUTOFMEMORY;
112167

tools/clang/tools/dxclib/dxc.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,8 @@ int DxcContext::Compile() {
872872
outputPDBPath += pDebugName.m_pData;
873873
}
874874
} else {
875-
if (m_dxcSupport.DxilDllFailedToLoad()) {
875+
// if there is no intent to validate externally
876+
if (m_dxcSupport.GetDxilDllPath().empty()) {
876877
IFT(pCompiler->Compile(
877878
pSource, StringRefWide(m_Opts.InputFile),
878879
StringRefWide(m_Opts.EntryPoint), StringRefWide(TargetProfile),

utils/hct/hcttest.cmd

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,6 @@ if "%TEST_USE_LIT%"=="1" (
351351
)
352352
set RES_EXEC=!ERRORLEVEL!
353353
)
354-
355-
356354
)
357355

358356
rem No other tests to run - skip copying and move on to report the results

0 commit comments

Comments
 (0)