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