-
Notifications
You must be signed in to change notification settings - Fork 721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a test dxil lib for testing loadability #5952
Changes from 1 commit
3ae2a52
496b071
df3fdf7
ea7d6fc
740fb27
cab6842
d00cb4d
bda8263
297c41e
b080b8e
63d46cd
bd3e013
f0e0cb2
b93e5aa
eac1e7d
d67697a
ba0d7c4
1c95008
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Builds a testing version of dxil.dll | ||
|
||
set(SHARED_LIBRARY TRUE) | ||
|
||
set(LLVM_LINK_COMPONENTS | ||
${LLVM_TARGETS_TO_BUILD} | ||
BitWriter | ||
DxcSupport | ||
DxilContainer | ||
DxilRootSignature | ||
HLSL | ||
MSSupport | ||
Support | ||
TransformUtils | ||
) | ||
|
||
include_directories( | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
${LLVM_BINARY_DIR}/projects/include | ||
) | ||
|
||
set(SOURCES | ||
DxilLib.cpp | ||
DxilLib.def | ||
DxilContainerBuilder.cpp | ||
DxilValidator.cpp | ||
) | ||
|
||
add_llvm_library(testdxil SHARED ${SOURCES}) | ||
|
||
if(WIN32) | ||
add_dependencies(testdxil DxcRuntimeEtw) | ||
endif(WIN32) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/////////////////////////////////////////////////////////////////////////////// | ||
// // | ||
// dxcontainerbuilder.cpp // | ||
// Copyright (C) Microsoft Corporation. All rights reserved. // | ||
// This file is distributed under the University of Illinois Open Source // | ||
// License. See LICENSE.TXT for details. // | ||
// // | ||
// Implements the Dxil Container Builder // | ||
// // | ||
/////////////////////////////////////////////////////////////////////////////// | ||
|
||
#include "dxc/DxilContainer/DxcContainerBuilder.h" | ||
#include "dxc/DxilContainer/DxilContainer.h" | ||
#include "dxc/Support/ErrorCodes.h" | ||
#include "dxc/Support/FileIOHelper.h" | ||
#include "dxc/Support/Global.h" | ||
#include "dxc/Support/WinIncludes.h" | ||
#include "dxc/Support/dxcapi.impl.h" | ||
#include "dxc/dxcapi.h" | ||
|
||
#include <algorithm> | ||
|
||
using namespace hlsl; | ||
|
||
HRESULT CreateDxcContainerBuilder(_In_ REFIID riid, _Out_ LPVOID *ppv) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't this be implemented in DxilLib.cpp, since we really aren't supplying another implementation here? One might almost mix it up with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There were some compilation errors when I tried to do this before that had to do with conflicting defines. I'll take another run at it. |
||
// Call dxil.dll's containerbuilder | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this comment accurate? Isn't this creating the local container builder instead? |
||
*ppv = nullptr; | ||
CComPtr<DxcContainerBuilder> Result( | ||
DxcContainerBuilder::Alloc(DxcGetThreadMallocNoRef())); | ||
IFROOM(Result.p); | ||
Result->Init(); | ||
return Result->QueryInterface(riid, ppv); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/////////////////////////////////////////////////////////////////////////////// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you mind renaming DxilLib.* files to TestDxilLib.*? I am often searching through the whole code base and since this code is similar to the actual DxilLib.cpp it would be nice to have it under a different name so it can be clearly seen in the search results that this is the test dll. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do |
||
// // | ||
// DxilLib.cpp // | ||
// Copyright (C) Microsoft. All rights reserved. // | ||
// This file is distributed under the University of Illinois Open Source // | ||
// License. See LICENSE.TXT for details. // | ||
// // | ||
// Implements the DxcCreateInstance, DxcCreateInstance2, and DllMain // | ||
// functions for the dxil library module // | ||
// // | ||
/////////////////////////////////////////////////////////////////////////////// | ||
|
||
#include "dxc/Support/Global.h" | ||
#include "dxc/Support/WinIncludes.h" | ||
#include "llvm/Support/FileSystem.h" | ||
#include "llvm/Support/ManagedStatic.h" | ||
#include <algorithm> | ||
#ifdef _WIN32 | ||
#include "Tracing/DxcRuntimeEtw.h" | ||
#include "dxc/Tracing/dxcetw.h" | ||
#endif | ||
|
||
#ifdef _WIN32 | ||
#define DXC_API_IMPORT | ||
#else | ||
#define DXC_API_IMPORT __attribute__((visibility("default"))) | ||
#endif | ||
|
||
#include "dxc/dxcisense.h" | ||
#include "dxc/dxctools.h" | ||
|
||
HRESULT CreateDxcValidator(_In_ REFIID riid, _Out_ LPVOID *ppv); | ||
HRESULT CreateDxcContainerBuilder(_In_ REFIID riid, _Out_ LPVOID *ppv); | ||
|
||
// C++ exception specification ignored except to indicate a function is not | ||
// __declspec(nothrow) | ||
static HRESULT InitMaybeFail() throw() { | ||
HRESULT hr; | ||
bool memSetup = false; | ||
IFC(DxcInitThreadMalloc()); | ||
DxcSetThreadMallocToDefault(); | ||
memSetup = true; | ||
if (::llvm::sys::fs::SetupPerThreadFileSystem()) { | ||
hr = E_FAIL; | ||
goto Cleanup; | ||
} | ||
Cleanup: | ||
if (FAILED(hr)) { | ||
if (memSetup) { | ||
DxcClearThreadMalloc(); | ||
DxcCleanupThreadMalloc(); | ||
} | ||
} else { | ||
DxcClearThreadMalloc(); | ||
} | ||
return hr; | ||
} | ||
|
||
#if defined(LLVM_ON_UNIX) | ||
HRESULT __attribute__((constructor)) DllMain() { return InitMaybeFail(); } | ||
|
||
void __attribute__((destructor)) DllShutdown() { | ||
DxcSetThreadMallocToDefault(); | ||
::llvm::sys::fs::CleanupPerThreadFileSystem(); | ||
::llvm::llvm_shutdown(); | ||
DxcClearThreadMalloc(); | ||
DxcCleanupThreadMalloc(); | ||
} | ||
#else | ||
|
||
#pragma warning(disable : 4290) | ||
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD Reason, LPVOID) { | ||
if (Reason == DLL_PROCESS_ATTACH) { | ||
EventRegisterMicrosoft_Windows_DxcRuntime_API(); | ||
DxcRuntimeEtw_DxcRuntimeInitialization_Start(); | ||
HRESULT hr = InitMaybeFail(); | ||
DxcRuntimeEtw_DxcRuntimeInitialization_Stop(hr); | ||
if (FAILED(hr)) { | ||
EventUnregisterMicrosoft_Windows_DxcRuntime_API(); | ||
return hr; | ||
} | ||
} else if (Reason == DLL_PROCESS_DETACH) { | ||
DxcRuntimeEtw_DxcRuntimeShutdown_Start(); | ||
DxcSetThreadMallocToDefault(); | ||
::llvm::sys::fs::CleanupPerThreadFileSystem(); | ||
::llvm::llvm_shutdown(); | ||
DxcClearThreadMalloc(); | ||
DxcCleanupThreadMalloc(); | ||
DxcRuntimeEtw_DxcRuntimeShutdown_Stop(S_OK); | ||
EventUnregisterMicrosoft_Windows_DxcRuntime_API(); | ||
} | ||
|
||
return TRUE; | ||
} | ||
|
||
void *__CRTDECL operator new(std::size_t size) { | ||
void *ptr = DxcNew(size); | ||
if (ptr == nullptr) | ||
throw std::bad_alloc(); | ||
return ptr; | ||
} | ||
void *__CRTDECL operator new(std::size_t size, | ||
const std::nothrow_t ¬hrow_value) throw() { | ||
return DxcNew(size); | ||
} | ||
void __CRTDECL operator delete(void *ptr) throw() { DxcDelete(ptr); } | ||
void __CRTDECL operator delete(void *ptr, | ||
const std::nothrow_t ¬hrow_constant) throw() { | ||
DxcDelete(ptr); | ||
} | ||
#endif | ||
|
||
static HRESULT ThreadMallocDxcCreateInstance(_In_ REFCLSID rclsid, | ||
_In_ REFIID riid, | ||
_Out_ LPVOID *ppv) { | ||
*ppv = nullptr; | ||
if (IsEqualCLSID(rclsid, CLSID_DxcValidator)) { | ||
return CreateDxcValidator(riid, ppv); | ||
} | ||
if (IsEqualCLSID(rclsid, CLSID_DxcContainerBuilder)) { | ||
return CreateDxcContainerBuilder(riid, ppv); | ||
} | ||
return REGDB_E_CLASSNOTREG; | ||
} | ||
|
||
DXC_API_IMPORT HRESULT __stdcall DxcCreateInstance(_In_ REFCLSID rclsid, | ||
_In_ REFIID riid, | ||
_Out_ LPVOID *ppv) { | ||
HRESULT hr = S_OK; | ||
DxcEtw_DXCompilerCreateInstance_Start(); | ||
DxcThreadMalloc TM(nullptr); | ||
hr = ThreadMallocDxcCreateInstance(rclsid, riid, ppv); | ||
DxcEtw_DXCompilerCreateInstance_Stop(hr); | ||
return hr; | ||
} | ||
|
||
DXC_API_IMPORT HRESULT __stdcall DxcCreateInstance2(_In_ IMalloc *pMalloc, | ||
_In_ REFCLSID rclsid, | ||
_In_ REFIID riid, | ||
_Out_ LPVOID *ppv) { | ||
if (ppv == nullptr) { | ||
return E_POINTER; | ||
} | ||
HRESULT hr = S_OK; | ||
DxcEtw_DXCompilerCreateInstance_Start(); | ||
DxcThreadMalloc TM(pMalloc); | ||
hr = ThreadMallocDxcCreateInstance(rclsid, riid, ppv); | ||
DxcEtw_DXCompilerCreateInstance_Stop(hr); | ||
return hr; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
LIBRARY testdxil | ||
|
||
EXPORTS | ||
DxcCreateInstance | ||
DxcCreateInstance2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is incorrect, it does not really implement a container builder. Any reason why this is not part of the DxilLib.cpp?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. The reason it's not part of DxilLib.cpp is because of some inclusions this requires that confuse the code in DxilLib.cpp. I spent a little while trying to resolve them, but decided it wasn't worth it as this is the structure of similar code elsewhere likely for the same reason.