Skip to content

Commit 33c88f9

Browse files
committed
address Tex, and make a flawed attempt at writing a unit test
1 parent 3700bfd commit 33c88f9

File tree

4 files changed

+59
-14
lines changed

4 files changed

+59
-14
lines changed

include/dxc/Support/dxcapi.extval.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
#include "dxc/Support/dxcapi.use.h"
2-
#include "dxc/dxcapi.h"
2+
#include <string>
33

44
class DxcDllExtValidationSupport : public dxc::DxcDllSupport {
55
// DxcDllExtValidationSupport manages the
66
// lifetime of dxcompiler.dll, while the member, m_DxilSupport,
77
// manages the lifetime of dxil.dll
8+
protected:
89
dxc::DxcDllSupport DxilSupport;
910

1011
std::string DxilDllPath;
12+
13+
HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) override;
14+
15+
public:
1116
// override DxcDllSupport's implementation of InitializeInternal,
1217
// adding the environment variable value check for a path to a dxil.dll
1318

1419
std::string GetDxilDllPath() { return DxilDllPath; }
1520
bool DxilDllFailedToLoad() {
1621
return !DxilDllPath.empty() && !DxilSupport.IsEnabled();
1722
}
18-
19-
HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName);
23+
24+
void Cleanup() override {
25+
DxilSupport.Cleanup();
26+
DxcDllSupport::Cleanup();
27+
}
28+
29+
HMODULE Detach() override {
30+
// Can't Detach and return a handle for DxilSupport. Cleanup() instead.
31+
DxilSupport.Cleanup();
32+
return DxcDllSupport::Detach();
33+
}
2034
};

include/dxc/Support/dxcapi.use.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
#define __DXCAPI_USE_H__
1414

1515
#include "dxc/dxcapi.h"
16-
#include <dxc/Support/Global.h> // for hresult handling with DXC_FAILED
17-
#include <filesystem> // C++17 and later
1816

