Skip to content

Commit 0fc5d9e

Browse files
committed
Reading from rc file now
1 parent 003bfd7 commit 0fc5d9e

File tree

6 files changed

+958
-904
lines changed

6 files changed

+958
-904
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#include <windows.h>
22

33
ShaderOpArithTable.xml DATASOURCE_XML "ShaderOpArithTable.xml"
4+
LongVectorOp DATASOURCE_XML "LongVectorOp.xml"

tools/clang/unittests/HLSLExec/HlslExecTestUtils.cpp

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ static UINT getD3D12SDKVersion(std::wstring SDKPath) {
7777
return SDKVersion;
7878
}
7979

80+
// Simple wrapper to free the loaded module on scope exit.
81+
struct DllWrapper {
82+
HMODULE Module = NULL; // NOLINT
83+
84+
~DllWrapper() { Close(); }
85+
86+
void Close() {
87+
if (Module) {
88+
FreeLibrary(Module);
89+
Module = NULL;
90+
}
91+
}
92+
};
93+
8094
static bool createDevice(
8195
ID3D12Device **D3DDevice, D3D_SHADER_MODEL TestModel, bool SkipUnsupported,
8296
std::function<HRESULT(IUnknown *, D3D_FEATURE_LEVEL, REFIID, void **)>
@@ -108,20 +122,7 @@ static bool createDevice(
108122
// load. To force this to be used, we make sure that this DLL is loaded
109123
// before attempting to create the device.
110124

111-
struct WarpDll {
112-
HMODULE Module = NULL; // NOLINT
113-
114-
~WarpDll() { Close(); }
115-
116-
void Close() {
117-
if (Module) {
118-
FreeLibrary(Module);
119-
Module = NULL;
120-
}
121-
}
122-
};
123-
124-
WarpDll ExplicitlyLoadedWarpDll;
125+
DllWrapper ExplicitlyLoadedWarpDll;
125126
WEX::Common::String WarpDllPath;
126127
if (SUCCEEDED(WEX::TestExecution::RuntimeParameters::TryGetValue(
127128
L"WARP_DLL", WarpDllPath))) {
@@ -212,6 +213,53 @@ static bool createDevice(
212213
return true;
213214
}
214215

216+
// Read a resource embedded into a dll via an .rc file and wrap it in a DXC
217+
// read-only stream
218+
void readEmbeddedHlslDataIntoNewStream(
219+
LPCWSTR ResourceName, // Resource name in rc file. e.g. L"LongVectorOp"
220+
IStream **TestXML, dxc::SpecificDllLoader &Support) {
221+
222+
DllWrapper Dll;
223+
Dll.Module = LoadLibraryEx(TEXT("ExecHLSLTests.dll"), nullptr,
224+
LOAD_LIBRARY_AS_DATAFILE);
225+
226+
// 1. Locate the resource
227+
HRSRC ResInfo = FindResourceW(Dll.Module, ResourceName, L"DATASOURCE_XML");
228+
if (!ResInfo)
229+
VERIFY_SUCCEEDED(HRESULT_FROM_WIN32(::GetLastError()));
230+
231+
// 2. Load the resource
232+
HGLOBAL ResData = LoadResource(Dll.Module, ResInfo);
233+
if (!ResData)
234+
VERIFY_SUCCEEDED(HRESULT_FROM_WIN32(::GetLastError()));
235+
VERIFY_SUCCEEDED(HRESULT_FROM_WIN32(::GetLastError()));
236+
237+
// 3. Access the resource bytes
238+
const void *Data = LockResource(ResData);
239+
VERIFY_IS_NOT_NULL(Data);
240+
241+
// Sanity
242+
const DWORD Size = SizeofResource(Dll.Module, ResInfo);
243+
VERIFY_IS_FALSE(0 == Size);
244+
245+
VERIFY_SUCCEEDED(
246+
Support.InitializeForDll(dxc::kDxCompilerLib, "DxcCreateInstance"));
247+
248+
CComPtr<IDxcLibrary> Library;
249+
VERIFY_SUCCEEDED(Support.CreateInstance(CLSID_DxcLibrary, &Library));
250+
251+
// 4. Create a DXC blob from the resource data
252+
CComPtr<IDxcBlobEncoding> Blob;
253+
VERIFY_SUCCEEDED(
254+
Library->CreateBlobWithEncodingFromPinned(Data, Size, CP_UTF8, &Blob));
255+
256+
// 5. Create a read-only stream from the DXC blob
257+
CComPtr<IStream> Stream;
258+
VERIFY_SUCCEEDED(Library->CreateStreamFromBlobReadOnly(Blob, &Stream));
259+
260+
*TestXML = Stream.Detach();
261+
}
262+
215263
void readHlslDataIntoNewStream(LPCWSTR RelativePath, IStream **Stream,
216264
dxc::SpecificDllLoader &Support) {
217265
VERIFY_SUCCEEDED(

tools/clang/unittests/HLSLExec/HlslExecTestUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class D3D12SDKSelector {
3939
bool SkipUnsupported = true);
4040
};
4141

42+
void readEmbeddedHlslDataIntoNewStream(LPCWSTR ResourceName, IStream **Stream,
43+
dxc::SpecificDllLoader &Support);
4244
void readHlslDataIntoNewStream(LPCWSTR RelativePath, IStream **Stream,
4345
dxc::SpecificDllLoader &Support);
4446

0 commit comments

Comments
 (0)