DxilOperations.cpp 117 KB

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