mesa: optimize _mesa_program_resource_location

- xxhash is faster than sha1.
- remove superfluous calls to strlen

Using SPECviewperf13 snx-03 first subtest and "perf -e cycles -g", perf report says:

 Before  | After  | Function
---------|--------|---------------
  47.39% | 47.36% | _mesa_CallList
   5.00% |  3.03% | _mesa_program_resource_location

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7078>
This commit is contained in:
Pierre-Eric Pelloux-Prayer
2020-10-07 17:31:51 +02:00
parent ba67843dbd
commit b81ed32ba8
4 changed files with 12 additions and 17 deletions
+2 -1
View File
@@ -1009,7 +1009,8 @@ tfeedback_decl::init(struct gl_context *ctx, const void *mem_ctx,
/* Parse a declaration. */
const char *base_name_end;
long subscript = parse_program_resource_name(input, &base_name_end);
long subscript = parse_program_resource_name(input, strlen(input),
&base_name_end);
this->var_name = ralloc_strndup(mem_ctx, input, base_name_end - input);
if (this->var_name == NULL) {
_mesa_error_no_memory(__func__);
+1 -1
View File
@@ -498,6 +498,7 @@ linker_warning(gl_shader_program *prog, const char *fmt, ...)
*/
long
parse_program_resource_name(const GLchar *name,
const size_t len,
const GLchar **out_base_name_end)
{
/* Section 7.3.1 ("Program Interfaces") of the OpenGL 4.3 spec says:
@@ -508,7 +509,6 @@ parse_program_resource_name(const GLchar *name,
* string will not include white space anywhere in the string."
*/
const size_t len = strlen(name);
*out_base_name_end = name + len;
if (len == 0 || name[len-1] != ']')
+1 -1
View File
@@ -50,7 +50,7 @@ build_program_resource_list(struct gl_context *ctx,
bool add_packed_varyings_only);
extern long
parse_program_resource_name(const GLchar *name,
parse_program_resource_name(const GLchar *name, const size_t len,
const GLchar **out_base_name_end);
#endif /* GLSL_PROGRAM_H */
+8 -14
View File
@@ -517,7 +517,7 @@ valid_array_index(const GLchar *name, unsigned *array_index)
long idx = 0;
const GLchar *out_base_name_end;
idx = parse_program_resource_name(name, &out_base_name_end);
idx = parse_program_resource_name(name, strlen(name), &out_base_name_end);
if (idx < 0)
return false;
@@ -528,17 +528,9 @@ valid_array_index(const GLchar *name, unsigned *array_index)
}
static uint32_t
compute_resource_key(GLenum programInterface, const char *name)
compute_resource_key(GLenum programInterface, const char *name, size_t len)
{
struct mesa_sha1 ctx;
unsigned char sha1[20];
_mesa_sha1_init(&ctx);
_mesa_sha1_update(&ctx, &programInterface, sizeof(programInterface));
_mesa_sha1_update(&ctx, name, strlen(name));
_mesa_sha1_final(&ctx, sha1);
return _mesa_hash_data(sha1, sizeof(sha1));
return _mesa_hash_data_with_seed(name, len, programInterface + len);
}
static struct gl_program_resource *
@@ -547,7 +539,8 @@ search_resource_hash(struct gl_shader_program *shProg,
unsigned *array_index)
{
const char *base_name_end;
long index = parse_program_resource_name(name, &base_name_end);
size_t len = strlen(name);
long index = parse_program_resource_name(name, len, &base_name_end);
char *name_copy;
/* If dealing with array, we need to get the basename. */
@@ -555,11 +548,12 @@ search_resource_hash(struct gl_shader_program *shProg,
name_copy = (char *) malloc(base_name_end - name + 1);
memcpy(name_copy, name, base_name_end - name);
name_copy[base_name_end - name] = '\0';
len = base_name_end - name;
} else {
name_copy = (char*) name;
}
uint32_t key = compute_resource_key(programInterface, name_copy);
uint32_t key = compute_resource_key(programInterface, name_copy, len);
struct gl_program_resource *res = (struct gl_program_resource *)
_mesa_hash_table_u64_search(shProg->data->ProgramResourceHash, key);
@@ -1927,7 +1921,7 @@ _mesa_create_program_resource_hash(struct gl_shader_program *shProg)
for (unsigned i = 0; i < shProg->data->NumProgramResourceList; i++, res++) {
const char *name = _mesa_program_resource_name(res);
if (name) {
uint32_t key = compute_resource_key(res->Type, name);
uint32_t key = compute_resource_key(res->Type, name, strlen(name));
_mesa_hash_table_u64_insert(shProg->data->ProgramResourceHash, key,
res);
}