From b9f9b35431c7cf890fddd9dd7fdaeaf19f3ef8e6 Mon Sep 17 00:00:00 2001 From: Jordan Justen Date: Wed, 28 Feb 2018 15:55:47 -0800 Subject: [PATCH] i965: Add brw_(read|write)_blob_program_data functions We will want to use these for both the disk shader cache, and for the ARB_get_program_binary. Signed-off-by: Jordan Justen Reviewed-by: Timothy Arceri --- src/mesa/drivers/dri/i965/brw_disk_cache.c | 45 ++---------------- src/mesa/drivers/dri/i965/brw_program.h | 10 ++++ .../drivers/dri/i965/brw_program_binary.c | 47 +++++++++++++++++++ 3 files changed, 61 insertions(+), 41 deletions(-) diff --git a/src/mesa/drivers/dri/i965/brw_disk_cache.c b/src/mesa/drivers/dri/i965/brw_disk_cache.c index 4aa304eb4a6..82a9c121c63 100644 --- a/src/mesa/drivers/dri/i965/brw_disk_cache.c +++ b/src/mesa/drivers/dri/i965/brw_disk_cache.c @@ -73,51 +73,14 @@ gen_shader_sha1(struct brw_context *brw, struct gl_program *prog, _mesa_sha1_compute(manifest, strlen(manifest), out_sha1); } -static void -write_blob_program_data(struct blob *binary, gl_shader_stage stage, - const void *program, - struct brw_stage_prog_data *prog_data) -{ - /* Write prog_data to blob. */ - blob_write_bytes(binary, prog_data, brw_prog_data_size(stage)); - - /* Write program to blob. */ - blob_write_bytes(binary, program, prog_data->program_size); - - /* Write push params */ - blob_write_bytes(binary, prog_data->param, - sizeof(uint32_t) * prog_data->nr_params); - - /* Write pull params */ - blob_write_bytes(binary, prog_data->pull_param, - sizeof(uint32_t) * prog_data->nr_pull_params); -} - static bool read_blob_program_data(struct blob_reader *binary, struct gl_program *prog, gl_shader_stage stage, const uint8_t **program, struct brw_stage_prog_data *prog_data) { - /* Read shader prog_data from blob. */ - blob_copy_bytes(binary, prog_data, brw_prog_data_size(stage)); - if (binary->overrun) - return false; - - /* Read shader program from blob. */ - *program = blob_read_bytes(binary, prog_data->program_size); - - /* Read push params */ - prog_data->param = rzalloc_array(NULL, uint32_t, prog_data->nr_params); - blob_copy_bytes(binary, prog_data->param, - sizeof(uint32_t) * prog_data->nr_params); - - /* Read pull params */ - prog_data->pull_param = rzalloc_array(NULL, uint32_t, - prog_data->nr_pull_params); - blob_copy_bytes(binary, prog_data->pull_param, - sizeof(uint32_t) * prog_data->nr_pull_params); - - return (binary->current == binary->end && !binary->overrun); + return + brw_read_blob_program_data(binary, prog, stage, program, prog_data) && + (binary->current == binary->end); } static bool @@ -318,7 +281,7 @@ write_program_data(struct brw_context *brw, struct gl_program *prog, * generation time when the program is in normal memory accessible with * cache to the CPU. Another easier change would be to use * _mesa_streaming_load_memcpy to read from the program mapped memory. */ - write_blob_program_data(&binary, stage, program_map, prog_data); + brw_write_blob_program_data(&binary, stage, program_map, prog_data); unsigned char sha1[20]; char buf[41]; diff --git a/src/mesa/drivers/dri/i965/brw_program.h b/src/mesa/drivers/dri/i965/brw_program.h index 701b8da482e..a49bc81a2b4 100644 --- a/src/mesa/drivers/dri/i965/brw_program.h +++ b/src/mesa/drivers/dri/i965/brw_program.h @@ -32,6 +32,8 @@ extern "C" { #endif struct brw_context; +struct blob; +struct blob_reader; enum brw_param_domain { BRW_PARAM_DOMAIN_BUILTIN = 0, @@ -107,6 +109,14 @@ void brw_upload_tes_prog(struct brw_context *brw); void brw_tes_populate_key(struct brw_context *brw, struct brw_tes_prog_key *key); +void brw_write_blob_program_data(struct blob *binary, gl_shader_stage stage, + const void *program, + struct brw_stage_prog_data *prog_data); +bool brw_read_blob_program_data(struct blob_reader *binary, + struct gl_program *prog, gl_shader_stage stage, + const uint8_t **program, + struct brw_stage_prog_data *prog_data); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/mesa/drivers/dri/i965/brw_program_binary.c b/src/mesa/drivers/dri/i965/brw_program_binary.c index cb1cfdb560a..b72dc04ecab 100644 --- a/src/mesa/drivers/dri/i965/brw_program_binary.c +++ b/src/mesa/drivers/dri/i965/brw_program_binary.c @@ -133,3 +133,50 @@ brw_deserialize_program_binary(struct gl_context *ctx, { brw_program_deserialize_driver_blob(ctx, prog, prog->info.stage); } + +void +brw_write_blob_program_data(struct blob *binary, gl_shader_stage stage, + const void *program, + struct brw_stage_prog_data *prog_data) +{ + /* Write prog_data to blob. */ + blob_write_bytes(binary, prog_data, brw_prog_data_size(stage)); + + /* Write program to blob. */ + blob_write_bytes(binary, program, prog_data->program_size); + + /* Write push params */ + blob_write_bytes(binary, prog_data->param, + sizeof(uint32_t) * prog_data->nr_params); + + /* Write pull params */ + blob_write_bytes(binary, prog_data->pull_param, + sizeof(uint32_t) * prog_data->nr_pull_params); +} + +bool +brw_read_blob_program_data(struct blob_reader *binary, struct gl_program *prog, + gl_shader_stage stage, const uint8_t **program, + struct brw_stage_prog_data *prog_data) +{ + /* Read shader prog_data from blob. */ + blob_copy_bytes(binary, prog_data, brw_prog_data_size(stage)); + if (binary->overrun) + return false; + + /* Read shader program from blob. */ + *program = blob_read_bytes(binary, prog_data->program_size); + + /* Read push params */ + prog_data->param = rzalloc_array(NULL, uint32_t, prog_data->nr_params); + blob_copy_bytes(binary, prog_data->param, + sizeof(uint32_t) * prog_data->nr_params); + + /* Read pull params */ + prog_data->pull_param = rzalloc_array(NULL, uint32_t, + prog_data->nr_pull_params); + blob_copy_bytes(binary, prog_data->pull_param, + sizeof(uint32_t) * prog_data->nr_pull_params); + + return !binary->overrun; +} -- 2.30.2