Commit 753b5a21 authored by Alyssa Rosenzweig's avatar Alyssa Rosenzweig 💜

Decode stencil ops

parent 531eb805
......@@ -71,15 +71,8 @@ enum mali_gl_mode {
#define MALI_NO_MSAA (1 << 30)
#define MALI_STENCIL_TEST (1 << 16)
/* These are packed, but also duplicated so it's better to construct like this.
* func should be a value from mali_stencil_func, corresponding to the
* according OpenGL stencil functions.
*
* Applies to stencil_0 and stencil_1
*/
#define MAKE_STENCIL_TEST(func, mask, ref) \
(func << 16) | (mask << 8) | (ref << 0)
/* Stencil test state is all encoded in a single u32, just with a lot of
* enums... */
enum mali_stencil_func {
MALI_STENCIL_NEVER = 0,
......@@ -92,6 +85,27 @@ enum mali_stencil_func {
MALI_STENCIL_ALWAYS = 7
};
enum mali_stencil_op {
MALI_STENCIL_KEEP = 0,
MALI_STENCIL_REPLACE = 1,
MALI_STENCIL_ZERO = 2,
MALI_STENCIL_INVERT = 3,
MALI_STENCIL_INCR_WRAP = 4,
MALI_STENCIL_DECR_WRAP = 5,
MALI_STENCIL_INCR = 6,
MALI_STENCIL_DECR = 7
};
struct mali_stencil_test {
unsigned ref : 8;
unsigned mask : 8;
enum mali_stencil_func func : 3;
enum mali_stencil_op sfail : 3;
enum mali_stencil_op dpfail : 3;
enum mali_stencil_op dppass : 3;
unsigned zero : 4;
} __attribute__((packed));
struct mali_shader_meta {
mali_ptr shader;
u32 zero1;
......@@ -122,10 +136,8 @@ struct mali_shader_meta {
u32 unknown2_3;
u32 unknown2_4;
/* Like clear_color, these fields appear to always be duplicated */
u32 stencil_front;
u32 stencil_back;
struct mali_stencil_test stencil_front;
struct mali_stencil_test stencil_back;
u32 unknown2_7;
u32 unknown2_8;
......
......@@ -112,9 +112,9 @@ static char *panwrap_gl_mode_name(enum mali_gl_mode mode)
#undef DEFINE_CASE
}
#define DEFINE_CASE(name) case MALI_STENCIL_ ## name: return "MALI_STENCIL_" #name
static char *panwrap_stencil_func_name(enum mali_stencil_func mode)
{
#define DEFINE_CASE(name) case MALI_STENCIL_ ## name: return "MALI_STENCIL_" #name
switch(mode) {
DEFINE_CASE(NEVER);
DEFINE_CASE(LESS);
......@@ -126,9 +126,25 @@ static char *panwrap_stencil_func_name(enum mali_stencil_func mode)
DEFINE_CASE(ALWAYS);
default: return "MALI_STENCIL_NEVER /* XXX: Unknown stencil function, check dump */";
}
#undef DEFINE_CASE
}
static char *panwrap_stencil_op_name(enum mali_stencil_op op)
{
switch(op) {
DEFINE_CASE(KEEP);
DEFINE_CASE(REPLACE);
DEFINE_CASE(ZERO);
DEFINE_CASE(INVERT);
DEFINE_CASE(INCR_WRAP);
DEFINE_CASE(DECR_WRAP);
DEFINE_CASE(INCR);
DEFINE_CASE(DECR);
default: return "MALI_STENCIL_KEEP /* XXX: Unknown stencil op, check dump */";
}
}
#undef DEFINE_CASE
static void panwrap_property_u32_list(const char *name, const u32 *lst, size_t c)
{
panwrap_log(".%s = { ", name);
......@@ -334,19 +350,28 @@ panwrap_replay_shader_address(const char *name, mali_ptr ptr)
}
static void
panwrap_replay_stencil(const char *name, u32 raw)
panwrap_replay_stencil(const char *name, const u32 *raw)
{
uint8_t ref = raw & 0xFF;
uint8_t mask = (raw >> 8) & 0xFF;
uint8_t func = (raw >> 16) & 0x7;
const struct mali_stencil_test *stencil = (struct mali_stencil_test *) raw;
uint8_t f1 = (raw >> 19) & 0x7;
uint8_t f2 = (raw >> 22) & 0x7;
uint8_t f3 = (raw >> 25) & 0x7;
const char *func = panwrap_stencil_func_name(stencil->func);
const char *sfail = panwrap_stencil_op_name(stencil->sfail);
const char *dpfail = panwrap_stencil_op_name(stencil->dpfail);
const char *dppass = panwrap_stencil_op_name(stencil->dppass);
const char *func_str = panwrap_stencil_func_name(func);
if (stencil->zero)
panwrap_msg("Stencil zero tripped: %X\n", stencil->zero);
panwrap_prop("stencil_%s = MAKE_STENCIL_TEST(%s, 0x%02X, %d) /* %d,%d,%d */", name, func_str, mask, ref, f1, f2, f3);
panwrap_log(".stencil_%s = {\n", name);
panwrap_indent++;
panwrap_prop("ref = %d", stencil->ref);
panwrap_prop("mask = 0x%02X", stencil->mask);
panwrap_prop("func = %s", func);
panwrap_prop("sfail = %s", sfail);
panwrap_prop("dpfail = %s", dpfail);
panwrap_prop("dppass = %s", dppass);
panwrap_indent--;
panwrap_log("},\n");
}
static int
......@@ -405,11 +430,8 @@ panwrap_replay_vertex_or_tiler_job(const struct mali_job_descriptor_header *h,
panwrap_log_decoded_flags(u4_flag_info, s->unknown2_4);
panwrap_log_cont(",\n");
if (s->stencil_front)
panwrap_replay_stencil("front", s->stencil_front);
if (s->stencil_back)
panwrap_replay_stencil("back", s->stencil_back);
panwrap_replay_stencil("front", &s->stencil_front);
panwrap_replay_stencil("back", &s->stencil_back);
panwrap_prop("unknown2_7 = 0x%" PRIx32, s->unknown2_7);
panwrap_prop("unknown2_8 = 0x%" PRIx32, s->unknown2_8);
......
......@@ -303,8 +303,22 @@ void main(void) {
.unknown2_2 = 0x0,
.unknown2_3 = MALI_HAS_MSAA | 0x3710ffff,
.unknown2_4 = /*MALI_NO_MSAA | */0x6f0ffff,
.stencil_front = MAKE_STENCIL_TEST(MALI_STENCIL_ALWAYS, 0xFF, 0),
.stencil_back = MAKE_STENCIL_TEST(MALI_STENCIL_ALWAYS, 0xFF, 0),
.stencil_front = {
.ref = 0,
.mask = 0xFF,
.func = MALI_STENCIL_ALWAYS,
.sfail = MALI_STENCIL_KEEP,
.dpfail = MALI_STENCIL_KEEP,
.dppass = MALI_STENCIL_KEEP,
},
.stencil_back = {
.ref = 0,
.mask = 0xFF,
.func = MALI_STENCIL_ALWAYS,
.sfail = MALI_STENCIL_KEEP,
.dpfail = MALI_STENCIL_KEEP,
.dppass = MALI_STENCIL_KEEP,
},
.unknown2_7 = 0x0,
.unknown2_8 = 0x0,
.blend_equation = 0xf0122122,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment