Skip to content

Commit c8b6248

Browse files
committed
address Tex
1 parent 7daf141 commit c8b6248

File tree

2 files changed

+25
-34
lines changed

2 files changed

+25
-34
lines changed

include/dxc/Support/dxcapi.extval.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ class DxcDllExtValidationLoader : public DllLoader {
1414
dxc::SpecificDllLoader DxCompilerSupport;
1515
dxc::SpecificDllLoader DxilExtValSupport;
1616
std::string DxilDllPath;
17-
int FailureReason = 0;
17+
enum {
18+
FailedNone = 0,
19+
FailedCompilerLoad,
20+
FailedDxilPath,
21+
FailedDxilLoad,
22+
} FailureReason = FailedNone;
1823

1924
public:
2025
std::string getDxilDllPath() { return DxilDllPath; }

lib/DxcSupport/dxcapi.extval.cpp

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class ExternalValidationCompiler : public IDxcCompiler2, public IDxcCompiler3 {
227227
IFR(Helper.initialize(Validator, &Arguments, &ArgCount, TargetProfile));
228228

229229
CComPtr<IDxcOperationResult> CompileResult;
230-
IFR(castUnsafe<IDxcCompiler>()->Compile(
230+
IFR(cast<IDxcCompiler>()->Compile(
231231
Source, SourceName, EntryPoint, TargetProfile, Arguments, ArgCount,
232232
Defines, DefineCount, IncludeHandler, &CompileResult));
233233
HRESULT CompileHR;
@@ -243,14 +243,14 @@ class ExternalValidationCompiler : public IDxcCompiler2, public IDxcCompiler3 {
243243
UINT32 ArgCount, const DxcDefine *Defines, UINT32 DefineCount,
244244
IDxcIncludeHandler *IncludeHandler,
245245
IDxcOperationResult **ResultObject) override {
246-
return castUnsafe<IDxcCompiler>()->Preprocess(
247-
Source, SourceName, Arguments, ArgCount, Defines, DefineCount,
248-
IncludeHandler, ResultObject);
246+
return cast<IDxcCompiler>()->Preprocess(Source, SourceName, Arguments,
247+
ArgCount, Defines, DefineCount,
248+
IncludeHandler, ResultObject);
249249
}
250250

251251
HRESULT STDMETHODCALLTYPE
252252
Disassemble(IDxcBlob *Source, IDxcBlobEncoding **Disassembly) override {
253-
return castUnsafe<IDxcCompiler>()->Disassemble(Source, Disassembly);
253+
return cast<IDxcCompiler>()->Disassemble(Source, Disassembly);
254254
}
255255

256256
// IDxcCompiler2 implementation
@@ -270,7 +270,7 @@ class ExternalValidationCompiler : public IDxcCompiler2, public IDxcCompiler3 {
270270
IFR(Helper.initialize(Validator, &Arguments, &ArgCount, TargetProfile));
271271

272272
CComPtr<IDxcOperationResult> CompileResult;
273-
IFR(castUnsafe<IDxcCompiler2>()->CompileWithDebug(
273+
IFR(cast<IDxcCompiler2>()->CompileWithDebug(
274274
Source, SourceName, EntryPoint, TargetProfile, Arguments, ArgCount,
275275
pDefines, DefineCount, IncludeHandler, &CompileResult, DebugBlobName,
276276
DebugBlob));
@@ -294,16 +294,16 @@ class ExternalValidationCompiler : public IDxcCompiler2, public IDxcCompiler3 {
294294
Helper.initialize(Validator, &Arguments, &ArgCount);
295295

296296
CComPtr<IDxcResult> CompileResult;
297-
IFR(castUnsafe<IDxcCompiler3>()->Compile(Source, Arguments, ArgCount,
298-
IncludeHandler,
299-
IID_PPV_ARGS(&CompileResult)));
297+
IFR(cast<IDxcCompiler3>()->Compile(Source, Arguments, ArgCount,
298+
IncludeHandler,
299+
IID_PPV_ARGS(&CompileResult)));
300300

301301
return Helper.doValidation(CompileResult, Riid, ResultObject);
302302
}
303303

304304
HRESULT STDMETHODCALLTYPE Disassemble(const DxcBuffer *Object, REFIID Riid,
305305
LPVOID *ResultObject) override {
306-
return castUnsafe<IDxcCompiler3>()->Disassemble(Object, Riid, ResultObject);
306+
return cast<IDxcCompiler3>()->Disassemble(Object, Riid, ResultObject);
307307
}
308308

309309
private:
@@ -318,26 +318,12 @@ class ExternalValidationCompiler : public IDxcCompiler2, public IDxcCompiler3 {
318318
CComPtr<IUnknown> Compiler;
319319
DXC_MICROCOM_TM_REF_FIELDS()
320320

321-
// Cast current compiler interface pointer. Used from methods of the
322-
// associated interface, assuming that the current compiler interface is
323-
// correct for the method call.
324-
// This will either be casting to the original interface retrieved by
325-
// QueryInterface, or to one from which that interface derives.
326-
template <typename T> T *castSafe() const {
327-
// Compare stored IID with the IID of T
328-
if (CompilerIID == __uuidof(T)) {
329-
// Safe to cast because the underlying compiler object in
330-
// Compiler originally implemented the interface T
331-
return static_cast<T *>(Compiler.p);
332-
}
333-
334-
return nullptr;
335-
}
336-
337-
template <typename T> T *castUnsafe() {
338-
if (T *Safe = castSafe<T>())
339-
return Safe;
340-
return static_cast<T *>(Compiler.p);
321+
template <typename T> CComPtr<T> cast() const {
322+
CComPtr<T> Result;
323+
if (Compiler)
324+
Compiler->QueryInterface(__uuidof(T), reinterpret_cast<void **>(&Result));
325+
assert(Result);
326+
return Result;
341327
}
342328
};
343329
} // namespace
@@ -426,7 +412,7 @@ DxcDllExtValidationLoader::initialize() {
426412
DxCompilerSupport.InitializeForDll(kDxCompilerLib, "DxcCreateInstance");
427413
// if dxcompiler.dll fails to load, return the failed HRESULT
428414
if (FAILED(Result)) {
429-
FailureReason = 1;
415+
FailureReason = FailedCompilerLoad;
430416
return Result;
431417
}
432418

@@ -442,14 +428,14 @@ DxcDllExtValidationLoader::initialize() {
442428

443429
// Check if path is absolute and exists
444430
if (!DllPath.is_absolute() || !std::filesystem::exists(DllPath)) {
445-
FailureReason = 2;
431+
FailureReason = FailedDxilPath;
446432
return E_INVALIDARG;
447433
}
448434

449435
Result = DxilExtValSupport.InitializeForDll(DxilDllPath.c_str(),
450436
"DxcCreateInstance");
451437
if (FAILED(Result)) {
452-
FailureReason = 3;
438+
FailureReason = FailedDxilLoad;
453439
return Result;
454440
}
455441

0 commit comments

Comments
 (0)