DxilModuleTest.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // Copyright (C) Microsoft Corporation. All rights reserved. //
  4. // DxilModuleTest.cpp //
  5. // //
  6. // Provides unit tests for DxilModule. //
  7. // //
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #include "dxc/Test/CompilationResult.h"
  10. #include "dxc/Test/HlslTestUtils.h"
  11. #include "dxc/Test/DxcTestUtils.h"
  12. #include "dxc/Support/microcom.h"
  13. #include "dxc/dxcapi.internal.h"
  14. #include "dxc/HLSL/HLOperationLowerExtension.h"
  15. #include "dxc/HlslIntrinsicOp.h"
  16. #include "dxc/DXIL/DxilOperations.h"
  17. #include "dxc/DXIL/DxilInstructions.h"
  18. #include "dxc/DxilContainer/DxilContainer.h"
  19. #include "dxc/DXIL/DxilModule.h"
  20. #include "llvm/Support/Regex.h"
  21. #include "llvm/Support/MSFileSystem.h"
  22. #include "llvm/Support/FileSystem.h"
  23. #include "llvm/Support/MemoryBuffer.h"
  24. #include "llvm/Support/ErrorOr.h"
  25. #include "llvm/Bitcode/ReaderWriter.h"
  26. #include "llvm/IR/LLVMContext.h"
  27. #include "llvm/IR/InstIterator.h"
  28. using namespace hlsl;
  29. using namespace llvm;
  30. ///////////////////////////////////////////////////////////////////////////////
  31. // DxilModule unit tests.
  32. #ifdef _WIN32
  33. class DxilModuleTest {
  34. #else
  35. class DxilModuleTest : public ::testing::Test {
  36. #endif
  37. public:
  38. BEGIN_TEST_CLASS(DxilModuleTest)
  39. TEST_CLASS_PROPERTY(L"Parallel", L"true")
  40. TEST_METHOD_PROPERTY(L"Priority", L"0")
  41. END_TEST_CLASS()
  42. TEST_CLASS_SETUP(InitSupport);
  43. dxc::DxcDllSupport m_dllSupport;
  44. VersionSupportInfo m_ver;
  45. // Basic loading tests.
  46. TEST_METHOD(LoadDxilModule_1_0)
  47. TEST_METHOD(LoadDxilModule_1_1)
  48. TEST_METHOD(LoadDxilModule_1_2)
  49. // Precise query tests.
  50. TEST_METHOD(Precise1)
  51. TEST_METHOD(Precise2)
  52. TEST_METHOD(Precise3)
  53. TEST_METHOD(Precise4)
  54. TEST_METHOD(Precise5)
  55. TEST_METHOD(Precise6)
  56. TEST_METHOD(Precise7)
  57. TEST_METHOD(CSGetNumThreads)
  58. TEST_METHOD(MSGetNumThreads)
  59. TEST_METHOD(ASGetNumThreads)
  60. TEST_METHOD(SetValidatorVersion)
  61. TEST_METHOD(PayloadQualifier)
  62. void VerifyValidatorVersionFails(
  63. LPCWSTR shaderModel, const std::vector<LPCWSTR> &arguments,
  64. const std::vector<LPCSTR> &expectedErrors);
  65. void VerifyValidatorVersionMatches(
  66. LPCWSTR shaderModel, const std::vector<LPCWSTR> &arguments,
  67. unsigned expectedMajor = UINT_MAX, unsigned expectedMinor = UINT_MAX);
  68. };
  69. bool DxilModuleTest::InitSupport() {
  70. if (!m_dllSupport.IsEnabled()) {
  71. VERIFY_SUCCEEDED(m_dllSupport.Initialize());
  72. m_ver.Initialize(m_dllSupport);
  73. }
  74. return true;
  75. }
  76. ///////////////////////////////////////////////////////////////////////////////
  77. // Compilation and dxil module loading support.
  78. namespace {
  79. class Compiler {
  80. public:
  81. Compiler(dxc::DxcDllSupport &dll)
  82. : m_dllSupport(dll)
  83. , m_msf(CreateMSFileSystem())
  84. , m_pts(m_msf.get())
  85. {
  86. m_ver.Initialize(m_dllSupport);
  87. VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcCompiler, &pCompiler));
  88. }
  89. bool SkipDxil_Test(unsigned major, unsigned minor) {
  90. return m_ver.SkipDxilVersion(major, minor);
  91. }
  92. IDxcOperationResult *Compile(const char *program, LPCWSTR shaderModel = L"ps_6_0") {
  93. return Compile(program, shaderModel, {}, {});
  94. }
  95. IDxcOperationResult *Compile(const char *program, LPCWSTR shaderModel, const std::vector<LPCWSTR> &arguments, const std::vector<DxcDefine> defs ) {
  96. Utf8ToBlob(m_dllSupport, program, &pCodeBlob);
  97. VERIFY_SUCCEEDED(pCompiler->Compile(pCodeBlob, L"hlsl.hlsl", L"main",
  98. shaderModel,
  99. const_cast<LPCWSTR *>(arguments.data()), arguments.size(),
  100. defs.data(), defs.size(),
  101. nullptr, &pCompileResult));
  102. return pCompileResult;
  103. }
  104. std::string Disassemble() {
  105. CComPtr<IDxcBlob> pBlob;
  106. CheckOperationSucceeded(pCompileResult, &pBlob);
  107. return DisassembleProgram(m_dllSupport, pBlob);
  108. }
  109. DxilModule &GetDxilModule() {
  110. // Make sure we compiled successfully.
  111. CComPtr<IDxcBlob> pBlob;
  112. CheckOperationSucceeded(pCompileResult, &pBlob);
  113. // Verify we have a valid dxil container.
  114. const DxilContainerHeader *pContainer =
  115. IsDxilContainerLike(pBlob->GetBufferPointer(), pBlob->GetBufferSize());
  116. VERIFY_IS_NOT_NULL(pContainer);
  117. VERIFY_IS_TRUE(IsValidDxilContainer(pContainer, pBlob->GetBufferSize()));
  118. // Get Dxil part from container.
  119. DxilPartIterator it = std::find_if(begin(pContainer), end(pContainer), DxilPartIsType(DFCC_DXIL));
  120. VERIFY_IS_FALSE(it == end(pContainer));
  121. const DxilProgramHeader *pProgramHeader =
  122. reinterpret_cast<const DxilProgramHeader *>(GetDxilPartData(*it));
  123. VERIFY_IS_TRUE(IsValidDxilProgramHeader(pProgramHeader, (*it)->PartSize));
  124. // Get a pointer to the llvm bitcode.
  125. const char *pIL;
  126. uint32_t pILLength;
  127. GetDxilProgramBitcode(pProgramHeader, &pIL, &pILLength);
  128. // Parse llvm bitcode into a module.
  129. std::unique_ptr<llvm::MemoryBuffer> pBitcodeBuf(
  130. llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(pIL, pILLength), "", false));
  131. llvm::ErrorOr<std::unique_ptr<llvm::Module>>
  132. pModule(llvm::parseBitcodeFile(pBitcodeBuf->getMemBufferRef(), m_llvmContext));
  133. if (std::error_code ec = pModule.getError()) {
  134. VERIFY_FAIL();
  135. }
  136. m_module = std::move(pModule.get());
  137. // Grab the dxil module;
  138. DxilModule *DM = DxilModule::TryGetDxilModule(m_module.get());
  139. VERIFY_IS_NOT_NULL(DM);
  140. return *DM;
  141. }
  142. public:
  143. static ::llvm::sys::fs::MSFileSystem *CreateMSFileSystem() {
  144. ::llvm::sys::fs::MSFileSystem *msfPtr;
  145. VERIFY_SUCCEEDED(CreateMSFileSystemForDisk(&msfPtr));
  146. return msfPtr;
  147. }
  148. dxc::DxcDllSupport &m_dllSupport;
  149. VersionSupportInfo m_ver;
  150. CComPtr<IDxcCompiler> pCompiler;
  151. CComPtr<IDxcBlobEncoding> pCodeBlob;
  152. CComPtr<IDxcOperationResult> pCompileResult;
  153. llvm::LLVMContext m_llvmContext;
  154. std::unique_ptr<llvm::Module> m_module;
  155. std::unique_ptr<::llvm::sys::fs::MSFileSystem> m_msf;
  156. ::llvm::sys::fs::AutoPerThreadSystem m_pts;
  157. };
  158. }
  159. ///////////////////////////////////////////////////////////////////////////////
  160. // Unit Test Implementation
  161. TEST_F(DxilModuleTest, LoadDxilModule_1_0) {
  162. Compiler c(m_dllSupport);
  163. c.Compile(
  164. "float4 main() : SV_Target {\n"
  165. " return 0;\n"
  166. "}\n"
  167. ,
  168. L"ps_6_0"
  169. );
  170. // Basic sanity check on dxil version in dxil module.
  171. DxilModule &DM = c.GetDxilModule();
  172. unsigned vMajor, vMinor;
  173. DM.GetDxilVersion(vMajor, vMinor);
  174. VERIFY_IS_TRUE(vMajor == 1);
  175. VERIFY_IS_TRUE(vMinor == 0);
  176. }
  177. TEST_F(DxilModuleTest, LoadDxilModule_1_1) {
  178. Compiler c(m_dllSupport);
  179. if (c.SkipDxil_Test(1,1)) return;
  180. c.Compile(
  181. "float4 main() : SV_Target {\n"
  182. " return 0;\n"
  183. "}\n"
  184. ,
  185. L"ps_6_1"
  186. );
  187. // Basic sanity check on dxil version in dxil module.
  188. DxilModule &DM = c.GetDxilModule();
  189. unsigned vMajor, vMinor;
  190. DM.GetDxilVersion(vMajor, vMinor);
  191. VERIFY_IS_TRUE(vMajor == 1);
  192. VERIFY_IS_TRUE(vMinor == 1);
  193. }
  194. TEST_F(DxilModuleTest, LoadDxilModule_1_2) {
  195. Compiler c(m_dllSupport);
  196. if (c.SkipDxil_Test(1,2)) return;
  197. c.Compile(
  198. "float4 main() : SV_Target {\n"
  199. " return 0;\n"
  200. "}\n"
  201. ,
  202. L"ps_6_2"
  203. );
  204. // Basic sanity check on dxil version in dxil module.
  205. DxilModule &DM = c.GetDxilModule();
  206. unsigned vMajor, vMinor;
  207. DM.GetDxilVersion(vMajor, vMinor);
  208. VERIFY_IS_TRUE(vMajor == 1);
  209. VERIFY_IS_TRUE(vMinor == 2);
  210. }
  211. TEST_F(DxilModuleTest, Precise1) {
  212. Compiler c(m_dllSupport);
  213. c.Compile(
  214. "precise float main(float x : X, float y : Y) : SV_Target {\n"
  215. " return sqrt(x) + y;\n"
  216. "}\n"
  217. );
  218. // Make sure sqrt and add are marked precise.
  219. DxilModule &DM = c.GetDxilModule();
  220. Function *F = DM.GetEntryFunction();
  221. int numChecks = 0;
  222. for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
  223. Instruction *Inst = &*I;
  224. if (DxilInst_Sqrt(Inst)) {
  225. numChecks++;
  226. VERIFY_IS_TRUE(DM.IsPrecise(Inst));
  227. }
  228. else if (LlvmInst_FAdd(Inst)) {
  229. numChecks++;
  230. VERIFY_IS_TRUE(DM.IsPrecise(Inst));
  231. }
  232. }
  233. VERIFY_ARE_EQUAL(numChecks, 2);
  234. }
  235. TEST_F(DxilModuleTest, Precise2) {
  236. Compiler c(m_dllSupport);
  237. c.Compile(
  238. "float main(float x : X, float y : Y) : SV_Target {\n"
  239. " return sqrt(x) + y;\n"
  240. "}\n"
  241. );
  242. // Make sure sqrt and add are not marked precise.
  243. DxilModule &DM = c.GetDxilModule();
  244. Function *F = DM.GetEntryFunction();
  245. int numChecks = 0;
  246. for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
  247. Instruction *Inst = &*I;
  248. if (DxilInst_Sqrt(Inst)) {
  249. numChecks++;
  250. VERIFY_IS_FALSE(DM.IsPrecise(Inst));
  251. }
  252. else if (LlvmInst_FAdd(Inst)) {
  253. numChecks++;
  254. VERIFY_IS_FALSE(DM.IsPrecise(Inst));
  255. }
  256. }
  257. VERIFY_ARE_EQUAL(numChecks, 2);
  258. }
  259. TEST_F(DxilModuleTest, Precise3) {
  260. // TODO: Enable this test when precise metadata is inserted for Gis.
  261. if (const bool GisIsBroken = true) return;
  262. Compiler c(m_dllSupport);
  263. c.Compile(
  264. "float main(float x : X, float y : Y) : SV_Target {\n"
  265. " return sqrt(x) + y;\n"
  266. "}\n",
  267. L"ps_6_0",
  268. { L"/Gis" }, {}
  269. );
  270. // Make sure sqrt and add are marked precise.
  271. DxilModule &DM = c.GetDxilModule();
  272. Function *F = DM.GetEntryFunction();
  273. int numChecks = 0;
  274. for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
  275. Instruction *Inst = &*I;
  276. if (DxilInst_Sqrt(Inst)) {
  277. numChecks++;
  278. VERIFY_IS_TRUE(DM.IsPrecise(Inst));
  279. }
  280. else if (LlvmInst_FAdd(Inst)) {
  281. numChecks++;
  282. VERIFY_IS_TRUE(DM.IsPrecise(Inst));
  283. }
  284. }
  285. VERIFY_ARE_EQUAL(numChecks, 2);
  286. }
  287. TEST_F(DxilModuleTest, Precise4) {
  288. Compiler c(m_dllSupport);
  289. c.Compile(
  290. "float main(float x : X, float y : Y) : SV_Target {\n"
  291. " precise float sx = 1 / sqrt(x);\n"
  292. " return sx + y;\n"
  293. "}\n"
  294. );
  295. // Make sure sqrt and div are marked precise, and add is not.
  296. DxilModule &DM = c.GetDxilModule();
  297. Function *F = DM.GetEntryFunction();
  298. int numChecks = 0;
  299. for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
  300. Instruction *Inst = &*I;
  301. if (DxilInst_Sqrt(Inst)) {
  302. numChecks++;
  303. VERIFY_IS_TRUE(DM.IsPrecise(Inst));
  304. }
  305. else if (LlvmInst_FDiv(Inst)) {
  306. numChecks++;
  307. VERIFY_IS_TRUE(DM.IsPrecise(Inst));
  308. }
  309. else if (LlvmInst_FAdd(Inst)) {
  310. numChecks++;
  311. VERIFY_IS_FALSE(DM.IsPrecise(Inst));
  312. }
  313. }
  314. VERIFY_ARE_EQUAL(numChecks, 3);
  315. }
  316. TEST_F(DxilModuleTest, Precise5) {
  317. Compiler c(m_dllSupport);
  318. c.Compile(
  319. "float C[10];\n"
  320. "float main(float x : X, float y : Y, int i : I) : SV_Target {\n"
  321. " float A[2];\n"
  322. " A[0] = x;\n"
  323. " A[1] = y;\n"
  324. " return A[i] + C[i];\n"
  325. "}\n"
  326. );
  327. // Make sure load and extract value are not reported as precise.
  328. DxilModule &DM = c.GetDxilModule();
  329. Function *F = DM.GetEntryFunction();
  330. int numChecks = 0;
  331. for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
  332. Instruction *Inst = &*I;
  333. if (LlvmInst_ExtractValue(Inst)) {
  334. numChecks++;
  335. VERIFY_IS_FALSE(DM.IsPrecise(Inst));
  336. }
  337. else if (LlvmInst_Load(Inst)) {
  338. numChecks++;
  339. VERIFY_IS_FALSE(DM.IsPrecise(Inst));
  340. }
  341. else if (LlvmInst_FAdd(Inst)) {
  342. numChecks++;
  343. VERIFY_IS_FALSE(DM.IsPrecise(Inst));
  344. }
  345. }
  346. VERIFY_ARE_EQUAL(numChecks, 3);
  347. }
  348. TEST_F(DxilModuleTest, Precise6) {
  349. Compiler c(m_dllSupport);
  350. c.Compile(
  351. "precise float2 main(float2 x : A, float2 y : B) : SV_Target {\n"
  352. " return sqrt(x * y);\n"
  353. "}\n"
  354. );
  355. // Make sure sqrt and mul are marked precise.
  356. DxilModule &DM = c.GetDxilModule();
  357. Function *F = DM.GetEntryFunction();
  358. int numChecks = 0;
  359. for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
  360. Instruction *Inst = &*I;
  361. if (DxilInst_Sqrt(Inst)) {
  362. numChecks++;
  363. VERIFY_IS_TRUE(DM.IsPrecise(Inst));
  364. }
  365. else if (LlvmInst_FMul(Inst)) {
  366. numChecks++;
  367. VERIFY_IS_TRUE(DM.IsPrecise(Inst));
  368. }
  369. }
  370. VERIFY_ARE_EQUAL(numChecks, 4);
  371. }
  372. TEST_F(DxilModuleTest, Precise7) {
  373. Compiler c(m_dllSupport);
  374. c.Compile(
  375. "float2 main(float2 x : A, float2 y : B) : SV_Target {\n"
  376. " return sqrt(x * y);\n"
  377. "}\n"
  378. );
  379. // Make sure sqrt and mul are not marked precise.
  380. DxilModule &DM = c.GetDxilModule();
  381. Function *F = DM.GetEntryFunction();
  382. int numChecks = 0;
  383. for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
  384. Instruction *Inst = &*I;
  385. if (DxilInst_Sqrt(Inst)) {
  386. numChecks++;
  387. VERIFY_IS_FALSE(DM.IsPrecise(Inst));
  388. }
  389. else if (LlvmInst_FMul(Inst)) {
  390. numChecks++;
  391. VERIFY_IS_FALSE(DM.IsPrecise(Inst));
  392. }
  393. }
  394. VERIFY_ARE_EQUAL(numChecks, 4);
  395. }
  396. TEST_F(DxilModuleTest, CSGetNumThreads) {
  397. Compiler c(m_dllSupport);
  398. c.Compile(
  399. "[numthreads(8, 4, 2)]\n"
  400. "void main() {\n"
  401. "}\n"
  402. ,
  403. L"cs_6_0"
  404. );
  405. DxilModule &DM = c.GetDxilModule();
  406. VERIFY_ARE_EQUAL(8u, DM.GetNumThreads(0));
  407. VERIFY_ARE_EQUAL(4u, DM.GetNumThreads(1));
  408. VERIFY_ARE_EQUAL(2u, DM.GetNumThreads(2));
  409. }
  410. TEST_F(DxilModuleTest, MSGetNumThreads) {
  411. Compiler c(m_dllSupport);
  412. if (c.SkipDxil_Test(1,5)) return;
  413. c.Compile(
  414. "struct MeshPerVertex { float4 pos : SV_Position; };\n"
  415. "[numthreads(8, 4, 2)]\n"
  416. "[outputtopology(\"triangle\")]\n"
  417. "void main(\n"
  418. " out indices uint3 primIndices[1]\n"
  419. ") {\n"
  420. " SetMeshOutputCounts(0, 0);\n"
  421. "}\n"
  422. ,
  423. L"ms_6_5"
  424. );
  425. DxilModule &DM = c.GetDxilModule();
  426. VERIFY_ARE_EQUAL(8u, DM.GetNumThreads(0));
  427. VERIFY_ARE_EQUAL(4u, DM.GetNumThreads(1));
  428. VERIFY_ARE_EQUAL(2u, DM.GetNumThreads(2));
  429. }
  430. TEST_F(DxilModuleTest, ASGetNumThreads) {
  431. Compiler c(m_dllSupport);
  432. if (c.SkipDxil_Test(1,5)) return;
  433. c.Compile(
  434. "struct Payload { uint i; };\n"
  435. "[numthreads(8, 4, 2)]\n"
  436. "void main() {\n"
  437. " Payload pld = {0};\n"
  438. " DispatchMesh(1, 1, 1, pld);\n"
  439. "}\n"
  440. ,
  441. L"as_6_5"
  442. );
  443. DxilModule &DM = c.GetDxilModule();
  444. VERIFY_ARE_EQUAL(8u, DM.GetNumThreads(0));
  445. VERIFY_ARE_EQUAL(4u, DM.GetNumThreads(1));
  446. VERIFY_ARE_EQUAL(2u, DM.GetNumThreads(2));
  447. }
  448. void DxilModuleTest::VerifyValidatorVersionFails(
  449. LPCWSTR shaderModel, const std::vector<LPCWSTR> &arguments,
  450. const std::vector<LPCSTR> &expectedErrors) {
  451. LPCSTR shader =
  452. "[shader(\"pixel\")]"
  453. "float4 main() : SV_Target {\n"
  454. " return 0;\n"
  455. "}\n";
  456. Compiler c(m_dllSupport);
  457. c.Compile(shader, shaderModel, arguments, {});
  458. CheckOperationResultMsgs(c.pCompileResult, expectedErrors, false, false);
  459. }
  460. void DxilModuleTest::VerifyValidatorVersionMatches(
  461. LPCWSTR shaderModel, const std::vector<LPCWSTR> &arguments,
  462. unsigned expectedMajor, unsigned expectedMinor) {
  463. LPCSTR shader =
  464. "[shader(\"pixel\")]"
  465. "float4 main() : SV_Target {\n"
  466. " return 0;\n"
  467. "}\n";
  468. Compiler c(m_dllSupport);
  469. c.Compile(shader, shaderModel, arguments, {});
  470. DxilModule &DM = c.GetDxilModule();
  471. unsigned vMajor, vMinor;
  472. DM.GetValidatorVersion(vMajor, vMinor);
  473. if (expectedMajor == UINT_MAX) {
  474. // Expect current version
  475. VERIFY_ARE_EQUAL(vMajor, c.m_ver.m_ValMajor);
  476. VERIFY_ARE_EQUAL(vMinor, c.m_ver.m_ValMinor);
  477. } else {
  478. VERIFY_ARE_EQUAL(vMajor, expectedMajor);
  479. VERIFY_ARE_EQUAL(vMinor, expectedMinor);
  480. }
  481. }
  482. TEST_F(DxilModuleTest, SetValidatorVersion) {
  483. Compiler c(m_dllSupport);
  484. if (c.SkipDxil_Test(1, 4)) return;
  485. // Current version
  486. VerifyValidatorVersionMatches(L"ps_6_2", {});
  487. VerifyValidatorVersionMatches(L"lib_6_3", {});
  488. // Current version, with validation disabled
  489. VerifyValidatorVersionMatches(L"ps_6_2", {L"-Vd"});
  490. VerifyValidatorVersionMatches(L"lib_6_3", {L"-Vd"});
  491. // Override validator version
  492. VerifyValidatorVersionMatches(L"ps_6_2", {L"-validator-version", L"1.2"}, 1,2);
  493. VerifyValidatorVersionMatches(L"lib_6_3", {L"-validator-version", L"1.3"}, 1,3);
  494. // Override validator version, with validation disabled
  495. VerifyValidatorVersionMatches(L"ps_6_2", {L"-Vd", L"-validator-version", L"1.2"}, 1,2);
  496. VerifyValidatorVersionMatches(L"lib_6_3", {L"-Vd", L"-validator-version", L"1.3"}, 1,3);
  497. // Never can validate (version 0,0):
  498. VerifyValidatorVersionMatches(L"lib_6_1", {L"-Vd"}, 0, 0);
  499. VerifyValidatorVersionMatches(L"lib_6_2", {L"-Vd"}, 0, 0);
  500. VerifyValidatorVersionMatches(L"lib_6_2", {L"-Vd", L"-validator-version", L"0.0"}, 0, 0);
  501. VerifyValidatorVersionMatches(L"lib_6_x", {}, 0, 0);
  502. VerifyValidatorVersionMatches(L"lib_6_x", {L"-validator-version", L"0.0"}, 0, 0);
  503. // Failure cases:
  504. VerifyValidatorVersionFails(L"ps_6_2", {L"-validator-version", L"1.1"}, {
  505. "validator version 1,1 does not support target profile."});
  506. VerifyValidatorVersionFails(L"lib_6_2", {L"-Tlib_6_2"}, {
  507. "Must disable validation for unsupported lib_6_1 or lib_6_2 targets"});
  508. VerifyValidatorVersionFails(L"lib_6_2", {L"-Vd", L"-validator-version", L"1.2"}, {
  509. "-validator-version cannot be used with library profiles lib_6_1 or lib_6_2."});
  510. VerifyValidatorVersionFails(L"lib_6_x", {L"-validator-version", L"1.3"}, {
  511. "Offline library profile cannot be used with non-zero -validator-version."});
  512. }
  513. TEST_F(DxilModuleTest, PayloadQualifier) {
  514. if (m_ver.SkipDxilVersion(1, 6)) return;
  515. std::vector<LPCWSTR> arguments = { L"-enable-payload-qualifiers" };
  516. Compiler c(m_dllSupport);
  517. LPCSTR shader = "struct [raypayload] Payload\n"
  518. "{\n"
  519. " double a : read(caller, closesthit, anyhit) : write(caller, miss, closesthit);\n"
  520. "};\n\n"
  521. "[shader(\"miss\")]\n"
  522. "void Miss( inout Payload payload ) { payload.a = 4.2; }\n";
  523. c.Compile(shader, L"lib_6_6", arguments, {});
  524. DxilModule &DM = c.GetDxilModule();
  525. const DxilTypeSystem &DTS = DM.GetTypeSystem();
  526. for (auto &p : DTS.GetPayloadAnnotationMap()) {
  527. const DxilPayloadAnnotation &plAnnotation = *p.second;
  528. for (unsigned i = 0; i < plAnnotation.GetNumFields(); ++i) {
  529. const DxilPayloadFieldAnnotation &fieldAnnotation =
  530. plAnnotation.GetFieldAnnotation(i);
  531. VERIFY_IS_TRUE(fieldAnnotation.HasAnnotations());
  532. VERIFY_ARE_EQUAL(DXIL::PayloadAccessQualifier::ReadWrite,
  533. fieldAnnotation.GetPayloadFieldQualifier(
  534. DXIL::PayloadAccessShaderStage::Caller));
  535. VERIFY_ARE_EQUAL(DXIL::PayloadAccessQualifier::ReadWrite,
  536. fieldAnnotation.GetPayloadFieldQualifier(
  537. DXIL::PayloadAccessShaderStage::Closesthit));
  538. VERIFY_ARE_EQUAL(DXIL::PayloadAccessQualifier::Write,
  539. fieldAnnotation.GetPayloadFieldQualifier(
  540. DXIL::PayloadAccessShaderStage::Miss));
  541. VERIFY_ARE_EQUAL(DXIL::PayloadAccessQualifier::Read,
  542. fieldAnnotation.GetPayloadFieldQualifier(
  543. DXIL::PayloadAccessShaderStage::Anyhit));
  544. }
  545. }
  546. }