radv: Add LLVM version to the device name string
[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_debug.h"
32 #include "radv_private.h"
33
34 #include "nir/nir.h"
35
36 struct radv_shader_module {
37 struct nir_shader *nir;
38 unsigned char sha1[20];
39 uint32_t size;
40 char data[0];
41 };
42
43 struct radv_shader_variant {
44 uint32_t ref_count;
45
46 struct radeon_winsys_bo *bo;
47 uint64_t bo_offset;
48 struct ac_shader_config config;
49 uint32_t code_size;
50 struct ac_shader_variant_info info;
51 unsigned rsrc1;
52 unsigned rsrc2;
53
54 /* debug only */
55 uint32_t *spirv;
56 uint32_t spirv_size;
57 struct nir_shader *nir;
58 char *disasm_string;
59
60 struct list_head slab_list;
61 };
62
63 struct radv_shader_slab {
64 struct list_head slabs;
65 struct list_head shaders;
66 struct radeon_winsys_bo *bo;
67 uint64_t size;
68 char *ptr;
69 };
70
71 void
72 radv_optimize_nir(struct nir_shader *shader);
73
74 nir_shader *
75 radv_shader_compile_to_nir(struct radv_device *device,
76 struct radv_shader_module *module,
77 const char *entrypoint_name,
78 gl_shader_stage stage,
79 const VkSpecializationInfo *spec_info);
80
81 void *
82 radv_alloc_shader_memory(struct radv_device *device,
83 struct radv_shader_variant *shader);
84
85 void
86 radv_destroy_shader_slabs(struct radv_device *device);
87
88 struct radv_shader_variant *
89 radv_shader_variant_create(struct radv_device *device,
90 struct radv_shader_module *module,
91 struct nir_shader *const *shaders,
92 int shader_count,
93 struct radv_pipeline_layout *layout,
94 const struct ac_shader_variant_key *key,
95 void **code_out,
96 unsigned *code_size_out);
97
98 struct radv_shader_variant *
99 radv_create_gs_copy_shader(struct radv_device *device, struct nir_shader *nir,
100 void **code_out, unsigned *code_size_out,
101 bool multiview);
102
103 void
104 radv_shader_variant_destroy(struct radv_device *device,
105 struct radv_shader_variant *variant);
106
107 const char *
108 radv_get_shader_name(struct radv_shader_variant *var, gl_shader_stage stage);
109
110 void
111 radv_shader_dump_stats(struct radv_device *device,
112 struct radv_shader_variant *variant,
113 gl_shader_stage stage,
114 FILE *file);
115
116 static inline bool
117 radv_can_dump_shader(struct radv_device *device,
118 struct radv_shader_module *module)
119 {
120 /* Only dump non-meta shaders, useful for debugging purposes. */
121 return device->instance->debug_flags & RADV_DEBUG_DUMP_SHADERS &&
122 module && !module->nir;
123 }
124
125 #endif