DXIL.rst 163 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070
  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. ==================== ===================================== ===========
  80. The DXIL verifier ensures that DXIL conforms to the specified shader model.
  81. 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.
  82. DXIL version
  83. ------------
  84. 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.
  85. DXIL version has major and minor versions that are specified as named metadata::
  86. !dx.version = !{ !0 }
  87. !0 = !{ i32 <major>, i32 <minor> }
  88. DXIL version must be declared exactly once per LLVM module (translation unit) and is valid for the entire module.
  89. DXIL will evolve in a manner that retains backward compatibility.
  90. DXIL 1.1 Changes
  91. ----------------
  92. 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.
  93. * New Intrinsics - AttributeAtVertex_, ViewID
  94. * New Systen Generated Value - SV_Barycentrics
  95. * New Container Part - ILDN
  96. DXIL 1.2 Changes
  97. ----------------
  98. * New format for type-annotations_ for functions to indicate floating point operations behavior for per function basis.
  99. LLVM Bitcode version
  100. --------------------
  101. The current version of DXIL is based on LLVM bitcode v3.7. This encoding is necessarily implied by something outside the DXIL module.
  102. General Issues
  103. ==============
  104. 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.
  105. Terminology
  106. -----------
  107. Resource refers to one of the following:
  108. * SRV - shader resource view (read-only)
  109. * UAV - unordered access view (read-write)
  110. * CBV - constant buffer view (read-only)
  111. * Sampler
  112. 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.
  113. DXIL abstraction level
  114. ----------------------
  115. 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.
  116. In particular, the following passes are performed to lower the HLSL/DXIR abstractions down to DXIL:
  117. * optimize function parameter copies
  118. * inline functions
  119. * allocate and transform shader signatures
  120. * lower matrices, optimizing intermediate storage
  121. * linearize multi-dimensional arrays and user-defined type accesses
  122. * scalarize vectors
  123. Scalar IR
  124. ---------
  125. 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.
  126. Metadata, resource declarations, and debugging info may contain vectors to more closely convey source code shape to tools and debuggers.
  127. Future versions of IR may contain vectors or grouping hints for less-than-32-bit quantities, such as half and i16.
  128. Memory accesses
  129. ---------------
  130. DXIL conceptually aligns with DXBC in how different memory types are accessed. Out-of-bounds behavior and various restrictions are preserved.
  131. Indexable thread-local and groupshared variables are represented as variables and accessed via LLVM C-like pointers.
  132. Swizzled resources, such as textures, have opaque memory layouts from a DXIL point of view. Accesses to these resources are done via intrinsics.
  133. 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.
  134. 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.
  135. 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.
  136. The following pointer types are supported:
  137. * Non-indexable thread-local variables.
  138. * Indexable thread-local variables (DXBC x-registers).
  139. * Groupshared variables (DXBC g-registers).
  140. * Device memory pointer.
  141. * Constant-buffer-like memory pointer.
  142. 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.
  143. A pointer can come into being in a number of ways:
  144. * Global Variables.
  145. * AllocaInst.
  146. * Synthesized as a result of some pointer arithmetic.
  147. DXIL uses 32-bit pointers in its representation.
  148. Out-of-bounds behavior
  149. ----------------------
  150. Indexable thread-local accesses are done via LLVM pointer and have C-like OOB semantics.
  151. Groupshared accesses are done via LLVM pointer too. The origin of a groupshared pointer must be a single TGSM allocation.
  152. 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.
  153. For groupshared pointer from regular GEP, OOB will has same behavior as DXBC. Loads return 0 for OOB accesses; OOB stores are silently dropped.
  154. Resource accesses keeps the same out-of-bounds behavior as DXBC. Loads return 0 for OOB accesses; OOB stores are silently dropped.
  155. 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.
  156. Memory access granularity
  157. -------------------------
  158. 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).
  159. Number of virtual values
  160. ------------------------
  161. 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.
  162. Control-flow restrictions
  163. -------------------------
  164. 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.
  165. DXIL allows fall-through for switch label blocks. This is a difference from DXBC, in which the fall-through is prohibited.
  166. 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.
  167. Functions
  168. ---------
  169. Instead of DXBC labels/calls, DXIL supports functions and call instructions. Recursion is not allowed; DXIL validator enforces this.
  170. 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.
  171. Identifiers
  172. -----------
  173. DXIL identifiers must conform to LLVM IR identifier rules.
  174. Identifier mangling rules are the ones used by Clang 3.7 with the HLSL target.
  175. The following identifier prefixes are reserved:
  176. * dx.*, dxil.*, dxir.*
  177. * llvm.dx.*, llvm.dxil.*, llvm.dxir.*
  178. Address Width
  179. -------------
  180. DXIL will use only 32-bit addresses for pointers. Byte offsets are also 32-bit.
  181. Shader restrictions
  182. -------------------
  183. There is no support for the following in DXIL:
  184. * recursion
  185. * exceptions
  186. * indirect function calls and dynamic dispatch
  187. Entry points
  188. ------------
  189. 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.
  190. For example::
  191. define void @"\01?myfunc1@@YAXXZ"() #0 { ... }
  192. define float @"\01?myfunc2@@YAMXZ"() #0 { ... }
  193. !dx.entryPoints = !{ !1, !2 }
  194. !1 = !{ void ()* @"\01?myfunc1@@YAXXZ", !"myfunc1", !3, null, null }
  195. !2 = !{ float ()* @"\01?myfunc2@@YAMXZ", !"myfunc2", !5, !6, !7 }
  196. Each entry point metadata record specifies:
  197. * reference to the entry point function global symbol
  198. * unmangled name
  199. * list of signatures
  200. * list of resources
  201. * list of tag-value pairs of shader capabilities and other properties
  202. A 'null' value specifies absence of a particular node.
  203. 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.
  204. Hull shader representation
  205. --------------------------
  206. 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.
  207. For example::
  208. !dx.entryPoints = !{ !1 }
  209. !1 = !{ void ()* @"ControlPointFunc", ..., !2 } ; shader entry record
  210. !2 = !{ !"HS", !3 }
  211. !3 = !{ void ()* @"PatchConstFunc", ... } ; additional hull shader state
  212. 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.
  213. 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.
  214. 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.
  215. =================== ==================== ====================== ======================
  216. Operation Control Point (Hull) Patch Constant Domain
  217. =================== ==================== ====================== ======================
  218. Store Input CP
  219. Load Input CP LoadInput LoadInput
  220. Store Output CP StoreOutput
  221. Load Output CP LoadOutputControlPoint LoadInput
  222. Store PC StorePatchConstant
  223. Load PC LoadPatchConstant LoadPatchConstant
  224. Store Output Vertex StoreOutput
  225. =================== ==================== ====================== ======================
  226. 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.
  227. Type System
  228. ===========
  229. Most of LLVM type system constructs are legal in DXIL.
  230. Primitive Types
  231. ---------------
  232. The following types are supported:
  233. * void
  234. * metadata
  235. * i1, i8, i16, i32, i64
  236. * half, float, double
  237. SM6.0 assumes native hardware support for i32 and float types.
  238. 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.
  239. HLSL min12int, min16int and min16uint data types are mapped to i16.
  240. half and i16 are treated as corresponding DXBC min-presicion types (min16float, min16int/min16uint) in SM6.0.
  241. 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.
  242. Hardware support for doubles in optional and is guarded by RequiresHardwareDouble CAP bit.
  243. Hardware support for i64 is optional and is guarded by a CAP bit.
  244. Vectors
  245. -------
  246. 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.
  247. Future DXIL may add support for <2 x half> and <2 x i16> vectors or hints for packing related half and i16 quantities.
  248. Matrices
  249. --------
  250. 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.
  251. Arrays
  252. ------
  253. 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.
  254. User-defined types
  255. ------------------
  256. 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.
  257. Type conversions
  258. ----------------
  259. Explicit conversions between types are supported via LLVM instructions.
  260. Precise qualifier
  261. -----------------
  262. 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.
  263. 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.
  264. 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.
  265. .. _type-annotations:
  266. Type annotations
  267. ----------------
  268. 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::
  269. namespace MyNameSpace {
  270. struct MyType {
  271. float field1;
  272. int2 field2;
  273. };
  274. }
  275. float main(float col : COLOR) : SV_Target {
  276. .....
  277. }
  278. !dx.typeAnnotations = !{!3, !7}
  279. !3 = !{i32 0, %"struct.MyNameSpace::MyType" undef, !4}
  280. !4 = !{i32 12, !5, !6}
  281. !5 = !{i32 6, !"field1", i32 3, i32 0, i32 7, i32 9}
  282. !6 = !{i32 6, !"field2", i32 3, i32 4, i32 7, i32 4}
  283. !7 = !{i32 1, void (float, float*)* @"main", !8}
  284. !8 = !{!9, !11, !14}
  285. !9 = !{i32 0, !10, !10}
  286. !10 = !{}
  287. !11 = !{i32 0, !12, !13}
  288. !12 = !{i32 4, !"COLOR", i32 7, i32 9}
  289. !13 = !{i32 0}
  290. !14 = !{i32 1, !15, !13}
  291. !15 = !{i32 4, !"SV_Target", i32 7, i32 9}
  292. !16 = !{null, !"lib.no::entry", null, null, null}
  293. The type/field annotation metadata hierarchy recursively mimics LLVM type hierarchy.
  294. dx.typeAnnotations is a metadata of type annotation nodes, where each node represents type annotation of a certain type::
  295. !dx.typeAnnotations = !{!3, !7}
  296. For each **type annotation** node, the first value represents the type of the annotation::
  297. !3 = !{i32 0, %"struct.MyNameSpace::MyType" undef, !4}
  298. !7 = !{i32 1, void (float, float*)* @"main", !8}
  299. === =====================================================================
  300. Idx Type
  301. === =====================================================================
  302. 0 Structure Annotation
  303. 1 Function Annotation
  304. 2 Function Annotation2 (Not available before DXIL 1.2)
  305. === =====================================================================
  306. The second value represents the name, the third is a corresponding type metadata node.
  307. **Structure Annotation** starts with the size of the structure in bytes, followed by the list of field annotations::
  308. !4 = !{i32 12, !5, !6}
  309. !5 = !{i32 6, !"field1", i32 3, i32 0, i32 7, i32 9}
  310. !6 = !{i32 6, !"field2", i32 3, i32 4, i32 7, i32 4}
  311. **Field Annotation** is a series of pairs with tag number followed by its value. Field Annotation pair is defined as follows
  312. === =====================================================================
  313. Idx Type
  314. === =====================================================================
  315. 0 SNorm
  316. 1 UNorm
  317. 2 Matrix
  318. 3 Buffer Offset
  319. 4 Semantic String
  320. 5 Interpolation Mode
  321. 6 Field Name
  322. 7 Component Type
  323. 8 Precise
  324. === =====================================================================
  325. **Function Annotation** is a series of parameter annotations::
  326. !7 = !{i32 1, void (float, float*)* @"main", !8}
  327. !8 = !{!9, !11, !14}
  328. Each **Parameter Annotation** contains Input/Output type, field annotation, and semantic index::
  329. !9 = !{i32 0, !10, !10}
  330. !10 = !{}
  331. !11 = !{i32 0, !12, !13}
  332. !12 = !{i32 4, !"COLOR", i32 7, i32 9}
  333. !13 = !{i32 0}
  334. !14 = !{i32 1, !15, !13}
  335. !15 = !{i32 4, !"SV_Target", i32 7, i32 9}
  336. **DXIL 1.2 Change**
  337. Prior to DXIL 1.2, function annotations metadata only contained a list of parameter annotations, starting with the input parameter
  338. For DXIL 1.2, **function annotation** will contain FunctionFPFlag, followed by parameter annotations::
  339. !7 = !{i32 2, void (float, float*)* @"main", !8}
  340. !8 = !{!9, !10}
  341. !9 = !{i32 0}
  342. !10 = !{!11, !13, !15}
  343. FunctionFPFlag is a flag to control the behavior of the floating point operation::
  344. !9 = !{i32 0}
  345. Currently three values are valid for floating point flag
  346. * 0: FP32 math operations on denorm may or may not flush to zero
  347. * 1: FP32 math operations perserve Denorms
  348. * 2: FP32 math operations flush denormal output numbers to zero
  349. For operations on FP16/FP64 denormal numbers will preserve denormal numbers.
  350. Shader Properties and Capabilities
  351. ==================================
  352. Additional shader properties are specified via tag-value pair list, which is the last element in the entry function description record.
  353. Shader Flags
  354. ------------
  355. 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:
  356. === =====================================================================
  357. Bit Description
  358. === =====================================================================
  359. 0 Disable shader optimizations
  360. 1 Disable math refactoring
  361. 2 Shader uses doubles
  362. 3 Force early depth stencil
  363. 4 Enable raw and structured buffers
  364. 5 Shader uses min-precision, expressed as half and i16
  365. 6 Shader uses double extension intrinsics
  366. 7 Shader uses MSAD
  367. 8 All resources must be bound for the duration of shader execution
  368. 9 Enable view port and RT array index from any stage feeding rasterizer
  369. 10 Shader uses inner coverage
  370. 11 Shader uses stencil
  371. 12 Shader uses intrinsics that access tiled resources
  372. 13 Shader uses relaxed typed UAV load formats
  373. 14 Shader uses Level9 comparison filtering
  374. 15 Shader uses up to 64 UAVs
  375. 16 Shader uses UAVs
  376. 17 Shader uses CS4 raw and structured buffers
  377. 18 Shader uses Rasterizer Ordered Views
  378. 19 Shader uses wave intrinsics
  379. 20 Shader uses int64 instructions
  380. === =====================================================================
  381. Geometry Shader
  382. ---------------
  383. 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.
  384. === ==== ===============================================================
  385. Idx Type Description
  386. === ==== ===============================================================
  387. 0 i32 Input primitive (InputPrimitive enum value).
  388. 1 i32 Max vertex count.
  389. 2 i32 Primitive topology for stream 0 (PrimitiveTopology enum value).
  390. 3 i32 Primitive topology for stream 1 (PrimitiveTopology enum value).
  391. 4 i32 Primitive topology for stream 2 (PrimitiveTopology enum value).
  392. 5 i32 Primitive topology for stream 3 (PrimitiveTopology enum value).
  393. === ==== ===============================================================
  394. Domain Shader
  395. -------------
  396. 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.
  397. === ==== ===============================================================
  398. Idx Type Description
  399. === ==== ===============================================================
  400. 0 i32 Tessellator domain (TessellatorDomain enum value).
  401. 1 i32 Input control point count.
  402. === ==== ===============================================================
  403. Hull Shader
  404. -----------
  405. 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.
  406. === ======= =====================================================================
  407. Idx Type Description
  408. === ======= =====================================================================
  409. 0 MDValue Patch constant function (global symbol).
  410. 1 i32 Input control point count.
  411. 2 i32 Output control point count.
  412. 3 i32 Tessellator domain (TessellatorDomain enum value).
  413. 4 i32 Tessellator partitioning (TessellatorPartitioning enum value).
  414. 5 i32 Tessellator output primitive (TessellatorOutputPrimitive enum value).
  415. 6 float Max tessellation factor.
  416. === ======= =====================================================================
  417. Compute Shader
  418. --------------
  419. Compute shader has the following tag-value properties.
  420. ===================== ======================== =============================================
  421. Tag Value Description
  422. ===================== ======================== =============================================
  423. kDxilNumThreadsTag(4) MD list: (i32, i32, i32) Number of threads (X,Y,Z) for compute shader.
  424. ===================== ======================== =============================================
  425. Shader Parameters and Signatures
  426. ================================
  427. This section formalizes how HLSL shader input and output parameters are expressed in DXIL.
  428. HLSL signatures and semantics
  429. -----------------------------
  430. 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.
  431. 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.
  432. 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.
  433. 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.
  434. 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.
  435. 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.
  436. 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.
  437. Signature Points are enumerated as follows in the SigPointKind
  438. .. <py>import hctdb_instrhelp</py>
  439. .. <py::lines('SIGPOINT-RST')>hctdb_instrhelp.get_sigpoint_rst()</py>
  440. .. SIGPOINT-RST:BEGIN
  441. == ======== ======= ========== ============== ============= ============================================================================
  442. ID SigPoint Related ShaderKind PackingKind SignatureKind Description
  443. == ======== ======= ========== ============== ============= ============================================================================
  444. 0 VSIn Invalid Vertex InputAssembler Input Ordinary Vertex Shader input from Input Assembler
  445. 1 VSOut Invalid Vertex Vertex Output Ordinary Vertex Shader output that may feed Rasterizer
  446. 2 PCIn HSCPIn Hull None Invalid Patch Constant function non-patch inputs
  447. 3 HSIn HSCPIn Hull None Invalid Hull Shader function non-patch inputs
  448. 4 HSCPIn Invalid Hull Vertex Input Hull Shader patch inputs - Control Points
  449. 5 HSCPOut Invalid Hull Vertex Output Hull Shader function output - Control Point
  450. 6 PCOut Invalid Hull PatchConstant PatchConstant Patch Constant function output - Patch Constant data passed to Domain Shader
  451. 7 DSIn Invalid Domain PatchConstant PatchConstant Domain Shader regular input - Patch Constant data plus system values
  452. 8 DSCPIn Invalid Domain Vertex Input Domain Shader patch input - Control Points
  453. 9 DSOut Invalid Domain Vertex Output Domain Shader output - vertex data that may feed Rasterizer
  454. 10 GSVIn Invalid Geometry Vertex Input Geometry Shader vertex input - qualified with primitive type
  455. 11 GSIn GSVIn Geometry None Invalid Geometry Shader non-vertex inputs (system values)
  456. 12 GSOut Invalid Geometry Vertex Output Geometry Shader output - vertex data that may feed Rasterizer
  457. 13 PSIn Invalid Pixel Vertex Input Pixel Shader input
  458. 14 PSOut Invalid Pixel Target Output Pixel Shader output
  459. 15 CSIn Invalid Compute None Invalid Compute Shader input
  460. == ======== ======= ========== ============== ============= ============================================================================
  461. .. SIGPOINT-RST:END
  462. Semantic Interpretations are as follows (SemanticInterpretationKind)
  463. .. <py>import hctdb_instrhelp</py>
  464. .. <py::lines('SEMINT-RST')>hctdb_instrhelp.get_sem_interpretation_enum_rst()</py>
  465. .. SEMINT-RST:BEGIN
  466. == ========== =============================================================
  467. ID Name Description
  468. == ========== =============================================================
  469. 0 NA Not Available
  470. 1 SV Normal System Value
  471. 2 SGV System Generated Value (sorted last)
  472. 3 Arb Treated as Arbitrary
  473. 4 NotInSig Not included in signature (intrinsic access)
  474. 5 NotPacked Included in signature, but does not contribute to packing
  475. 6 Target Special handling for SV_Target
  476. 7 TessFactor Special handling for tessellation factors
  477. 8 Shadow Shadow element must be added to a signature for compatibility
  478. == ========== =============================================================
  479. .. SEMINT-RST:END
  480. Semantic Interpretations for each SemanticKind at each SigPointKind are as follows
  481. .. <py>import hctdb_instrhelp</py>
  482. .. <py::lines('SEMINT-TABLE-RST')>hctdb_instrhelp.get_sem_interpretation_table_rst()</py>
  483. .. SEMINT-TABLE-RST:BEGIN
  484. ====================== ============ ===== ============ ============ ====== ======= ========== ============ ====== ===== ===== ============ ===== ============= ============= ========
  485. Semantic VSIn VSOut PCIn HSIn HSCPIn HSCPOut PCOut DSIn DSCPIn DSOut GSVIn GSIn GSOut PSIn PSOut CSIn
  486. ====================== ============ ===== ============ ============ ====== ======= ========== ============ ====== ===== ===== ============ ===== ============= ============= ========
  487. Arbitrary Arb Arb NA NA Arb Arb Arb Arb Arb Arb Arb NA Arb Arb NA NA
  488. VertexID SV NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
  489. InstanceID SV Arb NA NA Arb Arb NA NA Arb Arb Arb NA Arb Arb NA NA
  490. Position Arb SV NA NA SV SV Arb Arb SV SV SV NA SV SV NA NA
  491. RenderTargetArrayIndex Arb SV NA NA SV SV Arb Arb SV SV SV NA SV SV NA NA
  492. ViewPortArrayIndex Arb SV NA NA SV SV Arb Arb SV SV SV NA SV SV NA NA
  493. ClipDistance Arb SV NA NA SV SV Arb Arb SV SV SV NA SV SV NA NA
  494. CullDistance Arb SV NA NA SV SV Arb Arb SV SV SV NA SV SV NA NA
  495. OutputControlPointID NA NA NA NotInSig NA NA NA NA NA NA NA NA NA NA NA NA
  496. DomainLocation NA NA NA NA NA NA NA NotInSig NA NA NA NA NA NA NA NA
  497. PrimitiveID NA NA NotInSig NotInSig NA NA NA NotInSig NA NA NA Shadow SGV SGV NA NA
  498. GSInstanceID NA NA NA NA NA NA NA NA NA NA NA NotInSig NA NA NA NA
  499. SampleIndex NA NA NA NA NA NA NA NA NA NA NA NA NA Shadow _41 NA NA
  500. IsFrontFace NA NA NA NA NA NA NA NA NA NA NA NA SGV SGV NA NA
  501. Coverage NA NA NA NA NA NA NA NA NA NA NA NA NA NotInSig _50 NotPacked _41 NA
  502. InnerCoverage NA NA NA NA NA NA NA NA NA NA NA NA NA NotInSig _50 NA NA
  503. Target NA NA NA NA NA NA NA NA NA NA NA NA NA NA Target NA
  504. Depth NA NA NA NA NA NA NA NA NA NA NA NA NA NA NotPacked NA
  505. DepthLessEqual NA NA NA NA NA NA NA NA NA NA NA NA NA NA NotPacked _50 NA
  506. DepthGreaterEqual NA NA NA NA NA NA NA NA NA NA NA NA NA NA NotPacked _50 NA
  507. StencilRef NA NA NA NA NA NA NA NA NA NA NA NA NA NA NotPacked _50 NA
  508. DispatchThreadID NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NotInSig
  509. GroupID NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NotInSig
  510. GroupIndex NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NotInSig
  511. GroupThreadID NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NotInSig
  512. TessFactor NA NA NA NA NA NA TessFactor TessFactor NA NA NA NA NA NA NA NA
  513. InsideTessFactor NA NA NA NA NA NA TessFactor TessFactor NA NA NA NA NA NA NA NA
  514. ViewID NotInSig _61 NA NotInSig _61 NotInSig _61 NA NA NA NotInSig _61 NA NA NA NotInSig _61 NA NotInSig _61 NA NA
  515. Barycentrics NA NA NA NA NA NA NA NA NA NA NA NA NA NotPacked _61 NA NA
  516. ====================== ============ ===== ============ ============ ====== ======= ========== ============ ====== ===== ===== ============ ===== ============= ============= ========
  517. .. SEMINT-TABLE-RST:END
  518. Below is a vertex shader example that is used for illustration throughout this section::
  519. struct Foo {
  520. float a;
  521. float b[2];
  522. };
  523. struct VSIn {
  524. uint vid : SV_VertexID;
  525. float3 pos : Position;
  526. Foo foo[3] : SemIn1;
  527. float f : SemIn10;
  528. };
  529. struct VSOut
  530. {
  531. float f : SemOut1;
  532. Foo foo[3] : SemOut2;
  533. float4 pos : SV_Position;
  534. };
  535. void main(in VSIn In, // input signature
  536. out VSOut Out) // output signature
  537. {
  538. ...
  539. }
  540. 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.
  541. 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.
  542. Signature element record
  543. ------------------------
  544. Each signature element is represented in DXIL as a metadata record.
  545. For above example output signature, the element records are as follows::
  546. ; element ID, semantic name, etype, sv, s.idx, interp, rows, cols, start row, col, ext. list
  547. !20 = !{i32 6, !"SemOut", i8 0, i8 0, !40, i8 2, i32 1, i8 1, i32 1, i8 2, null}
  548. !21 = !{i32 7, !"SemOut", i8 0, i8 0, !41, i8 2, i32 3, i8 1, i32 1, i8 1, null}
  549. !22 = !{i32 8, !"SemOut", i8 0, i8 0, !42, i8 2, i32 6, i8 1, i32 1, i8 0, null}
  550. !23 = !{i32 9, !"SV_Position", i8 0, i8 3, !43, i8 2, i32 1, i8 4, i32 0, i8 0, null}
  551. A record contains the following fields.
  552. === =============== ===============================================================================
  553. Idx Type Description
  554. === =============== ===============================================================================
  555. 0 i32 Unique signature element record ID, used to identify the element in operations.
  556. 1 String metadata Semantic name.
  557. 2 i8 ComponentType (enum value).
  558. 3 i8 SemanticKind (enum value).
  559. 4 Metadata Metadata list that enumerates all semantic indexes of the flattened parameter.
  560. 5 i8 InterpolationMode (enum value).
  561. 6 i32 Number of element rows.
  562. 7 i8 Number of element columns.
  563. 8 i32 Starting row of element packing location.
  564. 9 i8 Starting column of element packing location.
  565. 10 Metadata Metadata list of additional tag-value pairs; can be 'null' or empty.
  566. === =============== ===============================================================================
  567. 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.
  568. The last metadata list is used to specify additional properties and future extensions.
  569. Signature record metadata
  570. -------------------------
  571. 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.
  572. Vertex shader HLSL
  573. ~~~~~~~~~~~~~~~~~~
  574. Here is the HLSL of the above vertex shader. The semantic index assignment is explained in section below::
  575. struct Foo
  576. {
  577. float a;
  578. float b[2];
  579. };
  580. struct VSIn
  581. {
  582. uint vid : SV_VertexID;
  583. float3 pos : Position;
  584. Foo foo[3] : SemIn1;
  585. // semantic index assignment:
  586. // foo[0].a : SemIn1
  587. // foo[0].b[0] : SemIn2
  588. // foo[0].b[1] : SemIn3
  589. // foo[1].a : SemIn4
  590. // foo[1].b[0] : SemIn5
  591. // foo[1].b[1] : SemIn6
  592. // foo[2].a : SemIn7
  593. // foo[2].b[0] : SemIn8
  594. // foo[2].b[1] : SemIn9
  595. float f : SemIn10;
  596. };
  597. struct VSOut
  598. {
  599. float f : SemOut1;
  600. Foo foo[3] : SemOut2;
  601. // semantic index assignment:
  602. // foo[0].a : SemOut2
  603. // foo[0].b[0] : SemOut3
  604. // foo[0].b[1] : SemOut4
  605. // foo[1].a : SemOut5
  606. // foo[1].b[0] : SemOut6
  607. // foo[1].b[1] : SemOut7
  608. // foo[2].a : SemOut8
  609. // foo[2].b[0] : SemOut9
  610. // foo[2].b[1] : SemOut10
  611. float4 pos : SV_Position;
  612. };
  613. void main(in VSIn In, // input signature
  614. out VSOut Out) // output signature
  615. {
  616. ...
  617. }
  618. 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:
  619. =================== ==== ======= ========= ===========
  620. Input element Rows Columns Start row Start column
  621. =================== ==== ======= ========= ===========
  622. uint VSIn.vid 1 1 0 0
  623. float3 VSIn.pos 1 3 1 0
  624. float VSIn.foo.a[3] 3 1 2 0
  625. float VSIn.foo.b[6] 6 1 5 0
  626. float VSIn.f 1 1 11 0
  627. =================== ==== ======= ========= ===========
  628. A reasonable packing algorithm would assign the following starting positions to the output signature elements:
  629. ==================== ==== ======= ========= ===========
  630. Input element Rows Columns Start row Start column
  631. ==================== ==== ======= ========= ===========
  632. uint VSOut.f 1 1 1 2
  633. float VSOut.foo.a[3] 3 1 1 1
  634. float VSOut.foo.b[6] 6 1 1 0
  635. float VSOut.pos 1 4 0 0
  636. ==================== ==== ======= ========= ===========
  637. Semantic index assignment
  638. ~~~~~~~~~~~~~~~~~~~~~~~~~
  639. 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.
  640. DXIL for VS signatures
  641. ~~~~~~~~~~~~~~~~~~~~~~
  642. The corresponding DXIL metadata is presented below::
  643. !dx.entryPoints = !{ !1 }
  644. !1 = !{ void @main(), !"main", !2, null, null }
  645. ; Signatures: In, Out, Patch Constant (optional)
  646. !2 = !{ !3, !4, null }
  647. ; Input signature (packed accordiong to IA rules)
  648. !3 = !{ !10, !11, !12, !13, !14 }
  649. ; element idx, semantic name, etype, sv, s.idx, interp, rows, cols, start row, col, ext. list
  650. !10 = !{i32 1, !"SV_VertexID", i8 0, i8 1, !30, i32 0, i32 1, i8 1, i32 0, i8 0, null}
  651. !11 = !{i32 2, !"Position", i8 0, i8 0, !30, i32 0, i32 1, i8 3, i32 1, i8 0, null}
  652. !12 = !{i32 3, !"SemIn", i8 0, i8 0, !32, i32 0, i32 3, i8 1, i32 2, i8 0, null}
  653. !13 = !{i32 4, !"SemIn", i8 0, i8 0, !33, i32 0, i32 6, i8 1, i32 5, i8 0, null}
  654. !14 = !{i32 5, !"SemIn", i8 0, i8 0, !34, i32 0, i32 1, i8 1, i32 11, i8 0, null}
  655. ; semantic index assignment:
  656. !30 = !{ i32 0 }
  657. !32 = !{ i32 1, i32 4, i32 7 }
  658. !33 = !{ i32 2, i32 3, i32 5, i32 6, i32 8, i32 9 }
  659. !34 = !{ i32 10 }
  660. ; Output signature (tightly packed according to pipeline stage packing rules)
  661. !4 = !{ !20, !21, !22, !23 }
  662. ; element ID, semantic name, etype, sv, s.idx, interp, rows, cols, start row, col, ext. list
  663. !20 = !{i32 6, !"SemOut", i8 0, i8 0, !40, i32 2, i32 1, i8 1, i32 1, i8 2, null}
  664. !21 = !{i32 7, !"SemOut", i8 0, i8 0, !41, i32 2, i32 3, i8 1, i32 1, i8 1, null}
  665. !22 = !{i32 8, !"SemOut", i8 0, i8 0, !42, i32 2, i32 6, i8 1, i32 1, i8 0, null}
  666. !23 = !{i32 9, !"SV_Position", i8 0, i8 3, !43, i32 2, i32 1, i8 4, i32 0, i8 0, null}
  667. ; semantic index assignment:
  668. !40 = !{ i32 1 }
  669. !41 = !{ i32 2, i32 5, i32 8 }
  670. !42 = !{ i32 3, i32 4, i32 6, i32 7, i32 9, i32 10 }
  671. !43 = !{ i32 0 }
  672. Hull shader example
  673. ~~~~~~~~~~~~~~~~~~~
  674. 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.
  675. Here is an HS example entry point metadata and signature list::
  676. ; !105 is extended parameter list containing reference to HS State:
  677. !101 = !{ void @HSMain(), !"HSMain", !102, null, !105 }
  678. ; Signatures: In, Out, Patch Constant
  679. !102 = !{ !103, !104, !204 }
  680. The entry point record specifies: (1) CP function HSMain as the main symbol, and (2) PC function via optional metadata node !105.
  681. CP-input signature describing one input control point::
  682. !103 = !{ !110, !111 }
  683. ; element ID, semantic name, etype, sv, s.idx, interp, rows, cols, start row, col, ext. list
  684. !110= !{i32 1, !"SV_Position", i8 0, i8 3, !130, i32 0, i32 1, i8 4, i32 0, i8 0, null}
  685. !111= !{i32 2, !"array", i8 0, i8 0, !131, i32 0, i32 4, i8 3, i32 1, i8 0, null}
  686. ; semantic indexing for flattened elements:
  687. !130 = !{ i32 0 }
  688. !131 = !{ i32 0, i32 1, i32 2, i32 3 }
  689. 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.
  690. CP-output signature describing one output control point::
  691. !104 = !{ !120, !121 }
  692. ; element ID, semantic name, etype, sv, s.idx, interp, rows, cols, start row, col, ext. list
  693. !120= !{i32 3, !"SV_Position", i8 0, i8 3, !130, i32 0, i32 1, i8 4, i32 0, i8 0, null}
  694. !121= !{i32 4, !"array", i8 0, i8 0, !131, i32 0, i32 4, i8 3, i32 1, i8 0, null}
  695. Hull shaders require an extended parameter that defines extra state::
  696. ; extended parameter HS State
  697. !105 = !{ i32 3, !201 }
  698. ; HS State record defines patch constant function and other properties
  699. ; Patch Constant Function, in CP count, out CP count, tess domain, tess part, out prim, max tess factor
  700. !201 = !{ void @PCMain(), 4, 4, 3, 1, 3, 16.0 }
  701. PC-output signature::
  702. !204 = !{ !220, !221, !222 }
  703. ; element ID, semantic name, etype, sv, s.idx, interp, rows, cols, start row, col, ext. list
  704. !220= !{i32 3, !"SV_TessFactor", i8 0, i8 25, !130, i32 0, i32 4, i8 1, i32 0, i8 3, null}
  705. !221= !{i32 4, !"SV_InsideTessFactor", i8 0, i8 26, !231, i32 0, i32 2, i8 1, i32 4, i8 3, null}
  706. !222= !{i32 5, !"array", i8 0, i8 0, !131, i32 0, i32 4, i8 3, i32 0, i8 0, null}
  707. ; semantic indexing for flattened elements:
  708. !231 = !{ i32 0, i32 1 }
  709. Accessing signature value in operations
  710. ---------------------------------------
  711. 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.
  712. These are the operation signatures::
  713. ; overloads: SM5.1: f16|f32|i16|i32, SM6.0: f16|f32|f64|i8|i16|i32|i64
  714. declare float @dx.op.loadInput.f32(
  715. i32, ; opcode
  716. i32, ; input ID
  717. i32, ; row (relative to start row of input ID)
  718. i8, ; column (relative to start column of input ID), constant in [0,3]
  719. i32) ; vertex index
  720. ; overloads: SM5.1: f16|f32|i16|i32, SM6.0: f16|f32|f64|i8|i16|i32|i64
  721. declare void @dx.op.storeOutput.f32(
  722. i32, ; opcode
  723. i32, ; output ID
  724. i32, ; row (relative to start row of output ID)
  725. i8, ; column (relative to start column of output ID), constant in [0,3]
  726. float) ; value to store
  727. 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.
  728. Signature packing
  729. -----------------
  730. 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.
  731. Signature packing types
  732. ~~~~~~~~~~~~~~~~~~~~~~~
  733. Two pipeline stages can connect in four different ways, resulting in four packing types.
  734. 1. Input Assembly: VS input only
  735. * Elements all map to unique registers, they may not be packed together.
  736. * Interpolation mode is not used.
  737. 2. Connects to Rasterizer: VS output, HS CP-input/output and PC-input, DS CP-input/output, GS input/output, PS input
  738. * Elements can be packed according to constraints.
  739. * Interpolation mode is used and must be consistent between connecting signatures.
  740. * 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.
  741. 3. Patch Constant: HS PC-output, DS PC-input
  742. * 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.
  743. * Interpolation mode is not used.
  744. 4. Pixel Shader Output: PS output only
  745. * Only SV_Target maps to output register space.
  746. * No packing is performed, semantic index corresponds to render target index.
  747. Packing constraints
  748. ~~~~~~~~~~~~~~~~~~~
  749. 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.
  750. 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.
  751. Packing constraints are as follows:
  752. 1. A register must have only one interpolation mode for all 4 components.
  753. 2. Register components containing SVs must be to the right of components containing non-SVs.
  754. 3. SV_ClipDistance and SV_CullDistance have additional constraints:
  755. a. May be packed together
  756. b. Must occupy a maximum of 2 registers (8-components)
  757. c. SV_ClipDistance must have linear interpolation mode
  758. 4. Registers containing SVs may not be within an index range, with the exception of Tessellation Factors (TessFactors).
  759. 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.
  760. 6. Non-TessFactor index ranges are combined into a larger range, if they overlap.
  761. 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.
  762. Packing for SGVs
  763. ~~~~~~~~~~~~~~~~
  764. 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.
  765. 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.
  766. 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.
  767. Shader Resources
  768. ================
  769. 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::
  770. !dx.resources = !{ !1, !2, !3, !4 }
  771. Resource lists are as follows.
  772. === ======== ==============================
  773. Idx Type Description
  774. === ======== ==============================
  775. 0 Metadata SRVs - shader resource views.
  776. 1 Metadata UAVs - unordered access views.
  777. 2 Metadata CBVs - constant buffer views.
  778. 3 Metadata Samplers.
  779. === ======== ==============================
  780. Metadata resource records
  781. -------------------------
  782. 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.
  783. Common fields:
  784. === =============== ==========================================================================================
  785. Idx Type Description
  786. === =============== ==========================================================================================
  787. 0 i32 Unique resource record ID, used to identify the resource record in createHandle operation.
  788. 1 Pointer Pointer to a global constant symbol with the original shape of resource and element type.
  789. 2 Metadata string Name of resource variable.
  790. 3 i32 Bind space ID of the root signature range that corresponds to this resource.
  791. 4 i32 Bind lower bound of the root signature range that corresponds to this resource.
  792. 5 i32 Range size of the root signature range that corresponds to this resource.
  793. === =============== ==========================================================================================
  794. When the shader has reflection information, the name is the original, unmangled HLSL name. If reflection is stripped, the name is empty string.
  795. SRV-specific fields:
  796. === =============== ==========================================================================================
  797. Idx Type Description
  798. === =============== ==========================================================================================
  799. 6 i32 SRV resource shape (enum value).
  800. 7 i32 SRV sample count.
  801. 8 Metadata Metadata list of additional tag-value pairs.
  802. === =============== ==========================================================================================
  803. SRV-specific tag/value pairs:
  804. === === ==== =================================================== ============================================
  805. Idx Tag Type Resource Type Description
  806. === === ==== =================================================== ============================================
  807. 0 0 i32 Any resource, except RawBuffer and StructuredBuffer Element type.
  808. 1 1 i32 StructuredBuffer Element stride or StructureBuffer, in bytes.
  809. === === ==== =================================================== ============================================
  810. The symbol names for the are kDxilTypedBufferElementTypeTag (0) and kDxilStructuredBufferElementStrideTag (1).
  811. UAV-specific fields:
  812. === =============== ==========================================================================================
  813. Idx Type Description
  814. === =============== ==========================================================================================
  815. 6 i32 UAV resource shape (enum value).
  816. 7 i1 1 - globally-coherent UAV; 0 - otherwise.
  817. 8 i1 1 - UAV has counter; 0 - otherwise.
  818. 9 i1 1 - UAV is ROV (rasterizer ordered view); 0 - otherwise.
  819. 10 Metadata Metadata list of additional tag-value pairs.
  820. === =============== ==========================================================================================
  821. UAV-specific tag/value pairs:
  822. === === ==== ====================================================== ============================================
  823. Idx Tag Type Resource Type Description
  824. === === ==== ====================================================== ============================================
  825. 0 0 i32 RW resource, except RWRawBuffer and RWStructuredBuffer Element type.
  826. 1 1 i32 RWStructuredBuffer Element stride or StructureBuffer, in bytes.
  827. === === ==== ====================================================== ============================================
  828. The symbol names for the are kDxilTypedBufferElementTypeTag (0) and kDxilStructuredBufferElementStrideTag (1).
  829. CBV-specific fields:
  830. === =============== ==========================================================================================
  831. Idx Type Description
  832. === =============== ==========================================================================================
  833. 6 i32 Constant buffer size in bytes.
  834. 7 Metadata Metadata list of additional tag-value pairs.
  835. === =============== ==========================================================================================
  836. Sampler-specific fields:
  837. === =============== ==========================================================================================
  838. Idx Type Description
  839. === =============== ==========================================================================================
  840. 6 i32 Sampler type (enum value).
  841. 7 Metadata Metadata list of additional tag-value pairs.
  842. === =============== ==========================================================================================
  843. The following example demonstrates SRV metadata::
  844. ; Original HLSL
  845. ; Texture2D<float4> MyTexture2D : register(t0, space0);
  846. ; StructuredBuffer<NS1::MyType1> MyBuffer[2][3] : register(t1, space0);
  847. !1 = !{ !2, !3 }
  848. ; Scalar resource: Texture2D<float4> MyTexture2D.
  849. %dx.types.ResElem.v4f32 = type { <4 x float> }
  850. @MyTexture2D = external addrspace(1) constant %dx.types.ResElem.v4f32, align 16
  851. !2 = !{ i32 0, %dx.types.ResElem.v4f32 addrspace(1)* @MyTexture2D, !"MyTexture2D",
  852. i32 0, i32 0, i32 1, i32 2, i32 0, null }
  853. ; Array resource: StructuredBuffer<MyType1> MyBuffer[2][3].
  854. %struct.NS1.MyType1 = type { float, <2 x i32> }
  855. %dx.types.ResElem.NS1.MyType1 = type { %struct.NS1.MyType1 }
  856. @MyBuffer = external addrspace(1) constant [2x [3 x %dx.types.ResElem.NS1.MyType1]], align 16
  857. !3 = !{ i32 1, [2 x [3 x %dx.types.ResElem.NS1.MyType1]] addrspace(1)* @MyBuffer, !"MyBuffer",
  858. i32 0, i32 1, i32 6, i32 11, i32 0, null }
  859. 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.
  860. Reflection information
  861. ----------------------
  862. 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.
  863. The following disassembly provides an example::
  864. ; Scalar resource: Texture2D<float4> MyTexture2D.
  865. %dx.types.ResElem.v4f32 = type { <4 x float> }
  866. @MyTexture2D = external addrspace(1) constant %dx.types.ResElem.v4f32, align 16
  867. !0 = !{ i32 0, %dx.types.ResElem.v4f32 addrspace(1)* @MyTexture2D, !"MyTexture2D",
  868. i32 0, i32 3, i32 1, i32 2, i32 0, null }
  869. ; struct MyType2 { float4 field1; int2 field2; };
  870. ; Constant buffer: ConstantBuffer<MyType2> MyCBuffer1[][3] : register(b5, space7)
  871. %struct.MyType2 = type { <4 x float>, <2 x i32> }
  872. ; Type reflection information (optional)
  873. !struct.MyType2 = !{ !1, !2 }
  874. !1 = !{ !"field1", null }
  875. !2 = !{ !"field2", null }
  876. %dx.types.ResElem.MyType1 = type { %struct.MyType2 }
  877. @MyCBuffer1 = external addrspace(1) constant [0 x [3 x %dx.types.ResElem.MyType2]], align 16
  878. !3 = !{ i32 0, [0 x [3 x %dx.types.ResElem.MyType1]] addrspace(1)* @MyCBuffer1, !"MyCBuffer1",
  879. i32 7, i32 5, i32 -1, null }
  880. 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.
  881. Structure of resource operation
  882. -------------------------------
  883. Operations involving shader resources and samplers are expressed via external function calls.
  884. Below is an example for the sample method::
  885. %dx.types.ResRet.f32 = type { float, float, float, float, i32 }
  886. declare %dx.types.ResRet.f32 @dx.op.sample.f32(
  887. i32, ; opcode
  888. %dx.types.ResHandle, ; texture handle
  889. %dx.types.SamplerHandle, ; sampler handle
  890. float, ; coordinate c0
  891. float, ; coordinate c1
  892. float, ; coordinate c2
  893. float, ; coordinate c3
  894. i32, ; offset o0
  895. i32, ; offset o1
  896. i32, ; offset o2
  897. float) ; clamp
  898. 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.
  899. If applicable, each intrinsic is overloaded on return type, e.g.::
  900. %dx.types.ResRet.f32 = type { float, float, float, float, i32 }
  901. %dx.types.ResRet.f16 = type { half, half, half, half, i32 }
  902. declare %dx.types.ResRet.f32 @dx.op.sample.f32(...)
  903. declare %dx.types.ResRet.f16 @dx.op.sample.f16(...)
  904. 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.
  905. 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.
  906. 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].
  907. 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.
  908. Both indices can be dynamic for SM6 and later to provide flexibility in usage of resources/samplers in control flow, e.g.::
  909. Texture2D<float4> a[8], b[8];
  910. ...
  911. Texture2D<float4> c;
  912. if(cond) // arbitrary expression
  913. c = a[idx1];
  914. else
  915. c = b[idx2];
  916. ... = c.Sample(...);
  917. 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.
  918. 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::
  919. Texture2D<float4> a[8];
  920. RWTexture2D<float4> b[6];
  921. ...
  922. Texture2D<float4> c;
  923. if(cond) // arbitrary expression
  924. c = a[idx1];
  925. else
  926. c = b[idx2];
  927. ... = c.Load(...);
  928. 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.
  929. If the clamp parameter is unused, its default value is 0.0f.
  930. 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.::
  931. %c0 = fpext half %0 to float
  932. %res = call %dx.types.ResRet.f32 @dx.op.sample.f32(..., %c0, ...)
  933. 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.
  934. Resource operations
  935. -------------------
  936. 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.
  937. Some general rules to interpret resource operations:
  938. * The number of active (meaningful) return components is determined by resource element type. Other return values must be unused; validator ensures this.
  939. * GPU instruction needs status only if the status return value is used in the program, which is determined through SSA.
  940. * Overload suffixes are specified for each resource operation.
  941. * Type of resource determines which inputs must be defined. Unused inputs are passed typed LLVM 'undef' values. This is checked by the DXIL validator.
  942. * Offset input parameters are i8 constants in [-8,+7] range; default offset is 0.
  943. Resource operation return types
  944. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  945. 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.
  946. The defined helper types are listed below::
  947. %dx.types.ResRet.i8 = type { i8, i8, i8, i8, i32 }
  948. %dx.types.ResRet.i16 = type { i16, i16, i16, i16, i32 }
  949. %dx.types.ResRet.i32 = type { i32, i32, i32, i32, i32 }
  950. %dx.types.ResRet.i64 = type { i64, i64, i64, i64, i32 }
  951. %dx.types.ResRet.f16 = type { half, half, half, half, i32 }
  952. %dx.types.ResRet.f32 = type { float, float, float, float, i32 }
  953. %dx.types.ResRet.f64 = type { double, double, double, double, i32 }
  954. %dx.types.Dimensions = type { i32, i32, i32, i32 }
  955. %dx.types.SamplePos = type { float, float }
  956. Resource handles
  957. ~~~~~~~~~~~~~~~~
  958. Resources are identified via handles passed to resource operations. Handles are represented via opaque type::
  959. %dx.types.Handle = type { i8 * }
  960. The handles are created out of resource range ID and index into the range::
  961. declare %dx.types.Handle @dx.op.createHandle(
  962. i32, ; opcode
  963. i8, ; resource class: SRV=0, UAV=1, CBV=2, Sampler=3
  964. i32, ; resource range ID (constant)
  965. i32, ; index into the range
  966. i1) ; non-uniform resource index: false or true
  967. Resource class is a constant that indicates which metadata list (SRV, UAV, CBV, Sampler) to use for property queries.
  968. 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.
  969. Index is an i32 value that may be a constant or a value computed by the shader.
  970. CBufferLoadLegacy
  971. ~~~~~~~~~~~~~~~~~
  972. The following signature shows the operation syntax::
  973. ; overloads: SM5.1: f32|i32|f64, future SM: possibly deprecated
  974. %dx.types.CBufRet.f32 = type { float, float, float, float }
  975. declare %dx.types.CBufRet.f32 @dx.op.cbufferLoadLegacy.f32(
  976. i32, ; opcode
  977. %dx.types.Handle, ; resource handle
  978. i32) ; 0-based row index (row = 16-byte DXBC register)
  979. Valid resource types: ConstantBuffer. Valid shader model: SM5.1 and earlier.
  980. 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.
  981. CBufferLoad
  982. ~~~~~~~~~~~
  983. The following signature shows the operation syntax::
  984. ; overloads: SM5.1: f32|i32|f64, SM6.0: f16|f32|f64|i16|i32|i64
  985. declare float @dx.op.cbufferLoad.f32(
  986. i32, ; opcode
  987. %dx.types.Handle, ; resource handle
  988. i32, ; byte offset from the start of the buffer memory
  989. i32) ; read alignment
  990. Valid resource types: ConstantBuffer.
  991. 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.
  992. 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.
  993. GetDimensions
  994. ~~~~~~~~~~~~~
  995. The following signature shows the operation syntax::
  996. declare %dx.types.Dimensions @dx.op.getDimensions(
  997. i32, ; opcode
  998. %dx.types.Handle, ; resource handle
  999. i32) ; MIP level
  1000. This table describes the return component meanings for each resource type { c0, c1, c2, c3 }.
  1001. ==================== ===== ========== ========== ==========
  1002. Valid resource types c0 c1 c2 c3
  1003. ==================== ===== ========== ========== ==========
  1004. [RW]Texture1D width undef undef MIP levels
  1005. [RW]Texture1DArray width array size undef MIP levels
  1006. [RW]Texture2D width height undef MIP levels
  1007. [RW]Texture2DArray width height array size MIP levels
  1008. [RW]Texture3D width height depth MIP levels
  1009. [RW]Texture2DMS width height undef samples
  1010. [RW]Texture2DMSArray width height array size samples
  1011. TextureCUBE width height undef MIP levels
  1012. TextureCUBEArray width height array size MIP levels
  1013. [RW]TypedBuffer width undef undef undef
  1014. [RW]RawBuffer width undef undef undef
  1015. [RW]StructuredBuffer width undef undef undef
  1016. ==================== ===== ========== ========== ==========
  1017. MIP levels is always undef for RW resources. Undef means the component will not be used. The validator will verify this.
  1018. There is no GetDimensions that returns float values.
  1019. Sample
  1020. ~~~~~~
  1021. The following signature shows the operation syntax::
  1022. ; overloads: SM5.1: f32, SM6.0: f16|f32
  1023. declare %dx.types.ResRet.f32 @dx.op.sample.f32(
  1024. i32, ; opcode
  1025. %dx.types.Handle, ; texture handle
  1026. %dx.types.Handle, ; sampler handle
  1027. float, ; coordinate c0
  1028. float, ; coordinate c1
  1029. float, ; coordinate c2
  1030. float, ; coordinate c3
  1031. i32, ; offset o0
  1032. i32, ; offset o1
  1033. i32, ; offset o2
  1034. float) ; clamp
  1035. =================== ================================ ===================
  1036. Valid resource type # of active coordinates # of active offsets
  1037. =================== ================================ ===================
  1038. Texture1D 1 (c0) 1 (o0)
  1039. Texture1DArray 2 (c0, c1 = array slice) 1 (o0)
  1040. Texture2D 2 (c0, c1) 2 (o0, o1)
  1041. Texture2DArray 3 (c0, c1, c2 = array slice) 2 (o0, o1)
  1042. Texture3D 3 (c0, c1, c2) 3 (o0, o1, o2)
  1043. TextureCUBE 3 (c0, c1, c2) 3 (o0, o1, o2)
  1044. TextureCUBEArray 4 (c0, c1, c2, c3 = array slice) 3 (o0, o1, o2)
  1045. =================== ================================ ===================
  1046. SampleBias
  1047. ~~~~~~~~~~
  1048. The following signature shows the operation syntax::
  1049. ; overloads: SM5.1: f32, SM6.0: f16|f32
  1050. declare %dx.types.ResRet.f32 @dx.op.sampleBias.f32(
  1051. i32, ; opcode
  1052. %dx.types.Handle, ; texture handle
  1053. %dx.types.Handle, ; sampler handle
  1054. float, ; coordinate c0
  1055. float, ; coordinate c1
  1056. float, ; coordinate c2
  1057. float, ; coordinate c3
  1058. i32, ; offset o0
  1059. i32, ; offset o1
  1060. i32, ; offset o2
  1061. float, ; bias: in [-16.f,15.99f]
  1062. float) ; clamp
  1063. Valid resource types and active components/offsets are the same as for the sample operation.
  1064. SampleLevel
  1065. ~~~~~~~~~~~
  1066. The following signature shows the operation syntax::
  1067. ; overloads: SM5.1: f32, SM6.0: f16|f32
  1068. declare %dx.types.ResRet.f32 @dx.op.sampleLevel.f32(
  1069. i32, ; opcode
  1070. %dx.types.Handle, ; texture handle
  1071. %dx.types.Handle, ; sampler handle
  1072. float, ; coordinate c0
  1073. float, ; coordinate c1
  1074. float, ; coordinate c2
  1075. float, ; coordinate c3
  1076. i32, ; offset o0
  1077. i32, ; offset o1
  1078. i32, ; offset o2
  1079. float) ; LOD
  1080. Valid resource types and active components/offsets are the same as for the sample operation.
  1081. SampleGrad
  1082. ~~~~~~~~~~
  1083. The following signature shows the operation syntax::
  1084. ; overloads: SM5.1: f32, SM6.0: f16|f32
  1085. declare %dx.types.ResRet.f32 @dx.op.sampleGrad.f32(
  1086. i32, ; opcode
  1087. %dx.types.Handle, ; texture handle
  1088. %dx.types.Handle, ; sampler handle
  1089. float, ; coordinate c0
  1090. float, ; coordinate c1
  1091. float, ; coordinate c2
  1092. float, ; coordinate c3
  1093. i32, ; offset o0
  1094. i32, ; offset o1
  1095. i32, ; offset o2
  1096. float, ; ddx0
  1097. float, ; ddx1
  1098. float, ; ddx2
  1099. float, ; ddy0
  1100. float, ; ddy1
  1101. float, ; ddy2
  1102. float) ; clamp
  1103. 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.
  1104. SampleCmp
  1105. ~~~~~~~~~
  1106. The following signature shows the operation syntax::
  1107. ; overloads: SM5.1: f32, SM6.0: f16|f32
  1108. declare %dx.types.ResRet.f32 @dx.op.sampleCmp.f32(
  1109. i32, ; opcode
  1110. %dx.types.Handle, ; texture handle
  1111. %dx.types.Handle, ; sampler handle
  1112. float, ; coordinate c0
  1113. float, ; coordinate c1
  1114. float, ; coordinate c2
  1115. float, ; coordinate c3
  1116. i32, ; offset o0
  1117. i32, ; offset o1
  1118. i32, ; offset o2
  1119. float, ; compare value
  1120. float) ; clamp
  1121. =================== ================================ ===================
  1122. Valid resource type # of active coordinates # of active offsets
  1123. =================== ================================ ===================
  1124. Texture1D 1 (c0) 1 (o0)
  1125. Texture1DArray 2 (c0, c1 = array slice) 1 (o0)
  1126. Texture2D 2 (c0, c1) 2 (o0, o1)
  1127. Texture2DArray 3 (c0, c1, c2 = array slice) 2 (o0, o1)
  1128. TextureCUBE 3 (c0, c1, c2) 3 (o0, o1, o2)
  1129. TextureCUBEArray 4 (c0, c1, c2, c3 = array slice) 3 (o0, o1, o2)
  1130. =================== ================================ ===================
  1131. SampleCmpLevelZero
  1132. ~~~~~~~~~~~~~~~~~~
  1133. The following signature shows the operation syntax::
  1134. ; overloads: SM5.1: f32, SM6.0: f16|f32
  1135. declare %dx.types.ResRet.f32 @dx.op.sampleCmpLevelZero.f32(
  1136. i32, ; opcode
  1137. %dx.types.Handle, ; texture handle
  1138. %dx.types.Handle, ; sampler handle
  1139. float, ; coordinate c0
  1140. float, ; coordinate c1
  1141. float, ; coordinate c2
  1142. float, ; coordinate c3
  1143. i32, ; offset o0
  1144. i32, ; offset o1
  1145. i32, ; offset o2
  1146. float) ; compare value
  1147. Valid resource types and active components/offsets are the same as for the sampleCmp operation.
  1148. TextureLoad
  1149. ~~~~~~~~~~~
  1150. The following signature shows the operation syntax::
  1151. ; overloads: SM5.1: f32|i32, SM6.0: f16|f32|i16|i32
  1152. declare %dx.types.ResRet.f32 @dx.op.textureLoad.f32(
  1153. i32, ; opcode
  1154. %dx.types.Handle, ; texture handle
  1155. i32, ; MIP level; sample for Texture2DMS
  1156. i32, ; coordinate c0
  1157. i32, ; coordinate c1
  1158. i32, ; coordinate c2
  1159. i32, ; offset o0
  1160. i32, ; offset o1
  1161. i32) ; offset o2
  1162. =================== ========= ============================ ===================
  1163. Valid resource type MIP level # of active coordinates # of active offsets
  1164. =================== ========= ============================ ===================
  1165. Texture1D yes 1 (c0) 1 (o0)
  1166. RWTexture1D undef 1 (c0) undef
  1167. Texture1DArray yes 2 (c0, c1 = array slice) 1 (o0)
  1168. RWTexture1DArray undef 2 (c0, c1 = array slice) undef
  1169. Texture2D yes 2 (c0, c1) 2 (o0, o1)
  1170. RWTexture2D undef 2 (c0, c1) undef
  1171. Texture2DArray yes 3 (c0, c1, c2 = array slice) 2 (o0, o1)
  1172. RWTexture2DArray undef 3 (c0, c1, c2 = array slice) undef
  1173. Texture3D yes 3 (c0, c1, c2) 3 (o0, o1, o2)
  1174. RWTexture3D undef 3 (c0, c1, c2) undef
  1175. =================== ========= ============================ ===================
  1176. For Texture2DMS:
  1177. =================== ============ =================================
  1178. Valid resource type Sample index # of active coordinate components
  1179. =================== ============ =================================
  1180. Texture2DMS yes 2 (c0, c1)
  1181. Texture2DMSArray yes 3 (c0, c1, c2 = array slice)
  1182. =================== ============ =================================
  1183. TextureStore
  1184. ~~~~~~~~~~~~
  1185. The following signature shows the operation syntax::
  1186. ; overloads: SM5.1: f32|i32, SM6.0: f16|f32|i16|i32
  1187. ; returns: status
  1188. declare void @dx.op.textureStore.f32(
  1189. i32, ; opcode
  1190. %dx.types.Handle, ; texture handle
  1191. i32, ; coordinate c0
  1192. i32, ; coordinate c1
  1193. i32, ; coordinate c2
  1194. float, ; value v0
  1195. float, ; value v1
  1196. float, ; value v2
  1197. float, ; value v3
  1198. i8) ; write mask
  1199. 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.
  1200. =================== =================================
  1201. Valid resource type # of active coordinate components
  1202. =================== =================================
  1203. RWTexture1D 1 (c0)
  1204. RWTexture1DArray 2 (c0, c1 = array slice)
  1205. RWTexture2D 2 (c0, c1)
  1206. RWTexture2DArray 3 (c0, c1, c2 = array slice)
  1207. RWTexture3D 3 (c0, c1, c2)
  1208. =================== =================================
  1209. CalculateLOD
  1210. ~~~~~~~~~~~~
  1211. The following signature shows the operation syntax::
  1212. ; returns: LOD
  1213. declare float @dx.op.calculateLOD.f32(
  1214. i32, ; opcode
  1215. %dx.types.Handle, ; texture handle
  1216. %dx.types.Handle, ; sampler handle
  1217. float, ; coordinate c0, [0.0, 1.0]
  1218. float, ; coordinate c1, [0.0, 1.0]
  1219. float, ; coordinate c2, [0.0, 1.0]
  1220. i1) ; true - clamped; false - unclamped
  1221. ============================= =======================
  1222. Valid resource type # of active coordinates
  1223. ============================= =======================
  1224. Texture1D, Texture1DArray 1 (c0)
  1225. Texture2D, Texture2DArray 2 (c0, c1)
  1226. Texture3D 3 (c0, c1, c2)
  1227. TextureCUBE, TextureCUBEArray 3 (c0, c1, c2)
  1228. ============================= =======================
  1229. TextureGather
  1230. ~~~~~~~~~~~~~
  1231. The following signature shows the operation syntax::
  1232. ; overloads: SM5.1: f32|i32, SM6.0: f16|f32|i16|i32
  1233. declare %dx.types.ResRet.f32 @dx.op.textureGather.f32(
  1234. i32, ; opcode
  1235. %dx.types.Handle, ; texture handle
  1236. %dx.types.Handle, ; sampler handle
  1237. float, ; coordinate c0
  1238. float, ; coordinate c1
  1239. float, ; coordinate c2
  1240. float, ; coordinate c3
  1241. i32, ; offset o0
  1242. i32, ; offset o1
  1243. i32) ; channel, constant in {0=red,1=green,2=blue,3=alpha}
  1244. =================== ================================ ===================
  1245. Valid resource type # of active coordinates # of active offsets
  1246. =================== ================================ ===================
  1247. Texture2D 2 (c0, c1) 2 (o0, o1)
  1248. Texture2DArray 3 (c0, c1, c2 = array slice) 2 (o0, o1)
  1249. TextureCUBE 3 (c0, c1, c2) 0
  1250. TextureCUBEArray 4 (c0, c1, c2, c3 = array slice) 0
  1251. =================== ================================ ===================
  1252. TextureGatherCmp
  1253. ~~~~~~~~~~~~~~~~
  1254. The following signature shows the operation syntax::
  1255. ; overloads: SM5.1: f32|i32, SM6.0: f16|f32|i16|i32
  1256. declare %dx.types.ResRet.f32 @dx.op.textureGatherCmp.f32(
  1257. i32, ; opcode
  1258. %dx.types.Handle, ; texture handle
  1259. %dx.types.Handle, ; sampler handle
  1260. float, ; coordinate c0
  1261. float, ; coordinate c1
  1262. float, ; coordinate c2
  1263. float, ; coordinate c3
  1264. i32, ; offset o0
  1265. i32, ; offset o1
  1266. i32, ; channel, constant in {0=red,1=green,2=blue,3=alpha}
  1267. float) ; compare value
  1268. Valid resource types and active components/offsets are the same as for the textureGather operation.
  1269. Texture2DMSGetSamplePosition
  1270. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1271. The following signature shows the operation syntax::
  1272. declare %dx.types.SamplePos @dx.op.texture2DMSGetSamplePosition(
  1273. i32, ; opcode
  1274. %dx.types.Handle, ; texture handle
  1275. i32) ; sample ID
  1276. Returns sample position of a texture.
  1277. RenderTargetGetSamplePosition
  1278. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1279. The following signature shows the operation syntax::
  1280. declare %dx.types.SamplePos @dx.op.renderTargetGetSamplePosition(
  1281. i32, ; opcode
  1282. i32) ; sample ID
  1283. Returns sample position of a render target.
  1284. RenderTargetGetSampleCount
  1285. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  1286. The following signature shows the operation syntax::
  1287. declare i32 @dx.op.renderTargetGetSampleCount(
  1288. i32) ; opcode
  1289. Returns sample count of a render target.
  1290. BufferLoad
  1291. ~~~~~~~~~~
  1292. The following signature shows the operation syntax::
  1293. ; overloads: SM5.1: f32|i32, SM6.0: f32|i32
  1294. declare %dx.types.ResRet.f32 @dx.op.bufferLoad.f32(
  1295. i32, ; opcode
  1296. %dx.types.Handle, ; resource handle
  1297. i32, ; coordinate c0
  1298. i32) ; coordinate c1
  1299. The call respects SM5.1 OOB and alignment rules.
  1300. =================== =====================================================
  1301. Valid resource type # of active coordinates
  1302. =================== =====================================================
  1303. [RW]TypedBuffer 1 (c0 in elements)
  1304. [RW]RawBuffer 1 (c0 in bytes)
  1305. [RW]TypedBuffer 2 (c0 in elements, c1 = byte offset into the element)
  1306. =================== =====================================================
  1307. BufferStore
  1308. ~~~~~~~~~~~
  1309. The following signature shows the operation syntax::
  1310. ; overloads: SM5.1: f32|i32, SM6.0: f32|i32
  1311. ; returns: status
  1312. declare void @dx.op.bufferStore.f32(
  1313. i32, ; opcode
  1314. %dx.types.Handle, ; resource handle
  1315. i32, ; coordinate c0
  1316. i32, ; coordinate c1
  1317. float, ; value v0
  1318. float, ; value v1
  1319. float, ; value v2
  1320. float, ; value v3
  1321. i8) ; write mask
  1322. The call respects SM5.1 OOB and alignment rules.
  1323. 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.
  1324. =================== =====================================================
  1325. Valid resource type # of active coordinates
  1326. =================== =====================================================
  1327. RWTypedBuffer 1 (c0 in elements)
  1328. RWRawBuffer 1 (c0 in bytes)
  1329. RWStructuredBuffer 2 (c0 in elements, c1 = byte offset into the element)
  1330. =================== =====================================================
  1331. BufferUpdateCounter
  1332. ~~~~~~~~~~~~~~~~~~~
  1333. The following signature shows the operation syntax::
  1334. ; opcodes: bufferUpdateCounter
  1335. declare void @dx.op.bufferUpdateCounter(
  1336. i32, ; opcode
  1337. %dx.types.ResHandle, ; buffer handle
  1338. i8) ; 1 - increment, -1 - decrement
  1339. Valid resource type: RWRawBuffer.
  1340. AtomicBinOp
  1341. ~~~~~~~~~~~
  1342. The following signature shows the operation syntax::
  1343. ; overloads: SM5.1: i32, SM6.0: i32
  1344. ; returns: original value in memory before the operation
  1345. declare i32 @dx.op.atomicBinOp.i32(
  1346. i32, ; opcode
  1347. %dx.types.Handle, ; resource handle
  1348. i32, ; binary operation code: EXCHANGE, IADD, AND, OR, XOR, IMIN, IMAX, UMIN, UMAX
  1349. i32, ; coordinate c0
  1350. i32, ; coordinate c1
  1351. i32, ; coordinate c2
  1352. i32) ; new value
  1353. The call respects SM5.1 OOB and alignment rules.
  1354. =================== =====================================================
  1355. Valid resource type # of active coordinates
  1356. =================== =====================================================
  1357. RWTexture1D 1 (c0)
  1358. RWTexture1DArray 2 (c0, c1 = array slice)
  1359. RWTexture2D 2 (c0, c1)
  1360. RWTexture2DArray 3 (c0, c1, c2 = array slice)
  1361. RWTexture3D 3 (c0, c1, c2)
  1362. RWTypedBuffer 1 (c0 in elements)
  1363. RWRawBuffer 1 (c0 in bytes)
  1364. RWStructuredBuffer 2 (c0 in elements, c1 - byte offset into the element)
  1365. =================== =====================================================
  1366. 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.
  1367. AtomicCompareExchange
  1368. ~~~~~~~~~~~~~~~~~~~~~
  1369. The following signature shows the operation syntax::
  1370. ; overloads: SM5.1: i32, SM6.0: i32
  1371. ; returns: original value in memory before the operation
  1372. declare i32 @dx.op.atomicBinOp.i32(
  1373. i32, ; opcode
  1374. %dx.types.Handle, ; resource handle
  1375. i32, ; coordinate c0
  1376. i32, ; coordinate c1
  1377. i32, ; coordinate c2
  1378. i32, ; comparison value
  1379. i32) ; new value
  1380. The call respects SM5.1 OOB and alignment rules.
  1381. =================== =====================================================
  1382. Valid resource type # of active coordinates
  1383. =================== =====================================================
  1384. RWTexture1D 1 (c0)
  1385. RWTexture1DArray 2 (c0, c1 = array slice)
  1386. RWTexture2D 2 (c0, c1)
  1387. RWTexture2DArray 3 (c0, c1, c2 = array slice)
  1388. RWTexture3D 3 (c0, c1, c2)
  1389. RWTypedBuffer 1 (c0 in elements)
  1390. RWRawBuffer 1 (c0 in bytes)
  1391. RWStructuredBuffer 2 (c0 in elements, c1 - byte offset into the element)
  1392. =================== =====================================================
  1393. AtomicCompareExchange subsumes DXBC's atomic compare store. The driver compiler is free to specialize the corresponding GPU instruction if the return value is unused.
  1394. GetBufferBasePtr (SM6.0)
  1395. ~~~~~~~~~~~~~~~~~~~~~~~~
  1396. The following signature shows the operation syntax::
  1397. Returns i8* pointer to the base of [RW]RawBuffer instance.
  1398. declare i8 addrspace(ASmemory) * @dx.op.getBufferBasePtr.pASmemory (
  1399. i32, ; opcode
  1400. %dx.types.Handle) ; resource handle
  1401. Returns i8* pointer to the base of ConstantBuffer instance.
  1402. declare i8 addrspace(AScbuffer) * @dx.op.getBufferBasePtr.pAScbuffer(
  1403. i32, ; opcode
  1404. %dx.types.Handle) ; resource handle
  1405. Given SM5.1 resource handle, return base pointer to perform pointer-based accesses to the resource memory.
  1406. 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.
  1407. Atomic operations via pointer
  1408. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1409. 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.
  1410. SM6.0 will enable similar mechanism for atomic operations performed on device memory (raw buffer).
  1411. Samplers
  1412. --------
  1413. There are no intrinsics for samplers. Sampler reflection data is represented similar to other resources.
  1414. Immediate Constant Buffer
  1415. -------------------------
  1416. There is no immediate constant buffer in DXIL. Instead, indexable constants are represented via LLVM global initialized constants in address space ASicb.
  1417. Texture Buffers
  1418. ---------------
  1419. A texture buffer is mapped to RawBuffer. Texture buffer variable declarations are present for reflection purposes only.
  1420. Groupshared memory
  1421. ------------------
  1422. 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).
  1423. Indexable threadlocal memory
  1424. ----------------------------
  1425. 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).
  1426. Load/Store/Atomics via pointer in future SM
  1427. -------------------------------------------
  1428. 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.
  1429. Each resource memory type is expressed by a unique LLVM address space. The following table shows memory types and their address spaces:
  1430. ========================================= =====================================
  1431. Memory type Address space number n - addrspace(n)
  1432. ========================================= =====================================
  1433. code, local, indexable threadlocal memory AS_default = 0
  1434. device memory ([RW]RawBuffer) AS_memory = 1
  1435. cbuffer-like memory (ConstantBuffer) AS_cbuffer = 2
  1436. groupshared memory AS_groupshared = 3
  1437. ========================================= =====================================
  1438. 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.
  1439. Additional resource properties
  1440. ------------------------------
  1441. TODO: enumerate all additional resource range properties, e.g., ROV, Texture2DMS, globally coherent, UAV counter, sampler mode, CB: immediate/dynamic indexed.
  1442. Operations
  1443. ==========
  1444. 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".
  1445. Operations via instructions
  1446. ---------------------------
  1447. 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.
  1448. 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.
  1449. .. <py>import hctdb_instrhelp</py>
  1450. .. <py::lines('INSTR-RST')>hctdb_instrhelp.get_instrs_rst()</py>
  1451. .. INSTR-RST:BEGIN
  1452. ============= ======================================================================= =================
  1453. Instruction Action Operand overloads
  1454. ============= ======================================================================= =================
  1455. Ret returns a value (possibly void), from a function. vhfd1wil
  1456. Br branches (conditional or unconditional)
  1457. Switch performs a multiway switch
  1458. Add returns the sum of its two operands wil
  1459. FAdd returns the sum of its two operands hfd
  1460. Sub returns the difference of its two operands wil
  1461. FSub returns the difference of its two operands hfd
  1462. Mul returns the product of its two operands wil
  1463. FMul returns the product of its two operands hfd
  1464. UDiv returns the quotient of its two unsigned operands wil
  1465. SDiv returns the quotient of its two signed operands wil
  1466. FDiv returns the quotient of its two operands hfd
  1467. URem returns the remainder from the unsigned division of its two operands wil
  1468. SRem returns the remainder from the signed division of its two operands wil
  1469. FRem returns the remainder from the division of its two operands hfd
  1470. Shl shifts left (logical) wil
  1471. LShr shifts right (logical), with zero bit fill wil
  1472. AShr shifts right (arithmetic), with 'a' operand sign bit fill wil
  1473. And returns a bitwise logical and of its two operands 1wil
  1474. Or returns a bitwise logical or of its two operands 1wil
  1475. Xor returns a bitwise logical xor of its two operands 1wil
  1476. Alloca allocates memory on the stack frame of the currently executing function
  1477. Load reads from memory
  1478. Store writes to memory
  1479. GetElementPtr gets the address of a subelement of an aggregate value
  1480. AtomicCmpXchg atomically modifies memory
  1481. AtomicRMW atomically modifies memory
  1482. Trunc truncates an integer 1wil
  1483. ZExt zero extends an integer 1wil
  1484. SExt sign extends an integer 1wil
  1485. FPToUI converts a floating point to UInt hfd1wil
  1486. FPToSI converts a floating point to SInt hfd1wil
  1487. UIToFP converts a UInt to floating point hfd1wil
  1488. SIToFP converts a SInt to floating point hfd1wil
  1489. FPTrunc truncates a floating point hfd
  1490. FPExt extends a floating point hfd
  1491. BitCast performs a bit-preserving type cast hfd1wil
  1492. AddrSpaceCast casts a value addrspace
  1493. ICmp compares integers 1wil
  1494. FCmp compares floating points hfd
  1495. PHI is a PHI node instruction
  1496. Call calls a function
  1497. Select selects an instruction
  1498. ExtractValue extracts from aggregate
  1499. ============= ======================================================================= =================
  1500. .. INSTR-RST:END
  1501. Operations via external functions
  1502. ---------------------------------
  1503. Operations missing in core LLVM IR, such as abs, fma, discard, etc., are represented by external functions, whose name is prefixed with dx.op.
  1504. 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.
  1505. 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.
  1506. .. <py::lines('OPCODES-RST')>hctdb_instrhelp.get_opcodes_rst()</py>
  1507. .. OPCODES-RST:BEGIN
  1508. === ============================= =================================================================================================================
  1509. ID Name Description
  1510. === ============================= =================================================================================================================
  1511. 0 TempRegLoad_ Helper load operation
  1512. 1 TempRegStore_ Helper store operation
  1513. 2 MinPrecXRegLoad_ Helper load operation for minprecision
  1514. 3 MinPrecXRegStore_ Helper store operation for minprecision
  1515. 4 LoadInput_ Loads the value from shader input
  1516. 5 StoreOutput_ Stores the value to shader output
  1517. 6 FAbs_ returns the absolute value of the input value.
  1518. 7 Saturate_ clamps the result of a single or double precision floating point value to [0.0f...1.0f]
  1519. 8 IsNaN_ Returns true if x is NAN or QNAN, false otherwise.
  1520. 9 IsInf_ Returns true if x is +INF or -INF, false otherwise.
  1521. 10 IsFinite_ Returns true if x is finite, false otherwise.
  1522. 11 IsNormal_ returns IsNormal
  1523. 12 Cos_ returns cosine(theta) for theta in radians.
  1524. 13 Sin_ returns sine(theta) for theta in radians.
  1525. 14 Tan_ returns tan(theta) for theta in radians.
  1526. 15 Acos_ Returns the arccosine of the specified value. Input should be a floating-point value within the range of -1 to 1.
  1527. 16 Asin_ Returns the arccosine of the specified value. Input should be a floating-point value within the range of -1 to 1
  1528. 17 Atan_ Returns the arctangent of the specified value. The return value is within the range of -PI/2 to PI/2.
  1529. 18 Hcos_ returns the hyperbolic cosine of the specified value.
  1530. 19 Hsin_ returns the hyperbolic sine of the specified value.
  1531. 20 Htan_ returns the hyperbolic tangent of the specified value.
  1532. 21 Exp_ returns 2^exponent
  1533. 22 Frc_ extract fracitonal component.
  1534. 23 Log_ returns log base 2.
  1535. 24 Sqrt_ returns square root
  1536. 25 Rsqrt_ returns reciprocal square root (1 / sqrt(src)
  1537. 26 Round_ne_ floating-point round to integral float.
  1538. 27 Round_ni_ floating-point round to integral float.
  1539. 28 Round_pi_ floating-point round to integral float.
  1540. 29 Round_z_ floating-point round to integral float.
  1541. 30 Bfrev_ Reverses the order of the bits.
  1542. 31 Countbits_ Counts the number of bits in the input integer.
  1543. 32 FirstbitLo_ Returns the location of the first set bit starting from the lowest order bit and working upward.
  1544. 33 FirstbitHi_ Returns the location of the first set bit starting from the highest order bit and working downward.
  1545. 34 FirstbitSHi_ Returns the location of the first set bit from the highest order bit based on the sign.
  1546. 35 FMax_ returns a if a >= b, else b
  1547. 36 FMin_ returns a if a < b, else b
  1548. 37 IMax_ IMax(a,b) returns a if a > b, else b
  1549. 38 IMin_ IMin(a,b) returns a if a < b, else b
  1550. 39 UMax_ unsigned integer maximum. UMax(a,b) = a > b ? a : b
  1551. 40 UMin_ unsigned integer minimum. UMin(a,b) = a < b ? a : b
  1552. 41 IMul_ multiply of 32-bit operands to produce the correct full 64-bit result.
  1553. 42 UMul_ multiply of 32-bit operands to produce the correct full 64-bit result.
  1554. 43 UDiv_ unsigned divide of the 32-bit operand src0 by the 32-bit operand src1.
  1555. 44 UAddc_ unsigned add of 32-bit operand with the carry
  1556. 45 USubb_ unsigned subtract of 32-bit operands with the borrow
  1557. 46 FMad_ floating point multiply & add
  1558. 47 Fma_ fused multiply-add
  1559. 48 IMad_ Signed integer multiply & add
  1560. 49 UMad_ Unsigned integer multiply & add
  1561. 50 Msad_ masked Sum of Absolute Differences.
  1562. 51 Ibfe_ Integer bitfield extract
  1563. 52 Ubfe_ Unsigned integer bitfield extract
  1564. 53 Bfi_ Given a bit range from the LSB of a number, places that number of bits in another number at any offset
  1565. 54 Dot2_ Two-dimensional vector dot-product
  1566. 55 Dot3_ Three-dimensional vector dot-product
  1567. 56 Dot4_ Four-dimensional vector dot-product
  1568. 57 CreateHandle creates the handle to a resource
  1569. 58 CBufferLoad loads a value from a constant buffer resource
  1570. 59 CBufferLoadLegacy loads a value from a constant buffer resource
  1571. 60 Sample samples a texture
  1572. 61 SampleBias samples a texture after applying the input bias to the mipmap level
  1573. 62 SampleLevel samples a texture using a mipmap-level offset
  1574. 63 SampleGrad samples a texture using a gradient to influence the way the sample location is calculated
  1575. 64 SampleCmp samples a texture and compares a single component against the specified comparison value
  1576. 65 SampleCmpLevelZero samples a texture and compares a single component against the specified comparison value
  1577. 66 TextureLoad reads texel data without any filtering or sampling
  1578. 67 TextureStore reads texel data without any filtering or sampling
  1579. 68 BufferLoad reads from a TypedBuffer
  1580. 69 BufferStore writes to a RWTypedBuffer
  1581. 70 BufferUpdateCounter atomically increments/decrements the hidden 32-bit counter stored with a Count or Append UAV
  1582. 71 CheckAccessFullyMapped determines whether all values from a Sample, Gather, or Load operation accessed mapped tiles in a tiled resource
  1583. 72 GetDimensions gets texture size information
  1584. 73 TextureGather gathers the four texels that would be used in a bi-linear filtering operation
  1585. 74 TextureGatherCmp same as TextureGather, except this instrution performs comparison on texels, similar to SampleCmp
  1586. 75 Texture2DMSGetSamplePosition gets the position of the specified sample
  1587. 76 RenderTargetGetSamplePosition gets the position of the specified sample
  1588. 77 RenderTargetGetSampleCount gets the number of samples for a render target
  1589. 78 AtomicBinOp performs an atomic operation on two operands
  1590. 79 AtomicCompareExchange atomic compare and exchange to memory
  1591. 80 Barrier inserts a memory barrier in the shader
  1592. 81 CalculateLOD calculates the level of detail
  1593. 82 Discard discard the current pixel
  1594. 83 DerivCoarseX_ computes the rate of change per stamp in x direction.
  1595. 84 DerivCoarseY_ computes the rate of change per stamp in y direction.
  1596. 85 DerivFineX_ computes the rate of change per pixel in x direction.
  1597. 86 DerivFineY_ computes the rate of change per pixel in y direction.
  1598. 87 EvalSnapped evaluates an input attribute at pixel center with an offset
  1599. 88 EvalSampleIndex evaluates an input attribute at a sample location
  1600. 89 EvalCentroid evaluates an input attribute at pixel center
  1601. 90 SampleIndex returns the sample index in a sample-frequency pixel shader
  1602. 91 Coverage returns the coverage mask input in a pixel shader
  1603. 92 InnerCoverage returns underestimated coverage input from conservative rasterization in a pixel shader
  1604. 93 ThreadId reads the thread ID
  1605. 94 GroupId reads the group ID (SV_GroupID)
  1606. 95 ThreadIdInGroup reads the thread ID within the group (SV_GroupThreadID)
  1607. 96 FlattenedThreadIdInGroup provides a flattened index for a given thread within a given group (SV_GroupIndex)
  1608. 97 EmitStream emits a vertex to a given stream
  1609. 98 CutStream completes the current primitive topology at the specified stream
  1610. 99 EmitThenCutStream equivalent to an EmitStream followed by a CutStream
  1611. 100 GSInstanceID GSInstanceID
  1612. 101 MakeDouble creates a double value
  1613. 102 SplitDouble splits a double into low and high parts
  1614. 103 LoadOutputControlPoint LoadOutputControlPoint
  1615. 104 LoadPatchConstant LoadPatchConstant
  1616. 105 DomainLocation DomainLocation
  1617. 106 StorePatchConstant StorePatchConstant
  1618. 107 OutputControlPointID OutputControlPointID
  1619. 108 PrimitiveID PrimitiveID
  1620. 109 CycleCounterLegacy CycleCounterLegacy
  1621. 110 WaveIsFirstLane returns 1 for the first lane in the wave
  1622. 111 WaveGetLaneIndex returns the index of the current lane in the wave
  1623. 112 WaveGetLaneCount returns the number of lanes in the wave
  1624. 113 WaveAnyTrue returns 1 if any of the lane evaluates the value to true
  1625. 114 WaveAllTrue returns 1 if all the lanes evaluate the value to true
  1626. 115 WaveActiveAllEqual returns 1 if all the lanes have the same value
  1627. 116 WaveActiveBallot returns a struct with a bit set for each lane where the condition is true
  1628. 117 WaveReadLaneAt returns the value from the specified lane
  1629. 118 WaveReadLaneFirst returns the value from the first lane
  1630. 119 WaveActiveOp returns the result the operation across waves
  1631. 120 WaveActiveBit returns the result of the operation across all lanes
  1632. 121 WavePrefixOp returns the result of the operation on prior lanes
  1633. 122 QuadReadLaneAt reads from a lane in the quad
  1634. 123 QuadOp returns the result of a quad-level operation
  1635. 124 BitcastI16toF16 bitcast between different sizes
  1636. 125 BitcastF16toI16 bitcast between different sizes
  1637. 126 BitcastI32toF32 bitcast between different sizes
  1638. 127 BitcastF32toI32 bitcast between different sizes
  1639. 128 BitcastI64toF64 bitcast between different sizes
  1640. 129 BitcastF64toI64 bitcast between different sizes
  1641. 130 LegacyF32ToF16 legacy fuction to convert float (f32) to half (f16) (this is not related to min-precision)
  1642. 131 LegacyF16ToF32 legacy fuction to convert half (f16) to float (f32) (this is not related to min-precision)
  1643. 132 LegacyDoubleToFloat legacy fuction to convert double to float
  1644. 133 LegacyDoubleToSInt32 legacy fuction to convert double to int32
  1645. 134 LegacyDoubleToUInt32 legacy fuction to convert double to uint32
  1646. 135 WaveAllBitCount returns the count of bits set to 1 across the wave
  1647. 136 WavePrefixBitCount returns the count of bits set to 1 on prior lanes
  1648. 137 AttributeAtVertex_ returns the values of the attributes at the vertex.
  1649. 138 ViewID returns the view index
  1650. === ============================= =================================================================================================================
  1651. Acos
  1652. ~~~~
  1653. The return value is within the range of -PI/2 to PI/2.
  1654. +----------+------+--------------+---------+------+------+---------+------+-----+
  1655. | src | -inf | [-1,1] | -denorm | -0 | +0 | +denorm | +inf | NaN |
  1656. +----------+------+--------------+---------+------+------+---------+------+-----+
  1657. | acos(src)| NaN | (-PI/2,+PI/2)| PI/2 | PI/2 | PI/2 | PI/2 | NaN | NaN |
  1658. +----------+------+--------------+---------+------+------+---------+------+-----+
  1659. Asin
  1660. ~~~~
  1661. The return value is within the range of -PI/2 to PI/2.
  1662. +----------+------+--------------+---------+------+------+---------+------+-----+
  1663. | src | -inf | [-1,1] | -denorm | -0 | +0 | +denorm | +inf | NaN |
  1664. +----------+------+--------------+---------+------+------+---------+------+-----+
  1665. | asin(src)| NaN | (-PI/2,+PI/2)| 0 | 0 | 0 | 0 | NaN | NaN |
  1666. +----------+------+--------------+---------+------+------+---------+------+-----+
  1667. Atan
  1668. ~~~~
  1669. +----------+------+--------------+---------+------+------+---------+---------------+-----+-----+
  1670. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F |+inf | NaN |
  1671. +----------+------+--------------+---------+------+------+---------+---------------+-----+-----+
  1672. | atan(src)| -PI/2| (-PI/2,+PI/2)| 0 | 0 | 0 | 0 | (-PI/2,+PI/2) |PI/2 | NaN |
  1673. +----------+------+--------------+---------+------+------+---------+---------------+-----+-----+
  1674. Returns the arctangent of the specified value. The return value is within the range of -PI/2 to PI/2
  1675. AttributeAtVertex
  1676. ~~~~~~~~~~~~~~~~~
  1677. returns the values of the attributes at the vertex. VertexID ranges from 0 to 2.
  1678. Bfi
  1679. ~~~
  1680. Given a bit range from the LSB of a number, place that number of bits in another number at any offset.
  1681. dst = Bfi(src0, src1, src2, src3);
  1682. The LSB 5 bits of src0 provide the bitfield width (0-31) to take from src2.
  1683. The LSB 5 bits of src1 provide the bitfield offset (0-31) to start replacing bits in the number read from src3.
  1684. Given width, offset: bitmask = (((1 << width)-1) << offset) & 0xffffffff, dest = ((src2 << offset) & bitmask) | (src3 & ~bitmask)
  1685. Bfrev
  1686. ~~~~~
  1687. Reverses the order of the bits. For example given 0x12345678 the result would be 0x1e6a2c48.
  1688. Cos
  1689. ~~~
  1690. Theta values can be any IEEE 32-bit floating point values.
  1691. The maximum absolute error is 0.0008 in the interval from -100*Pi to +100*Pi.
  1692. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1693. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  1694. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1695. | cos(src) | NaN | [-1 to +1] | +1 | +1 | +1 | +1 | [-1 to +1] | NaN | NaN |
  1696. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1697. Countbits
  1698. ~~~~~~~~~
  1699. Counts the number of bits in the input integer.
  1700. DerivCoarseX
  1701. ~~~~~~~~~~~~
  1702. dst = DerivCoarseX(src);
  1703. Computes the rate of change per stamp in x direction. Only a single x derivative pair is computed for each 2x2 stamp of pixels.
  1704. 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:
  1705. As an example, the x derivative could be a delta from the top row of pixels.
  1706. 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.
  1707. DerivCoarseY
  1708. ~~~~~~~~~~~~
  1709. dst = DerivCoarseY(src);
  1710. Computes the rate of change per stamp in y direction. Only a single y derivative pair is computed for each 2x2 stamp of pixels.
  1711. 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:
  1712. As an example, the y derivative could be a delta from the left column of pixels.
  1713. 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.
  1714. DerivFineX
  1715. ~~~~~~~~~~
  1716. dst = DerivFineX(src);
  1717. Computes the rate of change per pixel in x direction. Each pixel in the 2x2 stamp gets a unique pair of x derivative calculations
  1718. The data in the current Pixel Shader invocation always participates in the calculation of the requested derivative.
  1719. There is no specification dictating how the 2x2 quads will be aligned/tiled over a primitive.
  1720. DerivFineY
  1721. ~~~~~~~~~~
  1722. dst = DerivFineY(src);
  1723. Computes the rate of change per pixel in y direction. Each pixel in the 2x2 stamp gets a unique pair of y derivative calculations
  1724. The data in the current Pixel Shader invocation always participates in the calculation of the requested derivative.
  1725. There is no specification dictating how the 2x2 quads will be aligned/tiled over a primitive.
  1726. Dot2
  1727. ~~~~
  1728. Two-dimensional vector dot-product
  1729. Dot3
  1730. ~~~~
  1731. Three-dimensional vector dot-product
  1732. Dot4
  1733. ~~~~
  1734. Four-dimensional vector dot-product
  1735. Exp
  1736. ~~~
  1737. Returns 2^exponent. Note that hlsl log intrinsic returns the base-e exponent. Maximum relative error is e^-21.
  1738. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1739. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  1740. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1741. | exp(src) | 0 | +F | 1 | 1 | 1 | 1 | +F | +inf | NaN |
  1742. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1743. FAbs
  1744. ~~~~
  1745. The FAbs instruction takes simply forces the sign of the number(s) on the source operand positive, including on INF and denorm values.
  1746. Applying FAbs on NaN preserves NaN, although the particular NaN bit pattern that results is not defined.
  1747. FMad
  1748. ~~~~
  1749. Floating point multiply & add. This operation is not fused for "precise" operations.
  1750. FMad(a,b,c) = a * b + c
  1751. FMax
  1752. ~~~~
  1753. >= is used instead of > so that if min(x,y) = x then max(x,y) = y.
  1754. NaN has special handling: If one source operand is NaN, then the other source operand is returned.
  1755. If both are NaN, any NaN representation is returned.
  1756. This conforms to new IEEE 754R rules.
  1757. Denorms are flushed (sign preserved) before comparison, however the result written to dest may or may not be denorm flushed.
  1758. +------+-----------------------------+
  1759. | a | b |
  1760. | +------+--------+------+------+
  1761. | | -inf | F | +inf | NaN |
  1762. +------+------+--------+------+------+
  1763. | -inf | -inf | b | +inf | -inf |
  1764. +------+------+--------+------+------+
  1765. | F | a | a or b | +inf | a |
  1766. +------+------+--------+------+------+
  1767. | +inf | +inf | +inf | +inf | +inf |
  1768. +------+------+--------+------+------+
  1769. | NaN | -inf | b | +inf | NaN |
  1770. +------+------+--------+------+------+
  1771. FMin
  1772. ~~~~
  1773. NaN has special handling: If one source operand is NaN, then the other source operand is returned.
  1774. If both are NaN, any NaN representation is returned.
  1775. This conforms to new IEEE 754R rules.
  1776. Denorms are flushed (sign preserved) before comparison, however the result written to dest may or may not be denorm flushed.
  1777. +------+-----------------------------+
  1778. | a | b |
  1779. | +------+--------+------+------+
  1780. | | -inf | F | +inf | NaN |
  1781. +------+------+--------+------+------+
  1782. | -inf | -inf | -inf | -inf | -inf |
  1783. +------+------+--------+------+------+
  1784. | F | -inf | a or b | a | a |
  1785. +------+------+--------+------+------+
  1786. | +inf | -inf | b | +inf | +inf |
  1787. +------+------+--------+------+------+
  1788. | NaN | -inf | b | +inf | NaN |
  1789. +------+------+--------+------+------+
  1790. FirstbitHi
  1791. ~~~~~~~~~~
  1792. 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.
  1793. FirstbitLo
  1794. ~~~~~~~~~~
  1795. 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.
  1796. FirstbitSHi
  1797. ~~~~~~~~~~~
  1798. 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.
  1799. Fma
  1800. ~~~
  1801. Fused multiply-add. This operation is only defined in double precision.
  1802. Fma(a,b,c) = a * b + c
  1803. Frc
  1804. ~~~
  1805. +--------------+------+------+---------+----+----+---------+--------+------+-----+
  1806. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  1807. +--------------+------+------+---------+----+----+---------+--------+------+-----+
  1808. | log(src) | NaN |[+0,1)| +0 | +0 | +0 | +0 | [+0,1) | NaN | NaN |
  1809. +--------------+------+------+---------+----+----+---------+--------+------+-----+
  1810. Hcos
  1811. ~~~~
  1812. Returns the hyperbolic cosine of the specified value.
  1813. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1814. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  1815. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1816. | hcos(src)| +inf | (1, +inf) | +1 | +1 | +1 | +1 | (1, +inf) | +inf | NaN |
  1817. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1818. Hsin
  1819. ~~~~
  1820. Returns the hyperbolic sine of the specified value.
  1821. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1822. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  1823. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1824. | hsin(src)| -inf | -F | 0 | 0 | 0 | 0 | +F | +inf | NaN |
  1825. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1826. Htan
  1827. ~~~~
  1828. Returns the hyperbolic tangent of the specified value.
  1829. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1830. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  1831. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1832. | htan(src)| -1 | -F | 0 | 0 | 0 | 0 | +F | +1 | NaN |
  1833. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1834. IMad
  1835. ~~~~
  1836. Signed integer multiply & add
  1837. IMad(a,b,c) = a * b + c
  1838. IMax
  1839. ~~~~
  1840. IMax(a,b) returns a if a > b, else b. Optional negate modifier on source operands takes 2's complement before performing operation.
  1841. IMin
  1842. ~~~~
  1843. IMin(a,b) returns a if a < b, else b. Optional negate modifier on source operands takes 2's complement before performing operation.
  1844. IMul
  1845. ~~~~
  1846. IMul(src0, src1) = destHi, destLo
  1847. multiply of 32-bit operands src0 and src1 (note they are signed), producing the correct full 64-bit result.
  1848. The low 32 bits are placed in destLO. The high 32 bits are placed in destHI.
  1849. 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.
  1850. Optional negate modifier on source operands takes 2's complement before performing arithmetic operation.
  1851. Ibfe
  1852. ~~~~
  1853. dest = Ibfe(src0, src1, src2)
  1854. Given a range of bits in a number, shift those bits to the LSB and sign extend the MSB of the range.
  1855. width : The LSB 5 bits of src0 (0-31).
  1856. offset: The LSB 5 bits of src1 (0-31)
  1857. .. code:: c
  1858. if( width == 0 )
  1859. {
  1860. dest = 0
  1861. }
  1862. else if( width + offset < 32 )
  1863. {
  1864. shl dest, src2, 32-(width+offset)
  1865. ishr dest, dest, 32-width
  1866. }
  1867. else
  1868. {
  1869. ishr dest, src2, offset
  1870. }
  1871. IsFinite
  1872. ~~~~~~~~
  1873. Returns true if x is finite, false otherwise.
  1874. IsInf
  1875. ~~~~~
  1876. Returns true if x is +INF or -INF, false otherwise.
  1877. IsNaN
  1878. ~~~~~
  1879. Returns true if x is NAN or QNAN, false otherwise.
  1880. IsNormal
  1881. ~~~~~~~~
  1882. Returns IsNormal.
  1883. LoadInput
  1884. ~~~~~~~~~
  1885. Loads the value from shader input
  1886. Log
  1887. ~~~
  1888. Returns log base 2. Note that hlsl log intrinsic returns natural log.
  1889. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1890. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  1891. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1892. | log(src) | NaN | NaN | -inf |-inf|-inf| -inf | F | +inf | NaN |
  1893. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  1894. MinPrecXRegLoad
  1895. ~~~~~~~~~~~~~~~
  1896. Helper load operation for minprecision
  1897. MinPrecXRegStore
  1898. ~~~~~~~~~~~~~~~~
  1899. Helper store operation for minprecision
  1900. Msad
  1901. ~~~~
  1902. Returns the masked Sum of Absolute Differences.
  1903. dest = msad(ref, src, accum)
  1904. ref: contains 4 packed 8-bit unsigned integers in 32 bits.
  1905. src: contains 4 packed 8-bit unsigned integers in 32 bits.
  1906. accum: a 32-bit unsigned integer, providing an existing accumulation.
  1907. dest receives the result of the masked SAD operation added to the accumulation value.
  1908. .. code:: c
  1909. UINT msad( UINT ref, UINT src, UINT accum )
  1910. {
  1911. for (UINT i = 0; i < 4; i++)
  1912. {
  1913. BYTE refByte, srcByte, absDiff;
  1914. refByte = (BYTE)(ref >> (i * 8));
  1915. if (!refByte)
  1916. {
  1917. continue;
  1918. }
  1919. srcByte = (BYTE)(src >> (i * 8));
  1920. if (refByte >= srcByte)
  1921. {
  1922. absDiff = refByte - srcByte;
  1923. }
  1924. else
  1925. {
  1926. absDiff = srcByte - refByte;
  1927. }
  1928. // The recommended overflow behavior for MSAD is
  1929. // to do a 32-bit saturate. This is not
  1930. // required, however, and wrapping is allowed.
  1931. // So from an application point of view,
  1932. // overflow behavior is undefined.
  1933. if (UINT_MAX - accum < absDiff)
  1934. {
  1935. accum = UINT_MAX;
  1936. break;
  1937. }
  1938. accum += absDiff;
  1939. }
  1940. return accum;
  1941. }
  1942. Round_ne
  1943. ~~~~~~~~
  1944. Floating-point round of the values in src,
  1945. writing integral floating-point values to dest.
  1946. round_ne rounds towards nearest even. For halfway, it rounds away from zero.
  1947. +--------------+------+----+---------+----+----+---------+----+------+-----+
  1948. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  1949. +--------------+------+----+---------+----+----+---------+----+------+-----+
  1950. | round_ne(src)| -inf | -F | -0 | -0 | +0 | +0 | +F | +inf | NaN |
  1951. +--------------+------+----+---------+----+----+---------+----+------+-----+
  1952. Round_ni
  1953. ~~~~~~~~
  1954. Floating-point round of the values in src,
  1955. writing integral floating-point values to dest.
  1956. round_ni rounds towards -INF, commonly known as floor().
  1957. +--------------+------+----+---------+----+----+---------+----+------+-----+
  1958. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  1959. +--------------+------+----+---------+----+----+---------+----+------+-----+
  1960. | round_ni(src)| -inf | -F | -0 | -0 | +0 | +0 | +F | +inf | NaN |
  1961. +--------------+------+----+---------+----+----+---------+----+------+-----+
  1962. Round_pi
  1963. ~~~~~~~~
  1964. Floating-point round of the values in src,
  1965. writing integral floating-point values to dest.
  1966. round_pi rounds towards +INF, commonly known as ceil().
  1967. +--------------+------+----+---------+----+----+---------+----+------+-----+
  1968. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  1969. +--------------+------+----+---------+----+----+---------+----+------+-----+
  1970. | round_pi(src)| -inf | -F | -0 | -0 | +0 | +0 | +F | +inf | NaN |
  1971. +--------------+------+----+---------+----+----+---------+----+------+-----+
  1972. Round_z
  1973. ~~~~~~~
  1974. Floating-point round of the values in src,
  1975. writing integral floating-point values to dest.
  1976. round_z rounds towards zero.
  1977. +--------------+------+----+---------+----+----+---------+----+------+-----+
  1978. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  1979. +--------------+------+----+---------+----+----+---------+----+------+-----+
  1980. | round_z(src) | -inf | -F | -0 | -0 | +0 | +0 | +F | +inf | NaN |
  1981. +--------------+------+----+---------+----+----+---------+----+------+-----+
  1982. Rsqrt
  1983. ~~~~~
  1984. Maximum relative error is 2^21.
  1985. +--------------+------+----+---------+----+----+---------+----+------+-----+
  1986. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  1987. +--------------+------+----+---------+----+----+---------+----+------+-----+
  1988. | rsqrt(src) | -inf | -F | -0 | -0 | +0 | +0 | +F | +inf | NaN |
  1989. +--------------+------+----+---------+----+----+---------+----+------+-----+
  1990. Saturate
  1991. ~~~~~~~~
  1992. The Saturate instruction performs the following operation on its input value:
  1993. min(1.0f, max(0.0f, value))
  1994. where min() and max() in the above expression behave in the way Min and Max behave.
  1995. Saturate(NaN) returns 0, by the rules for min and max.
  1996. Sin
  1997. ~~~
  1998. Theta values can be any IEEE 32-bit floating point values.
  1999. The maximum absolute error is 0.0008 in the interval from -100*Pi to +100*Pi.
  2000. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  2001. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  2002. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  2003. | sin(src) | NaN | [-1 to +1] | -0 | -0 | +0 | +0 | [-1 to +1] | NaN | NaN |
  2004. +----------+------+------------+---------+----+----+---------+------------+------+-----+
  2005. Sqrt
  2006. ~~~~
  2007. Precision is 1 ulp.
  2008. +--------------+------+----+---------+----+----+---------+----+------+-----+
  2009. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  2010. +--------------+------+----+---------+----+----+---------+----+------+-----+
  2011. | sqrt(src) | NaN | NaN| -0 | -0 | +0 | +0 | +F | +inf | NaN |
  2012. +--------------+------+----+---------+----+----+---------+----+------+-----+
  2013. StoreOutput
  2014. ~~~~~~~~~~~
  2015. Stores the value to shader output
  2016. Tan
  2017. ~~~
  2018. Theta values can be any IEEE 32-bit floating point values.
  2019. +----------+----------+----------------+---------+----+----+---------+----------------+------+-----+
  2020. | src | -inf | -F | -denorm | -0 | +0 | +denorm | +F | +inf | NaN |
  2021. +----------+----------+----------------+---------+----+----+---------+----------------+------+-----+
  2022. | tan(src) | NaN | [-inf to +inf] | -0 | -0 | +0 | +0 | [-inf to +inf] | NaN | NaN |
  2023. +----------+----------+----------------+---------+----+----+---------+----------------+------+-----+
  2024. TempRegLoad
  2025. ~~~~~~~~~~~
  2026. Helper load operation
  2027. TempRegStore
  2028. ~~~~~~~~~~~~
  2029. Helper store operation
  2030. UAddc
  2031. ~~~~~
  2032. dest0, dest1 = UAddc(src0, src1)
  2033. unsigned add of 32-bit operands src0 and src1, placing the LSB part of the 32-bit result in dest0.
  2034. dest1 is written with: 1 if a carry is produced, 0 otherwise. Dest1 can be NULL if the carry is not needed
  2035. UDiv
  2036. ~~~~
  2037. destQUOT, destREM = UDiv(src0, src1);
  2038. unsigned divide of the 32-bit operand src0 by the 32-bit operand src1.
  2039. The results of the divides are the 32-bit quotients (placed in destQUOT) and 32-bit remainders (placed in destREM).
  2040. Divide by zero returns 0xffffffff for both quotient and remainder.
  2041. Either destQUOT or destREM may be specified as NULL instead of specifying a register, in the case the quotient or remainder are not needed.
  2042. Unsigned subtract of 32-bit operands src1 from src0, placing the LSB part of the 32-bit result in dest0.
  2043. dest1 is written with: 1 if a borrow is produced, 0 otherwise. Dest1 can be NULL if the borrow is not needed
  2044. UMad
  2045. ~~~~
  2046. Unsigned integer multiply & add.
  2047. Umad(a,b,c) = a * b + c
  2048. UMax
  2049. ~~~~
  2050. unsigned integer maximum. UMax(a,b) = a > b ? a : b
  2051. UMin
  2052. ~~~~
  2053. unsigned integer minimum. UMin(a,b) = a < b ? a : b
  2054. UMul
  2055. ~~~~
  2056. multiply of 32-bit operands src0 and src1 (note they are unsigned), producing the correct full 64-bit result.
  2057. The low 32 bits are placed in destLO. The high 32 bits are placed in destHI.
  2058. 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
  2059. USubb
  2060. ~~~~~
  2061. dest0, dest1 = USubb(src0, src1)
  2062. Ubfe
  2063. ~~~~
  2064. dest = ubfe(src0, src1, src2)
  2065. Given a range of bits in a number, shift those bits to the LSB and set remaining bits to 0.
  2066. width : The LSB 5 bits of src0 (0-31).
  2067. offset: The LSB 5 bits of src1 (0-31).
  2068. Given width, offset:
  2069. .. code:: c
  2070. if( width == 0 )
  2071. {
  2072. dest = 0
  2073. }
  2074. else if( width + offset < 32 )
  2075. {
  2076. shl dest, src2, 32-(width+offset)
  2077. ushr dest, dest, 32-width
  2078. }
  2079. else
  2080. {
  2081. ushr dest, src2, offset
  2082. }
  2083. .. OPCODES-RST:END
  2084. Custom instructions
  2085. -------------------
  2086. 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.
  2087. Validation Rules
  2088. ================
  2089. The following rules are verified by the *Validator* component and thus can be relied upon by downstream consumers.
  2090. 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.
  2091. .. <py::lines('VALRULES-RST')>hctdb_instrhelp.get_valrules_rst()</py>
  2092. .. VALRULES-RST:BEGIN
  2093. ====================================== =======================================================================================================================================================================================================================================================================================================
  2094. Rule Code Description
  2095. ====================================== =======================================================================================================================================================================================================================================================================================================
  2096. BITCODE.VALID TODO - Module must be bitcode-valid
  2097. CONTAINER.PARTINVALID DXIL Container must not contain unknown parts
  2098. CONTAINER.PARTMATCHES DXIL Container Parts must match Module
  2099. CONTAINER.PARTMISSING DXIL Container requires certain parts, corresponding to module
  2100. CONTAINER.PARTREPEATED DXIL Container must have only one of each part type
  2101. CONTAINER.ROOTSIGNATUREINCOMPATIBLE Root Signature in DXIL Container must be compatible with shader
  2102. DECL.DXILFNEXTERN External function must be a DXIL function
  2103. DECL.DXILNSRESERVED The DXIL reserved prefixes must only be used by built-in functions and types
  2104. DECL.FNFLATTENPARAM Function parameters must not use struct types
  2105. DECL.FNISCALLED Functions can only be used by call instructions
  2106. DECL.NOTUSEDEXTERNAL External declaration should not be used
  2107. DECL.USEDEXTERNALFUNCTION External function must be used
  2108. DECL.USEDINTERNAL Internal declaration must be used
  2109. FLOW.DEADLOOP Loop must have break
  2110. FLOW.FUNCTIONCALL Function with parameter is not permitted
  2111. FLOW.NORECUSION Recursion is not permitted
  2112. FLOW.REDUCIBLE Execution flow must be reducible
  2113. INSTR.ALLOWED Instructions must be of an allowed type
  2114. INSTR.ATTRIBUTEATVERTEXNOINTERPOLATION Attribute %0 must have nointerpolation mode in order to use GetAttributeAtVertex function.
  2115. INSTR.BARRIERMODEFORNONCS sync in a non-Compute Shader must only sync UAV (sync_uglobal)
  2116. 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.
  2117. INSTR.BARRIERMODEUSELESSUGROUP sync can't specify both _ugroup and _uglobal. If both are needed, just specify _uglobal.
  2118. INSTR.BUFFERUPDATECOUNTERONUAV BufferUpdateCounter valid only on UAV
  2119. INSTR.CALLOLOAD Call to DXIL intrinsic must match overload signature
  2120. INSTR.CANNOTPULLPOSITION pull-model evaluation of position disallowed
  2121. INSTR.CBUFFERCLASSFORCBUFFERHANDLE Expect Cbuffer for CBufferLoad handle
  2122. INSTR.CBUFFEROUTOFBOUND Cbuffer access out of bound
  2123. INSTR.COORDINATECOUNTFORRAWTYPEDBUF raw/typed buffer don't need 2 coordinates
  2124. INSTR.COORDINATECOUNTFORSTRUCTBUF structured buffer require 2 coordinates
  2125. INSTR.DXILSTRUCTUSER Dxil struct types should only used by ExtractValue
  2126. INSTR.DXILSTRUCTUSEROUTOFBOUND Index out of bound when extract value from dxil struct types
  2127. 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
  2128. INSTR.EXTRACTVALUE ExtractValue should only be used on dxil struct types and cmpxchg
  2129. INSTR.FAILTORESLOVETGSMPOINTER TGSM pointers must originate from an unambiguous TGSM global variable.
  2130. INSTR.HANDLENOTFROMCREATEHANDLE Resource handle should returned by createHandle
  2131. INSTR.IMMBIASFORSAMPLEB bias amount for sample_b must be in the range [%0,%1], but %2 was specified as an immediate
  2132. INSTR.INBOUNDSACCESS Access to out-of-bounds memory is disallowed
  2133. INSTR.MINPRECISIONNOTPRECISE Instructions marked precise may not refer to minprecision values
  2134. INSTR.MINPRECISONBITCAST Bitcast on minprecison types is not allowed
  2135. INSTR.MIPLEVELFORGETDIMENSION Use mip level on buffer when GetDimensions
  2136. INSTR.MIPONUAVLOAD uav load don't support mipLevel/sampleIndex
  2137. INSTR.NOGENERICPTRADDRSPACECAST Address space cast between pointer types must have one part to be generic address space
  2138. INSTR.NOIDIVBYZERO No signed integer division by zero
  2139. INSTR.NOINDEFINITEACOS No indefinite arccosine
  2140. INSTR.NOINDEFINITEASIN No indefinite arcsine
  2141. INSTR.NOINDEFINITEDSXY No indefinite derivative calculation
  2142. INSTR.NOINDEFINITELOG No indefinite logarithm
  2143. INSTR.NOREADINGUNINITIALIZED Instructions should not read uninitialized value
  2144. INSTR.NOUDIVBYZERO No unsigned integer division by zero
  2145. INSTR.OFFSETONUAVLOAD uav load don't support offset
  2146. INSTR.OLOAD DXIL intrinsic overload must be valid
  2147. INSTR.ONLYONEALLOCCONSUME RWStructuredBuffers may increment or decrement their counters, but not both.
  2148. INSTR.OPCODERESERVED Instructions must not reference reserved opcodes
  2149. INSTR.OPCONST DXIL intrinsic requires an immediate constant operand
  2150. INSTR.OPCONSTRANGE Constant values must be in-range for operation
  2151. INSTR.OPERANDRANGE DXIL intrinsic operand must be within defined range
  2152. INSTR.PTRBITCAST Pointer type bitcast must be have same size
  2153. INSTR.RESOURCECLASSFORLOAD load can only run on UAV/SRV resource
  2154. INSTR.RESOURCECLASSFORSAMPLERGATHER sample, lod and gather should on srv resource.
  2155. INSTR.RESOURCECLASSFORUAVSTORE store should on uav resource.
  2156. INSTR.RESOURCECOORDINATEMISS coord uninitialized
  2157. INSTR.RESOURCECOORDINATETOOMANY out of bound coord must be undef
  2158. INSTR.RESOURCEKINDFORBUFFERLOADSTORE buffer load/store only works on Raw/Typed/StructuredBuffer
  2159. INSTR.RESOURCEKINDFORCALCLOD lod requires resource declared as texture1D/2D/3D/Cube/CubeArray/1DArray/2DArray
  2160. INSTR.RESOURCEKINDFORGATHER gather requires resource declared as texture/2D/Cube/2DArray/CubeArray
  2161. INSTR.RESOURCEKINDFORGETDIM Invalid resource kind on GetDimensions
  2162. INSTR.RESOURCEKINDFORSAMPLE sample/_l/_d requires resource declared as texture1D/2D/3D/Cube/1DArray/2DArray/CubeArray
  2163. INSTR.RESOURCEKINDFORSAMPLEC samplec requires resource declared as texture1D/2D/Cube/1DArray/2DArray/CubeArray
  2164. INSTR.RESOURCEKINDFORTEXTURELOAD texture load only works on Texture1D/1DArray/2D/2DArray/3D/MS2D/MS2DArray
  2165. INSTR.RESOURCEKINDFORTEXTURESTORE texture store only works on Texture1D/1DArray/2D/2DArray/3D
  2166. INSTR.RESOURCEOFFSETMISS offset uninitialized
  2167. INSTR.RESOURCEOFFSETTOOMANY out of bound offset must be undef
  2168. INSTR.SAMPLECOMPTYPE sample_* instructions require resource to be declared to return UNORM, SNORM or FLOAT.
  2169. INSTR.SAMPLEINDEXFORLOAD2DMS load on Texture2DMS/2DMSArray require sampleIndex
  2170. INSTR.SAMPLERMODEFORLOD lod instruction requires sampler declared in default mode
  2171. INSTR.SAMPLERMODEFORSAMPLE sample/_l/_d/_cl_s/gather instruction requires sampler declared in default mode
  2172. INSTR.SAMPLERMODEFORSAMPLEC sample_c_*/gather_c instructions require sampler declared in comparison mode
  2173. INSTR.STRUCTBITCAST Bitcast on struct types is not allowed
  2174. INSTR.TEXTUREOFFSET offset texture instructions must take offset which can resolve to integer literal in the range -8 to 7
  2175. INSTR.TGSMRACECOND Race condition writing to shared memory detected, consider making this write conditional
  2176. INSTR.UNDEFRESULTFORGETDIMENSION GetDimensions used undef dimension %0 on %1
  2177. INSTR.WRITEMASKFORTYPEDUAVSTORE store on typed uav must write to all four components of the UAV
  2178. INSTR.WRITEMASKMATCHVALUEFORUAVSTORE uav store write mask must match store value mask, write mask is %0 and store value mask is %1
  2179. META.BARYCENTRICSFLOAT3 only 'float3' type is allowed for SV_Barycentrics.
  2180. META.BARYCENTRICSINTERPOLATION SV_Barycentrics cannot be used with 'nointerpolation' type
  2181. META.BARYCENTRICSTWOPERSPECTIVES There can only be up to two input attributes of SV_Barycentrics with different perspective interpolation mode.
  2182. META.BRANCHFLATTEN Can't use branch and flatten attributes together
  2183. META.CLIPCULLMAXCOMPONENTS Combined elements of SV_ClipDistance and SV_CullDistance must fit in 8 components
  2184. META.CLIPCULLMAXROWS Combined elements of SV_ClipDistance and SV_CullDistance must fit in two rows.
  2185. META.CONTROLFLOWHINTNOTONCONTROLFLOW Control flow hint only works on control flow inst
  2186. META.DENSERESIDS Resource identifiers must be zero-based and dense
  2187. META.DUPLICATESYSVALUE System value may only appear once in signature
  2188. META.ENTRYFUNCTION entrypoint not found
  2189. META.FLAGSUSAGE Flags must match usage
  2190. META.FORCECASEONSWITCH Attribute forcecase only works for switch
  2191. META.FPFLAG Invalid funciton floating point flag.
  2192. META.FUNCTIONANNOTATION Cannot find function annotation for %0
  2193. META.GLCNOTONAPPENDCONSUME globallycoherent cannot be used with append/consume buffers
  2194. META.INTEGERINTERPMODE Interpolation mode on integer must be Constant
  2195. META.INTERPMODEINONEROW Interpolation mode must be identical for all elements packed into the same row.
  2196. META.INTERPMODEVALID Interpolation mode must be valid
  2197. META.INVALIDCONTROLFLOWHINT Invalid control flow hint
  2198. META.KNOWN Named metadata should be known
  2199. META.MAXTESSFACTOR Hull Shader MaxTessFactor must be [%0..%1]. %2 specified
  2200. META.NOSEMANTICOVERLAP Semantics must not overlap
  2201. META.REQUIRED TODO - Required metadata missing
  2202. META.SEMAKINDMATCHESNAME Semantic name must match system value, when defined.
  2203. META.SEMAKINDVALID Semantic kind must be valid
  2204. META.SEMANTICCOMPTYPE %0 must be %1
  2205. META.SEMANTICINDEXMAX System value semantics have a maximum valid semantic index
  2206. META.SEMANTICLEN Semantic length must be at least 1 and at most 64
  2207. META.SEMANTICSHOULDBEALLOCATED Semantic should have a valid packing location
  2208. META.SEMANTICSHOULDNOTBEALLOCATED Semantic should have a packing location of -1
  2209. META.SIGNATURECOMPTYPE signature %0 specifies unrecognized or invalid component type
  2210. META.SIGNATUREDATAWIDTH Data width must be identical for all elements packed into the same row.
  2211. META.SIGNATUREILLEGALCOMPONENTORDER Component ordering for packed elements must be: arbitrary < system value < system generated value
  2212. META.SIGNATUREINDEXCONFLICT Only elements with compatible indexing rules may be packed together
  2213. META.SIGNATUREOUTOFRANGE Signature elements must fit within maximum signature size
  2214. META.SIGNATUREOVERLAP Signature elements may not overlap in packing location.
  2215. META.STRUCTBUFALIGNMENT StructuredBuffer stride not aligned
  2216. META.STRUCTBUFALIGNMENTOUTOFBOUND StructuredBuffer stride out of bounds
  2217. META.SYSTEMVALUEROWS System value may only have 1 row
  2218. META.TARGET Target triple must be 'dxil-ms-dx'
  2219. META.TESSELLATOROUTPUTPRIMITIVE Invalid Tessellator Output Primitive specified. Must be point, line, triangleCW or triangleCCW.
  2220. META.TESSELLATORPARTITION Invalid Tessellator Partitioning specified. Must be integer, pow2, fractional_odd or fractional_even.
  2221. META.TEXTURETYPE elements of typed buffers and textures must fit in four 32-bit quantities
  2222. META.USED All metadata must be used by dxil
  2223. META.VALIDSAMPLERMODE Invalid sampler mode on sampler
  2224. META.VALUERANGE Metadata value must be within range
  2225. META.WELLFORMED TODO - Metadata must be well-formed in operand count and types
  2226. 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.
  2227. SM.CBUFFERELEMENTOVERFLOW CBuffer elements must not overflow
  2228. SM.CBUFFEROFFSETOVERLAP CBuffer offsets must not overlap
  2229. SM.CBUFFERTEMPLATETYPEMUSTBESTRUCT D3D12 constant/texture buffer template element can only be a struct
  2230. SM.COMPLETEPOSITION Not all elements of SV_Position were written
  2231. SM.COUNTERONLYONSTRUCTBUF BufferUpdateCounter valid only on structured buffers
  2232. SM.CSNORETURN Compute shaders can't return values, outputs must be written in writable resources (UAVs).
  2233. SM.DOMAINLOCATIONIDXOOB DomainLocation component index out of bounds for the domain.
  2234. SM.DSINPUTCONTROLPOINTCOUNTRANGE DS input control point count must be [0..%0]. %1 specified
  2235. SM.DXILVERSION Target shader model requires specific Dxil Version
  2236. SM.GSINSTANCECOUNTRANGE GS instance count must be [1..%0]. %1 specified
  2237. SM.GSOUTPUTVERTEXCOUNTRANGE GS output vertex count must be [0..%0]. %1 specified
  2238. 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
  2239. SM.GSVALIDINPUTPRIMITIVE GS input primitive unrecognized
  2240. SM.GSVALIDOUTPUTPRIMITIVETOPOLOGY GS output primitive topology unrecognized
  2241. SM.HSINPUTCONTROLPOINTCOUNTRANGE HS input control point count must be [0..%0]. %1 specified
  2242. SM.HULLPASSTHRUCONTROLPOINTCOUNTMATCH For pass thru hull shader, input control point count must match output control point count
  2243. SM.INSIDETESSFACTORSIZEMATCHDOMAIN InsideTessFactor rows, columns (%0, %1) invalid for domain %2. Expected %3 rows and 1 column.
  2244. SM.INVALIDRESOURCECOMPTYPE Invalid resource return type
  2245. SM.INVALIDRESOURCEKIND Invalid resources kind
  2246. SM.INVALIDTEXTUREKINDONUAV Texture2DMS[Array] or TextureCube[Array] resources are not supported with UAVs
  2247. 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.
  2248. SM.MAXTGSMSIZE Total Thread Group Shared Memory storage is %0, exceeded %1
  2249. SM.MAXTHEADGROUP Declared Thread Group Count %0 (X*Y*Z) is beyond the valid maximum of %1
  2250. SM.MULTISTREAMMUSTBEPOINT When multiple GS output streams are used they must be pointlists
  2251. SM.NAME Target shader model name must be known
  2252. SM.NOINTERPMODE Interpolation mode must be undefined for VS input/PS output/patch constant.
  2253. SM.NOPSOUTPUTIDX Pixel shader output registers are not indexable.
  2254. SM.OPCODE Opcode must be defined in target shader model
  2255. SM.OPCODEININVALIDFUNCTION Invalid DXIL opcode usage like StorePatchConstant in patch constant function
  2256. SM.OPERAND Operand must be defined in target shader model
  2257. SM.OUTPUTCONTROLPOINTCOUNTRANGE output control point count must be [0..%0]. %1 specified
  2258. SM.OUTPUTCONTROLPOINTSTOTALSCALARS Total number of scalars across all HS output control points must not exceed
  2259. SM.PATCHCONSTANTONLYFORHSDS patch constant signature only valid in HS and DS
  2260. 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)
  2261. SM.PSCOVERAGEANDINNERCOVERAGE InnerCoverage and Coverage are mutually exclusive.
  2262. SM.PSMULTIPLEDEPTHSEMANTIC Pixel Shader only allows one type of depth semantic to be declared
  2263. SM.PSOUTPUTSEMANTIC Pixel Shader allows output semantics to be SV_Target, SV_Depth, SV_DepthGreaterEqual, SV_DepthLessEqual, SV_Coverage or SV_StencilRef, %0 found
  2264. SM.PSTARGETCOL0 SV_Target packed location must start at column 0
  2265. SM.PSTARGETINDEXMATCHESROW SV_Target semantic index must match packed row location
  2266. SM.RESOURCERANGEOVERLAP Resource ranges must not overlap
  2267. SM.ROVONLYINPS RasterizerOrdered objects are only allowed in 5.0+ pixel shaders
  2268. SM.SAMPLECOUNTONLYON2DMS Only Texture2DMS/2DMSArray could has sample count
  2269. SM.SEMANTIC Semantic must be defined in target shader model
  2270. SM.STREAMINDEXRANGE Stream index (%0) must between 0 and %1
  2271. SM.TESSFACTORFORDOMAIN Required TessFactor for domain not found declared anywhere in Patch Constant data
  2272. SM.TESSFACTORSIZEMATCHDOMAIN TessFactor rows, columns (%0, %1) invalid for domain %2. Expected %3 rows and 1 column.
  2273. SM.THREADGROUPCHANNELRANGE Declared Thread Group %0 size %1 outside valid range [%2..%3]
  2274. 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
  2275. SM.UNDEFINEDOUTPUT Not all elements of output %0 were written
  2276. SM.VALIDDOMAIN Invalid Tessellator Domain specified. Must be isoline, tri or quad
  2277. SM.VIEWIDNEEDSSLOT ViewID requires compatible space in pixel shader input signature
  2278. SM.ZEROHSINPUTCONTROLPOINTWITHINPUT When HS input control point count is 0, no input signature should exist
  2279. TYPES.DEFINED Type must be defined based on DXIL primitives
  2280. TYPES.I8 I8 can only used as immediate value for intrinsic
  2281. TYPES.INTWIDTH Int type must be of valid width
  2282. TYPES.NOMULTIDIM Only one dimension allowed for array type
  2283. TYPES.NOVECTOR Vector types must not be present
  2284. UNI.NOWAVESENSITIVEGRADIENT Gradient operations are not affected by wave-sensitive data or control flow.
  2285. ====================================== =======================================================================================================================================================================================================================================================================================================
  2286. .. VALRULES-RST:END
  2287. Modules and Linking
  2288. ===================
  2289. HLSL has linking capabilities to enable third-party libraries. The linking step happens before shader DXIL is given to the driver compilers.
  2290. Experimental library generation is added in DXIL1.1. A library could be created by compile with lib_6_1 profile.
  2291. 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.
  2292. Library support is not part of DXIL spec. Only requirement is linked shader must be valid DXIL.
  2293. Additional Notes
  2294. ================
  2295. These additional notes are not normative for DXIL, and are included for the convenience of implementers.
  2296. Other Versioned Components
  2297. --------------------------
  2298. 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.
  2299. Support is provided in the Microsoft Windows family of operating systems, when running on the D3D12 runtime.
  2300. 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).
  2301. .. _dxil_container_format:
  2302. DXIL Container Format
  2303. ---------------------
  2304. 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.
  2305. The following C declaration describes this structure::
  2306. struct DxilContainerHeader {
  2307. uint32_t HeaderFourCC;
  2308. uint8_t Digest[DxilContainerHashSize];
  2309. uint16_t MajorVersion;
  2310. uint16_t MinorVersion;
  2311. uint32_t ContainerSizeInBytes; // From start of this header
  2312. uint32_t PartCount;
  2313. // Structure is followed by uint32_t PartOffset[PartCount];
  2314. // The offset is to a DxilPartHeader.
  2315. };
  2316. Each part has a standard header, followed by a part-specify body::
  2317. struct DxilPartHeader {
  2318. uint32_t PartFourCC; // Four char code for part type.
  2319. uint32_t PartSize; // Byte count for PartData.
  2320. // Structure is followed by uint8_t PartData[PartSize].
  2321. };
  2322. The DXIL program is found in a part with the following body::
  2323. struct DxilProgramHeader {
  2324. uint32_t ProgramVersion; /// Major and minor version of shader, including type.
  2325. uint32_t SizeInUint32; /// Size in uint32_t units including this header.
  2326. uint32_t DxilMagic; // 0x4C495844, ASCII "DXIL".
  2327. uint32_t DxilVersion; // DXIL version.
  2328. uint32_t BitcodeOffset; // Offset to LLVM bitcode (from DxilMagic).
  2329. uint32_t BitcodeSize; // Size of LLVM bitcode.
  2330. // Followed by uint8_t[BitcodeHeader.BitcodeSize] after possible gap from BitcodeOffset
  2331. };
  2332. The bitcode payload is defined as per bitcode encoding.
  2333. Future Directions
  2334. -----------------
  2335. This section provides background on future directions for DXIL that may or may not materialize. They imply a new version of DXIL.
  2336. 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.
  2337. 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.
  2338. 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.
  2339. 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.
  2340. The target machine specification for HLSL might specify a 64-bit pointer side with 64-bit offsets.
  2341. Hardware support for generic pointer is essential for HLSL next as a fallback mechanism for cases when compiler cannot disambiguate pointer's address space.
  2342. Future DXIL will change how half and i16 are treated:
  2343. * i16 will have to be supported natively either in hardware or via emulation,
  2344. * 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.
  2345. Pending Specification Work
  2346. ==========================
  2347. The following work on this specification is still pending:
  2348. * Consider moving some additional tables and lists into hctdb and cross-reference.
  2349. * Complete the extended documentation for instructions.