anv: Keep the shader stage in anv_shader_bin

This will be used to decouple the logic flush_descriptor_sets() from
the position in the shader array, allowing us to store just the
shaders needed for each pipeline.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4040>
This commit is contained in:
Caio Marcelo de Oliveira Filho 2020-03-03 12:10:00 -08:00
parent 9bf044d254
commit 88df3bf79a
4 changed files with 32 additions and 8 deletions

View File

@ -69,8 +69,14 @@ upload_blorp_shader(struct blorp_batch *batch,
.sampler_count = 0,
};
/* The stage in anv_shader_bin is only useful for pipeline shaders, so just pass
* a dummy value here so we don't need to change BLORP API.
*
* TODO: Plumb the stage information to BLORP.
*/
gl_shader_stage stage = MESA_SHADER_NONE;
struct anv_shader_bin *bin =
anv_pipeline_cache_upload_kernel(&device->default_pipeline_cache,
anv_pipeline_cache_upload_kernel(&device->default_pipeline_cache, stage,
key, key_size, kernel, kernel_size,
NULL, 0,
prog_data, prog_data_size,

View File

@ -1360,7 +1360,7 @@ anv_pipeline_compile_graphics(struct anv_pipeline *pipeline,
&stages[s].bind_map);
struct anv_shader_bin *bin =
anv_device_upload_kernel(pipeline->device, cache,
anv_device_upload_kernel(pipeline->device, cache, s,
&stages[s].cache_key,
sizeof(stages[s].cache_key),
stages[s].code,
@ -1547,6 +1547,7 @@ anv_pipeline_compile_cs(struct anv_pipeline *pipeline,
const unsigned code_size = stage.prog_data.base.program_size;
bin = anv_device_upload_kernel(pipeline->device, cache,
MESA_SHADER_COMPUTE,
&stage.cache_key, sizeof(stage.cache_key),
stage.code, code_size,
stage.nir->constant_data,

View File

@ -32,6 +32,7 @@
struct anv_shader_bin *
anv_shader_bin_create(struct anv_device *device,
gl_shader_stage stage,
const void *key_data, uint32_t key_size,
const void *kernel_data, uint32_t kernel_size,
const void *constant_data, uint32_t constant_data_size,
@ -68,6 +69,8 @@ anv_shader_bin_create(struct anv_device *device,
shader->ref_cnt = 1;
shader->stage = stage;
key->size = key_size;
memcpy(key->data, key_data, key_size);
shader->key = key;
@ -132,6 +135,8 @@ static bool
anv_shader_bin_write_to_blob(const struct anv_shader_bin *shader,
struct blob *blob)
{
blob_write_uint32(blob, shader->stage);
blob_write_uint32(blob, shader->key->size);
blob_write_bytes(blob, shader->key->data, shader->key->size);
@ -182,6 +187,8 @@ static struct anv_shader_bin *
anv_shader_bin_create_from_blob(struct anv_device *device,
struct blob_reader *blob)
{
gl_shader_stage stage = blob_read_uint32(blob);
uint32_t key_size = blob_read_uint32(blob);
const void *key_data = blob_read_bytes(blob, key_size);
@ -223,7 +230,7 @@ anv_shader_bin_create_from_blob(struct anv_device *device,
if (blob->overrun)
return NULL;
return anv_shader_bin_create(device,
return anv_shader_bin_create(device, stage,
key_data, key_size,
kernel_data, kernel_size,
constant_data, constant_data_size,
@ -371,6 +378,7 @@ anv_pipeline_cache_add_shader_bin(struct anv_pipeline_cache *cache,
static struct anv_shader_bin *
anv_pipeline_cache_add_shader_locked(struct anv_pipeline_cache *cache,
gl_shader_stage stage,
const void *key_data, uint32_t key_size,
const void *kernel_data,
uint32_t kernel_size,
@ -389,7 +397,8 @@ anv_pipeline_cache_add_shader_locked(struct anv_pipeline_cache *cache,
return shader;
struct anv_shader_bin *bin =
anv_shader_bin_create(cache->device, key_data, key_size,
anv_shader_bin_create(cache->device, stage,
key_data, key_size,
kernel_data, kernel_size,
constant_data, constant_data_size,
prog_data, prog_data_size,
@ -404,6 +413,7 @@ anv_pipeline_cache_add_shader_locked(struct anv_pipeline_cache *cache,
struct anv_shader_bin *
anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache *cache,
gl_shader_stage stage,
const void *key_data, uint32_t key_size,
const void *kernel_data, uint32_t kernel_size,
const void *constant_data,
@ -419,7 +429,7 @@ anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache *cache,
pthread_mutex_lock(&cache->mutex);
struct anv_shader_bin *bin =
anv_pipeline_cache_add_shader_locked(cache, key_data, key_size,
anv_pipeline_cache_add_shader_locked(cache, stage, key_data, key_size,
kernel_data, kernel_size,
constant_data, constant_data_size,
prog_data, prog_data_size,
@ -435,7 +445,8 @@ anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache *cache,
return bin;
} else {
/* In this case, we're not caching it so the caller owns it entirely */
return anv_shader_bin_create(cache->device, key_data, key_size,
return anv_shader_bin_create(cache->device, stage,
key_data, key_size,
kernel_data, kernel_size,
constant_data, constant_data_size,
prog_data, prog_data_size,
@ -675,6 +686,7 @@ anv_device_search_for_kernel(struct anv_device *device,
struct anv_shader_bin *
anv_device_upload_kernel(struct anv_device *device,
struct anv_pipeline_cache *cache,
gl_shader_stage stage,
const void *key_data, uint32_t key_size,
const void *kernel_data, uint32_t kernel_size,
const void *constant_data,
@ -688,14 +700,14 @@ anv_device_upload_kernel(struct anv_device *device,
{
struct anv_shader_bin *bin;
if (cache) {
bin = anv_pipeline_cache_upload_kernel(cache, key_data, key_size,
bin = anv_pipeline_cache_upload_kernel(cache, stage, key_data, key_size,
kernel_data, kernel_size,
constant_data, constant_data_size,
prog_data, prog_data_size,
stats, num_stats,
xfb_info, bind_map);
} else {
bin = anv_shader_bin_create(device, key_data, key_size,
bin = anv_shader_bin_create(device, stage, key_data, key_size,
kernel_data, kernel_size,
constant_data, constant_data_size,
prog_data, prog_data_size,

View File

@ -1210,6 +1210,7 @@ anv_pipeline_cache_search(struct anv_pipeline_cache *cache,
const void *key, uint32_t key_size);
struct anv_shader_bin *
anv_pipeline_cache_upload_kernel(struct anv_pipeline_cache *cache,
gl_shader_stage stage,
const void *key_data, uint32_t key_size,
const void *kernel_data, uint32_t kernel_size,
const void *constant_data,
@ -1230,6 +1231,7 @@ anv_device_search_for_kernel(struct anv_device *device,
struct anv_shader_bin *
anv_device_upload_kernel(struct anv_device *device,
struct anv_pipeline_cache *cache,
gl_shader_stage stage,
const void *key_data, uint32_t key_size,
const void *kernel_data, uint32_t kernel_size,
const void *constant_data,
@ -3097,6 +3099,8 @@ struct anv_shader_bin_key {
struct anv_shader_bin {
uint32_t ref_cnt;
gl_shader_stage stage;
const struct anv_shader_bin_key *key;
struct anv_state kernel;
@ -3118,6 +3122,7 @@ struct anv_shader_bin {
struct anv_shader_bin *
anv_shader_bin_create(struct anv_device *device,
gl_shader_stage stage,
const void *key, uint32_t key_size,
const void *kernel, uint32_t kernel_size,
const void *constant_data, uint32_t constant_data_size,