diff --git a/.github/actions/setup-tinygrad/action.yml b/.github/actions/setup-tinygrad/action.yml index 76323bc415..0b2dbc05a5 100644 --- a/.github/actions/setup-tinygrad/action.yml +++ b/.github/actions/setup-tinygrad/action.yml @@ -302,4 +302,4 @@ runs: - name: Install mesa (macOS) if: inputs.mesa == 'true' && runner.os == 'macOS' shell: bash - run: brew install sirhcm/tinymesa/tinymesa + run: brew install sirhcm/tinymesa/tinymesa_cpu diff --git a/autogen_stubs.sh b/autogen_stubs.sh index 5d02cd37f4..58d919d597 100755 --- a/autogen_stubs.sh +++ b/autogen_stubs.sh @@ -520,17 +520,17 @@ generate_mesa() { LVP_NIR_OPTIONS=$(./extra/mesa/lvp_nir_options.sh $MESA_SRC) fixup $BASE/mesa.py - patch_dlopen $BASE/mesa.py tinymesa_cpu "(BASE:=os.getenv('MESA_PATH', f\"/usr{'/local/' if helpers.OSX else '/'}lib\"))+'/libtinymesa_cpu'+(EXT:='.dylib' if helpers.OSX else '.so')" "f'{BASE}/libtinymesa{EXT}'" "f'{brew_prefix()}/lib/libtinymesa_cpu.dylib'" + patch_dlopen $BASE/mesa.py tinymesa_cpu "(BASE:=os.getenv('MESA_PATH', f\"/usr{'/local/' if helpers.OSX else '/'}lib\"))+'/libtinymesa_cpu'+(EXT:='.dylib' if helpers.OSX else '.so')" "f'{BASE}/libtinymesa{EXT}'" "brew_path('tinymesa_cpu')" "brew_path('tinymesa')" echo "lvp_nir_options = gzip.decompress(base64.b64decode('$LVP_NIR_OPTIONS'))" >> $BASE/mesa.py cat <> $BASE/mesa.py + echo "def __getattr__(nm): raise AttributeError('LLVMpipe requires tinymesa_cpu' if 'tinymesa_cpu' not in dll._name else f'attribute {nm} not found') if dll else FileNotFoundError(f'libtinymesa not found (MESA_PATH={BASE}). See https://github.com/sirhcm/tinymesa ($TINYMESA_TAG, $MESA_TAG)')" >> $BASE/mesa.py sed -i "s/ctypes.glsl_base_type/glsl_base_type/" $BASE/mesa.py # bitfield bug in clang2py sed -i "s/('fp_fast_math', ctypes.c_bool, 9)/('fp_fast_math', ctypes.c_uint32, 9)/" $BASE/mesa.py diff --git a/tinygrad/runtime/autogen/mesa.py b/tinygrad/runtime/autogen/mesa.py index 78a0efc2e6..66cd9e5342 100644 --- a/tinygrad/runtime/autogen/mesa.py +++ b/tinygrad/runtime/autogen/mesa.py @@ -7,13 +7,14 @@ # LONGDOUBLE_SIZE is: 16 # import ctypes, ctypes.util, os, gzip, base64, subprocess, tinygrad.helpers as helpers -def brew_prefix(): - try: return subprocess.check_output(['brew', '--prefix', 'tinymesa']).decode().strip() - except Exception: return '' +def brew_path(nm): + try: return f"{subprocess.check_output(['brew', '--prefix', nm]).decode().strip()}/lib/lib{nm}.dylib" + except Exception: return 'failed' PATHS_TO_TRY = [ (BASE:=os.getenv('MESA_PATH', f"/usr{'/local/' if helpers.OSX else '/'}lib"))+'/libtinymesa_cpu'+(EXT:='.dylib' if helpers.OSX else '.so'), f'{BASE}/libtinymesa{EXT}', - f'{brew_prefix()}/lib/libtinymesa_cpu.dylib', + brew_path('tinymesa_cpu'), + brew_path('tinymesa'), ] def _try_dlopen_tinymesa_cpu(): library = ctypes.util.find_library("tinymesa_cpu") @@ -6087,7 +6088,7 @@ struct_nir_op_info._fields_ = [ nir_op_info = struct_nir_op_info try: nir_op_infos = (struct_nir_op_info * 489).in_dll(_libraries['libtinymesa_cpu.so'], 'nir_op_infos') -except AttributeError: pass +except (AttributeError, ValueError): pass try: nir_op_is_selection = _libraries['FIXME_STUB'].nir_op_is_selection nir_op_is_selection.restype = ctypes.c_bool @@ -8118,7 +8119,7 @@ c__EA_nir_intrinsic_index_flag = ctypes.c_uint32 # enum nir_intrinsic_index_flag = c__EA_nir_intrinsic_index_flag nir_intrinsic_index_flag__enumvalues = c__EA_nir_intrinsic_index_flag__enumvalues try: nir_intrinsic_index_names = (ctypes.POINTER(ctypes.c_char) * 75).in_dll(_libraries['libtinymesa_cpu.so'], 'nir_intrinsic_index_names') -except AttributeError: pass +except (AttributeError, ValueError): pass class struct_nir_intrinsic_instr(Structure): pass @@ -8242,7 +8243,7 @@ struct_nir_intrinsic_info._fields_ = [ nir_intrinsic_info = struct_nir_intrinsic_info try: nir_intrinsic_infos = (struct_nir_intrinsic_info * 732).in_dll(_libraries['libtinymesa_cpu.so'], 'nir_intrinsic_infos') -except AttributeError: pass +except (AttributeError, ValueError): pass try: nir_intrinsic_src_components = _libraries['libtinymesa_cpu.so'].nir_intrinsic_src_components nir_intrinsic_src_components.restype = ctypes.c_uint32 @@ -19877,4 +19878,4 @@ __all__ = \ 'union_util_format_description_0', 'util_format_colorspace', 'util_format_layout', 'va_list'] lvp_nir_options = gzip.decompress(base64.b64decode('H4sIAAAAAAAAA2NgZGRkYGAAkYxgCsQFsxigwgwQBoxmhCqFq2WEKwIrAEGIkQxoAEMALwCqVsCiGUwLMHA0QPn29nBJkswHANb8YpH4AAAA')) -def __getattr__(nm): raise AttributeError() if dll else FileNotFoundError(f'libtinymesa not found (MESA_PATH={BASE}). See https://github.com/sirhcm/tinymesa (tinymesa-32dc66c, mesa-25.2.4)') +def __getattr__(nm): raise AttributeError('LLVMpipe requires tinymesa_cpu' if 'tinymesa_cpu' not in dll._name else f'attribute {nm} not found') if dll else FileNotFoundError(f'libtinymesa not found (MESA_PATH={BASE}). See https://github.com/sirhcm/tinymesa (tinymesa-32dc66c, mesa-25.2.4)')