radv: disassemble SPIR-V binaries with RADV_DEBUG=spirv

This introduces a new separate option because the output can
be quite verbose. If spirv-dis is not found in the path, this
debug option is useless.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
This commit is contained in:
Samuel Pitoiset
2017-08-30 15:12:21 +02:00
parent ad42e2abb8
commit f14020c15f
4 changed files with 39 additions and 0 deletions

View File

@@ -62,3 +62,34 @@ radv_dump_trace(struct radv_device *device, struct radeon_winsys_cs *cs)
device->ws->cs_dump(cs, f, (const int*)device->trace_id_ptr, 2);
fclose(f);
}
void
radv_print_spirv(struct radv_shader_module *module, FILE *fp)
{
char path[] = "/tmp/fileXXXXXX";
char line[2048], command[128];
FILE *p;
int fd;
/* Dump the binary into a temporary file. */
fd = mkstemp(path);
if (fd < 0)
return;
if (write(fd, module->data, module->size) == -1)
goto fail;
sprintf(command, "spirv-dis %s", path);
/* Disassemble using spirv-dis if installed. */
p = popen(command, "r");
if (p) {
while (fgets(line, sizeof(line), p))
fprintf(fp, "%s", line);
pclose(p);
}
fail:
close(fd);
unlink(path);
}