util: Remove util_cpu_detect
util_cpu_detect is an anti-pattern: it relies on callers high up in the call chain initializing a local implementation detail. As a real example, I added: ...a Mali compiler unit test ...that called bi_imm_f16() to construct an FP16 immediate ...that calls _mesa_float_to_half internally ...that calls util_get_cpu_caps internally, but only on x86_64! ...that relies on util_cpu_detect having been called before. As a consequence, this unit test: ...crashes on x86_64 with USE_X86_64_ASM set ...passes on every other architecture ...works on my local arm64 workstation and on my test board ...failed CI which runs on x86_64 ...needed to have a random util_cpu_detect() call sprinkled in. This is a bad design decision. It pollutes the tree with magic, it causes mysterious CI failures especially for non-x86_64 developers, and it is not justified by a micro-optimization. Instead, let's call util_cpu_detect directly from util_get_cpu_caps, avoiding the footgun where it fails to be called. This cleans up Mesa's design, simplifies the tree, and avoids a class of a (possibly platform-specific) failures. To mitigate the added overhead, wrap it all in a (fast) atomic load check and declare the whole thing as ATTRIBUTE_CONST so the compiler will CSE calls to util_cpu_detect. Co-authored-by: Alyssa Rosenzweig <alyssa@collabora.com> Reviewed-by: Marek Olšák <maraeo@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15580>
This commit is contained in:

committed by
Marge Bot

parent
90a0675989
commit
1b8a43a0ba
@@ -26,7 +26,6 @@
|
||||
#include "compiler/glsl/glsl_parser_extras.h"
|
||||
#include "glsl_types.h"
|
||||
#include "util/hash_table.h"
|
||||
#include "util/u_cpu_detect.h"
|
||||
#include "util/u_string.h"
|
||||
|
||||
|
||||
@@ -520,11 +519,6 @@ hash_free_type_function(struct hash_entry *entry)
|
||||
void
|
||||
glsl_type_singleton_init_or_ref()
|
||||
{
|
||||
/* This is required for _mesa_half_to_float() which is
|
||||
* required for constant-folding 16-bit float ops.
|
||||
*/
|
||||
util_cpu_detect();
|
||||
|
||||
mtx_lock(&glsl_type::hash_mutex);
|
||||
glsl_type_users++;
|
||||
mtx_unlock(&glsl_type::hash_mutex);
|
||||
|
@@ -773,8 +773,6 @@ isa_decode(void *bin, int sz, FILE *out, const struct isa_decode_options *option
|
||||
if (!options)
|
||||
options = &default_options;
|
||||
|
||||
util_cpu_detect(); /* needed for _mesa_half_to_float() */
|
||||
|
||||
state = rzalloc_size(NULL, sizeof(*state));
|
||||
state->options = options;
|
||||
state->num_instr = sz / (BITMASK_WORDS * sizeof(BITSET_WORD));
|
||||
|
Reference in New Issue
Block a user