DxilOperations.cpp 127 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // DxilOperations.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. // Implementation of DXIL operation tables. //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #include "dxc/DXIL/DxilOperations.h"
  12. #include "dxc/Support/Global.h"
  13. #include "dxc/DXIL/DxilModule.h"
  14. #include "dxc/DXIL/DxilInstructions.h"
  15. #include "llvm/Support/raw_ostream.h"
  16. #include "llvm/ADT/ArrayRef.h"
  17. #include "llvm/IR/LLVMContext.h"
  18. #include "llvm/IR/Module.h"
  19. #include "llvm/IR/Type.h"
  20. #include "llvm/IR/Constants.h"
  21. #include "llvm/IR/Instructions.h"
  22. using namespace llvm;
  23. using std::vector;
  24. using std::string;
  25. namespace hlsl {
  26. using OC = OP::OpCode;
  27. using OCC = OP::OpCodeClass;
  28. //------------------------------------------------------------------------------
  29. //
  30. // OP class const-static data and related static methods.
  31. //
  32. /* <py>
  33. import hctdb_instrhelp
  34. </py> */
  35. /* <py::lines('OPCODE-OLOADS')>hctdb_instrhelp.get_oloads_props()</py>*/
  36. // OPCODE-OLOADS:BEGIN
  37. const OP::OpCodeProperty OP::m_OpCodeProps[(unsigned)OP::OpCode::NumOpCodes] = {
  38. // OpCode OpCode name, OpCodeClass OpCodeClass name, void, h, f, d, i1, i8, i16, i32, i64, udt, obj, function attribute
  39. // Temporary, indexable, input, output registers void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  40. { OC::TempRegLoad, "TempRegLoad", OCC::TempRegLoad, "tempRegLoad", { false, true, true, false, false, false, true, true, false, false, false}, Attribute::ReadOnly, },
  41. { OC::TempRegStore, "TempRegStore", OCC::TempRegStore, "tempRegStore", { false, true, true, false, false, false, true, true, false, false, false}, Attribute::None, },
  42. { OC::MinPrecXRegLoad, "MinPrecXRegLoad", OCC::MinPrecXRegLoad, "minPrecXRegLoad", { false, true, false, false, false, false, true, false, false, false, false}, Attribute::ReadOnly, },
  43. { OC::MinPrecXRegStore, "MinPrecXRegStore", OCC::MinPrecXRegStore, "minPrecXRegStore", { false, true, false, false, false, false, true, false, false, false, false}, Attribute::None, },
  44. { OC::LoadInput, "LoadInput", OCC::LoadInput, "loadInput", { false, true, true, false, false, false, true, true, false, false, false}, Attribute::ReadNone, },
  45. { OC::StoreOutput, "StoreOutput", OCC::StoreOutput, "storeOutput", { false, true, true, false, false, false, true, true, false, false, false}, Attribute::None, },
  46. // Unary float void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  47. { OC::FAbs, "FAbs", OCC::Unary, "unary", { false, true, true, true, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  48. { OC::Saturate, "Saturate", OCC::Unary, "unary", { false, true, true, true, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  49. { OC::IsNaN, "IsNaN", OCC::IsSpecialFloat, "isSpecialFloat", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  50. { OC::IsInf, "IsInf", OCC::IsSpecialFloat, "isSpecialFloat", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  51. { OC::IsFinite, "IsFinite", OCC::IsSpecialFloat, "isSpecialFloat", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  52. { OC::IsNormal, "IsNormal", OCC::IsSpecialFloat, "isSpecialFloat", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  53. { OC::Cos, "Cos", OCC::Unary, "unary", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  54. { OC::Sin, "Sin", OCC::Unary, "unary", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  55. { OC::Tan, "Tan", OCC::Unary, "unary", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  56. { OC::Acos, "Acos", OCC::Unary, "unary", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  57. { OC::Asin, "Asin", OCC::Unary, "unary", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  58. { OC::Atan, "Atan", OCC::Unary, "unary", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  59. { OC::Hcos, "Hcos", OCC::Unary, "unary", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  60. { OC::Hsin, "Hsin", OCC::Unary, "unary", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  61. { OC::Htan, "Htan", OCC::Unary, "unary", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  62. { OC::Exp, "Exp", OCC::Unary, "unary", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  63. { OC::Frc, "Frc", OCC::Unary, "unary", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  64. { OC::Log, "Log", OCC::Unary, "unary", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  65. { OC::Sqrt, "Sqrt", OCC::Unary, "unary", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  66. { OC::Rsqrt, "Rsqrt", OCC::Unary, "unary", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  67. // Unary float - rounding void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  68. { OC::Round_ne, "Round_ne", OCC::Unary, "unary", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  69. { OC::Round_ni, "Round_ni", OCC::Unary, "unary", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  70. { OC::Round_pi, "Round_pi", OCC::Unary, "unary", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  71. { OC::Round_z, "Round_z", OCC::Unary, "unary", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  72. // Unary int void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  73. { OC::Bfrev, "Bfrev", OCC::Unary, "unary", { false, false, false, false, false, false, true, true, true, false, false}, Attribute::ReadNone, },
  74. { OC::Countbits, "Countbits", OCC::UnaryBits, "unaryBits", { false, false, false, false, false, false, true, true, true, false, false}, Attribute::ReadNone, },
  75. { OC::FirstbitLo, "FirstbitLo", OCC::UnaryBits, "unaryBits", { false, false, false, false, false, false, true, true, true, false, false}, Attribute::ReadNone, },
  76. // Unary uint void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  77. { OC::FirstbitHi, "FirstbitHi", OCC::UnaryBits, "unaryBits", { false, false, false, false, false, false, true, true, true, false, false}, Attribute::ReadNone, },
  78. // Unary int void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  79. { OC::FirstbitSHi, "FirstbitSHi", OCC::UnaryBits, "unaryBits", { false, false, false, false, false, false, true, true, true, false, false}, Attribute::ReadNone, },
  80. // Binary float void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  81. { OC::FMax, "FMax", OCC::Binary, "binary", { false, true, true, true, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  82. { OC::FMin, "FMin", OCC::Binary, "binary", { false, true, true, true, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  83. // Binary int void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  84. { OC::IMax, "IMax", OCC::Binary, "binary", { false, false, false, false, false, false, true, true, true, false, false}, Attribute::ReadNone, },
  85. { OC::IMin, "IMin", OCC::Binary, "binary", { false, false, false, false, false, false, true, true, true, false, false}, Attribute::ReadNone, },
  86. // Binary uint void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  87. { OC::UMax, "UMax", OCC::Binary, "binary", { false, false, false, false, false, false, true, true, true, false, false}, Attribute::ReadNone, },
  88. { OC::UMin, "UMin", OCC::Binary, "binary", { false, false, false, false, false, false, true, true, true, false, false}, Attribute::ReadNone, },
  89. // Binary int with two outputs void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  90. { OC::IMul, "IMul", OCC::BinaryWithTwoOuts, "binaryWithTwoOuts", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  91. // Binary uint with two outputs void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  92. { OC::UMul, "UMul", OCC::BinaryWithTwoOuts, "binaryWithTwoOuts", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  93. { OC::UDiv, "UDiv", OCC::BinaryWithTwoOuts, "binaryWithTwoOuts", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  94. // Binary uint with carry or borrow void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  95. { OC::UAddc, "UAddc", OCC::BinaryWithCarryOrBorrow, "binaryWithCarryOrBorrow", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  96. { OC::USubb, "USubb", OCC::BinaryWithCarryOrBorrow, "binaryWithCarryOrBorrow", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  97. // Tertiary float void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  98. { OC::FMad, "FMad", OCC::Tertiary, "tertiary", { false, true, true, true, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  99. { OC::Fma, "Fma", OCC::Tertiary, "tertiary", { false, false, false, true, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  100. // Tertiary int void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  101. { OC::IMad, "IMad", OCC::Tertiary, "tertiary", { false, false, false, false, false, false, true, true, true, false, false}, Attribute::ReadNone, },
  102. // Tertiary uint void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  103. { OC::UMad, "UMad", OCC::Tertiary, "tertiary", { false, false, false, false, false, false, true, true, true, false, false}, Attribute::ReadNone, },
  104. // Tertiary int void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  105. { OC::Msad, "Msad", OCC::Tertiary, "tertiary", { false, false, false, false, false, false, false, true, true, false, false}, Attribute::ReadNone, },
  106. { OC::Ibfe, "Ibfe", OCC::Tertiary, "tertiary", { false, false, false, false, false, false, false, true, true, false, false}, Attribute::ReadNone, },
  107. // Tertiary uint void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  108. { OC::Ubfe, "Ubfe", OCC::Tertiary, "tertiary", { false, false, false, false, false, false, false, true, true, false, false}, Attribute::ReadNone, },
  109. // Quaternary void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  110. { OC::Bfi, "Bfi", OCC::Quaternary, "quaternary", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  111. // Dot void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  112. { OC::Dot2, "Dot2", OCC::Dot2, "dot2", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  113. { OC::Dot3, "Dot3", OCC::Dot3, "dot3", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  114. { OC::Dot4, "Dot4", OCC::Dot4, "dot4", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  115. // Resources void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  116. { OC::CreateHandle, "CreateHandle", OCC::CreateHandle, "createHandle", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  117. { OC::CBufferLoad, "CBufferLoad", OCC::CBufferLoad, "cbufferLoad", { false, true, true, true, false, true, true, true, true, false, false}, Attribute::ReadOnly, },
  118. { OC::CBufferLoadLegacy, "CBufferLoadLegacy", OCC::CBufferLoadLegacy, "cbufferLoadLegacy", { false, true, true, true, false, false, true, true, true, false, false}, Attribute::ReadOnly, },
  119. // Resources - sample void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  120. { OC::Sample, "Sample", OCC::Sample, "sample", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  121. { OC::SampleBias, "SampleBias", OCC::SampleBias, "sampleBias", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  122. { OC::SampleLevel, "SampleLevel", OCC::SampleLevel, "sampleLevel", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  123. { OC::SampleGrad, "SampleGrad", OCC::SampleGrad, "sampleGrad", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  124. { OC::SampleCmp, "SampleCmp", OCC::SampleCmp, "sampleCmp", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  125. { OC::SampleCmpLevelZero, "SampleCmpLevelZero", OCC::SampleCmpLevelZero, "sampleCmpLevelZero", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  126. // Resources void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  127. { OC::TextureLoad, "TextureLoad", OCC::TextureLoad, "textureLoad", { false, true, true, false, false, false, true, true, false, false, false}, Attribute::ReadOnly, },
  128. { OC::TextureStore, "TextureStore", OCC::TextureStore, "textureStore", { false, true, true, false, false, false, true, true, false, false, false}, Attribute::None, },
  129. { OC::BufferLoad, "BufferLoad", OCC::BufferLoad, "bufferLoad", { false, true, true, false, false, false, true, true, false, false, false}, Attribute::ReadOnly, },
  130. { OC::BufferStore, "BufferStore", OCC::BufferStore, "bufferStore", { false, true, true, false, false, false, true, true, false, false, false}, Attribute::None, },
  131. { OC::BufferUpdateCounter, "BufferUpdateCounter", OCC::BufferUpdateCounter, "bufferUpdateCounter", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  132. { OC::CheckAccessFullyMapped, "CheckAccessFullyMapped", OCC::CheckAccessFullyMapped, "checkAccessFullyMapped", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadOnly, },
  133. { OC::GetDimensions, "GetDimensions", OCC::GetDimensions, "getDimensions", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  134. // Resources - gather void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  135. { OC::TextureGather, "TextureGather", OCC::TextureGather, "textureGather", { false, true, true, false, false, false, true, true, false, false, false}, Attribute::ReadOnly, },
  136. { OC::TextureGatherCmp, "TextureGatherCmp", OCC::TextureGatherCmp, "textureGatherCmp", { false, true, true, false, false, false, true, true, false, false, false}, Attribute::ReadOnly, },
  137. // Resources - sample void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  138. { OC::Texture2DMSGetSamplePosition, "Texture2DMSGetSamplePosition", OCC::Texture2DMSGetSamplePosition, "texture2DMSGetSamplePosition", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  139. { OC::RenderTargetGetSamplePosition, "RenderTargetGetSamplePosition", OCC::RenderTargetGetSamplePosition, "renderTargetGetSamplePosition", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  140. { OC::RenderTargetGetSampleCount, "RenderTargetGetSampleCount", OCC::RenderTargetGetSampleCount, "renderTargetGetSampleCount", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  141. // Synchronization void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  142. { OC::AtomicBinOp, "AtomicBinOp", OCC::AtomicBinOp, "atomicBinOp", { false, false, false, false, false, false, false, true, true, false, false}, Attribute::None, },
  143. { OC::AtomicCompareExchange, "AtomicCompareExchange", OCC::AtomicCompareExchange, "atomicCompareExchange", { false, false, false, false, false, false, false, true, true, false, false}, Attribute::None, },
  144. { OC::Barrier, "Barrier", OCC::Barrier, "barrier", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::NoDuplicate, },
  145. // Derivatives void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  146. { OC::CalculateLOD, "CalculateLOD", OCC::CalculateLOD, "calculateLOD", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  147. // Pixel shader void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  148. { OC::Discard, "Discard", OCC::Discard, "discard", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  149. // Derivatives void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  150. { OC::DerivCoarseX, "DerivCoarseX", OCC::Unary, "unary", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  151. { OC::DerivCoarseY, "DerivCoarseY", OCC::Unary, "unary", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  152. { OC::DerivFineX, "DerivFineX", OCC::Unary, "unary", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  153. { OC::DerivFineY, "DerivFineY", OCC::Unary, "unary", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  154. // Pixel shader void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  155. { OC::EvalSnapped, "EvalSnapped", OCC::EvalSnapped, "evalSnapped", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  156. { OC::EvalSampleIndex, "EvalSampleIndex", OCC::EvalSampleIndex, "evalSampleIndex", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  157. { OC::EvalCentroid, "EvalCentroid", OCC::EvalCentroid, "evalCentroid", { false, true, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  158. { OC::SampleIndex, "SampleIndex", OCC::SampleIndex, "sampleIndex", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  159. { OC::Coverage, "Coverage", OCC::Coverage, "coverage", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  160. { OC::InnerCoverage, "InnerCoverage", OCC::InnerCoverage, "innerCoverage", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  161. // Compute/Mesh/Amplification shader void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  162. { OC::ThreadId, "ThreadId", OCC::ThreadId, "threadId", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  163. { OC::GroupId, "GroupId", OCC::GroupId, "groupId", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  164. { OC::ThreadIdInGroup, "ThreadIdInGroup", OCC::ThreadIdInGroup, "threadIdInGroup", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  165. { OC::FlattenedThreadIdInGroup, "FlattenedThreadIdInGroup", OCC::FlattenedThreadIdInGroup, "flattenedThreadIdInGroup", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  166. // Geometry shader void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  167. { OC::EmitStream, "EmitStream", OCC::EmitStream, "emitStream", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  168. { OC::CutStream, "CutStream", OCC::CutStream, "cutStream", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  169. { OC::EmitThenCutStream, "EmitThenCutStream", OCC::EmitThenCutStream, "emitThenCutStream", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  170. { OC::GSInstanceID, "GSInstanceID", OCC::GSInstanceID, "gsInstanceID", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  171. // Double precision void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  172. { OC::MakeDouble, "MakeDouble", OCC::MakeDouble, "makeDouble", { false, false, false, true, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  173. { OC::SplitDouble, "SplitDouble", OCC::SplitDouble, "splitDouble", { false, false, false, true, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  174. // Domain and hull shader void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  175. { OC::LoadOutputControlPoint, "LoadOutputControlPoint", OCC::LoadOutputControlPoint, "loadOutputControlPoint", { false, true, true, false, false, false, true, true, false, false, false}, Attribute::ReadNone, },
  176. { OC::LoadPatchConstant, "LoadPatchConstant", OCC::LoadPatchConstant, "loadPatchConstant", { false, true, true, false, false, false, true, true, false, false, false}, Attribute::ReadNone, },
  177. // Domain shader void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  178. { OC::DomainLocation, "DomainLocation", OCC::DomainLocation, "domainLocation", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  179. // Hull shader void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  180. { OC::StorePatchConstant, "StorePatchConstant", OCC::StorePatchConstant, "storePatchConstant", { false, true, true, false, false, false, true, true, false, false, false}, Attribute::None, },
  181. { OC::OutputControlPointID, "OutputControlPointID", OCC::OutputControlPointID, "outputControlPointID", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  182. // Hull, Domain and Geometry shaders void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  183. { OC::PrimitiveID, "PrimitiveID", OCC::PrimitiveID, "primitiveID", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  184. // Other void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  185. { OC::CycleCounterLegacy, "CycleCounterLegacy", OCC::CycleCounterLegacy, "cycleCounterLegacy", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  186. // Wave void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  187. { OC::WaveIsFirstLane, "WaveIsFirstLane", OCC::WaveIsFirstLane, "waveIsFirstLane", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  188. { OC::WaveGetLaneIndex, "WaveGetLaneIndex", OCC::WaveGetLaneIndex, "waveGetLaneIndex", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  189. { OC::WaveGetLaneCount, "WaveGetLaneCount", OCC::WaveGetLaneCount, "waveGetLaneCount", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  190. { OC::WaveAnyTrue, "WaveAnyTrue", OCC::WaveAnyTrue, "waveAnyTrue", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  191. { OC::WaveAllTrue, "WaveAllTrue", OCC::WaveAllTrue, "waveAllTrue", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  192. { OC::WaveActiveAllEqual, "WaveActiveAllEqual", OCC::WaveActiveAllEqual, "waveActiveAllEqual", { false, true, true, true, true, true, true, true, true, false, false}, Attribute::None, },
  193. { OC::WaveActiveBallot, "WaveActiveBallot", OCC::WaveActiveBallot, "waveActiveBallot", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  194. { OC::WaveReadLaneAt, "WaveReadLaneAt", OCC::WaveReadLaneAt, "waveReadLaneAt", { false, true, true, true, true, true, true, true, true, false, false}, Attribute::None, },
  195. { OC::WaveReadLaneFirst, "WaveReadLaneFirst", OCC::WaveReadLaneFirst, "waveReadLaneFirst", { false, true, true, true, true, true, true, true, true, false, false}, Attribute::None, },
  196. { OC::WaveActiveOp, "WaveActiveOp", OCC::WaveActiveOp, "waveActiveOp", { false, true, true, true, true, true, true, true, true, false, false}, Attribute::None, },
  197. { OC::WaveActiveBit, "WaveActiveBit", OCC::WaveActiveBit, "waveActiveBit", { false, false, false, false, false, true, true, true, true, false, false}, Attribute::None, },
  198. { OC::WavePrefixOp, "WavePrefixOp", OCC::WavePrefixOp, "wavePrefixOp", { false, true, true, true, false, true, true, true, true, false, false}, Attribute::None, },
  199. // Quad Wave Ops void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  200. { OC::QuadReadLaneAt, "QuadReadLaneAt", OCC::QuadReadLaneAt, "quadReadLaneAt", { false, true, true, true, true, true, true, true, true, false, false}, Attribute::None, },
  201. { OC::QuadOp, "QuadOp", OCC::QuadOp, "quadOp", { false, true, true, true, false, true, true, true, true, false, false}, Attribute::None, },
  202. // Bitcasts with different sizes void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  203. { OC::BitcastI16toF16, "BitcastI16toF16", OCC::BitcastI16toF16, "bitcastI16toF16", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  204. { OC::BitcastF16toI16, "BitcastF16toI16", OCC::BitcastF16toI16, "bitcastF16toI16", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  205. { OC::BitcastI32toF32, "BitcastI32toF32", OCC::BitcastI32toF32, "bitcastI32toF32", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  206. { OC::BitcastF32toI32, "BitcastF32toI32", OCC::BitcastF32toI32, "bitcastF32toI32", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  207. { OC::BitcastI64toF64, "BitcastI64toF64", OCC::BitcastI64toF64, "bitcastI64toF64", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  208. { OC::BitcastF64toI64, "BitcastF64toI64", OCC::BitcastF64toI64, "bitcastF64toI64", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  209. // Legacy floating-point void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  210. { OC::LegacyF32ToF16, "LegacyF32ToF16", OCC::LegacyF32ToF16, "legacyF32ToF16", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  211. { OC::LegacyF16ToF32, "LegacyF16ToF32", OCC::LegacyF16ToF32, "legacyF16ToF32", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  212. // Double precision void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  213. { OC::LegacyDoubleToFloat, "LegacyDoubleToFloat", OCC::LegacyDoubleToFloat, "legacyDoubleToFloat", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  214. { OC::LegacyDoubleToSInt32, "LegacyDoubleToSInt32", OCC::LegacyDoubleToSInt32, "legacyDoubleToSInt32", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  215. { OC::LegacyDoubleToUInt32, "LegacyDoubleToUInt32", OCC::LegacyDoubleToUInt32, "legacyDoubleToUInt32", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  216. // Wave void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  217. { OC::WaveAllBitCount, "WaveAllBitCount", OCC::WaveAllOp, "waveAllOp", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  218. { OC::WavePrefixBitCount, "WavePrefixBitCount", OCC::WavePrefixOp, "wavePrefixOp", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  219. // Pixel shader void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  220. { OC::AttributeAtVertex, "AttributeAtVertex", OCC::AttributeAtVertex, "attributeAtVertex", { false, true, true, false, false, false, true, true, false, false, false}, Attribute::ReadNone, },
  221. // Graphics shader void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  222. { OC::ViewID, "ViewID", OCC::ViewID, "viewID", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  223. // Resources void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  224. { OC::RawBufferLoad, "RawBufferLoad", OCC::RawBufferLoad, "rawBufferLoad", { false, true, true, true, false, false, true, true, true, false, false}, Attribute::ReadOnly, },
  225. { OC::RawBufferStore, "RawBufferStore", OCC::RawBufferStore, "rawBufferStore", { false, true, true, true, false, false, true, true, true, false, false}, Attribute::None, },
  226. // Raytracing object space uint System Values void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  227. { OC::InstanceID, "InstanceID", OCC::InstanceID, "instanceID", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  228. { OC::InstanceIndex, "InstanceIndex", OCC::InstanceIndex, "instanceIndex", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  229. // Raytracing hit uint System Values void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  230. { OC::HitKind, "HitKind", OCC::HitKind, "hitKind", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  231. // Raytracing uint System Values void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  232. { OC::RayFlags, "RayFlags", OCC::RayFlags, "rayFlags", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  233. // Ray Dispatch Arguments void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  234. { OC::DispatchRaysIndex, "DispatchRaysIndex", OCC::DispatchRaysIndex, "dispatchRaysIndex", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  235. { OC::DispatchRaysDimensions, "DispatchRaysDimensions", OCC::DispatchRaysDimensions, "dispatchRaysDimensions", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  236. // Ray Vectors void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  237. { OC::WorldRayOrigin, "WorldRayOrigin", OCC::WorldRayOrigin, "worldRayOrigin", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  238. { OC::WorldRayDirection, "WorldRayDirection", OCC::WorldRayDirection, "worldRayDirection", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  239. // Ray object space Vectors void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  240. { OC::ObjectRayOrigin, "ObjectRayOrigin", OCC::ObjectRayOrigin, "objectRayOrigin", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  241. { OC::ObjectRayDirection, "ObjectRayDirection", OCC::ObjectRayDirection, "objectRayDirection", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  242. // Ray Transforms void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  243. { OC::ObjectToWorld, "ObjectToWorld", OCC::ObjectToWorld, "objectToWorld", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  244. { OC::WorldToObject, "WorldToObject", OCC::WorldToObject, "worldToObject", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  245. // RayT void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  246. { OC::RayTMin, "RayTMin", OCC::RayTMin, "rayTMin", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  247. { OC::RayTCurrent, "RayTCurrent", OCC::RayTCurrent, "rayTCurrent", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  248. // AnyHit Terminals void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  249. { OC::IgnoreHit, "IgnoreHit", OCC::IgnoreHit, "ignoreHit", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::NoReturn, },
  250. { OC::AcceptHitAndEndSearch, "AcceptHitAndEndSearch", OCC::AcceptHitAndEndSearch, "acceptHitAndEndSearch", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::NoReturn, },
  251. // Indirect Shader Invocation void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  252. { OC::TraceRay, "TraceRay", OCC::TraceRay, "traceRay", { false, false, false, false, false, false, false, false, false, true, false}, Attribute::None, },
  253. { OC::ReportHit, "ReportHit", OCC::ReportHit, "reportHit", { false, false, false, false, false, false, false, false, false, true, false}, Attribute::None, },
  254. { OC::CallShader, "CallShader", OCC::CallShader, "callShader", { false, false, false, false, false, false, false, false, false, true, false}, Attribute::None, },
  255. // Library create handle from resource struct (like HL intrinsic) void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  256. { OC::CreateHandleForLib, "CreateHandleForLib", OCC::CreateHandleForLib, "createHandleForLib", { false, false, false, false, false, false, false, false, false, false, true}, Attribute::ReadOnly, },
  257. // Raytracing object space uint System Values void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  258. { OC::PrimitiveIndex, "PrimitiveIndex", OCC::PrimitiveIndex, "primitiveIndex", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  259. // Dot product with accumulate void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  260. { OC::Dot2AddHalf, "Dot2AddHalf", OCC::Dot2AddHalf, "dot2AddHalf", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  261. { OC::Dot4AddI8Packed, "Dot4AddI8Packed", OCC::Dot4AddPacked, "dot4AddPacked", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  262. { OC::Dot4AddU8Packed, "Dot4AddU8Packed", OCC::Dot4AddPacked, "dot4AddPacked", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  263. // Wave void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  264. { OC::WaveMatch, "WaveMatch", OCC::WaveMatch, "waveMatch", { false, true, true, true, false, true, true, true, true, false, false}, Attribute::None, },
  265. { OC::WaveMultiPrefixOp, "WaveMultiPrefixOp", OCC::WaveMultiPrefixOp, "waveMultiPrefixOp", { false, true, true, true, false, true, true, true, true, false, false}, Attribute::None, },
  266. { OC::WaveMultiPrefixBitCount, "WaveMultiPrefixBitCount", OCC::WaveMultiPrefixBitCount, "waveMultiPrefixBitCount", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  267. // Mesh shader instructions void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  268. { OC::SetMeshOutputCounts, "SetMeshOutputCounts", OCC::SetMeshOutputCounts, "setMeshOutputCounts", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  269. { OC::EmitIndices, "EmitIndices", OCC::EmitIndices, "emitIndices", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  270. { OC::GetMeshPayload, "GetMeshPayload", OCC::GetMeshPayload, "getMeshPayload", { false, false, false, false, false, false, false, false, false, true, false}, Attribute::ReadOnly, },
  271. { OC::StoreVertexOutput, "StoreVertexOutput", OCC::StoreVertexOutput, "storeVertexOutput", { false, true, true, false, false, false, true, true, false, false, false}, Attribute::None, },
  272. { OC::StorePrimitiveOutput, "StorePrimitiveOutput", OCC::StorePrimitiveOutput, "storePrimitiveOutput", { false, true, true, false, false, false, true, true, false, false, false}, Attribute::None, },
  273. // Amplification shader instructions void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  274. { OC::DispatchMesh, "DispatchMesh", OCC::DispatchMesh, "dispatchMesh", { false, false, false, false, false, false, false, false, false, true, false}, Attribute::None, },
  275. // Sampler Feedback void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  276. { OC::WriteSamplerFeedback, "WriteSamplerFeedback", OCC::WriteSamplerFeedback, "writeSamplerFeedback", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  277. { OC::WriteSamplerFeedbackBias, "WriteSamplerFeedbackBias", OCC::WriteSamplerFeedbackBias, "writeSamplerFeedbackBias", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  278. { OC::WriteSamplerFeedbackLevel, "WriteSamplerFeedbackLevel", OCC::WriteSamplerFeedbackLevel, "writeSamplerFeedbackLevel", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  279. { OC::WriteSamplerFeedbackGrad, "WriteSamplerFeedbackGrad", OCC::WriteSamplerFeedbackGrad, "writeSamplerFeedbackGrad", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  280. // Inline Ray Query void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  281. { OC::AllocateRayQuery, "AllocateRayQuery", OCC::AllocateRayQuery, "allocateRayQuery", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  282. { OC::RayQuery_TraceRayInline, "RayQuery_TraceRayInline", OCC::RayQuery_TraceRayInline, "rayQuery_TraceRayInline", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  283. { OC::RayQuery_Proceed, "RayQuery_Proceed", OCC::RayQuery_Proceed, "rayQuery_Proceed", { false, false, false, false, true, false, false, false, false, false, false}, Attribute::None, },
  284. { OC::RayQuery_Abort, "RayQuery_Abort", OCC::RayQuery_Abort, "rayQuery_Abort", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  285. { OC::RayQuery_CommitNonOpaqueTriangleHit, "RayQuery_CommitNonOpaqueTriangleHit", OCC::RayQuery_CommitNonOpaqueTriangleHit, "rayQuery_CommitNonOpaqueTriangleHit", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  286. { OC::RayQuery_CommitProceduralPrimitiveHit, "RayQuery_CommitProceduralPrimitiveHit", OCC::RayQuery_CommitProceduralPrimitiveHit, "rayQuery_CommitProceduralPrimitiveHit", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::None, },
  287. { OC::RayQuery_CommittedStatus, "RayQuery_CommittedStatus", OCC::RayQuery_StateScalar, "rayQuery_StateScalar", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadOnly, },
  288. { OC::RayQuery_CandidateType, "RayQuery_CandidateType", OCC::RayQuery_StateScalar, "rayQuery_StateScalar", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadOnly, },
  289. { OC::RayQuery_CandidateObjectToWorld3x4, "RayQuery_CandidateObjectToWorld3x4", OCC::RayQuery_StateMatrix, "rayQuery_StateMatrix", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  290. { OC::RayQuery_CandidateWorldToObject3x4, "RayQuery_CandidateWorldToObject3x4", OCC::RayQuery_StateMatrix, "rayQuery_StateMatrix", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  291. { OC::RayQuery_CommittedObjectToWorld3x4, "RayQuery_CommittedObjectToWorld3x4", OCC::RayQuery_StateMatrix, "rayQuery_StateMatrix", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  292. { OC::RayQuery_CommittedWorldToObject3x4, "RayQuery_CommittedWorldToObject3x4", OCC::RayQuery_StateMatrix, "rayQuery_StateMatrix", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  293. { OC::RayQuery_CandidateProceduralPrimitiveNonOpaque, "RayQuery_CandidateProceduralPrimitiveNonOpaque", OCC::RayQuery_StateScalar, "rayQuery_StateScalar", { false, false, false, false, true, false, false, false, false, false, false}, Attribute::ReadOnly, },
  294. { OC::RayQuery_CandidateTriangleFrontFace, "RayQuery_CandidateTriangleFrontFace", OCC::RayQuery_StateScalar, "rayQuery_StateScalar", { false, false, false, false, true, false, false, false, false, false, false}, Attribute::ReadOnly, },
  295. { OC::RayQuery_CommittedTriangleFrontFace, "RayQuery_CommittedTriangleFrontFace", OCC::RayQuery_StateScalar, "rayQuery_StateScalar", { false, false, false, false, true, false, false, false, false, false, false}, Attribute::ReadOnly, },
  296. { OC::RayQuery_CandidateTriangleBarycentrics, "RayQuery_CandidateTriangleBarycentrics", OCC::RayQuery_StateVector, "rayQuery_StateVector", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  297. { OC::RayQuery_CommittedTriangleBarycentrics, "RayQuery_CommittedTriangleBarycentrics", OCC::RayQuery_StateVector, "rayQuery_StateVector", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  298. { OC::RayQuery_RayFlags, "RayQuery_RayFlags", OCC::RayQuery_StateScalar, "rayQuery_StateScalar", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadOnly, },
  299. { OC::RayQuery_WorldRayOrigin, "RayQuery_WorldRayOrigin", OCC::RayQuery_StateVector, "rayQuery_StateVector", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  300. { OC::RayQuery_WorldRayDirection, "RayQuery_WorldRayDirection", OCC::RayQuery_StateVector, "rayQuery_StateVector", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  301. { OC::RayQuery_RayTMin, "RayQuery_RayTMin", OCC::RayQuery_StateScalar, "rayQuery_StateScalar", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  302. { OC::RayQuery_CandidateTriangleRayT, "RayQuery_CandidateTriangleRayT", OCC::RayQuery_StateScalar, "rayQuery_StateScalar", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  303. { OC::RayQuery_CommittedRayT, "RayQuery_CommittedRayT", OCC::RayQuery_StateScalar, "rayQuery_StateScalar", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  304. { OC::RayQuery_CandidateInstanceIndex, "RayQuery_CandidateInstanceIndex", OCC::RayQuery_StateScalar, "rayQuery_StateScalar", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadOnly, },
  305. { OC::RayQuery_CandidateInstanceID, "RayQuery_CandidateInstanceID", OCC::RayQuery_StateScalar, "rayQuery_StateScalar", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadOnly, },
  306. { OC::RayQuery_CandidateGeometryIndex, "RayQuery_CandidateGeometryIndex", OCC::RayQuery_StateScalar, "rayQuery_StateScalar", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadOnly, },
  307. { OC::RayQuery_CandidatePrimitiveIndex, "RayQuery_CandidatePrimitiveIndex", OCC::RayQuery_StateScalar, "rayQuery_StateScalar", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadOnly, },
  308. { OC::RayQuery_CandidateObjectRayOrigin, "RayQuery_CandidateObjectRayOrigin", OCC::RayQuery_StateVector, "rayQuery_StateVector", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  309. { OC::RayQuery_CandidateObjectRayDirection, "RayQuery_CandidateObjectRayDirection", OCC::RayQuery_StateVector, "rayQuery_StateVector", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  310. { OC::RayQuery_CommittedInstanceIndex, "RayQuery_CommittedInstanceIndex", OCC::RayQuery_StateScalar, "rayQuery_StateScalar", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadOnly, },
  311. { OC::RayQuery_CommittedInstanceID, "RayQuery_CommittedInstanceID", OCC::RayQuery_StateScalar, "rayQuery_StateScalar", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadOnly, },
  312. { OC::RayQuery_CommittedGeometryIndex, "RayQuery_CommittedGeometryIndex", OCC::RayQuery_StateScalar, "rayQuery_StateScalar", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadOnly, },
  313. { OC::RayQuery_CommittedPrimitiveIndex, "RayQuery_CommittedPrimitiveIndex", OCC::RayQuery_StateScalar, "rayQuery_StateScalar", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadOnly, },
  314. { OC::RayQuery_CommittedObjectRayOrigin, "RayQuery_CommittedObjectRayOrigin", OCC::RayQuery_StateVector, "rayQuery_StateVector", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  315. { OC::RayQuery_CommittedObjectRayDirection, "RayQuery_CommittedObjectRayDirection", OCC::RayQuery_StateVector, "rayQuery_StateVector", { false, false, true, false, false, false, false, false, false, false, false}, Attribute::ReadOnly, },
  316. // Raytracing object space uint System Values, raytracing tier 1.1 void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  317. { OC::GeometryIndex, "GeometryIndex", OCC::GeometryIndex, "geometryIndex", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadNone, },
  318. // Inline Ray Query void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  319. { OC::RayQuery_CandidateInstanceContributionToHitGroupIndex, "RayQuery_CandidateInstanceContributionToHitGroupIndex", OCC::RayQuery_StateScalar, "rayQuery_StateScalar", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadOnly, },
  320. { OC::RayQuery_CommittedInstanceContributionToHitGroupIndex, "RayQuery_CommittedInstanceContributionToHitGroupIndex", OCC::RayQuery_StateScalar, "rayQuery_StateScalar", { false, false, false, false, false, false, false, true, false, false, false}, Attribute::ReadOnly, },
  321. // Get handle from heap void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  322. { OC::AnnotateHandle, "AnnotateHandle", OCC::AnnotateHandle, "annotateHandle", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  323. { OC::CreateHandleFromBinding, "CreateHandleFromBinding", OCC::CreateHandleFromBinding, "createHandleFromBinding", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  324. { OC::CreateHandleFromHeap, "CreateHandleFromHeap", OCC::CreateHandleFromHeap, "createHandleFromHeap", { true, false, false, false, false, false, false, false, false, false, false}, Attribute::ReadNone, },
  325. // Unpacking intrinsics void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  326. { OC::Unpack4x8, "Unpack4x8", OCC::Unpack4x8, "unpack4x8", { false, false, false, false, false, false, true, true, false, false, false}, Attribute::ReadNone, },
  327. // Packing intrinsics void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  328. { OC::Pack4x8, "Pack4x8", OCC::Pack4x8, "pack4x8", { false, false, false, false, false, false, true, true, false, false, false}, Attribute::ReadNone, },
  329. // Helper Lanes void, h, f, d, i1, i8, i16, i32, i64, udt, obj , function attribute
  330. { OC::IsHelperLane, "IsHelperLane", OCC::IsHelperLane, "isHelperLane", { false, false, false, false, true, false, false, false, false, false, false}, Attribute::ReadOnly, },
  331. };
  332. // OPCODE-OLOADS:END
  333. const char *OP::m_OverloadTypeName[kNumTypeOverloads] = {
  334. "void", "f16", "f32", "f64", "i1", "i8", "i16", "i32", "i64", "udt",
  335. };
  336. const char *OP::m_NamePrefix = "dx.op.";
  337. const char *OP::m_TypePrefix = "dx.types.";
  338. const char *OP::m_MatrixTypePrefix = "class.matrix."; // Allowed in library
  339. // Keep sync with DXIL::AtomicBinOpCode
  340. static const char *AtomicBinOpCodeName[] = {
  341. "AtomicAdd",
  342. "AtomicAnd",
  343. "AtomicOr",
  344. "AtomicXor",
  345. "AtomicIMin",
  346. "AtomicIMax",
  347. "AtomicUMin",
  348. "AtomicUMax",
  349. "AtomicExchange",
  350. "AtomicInvalid" // Must be last.
  351. };
  352. unsigned OP::GetTypeSlot(Type *pType) {
  353. Type::TypeID T = pType->getTypeID();
  354. switch (T) {
  355. case Type::VoidTyID: return 0;
  356. case Type::HalfTyID: return 1;
  357. case Type::FloatTyID: return 2;
  358. case Type::DoubleTyID: return 3;
  359. case Type::IntegerTyID: {
  360. IntegerType *pIT = dyn_cast<IntegerType>(pType);
  361. unsigned Bits = pIT->getBitWidth();
  362. switch (Bits) {
  363. case 1: return 4;
  364. case 8: return 5;
  365. case 16: return 6;
  366. case 32: return 7;
  367. case 64: return 8;
  368. }
  369. }
  370. case Type::PointerTyID: return 9;
  371. case Type::StructTyID: return 10;
  372. default:
  373. break;
  374. }
  375. return UINT_MAX;
  376. }
  377. const char *OP::GetOverloadTypeName(unsigned TypeSlot) {
  378. DXASSERT(TypeSlot < kUserDefineTypeSlot, "otherwise caller passed OOB index");
  379. return m_OverloadTypeName[TypeSlot];
  380. }
  381. llvm::StringRef OP::GetTypeName(Type *Ty, std::string &str) {
  382. unsigned TypeSlot = OP::GetTypeSlot(Ty);
  383. if (TypeSlot < kUserDefineTypeSlot) {
  384. return GetOverloadTypeName(TypeSlot);
  385. } else if (TypeSlot == kUserDefineTypeSlot) {
  386. if (Ty->isPointerTy())
  387. Ty = Ty->getPointerElementType();
  388. StructType *ST = cast<StructType>(Ty);
  389. return ST->getStructName();
  390. } else if (TypeSlot == kObjectTypeSlot) {
  391. StructType *ST = cast<StructType>(Ty);
  392. return ST->getStructName();
  393. } else {
  394. raw_string_ostream os(str);
  395. Ty->print(os);
  396. os.flush();
  397. return str;
  398. }
  399. }
  400. llvm::StringRef OP::ConstructOverloadName(Type *Ty, DXIL::OpCode opCode,
  401. std::string &funcNameStorage) {
  402. if (Ty == Type::getVoidTy(Ty->getContext())) {
  403. funcNameStorage = (Twine(OP::m_NamePrefix) + Twine(GetOpCodeClassName(opCode))).str();
  404. } else {
  405. funcNameStorage = (Twine(OP::m_NamePrefix) + Twine(GetOpCodeClassName(opCode)) +
  406. "." + GetTypeName(Ty, funcNameStorage)).str();
  407. }
  408. return funcNameStorage;
  409. }
  410. const char *OP::GetOpCodeName(OpCode opCode) {
  411. DXASSERT(0 <= (unsigned)opCode && opCode < OpCode::NumOpCodes, "otherwise caller passed OOB index");
  412. return m_OpCodeProps[(unsigned)opCode].pOpCodeName;
  413. }
  414. const char *OP::GetAtomicOpName(DXIL::AtomicBinOpCode OpCode) {
  415. unsigned opcode = static_cast<unsigned>(OpCode);
  416. DXASSERT_LOCALVAR(opcode, opcode < static_cast<unsigned>(DXIL::AtomicBinOpCode::Invalid), "otherwise caller passed OOB index");
  417. return AtomicBinOpCodeName[static_cast<unsigned>(OpCode)];
  418. }
  419. OP::OpCodeClass OP::GetOpCodeClass(OpCode opCode) {
  420. DXASSERT(0 <= (unsigned)opCode && opCode < OpCode::NumOpCodes, "otherwise caller passed OOB index");
  421. return m_OpCodeProps[(unsigned)opCode].opCodeClass;
  422. }
  423. const char *OP::GetOpCodeClassName(OpCode opCode) {
  424. DXASSERT(0 <= (unsigned)opCode && opCode < OpCode::NumOpCodes, "otherwise caller passed OOB index");
  425. return m_OpCodeProps[(unsigned)opCode].pOpCodeClassName;
  426. }
  427. llvm::Attribute::AttrKind OP::GetMemAccessAttr(OpCode opCode) {
  428. DXASSERT(0 <= (unsigned)opCode && opCode < OpCode::NumOpCodes, "otherwise caller passed OOB index");
  429. return m_OpCodeProps[(unsigned)opCode].FuncAttr;
  430. }
  431. bool OP::IsOverloadLegal(OpCode opCode, Type *pType) {
  432. DXASSERT(0 <= (unsigned)opCode && opCode < OpCode::NumOpCodes, "otherwise caller passed OOB index");
  433. unsigned TypeSlot = GetTypeSlot(pType);
  434. return TypeSlot != UINT_MAX && m_OpCodeProps[(unsigned)opCode].bAllowOverload[TypeSlot];
  435. }
  436. bool OP::CheckOpCodeTable() {
  437. for (unsigned i = 0; i < (unsigned)OpCode::NumOpCodes; i++) {
  438. if ((unsigned)m_OpCodeProps[i].opCode != i)
  439. return false;
  440. }
  441. return true;
  442. }
  443. bool OP::IsDxilOpFuncName(StringRef name) {
  444. return name.startswith(OP::m_NamePrefix);
  445. }
  446. bool OP::IsDxilOpFunc(const llvm::Function *F) {
  447. // Test for null to allow IsDxilOpFunc(Call.getCalledFunc()) to be resilient to indirect calls
  448. if (F == nullptr || !F->hasName())
  449. return false;
  450. return IsDxilOpFuncName(F->getName());
  451. }
  452. bool OP::IsDxilOpTypeName(StringRef name) {
  453. return name.startswith(m_TypePrefix) || name.startswith(m_MatrixTypePrefix);
  454. }
  455. bool OP::IsDxilOpType(llvm::StructType *ST) {
  456. if (!ST->hasName())
  457. return false;
  458. StringRef Name = ST->getName();
  459. return IsDxilOpTypeName(Name);
  460. }
  461. bool OP::IsDupDxilOpType(llvm::StructType *ST) {
  462. if (!ST->hasName())
  463. return false;
  464. StringRef Name = ST->getName();
  465. if (!IsDxilOpTypeName(Name))
  466. return false;
  467. size_t DotPos = Name.rfind('.');
  468. if (DotPos == 0 || DotPos == StringRef::npos || Name.back() == '.' ||
  469. !isdigit(static_cast<unsigned char>(Name[DotPos + 1])))
  470. return false;
  471. return true;
  472. }
  473. StructType *OP::GetOriginalDxilOpType(llvm::StructType *ST, llvm::Module &M) {
  474. DXASSERT(IsDupDxilOpType(ST), "else should not call GetOriginalDxilOpType");
  475. StringRef Name = ST->getName();
  476. size_t DotPos = Name.rfind('.');
  477. StructType *OriginalST = M.getTypeByName(Name.substr(0, DotPos));
  478. DXASSERT(OriginalST, "else name collison without original type");
  479. DXASSERT(ST->isLayoutIdentical(OriginalST),
  480. "else invalid layout for dxil types");
  481. return OriginalST;
  482. }
  483. bool OP::IsDxilOpFuncCallInst(const llvm::Instruction *I) {
  484. const CallInst *CI = dyn_cast<CallInst>(I);
  485. if (CI == nullptr) return false;
  486. return IsDxilOpFunc(CI->getCalledFunction());
  487. }
  488. bool OP::IsDxilOpFuncCallInst(const llvm::Instruction *I, OpCode opcode) {
  489. if (!IsDxilOpFuncCallInst(I)) return false;
  490. return llvm::cast<llvm::ConstantInt>(I->getOperand(0))->getZExtValue() == (unsigned)opcode;
  491. }
  492. OP::OpCode OP::GetDxilOpFuncCallInst(const llvm::Instruction *I) {
  493. DXASSERT(IsDxilOpFuncCallInst(I), "else caller didn't call IsDxilOpFuncCallInst to check");
  494. return (OP::OpCode)llvm::cast<llvm::ConstantInt>(I->getOperand(0))->getZExtValue();
  495. }
  496. bool OP::IsDxilOpWave(OpCode C) {
  497. unsigned op = (unsigned)C;
  498. /* <py::lines('OPCODE-WAVE')>hctdb_instrhelp.get_instrs_pred("op", "is_wave")</py>*/
  499. // OPCODE-WAVE:BEGIN
  500. // Instructions: WaveIsFirstLane=110, WaveGetLaneIndex=111,
  501. // WaveGetLaneCount=112, WaveAnyTrue=113, WaveAllTrue=114,
  502. // WaveActiveAllEqual=115, WaveActiveBallot=116, WaveReadLaneAt=117,
  503. // WaveReadLaneFirst=118, WaveActiveOp=119, WaveActiveBit=120,
  504. // WavePrefixOp=121, QuadReadLaneAt=122, QuadOp=123, WaveAllBitCount=135,
  505. // WavePrefixBitCount=136, WaveMatch=165, WaveMultiPrefixOp=166,
  506. // WaveMultiPrefixBitCount=167
  507. return (110 <= op && op <= 123) || (135 <= op && op <= 136) || (165 <= op && op <= 167);
  508. // OPCODE-WAVE:END
  509. }
  510. bool OP::IsDxilOpGradient(OpCode C) {
  511. unsigned op = (unsigned)C;
  512. /* <py::lines('OPCODE-GRADIENT')>hctdb_instrhelp.get_instrs_pred("op", "is_gradient")</py>*/
  513. // OPCODE-GRADIENT:BEGIN
  514. // Instructions: Sample=60, SampleBias=61, SampleCmp=64, CalculateLOD=81,
  515. // DerivCoarseX=83, DerivCoarseY=84, DerivFineX=85, DerivFineY=86,
  516. // WriteSamplerFeedback=174, WriteSamplerFeedbackBias=175
  517. return (60 <= op && op <= 61) || op == 64 || op == 81 || (83 <= op && op <= 86) || (174 <= op && op <= 175);
  518. // OPCODE-GRADIENT:END
  519. }
  520. bool OP::IsDxilOpFeedback(OpCode C) {
  521. unsigned op = (unsigned)C;
  522. /* <py::lines('OPCODE-FEEDBACK')>hctdb_instrhelp.get_instrs_pred("op", "is_feedback")</py>*/
  523. // OPCODE-FEEDBACK:BEGIN
  524. // Instructions: WriteSamplerFeedback=174, WriteSamplerFeedbackBias=175,
  525. // WriteSamplerFeedbackLevel=176, WriteSamplerFeedbackGrad=177
  526. return (174 <= op && op <= 177);
  527. // OPCODE-FEEDBACK:END
  528. }
  529. #define SFLAG(stage) ((unsigned)1 << (unsigned)DXIL::ShaderKind::stage)
  530. void OP::GetMinShaderModelAndMask(OpCode C, bool bWithTranslation,
  531. unsigned &major, unsigned &minor,
  532. unsigned &mask) {
  533. unsigned op = (unsigned)C;
  534. // Default is 6.0, all stages
  535. major = 6; minor = 0;
  536. mask = ((unsigned)1 << (unsigned)DXIL::ShaderKind::Invalid) - 1;
  537. /* <py::lines('OPCODE-SMMASK')>hctdb_instrhelp.get_min_sm_and_mask_text()</py>*/
  538. // OPCODE-SMMASK:BEGIN
  539. // Instructions: ThreadId=93, GroupId=94, ThreadIdInGroup=95,
  540. // FlattenedThreadIdInGroup=96
  541. if ((93 <= op && op <= 96)) {
  542. mask = SFLAG(Compute) | SFLAG(Mesh) | SFLAG(Amplification);
  543. return;
  544. }
  545. // Instructions: DomainLocation=105
  546. if (op == 105) {
  547. mask = SFLAG(Domain);
  548. return;
  549. }
  550. // Instructions: LoadOutputControlPoint=103, LoadPatchConstant=104
  551. if ((103 <= op && op <= 104)) {
  552. mask = SFLAG(Domain) | SFLAG(Hull);
  553. return;
  554. }
  555. // Instructions: EmitStream=97, CutStream=98, EmitThenCutStream=99,
  556. // GSInstanceID=100
  557. if ((97 <= op && op <= 100)) {
  558. mask = SFLAG(Geometry);
  559. return;
  560. }
  561. // Instructions: PrimitiveID=108
  562. if (op == 108) {
  563. mask = SFLAG(Geometry) | SFLAG(Domain) | SFLAG(Hull);
  564. return;
  565. }
  566. // Instructions: StorePatchConstant=106, OutputControlPointID=107
  567. if ((106 <= op && op <= 107)) {
  568. mask = SFLAG(Hull);
  569. return;
  570. }
  571. // Instructions: QuadReadLaneAt=122, QuadOp=123
  572. if ((122 <= op && op <= 123)) {
  573. mask = SFLAG(Library) | SFLAG(Compute) | SFLAG(Amplification) | SFLAG(Mesh) | SFLAG(Pixel);
  574. return;
  575. }
  576. // Instructions: WaveIsFirstLane=110, WaveGetLaneIndex=111,
  577. // WaveGetLaneCount=112, WaveAnyTrue=113, WaveAllTrue=114,
  578. // WaveActiveAllEqual=115, WaveActiveBallot=116, WaveReadLaneAt=117,
  579. // WaveReadLaneFirst=118, WaveActiveOp=119, WaveActiveBit=120,
  580. // WavePrefixOp=121, WaveAllBitCount=135, WavePrefixBitCount=136
  581. if ((110 <= op && op <= 121) || (135 <= op && op <= 136)) {
  582. mask = SFLAG(Library) | SFLAG(Compute) | SFLAG(Amplification) | SFLAG(Mesh) | SFLAG(Pixel) | SFLAG(Vertex) | SFLAG(Hull) | SFLAG(Domain) | SFLAG(Geometry) | SFLAG(RayGeneration) | SFLAG(Intersection) | SFLAG(AnyHit) | SFLAG(ClosestHit) | SFLAG(Miss) | SFLAG(Callable);
  583. return;
  584. }
  585. // Instructions: Sample=60, SampleBias=61, SampleCmp=64, CalculateLOD=81,
  586. // DerivCoarseX=83, DerivCoarseY=84, DerivFineX=85, DerivFineY=86
  587. if ((60 <= op && op <= 61) || op == 64 || op == 81 || (83 <= op && op <= 86)) {
  588. mask = SFLAG(Library) | SFLAG(Pixel) | SFLAG(Compute) | SFLAG(Amplification) | SFLAG(Mesh);
  589. return;
  590. }
  591. // Instructions: RenderTargetGetSamplePosition=76,
  592. // RenderTargetGetSampleCount=77, Discard=82, EvalSnapped=87,
  593. // EvalSampleIndex=88, EvalCentroid=89, SampleIndex=90, Coverage=91,
  594. // InnerCoverage=92
  595. if ((76 <= op && op <= 77) || op == 82 || (87 <= op && op <= 92)) {
  596. mask = SFLAG(Pixel);
  597. return;
  598. }
  599. // Instructions: AttributeAtVertex=137
  600. if (op == 137) {
  601. major = 6; minor = 1;
  602. mask = SFLAG(Pixel);
  603. return;
  604. }
  605. // Instructions: ViewID=138
  606. if (op == 138) {
  607. major = 6; minor = 1;
  608. mask = SFLAG(Vertex) | SFLAG(Hull) | SFLAG(Domain) | SFLAG(Geometry) | SFLAG(Pixel) | SFLAG(Mesh);
  609. return;
  610. }
  611. // Instructions: RawBufferLoad=139, RawBufferStore=140
  612. if ((139 <= op && op <= 140)) {
  613. if (bWithTranslation) {
  614. major = 6; minor = 0;
  615. } else {
  616. major = 6; minor = 2;
  617. }
  618. return;
  619. }
  620. // Instructions: IgnoreHit=155, AcceptHitAndEndSearch=156
  621. if ((155 <= op && op <= 156)) {
  622. major = 6; minor = 3;
  623. mask = SFLAG(AnyHit);
  624. return;
  625. }
  626. // Instructions: CallShader=159
  627. if (op == 159) {
  628. major = 6; minor = 3;
  629. mask = SFLAG(Library) | SFLAG(ClosestHit) | SFLAG(RayGeneration) | SFLAG(Miss) | SFLAG(Callable);
  630. return;
  631. }
  632. // Instructions: ReportHit=158
  633. if (op == 158) {
  634. major = 6; minor = 3;
  635. mask = SFLAG(Library) | SFLAG(Intersection);
  636. return;
  637. }
  638. // Instructions: InstanceID=141, InstanceIndex=142, HitKind=143,
  639. // ObjectRayOrigin=149, ObjectRayDirection=150, ObjectToWorld=151,
  640. // WorldToObject=152, PrimitiveIndex=161
  641. if ((141 <= op && op <= 143) || (149 <= op && op <= 152) || op == 161) {
  642. major = 6; minor = 3;
  643. mask = SFLAG(Library) | SFLAG(Intersection) | SFLAG(AnyHit) | SFLAG(ClosestHit);
  644. return;
  645. }
  646. // Instructions: RayFlags=144, WorldRayOrigin=147, WorldRayDirection=148,
  647. // RayTMin=153, RayTCurrent=154
  648. if (op == 144 || (147 <= op && op <= 148) || (153 <= op && op <= 154)) {
  649. major = 6; minor = 3;
  650. mask = SFLAG(Library) | SFLAG(Intersection) | SFLAG(AnyHit) | SFLAG(ClosestHit) | SFLAG(Miss);
  651. return;
  652. }
  653. // Instructions: TraceRay=157
  654. if (op == 157) {
  655. major = 6; minor = 3;
  656. mask = SFLAG(Library) | SFLAG(RayGeneration) | SFLAG(ClosestHit) | SFLAG(Miss);
  657. return;
  658. }
  659. // Instructions: DispatchRaysIndex=145, DispatchRaysDimensions=146
  660. if ((145 <= op && op <= 146)) {
  661. major = 6; minor = 3;
  662. mask = SFLAG(Library) | SFLAG(RayGeneration) | SFLAG(Intersection) | SFLAG(AnyHit) | SFLAG(ClosestHit) | SFLAG(Miss) | SFLAG(Callable);
  663. return;
  664. }
  665. // Instructions: CreateHandleForLib=160
  666. if (op == 160) {
  667. if (bWithTranslation) {
  668. major = 6; minor = 0;
  669. } else {
  670. major = 6; minor = 3;
  671. }
  672. return;
  673. }
  674. // Instructions: Dot2AddHalf=162, Dot4AddI8Packed=163, Dot4AddU8Packed=164
  675. if ((162 <= op && op <= 164)) {
  676. major = 6; minor = 4;
  677. return;
  678. }
  679. // Instructions: WriteSamplerFeedbackLevel=176, WriteSamplerFeedbackGrad=177,
  680. // AllocateRayQuery=178, RayQuery_TraceRayInline=179, RayQuery_Proceed=180,
  681. // RayQuery_Abort=181, RayQuery_CommitNonOpaqueTriangleHit=182,
  682. // RayQuery_CommitProceduralPrimitiveHit=183, RayQuery_CommittedStatus=184,
  683. // RayQuery_CandidateType=185, RayQuery_CandidateObjectToWorld3x4=186,
  684. // RayQuery_CandidateWorldToObject3x4=187,
  685. // RayQuery_CommittedObjectToWorld3x4=188,
  686. // RayQuery_CommittedWorldToObject3x4=189,
  687. // RayQuery_CandidateProceduralPrimitiveNonOpaque=190,
  688. // RayQuery_CandidateTriangleFrontFace=191,
  689. // RayQuery_CommittedTriangleFrontFace=192,
  690. // RayQuery_CandidateTriangleBarycentrics=193,
  691. // RayQuery_CommittedTriangleBarycentrics=194, RayQuery_RayFlags=195,
  692. // RayQuery_WorldRayOrigin=196, RayQuery_WorldRayDirection=197,
  693. // RayQuery_RayTMin=198, RayQuery_CandidateTriangleRayT=199,
  694. // RayQuery_CommittedRayT=200, RayQuery_CandidateInstanceIndex=201,
  695. // RayQuery_CandidateInstanceID=202, RayQuery_CandidateGeometryIndex=203,
  696. // RayQuery_CandidatePrimitiveIndex=204, RayQuery_CandidateObjectRayOrigin=205,
  697. // RayQuery_CandidateObjectRayDirection=206,
  698. // RayQuery_CommittedInstanceIndex=207, RayQuery_CommittedInstanceID=208,
  699. // RayQuery_CommittedGeometryIndex=209, RayQuery_CommittedPrimitiveIndex=210,
  700. // RayQuery_CommittedObjectRayOrigin=211,
  701. // RayQuery_CommittedObjectRayDirection=212,
  702. // RayQuery_CandidateInstanceContributionToHitGroupIndex=214,
  703. // RayQuery_CommittedInstanceContributionToHitGroupIndex=215
  704. if ((176 <= op && op <= 212) || (214 <= op && op <= 215)) {
  705. major = 6; minor = 5;
  706. return;
  707. }
  708. // Instructions: DispatchMesh=173
  709. if (op == 173) {
  710. major = 6; minor = 5;
  711. mask = SFLAG(Amplification);
  712. return;
  713. }
  714. // Instructions: WaveMatch=165, WaveMultiPrefixOp=166,
  715. // WaveMultiPrefixBitCount=167
  716. if ((165 <= op && op <= 167)) {
  717. major = 6; minor = 5;
  718. mask = SFLAG(Library) | SFLAG(Compute) | SFLAG(Amplification) | SFLAG(Mesh) | SFLAG(Pixel) | SFLAG(Vertex) | SFLAG(Hull) | SFLAG(Domain) | SFLAG(Geometry) | SFLAG(RayGeneration) | SFLAG(Intersection) | SFLAG(AnyHit) | SFLAG(ClosestHit) | SFLAG(Miss) | SFLAG(Callable);
  719. return;
  720. }
  721. // Instructions: GeometryIndex=213
  722. if (op == 213) {
  723. major = 6; minor = 5;
  724. mask = SFLAG(Library) | SFLAG(Intersection) | SFLAG(AnyHit) | SFLAG(ClosestHit);
  725. return;
  726. }
  727. // Instructions: WriteSamplerFeedback=174, WriteSamplerFeedbackBias=175
  728. if ((174 <= op && op <= 175)) {
  729. major = 6; minor = 5;
  730. mask = SFLAG(Library) | SFLAG(Pixel);
  731. return;
  732. }
  733. // Instructions: SetMeshOutputCounts=168, EmitIndices=169, GetMeshPayload=170,
  734. // StoreVertexOutput=171, StorePrimitiveOutput=172
  735. if ((168 <= op && op <= 172)) {
  736. major = 6; minor = 5;
  737. mask = SFLAG(Mesh);
  738. return;
  739. }
  740. // Instructions: AnnotateHandle=216, CreateHandleFromBinding=217,
  741. // CreateHandleFromHeap=218, Unpack4x8=219, Pack4x8=220, IsHelperLane=221
  742. if ((216 <= op && op <= 221)) {
  743. major = 6; minor = 6;
  744. return;
  745. }
  746. // OPCODE-SMMASK:END
  747. }
  748. void OP::GetMinShaderModelAndMask(const llvm::CallInst *CI, bool bWithTranslation,
  749. unsigned valMajor, unsigned valMinor,
  750. unsigned &major, unsigned &minor,
  751. unsigned &mask) {
  752. OpCode opcode = OP::GetDxilOpFuncCallInst(CI);
  753. GetMinShaderModelAndMask(opcode, bWithTranslation, major, minor, mask);
  754. unsigned op = (unsigned)opcode;
  755. // These ops cannot indicate support for CS, AS, or MS,
  756. // otherwise, it's saying these are guaranteed to be supported
  757. // on the lowest shader model returned by this function
  758. // for these shader stages. For CS, SM 6.6 is required,
  759. // and for AS/MS, an optional feature is required.
  760. // This also breaks compatibility for existing validators.
  761. // We need a different mechanism to be supported in functions
  762. // for runtime linking.
  763. // Instructions: Sample=60, SampleBias=61, SampleCmp=64, CalculateLOD=81,
  764. // DerivCoarseX=83, DerivCoarseY=84, DerivFineX=85, DerivFineY=86
  765. if ((60 <= op && op <= 61) || op == 64 || op == 81 || (83 <= op && op <= 86)) {
  766. mask &= ~(SFLAG(Compute) | SFLAG(Amplification) | SFLAG(Mesh));
  767. return;
  768. }
  769. if (DXIL::CompareVersions(valMajor, valMinor, 1, 5) < 0) {
  770. // validator 1.4 didn't exclude wave ops in mask
  771. if (IsDxilOpWave(opcode))
  772. mask = ((unsigned)1 << (unsigned)DXIL::ShaderKind::Invalid) - 1;
  773. // These shader models don't exist before 1.5
  774. mask &= ~(SFLAG(Amplification) | SFLAG(Mesh));
  775. // validator 1.4 didn't have any additional rules applied:
  776. return;
  777. }
  778. // Additional rules are applied manually here.
  779. // Barrier with mode != UAVFenceGlobal requires compute, amplification, or mesh
  780. // Instructions: Barrier=80
  781. if (opcode == DXIL::OpCode::Barrier) {
  782. DxilInst_Barrier barrier(const_cast<CallInst*>(CI));
  783. unsigned mode = barrier.get_barrierMode_val();
  784. if (mode != (unsigned)DXIL::BarrierMode::UAVFenceGlobal) {
  785. mask = SFLAG(Library) | SFLAG(Compute) | SFLAG(Amplification) | SFLAG(Mesh);
  786. }
  787. return;
  788. }
  789. // 64-bit integer atomic ops require 6.6
  790. else if (opcode == DXIL::OpCode::AtomicBinOp || opcode == DXIL::OpCode::AtomicCompareExchange) {
  791. Type *pOverloadType = GetOverloadType(opcode, CI->getCalledFunction());
  792. if (pOverloadType->isIntegerTy(64)) {
  793. major = 6;
  794. minor = 6;
  795. }
  796. }
  797. }
  798. #undef SFLAG
  799. static Type *GetOrCreateStructType(LLVMContext &Ctx, ArrayRef<Type*> types, StringRef Name, Module *pModule) {
  800. if (StructType *ST = pModule->getTypeByName(Name)) {
  801. // TODO: validate the exist type match types if needed.
  802. return ST;
  803. }
  804. else
  805. return StructType::create(Ctx, types, Name);
  806. }
  807. //------------------------------------------------------------------------------
  808. //
  809. // OP methods.
  810. //
  811. OP::OP(LLVMContext &Ctx, Module *pModule)
  812. : m_Ctx(Ctx)
  813. , m_pModule(pModule)
  814. , m_LowPrecisionMode(DXIL::LowPrecisionMode::Undefined) {
  815. memset(m_pResRetType, 0, sizeof(m_pResRetType));
  816. memset(m_pCBufferRetType, 0, sizeof(m_pCBufferRetType));
  817. memset(m_OpCodeClassCache, 0, sizeof(m_OpCodeClassCache));
  818. static_assert(_countof(OP::m_OpCodeProps) == (size_t)OP::OpCode::NumOpCodes, "forgot to update OP::m_OpCodeProps");
  819. m_pHandleType = GetOrCreateStructType(m_Ctx, Type::getInt8PtrTy(m_Ctx),
  820. "dx.types.Handle", pModule);
  821. m_pResourcePropertiesType = GetOrCreateStructType(
  822. m_Ctx, {Type::getInt32Ty(m_Ctx), Type::getInt32Ty(m_Ctx)},
  823. "dx.types.ResourceProperties", pModule);
  824. m_pResourceBindingType =
  825. GetOrCreateStructType(m_Ctx,
  826. {Type::getInt32Ty(m_Ctx), Type::getInt32Ty(m_Ctx),
  827. Type::getInt32Ty(m_Ctx), Type::getInt8Ty(m_Ctx)},
  828. "dx.types.ResBind", pModule);
  829. Type *DimsType[4] = { Type::getInt32Ty(m_Ctx), Type::getInt32Ty(m_Ctx), Type::getInt32Ty(m_Ctx), Type::getInt32Ty(m_Ctx) };
  830. m_pDimensionsType = GetOrCreateStructType(m_Ctx, DimsType, "dx.types.Dimensions", pModule);
  831. Type *SamplePosType[2] = { Type::getFloatTy(m_Ctx), Type::getFloatTy(m_Ctx) };
  832. m_pSamplePosType = GetOrCreateStructType(m_Ctx, SamplePosType, "dx.types.SamplePos", pModule);
  833. Type *I32cTypes[2] = { Type::getInt32Ty(m_Ctx), Type::getInt1Ty(m_Ctx) };
  834. m_pBinaryWithCarryType = GetOrCreateStructType(m_Ctx, I32cTypes, "dx.types.i32c", pModule);
  835. Type *TwoI32Types[2] = { Type::getInt32Ty(m_Ctx), Type::getInt32Ty(m_Ctx) };
  836. m_pBinaryWithTwoOutputsType = GetOrCreateStructType(m_Ctx, TwoI32Types, "dx.types.twoi32", pModule);
  837. Type *SplitDoubleTypes[2] = { Type::getInt32Ty(m_Ctx), Type::getInt32Ty(m_Ctx) }; // Lo, Hi.
  838. m_pSplitDoubleType = GetOrCreateStructType(m_Ctx, SplitDoubleTypes, "dx.types.splitdouble", pModule);
  839. Type *FourI32Types[4] = { Type::getInt32Ty(m_Ctx), Type::getInt32Ty(m_Ctx), Type::getInt32Ty(m_Ctx), Type::getInt32Ty(m_Ctx) }; // HiHi, HiLo, LoHi, LoLo
  840. m_pFourI32Type = GetOrCreateStructType(m_Ctx, FourI32Types, "dx.types.fouri32", pModule);
  841. Type *FourI16Types[4] = { Type::getInt16Ty(m_Ctx), Type::getInt16Ty(m_Ctx), Type::getInt16Ty(m_Ctx), Type::getInt16Ty(m_Ctx) }; // HiHi, HiLo, LoHi, LoLo
  842. m_pFourI16Type = GetOrCreateStructType(m_Ctx, FourI16Types, "dx.types.fouri16", pModule);
  843. // When loading a module into an existing context where types are merged,
  844. // type names may change. When this happens, any intrinsics overloaded on
  845. // UDT types will no longer have matching overload names.
  846. // This causes RefreshCache() to assert.
  847. // This fixes the function names to they match the expected types,
  848. // preventing RefreshCache() from failing due to this issue.
  849. FixOverloadNames();
  850. // Try to find existing intrinsic function.
  851. RefreshCache();
  852. }
  853. void OP::RefreshCache() {
  854. for (Function &F : m_pModule->functions()) {
  855. if (OP::IsDxilOpFunc(&F) && !F.user_empty()) {
  856. CallInst *CI = cast<CallInst>(*F.user_begin());
  857. OpCode OpCode = OP::GetDxilOpFuncCallInst(CI);
  858. Type *pOverloadType = OP::GetOverloadType(OpCode, &F);
  859. Function *OpFunc = GetOpFunc(OpCode, pOverloadType);
  860. (void)(OpFunc);
  861. DXASSERT_NOMSG(OpFunc == &F);
  862. }
  863. }
  864. }
  865. void OP::FixOverloadNames() {
  866. // When merging code from multiple sources, such as with linking,
  867. // type names that collide, but don't have the same type will be
  868. // automically renamed with .0+ name disambiguation. However,
  869. // DXIL intrinsic overloads will not be renamed to disambiguate them,
  870. // since they exist in separate modules at the time.
  871. // This leads to name collisions between different types when linking.
  872. // Do this after loading into a shared context, and before copying
  873. // code into a common module, to prevent this problem.
  874. for (Function &F : m_pModule->functions()) {
  875. if (F.isDeclaration() && OP::IsDxilOpFunc(&F) && !F.user_empty()) {
  876. CallInst *CI = cast<CallInst>(*F.user_begin());
  877. DXIL::OpCode opCode = OP::GetDxilOpFuncCallInst(CI);
  878. llvm::Type *Ty = OP::GetOverloadType(opCode, &F);
  879. if (isa<StructType>(Ty)) {
  880. std::string funcName;
  881. if (OP::ConstructOverloadName(Ty, opCode, funcName).compare(F.getName()) != 0) {
  882. F.setName(funcName);
  883. }
  884. }
  885. }
  886. }
  887. }
  888. void OP::UpdateCache(OpCodeClass opClass, Type * Ty, llvm::Function *F) {
  889. m_OpCodeClassCache[(unsigned)opClass].pOverloads[Ty] = F;
  890. m_FunctionToOpClass[F] = opClass;
  891. }
  892. Function *OP::GetOpFunc(OpCode opCode, Type *pOverloadType) {
  893. DXASSERT(0 <= (unsigned)opCode && opCode < OpCode::NumOpCodes, "otherwise caller passed OOB OpCode");
  894. _Analysis_assume_(0 <= (unsigned)opCode && opCode < OpCode::NumOpCodes);
  895. DXASSERT(IsOverloadLegal(opCode, pOverloadType), "otherwise the caller requested illegal operation overload (eg HLSL function with unsupported types for mapped intrinsic function)");
  896. OpCodeClass opClass = m_OpCodeProps[(unsigned)opCode].opCodeClass;
  897. Function *&F = m_OpCodeClassCache[(unsigned)opClass].pOverloads[pOverloadType];
  898. if (F != nullptr) {
  899. UpdateCache(opClass, pOverloadType, F);
  900. return F;
  901. }
  902. vector<Type*> ArgTypes; // RetType is ArgTypes[0]
  903. Type *pETy = pOverloadType;
  904. Type *pRes = GetHandleType();
  905. Type *pDim = GetDimensionsType();
  906. Type *pPos = GetSamplePosType();
  907. Type *pV = Type::getVoidTy(m_Ctx);
  908. Type *pI1 = Type::getInt1Ty(m_Ctx);
  909. Type *pI8 = Type::getInt8Ty(m_Ctx);
  910. Type *pI16 = Type::getInt16Ty(m_Ctx);
  911. Type *pI32 = Type::getInt32Ty(m_Ctx);
  912. Type *pPI32 = Type::getInt32PtrTy(m_Ctx); (void)(pPI32); // Currently unused.
  913. Type *pI64 = Type::getInt64Ty(m_Ctx); (void)(pI64); // Currently unused.
  914. Type *pF16 = Type::getHalfTy(m_Ctx);
  915. Type *pF32 = Type::getFloatTy(m_Ctx);
  916. Type *pPF32 = Type::getFloatPtrTy(m_Ctx);
  917. Type *pI32C = GetBinaryWithCarryType();
  918. Type *p2I32 = GetBinaryWithTwoOutputsType();
  919. Type *pF64 = Type::getDoubleTy(m_Ctx);
  920. Type *pSDT = GetSplitDoubleType(); // Split double type.
  921. Type *p4I32 = GetFourI32Type(); // 4 i32s in a struct.
  922. Type *udt = pOverloadType;
  923. Type *obj = pOverloadType;
  924. Type *resProperty = GetResourcePropertiesType();
  925. Type *resBind = GetResourceBindingType();
  926. std::string funcName;
  927. ConstructOverloadName(pOverloadType, opCode, funcName);
  928. // Try to find exist function with the same name in the module.
  929. if (Function *existF = m_pModule->getFunction(funcName)) {
  930. F = existF;
  931. UpdateCache(opClass, pOverloadType, F);
  932. return F;
  933. }
  934. #define A(_x) ArgTypes.emplace_back(_x)
  935. #define RRT(_y) A(GetResRetType(_y))
  936. #define CBRT(_y) A(GetCBufferRetType(_y))
  937. #define VEC4(_y) A(GetVectorType(4,_y))
  938. /* <py::lines('OPCODE-OLOAD-FUNCS')>hctdb_instrhelp.get_oloads_funcs()</py>*/
  939. switch (opCode) { // return opCode
  940. // OPCODE-OLOAD-FUNCS:BEGIN
  941. // Temporary, indexable, input, output registers
  942. case OpCode::TempRegLoad: A(pETy); A(pI32); A(pI32); break;
  943. case OpCode::TempRegStore: A(pV); A(pI32); A(pI32); A(pETy); break;
  944. case OpCode::MinPrecXRegLoad: A(pETy); A(pI32); A(pPF32);A(pI32); A(pI8); break;
  945. case OpCode::MinPrecXRegStore: A(pV); A(pI32); A(pPF32);A(pI32); A(pI8); A(pETy); break;
  946. case OpCode::LoadInput: A(pETy); A(pI32); A(pI32); A(pI32); A(pI8); A(pI32); break;
  947. case OpCode::StoreOutput: A(pV); A(pI32); A(pI32); A(pI32); A(pI8); A(pETy); break;
  948. // Unary float
  949. case OpCode::FAbs: A(pETy); A(pI32); A(pETy); break;
  950. case OpCode::Saturate: A(pETy); A(pI32); A(pETy); break;
  951. case OpCode::IsNaN: A(pI1); A(pI32); A(pETy); break;
  952. case OpCode::IsInf: A(pI1); A(pI32); A(pETy); break;
  953. case OpCode::IsFinite: A(pI1); A(pI32); A(pETy); break;
  954. case OpCode::IsNormal: A(pI1); A(pI32); A(pETy); break;
  955. case OpCode::Cos: A(pETy); A(pI32); A(pETy); break;
  956. case OpCode::Sin: A(pETy); A(pI32); A(pETy); break;
  957. case OpCode::Tan: A(pETy); A(pI32); A(pETy); break;
  958. case OpCode::Acos: A(pETy); A(pI32); A(pETy); break;
  959. case OpCode::Asin: A(pETy); A(pI32); A(pETy); break;
  960. case OpCode::Atan: A(pETy); A(pI32); A(pETy); break;
  961. case OpCode::Hcos: A(pETy); A(pI32); A(pETy); break;
  962. case OpCode::Hsin: A(pETy); A(pI32); A(pETy); break;
  963. case OpCode::Htan: A(pETy); A(pI32); A(pETy); break;
  964. case OpCode::Exp: A(pETy); A(pI32); A(pETy); break;
  965. case OpCode::Frc: A(pETy); A(pI32); A(pETy); break;
  966. case OpCode::Log: A(pETy); A(pI32); A(pETy); break;
  967. case OpCode::Sqrt: A(pETy); A(pI32); A(pETy); break;
  968. case OpCode::Rsqrt: A(pETy); A(pI32); A(pETy); break;
  969. // Unary float - rounding
  970. case OpCode::Round_ne: A(pETy); A(pI32); A(pETy); break;
  971. case OpCode::Round_ni: A(pETy); A(pI32); A(pETy); break;
  972. case OpCode::Round_pi: A(pETy); A(pI32); A(pETy); break;
  973. case OpCode::Round_z: A(pETy); A(pI32); A(pETy); break;
  974. // Unary int
  975. case OpCode::Bfrev: A(pETy); A(pI32); A(pETy); break;
  976. case OpCode::Countbits: A(pI32); A(pI32); A(pETy); break;
  977. case OpCode::FirstbitLo: A(pI32); A(pI32); A(pETy); break;
  978. // Unary uint
  979. case OpCode::FirstbitHi: A(pI32); A(pI32); A(pETy); break;
  980. // Unary int
  981. case OpCode::FirstbitSHi: A(pI32); A(pI32); A(pETy); break;
  982. // Binary float
  983. case OpCode::FMax: A(pETy); A(pI32); A(pETy); A(pETy); break;
  984. case OpCode::FMin: A(pETy); A(pI32); A(pETy); A(pETy); break;
  985. // Binary int
  986. case OpCode::IMax: A(pETy); A(pI32); A(pETy); A(pETy); break;
  987. case OpCode::IMin: A(pETy); A(pI32); A(pETy); A(pETy); break;
  988. // Binary uint
  989. case OpCode::UMax: A(pETy); A(pI32); A(pETy); A(pETy); break;
  990. case OpCode::UMin: A(pETy); A(pI32); A(pETy); A(pETy); break;
  991. // Binary int with two outputs
  992. case OpCode::IMul: A(p2I32); A(pI32); A(pETy); A(pETy); break;
  993. // Binary uint with two outputs
  994. case OpCode::UMul: A(p2I32); A(pI32); A(pETy); A(pETy); break;
  995. case OpCode::UDiv: A(p2I32); A(pI32); A(pETy); A(pETy); break;
  996. // Binary uint with carry or borrow
  997. case OpCode::UAddc: A(pI32C); A(pI32); A(pETy); A(pETy); break;
  998. case OpCode::USubb: A(pI32C); A(pI32); A(pETy); A(pETy); break;
  999. // Tertiary float
  1000. case OpCode::FMad: A(pETy); A(pI32); A(pETy); A(pETy); A(pETy); break;
  1001. case OpCode::Fma: A(pETy); A(pI32); A(pETy); A(pETy); A(pETy); break;
  1002. // Tertiary int
  1003. case OpCode::IMad: A(pETy); A(pI32); A(pETy); A(pETy); A(pETy); break;
  1004. // Tertiary uint
  1005. case OpCode::UMad: A(pETy); A(pI32); A(pETy); A(pETy); A(pETy); break;
  1006. // Tertiary int
  1007. case OpCode::Msad: A(pETy); A(pI32); A(pETy); A(pETy); A(pETy); break;
  1008. case OpCode::Ibfe: A(pETy); A(pI32); A(pETy); A(pETy); A(pETy); break;
  1009. // Tertiary uint
  1010. case OpCode::Ubfe: A(pETy); A(pI32); A(pETy); A(pETy); A(pETy); break;
  1011. // Quaternary
  1012. case OpCode::Bfi: A(pETy); A(pI32); A(pETy); A(pETy); A(pETy); A(pETy); break;
  1013. // Dot
  1014. case OpCode::Dot2: A(pETy); A(pI32); A(pETy); A(pETy); A(pETy); A(pETy); break;
  1015. case OpCode::Dot3: A(pETy); A(pI32); A(pETy); A(pETy); A(pETy); A(pETy); A(pETy); A(pETy); break;
  1016. case OpCode::Dot4: A(pETy); A(pI32); A(pETy); A(pETy); A(pETy); A(pETy); A(pETy); A(pETy); A(pETy); A(pETy); break;
  1017. // Resources
  1018. case OpCode::CreateHandle: A(pRes); A(pI32); A(pI8); A(pI32); A(pI32); A(pI1); break;
  1019. case OpCode::CBufferLoad: A(pETy); A(pI32); A(pRes); A(pI32); A(pI32); break;
  1020. case OpCode::CBufferLoadLegacy: CBRT(pETy); A(pI32); A(pRes); A(pI32); break;
  1021. // Resources - sample
  1022. case OpCode::Sample: RRT(pETy); A(pI32); A(pRes); A(pRes); A(pF32); A(pF32); A(pF32); A(pF32); A(pI32); A(pI32); A(pI32); A(pF32); break;
  1023. case OpCode::SampleBias: RRT(pETy); A(pI32); A(pRes); A(pRes); A(pF32); A(pF32); A(pF32); A(pF32); A(pI32); A(pI32); A(pI32); A(pF32); A(pF32); break;
  1024. case OpCode::SampleLevel: RRT(pETy); A(pI32); A(pRes); A(pRes); A(pF32); A(pF32); A(pF32); A(pF32); A(pI32); A(pI32); A(pI32); A(pF32); break;
  1025. case OpCode::SampleGrad: RRT(pETy); A(pI32); A(pRes); A(pRes); A(pF32); A(pF32); A(pF32); A(pF32); A(pI32); A(pI32); A(pI32); A(pF32); A(pF32); A(pF32); A(pF32); A(pF32); A(pF32); A(pF32); break;
  1026. case OpCode::SampleCmp: RRT(pETy); A(pI32); A(pRes); A(pRes); A(pF32); A(pF32); A(pF32); A(pF32); A(pI32); A(pI32); A(pI32); A(pF32); A(pF32); break;
  1027. case OpCode::SampleCmpLevelZero: RRT(pETy); A(pI32); A(pRes); A(pRes); A(pF32); A(pF32); A(pF32); A(pF32); A(pI32); A(pI32); A(pI32); A(pF32); break;
  1028. // Resources
  1029. case OpCode::TextureLoad: RRT(pETy); A(pI32); A(pRes); A(pI32); A(pI32); A(pI32); A(pI32); A(pI32); A(pI32); A(pI32); break;
  1030. case OpCode::TextureStore: A(pV); A(pI32); A(pRes); A(pI32); A(pI32); A(pI32); A(pETy); A(pETy); A(pETy); A(pETy); A(pI8); break;
  1031. case OpCode::BufferLoad: RRT(pETy); A(pI32); A(pRes); A(pI32); A(pI32); break;
  1032. case OpCode::BufferStore: A(pV); A(pI32); A(pRes); A(pI32); A(pI32); A(pETy); A(pETy); A(pETy); A(pETy); A(pI8); break;
  1033. case OpCode::BufferUpdateCounter: A(pI32); A(pI32); A(pRes); A(pI8); break;
  1034. case OpCode::CheckAccessFullyMapped: A(pI1); A(pI32); A(pI32); break;
  1035. case OpCode::GetDimensions: A(pDim); A(pI32); A(pRes); A(pI32); break;
  1036. // Resources - gather
  1037. case OpCode::TextureGather: RRT(pETy); A(pI32); A(pRes); A(pRes); A(pF32); A(pF32); A(pF32); A(pF32); A(pI32); A(pI32); A(pI32); break;
  1038. case OpCode::TextureGatherCmp: RRT(pETy); A(pI32); A(pRes); A(pRes); A(pF32); A(pF32); A(pF32); A(pF32); A(pI32); A(pI32); A(pI32); A(pF32); break;
  1039. // Resources - sample
  1040. case OpCode::Texture2DMSGetSamplePosition:A(pPos); A(pI32); A(pRes); A(pI32); break;
  1041. case OpCode::RenderTargetGetSamplePosition:A(pPos); A(pI32); A(pI32); break;
  1042. case OpCode::RenderTargetGetSampleCount:A(pI32); A(pI32); break;
  1043. // Synchronization
  1044. case OpCode::AtomicBinOp: A(pETy); A(pI32); A(pRes); A(pI32); A(pI32); A(pI32); A(pI32); A(pETy); break;
  1045. case OpCode::AtomicCompareExchange: A(pETy); A(pI32); A(pRes); A(pI32); A(pI32); A(pI32); A(pETy); A(pETy); break;
  1046. case OpCode::Barrier: A(pV); A(pI32); A(pI32); break;
  1047. // Derivatives
  1048. case OpCode::CalculateLOD: A(pF32); A(pI32); A(pRes); A(pRes); A(pF32); A(pF32); A(pF32); A(pI1); break;
  1049. // Pixel shader
  1050. case OpCode::Discard: A(pV); A(pI32); A(pI1); break;
  1051. // Derivatives
  1052. case OpCode::DerivCoarseX: A(pETy); A(pI32); A(pETy); break;
  1053. case OpCode::DerivCoarseY: A(pETy); A(pI32); A(pETy); break;
  1054. case OpCode::DerivFineX: A(pETy); A(pI32); A(pETy); break;
  1055. case OpCode::DerivFineY: A(pETy); A(pI32); A(pETy); break;
  1056. // Pixel shader
  1057. case OpCode::EvalSnapped: A(pETy); A(pI32); A(pI32); A(pI32); A(pI8); A(pI32); A(pI32); break;
  1058. case OpCode::EvalSampleIndex: A(pETy); A(pI32); A(pI32); A(pI32); A(pI8); A(pI32); break;
  1059. case OpCode::EvalCentroid: A(pETy); A(pI32); A(pI32); A(pI32); A(pI8); break;
  1060. case OpCode::SampleIndex: A(pI32); A(pI32); break;
  1061. case OpCode::Coverage: A(pI32); A(pI32); break;
  1062. case OpCode::InnerCoverage: A(pI32); A(pI32); break;
  1063. // Compute/Mesh/Amplification shader
  1064. case OpCode::ThreadId: A(pI32); A(pI32); A(pI32); break;
  1065. case OpCode::GroupId: A(pI32); A(pI32); A(pI32); break;
  1066. case OpCode::ThreadIdInGroup: A(pI32); A(pI32); A(pI32); break;
  1067. case OpCode::FlattenedThreadIdInGroup:A(pI32); A(pI32); break;
  1068. // Geometry shader
  1069. case OpCode::EmitStream: A(pV); A(pI32); A(pI8); break;
  1070. case OpCode::CutStream: A(pV); A(pI32); A(pI8); break;
  1071. case OpCode::EmitThenCutStream: A(pV); A(pI32); A(pI8); break;
  1072. case OpCode::GSInstanceID: A(pI32); A(pI32); break;
  1073. // Double precision
  1074. case OpCode::MakeDouble: A(pF64); A(pI32); A(pI32); A(pI32); break;
  1075. case OpCode::SplitDouble: A(pSDT); A(pI32); A(pF64); break;
  1076. // Domain and hull shader
  1077. case OpCode::LoadOutputControlPoint: A(pETy); A(pI32); A(pI32); A(pI32); A(pI8); A(pI32); break;
  1078. case OpCode::LoadPatchConstant: A(pETy); A(pI32); A(pI32); A(pI32); A(pI8); break;
  1079. // Domain shader
  1080. case OpCode::DomainLocation: A(pF32); A(pI32); A(pI8); break;
  1081. // Hull shader
  1082. case OpCode::StorePatchConstant: A(pV); A(pI32); A(pI32); A(pI32); A(pI8); A(pETy); break;
  1083. case OpCode::OutputControlPointID: A(pI32); A(pI32); break;
  1084. // Hull, Domain and Geometry shaders
  1085. case OpCode::PrimitiveID: A(pI32); A(pI32); break;
  1086. // Other
  1087. case OpCode::CycleCounterLegacy: A(p2I32); A(pI32); break;
  1088. // Wave
  1089. case OpCode::WaveIsFirstLane: A(pI1); A(pI32); break;
  1090. case OpCode::WaveGetLaneIndex: A(pI32); A(pI32); break;
  1091. case OpCode::WaveGetLaneCount: A(pI32); A(pI32); break;
  1092. case OpCode::WaveAnyTrue: A(pI1); A(pI32); A(pI1); break;
  1093. case OpCode::WaveAllTrue: A(pI1); A(pI32); A(pI1); break;
  1094. case OpCode::WaveActiveAllEqual: A(pI1); A(pI32); A(pETy); break;
  1095. case OpCode::WaveActiveBallot: A(p4I32); A(pI32); A(pI1); break;
  1096. case OpCode::WaveReadLaneAt: A(pETy); A(pI32); A(pETy); A(pI32); break;
  1097. case OpCode::WaveReadLaneFirst: A(pETy); A(pI32); A(pETy); break;
  1098. case OpCode::WaveActiveOp: A(pETy); A(pI32); A(pETy); A(pI8); A(pI8); break;
  1099. case OpCode::WaveActiveBit: A(pETy); A(pI32); A(pETy); A(pI8); break;
  1100. case OpCode::WavePrefixOp: A(pETy); A(pI32); A(pETy); A(pI8); A(pI8); break;
  1101. // Quad Wave Ops
  1102. case OpCode::QuadReadLaneAt: A(pETy); A(pI32); A(pETy); A(pI32); break;
  1103. case OpCode::QuadOp: A(pETy); A(pI32); A(pETy); A(pI8); break;
  1104. // Bitcasts with different sizes
  1105. case OpCode::BitcastI16toF16: A(pF16); A(pI32); A(pI16); break;
  1106. case OpCode::BitcastF16toI16: A(pI16); A(pI32); A(pF16); break;
  1107. case OpCode::BitcastI32toF32: A(pF32); A(pI32); A(pI32); break;
  1108. case OpCode::BitcastF32toI32: A(pI32); A(pI32); A(pF32); break;
  1109. case OpCode::BitcastI64toF64: A(pF64); A(pI32); A(pI64); break;
  1110. case OpCode::BitcastF64toI64: A(pI64); A(pI32); A(pF64); break;
  1111. // Legacy floating-point
  1112. case OpCode::LegacyF32ToF16: A(pI32); A(pI32); A(pF32); break;
  1113. case OpCode::LegacyF16ToF32: A(pF32); A(pI32); A(pI32); break;
  1114. // Double precision
  1115. case OpCode::LegacyDoubleToFloat: A(pF32); A(pI32); A(pF64); break;
  1116. case OpCode::LegacyDoubleToSInt32: A(pI32); A(pI32); A(pF64); break;
  1117. case OpCode::LegacyDoubleToUInt32: A(pI32); A(pI32); A(pF64); break;
  1118. // Wave
  1119. case OpCode::WaveAllBitCount: A(pI32); A(pI32); A(pI1); break;
  1120. case OpCode::WavePrefixBitCount: A(pI32); A(pI32); A(pI1); break;
  1121. // Pixel shader
  1122. case OpCode::AttributeAtVertex: A(pETy); A(pI32); A(pI32); A(pI32); A(pI8); A(pI8); break;
  1123. // Graphics shader
  1124. case OpCode::ViewID: A(pI32); A(pI32); break;
  1125. // Resources
  1126. case OpCode::RawBufferLoad: RRT(pETy); A(pI32); A(pRes); A(pI32); A(pI32); A(pI8); A(pI32); break;
  1127. case OpCode::RawBufferStore: A(pV); A(pI32); A(pRes); A(pI32); A(pI32); A(pETy); A(pETy); A(pETy); A(pETy); A(pI8); A(pI32); break;
  1128. // Raytracing object space uint System Values
  1129. case OpCode::InstanceID: A(pI32); A(pI32); break;
  1130. case OpCode::InstanceIndex: A(pI32); A(pI32); break;
  1131. // Raytracing hit uint System Values
  1132. case OpCode::HitKind: A(pI32); A(pI32); break;
  1133. // Raytracing uint System Values
  1134. case OpCode::RayFlags: A(pI32); A(pI32); break;
  1135. // Ray Dispatch Arguments
  1136. case OpCode::DispatchRaysIndex: A(pI32); A(pI32); A(pI8); break;
  1137. case OpCode::DispatchRaysDimensions: A(pI32); A(pI32); A(pI8); break;
  1138. // Ray Vectors
  1139. case OpCode::WorldRayOrigin: A(pF32); A(pI32); A(pI8); break;
  1140. case OpCode::WorldRayDirection: A(pF32); A(pI32); A(pI8); break;
  1141. // Ray object space Vectors
  1142. case OpCode::ObjectRayOrigin: A(pF32); A(pI32); A(pI8); break;
  1143. case OpCode::ObjectRayDirection: A(pF32); A(pI32); A(pI8); break;
  1144. // Ray Transforms
  1145. case OpCode::ObjectToWorld: A(pF32); A(pI32); A(pI32); A(pI8); break;
  1146. case OpCode::WorldToObject: A(pF32); A(pI32); A(pI32); A(pI8); break;
  1147. // RayT
  1148. case OpCode::RayTMin: A(pF32); A(pI32); break;
  1149. case OpCode::RayTCurrent: A(pF32); A(pI32); break;
  1150. // AnyHit Terminals
  1151. case OpCode::IgnoreHit: A(pV); A(pI32); break;
  1152. case OpCode::AcceptHitAndEndSearch: A(pV); A(pI32); break;
  1153. // Indirect Shader Invocation
  1154. case OpCode::TraceRay: A(pV); A(pI32); A(pRes); A(pI32); A(pI32); A(pI32); A(pI32); A(pI32); A(pF32); A(pF32); A(pF32); A(pF32); A(pF32); A(pF32); A(pF32); A(pF32); A(udt); break;
  1155. case OpCode::ReportHit: A(pI1); A(pI32); A(pF32); A(pI32); A(udt); break;
  1156. case OpCode::CallShader: A(pV); A(pI32); A(pI32); A(udt); break;
  1157. // Library create handle from resource struct (like HL intrinsic)
  1158. case OpCode::CreateHandleForLib: A(pRes); A(pI32); A(obj); break;
  1159. // Raytracing object space uint System Values
  1160. case OpCode::PrimitiveIndex: A(pI32); A(pI32); break;
  1161. // Dot product with accumulate
  1162. case OpCode::Dot2AddHalf: A(pETy); A(pI32); A(pETy); A(pF16); A(pF16); A(pF16); A(pF16); break;
  1163. case OpCode::Dot4AddI8Packed: A(pI32); A(pI32); A(pI32); A(pI32); A(pI32); break;
  1164. case OpCode::Dot4AddU8Packed: A(pI32); A(pI32); A(pI32); A(pI32); A(pI32); break;
  1165. // Wave
  1166. case OpCode::WaveMatch: A(p4I32); A(pI32); A(pETy); break;
  1167. case OpCode::WaveMultiPrefixOp: A(pETy); A(pI32); A(pETy); A(pI32); A(pI32); A(pI32); A(pI32); A(pI8); A(pI8); break;
  1168. case OpCode::WaveMultiPrefixBitCount:A(pI32); A(pI32); A(pI1); A(pI32); A(pI32); A(pI32); A(pI32); break;
  1169. // Mesh shader instructions
  1170. case OpCode::SetMeshOutputCounts: A(pV); A(pI32); A(pI32); A(pI32); break;
  1171. case OpCode::EmitIndices: A(pV); A(pI32); A(pI32); A(pI32); A(pI32); A(pI32); break;
  1172. case OpCode::GetMeshPayload: A(pETy); A(pI32); break;
  1173. case OpCode::StoreVertexOutput: A(pV); A(pI32); A(pI32); A(pI32); A(pI8); A(pETy); A(pI32); break;
  1174. case OpCode::StorePrimitiveOutput: A(pV); A(pI32); A(pI32); A(pI32); A(pI8); A(pETy); A(pI32); break;
  1175. // Amplification shader instructions
  1176. case OpCode::DispatchMesh: A(pV); A(pI32); A(pI32); A(pI32); A(pI32); A(pETy); break;
  1177. // Sampler Feedback
  1178. case OpCode::WriteSamplerFeedback: A(pV); A(pI32); A(pRes); A(pRes); A(pRes); A(pF32); A(pF32); A(pF32); A(pF32); A(pF32); break;
  1179. case OpCode::WriteSamplerFeedbackBias:A(pV); A(pI32); A(pRes); A(pRes); A(pRes); A(pF32); A(pF32); A(pF32); A(pF32); A(pF32); A(pF32); break;
  1180. case OpCode::WriteSamplerFeedbackLevel:A(pV); A(pI32); A(pRes); A(pRes); A(pRes); A(pF32); A(pF32); A(pF32); A(pF32); A(pF32); break;
  1181. case OpCode::WriteSamplerFeedbackGrad:A(pV); A(pI32); A(pRes); A(pRes); A(pRes); A(pF32); A(pF32); A(pF32); A(pF32); A(pF32); A(pF32); A(pF32); A(pF32); A(pF32); A(pF32); A(pF32); break;
  1182. // Inline Ray Query
  1183. case OpCode::AllocateRayQuery: A(pI32); A(pI32); A(pI32); break;
  1184. case OpCode::RayQuery_TraceRayInline:A(pV); A(pI32); A(pI32); A(pRes); A(pI32); A(pI32); A(pF32); A(pF32); A(pF32); A(pF32); A(pF32); A(pF32); A(pF32); A(pF32); break;
  1185. case OpCode::RayQuery_Proceed: A(pI1); A(pI32); A(pI32); break;
  1186. case OpCode::RayQuery_Abort: A(pV); A(pI32); A(pI32); break;
  1187. case OpCode::RayQuery_CommitNonOpaqueTriangleHit:A(pV); A(pI32); A(pI32); break;
  1188. case OpCode::RayQuery_CommitProceduralPrimitiveHit:A(pV); A(pI32); A(pI32); A(pF32); break;
  1189. case OpCode::RayQuery_CommittedStatus:A(pI32); A(pI32); A(pI32); break;
  1190. case OpCode::RayQuery_CandidateType: A(pI32); A(pI32); A(pI32); break;
  1191. case OpCode::RayQuery_CandidateObjectToWorld3x4:A(pF32); A(pI32); A(pI32); A(pI32); A(pI8); break;
  1192. case OpCode::RayQuery_CandidateWorldToObject3x4:A(pF32); A(pI32); A(pI32); A(pI32); A(pI8); break;
  1193. case OpCode::RayQuery_CommittedObjectToWorld3x4:A(pF32); A(pI32); A(pI32); A(pI32); A(pI8); break;
  1194. case OpCode::RayQuery_CommittedWorldToObject3x4:A(pF32); A(pI32); A(pI32); A(pI32); A(pI8); break;
  1195. case OpCode::RayQuery_CandidateProceduralPrimitiveNonOpaque:A(pI1); A(pI32); A(pI32); break;
  1196. case OpCode::RayQuery_CandidateTriangleFrontFace:A(pI1); A(pI32); A(pI32); break;
  1197. case OpCode::RayQuery_CommittedTriangleFrontFace:A(pI1); A(pI32); A(pI32); break;
  1198. case OpCode::RayQuery_CandidateTriangleBarycentrics:A(pF32); A(pI32); A(pI32); A(pI8); break;
  1199. case OpCode::RayQuery_CommittedTriangleBarycentrics:A(pF32); A(pI32); A(pI32); A(pI8); break;
  1200. case OpCode::RayQuery_RayFlags: A(pI32); A(pI32); A(pI32); break;
  1201. case OpCode::RayQuery_WorldRayOrigin:A(pF32); A(pI32); A(pI32); A(pI8); break;
  1202. case OpCode::RayQuery_WorldRayDirection:A(pF32); A(pI32); A(pI32); A(pI8); break;
  1203. case OpCode::RayQuery_RayTMin: A(pF32); A(pI32); A(pI32); break;
  1204. case OpCode::RayQuery_CandidateTriangleRayT:A(pF32); A(pI32); A(pI32); break;
  1205. case OpCode::RayQuery_CommittedRayT: A(pF32); A(pI32); A(pI32); break;
  1206. case OpCode::RayQuery_CandidateInstanceIndex:A(pI32); A(pI32); A(pI32); break;
  1207. case OpCode::RayQuery_CandidateInstanceID:A(pI32); A(pI32); A(pI32); break;
  1208. case OpCode::RayQuery_CandidateGeometryIndex:A(pI32); A(pI32); A(pI32); break;
  1209. case OpCode::RayQuery_CandidatePrimitiveIndex:A(pI32); A(pI32); A(pI32); break;
  1210. case OpCode::RayQuery_CandidateObjectRayOrigin:A(pF32); A(pI32); A(pI32); A(pI8); break;
  1211. case OpCode::RayQuery_CandidateObjectRayDirection:A(pF32); A(pI32); A(pI32); A(pI8); break;
  1212. case OpCode::RayQuery_CommittedInstanceIndex:A(pI32); A(pI32); A(pI32); break;
  1213. case OpCode::RayQuery_CommittedInstanceID:A(pI32); A(pI32); A(pI32); break;
  1214. case OpCode::RayQuery_CommittedGeometryIndex:A(pI32); A(pI32); A(pI32); break;
  1215. case OpCode::RayQuery_CommittedPrimitiveIndex:A(pI32); A(pI32); A(pI32); break;
  1216. case OpCode::RayQuery_CommittedObjectRayOrigin:A(pF32); A(pI32); A(pI32); A(pI8); break;
  1217. case OpCode::RayQuery_CommittedObjectRayDirection:A(pF32); A(pI32); A(pI32); A(pI8); break;
  1218. // Raytracing object space uint System Values, raytracing tier 1.1
  1219. case OpCode::GeometryIndex: A(pI32); A(pI32); break;
  1220. // Inline Ray Query
  1221. case OpCode::RayQuery_CandidateInstanceContributionToHitGroupIndex:A(pI32); A(pI32); A(pI32); break;
  1222. case OpCode::RayQuery_CommittedInstanceContributionToHitGroupIndex:A(pI32); A(pI32); A(pI32); break;
  1223. // Get handle from heap
  1224. case OpCode::AnnotateHandle: A(pRes); A(pI32); A(pRes); A(resProperty);break;
  1225. case OpCode::CreateHandleFromBinding:A(pRes); A(pI32); A(resBind);A(pI32); A(pI1); break;
  1226. case OpCode::CreateHandleFromHeap: A(pRes); A(pI32); A(pI32); A(pI1); A(pI1); break;
  1227. // Unpacking intrinsics
  1228. case OpCode::Unpack4x8: VEC4(pETy); A(pI32); A(pI8); A(pI32); break;
  1229. // Packing intrinsics
  1230. case OpCode::Pack4x8: A(pI32); A(pI32); A(pI8); A(pETy); A(pETy); A(pETy); A(pETy); break;
  1231. // Helper Lanes
  1232. case OpCode::IsHelperLane: A(pI1); A(pI32); break;
  1233. // OPCODE-OLOAD-FUNCS:END
  1234. default: DXASSERT(false, "otherwise unhandled case"); break;
  1235. }
  1236. #undef RRT
  1237. #undef A
  1238. FunctionType *pFT;
  1239. DXASSERT(ArgTypes.size() > 1, "otherwise forgot to initialize arguments");
  1240. pFT = FunctionType::get(ArgTypes[0], ArrayRef<Type*>(&ArgTypes[1], ArgTypes.size()-1), false);
  1241. F = cast<Function>(m_pModule->getOrInsertFunction(funcName, pFT));
  1242. UpdateCache(opClass, pOverloadType, F);
  1243. F->setCallingConv(CallingConv::C);
  1244. F->addFnAttr(Attribute::NoUnwind);
  1245. if (m_OpCodeProps[(unsigned)opCode].FuncAttr != Attribute::None)
  1246. F->addFnAttr(m_OpCodeProps[(unsigned)opCode].FuncAttr);
  1247. return F;
  1248. }
  1249. const SmallMapVector<llvm::Type *, llvm::Function *, 8> &
  1250. OP::GetOpFuncList(OpCode opCode) const {
  1251. DXASSERT(0 <= (unsigned)opCode && opCode < OpCode::NumOpCodes,
  1252. "otherwise caller passed OOB OpCode");
  1253. _Analysis_assume_(0 <= (unsigned)opCode && opCode < OpCode::NumOpCodes);
  1254. return m_OpCodeClassCache[(unsigned)m_OpCodeProps[(unsigned)opCode]
  1255. .opCodeClass]
  1256. .pOverloads;
  1257. }
  1258. bool OP::IsDxilOpUsed(OpCode opcode) const {
  1259. auto &FnList = GetOpFuncList(opcode);
  1260. for (auto &it : FnList) {
  1261. llvm::Function *F = it.second;
  1262. if (!F) {
  1263. continue;
  1264. }
  1265. if (!F->user_empty()) {
  1266. return true;
  1267. }
  1268. }
  1269. return false;
  1270. }
  1271. void OP::RemoveFunction(Function *F) {
  1272. if (OP::IsDxilOpFunc(F)) {
  1273. OpCodeClass opClass = m_FunctionToOpClass[F];
  1274. for (auto it : m_OpCodeClassCache[(unsigned)opClass].pOverloads) {
  1275. if (it.second == F) {
  1276. m_OpCodeClassCache[(unsigned)opClass].pOverloads.erase(it.first);
  1277. m_FunctionToOpClass.erase(F);
  1278. break;
  1279. }
  1280. }
  1281. }
  1282. }
  1283. bool OP::GetOpCodeClass(const Function *F, OP::OpCodeClass &opClass) {
  1284. auto iter = m_FunctionToOpClass.find(F);
  1285. if (iter == m_FunctionToOpClass.end()) {
  1286. // When no user, cannot get opcode.
  1287. DXASSERT(F->user_empty() || !IsDxilOpFunc(F), "dxil function without an opcode class mapping?");
  1288. opClass = OP::OpCodeClass::NumOpClasses;
  1289. return false;
  1290. }
  1291. opClass = iter->second;
  1292. return true;
  1293. }
  1294. bool OP::UseMinPrecision() {
  1295. return m_LowPrecisionMode == DXIL::LowPrecisionMode::UseMinPrecision;
  1296. }
  1297. void OP::SetMinPrecision(bool bMinPrecision) {
  1298. DXIL::LowPrecisionMode mode =
  1299. bMinPrecision ? DXIL::LowPrecisionMode::UseMinPrecision
  1300. : DXIL::LowPrecisionMode::UseNativeLowPrecision;
  1301. DXASSERT((mode == m_LowPrecisionMode ||
  1302. m_LowPrecisionMode == DXIL::LowPrecisionMode::Undefined),
  1303. "LowPrecisionMode should only be set once.");
  1304. m_LowPrecisionMode = mode;
  1305. }
  1306. uint64_t OP::GetAllocSizeForType(llvm::Type *Ty) {
  1307. return m_pModule->getDataLayout().getTypeAllocSize(Ty);
  1308. }
  1309. llvm::Type *OP::GetOverloadType(OpCode opCode, llvm::Function *F) {
  1310. DXASSERT(F, "not work on nullptr");
  1311. Type *Ty = F->getReturnType();
  1312. FunctionType *FT = F->getFunctionType();
  1313. LLVMContext &Ctx = F->getContext();
  1314. /* <py::lines('OPCODE-OLOAD-TYPES')>hctdb_instrhelp.get_funcs_oload_type()</py>*/
  1315. switch (opCode) { // return OpCode
  1316. // OPCODE-OLOAD-TYPES:BEGIN
  1317. case OpCode::TempRegStore:
  1318. case OpCode::CallShader:
  1319. case OpCode::Pack4x8:
  1320. DXASSERT_NOMSG(FT->getNumParams() > 2);
  1321. return FT->getParamType(2);
  1322. case OpCode::MinPrecXRegStore:
  1323. case OpCode::StoreOutput:
  1324. case OpCode::BufferStore:
  1325. case OpCode::StorePatchConstant:
  1326. case OpCode::RawBufferStore:
  1327. case OpCode::StoreVertexOutput:
  1328. case OpCode::StorePrimitiveOutput:
  1329. case OpCode::DispatchMesh:
  1330. DXASSERT_NOMSG(FT->getNumParams() > 4);
  1331. return FT->getParamType(4);
  1332. case OpCode::IsNaN:
  1333. case OpCode::IsInf:
  1334. case OpCode::IsFinite:
  1335. case OpCode::IsNormal:
  1336. case OpCode::Countbits:
  1337. case OpCode::FirstbitLo:
  1338. case OpCode::FirstbitHi:
  1339. case OpCode::FirstbitSHi:
  1340. case OpCode::IMul:
  1341. case OpCode::UMul:
  1342. case OpCode::UDiv:
  1343. case OpCode::UAddc:
  1344. case OpCode::USubb:
  1345. case OpCode::WaveActiveAllEqual:
  1346. case OpCode::CreateHandleForLib:
  1347. case OpCode::WaveMatch:
  1348. DXASSERT_NOMSG(FT->getNumParams() > 1);
  1349. return FT->getParamType(1);
  1350. case OpCode::TextureStore:
  1351. DXASSERT_NOMSG(FT->getNumParams() > 5);
  1352. return FT->getParamType(5);
  1353. case OpCode::TraceRay:
  1354. DXASSERT_NOMSG(FT->getNumParams() > 15);
  1355. return FT->getParamType(15);
  1356. case OpCode::ReportHit:
  1357. DXASSERT_NOMSG(FT->getNumParams() > 3);
  1358. return FT->getParamType(3);
  1359. case OpCode::CreateHandle:
  1360. case OpCode::BufferUpdateCounter:
  1361. case OpCode::GetDimensions:
  1362. case OpCode::Texture2DMSGetSamplePosition:
  1363. case OpCode::RenderTargetGetSamplePosition:
  1364. case OpCode::RenderTargetGetSampleCount:
  1365. case OpCode::Barrier:
  1366. case OpCode::Discard:
  1367. case OpCode::EmitStream:
  1368. case OpCode::CutStream:
  1369. case OpCode::EmitThenCutStream:
  1370. case OpCode::CycleCounterLegacy:
  1371. case OpCode::WaveIsFirstLane:
  1372. case OpCode::WaveGetLaneIndex:
  1373. case OpCode::WaveGetLaneCount:
  1374. case OpCode::WaveAnyTrue:
  1375. case OpCode::WaveAllTrue:
  1376. case OpCode::WaveActiveBallot:
  1377. case OpCode::BitcastI16toF16:
  1378. case OpCode::BitcastF16toI16:
  1379. case OpCode::BitcastI32toF32:
  1380. case OpCode::BitcastF32toI32:
  1381. case OpCode::BitcastI64toF64:
  1382. case OpCode::BitcastF64toI64:
  1383. case OpCode::LegacyF32ToF16:
  1384. case OpCode::LegacyF16ToF32:
  1385. case OpCode::LegacyDoubleToFloat:
  1386. case OpCode::LegacyDoubleToSInt32:
  1387. case OpCode::LegacyDoubleToUInt32:
  1388. case OpCode::WaveAllBitCount:
  1389. case OpCode::WavePrefixBitCount:
  1390. case OpCode::IgnoreHit:
  1391. case OpCode::AcceptHitAndEndSearch:
  1392. case OpCode::WaveMultiPrefixBitCount:
  1393. case OpCode::SetMeshOutputCounts:
  1394. case OpCode::EmitIndices:
  1395. case OpCode::WriteSamplerFeedback:
  1396. case OpCode::WriteSamplerFeedbackBias:
  1397. case OpCode::WriteSamplerFeedbackLevel:
  1398. case OpCode::WriteSamplerFeedbackGrad:
  1399. case OpCode::AllocateRayQuery:
  1400. case OpCode::RayQuery_TraceRayInline:
  1401. case OpCode::RayQuery_Abort:
  1402. case OpCode::RayQuery_CommitNonOpaqueTriangleHit:
  1403. case OpCode::RayQuery_CommitProceduralPrimitiveHit:
  1404. case OpCode::AnnotateHandle:
  1405. case OpCode::CreateHandleFromBinding:
  1406. case OpCode::CreateHandleFromHeap:
  1407. return Type::getVoidTy(Ctx);
  1408. case OpCode::CheckAccessFullyMapped:
  1409. case OpCode::SampleIndex:
  1410. case OpCode::Coverage:
  1411. case OpCode::InnerCoverage:
  1412. case OpCode::ThreadId:
  1413. case OpCode::GroupId:
  1414. case OpCode::ThreadIdInGroup:
  1415. case OpCode::FlattenedThreadIdInGroup:
  1416. case OpCode::GSInstanceID:
  1417. case OpCode::OutputControlPointID:
  1418. case OpCode::PrimitiveID:
  1419. case OpCode::ViewID:
  1420. case OpCode::InstanceID:
  1421. case OpCode::InstanceIndex:
  1422. case OpCode::HitKind:
  1423. case OpCode::RayFlags:
  1424. case OpCode::DispatchRaysIndex:
  1425. case OpCode::DispatchRaysDimensions:
  1426. case OpCode::PrimitiveIndex:
  1427. case OpCode::Dot4AddI8Packed:
  1428. case OpCode::Dot4AddU8Packed:
  1429. case OpCode::RayQuery_CommittedStatus:
  1430. case OpCode::RayQuery_CandidateType:
  1431. case OpCode::RayQuery_RayFlags:
  1432. case OpCode::RayQuery_CandidateInstanceIndex:
  1433. case OpCode::RayQuery_CandidateInstanceID:
  1434. case OpCode::RayQuery_CandidateGeometryIndex:
  1435. case OpCode::RayQuery_CandidatePrimitiveIndex:
  1436. case OpCode::RayQuery_CommittedInstanceIndex:
  1437. case OpCode::RayQuery_CommittedInstanceID:
  1438. case OpCode::RayQuery_CommittedGeometryIndex:
  1439. case OpCode::RayQuery_CommittedPrimitiveIndex:
  1440. case OpCode::GeometryIndex:
  1441. case OpCode::RayQuery_CandidateInstanceContributionToHitGroupIndex:
  1442. case OpCode::RayQuery_CommittedInstanceContributionToHitGroupIndex:
  1443. return IntegerType::get(Ctx, 32);
  1444. case OpCode::CalculateLOD:
  1445. case OpCode::DomainLocation:
  1446. case OpCode::WorldRayOrigin:
  1447. case OpCode::WorldRayDirection:
  1448. case OpCode::ObjectRayOrigin:
  1449. case OpCode::ObjectRayDirection:
  1450. case OpCode::ObjectToWorld:
  1451. case OpCode::WorldToObject:
  1452. case OpCode::RayTMin:
  1453. case OpCode::RayTCurrent:
  1454. case OpCode::RayQuery_CandidateObjectToWorld3x4:
  1455. case OpCode::RayQuery_CandidateWorldToObject3x4:
  1456. case OpCode::RayQuery_CommittedObjectToWorld3x4:
  1457. case OpCode::RayQuery_CommittedWorldToObject3x4:
  1458. case OpCode::RayQuery_CandidateTriangleBarycentrics:
  1459. case OpCode::RayQuery_CommittedTriangleBarycentrics:
  1460. case OpCode::RayQuery_WorldRayOrigin:
  1461. case OpCode::RayQuery_WorldRayDirection:
  1462. case OpCode::RayQuery_RayTMin:
  1463. case OpCode::RayQuery_CandidateTriangleRayT:
  1464. case OpCode::RayQuery_CommittedRayT:
  1465. case OpCode::RayQuery_CandidateObjectRayOrigin:
  1466. case OpCode::RayQuery_CandidateObjectRayDirection:
  1467. case OpCode::RayQuery_CommittedObjectRayOrigin:
  1468. case OpCode::RayQuery_CommittedObjectRayDirection:
  1469. return Type::getFloatTy(Ctx);
  1470. case OpCode::MakeDouble:
  1471. case OpCode::SplitDouble:
  1472. return Type::getDoubleTy(Ctx);
  1473. case OpCode::RayQuery_Proceed:
  1474. case OpCode::RayQuery_CandidateProceduralPrimitiveNonOpaque:
  1475. case OpCode::RayQuery_CandidateTriangleFrontFace:
  1476. case OpCode::RayQuery_CommittedTriangleFrontFace:
  1477. case OpCode::IsHelperLane:
  1478. return IntegerType::get(Ctx, 1);
  1479. case OpCode::CBufferLoadLegacy:
  1480. case OpCode::Sample:
  1481. case OpCode::SampleBias:
  1482. case OpCode::SampleLevel:
  1483. case OpCode::SampleGrad:
  1484. case OpCode::SampleCmp:
  1485. case OpCode::SampleCmpLevelZero:
  1486. case OpCode::TextureLoad:
  1487. case OpCode::BufferLoad:
  1488. case OpCode::TextureGather:
  1489. case OpCode::TextureGatherCmp:
  1490. case OpCode::RawBufferLoad:
  1491. case OpCode::Unpack4x8:
  1492. {
  1493. StructType *ST = cast<StructType>(Ty);
  1494. return ST->getElementType(0);
  1495. }
  1496. // OPCODE-OLOAD-TYPES:END
  1497. default: return Ty;
  1498. }
  1499. }
  1500. Type *OP::GetHandleType() const {
  1501. return m_pHandleType;
  1502. }
  1503. Type *OP::GetResourcePropertiesType() const {
  1504. return m_pResourcePropertiesType;
  1505. }
  1506. Type *OP::GetResourceBindingType() const {
  1507. return m_pResourceBindingType;
  1508. }
  1509. Type *OP::GetDimensionsType() const
  1510. {
  1511. return m_pDimensionsType;
  1512. }
  1513. Type *OP::GetSamplePosType() const
  1514. {
  1515. return m_pSamplePosType;
  1516. }
  1517. Type *OP::GetBinaryWithCarryType() const {
  1518. return m_pBinaryWithCarryType;
  1519. }
  1520. Type *OP::GetBinaryWithTwoOutputsType() const {
  1521. return m_pBinaryWithTwoOutputsType;
  1522. }
  1523. Type *OP::GetSplitDoubleType() const {
  1524. return m_pSplitDoubleType;
  1525. }
  1526. Type *OP::GetFourI32Type() const {
  1527. return m_pFourI32Type;
  1528. }
  1529. Type *OP::GetFourI16Type() const {
  1530. return m_pFourI16Type;
  1531. }
  1532. bool OP::IsResRetType(llvm::Type *Ty) {
  1533. for (Type *ResTy : m_pResRetType) {
  1534. if (Ty == ResTy)
  1535. return true;
  1536. }
  1537. return false;
  1538. }
  1539. Type *OP::GetResRetType(Type *pOverloadType) {
  1540. unsigned TypeSlot = GetTypeSlot(pOverloadType);
  1541. if (m_pResRetType[TypeSlot] == nullptr) {
  1542. string TypeName("dx.types.ResRet.");
  1543. TypeName += GetOverloadTypeName(TypeSlot);
  1544. Type *FieldTypes[5] = { pOverloadType, pOverloadType, pOverloadType, pOverloadType, Type::getInt32Ty(m_Ctx) };
  1545. m_pResRetType[TypeSlot] = GetOrCreateStructType(m_Ctx, FieldTypes, TypeName, m_pModule);
  1546. }
  1547. return m_pResRetType[TypeSlot];
  1548. }
  1549. Type *OP::GetCBufferRetType(Type *pOverloadType) {
  1550. unsigned TypeSlot = GetTypeSlot(pOverloadType);
  1551. if (m_pCBufferRetType[TypeSlot] == nullptr) {
  1552. string TypeName("dx.types.CBufRet.");
  1553. TypeName += GetOverloadTypeName(TypeSlot);
  1554. Type *i64Ty = Type::getInt64Ty(pOverloadType->getContext());
  1555. Type *i16Ty = Type::getInt16Ty(pOverloadType->getContext());
  1556. if (pOverloadType->isDoubleTy() || pOverloadType == i64Ty) {
  1557. Type *FieldTypes[2] = { pOverloadType, pOverloadType };
  1558. m_pCBufferRetType[TypeSlot] = GetOrCreateStructType(m_Ctx, FieldTypes, TypeName, m_pModule);
  1559. }
  1560. else if (!UseMinPrecision() && (pOverloadType->isHalfTy() || pOverloadType == i16Ty)) {
  1561. TypeName += ".8"; // dx.types.CBufRet.fp16.8 for buffer of 8 halves
  1562. Type *FieldTypes[8] = {
  1563. pOverloadType, pOverloadType, pOverloadType, pOverloadType,
  1564. pOverloadType, pOverloadType, pOverloadType, pOverloadType,
  1565. };
  1566. m_pCBufferRetType[TypeSlot] = GetOrCreateStructType(m_Ctx, FieldTypes, TypeName, m_pModule);
  1567. }
  1568. else {
  1569. Type *FieldTypes[4] = { pOverloadType, pOverloadType, pOverloadType, pOverloadType };
  1570. m_pCBufferRetType[TypeSlot] = GetOrCreateStructType(m_Ctx, FieldTypes, TypeName, m_pModule);
  1571. }
  1572. }
  1573. return m_pCBufferRetType[TypeSlot];
  1574. }
  1575. Type *OP::GetVectorType(unsigned numElements, Type *pOverloadType) {
  1576. if (numElements == 4) {
  1577. if (pOverloadType == Type::getInt32Ty(pOverloadType->getContext())) {
  1578. return m_pFourI32Type;
  1579. }
  1580. else if (pOverloadType == Type::getInt16Ty(pOverloadType->getContext())) {
  1581. return m_pFourI16Type;
  1582. }
  1583. }
  1584. DXASSERT(false, "unexpected overload type");
  1585. return nullptr;
  1586. }
  1587. //------------------------------------------------------------------------------
  1588. //
  1589. // LLVM utility methods.
  1590. //
  1591. Constant *OP::GetI1Const(bool v) {
  1592. return Constant::getIntegerValue(IntegerType::get(m_Ctx, 1), APInt(1, v));
  1593. }
  1594. Constant *OP::GetI8Const(char v) {
  1595. return Constant::getIntegerValue(IntegerType::get(m_Ctx, 8), APInt(8, v));
  1596. }
  1597. Constant *OP::GetU8Const(unsigned char v) {
  1598. return GetI8Const((char)v);
  1599. }
  1600. Constant *OP::GetI16Const(int v) {
  1601. return Constant::getIntegerValue(IntegerType::get(m_Ctx, 16), APInt(16, v));
  1602. }
  1603. Constant *OP::GetU16Const(unsigned v) {
  1604. return GetI16Const((int)v);
  1605. }
  1606. Constant *OP::GetI32Const(int v) {
  1607. return Constant::getIntegerValue(IntegerType::get(m_Ctx, 32), APInt(32, v));
  1608. }
  1609. Constant *OP::GetU32Const(unsigned v) {
  1610. return GetI32Const((int)v);
  1611. }
  1612. Constant *OP::GetU64Const(unsigned long long v) {
  1613. return Constant::getIntegerValue(IntegerType::get(m_Ctx, 64), APInt(64, v));
  1614. }
  1615. Constant *OP::GetFloatConst(float v) {
  1616. return ConstantFP::get(m_Ctx, APFloat(v));
  1617. }
  1618. Constant *OP::GetDoubleConst(double v) {
  1619. return ConstantFP::get(m_Ctx, APFloat(v));
  1620. }
  1621. } // namespace hlsl