DxilContainerTest.cpp 66 KB

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