radeonsi: store shader disassemblies in memory for future users
authorMarek Olšák <marek.olsak@amd.com>
Fri, 10 Jul 2015 22:17:48 +0000 (00:17 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Fri, 31 Jul 2015 14:49:16 +0000 (16:49 +0200)
This will be used by the new ddebug pipe. I'm including it now to avoid
conflicts with other patches.

src/gallium/drivers/r600/evergreen_compute.c
src/gallium/drivers/radeon/r600_pipe_common.h
src/gallium/drivers/radeon/radeon_elf_util.c
src/gallium/drivers/radeon/radeon_elf_util.h
src/gallium/drivers/radeon/radeon_llvm_emit.c
src/gallium/drivers/radeonsi/si_compute.c
src/gallium/drivers/radeonsi/si_shader.c

index 4c3c34cd6642ef42b4cf0fb03fa464fd67e5b491..d89e3de9cc68a39474b11efbb4537d44cd82ed1b 100644 (file)
@@ -226,7 +226,7 @@ void *evergreen_create_compute_state(
        }
 #else
        memset(&shader->binary, 0, sizeof(shader->binary));
-       radeon_elf_read(code, header->num_bytes, &shader->binary, true);
+       radeon_elf_read(code, header->num_bytes, &shader->binary);
        r600_create_shader(&shader->bc, &shader->binary, &use_kill);
 
        shader->code_bo = r600_compute_buffer_alloc_vram(ctx->screen,
index fcb758b2086d2fd8c4f048ed17299a8e729ea7db..ea165fd0f6017284ef10333dee3eb598f030a97b 100644 (file)
@@ -129,9 +129,8 @@ struct radeon_shader_binary {
        struct radeon_shader_reloc *relocs;
        unsigned reloc_count;
 
-       /** Set to 1 if the disassembly for this binary has been dumped to
-        *  stderr. */
-       int disassembled;
+       /** Disassembled shader in a string. */
+       char *disasm_string;
 };
 
 struct r600_resource {
index 9b508227fd42827dc879f51222d48457cb464bb3..2e45d439e7a0d4078d2a5d3ac575db8a80465d78 100644 (file)
@@ -103,8 +103,7 @@ static void parse_relocs(Elf *elf, Elf_Data *relocs, Elf_Data *symbols,
 }
 
 void radeon_elf_read(const char *elf_data, unsigned elf_size,
-                                       struct radeon_shader_binary *binary,
-                                       unsigned debug)
+                    struct radeon_shader_binary *binary)
 {
        char *elf_buffer;
        Elf *elf;
@@ -124,7 +123,6 @@ void radeon_elf_read(const char *elf_data, unsigned elf_size,
        elf = elf_memory(elf_buffer, elf_size);
 
        elf_getshdrstrndx(elf, &section_str_index);
-       binary->disassembled = 0;
 
        while ((section = elf_nextscn(elf, section))) {
                const char *name;
@@ -145,12 +143,11 @@ void radeon_elf_read(const char *elf_data, unsigned elf_size,
                        binary->config_size = section_data->d_size;
                        binary->config = MALLOC(binary->config_size * sizeof(unsigned char));
                        memcpy(binary->config, section_data->d_buf, binary->config_size);
-               } else if (debug && !strcmp(name, ".AMDGPU.disasm")) {
-                       binary->disassembled = 1;
+               } else if (!strcmp(name, ".AMDGPU.disasm")) {
+                       /* Always read disassembly if it's available. */
                        section_data = elf_getdata(section, section_data);
-                       fprintf(stderr, "\nShader Disassembly:\n\n");
-                       fprintf(stderr, "%.*s\n", (int)section_data->d_size,
-                                                 (char *)section_data->d_buf);
+                       binary->disasm_string = strndup(section_data->d_buf,
+                                                       section_data->d_size);
                } else if (!strncmp(name, ".rodata", 7)) {
                        section_data = elf_getdata(section, section_data);
                        binary->rodata_size = section_data->d_size;
index ab83f98ea69c202513e6700542ac24a8fae75f15..ea4ab2f14b25bd2a62887ab574d0702345e566c5 100644 (file)
@@ -37,7 +37,7 @@ struct radeon_shader_reloc;
  * radeon_shader_binary object.
  */
 void radeon_elf_read(const char *elf_data, unsigned elf_size,
-               struct radeon_shader_binary *binary, unsigned debug);
+                    struct radeon_shader_binary *binary);
 
 /**
  * @returns A pointer to the start of the configuration information for
index c442c6566dc6466544e1e5b203ab2a40ee1e092b..04f62d13ca78d2bb43bd1493690fa0a225baee9b 100644 (file)
@@ -210,7 +210,7 @@ unsigned radeon_llvm_compile(LLVMModuleRef M, struct radeon_shader_binary *binar
        buffer_size = LLVMGetBufferSize(out_buffer);
        buffer_data = LLVMGetBufferStart(out_buffer);
 
-       radeon_elf_read(buffer_data, buffer_size, binary, dump);
+       radeon_elf_read(buffer_data, buffer_size, binary);
 
        /* Clean up */
        LLVMDisposeMemoryBuffer(out_buffer);
index 5e4225bd04c57bf00d8777b93ab1b01aa461d2a5..d4fe5653687a03b2fbefd35709b083dd97875cfb 100644 (file)
@@ -137,7 +137,7 @@ static void *si_create_compute_state(
        }
 #else
 
-       radeon_elf_read(code, header->num_bytes, &program->shader.binary, true);
+       radeon_elf_read(code, header->num_bytes, &program->shader.binary);
 
        /* init_scratch_buffer patches the shader code with the scratch address,
         * so we need to call it before si_shader_binary_read() which uploads
index 06faba3156e9e76e2eef8b07a52952a9865b881f..465eecd0346aed995451ee1b5e562c01280d325e 100644 (file)
@@ -3811,7 +3811,10 @@ int si_shader_binary_read(struct si_screen *sscreen, struct si_shader *shader)
        si_shader_binary_upload(sscreen, shader);
 
        if (dump) {
-               if (!binary->disassembled) {
+               if (binary->disasm_string) {
+                       fprintf(stderr, "\nShader Disassembly:\n\n");
+                       fprintf(stderr, "%s\n", binary->disasm_string);
+               } else {
                        fprintf(stderr, "SI CODE:\n");
                        for (i = 0; i < binary->code_size; i+=4 ) {
                                fprintf(stderr, "@0x%x: %02x%02x%02x%02x\n", i, binary->code[i + 3],
@@ -3849,7 +3852,8 @@ int si_compile_llvm(struct si_screen *sscreen, struct si_shader *shader,
        if (shader->scratch_bytes_per_wave == 0) {
                FREE(shader->binary.code);
                FREE(shader->binary.relocs);
-               memset(&shader->binary, 0, sizeof(shader->binary));
+               memset(&shader->binary, 0,
+                      offsetof(struct radeon_shader_binary, disasm_string));
        }
        return r;
 }
@@ -4176,4 +4180,5 @@ void si_shader_destroy(struct pipe_context *ctx, struct si_shader *shader)
 
        FREE(shader->binary.code);
        FREE(shader->binary.relocs);
+       FREE(shader->binary.disasm_string);
 }