mesa/src/compiler
Jason Ekstrand 1b8a43a0ba 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>
2022-04-20 18:44:35 +00:00
..
clc clc: Declare LLVMContexts on the stack 2022-04-14 21:19:56 +00:00
glsl glsl: fix needs_lowering() call in varying packing pass 2022-04-07 23:57:40 +00:00
isaspec util: Remove util_cpu_detect 2022-04-20 18:44:35 +00:00
nir nir/lower_alu_to_scalar: don't set the nir_builder cursor 2022-04-20 17:53:48 +00:00
spirv nir: introduce and use nir_component_mask 2022-04-19 06:54:47 +00:00
builtin_type_macros.h glsl: add vec5 glsl types 2022-01-18 16:10:35 +08:00
glsl_types.cpp util: Remove util_cpu_detect 2022-04-20 18:44:35 +00:00
glsl_types.h compiler/types: Add a texture type 2021-10-16 05:49:34 +00:00
meson.build spirv: Use a single binary for gtests 2021-10-20 17:55:36 +00:00
nir_gl_types.h nir: remove gl.h include from nir headers. 2022-01-19 21:54:58 +00:00
nir_types.cpp nir: remove gl.h include from nir headers. 2022-01-19 21:54:58 +00:00
nir_types.h nir: remove gl.h include from nir headers. 2022-01-19 21:54:58 +00:00
shader_enums.c compiler: Extract num_mesh_vertices_per_primitive function. 2022-02-14 11:13:42 +01:00
shader_enums.h nir: Introduce workgroup_index and ability to lower workgroup_id to it. 2022-03-08 17:36:31 +00:00
shader_info.h spirv: Implement the function portion of the Linkage capability 2022-03-23 10:24:31 +00:00