DxilOperations.cpp 129 KB

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