From f0d4f840f836af0f7560c87fd41df7131c1b31b4 Mon Sep 17 00:00:00 2001 From: Icecream95 Date: Wed, 23 Jun 2021 20:31:37 +1200 Subject: [PATCH] pan/mdg: Add 16 bytes of padding to the end of shaders Fixes INSTR_INVALID_PC faults when a shader ends on a 16MB boundary. Cc: mesa-stable Part-of: (cherry picked from commit 08495a948e16ac4fe54e282b77e8265551606219) --- .pick_status.json | 2 +- src/panfrost/midgard/midgard_compile.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.pick_status.json b/.pick_status.json index 883c9b25b52..b31ee762f2a 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -1264,7 +1264,7 @@ "description": "pan/mdg: Add 16 bytes of padding to the end of shaders", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null }, diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c index 58c9aea3f0d..b037521aa6e 100644 --- a/src/panfrost/midgard/midgard_compile.c +++ b/src/panfrost/midgard/midgard_compile.c @@ -3204,6 +3204,12 @@ midgard_compile_shader_nir(nir_shader *nir, fflush(stdout); } + /* A shader ending on a 16MB boundary causes INSTR_INVALID_PC faults, + * workaround by adding some padding to the end of the shader. (The + * kernel makes sure shader BOs can't cross 16MB boundaries.) */ + if (binary->size) + memset(util_dynarray_grow(binary, uint8_t, 16), 0, 16); + if ((midgard_debug & MIDGARD_DBG_SHADERDB || inputs->shaderdb) && !nir->info.internal) { unsigned nr_bundles = 0, nr_ins = 0;