...
 
Commits (5)
......@@ -191,7 +191,7 @@ enum mali_fbd_type {
#define FBD_TYPE (1)
#define FBD_MASK (~0x3f)
struct mali_payload_vertex_tiler {
struct mali_payload_vertex_tiler_32 {
/* Exactly as passed to glLineWidth */
float line_width;
......@@ -246,6 +246,113 @@ struct mali_payload_vertex_tiler {
} __attribute__((packed));
//ASSERT_SIZEOF_TYPE(struct mali_payload_vertex_tiler, 256, 256);
struct mali_payload_vertex_tiler_64 {
/* Off by one */
u32 vertex_count;
u32 unk1; // 0x28000000
u32 draw_mode;
u32 zero0;
u32 zero1;
/* Like many other strictly nonzero quantities, index_count is
* subtracted by one. For an indexed cube, this is equal to 35 = 6
* faces * 2 triangles/per face * 3 vertices/per triangle - 1. For
* non-indexed draws, equal to vertex_count. */
u32 index_count;
/* No hidden structure; literally just a pointer to an array of
* uint32_t indices. Thanks, guys, for not making my life insane for
* once! NULL for non-indexed draws. */
/* XXX verify this */
uintptr_t indices;
/* 0x20 */
u32 unk2; /* =0x2 */
u32 zero2;
u64 zero3;
/* 0x30 */
mali_ptr zero4;
mali_ptr unknown2;
/* 0x40 */
u64 zero5, zero6;
/* 0x50 */
mali_ptr uniforms;
u8 flags : 4;
uintptr_t _shader_upper : MALI_SHORT_PTR_BITS - 4; /* struct shader_meta */
/* 0x60 */
mali_ptr unknown5;
mali_ptr unknown6;
/* 0x70 */
mali_ptr unknown7;
mali_ptr unknown8;
/* 0x80 */
u64 zero7, zero8;
/* 0x90 */
mali_ptr framebuffer;
u64 zero9;
} __attribute__((packed));
/* Bifrost added a new specialized tiler payload */
struct mali_payload_tiler_bfr {
/* Off by one */
u32 vertex_count;
u32 unk1; /* 0x28000000 */
u32 draw_mode;
u32 zero0;
u32 zero1;
/* Like many other strictly nonzero quantities, index_count is
* subtracted by one. For an indexed cube, this is equal to 35 = 6
* faces * 2 triangles/per face * 3 vertices/per triangle - 1. For
* non-indexed draws, equal to vertex_count. */
u32 index_count;
/* No hidden structure; literally just a pointer to an array of
* uint32_t indices. Thanks, guys, for not making my life insane for
* once! NULL for non-indexed draws. */
/* XXX verify this */
uintptr_t indices;
/* 0x20 */
float line_width;
u32 zero2;
mali_ptr unknown0;
/* 0x30 */
u64 zero3, zero4, zero5, zero6, zero7, zero8;
/* 0x60 */
u32 gl_enables;
u32 zero9;
u64 zero10;
/* 0x70 */
mali_ptr unknown1;
mali_ptr unknown2;
u64 zero11, zero12;
/* 0x90 */
mali_ptr unknown3;
mali_ptr unknown4;
u64 zero13, zero14;
/* 0xB0 */
mali_ptr unknown5;
u64 zero15;
/* 0xC0 */
mali_ptr unknown6;
u64 zero16;
/* 0xD0 */
mali_ptr unknown7;
u64 zero17;
} __attribute__((packed));
/* Pointed to from texture_trampoline, mostly unknown still, haven't
* managed to replay successfully */
......@@ -372,9 +479,6 @@ struct mali_unknown6 {
#define MALI_COORDINATE_TO_TILE_MAX(W, H, flag) MALI_COORDINATE_TO_TILE(W, H, flag, 1)
struct mali_payload_fragment {
/* XXX: WTF? */
u32 zero;
/* XXX: we might be able to translate these into bitfields someday, but
* that will only be sensible if the mask of flags is limited to
* 0xF0000000 or 0x0000F000. If it's 0xF000F000, feel free to just
......
......@@ -29,7 +29,7 @@ endif
m_dep = cc.find_library('m', required: true)
dl_dep = cc.find_library('dl', required: false)
pthread_dep = cc.find_library('pthread', required: false)
pthread_dep = dependency('threads')
spd_dep = dependency('ShaderProgramDisassembler', required: true)
common_dep = [
......
This diff is collapsed.
......@@ -19,7 +19,7 @@
#include <mali-job.h>
#include "panwrap.h"
int panwrap_replay_jc(mali_ptr jc_gpu_va);
int panwrap_replay_jc(mali_ptr jc_gpu_va, bool bifrost);
int panwrap_replay_soft_replay(mali_ptr jc_gpu_va);
#endif /* !PANWRAP_DECODER_H */
......@@ -84,10 +84,23 @@ void replay_memory()
{
struct panwrap_mapped_memory *pos;
panwrap_msg("/proc/self/maps:\n");
FILE *fd = fopen("/proc/self/maps", "r");
if (!fd)
panwrap_msg("Error opening!\n");
int c;
while (EOF != (c = fgetc(fd)))
putchar(c);
fclose(fd);
list_for_each_entry(pos, &mmaps, node) {
/* If we don't have write access, no replay :) */
if (!(pos->flags & MALI_MEM_PROT_CPU_WR)) continue;
panwrap_msg("addr: %p, length: %zd flags: %d\n", pos->addr, pos->length, pos->flags);
fflush(stdout);
fflush(stderr);
if (pos->flags & MALI_MEM_PROT_GPU_EX) {
/* Shader memory get dumped but not replayed, as the
* dis/assembler is setup in-tree as it is. */
......@@ -100,13 +113,16 @@ void replay_memory()
fclose(fp);
panwrap_log("// FILE *f_%s = fopen(\"%s\", \"rb\");\n", pos->name, filename);
panwrap_log("// fread(%s, 1, %d, f_%s);\n", pos->name, pos->length, pos->name);
panwrap_log("// fread(%s, 1, %zd, f_%s);\n", pos->name, pos->length, pos->name);
panwrap_log("// fclose(f_%s);\n", pos->name);
} else {
/* Fill it with dumped memory, skipping zeroes */
uint32_t *array = (uint32_t *) pos->addr;
for (uint32_t i = 0; i < pos->length / sizeof(uint32_t); ++i) {
panwrap_msg("addr: %p\n", &array[i]);
fflush(stdout);
fflush(stderr);
if (array[i])
panwrap_log("%s%s[%d] = %s;\n", pos->touched[i] ? "// " : "", pos->name, i, pointer_as_memory_reference(array[i]));
}
......@@ -173,6 +189,8 @@ void panwrap_track_mmap(mali_ptr gpu_va, void *addr, size_t length,
mapped_mem->gpu_va = gpu_va;
}
panwrap_msg("mapped %zd bytes to " MALI_PTR_FMT "\n", length, mapped_mem->gpu_va);
mapped_mem->length = length;
mapped_mem->addr = addr;
mapped_mem->prot = prot;
......@@ -193,7 +211,7 @@ void panwrap_track_mmap(mali_ptr gpu_va, void *addr, size_t length,
/* Map region itself */
panwrap_log("uint32_t *%s = mmap64(NULL, %d, %d, %d, fd, alloc_gpu_va_%d);\n\n",
panwrap_log("uint32_t *%s = mmap64(NULL, %zd, %d, %d, fd, alloc_gpu_va_%d);\n\n",
mapped_mem->name, length, prot, flags, mapped_mem->allocation_number);
panwrap_log("if (%s == MAP_FAILED) printf(\"Error mapping %s\\n\");\n\n",
......@@ -340,7 +358,7 @@ __panwrap_fetch_mem_err(const struct panwrap_mapped_memory *mem,
struct panwrap_mapped_memory *pos;
list_for_each_entry(pos, &mmaps, node) {
panwrap_msg("%llx (%p)\n", pos->gpu_va, pos->addr);
panwrap_msg(MALI_PTR_FMT " (%p)\n", pos->gpu_va, pos->addr);
}
}
......
......@@ -46,12 +46,12 @@ struct panwrap_mapped_memory {
};
#define TOUCH_MEMSET(mem, addr, sz, offset) \
memset(mem->touched + ((addr - mem->gpu_va) / sizeof(uint32_t)), 1, (sz - offset) / sizeof(uint32_t)); \
memset((mem)->touched + (((addr) - (mem)->gpu_va) / sizeof(uint32_t)), 1, ((sz) - (offset)) / sizeof(uint32_t)); \
panwrap_log("\n");
#define TOUCH_LEN(mem, addr, sz, ename, number, dyn) \
TOUCH_MEMSET(mem, addr, sz, 0) \
panwrap_log("mali_ptr %s_%d_p = pandev_upload(%d, alloc_gpu_va_%d, %s, &%s_%d, sizeof(%s_%d), false);\n\n", ename, number, dyn ? -1 : (int) ((addr - mem->gpu_va)), mem->allocation_number, mem->name, ename, number, ename, number);
panwrap_log("mali_ptr %s_%d_p = pandev_upload(%d, alloc_gpu_va_%d, %s, &%s_%d, sizeof(%s_%d), false);\n\n", ename, number, (dyn) ? -1 : (int) (((addr) - (mem)->gpu_va)), (mem)->allocation_number, (mem)->name, ename, number, ename, number);
/* Job payloads are touched somewhat different than other structures, due to the
* variable lengths and odd packing requirements */
......
......@@ -25,17 +25,11 @@
* be integrated here as well in the near future, once an assembler is written
* for that platform. */
/* TODO: expose in meson so Lyude doesn't get annoyed at me for breaking
* Bifrost */
#define SHADER_MIDGARD
#ifdef SHADER_MIDGARD
/* Disassemble the shader itself. */
void
panwrap_shader_disassemble(mali_ptr shader_ptr, int shader_no, int type)
panwrap_shader_disassemble(mali_ptr shader_ptr, int shader_no, int type,
bool bifrost)
{
struct panwrap_mapped_memory *shaders = panwrap_find_mapped_gpu_mem_containing(shader_ptr);
ptrdiff_t offset = shader_ptr - shaders->gpu_va;
......@@ -43,12 +37,15 @@ panwrap_shader_disassemble(mali_ptr shader_ptr, int shader_no, int type)
/* Disassemble it at trace time... */
panwrap_log("const char shader_src_%d[] = R\"(\n", shader_no);
DisassembleMidgard(shaders->addr + offset, shaders->length - offset);
if (bifrost)
DisassembleBifrost(shaders->addr + offset, shaders->length - offset);
else
DisassembleMidgard(shaders->addr + offset, shaders->length - offset);
panwrap_log(")\";\n\n");
/* ...but reassemble at runtime! */
panwrap_log("pandev_shader_%s(%s + %d, shader_src_%d, %d);\n\n",
panwrap_log("pandev_shader_%s(%s + %zd, shader_src_%d, %d);\n\n",
type == SHADER_FRAGMENT ? "compile" : "assemble",
shaders->name,
offset / sizeof(uint32_t),
......@@ -56,13 +53,3 @@ panwrap_shader_disassemble(mali_ptr shader_ptr, int shader_no, int type)
type);
}
#else
void
panwrap_shader_disassemble(mali_ptr shader_ptr, int shader_no, int type)
{
panwrap_msg("Shader decoding is not yet supported on non-Midgard platforms\n");
panwrap_msg("No disassembly performed for shader at " MALI_PTR_FMT, shader_ptr);
}
#endif
......@@ -22,6 +22,7 @@
#define SHADER_VERTEX JOB_TYPE_VERTEX
#define SHADER_FRAGMENT JOB_TYPE_TILER
void panwrap_shader_disassemble(mali_ptr shader_ptr, int shader_no, int type);
void panwrap_shader_disassemble(mali_ptr shader_ptr, int shader_no, int type,
bool bifrost);
#endif /* !PANWRAP_SHADER_H */
......@@ -548,7 +548,7 @@ ioctl_decode_pre_sync(unsigned long int request, void *ptr)
else
panwrap_prop("handle = " MALI_PTR_FMT, args->handle);
panwrap_prop("user_addr = %s + %d", mem->name, args->user_addr - mem->addr);
panwrap_prop("user_addr = %s + %zd", mem->name, args->user_addr - mem->addr);
panwrap_prop("type = %s", args->type == MALI_SYNC_TO_DEVICE ? "MALI_SYNC_TO_DEVICE" : "MALI_SYNC_TO_CPU");
}
......@@ -576,7 +576,7 @@ ioctl_decode_pre_stream_create(unsigned long int request, void *ptr)
static int job_count = 0;
static void emit_atoms(void *ptr) {
static void emit_atoms(void *ptr, bool bifrost) {
const struct mali_ioctl_job_submit *args = ptr;
const struct mali_jd_atom_v2 *atoms = args->addr;
......@@ -592,7 +592,7 @@ static void emit_atoms(void *ptr) {
int req = a->core_req | a->compat_core_req;
if (!(req & MALI_JD_REQ_SOFT_JOB))
job_numbers[i] = panwrap_replay_jc(a->jc);
job_numbers[i] = panwrap_replay_jc(a->jc, bifrost);
else if (req & MALI_JD_REQ_SOFT_REPLAY)
job_numbers[i] = panwrap_replay_soft_replay(a->jc);
}
......@@ -976,14 +976,17 @@ static char *panwrap_lower_string(const char *str)
static int ioctl_count = 0;
/* HW version */
static bool bifrost = false;
/* XXX: Android has a messed up ioctl signature */
int ioctl(int fd, int request, ...)
int ioctl(int fd, int _request, ...)
{
const char *name;
char *lname;
int number;
union mali_ioctl_header *header;
PROLOG(ioctl);
unsigned long int request = _request;
int ioc_size = _IOC_SIZE(request);
int ret;
void *ptr;
......@@ -1004,7 +1007,6 @@ int ioctl(int fd, int request, ...)
LOCK();
msleep(log_delay);
name = ioctl_get_info(request)->name ?: "???";
header = ptr;
bool ignore = false;
......@@ -1012,6 +1014,8 @@ int ioctl(int fd, int request, ...)
if (!panwrap_indent)
ignore = true;
panwrap_msg("case: %ld\n", IOCTL_CASE(request));
/* Queries are not interesting for replay */
if (IOCTL_CASE(request) == IOCTL_CASE(MALI_IOCTL_MEM_QUERY))
ignore = true;
......@@ -1030,7 +1034,7 @@ int ioctl(int fd, int request, ...)
if (IOCTL_CASE(request) == IOCTL_CASE(MALI_IOCTL_JOB_SUBMIT)) {
panwrap_log("for (int i = 0; i < 30; ++i) {\n");
panwrap_indent++;
emit_atoms(ptr);
emit_atoms(ptr, bifrost);
replay_memory();
}
......@@ -1065,8 +1069,12 @@ int ioctl(int fd, int request, ...)
ioctl_decode_pre(request, ptr);
}
panwrap_msg("got here\n");
ret = orig_ioctl(fd, request, ptr);
panwrap_msg("got here 2\n");
/* Track memory allocation if needed */
if (IOCTL_CASE(request) == IOCTL_CASE(MALI_IOCTL_MEM_ALLOC)) {
const struct mali_ioctl_mem_alloc *args = ptr;
......@@ -1074,6 +1082,15 @@ int ioctl(int fd, int request, ...)
panwrap_track_allocation(args->gpu_va, args->flags, number, args->va_pages * 4096);
}
if (IOCTL_CASE(request) == IOCTL_CASE(MALI_IOCTL_GPU_PROPS_REG_DUMP)) {
const struct mali_ioctl_gpu_props_reg_dump *dump = ptr;
unsigned product_id = dump->core.product_id;
panwrap_msg("product id: %d\n", product_id);
/* based on mali_kbase_gpu_id.h and mali_kbase_hw.c */
if (product_id >> 12 == 6 && product_id != 0x6956 /* T60x */)
bifrost = true;
}
if (!ignore) {
panwrap_indent--;
panwrap_log("};\n\n");
......@@ -1108,6 +1125,8 @@ int ioctl(int fd, int request, ...)
panwrap_log_flush();
getchar();
}
panwrap_msg("got here 3\n");
out:
UNLOCK();
return ret;
......@@ -1173,6 +1192,7 @@ int munmap(void *addr, size_t length)
return orig_munmap(addr, length);
LOCK();
panwrap_msg("unmapped 0x%p, length %zd\n", addr, length);
ret = orig_munmap(addr, length);
mem = panwrap_find_mapped_mem(addr);
if (!mem)
......
......@@ -7,7 +7,11 @@ srcs = [
'trans-builder.c'
]
X_dep = cc.find_library('X11', required: true)
if is_android
X_dep = []
else
X_dep = cc.find_library('X11', required: true)
endif
executable(
'panloader',
......
......@@ -28,9 +28,11 @@
/* From Linux arch/arm/include/asm/page.h */
#ifndef PAGE_SIZE
#define PAGE_SHIFT 12
#define PAGE_SIZE (1 << PAGE_SHIFT)
#define PAGE_MASK (~(PAGE_SIZE - 1))
#endif
/* From the kernel module */
......
#include <X11/Xlib.h>
#include <stdint.h>
#ifndef __ANDROID__
#include <X11/Xlib.h>
Display *d;
Window w;
XImage *image;
......@@ -23,3 +26,13 @@ void slowfb_init(uint8_t *framebuffer, int width, int height) {
void slowfb_update(uint8_t *framebuffer, int width, int height) {
XPutImage(d, w, gc, image, 0, 0, 0, 0, width, height);
}
#else
void slowfb_init(uint8_t *framebuffer, int width, int height) {
}
void slowfb_update(uint8_t *framebuffer, int width, int height) {
}
#endif
......@@ -132,7 +132,7 @@ trans_attr(mali_ptr data, size_t type_sz, int columns, int vertices)
/* Vertex/tiler payload */
void
trans_rasterizer_state(struct mali_payload_vertex_tiler *vt,
trans_rasterizer_state(struct mali_payload_vertex_tiler_32 *vt,
float line_width,
int front_face)
{
......
......@@ -30,7 +30,7 @@ trans_viewport(int viewport_x0, int viewport_y0,
int viewport_x1, int viewport_y1);
void
trans_rasterizer_state(struct mali_payload_vertex_tiler *vt,
trans_rasterizer_state(struct mali_payload_vertex_tiler_32 *vt,
float line_width,
int front_face);
......
......@@ -12,7 +12,7 @@
#include "pandev.h"
#include "trans-builder.h"
void main(void) {
int main(void) {
int fd = pandev_raw_open(), rc;
if (fd < 0) {
......@@ -261,7 +261,7 @@ void main(void) {
mali_ptr unknown6_1_p = pandev_upload(-1, alloc_gpu_va_19, memory_19, &unknown6_1, sizeof(unknown6_1), false);
struct mali_payload_vertex_tiler payload_1 = {
struct mali_payload_vertex_tiler_32 payload_1 = {
.vertex_count = MALI_POSITIVE(3),
.unk1 = 0x28000000,
.draw_mode = 0x14000000,
......@@ -326,7 +326,7 @@ void main(void) {
mali_ptr unknown6_2_p = pandev_upload(-1, alloc_gpu_va_19, memory_19, &unknown6_2, sizeof(unknown6_2), false);
struct mali_payload_vertex_tiler payload_2 = {
struct mali_payload_vertex_tiler_32 payload_2 = {
.vertex_count = MALI_POSITIVE(3),
.unk1 = 0x28000000,
.draw_mode = 0x18030000 | MALI_GL_TRIANGLES,
......@@ -421,4 +421,5 @@ void main(void) {
slowfb_update((uint8_t*) framebuffer, 400, 320);
}
printf("Replay finished.\n");
return 0;
}