ValidationTest.cpp 103 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // ValidationTest.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. // //
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #include <memory>
  11. #include <vector>
  12. #include <string>
  13. #include <algorithm>
  14. #include "llvm/ADT/StringRef.h"
  15. #include "llvm/Support/Regex.h"
  16. #include "llvm/ADT/ArrayRef.h"
  17. #include "dxc/HLSL/DxilContainer.h"
  18. #include <atlbase.h>
  19. #include "dxc/Support/FileIOHelper.h"
  20. #include "WexTestClass.h"
  21. #include "DxcTestUtils.h"
  22. #include "HlslTestUtils.h"
  23. using namespace std;
  24. using namespace hlsl;
  25. void CheckOperationSucceeded(IDxcOperationResult *pResult, IDxcBlob **ppBlob) {
  26. HRESULT status;
  27. VERIFY_SUCCEEDED(pResult->GetStatus(&status));
  28. VERIFY_SUCCEEDED(status);
  29. VERIFY_SUCCEEDED(pResult->GetResult(ppBlob));
  30. }
  31. static
  32. bool CheckOperationResultMsgs(IDxcOperationResult *pResult,
  33. llvm::ArrayRef<LPCSTR> pErrorMsgs,
  34. bool maySucceedAnyway, bool bRegex) {
  35. HRESULT status;
  36. CComPtr<IDxcBlobEncoding> text;
  37. VERIFY_SUCCEEDED(pResult->GetStatus(&status));
  38. VERIFY_SUCCEEDED(pResult->GetErrorBuffer(&text));
  39. const char *pStart = text ? (const char *)text->GetBufferPointer() : nullptr;
  40. const char *pEnd = text ? pStart + text->GetBufferSize() : nullptr;
  41. if (pErrorMsgs.empty() || (pErrorMsgs.size() == 1 && !pErrorMsgs[0])) {
  42. if (FAILED(status) && pStart) {
  43. WEX::Logging::Log::Comment(WEX::Common::String().Format(
  44. L"Expected success but found errors\r\n%.*S", (pEnd - pStart),
  45. pStart));
  46. }
  47. VERIFY_SUCCEEDED(status);
  48. }
  49. else {
  50. if (SUCCEEDED(status) && maySucceedAnyway) {
  51. return false;
  52. }
  53. for (auto pErrorMsg : pErrorMsgs) {
  54. if (bRegex) {
  55. llvm::Regex RE(pErrorMsg);
  56. std::string reErrors;
  57. VERIFY_IS_TRUE(RE.isValid(reErrors));
  58. VERIFY_IS_TRUE(RE.match(llvm::StringRef((const char *)text->GetBufferPointer(), text->GetBufferSize())));
  59. }
  60. else {
  61. const char *pMatch = std::search(pStart, pEnd, pErrorMsg, pErrorMsg + strlen(pErrorMsg));
  62. if (pEnd == pMatch) {
  63. WEX::Logging::Log::Comment(WEX::Common::String().Format(
  64. L"Unable to find '%S' in text:\r\n%.*S", pErrorMsg, (pEnd - pStart),
  65. pStart));
  66. }
  67. VERIFY_ARE_NOT_EQUAL(pEnd, pMatch);
  68. }
  69. }
  70. }
  71. return true;
  72. }
  73. bool CheckOperationResultMsgs(IDxcOperationResult *pResult, LPCSTR *pErrorMsgs,
  74. size_t errorMsgCount, bool maySucceedAnyway,
  75. bool bRegex) {
  76. return CheckOperationResultMsgs(
  77. pResult, llvm::ArrayRef<LPCSTR>(pErrorMsgs, errorMsgCount),
  78. maySucceedAnyway, bRegex);
  79. }
  80. std::string DisassembleProgram(dxc::DxcDllSupport &dllSupport,
  81. IDxcBlob *pProgram) {
  82. CComPtr<IDxcCompiler> pCompiler;
  83. CComPtr<IDxcBlobEncoding> pDisassembly;
  84. if (!dllSupport.IsEnabled()) {
  85. VERIFY_SUCCEEDED(dllSupport.Initialize());
  86. }
  87. VERIFY_SUCCEEDED(dllSupport.CreateInstance(CLSID_DxcCompiler, &pCompiler));
  88. VERIFY_SUCCEEDED(pCompiler->Disassemble(pProgram, &pDisassembly));
  89. return BlobToUtf8(pDisassembly);
  90. }
  91. class ValidationTest
  92. {
  93. public:
  94. BEGIN_TEST_CLASS(ValidationTest)
  95. TEST_CLASS_PROPERTY(L"Parallel", L"true")
  96. TEST_METHOD_PROPERTY(L"Priority", L"0")
  97. END_TEST_CLASS()
  98. TEST_CLASS_SETUP(InitSupport);
  99. TEST_METHOD(WhenCorrectThenOK);
  100. TEST_METHOD(WhenMisalignedThenFail);
  101. TEST_METHOD(WhenEmptyFileThenFail);
  102. TEST_METHOD(WhenIncorrectMagicThenFail);
  103. TEST_METHOD(WhenIncorrectTargetTripleThenFail);
  104. TEST_METHOD(WhenIncorrectModelThenFail);
  105. TEST_METHOD(WhenIncorrectPSThenFail);
  106. TEST_METHOD(WhenWaveAffectsGradientThenFail);
  107. TEST_METHOD(WhenMultipleModulesThenFail);
  108. TEST_METHOD(WhenUnexpectedEOFThenFail);
  109. TEST_METHOD(WhenUnknownBlocksThenFail);
  110. TEST_METHOD(WhenZeroInputPatchCountWithInputThenFail);
  111. TEST_METHOD(LoadOutputControlPointNotInPatchConstantFunction);
  112. TEST_METHOD(StorePatchControlNotInPatchConstantFunction);
  113. TEST_METHOD(OutputControlPointIDInPatchConstantFunction);
  114. TEST_METHOD(GsVertexIDOutOfBound)
  115. TEST_METHOD(StreamIDOutOfBound)
  116. TEST_METHOD(SignatureStreamIDForNonGS)
  117. TEST_METHOD(TypedUAVStoreFullMask0)
  118. TEST_METHOD(TypedUAVStoreFullMask1)
  119. TEST_METHOD(Recursive)
  120. TEST_METHOD(Recursive2)
  121. TEST_METHOD(Recursive3)
  122. TEST_METHOD(ResourceRangeOverlap0)
  123. TEST_METHOD(ResourceRangeOverlap1)
  124. TEST_METHOD(ResourceRangeOverlap2)
  125. TEST_METHOD(ResourceRangeOverlap3)
  126. TEST_METHOD(CBufferOverlap0)
  127. TEST_METHOD(CBufferOverlap1)
  128. TEST_METHOD(ControlFlowHint)
  129. TEST_METHOD(ControlFlowHint1)
  130. TEST_METHOD(ControlFlowHint2)
  131. TEST_METHOD(SemanticLength1)
  132. TEST_METHOD(SemanticLength64)
  133. TEST_METHOD(PullModelPosition)
  134. TEST_METHOD(StructBufStrideAlign)
  135. TEST_METHOD(StructBufStrideOutOfBound)
  136. TEST_METHOD(StructBufGlobalCoherentAndCounter)
  137. TEST_METHOD(StructBufLoadCoordinates)
  138. TEST_METHOD(StructBufStoreCoordinates)
  139. TEST_METHOD(TypedBufRetType)
  140. TEST_METHOD(VsInputSemantic)
  141. TEST_METHOD(VsOutputSemantic)
  142. TEST_METHOD(HsInputSemantic)
  143. TEST_METHOD(HsOutputSemantic)
  144. TEST_METHOD(PatchConstSemantic)
  145. TEST_METHOD(DsInputSemantic)
  146. TEST_METHOD(DsOutputSemantic)
  147. TEST_METHOD(GsInputSemantic)
  148. TEST_METHOD(GsOutputSemantic)
  149. TEST_METHOD(PsInputSemantic)
  150. TEST_METHOD(PsOutputSemantic)
  151. TEST_METHOD(ArrayOfSVTarget)
  152. TEST_METHOD(InfiniteLog)
  153. TEST_METHOD(InfiniteAsin)
  154. TEST_METHOD(InfiniteAcos)
  155. TEST_METHOD(InfiniteDdxDdy)
  156. TEST_METHOD(IDivByZero)
  157. TEST_METHOD(UDivByZero)
  158. TEST_METHOD(UnusedMetadata)
  159. TEST_METHOD(MemoryOutOfBound)
  160. TEST_METHOD(LocalRes2)
  161. TEST_METHOD(LocalRes3)
  162. TEST_METHOD(LocalRes5)
  163. TEST_METHOD(LocalRes5Dbg)
  164. TEST_METHOD(LocalRes6)
  165. TEST_METHOD(LocalRes6Dbg)
  166. TEST_METHOD(AddrSpaceCast)
  167. TEST_METHOD(PtrBitCast)
  168. TEST_METHOD(MinPrecisionBitCast)
  169. TEST_METHOD(StructBitCast)
  170. TEST_METHOD(MultiDimArray)
  171. TEST_METHOD(SimpleGs8)
  172. TEST_METHOD(SimpleGs9)
  173. TEST_METHOD(SimpleGs10)
  174. TEST_METHOD(IllegalSampleOffset3)
  175. TEST_METHOD(IllegalSampleOffset4)
  176. TEST_METHOD(NoFunctionParam)
  177. TEST_METHOD(I8Type)
  178. TEST_METHOD(EmptyStructInBuffer)
  179. TEST_METHOD(BigStructInBuffer)
  180. TEST_METHOD(GloballyCoherent2)
  181. TEST_METHOD(GloballyCoherent3)
  182. // TODO: enable this.
  183. //TEST_METHOD(TGSMRaceCond)
  184. //TEST_METHOD(TGSMRaceCond2)
  185. TEST_METHOD(AddUint64Odd)
  186. TEST_METHOD(ClipCullMaxComponents)
  187. TEST_METHOD(ClipCullMaxRows)
  188. TEST_METHOD(DuplicateSysValue)
  189. TEST_METHOD(SemTargetMax)
  190. TEST_METHOD(SemTargetIndexMatchesRow)
  191. TEST_METHOD(SemTargetCol0)
  192. TEST_METHOD(SemIndexMax)
  193. TEST_METHOD(SemTessFactorIndexMax)
  194. TEST_METHOD(SemInsideTessFactorIndexMax)
  195. TEST_METHOD(SemShouldBeAllocated)
  196. TEST_METHOD(SemShouldNotBeAllocated)
  197. TEST_METHOD(SemComponentOrder)
  198. TEST_METHOD(SemComponentOrder2)
  199. TEST_METHOD(SemComponentOrder3)
  200. TEST_METHOD(SemIndexConflictArbSV)
  201. TEST_METHOD(SemIndexConflictTessfactors)
  202. TEST_METHOD(SemIndexConflictTessfactors2)
  203. TEST_METHOD(SemRowOutOfRange)
  204. TEST_METHOD(SemPackOverlap)
  205. TEST_METHOD(SemPackOverlap2)
  206. TEST_METHOD(SemMultiDepth)
  207. TEST_METHOD(WhenInstrDisallowedThenFail);
  208. TEST_METHOD(WhenDepthNotFloatThenFail);
  209. TEST_METHOD(BarrierFail);
  210. TEST_METHOD(CBufferLegacyOutOfBoundFail);
  211. TEST_METHOD(CsThreadSizeFail);
  212. TEST_METHOD(DeadLoopFail);
  213. TEST_METHOD(EvalFail);
  214. TEST_METHOD(GetDimCalcLODFail);
  215. TEST_METHOD(HsAttributeFail);
  216. TEST_METHOD(InnerCoverageFail);
  217. TEST_METHOD(InterpChangeFail);
  218. TEST_METHOD(InterpOnIntFail);
  219. TEST_METHOD(InvalidSigCompTyFail);
  220. TEST_METHOD(MultiStream2Fail);
  221. TEST_METHOD(PhiTGSMFail);
  222. TEST_METHOD(ReducibleFail);
  223. TEST_METHOD(SampleBiasFail);
  224. TEST_METHOD(SamplerKindFail);
  225. TEST_METHOD(SemaOverlapFail);
  226. TEST_METHOD(SigOutOfRangeFail);
  227. TEST_METHOD(SigOverlapFail);
  228. TEST_METHOD(SimpleHs1Fail);
  229. TEST_METHOD(SimpleHs3Fail);
  230. TEST_METHOD(SimpleHs4Fail);
  231. TEST_METHOD(SimpleDs1Fail);
  232. TEST_METHOD(SimpleGs1Fail);
  233. TEST_METHOD(UavBarrierFail);
  234. TEST_METHOD(UndefValueFail);
  235. TEST_METHOD(UpdateCounterFail);
  236. TEST_METHOD(LocalResCopy);
  237. TEST_METHOD(WhenSmUnknownThenFail);
  238. TEST_METHOD(WhenSmLegacyThenFail);
  239. TEST_METHOD(WhenMetaFlagsUsageDeclThenOK);
  240. TEST_METHOD(WhenMetaFlagsUsageThenFail);
  241. TEST_METHOD(WhenRootSigMismatchThenFail);
  242. TEST_METHOD(WhenRootSigCompatThenSucceed);
  243. TEST_METHOD(WhenRootSigMatchShaderSucceed_RootConstVis);
  244. TEST_METHOD(WhenRootSigMatchShaderFail_RootConstVis);
  245. TEST_METHOD(WhenRootSigMatchShaderSucceed_RootCBV);
  246. TEST_METHOD(WhenRootSigMatchShaderFail_RootCBV_Range);
  247. TEST_METHOD(WhenRootSigMatchShaderFail_RootCBV_Space);
  248. TEST_METHOD(WhenRootSigMatchShaderSucceed_RootSRV);
  249. TEST_METHOD(WhenRootSigMatchShaderFail_RootSRV_ResType);
  250. TEST_METHOD(WhenRootSigMatchShaderSucceed_RootUAV);
  251. TEST_METHOD(WhenRootSigMatchShaderSucceed_DescTable);
  252. TEST_METHOD(WhenRootSigMatchShaderSucceed_DescTable_GoodRange);
  253. TEST_METHOD(WhenRootSigMatchShaderSucceed_DescTable_Unbounded);
  254. TEST_METHOD(WhenRootSigMatchShaderFail_DescTable_Range1);
  255. TEST_METHOD(WhenRootSigMatchShaderFail_DescTable_Range2);
  256. TEST_METHOD(WhenRootSigMatchShaderFail_DescTable_Range3);
  257. TEST_METHOD(WhenRootSigMatchShaderFail_DescTable_Space);
  258. TEST_METHOD(WhenRootSigMatchShaderSucceed_Unbounded);
  259. TEST_METHOD(WhenRootSigMatchShaderFail_Unbounded1);
  260. TEST_METHOD(WhenRootSigMatchShaderFail_Unbounded2);
  261. TEST_METHOD(WhenRootSigMatchShaderFail_Unbounded3);
  262. TEST_METHOD(WhenProgramOutSigMissingThenFail);
  263. TEST_METHOD(WhenProgramOutSigUnexpectedThenFail);
  264. TEST_METHOD(WhenProgramSigMismatchThenFail);
  265. TEST_METHOD(WhenProgramInSigMissingThenFail);
  266. TEST_METHOD(WhenProgramSigMismatchThenFail2);
  267. TEST_METHOD(WhenProgramPCSigMissingThenFail);
  268. TEST_METHOD(WhenPSVMismatchThenFail);
  269. TEST_METHOD(WhenFeatureInfoMismatchThenFail);
  270. TEST_METHOD(ViewIDInCSFail)
  271. TEST_METHOD(ViewIDIn60Fail)
  272. TEST_METHOD(ViewIDNoSpaceFail)
  273. dxc::DxcDllSupport m_dllSupport;
  274. bool m_CompilerPreservesBBNames;
  275. bool SkipIRSensitiveTest() {
  276. if (!m_CompilerPreservesBBNames) {
  277. WEX::Logging::Log::Comment(L"Test skipped due to name preservation requirment.");
  278. return true;
  279. }
  280. return false;
  281. }
  282. void TestCheck(LPCWSTR name) {
  283. std::wstring fullPath = hlsl_test::GetPathToHlslDataFile(name);
  284. FileRunTestResult t = FileRunTestResult::RunFromFileCommands(fullPath.c_str());
  285. if (t.RunResult != 0) {
  286. CA2W commentWide(t.ErrorMessage.c_str(), CP_UTF8);
  287. WEX::Logging::Log::Comment(commentWide);
  288. WEX::Logging::Log::Error(L"Run result is not zero");
  289. }
  290. }
  291. void CheckValidationMsgs(IDxcBlob *pBlob, llvm::ArrayRef<LPCSTR> pErrorMsgs, bool bRegex = false) {
  292. CComPtr<IDxcValidator> pValidator;
  293. CComPtr<IDxcOperationResult> pResult;
  294. VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcValidator, &pValidator));
  295. VERIFY_SUCCEEDED(pValidator->Validate(pBlob, DxcValidatorFlags_Default, &pResult));
  296. CheckOperationResultMsgs(pResult, pErrorMsgs, false, bRegex);
  297. }
  298. void CheckValidationMsgs(const char *pBlob, size_t blobSize, llvm::ArrayRef<LPCSTR> pErrorMsgs, bool bRegex = false) {
  299. CComPtr<IDxcLibrary> pLibrary;
  300. CComPtr<IDxcBlobEncoding> pBlobEncoding; // Encoding doesn't actually matter, it's binary.
  301. VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcLibrary, &pLibrary));
  302. VERIFY_SUCCEEDED(pLibrary->CreateBlobWithEncodingFromPinned((LPBYTE)pBlob, blobSize, CP_UTF8, &pBlobEncoding));
  303. CheckValidationMsgs(pBlobEncoding, pErrorMsgs, bRegex);
  304. }
  305. void CompileSource(IDxcBlobEncoding *pSource, LPCSTR pShaderModel,
  306. IDxcBlob **pResultBlob) {
  307. CComPtr<IDxcCompiler> pCompiler;
  308. CComPtr<IDxcOperationResult> pResult;
  309. CComPtr<IDxcBlob> pProgram;
  310. CA2W shWide(pShaderModel, CP_UTF8);
  311. VERIFY_SUCCEEDED(
  312. m_dllSupport.CreateInstance(CLSID_DxcCompiler, &pCompiler));
  313. VERIFY_SUCCEEDED(pCompiler->Compile(pSource, L"hlsl.hlsl", L"main",
  314. shWide, nullptr, 0, nullptr, 0, nullptr,
  315. &pResult));
  316. CheckOperationResultMsgs(pResult, nullptr, false, false);
  317. VERIFY_SUCCEEDED(pResult->GetResult(pResultBlob));
  318. }
  319. void CompileSource(LPCSTR pSource, LPCSTR pShaderModel,
  320. IDxcBlob **pResultBlob) {
  321. CComPtr<IDxcBlobEncoding> pSourceBlob;
  322. Utf8ToBlob(m_dllSupport, pSource, &pSourceBlob);
  323. CompileSource(pSourceBlob, pShaderModel, pResultBlob);
  324. }
  325. void DisassembleProgram(IDxcBlob *pProgram, std::string *text) {
  326. *text = ::DisassembleProgram(m_dllSupport, pProgram);
  327. }
  328. void RewriteAssemblyCheckMsg(LPCSTR pSource, LPCSTR pShaderModel,
  329. llvm::ArrayRef<LPCSTR> pLookFors, llvm::ArrayRef<LPCSTR> pReplacements,
  330. llvm::ArrayRef<LPCSTR> pErrorMsgs, bool bRegex = false) {
  331. CComPtr<IDxcBlob> pText;
  332. CComPtr<IDxcBlobEncoding> pSourceBlob;
  333. Utf8ToBlob(m_dllSupport, pSource, &pSourceBlob);
  334. RewriteAssemblyToText(pSourceBlob, pShaderModel, pLookFors, pReplacements, &pText, bRegex);
  335. CComPtr<IDxcAssembler> pAssembler;
  336. CComPtr<IDxcOperationResult> pAssembleResult;
  337. VERIFY_SUCCEEDED(
  338. m_dllSupport.CreateInstance(CLSID_DxcAssembler, &pAssembler));
  339. VERIFY_SUCCEEDED(pAssembler->AssembleToContainer(pText, &pAssembleResult));
  340. if (!CheckOperationResultMsgs(pAssembleResult, pErrorMsgs, true, bRegex)) {
  341. // Assembly succeeded, try validation.
  342. CComPtr<IDxcBlob> pBlob;
  343. VERIFY_SUCCEEDED(pAssembleResult->GetResult(&pBlob));
  344. CheckValidationMsgs(pBlob, pErrorMsgs, bRegex);
  345. }
  346. }
  347. void RewriteAssemblyToText(IDxcBlobEncoding *pSource, LPCSTR pShaderModel,
  348. llvm::ArrayRef<LPCSTR> pLookFors, llvm::ArrayRef<LPCSTR> pReplacements,
  349. IDxcBlob **pBlob, bool bRegex = false) {
  350. CComPtr<IDxcBlob> pProgram;
  351. std::string disassembly;
  352. CompileSource(pSource, pShaderModel, &pProgram);
  353. DisassembleProgram(pProgram, &disassembly);
  354. for (unsigned i = 0; i < pLookFors.size(); ++i) {
  355. LPCSTR pLookFor = pLookFors[i];
  356. LPCSTR pReplacement = pReplacements[i];
  357. if (pLookFor && *pLookFor) {
  358. if (bRegex) {
  359. llvm::Regex RE(pLookFor);
  360. std::string reErrors;
  361. VERIFY_IS_TRUE(RE.isValid(reErrors));
  362. std::string replaced = RE.sub(pReplacement, disassembly, &reErrors);
  363. VERIFY_ARE_NOT_EQUAL(disassembly, replaced);
  364. VERIFY_IS_TRUE(reErrors.empty());
  365. disassembly = std::move(replaced);
  366. } else {
  367. bool found = false;
  368. size_t pos = 0;
  369. size_t lookForLen = strlen(pLookFor);
  370. size_t replaceLen = strlen(pReplacement);
  371. for (;;) {
  372. pos = disassembly.find(pLookFor, pos);
  373. if (pos == std::string::npos)
  374. break;
  375. found = true; // at least once
  376. disassembly.replace(pos, lookForLen, pReplacement);
  377. pos += replaceLen;
  378. }
  379. VERIFY_IS_TRUE(found);
  380. }
  381. }
  382. }
  383. Utf8ToBlob(m_dllSupport, disassembly.c_str(), pBlob);
  384. }
  385. void RewriteAssemblyCheckMsg(LPCWSTR name, LPCSTR pShaderModel,
  386. llvm::ArrayRef<LPCSTR> pLookFors, llvm::ArrayRef<LPCSTR> pReplacements,
  387. llvm::ArrayRef<LPCSTR> pErrorMsgs, bool bRegex = false) {
  388. std::wstring fullPath = hlsl_test::GetPathToHlslDataFile(name);
  389. CComPtr<IDxcLibrary> pLibrary;
  390. CComPtr<IDxcBlobEncoding> pSource;
  391. VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcLibrary, &pLibrary));
  392. VERIFY_SUCCEEDED(
  393. pLibrary->CreateBlobFromFile(fullPath.c_str(), nullptr, &pSource));
  394. CComPtr<IDxcBlob> pText;
  395. RewriteAssemblyToText(pSource, pShaderModel, pLookFors, pReplacements, &pText, bRegex);
  396. CComPtr<IDxcAssembler> pAssembler;
  397. CComPtr<IDxcOperationResult> pAssembleResult;
  398. VERIFY_SUCCEEDED(
  399. m_dllSupport.CreateInstance(CLSID_DxcAssembler, &pAssembler));
  400. VERIFY_SUCCEEDED(pAssembler->AssembleToContainer(pText, &pAssembleResult));
  401. if (!CheckOperationResultMsgs(pAssembleResult, pErrorMsgs, true, bRegex)) {
  402. // Assembly succeeded, try validation.
  403. CComPtr<IDxcBlob> pBlob;
  404. VERIFY_SUCCEEDED(pAssembleResult->GetResult(&pBlob));
  405. CheckValidationMsgs(pBlob, pErrorMsgs, bRegex);
  406. }
  407. }
  408. // compile one or two sources, validate module from 1 with container parts from 2, check messages
  409. void ReplaceContainerPartsCheckMsgs(LPCSTR pSource1, LPCSTR pSource2, LPCSTR pShaderModel,
  410. llvm::ArrayRef<DxilFourCC> PartsToReplace,
  411. llvm::ArrayRef<LPCSTR> pErrorMsgs) {
  412. CComPtr<IDxcBlob> pProgram1, pProgram2;
  413. CompileSource(pSource1, pShaderModel, &pProgram1);
  414. VERIFY_IS_NOT_NULL(pProgram1);
  415. if (pSource2) {
  416. CompileSource(pSource2, pShaderModel, &pProgram2);
  417. VERIFY_IS_NOT_NULL(pProgram2);
  418. } else {
  419. pProgram2 = pProgram1;
  420. }
  421. // construct container with moudle from pProgram1 with other parts from pProgram2:
  422. const DxilContainerHeader *pHeader1 = IsDxilContainerLike(pProgram1->GetBufferPointer(), pProgram1->GetBufferSize());
  423. VERIFY_IS_NOT_NULL(pHeader1);
  424. const DxilContainerHeader *pHeader2 = IsDxilContainerLike(pProgram2->GetBufferPointer(), pProgram2->GetBufferSize());
  425. VERIFY_IS_NOT_NULL(pHeader2);
  426. unique_ptr<DxilContainerWriter> pContainerWriter(NewDxilContainerWriter());
  427. // Add desired parts from first container
  428. for (auto pPart : pHeader1) {
  429. for (auto dfcc : PartsToReplace) {
  430. if (dfcc == pPart->PartFourCC) {
  431. pPart = nullptr;
  432. break;
  433. }
  434. }
  435. if (!pPart)
  436. continue;
  437. pContainerWriter->AddPart(pPart->PartFourCC, pPart->PartSize, [=](AbstractMemoryStream *pStream) {
  438. ULONG cbWritten = 0;
  439. pStream->Write(GetDxilPartData(pPart), pPart->PartSize, &cbWritten);
  440. });
  441. }
  442. // Add desired parts from second container
  443. for (auto pPart : pHeader2) {
  444. for (auto dfcc : PartsToReplace) {
  445. if (dfcc == pPart->PartFourCC) {
  446. pContainerWriter->AddPart(pPart->PartFourCC, pPart->PartSize, [=](AbstractMemoryStream *pStream) {
  447. ULONG cbWritten = 0;
  448. pStream->Write(GetDxilPartData(pPart), pPart->PartSize, &cbWritten);
  449. });
  450. break;
  451. }
  452. }
  453. }
  454. // Write the container
  455. CComPtr<IMalloc> pMalloc;
  456. VERIFY_SUCCEEDED(CoGetMalloc(1, &pMalloc));
  457. CComPtr<AbstractMemoryStream> pOutputStream;
  458. VERIFY_SUCCEEDED(CreateMemoryStream(pMalloc, &pOutputStream));
  459. pOutputStream->Reserve(pContainerWriter->size());
  460. pContainerWriter->write(pOutputStream);
  461. CheckValidationMsgs((const char *)pOutputStream->GetPtr(), pOutputStream->GetPtrSize(), pErrorMsgs, /*bRegex*/false);
  462. }
  463. };
  464. bool ValidationTest::InitSupport() {
  465. if (!m_dllSupport.IsEnabled()) {
  466. VERIFY_SUCCEEDED(m_dllSupport.Initialize());
  467. // This is a very indirect way of testing this. Consider improving support.
  468. CComPtr<IDxcValidator> pValidator;
  469. CComPtr<IDxcVersionInfo> pVersionInfo;
  470. UINT32 VersionFlags = 0;
  471. VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcValidator, &pValidator));
  472. VERIFY_SUCCEEDED(pValidator.QueryInterface(&pVersionInfo));
  473. VERIFY_SUCCEEDED(pVersionInfo->GetFlags(&VersionFlags));
  474. m_CompilerPreservesBBNames = (VersionFlags & DxcVersionInfoFlags_Debug) ? true : false;
  475. }
  476. return true;
  477. }
  478. TEST_F(ValidationTest, WhenCorrectThenOK) {
  479. CComPtr<IDxcBlob> pProgram;
  480. CompileSource("float4 main() : SV_Target { return 1; }", "ps_6_0", &pProgram);
  481. CheckValidationMsgs(pProgram, nullptr);
  482. }
  483. // Lots of these going on below for simplicity in setting up payloads.
  484. //
  485. // warning C4838: conversion from 'int' to 'const char' requires a narrowing conversion
  486. // warning C4309: 'initializing': truncation of constant value
  487. #pragma warning(disable: 4838)
  488. #pragma warning(disable: 4309)
  489. TEST_F(ValidationTest, WhenMisalignedThenFail) {
  490. // Bitcode size must 4-byte aligned
  491. const char blob[] = {
  492. 'B', 'C',
  493. };
  494. CheckValidationMsgs(blob, _countof(blob), "Invalid bitcode size");
  495. }
  496. TEST_F(ValidationTest, WhenEmptyFileThenFail) {
  497. // No blocks after signature.
  498. const char blob[] = {
  499. 'B', 'C', 0xc0, 0xde
  500. };
  501. CheckValidationMsgs(blob, _countof(blob), "Malformed IR file");
  502. }
  503. TEST_F(ValidationTest, WhenIncorrectMagicThenFail) {
  504. // Signature isn't 'B', 'C', 0xC0 0xDE
  505. const char blob[] = {
  506. 'B', 'C', 0xc0, 0xdd
  507. };
  508. CheckValidationMsgs(blob, _countof(blob), "Invalid bitcode signature");
  509. }
  510. TEST_F(ValidationTest, WhenIncorrectTargetTripleThenFail) {
  511. const char blob[] = {
  512. 'B', 'C', 0xc0, 0xde
  513. };
  514. CheckValidationMsgs(blob, _countof(blob), "Malformed IR file");
  515. }
  516. TEST_F(ValidationTest, WhenMultipleModulesThenFail) {
  517. const char blob[] = {
  518. 'B', 'C', 0xc0, 0xde,
  519. 0x21, 0x0c, 0x00, 0x00, // Enter sub-block, BlockID = 8, Code Size=3, padding x2
  520. 0x00, 0x00, 0x00, 0x00, // NumWords = 0
  521. 0x08, 0x00, 0x00, 0x00, // End-of-block, padding
  522. // At this point, this is valid bitcode (but missing required DXIL metadata)
  523. // Trigger the case we're looking for now
  524. 0x21, 0x0c, 0x00, 0x00, // Enter sub-block, BlockID = 8, Code Size=3, padding x2
  525. };
  526. CheckValidationMsgs(blob, _countof(blob), "Unused bits in buffer");
  527. }
  528. TEST_F(ValidationTest, WhenUnexpectedEOFThenFail) {
  529. // Importantly, this is testing the usage of report_fatal_error during deserialization.
  530. const char blob[] = {
  531. 'B', 'C', 0xc0, 0xde,
  532. 0x21, 0x0c, 0x00, 0x00, // Enter sub-block, BlockID = 8, Code Size=3, padding x2
  533. 0x00, 0x00, 0x00, 0x00, // NumWords = 0
  534. };
  535. CheckValidationMsgs(blob, _countof(blob), "Invalid record");
  536. }
  537. TEST_F(ValidationTest, WhenUnknownBlocksThenFail) {
  538. const char blob[] = {
  539. 'B', 'C', 0xc0, 0xde, // Signature
  540. 0x31, 0x00, 0x00, 0x00 // Enter sub-block, BlockID != 8
  541. };
  542. CheckValidationMsgs(blob, _countof(blob), "Unrecognized block found");
  543. }
  544. TEST_F(ValidationTest, WhenZeroInputPatchCountWithInputThenFail) {
  545. RewriteAssemblyCheckMsg(
  546. L"..\\CodeGenHLSL\\SimpleHs1.hlsl", "hs_6_0",
  547. "void ()* @\"\\01?HSPerPatchFunc@@YA?AUHSPerPatchData@@V?$InputPatch@UPSSceneIn@@$02@@@Z.flat\", i32 3, i32 3",
  548. "void ()* @\"\\01?HSPerPatchFunc@@YA?AUHSPerPatchData@@V?$InputPatch@UPSSceneIn@@$02@@@Z.flat\", i32 0, i32 3",
  549. "When HS input control point count is 0, no input signature should exist");
  550. }
  551. TEST_F(ValidationTest, WhenInstrDisallowedThenFail) {
  552. RewriteAssemblyCheckMsg(
  553. L"..\\CodeGenHLSL\\abs2.hlsl", "ps_6_0",
  554. {
  555. "target triple = \"dxil-ms-dx\"",
  556. "ret void",
  557. "dx.op.loadInput.i32(i32 4, i32 0, i32 0, i8 3, i32 undef)",
  558. "!\"ps\", i32 6, i32 0",
  559. },
  560. {
  561. "target triple = \"dxil-ms-dx\"\n%dx.types.wave_t = type { i8* }",
  562. "unreachable",
  563. "dx.op.loadInput.i32(i32 4, i32 0, i32 0, i8 3, i32 undef)\n%wave_local = alloca %dx.types.wave_t",
  564. "!\"vs\", i32 6, i32 0",
  565. },
  566. {"Semantic 'SV_Target' is invalid as vs Output",
  567. "Declaration '%dx.types.wave_t = type { i8* }' uses a reserved prefix",
  568. "Instructions must be of an allowed type",
  569. }
  570. );
  571. }
  572. TEST_F(ValidationTest, WhenDepthNotFloatThenFail) {
  573. RewriteAssemblyCheckMsg(L"..\\CodeGenHLSL\\IntegerDepth2.hlsl", "ps_6_0",
  574. {
  575. "!\"SV_Depth\", i8 9",
  576. },
  577. {
  578. "!\"SV_Depth\", i8 4",
  579. },
  580. {
  581. "SV_Depth must be float",
  582. });
  583. }
  584. TEST_F(ValidationTest, BarrierFail) {
  585. if (SkipIRSensitiveTest()) return;
  586. RewriteAssemblyCheckMsg(
  587. L"..\\CodeGenHLSL\\barrier.hlsl", "cs_6_0",
  588. {"dx.op.barrier(i32 80, i32 8)",
  589. "dx.op.barrier(i32 80, i32 9)",
  590. "dx.op.barrier(i32 80, i32 11)",
  591. "%class.RWStructuredBuffer = type { %class.matrix.float.2.2 }\n",
  592. "call i32 @dx.op.flattenedThreadIdInGroup.i32(i32 96)",
  593. },
  594. {"dx.op.barrier(i32 80, i32 15)",
  595. "dx.op.barrier(i32 80, i32 0)",
  596. "dx.op.barrier(i32 80, i32 %rem)",
  597. "%class.RWStructuredBuffer = type { %class.matrix.float.2.2 }\n"
  598. "@dx.typevar.8 = external addrspace(1) constant %class.RWStructuredBuffer\n"
  599. "@\"internalGV\" = internal global [64 x <4 x float>] undef\n",
  600. "call i32 @dx.op.flattenedThreadIdInGroup.i32(i32 96)\n"
  601. "%load = load %class.RWStructuredBuffer, %class.RWStructuredBuffer addrspace(1)* @dx.typevar.8",
  602. },
  603. {"Internal declaration 'internalGV' is unused",
  604. "External declaration 'dx.typevar.8' is unused",
  605. "Vector type '<4 x float>' is not allowed",
  606. "Mode of Barrier must be an immediate constant",
  607. "sync must include some form of memory barrier - _u (UAV) and/or _g (Thread Group Shared Memory)",
  608. "sync can't specify both _ugroup and _uglobal. If both are needed, just specify _uglobal"
  609. });
  610. }
  611. TEST_F(ValidationTest, CBufferLegacyOutOfBoundFail) {
  612. RewriteAssemblyCheckMsg(
  613. L"..\\CodeGenHLSL\\cbuffer1.50.hlsl", "ps_6_0",
  614. "cbufferLoadLegacy.f32(i32 59, %dx.types.Handle %Foo2_buffer, i32 0)",
  615. "cbufferLoadLegacy.f32(i32 59, %dx.types.Handle %Foo2_buffer, i32 6)",
  616. "Cbuffer access out of bound");
  617. }
  618. TEST_F(ValidationTest, CsThreadSizeFail) {
  619. RewriteAssemblyCheckMsg(
  620. L"..\\CodeGenHLSL\\share_mem1.hlsl", "cs_6_0",
  621. {"!{i32 8, i32 8, i32 1",
  622. "[256 x float]"},
  623. {"!{i32 1025, i32 1025, i32 1025",
  624. "[64000000 x float]"},
  625. {"Declared Thread Group X size 1025 outside valid range",
  626. "Declared Thread Group Y size 1025 outside valid range",
  627. "Declared Thread Group Z size 1025 outside valid range",
  628. "Declared Thread Group Count 1076890625 (X*Y*Z) is beyond the valid maximum",
  629. "Total Thread Group Shared Memory storage is 256000000, exceeded 32768",
  630. });
  631. }
  632. TEST_F(ValidationTest, DeadLoopFail) {
  633. if (SkipIRSensitiveTest()) return;
  634. RewriteAssemblyCheckMsg(
  635. L"..\\CodeGenHLSL\\loop1.hlsl", "ps_6_0",
  636. {"br i1 %exitcond, label %for.end.loopexit, label %for.body, !llvm.loop !([0-9]+)",
  637. "%add.lcssa = phi float \\[ %add, %for.body \\]",
  638. "!dx.entryPoints = !\\{!([0-9]+)\\}",
  639. "\\[ %add.lcssa, %for.end.loopexit \\]"
  640. },
  641. {"br label %for.body",
  642. "",
  643. "!dx.entryPoints = !\\{!\\1\\}\n!dx.unused = !\\{!\\1\\}",
  644. "[ 0.000000e+00, %for.end.loopexit ]"
  645. },
  646. {"Loop must have break",
  647. "Named metadata 'dx.unused' is unknown",
  648. },
  649. /*bRegex*/true);
  650. }
  651. TEST_F(ValidationTest, EvalFail) {
  652. RewriteAssemblyCheckMsg(
  653. L"..\\CodeGenHLSL\\Eval.hlsl", "ps_6_0",
  654. "!\"A\", i8 9, i8 0, !([0-9]+), i8 2, i32 1, i8 4",
  655. "!\"A\", i8 9, i8 0, !\\1, i8 0, i32 1, i8 4",
  656. "Interpolation mode on A used with eval_\\* instruction must be ",
  657. /*bRegex*/true);
  658. }
  659. TEST_F(ValidationTest, GetDimCalcLODFail) {
  660. RewriteAssemblyCheckMsg(
  661. L"..\\CodeGenHLSL\\GetDimCalcLOD.hlsl", "ps_6_0",
  662. {"extractvalue %dx.types.Dimensions %([0-9]+), 1",
  663. "float 1.000000e\\+00, i1 true"
  664. },
  665. {"extractvalue %dx.types.Dimensions %\\1, 2",
  666. "float undef, i1 true"
  667. },
  668. {"GetDimensions used undef dimension z on TextureCube",
  669. "coord uninitialized"},
  670. /*bRegex*/true);
  671. }
  672. TEST_F(ValidationTest, HsAttributeFail) {
  673. RewriteAssemblyCheckMsg(
  674. L"..\\CodeGenHLSL\\hsAttribute.hlsl", "hs_6_0",
  675. {"i32 3, i32 3, i32 2, i32 3, i32 3, float 6.400000e+01"
  676. },
  677. {"i32 36, i32 36, i32 0, i32 0, i32 0, float 6.500000e+01"
  678. },
  679. {"HS input control point count must be [0..32]. 36 specified",
  680. "Invalid Tessellator Domain specified. Must be isoline, tri or quad",
  681. "Invalid Tessellator Partitioning specified",
  682. "Invalid Tessellator Output Primitive specified",
  683. "Hull Shader MaxTessFactor must be [1.000000..64.000000]. 65.000000 specified",
  684. "output control point count must be [0..32]. 36 specified"});
  685. }
  686. TEST_F(ValidationTest, InnerCoverageFail) {
  687. RewriteAssemblyCheckMsg(
  688. L"..\\CodeGenHLSL\\InnerCoverage2.hlsl", "ps_6_0",
  689. {"dx.op.coverage.i32(i32 91)",
  690. "declare i32 @dx.op.coverage.i32(i32)"
  691. },
  692. {"dx.op.coverage.i32(i32 91)\n %inner = call i32 @dx.op.innerCoverage.i32(i32 92)",
  693. "declare i32 @dx.op.coverage.i32(i32)\n"
  694. "declare i32 @dx.op.innerCoverage.i32(i32)"
  695. },
  696. "InnerCoverage and Coverage are mutually exclusive.");
  697. }
  698. TEST_F(ValidationTest, InterpChangeFail) {
  699. RewriteAssemblyCheckMsg(
  700. L"..\\CodeGenHLSL\\interpChange.hlsl", "ps_6_0",
  701. "i32 1, i8 0, null}",
  702. "i32 0, i8 2, null}",
  703. "interpolation mode that differs from another element packed",
  704. /*bRegex*/true);
  705. }
  706. TEST_F(ValidationTest, InterpOnIntFail) {
  707. RewriteAssemblyCheckMsg(
  708. L"..\\CodeGenHLSL\\interpOnInt2.hlsl", "ps_6_0",
  709. "!\"A\", i8 5, i8 0, !([0-9]+), i8 1",
  710. "!\"A\", i8 5, i8 0, !\\1, i8 2",
  711. "signature element A specifies invalid interpolation mode for integer component type",
  712. /*bRegex*/true);
  713. }
  714. TEST_F(ValidationTest, InvalidSigCompTyFail) {
  715. RewriteAssemblyCheckMsg(
  716. L"..\\CodeGenHLSL\\abs2.hlsl", "ps_6_0",
  717. "!\"A\", i8 4",
  718. "!\"A\", i8 0",
  719. "A specifies unrecognized or invalid component type");
  720. }
  721. TEST_F(ValidationTest, MultiStream2Fail) {
  722. RewriteAssemblyCheckMsg(
  723. L"..\\CodeGenHLSL\\multiStreamGS.hlsl", "gs_6_0",
  724. "i32 1, i32 12, i32 7, i32 1, i32 1",
  725. "i32 1, i32 12, i32 7, i32 2, i32 1",
  726. "Multiple GS output streams are used but 'XXX' is not pointlist");
  727. }
  728. TEST_F(ValidationTest, PhiTGSMFail) {
  729. if (SkipIRSensitiveTest()) return;
  730. RewriteAssemblyCheckMsg(
  731. L"..\\CodeGenHLSL\\phiTGSM.hlsl", "cs_6_0",
  732. "ret void",
  733. "%arrayPhi = phi i32 addrspace(3)* [ %arrayidx, %if.then ], [ %arrayidx2, %if.else ]\n"
  734. "%phiAtom = atomicrmw add i32 addrspace(3)* %arrayPhi, i32 1 seq_cst\n"
  735. "ret void",
  736. "TGSM pointers must originate from an unambiguous TGSM global variable");
  737. }
  738. TEST_F(ValidationTest, ReducibleFail) {
  739. if (SkipIRSensitiveTest()) return;
  740. RewriteAssemblyCheckMsg(
  741. L"..\\CodeGenHLSL\\reducible.hlsl", "ps_6_0",
  742. {"%conv\n"
  743. " br label %if.end",
  744. "to float\n"
  745. " br label %if.end"
  746. },
  747. {"%conv\n"
  748. " br i1 %cmp, label %if.else, label %if.end",
  749. "to float\n"
  750. " br i1 %cmp, label %if.then, label %if.end"
  751. },
  752. "Execution flow must be reducible");
  753. }
  754. TEST_F(ValidationTest, SampleBiasFail) {
  755. RewriteAssemblyCheckMsg(
  756. L"..\\CodeGenHLSL\\sampleBias.hlsl", "ps_6_0",
  757. {"float -1.600000e+01"
  758. },
  759. {"float 1.800000e+01"
  760. },
  761. "bias amount for sample_b must be in the range [-16.000000,15.990000]");
  762. }
  763. TEST_F(ValidationTest, SamplerKindFail) {
  764. RewriteAssemblyCheckMsg(
  765. L"..\\CodeGenHLSL\\samplerKind.hlsl", "ps_6_0",
  766. {"uav1_UAV_2d = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 1",
  767. "g_txDiffuse_texture_2d = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 0",
  768. "\"g_samLinear\", i32 0, i32 0, i32 1, i32 0",
  769. "\"g_samLinearC\", i32 0, i32 1, i32 1, i32 1",
  770. },
  771. {"uav1_UAV_2d = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 0",
  772. "g_txDiffuse_texture_2d = call %dx.types.Handle @dx.op.createHandle(i32 57, i8 1",
  773. "\"g_samLinear\", i32 0, i32 0, i32 1, i32 3",
  774. "\"g_samLinearC\", i32 0, i32 1, i32 1, i32 3",
  775. },
  776. {"Invalid sampler mode",
  777. "require sampler declared in comparison mode",
  778. "requires sampler declared in default mode",
  779. "should on srv resource"});
  780. }
  781. TEST_F(ValidationTest, SemaOverlapFail) {
  782. RewriteAssemblyCheckMsg(
  783. L"..\\CodeGenHLSL\\semaOverlap1.hlsl", "ps_6_0",
  784. {"!([0-9]+) = !\\{i32 0, !\"A\", i8 9, i8 0, !([0-9]+), i8 2, i32 1, i8 4, i32 0, i8 0, null\\}\n"
  785. "!([0-9]+) = !\\{i32 0\\}\n"
  786. "!([0-9]+) = !\\{i32 1, !\"A\", i8 9, i8 0, !([0-9]+)",
  787. },
  788. {"!\\1 = !\\{i32 0, !\"A\", i8 9, i8 0, !\\2, i8 2, i32 1, i8 4, i32 0, i8 0, null\\}\n"
  789. "!\\3 = !\\{i32 0\\}\n"
  790. "!\\4 = !\\{i32 1, !\"A\", i8 9, i8 0, !\\2",
  791. },
  792. {"Semantic 'A' overlap at 0"},
  793. /*bRegex*/true);
  794. }
  795. TEST_F(ValidationTest, SigOutOfRangeFail) {
  796. RewriteAssemblyCheckMsg(
  797. L"..\\CodeGenHLSL\\semaOverlap1.hlsl", "ps_6_0",
  798. {"i32 1, i8 0, null}",
  799. },
  800. {"i32 8000, i8 0, null}",
  801. },
  802. {"signature element A at location (8000,0) size (1,4) is out of range"});
  803. }
  804. TEST_F(ValidationTest, SigOverlapFail) {
  805. RewriteAssemblyCheckMsg(
  806. L"..\\CodeGenHLSL\\semaOverlap1.hlsl", "ps_6_0",
  807. {"i32 1, i8 0, null}",
  808. },
  809. {"i32 0, i8 0, null}",
  810. },
  811. {"signature element A at location (0,0) size (1,4) overlaps another signature element"});
  812. }
  813. TEST_F(ValidationTest, SimpleHs1Fail) {
  814. RewriteAssemblyCheckMsg(
  815. L"..\\CodeGenHLSL\\SimpleHs1.hlsl", "hs_6_0",
  816. {"i32 3, i32 3, i32 2, i32 3, i32 3, float 6.400000e+01}",
  817. "\"SV_TessFactor\", i8 9, i8 25",
  818. "\"SV_InsideTessFactor\", i8 9, i8 26",
  819. },
  820. {"i32 3, i32 3000, i32 2, i32 3, i32 3, float 6.400000e+01}",
  821. "\"TessFactor\", i8 9, i8 0",
  822. "\"InsideTessFactor\", i8 9, i8 0",
  823. },
  824. {"output control point count must be [0..32]. 3000 specified",
  825. "Required TessFactor for domain not found declared anywhere in Patch Constant data",
  826. // TODO: enable this after support pass thru hull shader.
  827. //"For pass thru hull shader, input control point count must match output control point count",
  828. //"Total number of scalars across all HS output control points must not exceed",
  829. });
  830. }
  831. TEST_F(ValidationTest, SimpleHs3Fail) {
  832. RewriteAssemblyCheckMsg(
  833. L"..\\CodeGenHLSL\\SimpleHs3.hlsl", "hs_6_0",
  834. {
  835. "i32 3, i32 3, i32 2, i32 3, i32 3, float 6.400000e+01}",
  836. },
  837. {
  838. "i32 3, i32 3, i32 2, i32 3, i32 2, float 6.400000e+01}",
  839. },
  840. {"Hull Shader declared with Tri Domain must specify output primitive "
  841. "point, triangle_cw or triangle_ccw. Line output is not compatible with "
  842. "the Tri domain"});
  843. }
  844. TEST_F(ValidationTest, SimpleHs4Fail) {
  845. RewriteAssemblyCheckMsg(
  846. L"..\\CodeGenHLSL\\SimpleHs4.hlsl", "hs_6_0",
  847. {
  848. "i32 2, i32 2, i32 1, i32 3, i32 2, float 6.400000e+01}",
  849. },
  850. {
  851. "i32 2, i32 2, i32 1, i32 3, i32 3, float 6.400000e+01}",
  852. },
  853. {"Hull Shader declared with IsoLine Domain must specify output primitive "
  854. "point or line. Triangle_cw or triangle_ccw output are not compatible "
  855. "with the IsoLine Domain"});
  856. }
  857. TEST_F(ValidationTest, SimpleDs1Fail) {
  858. RewriteAssemblyCheckMsg(
  859. L"..\\CodeGenHLSL\\SimpleDs1.hlsl", "ds_6_0",
  860. {"!{i32 2, i32 3}"
  861. },
  862. {"!{i32 4, i32 36}"
  863. },
  864. {"DS input control point count must be [0..32]. 36 specified",
  865. "Invalid Tessellator Domain specified. Must be isoline, tri or quad",
  866. "DomainLocation component index out of bounds for the domain"});
  867. }
  868. TEST_F(ValidationTest, SimpleGs1Fail) {
  869. RewriteAssemblyCheckMsg(
  870. L"..\\CodeGenHLSL\\SimpleGs1.hlsl", "gs_6_0",
  871. {"!{i32 1, i32 3, i32 1, i32 5, i32 1}",
  872. "i8 4, i32 1, i8 4, i32 2, i8 0, null}"
  873. },
  874. {"!{i32 5, i32 1025, i32 1, i32 0, i32 33}",
  875. "i8 4, i32 1, i8 4, i32 2, i8 0, !100}\n"
  876. "!100 = !{i32 0, i32 5}"
  877. },
  878. {"GS output vertex count must be [0..1024]. 1025 specified",
  879. "GS instance count must be [1..32]. 33 specified",
  880. "GS output primitive topology unrecognized",
  881. "GS input primitive unrecognized",
  882. "Stream index (5) must between 0 and 3"});
  883. }
  884. TEST_F(ValidationTest, UavBarrierFail) {
  885. if (SkipIRSensitiveTest()) return;
  886. RewriteAssemblyCheckMsg(
  887. L"..\\CodeGenHLSL\\uavBarrier.hlsl", "ps_6_0",
  888. {"dx.op.barrier(i32 80, i32 2)",
  889. "textureLoad.f32(i32 66, %dx.types.Handle %uav1_UAV_2d, i32 undef",
  890. "i32 undef, i32 undef, i32 undef, i32 undef)",
  891. "float %add9.i3, i8 15)",
  892. },
  893. {"dx.op.barrier(i32 80, i32 9)",
  894. "textureLoad.f32(i32 66, %dx.types.Handle %uav1_UAV_2d, i32 1",
  895. "i32 1, i32 2, i32 undef, i32 undef)",
  896. "float undef, i8 7)",
  897. },
  898. {"uav load don't support offset",
  899. "uav load don't support mipLevel/sampleIndex",
  900. "store on typed uav must write to all four components of the UAV",
  901. "sync in a non-Compute Shader must only sync UAV (sync_uglobal)"});
  902. }
  903. TEST_F(ValidationTest, UndefValueFail) {
  904. TestCheck(L"..\\CodeGenHLSL\\UndefValue.hlsl");
  905. }
  906. TEST_F(ValidationTest, UpdateCounterFail) {
  907. if (SkipIRSensitiveTest()) return;
  908. RewriteAssemblyCheckMsg(
  909. L"..\\CodeGenHLSL\\UpdateCounter2.hlsl", "ps_6_0",
  910. {"%2 = call i32 @dx.op.bufferUpdateCounter(i32 70, %dx.types.Handle %buf2_UAV_structbuf, i8 1)",
  911. "%3 = call i32 @dx.op.bufferUpdateCounter(i32 70, %dx.types.Handle %buf2_UAV_structbuf, i8 1)"
  912. },
  913. {"%2 = call i32 @dx.op.bufferUpdateCounter(i32 70, %dx.types.Handle %buf2_UAV_structbuf, i8 -1)",
  914. "%3 = call i32 @dx.op.bufferUpdateCounter(i32 70, %dx.types.Handle %buf2_UAV_structbuf, i8 1)\n"
  915. "%srvUpdate = call i32 @dx.op.bufferUpdateCounter(i32 70, %dx.types.Handle %buf1_texture_buf, i8 undef)"
  916. },
  917. {"BufferUpdateCounter valid only on UAV",
  918. "BufferUpdateCounter valid only on structured buffers",
  919. "inc of BufferUpdateCounter must be an immediate constant",
  920. "RWStructuredBuffers may increment or decrement their counters, but not both"});
  921. }
  922. TEST_F(ValidationTest, LocalResCopy) {
  923. RewriteAssemblyCheckMsg(
  924. L"..\\CodeGenHLSL\\resCopy.hlsl", "cs_6_0", {"ret void"},
  925. {"%H = alloca %dx.types.ResRet.i32\n"
  926. "ret void"},
  927. {"Dxil struct types should only used by ExtractValue"});
  928. }
  929. TEST_F(ValidationTest, WhenIncorrectModelThenFail) {
  930. TestCheck(L"val-failures.hlsl");
  931. }
  932. TEST_F(ValidationTest, WhenIncorrectPSThenFail) {
  933. TestCheck(L"val-failures-ps.hlsl");
  934. }
  935. TEST_F(ValidationTest, WhenSmUnknownThenFail) {
  936. RewriteAssemblyCheckMsg("float4 main() : SV_Target { return 1; }", "ps_6_0",
  937. {"{!\"ps\", i32 6, i32 0}"},
  938. {"{!\"ps\", i32 1, i32 2}"},
  939. "Unknown shader model 'ps_1_2'");
  940. }
  941. TEST_F(ValidationTest, WhenSmLegacyThenFail) {
  942. RewriteAssemblyCheckMsg("float4 main() : SV_Target { return 1; }", "ps_6_0",
  943. "{!\"ps\", i32 6, i32 0}", "{!\"ps\", i32 5, i32 1}",
  944. "Unknown shader model 'ps_5_1'");
  945. }
  946. TEST_F(ValidationTest, WhenMetaFlagsUsageDeclThenOK) {
  947. RewriteAssemblyCheckMsg(
  948. "uint u; float4 main() : SV_Target { uint64_t n = u; n *= u; return (uint)(n >> 32); }", "ps_6_0",
  949. "1048576", "1048577", // inhibit optimization, which should work fine
  950. nullptr);
  951. }
  952. TEST_F(ValidationTest, GsVertexIDOutOfBound) {
  953. RewriteAssemblyCheckMsg(
  954. L"..\\CodeGenHLSL\\SimpleGs1.hlsl", "gs_6_0",
  955. "dx.op.loadInput.f32(i32 4, i32 0, i32 0, i8 2, i32 0)",
  956. "dx.op.loadInput.f32(i32 4, i32 0, i32 0, i8 2, i32 1)",
  957. "expect VertexID between 0~1, got 1");
  958. }
  959. TEST_F(ValidationTest, StreamIDOutOfBound) {
  960. RewriteAssemblyCheckMsg(
  961. L"..\\CodeGenHLSL\\SimpleGs1.hlsl", "gs_6_0",
  962. "dx.op.emitStream(i32 97, i8 0)",
  963. "dx.op.emitStream(i32 97, i8 1)",
  964. "expect StreamID between 0 , got 1");
  965. }
  966. TEST_F(ValidationTest, SignatureStreamIDForNonGS) {
  967. RewriteAssemblyCheckMsg(
  968. L"..\\CodeGenHLSL\\abs1.hlsl", "ps_6_0",
  969. ", i8 0, i32 1, i8 4, i32 0, i8 0, null}",
  970. ", i8 0, i32 1, i8 4, i32 0, i8 0, !19}\n!19 = !{i32 0, i32 1}",
  971. "Stream index (1) must between 0 and 0");
  972. }
  973. TEST_F(ValidationTest, TypedUAVStoreFullMask0) {
  974. RewriteAssemblyCheckMsg(
  975. L"..\\CodeGenHLSL\\uav_typed_store.hlsl", "ps_6_0",
  976. "float 2.000000e+00, i8 15)",
  977. "float 2.000000e+00, i8 undef)",
  978. "Mask of TextureStore must be an immediate constant");
  979. }
  980. TEST_F(ValidationTest, TypedUAVStoreFullMask1) {
  981. RewriteAssemblyCheckMsg(
  982. L"..\\CodeGenHLSL\\uav_typed_store.hlsl", "ps_6_0",
  983. "float 3.000000e+00, i8 15)",
  984. "float 3.000000e+00, i8 undef)",
  985. "Mask of BufferStore must be an immediate constant");
  986. }
  987. TEST_F(ValidationTest, Recursive) {
  988. // Includes coverage for user-defined functions.
  989. TestCheck(L"..\\CodeGenHLSL\\recursive.ll");
  990. }
  991. TEST_F(ValidationTest, Recursive2) {
  992. TestCheck(L"..\\CodeGenHLSL\\recursive2.hlsl");
  993. }
  994. TEST_F(ValidationTest, Recursive3) {
  995. TestCheck(L"..\\CodeGenHLSL\\recursive3.hlsl");
  996. }
  997. TEST_F(ValidationTest, ResourceRangeOverlap0) {
  998. RewriteAssemblyCheckMsg(
  999. L"..\\CodeGenHLSL\\resource_overlap.hlsl", "ps_6_0",
  1000. "!\"B\", i32 0, i32 1",
  1001. "!\"B\", i32 0, i32 0",
  1002. "Resource B with base 0 size 1 overlap");
  1003. }
  1004. TEST_F(ValidationTest, ResourceRangeOverlap1) {
  1005. RewriteAssemblyCheckMsg(
  1006. L"..\\CodeGenHLSL\\resource_overlap.hlsl", "ps_6_0",
  1007. "!\"s1\", i32 0, i32 1",
  1008. "!\"s1\", i32 0, i32 0",
  1009. "Resource s1 with base 0 size 1 overlap");
  1010. }
  1011. TEST_F(ValidationTest, ResourceRangeOverlap2) {
  1012. RewriteAssemblyCheckMsg(
  1013. L"..\\CodeGenHLSL\\resource_overlap.hlsl", "ps_6_0",
  1014. "!\"uav2\", i32 0, i32 0",
  1015. "!\"uav2\", i32 0, i32 3",
  1016. "Resource uav2 with base 3 size 1 overlap");
  1017. }
  1018. TEST_F(ValidationTest, ResourceRangeOverlap3) {
  1019. RewriteAssemblyCheckMsg(
  1020. L"..\\CodeGenHLSL\\resource_overlap.hlsl", "ps_6_0",
  1021. "!\"srv2\", i32 0, i32 1",
  1022. "!\"srv2\", i32 0, i32 0",
  1023. "Resource srv2 with base 0 size 1 overlap");
  1024. }
  1025. TEST_F(ValidationTest, CBufferOverlap0) {
  1026. RewriteAssemblyCheckMsg(
  1027. L"..\\CodeGenHLSL\\cbufferOffset.hlsl", "ps_6_0",
  1028. "i32 6, !\"g2\", i32 3, i32 0",
  1029. "i32 6, !\"g2\", i32 3, i32 8",
  1030. "CBuffer Foo1 has offset overlaps at 16");
  1031. }
  1032. TEST_F(ValidationTest, CBufferOverlap1) {
  1033. RewriteAssemblyCheckMsg(
  1034. L"..\\CodeGenHLSL\\cbufferOffset.hlsl", "ps_6_0",
  1035. " = !{i32 32, !",
  1036. " = !{i32 16, !",
  1037. "CBuffer Foo1 size insufficient for element at offset 16");
  1038. }
  1039. TEST_F(ValidationTest, ControlFlowHint) {
  1040. RewriteAssemblyCheckMsg(
  1041. L"..\\CodeGenHLSL\\if1.hlsl", "ps_6_0",
  1042. "!\"dx.controlflow.hints\", i32 1",
  1043. "!\"dx.controlflow.hints\", i32 5",
  1044. "Attribute forcecase only works for switch");
  1045. }
  1046. TEST_F(ValidationTest, ControlFlowHint1) {
  1047. RewriteAssemblyCheckMsg(
  1048. L"..\\CodeGenHLSL\\if1.hlsl", "ps_6_0",
  1049. "!\"dx.controlflow.hints\", i32 1",
  1050. "!\"dx.controlflow.hints\", i32 1, i32 2",
  1051. "Can't use branch and flatten attributes together");
  1052. }
  1053. TEST_F(ValidationTest, ControlFlowHint2) {
  1054. RewriteAssemblyCheckMsg(
  1055. L"..\\CodeGenHLSL\\if1.hlsl", "ps_6_0",
  1056. "!\"dx.controlflow.hints\", i32 1",
  1057. "!\"dx.controlflow.hints\", i32 3",
  1058. "Invalid control flow hint");
  1059. }
  1060. TEST_F(ValidationTest, SemanticLength1) {
  1061. RewriteAssemblyCheckMsg(
  1062. L"..\\CodeGenHLSL\\binary1.hlsl", "ps_6_0",
  1063. "!\"C\"",
  1064. "!\"\"",
  1065. "Semantic length must be at least 1 and at most 64");
  1066. }
  1067. TEST_F(ValidationTest, SemanticLength64) {
  1068. RewriteAssemblyCheckMsg(
  1069. L"..\\CodeGenHLSL\\binary1.hlsl", "ps_6_0",
  1070. "!\"C\"",
  1071. "!\"CSESESESESESESESESESESESESESESESESESESESESESESESESESESESESESESESE\"",
  1072. "Semantic length must be at least 1 and at most 64");
  1073. }
  1074. TEST_F(ValidationTest, PullModelPosition) {
  1075. RewriteAssemblyCheckMsg(
  1076. L"..\\CodeGenHLSL\\eval.hlsl", "ps_6_0",
  1077. "!\"A\", i8 9, i8 0",
  1078. "!\"SV_Position\", i8 9, i8 3",
  1079. "does not support pull-model evaluation of position");
  1080. }
  1081. TEST_F(ValidationTest, StructBufGlobalCoherentAndCounter) {
  1082. RewriteAssemblyCheckMsg(
  1083. L"..\\CodeGenHLSL\\struct_buf1.hlsl", "ps_6_0",
  1084. "!\"buf2\", i32 0, i32 0, i32 1, i32 12, i1 false, i1 false",
  1085. "!\"buf2\", i32 0, i32 0, i32 1, i32 12, i1 true, i1 true",
  1086. "globallycoherent cannot be used with append/consume buffers'buf2'");
  1087. }
  1088. TEST_F(ValidationTest, StructBufStrideAlign) {
  1089. RewriteAssemblyCheckMsg(
  1090. L"..\\CodeGenHLSL\\struct_buf1.hlsl", "ps_6_0",
  1091. "= !{i32 1, i32 52}",
  1092. "= !{i32 1, i32 50}",
  1093. "structured buffer element size must be a multiple of 4 bytes (actual size 50 bytes)");
  1094. }
  1095. TEST_F(ValidationTest, StructBufStrideOutOfBound) {
  1096. RewriteAssemblyCheckMsg(
  1097. L"..\\CodeGenHLSL\\struct_buf1.hlsl", "ps_6_0",
  1098. "= !{i32 1, i32 52}",
  1099. "= !{i32 1, i32 2052}",
  1100. "structured buffer elements cannot be larger than 2048 bytes (actual size 2052 bytes)");
  1101. }
  1102. TEST_F(ValidationTest, StructBufLoadCoordinates) {
  1103. RewriteAssemblyCheckMsg(
  1104. L"..\\CodeGenHLSL\\struct_buf1.hlsl", "ps_6_0",
  1105. "bufferLoad.f32(i32 68, %dx.types.Handle %buf1_texture_structbuf, i32 1, i32 8)",
  1106. "bufferLoad.f32(i32 68, %dx.types.Handle %buf1_texture_structbuf, i32 1, i32 undef)",
  1107. "structured buffer require 2 coordinates");
  1108. }
  1109. TEST_F(ValidationTest, StructBufStoreCoordinates) {
  1110. RewriteAssemblyCheckMsg(
  1111. L"..\\CodeGenHLSL\\struct_buf1.hlsl", "ps_6_0",
  1112. "bufferStore.f32(i32 69, %dx.types.Handle %buf2_UAV_structbuf, i32 0, i32 0",
  1113. "bufferStore.f32(i32 69, %dx.types.Handle %buf2_UAV_structbuf, i32 0, i32 undef",
  1114. "structured buffer require 2 coordinates");
  1115. }
  1116. TEST_F(ValidationTest, TypedBufRetType) {
  1117. RewriteAssemblyCheckMsg(
  1118. L"..\\CodeGenHLSL\\sample5.hlsl", "ps_6_0",
  1119. "%class.Texture2D = type { <4 x float>",
  1120. "%class.Texture2D = type { <4 x double>",
  1121. "elements of typed buffers and textures must fit in four 32-bit quantities");
  1122. }
  1123. TEST_F(ValidationTest, VsInputSemantic) {
  1124. RewriteAssemblyCheckMsg(
  1125. L"..\\CodeGenHLSL\\clip_planes.hlsl", "vs_6_0",
  1126. "!\"POSITION\", i8 9, i8 0",
  1127. "!\"SV_Target\", i8 9, i8 16",
  1128. "Semantic 'SV_Target' is invalid as vs Input");
  1129. }
  1130. TEST_F(ValidationTest, VsOutputSemantic) {
  1131. RewriteAssemblyCheckMsg(
  1132. L"..\\CodeGenHLSL\\clip_planes.hlsl", "vs_6_0",
  1133. "!\"NORMAL\", i8 9, i8 0",
  1134. "!\"SV_Target\", i8 9, i8 16",
  1135. "Semantic 'SV_Target' is invalid as vs Output");
  1136. }
  1137. TEST_F(ValidationTest, HsInputSemantic) {
  1138. RewriteAssemblyCheckMsg(
  1139. L"..\\CodeGenHLSL\\SimpleHs1.hlsl", "hs_6_0",
  1140. "!\"TEXCOORD\", i8 9, i8 0",
  1141. "!\"VertexID\", i8 4, i8 1",
  1142. "Semantic 'VertexID' is invalid as hs Input");
  1143. }
  1144. TEST_F(ValidationTest, HsOutputSemantic) {
  1145. RewriteAssemblyCheckMsg(
  1146. L"..\\CodeGenHLSL\\SimpleHs1.hlsl", "hs_6_0",
  1147. "!\"TEXCOORD\", i8 9, i8 0",
  1148. "!\"VertexID\", i8 4, i8 1",
  1149. "Semantic 'VertexID' is invalid as hs Output");
  1150. }
  1151. TEST_F(ValidationTest, PatchConstSemantic) {
  1152. RewriteAssemblyCheckMsg(
  1153. L"..\\CodeGenHLSL\\SimpleHs1.hlsl", "hs_6_0",
  1154. "!\"SV_TessFactor\", i8 9, i8 25",
  1155. "!\"VertexID\", i8 4, i8 1",
  1156. "Semantic 'VertexID' is invalid as hs PatchConstant");
  1157. }
  1158. TEST_F(ValidationTest, DsInputSemantic) {
  1159. RewriteAssemblyCheckMsg(
  1160. L"..\\CodeGenHLSL\\SimpleDs1.hlsl", "ds_6_0",
  1161. "!\"TEXCOORD\", i8 9, i8 0",
  1162. "!\"VertexID\", i8 4, i8 1",
  1163. "Semantic 'VertexID' is invalid as ds Input");
  1164. }
  1165. TEST_F(ValidationTest, DsOutputSemantic) {
  1166. RewriteAssemblyCheckMsg(
  1167. L"..\\CodeGenHLSL\\SimpleDs1.hlsl", "ds_6_0",
  1168. "!\"TEXCOORD\", i8 9, i8 0",
  1169. "!\"VertexID\", i8 4, i8 1",
  1170. "Semantic 'VertexID' is invalid as ds Output");
  1171. }
  1172. TEST_F(ValidationTest, GsInputSemantic) {
  1173. RewriteAssemblyCheckMsg(
  1174. L"..\\CodeGenHLSL\\SimpleGs1.hlsl", "gs_6_0",
  1175. "!\"POSSIZE\", i8 9, i8 0",
  1176. "!\"VertexID\", i8 4, i8 1",
  1177. "Semantic 'VertexID' is invalid as gs Input");
  1178. }
  1179. TEST_F(ValidationTest, GsOutputSemantic) {
  1180. RewriteAssemblyCheckMsg(
  1181. L"..\\CodeGenHLSL\\SimpleGs1.hlsl", "gs_6_0",
  1182. "!\"TEXCOORD\", i8 9, i8 0",
  1183. "!\"VertexID\", i8 4, i8 1",
  1184. "Semantic 'VertexID' is invalid as gs Output");
  1185. }
  1186. TEST_F(ValidationTest, PsInputSemantic) {
  1187. RewriteAssemblyCheckMsg(
  1188. L"..\\CodeGenHLSL\\abs2.hlsl", "ps_6_0",
  1189. "!\"A\", i8 4, i8 0",
  1190. "!\"VertexID\", i8 4, i8 1",
  1191. "Semantic 'VertexID' is invalid as ps Input");
  1192. }
  1193. TEST_F(ValidationTest, PsOutputSemantic) {
  1194. RewriteAssemblyCheckMsg(
  1195. L"..\\CodeGenHLSL\\abs2.hlsl", "ps_6_0",
  1196. "!\"SV_Target\", i8 9, i8 16",
  1197. "!\"VertexID\", i8 4, i8 1",
  1198. "Semantic 'VertexID' is invalid as ps Output");
  1199. }
  1200. TEST_F(ValidationTest, ArrayOfSVTarget) {
  1201. RewriteAssemblyCheckMsg(
  1202. L"..\\CodeGenHLSL\\targetArray.hlsl", "ps_6_0",
  1203. "i32 6, !\"SV_Target\", i8 9, i8 16, !([0-9]+), i8 0, i32 1",
  1204. "i32 6, !\"SV_Target\", i8 9, i8 16, !\\1, i8 0, i32 2",
  1205. "Pixel shader output registers are not indexable.",
  1206. /*bRegex*/true);
  1207. }
  1208. TEST_F(ValidationTest, InfiniteLog) {
  1209. RewriteAssemblyCheckMsg(
  1210. L"..\\CodeGenHLSL\\intrinsic_val_imm.hlsl", "ps_6_0",
  1211. "op.unary.f32\\(i32 23, float %[0-9+]\\)",
  1212. "op.unary.f32(i32 23, float 0x7FF0000000000000)",
  1213. "No indefinite logarithm",
  1214. /*bRegex*/true);
  1215. }
  1216. TEST_F(ValidationTest, InfiniteAsin) {
  1217. RewriteAssemblyCheckMsg(
  1218. L"..\\CodeGenHLSL\\intrinsic_val_imm.hlsl", "ps_6_0",
  1219. "op.unary.f32\\(i32 16, float %[0-9]+\\)",
  1220. "op.unary.f32(i32 16, float 0x7FF0000000000000)",
  1221. "No indefinite arcsine",
  1222. /*bRegex*/true);
  1223. }
  1224. TEST_F(ValidationTest, InfiniteAcos) {
  1225. RewriteAssemblyCheckMsg(
  1226. L"..\\CodeGenHLSL\\intrinsic_val_imm.hlsl", "ps_6_0",
  1227. "op.unary.f32\\(i32 15, float %[0-9]+\\)",
  1228. "op.unary.f32(i32 15, float 0x7FF0000000000000)",
  1229. "No indefinite arccosine",
  1230. /*bRegex*/true);
  1231. }
  1232. TEST_F(ValidationTest, InfiniteDdxDdy) {
  1233. RewriteAssemblyCheckMsg(
  1234. L"..\\CodeGenHLSL\\intrinsic_val_imm.hlsl", "ps_6_0",
  1235. "op.unary.f32\\(i32 85, float %[0-9]+\\)",
  1236. "op.unary.f32(i32 85, float 0x7FF0000000000000)",
  1237. "No indefinite derivative calculation",
  1238. /*bRegex*/true);
  1239. }
  1240. TEST_F(ValidationTest, IDivByZero) {
  1241. RewriteAssemblyCheckMsg(
  1242. L"..\\CodeGenHLSL\\intrinsic_val_imm.hlsl", "ps_6_0",
  1243. "sdiv i32 %([0-9]+), %[0-9]+",
  1244. "sdiv i32 %\\1, 0",
  1245. "No signed integer division by zero",
  1246. /*bRegex*/true);
  1247. }
  1248. TEST_F(ValidationTest, UDivByZero) {
  1249. RewriteAssemblyCheckMsg(
  1250. L"..\\CodeGenHLSL\\intrinsic_val_imm.hlsl", "ps_6_0",
  1251. "udiv i32 %([0-9]+), %[0-9]+",
  1252. "udiv i32 %\\1, 0",
  1253. "No unsigned integer division by zero",
  1254. /*bRegex*/true);
  1255. }
  1256. TEST_F(ValidationTest, UnusedMetadata) {
  1257. RewriteAssemblyCheckMsg(L"..\\CodeGenHLSL\\loop2.hlsl", "ps_6_0",
  1258. ", !llvm.loop ",
  1259. ", !llvm.loop2 ",
  1260. "All metadata must be used by dxil");
  1261. }
  1262. TEST_F(ValidationTest, MemoryOutOfBound) {
  1263. RewriteAssemblyCheckMsg(L"..\\CodeGenHLSL\\targetArray.hlsl", "ps_6_0",
  1264. "getelementptr [4 x float], [4 x float]* %7, i32 0, i32 3",
  1265. "getelementptr [4 x float], [4 x float]* %7, i32 0, i32 10",
  1266. "Access to out-of-bounds memory is disallowed");
  1267. }
  1268. TEST_F(ValidationTest, LocalRes2) {
  1269. TestCheck(L"..\\CodeGenHLSL\\local_resource2.hlsl");
  1270. }
  1271. TEST_F(ValidationTest, LocalRes3) {
  1272. TestCheck(L"..\\CodeGenHLSL\\local_resource3.hlsl");
  1273. }
  1274. TEST_F(ValidationTest, LocalRes5) {
  1275. TestCheck(L"..\\CodeGenHLSL\\local_resource5.hlsl");
  1276. }
  1277. TEST_F(ValidationTest, LocalRes5Dbg) {
  1278. TestCheck(L"..\\CodeGenHLSL\\local_resource5_dbg.hlsl");
  1279. }
  1280. TEST_F(ValidationTest, LocalRes6) {
  1281. TestCheck(L"..\\CodeGenHLSL\\local_resource6.hlsl");
  1282. }
  1283. TEST_F(ValidationTest, LocalRes6Dbg) {
  1284. TestCheck(L"..\\CodeGenHLSL\\local_resource6_dbg.hlsl");
  1285. }
  1286. TEST_F(ValidationTest, AddrSpaceCast) {
  1287. RewriteAssemblyCheckMsg(L"..\\CodeGenHLSL\\staticGlobals.hlsl", "ps_6_0",
  1288. "%([0-9]+) = getelementptr \\[4 x i32\\], \\[4 x i32\\]\\* %([0-9]+), i32 0, i32 0\n"
  1289. " store i32 %([0-9]+), i32\\* %\\1, align 4",
  1290. "%\\1 = getelementptr [4 x i32], [4 x i32]* %\\2, i32 0, i32 0\n"
  1291. " %X = addrspacecast i32* %\\1 to i32 addrspace(1)* \n"
  1292. " store i32 %\\3, i32 addrspace(1)* %X, align 4",
  1293. "generic address space",
  1294. /*bRegex*/true);
  1295. }
  1296. TEST_F(ValidationTest, PtrBitCast) {
  1297. RewriteAssemblyCheckMsg(L"..\\CodeGenHLSL\\staticGlobals.hlsl", "ps_6_0",
  1298. "%([0-9]+) = getelementptr \\[4 x i32\\], \\[4 x i32\\]\\* %([0-9]+), i32 0, i32 0\n"
  1299. " store i32 %([0-9]+), i32\\* %\\1, align 4",
  1300. "%\\1 = getelementptr [4 x i32], [4 x i32]* %\\2, i32 0, i32 0\n"
  1301. " %X = bitcast i32* %\\1 to double* \n"
  1302. " store i32 %\\3, i32* %\\1, align 4",
  1303. "Pointer type bitcast must be have same size",
  1304. /*bRegex*/true);
  1305. }
  1306. TEST_F(ValidationTest, MinPrecisionBitCast) {
  1307. RewriteAssemblyCheckMsg(L"..\\CodeGenHLSL\\staticGlobals.hlsl", "ps_6_0",
  1308. "%([0-9]+) = getelementptr \\[4 x i32\\], \\[4 x i32\\]\\* %([0-9]+), i32 0, i32 0\n"
  1309. " store i32 %([0-9]+), i32\\* %\\1, align 4",
  1310. "%\\1 = getelementptr [4 x i32], [4 x i32]* %\\2, i32 0, i32 0\n"
  1311. " %X = bitcast i32* %\\1 to [2 x half]* \n"
  1312. " store i32 %\\3, i32* %\\1, align 4",
  1313. "Bitcast on minprecison types is not allowed",
  1314. /*bRegex*/true);
  1315. }
  1316. TEST_F(ValidationTest, StructBitCast) {
  1317. RewriteAssemblyCheckMsg(L"..\\CodeGenHLSL\\staticGlobals.hlsl", "ps_6_0",
  1318. "%([0-9]+) = getelementptr \\[4 x i32\\], \\[4 x i32\\]\\* %([0-9]+), i32 0, i32 0\n"
  1319. " store i32 %([0-9]+), i32\\* %\\1, align 4",
  1320. "%\\1 = getelementptr [4 x i32], [4 x i32]* %\\2, i32 0, i32 0\n"
  1321. " %X = bitcast i32* %\\1 to %dx.types.Handle* \n"
  1322. " store i32 %\\3, i32* %\\1, align 4",
  1323. "Bitcast on struct types is not allowed",
  1324. /*bRegex*/true);
  1325. }
  1326. TEST_F(ValidationTest, MultiDimArray) {
  1327. RewriteAssemblyCheckMsg(L"..\\CodeGenHLSL\\staticGlobals.hlsl", "ps_6_0",
  1328. "= alloca [4 x i32]",
  1329. "= alloca [4 x i32]\n"
  1330. " %md = alloca [2 x [4 x float]]",
  1331. "Only one dimension allowed for array type");
  1332. }
  1333. TEST_F(ValidationTest, SimpleGs8) {
  1334. TestCheck(L"..\\CodeGenHLSL\\SimpleGS8.hlsl");
  1335. }
  1336. TEST_F(ValidationTest, SimpleGs9) {
  1337. TestCheck(L"..\\CodeGenHLSL\\SimpleGS9.hlsl");
  1338. }
  1339. TEST_F(ValidationTest, SimpleGs10) {
  1340. TestCheck(L"..\\CodeGenHLSL\\SimpleGS10.hlsl");
  1341. }
  1342. TEST_F(ValidationTest, IllegalSampleOffset3) {
  1343. TestCheck(L"..\\CodeGenHLSL\\optForNoOpt3.hlsl");
  1344. }
  1345. TEST_F(ValidationTest, IllegalSampleOffset4) {
  1346. TestCheck(L"..\\CodeGenHLSL\\optForNoOpt4.hlsl");
  1347. }
  1348. TEST_F(ValidationTest, NoFunctionParam) {
  1349. RewriteAssemblyCheckMsg(L"..\\CodeGenHLSL\\abs2.hlsl", "ps_6_0",
  1350. {"define void @main\\(\\)", "void \\(\\)\\* @main, !([0-9]+)\\}(.*)!\\1 = !\\{!([0-9]+)\\}", "void \\(\\)\\* @main"},
  1351. {"define void @main(<4 x i32> %mainArg)", "void (<4 x i32>)* @main, !\\1}\\2!\\1 = !{!\\3, !\\3}", "void (<4 x i32>)* @main"},
  1352. "with parameter is not permitted",
  1353. /*bRegex*/true);
  1354. }
  1355. TEST_F(ValidationTest, I8Type) {
  1356. RewriteAssemblyCheckMsg(L"..\\CodeGenHLSL\\staticGlobals.hlsl", "ps_6_0",
  1357. "%([0-9]+) = alloca \\[4 x i32\\]",
  1358. "%\\1 = alloca [4 x i32]\n"
  1359. " %m8 = alloca i8",
  1360. "I8 can only used as immediate value for intrinsic",
  1361. /*bRegex*/true);
  1362. }
  1363. TEST_F(ValidationTest, EmptyStructInBuffer) {
  1364. TestCheck(L"..\\CodeGenHLSL\\EmptyStructInBuffer.hlsl");
  1365. }
  1366. TEST_F(ValidationTest, BigStructInBuffer) {
  1367. TestCheck(L"..\\CodeGenHLSL\\BigStructInBuffer.hlsl");
  1368. }
  1369. TEST_F(ValidationTest, GloballyCoherent2) {
  1370. TestCheck(L"..\\CodeGenHLSL\\globallycoherent2.hlsl");
  1371. }
  1372. TEST_F(ValidationTest, GloballyCoherent3) {
  1373. TestCheck(L"..\\CodeGenHLSL\\globallycoherent3.hlsl");
  1374. }
  1375. // TODO: enable this.
  1376. //TEST_F(ValidationTest, TGSMRaceCond) {
  1377. // TestCheck(L"..\\CodeGenHLSL\\RaceCond.hlsl");
  1378. //}
  1379. //
  1380. //TEST_F(ValidationTest, TGSMRaceCond2) {
  1381. // RewriteAssemblyCheckMsg(L"..\\CodeGenHLSL\\structInBuffer.hlsl", "cs_6_0",
  1382. // "ret void",
  1383. // "%TID = call i32 @dx.op.flattenedThreadIdInGroup.i32(i32 96)\n"
  1384. // "store i32 %TID, i32 addrspace(3)* @\"\\01?sharedData@@3UFoo@@A.3\", align 4\n"
  1385. // "ret void",
  1386. // "Race condition writing to shared memory detected, consider making this write conditional");
  1387. //}
  1388. TEST_F(ValidationTest, AddUint64Odd) {
  1389. TestCheck(L"..\\CodeGenHLSL\\AddUint64Odd.hlsl");
  1390. }
  1391. TEST_F(ValidationTest, WhenWaveAffectsGradientThenFail) {
  1392. TestCheck(L"val-wave-failures-ps.hlsl");
  1393. }
  1394. TEST_F(ValidationTest, WhenMetaFlagsUsageThenFail) {
  1395. RewriteAssemblyCheckMsg(
  1396. "uint u; float4 main() : SV_Target { uint64_t n = u; n *= u; return (uint)(n >> 32); }", "ps_6_0",
  1397. "1048576", "0", // remove the int64 flag
  1398. "Flags must match usage");
  1399. }
  1400. TEST_F(ValidationTest, StorePatchControlNotInPatchConstantFunction) {
  1401. RewriteAssemblyCheckMsg(
  1402. "struct PSSceneIn \
  1403. { \
  1404. float4 pos : SV_Position; \
  1405. float2 tex : TEXCOORD0; \
  1406. float3 norm : NORMAL; \
  1407. }; \
  1408. \
  1409. struct HSPerVertexData \
  1410. { \
  1411. PSSceneIn v; \
  1412. }; \
  1413. struct HSPerPatchData \
  1414. { \
  1415. float edges[ 3 ] : SV_TessFactor; \
  1416. float inside : SV_InsideTessFactor; \
  1417. }; \
  1418. HSPerPatchData HSPerPatchFunc( const InputPatch< PSSceneIn, 3 > points, \
  1419. OutputPatch<HSPerVertexData, 3> outpoints) \
  1420. { \
  1421. HSPerPatchData d; \
  1422. \
  1423. d.edges[ 0 ] = points[0].tex.x + outpoints[0].v.tex.x; \
  1424. d.edges[ 1 ] = 1; \
  1425. d.edges[ 2 ] = 1; \
  1426. d.inside = 1; \
  1427. \
  1428. return d; \
  1429. }\
  1430. [domain(\"tri\")]\
  1431. [partitioning(\"fractional_odd\")]\
  1432. [outputtopology(\"triangle_cw\")]\
  1433. [patchconstantfunc(\"HSPerPatchFunc\")]\
  1434. [outputcontrolpoints(3)]\
  1435. HSPerVertexData main( const uint id : SV_OutputControlPointID,\
  1436. const InputPatch< PSSceneIn, 3 > points )\
  1437. {\
  1438. HSPerVertexData v;\
  1439. \
  1440. v.v = points[ id ];\
  1441. \
  1442. return v;\
  1443. }\
  1444. ",
  1445. "hs_6_0",
  1446. "dx.op.storeOutput.f32(i32 5",
  1447. "dx.op.storePatchConstant.f32(i32 106",
  1448. "opcode 'StorePatchConstant' should only used in 'PatchConstant function'");
  1449. }
  1450. TEST_F(ValidationTest, LoadOutputControlPointNotInPatchConstantFunction) {
  1451. RewriteAssemblyCheckMsg(
  1452. "struct PSSceneIn \
  1453. { \
  1454. float4 pos : SV_Position; \
  1455. float2 tex : TEXCOORD0; \
  1456. float3 norm : NORMAL; \
  1457. }; \
  1458. \
  1459. struct HSPerVertexData \
  1460. { \
  1461. PSSceneIn v; \
  1462. }; \
  1463. struct HSPerPatchData \
  1464. { \
  1465. float edges[ 3 ] : SV_TessFactor; \
  1466. float inside : SV_InsideTessFactor; \
  1467. }; \
  1468. HSPerPatchData HSPerPatchFunc( const InputPatch< PSSceneIn, 3 > points, \
  1469. OutputPatch<HSPerVertexData, 3> outpoints) \
  1470. { \
  1471. HSPerPatchData d; \
  1472. \
  1473. d.edges[ 0 ] = points[0].tex.x + outpoints[0].v.tex.x; \
  1474. d.edges[ 1 ] = 1; \
  1475. d.edges[ 2 ] = 1; \
  1476. d.inside = 1; \
  1477. \
  1478. return d; \
  1479. }\
  1480. [domain(\"tri\")]\
  1481. [partitioning(\"fractional_odd\")]\
  1482. [outputtopology(\"triangle_cw\")]\
  1483. [patchconstantfunc(\"HSPerPatchFunc\")]\
  1484. [outputcontrolpoints(3)]\
  1485. HSPerVertexData main( const uint id : SV_OutputControlPointID,\
  1486. const InputPatch< PSSceneIn, 3 > points )\
  1487. {\
  1488. HSPerVertexData v;\
  1489. \
  1490. v.v = points[ id ];\
  1491. \
  1492. return v;\
  1493. }\
  1494. ",
  1495. "hs_6_0",
  1496. "dx.op.loadInput.f32(i32 4",
  1497. "dx.op.loadOutputControlPoint.f32(i32 103",
  1498. "opcode 'LoadOutputControlPoint' should only used in 'PatchConstant function'");
  1499. }
  1500. TEST_F(ValidationTest, OutputControlPointIDInPatchConstantFunction) {
  1501. RewriteAssemblyCheckMsg(
  1502. "struct PSSceneIn \
  1503. { \
  1504. float4 pos : SV_Position; \
  1505. float2 tex : TEXCOORD0; \
  1506. float3 norm : NORMAL; \
  1507. }; \
  1508. \
  1509. struct HSPerVertexData \
  1510. { \
  1511. PSSceneIn v; \
  1512. }; \
  1513. struct HSPerPatchData \
  1514. { \
  1515. float edges[ 3 ] : SV_TessFactor; \
  1516. float inside : SV_InsideTessFactor; \
  1517. }; \
  1518. HSPerPatchData HSPerPatchFunc( const InputPatch< PSSceneIn, 3 > points, \
  1519. OutputPatch<HSPerVertexData, 3> outpoints) \
  1520. { \
  1521. HSPerPatchData d; \
  1522. \
  1523. d.edges[ 0 ] = points[0].tex.x + outpoints[0].v.tex.x; \
  1524. d.edges[ 1 ] = 1; \
  1525. d.edges[ 2 ] = 1; \
  1526. d.inside = 1; \
  1527. \
  1528. return d; \
  1529. }\
  1530. [domain(\"tri\")]\
  1531. [partitioning(\"fractional_odd\")]\
  1532. [outputtopology(\"triangle_cw\")]\
  1533. [patchconstantfunc(\"HSPerPatchFunc\")]\
  1534. [outputcontrolpoints(3)]\
  1535. HSPerVertexData main( const uint id : SV_OutputControlPointID,\
  1536. const InputPatch< PSSceneIn, 3 > points )\
  1537. {\
  1538. HSPerVertexData v;\
  1539. \
  1540. v.v = points[ id ];\
  1541. \
  1542. return v;\
  1543. }\
  1544. ",
  1545. "hs_6_0",
  1546. "ret void",
  1547. "call i32 @dx.op.outputControlPointID.i32(i32 107)\n ret void",
  1548. "opcode 'OutputControlPointID' should only used in 'hull function'");
  1549. }
  1550. TEST_F(ValidationTest, ClipCullMaxComponents) {
  1551. RewriteAssemblyCheckMsg(" \
  1552. struct VSOut { \
  1553. float3 clip0 : SV_ClipDistance; \
  1554. float3 clip1 : SV_ClipDistance1; \
  1555. float cull0 : SV_CullDistance; \
  1556. float cull1 : SV_CullDistance1; \
  1557. float cull2 : CullDistance2; \
  1558. }; \
  1559. VSOut main() { \
  1560. VSOut Out; \
  1561. Out.clip0 = 0.1; \
  1562. Out.clip1 = 0.2; \
  1563. Out.cull0 = 0.3; \
  1564. Out.cull1 = 0.4; \
  1565. Out.cull2 = 0.5; \
  1566. return Out; \
  1567. } \
  1568. ",
  1569. "vs_6_0",
  1570. "!{i32 4, !\"CullDistance\", i8 9, i8 0,",
  1571. "!{i32 4, !\"SV_CullDistance\", i8 9, i8 7,",
  1572. "ClipDistance and CullDistance use more than the maximum of 8 components combined.");
  1573. }
  1574. TEST_F(ValidationTest, ClipCullMaxRows) {
  1575. RewriteAssemblyCheckMsg(" \
  1576. struct VSOut { \
  1577. float3 clip0 : SV_ClipDistance; \
  1578. float3 clip1 : SV_ClipDistance1; \
  1579. float2 cull0 : CullDistance; \
  1580. }; \
  1581. VSOut main() { \
  1582. VSOut Out; \
  1583. Out.clip0 = 0.1; \
  1584. Out.clip1 = 0.2; \
  1585. Out.cull0 = 0.3; \
  1586. return Out; \
  1587. } \
  1588. ",
  1589. "vs_6_0",
  1590. "!{i32 2, !\"CullDistance\", i8 9, i8 0,",
  1591. "!{i32 2, !\"SV_CullDistance\", i8 9, i8 7,",
  1592. "ClipDistance and CullDistance occupy more than the maximum of 2 rows combined.");
  1593. }
  1594. TEST_F(ValidationTest, DuplicateSysValue) {
  1595. RewriteAssemblyCheckMsg(" \
  1596. float4 main(uint vid : SV_VertexID, uint iid : SV_InstanceID) : SV_Position { \
  1597. return (float4)0 + vid + iid; \
  1598. } \
  1599. ",
  1600. "vs_6_0",
  1601. "!{i32 1, !\"SV_InstanceID\", i8 5, i8 2,",
  1602. "!{i32 1, !\"\", i8 5, i8 1,",
  1603. //"System value SV_VertexID appears more than once in the same signature.");
  1604. "Semantic 'SV_VertexID' overlap at 0");
  1605. }
  1606. TEST_F(ValidationTest, SemTargetMax) {
  1607. RewriteAssemblyCheckMsg(" \
  1608. float4 main(float4 col : COLOR) : SV_Target7 { return col; } \
  1609. ",
  1610. "ps_6_0",
  1611. "!{i32 0, !\"SV_Target\", i8 9, i8 16, ![0-9]+, i8 0, i32 1, i8 4, i32 7, i8 0, null}",
  1612. "!{i32 0, !\"SV_Target\", i8 9, i8 16, !101, i8 0, i32 1, i8 4, i32 8, i8 0, null}\n!101 = !{i32 8}",
  1613. "SV_Target semantic index exceeds maximum \\(7\\)",
  1614. /*bRegex*/true);
  1615. }
  1616. TEST_F(ValidationTest, SemTargetIndexMatchesRow) {
  1617. RewriteAssemblyCheckMsg(" \
  1618. float4 main(float4 col : COLOR) : SV_Target7 { return col; } \
  1619. ",
  1620. "ps_6_0",
  1621. "!{i32 0, !\"SV_Target\", i8 9, i8 16, !([0-9]+), i8 0, i32 1, i8 4, i32 7, i8 0, null}",
  1622. "!{i32 0, !\"SV_Target\", i8 9, i8 16, !\\1, i8 0, i32 1, i8 4, i32 6, i8 0, null}",
  1623. "SV_Target semantic index must match packed row location",
  1624. /*bRegex*/true);
  1625. }
  1626. TEST_F(ValidationTest, SemTargetCol0) {
  1627. RewriteAssemblyCheckMsg(" \
  1628. float3 main(float4 col : COLOR) : SV_Target7 { return col.xyz; } \
  1629. ",
  1630. "ps_6_0",
  1631. "!{i32 0, !\"SV_Target\", i8 9, i8 16, !([0-9]+), i8 0, i32 1, i8 3, i32 7, i8 0, null}",
  1632. "!{i32 0, !\"SV_Target\", i8 9, i8 16, !\\1, i8 0, i32 1, i8 3, i32 7, i8 1, null}",
  1633. "SV_Target packed location must start at column 0",
  1634. /*bRegex*/true);
  1635. }
  1636. TEST_F(ValidationTest, SemIndexMax) {
  1637. RewriteAssemblyCheckMsg(" \
  1638. float4 main(uint vid : SV_VertexID, uint iid : SV_InstanceID) : SV_Position { \
  1639. return (float4)0 + vid + iid; \
  1640. } \
  1641. ",
  1642. "vs_6_0",
  1643. "!{i32 0, !\"SV_VertexID\", i8 5, i8 1, ![0-9]+, i8 0, i32 1, i8 1, i32 0, i8 0, null}",
  1644. "!{i32 0, !\"SV_VertexID\", i8 5, i8 1, !101, i8 0, i32 1, i8 1, i32 0, i8 0, null}\n!101 = !{i32 1}",
  1645. "SV_VertexID semantic index exceeds maximum \\(0\\)",
  1646. /*bRegex*/true);
  1647. }
  1648. TEST_F(ValidationTest, SemTessFactorIndexMax) {
  1649. RewriteAssemblyCheckMsg(" \
  1650. struct Vertex { \
  1651. float4 pos : SV_Position; \
  1652. }; \
  1653. struct PatchConstant { \
  1654. float edges[ 3 ] : SV_TessFactor; \
  1655. float inside : SV_InsideTessFactor; \
  1656. }; \
  1657. PatchConstant PCMain( InputPatch<Vertex, 3> patch) { \
  1658. PatchConstant PC; \
  1659. PC.edges = (float[3])patch[1].pos.xyz; \
  1660. PC.inside = patch[1].pos.w; \
  1661. return PC; \
  1662. } \
  1663. [domain(\"tri\")] \
  1664. [partitioning(\"fractional_odd\")] \
  1665. [outputtopology(\"triangle_cw\")] \
  1666. [patchconstantfunc(\"PCMain\")] \
  1667. [outputcontrolpoints(3)] \
  1668. Vertex main(uint id : SV_OutputControlPointID, InputPatch< Vertex, 3 > patch) { \
  1669. Vertex Out = patch[id]; \
  1670. Out.pos.w += 0.25; \
  1671. return Out; \
  1672. } \
  1673. ",
  1674. "hs_6_0",
  1675. "!{i32 0, !\"SV_TessFactor\", i8 9, i8 25, ![0-9]+, i8 0, i32 3, i8 1, i32 0, i8 3, null}",
  1676. "!{i32 0, !\"SV_TessFactor\", i8 9, i8 25, !101, i8 0, i32 2, i8 1, i32 0, i8 3, null}\n!101 = !{i32 0, i32 1}",
  1677. "TessFactor rows, columns \\(2, 1\\) invalid for domain Tri. Expected 3 rows and 1 column.",
  1678. /*bRegex*/true);
  1679. }
  1680. TEST_F(ValidationTest, SemInsideTessFactorIndexMax) {
  1681. RewriteAssemblyCheckMsg(" \
  1682. struct Vertex { \
  1683. float4 pos : SV_Position; \
  1684. }; \
  1685. struct PatchConstant { \
  1686. float edges[ 3 ] : SV_TessFactor; \
  1687. float inside : SV_InsideTessFactor; \
  1688. }; \
  1689. PatchConstant PCMain( InputPatch<Vertex, 3> patch) { \
  1690. PatchConstant PC; \
  1691. PC.edges = (float[3])patch[1].pos.xyz; \
  1692. PC.inside = patch[1].pos.w; \
  1693. return PC; \
  1694. } \
  1695. [domain(\"tri\")] \
  1696. [partitioning(\"fractional_odd\")] \
  1697. [outputtopology(\"triangle_cw\")] \
  1698. [patchconstantfunc(\"PCMain\")] \
  1699. [outputcontrolpoints(3)] \
  1700. Vertex main(uint id : SV_OutputControlPointID, InputPatch< Vertex, 3 > patch) { \
  1701. Vertex Out = patch[id]; \
  1702. Out.pos.w += 0.25; \
  1703. return Out; \
  1704. } \
  1705. ",
  1706. "hs_6_0",
  1707. "!{i32 1, !\"SV_InsideTessFactor\", i8 9, i8 26, !([0-9]+), i8 0, i32 1, i8 1, i32 3, i8 0, null}",
  1708. "!{i32 1, !\"SV_InsideTessFactor\", i8 9, i8 26, !\\1, i8 0, i32 2, i8 1, i32 3, i8 0, null}",
  1709. "InsideTessFactor rows, columns \\(2, 1\\) invalid for domain Tri. Expected 1 rows and 1 column.",
  1710. /*bRegex*/true);
  1711. }
  1712. TEST_F(ValidationTest, SemShouldBeAllocated) {
  1713. RewriteAssemblyCheckMsg(" \
  1714. struct Vertex { \
  1715. float4 pos : SV_Position; \
  1716. }; \
  1717. struct PatchConstant { \
  1718. float edges[ 3 ] : SV_TessFactor; \
  1719. float inside : SV_InsideTessFactor; \
  1720. }; \
  1721. PatchConstant PCMain( InputPatch<Vertex, 3> patch) { \
  1722. PatchConstant PC; \
  1723. PC.edges = (float[3])patch[1].pos.xyz; \
  1724. PC.inside = patch[1].pos.w; \
  1725. return PC; \
  1726. } \
  1727. [domain(\"tri\")] \
  1728. [partitioning(\"fractional_odd\")] \
  1729. [outputtopology(\"triangle_cw\")] \
  1730. [patchconstantfunc(\"PCMain\")] \
  1731. [outputcontrolpoints(3)] \
  1732. Vertex main(uint id : SV_OutputControlPointID, InputPatch< Vertex, 3 > patch) { \
  1733. Vertex Out = patch[id]; \
  1734. Out.pos.w += 0.25; \
  1735. return Out; \
  1736. } \
  1737. ",
  1738. "hs_6_0",
  1739. "!{i32 0, !\"SV_TessFactor\", i8 9, i8 25, !([0-9]+), i8 0, i32 3, i8 1, i32 0, i8 3, null}",
  1740. "!{i32 0, !\"SV_TessFactor\", i8 9, i8 25, !\\1, i8 0, i32 3, i8 1, i32 -1, i8 -1, null}",
  1741. "PatchConstant Semantic 'SV_TessFactor' should have a valid packing location",
  1742. /*bRegex*/true);
  1743. }
  1744. TEST_F(ValidationTest, SemShouldNotBeAllocated) {
  1745. RewriteAssemblyCheckMsg(" \
  1746. float4 main(float4 col : COLOR, out uint coverage : SV_Coverage) : SV_Target7 { coverage = 7; return col; } \
  1747. ",
  1748. "ps_6_0",
  1749. "!\"SV_Coverage\", i8 5, i8 14, !([0-9]+), i8 0, i32 1, i8 1, i32 -1, i8 -1, null}",
  1750. "!\"SV_Coverage\", i8 5, i8 14, !\\1, i8 0, i32 1, i8 1, i32 2, i8 0, null}",
  1751. "Output Semantic 'SV_Coverage' should have a packing location of -1",
  1752. /*bRegex*/true);
  1753. }
  1754. TEST_F(ValidationTest, SemComponentOrder) {
  1755. RewriteAssemblyCheckMsg(" \
  1756. void main( \
  1757. float2 f2in : f2in, \
  1758. float3 f3in : f3in, \
  1759. uint vid : SV_VertexID, \
  1760. uint iid : SV_InstanceID, \
  1761. out float4 pos : SV_Position, \
  1762. out float2 f2out : f2out, \
  1763. out float3 f3out : f3out, \
  1764. out float2 ClipDistance : SV_ClipDistance, \
  1765. out float CullDistance : SV_CullDistance) \
  1766. { \
  1767. pos = float4(f3in, f2in.x); \
  1768. ClipDistance = f2in.x; \
  1769. CullDistance = f2in.y; \
  1770. } \
  1771. ",
  1772. "vs_6_0",
  1773. "= !{i32 1, !\"f2out\", i8 9, i8 0, !([0-9]+), i8 2, i32 1, i8 2, i32 1, i8 0, null}\n"
  1774. "!([0-9]+) = !{i32 2, !\"f3out\", i8 9, i8 0, !([0-9]+), i8 2, i32 1, i8 3, i32 2, i8 0, null}\n"
  1775. "!([0-9]+) = !{i32 3, !\"SV_ClipDistance\", i8 9, i8 6, !([0-9]+), i8 2, i32 1, i8 2, i32 3, i8 0, null}\n"
  1776. "!([0-9]+) = !{i32 4, !\"SV_CullDistance\", i8 9, i8 7, !([0-9]+), i8 2, i32 1, i8 1, i32 3, i8 2, null}\n",
  1777. "= !{i32 1, !\"f2out\", i8 9, i8 0, !\\1, i8 2, i32 1, i8 2, i32 1, i8 2, null}\n"
  1778. "!\\2 = !{i32 2, !\"f3out\", i8 9, i8 0, !\\3, i8 2, i32 1, i8 3, i32 2, i8 1, null}\n"
  1779. "!\\4 = !{i32 3, !\"SV_ClipDistance\", i8 9, i8 6, !\\5, i8 2, i32 1, i8 2, i32 2, i8 0, null}\n"
  1780. "!\\6 = !{i32 4, !\"SV_CullDistance\", i8 9, i8 7, !\\7, i8 2, i32 1, i8 1, i32 1, i8 0, null}\n",
  1781. "signature element SV_ClipDistance at location \\(2,0\\) size \\(1,2\\) violates component ordering rule \\(arb < sv < sgv\\).\n"
  1782. "signature element SV_CullDistance at location \\(1,0\\) size \\(1,1\\) violates component ordering rule \\(arb < sv < sgv\\).",
  1783. /*bRegex*/true);
  1784. }
  1785. TEST_F(ValidationTest, SemComponentOrder2) {
  1786. RewriteAssemblyCheckMsg(" \
  1787. float4 main( \
  1788. float4 col : Color, \
  1789. uint2 val : Value, \
  1790. uint pid : SV_PrimitiveID, \
  1791. bool ff : SV_IsFrontFace) : SV_Target \
  1792. { \
  1793. return col; \
  1794. } \
  1795. ",
  1796. "ps_6_0",
  1797. "= !{i32 1, !\"Value\", i8 5, i8 0, !([0-9]+), i8 1, i32 1, i8 2, i32 1, i8 0, null}\n"
  1798. "!([0-9]+) = !{i32 2, !\"SV_PrimitiveID\", i8 5, i8 10, !([0-9]+), i8 1, i32 1, i8 1, i32 1, i8 2, null}\n"
  1799. "!([0-9]+) = !{i32 3, !\"SV_IsFrontFace\", i8 1, i8 13, !([0-9]+), i8 1, i32 1, i8 1, i32 1, i8 3, null}\n",
  1800. "= !{i32 1, !\"Value\", i8 5, i8 0, !\\1, i8 1, i32 1, i8 2, i32 1, i8 2, null}\n"
  1801. "!\\2 = !{i32 2, !\"SV_PrimitiveID\", i8 5, i8 10, !\\3, i8 1, i32 1, i8 1, i32 1, i8 0, null}\n"
  1802. "!\\4 = !{i32 3, !\"SV_IsFrontFace\", i8 1, i8 13, !\\5, i8 1, i32 1, i8 1, i32 1, i8 1, null}\n",
  1803. "signature element SV_PrimitiveID at location \\(1,0\\) size \\(1,1\\) violates component ordering rule \\(arb < sv < sgv\\).\n"
  1804. "signature element SV_IsFrontFace at location \\(1,1\\) size \\(1,1\\) violates component ordering rule \\(arb < sv < sgv\\).",
  1805. /*bRegex*/true);
  1806. }
  1807. TEST_F(ValidationTest, SemComponentOrder3) {
  1808. RewriteAssemblyCheckMsg(" \
  1809. float4 main( \
  1810. float4 col : Color, \
  1811. uint val : Value, \
  1812. uint pid : SV_PrimitiveID, \
  1813. bool ff : SV_IsFrontFace, \
  1814. uint vpid : ViewPortArrayIndex) : SV_Target \
  1815. { \
  1816. return col; \
  1817. } \
  1818. ",
  1819. "ps_6_0",
  1820. "= !{i32 1, !\"Value\", i8 5, i8 0, !([0-9]+), i8 1, i32 1, i8 1, i32 1, i8 0, null}\n"
  1821. "!([0-9]+) = !{i32 2, !\"SV_PrimitiveID\", i8 5, i8 10, !([0-9]+), i8 1, i32 1, i8 1, i32 1, i8 1, null}\n"
  1822. "!([0-9]+) = !{i32 3, !\"SV_IsFrontFace\", i8 1, i8 13, !([0-9]+), i8 1, i32 1, i8 1, i32 1, i8 2, null}\n"
  1823. "!([0-9]+) = !{i32 4, !\"ViewPortArrayIndex\", i8 5, i8 0, !([0-9]+), i8 1, i32 1, i8 1, i32 2, i8 0, null}\n",
  1824. "= !{i32 1, !\"Value\", i8 5, i8 0, !\\1, i8 1, i32 1, i8 1, i32 1, i8 1, null}\n"
  1825. "!\\2 = !{i32 2, !\"SV_PrimitiveID\", i8 5, i8 10, !\\3, i8 1, i32 1, i8 1, i32 1, i8 0, null}\n"
  1826. "!\\4 = !{i32 3, !\"SV_IsFrontFace\", i8 1, i8 13, !\\5, i8 1, i32 1, i8 1, i32 1, i8 2, null}\n"
  1827. "!\\6 = !{i32 4, !\"ViewPortArrayIndex\", i8 5, i8 0, !\\7, i8 1, i32 1, i8 1, i32 1, i8 3, null}\n",
  1828. "signature element SV_PrimitiveID at location \\(1,0\\) size \\(1,1\\) violates component ordering rule \\(arb < sv < sgv\\).\n"
  1829. "signature element ViewPortArrayIndex at location \\(1,3\\) size \\(1,1\\) violates component ordering rule \\(arb < sv < sgv\\).",
  1830. /*bRegex*/true);
  1831. }
  1832. TEST_F(ValidationTest, SemIndexConflictArbSV) {
  1833. RewriteAssemblyCheckMsg(" \
  1834. void main( \
  1835. float4 inpos : Position, \
  1836. uint iid : SV_InstanceID, \
  1837. out float4 pos : SV_Position, \
  1838. out uint id[2] : Array, \
  1839. out uint vpid : SV_ViewPortArrayIndex, \
  1840. out float2 ClipDistance : SV_ClipDistance, \
  1841. out float CullDistance : SV_CullDistance) \
  1842. { \
  1843. pos = inpos; \
  1844. ClipDistance = inpos.x; \
  1845. CullDistance = inpos.y; \
  1846. vpid = iid; \
  1847. id[0] = iid; \
  1848. id[1] = iid + 1; \
  1849. } \
  1850. ",
  1851. "vs_6_0",
  1852. "!{i32 2, !\"SV_ViewportArrayIndex\", i8 5, i8 5, !([0-9]+), i8 1, i32 1, i8 1, i32 3, i8 0, null}",
  1853. "!{i32 2, !\"SV_ViewportArrayIndex\", i8 5, i8 5, !\\1, i8 1, i32 1, i8 1, i32 1, i8 3, null}",
  1854. "signature element SV_ViewportArrayIndex at location \\(1,3\\) size \\(1,1\\) has an indexing conflict with another signature element packed into the same row.",
  1855. /*bRegex*/true);
  1856. }
  1857. TEST_F(ValidationTest, SemIndexConflictTessfactors) {
  1858. RewriteAssemblyCheckMsg(" \
  1859. struct Vertex { \
  1860. float4 pos : SV_Position; \
  1861. }; \
  1862. struct PatchConstant { \
  1863. float edges[ 4 ] : SV_TessFactor; \
  1864. float inside[ 2 ] : SV_InsideTessFactor; \
  1865. }; \
  1866. PatchConstant PCMain( InputPatch<Vertex, 4> patch) { \
  1867. PatchConstant PC; \
  1868. PC.edges = (float[4])patch[1].pos; \
  1869. PC.inside = (float[2])patch[1].pos.xy; \
  1870. return PC; \
  1871. } \
  1872. [domain(\"quad\")] \
  1873. [partitioning(\"fractional_odd\")] \
  1874. [outputtopology(\"triangle_cw\")] \
  1875. [patchconstantfunc(\"PCMain\")] \
  1876. [outputcontrolpoints(4)] \
  1877. Vertex main(uint id : SV_OutputControlPointID, InputPatch< Vertex, 4 > patch) { \
  1878. Vertex Out = patch[id]; \
  1879. Out.pos.w += 0.25; \
  1880. return Out; \
  1881. } \
  1882. ",
  1883. "hs_6_0",
  1884. //!{i32 0, !"SV_TessFactor", i8 9, i8 25, !23, i8 0, i32 4, i8 1, i32 0, i8 3, null}
  1885. "!{i32 1, !\"SV_InsideTessFactor\", i8 9, i8 26, !([0-9]+), i8 0, i32 2, i8 1, i32 4, i8 3, null}",
  1886. "!{i32 1, !\"SV_InsideTessFactor\", i8 9, i8 26, !\\1, i8 0, i32 2, i8 1, i32 0, i8 2, null}",
  1887. "signature element SV_InsideTessFactor at location \\(0,2\\) size \\(2,1\\) has an indexing conflict with another signature element packed into the same row.",
  1888. /*bRegex*/true);
  1889. }
  1890. TEST_F(ValidationTest, SemIndexConflictTessfactors2) {
  1891. RewriteAssemblyCheckMsg(" \
  1892. struct Vertex { \
  1893. float4 pos : SV_Position; \
  1894. }; \
  1895. struct PatchConstant { \
  1896. float edges[ 4 ] : SV_TessFactor; \
  1897. float inside[ 2 ] : SV_InsideTessFactor; \
  1898. float arb [ 3 ] : Arb; \
  1899. }; \
  1900. PatchConstant PCMain( InputPatch<Vertex, 4> patch) { \
  1901. PatchConstant PC; \
  1902. PC.edges = (float[4])patch[1].pos; \
  1903. PC.inside = (float[2])patch[1].pos.xy; \
  1904. PC.arb[0] = 1; PC.arb[1] = 2; PC.arb[2] = 3; \
  1905. return PC; \
  1906. } \
  1907. [domain(\"quad\")] \
  1908. [partitioning(\"fractional_odd\")] \
  1909. [outputtopology(\"triangle_cw\")] \
  1910. [patchconstantfunc(\"PCMain\")] \
  1911. [outputcontrolpoints(4)] \
  1912. Vertex main(uint id : SV_OutputControlPointID, InputPatch< Vertex, 4 > patch) { \
  1913. Vertex Out = patch[id]; \
  1914. Out.pos.w += 0.25; \
  1915. return Out; \
  1916. } \
  1917. ",
  1918. "hs_6_0",
  1919. "!{i32 2, !\"Arb\", i8 9, i8 0, !([0-9]+), i8 0, i32 3, i8 1, i32 0, i8 0, null}",
  1920. "!{i32 2, !\"Arb\", i8 9, i8 0, !\\1, i8 0, i32 3, i8 1, i32 2, i8 0, null}",
  1921. "signature element Arb at location \\(2,0\\) size \\(3,1\\) has an indexing conflict with another signature element packed into the same row.",
  1922. /*bRegex*/true);
  1923. }
  1924. TEST_F(ValidationTest, SemRowOutOfRange) {
  1925. RewriteAssemblyCheckMsg(" \
  1926. struct Vertex { \
  1927. float4 pos : SV_Position; \
  1928. }; \
  1929. struct PatchConstant { \
  1930. float edges[ 4 ] : SV_TessFactor; \
  1931. float inside[ 2 ] : SV_InsideTessFactor; \
  1932. float arb [ 3 ] : Arb; \
  1933. }; \
  1934. PatchConstant PCMain( InputPatch<Vertex, 4> patch) { \
  1935. PatchConstant PC; \
  1936. PC.edges = (float[4])patch[1].pos; \
  1937. PC.inside = (float[2])patch[1].pos.xy; \
  1938. PC.arb[0] = 1; PC.arb[1] = 2; PC.arb[2] = 3; \
  1939. return PC; \
  1940. } \
  1941. [domain(\"quad\")] \
  1942. [partitioning(\"fractional_odd\")] \
  1943. [outputtopology(\"triangle_cw\")] \
  1944. [patchconstantfunc(\"PCMain\")] \
  1945. [outputcontrolpoints(4)] \
  1946. Vertex main(uint id : SV_OutputControlPointID, InputPatch< Vertex, 4 > patch) { \
  1947. Vertex Out = patch[id]; \
  1948. Out.pos.w += 0.25; \
  1949. return Out; \
  1950. } \
  1951. ",
  1952. "hs_6_0",
  1953. "!{i32 2, !\"Arb\", i8 9, i8 0, !([0-9]+), i8 0, i32 3, i8 1, i32 0, i8 0, null}",
  1954. "!{i32 2, !\"Arb\", i8 9, i8 0, !\\1, i8 0, i32 3, i8 1, i32 31, i8 0, null}",
  1955. "signature element Arb at location \\(31,0\\) size \\(3,1\\) is out of range.",
  1956. /*bRegex*/true);
  1957. }
  1958. TEST_F(ValidationTest, SemPackOverlap) {
  1959. RewriteAssemblyCheckMsg(" \
  1960. struct Vertex { \
  1961. float4 pos : SV_Position; \
  1962. }; \
  1963. struct PatchConstant { \
  1964. float edges[ 4 ] : SV_TessFactor; \
  1965. float inside[ 2 ] : SV_InsideTessFactor; \
  1966. float arb [ 3 ] : Arb; \
  1967. }; \
  1968. PatchConstant PCMain( InputPatch<Vertex, 4> patch) { \
  1969. PatchConstant PC; \
  1970. PC.edges = (float[4])patch[1].pos; \
  1971. PC.inside = (float[2])patch[1].pos.xy; \
  1972. PC.arb[0] = 1; PC.arb[1] = 2; PC.arb[2] = 3; \
  1973. return PC; \
  1974. } \
  1975. [domain(\"quad\")] \
  1976. [partitioning(\"fractional_odd\")] \
  1977. [outputtopology(\"triangle_cw\")] \
  1978. [patchconstantfunc(\"PCMain\")] \
  1979. [outputcontrolpoints(4)] \
  1980. Vertex main(uint id : SV_OutputControlPointID, InputPatch< Vertex, 4 > patch) { \
  1981. Vertex Out = patch[id]; \
  1982. Out.pos.w += 0.25; \
  1983. return Out; \
  1984. } \
  1985. ",
  1986. "hs_6_0",
  1987. "!{i32 2, !\"Arb\", i8 9, i8 0, !([0-9]+), i8 0, i32 3, i8 1, i32 0, i8 0, null}",
  1988. "!{i32 2, !\"Arb\", i8 9, i8 0, !\\1, i8 0, i32 3, i8 1, i32 1, i8 3, null}",
  1989. "signature element Arb at location \\(1,3\\) size \\(3,1\\) overlaps another signature element.",
  1990. /*bRegex*/true);
  1991. }
  1992. TEST_F(ValidationTest, SemPackOverlap2) {
  1993. RewriteAssemblyCheckMsg(" \
  1994. void main( \
  1995. float4 inpos : Position, \
  1996. uint iid : SV_InstanceID, \
  1997. out float4 pos : SV_Position, \
  1998. out uint id[2] : Array, \
  1999. out uint3 value : Value, \
  2000. out float2 ClipDistance : SV_ClipDistance, \
  2001. out float CullDistance : SV_CullDistance) \
  2002. { \
  2003. pos = inpos; \
  2004. ClipDistance = inpos.x; \
  2005. CullDistance = inpos.y; \
  2006. value = iid; \
  2007. id[0] = iid; \
  2008. id[1] = iid + 1; \
  2009. } \
  2010. ",
  2011. "vs_6_0",
  2012. {"!{i32 1, !\"Array\", i8 5, i8 0, !([0-9]+), i8 1, i32 2, i8 1, i32 1, i8 0, null}(.*)"
  2013. "!\\1 = !{i32 0, i32 1}\n",
  2014. "= !{i32 2, !\"Value\", i8 5, i8 0, !([0-9]+), i8 1, i32 1, i8 3, i32 1, i8 1, null}"},
  2015. {"!{i32 1, !\"Array\", i8 5, i8 0, !\\1, i8 1, i32 2, i8 1, i32 1, i8 1, null}\\2"
  2016. "!\\1 = !{i32 0, i32 1}\n",
  2017. "= !{i32 2, !\"Value\", i8 5, i8 0, !\\1, i8 1, i32 1, i8 3, i32 2, i8 0, null}"},
  2018. "signature element Value at location \\(2,0\\) size \\(1,3\\) overlaps another signature element.",
  2019. /*bRegex*/true);
  2020. }
  2021. TEST_F(ValidationTest, SemMultiDepth) {
  2022. RewriteAssemblyCheckMsg(" \
  2023. float4 main(float4 f4 : Input, out float d0 : SV_Depth, out float d1 : SV_Target) : SV_Target1 \
  2024. { d0 = f4.z; d1 = f4.w; return f4; } \
  2025. ",
  2026. "ps_6_0",
  2027. {"!{i32 1, !\"SV_Target\", i8 9, i8 16, !([0-9]+), i8 0, i32 1, i8 1, i32 0, i8 0, null}"},
  2028. {"!{i32 1, !\"SV_DepthGreaterEqual\", i8 9, i8 19, !\\1, i8 0, i32 1, i8 1, i32 -1, i8 -1, null}"},
  2029. "Pixel Shader only allows one type of depth semantic to be declared",
  2030. /*bRegex*/true);
  2031. }
  2032. TEST_F(ValidationTest, WhenRootSigMismatchThenFail) {
  2033. ReplaceContainerPartsCheckMsgs(
  2034. "float c; [RootSignature ( \"RootConstants(b0, num32BitConstants = 1)\" )] float4 main() : semantic { return c; }",
  2035. "[RootSignature ( \"\" )] float4 main() : semantic { return 0; }",
  2036. "vs_6_0",
  2037. {DFCC_RootSignature},
  2038. {
  2039. "Root Signature in DXIL container is not compatible with shader.",
  2040. "Validation failed."
  2041. }
  2042. );
  2043. }
  2044. TEST_F(ValidationTest, WhenRootSigCompatThenSucceed) {
  2045. ReplaceContainerPartsCheckMsgs(
  2046. "[RootSignature ( \"\" )] float4 main() : semantic { return 0; }",
  2047. "float c; [RootSignature ( \"RootConstants(b0, num32BitConstants = 1)\" )] float4 main() : semantic { return c; }",
  2048. "vs_6_0",
  2049. {DFCC_RootSignature},
  2050. {}
  2051. );
  2052. }
  2053. TEST_F(ValidationTest, WhenRootSigMatchShaderSucceed_RootConstVis) {
  2054. ReplaceContainerPartsCheckMsgs(
  2055. "float c; float4 main() : semantic { return c; }",
  2056. "[RootSignature ( \"RootConstants(b0, visibility = SHADER_VISIBILITY_VERTEX, num32BitConstants = 1)\" )]"
  2057. " float4 main() : semantic { return 0; }",
  2058. "vs_6_0",
  2059. {DFCC_RootSignature},
  2060. {}
  2061. );
  2062. }
  2063. TEST_F(ValidationTest, WhenRootSigMatchShaderFail_RootConstVis) {
  2064. ReplaceContainerPartsCheckMsgs(
  2065. "float c; float4 main() : semantic { return c; }",
  2066. "[RootSignature ( \"RootConstants(b0, visibility = SHADER_VISIBILITY_PIXEL, num32BitConstants = 1)\" )]"
  2067. " float4 main() : semantic { return 0; }",
  2068. "vs_6_0",
  2069. {DFCC_RootSignature},
  2070. {
  2071. "Root Signature in DXIL container is not compatible with shader.",
  2072. "Validation failed."
  2073. }
  2074. );
  2075. }
  2076. TEST_F(ValidationTest, WhenRootSigMatchShaderSucceed_RootCBV) {
  2077. ReplaceContainerPartsCheckMsgs(
  2078. "struct Foo { float a; int4 b; }; "
  2079. "ConstantBuffer<Foo> cb1 : register(b2, space5); "
  2080. "float4 main() : semantic { return cb1.b.x; }",
  2081. "[RootSignature ( \"CBV(b2, space = 5)\" )]"
  2082. " float4 main() : semantic { return 0; }",
  2083. "vs_6_0",
  2084. {DFCC_RootSignature},
  2085. {}
  2086. );
  2087. }
  2088. TEST_F(ValidationTest, WhenRootSigMatchShaderFail_RootCBV_Range) {
  2089. ReplaceContainerPartsCheckMsgs(
  2090. "struct Foo { float a; int4 b; }; "
  2091. "ConstantBuffer<Foo> cb1 : register(b0, space5); "
  2092. "float4 main() : semantic { return cb1.b.x; }",
  2093. "[RootSignature ( \"CBV(b2, space = 5)\" )]"
  2094. " float4 main() : semantic { return 0; }",
  2095. "vs_6_0",
  2096. {DFCC_RootSignature},
  2097. {
  2098. "Root Signature in DXIL container is not compatible with shader.",
  2099. "Validation failed."
  2100. }
  2101. );
  2102. }
  2103. TEST_F(ValidationTest, WhenRootSigMatchShaderFail_RootCBV_Space) {
  2104. ReplaceContainerPartsCheckMsgs(
  2105. "struct Foo { float a; int4 b; }; "
  2106. "ConstantBuffer<Foo> cb1 : register(b2, space7); "
  2107. "float4 main() : semantic { return cb1.b.x; }",
  2108. "[RootSignature ( \"CBV(b2, space = 5)\" )]"
  2109. " float4 main() : semantic { return 0; }",
  2110. "vs_6_0",
  2111. {DFCC_RootSignature},
  2112. {
  2113. "Root Signature in DXIL container is not compatible with shader.",
  2114. "Validation failed."
  2115. }
  2116. );
  2117. }
  2118. TEST_F(ValidationTest, WhenRootSigMatchShaderSucceed_RootSRV) {
  2119. ReplaceContainerPartsCheckMsgs(
  2120. "struct Foo { float4 a; }; "
  2121. "StructuredBuffer<Foo> buf1 : register(t1, space3); "
  2122. "float4 main(float4 a : AAA) : SV_Target { return buf1[a.x].a; }",
  2123. "[RootSignature ( \"SRV(t1, space = 3)\" )]"
  2124. " float4 main() : SV_Target { return 0; }",
  2125. "ps_6_0",
  2126. {DFCC_RootSignature},
  2127. {}
  2128. );
  2129. }
  2130. TEST_F(ValidationTest, WhenRootSigMatchShaderFail_RootSRV_ResType) {
  2131. ReplaceContainerPartsCheckMsgs(
  2132. "struct Foo { float4 a; }; "
  2133. "StructuredBuffer<Foo> buf1 : register(t1, space3); "
  2134. "float4 main(float4 a : AAA) : SV_Target { return buf1[a.x].a; }",
  2135. "[RootSignature ( \"UAV(u1, space = 3)\" )]"
  2136. " float4 main() : SV_Target { return 0; }",
  2137. "ps_6_0",
  2138. {DFCC_RootSignature},
  2139. {
  2140. "Root Signature in DXIL container is not compatible with shader.",
  2141. "Validation failed."
  2142. }
  2143. );
  2144. }
  2145. TEST_F(ValidationTest, WhenRootSigMatchShaderSucceed_RootUAV) {
  2146. ReplaceContainerPartsCheckMsgs(
  2147. "struct Foo { float4 a; }; "
  2148. "RWStructuredBuffer<Foo> buf1 : register(u1, space3); "
  2149. "float4 main(float4 a : AAA) : SV_Target { return buf1[a.x].a; }",
  2150. "[RootSignature ( \"UAV(u1, space = 3)\" )]"
  2151. " float4 main() : SV_Target { return 0; }",
  2152. "ps_6_0",
  2153. {DFCC_RootSignature},
  2154. {}
  2155. );
  2156. }
  2157. TEST_F(ValidationTest, WhenRootSigMatchShaderSucceed_DescTable) {
  2158. ReplaceContainerPartsCheckMsgs(
  2159. "struct Foo { int a; float4 b; };"
  2160. ""
  2161. "ConstantBuffer<Foo> cb1[4] : register(b2, space5);"
  2162. "Texture2D<float4> tex1[8] : register(t1, space3);"
  2163. "RWBuffer<float4> buf1[6] : register(u33, space17);"
  2164. "SamplerState sampler1[5] : register(s0, space0);"
  2165. ""
  2166. "float4 main(float4 a : AAA) : SV_TARGET"
  2167. "{"
  2168. " return buf1[a.x][a.y] + cb1[a.x].b + tex1[a.x].Sample(sampler1[a.x], a.xy);"
  2169. "}",
  2170. "[RootSignature(\"DescriptorTable( SRV(t1,space=3,numDescriptors=8), "
  2171. "CBV(b2,space=5,numDescriptors=4), "
  2172. "UAV(u33,space=17,numDescriptors=6)), "
  2173. "DescriptorTable(Sampler(s0, numDescriptors=5))\")]"
  2174. " float4 main() : SV_Target { return 0; }",
  2175. "ps_6_0",
  2176. {DFCC_RootSignature},
  2177. {}
  2178. );
  2179. }
  2180. TEST_F(ValidationTest, WhenRootSigMatchShaderSucceed_DescTable_GoodRange) {
  2181. ReplaceContainerPartsCheckMsgs(
  2182. "struct Foo { int a; float4 b; };"
  2183. ""
  2184. "ConstantBuffer<Foo> cb1[4] : register(b2, space5);"
  2185. "Texture2D<float4> tex1[8] : register(t1, space3);"
  2186. "RWBuffer<float4> buf1[6] : register(u33, space17);"
  2187. "SamplerState sampler1[5] : register(s0, space0);"
  2188. ""
  2189. "float4 main(float4 a : AAA) : SV_TARGET"
  2190. "{"
  2191. " return buf1[a.x][a.y] + cb1[a.x].b + tex1[a.x].Sample(sampler1[a.x], a.xy);"
  2192. "}",
  2193. "[RootSignature(\"DescriptorTable( SRV(t0,space=3,numDescriptors=20), "
  2194. "CBV(b2,space=5,numDescriptors=4), "
  2195. "UAV(u33,space=17,numDescriptors=6)), "
  2196. "DescriptorTable(Sampler(s0, numDescriptors=5))\")]"
  2197. " float4 main() : SV_Target { return 0; }",
  2198. "ps_6_0",
  2199. {DFCC_RootSignature},
  2200. {}
  2201. );
  2202. }
  2203. TEST_F(ValidationTest, WhenRootSigMatchShaderSucceed_DescTable_Unbounded) {
  2204. ReplaceContainerPartsCheckMsgs(
  2205. "struct Foo { int a; float4 b; };"
  2206. ""
  2207. "ConstantBuffer<Foo> cb1[4] : register(b2, space5);"
  2208. "Texture2D<float4> tex1[8] : register(t1, space3);"
  2209. "RWBuffer<float4> buf1[6] : register(u33, space17);"
  2210. "SamplerState sampler1[5] : register(s0, space0);"
  2211. ""
  2212. "float4 main(float4 a : AAA) : SV_TARGET"
  2213. "{"
  2214. " return buf1[a.x][a.y] + cb1[a.x].b + tex1[a.x].Sample(sampler1[a.x], a.xy);"
  2215. "}",
  2216. "[RootSignature(\"DescriptorTable( CBV(b2,space=5,numDescriptors=4), "
  2217. "SRV(t1,space=3,numDescriptors=8), "
  2218. "UAV(u10,space=17,numDescriptors=unbounded)), "
  2219. "DescriptorTable(Sampler(s0, numDescriptors=5))\")]"
  2220. " float4 main() : SV_Target { return 0; }",
  2221. "ps_6_0",
  2222. {DFCC_RootSignature},
  2223. {}
  2224. );
  2225. }
  2226. TEST_F(ValidationTest, WhenRootSigMatchShaderFail_DescTable_Range1) {
  2227. ReplaceContainerPartsCheckMsgs(
  2228. "struct Foo { int a; float4 b; };"
  2229. ""
  2230. "ConstantBuffer<Foo> cb1[4] : register(b2, space5);"
  2231. "Texture2D<float4> tex1[8] : register(t1, space3);"
  2232. "RWBuffer<float4> buf1[6] : register(u33, space17);"
  2233. "SamplerState sampler1[5] : register(s0, space0);"
  2234. ""
  2235. "float4 main(float4 a : AAA) : SV_TARGET"
  2236. "{"
  2237. " return buf1[a.x][a.y] + cb1[a.x].b + tex1[a.x].Sample(sampler1[a.x], a.xy);"
  2238. "}",
  2239. "[RootSignature(\"DescriptorTable( CBV(b2,space=5,numDescriptors=4), "
  2240. "SRV(t2,space=3,numDescriptors=8), "
  2241. "UAV(u33,space=17,numDescriptors=6)), "
  2242. "DescriptorTable(Sampler(s0, numDescriptors=5))\")]"
  2243. " float4 main() : SV_Target { return 0; }",
  2244. "ps_6_0",
  2245. {DFCC_RootSignature},
  2246. {
  2247. "Shader SRV descriptor range (RegisterSpace=3, NumDescriptors=8, BaseShaderRegister=1) is not fully bound in root signature.",
  2248. "Root Signature in DXIL container is not compatible with shader.",
  2249. "Validation failed."
  2250. }
  2251. );
  2252. }
  2253. TEST_F(ValidationTest, WhenRootSigMatchShaderFail_DescTable_Range2) {
  2254. ReplaceContainerPartsCheckMsgs(
  2255. "struct Foo { int a; float4 b; };"
  2256. ""
  2257. "ConstantBuffer<Foo> cb1[4] : register(b2, space5);"
  2258. "Texture2D<float4> tex1[8] : register(t1, space3);"
  2259. "RWBuffer<float4> buf1[6] : register(u33, space17);"
  2260. "SamplerState sampler1[5] : register(s0, space0);"
  2261. ""
  2262. "float4 main(float4 a : AAA) : SV_TARGET"
  2263. "{"
  2264. " return buf1[a.x][a.y] + cb1[a.x].b + tex1[a.x].Sample(sampler1[a.x], a.xy);"
  2265. "}",
  2266. "[RootSignature(\"DescriptorTable( SRV(t2,space=3,numDescriptors=8), "
  2267. "CBV(b20,space=5,numDescriptors=4), "
  2268. "UAV(u33,space=17,numDescriptors=6)), "
  2269. "DescriptorTable(Sampler(s0, numDescriptors=5))\")]"
  2270. " float4 main() : SV_Target { return 0; }",
  2271. "ps_6_0",
  2272. {DFCC_RootSignature},
  2273. {
  2274. "Root Signature in DXIL container is not compatible with shader.",
  2275. "Validation failed."
  2276. }
  2277. );
  2278. }
  2279. TEST_F(ValidationTest, WhenRootSigMatchShaderFail_DescTable_Range3) {
  2280. ReplaceContainerPartsCheckMsgs(
  2281. "struct Foo { int a; float4 b; };"
  2282. ""
  2283. "ConstantBuffer<Foo> cb1[4] : register(b2, space5);"
  2284. "Texture2D<float4> tex1[8] : register(t1, space3);"
  2285. "RWBuffer<float4> buf1[6] : register(u33, space17);"
  2286. "SamplerState sampler1[5] : register(s0, space0);"
  2287. ""
  2288. "float4 main(float4 a : AAA) : SV_TARGET"
  2289. "{"
  2290. " return buf1[a.x][a.y] + cb1[a.x].b + tex1[a.x].Sample(sampler1[a.x], a.xy);"
  2291. "}",
  2292. "[RootSignature(\"DescriptorTable( CBV(b2,space=5,numDescriptors=4), "
  2293. "SRV(t1,space=3,numDescriptors=8), "
  2294. "UAV(u33,space=17,numDescriptors=5)), "
  2295. "DescriptorTable(Sampler(s0, numDescriptors=5))\")]"
  2296. " float4 main() : SV_Target { return 0; }",
  2297. "ps_6_0",
  2298. {DFCC_RootSignature},
  2299. {
  2300. "Root Signature in DXIL container is not compatible with shader.",
  2301. "Validation failed."
  2302. }
  2303. );
  2304. }
  2305. TEST_F(ValidationTest, WhenRootSigMatchShaderFail_DescTable_Space) {
  2306. ReplaceContainerPartsCheckMsgs(
  2307. "struct Foo { int a; float4 b; };"
  2308. ""
  2309. "ConstantBuffer<Foo> cb1[4] : register(b2, space5);"
  2310. "Texture2D<float4> tex1[8] : register(t1, space3);"
  2311. "RWBuffer<float4> buf1[6] : register(u33, space17);"
  2312. "SamplerState sampler1[5] : register(s0, space0);"
  2313. ""
  2314. "float4 main(float4 a : AAA) : SV_TARGET"
  2315. "{"
  2316. " return buf1[a.x][a.y] + cb1[a.x].b + tex1[a.x].Sample(sampler1[a.x], a.xy);"
  2317. "}",
  2318. "[RootSignature(\"DescriptorTable( SRV(t2,space=3,numDescriptors=8), "
  2319. "CBV(b2,space=5,numDescriptors=4), "
  2320. "UAV(u33,space=0,numDescriptors=6)), "
  2321. "DescriptorTable(Sampler(s0, numDescriptors=5))\")]"
  2322. " float4 main() : SV_Target { return 0; }",
  2323. "ps_6_0",
  2324. {DFCC_RootSignature},
  2325. {
  2326. "Root Signature in DXIL container is not compatible with shader.",
  2327. "Validation failed."
  2328. }
  2329. );
  2330. }
  2331. TEST_F(ValidationTest, WhenRootSigMatchShaderSucceed_Unbounded) {
  2332. ReplaceContainerPartsCheckMsgs(
  2333. "struct Foo { int a; float4 b; };"
  2334. ""
  2335. "ConstantBuffer<Foo> cb1[] : register(b2, space5);"
  2336. "Texture2D<float4> tex1[] : register(t1, space3);"
  2337. "RWBuffer<float4> buf1[] : register(u33, space17);"
  2338. "SamplerState sampler1[] : register(s0, space0);"
  2339. ""
  2340. "float4 main(float4 a : AAA) : SV_TARGET"
  2341. "{"
  2342. " return buf1[a.x][a.y] + cb1[a.x].b + tex1[a.x].Sample(sampler1[a.x], a.xy);"
  2343. "}",
  2344. "[RootSignature(\"DescriptorTable( CBV(b2,space=5,numDescriptors=1)), "
  2345. "DescriptorTable( SRV(t1,space=3,numDescriptors=unbounded)), "
  2346. "DescriptorTable( UAV(u10,space=17,numDescriptors=100)), "
  2347. "DescriptorTable(Sampler(s0, numDescriptors=5))\")]"
  2348. " float4 main() : SV_Target { return 0; }",
  2349. "ps_6_0",
  2350. {DFCC_RootSignature},
  2351. {}
  2352. );
  2353. }
  2354. TEST_F(ValidationTest, WhenRootSigMatchShaderFail_Unbounded1) {
  2355. ReplaceContainerPartsCheckMsgs(
  2356. "struct Foo { int a; float4 b; };"
  2357. ""
  2358. "ConstantBuffer<Foo> cb1[] : register(b2, space5);"
  2359. "Texture2D<float4> tex1[] : register(t1, space3);"
  2360. "RWBuffer<float4> buf1[] : register(u33, space17);"
  2361. "SamplerState sampler1[] : register(s0, space0);"
  2362. ""
  2363. "float4 main(float4 a : AAA) : SV_TARGET"
  2364. "{"
  2365. " return buf1[a.x][a.y] + cb1[a.x].b + tex1[a.x].Sample(sampler1[a.x], a.xy);"
  2366. "}",
  2367. "[RootSignature(\"DescriptorTable( CBV(b3,space=5,numDescriptors=1)), "
  2368. "DescriptorTable( SRV(t1,space=3,numDescriptors=unbounded)), "
  2369. "DescriptorTable( UAV(u10,space=17,numDescriptors=unbounded)), "
  2370. "DescriptorTable( Sampler(s0, numDescriptors=5))\")]"
  2371. " float4 main() : SV_Target { return 0; }",
  2372. "ps_6_0",
  2373. {DFCC_RootSignature},
  2374. {
  2375. "Root Signature in DXIL container is not compatible with shader.",
  2376. "Validation failed."
  2377. }
  2378. );
  2379. }
  2380. TEST_F(ValidationTest, WhenRootSigMatchShaderFail_Unbounded2) {
  2381. ReplaceContainerPartsCheckMsgs(
  2382. "struct Foo { int a; float4 b; };"
  2383. ""
  2384. "ConstantBuffer<Foo> cb1[] : register(b2, space5);"
  2385. "Texture2D<float4> tex1[] : register(t1, space3);"
  2386. "RWBuffer<float4> buf1[] : register(u33, space17);"
  2387. "SamplerState sampler1[] : register(s0, space0);"
  2388. ""
  2389. "float4 main(float4 a : AAA) : SV_TARGET"
  2390. "{"
  2391. " return buf1[a.x][a.y] + cb1[a.x].b + tex1[a.x].Sample(sampler1[a.x], a.xy);"
  2392. "}",
  2393. "[RootSignature(\"DescriptorTable( CBV(b2,space=5,numDescriptors=1)), "
  2394. "DescriptorTable( SRV(t1,space=3,numDescriptors=unbounded)), "
  2395. "DescriptorTable( UAV(u10,space=17,numDescriptors=unbounded)), "
  2396. "DescriptorTable( Sampler(s5, numDescriptors=unbounded))\")]"
  2397. " float4 main() : SV_Target { return 0; }",
  2398. "ps_6_0",
  2399. {DFCC_RootSignature},
  2400. {
  2401. "Root Signature in DXIL container is not compatible with shader.",
  2402. "Validation failed."
  2403. }
  2404. );
  2405. }
  2406. TEST_F(ValidationTest, WhenRootSigMatchShaderFail_Unbounded3) {
  2407. ReplaceContainerPartsCheckMsgs(
  2408. "struct Foo { int a; float4 b; };"
  2409. ""
  2410. "ConstantBuffer<Foo> cb1[] : register(b2, space5);"
  2411. "Texture2D<float4> tex1[] : register(t1, space3);"
  2412. "RWBuffer<float4> buf1[] : register(u33, space17);"
  2413. "SamplerState sampler1[] : register(s0, space0);"
  2414. ""
  2415. "float4 main(float4 a : AAA) : SV_TARGET"
  2416. "{"
  2417. " return buf1[a.x][a.y] + cb1[a.x].b + tex1[a.x].Sample(sampler1[a.x], a.xy);"
  2418. "}",
  2419. "[RootSignature(\"DescriptorTable( CBV(b2,space=5,numDescriptors=1)), "
  2420. "DescriptorTable( SRV(t1,space=3,numDescriptors=unbounded)), "
  2421. "DescriptorTable( UAV(u10,space=17,numDescriptors=7)), "
  2422. "DescriptorTable(Sampler(s0, numDescriptors=5))\")]"
  2423. " float4 main() : SV_Target { return 0; }",
  2424. "ps_6_0",
  2425. {DFCC_RootSignature},
  2426. {
  2427. "Root Signature in DXIL container is not compatible with shader.",
  2428. "Validation failed."
  2429. }
  2430. );
  2431. }
  2432. #define VERTEX_STRUCT1 \
  2433. "struct PSSceneIn \n\
  2434. { \n\
  2435. float4 pos : SV_Position; \n\
  2436. float2 tex : TEXCOORD0; \n\
  2437. float3 norm : NORMAL; \n\
  2438. }; \n"
  2439. #define VERTEX_STRUCT2 \
  2440. "struct PSSceneIn \n\
  2441. { \n\
  2442. float4 pos : SV_Position; \n\
  2443. float2 tex : TEXCOORD0; \n\
  2444. }; \n"
  2445. #define PC_STRUCT1 "struct HSPerPatchData { \n\
  2446. float edges[ 3 ] : SV_TessFactor; \n\
  2447. float inside : SV_InsideTessFactor; \n\
  2448. float foo : FOO; \n\
  2449. }; \n"
  2450. #define PC_STRUCT2 "struct HSPerPatchData { \n\
  2451. float edges[ 3 ] : SV_TessFactor; \n\
  2452. float inside : SV_InsideTessFactor; \n\
  2453. }; \n"
  2454. #define PC_FUNC "HSPerPatchData HSPerPatchFunc( InputPatch< PSSceneIn, 3 > points, \n\
  2455. OutputPatch<PSSceneIn, 3> outpoints) { \n\
  2456. HSPerPatchData d = (HSPerPatchData)0; \n\
  2457. d.edges[ 0 ] = points[0].tex.x + outpoints[0].tex.x; \n\
  2458. d.edges[ 1 ] = 1; \n\
  2459. d.edges[ 2 ] = 1; \n\
  2460. d.inside = 1; \n\
  2461. return d; \n\
  2462. } \n"
  2463. #define PC_FUNC_NOOUT "HSPerPatchData HSPerPatchFunc( InputPatch< PSSceneIn, 3 > points ) { \n\
  2464. HSPerPatchData d = (HSPerPatchData)0; \n\
  2465. d.edges[ 0 ] = points[0].tex.x; \n\
  2466. d.edges[ 1 ] = 1; \n\
  2467. d.edges[ 2 ] = 1; \n\
  2468. d.inside = 1; \n\
  2469. return d; \n\
  2470. } \n"
  2471. #define PC_FUNC_NOIN "HSPerPatchData HSPerPatchFunc( OutputPatch<PSSceneIn, 3> outpoints) { \n\
  2472. HSPerPatchData d = (HSPerPatchData)0; \n\
  2473. d.edges[ 0 ] = outpoints[0].tex.x; \n\
  2474. d.edges[ 1 ] = 1; \n\
  2475. d.edges[ 2 ] = 1; \n\
  2476. d.inside = 1; \n\
  2477. return d; \n\
  2478. } \n"
  2479. #define HS_ATTR "[domain(\"tri\")] \n\
  2480. [partitioning(\"fractional_odd\")] \n\
  2481. [outputtopology(\"triangle_cw\")] \n\
  2482. [patchconstantfunc(\"HSPerPatchFunc\")] \n\
  2483. [outputcontrolpoints(3)] \n"
  2484. #define HS_FUNC \
  2485. "PSSceneIn main(const uint id : SV_OutputControlPointID, \n\
  2486. const InputPatch< PSSceneIn, 3 > points ) { \n\
  2487. return points[ id ]; \n\
  2488. } \n"
  2489. #define HS_FUNC_NOOUT \
  2490. "void main(const uint id : SV_OutputControlPointID, \n\
  2491. const InputPatch< PSSceneIn, 3 > points ) { \n\
  2492. } \n"
  2493. #define HS_FUNC_NOIN \
  2494. "PSSceneIn main( const uint id : SV_OutputControlPointID ) { \n\
  2495. return (PSSceneIn)0; \n\
  2496. } \n"
  2497. #define DS_FUNC \
  2498. "[domain(\"tri\")] PSSceneIn main(const float3 bary : SV_DomainLocation, \n\
  2499. const OutputPatch<PSSceneIn, 3> patch, \n\
  2500. const HSPerPatchData perPatchData) { \n\
  2501. PSSceneIn v = patch[0]; \n\
  2502. v.pos = patch[0].pos * bary.x; \n\
  2503. v.pos += patch[1].pos * bary.y; \n\
  2504. v.pos += patch[2].pos * bary.z; \n\
  2505. return v; \n\
  2506. } \n"
  2507. #define DS_FUNC_NOPC \
  2508. "[domain(\"tri\")] PSSceneIn main(const float3 bary : SV_DomainLocation, \n\
  2509. const OutputPatch<PSSceneIn, 3> patch) { \n\
  2510. PSSceneIn v = patch[0]; \n\
  2511. v.pos = patch[0].pos * bary.x; \n\
  2512. v.pos += patch[1].pos * bary.y; \n\
  2513. v.pos += patch[2].pos * bary.z; \n\
  2514. return v; \n\
  2515. } \n"
  2516. TEST_F(ValidationTest, WhenProgramOutSigMissingThenFail) {
  2517. ReplaceContainerPartsCheckMsgs(
  2518. VERTEX_STRUCT1
  2519. PC_STRUCT1
  2520. PC_FUNC
  2521. HS_ATTR
  2522. HS_FUNC,
  2523. VERTEX_STRUCT1
  2524. PC_STRUCT1
  2525. PC_FUNC_NOOUT
  2526. HS_ATTR
  2527. HS_FUNC_NOOUT,
  2528. "hs_6_0",
  2529. {DFCC_InputSignature, DFCC_OutputSignature, DFCC_PatchConstantSignature},
  2530. {
  2531. "Container part 'Program Output Signature' does not match expected for module.",
  2532. "Validation failed."
  2533. }
  2534. );
  2535. }
  2536. TEST_F(ValidationTest, WhenProgramOutSigUnexpectedThenFail) {
  2537. ReplaceContainerPartsCheckMsgs(
  2538. VERTEX_STRUCT1
  2539. PC_STRUCT1
  2540. PC_FUNC_NOOUT
  2541. HS_ATTR
  2542. HS_FUNC_NOOUT,
  2543. VERTEX_STRUCT1
  2544. PC_STRUCT1
  2545. PC_FUNC
  2546. HS_ATTR
  2547. HS_FUNC,
  2548. "hs_6_0",
  2549. {DFCC_InputSignature, DFCC_OutputSignature, DFCC_PatchConstantSignature},
  2550. {
  2551. "Container part 'Program Output Signature' does not match expected for module.",
  2552. "Validation failed."
  2553. }
  2554. );
  2555. }
  2556. TEST_F(ValidationTest, WhenProgramSigMismatchThenFail) {
  2557. ReplaceContainerPartsCheckMsgs(
  2558. VERTEX_STRUCT1
  2559. PC_STRUCT1
  2560. PC_FUNC
  2561. HS_ATTR
  2562. HS_FUNC,
  2563. VERTEX_STRUCT2
  2564. PC_STRUCT2
  2565. PC_FUNC
  2566. HS_ATTR
  2567. HS_FUNC,
  2568. "hs_6_0",
  2569. {DFCC_InputSignature, DFCC_OutputSignature, DFCC_PatchConstantSignature},
  2570. {
  2571. "Container part 'Program Input Signature' does not match expected for module.",
  2572. "Container part 'Program Output Signature' does not match expected for module.",
  2573. "Container part 'Program Patch Constant Signature' does not match expected for module.",
  2574. "Validation failed."
  2575. }
  2576. );
  2577. }
  2578. TEST_F(ValidationTest, WhenProgramInSigMissingThenFail) {
  2579. ReplaceContainerPartsCheckMsgs(
  2580. VERTEX_STRUCT1
  2581. PC_STRUCT1
  2582. PC_FUNC
  2583. HS_ATTR
  2584. HS_FUNC,
  2585. // Compiling the HS_FUNC_NOIN produces the following error
  2586. //error: validation errors
  2587. //HS input control point count must be [1..32]. 0 specified
  2588. VERTEX_STRUCT1
  2589. PC_STRUCT1
  2590. PC_FUNC_NOIN
  2591. HS_ATTR
  2592. HS_FUNC_NOIN,
  2593. "hs_6_0",
  2594. {DFCC_InputSignature, DFCC_OutputSignature, DFCC_PatchConstantSignature},
  2595. {
  2596. "Container part 'Program Input Signature' does not match expected for module.",
  2597. "Validation failed."
  2598. }
  2599. );
  2600. }
  2601. TEST_F(ValidationTest, WhenProgramSigMismatchThenFail2) {
  2602. ReplaceContainerPartsCheckMsgs(
  2603. VERTEX_STRUCT1
  2604. PC_STRUCT1
  2605. DS_FUNC,
  2606. VERTEX_STRUCT2
  2607. PC_STRUCT2
  2608. DS_FUNC,
  2609. "ds_6_0",
  2610. {DFCC_InputSignature, DFCC_OutputSignature, DFCC_PatchConstantSignature},
  2611. {
  2612. "Container part 'Program Input Signature' does not match expected for module.",
  2613. "Container part 'Program Output Signature' does not match expected for module.",
  2614. "Container part 'Program Patch Constant Signature' does not match expected for module.",
  2615. "Validation failed."
  2616. }
  2617. );
  2618. }
  2619. TEST_F(ValidationTest, WhenProgramPCSigMissingThenFail) {
  2620. ReplaceContainerPartsCheckMsgs(
  2621. VERTEX_STRUCT1
  2622. PC_STRUCT1
  2623. DS_FUNC,
  2624. VERTEX_STRUCT2
  2625. PC_STRUCT2
  2626. DS_FUNC_NOPC,
  2627. "ds_6_0",
  2628. {DFCC_InputSignature, DFCC_OutputSignature, DFCC_PatchConstantSignature},
  2629. {
  2630. "Container part 'Program Input Signature' does not match expected for module.",
  2631. "Container part 'Program Output Signature' does not match expected for module.",
  2632. "Missing part 'Program Patch Constant Signature' required by module.",
  2633. "Validation failed."
  2634. }
  2635. );
  2636. }
  2637. #undef VERTEX_STRUCT1
  2638. #undef VERTEX_STRUCT2
  2639. #undef PC_STRUCT1
  2640. #undef PC_STRUCT2
  2641. #undef PC_FUNC
  2642. #undef PC_FUNC_NOOUT
  2643. #undef PC_FUNC_NOIN
  2644. #undef HS_ATTR
  2645. #undef HS_FUNC
  2646. #undef HS_FUNC_NOOUT
  2647. #undef HS_FUNC_NOIN
  2648. #undef DS_FUNC
  2649. #undef DS_FUNC_NOPC
  2650. TEST_F(ValidationTest, WhenPSVMismatchThenFail) {
  2651. ReplaceContainerPartsCheckMsgs(
  2652. "float c; [RootSignature ( \"RootConstants(b0, num32BitConstants = 1)\" )] float4 main() : semantic { return c; }",
  2653. "[RootSignature ( \"\" )] float4 main() : semantic { return 0; }",
  2654. "vs_6_0",
  2655. {DFCC_PipelineStateValidation},
  2656. {
  2657. "Container part 'Pipeline State Validation' does not match expected for module.",
  2658. "Validation failed."
  2659. }
  2660. );
  2661. }
  2662. TEST_F(ValidationTest, WhenFeatureInfoMismatchThenFail) {
  2663. ReplaceContainerPartsCheckMsgs(
  2664. "float4 main(uint2 foo : FOO) : SV_Target { return asdouble(foo.x, foo.y) * 2.0; }",
  2665. "float4 main() : SV_Target { return 0; }",
  2666. "ps_6_0",
  2667. {DFCC_FeatureInfo},
  2668. {
  2669. "Container part 'Feature Info' does not match expected for module.",
  2670. "Validation failed."
  2671. }
  2672. );
  2673. }
  2674. TEST_F(ValidationTest, ViewIDInCSFail) {
  2675. RewriteAssemblyCheckMsg(" \
  2676. RWStructuredBuffer<uint> Buf; \
  2677. [numthreads(1,1,1)] \
  2678. void main(uint id : SV_GroupIndex) \
  2679. { Buf[id] = 0; } \
  2680. ",
  2681. "cs_6_1",
  2682. {"dx.op.flattenedThreadIdInGroup.i32(i32 96",
  2683. "declare i32 @dx.op.flattenedThreadIdInGroup.i32(i32)"},
  2684. {"dx.op.viewID.i32(i32 142",
  2685. "declare i32 @dx.op.viewID.i32(i32)"},
  2686. "Opcode ViewID not valid in shader model cs_6_1",
  2687. /*bRegex*/false);
  2688. }
  2689. TEST_F(ValidationTest, ViewIDIn60Fail) {
  2690. RewriteAssemblyCheckMsg(" \
  2691. [domain(\"tri\")] \
  2692. float4 main(float3 pos : Position, uint id : SV_PrimitiveID) : SV_Position \
  2693. { return float4(pos, id); } \
  2694. ",
  2695. "ds_6_0",
  2696. {"dx.op.primitiveID.i32(i32 108",
  2697. "declare i32 @dx.op.primitiveID.i32(i32)"},
  2698. {"dx.op.viewID.i32(i32 142",
  2699. "declare i32 @dx.op.viewID.i32(i32)"},
  2700. "Opcode ViewID not valid in shader model ds_6_0",
  2701. /*bRegex*/false);
  2702. }
  2703. TEST_F(ValidationTest, ViewIDNoSpaceFail) {
  2704. RewriteAssemblyCheckMsg(" \
  2705. float4 main(uint vid : SV_ViewID, float3 In[31] : INPUT) : SV_Target \
  2706. { return float4(In[vid], 1); } \
  2707. ",
  2708. "ps_6_1",
  2709. {"!{i32 0, !\"INPUT\", i8 9, i8 0, !([0-9]+), i8 2, i32 31",
  2710. "!{i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30}"},
  2711. {"!{i32 0, !\"INPUT\", i8 9, i8 0, !\\1, i8 2, i32 32",
  2712. "!{i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 24, i32 25, i32 26, i32 27, i32 28, i32 29, i32 30, i32 31}"},
  2713. "Pixel shader input signature lacks available space for ViewID",
  2714. /*bRegex*/true);
  2715. }
  2716. // TODO: reject non-zero padding