# gpuchecker.py import re from fastapi import APIRouter from fastapi.responses import PlainTextResponse router = APIRouter() def _check_graphics_card_info(supported_models, unsupported_models, graphics_card_info): for model_pattern, descr in supported_models.items(): if match := re.search(model_pattern, graphics_card_info, re.I): return True, match.group(), descr.format(*match.groups()) for model_pattern, descr in unsupported_models.items(): if match := re.search(model_pattern, graphics_card_info, re.I): return False, match.group(), descr.format(*match.groups()) return False, None, None def _check_amd(graphics_card_info): supported_models = { r"Radeon\s*6\d{2}([A-Z])?\b": "this model belongs to the RDNA 2 architecture", r"(Radeon\s*)?R9\s*[A-Z0-9]+": "R9 models belongs to the GCN 1st gen or newer architecture", r"(Radeon\s*)?(Pro\s*)?\bW7\d{3}(X)?\b(\s*Duo)?": "Radeon Pro W7000 models belongs to the RDNA 3 architecture", r"(Radeon\s*)?(Pro\s*)?\bW([5-6])\d{3}(X)?\b(\s*Duo)?": "Radeon Pro W{2}000 models belongs to the RDNA 2 architecture", r"(AMD\s*)?6800 XT": "this model belongs to the RDNA 2 architecture", r"Radeon\s*(\(TM\)\s*)?RX Vega(\s*\d{2}\b)": "Radeon RX Vega models belongs to the GCN 5th gen architecture", r"Radeon Pro Vega ((\d{2}(X)?|II)\b)?(\s*Duo)?": "Radeon Pro Vega models belongs to the GCN 5th gen architecture", r"Radeon\s*(\(TM\)\s*)?Pro [4-5]\d{2}(X)?": "Radeon Pro 400/500 series belongs to the GCN 4th gen architecture", r"Radeon VII": "RX models belongs to the GCN 5 architecture", r"Radeon Graphics \(renoir": "this model belongs to the GCN 5th gen architecture (Vega)", r"Radeon\s*(\(TM\)\s*)?Vega 8 (Graphics )?\(raven[^)]+\)": "this model belongs to the GCN 5th gen architecture (Vega)", r"Radeon\s*(\(TM\)\s*)?(Pro\s*)?WX\s*(5\d{3}\b)": "this model belongs to the GCN 4th gen architecture", r"FirePro": "FirePro models belongs to the GCN 1st gen or newer architecture", r"HD\s*(7[7-9]\d{2})": "HD {0} model belongs to the GCN 1st gen or newer architecture", r"(Radeon\s*)?RX\s*([5-7]\d{3})(M|X)?(\s*(XT|Series|S|XTX))?\b": "RX models belongs to the GCN 1st gen or newer architecture", r"(Radeon\s*)?(RX\s*)?6(3|4)0\b": "it has Polaris 23 chip that belongs to GCN 4th gen architecture", r"(Radeon\s*)?62(0|5)\b": "it has Polaris 24 chip that belongs to GCN 3st gen architecture", r"(Radeon\s*)?610\b": "it has Banks chip that belongs to GCN 1st gen architecture", r"(Radeon\s*)?RX\s*580(X?)\b": "it has Polaris 20 XT chip that belongs to GCN 4th gen architecture", r"(Radeon\s*)?RX\s*570\b": "it has Ellesmere Pro chip that belongs to GCN 4th gen architecture", r"(Radeon\s*)?RX\s*560X\b": "it has Polaris 31 XL chip that belongs to GCN 4th gen architecture", r"(Radeon\s*)?RX\s*560\b": "it has Baffin XT chip that belongs to GCN 4th gen architecture", r"(Radeon\s*)?5(40X|50X)\b": "it has Polaris 23 XT chip that belongs to GCN 4th gen architecture", r"(Radeon\s*)?RX\s*5(40|50)\b": "it has Lexa Pro chip that belongs to GCN 4th gen architecture", r"(Radeon\s*)?RX\s*480\b": "it has Arctic Islands chip that belongs to GCN 4th gen architecture", r"(Radeon\s*)?(\(TM\)\s*)?RX\s*4[6-8]0(\b|D)": "it has Ellesmere chip that belongs to GCN 4st gen architecture", r"(Radeon\s*)?5(30X|35)\b": "it has Polaris 24 XT chip that belongs to GCN 3rd gen architecture", r"(Radeon\s*)?530\b": "it has Weston chip that belongs to GCN 3rd gen architecture", r"(Radeon\s*)?520\b": "it has Banks chip that belongs to GCN 1st gen architecture", r"(Radeon\s*)?(\(TM\)\s*)?R4": "Radeon R4 models belongs to the GCN 1st gen or newer architecture", r"(Radeon\s*)?(\(TM\)\s*)?R5 (M)?335": "Radeon R5 M335 belongs to the GCN 1st gen architecture", r"(Radeon\s*)?(\(TM\)\s*)?R7 (M)?2\d{2}(E|X)?\b": "Radeon R7 200 models belongs to GCN 1st or 2nd gen architecture", r"(Radeon\s*)?(\(TM\)\s*)?R5 (M)?24\d(E|X)?\b": "Radeon R5 240 models belongs to GCN 1st gen architecture", # r"Radeon\s*(\(TM\)\s*)?(Pro\s*)?Vega (Pro\s*)?": "this model belongs to the GCN 4th gen architecture", # Add more model-to-architecture mappings as needed } unsupported_models = { r"HD ([5-6])\d{3}": "HD {0}XXX models have TeraScale architecture that is older than GCN 1st gen", r"HD\s*(7[3-6]\d{2})": "HD {0} model has TeraScale 2 architecture that is older than GCN 1st gen", r"Radeon R5 (M)?2(2|3)\d(X)?\b": "Radeon R5 220/230 models belongs to Terascale 2 architecture that is older than GCN 1st gen", r"(AMD\s*ATI\s*)?Radeon\s*680M": "AMD ATI Radeon 680M has TeraScale architecture that is older than GCN 1st gen", # Add more model-to-architecture mappings as needed } return _check_graphics_card_info(supported_models, unsupported_models, graphics_card_info) def _check_nvidia(graphics_card_info): supported_models = { r"(GeForce )?(RTX\s*)?(?= 11: return True else: if major >= 10 and minor >= 15: return True return False def gpu_checker_get_message(text): is_supported = False vendor = None model = None descr = None if "nvidia" in text.lower() or "rtx" in text.lower() or "gtx" in text.lower() or "geforce" in text.lower(): vendor = 'NVIDIA' is_supported, model, descr = _check_nvidia(text) elif "amd " in text.lower() or "ati " in text.lower() or "radeon" in text.lower(): vendor = 'AMD' is_supported, model, descr = _check_amd(text) elif "intel" in text.lower(): vendor = 'Intel' is_supported, model, descr = _check_intel(text) elif "apple" in text.lower() or re.search(r'\bM1\b', text): vendor = 'Apple' is_supported, model, descr = _check_apple(text) else: for func in {_check_nvidia, _check_amd, _check_intel, _check_apple}: is_supported, model, descr = func(text) if model: vendor = 'GPU' break if not vendor: return "Could not find graphics card information" elif not model: return f"Could not determine the card model from {vendor}" message = f"The {vendor} card {model} is {'supported' if is_supported else 'not supported'} as {descr}" if not is_supported: message += """ This GPU is below the minimum requirements for Blender, so Blender no longer provide support for it. https://www.blender.org/download/requirements/ Installing the latest graphics driver sometimes helps to make such GPUs work, see here for more information. https://docs.blender.org/manual/en/dev/troubleshooting/gpu/index.html If that doesn't help, you can use Blender 2.79: https://www.blender.org/download/previous-versions/ """ return message @router.get("/gpu_checker", response_class=PlainTextResponse) def gpu_checker(gpu_info: str = ""): message = gpu_checker_get_message(gpu_info) return message if __name__ == "__main__": gpu_info = "AMD Radeon HD 7660D" message = gpu_checker_get_message(gpu_info) print(message)