summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2015-07-11 00:17:48 +0200
committerMarek Olšák <[email protected]>2015-07-31 16:49:16 +0200
commit7dd1f45bc41c4a936b0ff84400840524bb9f8871 (patch)
tree11e31bc5fcb512370af17886c00133aa036e4817 /src
parent1bbe40836306549414408bb7f30b9288c020db75 (diff)
radeonsi: store shader disassemblies in memory for future users
This will be used by the new ddebug pipe. I'm including it now to avoid conflicts with other patches.
Diffstat (limited to 'src')
-rw-r--r--src/gallium/drivers/r600/evergreen_compute.c2
-rw-r--r--src/gallium/drivers/radeon/r600_pipe_common.h5
-rw-r--r--src/gallium/drivers/radeon/radeon_elf_util.c13
-rw-r--r--src/gallium/drivers/radeon/radeon_elf_util.h2
-rw-r--r--src/gallium/drivers/radeon/radeon_llvm_emit.c2
-rw-r--r--src/gallium/drivers/radeonsi/si_compute.c2
-rw-r--r--src/gallium/drivers/radeonsi/si_shader.c9
7 files changed, 18 insertions, 17 deletions
diff --git a/src/gallium/drivers/r600/evergreen_compute.c b/src/gallium/drivers/r600/evergreen_compute.c
index 4c3c34cd664..d89e3de9cc6 100644
--- a/src/gallium/drivers/r600/evergreen_compute.c
+++ b/src/gallium/drivers/r600/evergreen_compute.c
@@ -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,
diff --git a/src/gallium/drivers/radeon/r600_pipe_common.h b/src/gallium/drivers/radeon/r600_pipe_common.h
index fcb758b2086..ea165fd0f60 100644
--- a/src/gallium/drivers/radeon/r600_pipe_common.h
+++ b/src/gallium/drivers/radeon/r600_pipe_common.h
@@ -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 {
diff --git a/src/gallium/drivers/radeon/radeon_elf_util.c b/src/gallium/drivers/radeon/radeon_elf_util.c
index 9b508227fd4..2e45d439e7a 100644
--- a/src/gallium/drivers/radeon/radeon_elf_util.c
+++ b/src/gallium/drivers/radeon/radeon_elf_util.c
@@ -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;
diff --git a/src/gallium/drivers/radeon/radeon_elf_util.h b/src/gallium/drivers/radeon/radeon_elf_util.h
index ab83f98ea69..ea4ab2f14b2 100644
--- a/src/gallium/drivers/radeon/radeon_elf_util.h
+++ b/src/gallium/drivers/radeon/radeon_elf_util.h
@@ -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
diff --git a/src/gallium/drivers/radeon/radeon_llvm_emit.c b/src/gallium/drivers/radeon/radeon_llvm_emit.c
index c442c6566dc..04f62d13ca7 100644
--- a/src/gallium/drivers/radeon/radeon_llvm_emit.c
+++ b/src/gallium/drivers/radeon/radeon_llvm_emit.c
@@ -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);
diff --git a/src/gallium/drivers/radeonsi/si_compute.c b/src/gallium/drivers/radeonsi/si_compute.c
index 5e4225bd04c..d4fe5653687 100644
--- a/src/gallium/drivers/radeonsi/si_compute.c
+++ b/src/gallium/drivers/radeonsi/si_compute.c
@@ -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
diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c
index 06faba3156e..465eecd0346 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -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);
}