xref: /aosp_15_r20/external/mesa3d/src/microsoft/vulkan/dzn_nir.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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 DZN_NIR_H
25 #define DZN_NIR_H
26 
27 #define D3D12_IGNORE_SDK_LAYERS
28 #define COBJMACROS
29 #include <unknwn.h>
30 #include <directx/d3d12.h>
31 
32 #include "nir.h"
33 
34 struct dzn_indirect_draw_rewrite_params {
35    uint32_t draw_buf_stride;
36 };
37 
38 struct dzn_indirect_draw_triangle_fan_rewrite_params {
39    uint32_t draw_buf_stride;
40    uint32_t triangle_fan_index_buf_stride;
41    uint64_t triangle_fan_index_buf_start;
42 };
43 
44 struct dzn_indirect_draw_triangle_fan_prim_restart_rewrite_params {
45    uint32_t draw_buf_stride;
46    uint32_t triangle_fan_index_buf_stride;
47    uint64_t triangle_fan_index_buf_start;
48    uint64_t exec_buf_start;
49 };
50 
51 struct dzn_triangle_fan_rewrite_index_params {
52    uint32_t first_index;
53 };
54 
55 struct dzn_triangle_fan_prim_restart_rewrite_index_params {
56    uint32_t first_index;
57    uint32_t index_count;
58 };
59 
60 struct dzn_indirect_triangle_fan_rewrite_index_exec_params {
61    uint64_t new_index_buf;
62    struct dzn_triangle_fan_rewrite_index_params params;
63    struct {
64       uint32_t x, y, z;
65    } group_count;
66 };
67 
68 struct dzn_indirect_triangle_fan_prim_restart_rewrite_index_exec_params {
69    uint64_t new_index_buf;
70    struct dzn_triangle_fan_prim_restart_rewrite_index_params params;
71    uint64_t index_count_ptr;
72    struct {
73       uint32_t x, y, z;
74    } group_count;
75 };
76 
77 struct dzn_indirect_draw_type {
78    union {
79       struct {
80          uint8_t indexed : 1;
81          uint8_t indirect_count : 1;
82          uint8_t draw_params : 1;
83          uint8_t draw_id : 1;
84          uint8_t triangle_fan : 1;
85          uint8_t triangle_fan_primitive_restart : 1;
86       };
87       uint8_t value;
88    };
89 };
90 #define DZN_NUM_INDIRECT_DRAW_TYPES (1 << 6)
91 
92 nir_shader *
93 dzn_nir_indirect_draw_shader(struct dzn_indirect_draw_type type);
94 
95 nir_shader *
96 dzn_nir_triangle_fan_rewrite_index_shader(uint8_t old_index_size);
97 
98 nir_shader *
99 dzn_nir_triangle_fan_prim_restart_rewrite_index_shader(uint8_t old_index_size);
100 
101 enum dzn_blit_resolve_mode {
102    dzn_blit_resolve_none,
103    dzn_blit_resolve_average,
104    dzn_blit_resolve_min,
105    dzn_blit_resolve_max,
106    dzn_blit_resolve_sample_zero,
107 };
108 struct dzn_nir_blit_info {
109    union {
110       struct {
111          uint32_t src_samples : 6;
112          uint32_t loc : 4;
113          uint32_t out_type : 4;
114          uint32_t sampler_dim : 4;
115          uint32_t src_is_array : 1;
116          uint32_t resolve_mode : 3;
117          uint32_t stencil_fallback : 1;
118          uint32_t padding : 9;
119       };
120       const uint32_t hash_key;
121    };
122 };
123 
124 nir_shader *
125 dzn_nir_blit_vs(void);
126 
127 nir_shader *
128 dzn_nir_blit_fs(const struct dzn_nir_blit_info *info);
129 
130 struct dzn_nir_point_gs_info {
131    unsigned cull_mode;
132    bool front_ccw;
133    bool depth_bias;
134    bool depth_bias_dynamic;
135    DXGI_FORMAT ds_fmt;
136    /* Constant values */
137    float constant_depth_bias;
138    float slope_scaled_depth_bias;
139    float depth_bias_clamp;
140    /* Used for loading dynamic values */
141    struct {
142       uint32_t register_space;
143       uint32_t base_shader_register;
144    } runtime_data_cbv;
145 };
146 nir_shader *
147 dzn_nir_polygon_point_mode_gs(const nir_shader *vs, struct dzn_nir_point_gs_info *info);
148 
149 #endif
150