ac: reorg ac_shader_binary struct to take less space.
[mesa.git] / src / amd / common / ac_binary.h
1 /*
2 * Copyright 2014 Advanced Micro Devices, Inc.
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 FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Authors: Tom Stellard <thomas.stellard@amd.com>
24 *
25 */
26
27 #ifndef AC_BINARY_H
28 #define AC_BINARY_H
29
30 #include <stdint.h>
31 #include <stdbool.h>
32
33 struct ac_shader_reloc {
34 char name[32];
35 uint64_t offset;
36 };
37
38 struct ac_shader_binary {
39 unsigned code_size;
40 unsigned config_size;
41 /** The number of bytes of config information for each global symbol.
42 */
43 unsigned config_size_per_symbol;
44 unsigned rodata_size;
45 unsigned global_symbol_count;
46 unsigned reloc_count;
47
48 /** Shader code */
49 unsigned char *code;
50
51 /** Config/Context register state that accompanies this shader.
52 * This is a stream of dword pairs. First dword contains the
53 * register address, the second dword contains the value.*/
54 unsigned char *config;
55
56
57 /** Constant data accessed by the shader. This will be uploaded
58 * into a constant buffer. */
59 unsigned char *rodata;
60
61 /** List of symbol offsets for the shader */
62 uint64_t *global_symbol_offsets;
63
64 struct ac_shader_reloc *relocs;
65
66 /** Disassembled shader in a string. */
67 char *disasm_string;
68 char *llvm_ir_string;
69 };
70
71 struct ac_shader_config {
72 unsigned num_sgprs;
73 unsigned num_vgprs;
74 unsigned spilled_sgprs;
75 unsigned spilled_vgprs;
76 unsigned lds_size;
77 unsigned spi_ps_input_ena;
78 unsigned spi_ps_input_addr;
79 unsigned float_mode;
80 unsigned scratch_bytes_per_wave;
81 };
82
83 /*
84 * Parse the elf binary stored in \p elf_data and create a
85 * ac_shader_binary object.
86 */
87 bool ac_elf_read(const char *elf_data, unsigned elf_size,
88 struct ac_shader_binary *binary);
89
90 /**
91 * @returns A pointer to the start of the configuration information for
92 * the function starting at \p symbol_offset of the binary.
93 */
94 const unsigned char *ac_shader_binary_config_start(
95 const struct ac_shader_binary *binary,
96 uint64_t symbol_offset);
97
98 void ac_shader_binary_read_config(struct ac_shader_binary *binary,
99 struct ac_shader_config *conf,
100 unsigned symbol_offset,
101 bool supports_spill);
102
103 #endif /* AC_BINARY_H */