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 <jordan.l.justen@intel.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
This commit is contained in:
Jordan Justen 2018-02-28 15:55:47 -08:00
parent 1777c23abf
commit b9f9b35431
No known key found for this signature in database
GPG Key ID: 37F99F68CAF992EB
3 changed files with 61 additions and 41 deletions

View File

@ -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];

View File

@ -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

View File

@ -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;
}