radv: Add code to compile merged shaders.
[mesa.git] / src / amd / vulkan / radv_shader.h
1 /*
2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
4 *
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25 * IN THE SOFTWARE.
26 */
27
28 #ifndef RADV_SHADER_H
29 #define RADV_SHADER_H
30
31 #include "radv_private.h"
32
33 #include "nir/nir.h"
34
35 struct radv_shader_module {
36 struct nir_shader *nir;
37 unsigned char sha1[20];
38 uint32_t size;
39 char data[0];
40 };
41
42 struct radv_shader_variant {
43 uint32_t ref_count;
44
45 struct radeon_winsys_bo *bo;
46 uint64_t bo_offset;
47 struct ac_shader_config config;
48 uint32_t code_size;
49 struct ac_shader_variant_info info;
50 unsigned rsrc1;
51 unsigned rsrc2;
52
53 /* debug only */
54 uint32_t *spirv;
55 uint32_t spirv_size;
56 struct nir_shader *nir;
57 char *disasm_string;
58
59 struct list_head slab_list;
60 };
61
62 struct radv_shader_slab {
63 struct list_head slabs;
64 struct list_head shaders;
65 struct radeon_winsys_bo *bo;
66 uint64_t size;
67 char *ptr;
68 };
69
70 void
71 radv_optimize_nir(struct nir_shader *shader);
72
73 nir_shader *
74 radv_shader_compile_to_nir(struct radv_device *device,
75 struct radv_shader_module *module,
76 const char *entrypoint_name,
77 gl_shader_stage stage,
78 const VkSpecializationInfo *spec_info);
79
80 void *
81 radv_alloc_shader_memory(struct radv_device *device,
82 struct radv_shader_variant *shader);
83
84 void
85 radv_destroy_shader_slabs(struct radv_device *device);
86
87 struct radv_shader_variant *
88 radv_shader_variant_create(struct radv_device *device,
89 struct radv_shader_module *module,
90 struct nir_shader *const *shaders,
91 int shader_count,
92 struct radv_pipeline_layout *layout,
93 const struct ac_shader_variant_key *key,
94 void **code_out,
95 unsigned *code_size_out);
96
97 struct radv_shader_variant *
98 radv_create_gs_copy_shader(struct radv_device *device, struct nir_shader *nir,
99 void **code_out, unsigned *code_size_out,
100 bool multiview);
101
102 void
103 radv_shader_variant_destroy(struct radv_device *device,
104 struct radv_shader_variant *variant);
105
106 uint32_t
107 radv_shader_stage_to_user_data_0(gl_shader_stage stage, bool has_gs,
108 bool has_tess);
109
110 const char *
111 radv_get_shader_name(struct radv_shader_variant *var, gl_shader_stage stage);
112
113 void
114 radv_shader_dump_stats(struct radv_device *device,
115 struct radv_shader_variant *variant,
116 gl_shader_stage stage,
117 FILE *file);
118
119 #endif