Merge remote-tracking branch 'mesa-public/master' into vulkan
[mesa.git] / src / vulkan / anv_nir_builder.h
1 /*
2 * Copyright © 2015 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 #include "anv_nir.h"
25 #include "glsl/nir/nir_builder.h"
26 #include "util/ralloc.h"
27
28 /* This file includes NIR helpers used by meta shaders in the Vulkan
29 * driver. Eventually, these will all be merged into nir_builder.
30 * However, for now, keeping them in their own file helps to prevent merge
31 * conflicts.
32 */
33
34 static inline void
35 nir_builder_init_simple_shader(nir_builder *b, gl_shader_stage stage)
36 {
37 b->shader = nir_shader_create(NULL, stage, NULL);
38
39 nir_function *func = nir_function_create(b->shader,
40 ralloc_strdup(b->shader, "main"));
41 nir_function_overload *overload = nir_function_overload_create(func);
42 overload->num_params = 0;
43
44 b->impl = nir_function_impl_create(overload);
45 b->cursor = nir_after_cf_list(&b->impl->body);
46 }
47
48 static inline void
49 nir_copy_var(nir_builder *build, nir_variable *dest, nir_variable *src)
50 {
51 nir_intrinsic_instr *copy =
52 nir_intrinsic_instr_create(build->shader, nir_intrinsic_copy_var);
53 copy->variables[0] = nir_deref_var_create(copy, dest);
54 copy->variables[1] = nir_deref_var_create(copy, src);
55 nir_builder_instr_insert(build, &copy->instr);
56 }