diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/broadcom/common/v3d_debug.c | 1 | ||||
-rw-r--r-- | src/broadcom/common/v3d_debug.h | 1 | ||||
-rw-r--r-- | src/gallium/drivers/v3d/v3d_program.c | 76 |
3 files changed, 78 insertions, 0 deletions
diff --git a/src/broadcom/common/v3d_debug.c b/src/broadcom/common/v3d_debug.c index 97404448e58..4a20dd26e41 100644 --- a/src/broadcom/common/v3d_debug.c +++ b/src/broadcom/common/v3d_debug.c @@ -54,6 +54,7 @@ static const struct debug_control debug_control[] = { { "vs", V3D_DEBUG_VS}, { "cs", V3D_DEBUG_CS}, { "always_flush", V3D_DEBUG_ALWAYS_FLUSH}, + { "precompile", V3D_DEBUG_PRECOMPILE}, { NULL, 0 } }; diff --git a/src/broadcom/common/v3d_debug.h b/src/broadcom/common/v3d_debug.h index d9f5255e216..83c368e35e9 100644 --- a/src/broadcom/common/v3d_debug.h +++ b/src/broadcom/common/v3d_debug.h @@ -55,6 +55,7 @@ extern uint32_t V3D_DEBUG; #define V3D_DEBUG_NORAST (1 << 11) #define V3D_DEBUG_ALWAYS_FLUSH (1 << 12) #define V3D_DEBUG_CLIF (1 << 13) +#define V3D_DEBUG_PRECOMPILE (1 << 14) #ifdef HAVE_ANDROID_PLATFORM #define LOG_TAG "BROADCOM-MESA" diff --git a/src/gallium/drivers/v3d/v3d_program.c b/src/gallium/drivers/v3d/v3d_program.c index 5047ff75c55..d6350682936 100644 --- a/src/gallium/drivers/v3d/v3d_program.c +++ b/src/gallium/drivers/v3d/v3d_program.c @@ -38,6 +38,12 @@ #include "broadcom/cle/v3d_packet_v33_pack.h" #include "mesa/state_tracker/st_glsl_types.h" +static struct v3d_compiled_shader * +v3d_get_compiled_shader(struct v3d_context *v3d, struct v3d_key *key); +static void +v3d_setup_shared_precompile_key(struct v3d_uncompiled_shader *uncompiled, + struct v3d_key *key); + static gl_varying_slot v3d_get_slot_for_driver_location(nir_shader *s, uint32_t driver_location) { @@ -175,6 +181,56 @@ uniforms_type_size(const struct glsl_type *type) return st_glsl_storage_type_size(type, false); } +/** + * Precompiles a shader variant at shader state creation time if + * V3D_DEBUG=precompile is set. Used for shader-db + * (https://gitlab.freedesktop.org/mesa/shader-db) + */ +static void +v3d_shader_precompile(struct v3d_context *v3d, + struct v3d_uncompiled_shader *so) +{ + nir_shader *s = so->base.ir.nir; + + if (s->info.stage == MESA_SHADER_FRAGMENT) { + struct v3d_fs_key key = { + .base.shader_state = so, + }; + + v3d_setup_shared_precompile_key(so, &key.base); + v3d_get_compiled_shader(v3d, &key.base); + } else { + struct v3d_vs_key key = { + .base.shader_state = so, + }; + + v3d_setup_shared_precompile_key(so, &key.base); + + /* Compile VS: All outputs */ + for (int vary = 0; vary < 64; vary++) { + if (!(s->info.outputs_written & (1ull << vary))) + continue; + for (int i = 0; i < 4; i++) { + key.fs_inputs[key.num_fs_inputs++] = + v3d_slot_from_slot_and_component(vary, + i); + } + } + + v3d_get_compiled_shader(v3d, &key.base); + + /* Compile VS bin shader: only position (XXX: include TF) */ + key.is_coord = true; + key.num_fs_inputs = 0; + for (int i = 0; i < 4; i++) { + key.fs_inputs[key.num_fs_inputs++] = + v3d_slot_from_slot_and_component(VARYING_SLOT_POS, + i); + } + v3d_get_compiled_shader(v3d, &key.base); + } +} + static void * v3d_shader_state_create(struct pipe_context *pctx, const struct pipe_shader_state *cso) @@ -245,6 +301,9 @@ v3d_shader_state_create(struct pipe_context *pctx, fprintf(stderr, "\n"); } + if (V3D_DEBUG & V3D_DEBUG_PRECOMPILE) + v3d_shader_precompile(v3d, so); + return so; } @@ -399,6 +458,23 @@ v3d_setup_shared_key(struct v3d_context *v3d, struct v3d_key *key, } static void +v3d_setup_shared_precompile_key(struct v3d_uncompiled_shader *uncompiled, + struct v3d_key *key) +{ + nir_shader *s = uncompiled->base.ir.nir; + + for (int i = 0; i < s->info.num_textures; i++) { + key->tex[i].return_size = 16; + key->tex[i].return_channels = 2; + + key->tex[i].swizzle[0] = PIPE_SWIZZLE_X; + key->tex[i].swizzle[1] = PIPE_SWIZZLE_Y; + key->tex[i].swizzle[2] = PIPE_SWIZZLE_Z; + key->tex[i].swizzle[3] = PIPE_SWIZZLE_W; + } +} + +static void v3d_update_compiled_fs(struct v3d_context *v3d, uint8_t prim_mode) { struct v3d_job *job = v3d->job; |