panfrost: Adds Bifrost shader disassembler utility

This code is stable and can live upstream independently while the rest
of the Bifrost stack comes up.

v2: Added a verbose flag to hide away some of the more verbose features
that nobody really needs

[The Bifrost disassembler is written by Connor Abbott, Lyude Paul, and
Ryan Houdek.]

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
This commit is contained in:
Ryan Houdek
2019-04-21 20:41:09 -07:00
committed by Alyssa Rosenzweig
parent bb1aff3007
commit 2cd1aa3429
5 changed files with 2434 additions and 0 deletions
@@ -0,0 +1,85 @@
/*
* Copyright (C) 2019 Connor Abbott <cwabbott0@gmail.com>
* Copyright (C) 2019 Lyude Paul <thatslyude@gmail.com>
* Copyright (C) 2019 Ryan Houdek <Sonicadvance1@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* 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 __bifrost_h__
#define __bifrost_h__
#include <stdint.h>
#include <stdbool.h>
struct bifrost_header {
unsigned unk0 : 7;
// If true, convert any infinite result of any floating-point operation to
// the biggest representable number.
unsigned suppress_inf: 1;
// Convert any NaN results to 0.
unsigned suppress_nan : 1;
unsigned unk1 : 2;
// true if the execution mask of the next clause is the same as the mask of
// the current clause.
unsigned back_to_back : 1;
unsigned no_end_of_shader: 1;
unsigned unk2 : 2;
// Set to true for fragment shaders, to implement this bit of spec text
// from section 7.1.5 of the GLSL ES spec:
//
// "Stores to image and buffer variables performed by helper invocations
// have no effect on the underlying image or buffer memory."
//
// Helper invocations are threads (invocations) corresponding to pixels in
// a quad that aren't actually part of the triangle, but are included to
// make derivatives work correctly. They're usually turned on, but they
// need to be masked off for GLSL-level stores. This bit seems to be the
// only bit that's actually different between fragment shaders and other
// shaders, so this is probably what it's doing.
unsigned elide_writes : 1;
// If backToBack is off:
// - true for conditional branches and fallthrough
// - false for unconditional branches
// The blob seems to always set it to true if back-to-back is on.
unsigned branch_cond : 1;
// This bit is set when the next clause writes to the data register of some
// previous clause.
unsigned datareg_writebarrier: 1;
unsigned datareg : 6;
unsigned scoreboard_deps: 8;
unsigned scoreboard_index: 3;
unsigned clause_type: 4;
unsigned unk3 : 1; // part of clauseType?
unsigned next_clause_type: 4;
unsigned unk4 : 1; // part of nextClauseType?
};
struct bifrost_fma_inst {
unsigned src0 : 3;
unsigned op : 20;
};
struct bifrost_add_inst {
unsigned src0 : 3;
unsigned op : 17;
};
#endif
@@ -0,0 +1,63 @@
/*
* Copyright (C) 2019 Ryan Houdek <Sonicadvance1@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* 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.
*/
#include "main/mtypes.h"
#include "compiler/glsl/standalone.h"
#include "compiler/glsl/glsl_to_nir.h"
#include "compiler/nir_types.h"
#include "disassemble.h"
#include "util/u_dynarray.h"
static void
disassemble(const char *filename)
{
FILE *fp = fopen(filename, "rb");
assert(fp);
fseek(fp, 0, SEEK_END);
int filesize = ftell(fp);
rewind(fp);
unsigned char *code = malloc(filesize);
int res = fread(code, 1, filesize, fp);
if (res != filesize) {
printf("Couldn't read full file\n");
}
fclose(fp);
disassemble_bifrost(code, filesize, false);
free(code);
}
int
main(int argc, char **argv)
{
if (argc < 2) {
printf("Pass a command\n");
exit(1);
}
if (strcmp(argv[1], "disasm") == 0) {
disassemble(argv[2]);
}
return 0;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2019 Connor Abbott <cwabbott0@gmail.com>
* Copyright (C) 2019 Lyude Paul <thatslyude@gmail.com>
* Copyright (C) 2019 Ryan Houdek <Sonicadvance1@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* 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.
*/
#include <stdbool.h>
#include <stddef.h>
void disassemble_bifrost(uint8_t *code, size_t size, bool verbose);
+31
View File
@@ -30,6 +30,8 @@ files_panfrost = files(
'midgard/cppwrap.cpp',
'midgard/disassemble.c',
'bifrost/disassemble.c',
'pan_context.c',
'pan_job.c',
'pan_trace.c',
@@ -55,6 +57,7 @@ inc_panfrost = [
inc_src,
include_directories('include'),
include_directories('midgard'),
include_directories('bifrost'),
]
compile_args_panfrost = [
@@ -98,6 +101,11 @@ files_midgard = files(
'midgard/cmdline.c',
)
files_bifrost = files(
'bifrost/disassemble.c',
'bifrost/cmdline.c',
)
midgard_compiler = executable(
'midgard_compiler',
[files_midgard, midgard_nir_algebraic_c],
@@ -114,6 +122,29 @@ midgard_compiler = executable(
build_by_default : true
)
bifrost_compiler = executable(
'bifrost_compiler',
[files_bifrost],
include_directories : [
inc_common,
inc_src,
inc_include,
inc_gallium,
inc_gallium_aux,
include_directories('bifrost')
],
dependencies : [
dep_thread,
idep_nir
],
link_with : [
libgallium,
libglsl_standalone,
libmesa_util
],
build_by_default : true
)
files_pandecode = files(
'pandecode/cmdline.c',
'pandecode/decode.c',