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.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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, §ion_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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user