1917
namespace dxc {
2018

@@ -28,7 +26,7 @@ class DxcDllSupport {
2826
DxcCreateInstanceProc m_createFn;
2927
DxcCreateInstance2Proc m_createFn2;
3028

31-
HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) {
29+
virtual HRESULT InitializeInternal(LPCSTR dllName, LPCSTR fnName) {
3230
if (m_dll != nullptr)
3331
return S_OK;
3432

@@ -89,11 +87,11 @@ class DxcDllSupport {
8987

9088
virtual ~DxcDllSupport() { Cleanup(); }
9189

92-
HRESULT virtual Initialize() {
90+
HRESULT Initialize() {
9391
return InitializeInternal(kDxCompilerLib, "DxcCreateInstance");
9492
}
9593

96-
HRESULT virtual InitializeForDll(LPCSTR dll, LPCSTR entryPoint) {
94+
HRESULT InitializeForDll(LPCSTR dll, LPCSTR entryPoint) {
9795
return InitializeInternal(dll, entryPoint);
9896
}
9997

@@ -102,7 +100,7 @@ class DxcDllSupport {
102100
return CreateInstance(clsid, __uuidof(TInterface), (IUnknown **)pResult);
103101
}
104102

105-
HRESULT virtual CreateInstance(REFCLSID clsid, REFIID riid,
103+
virtual HRESULT CreateInstance(REFCLSID clsid, REFIID riid,
106104
IUnknown **pResult) {
107105
if (pResult == nullptr)
108106
return E_POINTER;
@@ -119,7 +117,7 @@ class DxcDllSupport {
119117
(IUnknown **)pResult);
120118
}
121119

122-
HRESULT virtual CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid,
120+
virtual HRESULT CreateInstance2(IMalloc *pMalloc, REFCLSID clsid, REFIID riid,
123121
IUnknown **pResult) {
124122
if (pResult == nullptr)
125123
return E_POINTER;
@@ -144,7 +142,7 @@ class DxcDllSupport {
144142
return true;
145143
}
146144

147-
void virtual Cleanup() {
145+
virtual void Cleanup() {
148146
if (m_dll != nullptr) {
149147
m_createFn = nullptr;
150148
m_createFn2 = nullptr;
@@ -157,7 +155,7 @@ class DxcDllSupport {
157155
}
158156
}
159157

160-
HMODULE virtual Detach() {
158+
virtual HMODULE Detach() {
161159
HMODULE hModule = m_dll;
162160
m_dll = nullptr;
163161
return hModule;

lib/DxcSupport/dxcapi.extval.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#include "dxc/Support/WinIncludes.h"
2+
#include <dxc/Support/Global.h> // for hresult handling with DXC_FAILED
3+
#include <filesystem> // C++17 and later
24
// WinIncludes must come before dxcapi.extval.h
35
#include "dxc/Support/dxcapi.extval.h"
46

7+
58
HRESULT DxcDllExtValidationSupport::InitializeInternal(LPCSTR dllName,
69
LPCSTR fnName) {
710
// Load dxcompiler.dll
8-
HRESULT result = InitializeForDll(dllName, fnName);
11+
HRESULT result = DxcDllSupport::InitializeInternal(dllName, fnName);
912
// if dxcompiler.dll fails to load, return the failed HRESULT
1013
if (DXC_FAILED(result)) {
1114
return result;

tools/clang/unittests/HLSL/ValidationTest.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
#include "dxc/Support/Global.h"
3333

3434
#include "dxc/DXIL/DxilShaderModel.h"
35-
#include "dxc/Test/DxcTestUtils.h"
35+
#include "dxc/Test/DxcTestUtils.h" // includes dxcapi.use.h
36+
#include "dxc/Support/dxcapi.extval.h"
3637
#include "dxc/Test/HlslTestUtils.h"
3738

3839
using namespace std;
@@ -299,6 +300,7 @@ class ValidationTest : public ::testing::Test {
299300
TEST_METHOD(ValidatePrintfNotAllowed)
300301

301302
TEST_METHOD(ValidateWithHash)
303+
TEST_METHOD(ValidateWithExternalValidator)
302304
TEST_METHOD(ValidateVersionNotAllowed)
303305
TEST_METHOD(ValidatePreviewBypassHash)
304306
TEST_METHOD(ValidateProgramVersionAgainstDxilModule)
@@ -328,6 +330,7 @@ class ValidationTest : public ::testing::Test {
328330
TEST_METHOD(WrongPSVVersion)
329331

330332
dxc::DxcDllSupport m_dllSupport;
333+
DxcDllExtValidationSupport m_dllExtSupport;
331334
VersionSupportInfo m_ver;
332335

333336
void TestCheck(LPCWSTR name) {
@@ -4207,6 +4210,33 @@ TEST_F(ValidationTest, ValidateWithHash) {
42074210
VERIFY_ARE_EQUAL(memcmp(Result, pHeader->Hash.Digest, sizeof(Result)), 0);
42084211
}
42094212

4213+
TEST_F(ValidationTest, ValidateWithExternalValidator) {
4214+
if (!m_dllExtSupport.IsEnabled()) {
4215+
VERIFY_SUCCEEDED(m_dllExtSupport.Initialize());
4216+
}
4217+
4218+
if (m_ver.SkipDxilVersion(1, ShaderModel::kHighestReleasedMinor))
4219+
return;
4220+
CComPtr<IDxcBlob> pProgram;
4221+
CompileSource("float4 main(float a:A, float b:B) : SV_Target { return 1; }",
4222+
"ps_6_0", &pProgram);
4223+
4224+
CComPtr<IDxcValidator> pValidator;
4225+
CComPtr<IDxcOperationResult> pResult;
4226+
unsigned Flags = 0;
4227+
VERIFY_SUCCEEDED(
4228+
m_dllExtSupport.CreateInstance(CLSID_DxcValidator, &pValidator));
4229+
// With hash.
4230+
VERIFY_SUCCEEDED(pValidator->Validate(pProgram, Flags, &pResult));
4231+
// Make sure the validation was successful.
4232+
HRESULT status;
4233+
VERIFY_IS_NOT_NULL(pResult);
4234+
CComPtr<IDxcBlob> pValidationOutput;
4235+
pResult->GetStatus(&status);
4236+
VERIFY_SUCCEEDED(status);
4237+
pResult->GetResult(&pValidationOutput);
4238+
}
4239+
42104240
TEST_F(ValidationTest, ValidatePreviewBypassHash) {
42114241
if (m_ver.SkipDxilVersion(1, ShaderModel::kHighestMinor))
42124242
return;

0 commit comments

Comments
 (0)