DXIL.rst 189 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291
  1. =============================
  2. DirectX Intermediate Language
  3. =============================
  4. .. contents::
  5. :local:
  6. :depth: 2
  7. Introduction
  8. ============
  9. This document presents the design of the DirectX Intermediate Language (DXIL) for GPU shaders. DXIL is intended to support a direct mapping of the HLSL programming language into Low-Level Virtual Machine Intermediate Representation (LLVM IR), suitable for consumption in GPU drivers. This version of the specification is based on LLVM 3.7 in the use of metadata syntax.
  10. We distinguish between DXIL, which is a low-level IR for GPU driver compilers, and DXIR, which is a high-level IR, more suitable for emission by IR producers, such as Clang. DXIR is transformed to DXIL by the optimizer. DXIR accepts high-level constructs, such as user-defined types, multi-dimensional arrays, matrices, and vectors. These, however, are not suitable for fast JIT-ing in the driver compilers, and so are lowered by the optimizer, such that DXIL works on simpler abstractions. Both DXIL and DXIR are derived from LLVM IR. This document does not describe DXIR.
  11. LLVM is quickly becoming a de facto standard in modern compilation technology. The LLVM framework offers several distinct features, such as a vibrant ecosystem, complete compilation framework, modular design, and reasonable documentation. We can leverage these to achieve two important objectives.
  12. First, unification of shader compilation tool chain. DXIL is a contract between IR producers, such as compilers for HLSL and other domain-specific languages, and IR consumers, such as IHV driver JIT compilers or offline XBOX shader compiler. In addition, the design provides for conversion the current HLSL IL, called DXBC IL in this document, to DXIL.
  13. Second, leveraging the LLVM ecosystem. Microsoft will publicly document DXIL and DXIR to attract domain language implementers and spur innovation. Using LLVM-based IR offers reduced entry costs for small teams, simply because small teams are likely to use LLVM and Clang as their main compilation framework. We will provide DXIL verifier to check consistency of generated DXIL.
  14. The following diagram shows how some of these components tie together::
  15. HLSL Other shading langs DSL DXBC IL
  16. + + + +
  17. | | | |
  18. v v v v
  19. Clang Clang Other Tools dxbc2dxil
  20. + + + +
  21. | | | |
  22. v v v |
  23. +------+--------------------+---------+ |
  24. | High level IR (DXIR) | |
  25. +-------------------------------------+ |
  26. | |
  27. | |
  28. v |
  29. Optimizer <-----+ Linker |
  30. + ^ + |
  31. | | | |
  32. | | | |
  33. +------------v------+-------------v-----v-------+
  34. | Low level IR (DXIL) |
  35. +------------+----------------------+-----------+
  36. | |
  37. v v
  38. Driver Compiler Verifier
  39. The *dxbc2dxil* element in the diagram is a component that converts existing DXBC shader byte code into DXIL. The *Optimizer* element is a component that consumes DXIR, verifies it is valid, optimizes it, and produces a valid DXIL form. The *Verifier* element is a public component that verifies and signs DXIL. The *Linker* is a component that combines precompiled DXIL libraries with the entry function to produce a valid shader.
  40. DXIL does not support the following HLSL features that were present in prior implementations.
  41. * Shader models 9 and below. Microsoft may implement 10level9 shader models via DXIL capability tiers.
  42. * Effects.
  43. * HLSL interfaces.
  44. * Shader compression/decompression.
  45. * Partial precision. Half data type should be used instead.
  46. * min10float type. Half data type should be used instead.
  47. * HLSL *uniform* parameter qualifier.
  48. * Current fxc legacy compatibility mode for old shader models (e.g., c-register binding).
  49. * PDB. Debug Information annotations are used instead.
  50. * Compute shader model cs_4_0.
  51. * DXBC label, call, fcall constructs.
  52. The following principles are used to ease reuse with LLVM components and aid extensibility.
  53. * DXIL uses a subset of LLVM IR constructs that makes sense for HLSL.
  54. * No modifications to the core LLVM IR; i.e., no new instructions or fundamental types.
  55. * Additional information is conveyed via metadata, LLVM intrinsics or external functions.
  56. * Name prefixes: 'llvm.dx.', 'llvm.dxil.', 'llvm.dxir.', 'dx.', 'dxil.', and 'dxir.' are reserved.
  57. LLVM IR has three equivalent forms: human-readable, binary (bitcode), and in-memory. DXIL is a binary format and is based on a subset of LLVM IR bitcode format. The document uses only human-readable form to describe DXIL.
  58. Versioning
  59. ==========
  60. There are three versioning mechanisms in DXIL shaders: shader model, DXIL version, and LLVM bitcode version.
  61. At a high-level, the shader model describes the target execution model and environment; DXIL provides a mechanism to express programs (including rules around expressing data types and operations); and LLVM bitcode provides a way to encode a DXIL program.
  62. Shader Model
  63. ------------
  64. The shader model in DXIL is similar to DXBC shader model. A shader model specifies the execution model, the set of capabilities that shader instructions can use and the constraints that a shader program must adhere to.
  65. The shader model is specified as a named metadata in DXIL::
  66. !dx.shaderModel = !{ !0 }
  67. !0 = !{ !"<shadelModelName>", i32 <major>, i32 <minor> }
  68. The following values of <shaderModelName>_<major>_<minor> are supported:
  69. ==================== ===================================== ===========
  70. Target Legacy Models DXIL Models
  71. ==================== ===================================== ===========
  72. Vertex shader (VS) vs_4_0, vs_4_1, vs_5_0, vs_5_1 vs_6_0
  73. Hull shader (HS) hs_5_0, hs_5_1 hs_6_0
  74. Domain shader (DS) ds_5_0, ds_5_1 ds_6_0
  75. Geometry shader (GS) gs_4_0, gs_4_1, gs_5_0, gs_5_1 gs_6_0
  76. Pixel shader (PS) ps_4_0, ps_4_1, ps_5_0, ps_5_1 ps_6_0
  77. Compute shader (CS) cs_5_0 (cs_4_0 is mapped onto cs_5_0) cs_6_0
  78. Shader library no support lib_6_1
  79. Mesh shader (MS) no support ms_6_5
  80. Amplification shader (AS) no support as_6_5
  81. ========================= ===================================== ===========
  82. The DXIL verifier ensures that DXIL conforms to the specified shader model.
  83. For shader models prior to 6.0, only the rules applicable to the DXIL representation are valid. For example, the limits on maximum number of resources is honored, but the limits on registers aren't because DXIL does not have a representation for registers.
  84. DXIL version
  85. ------------
  86. The primary mechanism to evolve HLSL capabilities is through shader models. However, DXIL version is reserved for additional flexibility of future extensions. There are two currently defined versions: 1.0 and 1.1.
  87. DXIL version has major and minor versions that are specified as named metadata::
  88. !dx.version = !{ !0 }
  89. !0 = !{ i32 <major>, i32 <minor> }
  90. DXIL version must be declared exactly once per LLVM module (translation unit) and is valid for the entire module.
  91. DXIL will evolve in a manner that retains backward compatibility.
  92. DXIL 1.1 Changes
  93. ----------------
  94. Main two features that were introduced for DXIL1.1 (Shader Model 6.1) are view instancing and barycentric coordinates. Specifically, there are following changes to the DXIL representation.
  95. * New Intrinsics - AttributeAtVertex_, ViewID
  96. * New System Generated Value - SV_Barycentrics
  97. * New Container Part - ILDN
  98. DXIL 1.2 Changes
  99. ----------------
  100. * RawBufferLoad and RawBufferStore DXIL operations for ByteAddressBuffer and StructuredBuffer
  101. * Denorm mode as a function attribute for float32 "fp32-denorm-mode"=<value>
  102. LLVM Bitcode version
  103. --------------------
  104. The current version of DXIL is based on LLVM bitcode v3.7. This encoding is necessarily implied by something outside the DXIL module.
  105. General Issues
  106. ==============
  107. An important goal is to enable HLSL to be closer to a strict subset of C/C++. This has implications for DXIL design and future hardware feature requests outlined below.
  108. Terminology
  109. -----------
  110. Resource refers to one of the following:
  111. * SRV - shader resource view (read-only)
  112. * UAV - unordered access view (read-write)
  113. * CBV - constant buffer view (read-only)
  114. * Sampler
  115. Intrinsics typically refer to operations missing in the core LLVM IR. DXIL represents HLSL built-in functions (also called intrinsics) not as LLVM intrinsics, but rather as external function calls.
  116. DXIL abstraction level
  117. ----------------------
  118. DXIL has level of abstraction similar to a 'scalarized' DXBC. DXIL is lower level IR than DXIR emitted by the front-end to be amenable to fast and robust JIT-ing in driver compilers.
  119. In particular, the following passes are performed to lower the HLSL/DXIR abstractions down to DXIL:
  120. * optimize function parameter copies
  121. * inline functions
  122. * allocate and transform shader signatures
  123. * lower matrices, optimizing intermediate storage
  124. * linearize multi-dimensional arrays and user-defined type accesses
  125. * scalarize vectors
  126. Scalar IR
  127. ---------
  128. DXIL operations work with scalar quantities. Several scalar quantities may be grouped together in a struct to represent several return values, which is used for memory operations, e.g., load/store, sample, etc., that benefit from access coalescing.
  129. Metadata, resource declarations, and debugging info may contain vectors to more closely convey source code shape to tools and debuggers.
  130. Future versions of IR may contain vectors or grouping hints for less-than-32-bit quantities, such as half and i16.
  131. Memory accesses
  132. ---------------
  133. DXIL conceptually aligns with DXBC in how different memory types are accessed. Out-of-bounds behavior and various restrictions are preserved.
  134. Indexable thread-local and groupshared variables are represented as variables and accessed via LLVM C-like pointers.
  135. Swizzled resources, such as textures, have opaque memory layouts from a DXIL point of view. Accesses to these resources are done via intrinsics.
  136. There are two layouts for constant buffer memory: (1) legacy, matching DXBC's layout and (2) linear layout. SM6 DXIL uses intrinsics to read cbuffer for either layout.
  137. Shader signatures require packing and are located in a special type of memory that cannot be viewed as linear. Accesses to signature values are done via special intrinsics in DXIL. If a signature parameter needs to be passed to a function, a copy is created first in threadlocal memory and the copy is passed to the function.
  138. Typed buffers represent memory with in-flight data conversion. Typed buffer load/store/atomics are done via special functions in DXIL with element-granularity indexing.
  139. The following pointer types are supported:
  140. * Non-indexable thread-local variables.
  141. * Indexable thread-local variables (DXBC x-registers).
  142. * Groupshared variables (DXBC g-registers).
  143. * Device memory pointer.
  144. * Constant-buffer-like memory pointer.
  145. The type of DXIL pointer is differentiated by LLVM addrspace construct. The HLSL compiler will make the best effort to infer the exact pointer addrspace such that a driver compiler can issue the most efficient instruction.
  146. A pointer can come into being in a number of ways:
  147. * Global Variables.
  148. * AllocaInst.
  149. * Synthesized as a result of some pointer arithmetic.
  150. DXIL uses 32-bit pointers in its representation.
  151. Out-of-bounds behavior
  152. ----------------------
  153. Indexable thread-local accesses are done via LLVM pointer and have C-like OOB semantics.
  154. Groupshared accesses are done via LLVM pointer too. The origin of a groupshared pointer must be a single TGSM allocation.
  155. If a groupshared pointer uses in-bound GEP instruction, it should not OOB. The behavior for an OOB access for in-bound pointer is undefined.
  156. For groupshared pointer from regular GEP, OOB will has same behavior as DXBC. Loads return 0 for OOB accesses; OOB stores are silently dropped.
  157. Resource accesses keeps the same out-of-bounds behavior as DXBC. Loads return 0 for OOB accesses; OOB stores are silently dropped.
  158. OOB pointer accesses in SM6.0 and later have undefined (C-like) behavior. LLVM memory optimization passes can be used to optimize such accesses. Where out-of-bound behavior is desired, intrinsic functions are used to access memory.
  159. Memory access granularity
  160. -------------------------
  161. Intrinsic and resource accesses may imply a wider access than requested by an instruction. DXIL defines memory accesses for i1, i16, i32, i64, f16, f32, f64 on thread local memory, and i32, f32, f64 for memory I/O (that is, groupshared memory and memory accessed via resources such as CBs, UAVs and SRVs).
  162. Number of virtual values
  163. ------------------------
  164. There is no limit on the number of virtual values in DXIL. The IR is guaranteed to be in an SSA form. For optimized shaders, the optimizer will run -mem2reg LLVM pass as well as perform other memory to register promotions if profitable.
  165. Control-flow restrictions
  166. -------------------------
  167. The DXIL control-flow graph must be reducible, as checked by T1-T2 test. DXIL does not preserve structured control flow of DXBC. Preserving structured control-flow property would impose significant burden on third-party tools optimizing to DXIL via LLVM, reducing appeal of DXIL.
  168. DXIL allows fall-through for switch label blocks. This is a difference from DXBC, in which the fall-through is prohibited.
  169. DXIL will not support the DXBC label and call instructions; LLVM functions can be used instead (see below). The primary uses for these are (1) HLSL interfaces, which are not supported, and (2) outlining of case-bodies in a switch statement annotated with [call], which is not a scenario of interest.
  170. Functions
  171. ---------
  172. Instead of DXBC labels/calls, DXIL supports functions and call instructions. Recursion is not allowed; DXIL validator enforces this.
  173. The functions are regular LLVM functions. Parameters can be passed by-value or by-reference. The functions are to facilitate separate compilation for big, complex shaders. However, driver compilers are free to inline functions as they see fit.
  174. Identifiers
  175. -----------
  176. DXIL identifiers must conform to LLVM IR identifier rules.
  177. Identifier mangling rules are the ones used by Clang 3.7 with the HLSL target.
  178. The following identifier prefixes are reserved:
  179. * dx.*, dxil.*, dxir.*
  180. * llvm.dx.*, llvm.dxil.*, llvm.dxir.*
  181. Address Width
  182. -------------
  183. DXIL will use only 32-bit addresses for pointers. Byte offsets are also 32-bit.
  184. Shader restrictions
  185. -------------------
  186. There is no support for the following in DXIL:
  187. * recursion
  188. * exceptions
  189. * indirect function calls and dynamic dispatch
  190. Entry points
  191. ------------
  192. The dx.entryPoints metadata specifies a list of entry point records, one for each entry point. Libraries could specify more than one entry point per module but currently exist outside the DXIL specification; the other shader models must specify exactly one entry point.
  193. For example::
  194. define void @"\01?myfunc1@@YAXXZ"() #0 { ... }
  195. define float @"\01?myfunc2@@YAMXZ"() #0 { ... }
  196. !dx.entryPoints = !{ !1, !2 }
  197. !1 = !{ void ()* @"\01?myfunc1@@YAXXZ", !"myfunc1", !3, null, null }
  198. !2 = !{ float ()* @"\01?myfunc2@@YAMXZ", !"myfunc2", !5, !6, !7 }
  199. Each entry point metadata record specifies:
  200. * reference to the entry point function global symbol
  201. * unmangled name
  202. * list of signatures
  203. * list of resources
  204. * list of tag-value pairs of shader capabilities and other properties
  205. A 'null' value specifies absence of a particular node.
  206. Shader capabilities are properties that are additional to properties dictated by shader model. The list is organized as pairs of i32 tag, followed immediately by the value itself.
  207. Hull shader representation
  208. --------------------------
  209. The hull shader is represented as two functions, related via metadata: (1) control point phase function, which is the entry point of the hull shader, and (2) patch constant phase function.
  210. For example::
  211. !dx.entryPoints = !{ !1 }
  212. !1 = !{ void ()* @"ControlPointFunc", ..., !2 } ; shader entry record
  213. !2 = !{ !"HS", !3 }
  214. !3 = !{ void ()* @"PatchConstFunc", ... } ; additional hull shader state
  215. The patch constant function represents original HLSL computation, and is not separated into fork and join phases, as it is the case in DXBC. The driver compiler may perform such separation if this is profitable for the target GPU.
  216. In DXBC to DXIL conversion, the original patch constant function cannot be recovered during DXBC-to-DXIL conversion. Instead, instructions of each fork and join phases are 'wrapped' by a loop that iterates the corresponding number of phase-instance-count iterations. Thus, fork/join instance ID becomes the loop induction variable. LoadPatchConstant intrinsic (see below) represents load from DXBC vpc register.
  217. The following table summarizes the names of intrinsic functions to load inputs and store outputs of hull and domain shaders. CP stands for Control Point, PC - for Patch Constant.
  218. =================== ==================== ====================== ======================
  219. Operation Control Point (Hull) Patch Constant Domain
  220. =================== ==================== ====================== ======================
  221. Store Input CP
  222. Load Input CP LoadInput LoadInput
  223. Store Output CP StoreOutput
  224. Load Output CP LoadOutputControlPoint LoadInput
  225. Store PC StorePatchConstant
  226. Load PC LoadPatchConstant LoadPatchConstant
  227. Store Output Vertex StoreOutput
  228. =================== ==================== ====================== ======================
  229. LoadPatchConstant function in PC stage is generated only by DXBC-to-DXIL converter, to access DXBC vpc registers. HLSL compiler produces IR that references LLVM IR values directly.
  230. Type System
  231. ===========
  232. Most of LLVM type system constructs are legal in DXIL.
  233. Primitive Types
  234. ---------------
  235. The following types are supported:
  236. * void
  237. * metadata
  238. * i1, i8, i16, i32, i64
  239. * half, float, double
  240. SM6.0 assumes native hardware support for i32 and float types.
  241. i8 is supported only in a few intrinsics to signify masks, enumeration constant values, or in metadata. It's not supported for memory access or computation by the shader.
  242. HLSL min12int, min16int and min16uint data types are mapped to i16.
  243. half and i16 are treated as corresponding DXBC min-presicion types (min16float, min16int/min16uint) in SM6.0.
  244. The HLSL compiler optimizer treats half, i16 and i8 data as data types natively supported by the hardware; i.e., saturation, range clipping, INF/NaN are done according to the IEEE standard. Such semantics allow the optimizer to reuse LLVM optimization passes.
  245. Hardware support for doubles in optional and is guarded by RequiresHardwareDouble CAP bit.
  246. Hardware support for i64 is optional and is guarded by a CAP bit.
  247. Vectors
  248. -------
  249. HLSL vectors are scalarized. They do not participate in computation; however, they may be present in declarations to convey original variable layout to tools, debuggers, and reflection.
  250. Future DXIL may add support for <2 x half> and <2 x i16> vectors or hints for packing related half and i16 quantities.
  251. Matrices
  252. --------
  253. Matrices are lowered to vectors, and are not referenced by instructions. They may be present in declarations to convey original variable layout to tools, debuggers, and reflection.
  254. Arrays
  255. ------
  256. Instructions may reference only 1D arrays of primitive types. However, complex arrays, e.g., multidimensional arrays or user-defined types, may be present to convey original variable layout to tools, debuggers, and reflection.
  257. User-defined types
  258. ------------------
  259. Original HLSL UDTs are lowered and are not referenced by instructions. However, they may be present in declarations to convey original variable layout to tools, debuggers, and reflection. Some resource operations return 'grouping' UDTs that group several return values; such UDTs are immediately 'decomposed' into components that are then consumed by other instructions.
  260. Type conversions
  261. ----------------
  262. Explicit conversions between types are supported via LLVM instructions.
  263. Precise qualifier
  264. -----------------
  265. By default, all floating-point HLSL operations are considered 'fast' or non-precise. HLSL and driver compilers are allowed to refactor such operations. Non-precise LLVM instructions: fadd, fsub, fmul, fdiv, frem, fcmp are marked with 'fast' math flags.
  266. HLSL precise type qualifier requires that all operations contributing to the value be IEEE compliant with respect to optimizations. The /Gis compiler switch implicitly declares all variables and values as precise.
  267. Precise behavior is represented in LLVM instructions: fadd, fsub, fmul, fdiv, frem, fcmp by not having 'fast' math flags set. Each relevant call instruction that contributes to computation of a precise value is annotated with dx.precise metadata that indicates that it is illegal for the driver compiler to perform IEEE-unsafe optimizations.
  268. .. _type-annotations:
  269. Type annotations
  270. ----------------
  271. User-defined types are annotated in DXIL to 'attach' additional properties to structure fields. For example, DXIL may contain type annotations of structures and funcitons for reflection purposes::
  272. namespace MyNameSpace {
  273. struct MyType {
  274. float field1;
  275. int2 field2;
  276. };
  277. }
  278. float main(float col : COLOR) : SV_Target {
  279. .....
  280. }
  281. !dx.typeAnnotations = !{!3, !7}
  282. !3 = !{i32 0, %"struct.MyNameSpace::MyType" undef, !4}
  283. !4 = !{i32 12, !5, !6}
  284. !5 = !{i32 6, !"field1", i32 3, i32 0, i32 7, i32 9}
  285. !6 = !{i32 6, !"field2", i32 3, i32 4, i32 7, i32 4}
  286. !7 = !{i32 1, void (float, float*)* @"main", !8}
  287. !8 = !{!9, !11, !14}
  288. !9 = !{i32 0, !10, !10}
  289. !10 = !{}
  290. !11 = !{i32 0, !12, !13}
  291. !12 = !{i32 4, !"COLOR", i32 7, i32 9}
  292. !13 = !{i32 0}
  293. !14 = !{i32 1, !15, !13}
  294. !15 = !{i32 4, !"SV_Target", i32 7, i32 9}
  295. !16 = !{null, !"lib.no::entry", null, null, null}
  296. The type/field annotation metadata hierarchy recursively mimics LLVM type hierarchy.
  297. dx.typeAnnotations is a metadata of type annotation nodes, where each node represents type annotation of a certain type::
  298. !dx.typeAnnotations = !{!3, !7}
  299. For each **type annotation** node, the first value represents the type of the annotation::
  300. !3 = !{i32 0, %"struct.MyNameSpace::MyType" undef, !4}
  301. !7 = !{i32 1, void (float, float*)* @"main", !8}
  302. === =====================================================================
  303. Idx Type
  304. === =====================================================================
  305. 0 Structure Annotation
  306. 1 Function Annotation
  307. === =====================================================================
  308. The second value represents the name, the third is a corresponding type metadata node.
  309. **Structure Annotation** starts with the size of the structure in bytes, followed by the list of field annotations::
  310. !4 = !{i32 12, !5, !6}
  311. !5 = !{i32 6, !"field1", i32 3, i32 0, i32 7, i32 9}
  312. !6 = !{i32 6, !"field2", i32 3, i32 4, i32 7, i32 4}
  313. **Field Annotation** is a series of pairs with tag number followed by its value. Field Annotation pair is defined as follows
  314. === =====================================================================
  315. Idx Type
  316. === =====================================================================
  317. 0 SNorm
  318. 1 UNorm
  319. 2 Matrix
  320. 3 Buffer Offset
  321. 4 Semantic String
  322. 5 Interpolation Mode
  323. 6 Field Name
  324. 7 Component Type
  325. 8 Precise
  326. === =====================================================================
  327. **Function Annotation** is a series of parameter annotations::
  328. !7 = !{i32 1, void (float, float*)* @"main", !8}
  329. !8 = !{!9, !11, !14}
  330. Each **Parameter Annotation** contains Input/Output type, field annotation, and semantic index::
  331. !9 = !{i32 0, !10, !10}
  332. !10 = !{}
  333. !11 = !{i32 0, !12, !13}
  334. !12 = !{i32 4, !"COLOR", i32 7, i32 9}
  335. !13 = !{i32 0}
  336. !14 = !{i32 1, !15, !13}
  337. !15 = !{i32 4, !"SV_Target", i32 7, i32 9}
  338. Shader Properties and Capabilities
  339. ==================================
  340. Additional shader properties are specified via tag-value pair list, which is the last element in the entry function description record.
  341. Shader Flags
  342. ------------
  343. Shaders have additional flags that covey their capabilities via tag-value pair with tag kDxilShaderFlagsTag (0), followed by an i64 bitmask integer. The bits have the following meaning:
  344. === =====================================================================
  345. Bit Description
  346. === =====================================================================
  347. 0 Disable shader optimizations
  348. 1 Disable math refactoring
  349. 2 Shader uses doubles
  350. 3 Force early depth stencil
  351. 4 Enable raw and structured buffers
  352. 5 Shader uses min-precision, expressed as half and i16
  353. 6 Shader uses double extension intrinsics
  354. 7 Shader uses MSAD
  355. 8 All resources must be bound for the duration of shader execution
  356. 9 Enable view port and RT array index from any stage feeding rasterizer
  357. 10 Shader uses inner coverage
  358. 11 Shader uses stencil
  359. 12 Shader uses intrinsics that access tiled resources
  360. 13 Shader uses relaxed typed UAV load formats
  361. 14 Shader uses Level9 comparison filtering
  362. 15 Shader uses up to 64 UAVs
  363. 16 Shader uses UAVs
  364. 17 Shader uses CS4 raw and structured buffers
  365. 18 Shader uses Rasterizer Ordered Views
  366. 19 Shader uses wave intrinsics
  367. 20 Shader uses int64 instructions
  368. === =====================================================================
  369. Geometry Shader
  370. ---------------
  371. Geometry shader properties are specified via tag-value pair with tag kDxilGSStateTag (1), followed by a list of GS properties. The format of this list is the following.
  372. === ==== ===============================================================
  373. Idx Type Description
  374. === ==== ===============================================================
  375. 0 i32 Input primitive (InputPrimitive enum value).
  376. 1 i32 Max vertex count.
  377. 2 i32 Primitive topology for stream 0 (PrimitiveTopology enum value).
  378. 3 i32 Primitive topology for stream 1 (PrimitiveTopology enum value).
  379. 4 i32 Primitive topology for stream 2 (PrimitiveTopology enum value).
  380. 5 i32 Primitive topology for stream 3 (PrimitiveTopology enum value).
  381. === ==== ===============================================================
  382. Domain Shader
  383. -------------
  384. Domain shader properties are specified via tag-value pair with tag kDxilDSStateTag (2), followed by a list of DS properties. The format of this list is the following.
  385. === ==== ===============================================================
  386. Idx Type Description
  387. === ==== ===============================================================
  388. 0 i32 Tessellator domain (TessellatorDomain enum value).
  389. 1 i32 Input control point count.
  390. === ==== ===============================================================
  391. Hull Shader
  392. -----------
  393. Hull shader properties are specified via tag-value pair with tag kDxilHSStateTag (3), followed by a list of HS properties. The format of this list is the following.
  394. === ======= =====================================================================
  395. Idx Type Description
  396. === ======= =====================================================================
  397. 0 MDValue Patch constant function (global symbol).
  398. 1 i32 Input control point count.
  399. 2 i32 Output control point count.
  400. 3 i32 Tessellator domain (TessellatorDomain enum value).
  401. 4 i32 Tessellator partitioning (TessellatorPartitioning enum value).
  402. 5 i32 Tessellator output primitive (TessellatorOutputPrimitive enum value).
  403. 6 float Max tessellation factor.
  404. === ======= =====================================================================
  405. Compute Shader
  406. --------------
  407. Compute shader has the following tag-value properties.
  408. ===================== ======================== =============================================
  409. Tag Value Description
  410. ===================== ======================== =============================================
  411. kDxilNumThreadsTag(4) MD list: (i32, i32, i32) Number of threads (X,Y,Z) for compute shader.
  412. ===================== ======================== =============================================
  413. Shader Parameters and Signatures
  414. ================================
  415. This section formalizes how HLSL shader input and output parameters are expressed in DXIL.
  416. HLSL signatures and semantics
  417. -----------------------------
  418. Formal parameters of a shader entry function in HLSL specify how the shader interacts with the graphics pipeline. Input parameters, referred to as an input signature, specify values received by the shader. Output parameters, referred to as an output signature, specify values produced by the shader. The shader compiler maps HLSL input and output signatures into DXIL specifications that conform to hardware constraints outlined in the Direct3D Functional Specification. DXIL specifications are also called signatures.
  419. Signature mapping is a complex process, as there are many constraints. All signature parameters must fit into a finite space of N 4x32-bit registers. For efficiency reasons, parameters are packed together in a way that does not violate specification constraints. The process is called signature packing. Most signatures are tightly packed; however, the VS input signature is not packed, as the values are coming from the Input Assembler (IA) stage rather than the graphics pipeline. Alternately, the PS output signature is allocated to align the SV_Target semantic index with the output register index.
  420. Each HLSL signature parameter is defined via C-like type, interpolation mode, and semantic name and index. The type defines parameter shape, which may be quite complex. Interpolation mode adds to the packing constraints, namely that parameters packed together must have compatible interpolation modes. Semantics are extra names associated with parameters for the following purposes: (1) to specify whether a parameter is as a special System Value (SV) or not, (2) to link parameters to IA or StreamOut API streams, and (3) to aid debugging. Semantic index is used to disambiguate parameters that use the same semantic name, or span multiple rows of the register space.
  421. SV semantics add specific meanings and constraints to associated parameters. A parameter may be supplied by the hardware, and is then known as a System Generated Value (SGV). Alternatively, a parameter may be interpreted by the hardware and is then known as System Interpreted Value (SIV). SGVs and SIVs are pipeline-stage dependent; moreover, some participate in signature packing and some do not. Non-SV semantics always participate in signature packing.
  422. Most System Generated Values (SGV) are loaded using special Dxil intrinsic functions, rather than loading the input from a signature. These usually will not be present in the signature at all. Their presence may be detected by the declaration and use of the special instrinsic function itself. The exceptions to this are notible. In one case they are present and loaded from the signature instead of a special intrinsic because they must be part of the packed signature potentially passed from the prior stage, allowing the prior stage to override these values, such as for SV_PrimitiveID and SV_IsFrontFace that may be written in the the Geometry Shader. In another case, they identify signature elements that still contribute to DXBC signature for informational purposes, but will only use the special intrinsic function to read the value, such as for SV_PrimitiveID for GS input and SampleIndex for PS input.
  423. The classification of behavior for various system values in various signature locations is described in a table organized by SemanticKind and SigPointKind. The SigPointKind is a new classification that uniquely identifies each set of parameters that may be input or output for each entry point. For each combination of SemanticKind and SigPointKind, there is a SemanticInterpretationKind that defines the class of treatment for that location.
  424. Each SigPointKind also has a corresponding element allocation (or packing) behavior called PackingKind. Some SigPointKinds do not result in a signature at all, which corresponds to the packing kind of PackingKind::None.
  425. Signature Points are enumerated as follows in the SigPointKind
  426. .. <py>import hctdb_instrhelp</py>
  427. .. <py::lines('SIGPOINT-RST')>hctdb_instrhelp.get_sigpoint_rst()</py>
  428. .. SIGPOINT-RST:BEGIN
  429. == ======== ======= ============= ============== ================ ============================================================================
  430. ID SigPoint Related ShaderKind PackingKind SignatureKind Description
  431. == ======== ======= ============= ============== ================ ============================================================================
  432. 0 VSIn Invalid Vertex InputAssembler Input Ordinary Vertex Shader input from Input Assembler
  433. 1 VSOut Invalid Vertex Vertex Output Ordinary Vertex Shader output that may feed Rasterizer
  434. 2 PCIn HSCPIn Hull None Invalid Patch Constant function non-patch inputs
  435. 3 HSIn HSCPIn Hull None Invalid Hull Shader function non-patch inputs
  436. 4 HSCPIn Invalid Hull Vertex Input Hull Shader patch inputs - Control Points
  437. 5 HSCPOut Invalid Hull Vertex Output Hull Shader function output - Control Point
  438. 6 PCOut Invalid Hull PatchConstant PatchConstOrPrim Patch Constant function output - Patch Constant data passed to Domain Shader
  439. 7 DSIn Invalid Domain PatchConstant PatchConstOrPrim Domain Shader regular input - Patch Constant data plus system values
  440. 8 DSCPIn Invalid Domain Vertex Input Domain Shader patch input - Control Points
  441. 9 DSOut Invalid Domain Vertex Output Domain Shader output - vertex data that may feed Rasterizer
  442. 10 GSVIn Invalid Geometry Vertex Input Geometry Shader vertex input - qualified with primitive type
  443. 11 GSIn GSVIn Geometry None Invalid Geometry Shader non-vertex inputs (system values)
  444. 12 GSOut Invalid Geometry Vertex Output Geometry Shader output - vertex data that may feed Rasterizer
  445. 13 PSIn Invalid Pixel Vertex Input Pixel Shader input
  446. 14 PSOut Invalid Pixel Target Output Pixel Shader output
  447. 15 CSIn Invalid Compute None Invalid Compute Shader input
  448. 16 MSIn Invalid Mesh None Invalid Mesh Shader input
  449. 17 MSOut Invalid Mesh Vertex Output Mesh Shader vertices output
  450. 18 MSPOut Invalid Mesh Vertex PatchConstOrPrim Mesh Shader primitives output
  451. 19 ASIn Invalid Amplification None Invalid Amplification Shader input
  452. == ======== ======= ============= ============== ================ ============================================================================
  453. .. SIGPOINT-RST:END
  454. Semantic Interpretations are as follows (SemanticInterpretationKind)
  455. .. <py>import hctdb_instrhelp</py>
  456. .. <py::lines('SEMINT-RST')>hctdb_instrhelp.get_sem_interpretation_enum_rst()</py>
  457. .. SEMINT-RST:BEGIN
  458. == ========== =============================================================
  459. ID Name Description
  460. == ========== =============================================================
  461. 0 NA Not Available
  462. 1 SV Normal System Value
  463. 2 SGV System Generated Value (sorted last)
  464. 3 Arb Treated as Arbitrary
  465. 4 NotInSig Not included in signature (intrinsic access)
  466. 5 NotPacked Included in signature, but does not contribute to packing
  467. 6 Target Special handling for SV_Target
  468. 7 TessFactor Special handling for tessellation factors
  469. 8 Shadow Shadow element must be added to a signature for compatibility
  470. 8 ClipCull Special packing rules for SV_ClipDistance or SV_CullDistance
  471. == ========== =============================================================
  472. .. SEMINT-RST:END
  473. Semantic Interpretations for each SemanticKind at each SigPointKind are as follows
  474. .. <py>import hctdb_instrhelp</py>
  475. .. <py::lines('SEMINT-TABLE-RST')>hctdb_instrhelp.get_sem_interpretation_table_rst()</py>
  476. .. SEMINT-TABLE-RST:BEGIN
  477. ====================== ============ ======== ============ ============ ======== ======== ========== ============ ======== ======== ======== ============ ======== ============= ============= ======== ======== ======== ========= ========
  478. Semantic VSIn VSOut PCIn HSIn HSCPIn HSCPOut PCOut DSIn DSCPIn DSOut GSVIn GSIn GSOut PSIn PSOut CSIn MSIn MSOut MSPOut ASIn
  479. ====================== ============ ======== ============ ============ ======== ======== ========== ============ ======== ======== ======== ============ ======== ============= ============= ======== ======== ======== ========= ========
  480. Arbitrary Arb Arb NA NA Arb Arb Arb Arb Arb Arb Arb NA Arb Arb NA NA NA Arb Arb NA
  481. VertexID SV NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
  482. InstanceID SV Arb NA NA Arb Arb NA NA Arb Arb Arb NA Arb Arb NA NA NA NA NA NA
  483. Position Arb SV NA NA SV SV Arb Arb SV SV SV NA SV SV NA NA NA SV NA NA
  484. RenderTargetArrayIndex Arb SV NA NA SV SV Arb Arb SV SV SV NA SV SV NA NA NA NA SV NA
  485. ViewPortArrayIndex Arb SV NA NA SV SV Arb Arb SV SV SV NA SV SV NA NA NA NA SV NA
  486. ClipDistance Arb ClipCull NA NA ClipCull ClipCull Arb Arb ClipCull ClipCull ClipCull NA ClipCull ClipCull NA NA NA ClipCull NA NA
  487. CullDistance Arb ClipCull NA NA ClipCull ClipCull Arb Arb ClipCull ClipCull ClipCull NA ClipCull ClipCull NA NA NA ClipCull NA NA
  488. OutputControlPointID NA NA NA NotInSig NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
  489. DomainLocation NA NA NA NA NA NA NA NotInSig NA NA NA NA NA NA NA NA NA NA NA NA
  490. PrimitiveID NA NA NotInSig NotInSig NA NA NA NotInSig NA NA NA Shadow SGV SGV NA NA NA NA SV NA
  491. GSInstanceID NA NA NA NA NA NA NA NA NA NA NA NotInSig NA NA NA NA NA NA NA NA
  492. SampleIndex NA NA NA NA NA NA NA NA NA NA NA NA NA Shadow _41 NA NA NA NA NA NA
  493. IsFrontFace NA NA NA NA NA NA NA NA NA NA NA NA SGV SGV NA NA NA NA NA NA
  494. Coverage NA NA NA NA NA NA NA NA NA NA NA NA NA NotInSig _50 NotPacked _41 NA NA NA NA NA
  495. InnerCoverage NA NA NA NA NA NA NA NA NA NA NA NA NA NotInSig _50 NA NA NA NA NA NA
  496. Target NA NA NA NA NA NA NA NA NA NA NA NA NA NA Target NA NA NA NA NA
  497. Depth NA NA NA NA NA NA NA NA NA NA NA NA NA NA NotPacked NA NA NA NA NA
  498. DepthLessEqual NA NA NA NA NA NA NA NA NA NA NA NA NA NA NotPacked _50 NA NA NA NA NA
  499. DepthGreaterEqual NA NA NA NA NA NA NA NA NA NA NA NA NA NA NotPacked _50 NA NA NA NA NA
  500. StencilRef NA NA NA NA NA NA NA NA NA NA NA NA NA NA NotPacked _50 NA NA NA NA NA
  501. DispatchThreadID NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NotInSig NotInSig NA NA NotInSig
  502. GroupID NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NotInSig NotInSig NA NA NotInSig
  503. GroupIndex NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NotInSig NotInSig NA NA NotInSig
  504. GroupThreadID NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NotInSig NotInSig NA NA NotInSig
  505. TessFactor NA NA NA NA NA NA TessFactor TessFactor NA NA NA NA NA NA NA NA NA NA NA NA
  506. InsideTessFactor NA NA NA NA NA NA TessFactor TessFactor NA NA NA NA NA NA NA NA NA NA NA NA
  507. ViewID NotInSig _61 NA NotInSig _61 NotInSig _61 NA NA NA NotInSig _61 NA NA NA NotInSig _61 NA NotInSig _61 NA NA NotInSig NA NA NA
  508. Barycentrics NA NA NA NA NA NA NA NA NA NA NA NA NA NotPacked _61 NA NA NA NA NA NA
  509. ShadingRate NA SV _64 NA NA SV _64 SV _64 NA NA SV _64 SV _64 SV _64 NA SV _64 SV _64 NA NA NA NA SV NA
  510. CullPrimitive NA NA NA NA NA NA NA NA NA NA NA NA NA NotInSig NA NA NA NA NotPacked NA
  511. ====================== ============ ======== ============ ============ ======== ======== ========== ============ ======== ======== ======== ============ ======== ============= ============= ======== ======== ======== ========= ========
  512. .. SEMINT-TABLE-RST:END
  513. Below is a vertex shader example that is used for illustration throughout this section::
  514. struct Foo {
  515. float a;
  516. float b[2];
  517. };
  518. struct VSIn {
  519. uint vid : SV_VertexID;
  520. float3 pos : Position;
  521. Foo foo[3] : SemIn1;
  522. float f : SemIn10;
  523. };
  524. struct VSOut
  525. {
  526. float f : SemOut1;
  527. Foo foo[3] : SemOut2;
  528. float4 pos : SV_Position;
  529. };
  530. void main(in VSIn In, // input signature
  531. out VSOut Out) // output signature
  532. {
  533. ...
  534. }
  535. Signature packing must be efficient. It should use as few registers as possible, and the packing algorithm should run in reasonable time. The complication is that the problem is NP complete, and the algorithm needs to resort to using a heuristic.
  536. While the details of the packing algorithm are not important at the moment, it is important to outline some concepts related to how a packed signature is represented in DXIL. Packing is further complicated by the complexity of parameter shapes induced by the C/C++ type system. In the example above, fields of Out.foo array field are actually arrays themselves, strided in memory. Allocating such strided shapes efficiently is hard. To simplify packing, the first step is to break user-defined (struct) parameters into constituent components and to make strided arrays contiguous. This preparation step enables the algorithm to operate on dense rectangular shapes, which we call signature elements. The output signature in the example above has the following elements: float Out_f, float Out_foo_a[3], float Out_foo_b[2][3], and float4 pos. Each element is characterized by the number of rows and columns. These are 1x1, 3x1, 6x1, and 1x4, respectively. The packing algorithm reduces to fitting these elements into Nx4 register space, satisfying all packing-compatibility constraints.
  537. Signature element record
  538. ------------------------
  539. Each signature element is represented in DXIL as a metadata record.
  540. For above example output signature, the element records are as follows::
  541. ; element ID, semantic name, etype, sv, s.idx, interp, rows, cols, start row, col, ext. list
  542. !20 = !{i32 6, !"SemOut", i8 0, i8 0, !40, i8 2, i32 1, i8 1, i32 1, i8 2, null}
  543. !21 = !{i32 7, !"SemOut", i8 0, i8 0, !41, i8 2, i32 3, i8 1, i32 1, i8 1, null}
  544. !22 = !{i32 8, !"SemOut", i8 0, i8 0, !42, i8 2, i32 6, i8 1, i32 1, i8 0, null}
  545. !23 = !{i32 9, !"SV_Position", i8 0, i8 3, !43, i8 2, i32 1, i8 4, i32 0, i8 0, null}
  546. A record contains the following fields.
  547. === =============== ===============================================================================
  548. Idx Type Description
  549. === =============== ===============================================================================
  550. 0 i32 Unique signature element record ID, used to identify the element in operations.
  551. 1 String metadata Semantic name.
  552. 2 i8 ComponentType (enum value).
  553. 3 i8 SemanticKind (enum value).
  554. 4 Metadata Metadata list that enumerates all semantic indexes of the flattened parameter.
  555. 5 i8 InterpolationMode (enum value).
  556. 6 i32 Number of element rows.
  557. 7 i8 Number of element columns.
  558. 8 i32 Starting row of element packing location.
  559. 9 i8 Starting column of element packing location.
  560. 10 Metadata Metadata list of additional tag-value pairs; can be 'null' or empty.
  561. === =============== ===============================================================================
  562. Semantic name system values always start with 'S', 'V', '_' , and it is illegal to start a user semantic with this prefix. Non-SVs can be ignored by drivers. Debug layers may use these to help validate signature compatibility between stages.
  563. The last metadata list is used to specify additional properties and future extensions.
  564. Signature record metadata
  565. -------------------------
  566. A shader typically has two signatures: input and output, while domain shader has an additional patch constant signature. The signatures are composed of signature element records and are attached to the shader entry metadata. The examples below clarify metadata details.
  567. Vertex shader HLSL
  568. ~~~~~~~~~~~~~~~~~~
  569. Here is the HLSL of the above vertex shader. The semantic index assignment is explained in section below::
  570. struct Foo
  571. {
  572. float a;
  573. float b[2];
  574. };
  575. struct VSIn
  576. {
  577. uint vid : SV_VertexID;
  578. float3 pos : Position;
  579. Foo foo[3] : SemIn1;
  580. // semantic index assignment:
  581. // foo[0].a : SemIn1
  582. // foo[0].b[0] : SemIn2
  583. // foo[0].b[1] : SemIn3
  584. // foo[1].a : SemIn4
  585. // foo[1].b[0] : SemIn5
  586. // foo[1].b[1] : SemIn6
  587. // foo[2].a : SemIn7
  588. // foo[2].b[0] : SemIn8
  589. // foo[2].b[1] : SemIn9
  590. float f : SemIn10;
  591. };
  592. struct VSOut
  593. {
  594. float f : SemOut1;
  595. Foo foo[3] : SemOut2;
  596. // semantic index assignment:
  597. // foo[0].a : SemOut2
  598. // foo[0].b[0] : SemOut3
  599. // foo[0].b[1] : SemOut4
  600. // foo[1].a : SemOut5
  601. // foo[1].b[0] : SemOut6
  602. // foo[1].b[1] : SemOut7
  603. // foo[2].a : SemOut8
  604. // foo[2].b[0] : SemOut9
  605. // foo[2].b[1] : SemOut10
  606. float4 pos : SV_Position;
  607. };
  608. void main(in VSIn In, // input signature
  609. out VSOut Out) // output signature
  610. {
  611. ...
  612. }
  613. The input signature is packed to be compatible with the IA stage. A packing algorithm must assign the following starting positions to the input signature elements:
  614. =================== ==== ======= ========= ===========
  615. Input element Rows Columns Start row Start column
  616. =================== ==== ======= ========= ===========
  617. uint VSIn.vid 1 1 0 0
  618. float3 VSIn.pos 1 3 1 0
  619. float VSIn.foo.a[3] 3 1 2 0
  620. float VSIn.foo.b[6] 6 1 5 0
  621. float VSIn.f 1 1 11 0
  622. =================== ==== ======= ========= ===========
  623. A reasonable packing algorithm would assign the following starting positions to the output signature elements:
  624. ==================== ==== ======= ========= ===========
  625. Input element Rows Columns Start row Start column
  626. ==================== ==== ======= ========= ===========
  627. uint VSOut.f 1 1 1 2
  628. float VSOut.foo.a[3] 3 1 1 1
  629. float VSOut.foo.b[6] 6 1 1 0
  630. float VSOut.pos 1 4 0 0
  631. ==================== ==== ======= ========= ===========
  632. Semantic index assignment
  633. ~~~~~~~~~~~~~~~~~~~~~~~~~
  634. Semantic index assignment in DXIL is exactly the same as for DXBC. Semantic index assignment, abbreviated s.idx above, is a consecutive enumeration of all fields under the same semantic name as if the signature were packed for the IA stage. That is, given a complex signature element, e.g., VSOut's foo[3] with semantic name SemOut and starting index 2, the element is flattened into individual fields: foo[0].a, foo[0].b[0], ..., foo[2].b[1], and the fields receive consecutive semantic indexes 2, 3, ..., 10, respectively. Semantic-index pairs are used to set up the IA stage and to capture values of individual signature registers via the StreamOut API.
  635. DXIL for VS signatures
  636. ~~~~~~~~~~~~~~~~~~~~~~
  637. The corresponding DXIL metadata is presented below::
  638. !dx.entryPoints = !{ !1 }
  639. !1 = !{ void @main(), !"main", !2, null, null }
  640. ; Signatures: In, Out, Patch Constant (optional)
  641. !2 = !{ !3, !4, null }
  642. ; Input signature (packed accordiong to IA rules)
  643. !3 = !{ !10, !11, !12, !13, !14 }
  644. ; element idx, semantic name, etype, sv, s.idx, interp, rows, cols, start row, col, ext. list
  645. !10 = !{i32 1, !"SV_VertexID", i8 0, i8 1, !30, i32 0, i32 1, i8 1, i32 0, i8 0, null}
  646. !11 = !{i32 2, !"Position", i8 0, i8 0, !30, i32 0, i32 1, i8 3, i32 1, i8 0, null}
  647. !12 = !{i32 3, !"SemIn", i8 0, i8 0, !32, i32 0, i32 3, i8 1, i32 2, i8 0, null}
  648. !13 = !{i32 4, !"SemIn", i8 0, i8 0, !33, i32 0, i32 6, i8 1, i32 5, i8 0, null}
  649. !14 = !{i32 5, !"SemIn", i8 0, i8 0, !34, i32 0, i32 1, i8 1, i32 11, i8 0, null}
  650. ; semantic index assignment:
  651. !30 = !{ i32 0 }
  652. !32 = !{ i32 1, i32 4, i32 7 }
  653. !33 = !{ i32 2, i32 3, i32 5, i32 6, i32 8, i32 9 }
  654. !34 = !{ i32 10 }
  655. ; Output signature (tightly packed according to pipeline stage packing rules)
  656. !4 = !{ !20, !21, !22, !23 }
  657. ; element ID, semantic name, etype, sv, s.idx, interp, rows, cols, start row, col, ext. list
  658. !20 = !{i32 6, !"SemOut", i8 0, i8 0, !40, i32 2, i32 1, i8 1, i32 1, i8 2, null}
  659. !21 = !{i32 7, !"SemOut", i8 0, i8 0, !41, i32 2, i32 3, i8 1, i32 1, i8 1, null}
  660. !22 = !{i32 8, !"SemOut", i8 0, i8 0, !42, i32 2, i32 6, i8 1, i32 1, i8 0, null}
  661. !23 = !{i32 9, !"SV_Position", i8 0, i8 3, !43, i32 2, i32 1, i8 4, i32 0, i8 0, null}
  662. ; semantic index assignment:
  663. !40 = !{ i32 1 }
  664. !41 = !{ i32 2, i32 5, i32 8 }
  665. !42 = !{ i32 3, i32 4, i32 6, i32 7, i32 9, i32 10 }
  666. !43 = !{ i32 0 }
  667. Hull shader example
  668. ~~~~~~~~~~~~~~~~~~~
  669. A hull shader (HS) is defined by two entry point functions: control point (CP) function to compute control points, and patch constant (PC) function to compute patch constant data, including the tessellation factors. The inputs to both functions are the input control points for an entire patch, and therefore each element may be indexed by row and, in addition, is indexed by vertex.
  670. Here is an HS example entry point metadata and signature list::
  671. ; !105 is extended parameter list containing reference to HS State:
  672. !101 = !{ void @HSMain(), !"HSMain", !102, null, !105 }
  673. ; Signatures: In, Out, Patch Constant
  674. !102 = !{ !103, !104, !204 }
  675. The entry point record specifies: (1) CP function HSMain as the main symbol, and (2) PC function via optional metadata node !105.
  676. CP-input signature describing one input control point::
  677. !103 = !{ !110, !111 }
  678. ; element ID, semantic name, etype, sv, s.idx, interp, rows, cols, start row, col, ext. list
  679. !110= !{i32 1, !"SV_Position", i8 0, i8 3, !130, i32 0, i32 1, i8 4, i32 0, i8 0, null}
  680. !111= !{i32 2, !"array", i8 0, i8 0, !131, i32 0, i32 4, i8 3, i32 1, i8 0, null}
  681. ; semantic indexing for flattened elements:
  682. !130 = !{ i32 0 }
  683. !131 = !{ i32 0, i32 1, i32 2, i32 3 }
  684. Note that SV_OutputControlPointID and SV_PrimitiveID input elements are SGVs loaded through special Dxil intrinsics, and are not present in the signature at all. These have a semantic interpretation of SemanticInterpretationKind::NotInSig.
  685. CP-output signature describing one output control point::
  686. !104 = !{ !120, !121 }
  687. ; element ID, semantic name, etype, sv, s.idx, interp, rows, cols, start row, col, ext. list
  688. !120= !{i32 3, !"SV_Position", i8 0, i8 3, !130, i32 0, i32 1, i8 4, i32 0, i8 0, null}
  689. !121= !{i32 4, !"array", i8 0, i8 0, !131, i32 0, i32 4, i8 3, i32 1, i8 0, null}
  690. Hull shaders require an extended parameter that defines extra state::
  691. ; extended parameter HS State
  692. !105 = !{ i32 3, !201 }
  693. ; HS State record defines patch constant function and other properties
  694. ; Patch Constant Function, in CP count, out CP count, tess domain, tess part, out prim, max tess factor
  695. !201 = !{ void @PCMain(), 4, 4, 3, 1, 3, 16.0 }
  696. PC-output signature::
  697. !204 = !{ !220, !221, !222 }
  698. ; element ID, semantic name, etype, sv, s.idx, interp, rows, cols, start row, col, ext. list
  699. !220= !{i32 3, !"SV_TessFactor", i8 0, i8 25, !130, i32 0, i32 4, i8 1, i32 0, i8 3, null}
  700. !221= !{i32 4, !"SV_InsideTessFactor", i8 0, i8 26, !231, i32 0, i32 2, i8 1, i32 4, i8 3, null}
  701. !222= !{i32 5, !"array", i8 0, i8 0, !131, i32 0, i32 4, i8 3, i32 0, i8 0, null}
  702. ; semantic indexing for flattened elements:
  703. !231 = !{ i32 0, i32 1 }
  704. Accessing signature value in operations
  705. ---------------------------------------
  706. There are no function parameters or variables that correspond to signature elements. Instead loadInput and storeOutput functions are used to access signature element values in operations. The accesses are scalar.
  707. These are the operation signatures::
  708. ; overloads: SM5.1: f16|f32|i16|i32, SM6.0: f16|f32|f64|i8|i16|i32|i64
  709. declare float @dx.op.loadInput.f32(
  710. i32, ; opcode
  711. i32, ; input ID
  712. i32, ; row (relative to start row of input ID)
  713. i8, ; column (relative to start column of input ID), constant in [0,3]
  714. i32) ; vertex index
  715. ; overloads: SM5.1: f16|f32|i16|i32, SM6.0: f16|f32|f64|i8|i16|i32|i64
  716. declare void @dx.op.storeOutput.f32(
  717. i32, ; opcode
  718. i32, ; output ID
  719. i32, ; row (relative to start row of output ID)
  720. i8, ; column (relative to start column of output ID), constant in [0,3]
  721. float) ; value to store
  722. LoadInput/storeOutput takes input/output element ID, which is the unique ID of a signature element metadata record. The row parameter is the array element row index from the start of the element; the register index is obtained by adding the start row of the element and the row parameter value. Similarly, the column parameter is relative column index; the packed register component is obtained by adding the start component of the element (packed col) and the column value. Several overloads exist to access elements of different primitive types. LoadInput takes an additional vertex index parameter that represents vertex index for DS CP-inputs and GS inputs; vertex index must be undef in other cases.
  723. Signature packing
  724. -----------------
  725. Signature elements must be packed into a space of N 4-32-bit registers according to runtime constraints. DXIL contains packed signatures. The packing algorithm is more aggressive than that for DX11. However, DXIL packing is only a suggestion to the driver implementation. Driver compilers can rearrange signature elements as they see fit, while preserving compatibility of connected pipeline stages. DXIL is designed in such a way that it is easy to 'relocate' signature elements - loadInput/storeOutput row and column indices do not need to change since they are relative to the start row/column for each element.
  726. Signature packing types
  727. ~~~~~~~~~~~~~~~~~~~~~~~
  728. Two pipeline stages can connect in four different ways, resulting in four packing types.
  729. 1. Input Assembly: VS input only
  730. * Elements all map to unique registers, they may not be packed together.
  731. * Interpolation mode is not used.
  732. 2. Connects to Rasterizer: VS output, HS CP-input/output and PC-input, DS CP-input/output, GS input/output, PS input
  733. * Elements can be packed according to constraints.
  734. * Interpolation mode is used and must be consistent between connecting signatures.
  735. * While HS CP-output and DS CP-input signatures do not go through the rasterizer, they are still treated as such. The reason is the pass-through HS case, in which HS CP-input and HS CP-output must have identical packing for efficiency.
  736. 3. Patch Constant: HS PC-output, DS PC-input
  737. * SV_TessFactor and SV_InsideTessFactor are the only SVs relevant here, and this is the only location where they are legal. These have special packing considerations.
  738. * Interpolation mode is not used.
  739. 4. Pixel Shader Output: PS output only
  740. * Only SV_Target maps to output register space.
  741. * No packing is performed, semantic index corresponds to render target index.
  742. Packing constraints
  743. ~~~~~~~~~~~~~~~~~~~
  744. The packing algorithm is stricter and more aggressive in DXIL than in DXBC, although still compatible. In particular, array signature elements are not broken up into scalars, even if each array access can be disambiguated to a literal index. DXIL and DXBC signature packing are not identical, so linking them together into a single pipeline is not supported across compiler generations.
  745. The row dimension of a signature element represents an index range. If constraints permit, two adjacent or overlapping index ranges are coalesced into a single index range.
  746. Packing constraints are as follows:
  747. 1. A register must have only one interpolation mode for all 4 components.
  748. 2. Register components containing SVs must be to the right of components containing non-SVs.
  749. 3. SV_ClipDistance and SV_CullDistance have additional constraints:
  750. a. May be packed together
  751. b. Must occupy a maximum of 2 registers (8-components)
  752. c. SV_ClipDistance must have linear interpolation mode
  753. 4. Registers containing SVs may not be within an index range, with the exception of Tessellation Factors (TessFactors).
  754. 5. If an index range R1 overlaps with a TessFactor index range R2, R1 must be contained within R2. As a consequence, outside and inside TessFactors occupy disjoint index ranges when packed.
  755. 6. Non-TessFactor index ranges are combined into a larger range, if they overlap.
  756. 7. SGVs must be packed after all non-SGVs have been packed. If there are several SGVs, they are packed in the order of HLSL declaration.
  757. Packing for SGVs
  758. ~~~~~~~~~~~~~~~~
  759. Non-SGV portions of two connecting signatures must match; however, SGV portions don't have to. An example would be a PS declaring SV_PrimitiveID as an input. If VS connects to PS, PS's SV_PrimitiveID value is synthesized by hardware; moreover, it is illegal to output SV_PrimitiveID from a VS. If GS connects PS, GS may declare SV_PrimitiveID as its output.
  760. Unfortunately, SGV specification creates a complication for separate compilation of connecting shaders. For example, GS outputs SV_PrimitiveID, and PS inputs SV_IsFrontFace and SV_PrimitiveID in this order. The positions of SV_PrimitiveID are incompatible in GS and PS signatures. Not much can be done about this ambiguity in SM5.0 and earlier; the programmers will have to rely on SDKLayers to catch potential mismatch.
  761. SM5.1 and later shaders work on D3D12+ runtime that uses PSO objects to describe pipeline state. Therefore, a driver compiler has access to both connecting shaders during compilation, even though the HLSL compiler does not. The driver compiler can resolve SGV ambiguity in signatures easily. For SM5.1 and later, the HLSL compiler will ensure that declared SGVs fit into packed signature; however, it will set SGV's start row-column location to (-1, 0) such that the driver compiler must resolve SGV placement during PSO compilation.
  762. Shader Resources
  763. ================
  764. All global resources referenced by entry points of an LLVM module are described via named metadata dx.resources, which consists of four metadata lists of resource records::
  765. !dx.resources = !{ !1, !2, !3, !4 }
  766. Resource lists are as follows.
  767. === ======== ==============================
  768. Idx Type Description
  769. === ======== ==============================
  770. 0 Metadata SRVs - shader resource views.
  771. 1 Metadata UAVs - unordered access views.
  772. 2 Metadata CBVs - constant buffer views.
  773. 3 Metadata Samplers.
  774. === ======== ==============================
  775. Metadata resource records
  776. -------------------------
  777. Each resource list contains resource records. Each resource record contains fields that are common for each resource type, followed by fields specific to each resource type, followed by a metadata list of tag/value pairs, which can be used to specify additional properties or future extensions and may be null or empty.
  778. Common fields:
  779. === =============== ==========================================================================================
  780. Idx Type Description
  781. === =============== ==========================================================================================
  782. 0 i32 Unique resource record ID, used to identify the resource record in createHandle operation.
  783. 1 Pointer Pointer to a global constant symbol with the original shape of resource and element type.
  784. 2 Metadata string Name of resource variable.
  785. 3 i32 Bind space ID of the root signature range that corresponds to this resource.
  786. 4 i32 Bind lower bound of the root signature range that corresponds to this resource.
  787. 5 i32 Range size of the root signature range that corresponds to this resource.
  788. === =============== ==========================================================================================
  789. When the shader has reflection information, the name is the original, unmangled HLSL name. If reflection is stripped, the name is empty string.
  790. SRV-specific fields:
  791. === =============== ==========================================================================================
  792. Idx Type Description
  793. === =============== ==========================================================================================
  794. 6 i32 SRV resource shape (enum value).
  795. 7 i32 SRV sample count.
  796. 8 Metadata Metadata list of additional tag-value pairs.
  797. === =============== ==========================================================================================
  798. SRV-specific tag/value pairs:
  799. === === ==== =================================================== ============================================
  800. Idx Tag Type Resource Type Description
  801. === === ==== =================================================== ============================================
  802. 0 0 i32 Any resource, except RawBuffer and StructuredBuffer Element type.
  803. 1 1 i32 StructuredBuffer Element stride or StructureBuffer, in bytes.
  804. === === ==== =================================================== ============================================
  805. The symbol names for the are kDxilTypedBufferElementTypeTag (0) and kDxilStructuredBufferElementStrideTag (1).
  806. UAV-specific fields:
  807. === =============== ==========================================================================================
  808. Idx Type Description
  809. === =============== ==========================================================================================
  810. 6 i32 UAV resource shape (enum value).
  811. 7 i1 1 - globally-coherent UAV; 0 - otherwise.
  812. 8 i1 1 - UAV has counter; 0 - otherwise.
  813. 9 i1 1 - UAV is ROV (rasterizer ordered view); 0 - otherwise.
  814. 10 Metadata Metadata list of additional tag-value pairs.
  815. === =============== ==========================================================================================
  816. UAV-specific tag/value pairs:
  817. === === ==== ====================================================== ============================================
  818. Idx Tag Type Resource Type Description
  819. === === ==== ====================================================== ============================================
  820. 0 0 i32 RW resource, except RWRawBuffer and RWStructuredBuffer Element type.
  821. 1 1 i32 RWStructuredBuffer Element stride or StructureBuffer, in bytes.
  822. === === ==== ====================================================== ============================================
  823. The symbol names for the are kDxilTypedBufferElementTypeTag (0) and kDxilStructuredBufferElementStrideTag (1).
  824. CBV-specific fields:
  825. === =============== ==========================================================================================
  826. Idx Type Description
  827. === =============== ==========================================================================================
  828. 6 i32 Constant buffer size in bytes.
  829. 7 Metadata Metadata list of additional tag-value pairs.
  830. === =============== ==========================================================================================
  831. Sampler-specific fields:
  832. === =============== ==========================================================================================
  833. Idx Type Description
  834. === =============== ==========================================================================================
  835. 6 i32 Sampler type (enum value).
  836. 7 Metadata Metadata list of additional tag-value pairs.
  837. === =============== ==========================================================================================
  838. The following example demonstrates SRV metadata::
  839. ; Original HLSL
  840. ; Texture2D<float4> MyTexture2D : register(t0, space0);
  841. ; StructuredBuffer<NS1::MyType1> MyBuffer[2][3] : register(t1, space0);
  842. !1 = !{ !2, !3 }
  843. ; Scalar resource: Texture2D<float4> MyTexture2D.
  844. %dx.types.ResElem.v4f32 = type { <4 x float> }
  845. @MyTexture2D = external addrspace(1) constant %dx.types.ResElem.v4f32, align 16
  846. !2 = !{ i32 0, %dx.types.ResElem.v4f32 addrspace(1)* @MyTexture2D, !"MyTexture2D",
  847. i32 0, i32 0, i32 1, i32 2, i32 0, null }
  848. ; Array resource: StructuredBuffer<MyType1> MyBuffer[2][3].
  849. %struct.NS1.MyType1 = type { float, <2 x i32> }
  850. %dx.types.ResElem.NS1.MyType1 = type { %struct.NS1.MyType1 }
  851. @MyBuffer = external addrspace(1) constant [2x [3 x %dx.types.ResElem.NS1.MyType1]], align 16
  852. !3 = !{ i32 1, [2 x [3 x %dx.types.ResElem.NS1.MyType1]] addrspace(1)* @MyBuffer, !"MyBuffer",
  853. i32 0, i32 1, i32 6, i32 11, i32 0, null }
  854. The type name of the variable is constructed by appending the element name (primitive, vector or UDT name) to dx.types.ResElem prefix. The type configuration of the resource range variable conveys (1) resource range shape and (2) resource element type.
  855. Reflection information
  856. ----------------------
  857. Resource reflection data is conveyed via the resource's metadata record and global, external variable. The metadata record contains the original HLSL name, root signature range information, and the reference to the global resource variable declaration. The resource variable declaration conveys resource range shape, resource type and resource element type.
  858. The following disassembly provides an example::
  859. ; Scalar resource: Texture2D<float4> MyTexture2D.
  860. %dx.types.ResElem.v4f32 = type { <4 x float> }
  861. @MyTexture2D = external addrspace(1) constant %dx.types.ResElem.v4f32, align 16
  862. !0 = !{ i32 0, %dx.types.ResElem.v4f32 addrspace(1)* @MyTexture2D, !"MyTexture2D",
  863. i32 0, i32 3, i32 1, i32 2, i32 0, null }
  864. ; struct MyType2 { float4 field1; int2 field2; };
  865. ; Constant buffer: ConstantBuffer<MyType2> MyCBuffer1[][3] : register(b5, space7)
  866. %struct.MyType2 = type { <4 x float>, <2 x i32> }
  867. ; Type reflection information (optional)
  868. !struct.MyType2 = !{ !1, !2 }
  869. !1 = !{ !"field1", null }
  870. !2 = !{ !"field2", null }
  871. %dx.types.ResElem.MyType1 = type { %struct.MyType2 }
  872. @MyCBuffer1 = external addrspace(1) constant [0 x [3 x %dx.types.ResElem.MyType2]], align 16
  873. !3 = !{ i32 0, [0 x [3 x %dx.types.ResElem.MyType1]] addrspace(1)* @MyCBuffer1, !"MyCBuffer1",
  874. i32 7, i32 5, i32 -1, null }
  875. The reflection information can be removed from DXIL by obfuscating the resource HLSL name and resource variable name as well as removing reflection type annotations, if any.
  876. Structure of resource operation
  877. -------------------------------
  878. Operations involving shader resources and samplers are expressed via external function calls.
  879. Below is an example for the sample method::
  880. %dx.types.ResRet.f32 = type { float, float, float, float, i32 }
  881. declare %dx.types.ResRet.f32 @dx.op.sample.f32(
  882. i32, ; opcode
  883. %dx.types.ResHandle, ; texture handle
  884. %dx.types.SamplerHandle, ; sampler handle
  885. float, ; coordinate c0
  886. float, ; coordinate c1
  887. float, ; coordinate c2
  888. float, ; coordinate c3
  889. i32, ; offset o0
  890. i32, ; offset o1
  891. i32, ; offset o2
  892. float) ; clamp
  893. The method always returns five scalar values that are aggregated in dx.types.ResRet.f32 type and extracted into scalars via LLVM's extractelement right after the call. The first four elements are sample values and the last field is the status of operation for tiled resources. Some return values may be unused, which is easily determined from the SSA form. The driver compiler is free to specialize the sample instruction to the most efficient form depending on which return values are used in computation.
  894. If applicable, each intrinsic is overloaded on return type, e.g.::
  895. %dx.types.ResRet.f32 = type { float, float, float, float, i32 }
  896. %dx.types.ResRet.f16 = type { half, half, half, half, i32 }
  897. declare %dx.types.ResRet.f32 @dx.op.sample.f32(...)
  898. declare %dx.types.ResRet.f16 @dx.op.sample.f16(...)
  899. Wherever applicable, the return type indicates the "precision" at which the operation is executed. For example, sample intrinsic that returns half data is allowed to be executed at half precision, assuming hardware supports this; however, if the return type is float, the sample operation must be executed in float precision. If lower-precision is not supported by hardware, it is allowed to execute a higher-precision variant of the operation.
  900. The opcode parameter uniquely identifies the sample operation. More details can be found in the Instructions section. The value of opcode is the same for all overloads of an operation.
  901. Some resource operations are "polymorphic" with respect to resource types, e.g., dx.op.sample.f32 operates on several resource types: Texture1D[Array], Texture2D[Array], Texture3D, TextureCUBE[Array].
  902. Each resource/sampler is represented by a pair of i32 values. The first value is a unique (virtual) resource range ID, which corresponds to HLSL declaration of a resource/sampler. Range ID must be a constant for SM5.1 and below. The second integer is a 0-based index within the range. The index must be constant for SM5.0 and below.
  903. Both indices can be dynamic for SM6 and later to provide flexibility in usage of resources/samplers in control flow, e.g.::
  904. Texture2D<float4> a[8], b[8];
  905. ...
  906. Texture2D<float4> c;
  907. if(cond) // arbitrary expression
  908. c = a[idx1];
  909. else
  910. c = b[idx2];
  911. ... = c.Sample(...);
  912. Resources/samplers used in such a way must reside in descriptor tables (cannot be root descriptors); this will be validated during shader and root signature setup.
  913. The DXIL verifier will ensure that all leaf-ranges (a and b above) of such a resource/sampler live-range have the same resource/sampler type and element type. If applicable, this constraint may be relaxed in the future. In particular, it is logical from HLSL programmer point of view to issue loads on compatible resource types, e.g., Texture2D, RWTexture2D, ROVTexture2D::
  914. Texture2D<float4> a[8];
  915. RWTexture2D<float4> b[6];
  916. ...
  917. Texture2D<float4> c;
  918. if(cond) // arbitrary expression
  919. c = a[idx1];
  920. else
  921. c = b[idx2];
  922. ... = c.Load(...);
  923. LLVM's undef value is used for unused input parameters. For example, coordinates c2 and c3 in an dx.op.sample.f32 call for Texture2D are undef, as only two coordinates c0 and c1 are required.
  924. If the clamp parameter is unused, its default value is 0.0f.
  925. Resource operations are not overloaded on input parameter types. For example, dx.op.sample.f32 operation does not have an overload where coordinates have half, rather than float, data type. Instead, the precision of input arguments can be inferred from the IR via a straightforward lookup along an SSA edge, e.g.::
  926. %c0 = fpext half %0 to float
  927. %res = call %dx.types.ResRet.f32 @dx.op.sample.f32(..., %c0, ...)
  928. SSA form makes it easy to infer that value %0 of type half got promoted to float. The driver compiler can tailor the instruction to the most efficient form for the target hardware.
  929. Resource operations
  930. -------------------
  931. The section lists resource access operations. The specification is given for float return type, if applicable. The list of all overloads can be found in the appendix on intrinsic operations.
  932. Some general rules to interpret resource operations:
  933. * The number of active (meaningful) return components is determined by resource element type. Other return values must be unused; validator ensures this.
  934. * GPU instruction needs status only if the status return value is used in the program, which is determined through SSA.
  935. * Overload suffixes are specified for each resource operation.
  936. * Type of resource determines which inputs must be defined. Unused inputs are passed typed LLVM 'undef' values. This is checked by the DXIL validator.
  937. * Offset input parameters are i8 constants in [-8,+7] range; default offset is 0.
  938. Resource operation return types
  939. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  940. Many resource operations return several scalar values as well as status for tiled resource access. The return values are grouped into a helper structure type, as this is LLVM's way to return several values from the operation. After an operation, helper types are immediately decomposed into scalars, which are used in further computation.
  941. The defined helper types are listed below::
  942. %dx.types.ResRet.i8 = type { i8, i8, i8, i8, i32 }
  943. %dx.types.ResRet.i16 = type { i16, i16, i16, i16, i32 }
  944. %dx.types.ResRet.i32 = type { i32, i32, i32, i32, i32 }
  945. %dx.types.ResRet.i64 = type { i64, i64, i64, i64, i32 }
  946. %dx.types.ResRet.f16 = type { half, half, half, half, i32 }
  947. %dx.types.ResRet.f32 = type { float, float, float, float, i32 }
  948. %dx.types.ResRet.f64 = type { double, double, double, double, i32 }
  949. %dx.types.Dimensions = type { i32, i32, i32, i32 }
  950. %dx.types.SamplePos = type { float, float }
  951. Resource handles
  952. ~~~~~~~~~~~~~~~~
  953. Resources are identified via handles passed to resource operations. Handles are represented via opaque type::
  954. %dx.types.Handle = type { i8 * }
  955. The handles are created out of resource range ID and index into the range::
  956. declare %dx.types.Handle @dx.op.createHandle(
  957. i32, ; opcode
  958. i8, ; resource class: SRV=0, UAV=1, CBV=2, Sampler=3
  959. i32, ; resource range ID (constant)
  960. i32, ; index into the range
  961. i1) ; non-uniform resource index: false or true
  962. Resource class is a constant that indicates which metadata list (SRV, UAV, CBV, Sampler) to use for property queries.
  963. Resource range ID is an i32 constant, which is the position of the metadata record in the corresponding metadata list. Range IDs start with 0 and are contiguous within each list.
  964. Index is an i32 value that may be a constant or a value computed by the shader.
  965. CBufferLoadLegacy
  966. ~~~~~~~~~~~~~~~~~
  967. The following signature shows the operation syntax::
  968. ; overloads: SM5.1: f32|i32|f64, future SM: possibly deprecated
  969. %dx.types.CBufRet.f32 = type { float, float, float, float }
  970. declare %dx.types.CBufRet.f32 @dx.op.cbufferLoadLegacy.f32(
  971. i32, ; opcode
  972. %dx.types.Handle, ; resource handle
  973. i32) ; 0-based row index (row = 16-byte DXBC register)
  974. Valid resource types: ConstantBuffer. Valid shader model: SM5.1 and earlier.
  975. The operation loads four 32-bit values from a constant buffer, which has legacy, 16-byte layout. Values are extracted via "extractvalue" instruction; unused values may be optimized away by the driver compiler. The operation respects SM5.1 and earlier OOB behavior for cbuffers.
  976. CBufferLoad
  977. ~~~~~~~~~~~
  978. The following signature shows the operation syntax::
  979. ; overloads: SM5.1: f32|i32|f64, SM6.0: f16|f32|f64|i16|i32|i64
  980. declare float @dx.op.cbufferLoad.f32(
  981. i32, ; opcode
  982. %dx.types.Handle, ; resource handle
  983. i32, ; byte offset from the start of the buffer memory
  984. i32) ; read alignment
  985. Valid resource types: ConstantBuffer.
  986. The operation loads a value from a constant buffer, which has linear layout, using 1D index: byte offset from the beginning of the buffer memory. The operation respects SM5.1 and earlier OOB behavior for cbuffers.
  987. Read alignment is a constant value identifying what the byte offset alignment is. If the actual byte offset does not have this alignment, the results of this operation are undefined.
  988. GetDimensions
  989. ~~~~~~~~~~~~~
  990. The following signature shows the operation syntax::
  991. declare %dx.types.Dimensions @dx.op.getDimensions(
  992. i32, ; opcode
  993. %dx.types.Handle, ; resource handle
  994. i32) ; MIP level
  995. This table describes the return component meanings for each resource type { c0, c1, c2, c3 }.
  996. ==================== ===== ========== ========== ==========
  997. Valid resource types c0 c1 c2 c3
  998. ==================== ===== ========== ========== ==========
  999. [RW]Texture1D width undef undef MIP levels
  1000. [RW]Texture1DArray width array size undef MIP levels
  1001. [RW]Texture2D width height undef MIP levels
  1002. [RW]Texture2DArray width height array size MIP levels
  1003. [RW]Texture3D width height depth MIP levels
  1004. [RW]Texture2DMS width height undef samples
  1005. [RW]Texture2DMSArray width height array size samples
  1006. TextureCUBE width height undef MIP levels
  1007. TextureCUBEArray width height array size MIP levels
  1008. [RW]TypedBuffer width undef undef undef
  1009. [RW]RawBuffer width undef undef undef
  1010. [RW]StructuredBuffer width undef undef undef
  1011. ==================== ===== ========== ========== ==========
  1012. MIP levels is always undef for RW resources. Undef means the component will not be used. The validator will verify this.
  1013. There is no GetDimensions that returns float values.
  1014. Sample
  1015. ~~~~~~
  1016. The following signature shows the operation syntax::
  1017. ; overloads: SM5.1: f32, SM6.0: f16|f32
  1018. declare %dx.types.ResRet.f32 @dx.op.sample.f32(
  1019. i32, ; opcode
  1020. %dx.types.Handle, ; texture handle
  1021. %dx.types.Handle, ; sampler handle
  1022. float, ; coordinate c0
  1023. float, ; coordinate c1
  1024. float, ; coordinate c2
  1025. float, ; coordinate c3
  1026. i32, ; offset o0
  1027. i32, ; offset o1
  1028. i32, ; offset o2
  1029. float) ; clamp
  1030. =================== ================================ ===================
  1031. Valid resource type # of active coordinates # of active offsets
  1032. =================== ================================ ===================
  1033. Texture1D 1 (c0) 1 (o0)
  1034. Texture1DArray 2 (c0, c1 = array slice) 1 (o0)
  1035. Texture2D 2 (c0, c1) 2 (o0, o1)
  1036. Texture2DArray 3 (c0, c1, c2 = array slice) 2 (o0, o1)
  1037. Texture3D 3 (c0, c1, c2) 3 (o0, o1, o2)
  1038. TextureCUBE 3 (c0, c1, c2) 3 (o0, o1, o2)
  1039. TextureCUBEArray 4 (c0, c1, c2, c3 = array slice) 3 (o0, o1, o2)
  1040. =================== ================================ ===================
  1041. SampleBias
  1042. ~~~~~~~~~~
  1043. The following signature shows the operation syntax::
  1044. ; overloads: SM5.1: f32, SM6.0: f16|f32
  1045. declare %dx.types.ResRet.f32 @dx.op.sampleBias.f32(
  1046. i32, ; opcode
  1047. %dx.types.Handle, ; texture handle
  1048. %dx.types.Handle, ; sampler handle
  1049. float, ; coordinate c0
  1050. float, ; coordinate c1
  1051. float, ; coordinate c2
  1052. float, ; coordinate c3
  1053. i32, ; offset o0
  1054. i32, ; offset o1
  1055. i32, ; offset o2
  1056. float, ; bias: in [-16.f,15.99f]
  1057. float) ; clamp
  1058. Valid resource types and active components/offsets are the same as for the sample operation.
  1059. SampleLevel
  1060. ~~~~~~~~~~~
  1061. The following signature shows the operation syntax::
  1062. ; overloads: SM5.1: f32, SM6.0: f16|f32
  1063. declare %dx.types.ResRet.f32 @dx.op.sampleLevel.f32(
  1064. i32, ; opcode
  1065. %dx.types.Handle, ; texture handle
  1066. %dx.types.Handle, ; sampler handle
  1067. float, ; coordinate c0
  1068. float, ; coordinate c1
  1069. float, ; coordinate c2
  1070. float, ; coordinate c3
  1071. i32, ; offset o0
  1072. i32, ; offset o1
  1073. i32, ; offset o2
  1074. float) ; LOD
  1075. Valid resource types and active components/offsets are the same as for the sample operation.
  1076. SampleGrad
  1077. ~~~~~~~~~~
  1078. The following signature shows the operation syntax::
  1079. ; overloads: SM5.1: f32, SM6.0: f16|f32
  1080. declare %dx.types.ResRet.f32 @dx.op.sampleGrad.f32(
  1081. i32, ; opcode
  1082. %dx.types.Handle, ; texture handle
  1083. %dx.types.Handle, ; sampler handle
  1084. float, ; coordinate c0
  1085. float, ; coordinate c1
  1086. float, ; coordinate c2
  1087. float, ; coordinate c3
  1088. i32, ; offset o0
  1089. i32, ; offset o1
  1090. i32, ; offset o2
  1091. float, ; ddx0
  1092. float, ; ddx1
  1093. float, ; ddx2
  1094. float, ; ddy0
  1095. float, ; ddy1
  1096. float, ; ddy2
  1097. float) ; clamp
  1098. Valid resource types and active components and offsets are the same as for the sample operation. Valid active ddx and ddy are the same as offsets.
  1099. SampleCmp
  1100. ~~~~~~~~~
  1101. The following signature shows the operation syntax::
  1102. ; overloads: SM5.1: f32, SM6.0: f16|f32
  1103. declare %dx.types.ResRet.f32 @dx.op.sampleCmp.f32(
  1104. i32, ; opcode
  1105. %dx.types.Handle, ; texture handle
  1106. %dx.types.Handle, ; sampler handle
  1107. float, ; coordinate c0
  1108. float, ; coordinate c1
  1109. float, ; coordinate c2
  1110. float, ; coordinate c3
  1111. i32, ; offset o0
  1112. i32, ; offset o1
  1113. i32, ; offset o2
  1114. float, ; compare value
  1115. float) ; clamp
  1116. =================== ================================ ===================
  1117. Valid resource type # of active coordinates # of active offsets
  1118. =================== ================================ ===================
  1119. Texture1D 1 (c0) 1 (o0)
  1120. Texture1DArray 2 (c0, c1 = array slice) 1 (o0)
  1121. Texture2D 2 (c0, c1) 2 (o0, o1)
  1122. Texture2DArray 3 (c0, c1, c2 = array slice) 2 (o0, o1)
  1123. TextureCUBE 3 (c0, c1, c2) 3 (o0, o1, o2)
  1124. TextureCUBEArray 4 (c0, c1, c2, c3 = array slice) 3 (o0, o1, o2)
  1125. =================== ================================ ===================
  1126. SampleCmpLevelZero
  1127. ~~~~~~~~~~~~~~~~~~
  1128. The following signature shows the operation syntax::
  1129. ; overloads: SM5.1: f32, SM6.0: f16|f32
  1130. declare %dx.types.ResRet.f32 @dx.op.sampleCmpLevelZero.f32(
  1131. i32, ; opcode
  1132. %dx.types.Handle, ; texture handle
  1133. %dx.types.Handle, ; sampler handle
  1134. float, ; coordinate c0
  1135. float, ; coordinate c1
  1136. float, ; coordinate c2
  1137. float, ; coordinate c3
  1138. i32, ; offset o0
  1139. i32, ; offset o1
  1140. i32, ; offset o2
  1141. float) ; compare value
  1142. Valid resource types and active components/offsets are the same as for the sampleCmp operation.
  1143. TextureLoad
  1144. ~~~~~~~~~~~
  1145. The following signature shows the operation syntax::
  1146. ; overloads: SM5.1: f32|i32, SM6.0: f16|f32|i16|i32
  1147. declare %dx.types.ResRet.f32 @dx.op.textureLoad.f32(
  1148. i32, ; opcode
  1149. %dx.types.Handle, ; texture handle
  1150. i32, ; MIP level; sample for Texture2DMS
  1151. i32, ; coordinate c0
  1152. i32, ; coordinate c1
  1153. i32, ; coordinate c2
  1154. i32, ; offset o0
  1155. i32, ; offset o1
  1156. i32) ; offset o2
  1157. =================== ========= ============================ ===================
  1158. Valid resource type MIP level # of active coordinates # of active offsets
  1159. =================== ========= ============================ ===================
  1160. Texture1D yes 1 (c0) 1 (o0)
  1161. RWTexture1D undef 1 (c0) undef
  1162. Texture1DArray yes 2 (c0, c1 = array slice) 1 (o0)
  1163. RWTexture1DArray undef 2 (c0, c1 = array slice) undef
  1164. Texture2D yes 2 (c0, c1) 2 (o0, o1)
  1165. RWTexture2D undef 2 (c0, c1) undef
  1166. Texture2DArray yes 3 (c0, c1, c2 = array slice) 2 (o0, o1)
  1167. RWTexture2DArray undef 3 (c0, c1, c2 = array slice) undef
  1168. Texture3D yes 3 (c0, c1, c2) 3 (o0, o1, o2)
  1169. RWTexture3D undef 3 (c0, c1, c2) undef
  1170. =================== ========= ============================ ===================
  1171. For Texture2DMS:
  1172. =================== ============ =================================
  1173. Valid resource type Sample index # of active coordinate components
  1174. =================== ============ =================================
  1175. Texture2DMS yes 2 (c0, c1)
  1176. Texture2DMSArray yes 3 (c0, c1, c2 = array slice)
  1177. =================== ============ =================================
  1178. TextureStore
  1179. ~~~~~~~~~~~~
  1180. The following signature shows the operation syntax::
  1181. ; overloads: SM5.1: f32|i32, SM6.0: f16|f32|i16|i32
  1182. ; returns: status
  1183. declare void @dx.op.textureStore.f32(
  1184. i32, ; opcode
  1185. %dx.types.Handle, ; texture handle
  1186. i32, ; coordinate c0
  1187. i32, ; coordinate c1
  1188. i32, ; coordinate c2
  1189. float, ; value v0
  1190. float, ; value v1
  1191. float, ; value v2
  1192. float, ; value v3
  1193. i8) ; write mask
  1194. The write mask indicates which components are written (x - 1, y - 2, z - 4, w - 8), similar to DXBC. The mask must cover all resource components.
  1195. =================== =================================
  1196. Valid resource type # of active coordinate components
  1197. =================== =================================
  1198. RWTexture1D 1 (c0)
  1199. RWTexture1DArray 2 (c0, c1 = array slice)
  1200. RWTexture2D 2 (c0, c1)
  1201. RWTexture2DArray 3 (c0, c1, c2 = array slice)
  1202. RWTexture3D 3 (c0, c1, c2)
  1203. =================== =================================
  1204. CalculateLOD
  1205. ~~~~~~~~~~~~
  1206. The following signature shows the operation syntax::
  1207. ; returns: LOD
  1208. declare float @dx.op.calculateLOD.f32(
  1209. i32, ; opcode
  1210. %dx.types.Handle, ; texture handle
  1211. %dx.types.Handle, ; sampler handle
  1212. float, ; coordinate c0, [0.0, 1.0]
  1213. float, ; coordinate c1, [0.0, 1.0]
  1214. float, ; coordinate c2, [0.0, 1.0]
  1215. i1) ; true - clamped; false - unclamped
  1216. ============================= =======================
  1217. Valid resource type # of active coordinates
  1218. ============================= =======================
  1219. Texture1D, Texture1DArray 1 (c0)
  1220. Texture2D, Texture2DArray 2 (c0, c1)
  1221. Texture3D 3 (c0, c1, c2)
  1222. TextureCUBE, TextureCUBEArray 3 (c0, c1, c2)
  1223. ============================= =======================
  1224. TextureGather
  1225. ~~~~~~~~~~~~~
  1226. The following signature shows the operation syntax::
  1227. ; overloads: SM5.1: f32|i32, SM6.0: f16|f32|i16|i32
  1228. declare %dx.types.ResRet.f32 @dx.op.textureGather.f32(
  1229. i32, ; opcode
  1230. %dx.types.Handle, ; texture handle
  1231. %dx.types.Handle, ; sampler handle
  1232. float, ; coordinate c0
  1233. float, ; coordinate c1
  1234. float, ; coordinate c2
  1235. float, ; coordinate c3
  1236. i32, ; offset o0
  1237. i32, ; offset o1
  1238. i32) ; channel, constant in {0=red,1=green,2=blue,3=alpha}
  1239. =================== ================================ ===================
  1240. Valid resource type # of active coordinates # of active offsets
  1241. =================== ================================ ===================
  1242. Texture2D 2 (c0, c1) 2 (o0, o1)
  1243. Texture2DArray 3 (c0, c1, c2 = array slice) 2 (o0, o1)
  1244. TextureCUBE 3 (c0, c1, c2) 0
  1245. TextureCUBEArray 4 (c0, c1, c2, c3 = array slice) 0
  1246. =================== ================================ ===================
  1247. TextureGatherCmp
  1248. ~~~~~~~~~~~~~~~~
  1249. The following signature shows the operation syntax::
  1250. ; overloads: SM5.1: f32|i32, SM6.0: f16|f32|i16|i32
  1251. declare %dx.types.ResRet.f32 @dx.op.textureGatherCmp.f32(
  1252. i32, ; opcode
  1253. %dx.types.Handle, ; texture handle
  1254. %dx.types.Handle, ; sampler handle
  1255. float, ; coordinate c0
  1256. float, ; coordinate c1
  1257. float, ; coordinate c2
  1258. float, ; coordinate c3
  1259. i32, ; offset o0
  1260. i32, ; offset o1
  1261. i32, ; channel, constant in {0=red,1=green,2=blue,3=alpha}
  1262. float) ; compare value
  1263. Valid resource types and active components/offsets are the same as for the textureGather operation.
  1264. Texture2DMSGetSamplePosition
  1265. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1266. The following signature shows the operation syntax::
  1267. declare %dx.types.SamplePos @dx.op.texture2DMSGetSamplePosition(
  1268. i32, ; opcode
  1269. %dx.types.Handle, ; texture handle
  1270. i32) ; sample ID
  1271. Returns sample position of a texture.
  1272. RenderTargetGetSamplePosition
  1273. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1274. The following signature shows the operation syntax::
  1275. declare %dx.types.SamplePos @dx.op.renderTargetGetSamplePosition(
  1276. i32, ; opcode
  1277. i32) ; sample ID
  1278. Returns sample position of a render target.
  1279. RenderTargetGetSampleCount
  1280. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  1281. The following signature shows the operation syntax::
  1282. declare i32 @dx.op.renderTargetGetSampleCount(
  1283. i32) ; opcode
  1284. Returns sample count of a render target.
  1285. BufferLoad
  1286. ~~~~~~~~~~
  1287. The following signature shows the operation syntax::
  1288. ; overloads: SM5.1: f32|i32, SM6.0: f32|i32
  1289. ; returns: status
  1290. declare %dx.types.ResRet.f32 @dx.op.bufferLoad.f32(
  1291. i32, ; opcode
  1292. %dx.types.Handle, ; resource handle
  1293. i32, ; coordinate c0
  1294. i32) ; coordinate c1
  1295. The call respects SM5.1 OOB and alignment rules.
  1296. ==================== =====================================================
  1297. Valid resource type # of active coordinates
  1298. ==================== =====================================================
  1299. [RW]TypedBuffer 1 (c0 in elements)
  1300. [RW]RawBuffer 1 (c0 in bytes)
  1301. [RW]StructuredBuffer 2 (c0 in elements, c1 = byte offset into the element)
  1302. ==================== =====================================================
  1303. RawBufferLoad
  1304. ~~~~~~~~~~~~~
  1305. The following signature shows the operation syntax::
  1306. ; overloads: SM5.1: f32|i32, SM6.0: f32|i32, SM6.2: f16|f32|i16|i32
  1307. ; returns: status
  1308. declare %dx.types.ResRet.f32 @dx.op.rawBufferLoad.f32(
  1309. i32, ; opcode
  1310. %dx.types.Handle, ; resource handle
  1311. i32, ; coordinate c0 (index)
  1312. i32, ; coordinate c1 (elementOffset)
  1313. i8, ; mask
  1314. i32, ; alignment
  1315. )
  1316. The call respects SM5.1 OOB and alignment rules.
  1317. ==================== =====================================================
  1318. Valid resource type # of active coordinates
  1319. ==================== =====================================================
  1320. [RW]RawBuffer 1 (c0 in bytes)
  1321. [RW]StructuredBuffer 2 (c0 in elements, c1 = byte offset into the element)
  1322. ==================== =====================================================
  1323. BufferStore
  1324. ~~~~~~~~~~~
  1325. The following signature shows the operation syntax::
  1326. ; overloads: SM5.1: f32|i32, SM6.0: f32|i32
  1327. declare void @dx.op.bufferStore.f32(
  1328. i32, ; opcode
  1329. %dx.types.Handle, ; resource handle
  1330. i32, ; coordinate c0
  1331. i32, ; coordinate c1
  1332. float, ; value v0
  1333. float, ; value v1
  1334. float, ; value v2
  1335. float, ; value v3
  1336. i8) ; write mask
  1337. The call respects SM5.1 OOB and alignment rules.
  1338. The write mask indicates which components are written (x - 1, y - 2, z - 4, w - 8), similar to DXBC. For RWTypedBuffer, the mask must cover all resource components. For RWRawBuffer and RWStructuredBuffer, valid masks are: x, xy, xyz, xyzw.
  1339. =================== =====================================================
  1340. Valid resource type # of active coordinates
  1341. =================== =====================================================
  1342. RWTypedBuffer 1 (c0 in elements)
  1343. RWRawBuffer 1 (c0 in bytes)
  1344. RWStructuredBuffer 2 (c0 in elements, c1 = byte offset into the element)
  1345. =================== =====================================================
  1346. RawBufferStore
  1347. ~~~~~~~~~~~~~~
  1348. The following signature shows the operation syntax::
  1349. ; overloads: SM5.1: f32|i32, SM6.0: f32|i32, SM6.2: f16|f32|i16|i32
  1350. declare void @dx.op.rawBufferStore.f32(
  1351. i32, ; opcode
  1352. %dx.types.Handle, ; resource handle
  1353. i32, ; coordinate c0 (index)
  1354. i32, ; coordinate c1 (elementOffset)
  1355. float, ; value v0
  1356. float, ; value v1
  1357. float, ; value v2
  1358. float, ; value v3
  1359. i8, ; write mask
  1360. i32) ; alignment
  1361. The call respects SM5.1 OOB and alignment rules.
  1362. The write mask indicates which components are written (x - 1, y - 2, z - 4, w - 8), similar to DXBC. For RWTypedBuffer, the mask must cover all resource components. For RWRawBuffer and RWStructuredBuffer, valid masks are: x, xy, xyz, xyzw.
  1363. ==================== =====================================================
  1364. Valid resource type # of active coordinates
  1365. ==================== =====================================================
  1366. RWRawbuffer 1 (c0 in bytes)
  1367. RWStructuredbuffer 2 (c0 in elements, c1 = byte offset into the element)
  1368. ==================== =====================================================
  1369. BufferUpdateCounter
  1370. ~~~~~~~~~~~~~~~~~~~
  1371. The following signature shows the operation syntax::
  1372. ; opcodes: bufferUpdateCounter
  1373. declare void @dx.op.bufferUpdateCounter(
  1374. i32, ; opcode
  1375. %dx.types.ResHandle, ; buffer handle
  1376. i8) ; 1 - increment, -1 - decrement
  1377. Valid resource type: RWRawBuffer.
  1378. AtomicBinOp
  1379. ~~~~~~~~~~~
  1380. The following signature shows the operation syntax::
  1381. ; overloads: SM5.1: i32, SM6.0: i32
  1382. ; returns: original value in memory before the operation
  1383. declare i32 @dx.op.atomicBinOp.i32(
  1384. i32, ; opcode
  1385. %dx.types.Handle, ; resource handle
  1386. i32, ; binary operation code: EXCHANGE, IADD, AND, OR, XOR, IMIN, IMAX, UMIN, UMAX
  1387. i32, ; coordinate c0
  1388. i32, ; coordinate c1
  1389. i32, ; coordinate c2
  1390. i32) ; new value
  1391. The call respects SM5.1 OOB and alignment rules.
  1392. =================== =====================================================
  1393. Valid resource type # of active coordinates
  1394. =================== =====================================================
  1395. RWTexture1D 1 (c0)
  1396. RWTexture1DArray 2 (c0, c1 = array slice)
  1397. RWTexture2D 2 (c0, c1)
  1398. RWTexture2DArray 3 (c0, c1, c2 = array slice)
  1399. RWTexture3D 3 (c0, c1, c2)
  1400. RWTypedBuffer 1 (c0 in elements)
  1401. RWRawBuffer 1 (c0 in bytes)
  1402. RWStructuredBuffer 2 (c0 in elements, c1 - byte offset into the element)
  1403. =================== =====================================================
  1404. AtomicBinOp subsumes corresponding DXBC atomic operations that do not return the old value in memory. The driver compiler is free to specialize the corresponding GPU instruction if the return value is unused.
  1405. AtomicCompareExchange
  1406. ~~~~~~~~~~~~~~~~~~~~~
  1407. The following signature shows the operation syntax::
  1408. ; overloads: SM5.1: i32, SM6.0: i32
  1409. ; returns: original value in memory before the operation
  1410. declare i32 @dx.op.atomicBinOp.i32(
  1411. i32, ; opcode
  1412. %dx.types.Handle, ; resource handle
  1413. i32, ; coordinate c0
  1414. i32, ; coordinate c1
  1415. i32, ; coordinate c2
  1416. i32, ; comparison value
  1417. i32) ; new value
  1418. The call respects SM5.1 OOB and alignment rules.
  1419. =================== =====================================================
  1420. Valid resource type # of active coordinates
  1421. =================== =====================================================
  1422. RWTexture1D 1 (c0)
  1423. RWTexture1DArray 2 (c0, c1 = array slice)
  1424. RWTexture2D 2 (c0, c1)
  1425. RWTexture2DArray 3 (c0, c1, c2 = array slice)
  1426. RWTexture3D 3 (c0, c1, c2)
  1427. RWTypedBuffer 1 (c0 in elements)
  1428. RWRawBuffer 1 (c0 in bytes)
  1429. RWStructuredBuffer 2 (c0 in elements, c1 - byte offset into the element)
  1430. =================== =====================================================
  1431. AtomicCompareExchange subsumes DXBC's atomic compare store. The driver compiler is free to specialize the corresponding GPU instruction if the return value is unused.
  1432. GetBufferBasePtr (SM6.0)
  1433. ~~~~~~~~~~~~~~~~~~~~~~~~
  1434. The following signature shows the operation syntax::
  1435. Returns i8* pointer to the base of [RW]RawBuffer instance.
  1436. declare i8 addrspace(ASmemory) * @dx.op.getBufferBasePtr.pASmemory (
  1437. i32, ; opcode
  1438. %dx.types.Handle) ; resource handle
  1439. Returns i8* pointer to the base of ConstantBuffer instance.
  1440. declare i8 addrspace(AScbuffer) * @dx.op.getBufferBasePtr.pAScbuffer(
  1441. i32, ; opcode
  1442. %dx.types.Handle) ; resource handle
  1443. Given SM5.1 resource handle, return base pointer to perform pointer-based accesses to the resource memory.
  1444. Note: the functionality is requested for SM6.0 to support pointer-based accesses to SM5.1 resources with raw linear memory (raw buffer and cbuffer) in HLSL next. This would be one of the way how a valid pointer is produced in the shader, and would let new-style, pointer-based code access SM5.1 resources with linear memory view.
  1445. Atomic operations via pointer
  1446. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1447. Groupshared memory atomic operations are done via LLVM atomic instructions atomicrmw and cmpxchg. The instructions accept only i32 addrspace(ASgs) * pointers, where ASgs is the addrspace number of groupshared variables. Atomicrmw instruction does not support 'sub' and 'nand' operations. These constraints may be revisited in the future. OOB behavior is undefined.
  1448. SM6.0 will enable similar mechanism for atomic operations performed on device memory (raw buffer).
  1449. Samplers
  1450. --------
  1451. There are no intrinsics for samplers. Sampler reflection data is represented similar to other resources.
  1452. Immediate Constant Buffer
  1453. -------------------------
  1454. There is no immediate constant buffer in DXIL. Instead, indexable constants are represented via LLVM global initialized constants in address space ASicb.
  1455. Texture Buffers
  1456. ---------------
  1457. A texture buffer is mapped to RawBuffer. Texture buffer variable declarations are present for reflection purposes only.
  1458. Groupshared memory
  1459. ------------------
  1460. Groupshared memory (DXBC g-registers) is linear in DXIL. Groupshared variables are declared via global variables in addrspace(ASgs). The optimizer will not group variables; the driver compiler can do this if desired. Accesses to groupshared variables occur via pointer load/store instructions (see below).
  1461. Indexable threadlocal memory
  1462. ----------------------------
  1463. Indexable threadlocal memory (DXBC x-registers) is linear in DXIL. Threadlocal variables are "declared" via alloca instructions. Threadlocal variables are assumed to reside in addrspace(0). The variables are not allocated into some memory pool; the driver compiler can do this, if desired. Accesses to threadlocal variables occur via pointer load/store instructions (see below).
  1464. Load/Store/Atomics via pointer in future SM
  1465. -------------------------------------------
  1466. HLSL offers several abstractions with linear memory: buffers, cbuffers, groupshared and indexable threadlocal memory, that are conceptually similar, but have different HLSL syntax and some differences in behavior, which are exposed to HLSL developers. The plan is to introduce pointers into HLSL to unify access syntax to such linear-memory resources such that they appear conceptually the same to HLSL programmers.
  1467. Each resource memory type is expressed by a unique LLVM address space. The following table shows memory types and their address spaces:
  1468. ========================================= =====================================
  1469. Memory type Address space number n - addrspace(n)
  1470. ========================================= =====================================
  1471. code, local, indexable threadlocal memory AS_default = 0
  1472. device memory ([RW]RawBuffer) AS_memory = 1
  1473. cbuffer-like memory (ConstantBuffer) AS_cbuffer = 2
  1474. groupshared memory AS_groupshared = 3
  1475. ========================================= =====================================
  1476. Pointers can be produced in the shader in a variety of ways (see Memory accesses section). Note that if GetBaseBufferPtr was used on [RW]RawBuffer or ConstantBuffer to produce a pointer, the base pointer is stateless; i.e., it "loses its connection" to the underlying resource and is treated as a stateless pointer into a particular memory type.
  1477. Additional resource properties
  1478. ------------------------------
  1479. TODO: enumerate all additional resource range properties, e.g., ROV, Texture2DMS, globally coherent, UAV counter, sampler mode, CB: immediate/dynamic indexed.
  1480. Operations
  1481. ==========
  1482. DXIL operations are represented in two ways: using LLVM instructions and using LLVM external functions. The reference list of operations as well as their overloads can be found in the attached Excel spreadsheet "DXIL Operations".
  1483. Operations via instructions
  1484. ---------------------------
  1485. DXIL uses a subset of core LLVM IR instructions that make sense for HLSL, where the meaning of the LLVM IR operation matches the meaning of the HLSL operation.
  1486. The following LLVM instructions are valid in a DXIL program, with the specified operand types where applicable. The legend for overload types (v)oid, (h)alf, (f)loat, (d)ouble, (1)-bit, (8)-bit, (w)ord, (i)nt, (l)ong.
  1487. .. <py>import hctdb_instrhelp</py>
  1488. .. <py::lines('INSTR-RST')>hctdb_instrhelp.get_instrs_rst()</py>
  1489. .. INSTR-RST:BEGIN
  1490. ============= ======================================================================= =================
  1491. Instruction Action Operand overloads
  1492. ============= ======================================================================= =================
  1493. Ret returns a value (possibly void), from a function. vhfd1wil
  1494. Br branches (conditional or unconditional)
  1495. Switch performs a multiway switch
  1496. Add returns the sum of its two operands wil
  1497. FAdd returns the sum of its two operands hfd
  1498. Sub returns the difference of its two operands wil
  1499. FSub returns the difference of its two operands hfd
  1500. Mul returns the product of its two operands wil
  1501. FMul returns the product of its two operands hfd
  1502. UDiv returns the quotient of its two unsigned operands wil
  1503. SDiv returns the quotient of its two signed operands wil
  1504. FDiv returns the quotient of its two operands hfd
  1505. URem returns the remainder from the unsigned division of its two operands wil
  1506. SRem returns the remainder from the signed division of its two operands wil
  1507. FRem returns the remainder from the division of its two operands hfd
  1508. Shl shifts left (logical) wil
  1509. LShr shifts right (logical), with zero bit fill wil
  1510. AShr shifts right (arithmetic), with 'a' operand sign bit fill wil
  1511. And returns a bitwise logical and of its two operands 1wil
  1512. Or returns a bitwise logical or of its two operands 1wil
  1513. Xor returns a bitwise logical xor of its two operands 1wil
  1514. Alloca allocates memory on the stack frame of the currently executing function
  1515. Load reads from memory
  1516. Store writes to memory
  1517. GetElementPtr gets the address of a subelement of an aggregate value
  1518. AtomicCmpXchg atomically modifies memory
  1519. AtomicRMW atomically modifies memory
  1520. Trunc truncates an integer 1wil
  1521. ZExt zero extends an integer 1wil
  1522. SExt sign extends an integer 1wil
  1523. FPToUI converts a floating point to UInt hfd1wil
  1524. FPToSI converts a floating point to SInt hfd1wil
  1525. UIToFP converts a UInt to floating point hfd1wil
  1526. SIToFP converts a SInt to floating point hfd1wil
  1527. FPTrunc truncates a floating point hfd
  1528. FPExt extends a floating point hfd
  1529. BitCast performs a bit-preserving type cast hfd1wil
  1530. AddrSpaceCast casts a value addrspace
  1531. ICmp compares integers 1wil
  1532. FCmp compares floating points hfd
  1533. PHI is a PHI node instruction
  1534. Call calls a function
  1535. Select selects an instruction
  1536. ExtractValue extracts from aggregate
  1537. ============= ======================================================================= =================
  1538. FAdd
  1539. ~~~~
  1540. %des = fadd float %src0, %src1
  1541. The following table shows the results obtained when executing the instruction with various classes of numbers, assuming that "fp32-denorm-mode"="preserve".
  1542. For "fp32-denorm-mode"="ftz" mode, denorms inputs should be treated as corresponding signed zero, and any resulting denorm is also flushed to zero.
  1543. +----------+----------+--------+----------+----+----+-----------+--------+------+-----+
  1544. | src0\src1| -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  1545. +----------+----------+--------+----------+----+----+-----------+--------+------+-----+
  1546. | -inf | -inf | -inf | -inf |-inf|-inf| -inf | -inf | NaN | NaN |
  1547. +----------+----------+--------+----------+----+----+-----------+--------+------+-----+
  1548. | -F | -inf | -F | -F |src0|src0| -F | +/-F | +inf | NaN |
  1549. +----------+----------+--------+----------+----+----+-----------+--------+------+-----+
  1550. | -denorm | -inf | -F |-F/denorm |src0|src0| +/-denorm | +F | +inf | NaN |
  1551. +----------+----------+--------+----------+----+----+-----------+--------+------+-----+
  1552. | -0 | -inf | src1 | src1 |-0 |+0 | src1 | src1 | +inf | NaN |
  1553. +----------+----------+--------+----------+----+----+-----------+--------+------+-----+
  1554. | +0 | -inf | src1 | src1 |-0 |+0 | src1 | src1 | +inf | NaN |
  1555. +----------+----------+--------+----------+----+----+-----------+--------+------+-----+
  1556. | +denorm | -inf | -F |+/-denorm |src0|src0| +F/denorm | +F | +inf | NaN |
  1557. +----------+----------+--------+----------+----+----+-----------+--------+------+-----+
  1558. | +F | -inf | +/-F | +F |src0|src0| +F | +F | +inf | NaN |
  1559. +----------+----------+--------+----------+----+----+-----------+--------+------+-----+
  1560. | +inf | NaN | +inf | +inf |+inf|+inf| +inf | +inf | +inf | NaN |
  1561. +----------+----------+--------+----------+----+----+-----------+--------+------+-----+
  1562. | NaN | NaN | NaN | NaN |NaN |NaN | NaN | NaN | NaN | NaN |
  1563. +----------+----------+--------+----------+----+----+-----------+--------+------+-----+
  1564. FDiv
  1565. ~~~~
  1566. %dest = fdiv float %src0, %src1
  1567. The following table shows the results obtained when executing the instruction with various classes of numbers, assuming that fast math flag is not used and "fp32-denorm-mode"="preserve".
  1568. When "fp32-denorm-mode"="ftz", denorm inputs should be interpreted as corresponding signed zero, and any resulting denorm is also flushed to zero.
  1569. When fast math is enabled, implementation may use reciprocal form: src0*(1/src1). This may result in evaluating src0*(+/-)INF from src0*(1/(+/-)denorm). This may produce NaN in some cases or (+/-)INF in others.
  1570. +-----------+----------+--------+-------+---------+----+----+---------+-------+--------+------+-----+
  1571. | src0\\src1| -inf | -F | -1 | -denorm | -0 | +0 | +denorm | +1 | +F | +inf | NaN |
  1572. +-----------+----------+--------+-------+---------+----+----+---------+-------+--------+------+-----+
  1573. | -inf | NaN | +inf | +inf | +inf |+inf|-inf| -inf | -inf | -inf | NaN | NaN |
  1574. +-----------+----------+--------+-------+---------+----+----+---------+-------+--------+------+-----+
  1575. | -F | +0 | +F | -src0 | +F |+inf|-inf| -F | src0 | -F | -0 | NaN |
  1576. +-----------+----------+--------+-------+---------+----+----+---------+-------+--------+------+-----+
  1577. | -denorm | +0 | +denorm| -src0 | +F |+inf|-inf| -F | src0 |-denorm | -0 | NaN |
  1578. +-----------+----------+--------+-------+---------+----+----+---------+-------+--------+------+-----+
  1579. | -0 | +0 | +0 | +0 | 0 |NaN |NaN | 0 | -0 | -0 | -0 | NaN |
  1580. +-----------+----------+--------+-------+---------+----+----+---------+-------+--------+------+-----+
  1581. | +0 | -0 | -0 | -0 | 0 |NaN |NaN | 0 | +0 | +0 | +0 | NaN |
  1582. +-----------+----------+--------+-------+---------+----+----+---------+-------+--------+------+-----+
  1583. | +denorm | -0 | -denorm| -src0 | -F |-inf|+inf| +F | src0 |+denorm | +0 | NaN |
  1584. +-----------+----------+--------+-------+---------+----+----+---------+-------+--------+------+-----+
  1585. | +F | -0 | -F | -src0 | -F |-inf|+inf| +F | src0 | +F | +0 | NaN |
  1586. +-----------+----------+--------+-------+---------+----+----+---------+-------+--------+------+-----+
  1587. | +inf | NaN | -inf | -inf | -inf |-inf|+inf| +inf | +inf | +inf | NaN | NaN |
  1588. +-----------+----------+--------+-------+---------+----+----+---------+-------+--------+------+-----+
  1589. | NaN | NaN | NaN | NaN | NaN |NaN |NaN | NaN | NaN | NaN | NaN | NaN |
  1590. +-----------+----------+--------+-------+---------+----+----+---------+-------+--------+------+-----+
  1591. .. INSTR-RST:END
  1592. Operations via external functions
  1593. ---------------------------------
  1594. Operations missing in core LLVM IR, such as abs, fma, discard, etc., are represented by external functions, whose name is prefixed with dx.op.
  1595. The very first parameter of each such external function is the opcode of the operation, which is an i32 constant. For example, dx.op.unary computes a unary function T res = opcode(T input). Opcode defines which unary function to perform.
  1596. Opcodes are defined on a dense range and will be provided as enum in a header file. The opcode parameter is introduced for efficiency reasons: grouping of operations to reduce the total number of overloads and more efficient property lookup, e.g., via an array of operation properties rather than a hash table.
  1597. .. <py::lines('OPCODES-RST')>hctdb_instrhelp.get_opcodes_rst()</py>
  1598. .. OPCODES-RST:BEGIN
  1599. === ===================================================== =======================================================================================================================================================================================================================
  1600. ID Name Description
  1601. === ===================================================== =======================================================================================================================================================================================================================
  1602. 0 TempRegLoad_ Helper load operation
  1603. 1 TempRegStore_ Helper store operation
  1604. 2 MinPrecXRegLoad_ Helper load operation for minprecision
  1605. 3 MinPrecXRegStore_ Helper store operation for minprecision
  1606. 4 LoadInput_ Loads the value from shader input
  1607. 5 StoreOutput_ Stores the value to shader output
  1608. 6 FAbs_ returns the absolute value of the input value.
  1609. 7 Saturate_ clamps the result of a single or double precision floating point value to [0.0f...1.0f]
  1610. 8 IsNaN_ Returns true if x is NAN or QNAN, false otherwise.
  1611. 9 IsInf_ Returns true if x is +INF or -INF, false otherwise.
  1612. 10 IsFinite_ Returns true if x is finite, false otherwise.
  1613. 11 IsNormal_ returns IsNormal
  1614. 12 Cos_ returns cosine(theta) for theta in radians.
  1615. 13 Sin_ returns sine(theta) for theta in radians.
  1616. 14 Tan_ returns tan(theta) for theta in radians.
  1617. 15 Acos_ Returns the arccosine of the specified value. Input should be a floating-point value within the range of -1 to 1.
  1618. 16 Asin_ Returns the arccosine of the specified value. Input should be a floating-point value within the range of -1 to 1
  1619. 17 Atan_ Returns the arctangent of the specified value. The return value is within the range of -PI/2 to PI/2.
  1620. 18 Hcos_ returns the hyperbolic cosine of the specified value.
  1621. 19 Hsin_ returns the hyperbolic sine of the specified value.
  1622. 20 Htan_ returns the hyperbolic tangent of the specified value.
  1623. 21 Exp_ returns 2^exponent
  1624. 22 Frc_ extract fracitonal component.
  1625. 23 Log_ returns log base 2.
  1626. 24 Sqrt_ returns square root
  1627. 25 Rsqrt_ returns reciprocal square root (1 / sqrt(src)
  1628. 26 Round_ne_ floating-point round to integral float.
  1629. 27 Round_ni_ floating-point round to integral float.
  1630. 28 Round_pi_ floating-point round to integral float.
  1631. 29 Round_z_ floating-point round to integral float.
  1632. 30 Bfrev_ Reverses the order of the bits.
  1633. 31 Countbits_ Counts the number of bits in the input integer.
  1634. 32 FirstbitLo_ Returns the location of the first set bit starting from the lowest order bit and working upward.
  1635. 33 FirstbitHi_ Returns the location of the first set bit starting from the highest order bit and working downward.
  1636. 34 FirstbitSHi_ Returns the location of the first set bit from the highest order bit based on the sign.
  1637. 35 FMax_ returns a if a >= b, else b
  1638. 36 FMin_ returns a if a < b, else b
  1639. 37 IMax_ IMax(a,b) returns a if a > b, else b
  1640. 38 IMin_ IMin(a,b) returns a if a < b, else b
  1641. 39 UMax_ unsigned integer maximum. UMax(a,b) = a > b ? a : b
  1642. 40 UMin_ unsigned integer minimum. UMin(a,b) = a < b ? a : b
  1643. 41 IMul_ multiply of 32-bit operands to produce the correct full 64-bit result.
  1644. 42 UMul_ multiply of 32-bit operands to produce the correct full 64-bit result.
  1645. 43 UDiv_ unsigned divide of the 32-bit operand src0 by the 32-bit operand src1.
  1646. 44 UAddc_ unsigned add of 32-bit operand with the carry
  1647. 45 USubb_ unsigned subtract of 32-bit operands with the borrow
  1648. 46 FMad_ floating point multiply & add
  1649. 47 Fma_ fused multiply-add
  1650. 48 IMad_ Signed integer multiply & add
  1651. 49 UMad_ Unsigned integer multiply & add
  1652. 50 Msad_ masked Sum of Absolute Differences.
  1653. 51 Ibfe_ Integer bitfield extract
  1654. 52 Ubfe_ Unsigned integer bitfield extract
  1655. 53 Bfi_ Given a bit range from the LSB of a number, places that number of bits in another number at any offset
  1656. 54 Dot2_ Two-dimensional vector dot-product
  1657. 55 Dot3_ Three-dimensional vector dot-product
  1658. 56 Dot4_ Four-dimensional vector dot-product
  1659. 57 CreateHandle creates the handle to a resource
  1660. 58 CBufferLoad loads a value from a constant buffer resource
  1661. 59 CBufferLoadLegacy loads a value from a constant buffer resource
  1662. 60 Sample samples a texture
  1663. 61 SampleBias samples a texture after applying the input bias to the mipmap level
  1664. 62 SampleLevel samples a texture using a mipmap-level offset
  1665. 63 SampleGrad samples a texture using a gradient to influence the way the sample location is calculated
  1666. 64 SampleCmp samples a texture and compares a single component against the specified comparison value
  1667. 65 SampleCmpLevelZero samples a texture and compares a single component against the specified comparison value
  1668. 66 TextureLoad reads texel data without any filtering or sampling
  1669. 67 TextureStore reads texel data without any filtering or sampling
  1670. 68 BufferLoad reads from a TypedBuffer
  1671. 69 BufferStore writes to a RWTypedBuffer
  1672. 70 BufferUpdateCounter atomically increments/decrements the hidden 32-bit counter stored with a Count or Append UAV
  1673. 71 CheckAccessFullyMapped determines whether all values from a Sample, Gather, or Load operation accessed mapped tiles in a tiled resource
  1674. 72 GetDimensions gets texture size information
  1675. 73 TextureGather gathers the four texels that would be used in a bi-linear filtering operation
  1676. 74 TextureGatherCmp same as TextureGather, except this instrution performs comparison on texels, similar to SampleCmp
  1677. 75 Texture2DMSGetSamplePosition gets the position of the specified sample
  1678. 76 RenderTargetGetSamplePosition gets the position of the specified sample
  1679. 77 RenderTargetGetSampleCount gets the number of samples for a render target
  1680. 78 AtomicBinOp performs an atomic operation on two operands
  1681. 79 AtomicCompareExchange atomic compare and exchange to memory
  1682. 80 Barrier inserts a memory barrier in the shader
  1683. 81 CalculateLOD calculates the level of detail
  1684. 82 Discard discard the current pixel
  1685. 83 DerivCoarseX_ computes the rate of change per stamp in x direction.
  1686. 84 DerivCoarseY_ computes the rate of change per stamp in y direction.
  1687. 85 DerivFineX_ computes the rate of change per pixel in x direction.
  1688. 86 DerivFineY_ computes the rate of change per pixel in y direction.
  1689. 87 EvalSnapped evaluates an input attribute at pixel center with an offset
  1690. 88 EvalSampleIndex evaluates an input attribute at a sample location
  1691. 89 EvalCentroid evaluates an input attribute at pixel center
  1692. 90 SampleIndex returns the sample index in a sample-frequency pixel shader
  1693. 91 Coverage returns the coverage mask input in a pixel shader
  1694. 92 InnerCoverage returns underestimated coverage input from conservative rasterization in a pixel shader
  1695. 93 ThreadId reads the thread ID
  1696. 94 GroupId reads the group ID (SV_GroupID)
  1697. 95 ThreadIdInGroup reads the thread ID within the group (SV_GroupThreadID)
  1698. 96 FlattenedThreadIdInGroup provides a flattened index for a given thread within a given group (SV_GroupIndex)
  1699. 97 EmitStream emits a vertex to a given stream
  1700. 98 CutStream completes the current primitive topology at the specified stream
  1701. 99 EmitThenCutStream equivalent to an EmitStream followed by a CutStream
  1702. 100 GSInstanceID GSInstanceID
  1703. 101 MakeDouble creates a double value
  1704. 102 SplitDouble splits a double into low and high parts
  1705. 103 LoadOutputControlPoint LoadOutputControlPoint
  1706. 104 LoadPatchConstant LoadPatchConstant
  1707. 105 DomainLocation DomainLocation
  1708. 106 StorePatchConstant StorePatchConstant
  1709. 107 OutputControlPointID OutputControlPointID
  1710. 108 PrimitiveID PrimitiveID
  1711. 109 CycleCounterLegacy CycleCounterLegacy
  1712. 110 WaveIsFirstLane returns 1 for the first lane in the wave
  1713. 111 WaveGetLaneIndex returns the index of the current lane in the wave
  1714. 112 WaveGetLaneCount returns the number of lanes in the wave
  1715. 113 WaveAnyTrue returns 1 if any of the lane evaluates the value to true
  1716. 114 WaveAllTrue returns 1 if all the lanes evaluate the value to true
  1717. 115 WaveActiveAllEqual returns 1 if all the lanes have the same value
  1718. 116 WaveActiveBallot returns a struct with a bit set for each lane where the condition is true
  1719. 117 WaveReadLaneAt returns the value from the specified lane
  1720. 118 WaveReadLaneFirst returns the value from the first lane
  1721. 119 WaveActiveOp returns the result the operation across waves
  1722. 120 WaveActiveBit returns the result of the operation across all lanes
  1723. 121 WavePrefixOp returns the result of the operation on prior lanes
  1724. 122 QuadReadLaneAt reads from a lane in the quad
  1725. 123 QuadOp returns the result of a quad-level operation
  1726. 124 BitcastI16toF16 bitcast between different sizes
  1727. 125 BitcastF16toI16 bitcast between different sizes
  1728. 126 BitcastI32toF32 bitcast between different sizes
  1729. 127 BitcastF32toI32 bitcast between different sizes
  1730. 128 BitcastI64toF64 bitcast between different sizes
  1731. 129 BitcastF64toI64 bitcast between different sizes
  1732. 130 LegacyF32ToF16 legacy fuction to convert float (f32) to half (f16) (this is not related to min-precision)
  1733. 131 LegacyF16ToF32 legacy fuction to convert half (f16) to float (f32) (this is not related to min-precision)
  1734. 132 LegacyDoubleToFloat legacy fuction to convert double to float
  1735. 133 LegacyDoubleToSInt32 legacy fuction to convert double to int32
  1736. 134 LegacyDoubleToUInt32 legacy fuction to convert double to uint32
  1737. 135 WaveAllBitCount returns the count of bits set to 1 across the wave
  1738. 136 WavePrefixBitCount returns the count of bits set to 1 on prior lanes
  1739. 137 AttributeAtVertex_ returns the values of the attributes at the vertex.
  1740. 138 ViewID returns the view index
  1741. 139 RawBufferLoad reads from a raw buffer and structured buffer
  1742. 140 RawBufferStore writes to a RWByteAddressBuffer or RWStructuredBuffer
  1743. 141 InstanceID The user-provided InstanceID on the bottom-level acceleration structure instance within the top-level structure
  1744. 142 InstanceIndex The autogenerated index of the current instance in the top-level structure
  1745. 143 HitKind Returns the value passed as HitKind in ReportIntersection(). If intersection was reported by fixed-function triangle intersection, HitKind will be one of HIT_KIND_TRIANGLE_FRONT_FACE or HIT_KIND_TRIANGLE_BACK_FACE.
  1746. 144 RayFlags uint containing the current ray flags.
  1747. 145 DispatchRaysIndex The current x and y location within the Width and Height
  1748. 146 DispatchRaysDimensions The Width and Height values from the D3D12_DISPATCH_RAYS_DESC structure provided to the originating DispatchRays() call.
  1749. 147 WorldRayOrigin The world-space origin for the current ray.
  1750. 148 WorldRayDirection The world-space direction for the current ray.
  1751. 149 ObjectRayOrigin Object-space origin for the current ray.
  1752. 150 ObjectRayDirection Object-space direction for the current ray.
  1753. 151 ObjectToWorld Matrix for transforming from object-space to world-space.
  1754. 152 WorldToObject Matrix for transforming from world-space to object-space.
  1755. 153 RayTMin float representing the parametric starting point for the ray.
  1756. 154 RayTCurrent float representing the current parametric ending point for the ray
  1757. 155 IgnoreHit Used in an any hit shader to reject an intersection and terminate the shader
  1758. 156 AcceptHitAndEndSearch Used in an any hit shader to abort the ray query and the intersection shader (if any). The current hit is committed and execution passes to the closest hit shader with the closest hit recorded so far
  1759. 157 TraceRay initiates raytrace
  1760. 158 ReportHit returns true if hit was accepted
  1761. 159 CallShader Call a shader in the callable shader table supplied through the DispatchRays() API
  1762. 160 CreateHandleForLib create resource handle from resource struct for library
  1763. 161 PrimitiveIndex PrimitiveIndex for raytracing shaders
  1764. 162 Dot2AddHalf 2D half dot product with accumulate to float
  1765. 163 Dot4AddI8Packed signed dot product of 4 x i8 vectors packed into i32, with accumulate to i32
  1766. 164 Dot4AddU8Packed unsigned dot product of 4 x u8 vectors packed into i32, with accumulate to i32
  1767. 165 WaveMatch returns the bitmask of active lanes that have the same value
  1768. 166 WaveMultiPrefixOp returns the result of the operation on groups of lanes identified by a bitmask
  1769. 167 WaveMultiPrefixBitCount returns the count of bits set to 1 on groups of lanes identified by a bitmask
  1770. 168 SetMeshOutputCounts Mesh shader intrinsic SetMeshOutputCounts
  1771. 169 EmitIndices emit a primitive's vertex indices in a mesh shader
  1772. 170 GetMeshPayload get the mesh payload which is from amplification shader
  1773. 171 StoreVertexOutput stores the value to mesh shader vertex output
  1774. 172 StorePrimitiveOutput stores the value to mesh shader primitive output
  1775. 173 DispatchMesh Amplification shader intrinsic DispatchMesh
  1776. 174 WriteSamplerFeedback updates a feedback texture for a sampling operation
  1777. 175 WriteSamplerFeedbackBias updates a feedback texture for a sampling operation with a bias on the mipmap level
  1778. 176 WriteSamplerFeedbackLevel updates a feedback texture for a sampling operation with a mipmap-level offset
  1779. 177 WriteSamplerFeedbackGrad updates a feedback texture for a sampling operation with explicit gradients
  1780. 178 AllocateRayQuery allocates space for RayQuery and return handle
  1781. 179 RayQuery_TraceRayInline initializes RayQuery for raytrace
  1782. 180 RayQuery_Proceed advances a ray query
  1783. 181 RayQuery_Abort aborts a ray query
  1784. 182 RayQuery_CommitNonOpaqueTriangleHit commits a non opaque triangle hit
  1785. 183 RayQuery_CommitProceduralPrimitiveHit commits a procedural primitive hit
  1786. 184 RayQuery_CommittedStatus returns uint status (COMMITTED_STATUS) of the committed hit in a ray query
  1787. 185 RayQuery_CandidateType returns uint candidate type (CANDIDATE_TYPE) of the current hit candidate in a ray query, after Proceed() has returned true
  1788. 186 RayQuery_CandidateObjectToWorld3x4 returns matrix for transforming from object-space to world-space for a candidate hit.
  1789. 187 RayQuery_CandidateWorldToObject3x4 returns matrix for transforming from world-space to object-space for a candidate hit.
  1790. 188 RayQuery_CommittedObjectToWorld3x4 returns matrix for transforming from object-space to world-space for a Committed hit.
  1791. 189 RayQuery_CommittedWorldToObject3x4 returns matrix for transforming from world-space to object-space for a Committed hit.
  1792. 190 RayQuery_CandidateProceduralPrimitiveNonOpaque returns if current candidate procedural primitive is non opaque
  1793. 191 RayQuery_CandidateTriangleFrontFace returns if current candidate triangle is front facing
  1794. 192 RayQuery_CommittedTriangleFrontFace returns if current committed triangle is front facing
  1795. 193 RayQuery_CandidateTriangleBarycentrics returns candidate triangle hit barycentrics
  1796. 194 RayQuery_CommittedTriangleBarycentrics returns committed triangle hit barycentrics
  1797. 195 RayQuery_RayFlags returns ray flags
  1798. 196 RayQuery_WorldRayOrigin returns world ray origin
  1799. 197 RayQuery_WorldRayDirection returns world ray direction
  1800. 198 RayQuery_RayTMin returns float representing the parametric starting point for the ray.
  1801. 199 RayQuery_CandidateTriangleRayT returns float representing the parametric point on the ray for the current candidate triangle hit.
  1802. 200 RayQuery_CommittedRayT returns float representing the parametric point on the ray for the current committed hit.
  1803. 201 RayQuery_CandidateInstanceIndex returns candidate hit instance index
  1804. 202 RayQuery_CandidateInstanceID returns candidate hit instance ID
  1805. 203 RayQuery_CandidateGeometryIndex returns candidate hit geometry index
  1806. 204 RayQuery_CandidatePrimitiveIndex returns candidate hit geometry index
  1807. 205 RayQuery_CandidateObjectRayOrigin returns candidate hit object ray origin
  1808. 206 RayQuery_CandidateObjectRayDirection returns candidate object ray direction
  1809. 207 RayQuery_CommittedInstanceIndex returns committed hit instance index
  1810. 208 RayQuery_CommittedInstanceID returns committed hit instance ID
  1811. 209 RayQuery_CommittedGeometryIndex returns committed hit geometry index
  1812. 210 RayQuery_CommittedPrimitiveIndex returns committed hit geometry index
  1813. 211 RayQuery_CommittedObjectRayOrigin returns committed hit object ray origin
  1814. 212 RayQuery_CommittedObjectRayDirection returns committed object ray direction
  1815. 213 GeometryIndex The autogenerated index of the current geometry in the bottom-level structure
  1816. 214 RayQuery_CandidateInstanceContributionToHitGroupIndex returns candidate hit InstanceContributionToHitGroupIndex
  1817. 215 RayQuery_CommittedInstanceContributionToHitGroupIndex returns committed hit InstanceContributionToHitGroupIndex
  1818. 216 CreateHandleFromHeap create resource handle from heap
  1819. 217 AnnotateHandle annotate handle with resource properties
  1820. === ===================================================== =======================================================================================================================================================================================================================
  1821. Acos
  1822. ~~~~
  1823. The return value is within the range of -PI/2 to PI/2.
  1824. +----------+------+--------------+---------+------+------+---------+------+-----+
  1825. | src | -inf | [-1,1] | -denorm | -0 | +0 | +denorm | +inf | NaN |
  1826. +----------+------+--------------+---------+------+------+---------+------+-----+
  1827. | acos(src)| NaN | (-PI/2,+PI/2)| PI/2 | PI/2 | PI/2 | PI/2 | NaN | NaN |
  1828. +----------+------+--------------+---------+------+------+---------+------+-----+
  1829. Asin
  1830. ~~~~
  1831. The return value is within the range of -PI/2 to PI/2.
  1832. +----------+------+--------------+---------+------+------+---------+------+-----+
  1833. | src | -inf | [-1,1] | -denorm | -0 | +0 | +denorm | +inf | NaN |
  1834. +----------+------+--------------+---------+------+------+---------+------+-----+
  1835. | asin(src)| NaN | (-PI/2,+PI/2)| 0 | 0 | 0 | 0 | NaN | NaN |
  1836. +----------+------+--------------+---------+------+------+---------+------+-----+
  1837. Atan
  1838. ~~~~
  1839. +----------+------+--------------+---------+------+------+---------+---------------+-----+-----+
  1840. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F |+inf | NaN |
  1841. +----------+------+--------------+---------+------+------+---------+---------------+-----+-----+
  1842. | atan(src)| -PI/2| (-PI/2,+PI/2)| 0 | 0 | 0 | 0 | (-PI/2,+PI/2) |PI/2 | NaN |
  1843. +----------+------+--------------+---------+------+------+---------+---------------+-----+-----+
  1844. Returns the arctangent of the specified value. The return value is within the range of -PI/2 to PI/2
  1845. AttributeAtVertex
  1846. ~~~~~~~~~~~~~~~~~
  1847. returns the values of the attributes at the vertex. VertexID ranges from 0 to 2.
  1848. Bfi
  1849. ~~~
  1850. Given a bit range from the LSB of a number, place that number of bits in another number at any offset.
  1851. dst = Bfi(src0, src1, src2, src3);
  1852. The LSB 5 bits of src0 provide the bitfield width (0-31) to take from src2.
  1853. The LSB 5 bits of src1 provide the bitfield offset (0-31) to start replacing bits in the number read from src3.
  1854. Given width, offset: bitmask = (((1 << width)-1) << offset) & 0xffffffff, dest = ((src2 << offset) & bitmask) | (src3 & ~bitmask)
  1855. Bfrev
  1856. ~~~~~
  1857. Reverses the order of the bits. For example given 0x12345678 the result would be 0x1e6a2c48.
  1858. Cos
  1859. ~~~
  1860. Theta values can be any IEEE 32-bit floating point values.
  1861. The maximum absolute error is 0.0008 in the interval from -100*Pi to +100*Pi.
  1862. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1863. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  1864. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1865. | cos(src) | NaN | [-1 to +1] | +1 | +1 | +1 | +1 | [-1 to +1] | NaN | NaN |
  1866. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1867. Countbits
  1868. ~~~~~~~~~
  1869. Counts the number of bits in the input integer.
  1870. DerivCoarseX
  1871. ~~~~~~~~~~~~
  1872. dst = DerivCoarseX(src);
  1873. Computes the rate of change per stamp in x direction. Only a single x derivative pair is computed for each 2x2 stamp of pixels.
  1874. The data in the current Pixel Shader invocation may or may not participate in the calculation of the requested derivative, given the derivative will be calculated only once per 2x2 quad:
  1875. As an example, the x derivative could be a delta from the top row of pixels.
  1876. The exact calculation is up to the hardware vendor. There is also no specification dictating how the 2x2 quads will be aligned/tiled over a primitive.
  1877. DerivCoarseY
  1878. ~~~~~~~~~~~~
  1879. dst = DerivCoarseY(src);
  1880. Computes the rate of change per stamp in y direction. Only a single y derivative pair is computed for each 2x2 stamp of pixels.
  1881. The data in the current Pixel Shader invocation may or may not participate in the calculation of the requested derivative, given the derivative will be calculated only once per 2x2 quad:
  1882. As an example, the y derivative could be a delta from the left column of pixels.
  1883. The exact calculation is up to the hardware vendor. There is also no specification dictating how the 2x2 quads will be aligned/tiled over a primitive.
  1884. DerivFineX
  1885. ~~~~~~~~~~
  1886. dst = DerivFineX(src);
  1887. Computes the rate of change per pixel in x direction. Each pixel in the 2x2 stamp gets a unique pair of x derivative calculations
  1888. The data in the current Pixel Shader invocation always participates in the calculation of the requested derivative.
  1889. There is no specification dictating how the 2x2 quads will be aligned/tiled over a primitive.
  1890. DerivFineY
  1891. ~~~~~~~~~~
  1892. dst = DerivFineY(src);
  1893. Computes the rate of change per pixel in y direction. Each pixel in the 2x2 stamp gets a unique pair of y derivative calculations
  1894. The data in the current Pixel Shader invocation always participates in the calculation of the requested derivative.
  1895. There is no specification dictating how the 2x2 quads will be aligned/tiled over a primitive.
  1896. Dot2
  1897. ~~~~
  1898. Two-dimensional vector dot-product
  1899. Dot3
  1900. ~~~~
  1901. Three-dimensional vector dot-product
  1902. Dot4
  1903. ~~~~
  1904. Four-dimensional vector dot-product
  1905. Exp
  1906. ~~~
  1907. Returns 2^exponent. Note that hlsl log intrinsic returns the base-e exponent. Maximum relative error is e^-21.
  1908. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1909. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  1910. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1911. | exp(src) | 0 | +F | 1 | 1 | 1 | 1 | +F | +inf | NaN |
  1912. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1913. FAbs
  1914. ~~~~
  1915. The FAbs instruction takes simply forces the sign of the number(s) on the source operand positive, including on INF and denorm values.
  1916. Applying FAbs on NaN preserves NaN, although the particular NaN bit pattern that results is not defined.
  1917. FMad
  1918. ~~~~
  1919. Floating point multiply & add. This operation is not fused for "precise" operations.
  1920. FMad(a,b,c) = a * b + c
  1921. FMax
  1922. ~~~~
  1923. >= is used instead of > so that if min(x,y) = x then max(x,y) = y.
  1924. NaN has special handling: If one source operand is NaN, then the other source operand is returned.
  1925. If both are NaN, any NaN representation is returned.
  1926. This conforms to new IEEE 754R rules.
  1927. Denorms are flushed (sign preserved) before comparison, however the result written to dest may or may not be denorm flushed.
  1928. +------+-----------------------------+
  1929. | a | b |
  1930. | +------+--------+------+------+
  1931. | | -inf | F | +inf | NaN |
  1932. +------+------+--------+------+------+
  1933. | -inf | -inf | b | +inf | -inf |
  1934. +------+------+--------+------+------+
  1935. | F | a | a or b | +inf | a |
  1936. +------+------+--------+------+------+
  1937. | +inf | +inf | +inf | +inf | +inf |
  1938. +------+------+--------+------+------+
  1939. | NaN | -inf | b | +inf | NaN |
  1940. +------+------+--------+------+------+
  1941. FMin
  1942. ~~~~
  1943. NaN has special handling: If one source operand is NaN, then the other source operand is returned.
  1944. If both are NaN, any NaN representation is returned.
  1945. This conforms to new IEEE 754R rules.
  1946. Denorms are flushed (sign preserved) before comparison, however the result written to dest may or may not be denorm flushed.
  1947. +------+-----------------------------+
  1948. | a | b |
  1949. | +------+--------+------+------+
  1950. | | -inf | F | +inf | NaN |
  1951. +------+------+--------+------+------+
  1952. | -inf | -inf | -inf | -inf | -inf |
  1953. +------+------+--------+------+------+
  1954. | F | -inf | a or b | a | a |
  1955. +------+------+--------+------+------+
  1956. | +inf | -inf | b | +inf | +inf |
  1957. +------+------+--------+------+------+
  1958. | NaN | -inf | b | +inf | NaN |
  1959. +------+------+--------+------+------+
  1960. FirstbitHi
  1961. ~~~~~~~~~~
  1962. Returns the integer position of the first bit set in the 32-bit input starting from the MSB. For example, 0x10000000 would return 3. Returns 0xffffffff if no match was found.
  1963. FirstbitLo
  1964. ~~~~~~~~~~
  1965. Returns the integer position of the first bit set in the 32-bit input starting from the LSB. For example, 0x00000000 would return 1. Returns 0xffffffff if no match was found.
  1966. FirstbitSHi
  1967. ~~~~~~~~~~~
  1968. Returns the first 0 from the MSB if the number is negative, else the first 1 from the MSB. Returns 0xffffffff if no match was found.
  1969. Fma
  1970. ~~~
  1971. Fused multiply-add. This operation is only defined in double precision.
  1972. Fma(a,b,c) = a * b + c
  1973. Frc
  1974. ~~~
  1975. +--------------+------+------+---------+----+----+---------+--------+------+-----+
  1976. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  1977. +--------------+------+------+---------+----+----+---------+--------+------+-----+
  1978. | log(src) | NaN |[+0,1)| +0 | +0 | +0 | +0 | [+0,1) | NaN | NaN |
  1979. +--------------+------+------+---------+----+----+---------+--------+------+-----+
  1980. Hcos
  1981. ~~~~
  1982. Returns the hyperbolic cosine of the specified value.
  1983. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1984. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  1985. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1986. | hcos(src)| +inf | (1, +inf) | +1 | +1 | +1 | +1 | (1, +inf) | +inf | NaN |
  1987. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1988. Hsin
  1989. ~~~~
  1990. Returns the hyperbolic sine of the specified value.
  1991. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1992. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  1993. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1994. | hsin(src)| -inf | -F | 0 | 0 | 0 | 0 | +F | +inf | NaN |
  1995. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1996. Htan
  1997. ~~~~
  1998. Returns the hyperbolic tangent of the specified value.
  1999. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  2000. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  2001. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  2002. | htan(src)| -1 | -F | 0 | 0 | 0 | 0 | +F | +1 | NaN |
  2003. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  2004. IMad
  2005. ~~~~
  2006. Signed integer multiply & add
  2007. IMad(a,b,c) = a * b + c
  2008. IMax
  2009. ~~~~
  2010. IMax(a,b) returns a if a > b, else b. Optional negate modifier on source operands takes 2's complement before performing operation.
  2011. IMin
  2012. ~~~~
  2013. IMin(a,b) returns a if a < b, else b. Optional negate modifier on source operands takes 2's complement before performing operation.
  2014. IMul
  2015. ~~~~
  2016. IMul(src0, src1) = destHi, destLo
  2017. multiply of 32-bit operands src0 and src1 (note they are signed), producing the correct full 64-bit result.
  2018. The low 32 bits are placed in destLO. The high 32 bits are placed in destHI.
  2019. Either of destHI or destLO may be specified as NULL instead of specifying a register, in the case high or low 32 bits of the 64-bit result are not needed.
  2020. Optional negate modifier on source operands takes 2's complement before performing arithmetic operation.
  2021. Ibfe
  2022. ~~~~
  2023. dest = Ibfe(src0, src1, src2)
  2024. Given a range of bits in a number, shift those bits to the LSB and sign extend the MSB of the range.
  2025. width : The LSB 5 bits of src0 (0-31).
  2026. offset: The LSB 5 bits of src1 (0-31)
  2027. .. code:: c
  2028. if( width == 0 )
  2029. {
  2030. dest = 0
  2031. }
  2032. else if( width + offset < 32 )
  2033. {
  2034. shl dest, src2, 32-(width+offset)
  2035. ishr dest, dest, 32-width
  2036. }
  2037. else
  2038. {
  2039. ishr dest, src2, offset
  2040. }
  2041. IsFinite
  2042. ~~~~~~~~
  2043. Returns true if x is finite, false otherwise.
  2044. IsInf
  2045. ~~~~~
  2046. Returns true if x is +INF or -INF, false otherwise.
  2047. IsNaN
  2048. ~~~~~
  2049. Returns true if x is NAN or QNAN, false otherwise.
  2050. IsNormal
  2051. ~~~~~~~~
  2052. Returns IsNormal.
  2053. LoadInput
  2054. ~~~~~~~~~
  2055. Loads the value from shader input
  2056. Log
  2057. ~~~
  2058. Returns log base 2. Note that hlsl log intrinsic returns natural log.
  2059. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  2060. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  2061. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  2062. | log(src) | NaN | NaN | -inf |-inf|-inf| -inf | F | +inf | NaN |
  2063. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  2064. MinPrecXRegLoad
  2065. ~~~~~~~~~~~~~~~
  2066. Helper load operation for minprecision
  2067. MinPrecXRegStore
  2068. ~~~~~~~~~~~~~~~~
  2069. Helper store operation for minprecision
  2070. Msad
  2071. ~~~~
  2072. Returns the masked Sum of Absolute Differences.
  2073. dest = msad(ref, src, accum)
  2074. ref: contains 4 packed 8-bit unsigned integers in 32 bits.
  2075. src: contains 4 packed 8-bit unsigned integers in 32 bits.
  2076. accum: a 32-bit unsigned integer, providing an existing accumulation.
  2077. dest receives the result of the masked SAD operation added to the accumulation value.
  2078. .. code:: c
  2079. UINT msad( UINT ref, UINT src, UINT accum )
  2080. {
  2081. for (UINT i = 0; i < 4; i++)
  2082. {
  2083. BYTE refByte, srcByte, absDiff;
  2084. refByte = (BYTE)(ref >> (i * 8));
  2085. if (!refByte)
  2086. {
  2087. continue;
  2088. }
  2089. srcByte = (BYTE)(src >> (i * 8));
  2090. if (refByte >= srcByte)
  2091. {
  2092. absDiff = refByte - srcByte;
  2093. }
  2094. else
  2095. {
  2096. absDiff = srcByte - refByte;
  2097. }
  2098. // The recommended overflow behavior for MSAD is
  2099. // to do a 32-bit saturate. This is not
  2100. // required, however, and wrapping is allowed.
  2101. // So from an application point of view,
  2102. // overflow behavior is undefined.
  2103. if (UINT_MAX - accum < absDiff)
  2104. {
  2105. accum = UINT_MAX;
  2106. break;
  2107. }
  2108. accum += absDiff;
  2109. }
  2110. return accum;
  2111. }
  2112. Round_ne
  2113. ~~~~~~~~
  2114. Floating-point round of the values in src,
  2115. writing integral floating-point values to dest.
  2116. round_ne rounds towards nearest even. For halfway, it rounds away from zero.
  2117. +--------------+------+----+---------+----+----+---------+----+------+-----+
  2118. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  2119. +--------------+------+----+---------+----+----+---------+----+------+-----+
  2120. | round_ne(src)| -inf | -F | -0 | -0 | +0 | +0 | +F | +inf | NaN |
  2121. +--------------+------+----+---------+----+----+---------+----+------+-----+
  2122. Round_ni
  2123. ~~~~~~~~
  2124. Floating-point round of the values in src,
  2125. writing integral floating-point values to dest.
  2126. round_ni rounds towards -INF, commonly known as floor().
  2127. +--------------+------+----+---------+----+----+---------+----+------+-----+
  2128. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  2129. +--------------+------+----+---------+----+----+---------+----+------+-----+
  2130. | round_ni(src)| -inf | -F | -0 | -0 | +0 | +0 | +F | +inf | NaN |
  2131. +--------------+------+----+---------+----+----+---------+----+------+-----+
  2132. Round_pi
  2133. ~~~~~~~~
  2134. Floating-point round of the values in src,
  2135. writing integral floating-point values to dest.
  2136. round_pi rounds towards +INF, commonly known as ceil().
  2137. +--------------+------+----+---------+----+----+---------+----+------+-----+
  2138. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  2139. +--------------+------+----+---------+----+----+---------+----+------+-----+
  2140. | round_pi(src)| -inf | -F | -0 | -0 | +0 | +0 | +F | +inf | NaN |
  2141. +--------------+------+----+---------+----+----+---------+----+------+-----+
  2142. Round_z
  2143. ~~~~~~~
  2144. Floating-point round of the values in src,
  2145. writing integral floating-point values to dest.
  2146. round_z rounds towards zero.
  2147. +--------------+------+----+---------+----+----+---------+----+------+-----+
  2148. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  2149. +--------------+------+----+---------+----+----+---------+----+------+-----+
  2150. | round_z(src) | -inf | -F | -0 | -0 | +0 | +0 | +F | +inf | NaN |
  2151. +--------------+------+----+---------+----+----+---------+----+------+-----+
  2152. Rsqrt
  2153. ~~~~~
  2154. Maximum relative error is 2^21.
  2155. +--------------+------+----+---------+----+----+---------+----+------+-----+
  2156. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  2157. +--------------+------+----+---------+----+----+---------+----+------+-----+
  2158. | rsqrt(src) | -inf | -F | -0 | -0 | +0 | +0 | +F | +inf | NaN |
  2159. +--------------+------+----+---------+----+----+---------+----+------+-----+
  2160. Saturate
  2161. ~~~~~~~~
  2162. The Saturate instruction performs the following operation on its input value:
  2163. min(1.0f, max(0.0f, value))
  2164. where min() and max() in the above expression behave in the way Min and Max behave.
  2165. Saturate(NaN) returns 0, by the rules for min and max.
  2166. Sin
  2167. ~~~
  2168. Theta values can be any IEEE 32-bit floating point values.
  2169. The maximum absolute error is 0.0008 in the interval from -100*Pi to +100*Pi.
  2170. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  2171. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  2172. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  2173. | sin(src) | NaN | [-1 to +1] | -0 | -0 | +0 | +0 | [-1 to +1] | NaN | NaN |
  2174. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  2175. Sqrt
  2176. ~~~~
  2177. Precision is 1 ulp.
  2178. +--------------+------+----+---------+----+----+---------+----+------+-----+
  2179. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  2180. +--------------+------+----+---------+----+----+---------+----+------+-----+
  2181. | sqrt(src) | NaN | NaN| -0 | -0 | +0 | +0 | +F | +inf | NaN |
  2182. +--------------+------+----+---------+----+----+---------+----+------+-----+
  2183. StoreOutput
  2184. ~~~~~~~~~~~
  2185. Stores the value to shader output
  2186. Tan
  2187. ~~~
  2188. Theta values can be any IEEE 32-bit floating point values.
  2189. +----------+----------+----------------+---------+----+----+---------+----------------+------+-----+
  2190. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  2191. +----------+----------+----------------+---------+----+----+---------+----------------+------+-----+
  2192. | tan(src) | NaN | [-inf to +inf] | -0 | -0 | +0 | +0 | [-inf to +inf] | NaN | NaN |
  2193. +----------+----------+----------------+---------+----+----+---------+----------------+------+-----+
  2194. TempRegLoad
  2195. ~~~~~~~~~~~
  2196. Helper load operation
  2197. TempRegStore
  2198. ~~~~~~~~~~~~
  2199. Helper store operation
  2200. UAddc
  2201. ~~~~~
  2202. dest0, dest1 = UAddc(src0, src1)
  2203. unsigned add of 32-bit operands src0 and src1, placing the LSB part of the 32-bit result in dest0.
  2204. dest1 is written with: 1 if a carry is produced, 0 otherwise. Dest1 can be NULL if the carry is not needed
  2205. UDiv
  2206. ~~~~
  2207. destQUOT, destREM = UDiv(src0, src1);
  2208. unsigned divide of the 32-bit operand src0 by the 32-bit operand src1.
  2209. The results of the divides are the 32-bit quotients (placed in destQUOT) and 32-bit remainders (placed in destREM).
  2210. Divide by zero returns 0xffffffff for both quotient and remainder.
  2211. Either destQUOT or destREM may be specified as NULL instead of specifying a register, in the case the quotient or remainder are not needed.
  2212. Unsigned subtract of 32-bit operands src1 from src0, placing the LSB part of the 32-bit result in dest0.
  2213. dest1 is written with: 1 if a borrow is produced, 0 otherwise. Dest1 can be NULL if the borrow is not needed
  2214. UMad
  2215. ~~~~
  2216. Unsigned integer multiply & add.
  2217. Umad(a,b,c) = a * b + c
  2218. UMax
  2219. ~~~~
  2220. unsigned integer maximum. UMax(a,b) = a > b ? a : b
  2221. UMin
  2222. ~~~~
  2223. unsigned integer minimum. UMin(a,b) = a < b ? a : b
  2224. UMul
  2225. ~~~~
  2226. multiply of 32-bit operands src0 and src1 (note they are unsigned), producing the correct full 64-bit result.
  2227. The low 32 bits are placed in destLO. The high 32 bits are placed in destHI.
  2228. Either of destHI or destLO may be specified as NULL instead of specifying a register, in the case high or low 32 bits of the 64-bit result are not needed
  2229. USubb
  2230. ~~~~~
  2231. dest0, dest1 = USubb(src0, src1)
  2232. Ubfe
  2233. ~~~~
  2234. dest = ubfe(src0, src1, src2)
  2235. Given a range of bits in a number, shift those bits to the LSB and set remaining bits to 0.
  2236. width : The LSB 5 bits of src0 (0-31).
  2237. offset: The LSB 5 bits of src1 (0-31).
  2238. Given width, offset:
  2239. .. code:: c
  2240. if( width == 0 )
  2241. {
  2242. dest = 0
  2243. }
  2244. else if( width + offset < 32 )
  2245. {
  2246. shl dest, src2, 32-(width+offset)
  2247. ushr dest, dest, 32-width
  2248. }
  2249. else
  2250. {
  2251. ushr dest, src2, offset
  2252. }
  2253. .. OPCODES-RST:END
  2254. Custom instructions
  2255. -------------------
  2256. Instructions for third-party extensions will be specially-prefixed external function calls, identified by a declared extension-set-prefix. Additional metadata will be included to provide hints about uniformity, pure or const guarantees, alignment, etc.
  2257. Validation Rules
  2258. ================
  2259. The following rules are verified by the *Validator* component and thus can be relied upon by downstream consumers.
  2260. The set of validation rules that are known to hold for a DXIL program is identifier by the 'dx.valver' named metadata node, which consists of a two-element tuple of constant int values, a major and minor version. Minor version numbers are increments as rules are added to a prior table or as the implementation fixes issues.
  2261. .. <py::lines('VALRULES-RST')>hctdb_instrhelp.get_valrules_rst()</py>
  2262. .. VALRULES-RST:BEGIN
  2263. ========================================= =======================================================================================================================================================================================================================================================================================================
  2264. Rule Code Description
  2265. ========================================= =======================================================================================================================================================================================================================================================================================================
  2266. BITCODE.VALID TODO - Module must be bitcode-valid
  2267. CONTAINER.PARTINVALID DXIL Container must not contain unknown parts
  2268. CONTAINER.PARTMATCHES DXIL Container Parts must match Module
  2269. CONTAINER.PARTMISSING DXIL Container requires certain parts, corresponding to module
  2270. CONTAINER.PARTREPEATED DXIL Container must have only one of each part type
  2271. CONTAINER.ROOTSIGNATUREINCOMPATIBLE Root Signature in DXIL Container must be compatible with shader
  2272. DECL.ATTRSTRUCT Attributes parameter must be struct type
  2273. DECL.DXILFNEXTERN External function must be a DXIL function
  2274. DECL.DXILNSRESERVED The DXIL reserved prefixes must only be used by built-in functions and types
  2275. DECL.EXTRAARGS Extra arguments not allowed for shader functions
  2276. DECL.FNATTRIBUTE Functions should only contain known function attributes
  2277. DECL.FNFLATTENPARAM Function parameters must not use struct types
  2278. DECL.FNISCALLED Functions can only be used by call instructions
  2279. DECL.NOTUSEDEXTERNAL External declaration should not be used
  2280. DECL.PARAMSTRUCT Callable function parameter must be struct type
  2281. DECL.PAYLOADSTRUCT Payload parameter must be struct type
  2282. DECL.RESOURCEINFNSIG Resources not allowed in function signatures
  2283. DECL.SHADERMISSINGARG payload/params/attributes parameter is required for certain shader types
  2284. DECL.SHADERRETURNVOID Shader functions must return void
  2285. DECL.USEDEXTERNALFUNCTION External function must be used
  2286. DECL.USEDINTERNAL Internal declaration must be used
  2287. FLOW.DEADLOOP Loop must have break
  2288. FLOW.FUNCTIONCALL Function with parameter is not permitted
  2289. FLOW.NORECUSION Recursion is not permitted
  2290. FLOW.REDUCIBLE Execution flow must be reducible
  2291. INSTR.ALLOWED Instructions must be of an allowed type
  2292. INSTR.ATTRIBUTEATVERTEXNOINTERPOLATION Attribute %0 must have nointerpolation mode in order to use GetAttributeAtVertex function.
  2293. INSTR.BARRIERMODEFORNONCS sync in a non-Compute/Amplification/Mesh Shader must only sync UAV (sync_uglobal)
  2294. INSTR.BARRIERMODENOMEMORY sync must include some form of memory barrier - _u (UAV) and/or _g (Thread Group Shared Memory). Only _t (thread group sync) is optional.
  2295. INSTR.BARRIERMODEUSELESSUGROUP sync can't specify both _ugroup and _uglobal. If both are needed, just specify _uglobal.
  2296. INSTR.BUFFERUPDATECOUNTERONRESHASCOUNTER BufferUpdateCounter valid only when HasCounter is true
  2297. INSTR.BUFFERUPDATECOUNTERONUAV BufferUpdateCounter valid only on UAV
  2298. INSTR.CALLOLOAD Call to DXIL intrinsic must match overload signature
  2299. INSTR.CANNOTPULLPOSITION pull-model evaluation of position disallowed
  2300. INSTR.CBUFFERCLASSFORCBUFFERHANDLE Expect Cbuffer for CBufferLoad handle
  2301. INSTR.CBUFFEROUTOFBOUND Cbuffer access out of bound
  2302. INSTR.CHECKACCESSFULLYMAPPED CheckAccessFullyMapped should only used on resource status
  2303. INSTR.COORDINATECOUNTFORRAWTYPEDBUF raw/typed buffer don't need 2 coordinates
  2304. INSTR.COORDINATECOUNTFORSTRUCTBUF structured buffer require 2 coordinates
  2305. INSTR.CREATEHANDLEIMMRANGEID Local resource must map to global resource.
  2306. INSTR.DXILSTRUCTUSER Dxil struct types should only used by ExtractValue
  2307. INSTR.DXILSTRUCTUSEROUTOFBOUND Index out of bound when extract value from dxil struct types
  2308. INSTR.EVALINTERPOLATIONMODE Interpolation mode on %0 used with eval_* instruction must be linear, linear_centroid, linear_noperspective, linear_noperspective_centroid, linear_sample or linear_noperspective_sample
  2309. INSTR.EXTRACTVALUE ExtractValue should only be used on dxil struct types and cmpxchg
  2310. INSTR.FAILTORESLOVETGSMPOINTER TGSM pointers must originate from an unambiguous TGSM global variable.
  2311. INSTR.HANDLENOTFROMCREATEHANDLE Resource handle should returned by createHandle
  2312. INSTR.IMMBIASFORSAMPLEB bias amount for sample_b must be in the range [%0,%1], but %2 was specified as an immediate
  2313. INSTR.INBOUNDSACCESS Access to out-of-bounds memory is disallowed
  2314. INSTR.MINPRECISIONNOTPRECISE Instructions marked precise may not refer to minprecision values
  2315. INSTR.MINPRECISONBITCAST Bitcast on minprecison types is not allowed
  2316. INSTR.MIPLEVELFORGETDIMENSION Use mip level on buffer when GetDimensions
  2317. INSTR.MIPONUAVLOAD uav load don't support mipLevel/sampleIndex
  2318. INSTR.MISSINGSETMESHOUTPUTCOUNTS Missing SetMeshOutputCounts call.
  2319. INSTR.MULTIPLEGETMESHPAYLOAD GetMeshPayload cannot be called multiple times.
  2320. INSTR.MULTIPLESETMESHOUTPUTCOUNTS SetMeshOUtputCounts cannot be called multiple times.
  2321. INSTR.NOGENERICPTRADDRSPACECAST Address space cast between pointer types must have one part to be generic address space
  2322. INSTR.NOIDIVBYZERO No signed integer division by zero
  2323. INSTR.NOINDEFINITEACOS No indefinite arccosine
  2324. INSTR.NOINDEFINITEASIN No indefinite arcsine
  2325. INSTR.NOINDEFINITEDSXY No indefinite derivative calculation
  2326. INSTR.NOINDEFINITELOG No indefinite logarithm
  2327. INSTR.NONDOMINATINGDISPATCHMESH Non-Dominating DispatchMesh call.
  2328. INSTR.NONDOMINATINGSETMESHOUTPUTCOUNTS Non-Dominating SetMeshOutputCounts call.
  2329. INSTR.NOREADINGUNINITIALIZED Instructions should not read uninitialized value
  2330. INSTR.NOTONCEDISPATCHMESH DispatchMesh must be called exactly once in an Amplification shader.
  2331. INSTR.NOUDIVBYZERO No unsigned integer division by zero
  2332. INSTR.OFFSETONUAVLOAD uav load don't support offset
  2333. INSTR.OLOAD DXIL intrinsic overload must be valid
  2334. INSTR.ONLYONEALLOCCONSUME RWStructuredBuffers may increment or decrement their counters, but not both.
  2335. INSTR.OPCODERESERVED Instructions must not reference reserved opcodes
  2336. INSTR.OPCONST DXIL intrinsic requires an immediate constant operand
  2337. INSTR.OPCONSTRANGE Constant values must be in-range for operation
  2338. INSTR.OPERANDRANGE DXIL intrinsic operand must be within defined range
  2339. INSTR.PTRBITCAST Pointer type bitcast must be have same size
  2340. INSTR.RESOURCECLASSFORLOAD load can only run on UAV/SRV resource
  2341. INSTR.RESOURCECLASSFORSAMPLERGATHER sample, lod and gather should be on srv resource.
  2342. INSTR.RESOURCECLASSFORUAVSTORE store should be on uav resource.
  2343. INSTR.RESOURCECOORDINATEMISS coord uninitialized
  2344. INSTR.RESOURCECOORDINATETOOMANY out of bound coord must be undef
  2345. INSTR.RESOURCEKINDFORBUFFERLOADSTORE buffer load/store only works on Raw/Typed/StructuredBuffer
  2346. INSTR.RESOURCEKINDFORCALCLOD lod requires resource declared as texture1D/2D/3D/Cube/CubeArray/1DArray/2DArray
  2347. INSTR.RESOURCEKINDFORGATHER gather requires resource declared as texture/2D/Cube/2DArray/CubeArray
  2348. INSTR.RESOURCEKINDFORGETDIM Invalid resource kind on GetDimensions
  2349. INSTR.RESOURCEKINDFORSAMPLE sample/_l/_d requires resource declared as texture1D/2D/3D/Cube/1DArray/2DArray/CubeArray
  2350. INSTR.RESOURCEKINDFORSAMPLEC samplec requires resource declared as texture1D/2D/Cube/1DArray/2DArray/CubeArray
  2351. INSTR.RESOURCEKINDFORTEXTURELOAD texture load only works on Texture1D/1DArray/2D/2DArray/3D/MS2D/MS2DArray
  2352. INSTR.RESOURCEKINDFORTEXTURESTORE texture store only works on Texture1D/1DArray/2D/2DArray/3D
  2353. INSTR.RESOURCEKINDFORTRACERAY TraceRay should only use RTAccelerationStructure
  2354. INSTR.RESOURCEMAPTOSINGLEENTRY Fail to map resource to resource table
  2355. INSTR.RESOURCEOFFSETMISS offset uninitialized
  2356. INSTR.RESOURCEOFFSETTOOMANY out of bound offset must be undef
  2357. INSTR.RESOURCEUSER Resource should only used by Load/GEP/Call
  2358. INSTR.SAMPLECOMPTYPE sample_* instructions require resource to be declared to return UNORM, SNORM or FLOAT.
  2359. INSTR.SAMPLEINDEXFORLOAD2DMS load on Texture2DMS/2DMSArray require sampleIndex
  2360. INSTR.SAMPLERMODEFORLOD lod instruction requires sampler declared in default mode
  2361. INSTR.SAMPLERMODEFORSAMPLE sample/_l/_d/_cl_s/gather instruction requires sampler declared in default mode
  2362. INSTR.SAMPLERMODEFORSAMPLEC sample_c_*/gather_c instructions require sampler declared in comparison mode
  2363. INSTR.SIGNATUREOPERATIONNOTINENTRY Dxil operation for input output signature must be in entryPoints.
  2364. INSTR.STATUS Resource status should only used by CheckAccessFullyMapped
  2365. INSTR.STRUCTBITCAST Bitcast on struct types is not allowed
  2366. INSTR.TEXTUREOFFSET offset texture instructions must take offset which can resolve to integer literal in the range -8 to 7
  2367. INSTR.TGSMRACECOND Race condition writing to shared memory detected, consider making this write conditional
  2368. INSTR.UNDEFRESULTFORGETDIMENSION GetDimensions used undef dimension %0 on %1
  2369. INSTR.WRITEMASKFORTYPEDUAVSTORE store on typed uav must write to all four components of the UAV
  2370. INSTR.WRITEMASKMATCHVALUEFORUAVSTORE uav store write mask must match store value mask, write mask is %0 and store value mask is %1
  2371. META.BARYCENTRICSFLOAT3 only 'float3' type is allowed for SV_Barycentrics.
  2372. META.BARYCENTRICSINTERPOLATION SV_Barycentrics cannot be used with 'nointerpolation' type
  2373. META.BARYCENTRICSTWOPERSPECTIVES There can only be up to two input attributes of SV_Barycentrics with different perspective interpolation mode.
  2374. META.BRANCHFLATTEN Can't use branch and flatten attributes together
  2375. META.CLIPCULLMAXCOMPONENTS Combined elements of SV_ClipDistance and SV_CullDistance must fit in 8 components
  2376. META.CLIPCULLMAXROWS Combined elements of SV_ClipDistance and SV_CullDistance must fit in two rows.
  2377. META.CONTROLFLOWHINTNOTONCONTROLFLOW Control flow hint only works on control flow inst
  2378. META.DENSERESIDS Resource identifiers must be zero-based and dense
  2379. META.DUPLICATESYSVALUE System value may only appear once in signature
  2380. META.ENTRYFUNCTION entrypoint not found
  2381. META.FLAGSUSAGE Flags must match usage
  2382. META.FORCECASEONSWITCH Attribute forcecase only works for switch
  2383. META.GLCNOTONAPPENDCONSUME globallycoherent cannot be used with append/consume buffers
  2384. META.INTEGERINTERPMODE Interpolation mode on integer must be Constant
  2385. META.INTERPMODEINONEROW Interpolation mode must be identical for all elements packed into the same row.
  2386. META.INTERPMODEVALID Interpolation mode must be valid
  2387. META.INVALIDCONTROLFLOWHINT Invalid control flow hint
  2388. META.KNOWN Named metadata should be known
  2389. META.MAXTESSFACTOR Hull Shader MaxTessFactor must be [%0..%1]. %2 specified
  2390. META.NOENTRYPROPSFORENTRY EntryPoints must have entry properties.
  2391. META.NOSEMANTICOVERLAP Semantics must not overlap
  2392. META.REQUIRED TODO - Required metadata missing
  2393. META.SEMAKINDMATCHESNAME Semantic name must match system value, when defined.
  2394. META.SEMAKINDVALID Semantic kind must be valid
  2395. META.SEMANTICCOMPTYPE %0 must be %1
  2396. META.SEMANTICINDEXMAX System value semantics have a maximum valid semantic index
  2397. META.SEMANTICLEN Semantic length must be at least 1 and at most 64
  2398. META.SEMANTICSHOULDBEALLOCATED Semantic should have a valid packing location
  2399. META.SEMANTICSHOULDNOTBEALLOCATED Semantic should have a packing location of -1
  2400. META.SIGNATURECOMPTYPE signature %0 specifies unrecognized or invalid component type
  2401. META.SIGNATUREDATAWIDTH Data width must be identical for all elements packed into the same row.
  2402. META.SIGNATUREILLEGALCOMPONENTORDER Component ordering for packed elements must be: arbitrary < system value < system generated value
  2403. META.SIGNATUREINDEXCONFLICT Only elements with compatible indexing rules may be packed together
  2404. META.SIGNATUREOUTOFRANGE Signature elements must fit within maximum signature size
  2405. META.SIGNATUREOVERLAP Signature elements may not overlap in packing location.
  2406. META.STRUCTBUFALIGNMENT StructuredBuffer stride not aligned
  2407. META.STRUCTBUFALIGNMENTOUTOFBOUND StructuredBuffer stride out of bounds
  2408. META.SYSTEMVALUEROWS System value may only have 1 row
  2409. META.TARGET Target triple must be 'dxil-ms-dx'
  2410. META.TESSELLATOROUTPUTPRIMITIVE Invalid Tessellator Output Primitive specified. Must be point, line, triangleCW or triangleCCW.
  2411. META.TESSELLATORPARTITION Invalid Tessellator Partitioning specified. Must be integer, pow2, fractional_odd or fractional_even.
  2412. META.TEXTURETYPE elements of typed buffers and textures must fit in four 32-bit quantities
  2413. META.USED All metadata must be used by dxil
  2414. META.VALIDSAMPLERMODE Invalid sampler mode on sampler
  2415. META.VALUERANGE Metadata value must be within range
  2416. META.WELLFORMED TODO - Metadata must be well-formed in operand count and types
  2417. SM.64BITRAWBUFFERLOADSTORE i64/f64 rawBufferLoad/Store overloads are allowed after SM 6.3
  2418. SM.AMPLIFICATIONSHADERPAYLOADSIZE For shader '%0', payload size is greater than %1
  2419. SM.AMPLIFICATIONSHADERPAYLOADSIZEDECLARED For shader '%0', payload size %1 is greater than declared size of %2 bytes
  2420. SM.APPENDANDCONSUMEONSAMEUAV BufferUpdateCounter inc and dec on a given UAV (%d) cannot both be in the same shader for shader model less than 5.1.
  2421. SM.CBUFFERARRAYOFFSETALIGNMENT CBuffer array offset must be aligned to 16-bytes
  2422. SM.CBUFFERELEMENTOVERFLOW CBuffer elements must not overflow
  2423. SM.CBUFFEROFFSETOVERLAP CBuffer offsets must not overlap
  2424. SM.CBUFFERTEMPLATETYPEMUSTBESTRUCT D3D12 constant/texture buffer template element can only be a struct
  2425. SM.COMPLETEPOSITION Not all elements of SV_Position were written
  2426. SM.CONSTANTINTERPMODE Interpolation mode must be constant for MS primitive output.
  2427. SM.COUNTERONLYONSTRUCTBUF BufferUpdateCounter valid only on structured buffers
  2428. SM.CSNOSIGNATURES Compute shaders must not have shader signatures.
  2429. SM.DOMAINLOCATIONIDXOOB DomainLocation component index out of bounds for the domain.
  2430. SM.DSINPUTCONTROLPOINTCOUNTRANGE DS input control point count must be [0..%0]. %1 specified
  2431. SM.DXILVERSION Target shader model requires specific Dxil Version
  2432. SM.GSINSTANCECOUNTRANGE GS instance count must be [1..%0]. %1 specified
  2433. SM.GSOUTPUTVERTEXCOUNTRANGE GS output vertex count must be [0..%0]. %1 specified
  2434. SM.GSTOTALOUTPUTVERTEXDATARANGE Declared output vertex count (%0) multiplied by the total number of declared scalar components of output data (%1) equals %2. This value cannot be greater than %3
  2435. SM.GSVALIDINPUTPRIMITIVE GS input primitive unrecognized
  2436. SM.GSVALIDOUTPUTPRIMITIVETOPOLOGY GS output primitive topology unrecognized
  2437. SM.HSINPUTCONTROLPOINTCOUNTRANGE HS input control point count must be [0..%0]. %1 specified
  2438. SM.HULLPASSTHRUCONTROLPOINTCOUNTMATCH For pass thru hull shader, input control point count must match output control point count
  2439. SM.INSIDETESSFACTORSIZEMATCHDOMAIN InsideTessFactor rows, columns (%0, %1) invalid for domain %2. Expected %3 rows and 1 column.
  2440. SM.INVALIDRESOURCECOMPTYPE Invalid resource return type
  2441. SM.INVALIDRESOURCEKIND Invalid resources kind
  2442. SM.INVALIDSAMPLERFEEDBACKTYPE Invalid sampler feedback type
  2443. SM.INVALIDTEXTUREKINDONUAV Texture2DMS[Array] or TextureCube[Array] resources are not supported with UAVs
  2444. SM.ISOLINEOUTPUTPRIMITIVEMISMATCH Hull Shader declared with IsoLine Domain must specify output primitive point or line. Triangle_cw or triangle_ccw output are not compatible with the IsoLine Domain.
  2445. SM.MAXMSSMSIZE Total Thread Group Shared Memory storage is %0, exceeded %1
  2446. SM.MAXTGSMSIZE Total Thread Group Shared Memory storage is %0, exceeded %1
  2447. SM.MAXTHEADGROUP Declared Thread Group Count %0 (X*Y*Z) is beyond the valid maximum of %1
  2448. SM.MESHPSIGROWCOUNT For shader '%0', primitive output signatures are taking up more than %1 rows
  2449. SM.MESHSHADERINOUTSIZE For shader '%0', payload plus output size is greater than %1
  2450. SM.MESHSHADERMAXPRIMITIVECOUNT MS max primitive output count must be [0..%0]. %1 specified
  2451. SM.MESHSHADERMAXVERTEXCOUNT MS max vertex output count must be [0..%0]. %1 specified
  2452. SM.MESHSHADEROUTPUTSIZE For shader '%0', vertex plus primitive output size is greater than %1
  2453. SM.MESHSHADERPAYLOADSIZE For shader '%0', payload size is greater than %1
  2454. SM.MESHSHADERPAYLOADSIZEDECLARED For shader '%0', payload size %1 is greater than declared size of %2 bytes
  2455. SM.MESHTOTALSIGROWCOUNT For shader '%0', vertex and primitive output signatures are taking up more than %1 rows
  2456. SM.MESHVSIGROWCOUNT For shader '%0', vertex output signatures are taking up more than %1 rows
  2457. SM.MULTISTREAMMUSTBEPOINT When multiple GS output streams are used they must be pointlists
  2458. SM.NAME Target shader model name must be known
  2459. SM.NOINTERPMODE Interpolation mode must be undefined for VS input/PS output/patch constant.
  2460. SM.NOPSOUTPUTIDX Pixel shader output registers are not indexable.
  2461. SM.OPCODE Opcode must be defined in target shader model
  2462. SM.OPCODEININVALIDFUNCTION Invalid DXIL opcode usage like StorePatchConstant in patch constant function
  2463. SM.OPERAND Operand must be defined in target shader model
  2464. SM.OUTPUTCONTROLPOINTCOUNTRANGE output control point count must be [0..%0]. %1 specified
  2465. SM.OUTPUTCONTROLPOINTSTOTALSCALARS Total number of scalars across all HS output control points must not exceed
  2466. SM.PATCHCONSTANTONLYFORHSDS patch constant signature only valid in HS and DS
  2467. SM.PSCONSISTENTINTERP Interpolation mode for PS input position must be linear_noperspective_centroid or linear_noperspective_sample when outputting oDepthGE or oDepthLE and not running at sample frequency (which is forced by inputting SV_SampleIndex or declaring an input linear_sample or linear_noperspective_sample)
  2468. SM.PSCOVERAGEANDINNERCOVERAGE InnerCoverage and Coverage are mutually exclusive.
  2469. SM.PSMULTIPLEDEPTHSEMANTIC Pixel Shader only allows one type of depth semantic to be declared
  2470. SM.PSOUTPUTSEMANTIC Pixel Shader allows output semantics to be SV_Target, SV_Depth, SV_DepthGreaterEqual, SV_DepthLessEqual, SV_Coverage or SV_StencilRef, %0 found
  2471. SM.PSTARGETCOL0 SV_Target packed location must start at column 0
  2472. SM.PSTARGETINDEXMATCHESROW SV_Target semantic index must match packed row location
  2473. SM.RAYSHADERPAYLOADSIZE For shader '%0', %1 size is smaller than argument's allocation size
  2474. SM.RAYSHADERSIGNATURES Ray tracing shader '%0' should not have any shader signatures
  2475. SM.RESOURCERANGEOVERLAP Resource ranges must not overlap
  2476. SM.ROVONLYINPS RasterizerOrdered objects are only allowed in 5.0+ pixel shaders
  2477. SM.SAMPLECOUNTONLYON2DMS Only Texture2DMS/2DMSArray could has sample count
  2478. SM.SEMANTIC Semantic must be defined in target shader model
  2479. SM.STREAMINDEXRANGE Stream index (%0) must between 0 and %1
  2480. SM.TESSFACTORFORDOMAIN Required TessFactor for domain not found declared anywhere in Patch Constant data
  2481. SM.TESSFACTORSIZEMATCHDOMAIN TessFactor rows, columns (%0, %1) invalid for domain %2. Expected %3 rows and 1 column.
  2482. SM.THREADGROUPCHANNELRANGE Declared Thread Group %0 size %1 outside valid range [%2..%3]
  2483. SM.TRIOUTPUTPRIMITIVEMISMATCH Hull Shader declared with Tri Domain must specify output primitive point, triangle_cw or triangle_ccw. Line output is not compatible with the Tri domain
  2484. SM.UNDEFINEDOUTPUT Not all elements of output %0 were written
  2485. SM.VALIDDOMAIN Invalid Tessellator Domain specified. Must be isoline, tri or quad
  2486. SM.VIEWIDNEEDSSLOT ViewID requires compatible space in pixel shader input signature
  2487. SM.ZEROHSINPUTCONTROLPOINTWITHINPUT When HS input control point count is 0, no input signature should exist
  2488. TYPES.DEFINED Type must be defined based on DXIL primitives
  2489. TYPES.I8 I8 can only used as immediate value for intrinsic
  2490. TYPES.INTWIDTH Int type must be of valid width
  2491. TYPES.NOMULTIDIM Only one dimension allowed for array type
  2492. TYPES.NOPTRTOPTR Pointers to pointers, or pointers in structures are not allowed
  2493. TYPES.NOVECTOR Vector types must not be present
  2494. ========================================= =======================================================================================================================================================================================================================================================================================================
  2495. .. VALRULES-RST:END
  2496. Modules and Linking
  2497. ===================
  2498. HLSL has linking capabilities to enable third-party libraries. The linking step happens before shader DXIL is given to the driver compilers.
  2499. Experimental library generation is added in DXIL1.1. A library could be created by compile with lib_6_1 profile.
  2500. A library is a dxil container like the compile result of other shader profiles. The difference is library will keep information for linking like resource link info and entry function signatures.
  2501. Library support is not part of DXIL spec. Only requirement is linked shader must be valid DXIL.
  2502. Additional Notes
  2503. ================
  2504. These additional notes are not normative for DXIL, and are included for the convenience of implementers.
  2505. Other Versioned Components
  2506. --------------------------
  2507. In addition to shader model, DXIL and bitcode representation versions, two other interesting versioned components are discussed: the supporting operating system and runtime, and the HLSL language.
  2508. Support is provided in the Microsoft Windows family of operating systems, when running on the D3D12 runtime.
  2509. The HLSL language is versioned independently of DXIL, and currently follows an 'HLSL <year>' naming scheme. HLSL 2015 is the dialect supported by the d3dcompiler_47 library; a limited form of support is provided in the open source HLSL on LLVM project. HLSL 2016 is the version supported by the current HLSL on LLVM project, which removes some features (primarily effect framework syntax, backquote operator) and adds new ones (wave intrinsics and basic i64 support).
  2510. .. _dxil_container_format:
  2511. DXIL Container Format
  2512. ---------------------
  2513. DXIL is typically encapsulated in a DXIL container. A DXIL container is composed of a header, a sequence of part lengths, and a sequence of parts.
  2514. The following C declaration describes this structure::
  2515. struct DxilContainerHeader {
  2516. uint32_t HeaderFourCC;
  2517. uint8_t Digest[DxilContainerHashSize];
  2518. uint16_t MajorVersion;
  2519. uint16_t MinorVersion;
  2520. uint32_t ContainerSizeInBytes; // From start of this header
  2521. uint32_t PartCount;
  2522. // Structure is followed by uint32_t PartOffset[PartCount];
  2523. // The offset is to a DxilPartHeader.
  2524. };
  2525. Each part has a standard header, followed by a part-specify body::
  2526. struct DxilPartHeader {
  2527. uint32_t PartFourCC; // Four char code for part type.
  2528. uint32_t PartSize; // Byte count for PartData.
  2529. // Structure is followed by uint8_t PartData[PartSize].
  2530. };
  2531. The DXIL program is found in a part with the following body::
  2532. struct DxilProgramHeader {
  2533. uint32_t ProgramVersion; /// Major and minor version of shader, including type.
  2534. uint32_t SizeInUint32; /// Size in uint32_t units including this header.
  2535. uint32_t DxilMagic; // 0x4C495844, ASCII "DXIL".
  2536. uint32_t DxilVersion; // DXIL version.
  2537. uint32_t BitcodeOffset; // Offset to LLVM bitcode (from DxilMagic).
  2538. uint32_t BitcodeSize; // Size of LLVM bitcode.
  2539. // Followed by uint8_t[BitcodeHeader.BitcodeSize] after possible gap from BitcodeOffset
  2540. };
  2541. The bitcode payload is defined as per bitcode encoding.
  2542. Future Directions
  2543. -----------------
  2544. This section provides background on future directions for DXIL that may or may not materialize. They imply a new version of DXIL.
  2545. It's desirable to support generic pointers, pointing to one of other kinds of pointers. If the compiler fails to disambiguate, memory access is done via a generic pointer; the HLSL compiler will warn the user about each access that it cannot disambiguate. Not supported for SM6.
  2546. HLSL will eventually support more primitive types such as i8, i16, i32, i64, half, float, double, as well as declspec(align(n)) and #pragma pack(n) directives. SM6.0 will eventually require byte-granularity access support in hardware, especially writes. Not supported for SM6.
  2547. There will be a Requires32BitAlignedAccesses CAP flag. If absent, this would indicate that the shader requires writes that (1) do not write full four bytes, or (2) are not aligned on four-byte boundary. If hardware does not natively support these, the shader is rejected. Programmers can work around this hardware limitation by manually aligning smaller data on four-byte boundary in HLSL.
  2548. When libraries are supported as first-class DXIL constructs, "lib_*" shader models can specify more than one entry point per module; the other shader models must specify exactly one entry point.
  2549. The target machine specification for HLSL might specify a 64-bit pointer side with 64-bit offsets.
  2550. Hardware support for generic pointer is essential for HLSL next as a fallback mechanism for cases when compiler cannot disambiguate pointer's address space.
  2551. Future DXIL will change how half and i16 are treated:
  2552. * i16 will have to be supported natively either in hardware or via emulation,
  2553. * half's behavior will depend on the value of RequiresHardwareHalf CAP; if it's not set, half can be treated as min-precision type (min16float); i.e., computation may be done with values implicitly promoted to floats; if it's set and hardware does not support half type natively, the driver compiler can either emulate exact IEEE half behavior or fail shader creation.
  2554. Pending Specification Work
  2555. ==========================
  2556. The following work on this specification is still pending:
  2557. * Consider moving some additional tables and lists into hctdb and cross-reference.
  2558. * Complete the extended documentation for instructions.