Skip to content

Commit ee13241

Browse files
committed
Add a section describing Shader Model based constraint specification.
1 parent 52ca055 commit ee13241

File tree

1 file changed

+74
-8
lines changed

1 file changed

+74
-8
lines changed

llvm/docs/DirectX/DXILOpTableGenDesign.rst

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,6 @@ this option.
262262
This specification option allows for readable, compact yet expressive
263263
representation of DXIL Ops without any duplication of information.
264264

265-
Specify accepted overload types as attribute records
266-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
267-
Various other properties of a DXIL Op (such as the ``bool is_*`` and
268-
``shader_model`` viz., minimum shader model required) can
269-
be uniformly represented as ``DXILAttribute`` records. These attributes
270-
provide the filters to apply for generation of C++ code guarded by
271-
``#ifdef .. #endif`` in ``DXILOperation.inc`` by ``DXILEmitter`` backend code.
272-
273265
Option 4 : Specify a function to validate accepted overload types
274266
-----------------------------------------------------------------
275267

@@ -298,6 +290,76 @@ valid overload types lacks the clear expressiveness and declarative readability
298290
of an explicit specification. In addition, validation functions add to the
299291
maintenance overhead while not necessarily making the specification more readable.
300292

293+
Specification of Valid Overload Types for Shader Models
294+
-------------------------------------------------------
295+
Depending on the Shader Model, valid overload types for some DXIL Ops
296+
differ. For example, ``float`` is valid overload type in ``Sin`` for SM 6.0
297+
and later, while ``half`` and ``float`` are valid overload types for ``Sin`` in
298+
SM 6.2 and later. Expressing such constraints in DXIL Ops records is needed
299+
to ensure valid code generation by DXIL Lowering pass.
300+
301+
This information may be specified by associating the Shader Model with
302+
corresponding valid overload type as pairs (e.g., (``<ShaderModel, OverloadTypeList>``).
303+
As a result, the field ``OpTypes`` in ``class DXILOpMappingBase`` specified in
304+
`DesignSection`_ may be changed to
305+
306+
.. code-block::
307+
308+
list<DXILOpOverload> OpOverloadTypes = ?; // Valid list of <SM, OLType>
309+
310+
where,
311+
312+
.. code-block::
313+
314+
// Abstract class to specify minimum Shader model version required
315+
// to support DXIL Op
316+
class DXILShaderModel<int major, int minor> {
317+
int Major = major;
318+
int Minor = minor;
319+
}
320+
321+
// Valid minimum Shader model version records
322+
323+
// Shader Model 6.x
324+
def SM6_0 : DXILShaderModel<6, 0>;
325+
...
326+
def SM6_2 : DXILShaderModel<6, 2>;
327+
...
328+
329+
// Abstract class mapping valid DXIL Op overloads the minimum
330+
// version of Shader Model they are supported
331+
class DXILOpOverload<DXILShaderModel minsm, list<LLVMType> overloads> {
332+
DXILShaderModel ShaderModel = minsm;
333+
list<LLVMType> OpOverloads = overloads;
334+
}
335+
336+
Using the above notation, following is the specification of ``Sin``
337+
using Option 3.
338+
339+
.. code-block::
340+
341+
let OpClass = unary,
342+
OpOverloadTypes = [DXILOpOverload<SM6_0, [llvm_float_ty]>,
343+
DXILOpOverload<SM6_2, [llvm_half_ty, llvm_float_ty]>] in {
344+
def Sin : DXILOpMapping<13, int_sin,
345+
"Returns sine(theta) for theta in radians.">;
346+
347+
With Option 1, a slightly different representation of the may be employed
348+
349+
.. code-block::
350+
351+
let Optypes = [[DXILOpOverload<SM6_0, [llvm_float_ty]>,
352+
[DXILOpOverload<SM6_0, [llvm_half_ty]>,
353+
[DXILOpOverload<SM6_2, [llvm_float_ty]>]
354+
def Sin : ...
355+
356+
which will be more verbose while, not availing the classification
357+
of DXIL Op classes' prototype information which is possible with Option 3.
358+
359+
Option 2 that inherits overload types from LLVM Intrinsic specification with
360+
no representation for constraints, does not lend itself to be a readable, and
361+
expressive qspecification of Shader Model based valid overload types.
362+
301363
Summary
302364
=======
303365

@@ -310,3 +372,7 @@ implementation employs Option 2a. It is in place, primarily, to facilitate conti
310372
lowering of new LLVM intrinsics for HLSL functions being added in the front end. It
311373
serves to uncover any additional considerations necessary for an improved design of
312374
``DXIL.td``.
375+
376+
Option 3, however, is emerging to be better alternative for a specification that
377+
allows for readable, compact yet expressive representation of DXIL Ops that is
378+
capable of validation rule specification without duplication of information.

0 commit comments

Comments
 (0)