ValidationTest.cpp 106 KB

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