Commit 7eb67a9b authored by Alyssa Rosenzweig's avatar Alyssa Rosenzweig 💜

Replace shader binaries with environment variables

While not interesting long term, replacing shader binaries will enable
us to test the shader compiler infrastructure before the corresponding
loading code is working in panwrap.
Signed-off-by: Alyssa Rosenzweig's avatarAlyssa Rosenzweig <alyssa@rosenzweig.io>
parent 112e040e
...@@ -15,6 +15,10 @@ ...@@ -15,6 +15,10 @@
#include "panwrap.h" #include "panwrap.h"
#include <mali-ioctl.h> #include <mali-ioctl.h>
#include <mali-job.h> #include <mali-job.h>
#include <stdio.h>
extern char* replace_fragment;
extern char* replace_vertex;
static char *panwrap_job_type_name(enum mali_job_type type) static char *panwrap_job_type_name(enum mali_job_type type)
{ {
...@@ -232,11 +236,28 @@ void panwrap_decode_vertex_or_tiler_job(const struct mali_job_descriptor_header ...@@ -232,11 +236,28 @@ void panwrap_decode_vertex_or_tiler_job(const struct mali_job_descriptor_header
if (meta_ptr) { if (meta_ptr) {
meta = panwrap_fetch_gpu_mem(NULL, meta_ptr, sizeof(*meta)); meta = panwrap_fetch_gpu_mem(NULL, meta_ptr, sizeof(*meta));
/* For testing the shader compiler infrastructure, panloader
* can replace shaders at runtime, configurable by
* environmental variables. */
char *replacement = h->job_type == JOB_TYPE_VERTEX ?
replace_vertex : replace_fragment;
if (*replacement) {
/* TODO: Determine size and possibly allocate our own
* shader buffer */
FILE *fp = fopen(replacement, "rb");
fread(meta->shader, 1, 64, fp);
fclose(fp);
}
panwrap_log("Shader blob: @ " MALI_PTR_FMT "\n", meta_ptr); panwrap_log("Shader blob: @ " MALI_PTR_FMT "\n", meta_ptr);
panwrap_indent++; panwrap_indent++;
panwrap_log_hexdump( panwrap_log_hexdump(
panwrap_fetch_gpu_mem(NULL, meta->shader, 832), 832); panwrap_fetch_gpu_mem(NULL, meta->shader, 832), 832);
panwrap_indent--; panwrap_indent--;
} else } else
panwrap_log("<no shader>\n"); panwrap_log("<no shader>\n");
......
...@@ -111,9 +111,13 @@ static LIST_HEAD(mmaps); ...@@ -111,9 +111,13 @@ static LIST_HEAD(mmaps);
static bool step_mode; static bool step_mode;
static long log_delay; static long log_delay;
char* replace_fragment;
char* replace_vertex;
PANLOADER_CONSTRUCTOR { PANLOADER_CONSTRUCTOR {
step_mode = panwrap_parse_env_bool("PANWRAP_STEP_MODE", false); step_mode = panwrap_parse_env_bool("PANWRAP_STEP_MODE", false);
log_delay = panwrap_parse_env_long("PANWRAP_LOG_DELAY", 0); log_delay = panwrap_parse_env_long("PANWRAP_LOG_DELAY", 0);
replace_fragment = panwrap_parse_env_string("PANWRAP_REPLACE_FRAGMENT", "");
replace_vertex = panwrap_parse_env_string("PANWRAP_REPLACE_VERTEX", "");
} }
#define LOCK() pthread_mutex_lock(&l); #define LOCK() pthread_mutex_lock(&l);
......
...@@ -279,6 +279,18 @@ panwrap_parse_env_long(const char *env, long def) ...@@ -279,6 +279,18 @@ panwrap_parse_env_long(const char *env, long def)
return ret; return ret;
} }
char *
panwrap_parse_env_string(const char *env, char *def)
{
const char *val = getenv(env);
if (!val)
return def;
return val;
}
PANLOADER_CONSTRUCTOR { PANLOADER_CONSTRUCTOR {
const char *env; const char *env;
......
...@@ -47,6 +47,7 @@ void panwrap_log_hexdump_trimmed(const void *data, size_t size); ...@@ -47,6 +47,7 @@ void panwrap_log_hexdump_trimmed(const void *data, size_t size);
bool panwrap_parse_env_bool(const char *env, bool def); bool panwrap_parse_env_bool(const char *env, bool def);
long panwrap_parse_env_long(const char *env, long def); long panwrap_parse_env_long(const char *env, long def);
char * panwrap_parse_env_string(const char *env, char *def);
extern short panwrap_indent; extern short panwrap_indent;
......
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