1 /*
2 * Copyright © 2023 Intel 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 /**
25 * This file implements the lowering required for
26 * VK_EXT_extended_dynamic_state2 extendedDynamicState2PatchControlPoints.
27 *
28 * When VK_DYNAMIC_STATE_PATCH_CONTROL_POINTS_EXT is set on a pipeline, we
29 * need to compile the TCS shader assuming the max (32) number of control
30 * points. The actually value is provided through push constants.
31 */
32
33 #include "anv_nir.h"
34 #include "nir_builder.h"
35
36 #define sizeof_field(type, field) sizeof(((type *)0)->field)
37
38 static bool
lower_patch_vertices_in_instr(nir_builder * b,nir_intrinsic_instr * load,UNUSED void * _data)39 lower_patch_vertices_in_instr(nir_builder *b, nir_intrinsic_instr *load,
40 UNUSED void *_data)
41 {
42 if (load->intrinsic != nir_intrinsic_load_patch_vertices_in)
43 return false;
44
45 b->cursor = nir_before_instr(&load->instr);
46
47 nir_def_rewrite_uses(
48 &load->def,
49 anv_load_driver_uniform(b, 1, gfx.tcs_input_vertices));
50 nir_instr_remove(&load->instr);
51
52 return true;
53 }
54
55 bool
anv_nir_lower_load_patch_vertices_in(nir_shader * shader)56 anv_nir_lower_load_patch_vertices_in(nir_shader *shader)
57 {
58 return nir_shader_intrinsics_pass(shader, lower_patch_vertices_in_instr,
59 nir_metadata_control_flow,
60 NULL);
61 }
62