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 D3D12_COMPILER_H 25 #define D3D12_COMPILER_H 26 27 #include "dxil_nir_lower_int_samplers.h" 28 29 #include "pipe/p_defines.h" 30 #include "pipe/p_state.h" 31 32 #include "compiler/shader_info.h" 33 #include "program/prog_statevars.h" 34 35 #include "nir.h" 36 37 struct pipe_screen; 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 enum d3d12_state_var { 44 D3D12_STATE_VAR_Y_FLIP = 0, 45 D3D12_STATE_VAR_PT_SPRITE, 46 D3D12_STATE_VAR_FIRST_VERTEX, 47 D3D12_STATE_VAR_DEPTH_TRANSFORM, 48 D3D12_MAX_STATE_VARS 49 }; 50 51 #define D3D12_MAX_POINT_SIZE 255.0f 52 53 struct d3d12_validation_tools *d3d12_validator_create(); 54 55 void d3d12_validator_destroy(struct d3d12_validation_tools *validator); 56 57 const void * 58 d3d12_get_compiler_options(struct pipe_screen *screen, 59 enum pipe_shader_ir ir, 60 enum pipe_shader_type shader); 61 62 struct d3d12_varying_info { 63 struct { 64 const struct glsl_type *type; 65 unsigned interpolation:3; // INTERP_MODE_COUNT = 5 66 unsigned driver_location:6; // VARYING_SLOT_MAX = 64 67 } vars[VARYING_SLOT_MAX]; 68 uint64_t mask; 69 }; 70 71 struct d3d12_shader_key { 72 enum pipe_shader_type stage; 73 74 struct d3d12_varying_info required_varying_inputs; 75 struct d3d12_varying_info required_varying_outputs; 76 uint64_t next_varying_inputs; 77 uint64_t prev_varying_outputs; 78 unsigned last_vertex_processing_stage : 1; 79 unsigned invert_depth : 1; 80 unsigned samples_int_textures : 1; 81 unsigned tex_saturate_s : PIPE_MAX_SAMPLERS; 82 unsigned tex_saturate_r : PIPE_MAX_SAMPLERS; 83 unsigned tex_saturate_t : PIPE_MAX_SAMPLERS; 84 85 struct { 86 unsigned needs_format_emulation:1; 87 enum pipe_format format_conversion[PIPE_MAX_ATTRIBS]; 88 } vs; 89 90 struct { 91 unsigned sprite_coord_enable:24; 92 unsigned sprite_origin_upper_left:1; 93 unsigned point_pos_stream_out:1; 94 unsigned writes_psize:1; 95 unsigned point_size_per_vertex:1; 96 unsigned aa_point:1; 97 unsigned stream_output_factor:3; 98 unsigned primitive_id:1; 99 unsigned triangle_strip:1; 100 } gs; 101 102 struct { 103 unsigned missing_dual_src_outputs : 2; 104 unsigned frag_result_color_lowering : 4; 105 unsigned cast_to_uint : 1; 106 unsigned cast_to_int : 1; 107 unsigned provoking_vertex : 2; 108 unsigned manual_depth_range : 1; 109 unsigned polygon_stipple : 1; 110 unsigned remap_front_facing : 1; 111 } fs; 112 113 int n_texture_states; 114 dxil_wrap_sampler_state tex_wrap_states[PIPE_MAX_SHADER_SAMPLER_VIEWS]; 115 dxil_texture_swizzle_state swizzle_state[PIPE_MAX_SHADER_SAMPLER_VIEWS]; 116 enum compare_func sampler_compare_funcs[PIPE_MAX_SHADER_SAMPLER_VIEWS]; 117 }; 118 119 struct d3d12_shader { 120 void *bytecode; 121 size_t bytecode_length; 122 123 nir_shader *nir; 124 125 struct { 126 unsigned binding; 127 } cb_bindings[PIPE_MAX_CONSTANT_BUFFERS]; 128 size_t num_cb_bindings; 129 130 struct { 131 enum d3d12_state_var var; 132 unsigned offset; 133 } state_vars[D3D12_MAX_STATE_VARS]; 134 unsigned num_state_vars; 135 size_t state_vars_size; 136 bool state_vars_used; 137 138 struct { 139 int binding; 140 uint32_t dimension; 141 } srv_bindings[PIPE_MAX_SHADER_SAMPLER_VIEWS]; 142 size_t begin_srv_binding; 143 size_t end_srv_binding; 144 145 bool has_default_ubo0; 146 unsigned pstipple_binding; 147 148 struct d3d12_shader_key key; 149 struct d3d12_shader *next_variant; 150 }; 151 152 struct d3d12_gs_variant_key 153 { 154 unsigned passthrough:1; 155 unsigned provoking_vertex:3; 156 unsigned alternate_tri:1; 157 unsigned fill_mode:2; 158 unsigned cull_mode:2; 159 unsigned has_front_face:1; 160 unsigned front_ccw:1; 161 unsigned edge_flag_fix:1; 162 unsigned flatshade_first:1; 163 uint64_t flat_varyings; 164 struct d3d12_varying_info varyings; 165 }; 166 167 struct d3d12_shader_selector { 168 enum pipe_shader_type stage; 169 nir_shader *initial; 170 struct d3d12_shader *first; 171 struct d3d12_shader *current; 172 173 struct pipe_stream_output_info so_info; 174 175 unsigned samples_int_textures:1; 176 unsigned compare_with_lod_bias_grad:1; 177 178 bool is_gs_variant; 179 struct d3d12_gs_variant_key gs_key; 180 }; 181 182 struct d3d12_context; 183 184 struct d3d12_shader_selector * 185 d3d12_create_shader(struct d3d12_context *ctx, 186 enum pipe_shader_type stage, 187 const struct pipe_shader_state *shader); 188 189 void 190 d3d12_shader_free(struct d3d12_shader_selector *shader); 191 192 void 193 d3d12_select_shader_variants(struct d3d12_context *ctx, 194 const struct pipe_draw_info *dinfo); 195 196 void 197 d3d12_gs_variant_cache_init(struct d3d12_context *ctx); 198 199 void 200 d3d12_gs_variant_cache_destroy(struct d3d12_context *ctx); 201 202 struct d3d12_shader_selector * 203 d3d12_get_gs_variant(struct d3d12_context *ctx, struct d3d12_gs_variant_key *key); 204 205 #ifdef __cplusplus 206 } 207 #endif 208 209 #endif 210