SystemValueTest.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // SystemValueTest.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. // Test system values at various signature points //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #include <memory>
  12. #include <vector>
  13. #include <string>
  14. #include <cassert>
  15. #include <sstream>
  16. #include <algorithm>
  17. #include "dxc/Support/WinIncludes.h"
  18. #include "dxc/dxcapi.h"
  19. #include "dxc/Test/HlslTestUtils.h"
  20. #include "dxc/Test/DxcTestUtils.h"
  21. #include "llvm/Support/raw_os_ostream.h"
  22. #include "dxc/Support/Global.h"
  23. #include "dxc/Support/dxcapi.use.h"
  24. #include "dxc/Support/HLSLOptions.h"
  25. #include "dxc/Support/Unicode.h"
  26. #include "dxc/DXIL/DxilConstants.h"
  27. #include "dxc/DXIL/DxilSemantic.h"
  28. #include "dxc/DXIL/DxilSigPoint.h"
  29. #include "dxc/DXIL/DxilShaderModel.h"
  30. #include <fstream>
  31. using namespace std;
  32. using namespace hlsl_test;
  33. using namespace hlsl;
  34. #ifdef _WIN32
  35. class SystemValueTest {
  36. #else
  37. class SystemValueTest : public ::testing::Test {
  38. #endif
  39. public:
  40. BEGIN_TEST_CLASS(SystemValueTest)
  41. TEST_CLASS_PROPERTY(L"Parallel", L"true")
  42. TEST_METHOD_PROPERTY(L"Priority", L"0")
  43. END_TEST_CLASS()
  44. TEST_CLASS_SETUP(InitSupport);
  45. TEST_METHOD(VerifyArbitrarySupport)
  46. TEST_METHOD(VerifyNotAvailableFail)
  47. TEST_METHOD(VerifySVAsArbitrary)
  48. TEST_METHOD(VerifySVAsSV)
  49. TEST_METHOD(VerifySGV)
  50. TEST_METHOD(VerifySVNotPacked)
  51. TEST_METHOD(VerifySVNotInSig)
  52. TEST_METHOD(VerifyVertexPacking)
  53. TEST_METHOD(VerifyPatchConstantPacking)
  54. TEST_METHOD(VerifyTargetPacking)
  55. TEST_METHOD(VerifyTessFactors)
  56. TEST_METHOD(VerifyShadowEntries)
  57. TEST_METHOD(VerifyVersionedSemantics)
  58. TEST_METHOD(VerifyMissingSemanticFailure)
  59. void CompileHLSLTemplate(CComPtr<IDxcOperationResult> &pResult, DXIL::SigPointKind sigPointKind, DXIL::SemanticKind semKind, bool addArb, unsigned Major = 0, unsigned Minor = 0) {
  60. const Semantic *sem = Semantic::Get(semKind);
  61. const char* pSemName = sem->GetName();
  62. std::wstring sigDefValue(L"");
  63. if(semKind < DXIL::SemanticKind::Invalid && pSemName) {
  64. if(Semantic::HasSVPrefix(pSemName))
  65. pSemName += 3;
  66. CA2W semNameW(pSemName, CP_UTF8);
  67. sigDefValue = L"Def_";
  68. sigDefValue += semNameW;
  69. }
  70. if (addArb) {
  71. if (!sigDefValue.empty())
  72. sigDefValue += L" ";
  73. sigDefValue += L"Def_Arb(uint, arb0, ARB0)";
  74. }
  75. return CompileHLSLTemplate(pResult, sigPointKind, sigDefValue, Major, Minor);
  76. }
  77. void CompileHLSLTemplate(CComPtr<IDxcOperationResult> &pResult, DXIL::SigPointKind sigPointKind, const std::wstring &sigDefValue, unsigned Major = 0, unsigned Minor = 0) {
  78. const SigPoint * sigPoint = SigPoint::GetSigPoint(sigPointKind);
  79. DXIL::ShaderKind shaderKind = sigPoint->GetShaderKind();
  80. std::wstring path = hlsl_test::GetPathToHlslDataFile(L"system-values.hlsl");
  81. CComPtr<IDxcCompiler> pCompiler;
  82. VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcCompiler, &pCompiler));
  83. if (!m_pSource) {
  84. CComPtr<IDxcLibrary> library;
  85. IFT(m_dllSupport.CreateInstance(CLSID_DxcLibrary, &library));
  86. IFT(library->CreateBlobFromFile(path.c_str(), nullptr, &m_pSource));
  87. }
  88. LPCWSTR entry, profile;
  89. wchar_t profile_buf[] = L"vs_6_1";
  90. switch(shaderKind) {
  91. case DXIL::ShaderKind::Vertex: entry = L"VSMain"; profile = L"vs_6_1"; break;
  92. case DXIL::ShaderKind::Pixel: entry = L"PSMain"; profile = L"ps_6_1"; break;
  93. case DXIL::ShaderKind::Geometry: entry = L"GSMain"; profile = L"gs_6_1"; break;
  94. case DXIL::ShaderKind::Hull: entry = L"HSMain"; profile = L"hs_6_1"; break;
  95. case DXIL::ShaderKind::Domain: entry = L"DSMain"; profile = L"ds_6_1"; break;
  96. case DXIL::ShaderKind::Compute: entry = L"CSMain"; profile = L"cs_6_1"; break;
  97. case DXIL::ShaderKind::Mesh: entry = L"MSMain"; profile = L"ms_6_5"; break;
  98. case DXIL::ShaderKind::Amplification: entry = L"ASMain"; profile = L"as_6_5"; break;
  99. case DXIL::ShaderKind::Library:
  100. case DXIL::ShaderKind::Invalid:
  101. assert(!"invalid shaderKind");
  102. break;
  103. }
  104. if (Major == 0) {
  105. Major = m_HighestMajor;
  106. Minor = m_HighestMinor;
  107. }
  108. if (Major != 6 || Minor != 1) {
  109. profile_buf[0] = profile[0];
  110. profile_buf[3] = L'0' + (wchar_t)Major;
  111. profile_buf[5] = L'0' + (wchar_t)Minor;
  112. profile = profile_buf;
  113. }
  114. CA2W sigPointNameW(sigPoint->GetName(), CP_UTF8);
  115. // Strip SV_ from semantic name
  116. std::wstring sigDefName(sigPointNameW);
  117. sigDefName += L"_Defs";
  118. DxcDefine define;
  119. define.Name = sigDefName.c_str();
  120. define.Value = sigDefValue.c_str();
  121. VERIFY_SUCCEEDED(pCompiler->Compile(m_pSource, path.c_str(), entry,
  122. profile, nullptr, 0, &define, 1,
  123. nullptr, &pResult));
  124. }
  125. void CheckAnyOperationResultMsg(IDxcOperationResult *pResult,
  126. const char **pErrorMsgArray = nullptr,
  127. unsigned ErrorMsgCount = 0) {
  128. HRESULT status;
  129. VERIFY_SUCCEEDED(pResult->GetStatus(&status));
  130. if (pErrorMsgArray == nullptr || ErrorMsgCount == 0) {
  131. VERIFY_SUCCEEDED(status);
  132. return;
  133. }
  134. VERIFY_FAILED(status);
  135. CComPtr<IDxcBlobEncoding> text;
  136. VERIFY_SUCCEEDED(pResult->GetErrorBuffer(&text));
  137. const char *pStart = (const char *)text->GetBufferPointer();
  138. const char *pEnd = pStart + text->GetBufferSize();
  139. bool bMessageFound = false;
  140. for (unsigned i = 0; i < ErrorMsgCount; i++) {
  141. const char *pErrorMsg = pErrorMsgArray[i];
  142. const char *pMatch = std::search(pStart, pEnd, pErrorMsg, pErrorMsg + strlen(pErrorMsg));
  143. if (pEnd != pMatch)
  144. bMessageFound = true;
  145. }
  146. VERIFY_IS_TRUE(bMessageFound);
  147. }
  148. dxc::DxcDllSupport m_dllSupport;
  149. VersionSupportInfo m_ver;
  150. unsigned m_HighestMajor, m_HighestMinor; // Shader Model Supported
  151. CComPtr<IDxcBlobEncoding> m_pSource;
  152. };
  153. bool SystemValueTest::InitSupport() {
  154. if (!m_dllSupport.IsEnabled()) {
  155. VERIFY_SUCCEEDED(m_dllSupport.Initialize());
  156. m_ver.Initialize(m_dllSupport);
  157. m_HighestMajor = 6;
  158. m_HighestMinor = 0;
  159. if ((m_ver.m_DxilMajor > 1 || (m_ver.m_DxilMajor == 1 && m_ver.m_DxilMinor > 1)) &&
  160. (m_ver.m_ValMajor > 1 || (m_ver.m_ValMajor == 1 && m_ver.m_ValMinor > 1))) {
  161. m_HighestMinor = 1;
  162. }
  163. }
  164. return true;
  165. }
  166. static bool ArbAllowed(DXIL::SigPointKind sp) {
  167. switch (sp) {
  168. case DXIL::SigPointKind::VSIn:
  169. case DXIL::SigPointKind::VSOut:
  170. case DXIL::SigPointKind::GSVIn:
  171. case DXIL::SigPointKind::GSOut:
  172. case DXIL::SigPointKind::HSCPIn:
  173. case DXIL::SigPointKind::HSCPOut:
  174. case DXIL::SigPointKind::PCOut:
  175. case DXIL::SigPointKind::DSCPIn:
  176. case DXIL::SigPointKind::DSIn:
  177. case DXIL::SigPointKind::DSOut:
  178. case DXIL::SigPointKind::PSIn:
  179. case DXIL::SigPointKind::MSOut:
  180. case DXIL::SigPointKind::MSPOut:
  181. return true;
  182. default:
  183. return false;
  184. }
  185. return false;
  186. }
  187. TEST_F(SystemValueTest, VerifyArbitrarySupport) {
  188. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  189. for (DXIL::SigPointKind sp = (DXIL::SigPointKind)0; sp < DXIL::SigPointKind::Invalid; sp = (DXIL::SigPointKind)((unsigned)sp + 1)) {
  190. if (sp >= DXIL::SigPointKind::MSIn && sp <= DXIL::SigPointKind::ASIn) {
  191. // TODO: add tests for mesh/amplification shaders to system-values.hlsl
  192. continue;
  193. }
  194. CComPtr<IDxcOperationResult> pResult;
  195. CompileHLSLTemplate(pResult, sp, DXIL::SemanticKind::Invalid, true);
  196. HRESULT result;
  197. VERIFY_SUCCEEDED(pResult->GetStatus(&result));
  198. if (ArbAllowed(sp)) {
  199. CheckAnyOperationResultMsg(pResult);
  200. } else {
  201. // TODO: We should probably improve this error message since it pertains to a parameter
  202. // at a particular signature point, not necessarily the whole shader model.
  203. // These are a couple of possible errors:
  204. // error: invalid semantic 'ARB' for <sm>
  205. // error: Semantic ARB is invalid for shader model <sm>
  206. // error: invalid semantic found in <sm>
  207. const char *Errors[] = {
  208. "error: Semantic ARB is invalid for shader model",
  209. "error: invalid semantic 'ARB' for",
  210. "error: invalid semantic found in CS",
  211. };
  212. CheckAnyOperationResultMsg(pResult, Errors, _countof(Errors));
  213. }
  214. }
  215. }
  216. TEST_F(SystemValueTest, VerifyNotAvailableFail) {
  217. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  218. for (DXIL::SigPointKind sp = (DXIL::SigPointKind)0; sp < DXIL::SigPointKind::Invalid; sp = (DXIL::SigPointKind)((unsigned)sp + 1)) {
  219. if (sp >= DXIL::SigPointKind::MSIn && sp <= DXIL::SigPointKind::ASIn) {
  220. // TODO: add tests for mesh/amplification shaders to system-values.hlsl
  221. continue;
  222. }
  223. for (DXIL::SemanticKind sv = (DXIL::SemanticKind)((unsigned)DXIL::SemanticKind::Arbitrary + 1); sv < DXIL::SemanticKind::Invalid; sv = (DXIL::SemanticKind)((unsigned)sv + 1)) {
  224. if (sv == DXIL::SemanticKind::CullPrimitive) {
  225. // TODO: add tests for CullPrimitive
  226. continue;
  227. }
  228. DXIL::SemanticInterpretationKind interpretation = hlsl::SigPoint::GetInterpretation(sv, sp, m_HighestMajor, m_HighestMinor);
  229. if (interpretation == DXIL::SemanticInterpretationKind::NA) {
  230. CComPtr<IDxcOperationResult> pResult;
  231. CompileHLSLTemplate(pResult, sp, sv, false);
  232. // error: Semantic SV_SampleIndex is invalid for shader model: vs
  233. // error: invalid semantic 'SV_VertexID' for gs
  234. // error: invalid semantic found in CS
  235. const Semantic *pSemantic = Semantic::Get(sv);
  236. const char *SemName = pSemantic->GetName();
  237. std::string ErrorStrs[] = {
  238. std::string("error: Semantic ") + SemName + " is invalid for shader model:",
  239. std::string("error: invalid semantic '") + SemName + "' for",
  240. "error: invalid semantic found in CS",
  241. };
  242. const char *Errors[_countof(ErrorStrs)];
  243. for (unsigned i = 0; i < _countof(ErrorStrs); i++)
  244. Errors[i] = ErrorStrs[i].c_str();
  245. CheckAnyOperationResultMsg(pResult, Errors, _countof(Errors));
  246. }
  247. }
  248. }
  249. }
  250. TEST_F(SystemValueTest, VerifySVAsArbitrary) {
  251. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  252. for (DXIL::SigPointKind sp = (DXIL::SigPointKind)0; sp < DXIL::SigPointKind::Invalid; sp = (DXIL::SigPointKind)((unsigned)sp + 1)) {
  253. if (sp >= DXIL::SigPointKind::MSIn && sp <= DXIL::SigPointKind::ASIn) {
  254. // TODO: add tests for mesh/amplification shaders to system-values.hlsl
  255. continue;
  256. }
  257. for (DXIL::SemanticKind sv = (DXIL::SemanticKind)((unsigned)DXIL::SemanticKind::Arbitrary + 1); sv < DXIL::SemanticKind::Invalid; sv = (DXIL::SemanticKind)((unsigned)sv + 1)) {
  258. DXIL::SemanticInterpretationKind interpretation = hlsl::SigPoint::GetInterpretation(sv, sp, m_HighestMajor, m_HighestMinor);
  259. if (interpretation == DXIL::SemanticInterpretationKind::Arb) {
  260. CComPtr<IDxcOperationResult> pResult;
  261. CompileHLSLTemplate(pResult, sp, sv, false);
  262. HRESULT result;
  263. VERIFY_SUCCEEDED(pResult->GetStatus(&result));
  264. VERIFY_SUCCEEDED(result);
  265. // TODO: Verify system value item is included in signature, treated as arbitrary,
  266. // and that the element id is used in load input instruction.
  267. }
  268. }
  269. }
  270. }
  271. TEST_F(SystemValueTest, VerifySVAsSV) {
  272. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  273. for (DXIL::SigPointKind sp = (DXIL::SigPointKind)0; sp < DXIL::SigPointKind::Invalid; sp = (DXIL::SigPointKind)((unsigned)sp + 1)) {
  274. if (sp >= DXIL::SigPointKind::MSIn && sp <= DXIL::SigPointKind::ASIn) {
  275. // TODO: add tests for mesh/amplification shaders to system-values.hlsl
  276. continue;
  277. }
  278. for (DXIL::SemanticKind sv = (DXIL::SemanticKind)((unsigned)DXIL::SemanticKind::Arbitrary + 1); sv < DXIL::SemanticKind::Invalid; sv = (DXIL::SemanticKind)((unsigned)sv + 1)) {
  279. DXIL::SemanticInterpretationKind interpretation = hlsl::SigPoint::GetInterpretation(sv, sp, m_HighestMajor, m_HighestMinor);
  280. if (interpretation == DXIL::SemanticInterpretationKind::SV || interpretation == DXIL::SemanticInterpretationKind::SGV) {
  281. CComPtr<IDxcOperationResult> pResult;
  282. CompileHLSLTemplate(pResult, sp, sv, false);
  283. HRESULT result;
  284. VERIFY_SUCCEEDED(pResult->GetStatus(&result));
  285. VERIFY_SUCCEEDED(result);
  286. // TODO: Verify system value is included in signature, system value enum is appropriately set,
  287. // and that the element id is used in load input instruction.
  288. }
  289. }
  290. }
  291. }
  292. TEST_F(SystemValueTest, VerifySGV) {
  293. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  294. for (DXIL::SigPointKind sp = (DXIL::SigPointKind)0; sp < DXIL::SigPointKind::Invalid; sp = (DXIL::SigPointKind)((unsigned)sp + 1)) {
  295. if (sp >= DXIL::SigPointKind::MSIn && sp <= DXIL::SigPointKind::ASIn) {
  296. // TODO: add tests for mesh/amplification shaders to system-values.hlsl
  297. continue;
  298. }
  299. for (DXIL::SemanticKind sv = (DXIL::SemanticKind)((unsigned)DXIL::SemanticKind::Arbitrary + 1); sv < DXIL::SemanticKind::Invalid; sv = (DXIL::SemanticKind)((unsigned)sv + 1)) {
  300. DXIL::SemanticInterpretationKind interpretation = hlsl::SigPoint::GetInterpretation(sv, sp, m_HighestMajor, m_HighestMinor);
  301. if (interpretation == DXIL::SemanticInterpretationKind::SGV) {
  302. CComPtr<IDxcOperationResult> pResult;
  303. CompileHLSLTemplate(pResult, sp, sv, true);
  304. HRESULT result;
  305. VERIFY_SUCCEEDED(pResult->GetStatus(&result));
  306. VERIFY_SUCCEEDED(result);
  307. // TODO: Verify system value is included in signature and arbitrary is packed before system value
  308. // Or: verify failed when using greedy signature packing
  309. // TODO: Verify warning about declaring the system value last for fxc HLSL compatibility.
  310. }
  311. }
  312. }
  313. }
  314. TEST_F(SystemValueTest, VerifySVNotPacked) {
  315. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  316. for (DXIL::SigPointKind sp = (DXIL::SigPointKind)0; sp < DXIL::SigPointKind::Invalid; sp = (DXIL::SigPointKind)((unsigned)sp + 1)) {
  317. if (sp >= DXIL::SigPointKind::MSIn && sp <= DXIL::SigPointKind::ASIn) {
  318. // TODO: add tests for mesh/amplification shaders to system-values.hlsl
  319. continue;
  320. }
  321. for (DXIL::SemanticKind sv = (DXIL::SemanticKind)((unsigned)DXIL::SemanticKind::Arbitrary + 1); sv < DXIL::SemanticKind::Invalid; sv = (DXIL::SemanticKind)((unsigned)sv + 1)) {
  322. DXIL::SemanticInterpretationKind interpretation = hlsl::SigPoint::GetInterpretation(sv, sp, m_HighestMajor, m_HighestMinor);
  323. if (interpretation == DXIL::SemanticInterpretationKind::NotPacked) {
  324. CComPtr<IDxcOperationResult> pResult;
  325. CompileHLSLTemplate(pResult, sp, sv, false);
  326. HRESULT result;
  327. VERIFY_SUCCEEDED(pResult->GetStatus(&result));
  328. VERIFY_SUCCEEDED(result);
  329. // TODO: Verify system value is included in signature and has packing location (-1, -1),
  330. // and that the element id is used in load input instruction.
  331. }
  332. }
  333. }
  334. }
  335. TEST_F(SystemValueTest, VerifySVNotInSig) {
  336. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  337. for (DXIL::SigPointKind sp = (DXIL::SigPointKind)0; sp < DXIL::SigPointKind::Invalid; sp = (DXIL::SigPointKind)((unsigned)sp + 1)) {
  338. if (sp >= DXIL::SigPointKind::MSIn && sp <= DXIL::SigPointKind::ASIn) {
  339. // TODO: add tests for mesh/amplification shaders to system-values.hlsl
  340. continue;
  341. }
  342. for (DXIL::SemanticKind sv = (DXIL::SemanticKind)((unsigned)DXIL::SemanticKind::Arbitrary + 1); sv < DXIL::SemanticKind::Invalid; sv = (DXIL::SemanticKind)((unsigned)sv + 1)) {
  343. DXIL::SemanticInterpretationKind interpretation = hlsl::SigPoint::GetInterpretation(sv, sp, m_HighestMajor, m_HighestMinor);
  344. if (interpretation == DXIL::SemanticInterpretationKind::NotInSig) {
  345. CComPtr<IDxcOperationResult> pResult;
  346. CompileHLSLTemplate(pResult, sp, sv, false);
  347. HRESULT result;
  348. VERIFY_SUCCEEDED(pResult->GetStatus(&result));
  349. VERIFY_SUCCEEDED(result);
  350. // TODO: Verify system value is not included in signature,
  351. // that intrinsic function is used, and that the element id is not used in load input instruction.
  352. }
  353. }
  354. }
  355. }
  356. TEST_F(SystemValueTest, VerifyVertexPacking) {
  357. // TODO: Implement
  358. VERIFY_IS_TRUE("Not Implemented");
  359. for (DXIL::SigPointKind sp = (DXIL::SigPointKind)0; sp < DXIL::SigPointKind::Invalid; sp = (DXIL::SigPointKind)((unsigned)sp + 1)) {
  360. if (sp >= DXIL::SigPointKind::MSIn && sp <= DXIL::SigPointKind::ASIn) {
  361. // TODO: add tests for mesh/amplification shaders to system-values.hlsl
  362. continue;
  363. }
  364. DXIL::PackingKind pk = SigPoint::GetSigPoint(sp)->GetPackingKind();
  365. if (pk == DXIL::PackingKind::Vertex) {
  366. // TBD: Test constraints here, or add constraints to validator and just generate cases to pack here, expecting success?
  367. }
  368. }
  369. }
  370. TEST_F(SystemValueTest, VerifyPatchConstantPacking) {
  371. // TODO: Implement
  372. VERIFY_IS_TRUE("Not Implemented");
  373. for (DXIL::SigPointKind sp = (DXIL::SigPointKind)0; sp < DXIL::SigPointKind::Invalid; sp = (DXIL::SigPointKind)((unsigned)sp + 1)) {
  374. if (sp >= DXIL::SigPointKind::MSIn && sp <= DXIL::SigPointKind::ASIn) {
  375. // TODO: add tests for mesh/amplification shaders to system-values.hlsl
  376. continue;
  377. }
  378. DXIL::PackingKind pk = SigPoint::GetSigPoint(sp)->GetPackingKind();
  379. if (pk == DXIL::PackingKind::PatchConstant) {
  380. // TBD: Test constraints here, or add constraints to validator and just generate cases to pack here, expecting success?
  381. }
  382. }
  383. }
  384. TEST_F(SystemValueTest, VerifyTargetPacking) {
  385. // TODO: Implement
  386. VERIFY_IS_TRUE("Not Implemented");
  387. for (DXIL::SigPointKind sp = (DXIL::SigPointKind)0; sp < DXIL::SigPointKind::Invalid; sp = (DXIL::SigPointKind)((unsigned)sp + 1)) {
  388. if (sp >= DXIL::SigPointKind::MSIn && sp <= DXIL::SigPointKind::ASIn) {
  389. // TODO: add tests for mesh/amplification shaders to system-values.hlsl
  390. continue;
  391. }
  392. DXIL::PackingKind pk = SigPoint::GetSigPoint(sp)->GetPackingKind();
  393. if (pk == DXIL::PackingKind::Target) {
  394. // TBD: Test constraints here, or add constraints to validator and just generate cases to pack here, expecting success?
  395. }
  396. }
  397. }
  398. TEST_F(SystemValueTest, VerifyTessFactors) {
  399. // TODO: Implement
  400. VERIFY_IS_TRUE("Not Implemented");
  401. // TBD: Split between return and out params?
  402. }
  403. TEST_F(SystemValueTest, VerifyShadowEntries) {
  404. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  405. for (DXIL::SigPointKind sp = (DXIL::SigPointKind)0; sp < DXIL::SigPointKind::Invalid; sp = (DXIL::SigPointKind)((unsigned)sp + 1)) {
  406. if (sp >= DXIL::SigPointKind::MSIn && sp <= DXIL::SigPointKind::ASIn) {
  407. // TODO: add tests for mesh/amplification shaders to system-values.hlsl
  408. continue;
  409. }
  410. for (DXIL::SemanticKind sv = (DXIL::SemanticKind)((unsigned)DXIL::SemanticKind::Arbitrary + 1); sv < DXIL::SemanticKind::Invalid; sv = (DXIL::SemanticKind)((unsigned)sv + 1)) {
  411. DXIL::SemanticInterpretationKind interpretation = hlsl::SigPoint::GetInterpretation(sv, sp, m_HighestMajor, m_HighestMinor);
  412. if (interpretation == DXIL::SemanticInterpretationKind::Shadow) {
  413. CComPtr<IDxcOperationResult> pResult;
  414. CompileHLSLTemplate(pResult, sp, sv, false);
  415. HRESULT result;
  416. VERIFY_SUCCEEDED(pResult->GetStatus(&result));
  417. VERIFY_SUCCEEDED(result);
  418. // TODO: Verify system value is included in corresponding signature (with fallback),
  419. // that intrinsic function is used, and that the element id is not used in load input instruction.
  420. }
  421. }
  422. }
  423. }
  424. TEST_F(SystemValueTest, VerifyVersionedSemantics) {
  425. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  426. struct TestInfo {
  427. DXIL::SigPointKind sp;
  428. DXIL::SemanticKind sv;
  429. unsigned Major, Minor;
  430. };
  431. const unsigned kNumTests = 13;
  432. TestInfo info[kNumTests] = {
  433. {DXIL::SigPointKind::PSIn, DXIL::SemanticKind::SampleIndex, 4, 1 },
  434. {DXIL::SigPointKind::PSIn, DXIL::SemanticKind::Coverage, 5, 0 },
  435. {DXIL::SigPointKind::PSOut, DXIL::SemanticKind::Coverage, 4, 1 },
  436. {DXIL::SigPointKind::PSIn, DXIL::SemanticKind::InnerCoverage, 5, 0 },
  437. {DXIL::SigPointKind::PSOut, DXIL::SemanticKind::DepthLessEqual, 5, 0 },
  438. {DXIL::SigPointKind::PSOut, DXIL::SemanticKind::DepthGreaterEqual, 5, 0 },
  439. {DXIL::SigPointKind::PSOut, DXIL::SemanticKind::StencilRef, 5, 0 },
  440. {DXIL::SigPointKind::VSIn, DXIL::SemanticKind::ViewID, 6, 1 },
  441. {DXIL::SigPointKind::HSIn, DXIL::SemanticKind::ViewID, 6, 1 },
  442. {DXIL::SigPointKind::PCIn, DXIL::SemanticKind::ViewID, 6, 1 },
  443. {DXIL::SigPointKind::DSIn, DXIL::SemanticKind::ViewID, 6, 1 },
  444. {DXIL::SigPointKind::GSIn, DXIL::SemanticKind::ViewID, 6, 1 },
  445. {DXIL::SigPointKind::PSIn, DXIL::SemanticKind::ViewID, 6, 1 },
  446. };
  447. for (unsigned i = 0; i < kNumTests; i++) {
  448. TestInfo &test = info[i];
  449. unsigned MajorLower = test.Major, MinorLower = test.Minor;
  450. if (MinorLower > 0)
  451. MinorLower--;
  452. else {
  453. MajorLower--;
  454. MinorLower = 1;
  455. }
  456. DXIL::SemanticInterpretationKind SI = hlsl::SigPoint::GetInterpretation(test.sv, test.sp, test.Major, test.Minor);
  457. VERIFY_IS_TRUE(SI != DXIL::SemanticInterpretationKind::NA);
  458. DXIL::SemanticInterpretationKind SILower = hlsl::SigPoint::GetInterpretation(test.sv, test.sp, MajorLower, MinorLower);
  459. VERIFY_IS_TRUE(SILower == DXIL::SemanticInterpretationKind::NA);
  460. // Don't try compiling to pre-dxil targets:
  461. if (MajorLower < 6)
  462. continue;
  463. // Don't try targets our compiler/validator combination do not support.
  464. if (test.Major > m_HighestMajor || test.Minor > m_HighestMinor)
  465. continue;
  466. {
  467. CComPtr<IDxcOperationResult> pResult;
  468. CompileHLSLTemplate(pResult, test.sp, test.sv, false, test.Major, test.Minor);
  469. HRESULT result;
  470. VERIFY_SUCCEEDED(pResult->GetStatus(&result));
  471. VERIFY_SUCCEEDED(result);
  472. }
  473. {
  474. CComPtr<IDxcOperationResult> pResult;
  475. CompileHLSLTemplate(pResult, test.sp, test.sv, false, MajorLower, MinorLower);
  476. HRESULT result;
  477. VERIFY_SUCCEEDED(pResult->GetStatus(&result));
  478. VERIFY_FAILED(result);
  479. const char *Errors[] = {
  480. "is invalid for shader model",
  481. "error: invalid semantic"
  482. };
  483. CheckAnyOperationResultMsg(pResult, Errors, _countof(Errors));
  484. }
  485. }
  486. }
  487. TEST_F(SystemValueTest, VerifyMissingSemanticFailure) {
  488. WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
  489. for (DXIL::SigPointKind sp = (DXIL::SigPointKind)0; sp < DXIL::SigPointKind::Invalid; sp = (DXIL::SigPointKind)((unsigned)sp + 1)) {
  490. if (sp >= DXIL::SigPointKind::MSIn && sp <= DXIL::SigPointKind::ASIn) {
  491. // TODO: add tests for mesh/amplification shaders to system-values.hlsl
  492. continue;
  493. }
  494. std::wstring sigDefValue(L"Def_Arb_NoSem(uint, arb0)");
  495. CComPtr<IDxcOperationResult> pResult;
  496. CompileHLSLTemplate(pResult, sp, sigDefValue);
  497. const char *Errors[] = {
  498. "error: Semantic must be defined for all parameters of an entry function or patch constant function",
  499. };
  500. CheckAnyOperationResultMsg(pResult, Errors, _countof(Errors));
  501. }
  502. }