DxilContainerTest.cpp 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // DxilContainerTest.cpp //
  4. // Copyright (C) Microsoft Corporation. All rights reserved. //
  5. // This file is distributed under the University of Illinois Open Source //
  6. // License. See LICENSE.TXT for details. //
  7. // //
  8. // Provides tests for container formatting and validation. //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #ifndef UNICODE
  12. #define UNICODE
  13. #endif
  14. #include <memory>
  15. #include <vector>
  16. #include <string>
  17. #include <tuple>
  18. #include <cassert>
  19. #include <sstream>
  20. #include <algorithm>
  21. #include <unordered_set>
  22. #include "dxc/Support/WinIncludes.h"
  23. #include "dxc/dxcapi.h"
  24. #include <atlfile.h>
  25. #include "HLSLTestData.h"
  26. #include "WexTestClass.h"
  27. #include "HlslTestUtils.h"
  28. #include "DxcTestUtils.h"
  29. #include "dxc/Support/Global.h"
  30. #include "dxc/Support/dxcapi.use.h"
  31. #include "dxc/Support/HLSLOptions.h"
  32. #include "dxc/HLSL/DxilContainer.h"
  33. #include "dxc/HLSL/DxilRuntimeReflection.h"
  34. #include "dxc/HLSL/DxilShaderFlags.h"
  35. #include "dxc/HLSL/DxilUtil.h"
  36. #include <fstream>
  37. #include <filesystem>
  38. #include <chrono>
  39. #include <d3dcompiler.h>
  40. #pragma comment(lib, "d3dcompiler.lib")
  41. #include <codecvt>
  42. using namespace std;
  43. using namespace hlsl_test;
  44. using namespace std::experimental::filesystem;
  45. static uint8_t MaskCount(uint8_t V) {
  46. DXASSERT_NOMSG(0 <= V && V <= 0xF);
  47. static const uint8_t Count[16] = {
  48. 0, 1, 1, 2,
  49. 1, 2, 2, 3,
  50. 1, 2, 2, 3,
  51. 2, 3, 3, 4
  52. };
  53. return Count[V];
  54. }
  55. class DxilContainerTest {
  56. public:
  57. BEGIN_TEST_CLASS(DxilContainerTest)
  58. TEST_CLASS_PROPERTY(L"Parallel", L"true")
  59. TEST_METHOD_PROPERTY(L"Priority", L"0")
  60. END_TEST_CLASS()
  61. TEST_CLASS_SETUP(InitSupport);
  62. TEST_METHOD(CompileWhenDebugSourceThenSourceMatters)
  63. TEST_METHOD(CompileWhenOkThenCheckRDAT)
  64. TEST_METHOD(CompileWhenOkThenCheckRDAT2)
  65. TEST_METHOD(CompileWhenOkThenCheckReflection1)
  66. TEST_METHOD(CompileWhenOKThenIncludesFeatureInfo)
  67. TEST_METHOD(CompileWhenOKThenIncludesSignatures)
  68. TEST_METHOD(CompileWhenSigSquareThenIncludeSplit)
  69. TEST_METHOD(DisassemblyWhenMissingThenFails)
  70. TEST_METHOD(DisassemblyWhenBCInvalidThenFails)
  71. TEST_METHOD(DisassemblyWhenInvalidThenFails)
  72. TEST_METHOD(DisassemblyWhenValidThenOK)
  73. TEST_METHOD(ValidateFromLL_Abs2)
  74. TEST_METHOD(DxilContainerUnitTest)
  75. TEST_METHOD(ReflectionMatchesDXBC_CheckIn)
  76. BEGIN_TEST_METHOD(ReflectionMatchesDXBC_Full)
  77. TEST_METHOD_PROPERTY(L"Priority", L"1")
  78. END_TEST_METHOD()
  79. dxc::DxcDllSupport m_dllSupport;
  80. VersionSupportInfo m_ver;
  81. void CreateBlobPinned(_In_bytecount_(size) LPCVOID data, SIZE_T size,
  82. UINT32 codePage, _Outptr_ IDxcBlobEncoding **ppBlob) {
  83. CComPtr<IDxcLibrary> library;
  84. IFT(m_dllSupport.CreateInstance(CLSID_DxcLibrary, &library));
  85. IFT(library->CreateBlobWithEncodingFromPinned((LPBYTE)data, size, codePage,
  86. ppBlob));
  87. }
  88. void CreateBlobFromText(_In_z_ const char *pText,
  89. _Outptr_ IDxcBlobEncoding **ppBlob) {
  90. CreateBlobPinned(pText, strlen(pText), CP_UTF8, ppBlob);
  91. }
  92. HRESULT CreateCompiler(IDxcCompiler **ppResult) {
  93. if (!m_dllSupport.IsEnabled()) {
  94. VERIFY_SUCCEEDED(m_dllSupport.Initialize());
  95. }
  96. return m_dllSupport.CreateInstance(CLSID_DxcCompiler, ppResult);
  97. }
  98. void CompareShaderInputBindDesc(D3D12_SHADER_INPUT_BIND_DESC *pTestDesc,
  99. D3D12_SHADER_INPUT_BIND_DESC *pBaseDesc) {
  100. VERIFY_ARE_EQUAL(pTestDesc->BindCount, pBaseDesc->BindCount);
  101. VERIFY_ARE_EQUAL(pTestDesc->BindPoint, pBaseDesc->BindPoint);
  102. VERIFY_ARE_EQUAL(pTestDesc->Dimension, pBaseDesc->Dimension);
  103. VERIFY_ARE_EQUAL_STR(pTestDesc->Name, pBaseDesc->Name);
  104. VERIFY_ARE_EQUAL(pTestDesc->NumSamples, pBaseDesc->NumSamples);
  105. VERIFY_ARE_EQUAL(pTestDesc->ReturnType, pBaseDesc->ReturnType);
  106. VERIFY_ARE_EQUAL(pTestDesc->Space, pBaseDesc->Space);
  107. if (pBaseDesc->Type == D3D_SIT_UAV_APPEND_STRUCTURED ||
  108. pBaseDesc->Type == D3D_SIT_UAV_CONSUME_STRUCTURED) {
  109. // dxil only have rw with counter.
  110. VERIFY_ARE_EQUAL(pTestDesc->Type, D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER);
  111. } else if (pTestDesc->Type == D3D_SIT_STRUCTURED &&
  112. pBaseDesc->Type != D3D_SIT_STRUCTURED) {
  113. VERIFY_ARE_EQUAL(pBaseDesc->Type, D3D_SIT_TEXTURE);
  114. } else
  115. VERIFY_ARE_EQUAL(pTestDesc->Type, pBaseDesc->Type);
  116. // D3D_SIF_USERPACKED is never set in dxil.
  117. UINT unusedFlag = D3D_SIF_USERPACKED;
  118. VERIFY_ARE_EQUAL(pTestDesc->uFlags, pBaseDesc->uFlags & ~unusedFlag);
  119. // VERIFY_ARE_EQUAL(pTestDesc->uID, pBaseDesc->uID); // Like register, this can vary.
  120. }
  121. void CompareParameterDesc(D3D12_SIGNATURE_PARAMETER_DESC *pTestDesc,
  122. D3D12_SIGNATURE_PARAMETER_DESC *pBaseDesc, bool isInput) {
  123. VERIFY_ARE_EQUAL(0, _stricmp(pTestDesc->SemanticName, pBaseDesc->SemanticName));
  124. if (pTestDesc->SystemValueType == D3D_NAME_CLIP_DISTANCE) return; // currently generating multiple clip distance params, one per component
  125. VERIFY_ARE_EQUAL(pTestDesc->ComponentType, pBaseDesc->ComponentType);
  126. VERIFY_ARE_EQUAL(MaskCount(pTestDesc->Mask), MaskCount(pBaseDesc->Mask));
  127. VERIFY_ARE_EQUAL(pTestDesc->MinPrecision, pBaseDesc->MinPrecision);
  128. if (!isInput)
  129. VERIFY_ARE_EQUAL(pTestDesc->ReadWriteMask != 0, pBaseDesc->ReadWriteMask != 0); // VERIFY_ARE_EQUAL(pTestDesc->ReadWriteMask, pBaseDesc->ReadWriteMask);
  130. // VERIFY_ARE_EQUAL(pTestDesc->Register, pBaseDesc->Register);
  131. //VERIFY_ARE_EQUAL(pTestDesc->SemanticIndex, pBaseDesc->SemanticIndex);
  132. VERIFY_ARE_EQUAL(pTestDesc->Stream, pBaseDesc->Stream);
  133. VERIFY_ARE_EQUAL(pTestDesc->SystemValueType, pBaseDesc->SystemValueType);
  134. }
  135. void CompareType(ID3D12ShaderReflectionType *pTest,
  136. ID3D12ShaderReflectionType *pBase,
  137. bool shouldSuppressOffsetChecks = false)
  138. {
  139. D3D12_SHADER_TYPE_DESC testDesc, baseDesc;
  140. VERIFY_SUCCEEDED(pTest->GetDesc(&testDesc));
  141. VERIFY_SUCCEEDED(pBase->GetDesc(&baseDesc));
  142. VERIFY_ARE_EQUAL(testDesc.Class, baseDesc.Class);
  143. VERIFY_ARE_EQUAL(testDesc.Type, baseDesc.Type);
  144. VERIFY_ARE_EQUAL(testDesc.Rows, baseDesc.Rows);
  145. VERIFY_ARE_EQUAL(testDesc.Columns, baseDesc.Columns);
  146. VERIFY_ARE_EQUAL(testDesc.Elements, baseDesc.Elements);
  147. VERIFY_ARE_EQUAL(testDesc.Members, baseDesc.Members);
  148. if(!shouldSuppressOffsetChecks)
  149. {
  150. VERIFY_ARE_EQUAL(testDesc.Offset, baseDesc.Offset);
  151. }
  152. VERIFY_ARE_EQUAL(0, strcmp(testDesc.Name, baseDesc.Name));
  153. for (UINT i = 0; i < baseDesc.Members; ++i) {
  154. ID3D12ShaderReflectionType* testMemberType = pTest->GetMemberTypeByIndex(i);
  155. ID3D12ShaderReflectionType* baseMemberType = pBase->GetMemberTypeByIndex(i);
  156. VERIFY_IS_NOT_NULL(testMemberType);
  157. VERIFY_IS_NOT_NULL(baseMemberType);
  158. CompareType(testMemberType, baseMemberType, shouldSuppressOffsetChecks);
  159. LPCSTR testMemberName = pTest->GetMemberTypeName(i);
  160. LPCSTR baseMemberName = pBase->GetMemberTypeName(i);
  161. VERIFY_ARE_EQUAL(0, strcmp(testMemberName, baseMemberName));
  162. }
  163. }
  164. typedef HRESULT (__stdcall ID3D12ShaderReflection::*GetParameterDescFn)(UINT, D3D12_SIGNATURE_PARAMETER_DESC*);
  165. void SortNameIdxVector(std::vector<std::tuple<LPCSTR, UINT, UINT>> &value) {
  166. struct FirstPredT {
  167. bool operator()(std::tuple<LPCSTR, UINT, UINT> &l,
  168. std::tuple<LPCSTR, UINT, UINT> &r) {
  169. int strResult = strcmp(std::get<0>(l), std::get<0>(r));
  170. return (strResult < 0 ) || (strResult == 0 && std::get<1>(l) < std::get<1>(r));
  171. }
  172. } FirstPred;
  173. std::sort(value.begin(), value.end(), FirstPred);
  174. }
  175. void CompareParameterDescs(UINT count, ID3D12ShaderReflection *pTest,
  176. ID3D12ShaderReflection *pBase,
  177. GetParameterDescFn Fn, bool isInput) {
  178. std::vector<std::tuple<LPCSTR, UINT, UINT>> testParams, baseParams;
  179. testParams.reserve(count);
  180. baseParams.reserve(count);
  181. for (UINT i = 0; i < count; ++i) {
  182. D3D12_SIGNATURE_PARAMETER_DESC D;
  183. VERIFY_SUCCEEDED((pTest->*Fn)(i, &D));
  184. testParams.push_back(std::make_tuple(D.SemanticName, D.SemanticIndex, i));
  185. VERIFY_SUCCEEDED((pBase->*Fn)(i, &D));
  186. baseParams.push_back(std::make_tuple(D.SemanticName, D.SemanticIndex, i));
  187. }
  188. SortNameIdxVector(testParams);
  189. SortNameIdxVector(baseParams);
  190. for (UINT i = 0; i < count; ++i) {
  191. D3D12_SIGNATURE_PARAMETER_DESC testParamDesc, baseParamDesc;
  192. VERIFY_SUCCEEDED(
  193. (pTest->*Fn)(std::get<2>(testParams[i]), &testParamDesc));
  194. VERIFY_SUCCEEDED(
  195. (pBase->*Fn)(std::get<2>(baseParams[i]), &baseParamDesc));
  196. CompareParameterDesc(&testParamDesc, &baseParamDesc, isInput);
  197. }
  198. }
  199. void CompareReflection(ID3D12ShaderReflection *pTest, ID3D12ShaderReflection *pBase) {
  200. D3D12_SHADER_DESC testDesc, baseDesc;
  201. VERIFY_SUCCEEDED(pTest->GetDesc(&testDesc));
  202. VERIFY_SUCCEEDED(pBase->GetDesc(&baseDesc));
  203. VERIFY_ARE_EQUAL(D3D12_SHVER_GET_TYPE(testDesc.Version), D3D12_SHVER_GET_TYPE(baseDesc.Version));
  204. VERIFY_ARE_EQUAL(testDesc.ConstantBuffers, baseDesc.ConstantBuffers);
  205. VERIFY_ARE_EQUAL(testDesc.BoundResources, baseDesc.BoundResources);
  206. VERIFY_ARE_EQUAL(testDesc.InputParameters, baseDesc.InputParameters);
  207. VERIFY_ARE_EQUAL(testDesc.OutputParameters, baseDesc.OutputParameters);
  208. VERIFY_ARE_EQUAL(testDesc.PatchConstantParameters, baseDesc.PatchConstantParameters);
  209. {
  210. for (UINT i = 0; i < testDesc.ConstantBuffers; ++i) {
  211. ID3D12ShaderReflectionConstantBuffer *pTestCB, *pBaseCB;
  212. D3D12_SHADER_BUFFER_DESC testCB, baseCB;
  213. pTestCB = pTest->GetConstantBufferByIndex(i);
  214. VERIFY_SUCCEEDED(pTestCB->GetDesc(&testCB));
  215. pBaseCB = pBase->GetConstantBufferByName(testCB.Name);
  216. VERIFY_SUCCEEDED(pBaseCB->GetDesc(&baseCB));
  217. VERIFY_ARE_EQUAL_STR(testCB.Name, baseCB.Name);
  218. VERIFY_ARE_EQUAL(testCB.Type, baseCB.Type);
  219. VERIFY_ARE_EQUAL(testCB.Variables, baseCB.Variables);
  220. VERIFY_ARE_EQUAL(testCB.Size, baseCB.Size);
  221. VERIFY_ARE_EQUAL(testCB.uFlags, baseCB.uFlags);
  222. llvm::StringMap<D3D12_SHADER_VARIABLE_DESC> variableMap;
  223. llvm::StringMap<ID3D12ShaderReflectionType*> variableTypeMap;
  224. for (UINT vi = 0; vi < testCB.Variables; ++vi) {
  225. ID3D12ShaderReflectionVariable *pBaseConst;
  226. D3D12_SHADER_VARIABLE_DESC baseConst;
  227. pBaseConst = pBaseCB->GetVariableByIndex(vi);
  228. VERIFY_SUCCEEDED(pBaseConst->GetDesc(&baseConst));
  229. variableMap[baseConst.Name] = baseConst;
  230. ID3D12ShaderReflectionType* pBaseType = pBaseConst->GetType();
  231. VERIFY_IS_NOT_NULL(pBaseType);
  232. variableTypeMap[baseConst.Name] = pBaseType;
  233. }
  234. for (UINT vi = 0; vi < testCB.Variables; ++vi) {
  235. ID3D12ShaderReflectionVariable *pTestConst;
  236. D3D12_SHADER_VARIABLE_DESC testConst;
  237. pTestConst = pTestCB->GetVariableByIndex(vi);
  238. VERIFY_SUCCEEDED(pTestConst->GetDesc(&testConst));
  239. VERIFY_ARE_EQUAL(variableMap.count(testConst.Name), 1);
  240. D3D12_SHADER_VARIABLE_DESC baseConst = variableMap[testConst.Name];
  241. VERIFY_ARE_EQUAL(testConst.uFlags, baseConst.uFlags);
  242. VERIFY_ARE_EQUAL(testConst.StartOffset, baseConst.StartOffset);
  243. // TODO: enalbe size cmp.
  244. //VERIFY_ARE_EQUAL(testConst.Size, baseConst.Size);
  245. ID3D12ShaderReflectionType* pTestType = pTestConst->GetType();
  246. VERIFY_IS_NOT_NULL(pTestType);
  247. VERIFY_ARE_EQUAL(variableTypeMap.count(testConst.Name), 1);
  248. ID3D12ShaderReflectionType* pBaseType = variableTypeMap[testConst.Name];
  249. // Note: we suppress comparing offsets for structured buffers, because dxc and fxc don't
  250. // seem to agree in that case.
  251. //
  252. // The information in the `D3D12_SHADER_BUFFER_DESC` doesn't give us enough to
  253. // be able to isolate structured buffers, so we do the test negatively: suppress
  254. // offset checks *unless* we are looking at a `cbuffer` or `tbuffer`.
  255. bool shouldSuppressOffsetChecks = true;
  256. switch( baseCB.Type )
  257. {
  258. default:
  259. break;
  260. case D3D_CT_CBUFFER:
  261. case D3D_CT_TBUFFER:
  262. shouldSuppressOffsetChecks = false;
  263. break;
  264. }
  265. CompareType(pTestType, pBaseType, shouldSuppressOffsetChecks);
  266. }
  267. }
  268. }
  269. for (UINT i = 0; i < testDesc.BoundResources; ++i) {
  270. D3D12_SHADER_INPUT_BIND_DESC testParamDesc, baseParamDesc;
  271. VERIFY_SUCCEEDED(pTest->GetResourceBindingDesc(i, &testParamDesc), WStrFmt(L"i=%u", i));
  272. VERIFY_SUCCEEDED(pBase->GetResourceBindingDescByName(testParamDesc.Name, &baseParamDesc));
  273. CompareShaderInputBindDesc(&testParamDesc, &baseParamDesc);
  274. }
  275. CompareParameterDescs(testDesc.InputParameters, pTest, pBase, &ID3D12ShaderReflection::GetInputParameterDesc, true);
  276. CompareParameterDescs(testDesc.OutputParameters, pTest, pBase,
  277. &ID3D12ShaderReflection::GetOutputParameterDesc,
  278. false);
  279. bool isHs = testDesc.HSPartitioning != D3D_TESSELLATOR_PARTITIONING::D3D11_TESSELLATOR_PARTITIONING_UNDEFINED;
  280. CompareParameterDescs(
  281. testDesc.PatchConstantParameters, pTest, pBase,
  282. &ID3D12ShaderReflection::GetPatchConstantParameterDesc, !isHs);
  283. {
  284. UINT32 testTotal, testX, testY, testZ;
  285. UINT32 baseTotal, baseX, baseY, baseZ;
  286. testTotal = pTest->GetThreadGroupSize(&testX, &testY, &testZ);
  287. baseTotal = pBase->GetThreadGroupSize(&baseX, &baseY, &baseZ);
  288. VERIFY_ARE_EQUAL(testTotal, baseTotal);
  289. VERIFY_ARE_EQUAL(testX, baseX);
  290. VERIFY_ARE_EQUAL(testY, baseY);
  291. VERIFY_ARE_EQUAL(testZ, baseZ);
  292. }
  293. }
  294. void split(const wstring &s, wchar_t delim, vector<wstring> &elems) {
  295. wstringstream ss(s);
  296. wstring item;
  297. while (getline(ss, item, delim)) {
  298. elems.push_back(item);
  299. }
  300. }
  301. vector<wstring> split(const wstring &s, char delim) {
  302. vector<wstring> elems;
  303. split(s, delim, elems);
  304. return elems;
  305. }
  306. wstring SplitFilename(const wstring &str) {
  307. size_t found;
  308. found = str.find_last_of(L"/\\");
  309. return str.substr(0, found);
  310. }
  311. void NameParseCommandPartsFromFile(LPCWSTR path, std::vector<FileRunCommandPart> &parts) {
  312. vector<wstring> Parts = split(wstring(path), '+');
  313. std::wstring Name = Parts[0];
  314. std::wstring EntryPoint = Parts[1];
  315. std::wstring ShaderModel = Parts[2];
  316. std::wstring Arguments = L"-T ";
  317. Arguments += ShaderModel;
  318. Arguments += L" -E ";
  319. Arguments += EntryPoint;
  320. Arguments += L" %s";
  321. std::wstring_convert<std::codecvt_utf8_utf16<wchar_t> > w;
  322. string ArgumentsNarrow = w.to_bytes(Arguments);
  323. FileRunCommandPart P(string("%dxc"), ArgumentsNarrow, path);
  324. parts.push_back(P);
  325. }
  326. HRESULT CompileFromFile(LPCWSTR path, bool useDXBC, IDxcBlob **ppBlob) {
  327. std::vector<FileRunCommandPart> parts;
  328. //NameParseCommandPartsFromFile(path, parts);
  329. ParseCommandPartsFromFile(path, parts);
  330. VERIFY_IS_TRUE(parts.size() > 0);
  331. VERIFY_ARE_EQUAL_STR(parts[0].Command.c_str(), "%dxc");
  332. FileRunCommandPart &dxc = parts[0];
  333. m_dllSupport.Initialize();
  334. dxc.DllSupport = &m_dllSupport;
  335. hlsl::options::MainArgs args;
  336. hlsl::options::DxcOpts opts;
  337. dxc.ReadOptsForDxc(args, opts);
  338. if (opts.CodeGenHighLevel) return E_FAIL; // skip for now
  339. if (useDXBC) {
  340. // Consider supporting defines and flags if/when needed.
  341. std::string TargetProfile(opts.TargetProfile.str());
  342. TargetProfile[3] = '5'; TargetProfile[5] = '1';
  343. CComPtr<ID3DBlob> pDxbcBlob;
  344. CComPtr<ID3DBlob> pDxbcErrors;
  345. UINT unboundDescTab = (1 << 20);
  346. IFR(D3DCompileFromFile(path, nullptr, D3D_COMPILE_STANDARD_FILE_INCLUDE,
  347. opts.EntryPoint.str().c_str(),
  348. TargetProfile.c_str(),
  349. unboundDescTab, 0, &pDxbcBlob, &pDxbcErrors));
  350. IFR(pDxbcBlob.QueryInterface(ppBlob));
  351. }
  352. else {
  353. dxc.Run(nullptr);
  354. IFRBOOL(dxc.RunResult == 0, E_FAIL);
  355. IFR(dxc.OpResult->GetResult(ppBlob));
  356. }
  357. return S_OK;
  358. }
  359. void CreateReflectionFromBlob(IDxcBlob *pBlob, ID3D12ShaderReflection **ppReflection) {
  360. CComPtr<IDxcContainerReflection> pReflection;
  361. UINT32 shaderIdx;
  362. m_dllSupport.CreateInstance(CLSID_DxcContainerReflection, &pReflection);
  363. VERIFY_SUCCEEDED(pReflection->Load(pBlob));
  364. VERIFY_SUCCEEDED(pReflection->FindFirstPartKind(hlsl::DFCC_DXIL, &shaderIdx));
  365. VERIFY_SUCCEEDED(pReflection->GetPartReflection(shaderIdx, __uuidof(ID3D12ShaderReflection), (void**)ppReflection));
  366. }
  367. void CreateReflectionFromDXBC(IDxcBlob *pBlob, ID3D12ShaderReflection **ppReflection) {
  368. VERIFY_SUCCEEDED(
  369. D3DReflect(pBlob->GetBufferPointer(), pBlob->GetBufferSize(),
  370. __uuidof(ID3D12ShaderReflection), (void **)ppReflection));
  371. }
  372. void CompileToProgram(LPCSTR program, LPCWSTR entryPoint, LPCWSTR target,
  373. LPCWSTR *pArguments, UINT32 argCount,
  374. IDxcBlob **ppProgram) {
  375. CComPtr<IDxcCompiler> pCompiler;
  376. CComPtr<IDxcBlobEncoding> pSource;
  377. CComPtr<IDxcBlob> pProgram;
  378. CComPtr<IDxcOperationResult> pResult;
  379. VERIFY_SUCCEEDED(CreateCompiler(&pCompiler));
  380. CreateBlobFromText(program, &pSource);
  381. VERIFY_SUCCEEDED(pCompiler->Compile(pSource, L"hlsl.hlsl", entryPoint,
  382. target, pArguments, argCount, nullptr,
  383. 0, nullptr, &pResult));
  384. VERIFY_SUCCEEDED(pResult->GetResult(&pProgram));
  385. *ppProgram = pProgram.Detach();
  386. }
  387. bool DoesValidatorSupportDebugName() {
  388. CComPtr<IDxcVersionInfo> pVersionInfo;
  389. UINT Major, Minor;
  390. HRESULT hrVer = m_dllSupport.CreateInstance(CLSID_DxcValidator, &pVersionInfo);
  391. if (hrVer == E_NOINTERFACE) return false;
  392. VERIFY_SUCCEEDED(hrVer);
  393. VERIFY_SUCCEEDED(pVersionInfo->GetVersion(&Major, &Minor));
  394. return Major == 1 && (Minor >= 1);
  395. }
  396. std::string CompileToDebugName(LPCSTR program, LPCWSTR entryPoint,
  397. LPCWSTR target, LPCWSTR *pArguments, UINT32 argCount) {
  398. CComPtr<IDxcBlob> pProgram;
  399. CComPtr<IDxcBlob> pNameBlob;
  400. CComPtr<IDxcContainerReflection> pContainer;
  401. UINT32 index;
  402. CompileToProgram(program, entryPoint, target, pArguments, argCount, &pProgram);
  403. VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcContainerReflection, &pContainer));
  404. VERIFY_SUCCEEDED(pContainer->Load(pProgram));
  405. if (FAILED(pContainer->FindFirstPartKind(hlsl::DFCC_ShaderDebugName, &index))) {
  406. return std::string();
  407. }
  408. VERIFY_SUCCEEDED(pContainer->GetPartContent(index, &pNameBlob));
  409. const hlsl::DxilShaderDebugName *pDebugName = (hlsl::DxilShaderDebugName *)pNameBlob->GetBufferPointer();
  410. return std::string((const char *)(pDebugName + 1));
  411. }
  412. std::string DisassembleProgram(LPCSTR program, LPCWSTR entryPoint,
  413. LPCWSTR target) {
  414. CComPtr<IDxcCompiler> pCompiler;
  415. CComPtr<IDxcBlob> pProgram;
  416. CComPtr<IDxcBlobEncoding> pDisassembly;
  417. CompileToProgram(program, entryPoint, target, nullptr, 0, &pProgram);
  418. VERIFY_SUCCEEDED(CreateCompiler(&pCompiler));
  419. VERIFY_SUCCEEDED(pCompiler->Disassemble(pProgram, &pDisassembly));
  420. return BlobToUtf8(pDisassembly);
  421. }
  422. void SetupBasicHeader(hlsl::DxilContainerHeader *pHeader,
  423. uint32_t partCount = 0) {
  424. ZeroMemory(pHeader, sizeof(*pHeader));
  425. pHeader->HeaderFourCC = hlsl::DFCC_Container;
  426. pHeader->Version.Major = 1;
  427. pHeader->Version.Minor = 0;
  428. pHeader->PartCount = partCount;
  429. pHeader->ContainerSizeInBytes =
  430. sizeof(hlsl::DxilContainerHeader) +
  431. sizeof(uint32_t) * partCount +
  432. sizeof(hlsl::DxilPartHeader) * partCount;
  433. }
  434. void CodeGenTestCheck(LPCWSTR name) {
  435. std::wstring fullPath = hlsl_test::GetPathToHlslDataFile(name);
  436. FileRunTestResult t = FileRunTestResult::RunFromFileCommands(fullPath.c_str());
  437. if (t.RunResult != 0) {
  438. CA2W commentWide(t.ErrorMessage.c_str(), CP_UTF8);
  439. WEX::Logging::Log::Comment(commentWide);
  440. WEX::Logging::Log::Error(L"Run result is not zero");
  441. }
  442. }
  443. WEX::Common::String WStrFmt(const wchar_t* msg, ...) {
  444. va_list args;
  445. va_start(args, msg);
  446. WEX::Common::String result = WEX::Common::String().FormatV(msg, args);
  447. va_end(args);
  448. return result;
  449. }
  450. void ReflectionTest(LPCWSTR name, bool ignoreIfDXBCFails) {
  451. WEX::Logging::Log::Comment(WEX::Common::String().Format(L"Reflection comparison for %s", name));
  452. CComPtr<IDxcBlob> pProgram;
  453. CComPtr<IDxcBlob> pProgramDXBC;
  454. HRESULT hrDXBC = CompileFromFile(name, true, &pProgramDXBC);
  455. if (FAILED(hrDXBC)) {
  456. WEX::Logging::Log::Comment(L"Failed to compile DXBC blob.");
  457. if (ignoreIfDXBCFails) return;
  458. VERIFY_FAIL();
  459. }
  460. if (FAILED(CompileFromFile(name, false, &pProgram))) {
  461. WEX::Logging::Log::Comment(L"Failed to compile DXIL blob.");
  462. if (ignoreIfDXBCFails) return;
  463. VERIFY_FAIL();
  464. }
  465. CComPtr<ID3D12ShaderReflection> pProgramReflection;
  466. CComPtr<ID3D12ShaderReflection> pProgramReflectionDXBC;
  467. CreateReflectionFromBlob(pProgram, &pProgramReflection);
  468. CreateReflectionFromDXBC(pProgramDXBC, &pProgramReflectionDXBC);
  469. CompareReflection(pProgramReflection, pProgramReflectionDXBC);
  470. }
  471. };
  472. bool DxilContainerTest::InitSupport() {
  473. if (!m_dllSupport.IsEnabled()) {
  474. VERIFY_SUCCEEDED(m_dllSupport.Initialize());
  475. m_ver.Initialize(m_dllSupport);
  476. }
  477. return true;
  478. }
  479. TEST_F(DxilContainerTest, CompileWhenDebugSourceThenSourceMatters) {
  480. char program1[] = "float4 main() : SV_Target { return 0; }";
  481. char program2[] = " float4 main() : SV_Target { return 0; } ";
  482. LPCWSTR Zi[] = { L"/Zi" };
  483. LPCWSTR ZiZss[] = { L"/Zi", L"/Zss" };
  484. LPCWSTR ZiZsb[] = { L"/Zi", L"/Zsb" };
  485. // No debug info, no debug name...
  486. std::string noName = CompileToDebugName(program1, L"main", L"ps_6_0", nullptr, 0);
  487. VERIFY_IS_TRUE(noName.empty());
  488. if (!DoesValidatorSupportDebugName())
  489. return;
  490. // Debug info, default to source name.
  491. std::string sourceName1 = CompileToDebugName(program1, L"main", L"ps_6_0", Zi, _countof(Zi));
  492. VERIFY_IS_FALSE(sourceName1.empty());
  493. // Deterministic naming.
  494. std::string sourceName1Again = CompileToDebugName(program1, L"main", L"ps_6_0", Zi, _countof(Zi));
  495. VERIFY_ARE_EQUAL_STR(sourceName1.c_str(), sourceName1Again.c_str());
  496. // Changes in source become changes in name.
  497. std::string sourceName2 = CompileToDebugName(program2, L"main", L"ps_6_0", Zi, _countof(Zi));
  498. VERIFY_IS_FALSE(0 == strcmp(sourceName2.c_str(), sourceName1.c_str()));
  499. // Source again, different because different switches are specified.
  500. std::string sourceName1Zss = CompileToDebugName(program1, L"main", L"ps_6_0", ZiZss, _countof(ZiZss));
  501. VERIFY_IS_FALSE(0 == strcmp(sourceName1Zss.c_str(), sourceName1.c_str()));
  502. // Binary program 1 and 2 should be different from source and equal to each other.
  503. std::string binName1 = CompileToDebugName(program1, L"main", L"ps_6_0", ZiZsb, _countof(ZiZsb));
  504. std::string binName2 = CompileToDebugName(program2, L"main", L"ps_6_0", ZiZsb, _countof(ZiZsb));
  505. VERIFY_ARE_EQUAL_STR(binName1.c_str(), binName2.c_str());
  506. VERIFY_IS_FALSE(0 == strcmp(sourceName1Zss.c_str(), binName1.c_str()));
  507. }
  508. TEST_F(DxilContainerTest, CompileWhenOKThenIncludesSignatures) {
  509. char program[] =
  510. "struct PSInput {\r\n"
  511. " float4 position : SV_POSITION;\r\n"
  512. " float4 color : COLOR;\r\n"
  513. "};\r\n"
  514. "PSInput VSMain(float4 position : POSITION, float4 color : COLOR) {\r\n"
  515. " PSInput result;\r\n"
  516. " result.position = position;\r\n"
  517. " result.color = color;\r\n"
  518. " return result;\r\n"
  519. "}\r\n"
  520. "float4 PSMain(PSInput input) : SV_TARGET {\r\n"
  521. " return input.color;\r\n"
  522. "}";
  523. {
  524. std::string s = DisassembleProgram(program, L"VSMain", L"vs_6_0");
  525. // NOTE: this will change when proper packing is done, and when 'always-writes' is accurately implemented.
  526. const char expected[] =
  527. ";\n"
  528. "; Input signature:\n"
  529. ";\n"
  530. "; Name Index Mask Register SysValue Format Used\n"
  531. "; -------------------- ----- ------ -------- -------- ------- ------\n"
  532. "; POSITION 0 xyzw 0 NONE float \n" // should read 'xyzw' in Used
  533. "; COLOR 0 xyzw 1 NONE float \n" // should read '1' in register
  534. ";\n"
  535. ";\n"
  536. "; Output signature:\n"
  537. ";\n"
  538. "; Name Index Mask Register SysValue Format Used\n"
  539. "; -------------------- ----- ------ -------- -------- ------- ------\n"
  540. "; SV_Position 0 xyzw 0 POS float xyzw\n" // could read SV_POSITION
  541. "; COLOR 0 xyzw 1 NONE float xyzw\n"; // should read '1' in register
  542. std::string start(s.c_str(), strlen(expected));
  543. VERIFY_ARE_EQUAL_STR(expected, start.c_str());
  544. }
  545. {
  546. std::string s = DisassembleProgram(program, L"PSMain", L"ps_6_0");
  547. // NOTE: this will change when proper packing is done, and when 'always-writes' is accurately implemented.
  548. const char expected[] =
  549. ";\n"
  550. "; Input signature:\n"
  551. ";\n"
  552. "; Name Index Mask Register SysValue Format Used\n"
  553. "; -------------------- ----- ------ -------- -------- ------- ------\n"
  554. "; SV_Position 0 xyzw 0 POS float \n" // could read SV_POSITION
  555. "; COLOR 0 xyzw 1 NONE float \n" // should read '1' in register, xyzw in Used
  556. ";\n"
  557. ";\n"
  558. "; Output signature:\n"
  559. ";\n"
  560. "; Name Index Mask Register SysValue Format Used\n"
  561. "; -------------------- ----- ------ -------- -------- ------- ------\n"
  562. "; SV_Target 0 xyzw 0 TARGET float xyzw\n";// could read SV_TARGET
  563. std::string start(s.c_str(), strlen(expected));
  564. VERIFY_ARE_EQUAL_STR(expected, start.c_str());
  565. }
  566. }
  567. TEST_F(DxilContainerTest, CompileWhenSigSquareThenIncludeSplit) {
  568. #if 0 // TODO: reenable test when multiple rows are supported.
  569. const char program[] =
  570. "float main(float4x4 a : A, int4 b : B) : SV_Target {\n"
  571. " return a[b.x][b.y];\n"
  572. "}";
  573. std::string s = DisassembleProgram(program, L"main", L"ps_6_0");
  574. const char expected[] =
  575. "// Input signature:\n"
  576. "//\n"
  577. "// Name Index Mask Register SysValue Format Used\n"
  578. "// -------------------- ----- ------ -------- -------- ------- ------\n"
  579. "// A 0 xyzw 0 NONE float xyzw\n"
  580. "// A 1 xyzw 1 NONE float xyzw\n"
  581. "// A 2 xyzw 2 NONE float xyzw\n"
  582. "// A 3 xyzw 3 NONE float xyzw\n"
  583. "// B 0 xyzw 4 NONE int xy\n"
  584. "//\n"
  585. "//\n"
  586. "// Output signature:\n"
  587. "//\n"
  588. "// Name Index Mask Register SysValue Format Used\n"
  589. "// -------------------- ----- ------ -------- -------- ------- ------\n"
  590. "// SV_Target 0 x 0 TARGET float x\n";
  591. std::string start(s.c_str(), strlen(expected));
  592. VERIFY_ARE_EQUAL_STR(expected, start.c_str());
  593. #endif
  594. }
  595. TEST_F(DxilContainerTest, CompileWhenOkThenCheckRDAT) {
  596. if (m_ver.SkipDxilVersion(1, 3)) return;
  597. const char *shader = "float c_buf;"
  598. "RWTexture1D<int4> tex : register(u5);"
  599. "Texture1D<float4> tex2 : register(t0);"
  600. "RWByteAddressBuffer b_buf;"
  601. "struct Foo { float2 f2; int2 i2; };"
  602. "AppendStructuredBuffer<Foo> append_buf;"
  603. "ConsumeStructuredBuffer<Foo> consume_buf;"
  604. "RasterizerOrderedByteAddressBuffer rov_buf;"
  605. "globallycoherent RWByteAddressBuffer gc_buf;"
  606. "float function_import(float x);"
  607. "float function0(min16float x) { "
  608. " return x + 1 + tex[0].x; }"
  609. "float function1(float x, min12int i) {"
  610. " return x + c_buf + b_buf.Load(x) + tex2[i].x; }"
  611. "float function2(float x) { return x + function_import(x); }"
  612. "void function3(int i) {"
  613. " Foo f = consume_buf.Consume();"
  614. " f.f2 += 0.5; append_buf.Append(f);"
  615. " rov_buf.Store(i, f.i2.x);"
  616. " gc_buf.Store(i, f.i2.y);"
  617. " b_buf.Store(i, f.i2.x + f.i2.y); }";
  618. CComPtr<IDxcCompiler> pCompiler;
  619. CComPtr<IDxcBlobEncoding> pSource;
  620. CComPtr<IDxcBlob> pProgram;
  621. CComPtr<IDxcBlobEncoding> pDisassembly;
  622. CComPtr<IDxcOperationResult> pResult;
  623. struct CheckResFlagInfo { std::string name; hlsl::DXIL::ResourceKind kind; hlsl::RDAT::DxilResourceFlag flag; };
  624. const unsigned numResFlagCheck = 5;
  625. CheckResFlagInfo resFlags[numResFlagCheck] = {
  626. { "b_buf", hlsl::DXIL::ResourceKind::RawBuffer, hlsl::RDAT::DxilResourceFlag::None },
  627. { "append_buf", hlsl::DXIL::ResourceKind::StructuredBuffer, hlsl::RDAT::DxilResourceFlag::UAVCounter },
  628. { "consume_buf", hlsl::DXIL::ResourceKind::StructuredBuffer, hlsl::RDAT::DxilResourceFlag::UAVCounter },
  629. { "gc_buf", hlsl::DXIL::ResourceKind::RawBuffer, hlsl::RDAT::DxilResourceFlag::UAVGloballyCoherent },
  630. { "rov_buf", hlsl::DXIL::ResourceKind::RawBuffer, hlsl::RDAT::DxilResourceFlag::UAVRasterizerOrderedView }
  631. };
  632. VERIFY_SUCCEEDED(CreateCompiler(&pCompiler));
  633. CreateBlobFromText(shader, &pSource);
  634. VERIFY_SUCCEEDED(pCompiler->Compile(pSource, L"hlsl.hlsl", L"main",
  635. L"lib_6_3", nullptr, 0, nullptr, 0,
  636. nullptr, &pResult));
  637. HRESULT hrStatus;
  638. VERIFY_SUCCEEDED(pResult->GetStatus(&hrStatus));
  639. VERIFY_SUCCEEDED(hrStatus);
  640. VERIFY_SUCCEEDED(pResult->GetResult(&pProgram));
  641. CComPtr<IDxcContainerReflection> containerReflection;
  642. uint32_t partCount;
  643. IFT(m_dllSupport.CreateInstance(CLSID_DxcContainerReflection, &containerReflection));
  644. IFT(containerReflection->Load(pProgram));
  645. IFT(containerReflection->GetPartCount(&partCount));
  646. bool blobFound = false;
  647. for (uint32_t i = 0; i < partCount; ++i) {
  648. uint32_t kind;
  649. IFT(containerReflection->GetPartKind(i, &kind));
  650. if (kind == (uint32_t)hlsl::DxilFourCC::DFCC_RuntimeData) {
  651. blobFound = true;
  652. using namespace hlsl::RDAT;
  653. CComPtr<IDxcBlob> pBlob;
  654. IFT(containerReflection->GetPartContent(i, &pBlob));
  655. // Validate using DxilRuntimeData
  656. DxilRuntimeData context;
  657. context.InitFromRDAT((char *)pBlob->GetBufferPointer(), pBlob->GetBufferSize());
  658. FunctionTableReader *funcTableReader = context.GetFunctionTableReader();
  659. ResourceTableReader *resTableReader = context.GetResourceTableReader();
  660. VERIFY_ARE_EQUAL(funcTableReader->GetNumFunctions(), 4);
  661. std::string str("function");
  662. for (uint32_t j = 0; j < funcTableReader->GetNumFunctions(); ++j) {
  663. FunctionReader funcReader = funcTableReader->GetItem(j);
  664. std::string funcName(funcReader.GetUnmangledName());
  665. VERIFY_IS_TRUE(str.compare(funcName.substr(0,8)) == 0);
  666. std::string cur_str = str;
  667. cur_str.push_back('0' + j);
  668. if (cur_str.compare("function0") == 0) {
  669. VERIFY_ARE_EQUAL(funcReader.GetNumResources(), 1);
  670. hlsl::ShaderFlags flag;
  671. flag.SetUAVLoadAdditionalFormats(true);
  672. flag.SetLowPrecisionPresent(true);
  673. uint64_t rawFlag = flag.GetFeatureInfo();
  674. VERIFY_ARE_EQUAL(funcReader.GetFeatureFlag(), rawFlag);
  675. ResourceReader resReader = funcReader.GetResource(0);
  676. VERIFY_ARE_EQUAL(resReader.GetResourceClass(), hlsl::DXIL::ResourceClass::UAV);
  677. VERIFY_ARE_EQUAL(resReader.GetResourceKind(), hlsl::DXIL::ResourceKind::Texture1D);
  678. }
  679. else if (cur_str.compare("function1") == 0) {
  680. hlsl::ShaderFlags flag;
  681. flag.SetLowPrecisionPresent(true);
  682. uint64_t rawFlag = flag.GetFeatureInfo();
  683. VERIFY_ARE_EQUAL(funcReader.GetFeatureFlag(), rawFlag);
  684. VERIFY_ARE_EQUAL(funcReader.GetNumResources(), 3);
  685. }
  686. else if (cur_str.compare("function2") == 0) {
  687. VERIFY_ARE_EQUAL(funcReader.GetFeatureFlag() & 0xffffffffffffffff, 0);
  688. VERIFY_ARE_EQUAL(funcReader.GetNumResources(), 0);
  689. std::string dependency = funcReader.GetDependency(0);
  690. VERIFY_IS_TRUE(dependency.find("function_import") != std::string::npos);
  691. }
  692. else if (cur_str.compare("function3") == 0) {
  693. VERIFY_ARE_EQUAL(funcReader.GetFeatureFlag() & 0xffffffffffffffff, 0);
  694. VERIFY_ARE_EQUAL(funcReader.GetNumResources(), numResFlagCheck);
  695. for (unsigned i = 0; i < funcReader.GetNumResources(); ++i) {
  696. ResourceReader resReader = funcReader.GetResource(0);
  697. VERIFY_ARE_EQUAL(resReader.GetResourceClass(), hlsl::DXIL::ResourceClass::UAV);
  698. unsigned j = 0;
  699. for (; j < numResFlagCheck; ++j) {
  700. if (resFlags[j].name.compare(resReader.GetName()) == 0)
  701. break;
  702. }
  703. VERIFY_IS_LESS_THAN(j, numResFlagCheck);
  704. VERIFY_ARE_EQUAL(resReader.GetResourceKind(), resFlags[j].kind);
  705. VERIFY_ARE_EQUAL(resReader.GetFlags(), static_cast<uint32_t>(resFlags[j].flag));
  706. }
  707. }
  708. else {
  709. IFTBOOLMSG(false, E_FAIL, "unknown function name");
  710. }
  711. }
  712. VERIFY_ARE_EQUAL(resTableReader->GetNumResources(), 8);
  713. // This is validation test for DxilRuntimeReflection implemented on DxilRuntimeReflection.inl
  714. unique_ptr<DxilRuntimeReflection> pReflection(CreateDxilRuntimeReflection());
  715. VERIFY_IS_TRUE(pReflection->InitFromRDAT(pBlob->GetBufferPointer(), pBlob->GetBufferSize()));
  716. DxilLibraryDesc lib_reflection = pReflection->GetLibraryReflection();
  717. VERIFY_ARE_EQUAL(lib_reflection.NumFunctions, 4);
  718. for (uint32_t j = 0; j < 3; ++j) {
  719. DxilFunctionDesc function = lib_reflection.pFunction[j];
  720. std::string cur_str = str;
  721. cur_str.push_back('0' + j);
  722. if (cur_str.compare("function0") == 0) {
  723. hlsl::ShaderFlags flag;
  724. flag.SetUAVLoadAdditionalFormats(true);
  725. flag.SetLowPrecisionPresent(true);
  726. uint64_t rawFlag = flag.GetFeatureInfo();
  727. uint64_t featureFlag = static_cast<uint64_t>(function.FeatureInfo2) << 32;
  728. featureFlag |= static_cast<uint64_t>(function.FeatureInfo1);
  729. VERIFY_ARE_EQUAL(featureFlag, rawFlag);
  730. VERIFY_ARE_EQUAL(function.NumResources, 1);
  731. VERIFY_ARE_EQUAL(function.NumFunctionDependencies, 0);
  732. const DxilResourceDesc &resource = *function.Resources[0];
  733. VERIFY_ARE_EQUAL(resource.Class, (uint32_t)hlsl::DXIL::ResourceClass::UAV);
  734. VERIFY_ARE_EQUAL(resource.Kind, (uint32_t)hlsl::DXIL::ResourceKind::Texture1D);
  735. std::wstring wName = resource.Name;
  736. VERIFY_ARE_EQUAL(wName.compare(L"tex"), 0);
  737. }
  738. else if (cur_str.compare("function1") == 0) {
  739. hlsl::ShaderFlags flag;
  740. flag.SetLowPrecisionPresent(true);
  741. uint64_t rawFlag = flag.GetFeatureInfo();
  742. uint64_t featureFlag = static_cast<uint64_t>(function.FeatureInfo2) << 32;
  743. featureFlag |= static_cast<uint64_t>(function.FeatureInfo1);
  744. VERIFY_ARE_EQUAL(featureFlag, rawFlag);
  745. VERIFY_ARE_EQUAL(function.NumResources, 3);
  746. VERIFY_ARE_EQUAL(function.NumFunctionDependencies, 0);
  747. std::unordered_set<std::wstring> stringSet = { L"$Globals", L"b_buf", L"tex2" };
  748. for (uint32_t j = 0; j < 3; ++j) {
  749. const DxilResourceDesc &resource = *function.Resources[j];
  750. std::wstring compareName = resource.Name;
  751. VERIFY_IS_TRUE(stringSet.find(compareName) != stringSet.end());
  752. }
  753. }
  754. else if (cur_str.compare("function2") == 0) {
  755. VERIFY_ARE_EQUAL(function.FeatureInfo1, 0);
  756. VERIFY_ARE_EQUAL(function.FeatureInfo2, 0);
  757. VERIFY_ARE_EQUAL(function.NumResources, 0);
  758. VERIFY_ARE_EQUAL(function.NumFunctionDependencies, 1);
  759. std::wstring dependency = function.FunctionDependencies[0];
  760. VERIFY_IS_TRUE(dependency.find(L"function_import") != std::wstring::npos);
  761. }
  762. else if (cur_str.compare("function3") == 0) {
  763. VERIFY_ARE_EQUAL(function.FeatureInfo1, 0);
  764. VERIFY_ARE_EQUAL(function.FeatureInfo2, 0);
  765. VERIFY_ARE_EQUAL(function.NumResources, numResFlagCheck);
  766. VERIFY_ARE_EQUAL(function.NumFunctionDependencies, 0);
  767. for (unsigned i = 0; i < function.NumResources; ++i) {
  768. const DxilResourceDesc *res = function.Resources[i];
  769. VERIFY_ARE_EQUAL(res->Class, static_cast<uint32_t>(hlsl::DXIL::ResourceClass::UAV));
  770. unsigned j = 0;
  771. for (; j < numResFlagCheck; ++j) {
  772. CA2W WName(resFlags[j].name.c_str());
  773. std::wstring compareName(WName);
  774. if (compareName.compare(res->Name) == 0)
  775. break;
  776. }
  777. VERIFY_IS_LESS_THAN(j, numResFlagCheck);
  778. VERIFY_ARE_EQUAL(res->Kind, static_cast<uint32_t>(resFlags[j].kind));
  779. VERIFY_ARE_EQUAL(res->Flags, static_cast<uint32_t>(resFlags[j].flag));
  780. }
  781. }
  782. else {
  783. IFTBOOLMSG(false, E_FAIL, "unknown function name");
  784. }
  785. }
  786. VERIFY_IS_TRUE(lib_reflection.NumResources == 8);
  787. }
  788. }
  789. IFTBOOLMSG(blobFound, E_FAIL, "failed to find RDAT blob after compiling");
  790. }
  791. TEST_F(DxilContainerTest, CompileWhenOkThenCheckRDAT2) {
  792. if (m_ver.SkipDxilVersion(1, 3)) return;
  793. // This is a case when the user of resource is a constant, not instruction.
  794. // Compiler generates the following load instruction for texture.
  795. // load %class.Texture2D, %class.Texture2D* getelementptr inbounds ([3 x
  796. // %class.Texture2D], [3 x %class.Texture2D]*
  797. // @"\01?ThreeTextures@@3PAV?$Texture2D@M@@A", i32 0, i32 0), align 4
  798. const char *shader =
  799. "SamplerState Sampler : register(s0); RWBuffer<float> Uav : "
  800. "register(u0); Texture2D<float> ThreeTextures[3] : register(t0); "
  801. "float function1();"
  802. "[shader(\"raygeneration\")] void RayGenMain() { Uav[0] = "
  803. "ThreeTextures[0].Sample(Sampler, float2(0, 0)) + "
  804. "ThreeTextures[2].Sample(Sampler, float2(0, 0)) + function1(); }";
  805. CComPtr<IDxcCompiler> pCompiler;
  806. CComPtr<IDxcBlobEncoding> pSource;
  807. CComPtr<IDxcBlob> pProgram;
  808. CComPtr<IDxcBlobEncoding> pDisassembly;
  809. CComPtr<IDxcOperationResult> pResult;
  810. HRESULT status;
  811. VERIFY_SUCCEEDED(CreateCompiler(&pCompiler));
  812. CreateBlobFromText(shader, &pSource);
  813. VERIFY_SUCCEEDED(pCompiler->Compile(pSource, L"hlsl.hlsl", L"main",
  814. L"lib_6_3", nullptr, 0, nullptr, 0,
  815. nullptr, &pResult));
  816. VERIFY_SUCCEEDED(pResult->GetResult(&pProgram));
  817. VERIFY_SUCCEEDED(pResult->GetStatus(&status));
  818. VERIFY_SUCCEEDED(status);
  819. CComPtr<IDxcContainerReflection> pReflection;
  820. uint32_t partCount;
  821. IFT(m_dllSupport.CreateInstance(CLSID_DxcContainerReflection, &pReflection));
  822. IFT(pReflection->Load(pProgram));
  823. IFT(pReflection->GetPartCount(&partCount));
  824. bool blobFound = false;
  825. for (uint32_t i = 0; i < partCount; ++i) {
  826. uint32_t kind;
  827. IFT(pReflection->GetPartKind(i, &kind));
  828. if (kind == (uint32_t)hlsl::DxilFourCC::DFCC_RuntimeData) {
  829. blobFound = true;
  830. using namespace hlsl::RDAT;
  831. CComPtr<IDxcBlob> pBlob;
  832. IFT(pReflection->GetPartContent(i, &pBlob));
  833. DxilRuntimeData context;
  834. context.InitFromRDAT((char *)pBlob->GetBufferPointer(), pBlob->GetBufferSize());
  835. FunctionTableReader *funcTableReader = context.GetFunctionTableReader();
  836. ResourceTableReader *resTableReader = context.GetResourceTableReader();
  837. VERIFY_IS_TRUE(funcTableReader->GetNumFunctions() == 1);
  838. VERIFY_IS_TRUE(resTableReader->GetNumResources() == 3);
  839. FunctionReader funcReader = funcTableReader->GetItem(0);
  840. llvm::StringRef name(funcReader.GetUnmangledName());
  841. VERIFY_IS_TRUE(name.compare("RayGenMain") == 0);
  842. VERIFY_IS_TRUE(funcReader.GetShaderKind() ==
  843. hlsl::DXIL::ShaderKind::RayGeneration);
  844. VERIFY_IS_TRUE(funcReader.GetNumResources() == 3);
  845. VERIFY_IS_TRUE(funcReader.GetNumDependencies() == 1);
  846. llvm::StringRef dependencyName =
  847. hlsl::dxilutil::DemangleFunctionName(funcReader.GetDependency(0));
  848. VERIFY_IS_TRUE(dependencyName.compare("function1") == 0);
  849. }
  850. }
  851. IFTBOOLMSG(blobFound, E_FAIL, "failed to find RDAT blob after compiling");
  852. }
  853. static uint32_t EncodedVersion_lib_6_3 = hlsl::EncodeVersion(hlsl::DXIL::ShaderKind::Library, 6, 3);
  854. static uint32_t EncodedVersion_vs_6_3 = hlsl::EncodeVersion(hlsl::DXIL::ShaderKind::Vertex, 6, 3);
  855. static void Ref1_CheckCBuffer_Globals(ID3D12ShaderReflectionConstantBuffer *pCBReflection, D3D12_SHADER_BUFFER_DESC &cbDesc) {
  856. std::string cbName = cbDesc.Name;
  857. VERIFY_IS_TRUE(cbName.compare("$Globals") == 0);
  858. VERIFY_ARE_EQUAL(cbDesc.Size, 16);
  859. VERIFY_ARE_EQUAL(cbDesc.Type, D3D_CT_CBUFFER);
  860. VERIFY_ARE_EQUAL(cbDesc.Variables, 1);
  861. // cbval1
  862. ID3D12ShaderReflectionVariable *pVar = pCBReflection->GetVariableByIndex(0);
  863. D3D12_SHADER_VARIABLE_DESC varDesc;
  864. VERIFY_SUCCEEDED(pVar->GetDesc(&varDesc));
  865. VERIFY_ARE_EQUAL_STR(varDesc.Name, "cbval1");
  866. VERIFY_ARE_EQUAL(varDesc.StartOffset, 0);
  867. VERIFY_ARE_EQUAL(varDesc.Size, 4);
  868. // TODO: verify rest of variable
  869. ID3D12ShaderReflectionType *pType = pVar->GetType();
  870. D3D12_SHADER_TYPE_DESC tyDesc;
  871. VERIFY_SUCCEEDED(pType->GetDesc(&tyDesc));
  872. VERIFY_ARE_EQUAL(tyDesc.Class, D3D_SVC_SCALAR);
  873. VERIFY_ARE_EQUAL(tyDesc.Type, D3D_SVT_FLOAT);
  874. // TODO: verify rest of type
  875. }
  876. static void Ref1_CheckCBuffer_MyCB(ID3D12ShaderReflectionConstantBuffer *pCBReflection, D3D12_SHADER_BUFFER_DESC &cbDesc) {
  877. std::string cbName = cbDesc.Name;
  878. VERIFY_IS_TRUE(cbName.compare("MyCB") == 0);
  879. VERIFY_ARE_EQUAL(cbDesc.Size, 32);
  880. VERIFY_ARE_EQUAL(cbDesc.Type, D3D_CT_CBUFFER);
  881. VERIFY_ARE_EQUAL(cbDesc.Variables, 2);
  882. // cbval2
  883. {
  884. ID3D12ShaderReflectionVariable *pVar = pCBReflection->GetVariableByIndex(0);
  885. D3D12_SHADER_VARIABLE_DESC varDesc;
  886. VERIFY_SUCCEEDED(pVar->GetDesc(&varDesc));
  887. VERIFY_ARE_EQUAL_STR(varDesc.Name, "cbval2");
  888. VERIFY_ARE_EQUAL(varDesc.StartOffset, 0);
  889. VERIFY_ARE_EQUAL(varDesc.Size, 16);
  890. // TODO: verify rest of variable
  891. ID3D12ShaderReflectionType *pType = pVar->GetType();
  892. D3D12_SHADER_TYPE_DESC tyDesc;
  893. VERIFY_SUCCEEDED(pType->GetDesc(&tyDesc));
  894. VERIFY_ARE_EQUAL(tyDesc.Class, D3D_SVC_VECTOR);
  895. VERIFY_ARE_EQUAL(tyDesc.Type, D3D_SVT_INT);
  896. // TODO: verify rest of type
  897. }
  898. // cbval3
  899. {
  900. ID3D12ShaderReflectionVariable *pVar = pCBReflection->GetVariableByIndex(1);
  901. D3D12_SHADER_VARIABLE_DESC varDesc;
  902. VERIFY_SUCCEEDED(pVar->GetDesc(&varDesc));
  903. VERIFY_ARE_EQUAL_STR(varDesc.Name, "cbval3");
  904. VERIFY_ARE_EQUAL(varDesc.StartOffset, 16);
  905. VERIFY_ARE_EQUAL(varDesc.Size, 16);
  906. // TODO: verify rest of variable
  907. ID3D12ShaderReflectionType *pType = pVar->GetType();
  908. D3D12_SHADER_TYPE_DESC tyDesc;
  909. VERIFY_SUCCEEDED(pType->GetDesc(&tyDesc));
  910. VERIFY_ARE_EQUAL(tyDesc.Class, D3D_SVC_VECTOR);
  911. VERIFY_ARE_EQUAL(tyDesc.Type, D3D_SVT_INT);
  912. // TODO: verify rest of type
  913. }
  914. }
  915. static void Ref1_CheckBinding_Globals(D3D12_SHADER_INPUT_BIND_DESC &resDesc) {
  916. std::string resName = resDesc.Name;
  917. VERIFY_IS_TRUE(resName.compare("$Globals") == 0);
  918. VERIFY_ARE_EQUAL(resDesc.Type, D3D_SIT_CBUFFER);
  919. // not explicitly bound:
  920. VERIFY_ARE_EQUAL(resDesc.BindPoint, 4294967295);
  921. VERIFY_ARE_EQUAL(resDesc.Space, 0);
  922. VERIFY_ARE_EQUAL(resDesc.BindCount, 1);
  923. }
  924. static void Ref1_CheckBinding_MyCB(D3D12_SHADER_INPUT_BIND_DESC &resDesc) {
  925. std::string resName = resDesc.Name;
  926. VERIFY_IS_TRUE(resName.compare("MyCB") == 0);
  927. VERIFY_ARE_EQUAL(resDesc.Type, D3D_SIT_CBUFFER);
  928. VERIFY_ARE_EQUAL(resDesc.BindPoint, 11);
  929. VERIFY_ARE_EQUAL(resDesc.Space, 2);
  930. VERIFY_ARE_EQUAL(resDesc.BindCount, 1);
  931. }
  932. static void Ref1_CheckBinding_tex(D3D12_SHADER_INPUT_BIND_DESC &resDesc) {
  933. std::string resName = resDesc.Name;
  934. VERIFY_IS_TRUE(resName.compare("tex") == 0);
  935. VERIFY_ARE_EQUAL(resDesc.Type, D3D_SIT_UAV_RWTYPED);
  936. VERIFY_ARE_EQUAL(resDesc.BindPoint, 5);
  937. VERIFY_ARE_EQUAL(resDesc.Space, 0);
  938. VERIFY_ARE_EQUAL(resDesc.BindCount, 1);
  939. }
  940. static void Ref1_CheckBinding_tex2(D3D12_SHADER_INPUT_BIND_DESC &resDesc) {
  941. std::string resName = resDesc.Name;
  942. VERIFY_IS_TRUE(resName.compare("tex2") == 0);
  943. VERIFY_ARE_EQUAL(resDesc.Type, D3D_SIT_TEXTURE);
  944. VERIFY_ARE_EQUAL(resDesc.BindPoint, 0);
  945. VERIFY_ARE_EQUAL(resDesc.Space, 0);
  946. VERIFY_ARE_EQUAL(resDesc.BindCount, 1);
  947. }
  948. static void Ref1_CheckBinding_samp(D3D12_SHADER_INPUT_BIND_DESC &resDesc) {
  949. std::string resName = resDesc.Name;
  950. VERIFY_IS_TRUE(resName.compare("samp") == 0);
  951. VERIFY_ARE_EQUAL(resDesc.Type, D3D_SIT_SAMPLER);
  952. VERIFY_ARE_EQUAL(resDesc.BindPoint, 7);
  953. VERIFY_ARE_EQUAL(resDesc.Space, 0);
  954. VERIFY_ARE_EQUAL(resDesc.BindCount, 1);
  955. }
  956. static void Ref1_CheckBinding_b_buf(D3D12_SHADER_INPUT_BIND_DESC &resDesc) {
  957. std::string resName = resDesc.Name;
  958. VERIFY_IS_TRUE(resName.compare("b_buf") == 0);
  959. VERIFY_ARE_EQUAL(resDesc.Type, D3D_SIT_UAV_RWBYTEADDRESS);
  960. // not explicitly bound:
  961. VERIFY_ARE_EQUAL(resDesc.BindPoint, 4294967295);
  962. VERIFY_ARE_EQUAL(resDesc.Space, 0);
  963. VERIFY_ARE_EQUAL(resDesc.BindCount, 1);
  964. }
  965. TEST_F(DxilContainerTest, CompileWhenOkThenCheckReflection1) {
  966. if (m_ver.SkipDxilVersion(1, 3)) return;
  967. const char *shader =
  968. "float cbval1;"
  969. "cbuffer MyCB : register(b11, space2) { int4 cbval2, cbval3; }"
  970. "RWTexture1D<int4> tex : register(u5);"
  971. "Texture1D<float4> tex2 : register(t0);"
  972. "SamplerState samp : register(s7);"
  973. "RWByteAddressBuffer b_buf;"
  974. "float function0(min16float x) { "
  975. " return x + cbval2.x + tex[0].x; }"
  976. "float function1(float x, min12int i) {"
  977. " return x + cbval1 + b_buf.Load(x) + tex2.Sample(samp, x).x; }"
  978. "[shader(\"vertex\")]"
  979. "float function2(float4 x : POSITION) : SV_Position { return x + cbval1 + cbval3.x; }";
  980. CComPtr<IDxcCompiler> pCompiler;
  981. CComPtr<IDxcBlobEncoding> pSource;
  982. CComPtr<IDxcBlob> pProgram;
  983. CComPtr<IDxcBlobEncoding> pDisassembly;
  984. CComPtr<IDxcOperationResult> pResult;
  985. CComPtr<ID3D12LibraryReflection> pLibraryReflection;
  986. VERIFY_SUCCEEDED(CreateCompiler(&pCompiler));
  987. CreateBlobFromText(shader, &pSource);
  988. VERIFY_SUCCEEDED(pCompiler->Compile(pSource, L"hlsl.hlsl", L"",
  989. L"lib_6_3", nullptr, 0, nullptr, 0,
  990. nullptr, &pResult));
  991. VERIFY_SUCCEEDED(pResult->GetResult(&pProgram));
  992. CComPtr<IDxcContainerReflection> containerReflection;
  993. uint32_t partCount;
  994. VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcContainerReflection, &containerReflection));
  995. VERIFY_SUCCEEDED(containerReflection->Load(pProgram));
  996. VERIFY_SUCCEEDED(containerReflection->GetPartCount(&partCount));
  997. bool blobFound = false;
  998. for (uint32_t i = 0; i < partCount; ++i) {
  999. uint32_t kind;
  1000. VERIFY_SUCCEEDED(containerReflection->GetPartKind(i, &kind));
  1001. if (kind == (uint32_t)hlsl::DxilFourCC::DFCC_DXIL) {
  1002. blobFound = true;
  1003. VERIFY_SUCCEEDED(containerReflection->GetPartReflection(i, IID_PPV_ARGS(&pLibraryReflection)));
  1004. D3D12_LIBRARY_DESC LibDesc;
  1005. VERIFY_SUCCEEDED(pLibraryReflection->GetDesc(&LibDesc));
  1006. VERIFY_ARE_EQUAL(LibDesc.FunctionCount, 4);
  1007. for (INT iFn = 0; iFn < (INT)LibDesc.FunctionCount; iFn++) {
  1008. ID3D12FunctionReflection *pFunctionReflection = pLibraryReflection->GetFunctionByIndex(iFn);
  1009. D3D12_FUNCTION_DESC FnDesc;
  1010. pFunctionReflection->GetDesc(&FnDesc);
  1011. std::string Name = FnDesc.Name;
  1012. if (Name.compare("\01?function0@@YAM$f16@@Z") == 0) {
  1013. VERIFY_ARE_EQUAL(FnDesc.Version, EncodedVersion_lib_6_3);
  1014. VERIFY_ARE_EQUAL(FnDesc.ConstantBuffers, 1);
  1015. VERIFY_ARE_EQUAL(FnDesc.BoundResources, 2);
  1016. D3D12_SHADER_BUFFER_DESC cbDesc;
  1017. ID3D12ShaderReflectionConstantBuffer *pCBReflection = pFunctionReflection->GetConstantBufferByIndex(0);
  1018. VERIFY_SUCCEEDED(pCBReflection->GetDesc(&cbDesc));
  1019. std::string cbName = cbDesc.Name;
  1020. (void)(cbName);
  1021. Ref1_CheckCBuffer_MyCB(pCBReflection, cbDesc);
  1022. for (INT iRes = 0; iRes < (INT)FnDesc.BoundResources; iRes++) {
  1023. D3D12_SHADER_INPUT_BIND_DESC resDesc;
  1024. pFunctionReflection->GetResourceBindingDesc(iRes, &resDesc);
  1025. std::string resName = resDesc.Name;
  1026. if (resName.compare("$Globals") == 0) {
  1027. Ref1_CheckBinding_Globals(resDesc);
  1028. } else if (resName.compare("MyCB") == 0) {
  1029. Ref1_CheckBinding_MyCB(resDesc);
  1030. } else if (resName.compare("samp") == 0) {
  1031. Ref1_CheckBinding_samp(resDesc);
  1032. } else if (resName.compare("tex") == 0) {
  1033. Ref1_CheckBinding_tex(resDesc);
  1034. } else if (resName.compare("tex2") == 0) {
  1035. Ref1_CheckBinding_tex2(resDesc);
  1036. } else if (resName.compare("b_buf") == 0) {
  1037. Ref1_CheckBinding_b_buf(resDesc);
  1038. } else {
  1039. VERIFY_FAIL(L"Unexpected resource used");
  1040. }
  1041. }
  1042. } else if (Name.compare("\01?function1@@YAMMF@Z") == 0) {
  1043. VERIFY_ARE_EQUAL(FnDesc.Version, EncodedVersion_lib_6_3);
  1044. VERIFY_ARE_EQUAL(FnDesc.ConstantBuffers, 1);
  1045. VERIFY_ARE_EQUAL(FnDesc.BoundResources, 4);
  1046. D3D12_SHADER_BUFFER_DESC cbDesc;
  1047. ID3D12ShaderReflectionConstantBuffer *pCBReflection = pFunctionReflection->GetConstantBufferByIndex(0);
  1048. VERIFY_SUCCEEDED(pCBReflection->GetDesc(&cbDesc));
  1049. std::string cbName = cbDesc.Name;
  1050. (void)(cbName);
  1051. Ref1_CheckCBuffer_Globals(pCBReflection, cbDesc);
  1052. for (INT iRes = 0; iRes < (INT)FnDesc.BoundResources; iRes++) {
  1053. D3D12_SHADER_INPUT_BIND_DESC resDesc;
  1054. pFunctionReflection->GetResourceBindingDesc(iRes, &resDesc);
  1055. std::string resName = resDesc.Name;
  1056. if (resName.compare("$Globals") == 0) {
  1057. Ref1_CheckBinding_Globals(resDesc);
  1058. } else if (resName.compare("MyCB") == 0) {
  1059. Ref1_CheckBinding_MyCB(resDesc);
  1060. } else if (resName.compare("samp") == 0) {
  1061. Ref1_CheckBinding_samp(resDesc);
  1062. } else if (resName.compare("tex") == 0) {
  1063. Ref1_CheckBinding_tex(resDesc);
  1064. } else if (resName.compare("tex2") == 0) {
  1065. Ref1_CheckBinding_tex2(resDesc);
  1066. } else if (resName.compare("b_buf") == 0) {
  1067. Ref1_CheckBinding_b_buf(resDesc);
  1068. } else {
  1069. VERIFY_FAIL(L"Unexpected resource used");
  1070. }
  1071. }
  1072. } else if (Name.compare("\01?function2@@YAMV?$vector@M$03@@@Z") == 0) {
  1073. // library version of shader function is mangled
  1074. VERIFY_ARE_EQUAL(FnDesc.Version, EncodedVersion_lib_6_3);
  1075. VERIFY_ARE_EQUAL(FnDesc.ConstantBuffers, 2);
  1076. VERIFY_ARE_EQUAL(FnDesc.BoundResources, 2);
  1077. for (INT iCB = 0; iCB < (INT)FnDesc.BoundResources; iCB++) {
  1078. D3D12_SHADER_BUFFER_DESC cbDesc;
  1079. ID3D12ShaderReflectionConstantBuffer *pCBReflection = pFunctionReflection->GetConstantBufferByIndex(0);
  1080. VERIFY_SUCCEEDED(pCBReflection->GetDesc(&cbDesc));
  1081. std::string cbName = cbDesc.Name;
  1082. if (cbName.compare("$Globals") == 0) {
  1083. Ref1_CheckCBuffer_Globals(pCBReflection, cbDesc);
  1084. } else if (cbName.compare("MyCB") == 0) {
  1085. Ref1_CheckCBuffer_MyCB(pCBReflection, cbDesc);
  1086. }
  1087. }
  1088. for (INT iRes = 0; iRes < (INT)FnDesc.BoundResources; iRes++) {
  1089. D3D12_SHADER_INPUT_BIND_DESC resDesc;
  1090. pFunctionReflection->GetResourceBindingDesc(iRes, &resDesc);
  1091. std::string resName = resDesc.Name;
  1092. if (resName.compare("$Globals") == 0) {
  1093. Ref1_CheckBinding_Globals(resDesc);
  1094. } else if (resName.compare("MyCB") == 0) {
  1095. Ref1_CheckBinding_MyCB(resDesc);
  1096. } else {
  1097. VERIFY_FAIL(L"Unexpected resource used");
  1098. }
  1099. }
  1100. } else if (Name.compare("function2") == 0) {
  1101. // shader function with unmangled name
  1102. VERIFY_ARE_EQUAL(FnDesc.Version, EncodedVersion_vs_6_3);
  1103. VERIFY_ARE_EQUAL(FnDesc.ConstantBuffers, 2);
  1104. VERIFY_ARE_EQUAL(FnDesc.BoundResources, 2);
  1105. for (INT iCB = 0; iCB < (INT)FnDesc.BoundResources; iCB++) {
  1106. D3D12_SHADER_BUFFER_DESC cbDesc;
  1107. ID3D12ShaderReflectionConstantBuffer *pCBReflection = pFunctionReflection->GetConstantBufferByIndex(0);
  1108. VERIFY_SUCCEEDED(pCBReflection->GetDesc(&cbDesc));
  1109. std::string cbName = cbDesc.Name;
  1110. if (cbName.compare("$Globals") == 0) {
  1111. Ref1_CheckCBuffer_Globals(pCBReflection, cbDesc);
  1112. } else if (cbName.compare("MyCB") == 0) {
  1113. Ref1_CheckCBuffer_MyCB(pCBReflection, cbDesc);
  1114. }
  1115. }
  1116. for (INT iRes = 0; iRes < (INT)FnDesc.BoundResources; iRes++) {
  1117. D3D12_SHADER_INPUT_BIND_DESC resDesc;
  1118. pFunctionReflection->GetResourceBindingDesc(iRes, &resDesc);
  1119. std::string resName = resDesc.Name;
  1120. if (resName.compare("$Globals") == 0) {
  1121. Ref1_CheckBinding_Globals(resDesc);
  1122. } else if (resName.compare("MyCB") == 0) {
  1123. Ref1_CheckBinding_MyCB(resDesc);
  1124. } else {
  1125. VERIFY_FAIL(L"Unexpected resource used");
  1126. }
  1127. }
  1128. } else {
  1129. VERIFY_FAIL(L"Unexpected function");
  1130. }
  1131. }
  1132. // TODO: FINISH THIS
  1133. }
  1134. }
  1135. IFTBOOLMSG(blobFound, E_FAIL, "failed to find RDAT blob after compiling");
  1136. }
  1137. TEST_F(DxilContainerTest, CompileWhenOKThenIncludesFeatureInfo) {
  1138. CComPtr<IDxcCompiler> pCompiler;
  1139. CComPtr<IDxcBlobEncoding> pSource;
  1140. CComPtr<IDxcBlob> pProgram;
  1141. CComPtr<IDxcBlobEncoding> pDisassembly;
  1142. CComPtr<IDxcOperationResult> pResult;
  1143. hlsl::DxilContainerHeader *pHeader;
  1144. hlsl::DxilPartIterator pPartIter(nullptr, 0);
  1145. VERIFY_SUCCEEDED(CreateCompiler(&pCompiler));
  1146. CreateBlobFromText("float4 main() : SV_Target { return 0; }", &pSource);
  1147. VERIFY_SUCCEEDED(pCompiler->Compile(pSource, L"hlsl.hlsl", L"main", L"ps_6_0",
  1148. nullptr, 0, nullptr, 0, nullptr,
  1149. &pResult));
  1150. VERIFY_SUCCEEDED(pResult->GetResult(&pProgram));
  1151. // Now mess with the program bitcode.
  1152. pHeader = (hlsl::DxilContainerHeader *)pProgram->GetBufferPointer();
  1153. pPartIter = std::find_if(hlsl::begin(pHeader), hlsl::end(pHeader),
  1154. hlsl::DxilPartIsType(hlsl::DFCC_FeatureInfo));
  1155. VERIFY_ARE_NOT_EQUAL(hlsl::end(pHeader), pPartIter);
  1156. VERIFY_ARE_EQUAL(sizeof(uint64_t), (*pPartIter)->PartSize);
  1157. VERIFY_ARE_EQUAL(0, *(uint64_t *)hlsl::GetDxilPartData(*pPartIter));
  1158. }
  1159. TEST_F(DxilContainerTest, DisassemblyWhenBCInvalidThenFails) {
  1160. CComPtr<IDxcCompiler> pCompiler;
  1161. CComPtr<IDxcBlobEncoding> pSource;
  1162. CComPtr<IDxcBlob> pProgram;
  1163. CComPtr<IDxcBlobEncoding> pDisassembly;
  1164. CComPtr<IDxcOperationResult> pResult;
  1165. hlsl::DxilContainerHeader *pHeader;
  1166. hlsl::DxilPartHeader *pPart;
  1167. VERIFY_SUCCEEDED(CreateCompiler(&pCompiler));
  1168. CreateBlobFromText("float4 main() : SV_Target { return 0; }", &pSource);
  1169. VERIFY_SUCCEEDED(pCompiler->Compile(pSource, L"hlsl.hlsl", L"main", L"ps_6_0",
  1170. nullptr, 0, nullptr, 0, nullptr,
  1171. &pResult));
  1172. VERIFY_SUCCEEDED(pResult->GetResult(&pProgram));
  1173. // Now mess with the program bitcode.
  1174. pHeader = (hlsl::DxilContainerHeader *)pProgram->GetBufferPointer();
  1175. pPart = const_cast<hlsl::DxilPartHeader *>(
  1176. *std::find_if(hlsl::begin(pHeader), hlsl::end(pHeader),
  1177. hlsl::DxilPartIsType(hlsl::DFCC_DXIL)));
  1178. strcpy_s(hlsl::GetDxilPartData(pPart), pPart->PartSize, "corruption");
  1179. VERIFY_FAILED(pCompiler->Disassemble(pProgram, &pDisassembly));
  1180. }
  1181. TEST_F(DxilContainerTest, DisassemblyWhenMissingThenFails) {
  1182. CComPtr<IDxcCompiler> pCompiler;
  1183. CComPtr<IDxcBlobEncoding> pSource;
  1184. CComPtr<IDxcBlobEncoding> pDisassembly;
  1185. hlsl::DxilContainerHeader header;
  1186. SetupBasicHeader(&header);
  1187. VERIFY_SUCCEEDED(CreateCompiler(&pCompiler));
  1188. CreateBlobPinned(&header, header.ContainerSizeInBytes, CP_UTF8, &pSource);
  1189. VERIFY_FAILED(pCompiler->Disassemble(pSource, &pDisassembly));
  1190. }
  1191. TEST_F(DxilContainerTest, DisassemblyWhenInvalidThenFails) {
  1192. CComPtr<IDxcCompiler> pCompiler;
  1193. CComPtr<IDxcBlobEncoding> pDisassembly;
  1194. uint8_t scratch[1024];
  1195. hlsl::DxilContainerHeader *pHeader = (hlsl::DxilContainerHeader *)scratch;
  1196. VERIFY_SUCCEEDED(CreateCompiler(&pCompiler));
  1197. // Too small to contain header.
  1198. {
  1199. CComPtr<IDxcBlobEncoding> pSource;
  1200. SetupBasicHeader(pHeader);
  1201. CreateBlobPinned(pHeader, sizeof(hlsl::DxilContainerHeader) - 4, CP_UTF8,
  1202. &pSource);
  1203. VERIFY_FAILED(pCompiler->Disassemble(pSource, &pDisassembly));
  1204. }
  1205. // Wrong major version.
  1206. {
  1207. CComPtr<IDxcBlobEncoding> pSource;
  1208. SetupBasicHeader(pHeader);
  1209. pHeader->Version.Major = 100;
  1210. CreateBlobPinned(pHeader, pHeader->ContainerSizeInBytes, CP_UTF8, &pSource);
  1211. VERIFY_FAILED(pCompiler->Disassemble(pSource, &pDisassembly));
  1212. }
  1213. // Size out of bounds.
  1214. {
  1215. CComPtr<IDxcBlobEncoding> pSource;
  1216. SetupBasicHeader(pHeader);
  1217. pHeader->ContainerSizeInBytes = 1024;
  1218. CreateBlobPinned(pHeader, sizeof(hlsl::DxilContainerHeader), CP_UTF8,
  1219. &pSource);
  1220. VERIFY_FAILED(pCompiler->Disassemble(pSource, &pDisassembly));
  1221. }
  1222. // Size too large as per spec limit.
  1223. {
  1224. CComPtr<IDxcBlobEncoding> pSource;
  1225. SetupBasicHeader(pHeader);
  1226. pHeader->ContainerSizeInBytes = hlsl::DxilContainerMaxSize + 1;
  1227. CreateBlobPinned(pHeader, pHeader->ContainerSizeInBytes, CP_UTF8, &pSource);
  1228. VERIFY_FAILED(pCompiler->Disassemble(pSource, &pDisassembly));
  1229. }
  1230. // Not large enough to hold offset table.
  1231. {
  1232. CComPtr<IDxcBlobEncoding> pSource;
  1233. SetupBasicHeader(pHeader);
  1234. pHeader->PartCount = 1;
  1235. CreateBlobPinned(pHeader, pHeader->ContainerSizeInBytes, CP_UTF8, &pSource);
  1236. VERIFY_FAILED(pCompiler->Disassemble(pSource, &pDisassembly));
  1237. }
  1238. // Part offset out of bounds.
  1239. {
  1240. CComPtr<IDxcBlobEncoding> pSource;
  1241. SetupBasicHeader(pHeader);
  1242. pHeader->PartCount = 1;
  1243. *((uint32_t *)(pHeader + 1)) = 1024;
  1244. pHeader->ContainerSizeInBytes += sizeof(uint32_t);
  1245. CreateBlobPinned(pHeader, pHeader->ContainerSizeInBytes, CP_UTF8, &pSource);
  1246. VERIFY_FAILED(pCompiler->Disassemble(pSource, &pDisassembly));
  1247. }
  1248. // Part size out of bounds.
  1249. {
  1250. CComPtr<IDxcBlobEncoding> pSource;
  1251. SetupBasicHeader(pHeader);
  1252. pHeader->PartCount = 1;
  1253. *((uint32_t *)(pHeader + 1)) = sizeof(*pHeader) + sizeof(uint32_t);
  1254. pHeader->ContainerSizeInBytes += sizeof(uint32_t);
  1255. hlsl::GetDxilContainerPart(pHeader, 0)->PartSize = 1024;
  1256. pHeader->ContainerSizeInBytes += sizeof(hlsl::DxilPartHeader);
  1257. CreateBlobPinned(pHeader, pHeader->ContainerSizeInBytes, CP_UTF8, &pSource);
  1258. VERIFY_FAILED(pCompiler->Disassemble(pSource, &pDisassembly));
  1259. }
  1260. }
  1261. TEST_F(DxilContainerTest, DisassemblyWhenValidThenOK) {
  1262. CComPtr<IDxcCompiler> pCompiler;
  1263. CComPtr<IDxcBlobEncoding> pSource;
  1264. CComPtr<IDxcBlob> pProgram;
  1265. CComPtr<IDxcBlobEncoding> pDisassembly;
  1266. CComPtr<IDxcOperationResult> pResult;
  1267. hlsl::DxilContainerHeader header;
  1268. SetupBasicHeader(&header);
  1269. VERIFY_SUCCEEDED(CreateCompiler(&pCompiler));
  1270. CreateBlobFromText("float4 main() : SV_Target { return 0; }", &pSource);
  1271. VERIFY_SUCCEEDED(pCompiler->Compile(pSource, L"hlsl.hlsl", L"main", L"ps_6_0",
  1272. nullptr, 0, nullptr, 0, nullptr,
  1273. &pResult));
  1274. VERIFY_SUCCEEDED(pResult->GetResult(&pProgram));
  1275. VERIFY_SUCCEEDED(pCompiler->Disassemble(pProgram, &pDisassembly));
  1276. std::string disassembleString(BlobToUtf8(pDisassembly));
  1277. VERIFY_ARE_NOT_EQUAL(0, disassembleString.size());
  1278. }
  1279. class HlslFileVariables {
  1280. private:
  1281. std::wstring m_Entry;
  1282. std::wstring m_Mode;
  1283. std::wstring m_Target;
  1284. std::vector<std::wstring> m_Arguments;
  1285. std::vector<LPCWSTR> m_ArgumentPtrs;
  1286. public:
  1287. HlslFileVariables(HlslFileVariables &other) = delete;
  1288. const LPCWSTR *GetArguments() const { return m_ArgumentPtrs.data(); }
  1289. UINT32 GetArgumentCount() const { return m_ArgumentPtrs.size(); }
  1290. LPCWSTR GetEntry() const { return m_Entry.c_str(); }
  1291. LPCWSTR GetMode() const { return m_Mode.c_str(); }
  1292. LPCWSTR GetTarget() const { return m_Target.c_str(); }
  1293. void Reset();
  1294. HRESULT SetFromText(_In_count_(len) const char *pText, size_t len);
  1295. };
  1296. void HlslFileVariables::Reset() {
  1297. m_Entry.resize(0);
  1298. m_Mode.resize(0);
  1299. m_Target.resize(0);
  1300. m_Arguments.resize(0);
  1301. m_ArgumentPtrs.resize(0);
  1302. }
  1303. #include <codecvt>
  1304. static bool wcsneq(const wchar_t *pValue, const wchar_t *pCheck) {
  1305. return 0 == wcsncmp(pValue, pCheck, wcslen(pCheck));
  1306. }
  1307. HRESULT HlslFileVariables::SetFromText(_In_count_(len) const char *pText, size_t len) {
  1308. // Look for the line of interest.
  1309. const char *pEnd = pText + len;
  1310. const char *pLineEnd = pText;
  1311. while (pLineEnd < pEnd && *pLineEnd != '\n') pLineEnd++;
  1312. // Create a UTF-16-backing store.
  1313. std::wstring_convert<std::codecvt_utf8_utf16<wchar_t> > w;
  1314. std::wstring line = w.from_bytes(pText, pLineEnd);
  1315. // Find starting and ending '-*-' delimiters.
  1316. const wchar_t *pWText = line.c_str();
  1317. const wchar_t *pVarStart = wcsstr(pWText, L"-*-");
  1318. if (!pVarStart) return E_INVALIDARG;
  1319. pVarStart += 3;
  1320. const wchar_t *pVarEnd = wcsstr(pVarStart, L"-*-");
  1321. if (!pVarEnd) return E_INVALIDARG;
  1322. for (;;) {
  1323. // Find 'name' ':' 'value' ';'
  1324. const wchar_t *pVarNameStart = pVarStart;
  1325. while (pVarNameStart < pVarEnd && L' ' == *pVarNameStart) ++pVarNameStart;
  1326. if (pVarNameStart == pVarEnd) break;
  1327. const wchar_t *pVarValDelim = pVarNameStart;
  1328. while (pVarValDelim < pVarEnd && L':' != *pVarValDelim) ++pVarValDelim;
  1329. if (pVarValDelim == pVarEnd) break;
  1330. const wchar_t *pVarValStart = pVarValDelim + 1;
  1331. while (pVarValStart < pVarEnd && L' ' == *pVarValStart) ++pVarValStart;
  1332. if (pVarValStart == pVarEnd) break;
  1333. const wchar_t *pVarValEnd = pVarValStart;
  1334. while (pVarValEnd < pVarEnd && L';' != *pVarValEnd) ++pVarValEnd;
  1335. if (wcsneq(pVarNameStart, L"mode")) {
  1336. m_Mode.assign(pVarValStart, pVarValEnd - pVarValStart - 1);
  1337. }
  1338. else if (wcsneq(pVarNameStart, L"hlsl-entry")) {
  1339. m_Entry.assign(pVarValStart, pVarValEnd - pVarValStart - 1);
  1340. }
  1341. else if (wcsneq(pVarNameStart, L"hlsl-target")) {
  1342. m_Target.assign(pVarValStart, pVarValEnd - pVarValStart - 1);
  1343. }
  1344. else if (wcsneq(pVarNameStart, L"hlsl-args")) {
  1345. // skip for now
  1346. }
  1347. }
  1348. return S_OK;
  1349. }
  1350. TEST_F(DxilContainerTest, ReflectionMatchesDXBC_CheckIn) {
  1351. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  1352. ReflectionTest(hlsl_test::GetPathToHlslDataFile(L"..\\CodeGenHLSL\\Samples\\DX11\\SimpleBezier11DS.hlsl").c_str(), false);
  1353. ReflectionTest(hlsl_test::GetPathToHlslDataFile(L"..\\CodeGenHLSL\\Samples\\DX11\\SubD11_SmoothPS.hlsl").c_str(), false);
  1354. }
  1355. TEST_F(DxilContainerTest, ReflectionMatchesDXBC_Full) {
  1356. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  1357. std::wstring codeGenPath = hlsl_test::GetPathToHlslDataFile(L"..\\CodeGenHLSL\\Samples");
  1358. // This test was running at about three minutes; that can be enabled with TestAll=True,
  1359. // otherwise the much shorter list is used.
  1360. const bool TestAll = false;
  1361. LPCWSTR PreApprovedPaths[] = {
  1362. L"2DQuadShaders_VS.hlsl",
  1363. L"BC6HEncode_TryModeLE10CS.hlsl",
  1364. L"DepthViewerVS.hlsl",
  1365. L"DetailTessellation11_DS.hlsl",
  1366. L"GenerateHistogramCS.hlsl",
  1367. L"OIT_PS.hlsl",
  1368. L"PNTriangles11_DS.hlsl",
  1369. L"PerfGraphPS.hlsl",
  1370. L"PerfGraphVS.hlsl",
  1371. L"ScreenQuadVS.hlsl",
  1372. L"SimpleBezier11HS.hlsl"
  1373. };
  1374. for (auto &p: recursive_directory_iterator(path(codeGenPath))) {
  1375. if (is_regular_file(p)) {
  1376. LPCWSTR fullPath = p.path().c_str();
  1377. if (wcsstr(fullPath, L".hlsli") != nullptr) continue;
  1378. if (wcsstr(fullPath, L"TessellatorCS40_defines.h") != nullptr) continue;
  1379. // Skip failed tests.
  1380. if (wcsstr(fullPath, L"SubD11_SubDToBezierHS") != nullptr) continue;
  1381. if (!TestAll) {
  1382. bool shouldTest = false;
  1383. LPCWSTR *PreApprovedEnd = PreApprovedPaths + _countof(PreApprovedPaths);
  1384. shouldTest = PreApprovedEnd == std::find_if(PreApprovedPaths, PreApprovedEnd,
  1385. [&](LPCWSTR candidate) { return nullptr != wcsstr(fullPath, candidate); });
  1386. if (!shouldTest) {
  1387. break;
  1388. }
  1389. }
  1390. auto start = std::chrono::system_clock::now();
  1391. ReflectionTest(fullPath, true);
  1392. if (TestAll) {
  1393. // If testing all cases, print out their timing.
  1394. auto end = std::chrono::system_clock::now();
  1395. auto dur = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
  1396. LogCommentFmt(L"%s,%u", fullPath, (unsigned)dur.count());
  1397. }
  1398. }
  1399. }
  1400. }
  1401. TEST_F(DxilContainerTest, ValidateFromLL_Abs2) {
  1402. CodeGenTestCheck(L"abs2_m.ll");
  1403. }
  1404. TEST_F(DxilContainerTest, DxilContainerUnitTest) {
  1405. CComPtr<IDxcCompiler> pCompiler;
  1406. CComPtr<IDxcBlobEncoding> pSource;
  1407. CComPtr<IDxcBlob> pProgram;
  1408. CComPtr<IDxcBlobEncoding> pDisassembly;
  1409. CComPtr<IDxcOperationResult> pResult;
  1410. std::vector<LPCWSTR> arguments;
  1411. arguments.emplace_back(L"/Zi");
  1412. VERIFY_SUCCEEDED(CreateCompiler(&pCompiler));
  1413. CreateBlobFromText("float4 main() : SV_Target { return 0; }", &pSource);
  1414. // Test DxilContainer with ShaderDebugInfoDXIL
  1415. VERIFY_SUCCEEDED(pCompiler->Compile(pSource, L"hlsl.hlsl", L"main", L"ps_6_0", arguments.data(), 1, nullptr, 0, nullptr, &pResult));
  1416. VERIFY_SUCCEEDED(pResult->GetResult(&pProgram));
  1417. const hlsl::DxilContainerHeader *pHeader = static_cast<const hlsl::DxilContainerHeader *> (pProgram->GetBufferPointer());
  1418. VERIFY_IS_TRUE(hlsl::IsValidDxilContainer(pHeader, pProgram->GetBufferSize()));
  1419. VERIFY_IS_NOT_NULL(hlsl::IsDxilContainerLike(pHeader, pProgram->GetBufferSize()));
  1420. VERIFY_IS_NOT_NULL(hlsl::GetDxilProgramHeader(pHeader, hlsl::DxilFourCC::DFCC_DXIL));
  1421. VERIFY_IS_NOT_NULL(hlsl::GetDxilProgramHeader(pHeader, hlsl::DxilFourCC::DFCC_ShaderDebugInfoDXIL));
  1422. VERIFY_IS_NOT_NULL(hlsl::GetDxilPartByType(pHeader, hlsl::DxilFourCC::DFCC_DXIL));
  1423. VERIFY_IS_NOT_NULL(hlsl::GetDxilPartByType(pHeader, hlsl::DxilFourCC::DFCC_ShaderDebugInfoDXIL));
  1424. pResult.Release();
  1425. pProgram.Release();
  1426. // Test DxilContainer without ShaderDebugInfoDXIL
  1427. VERIFY_SUCCEEDED(pCompiler->Compile(pSource, L"hlsl.hlsl", L"main", L"ps_6_0", nullptr, 0, nullptr, 0, nullptr, &pResult));
  1428. VERIFY_SUCCEEDED(pResult->GetResult(&pProgram));
  1429. pHeader = static_cast<const hlsl::DxilContainerHeader *> (pProgram->GetBufferPointer());
  1430. VERIFY_IS_TRUE(hlsl::IsValidDxilContainer(pHeader, pProgram->GetBufferSize()));
  1431. VERIFY_IS_NOT_NULL(hlsl::IsDxilContainerLike(pHeader, pProgram->GetBufferSize()));
  1432. VERIFY_IS_NOT_NULL(hlsl::GetDxilProgramHeader(pHeader, hlsl::DxilFourCC::DFCC_DXIL));
  1433. VERIFY_IS_NULL(hlsl::GetDxilProgramHeader(pHeader, hlsl::DxilFourCC::DFCC_ShaderDebugInfoDXIL));
  1434. VERIFY_IS_NOT_NULL(hlsl::GetDxilPartByType(pHeader, hlsl::DxilFourCC::DFCC_DXIL));
  1435. VERIFY_IS_NULL(hlsl::GetDxilPartByType(pHeader, hlsl::DxilFourCC::DFCC_ShaderDebugInfoDXIL));
  1436. // Test Empty DxilContainer
  1437. hlsl::DxilContainerHeader header;
  1438. SetupBasicHeader(&header);
  1439. VERIFY_IS_TRUE(hlsl::IsValidDxilContainer(&header, header.ContainerSizeInBytes));
  1440. VERIFY_IS_NOT_NULL(hlsl::IsDxilContainerLike(&header, header.ContainerSizeInBytes));
  1441. VERIFY_IS_NULL(hlsl::GetDxilProgramHeader(&header, hlsl::DxilFourCC::DFCC_DXIL));
  1442. VERIFY_IS_NULL(hlsl::GetDxilPartByType(&header, hlsl::DxilFourCC::DFCC_DXIL));
  1443. }