• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017 Advanced Micro Devices, Inc.
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  * on the rights to use, copy, modify, merge, publish, distribute, sub
8  * license, and/or sell copies of the Software, and to permit persons to whom
9  * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21  * USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
24 #ifndef AC_SHADER_ABI_H
25 #define AC_SHADER_ABI_H
26 
27 #include "ac_shader_args.h"
28 #include "ac_shader_util.h"
29 #include "compiler/shader_enums.h"
30 #include "nir.h"
31 #include <llvm-c/Core.h>
32 
33 #include <assert.h>
34 
35 #define AC_LLVM_MAX_OUTPUTS (VARYING_SLOT_VAR31 + 1)
36 
37 /* Document the shader ABI during compilation. This is what allows radeonsi and
38  * radv to share a compiler backend.
39  */
40 struct ac_shader_abi {
41    /* Each entry is a pointer to a f32 or a f16 value (only possible for FS) */
42    LLVMValueRef outputs[AC_LLVM_MAX_OUTPUTS * 4];
43    bool is_16bit[AC_LLVM_MAX_OUTPUTS * 4];
44 
45    /* These input registers sometimes need to be fixed up. */
46    LLVMValueRef vertex_id;
47    LLVMValueRef instance_id;
48    LLVMValueRef persp_centroid, linear_centroid;
49    LLVMValueRef color0, color1;
50    LLVMValueRef user_data;
51 
52    /* Varying -> attribute number mapping. Also NIR-only */
53    unsigned fs_input_attr_indices[MAX_VARYING];
54 
55    void (*export_vertex)(struct ac_shader_abi *abi);
56 
57    void (*emit_vertex)(struct ac_shader_abi *abi, unsigned stream, LLVMValueRef *addrs);
58 
59    void (*emit_primitive)(struct ac_shader_abi *abi, unsigned stream);
60 
61    void (*emit_vertex_with_counter)(struct ac_shader_abi *abi, unsigned stream,
62                                     LLVMValueRef vertexidx, LLVMValueRef *addrs);
63 
64    LLVMValueRef (*load_inputs)(struct ac_shader_abi *abi,
65                                unsigned driver_location, unsigned component,
66                                unsigned num_components, unsigned vertex_index,
67                                LLVMTypeRef type);
68 
69    LLVMValueRef (*load_tess_varyings)(struct ac_shader_abi *abi, LLVMTypeRef type,
70                                       LLVMValueRef vertex_index, LLVMValueRef param_index,
71                                       unsigned driver_location, unsigned component,
72                                       unsigned num_components, bool load_inputs);
73 
74    LLVMValueRef (*load_ubo)(struct ac_shader_abi *abi, LLVMValueRef index);
75 
76    /**
77     * Load the descriptor for the given buffer.
78     *
79     * \param buffer the buffer as presented in NIR: this is the descriptor
80     *               in Vulkan, and the buffer index in OpenGL/Gallium
81     * \param write whether buffer contents will be written
82     * \param non_uniform whether the buffer descriptor is not assumed to be uniform
83     */
84    LLVMValueRef (*load_ssbo)(struct ac_shader_abi *abi, LLVMValueRef buffer, bool write, bool non_uniform);
85 
86    /**
87     * Load a descriptor associated to a sampler.
88     *
89     * \param descriptor_set the descriptor set index (only for Vulkan)
90     * \param base_index the base index of the sampler variable
91     * \param constant_index constant part of an array index (or 0, if the
92     *                       sampler variable is not an array)
93     * \param index non-constant part of an array index (may be NULL)
94     * \param desc_type the type of descriptor to load
95     * \param image whether the descriptor is loaded for an image operation
96     */
97    LLVMValueRef (*load_sampler_desc)(struct ac_shader_abi *abi, unsigned descriptor_set,
98                                      unsigned base_index, unsigned constant_index,
99                                      LLVMValueRef index, enum ac_descriptor_type desc_type,
100                                      bool image, bool write, bool bindless);
101 
102    LLVMValueRef (*load_sample_position)(struct ac_shader_abi *abi, LLVMValueRef sample_id);
103 
104    LLVMValueRef (*emit_fbfetch)(struct ac_shader_abi *abi);
105 
106    LLVMValueRef (*intrinsic_load)(struct ac_shader_abi *abi, nir_intrinsic_op op);
107 
108    /* Whether to clamp the shadow reference value to [0,1]on GFX8. Radeonsi currently
109     * uses it due to promoting D16 to D32, but radv needs it off. */
110    bool clamp_shadow_reference;
111    bool interp_at_sample_force_center;
112 
113    /* Whether bounds checks are required */
114    bool robust_buffer_access;
115 
116    /* Check for Inf interpolation coeff */
117    bool kill_ps_if_inf_interp;
118 
119    /* Whether undef values must be converted to zero */
120    bool convert_undef_to_zero;
121 
122    /* Clamp div by 0 (so it won't produce NaN) */
123    bool clamp_div_by_zero;
124 
125    /* Whether to inline the compute dispatch size in user sgprs. */
126    bool load_grid_size_from_user_sgpr;
127 
128    /* Whether to detect divergent textures/samplers index and apply
129     * waterfall to avoid incorrect rendering. */
130    bool use_waterfall_for_divergent_tex_samplers;
131 
132    /* Number of all interpolated inputs */
133    unsigned num_interp;
134 };
135 
136 #endif /* AC_SHADER_ABI_H */
137