1 /*
2  * Copyright © Microsoft Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 #ifndef DXIL_SIGNATURE_H
25 #define DXIL_SIGNATURE_H
26 
27 #include "dxil_enums.h"
28 #include "nir.h"
29 #include "util/string_buffer.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /* struct taken from DXILContainer
36  * Enums values were replaced by uint32_t since they must occupy 32 bit
37  */
38 
39 struct dxil_signature_element {
40    uint32_t stream;                   // Stream index (parameters must appear in non-decreasing stream order)
41    uint32_t semantic_name_offset;     // Offset to char * stream from start of DxilProgramSignature.
42    uint32_t semantic_index;           // Semantic Index
43    uint32_t system_value;             // Semantic type. Similar to DxilSemantic::Kind, but a serialized rather than processing rep.
44    uint32_t comp_type;                // Type of bits.
45    uint32_t reg;                      // Register Index (row index)
46    uint8_t  mask;                     // Mask (column allocation)
47    union {                            // Unconditional cases useful for validation of shader linkage.
48       uint8_t never_writes_mask;      // For an output signature, the shader the signature belongs to never
49                                       // writes the masked components of the output register.
50       uint8_t always_reads_mask;      // For an input signature, the shader the signature belongs to always
51                                       // reads the masked components of the input register.
52    };
53    uint16_t pad;
54    uint32_t min_precision;             // Minimum precision of input/output data
55 };
56 
57 struct dxil_signature_record {
58    struct dxil_signature_element elements[32];
59    unsigned num_elements;
60    const char *sysvalue;
61    char *name;
62 };
63 
64 struct dxil_psv_sem_index_table {
65    uint32_t data[80];
66    uint32_t size;
67 };
68 
69 struct dxil_psv_signature_element {
70    uint32_t semantic_name_offset;          // Offset into StringTable
71    uint32_t semantic_indexes_offset;       // Offset into PSVSemanticIndexTable, count == Rows
72    uint8_t rows;                   // Number of rows this element occupies
73    uint8_t start_row;               // Starting row of packing location if allocated
74    uint8_t cols_and_start;           // 0:4 = Cols, 4:6 = StartCol, 6:7 == Allocated
75    uint8_t semantic_kind;           // PSVSemanticKind
76    uint8_t component_type;          // DxilProgramSigCompType
77    uint8_t interpolation_mode;      // DXIL::InterpolationMode or D3D10_SB_INTERPOLATION_MODE
78    uint8_t dynamic_mask_and_stream;   // 0:4 = DynamicIndexMask, 4:6 = OutputStream (0-3)
79    uint8_t reserved;
80 };
81 
82 struct dxil_psv_runtime_info_0 {
83    union {
84       struct {
85          char output_position_present;
86       } vs;
87 
88       struct {
89          uint32_t input_control_point_count;
90          uint32_t output_control_point_count;
91          uint32_t tessellator_domain;
92          uint32_t tessellator_output_primitive;
93       } hs;
94 
95       struct {
96          uint32_t input_control_point_count;
97          char output_position_present;
98          uint32_t tessellator_domain;
99       } ds;
100 
101       struct {
102          uint32_t input_primitive;
103          uint32_t output_toplology;
104          uint32_t output_stream_mask;
105          char output_position_present;
106       } gs;
107 
108       struct {
109          char depth_output;
110          char sample_frequency;
111       } ps;
112 
113       /* Maximum sized defining the union size (MSInfo)*/
114       struct {
115          uint32_t dummy1[3];
116          uint16_t dummy2[2];
117       } dummy;
118    };
119    uint32_t min_expected_wave_lane_count;  // minimum lane count required, 0 if unused
120    uint32_t max_expected_wave_lane_count;  // maximum lane count required, 0xffffffff if unused
121 };
122 
123 struct dxil_psv_runtime_info_1 {
124    struct dxil_psv_runtime_info_0 psv0;
125    uint8_t shader_stage;              // PSVShaderKind
126    uint8_t uses_view_id;
127    union {
128      uint16_t max_vertex_count;          // MaxVertexCount for GS only (max 1024)
129      uint8_t sig_patch_const_or_prim_vectors;  // Output for HS; Input for DS; Primitive output for MS (overlaps MS1::SigPrimVectors)
130      // struct { uint8_t dummy[2]; } fill;
131    };
132 
133    // PSVSignatureElement counts
134    uint8_t sig_input_elements;
135    uint8_t sig_output_elements;
136    uint8_t sig_patch_const_or_prim_elements;
137 
138    // Number of packed vectors per signature
139    uint8_t sig_input_vectors;
140    uint8_t sig_output_vectors[4];
141 };
142 
143 struct dxil_mdnode;
144 struct dxil_module;
145 
146 const struct dxil_mdnode *
147 get_signatures(struct dxil_module *mod, nir_shader *s, bool vulkan, unsigned input_clip_size);
148 
149 #ifdef __cplusplus
150 }
151 #endif
152 
153 #endif
154