@@ -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+
8094static 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+
215263void readHlslDataIntoNewStream (LPCWSTR RelativePath, IStream **Stream,
216264 dxc::SpecificDllLoader &Support) {
217265 VERIFY_SUCCEEDED (
0 commit comments