[Mesa-dev] [PATCH 01/10] amd/common: extract ac_parse_shader_binary_config

Nicolai Hähnle nhaehnle at gmail.com
Fri May 3 11:18:20 UTC 2019


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

---
 src/amd/common/ac_binary.c | 77 +++++++++++++++++++++-----------------
 src/amd/common/ac_binary.h |  4 ++
 2 files changed, 47 insertions(+), 34 deletions(-)

diff --git a/src/amd/common/ac_binary.c b/src/amd/common/ac_binary.c
index fabeb15a204..44251886b5f 100644
--- a/src/amd/common/ac_binary.c
+++ b/src/amd/common/ac_binary.c
@@ -199,57 +199,30 @@ const unsigned char *ac_shader_binary_config_start(
 	unsigned i;
 	for (i = 0; i < binary->global_symbol_count; ++i) {
 		if (binary->global_symbol_offsets[i] == symbol_offset) {
 			unsigned offset = i * binary->config_size_per_symbol;
 			return binary->config + offset;
 		}
 	}
 	return binary->config;
 }
 
-
-static const char *scratch_rsrc_dword0_symbol =
-	"SCRATCH_RSRC_DWORD0";
-
-static const char *scratch_rsrc_dword1_symbol =
-	"SCRATCH_RSRC_DWORD1";
-
-void ac_shader_binary_read_config(struct ac_shader_binary *binary,
-				  struct ac_shader_config *conf,
-				  unsigned symbol_offset,
-				  bool supports_spill)
+/* Parse configuration data in .AMDGPU.config section format. */
+void ac_parse_shader_binary_config(const char *data, size_t nbytes,
+				   bool really_needs_scratch,
+				   struct ac_shader_config *conf)
 {
-	unsigned i;
-	const unsigned char *config =
-		ac_shader_binary_config_start(binary, symbol_offset);
-	bool really_needs_scratch = false;
 	uint32_t wavesize = 0;
-	/* LLVM adds SGPR spills to the scratch size.
-	 * Find out if we really need the scratch buffer.
-	 */
-	if (supports_spill) {
-		really_needs_scratch = true;
-	} else {
-		for (i = 0; i < binary->reloc_count; i++) {
-			const struct ac_shader_reloc *reloc = &binary->relocs[i];
 
-			if (!strcmp(scratch_rsrc_dword0_symbol, reloc->name) ||
-			    !strcmp(scratch_rsrc_dword1_symbol, reloc->name)) {
-				really_needs_scratch = true;
-				break;
-			}
-		}
-	}
-
-	for (i = 0; i < binary->config_size_per_symbol; i+= 8) {
-		unsigned reg = util_le32_to_cpu(*(uint32_t*)(config + i));
-		unsigned value = util_le32_to_cpu(*(uint32_t*)(config + i + 4));
+	for (size_t i = 0; i < nbytes; i += 8) {
+		unsigned reg = util_le32_to_cpu(*(uint32_t*)(data + i));
+		unsigned value = util_le32_to_cpu(*(uint32_t*)(data + i + 4));
 		switch (reg) {
 		case R_00B028_SPI_SHADER_PGM_RSRC1_PS:
 		case R_00B128_SPI_SHADER_PGM_RSRC1_VS:
 		case R_00B228_SPI_SHADER_PGM_RSRC1_GS:
 		case R_00B848_COMPUTE_PGM_RSRC1:
 		case R_00B428_SPI_SHADER_PGM_RSRC1_HS:
 			conf->num_sgprs = MAX2(conf->num_sgprs, (G_00B028_SGPRS(value) + 1) * 8);
 			conf->num_vgprs = MAX2(conf->num_vgprs, (G_00B028_VGPRS(value) + 1) * 4);
 			conf->float_mode =  G_00B028_FLOAT_MODE(value);
 			break;
@@ -292,20 +265,56 @@ void ac_shader_binary_read_config(struct ac_shader_binary *binary,
 		if (!conf->spi_ps_input_addr)
 			conf->spi_ps_input_addr = conf->spi_ps_input_ena;
 	}
 
 	if (really_needs_scratch) {
 		/* sgprs spills aren't spilling */
 	        conf->scratch_bytes_per_wave = G_00B860_WAVESIZE(wavesize) * 256 * 4;
 	}
 }
 
+static const char *scratch_rsrc_dword0_symbol =
+	"SCRATCH_RSRC_DWORD0";
+
+static const char *scratch_rsrc_dword1_symbol =
+	"SCRATCH_RSRC_DWORD1";
+
+void ac_shader_binary_read_config(struct ac_shader_binary *binary,
+				  struct ac_shader_config *conf,
+				  unsigned symbol_offset,
+				  bool supports_spill)
+{
+	unsigned i;
+	const char *config =
+		(const char *)ac_shader_binary_config_start(binary, symbol_offset);
+	bool really_needs_scratch = false;
+	/* LLVM adds SGPR spills to the scratch size.
+	 * Find out if we really need the scratch buffer.
+	 */
+	if (supports_spill) {
+		really_needs_scratch = true;
+	} else {
+		for (i = 0; i < binary->reloc_count; i++) {
+			const struct ac_shader_reloc *reloc = &binary->relocs[i];
+
+			if (!strcmp(scratch_rsrc_dword0_symbol, reloc->name) ||
+			    !strcmp(scratch_rsrc_dword1_symbol, reloc->name)) {
+				really_needs_scratch = true;
+				break;
+			}
+		}
+	}
+
+	ac_parse_shader_binary_config(config, binary->config_size_per_symbol,
+				      really_needs_scratch, conf);
+}
+
 void ac_shader_binary_clean(struct ac_shader_binary *b)
 {
 	if (!b)
 		return;
 	FREE(b->code);
 	FREE(b->config);
 	FREE(b->rodata);
 	FREE(b->global_symbol_offsets);
 	FREE(b->relocs);
 	FREE(b->disasm_string);
diff --git a/src/amd/common/ac_binary.h b/src/amd/common/ac_binary.h
index 735e3932055..febc4da7fed 100644
--- a/src/amd/common/ac_binary.h
+++ b/src/amd/common/ac_binary.h
@@ -17,20 +17,21 @@
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  */
 
 #ifndef AC_BINARY_H
 #define AC_BINARY_H
 
+#include <stddef.h>
 #include <stdint.h>
 #include <stdbool.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 struct ac_shader_reloc {
 	char name[32];
 	uint64_t offset;
@@ -89,20 +90,23 @@ bool ac_elf_read(const char *elf_data, unsigned elf_size,
 		 struct ac_shader_binary *binary);
 
 /**
  * @returns A pointer to the start of the configuration information for
  * the function starting at \p symbol_offset of the binary.
  */
 const unsigned char *ac_shader_binary_config_start(
 	const struct ac_shader_binary *binary,
 	uint64_t symbol_offset);
 
+void ac_parse_shader_binary_config(const char *data, size_t nbytes,
+				   bool really_needs_scratch,
+				   struct ac_shader_config *conf);
 void ac_shader_binary_read_config(struct ac_shader_binary *binary,
 				  struct ac_shader_config *conf,
 				  unsigned symbol_offset,
 				  bool supports_spill);
 void ac_shader_binary_clean(struct ac_shader_binary *b);
 
 #ifdef __cplusplus
 }
 #endif
 
-- 
2.20.1



More information about the mesa-dev mailing list