DxilOperations.cpp 120 KB

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